boardinfo
This commit is contained in:
parent
46809d811b
commit
0f71e121fa
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ COMPILER_PATH = g++
|
|||
OUTPUT = main
|
||||
CFLAGS = -std=c++14 -O3
|
||||
LDFLAGS =
|
||||
OBJECTS = main.o drv/b15f.o
|
||||
OBJECTS = main.o drv/b15f.o drv/plottyfile.o
|
||||
|
||||
COMPILE = $(COMPILER_PATH) $(CFLAGS)
|
||||
|
||||
|
|
36
drv/b15f.cpp
36
drv/b15f.cpp
|
@ -50,6 +50,10 @@ void B15F::init()
|
|||
if(tries == 0)
|
||||
throw DriverException("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
|
||||
std::cout << "OK" << std::endl;
|
||||
|
||||
// Gib board info aus
|
||||
std::vector<std::string> info = getBoardInfo();
|
||||
std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,6 +119,38 @@ bool B15F::testIntConv()
|
|||
}
|
||||
|
||||
|
||||
std::vector<std::string> B15F::getBoardInfo(void)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<std::string> info;
|
||||
|
||||
writeByte(RQ_INFO);
|
||||
uint8_t n = readByte();
|
||||
while(n--)
|
||||
{
|
||||
uint8_t len = readByte();
|
||||
std::string str;
|
||||
|
||||
while(len--)
|
||||
str += static_cast<char>(readByte());
|
||||
|
||||
info.push_back(str);
|
||||
}
|
||||
|
||||
uint8_t aw = readByte();
|
||||
|
||||
if(aw != MSG_OK)
|
||||
throw DriverException("Board Info fehlerhalft");
|
||||
|
||||
return info;
|
||||
}
|
||||
catch(DriverException& de)
|
||||
{
|
||||
reconnect();
|
||||
return getBoardInfo();
|
||||
}
|
||||
}
|
||||
|
||||
bool B15F::digitaleAusgabe0(uint8_t port)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -25,6 +26,7 @@ public:
|
|||
void discard(void);
|
||||
bool testConnection(void);
|
||||
bool testIntConv(void);
|
||||
std::vector<std::string> getBoardInfo(void);
|
||||
|
||||
// Board Befehle
|
||||
bool digitaleAusgabe0(uint8_t);
|
||||
|
|
BIN
drv/b15f.o
BIN
drv/b15f.o
Binary file not shown.
84
drv/plottyfile.cpp
Normal file
84
drv/plottyfile.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include "plottyfile.h"
|
||||
|
||||
void PlottyFile::prepStr(std::string& str, uint8_t len)
|
||||
{
|
||||
if(str.length() > len)
|
||||
throw std::runtime_error("Zu grosser String.");
|
||||
|
||||
if(str.length() != len)
|
||||
str += '\n';
|
||||
|
||||
while(str.length() < len)
|
||||
str += '\0';
|
||||
}
|
||||
|
||||
void PlottyFile::writeToFile(std::string filename)
|
||||
{
|
||||
|
||||
command = 0x1D;
|
||||
title = "HTWK-HWLab";
|
||||
filetype = "MD";
|
||||
version = 1;
|
||||
subversion = 0;
|
||||
function_type = 'C';
|
||||
quadrant = 1;
|
||||
ref_x = 5000;
|
||||
ref_y = 50;
|
||||
para_first = 1;
|
||||
para_stepwidth = 1;
|
||||
unit_x = "Unit X";
|
||||
desc_x = "Desc X";
|
||||
unit_y = "Unit Y";
|
||||
desc_y = "Desc Y";
|
||||
unit_para = "Unit P";
|
||||
desc_para = "Desc P";
|
||||
|
||||
prepStr(title, 10);
|
||||
prepStr(unit_x, 10);
|
||||
prepStr(desc_x, 20);
|
||||
prepStr(unit_y, 10);
|
||||
prepStr(desc_y, 20);
|
||||
prepStr(unit_para, 10);
|
||||
prepStr(desc_para, 20);
|
||||
|
||||
std::ofstream file(filename);
|
||||
file.write(reinterpret_cast<char*>(&command), 1);
|
||||
file.write(title.c_str(), title.length());
|
||||
file.write(filetype.c_str(), 2);
|
||||
file.write(reinterpret_cast<char*>(&version), 2);
|
||||
file.write(reinterpret_cast<char*>(&subversion), 2);
|
||||
file.write(reinterpret_cast<char*>(&function_type), 1);
|
||||
file.write(reinterpret_cast<char*>(&quadrant), 1);
|
||||
file.write(reinterpret_cast<char*>(&ref_x), 2);
|
||||
file.write(reinterpret_cast<char*>(&ref_y), 2);
|
||||
file.write(reinterpret_cast<char*>(¶_first), 2);
|
||||
file.write(reinterpret_cast<char*>(¶_stepwidth), 2);
|
||||
file.write(unit_x.c_str(), unit_x.length());
|
||||
file.write(desc_x.c_str(), desc_x.length());
|
||||
file.write(unit_y.c_str(), unit_y.length());
|
||||
file.write(desc_y.c_str(), desc_y.length());
|
||||
file.write(unit_para.c_str(), unit_para.length());
|
||||
file.write(desc_para.c_str(), desc_para.length());
|
||||
file.write(reinterpret_cast<const char*>(&eof), 1);
|
||||
|
||||
while(file.tellp() < 256)
|
||||
file.put(0);
|
||||
|
||||
for(uint16_t i = 0; i < 1023; i++)
|
||||
{
|
||||
file.put(i >> 8);
|
||||
file.put(i & 0xFF);
|
||||
file.put(1);
|
||||
file.put(0);
|
||||
}
|
||||
|
||||
for(uint16_t i = 0; i < 1023; i++)
|
||||
{
|
||||
file.put((i >> 8) | 128);
|
||||
file.put(i & 0xFF);
|
||||
file.put(2);
|
||||
file.put(0);
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
35
drv/plottyfile.h
Normal file
35
drv/plottyfile.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef PLOTTYFILE_H
|
||||
#define PLOTTYFILE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
|
||||
class PlottyFile
|
||||
{
|
||||
public:
|
||||
void writeToFile(std::string filename);
|
||||
private:
|
||||
void prepStr(std::string& str, uint8_t len);
|
||||
|
||||
int8_t command;
|
||||
std::string title;
|
||||
std::string filetype;
|
||||
int16_t version;
|
||||
int16_t subversion;
|
||||
uint8_t function_type;
|
||||
uint8_t quadrant;
|
||||
uint16_t ref_x;
|
||||
uint16_t ref_y;
|
||||
uint16_t para_first;
|
||||
uint16_t para_stepwidth;
|
||||
std::string unit_x;
|
||||
std::string desc_x;
|
||||
std::string unit_y;
|
||||
std::string desc_y;
|
||||
std::string unit_para;
|
||||
std::string desc_para;
|
||||
const uint8_t eof = 0xD;
|
||||
};
|
||||
|
||||
#endif // PLOTTYFILE_H
|
BIN
drv/plottyfile.o
Normal file
BIN
drv/plottyfile.o
Normal file
Binary file not shown.
|
@ -2,24 +2,13 @@ set margin 10,10
|
|||
unset key
|
||||
set grid
|
||||
set title ''
|
||||
set xlabel 'UDrain [mV]'
|
||||
set ylabel 'IDrain [mA]'
|
||||
set xlabel 'Desc X [Unit X]'
|
||||
set ylabel 'Desc Y [Unit Y]'
|
||||
set xrange [0:5000]
|
||||
set yrange [0:50]
|
||||
set label at 2785,31 'UGS [Digit ] = 125' left
|
||||
set label at 2663,28 'UGS [Digit ] = 150' left
|
||||
set label at 2614,25 'UGS [Digit ] = 175' left
|
||||
set label at 2541,18 'UGS [Digit ] = 200' left
|
||||
set label at 2565,21 'UGS [Digit ] = 225' left
|
||||
set label at 2468,13 'UGS [Digit ] = 250' left
|
||||
set label at 2492,15 'UGS [Digit ] = 275' left
|
||||
set label at 2443,11 'UGS [Digit ] = 300' left
|
||||
set label at 2443,11 'UGS [Digit ] = 325' left
|
||||
set label at 2394,8 'UGS [Digit ] = 350' left
|
||||
set label at 2297,4 'UGS [Digit ] = 375' left
|
||||
set label at 2297,4 'UGS [Digit ] = 400' left
|
||||
set label at 2297,4 'UGS [Digit ] = 400' left
|
||||
set label at 4995,12 'Desc P [Unit P] = 1' left
|
||||
set label at 4995,25 'Desc P [Unit P] = 2' left
|
||||
unset output
|
||||
set terminal qt
|
||||
unset output
|
||||
plot "/tmp/tempfile0" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 100' w l,"/tmp/tempfile1" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 125' w l,"/tmp/tempfile2" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 150' w l,"/tmp/tempfile3" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 175' w l,"/tmp/tempfile4" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 200' w l,"/tmp/tempfile5" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 225' w l,"/tmp/tempfile6" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 250' w l,"/tmp/tempfile7" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 275' w l,"/tmp/tempfile8" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 300' w l,"/tmp/tempfile9" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 325' w l,"/tmp/tempfile10" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 350' w l,"/tmp/tempfile11" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 375' w l,"/tmp/tempfile12" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 400' w l,"/tmp/tempfile13" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'UGS [Digit ] = 425' w l
|
||||
plot "/tmp/tempfile0" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'Desc P [Unit P] = 1' w l,"/tmp/tempfile32" using ($1*4.887586):($2*0.048876) binary format="%int16%int16" endian=big title 'Desc P [Unit P] = 2' w l
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include <iostream>
|
||||
#include "drv/b15f.h"
|
||||
#include "drv/plottyfile.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -21,7 +22,10 @@ int main()
|
|||
uint16_t bb[1024];
|
||||
drv.analogEingabeSequenz(1, &ba[0], 0, 0, &bb[0], 0, 1023, -1, 1023);
|
||||
|
||||
system("./plotty --in graph");
|
||||
PlottyFile pf;
|
||||
pf.writeToFile("test_plot");
|
||||
|
||||
system("./plotty --in test_plot");
|
||||
|
||||
std::cout << "Schluss." << std::endl;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue