diff --git a/Makefile b/Makefile index d84f459..d0bc5e0 100644 --- a/Makefile +++ b/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) diff --git a/drv/b15f.cpp b/drv/b15f.cpp index 46a0fa0..71bfcbf 100644 --- a/drv/b15f.cpp +++ b/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 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 B15F::getBoardInfo(void) +{ + try + { + std::vector info; + + writeByte(RQ_INFO); + uint8_t n = readByte(); + while(n--) + { + uint8_t len = readByte(); + std::string str; + + while(len--) + str += static_cast(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) { diff --git a/drv/b15f.h b/drv/b15f.h index 65d0c53..1d9d3ad 100644 --- a/drv/b15f.h +++ b/drv/b15f.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,7 @@ public: void discard(void); bool testConnection(void); bool testIntConv(void); + std::vector getBoardInfo(void); // Board Befehle bool digitaleAusgabe0(uint8_t); diff --git a/drv/b15f.o b/drv/b15f.o index fe7f7dd..2af3163 100644 Binary files a/drv/b15f.o and b/drv/b15f.o differ diff --git a/drv/plottyfile.cpp b/drv/plottyfile.cpp new file mode 100644 index 0000000..380e8cc --- /dev/null +++ b/drv/plottyfile.cpp @@ -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(&command), 1); + file.write(title.c_str(), title.length()); + file.write(filetype.c_str(), 2); + file.write(reinterpret_cast(&version), 2); + file.write(reinterpret_cast(&subversion), 2); + file.write(reinterpret_cast(&function_type), 1); + file.write(reinterpret_cast(&quadrant), 1); + file.write(reinterpret_cast(&ref_x), 2); + file.write(reinterpret_cast(&ref_y), 2); + file.write(reinterpret_cast(¶_first), 2); + file.write(reinterpret_cast(¶_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(&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(); +} diff --git a/drv/plottyfile.h b/drv/plottyfile.h new file mode 100644 index 0000000..bae5ed6 --- /dev/null +++ b/drv/plottyfile.h @@ -0,0 +1,35 @@ +#ifndef PLOTTYFILE_H +#define PLOTTYFILE_H + +#include +#include +#include + +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 diff --git a/drv/plottyfile.o b/drv/plottyfile.o new file mode 100644 index 0000000..caa1ba7 Binary files /dev/null and b/drv/plottyfile.o differ diff --git a/gnuplotscript.gp b/gnuplotscript.gp index 8f3b0d1..5fccc88 100644 --- a/gnuplotscript.gp +++ b/gnuplotscript.gp @@ -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 diff --git a/main b/main index 1b8f4ad..38a175e 100755 Binary files a/main and b/main differ diff --git a/main.cpp b/main.cpp index f14fd10..b1a36b2 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #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; } diff --git a/main.o b/main.o index b3c3644..c773a0e 100644 Binary files a/main.o and b/main.o differ diff --git a/test_plot b/test_plot new file mode 100644 index 0000000..4190e63 Binary files /dev/null and b/test_plot differ