diff --git a/control/bin/b15fcli b/control/bin/b15fcli deleted file mode 100755 index 864a09c..0000000 Binary files a/control/bin/b15fcli and /dev/null differ diff --git a/control/examples/pegel/main.cpp b/control/examples/pegel/main.cpp index 2487217..b2624fd 100644 --- a/control/examples/pegel/main.cpp +++ b/control/examples/pegel/main.cpp @@ -13,8 +13,9 @@ int main() uint16_t buf[1024]; - const uint16_t sample_count = 1024; + const uint16_t count = 1024; const uint16_t delta = 1; + const uint16_t start = 0; pf.setUnitX("V"); pf.setUnitY("V"); @@ -27,18 +28,17 @@ int main() pf.setParaFirstCurve(0); pf.setParaStepWidth(0); - uint8_t curve = 0; - + const uint8_t curve = 0; - drv.analogSequence(0, &buf[0], 0, 1, nullptr, 0, 0, delta, sample_count); + drv.analogSequence(0, &buf[0], 0, 1, nullptr, 0, start, delta, count); - for(uint16_t x = 0; x < sample_count * delta; x += delta) + for(uint16_t x = 0; x < count; x++) { std::cout << x << " - " << buf[x] << std::endl; pf.addDot(Dot(x, buf[x], curve)); } // speichern und plotty starten - pf.writeToFile(PLOT_FILE); + pf.writeToFile(PLOT_FILE); pf.startPlotty(PLOT_FILE); } diff --git a/control/src/Makefile b/control/src/Makefile index 0011e50..cd10e0f 100644 --- a/control/src/Makefile +++ b/control/src/Makefile @@ -38,7 +38,7 @@ OBJECTS_CLI = cli.o ui/view.o ui/view_selection.o ui/view_promt.o ui/view_info # *** TARGETS *** -all: drv cli doc +all: drv cli style doc drv: $(OBJECTS_DRV) $(OUT_TMP_DRV) @@ -50,8 +50,13 @@ cli: drv $(OBJECTS_CLI) @bash -c 'if [ ! -f "$(OUT_DRV)" ]; then echo -e "\n*** Warning ***: driver not installed\nType \"sudo make install\" to install or update b15fdrv."; fi' doc: - @echo "Creating documentation with doxygen.." + @echo "Creating documentation with doxygen..." $(PATH_DOXYGEN) doxygen-cfg + @echo problems found: `($(PATH_DOXYGEN) doxygen-cfg 3>&2 2>&1 1>&3) 2>/dev/null | wc -l` + +style: + @echo "Formatting source code with astyle..." + astyle --recursive --style=allman *.cpp,*.h,*.c,*.hpp install: @echo "Installing driver..." @@ -78,6 +83,7 @@ clean: @echo "Cleaning..." rm -f $(OBJECTS_DRV) $(OBJECTS_CLI) $(OUT_TMP_CLI) $(OUT_TMP_DRV) rm -rf $(OUT_DOC) + find . -type f -name '*.orig' -delete .cpp.o: $(PATH_COMPILER) $(CFLAGS) -c $< -o $@ diff --git a/control/src/cli.cpp b/control/src/cli.cpp index aa57de7..5f76d3c 100644 --- a/control/src/cli.cpp +++ b/control/src/cli.cpp @@ -24,91 +24,92 @@ volatile bool t_refresh_active = false; void signal_handler(int signal) { - if(signal == SIGWINCH) - { - win_changed_cooldown = 10; // 100ms - - if (!t_refresh_active) - { - if(t_refresh.joinable()) - t_refresh.join(); - t_refresh_active = true; - t_refresh = std::thread([](){ - - while(win_changed_cooldown--) - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - - t_refresh_active = false; - - if(win_stack.size()) - win_stack.back()->repaint(); - - }); - } - - } - else if(signal == SIGINT) - { - cleanup(); - std::cout << "SIGINT - Abbruch." << std::endl; - exit(EXIT_FAILURE); - } + if(signal == SIGWINCH) + { + win_changed_cooldown = 10; // 100ms + + if (!t_refresh_active) + { + if(t_refresh.joinable()) + t_refresh.join(); + t_refresh_active = true; + t_refresh = std::thread([]() + { + + while(win_changed_cooldown--) + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + t_refresh_active = false; + + if(win_stack.size()) + win_stack.back()->repaint(); + + }); + } + + } + else if(signal == SIGINT) + { + cleanup(); + std::cout << "SIGINT - Abbruch." << std::endl; + exit(EXIT_FAILURE); + } } void abort_handler(std::exception& ex) { - ViewInfo* view = new ViewInfo(); - view->setTitle("Fehler"); - std::string msg(ex.what()); - msg += "\n\nBeende in 5 Sekunden."; - view->setText(msg.c_str()); - view->setLabelClose(""); - view->repaint(); - - std::this_thread::sleep_for(std::chrono::milliseconds(5000)); - - cleanup(); - std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl; - exit(EXIT_FAILURE); + ViewInfo* view = new ViewInfo(); + view->setTitle("Fehler"); + std::string msg(ex.what()); + msg += "\n\nBeende in 5 Sekunden."; + view->setText(msg.c_str()); + view->setLabelClose(""); + view->repaint(); + + std::this_thread::sleep_for(std::chrono::milliseconds(5000)); + + cleanup(); + std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl; + exit(EXIT_FAILURE); } void init() { - // init b15 driver - B15F::getInstance(); + // init b15 driver + B15F::getInstance(); #ifndef B15F_CLI_DEBUG - std::cout << std::endl << "Starte in 3s ..." << std::endl; - sleep(3); + std::cout << std::endl << "Starte in 3s ..." << std::endl; + sleep(3); #endif - B15F::setAbortHandler(&abort_handler); - - // init all ncurses stuff - initscr(); - start_color(); - curs_set(0); // 0: invisible, 1: normal, 2: very visible - clear(); - noecho(); - cbreak(); // Line buffering disabled. pass on everything - mousemask(ALL_MOUSE_EVENTS, NULL); - - // connect signals to handler - signal(SIGWINCH, signal_handler); - signal(SIGINT, signal_handler); - - // set view context - View::setWinContext(newwin(25, 85, 0, 0)); + B15F::setAbortHandler(&abort_handler); + + // init all ncurses stuff + initscr(); + start_color(); + curs_set(0); // 0: invisible, 1: normal, 2: very visible + clear(); + noecho(); + cbreak(); // Line buffering disabled. pass on everything + mousemask(ALL_MOUSE_EVENTS, NULL); + + // connect signals to handler + signal(SIGWINCH, signal_handler); + signal(SIGINT, signal_handler); + + // set view context + View::setWinContext(newwin(25, 85, 0, 0)); } int main() { - init(); - - int exit_code = EXIT_SUCCESS; - - show_main(0); - - cleanup(); - - return exit_code; + init(); + + int exit_code = EXIT_SUCCESS; + + show_main(0); + + cleanup(); + + return exit_code; } diff --git a/control/src/doxygen-cfg b/control/src/doxygen-cfg index 7093299..a4533e1 100644 --- a/control/src/doxygen-cfg +++ b/control/src/doxygen-cfg @@ -1260,7 +1260,7 @@ HTML_COLORSTYLE_GAMMA = 80 # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_TIMESTAMP = NO +HTML_TIMESTAMP = YES # If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML # documentation will contain a main index with vertical navigation menus that @@ -1279,7 +1279,7 @@ HTML_DYNAMIC_MENUS = YES # The default value is: NO. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_DYNAMIC_SECTIONS = NO +HTML_DYNAMIC_SECTIONS = YES # With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries # shown in the various tree structured indices initially; the user can expand diff --git a/control/src/drv/b15f.cpp b/control/src/drv/b15f.cpp index 17114b6..0204cc6 100644 --- a/control/src/drv/b15f.cpp +++ b/control/src/drv/b15f.cpp @@ -5,315 +5,320 @@ errorhandler_t B15F::errorhandler = nullptr; B15F::B15F() { - init(); + init(); } void B15F::init() { - - std::string device = exec("bash -c 'ls /dev/ttyUSB*'"); - while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos) - device.pop_back(); - - if(device.length() == 0) - abort("Adapter nicht gefunden"); - - std::cout << PRE << "Verwende Adapter: " << device << std::endl; - - - - std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush; - usart.setBaudrate(BAUDRATE); - usart.openDevice(device); - std::cout << "OK" << std::endl; - - - std::cout << PRE << "Teste Verbindung... " << std::flush; - uint8_t tries = 3; - while(tries--) - { - // verwerfe Daten, die µC noch hat - //discard(); - - if(!testConnection()) - continue; - - if(!testIntConv()) - continue; - - break; - } - if(tries == 0) - abort("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; + std::string device = exec("bash -c 'ls /dev/ttyUSB*'"); + while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos) + device.pop_back(); + + if(device.length() == 0) + abort("Adapter nicht gefunden"); + + std::cout << PRE << "Verwende Adapter: " << device << std::endl; + + + + std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush; + usart.setBaudrate(BAUDRATE); + usart.openDevice(device); + std::cout << "OK" << std::endl; + + + + std::cout << PRE << "Teste Verbindung... " << std::flush; + uint8_t tries = 3; + while(tries--) + { + // verwerfe Daten, die µC noch hat + //discard(); + + if(!testConnection()) + continue; + + if(!testIntConv()) + continue; + + break; + } + if(tries == 0) + abort("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; } void B15F::reconnect() { - uint8_t tries = RECONNECT_TRIES; - while(tries--) - { - delay_ms(RECONNECT_TIMEOUT); - discard(); - - if(testConnection()) - return; - } - - abort("Verbindung kann nicht repariert werden"); + uint8_t tries = RECONNECT_TRIES; + while(tries--) + { + delay_ms(RECONNECT_TIMEOUT); + discard(); + + if(testConnection()) + return; + } + + abort("Verbindung kann nicht repariert werden"); } void B15F::discard(void) { - try - { - usart.clearOutputBuffer(); - for(uint8_t i = 0; i < 16; i++) - { - usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input) - delay_ms(4); - } - usart.clearInputBuffer(); - } - catch(std::exception& ex) - { - abort(ex); - } + try + { + usart.clearOutputBuffer(); + for(uint8_t i = 0; i < 16; i++) + { + usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input) + delay_ms(4); + } + usart.clearInputBuffer(); + } + catch(std::exception& ex) + { + abort(ex); + } } bool B15F::testConnection() { - // erzeuge zufälliges Byte - srand(time(NULL)); - uint8_t dummy = rand() % 256; - - usart.writeByte(RQ_TEST); - usart.writeByte(dummy); - - uint8_t aw = usart.readByte(); - uint8_t mirror = usart.readByte(); - - return aw == MSG_OK && mirror == dummy; + // erzeuge zufälliges Byte + srand(time(NULL)); + uint8_t dummy = rand() % 256; + + usart.writeByte(RQ_TEST); + usart.writeByte(dummy); + + uint8_t aw = usart.readByte(); + uint8_t mirror = usart.readByte(); + + return aw == MSG_OK && mirror == dummy; } bool B15F::testIntConv() { - srand(time(NULL)); - uint16_t dummy = rand() % (0xFFFF / 3); - - usart.writeByte(RQ_INT); - usart.writeInt(dummy); - - uint16_t aw = usart.readInt(); - return aw == dummy * 3; + srand(time(NULL)); + uint16_t dummy = rand() % (0xFFFF / 3); + + usart.writeByte(RQ_INT); + usart.writeInt(dummy); + + uint16_t aw = usart.readInt(); + return aw == dummy * 3; } std::vector B15F::getBoardInfo(void) { - std::vector info; - - usart.writeByte(RQ_INFO); - - uint8_t n = usart.readByte(); - while(n--) - { - uint8_t len = usart.readByte(); - std::string str; - - while(len--) { - str += static_cast(usart.readByte()); - } - - info.push_back(str); - } - - uint8_t aw = usart.readByte(); - if(aw != MSG_OK) - abort("Board Info fehlerhalft: code " + std::to_string((int) aw)); - - return info; + std::vector info; + + usart.writeByte(RQ_INFO); + + uint8_t n = usart.readByte(); + while(n--) + { + uint8_t len = usart.readByte(); + std::string str; + + while(len--) + { + str += static_cast(usart.readByte()); + } + + info.push_back(str); + } + + uint8_t aw = usart.readByte(); + if(aw != MSG_OK) + abort("Board Info fehlerhalft: code " + std::to_string((int) aw)); + + return info; } bool B15F::activateSelfTestMode() { - usart.writeByte(RQ_ST); - - uint8_t aw = usart.readByte(); - return aw == MSG_OK; + usart.writeByte(RQ_ST); + + uint8_t aw = usart.readByte(); + return aw == MSG_OK; } bool B15F::digitalWrite0(uint8_t port) { - usart.writeByte(RQ_BA0); - usart.writeByte(port); - - uint8_t aw = usart.readByte(); - delay_us(10); - return aw == MSG_OK; + usart.writeByte(RQ_BA0); + usart.writeByte(port); + + uint8_t aw = usart.readByte(); + delay_us(10); + return aw == MSG_OK; } bool B15F::digitalWrite1(uint8_t port) { - usart.writeByte(RQ_BA1); - usart.writeByte(port); - - uint8_t aw = usart.readByte(); - delay_us(10); - return aw == MSG_OK; + usart.writeByte(RQ_BA1); + usart.writeByte(port); + + uint8_t aw = usart.readByte(); + delay_us(10); + return aw == MSG_OK; } uint8_t B15F::digitalRead0() { - usart.clearInputBuffer(); - usart.writeByte(RQ_BE0); - uint8_t byte = usart.readByte(); - delay_us(10); - return byte; + usart.clearInputBuffer(); + usart.writeByte(RQ_BE0); + uint8_t byte = usart.readByte(); + delay_us(10); + return byte; } uint8_t B15F::digitalRead1() { - usart.clearInputBuffer(); - usart.writeByte(RQ_BE1); - uint8_t byte = usart.readByte(); - delay_us(10); - return byte; + usart.clearInputBuffer(); + usart.writeByte(RQ_BE1); + uint8_t byte = usart.readByte(); + delay_us(10); + return byte; } uint8_t B15F::readDipSwitch() { - usart.clearInputBuffer(); - usart.writeByte(RQ_DSW); - uint8_t byte = usart.readByte(); - delay_us(10); - return byte; + usart.clearInputBuffer(); + usart.writeByte(RQ_DSW); + uint8_t byte = usart.readByte(); + delay_us(10); + return byte; } bool B15F::analogWrite0(uint16_t value) { - usart.writeByte(RQ_AA0); - usart.writeInt(value); - - uint8_t aw = usart.readByte(); - delay_us(10); - return aw == MSG_OK; + usart.writeByte(RQ_AA0); + usart.writeInt(value); + + uint8_t aw = usart.readByte(); + delay_us(10); + return aw == MSG_OK; } bool B15F::analogWrite1(uint16_t value) { - usart.writeByte(RQ_AA1); - usart.writeInt(value); - - uint8_t aw = usart.readByte(); - delay_us(10); - return aw == MSG_OK; + usart.writeByte(RQ_AA1); + usart.writeInt(value); + + uint8_t aw = usart.readByte(); + delay_us(10); + return aw == MSG_OK; } uint16_t B15F::analogRead(uint8_t channel) { - usart.clearInputBuffer(); - if(channel > 7) - abort("Bad ADC channel: " + std::to_string(channel)); - - uint8_t rq[] = { - RQ_ADC, - channel - }; - - int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000); - if(n_sent != sizeof(rq)) - abort("Sent failed"); - - uint16_t adc = usart.readInt(); - - if(adc > 1023) - abort("Bad ADC data detected (1)"); - return adc; + usart.clearInputBuffer(); + if(channel > 7) + abort("Bad ADC channel: " + std::to_string(channel)); + + uint8_t rq[] = + { + RQ_ADC, + channel + }; + + int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000); + if(n_sent != sizeof(rq)) + abort("Sent failed"); + + uint16_t adc = usart.readInt(); + + if(adc > 1023) + abort("Bad ADC data detected (1)"); + return adc; } void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count) { - // check pointers - buffer_a += offset_a; - buffer_b += offset_b; - - - usart.clearInputBuffer(); - usart.writeByte(RQ_ADC_DAC_STROKE); - usart.writeByte(channel_a); - usart.writeByte(channel_b); - usart.writeInt(start); - usart.writeInt(static_cast(delta)); - usart.writeInt(count); - - for(uint16_t i = 0; i < count; i++) - { - if(buffer_a) - { - buffer_a[i] = usart.readInt(); - - if(buffer_a[i] > 1023) // check for broken usart connection - abort("Bad ADC data detected (2)"); - } - else - { - usart.readInt(); - } - - if(buffer_b) - { - buffer_b[i] = usart.readInt(); - - if(buffer_b[i] > 1023) // check for broken usart connection - abort("Bad ADC data detected (3)"); - } - else - { - usart.readInt(); - } - } - - uint8_t aw = usart.readByte(); - if(aw != MSG_OK) - abort("Sequenz unterbrochen"); - - delay_us(10); + // check pointers + buffer_a += offset_a; + buffer_b += offset_b; + + + usart.clearInputBuffer(); + usart.writeByte(RQ_ADC_DAC_STROKE); + usart.writeByte(channel_a); + usart.writeByte(channel_b); + usart.writeInt(start); + usart.writeInt(static_cast(delta)); + usart.writeInt(count); + + for(uint16_t i = 0; i < count; i++) + { + if(buffer_a) + { + buffer_a[i] = usart.readInt(); + + if(buffer_a[i] > 1023) // check for broken usart connection + abort("Bad ADC data detected (2)"); + } + else + { + usart.readInt(); + } + + if(buffer_b) + { + buffer_b[i] = usart.readInt(); + + if(buffer_b[i] > 1023) // check for broken usart connection + abort("Bad ADC data detected (3)"); + } + else + { + usart.readInt(); + } + } + + uint8_t aw = usart.readByte(); + if(aw != MSG_OK) + abort("Sequenz unterbrochen"); + + delay_us(10); } void B15F::delay_ms(uint16_t ms) { - std::this_thread::sleep_for(std::chrono::milliseconds(ms)); + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); } void B15F::delay_us(uint16_t us) { - std::this_thread::sleep_for(std::chrono::microseconds(us)); + std::this_thread::sleep_for(std::chrono::microseconds(us)); } - + B15F& B15F::getInstance(void) { - if(!instance) - instance = new B15F(); + if(!instance) + instance = new B15F(); - return *instance; + return *instance; } // https://stackoverflow.com/a/478960 -std::string B15F::exec(std::string cmd) { +std::string B15F::exec(std::string cmd) +{ std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd.c_str(), "r"), pclose); - if (!pipe) { + if (!pipe) + { throw std::runtime_error("popen() failed!"); } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) + { result += buffer.data(); } return result; @@ -321,22 +326,22 @@ std::string B15F::exec(std::string cmd) { void B15F::abort(std::string msg) { - DriverException ex(msg); - abort(ex); + DriverException ex(msg); + abort(ex); } void B15F::abort(std::exception& ex) { - if(errorhandler) - errorhandler(ex); - else - { - std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl; - std::cout << ex.what() << std::endl; - throw DriverException(ex.what()); - } + if(errorhandler) + errorhandler(ex); + else + { + std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl; + std::cout << ex.what() << std::endl; + throw DriverException(ex.what()); + } } void B15F::setAbortHandler(errorhandler_t func) { - errorhandler = func; + errorhandler = func; } diff --git a/control/src/drv/b15f.h b/control/src/drv/b15f.h index dc06e43..88172ba 100644 --- a/control/src/drv/b15f.h +++ b/control/src/drv/b15f.h @@ -21,216 +21,218 @@ typedef std::function errorhandler_t; +/*! main driver class */ + class B15F { private: - // privater Konstruktor - B15F(void); + // privater Konstruktor + B15F(void); public: - - /************************************* - * Grundfunktionen des B15F Treibers * - *************************************/ - - /** - * Versucht die Verbindung zum B15 wiederherzustellen - * \throws DriverException - */ - void reconnect(void); - - /** - * Verwirft Daten im USART Puffer auf dieser Maschine und B15 - * \throws DriverException - */ - void discard(void); - - /** - * Testet die USART Verbindung auf Funktion - * \throws DriverException - */ - bool testConnection(void); - - /** - * Testet die Integer Konvertierung der USART Verbindung - * \throws DriverException - */ - bool testIntConv(void); - - /** - * Liefert Informationen zur aktuellen Firmware des B15 - * \throws DriverException - */ - std::vector getBoardInfo(void); - - /** - * Lässt den Treiber für eine angegebene Zeit pausieren - * \param ms Verzögerung in Millisekunden - */ - void delay_ms(uint16_t ms); - - /** - * Lässt den Treiber für eine angegebene Zeit pausieren - * \param us Verzögerung in Microsekunden - */ - void delay_us(uint16_t us); - - /** - * Liefert eine Referenz zur aktuellen Treiber-Instanz - * @throws DriverException - */ - static B15F& getInstance(void); - - /** - * Führt ein Befehl auf dieser Maschine aus und liefert stdout zurück - * \param cmd Der Befehl - */ - static std::string exec(std::string cmd); - /** - * Multithread sicherer Abbruch des B15F-Treibers - * \param msg Beschreibung der Abbruchursache - */ - static void abort(std::string msg); + /************************************* + * Grundfunktionen des B15F Treibers * + *************************************/ - /** - * Multithread sicherer Abbruch des B15F-Treibers - * \param ex Exception als Abbruchursache - */ - static void abort(std::exception& ex); + /** + * Versucht die Verbindung zum B15 wiederherzustellen + * \throws DriverException + */ + void reconnect(void); - /** - * Setzt eine Fehlerbehandlungsroutine für den Treiberabbruch (abort) - * \param func Funktion, die Exception als Parameter bekommt - */ - static void setAbortHandler(errorhandler_t func); + /** + * Verwirft Daten im USART Puffer auf dieser Maschine und B15 + * \throws DriverException + */ + void discard(void); - /*************************************/ - - - - /************************* - * Steuerbefehle für B15 * - *************************/ - - /** - * Versetzt das Board in den Selbsttest-Modus - * WICHTIG: Es darf dabei nichts an den Klemmen angeschlossen sein! - * \throws DriverException - */ - bool activateSelfTestMode(void); - - /** - * Setzt den Wert des digitalen Ausgabeports 0 - * \param port Wert für gesamten Port - * \throws DriverException - */ - bool digitalWrite0(uint8_t); - - /** - * Setzt den Wert des digitalen Ausgabeports 1 - * \param port Wert für gesamten Port - * \throws DriverException - */ - bool digitalWrite1(uint8_t); - - /** - * Liest den Wert des digitalen Eingabeports 0 - * \return Wert für gesamten Port - * \throws DriverException - */ - uint8_t digitalRead0(void); - - /** - * Liest den Wert des digitalen Eingabeports 1 - * \return Wert für gesamten Port - * \throws DriverException - */ - uint8_t digitalRead1(void); - - /** - * Liest den Wert des digitalen Eingabeports, an dem der DIP-switch angeschlossen ist (S7) - * \return Wert für gesamten Port - * \throws DriverException - */ - uint8_t readDipSwitch(void); - - /** - * Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 0 - * \param port 10-Bit Wert - * \throws DriverException - */ - bool analogWrite0(uint16_t); - - /** - * Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 1 - * \param port 10-Bit Wert - * \throws DriverException - */ - bool analogWrite1(uint16_t); - - /** - * Liest den Wert des Analog-Digital-Converters (ADC / ADU) - * \param channel Kanalwahl von 0 - 7 - * \throws DriverException - */ - uint16_t analogRead(uint8_t channel); - - /** - * DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkrementiert. - * Für jeden eingestelleten DAC-Wert werden zwei ADCs (channel_a und channel_b) angesprochen und die Werte übermittelt. - * Die Werte werden in buffer_a für Kanal a und buffer_b für Kanal b gespeichert. - * \param channel_a Auswahl des ADC a, von 0 - 7 - * \param buffer_a Speichertort für Werte des Kanals a - * \param offset_a Anzahl an Werten des Kanals a, die im Speicher übersprungen werden sollen - * \param channel_b Auswahl des ADC b, von 0 - 7 - * \param buffer_b Speichertort für Werte des Kanals b - * \param offset_b Anzahl an Werten des Kanals b, die im Speicher übersprungen werden - * \param start Startwert des DACs - * \param delta Schrittweite, mit welcher der DAC inkrementiert wird - * \param count Anzahl an Inkrementierungen - * \throws DriverException - */ - void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count); - - /*************************/ + /** + * Testet die USART Verbindung auf Funktion + * \throws DriverException + */ + bool testConnection(void); + + /** + * Testet die Integer Konvertierung der USART Verbindung + * \throws DriverException + */ + bool testIntConv(void); + + /** + * Liefert Informationen zur aktuellen Firmware des B15 + * \throws DriverException + */ + std::vector getBoardInfo(void); + + /** + * Lässt den Treiber für eine angegebene Zeit pausieren + * \param ms Verzögerung in Millisekunden + */ + void delay_ms(uint16_t ms); + + /** + * Lässt den Treiber für eine angegebene Zeit pausieren + * \param us Verzögerung in Microsekunden + */ + void delay_us(uint16_t us); + + /** + * Liefert eine Referenz zur aktuellen Treiber-Instanz + * @throws DriverException + */ + static B15F& getInstance(void); + + /** + * Führt ein Befehl auf dieser Maschine aus und liefert stdout zurück + * \param cmd Der Befehl + */ + static std::string exec(std::string cmd); + + /** + * Multithread sicherer Abbruch des B15F-Treibers + * \param msg Beschreibung der Abbruchursache + */ + static void abort(std::string msg); + + /** + * Multithread sicherer Abbruch des B15F-Treibers + * \param ex Exception als Abbruchursache + */ + static void abort(std::exception& ex); + + /** + * Setzt eine Fehlerbehandlungsroutine für den Treiberabbruch (abort) + * \param func Funktion, die Exception als Parameter bekommt + */ + static void setAbortHandler(errorhandler_t func); + + /*************************************/ - // CONSTANTS - const std::string PRE = "[B15F] "; - constexpr static uint8_t MSG_OK = 0xFF; - constexpr static uint8_t MSG_FAIL = 0xFE; - constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms - constexpr static uint16_t WDT_TIMEOUT = 15; // ms - constexpr static uint8_t RECONNECT_TRIES = 3; - constexpr static uint32_t BAUDRATE = 57600; + + /************************* + * Steuerbefehle für B15 * + *************************/ + + /** + * Versetzt das Board in den Selbsttest-Modus + * WICHTIG: Es darf dabei nichts an den Klemmen angeschlossen sein! + * \throws DriverException + */ + bool activateSelfTestMode(void); + + /** + * Setzt den Wert des digitalen Ausgabeports 0 + * \param port Wert für gesamten Port + * \throws DriverException + */ + bool digitalWrite0(uint8_t); + + /** + * Setzt den Wert des digitalen Ausgabeports 1 + * \param port Wert für gesamten Port + * \throws DriverException + */ + bool digitalWrite1(uint8_t); + + /** + * Liest den Wert des digitalen Eingabeports 0 + * \return Wert für gesamten Port + * \throws DriverException + */ + uint8_t digitalRead0(void); + + /** + * Liest den Wert des digitalen Eingabeports 1 + * \return Wert für gesamten Port + * \throws DriverException + */ + uint8_t digitalRead1(void); + + /** + * Liest den Wert des digitalen Eingabeports, an dem der DIP-switch angeschlossen ist (S7) + * \return Wert für gesamten Port + * \throws DriverException + */ + uint8_t readDipSwitch(void); + + /** + * Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 0 + * \param port 10-Bit Wert + * \throws DriverException + */ + bool analogWrite0(uint16_t port); + + /** + * Setzt den Wert des Digital-Analog-Converters (DAC / DAU) 1 + * \param port 10-Bit Wert + * \throws DriverException + */ + bool analogWrite1(uint16_t port); + + /** + * Liest den Wert des Analog-Digital-Converters (ADC / ADU) + * \param channel Kanalwahl von 0 - 7 + * \throws DriverException + */ + uint16_t analogRead(uint8_t channel); + + /** + * DAC 0 wird auf den Startwert gesetzt und dann schrittweise um Delta inkrementiert. + * Für jeden eingestelleten DAC-Wert werden zwei ADCs (channel_a und channel_b) angesprochen und die Werte übermittelt. + * Die Werte werden in buffer_a für Kanal a und buffer_b für Kanal b gespeichert. + * \param channel_a Auswahl des ADC a, von 0 - 7 + * \param buffer_a Speichertort für Werte des Kanals a + * \param offset_a Anzahl an Werten des Kanals a, die im Speicher übersprungen werden sollen + * \param channel_b Auswahl des ADC b, von 0 - 7 + * \param buffer_b Speichertort für Werte des Kanals b + * \param offset_b Anzahl an Werten des Kanals b, die im Speicher übersprungen werden + * \param start Startwert des DACs + * \param delta Schrittweite, mit welcher der DAC inkrementiert wird + * \param count Anzahl an Inkrementierungen + * \throws DriverException + */ + void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count); + + /*************************/ + + + // CONSTANTS + const std::string PRE = "[B15F] "; //!< B15F stdout prefix + constexpr static uint8_t MSG_OK = 0xFF; //!< Value to acknowledge a received command + constexpr static uint8_t MSG_FAIL = 0xFE; //!< Value to reject a received command + constexpr static uint16_t RECONNECT_TIMEOUT = 64; //!< Time in ms after which a reconnect attempt aborts + constexpr static uint16_t WDT_TIMEOUT = 15; //!< Time in ms after which the watch dog timer resets the MCU + constexpr static uint8_t RECONNECT_TRIES = 3; //!< Maximum count of reconnect attempts after which the driver stops + constexpr static uint32_t BAUDRATE = 57600; //!< USART baudrate for communication with the MCU private: - - /** - * Initialisiert und testet die Verbindung zum B15 - * \throws DriverException - */ - void init(void); - USART usart; - static B15F* instance; - static errorhandler_t errorhandler; - - // REQUESTS - constexpr static uint8_t RQ_DISC = 0; - constexpr static uint8_t RQ_TEST = 1; - constexpr static uint8_t RQ_INFO = 2; - constexpr static uint8_t RQ_INT = 3; - constexpr static uint8_t RQ_ST = 4; - constexpr static uint8_t RQ_BA0 = 5; - constexpr static uint8_t RQ_BA1 = 6; - constexpr static uint8_t RQ_BE0 = 7; - constexpr static uint8_t RQ_BE1 = 8; - constexpr static uint8_t RQ_DSW = 9; - constexpr static uint8_t RQ_AA0 = 10; - constexpr static uint8_t RQ_AA1 = 11; - constexpr static uint8_t RQ_ADC = 12; - constexpr static uint8_t RQ_ADC_DAC_STROKE = 13; + /** + * Initialisiert und testet die Verbindung zum B15 + * \throws DriverException + */ + void init(void); + + USART usart; + static B15F* instance; + static errorhandler_t errorhandler; + + // REQUESTS + constexpr static uint8_t RQ_DISC = 0; + constexpr static uint8_t RQ_TEST = 1; + constexpr static uint8_t RQ_INFO = 2; + constexpr static uint8_t RQ_INT = 3; + constexpr static uint8_t RQ_ST = 4; + constexpr static uint8_t RQ_BA0 = 5; + constexpr static uint8_t RQ_BA1 = 6; + constexpr static uint8_t RQ_BE0 = 7; + constexpr static uint8_t RQ_BE1 = 8; + constexpr static uint8_t RQ_DSW = 9; + constexpr static uint8_t RQ_AA0 = 10; + constexpr static uint8_t RQ_AA1 = 11; + constexpr static uint8_t RQ_ADC = 12; + constexpr static uint8_t RQ_ADC_DAC_STROKE = 13; }; #endif // B15F_H diff --git a/control/src/drv/dot.cpp b/control/src/drv/dot.cpp index 29e80fd..0edb0b4 100644 --- a/control/src/drv/dot.cpp +++ b/control/src/drv/dot.cpp @@ -2,21 +2,21 @@ Dot::Dot(uint16_t x, uint16_t y, uint8_t curve) : x(x), y(y), curve(curve) { - if(curve >= 64) - throw std::range_error("Kurvenindex muss im Bereich [0, 63] liegen"); + if(curve >= 64) + throw std::range_error("Kurvenindex muss im Bereich [0, 63] liegen"); } uint16_t Dot::getX() const { - return x; + return x; } uint16_t Dot::getY() const { - return y; + return y; } uint8_t Dot::getCurve(void) const { - return curve; + return curve; } diff --git a/control/src/drv/dot.h b/control/src/drv/dot.h index 3f2b7f0..48f3493 100644 --- a/control/src/drv/dot.h +++ b/control/src/drv/dot.h @@ -4,17 +4,37 @@ #include #include +/** + * Immutable dot class with x and y coordinate and curve index. + * Dots with the same curve index get the same color by plotty. + */ + class Dot { public: - Dot(uint16_t x, uint16_t y, uint8_t curve); - uint16_t getX(void) const; - uint16_t getY(void) const; - uint8_t getCurve(void) const; - + /** + * Constructor with x and y coordinate and curve index. + */ + Dot(uint16_t x, uint16_t y, uint8_t curve); + + /** + * Returns the x coordinate. + */ + uint16_t getX(void) const; + + /** + * Returns the y coordinate. + */ + uint16_t getY(void) const; + + /** + * Returns the curve index. + */ + uint8_t getCurve(void) const; + private: - uint16_t x, y; - uint8_t curve; + uint16_t x, y; + uint8_t curve; }; diff --git a/control/src/drv/driverexception.h b/control/src/drv/driverexception.h index 18a88a9..cc6764b 100644 --- a/control/src/drv/driverexception.h +++ b/control/src/drv/driverexception.h @@ -5,28 +5,30 @@ // SOURCE: https://stackoverflow.com/a/8152888 +/*! Exception driver problems, for instance incompatible firmware version. */ + class DriverException: public std::exception { public: - explicit DriverException(const char* message) : msg_(message) - { - } + explicit DriverException(const char* message) : msg_(message) + { + } - explicit DriverException(const std::string& message) : msg_(message) - { - } + explicit DriverException(const std::string& message) : msg_(message) + { + } - virtual ~DriverException() throw () - { - } + virtual ~DriverException() throw () + { + } - virtual const char* what() const throw () - { - return msg_.c_str(); - } + virtual const char* what() const throw () + { + return msg_.c_str(); + } protected: - std::string msg_; + std::string msg_; }; #endif // DRIVEREXCEPTION_H diff --git a/control/src/drv/plottyfile.cpp b/control/src/drv/plottyfile.cpp index 1f2b955..c236531 100644 --- a/control/src/drv/plottyfile.cpp +++ b/control/src/drv/plottyfile.cpp @@ -2,197 +2,197 @@ void PlottyFile::addDot(Dot& dot) { - dots.push_back(dot); + dots.push_back(dot); } void PlottyFile::addDot(Dot dot) { - dots.push_back(dot); + dots.push_back(dot); } void PlottyFile::setFunctionType(FunctionType function_type) { - this->function_type = function_type; + this->function_type = function_type; } void PlottyFile::setQuadrant(uint8_t quadrant) { - if(quadrant < 1 || quadrant > 4) - throw std::range_error("Ungueltiger Quadrant"); - this->quadrant = quadrant; + if(quadrant < 1 || quadrant > 4) + throw std::range_error("Ungueltiger Quadrant"); + this->quadrant = quadrant; } void PlottyFile::setRefX(uint16_t ref_x) { - this->ref_x = ref_x; + this->ref_x = ref_x; } void PlottyFile::setRefY(uint16_t ref_y) { - this->ref_y = ref_y; + this->ref_y = ref_y; } void PlottyFile::setParaFirstCurve(uint16_t para_first) { - this->para_first = para_first; + this->para_first = para_first; } void PlottyFile::setParaStepWidth(uint16_t para_stepwidth) { - this->para_stepwidth = para_stepwidth; + this->para_stepwidth = para_stepwidth; } void PlottyFile::setUnitX(std::string unit_x) { - this->unit_x = unit_x; + this->unit_x = unit_x; } void PlottyFile::setDescX(std::string desc_x) { - this->desc_x = desc_x; + this->desc_x = desc_x; } void PlottyFile::setUnitY(std::string unit_y) { - this->unit_y = unit_y; + this->unit_y = unit_y; } void PlottyFile::setDescY(std::string desc_y) { - this->desc_y = desc_y; + this->desc_y = desc_y; } void PlottyFile::setUnitPara(std::string unit_para) { - this->unit_para = unit_para; + this->unit_para = unit_para; } void PlottyFile::setDescPara(std::string desc_para) { - this->desc_para = desc_para; + this->desc_para = desc_para; } - + FunctionType PlottyFile::getFunctionType() const { - return function_type; + return function_type; } uint8_t PlottyFile::getQuadrant() const { - return quadrant; + return quadrant; } uint16_t PlottyFile::getRefX() const { - return ref_x; + return ref_x; } uint16_t PlottyFile::getRefY() const { - return ref_y; + return ref_y; } uint16_t PlottyFile::getParaFirstCurve() const { - return para_first; + return para_first; } uint16_t PlottyFile::getParaStepWidth() const { - return para_stepwidth; + return para_stepwidth; } std::string PlottyFile::getUnitX() const { - return unit_x; + return unit_x; } std::string PlottyFile::getDescX() const { - return desc_x; + return desc_x; } std::string PlottyFile::getUnitY() const { - return unit_y; + return unit_y; } std::string PlottyFile::getDescY() const { - return desc_y; + return desc_y; } std::string PlottyFile::getUnitPara() const { - return unit_para; + return unit_para; } std::string PlottyFile::getDescPara() const { - return desc_para; + return desc_para; } 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'; + 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) -{ - prepStr(unit_x, STR_LEN_SHORT); - prepStr(desc_x, STR_LEN_LARGE); - prepStr(unit_y, STR_LEN_SHORT); - prepStr(desc_y, STR_LEN_LARGE); - prepStr(unit_para, STR_LEN_SHORT); - prepStr(desc_para, STR_LEN_LARGE); - - std::ofstream file(filename); - - // write file header - file.write(reinterpret_cast(&command), 1); - file.write(head.c_str(), head.length()); - file.write(filetype.c_str(), filetype.length()); - file.write(reinterpret_cast(&version), 2); - file.write(reinterpret_cast(&subversion), 2); - file.put(static_cast(function_type)); - 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); - - // make sure header size is 256 Byte - while(file.tellp() < 256) - file.put(0); - - for(Dot& dot : dots) - { - file.put((dot.getX() >> 8) | (static_cast(dot.getCurve()) << 2)); - file.put(dot.getX() & 0xFF); - file.put(dot.getY() >> 8); - file.put(dot.getY() & 0xFF); - } - - file.close(); +{ + prepStr(unit_x, STR_LEN_SHORT); + prepStr(desc_x, STR_LEN_LARGE); + prepStr(unit_y, STR_LEN_SHORT); + prepStr(desc_y, STR_LEN_LARGE); + prepStr(unit_para, STR_LEN_SHORT); + prepStr(desc_para, STR_LEN_LARGE); + + std::ofstream file(filename); + + // write file header + file.write(reinterpret_cast(&command), 1); + file.write(head.c_str(), head.length()); + file.write(filetype.c_str(), filetype.length()); + file.write(reinterpret_cast(&version), 2); + file.write(reinterpret_cast(&subversion), 2); + file.put(static_cast(function_type)); + 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); + + // make sure header size is 256 Byte + while(file.tellp() < 256) + file.put(0); + + for(Dot& dot : dots) + { + file.put((dot.getX() >> 8) | (static_cast(dot.getCurve()) << 2)); + file.put(dot.getX() & 0xFF); + file.put(dot.getY() >> 8); + file.put(dot.getY() & 0xFF); + } + + file.close(); } void PlottyFile::startPlotty(std::string filename) { - int code = system(("plotty --in " + filename).c_str()); - if(code) - throw std::runtime_error("Fehler beim Aufruf von plotty"); + int code = system(("plotty --in " + filename).c_str()); + if(code) + throw std::runtime_error("Fehler beim Aufruf von plotty"); } diff --git a/control/src/drv/plottyfile.h b/control/src/drv/plottyfile.h index 17b02eb..6197bf2 100644 --- a/control/src/drv/plottyfile.h +++ b/control/src/drv/plottyfile.h @@ -9,71 +9,200 @@ enum FunctionType { - CurveFamily = 'S', - Curve = 'C', - Level = 'P' -}; + CurveFamily = 'S', + Curve = 'C', + Level = 'P' +}; + +/*! Wrapper class for convenient plot file creation, needed to display graphs using plotty. */ class PlottyFile { public: - void addDot(Dot& dot); - void addDot(Dot dot); - - void setFunctionType(FunctionType); - void setQuadrant(uint8_t); - void setRefX(uint16_t); - void setRefY(uint16_t); - void setParaFirstCurve(uint16_t); - void setParaStepWidth(uint16_t); - void setUnitX(std::string); - void setDescX(std::string); - void setUnitY(std::string); - void setDescY(std::string); - void setUnitPara(std::string); - void setDescPara(std::string); - - FunctionType getFunctionType(void) const; - uint8_t getQuadrant(void) const; - uint16_t getRefX(void) const; - uint16_t getRefY(void) const; - uint16_t getParaFirstCurve(void) const; - uint16_t getParaStepWidth(void) const; - std::string getUnitX(void) const; - std::string getDescX(void) const; - std::string getUnitY(void) const; - std::string getDescY(void) const; - std::string getUnitPara(void) const; - std::string getDescPara(void) const; - - void writeToFile(std::string filename); - void startPlotty(std::string filename); + /** + * Adds a dot to the plotty file. + * \param dot the dot + */ + void addDot(Dot& dot); + + /** + * Adds a dot by reference to the plotty file. + * \param dot the dot + */ + void addDot(Dot dot); + + /** + * Sets the FunctionType of this plotty file. + * \param function_type enum value + */ + void setFunctionType(FunctionType function_type); + + /** + * Sets the quadrant of this plot. + * \param quadrant quadrant number (1..4) + */ + void setQuadrant(uint8_t quadrant); + + /** + * Sets reference (max) value of the x axis + * \param ref_x reference value + */ + void setRefX(uint16_t ref_x); + + /** + * Sets reference (max) value of the y axis + * \param ref_y reference value + */ + void setRefY(uint16_t ref_y); + + /** + * Sets initial value of the parameter. + * Gets used together with the stepwith to label the curves. + * \param para_first initial parameter value + */ + void setParaFirstCurve(uint16_t para_first); + + /** + * Sets the stepwith the parameter got increased with each curve. + * \param para_first parameter stepwith + */ + void setParaStepWidth(uint16_t para_stepwidth); + + /** + * Sets the unit of the x axis. + * \param para_first unit + */ + void setUnitX(std::string unit_x); + + /** + * Sets the description of the x axis. + * \param para_first description + */ + void setDescX(std::string desc_x); + + /** + * Sets the unit of the y axis. + * \param para_first unit + */ + void setUnitY(std::string unit_y); + + /** + * Sets the description of the y axis. + * \param para_first description + */ + void setDescY(std::string desc_y); + + /** + * Sets the unit of the parameter. + * \param para_first unit + */ + void setUnitPara(std::string unit_para); + /** + * Sets the description of the parameter. + * \param para_first description + */ + void setDescPara(std::string desc_para); + + + + /** + * \return the FunctionType + */ + FunctionType getFunctionType(void) const; + + /** + * \return the quadrant + */ + uint8_t getQuadrant(void) const; + + /** + * \return x reference (max) value + */ + uint16_t getRefX(void) const; + + /** + * \return y reference (max) value + */ + uint16_t getRefY(void) const; + + /** + * \return initial parameter value + */ + uint16_t getParaFirstCurve(void) const; + + /** + * \return parameter stepwith + */ + uint16_t getParaStepWidth(void) const; + + /** + * \return unit of x axis + */ + std::string getUnitX(void) const; + + /** + * \return description of x axis + */ + std::string getDescX(void) const; + + /** + * \return unit of y axis + */ + std::string getUnitY(void) const; + + /** + * \return description of y axis + */ + std::string getDescY(void) const; + + /** + * \return unit of parameter + */ + std::string getUnitPara(void) const; + + /** + * \return description of parameter + */ + std::string getDescPara(void) const; + + + /** + * Saves the PlottyFile in a binary format, ready to open with plotty. + * \param filename desired plot path + */ + void writeToFile(std::string filename); + + /** + * Starts plotty with a plot file. + * \param filename plot path + */ + void startPlotty(std::string filename); private: - void prepStr(std::string& str, uint8_t len); + void prepStr(std::string& str, uint8_t len); - std::vector dots; + std::vector dots; - int8_t command = 0x1D; - const std::string head = "HTWK-HWLab"; - const std::string filetype = "MD"; - int16_t version = 1; - int16_t subversion = 0; - FunctionType function_type = FunctionType::Curve; - uint8_t quadrant = 1; - uint16_t ref_x = 1023; - uint16_t ref_y = 1023; - uint16_t para_first = 1; - uint16_t para_stepwidth = 1; - 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; - - constexpr static uint8_t STR_LEN_SHORT = 10; - constexpr static uint8_t STR_LEN_LARGE = 20; + int8_t command = 0x1D; + const std::string head = "HTWK-HWLab"; + const std::string filetype = "MD"; + int16_t version = 1; + int16_t subversion = 0; + FunctionType function_type = FunctionType::Curve; + uint8_t quadrant = 1; + uint16_t ref_x = 1023; + uint16_t ref_y = 1023; + uint16_t para_first = 1; + uint16_t para_stepwidth = 1; + 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; + + constexpr static uint8_t STR_LEN_SHORT = 10; + constexpr static uint8_t STR_LEN_LARGE = 20; }; #endif // PLOTTYFILE_H diff --git a/control/src/drv/timeoutexception.h b/control/src/drv/timeoutexception.h index 159ec7b..a0be40f 100644 --- a/control/src/drv/timeoutexception.h +++ b/control/src/drv/timeoutexception.h @@ -5,31 +5,33 @@ // SOURCE: https://stackoverflow.com/a/8152888 +/*! Exception for USART related timeouts. */ + class TimeoutException: public std::exception { public: - explicit TimeoutException(const char* message, int timeout) : TimeoutException(std::string(message), timeout) - { - } + explicit TimeoutException(const char* message, int timeout) : TimeoutException(std::string(message), timeout) + { + } - explicit TimeoutException(const std::string& message, int timeout) : msg(message), m_timeout(timeout) - { - if(!msg.length()) - msg = "Timeout reached (" + std::to_string(m_timeout) + ")"; - } + explicit TimeoutException(const std::string& message, int timeout) : msg(message), m_timeout(timeout) + { + if(!msg.length()) + msg = "Timeout reached (" + std::to_string(m_timeout) + ")"; + } - virtual ~TimeoutException() throw () - { - } + virtual ~TimeoutException() throw () + { + } - virtual const char* what() const throw () - { - return msg.c_str(); - } + virtual const char* what() const throw () + { + return msg.c_str(); + } protected: - std::string msg; - int m_timeout; + std::string msg; + int m_timeout; }; #endif // TIMEOUTEXCEPTION_H diff --git a/control/src/drv/usart.cpp b/control/src/drv/usart.cpp index a18de62..dcc7dd9 100644 --- a/control/src/drv/usart.cpp +++ b/control/src/drv/usart.cpp @@ -2,323 +2,324 @@ void USART::openDevice(std::string device) { - file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/); - if(file_desc <= 0) - throw USARTException("Fehler beim Öffnen des Gerätes"); - - struct termios options; - int code = tcgetattr(file_desc, &options); - if(code) - throw USARTException("Fehler beim Lesen der Geräteparameter"); - - options.c_cflag = CS8 | CLOCAL | CREAD; - options.c_iflag = IGNPAR; - options.c_oflag = 0; - options.c_lflag = 0; - options.c_cc[VMIN] = 0; // #bytes read returns at least - options.c_cc[VTIME] = timeout; + file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/); + if(file_desc <= 0) + throw USARTException("Fehler beim Öffnen des Gerätes"); + + struct termios options; + int code = tcgetattr(file_desc, &options); + if(code) + throw USARTException("Fehler beim Lesen der Geräteparameter"); + + options.c_cflag = CS8 | CLOCAL | CREAD; + options.c_iflag = IGNPAR; + options.c_oflag = 0; + options.c_lflag = 0; + options.c_cc[VMIN] = 0; // #bytes read returns at least + options.c_cc[VTIME] = timeout; code = cfsetspeed(&options, baudrate); - if(code) - throw USARTException("Fehler beim Setzen der Baudrate"); - - code = tcsetattr(file_desc, TCSANOW, &options); - if(code) - throw USARTException("Fehler beim Setzen der Geräteparameter"); - - clearOutputBuffer(); - clearInputBuffer(); + if(code) + throw USARTException("Fehler beim Setzen der Baudrate"); + + code = tcsetattr(file_desc, TCSANOW, &options); + if(code) + throw USARTException("Fehler beim Setzen der Geräteparameter"); + + clearOutputBuffer(); + clearInputBuffer(); } - + void USART::closeDevice() { - int code = close(file_desc); - if(code) - throw USARTException("Fehler beim Schließen des Gerätes"); + int code = close(file_desc); + if(code) + throw USARTException("Fehler beim Schließen des Gerätes"); } - + void USART::clearInputBuffer() { - int code = tcflush(file_desc, TCIFLUSH); - if(code) - throw USARTException("Fehler beim Leeren des Eingangspuffers"); + int code = tcflush(file_desc, TCIFLUSH); + if(code) + throw USARTException("Fehler beim Leeren des Eingangspuffers"); } - + void USART::clearOutputBuffer() { - int code = tcflush(file_desc, TCOFLUSH); - if(code) - throw USARTException("Fehler beim Leeren des Ausgangspuffers"); + int code = tcflush(file_desc, TCOFLUSH); + if(code) + throw USARTException("Fehler beim Leeren des Ausgangspuffers"); } - + void USART::flushOutputBuffer() { - int code = tcdrain(file_desc); - if(code) - throw USARTException("Fehler beim Versenden des Ausgangspuffers"); + int code = tcdrain(file_desc); + if(code) + throw USARTException("Fehler beim Versenden des Ausgangspuffers"); } void USART::printStatistics() { - double pz = 1e2 * n_blocks_failed / n_blocks_total; - pz = std::round(pz * 1e2) / 1e2; - std::cout << "blocks total: " << n_blocks_total << " ok: " << (n_blocks_total - n_blocks_failed) << " failed: " << n_blocks_failed << " (" << pz << "%)" << std::endl; + double pz = 1e2 * n_blocks_failed / n_blocks_total; + pz = std::round(pz * 1e2) / 1e2; + std::cout << "blocks total: " << n_blocks_total << " ok: " << (n_blocks_total - n_blocks_failed) << " failed: " << n_blocks_failed << " (" << pz << "%)" << std::endl; } void USART::writeByte(uint8_t b) { - int sent = write(file_desc, &b, 1); - if(sent != 1) - { - std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl; - usleep(100000); - sent = write(file_desc, &b, 1); - if(sent != 1) - throw USARTException("Fehler beim Senden: writeByte()"); - } - + int sent = write(file_desc, &b, 1); + if(sent != 1) + { + std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl; + usleep(100000); + sent = write(file_desc, &b, 1); + if(sent != 1) + throw USARTException("Fehler beim Senden: writeByte()"); + } + } - + void USART::writeInt(uint16_t d) { - int sent = write(file_desc, reinterpret_cast(&d), 2); - if(sent != 2) - throw USARTException("Fehler beim Senden: writeInt()"); + int sent = write(file_desc, reinterpret_cast(&d), 2); + if(sent != 2) + throw USARTException("Fehler beim Senden: writeInt()"); } int USART::read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout) { - uint32_t elapsed = 0; - int n_read = -1; - auto start = std::chrono::steady_clock::now(); - auto end = start; - while(elapsed < timeout) - { - n_read = read(file_desc, buffer + offset, len); - if (n_read == len) - return n_read; - - end = std::chrono::steady_clock::now(); - elapsed = std::chrono::duration_cast(end - start).count(); - } - - return 0; + uint32_t elapsed = 0; + int n_read = -1; + auto start = std::chrono::steady_clock::now(); + auto end = start; + while(elapsed < timeout) + { + n_read = read(file_desc, buffer + offset, len); + if (n_read == len) + return n_read; + + end = std::chrono::steady_clock::now(); + elapsed = std::chrono::duration_cast(end - start).count(); + } + + return 0; } int USART::write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout) { - uint32_t elapsed = 0; - int n_sent = -1; - auto start = std::chrono::steady_clock::now(); - auto end = start; - while(elapsed < timeout) - { - n_sent = write(file_desc, buffer + offset, len); - flushOutputBuffer(); - if (n_sent == len) - return n_sent; - - end = std::chrono::steady_clock::now(); - elapsed = std::chrono::duration_cast(end - start).count(); - } - - return n_sent; + uint32_t elapsed = 0; + int n_sent = -1; + auto start = std::chrono::steady_clock::now(); + auto end = start; + while(elapsed < timeout) + { + n_sent = write(file_desc, buffer + offset, len); + flushOutputBuffer(); + if (n_sent == len) + return n_sent; + + end = std::chrono::steady_clock::now(); + elapsed = std::chrono::duration_cast(end - start).count(); + } + + return n_sent; } void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len) { - uint8_t crc; - uint8_t aw; - const uint16_t us_per_bit = (1000000 / baudrate) * 16; - const uint16_t n_total = len + 3; - - n_blocks_total++; - bool failed = false; - - do - { - // calc crc - crc = 0; - for(uint8_t i = 0; i < len; i++) - { - crc ^= buffer[i]; - for (uint8_t k = 0; k < 8; k++) - { - if (crc & 1) - crc ^= CRC7_POLY; - crc >>= 1; - } - } - - // construct block - block_buffer[0] = len; - std::memcpy(&block_buffer[1], buffer + offset, len); - block_buffer[len + 1] = crc; - block_buffer[len + 2] = BLOCK_END; - - // send block - clearOutputBuffer(); - clearInputBuffer(); - int n_sent = write_timeout(&block_buffer[0], 0, len + 3, us_per_bit * n_total); - if(n_sent != n_total) - throw std::runtime_error("fatal (send): " + std::to_string(n_sent)); - - /*for(uint8_t i = 0; i < len + 3; i++) - { - write_timeout(&block_buffer[i], 0, 1, us_per_bit * n_total); - //tcdrain(file_desc); - //usleep(1000); - }*/ - - // flush output data - tcdrain(file_desc); - - //usleep(us_per_bit * n_total * 10); - - // check response - int n_read = read_timeout(&aw, 0, 1, us_per_bit * n_blocks_total * 10); - for(uint16_t i = 0; i < 255 && n_read != 1; i++) - { - writeByte(0x80); // Stoppzeichen für Block - if(tcdrain(file_desc)) - { - std::cout << "drain failed" << std::endl; - } - std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl; - usleep(us_per_bit*100); - n_read = read_timeout(&aw, 0, 1, us_per_bit); - } - - if(n_read != 1) - throw std::runtime_error("fatal: " + std::to_string(n_read)); - - //clearInputBuffer(); - - if(aw != 0xFF) { - if(!failed) - n_blocks_failed++; - failed = true; - std::cout << "block failed, retry" << std::endl; - } - } - while(aw != 0xFF); - - //std::cout << "OK" << std::endl; + uint8_t crc; + uint8_t aw; + const uint16_t us_per_bit = (1000000 / baudrate) * 16; + const uint16_t n_total = len + 3; + + n_blocks_total++; + bool failed = false; + + do + { + // calc crc + crc = 0; + for(uint8_t i = 0; i < len; i++) + { + crc ^= buffer[i]; + for (uint8_t k = 0; k < 8; k++) + { + if (crc & 1) + crc ^= CRC7_POLY; + crc >>= 1; + } + } + + // construct block + block_buffer[0] = len; + std::memcpy(&block_buffer[1], buffer + offset, len); + block_buffer[len + 1] = crc; + block_buffer[len + 2] = BLOCK_END; + + // send block + clearOutputBuffer(); + clearInputBuffer(); + int n_sent = write_timeout(&block_buffer[0], 0, len + 3, us_per_bit * n_total); + if(n_sent != n_total) + throw std::runtime_error("fatal (send): " + std::to_string(n_sent)); + + /*for(uint8_t i = 0; i < len + 3; i++) + { + write_timeout(&block_buffer[i], 0, 1, us_per_bit * n_total); + //tcdrain(file_desc); + //usleep(1000); + }*/ + + // flush output data + tcdrain(file_desc); + + //usleep(us_per_bit * n_total * 10); + + // check response + int n_read = read_timeout(&aw, 0, 1, us_per_bit * n_blocks_total * 10); + for(uint16_t i = 0; i < 255 && n_read != 1; i++) + { + writeByte(0x80); // Stoppzeichen für Block + if(tcdrain(file_desc)) + { + std::cout << "drain failed" << std::endl; + } + std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl; + usleep(us_per_bit*100); + n_read = read_timeout(&aw, 0, 1, us_per_bit); + } + + if(n_read != 1) + throw std::runtime_error("fatal: " + std::to_string(n_read)); + + //clearInputBuffer(); + + if(aw != 0xFF) + { + if(!failed) + n_blocks_failed++; + failed = true; + std::cout << "block failed, retry" << std::endl; + } + } + while(aw != 0xFF); + + //std::cout << "OK" << std::endl; } - + uint8_t USART::readByte(void) { - char b; - auto start = std::chrono::steady_clock::now(); - auto end = start; - uint16_t elapsed = 0; - while(elapsed < timeout * 100) - { - int code = read(file_desc, &b, 1); - if (code > 0) - return static_cast(b); - - end = std::chrono::steady_clock::now(); - elapsed = std::chrono::duration_cast(end - start).count(); - } - - throw TimeoutException("Verbindung unterbrochen.", timeout); + char b; + auto start = std::chrono::steady_clock::now(); + auto end = start; + uint16_t elapsed = 0; + while(elapsed < timeout * 100) + { + int code = read(file_desc, &b, 1); + if (code > 0) + return static_cast(b); + + end = std::chrono::steady_clock::now(); + elapsed = std::chrono::duration_cast(end - start).count(); + } + + throw TimeoutException("Verbindung unterbrochen.", timeout); } uint16_t USART::readInt(void) { - return readByte() | readByte() << 8; + return readByte() | readByte() << 8; } bool USART::readBlock(uint8_t* buffer, uint16_t offset) { - uint8_t len = readByte(); - uint8_t crc = 0; - buffer += offset; - - uint32_t block_timeout = timeout / 10; - - // wait for block - int n_ready; - uint16_t elapsed = 0; - auto start = std::chrono::steady_clock::now(); - auto end = start; - while(elapsed < block_timeout) - { - int code = ioctl(file_desc, FIONREAD, &n_ready); - if(code != 0) - { - std::cout << "n_ready code: " << code << std::endl; - return false; - } - - if(n_ready >= len + 1) - break; - - end = std::chrono::steady_clock::now(); - elapsed = std::chrono::duration_cast(end - start).count(); - } - if(elapsed >= timeout) - { - std::cout << "block timeout: " << std::endl; - return false; - } - - while(len--) - { - *buffer = readByte(); - - crc ^= *buffer++; - for (uint8_t i = 0; i < 8; i++) - { - if (crc & 1) - crc ^= CRC7_POLY; - crc >>= 1; - } - } - - crc ^= readByte(); - for (uint8_t i = 0; i < 8; i++) - { - if (crc & 1) - crc ^= CRC7_POLY; - crc >>= 1; - } - - if(TEST == 1) - crc = 1; - if(TEST > 100) - TEST = 0; - - if (crc == 0) - { - writeByte(0xFF); - return true; - } - else - { - writeByte(0xFE); - return false; - } + uint8_t len = readByte(); + uint8_t crc = 0; + buffer += offset; + + uint32_t block_timeout = timeout / 10; + + // wait for block + int n_ready; + uint16_t elapsed = 0; + auto start = std::chrono::steady_clock::now(); + auto end = start; + while(elapsed < block_timeout) + { + int code = ioctl(file_desc, FIONREAD, &n_ready); + if(code != 0) + { + std::cout << "n_ready code: " << code << std::endl; + return false; + } + + if(n_ready >= len + 1) + break; + + end = std::chrono::steady_clock::now(); + elapsed = std::chrono::duration_cast(end - start).count(); + } + if(elapsed >= timeout) + { + std::cout << "block timeout: " << std::endl; + return false; + } + + while(len--) + { + *buffer = readByte(); + + crc ^= *buffer++; + for (uint8_t i = 0; i < 8; i++) + { + if (crc & 1) + crc ^= CRC7_POLY; + crc >>= 1; + } + } + + crc ^= readByte(); + for (uint8_t i = 0; i < 8; i++) + { + if (crc & 1) + crc ^= CRC7_POLY; + crc >>= 1; + } + + if(TEST == 1) + crc = 1; + if(TEST > 100) + TEST = 0; + + if (crc == 0) + { + writeByte(0xFF); + return true; + } + else + { + writeByte(0xFE); + return false; + } } uint32_t USART::getBaudrate() { - return baudrate; + return baudrate; } uint8_t USART::getTimeout() { - return timeout; + return timeout; } - + void USART::setBaudrate(uint32_t baudrate) { - this->baudrate = baudrate; + this->baudrate = baudrate; } void USART::setTimeout(uint8_t timeout) { - this->timeout = timeout; + this->timeout = timeout; } diff --git a/control/src/drv/usart.h b/control/src/drv/usart.h index b33019a..de2719f 100644 --- a/control/src/drv/usart.h +++ b/control/src/drv/usart.h @@ -13,137 +13,139 @@ #include "usartexception.h" #include "timeoutexception.h" +/*! C++ Wrapper class for termios usart library. */ + class USART { public: - - /************************************************* - * Methoden für die Verwaltung der Schnittstelle * - *************************************************/ - - /** - * Öffnet die USART Schnittstelle - * \param device Linux-Gerätepfad - * \throws USARTException - */ - void openDevice(std::string device); - - /** - * Schließt die USART Schnittstelle - * \throws USARTException - */ - void closeDevice(void); - - /** - * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gelesen wurden - * \throws USARTException - */ - void clearInputBuffer(void); - - /** - * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden - * \throws USARTException - */ - void clearOutputBuffer(void); - - /** - * Schreibt Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden - * \throws USARTException - */ - void flushOutputBuffer(void); - - /** - * Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an - */ - void printStatistics(void); - - /*************************************************/ - - - - /************************************* - * Methoden für die Datenübertragung * - *************************************/ - - /** - * Sendet ein Byte über die USART Schnittstelle - * \param b das zu sendende Byte - * \throws USARTException - */ - void writeByte(uint8_t b); - - /** - * Sendet ein Integer über die USART Schnittstelle - * \param b das zu sendende Byte - * \throws USARTException - */ - void writeInt(uint16_t d); - - /** - * Empfängt ein Byte über die USART Schnittstelle - * \throws USARTException - */ - uint8_t readByte(void); - - /** - * Empfängt ein Integer über die USART Schnittstelle - * \throws USARTException - */ - uint16_t readInt(void); - - int read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout); - int write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout); - void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len); - bool readBlock(uint8_t* buffer, uint16_t offset); - - /*************************************/ - - - - /*************************************** - * Methoden für einstellbare Parameter * - ***************************************/ - - /** - * Liefert die eingestellte Baudrate - * Änderungen werden erst nach einem open() wirksam - */ - uint32_t getBaudrate(void); - - /** - * Liefert den eingestellten Timeout (in Dezisekunden) - * Änderungen werden erst nach einem open() wirksam - */ - uint8_t getTimeout(void); - - /** - * Setzt die Baudrate - * Änderungen werden erst nach einem open() wirksam - */ - void setBaudrate(uint32_t baudrate); - - /** - * Setzt den Timeout (in Dezisekunden) - * Änderungen werden erst nach einem open() wirksam - */ - void setTimeout(uint8_t timeout); - - /***************************************/ - - constexpr static uint8_t CRC7_POLY = 0x91; - constexpr static uint8_t MAX_BLOCK_SIZE = 64; - constexpr static uint8_t BLOCK_END = 0x80; + + /************************************************* + * Methoden für die Verwaltung der Schnittstelle * + *************************************************/ + + /** + * Öffnet die USART Schnittstelle + * \param device Linux-Gerätepfad + * \throws USARTException + */ + void openDevice(std::string device); + + /** + * Schließt die USART Schnittstelle + * \throws USARTException + */ + void closeDevice(void); + + /** + * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gelesen wurden + * \throws USARTException + */ + void clearInputBuffer(void); + + /** + * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden + * \throws USARTException + */ + void clearOutputBuffer(void); + + /** + * Schreibt Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden + * \throws USARTException + */ + void flushOutputBuffer(void); + + /** + * Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an + */ + void printStatistics(void); + + /*************************************************/ + + + + /************************************* + * Methoden für die Datenübertragung * + *************************************/ + + /** + * Sendet ein Byte über die USART Schnittstelle + * \param b das zu sendende Byte + * \throws USARTException + */ + void writeByte(uint8_t b); + + /** + * Sendet ein Integer über die USART Schnittstelle + * \param b das zu sendende Byte + * \throws USARTException + */ + void writeInt(uint16_t d); + + /** + * Empfängt ein Byte über die USART Schnittstelle + * \throws USARTException + */ + uint8_t readByte(void); + + /** + * Empfängt ein Integer über die USART Schnittstelle + * \throws USARTException + */ + uint16_t readInt(void); + + int read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout); + int write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout); + void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len); + bool readBlock(uint8_t* buffer, uint16_t offset); + + /*************************************/ + + + + /*************************************** + * Methoden für einstellbare Parameter * + ***************************************/ + + /** + * Liefert die eingestellte Baudrate + * Änderungen werden erst nach einem open() wirksam + */ + uint32_t getBaudrate(void); + + /** + * Liefert den eingestellten Timeout (in Dezisekunden) + * Änderungen werden erst nach einem open() wirksam + */ + uint8_t getTimeout(void); + + /** + * Setzt die Baudrate + * Änderungen werden erst nach einem open() wirksam + */ + void setBaudrate(uint32_t baudrate); + + /** + * Setzt den Timeout (in Dezisekunden) + * Änderungen werden erst nach einem open() wirksam + */ + void setTimeout(uint8_t timeout); + + /***************************************/ + + constexpr static uint8_t CRC7_POLY = 0x91; + constexpr static uint8_t MAX_BLOCK_SIZE = 64; + constexpr static uint8_t BLOCK_END = 0x80; private: - - int file_desc = -1; // Linux Dateideskriptor - uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden! - int TEST = 0; - uint8_t timeout = 10; // in Dezisekunden - uint8_t block_buffer[MAX_BLOCK_SIZE + 3]; - - // debug statistics - uint32_t n_blocks_total = 0; - uint32_t n_blocks_failed = 0; + + int file_desc = -1; // Linux Dateideskriptor + uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden! + int TEST = 0; + uint8_t timeout = 10; // in Dezisekunden + uint8_t block_buffer[MAX_BLOCK_SIZE + 3]; + + // debug statistics + uint32_t n_blocks_total = 0; + uint32_t n_blocks_failed = 0; }; diff --git a/control/src/drv/usartexception.h b/control/src/drv/usartexception.h index 840ce6c..a8ba5c7 100644 --- a/control/src/drv/usartexception.h +++ b/control/src/drv/usartexception.h @@ -6,28 +6,30 @@ // SOURCE: https://stackoverflow.com/a/8152888 +/*! Exception for USART problems, for instance buffer overflow. */ + class USARTException: public std::exception { public: - explicit USARTException(const char* message) : msg(message) - { - } + explicit USARTException(const char* message) : msg(message) + { + } - explicit USARTException(const std::string& message) : msg(message) - { - } + explicit USARTException(const std::string& message) : msg(message) + { + } - virtual ~USARTException() throw () - { - } + virtual ~USARTException() throw () + { + } - virtual const char* what() const throw () - { - return msg.c_str(); - } + virtual const char* what() const throw () + { + return msg.c_str(); + } protected: - std::string msg; + std::string msg; }; #endif // USARTEXCEPTION_H diff --git a/control/src/ui/ui.cpp b/control/src/ui/ui.cpp index f1c1556..cb2198c 100644 --- a/control/src/ui/ui.cpp +++ b/control/src/ui/ui.cpp @@ -6,277 +6,277 @@ std::thread t_refresh; void show_main(int) { - ViewSelection* view = new ViewSelection(); - view->setTitle("B15F - Command Line Interface"); - view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor); - view->addChoice("[ Digitale Ausgabe BE0 ]", &show_digital_output0); - view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1); - view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0); - view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1); - view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info); - view->addChoice("[ Informationen ]", &show_info); - view->addChoice("", nullptr); - view->addChoice("[ Beenden ]", &finish); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewSelection* view = new ViewSelection(); + view->setTitle("B15F - Command Line Interface"); + view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor); + view->addChoice("[ Digitale Ausgabe BE0 ]", &show_digital_output0); + view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1); + view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0); + view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1); + view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info); + view->addChoice("[ Informationen ]", &show_info); + view->addChoice("", nullptr); + view->addChoice("[ Beenden ]", &finish); + view->repaint(); + + win_stack.push_back(view); + input(0); } void input(int) { - call_t nextCall; - int key; - do - { - key = wgetch(View::getWinContext()); - win_stack.back()->repaint(); - nextCall = win_stack.back()->keypress(key); - - if(key == -1) - view_back(key); - - if(nextCall) - nextCall(key); - } - while(win_stack.size()); + call_t nextCall; + int key; + do + { + key = wgetch(View::getWinContext()); + win_stack.back()->repaint(); + nextCall = win_stack.back()->keypress(key); + + if(key == -1) + view_back(key); + + if(nextCall) + nextCall(key); + } + while(win_stack.size()); } void view_back(int) { - if(win_stack.size()) - { - delete win_stack.back(); - win_stack.pop_back(); - } - if(win_stack.size()) - win_stack.back()->repaint(); + if(win_stack.size()) + { + delete win_stack.back(); + win_stack.pop_back(); + } + if(win_stack.size()) + win_stack.back()->repaint(); } void finish(int) { - cleanup(); - exit(EXIT_SUCCESS); + cleanup(); + exit(EXIT_SUCCESS); } void cleanup() { - if(t_refresh.joinable()) - t_refresh.join(); - clrtoeol(); - refresh(); - endwin(); + if(t_refresh.joinable()) + t_refresh.join(); + clrtoeol(); + refresh(); + endwin(); } void show_info(int) { - ViewInfo* view = new ViewInfo(); - view->setTitle("Info"); - view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal..."); - view->setLabelClose("[ Zurueck ]"); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewInfo* view = new ViewInfo(); + view->setTitle("Info"); + view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal..."); + view->setLabelClose("[ Zurueck ]"); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_monitor(int) { - ViewMonitor* view = new ViewMonitor(); - view->setTitle("Monitor"); - view->setText("\nErfasse Messwerte..."); - view->setLabelClose("[ Zurueck ]"); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewMonitor* view = new ViewMonitor(); + view->setTitle("Monitor"); + view->setText("\nErfasse Messwerte..."); + view->setLabelClose("[ Zurueck ]"); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_invalid_port_input(int) { - ViewInfo* view = new ViewInfo(); - view->setTitle("Falsche Eingabe"); - view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an."); - view->setLabelClose("[ Schliessen ]"); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewInfo* view = new ViewInfo(); + view->setTitle("Falsche Eingabe"); + view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an."); + view->setLabelClose("[ Schliessen ]"); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_invalid_dac_input(int) { - ViewInfo* view = new ViewInfo(); - view->setTitle("Falsche Eingabe"); - view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an."); - view->setLabelClose("[ Schliessen ]"); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewInfo* view = new ViewInfo(); + view->setTitle("Falsche Eingabe"); + view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an."); + view->setLabelClose("[ Schliessen ]"); + view->repaint(); + + win_stack.push_back(view); + input(0); } void write_digital_output0(int) { - try - { - int d = std::stoi(static_cast(win_stack.back())->getInput(), 0, 16); - if(d > 255 || 0 > d) - throw std::invalid_argument("bad value"); - uint8_t port = static_cast(d); - - B15F& drv = B15F::getInstance(); - drv.digitalWrite0(port); - view_back(0); - } - catch(std::invalid_argument& ex) - { - show_invalid_port_input(0); - } + try + { + int d = std::stoi(static_cast(win_stack.back())->getInput(), 0, 16); + if(d > 255 || 0 > d) + throw std::invalid_argument("bad value"); + uint8_t port = static_cast(d); + + B15F& drv = B15F::getInstance(); + drv.digitalWrite0(port); + view_back(0); + } + catch(std::invalid_argument& ex) + { + show_invalid_port_input(0); + } } void write_digital_output1(int) { - try - { - int d = std::stoi(static_cast(win_stack.back())->getInput(), 0, 16); - if(d > 255 || 0 > d) - throw std::invalid_argument("bad value"); - uint8_t port = static_cast(d); - - B15F& drv = B15F::getInstance(); - drv.digitalWrite1(port); - view_back(0); - } - catch(std::invalid_argument& ex) - { - show_invalid_port_input(0); - } + try + { + int d = std::stoi(static_cast(win_stack.back())->getInput(), 0, 16); + if(d > 255 || 0 > d) + throw std::invalid_argument("bad value"); + uint8_t port = static_cast(d); + + B15F& drv = B15F::getInstance(); + drv.digitalWrite1(port); + view_back(0); + } + catch(std::invalid_argument& ex) + { + show_invalid_port_input(0); + } } void write_analog_output0(int) { - try - { - uint16_t port = std::stoi(static_cast(win_stack.back())->getInput()); - if(port > 1023) - throw std::invalid_argument("bad value"); - - B15F& drv = B15F::getInstance(); - drv.analogWrite0(port); - view_back(0); - } - catch(std::invalid_argument& ex) - { - show_invalid_dac_input(0); - } + try + { + uint16_t port = std::stoi(static_cast(win_stack.back())->getInput()); + if(port > 1023) + throw std::invalid_argument("bad value"); + + B15F& drv = B15F::getInstance(); + drv.analogWrite0(port); + view_back(0); + } + catch(std::invalid_argument& ex) + { + show_invalid_dac_input(0); + } } void write_analog_output1(int) { - try - { - uint16_t port = std::stoi(static_cast(win_stack.back())->getInput()); - if(port > 1023) - throw std::invalid_argument("bad value"); - - B15F& drv = B15F::getInstance(); - drv.analogWrite1(port); - view_back(0); - } - catch(std::invalid_argument& ex) - { - show_invalid_dac_input(0); - } + try + { + uint16_t port = std::stoi(static_cast(win_stack.back())->getInput()); + if(port > 1023) + throw std::invalid_argument("bad value"); + + B15F& drv = B15F::getInstance(); + drv.analogWrite1(port); + view_back(0); + } + catch(std::invalid_argument& ex) + { + show_invalid_dac_input(0); + } } void show_digital_output0(int) { - ViewPromt* view = new ViewPromt(); - view->setTitle("Digitale Ausgabe BE0"); - view->setMessage("\nAusgabe Port-Wert (hex): 0x"); - view->setCancel("[ Zurueck ]", true); - view->setConfirm("[ OK ]", &write_digital_output0); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewPromt* view = new ViewPromt(); + view->setTitle("Digitale Ausgabe BE0"); + view->setMessage("\nAusgabe Port-Wert (hex): 0x"); + view->setCancel("[ Zurueck ]", true); + view->setConfirm("[ OK ]", &write_digital_output0); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_digital_output1(int) { - ViewPromt* view = new ViewPromt(); - view->setTitle("Digitale Ausgabe BE1"); - view->setMessage("\nAusgabe Port-Wert (hex): 0x"); - view->setCancel("[ Zurueck ]", true); - view->setConfirm("[ OK ]", &write_digital_output1); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewPromt* view = new ViewPromt(); + view->setTitle("Digitale Ausgabe BE1"); + view->setMessage("\nAusgabe Port-Wert (hex): 0x"); + view->setCancel("[ Zurueck ]", true); + view->setConfirm("[ OK ]", &write_digital_output1); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_analog_output0(int) { - ViewPromt* view = new ViewPromt(); - view->setTitle("Analoge Ausgabe AA0"); - view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): "); - view->setCancel("[ Zurueck ]", true); - view->setConfirm("[ OK ]", &write_analog_output0); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewPromt* view = new ViewPromt(); + view->setTitle("Analoge Ausgabe AA0"); + view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): "); + view->setCancel("[ Zurueck ]", true); + view->setConfirm("[ OK ]", &write_analog_output0); + view->repaint(); + + win_stack.push_back(view); + input(0); } void show_analog_output1(int) { - ViewPromt* view = new ViewPromt(); - view->setTitle("Analoge Ausgabe AA1"); - view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): "); - view->setCancel("[ Zurueck ]", true); - view->setConfirm("[ OK ]", &write_analog_output1); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewPromt* view = new ViewPromt(); + view->setTitle("Analoge Ausgabe AA1"); + view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): "); + view->setCancel("[ Zurueck ]", true); + view->setConfirm("[ OK ]", &write_analog_output1); + view->repaint(); + + win_stack.push_back(view); + input(0); } void start_selftest(int) { - B15F& drv = B15F::getInstance(); - drv.activateSelfTestMode(); - - ViewInfo* view = new ViewInfo(); - view->setTitle("Selbsttest aktiv"); - view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1"); - view->setLabelClose("[ Selbsttest Beenden ]"); - view->setCall(&stop_selftest); - view->repaint(); - - win_stack.push_back(view); - input(0); + B15F& drv = B15F::getInstance(); + drv.activateSelfTestMode(); + + ViewInfo* view = new ViewInfo(); + view->setTitle("Selbsttest aktiv"); + view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1"); + view->setLabelClose("[ Selbsttest Beenden ]"); + view->setCall(&stop_selftest); + view->repaint(); + + win_stack.push_back(view); + input(0); } void stop_selftest(int) { - B15F& drv = B15F::getInstance(); - drv.discard(); - drv.delay_ms(B15F::WDT_TIMEOUT); - drv.reconnect(); - drv.digitalWrite0(0); - drv.digitalWrite1(0); + B15F& drv = B15F::getInstance(); + drv.discard(); + drv.delay_ms(B15F::WDT_TIMEOUT); + drv.reconnect(); + drv.digitalWrite0(0); + drv.digitalWrite1(0); } void show_selftest_info(int) { - ViewInfo* view = new ViewInfo(); - view->setTitle("Selbsttest"); - view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und bestaetigen\nmit Enter."); - view->setLabelClose("[ Weiter ]"); - view->setCall(&start_selftest); - view->repaint(); - - win_stack.push_back(view); - input(0); + ViewInfo* view = new ViewInfo(); + view->setTitle("Selbsttest"); + view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und bestaetigen\nmit Enter."); + view->setLabelClose("[ Weiter ]"); + view->setCall(&start_selftest); + view->repaint(); + + win_stack.push_back(view); + input(0); } diff --git a/control/src/ui/view.cpp b/control/src/ui/view.cpp index af3e590..8154379 100644 --- a/control/src/ui/view.cpp +++ b/control/src/ui/view.cpp @@ -4,12 +4,12 @@ WINDOW* View::win = nullptr; View::View() { - if(!win) - { - B15F::abort("View::win not initialized, missing context"); - } - getmaxyx(win, height, width); // init width and height - keypad(win, TRUE); + if(!win) + { + B15F::abort("View::win not initialized, missing context"); + } + getmaxyx(win, height, width); // init width and height + keypad(win, TRUE); } View::~View() @@ -18,12 +18,12 @@ View::~View() void View::setWinContext(WINDOW* win) { - View::win = win; + View::win = win; } WINDOW* View::getWinContext() { - return win; + return win; } // from: https://stackoverflow.com/a/37454181 @@ -46,33 +46,33 @@ std::vector View::str_split(const std::string& str, const std::stri void View::setTitle(std::string title) { - this->title = title; + this->title = title; } void View::repaint() { - // get screen size - struct winsize size; - if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0) - throw std::runtime_error("TIOCGWINSZ error"); - - - start_x = floor((size.ws_col - width) / 2.); - start_y = floor((size.ws_row - height) / 2.); - - curs_set(0); // hide cursor - mvwin(win, start_y, start_x); - clear(); - wclear(win); - - // generic draw - box(win, 0, 0); - int offset_x = (width - title.length()) / 2; - mvwprintw(win, 1, offset_x, "%s", title.c_str()); - - // specific draw - draw(); + // get screen size + struct winsize size; + if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0) + throw std::runtime_error("TIOCGWINSZ error"); - refresh(); - wrefresh(win); + + start_x = floor((size.ws_col - width) / 2.); + start_y = floor((size.ws_row - height) / 2.); + + curs_set(0); // hide cursor + mvwin(win, start_y, start_x); + clear(); + wclear(win); + + // generic draw + box(win, 0, 0); + int offset_x = (width - title.length()) / 2; + mvwprintw(win, 1, offset_x, "%s", title.c_str()); + + // specific draw + draw(); + + refresh(); + wrefresh(win); } diff --git a/control/src/ui/view.h b/control/src/ui/view.h index 1445035..a63043b 100644 --- a/control/src/ui/view.h +++ b/control/src/ui/view.h @@ -14,32 +14,34 @@ extern std::string ERR_MSG; typedef std::function call_t; +/*! Base class for multiple views with the ncurses user interface. */ + class View { public: - View(void); - virtual ~View(void); - - static void setWinContext(WINDOW* win); - static WINDOW* getWinContext(void); - static std::vector str_split(const std::string& str, const std::string delim); - - virtual void setTitle(std::string title); - - virtual void repaint(void); - - virtual void draw(void) = 0; - virtual call_t keypress(int& key) = 0; - - + View(void); + virtual ~View(void); + + static void setWinContext(WINDOW* win); + static WINDOW* getWinContext(void); + static std::vector str_split(const std::string& str, const std::string delim); + + virtual void setTitle(std::string title); + + virtual void repaint(void); + + virtual void draw(void) = 0; + virtual call_t keypress(int& key) = 0; + + protected: - int width, height; - int start_x = 0, start_y = 0; - std::string title; - std::vector calls; - - static WINDOW* win; - constexpr static int KEY_ENT = 10; + int width, height; + int start_x = 0, start_y = 0; + std::string title; + std::vector calls; + + static WINDOW* win; + constexpr static int KEY_ENT = 10; }; #endif // VIEW_H diff --git a/control/src/ui/view_info.cpp b/control/src/ui/view_info.cpp index 056ef0f..5adabbc 100644 --- a/control/src/ui/view_info.cpp +++ b/control/src/ui/view_info.cpp @@ -2,62 +2,62 @@ ViewInfo::ViewInfo() { - calls.push_back(nullptr); + calls.push_back(nullptr); } void ViewInfo::setText(std::string text) { - this->text = text; + this->text = text; } void ViewInfo::setLabelClose(std::string label) { - this->label_close = label; + this->label_close = label; } void ViewInfo::setCall(call_t call) { - calls[0] = call; + calls[0] = call; } void ViewInfo::draw() { - int li = 0; - for(std::string line : str_split(text, "\n")) - mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str()); - - close_offset_x = (width - label_close.length()) / 2; - close_offset_y = height - 2; - - wattron(win, A_REVERSE); - mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str()); - wattroff(win, A_REVERSE); + int li = 0; + for(std::string line : str_split(text, "\n")) + mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str()); + + close_offset_x = (width - label_close.length()) / 2; + close_offset_y = height - 2; + + wattron(win, A_REVERSE); + mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str()); + wattroff(win, A_REVERSE); } call_t ViewInfo::keypress(int& key) { - switch(key) - { - - case KEY_MOUSE: - { - // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml - MEVENT event; - if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) - { - size_t column = start_x + close_offset_x; - size_t row = start_y + close_offset_y; - size_t mouse_x = event.x, mouse_y = event.y; - if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length()) - key = -1; // do return from view - } - break; - } - case KEY_ENT: - key = -1; // do return from view - break; - default: - break; - } - return calls[0]; + switch(key) + { + + case KEY_MOUSE: + { + // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml + MEVENT event; + if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + { + size_t column = start_x + close_offset_x; + size_t row = start_y + close_offset_y; + size_t mouse_x = event.x, mouse_y = event.y; + if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length()) + key = -1; // do return from view + } + break; + } + case KEY_ENT: + key = -1; // do return from view + break; + default: + break; + } + return calls[0]; } diff --git a/control/src/ui/view_info.h b/control/src/ui/view_info.h index be5cbf4..7a3eb4b 100644 --- a/control/src/ui/view_info.h +++ b/control/src/ui/view_info.h @@ -3,23 +3,25 @@ #include "view.h" +/*! View for simple text message output. */ + class ViewInfo : public View { public: - ViewInfo(void); - virtual void setText(std::string text); - virtual void setLabelClose(std::string label);; - virtual void setCall(call_t call); - virtual void draw(void) override; - virtual call_t keypress(int& key) override; + ViewInfo(void); + virtual void setText(std::string text); + virtual void setLabelClose(std::string label);; + virtual void setCall(call_t call); + virtual void draw(void) override; + virtual call_t keypress(int& key) override; protected: - std::string text; - std::string label_close; - int close_offset_x = 0; - int close_offset_y = 0; - constexpr static int text_offset_x = 2; - constexpr static int text_offset_y = 3; + std::string text; + std::string label_close; + int close_offset_x = 0; + int close_offset_y = 0; + constexpr static int text_offset_x = 2; + constexpr static int text_offset_y = 3; }; #endif // VIEW_INFO diff --git a/control/src/ui/view_monitor.cpp b/control/src/ui/view_monitor.cpp index 8697eef..f309b6f 100644 --- a/control/src/ui/view_monitor.cpp +++ b/control/src/ui/view_monitor.cpp @@ -1,139 +1,139 @@ #include "view_monitor.h" ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this) -{ +{ } call_t ViewMonitor::keypress(int& key) { - switch(key) - { - - case KEY_MOUSE: - { - // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml - MEVENT event; - bool hit = false; - if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) - { - size_t column = start_x + close_offset_x; - size_t row = start_y + close_offset_y; - size_t mouse_x = event.x, mouse_y = event.y; - if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length()) - hit = true; - } - if(!hit) - break; - - // fall through to next case - [[fallthrough]]; - } - case KEY_ENT: - run_worker = false; - key = -1; // do return from view - wclear(win); - wrefresh(win); - t_worker.join(); - break; - default: - break; - } - return calls[0]; + switch(key) + { + + case KEY_MOUSE: + { + // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml + MEVENT event; + bool hit = false; + if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + { + size_t column = start_x + close_offset_x; + size_t row = start_y + close_offset_y; + size_t mouse_x = event.x, mouse_y = event.y; + if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length()) + hit = true; + } + if(!hit) + break; + + // fall through to next case + [[fallthrough]]; + } + case KEY_ENT: + run_worker = false; + key = -1; // do return from view + wclear(win); + wrefresh(win); + t_worker.join(); + break; + default: + break; + } + return calls[0]; } std::string ViewMonitor::fancyDigitalString(uint8_t& b) { - std::stringstream str; - str << std::bitset<8>(b).to_string(); - str << " "; - str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec; - return str.str(); + std::stringstream str; + str << std::bitset<8>(b).to_string(); + str << " "; + str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec; + return str.str(); } std::string ViewMonitor::fancyAnalogString(uint16_t& v) { - std::stringstream str; - double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0; - - str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V "; - - str << "["; - uint8_t p = round(v * 40.0 / 1023.0); - for(uint8_t i = 0; i < p; i++) - str << "X"; - for(uint8_t i = 0; i < 40 - p; i++) - str << " "; - str << "]" << std::endl; - - return str.str(); + std::stringstream str; + double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0; + + str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V "; + + str << "["; + uint8_t p = round(v * 40.0 / 1023.0); + for(uint8_t i = 0; i < p; i++) + str << "X"; + for(uint8_t i = 0; i < 40 - p; i++) + str << " "; + str << "]" << std::endl; + + return str.str(); } void ViewMonitor::worker() { - B15F& drv = B15F::getInstance(); - while(run_worker) - { - try - { - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - - uint8_t be0 = drv.digitalRead0(); - uint8_t be1 = drv.digitalRead1(); - uint8_t dsw = drv.readDipSwitch(); - uint16_t adc[8]; - for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++) - adc[i] = drv.analogRead(i); - - - std::stringstream str; - - // hline - for(uint8_t i = 0; i < width - 2 * text_offset_x; i++) - if(i % 2 == 0) - str << "-"; - else - str << " "; - str << std::endl; - - str << "Digitale Enigaenge:" << std::endl; - str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl; - str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl; - str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl; - - // hline - for(uint8_t i = 0; i < width - 2 * text_offset_x; i++) - if(i % 2 == 0) - str << "-"; - else - str << " "; - str << std::endl; - - str << "Analoge Eingaenge:" << std::endl; - for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++) - { - str << "Kanal " << std::to_string((int) i) << ": "; - str << fancyAnalogString(adc[i]) << std::endl; - } - - text = str.str(); - repaint(); - } - catch(DriverException& ex) - { - std::cout << "DriverException: " << ex.what() << std::endl; - drv.delay_ms(1000); - } - catch(...) - { - try - { - drv.reconnect(); - } - catch(...) - { - B15F::abort("yoho meine dudes"); - return; - } - } - } + B15F& drv = B15F::getInstance(); + while(run_worker) + { + try + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + uint8_t be0 = drv.digitalRead0(); + uint8_t be1 = drv.digitalRead1(); + uint8_t dsw = drv.readDipSwitch(); + uint16_t adc[8]; + for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++) + adc[i] = drv.analogRead(i); + + + std::stringstream str; + + // hline + for(uint8_t i = 0; i < width - 2 * text_offset_x; i++) + if(i % 2 == 0) + str << "-"; + else + str << " "; + str << std::endl; + + str << "Digitale Enigaenge:" << std::endl; + str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl; + str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl; + str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl; + + // hline + for(uint8_t i = 0; i < width - 2 * text_offset_x; i++) + if(i % 2 == 0) + str << "-"; + else + str << " "; + str << std::endl; + + str << "Analoge Eingaenge:" << std::endl; + for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++) + { + str << "Kanal " << std::to_string((int) i) << ": "; + str << fancyAnalogString(adc[i]) << std::endl; + } + + text = str.str(); + repaint(); + } + catch(DriverException& ex) + { + std::cout << "DriverException: " << ex.what() << std::endl; + drv.delay_ms(1000); + } + catch(...) + { + try + { + drv.reconnect(); + } + catch(...) + { + B15F::abort("yoho meine dudes"); + return; + } + } + } } diff --git a/control/src/ui/view_monitor.h b/control/src/ui/view_monitor.h index 33552bf..9ab39b5 100644 --- a/control/src/ui/view_monitor.h +++ b/control/src/ui/view_monitor.h @@ -8,22 +8,24 @@ #include "view_info.h" #include "../drv/b15f.h" +/*! View to display all B15 inputs. */ + class ViewMonitor : public ViewInfo { - + public: - ViewMonitor(void); - virtual call_t keypress(int& key) override; + ViewMonitor(void); + virtual call_t keypress(int& key) override; private: - std::string fancyDigitalString(uint8_t& b); - std::string fancyAnalogString(uint16_t& v); + std::string fancyDigitalString(uint8_t& b); + std::string fancyAnalogString(uint16_t& v); protected: - virtual void worker(void); - volatile bool run_worker = true; - std::thread t_worker; - + virtual void worker(void); + volatile bool run_worker = true; + std::thread t_worker; + }; #endif // VIEW_MONITOR_H diff --git a/control/src/ui/view_promt.cpp b/control/src/ui/view_promt.cpp index bd57829..3705aaf 100644 --- a/control/src/ui/view_promt.cpp +++ b/control/src/ui/view_promt.cpp @@ -2,120 +2,120 @@ void ViewPromt::draw() { - curs_set(1); // show cursor - - int li = text_offset_y; - int ci = 0; - for(std::string line : str_split(message + input, "\n")) - { - mvwprintw(win, ++li, text_offset_x, "%s", line.c_str()); - ci = line.length() + text_offset_x; - } - - button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2; - button_offset_y = height - text_offset_y; - - if(selection == 0) - { - wattron(win, A_REVERSE); - mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str()); - wattroff(win, A_REVERSE); - mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str()); - mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str()); - } - else - { - mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str()); - mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str()); - wattron(win, A_REVERSE); - mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str()); - wattroff(win, A_REVERSE); - } - wmove(win, li, ci); + curs_set(1); // show cursor + + int li = text_offset_y; + int ci = 0; + for(std::string line : str_split(message + input, "\n")) + { + mvwprintw(win, ++li, text_offset_x, "%s", line.c_str()); + ci = line.length() + text_offset_x; + } + + button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2; + button_offset_y = height - text_offset_y; + + if(selection == 0) + { + wattron(win, A_REVERSE); + mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str()); + wattroff(win, A_REVERSE); + mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str()); + mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str()); + } + else + { + mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str()); + mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str()); + wattron(win, A_REVERSE); + mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str()); + wattroff(win, A_REVERSE); + } + wmove(win, li, ci); } void ViewPromt::setMessage(std::string message) { - this->message = message; + this->message = message; } void ViewPromt::setConfirm(std::string name, std::function call) { - label_confirm = name; - call_confirm = call; + label_confirm = name; + call_confirm = call; } void ViewPromt::setCancel(std::string name, bool cancelable) { - label_cancel = name; - this->cancelable = cancelable; + label_cancel = name; + this->cancelable = cancelable; } std::string ViewPromt::getInput() { - return input; + return input; } std::function ViewPromt::keypress(int& key) -{ - std::function ret = nullptr; - switch(key) - { - case KEY_BACKSPACE: - if(input.length()) - input.pop_back(); - break; - case '\t': - case KEY_LEFT: - case KEY_RIGHT: - selection = (selection + 1 ) % 2; - break; - case KEY_MOUSE: - { - // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml - MEVENT event; - bool hit = false; - if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) - { - size_t column_start = start_x + button_offset_x; - size_t row_start = start_y + button_offset_y; - size_t mouse_x = event.x, mouse_y = event.y; - if(mouse_y == row_start) - { - if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length()) - { - if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED) - hit = true; - selection = 0; - } - if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length()) - { - if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED) - hit = true; - selection = 1; - } - } - } - if(!hit) - break; - - // fall through to next case - [[fallthrough]]; - } - case KEY_ENT: - if(selection == 0) // exit - key = -1; // do return from view - else - ret = call_confirm; - break; - default: - break; - } - - if(key >= ' ' && key <= '~') - input += (char) key; - - if(key != KEY_ENT) +{ + std::function ret = nullptr; + switch(key) + { + case KEY_BACKSPACE: + if(input.length()) + input.pop_back(); + break; + case '\t': + case KEY_LEFT: + case KEY_RIGHT: + selection = (selection + 1 ) % 2; + break; + case KEY_MOUSE: + { + // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml + MEVENT event; + bool hit = false; + if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + { + size_t column_start = start_x + button_offset_x; + size_t row_start = start_y + button_offset_y; + size_t mouse_x = event.x, mouse_y = event.y; + if(mouse_y == row_start) + { + if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length()) + { + if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED) + hit = true; + selection = 0; + } + if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length()) + { + if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED) + hit = true; + selection = 1; + } + } + } + if(!hit) + break; + + // fall through to next case + [[fallthrough]]; + } + case KEY_ENT: + if(selection == 0) // exit + key = -1; // do return from view + else + ret = call_confirm; + break; + default: + break; + } + + if(key >= ' ' && key <= '~') + input += (char) key; + + if(key != KEY_ENT) repaint(); - return ret; + return ret; } diff --git a/control/src/ui/view_promt.h b/control/src/ui/view_promt.h index fb74100..a43ae5b 100644 --- a/control/src/ui/view_promt.h +++ b/control/src/ui/view_promt.h @@ -5,28 +5,30 @@ #include #include "view.h" +/*! View for basic user text input. */ + class ViewPromt : public View { public: - virtual void draw(void) override; - virtual void setMessage(std::string message); - virtual void setConfirm(std::string name, call_t call); - virtual void setCancel(std::string name, bool cancelable); - virtual std::string getInput(void); - virtual call_t keypress(int& key) override; + virtual void draw(void) override; + virtual void setMessage(std::string message); + virtual void setConfirm(std::string name, call_t call); + virtual void setCancel(std::string name, bool cancelable); + virtual std::string getInput(void); + virtual call_t keypress(int& key) override; protected: - size_t selection = 1; - std::string input; - std::string message = "Input"; - std::string label_confirm = "[ OK ]"; - std::string sep = " "; - std::string label_cancel = "[ Cancel ]"; - call_t call_confirm = nullptr; - bool cancelable = true; - int button_offset_x = 0, button_offset_y = 0; - constexpr static int text_offset_x = 2; - constexpr static int text_offset_y = 2; + size_t selection = 1; + std::string input; + std::string message = "Input"; + std::string label_confirm = "[ OK ]"; + std::string sep = " "; + std::string label_cancel = "[ Cancel ]"; + call_t call_confirm = nullptr; + bool cancelable = true; + int button_offset_x = 0, button_offset_y = 0; + constexpr static int text_offset_x = 2; + constexpr static int text_offset_y = 2; }; #endif // VIEW_PROMT_H diff --git a/control/src/ui/view_selection.cpp b/control/src/ui/view_selection.cpp index 454c3ab..e0899cd 100644 --- a/control/src/ui/view_selection.cpp +++ b/control/src/ui/view_selection.cpp @@ -2,75 +2,75 @@ void ViewSelection::draw() { - //curs_set(0); // hide cursor - for(size_t i = 0; i < choices.size(); i++) - { - if(selection == i) - wattron(win, A_REVERSE); - mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str()); - if(selection == i) - wattroff(win, A_REVERSE); - } + //curs_set(0); // hide cursor + for(size_t i = 0; i < choices.size(); i++) + { + if(selection == i) + wattron(win, A_REVERSE); + mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str()); + if(selection == i) + wattroff(win, A_REVERSE); + } } void ViewSelection::addChoice(std::string name, call_t call) { - choices.push_back(name); - calls.push_back(call); + choices.push_back(name); + calls.push_back(call); } call_t ViewSelection::keypress(int& key) { - call_t ret = nullptr; - switch(key) - { - case KEY_UP: - do - selection = (selection - 1 + choices.size()) % choices.size(); - while(!choices[selection].length() && choices.size()); - break; - - case '\t': - case KEY_DOWN: - do - selection = (selection + 1) % choices.size(); - while(!choices[selection].length() && choices.size()); - break; - - case KEY_MOUSE: - { - // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml - MEVENT event; - bool hit = false; - if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) - { - size_t column_start = start_x + choice_offset_x; - size_t row_start = start_y + choice_offset_y; - size_t mouse_x = event.x, mouse_y = event.y; - for(size_t i = 0; i < choices.size(); i++) - if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length()) - { - if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED) - hit = true; - selection = i; - } - } - if(!hit) - break; - - // fall through to next case - [[fallthrough]]; - } - - case KEY_ENT: - if(selection == choices.size() - 1) // exit - key = -1; // do return from view - else - ret = calls[selection]; - break; - default: - break; - } - repaint(); - return ret; + call_t ret = nullptr; + switch(key) + { + case KEY_UP: + do + selection = (selection - 1 + choices.size()) % choices.size(); + while(!choices[selection].length() && choices.size()); + break; + + case '\t': + case KEY_DOWN: + do + selection = (selection + 1) % choices.size(); + while(!choices[selection].length() && choices.size()); + break; + + case KEY_MOUSE: + { + // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml + MEVENT event; + bool hit = false; + if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED)) + { + size_t column_start = start_x + choice_offset_x; + size_t row_start = start_y + choice_offset_y; + size_t mouse_x = event.x, mouse_y = event.y; + for(size_t i = 0; i < choices.size(); i++) + if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length()) + { + if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED) + hit = true; + selection = i; + } + } + if(!hit) + break; + + // fall through to next case + [[fallthrough]]; + } + + case KEY_ENT: + if(selection == choices.size() - 1) // exit + key = -1; // do return from view + else + ret = calls[selection]; + break; + default: + break; + } + repaint(); + return ret; } diff --git a/control/src/ui/view_selection.h b/control/src/ui/view_selection.h index 4963f73..d97e062 100644 --- a/control/src/ui/view_selection.h +++ b/control/src/ui/view_selection.h @@ -5,20 +5,22 @@ #include #include "view.h" +/*! View for user selection input. */ + class ViewSelection : public View { public: - virtual void draw(void) override; - virtual void addChoice(std::string name, call_t call); - virtual call_t keypress(int& key) override; - + virtual void draw(void) override; + virtual void addChoice(std::string name, call_t call); + virtual call_t keypress(int& key) override; + protected: - size_t selection = 0; - std::vector choices; - - constexpr static int choice_offset_x = 2; - constexpr static int choice_offset_y = 3; + size_t selection = 0; + std::vector choices; + + constexpr static int choice_offset_x = 2; + constexpr static int choice_offset_y = 3; }; #endif // VIEW_SELECTION_H diff --git a/docs/html/annotated.html b/docs/html/annotated.html index 06ae8d2..e8fa8b6 100644 --- a/docs/html/annotated.html +++ b/docs/html/annotated.html @@ -85,7 +85,7 @@ $(function() { diff --git a/docs/html/b15f_8cpp_source.html b/docs/html/b15f_8cpp_source.html index a12e858..5efca6f 100644 --- a/docs/html/b15f_8cpp_source.html +++ b/docs/html/b15f_8cpp_source.html @@ -70,41 +70,46 @@ $(function() {
b15f.cpp
-
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
62  delay_ms(RECONNECT_TIMEOUT);
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--) {
131  str += static_cast<char>(usart.readByte());
132  }
133 
134  info.push_back(str);
135  }
136 
137  uint8_t aw = usart.readByte();
138  if(aw != MSG_OK)
139  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
140 
141  return info;
142 }
143 
145 {
146  usart.writeByte(RQ_ST);
147 
148  uint8_t aw = usart.readByte();
149  return aw == MSG_OK;
150 }
151 
152 bool B15F::digitalWrite0(uint8_t port)
153 {
154  usart.writeByte(RQ_BA0);
155  usart.writeByte(port);
156 
157  uint8_t aw = usart.readByte();
158  delay_us(10);
159  return aw == MSG_OK;
160 }
161 
162 bool B15F::digitalWrite1(uint8_t port)
163 {
164  usart.writeByte(RQ_BA1);
165  usart.writeByte(port);
166 
167  uint8_t aw = usart.readByte();
168  delay_us(10);
169  return aw == MSG_OK;
170 }
171 
173 {
174  usart.clearInputBuffer();
175  usart.writeByte(RQ_BE0);
176  uint8_t byte = usart.readByte();
177  delay_us(10);
178  return byte;
179 }
180 
182 {
183  usart.clearInputBuffer();
184  usart.writeByte(RQ_BE1);
185  uint8_t byte = usart.readByte();
186  delay_us(10);
187  return byte;
188 }
189 
191 {
192  usart.clearInputBuffer();
193  usart.writeByte(RQ_DSW);
194  uint8_t byte = usart.readByte();
195  delay_us(10);
196  return byte;
197 }
198 
199 bool B15F::analogWrite0(uint16_t value)
200 {
201  usart.writeByte(RQ_AA0);
202  usart.writeInt(value);
203 
204  uint8_t aw = usart.readByte();
205  delay_us(10);
206  return aw == MSG_OK;
207 }
208 
209 bool B15F::analogWrite1(uint16_t value)
210 {
211  usart.writeByte(RQ_AA1);
212  usart.writeInt(value);
213 
214  uint8_t aw = usart.readByte();
215  delay_us(10);
216  return aw == MSG_OK;
217 }
218 
219 uint16_t B15F::analogRead(uint8_t channel)
220 {
221  usart.clearInputBuffer();
222  if(channel > 7)
223  abort("Bad ADC channel: " + std::to_string(channel));
224 
225  uint8_t rq[] = {
226  RQ_ADC,
227  channel
228  };
229 
230  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
231  if(n_sent != sizeof(rq))
232  abort("Sent failed");
233 
234  uint16_t adc = usart.readInt();
235 
236  if(adc > 1023)
237  abort("Bad ADC data detected (1)");
238  return adc;
239 }
240 
241 void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
242 {
243  // check pointers
244  buffer_a += offset_a;
245  buffer_b += offset_b;
246 
247 
248  usart.clearInputBuffer();
249  usart.writeByte(RQ_ADC_DAC_STROKE);
250  usart.writeByte(channel_a);
251  usart.writeByte(channel_b);
252  usart.writeInt(start);
253  usart.writeInt(static_cast<uint16_t>(delta));
254  usart.writeInt(count);
255 
256  for(uint16_t i = 0; i < count; i++)
257  {
258  if(buffer_a)
259  {
260  buffer_a[i] = usart.readInt();
261 
262  if(buffer_a[i] > 1023) // check for broken usart connection
263  abort("Bad ADC data detected (2)");
264  }
265  else
266  {
267  usart.readInt();
268  }
269 
270  if(buffer_b)
271  {
272  buffer_b[i] = usart.readInt();
273 
274  if(buffer_b[i] > 1023) // check for broken usart connection
275  abort("Bad ADC data detected (3)");
276  }
277  else
278  {
279  usart.readInt();
280  }
281  }
282 
283  uint8_t aw = usart.readByte();
284  if(aw != MSG_OK)
285  abort("Sequenz unterbrochen");
286 
287  delay_us(10);
288 }
289 
290 void B15F::delay_ms(uint16_t ms)
291 {
292  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
293 }
294 
295 void B15F::delay_us(uint16_t us)
296 {
297  std::this_thread::sleep_for(std::chrono::microseconds(us));
298 }
299 
301 {
302  if(!instance)
303  instance = new B15F();
304 
305  return *instance;
306 }
307 
308 // https://stackoverflow.com/a/478960
309 std::string B15F::exec(std::string cmd) {
310  std::array<char, 128> buffer;
311  std::string result;
312  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
313  if (!pipe) {
314  throw std::runtime_error("popen() failed!");
315  }
316  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
317  result += buffer.data();
318  }
319  return result;
320 }
321 
322 void B15F::abort(std::string msg)
323 {
324  DriverException ex(msg);
325  abort(ex);
326 }
327 void B15F::abort(std::exception& ex)
328 {
329  if(errorhandler)
330  errorhandler(ex);
331  else
332  {
333  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
334  std::cout << ex.what() << std::endl;
335  throw DriverException(ex.what());
336  }
337 }
338 
339 void B15F::setAbortHandler(errorhandler_t func)
340 {
341  errorhandler = func;
342 }
-
static std::string exec(std::string cmd)
Definition: b15f.cpp:309
-
uint8_t readByte(void)
Definition: usart.cpp:210
-
void delay_us(uint16_t us)
Definition: b15f.cpp:295
-
uint8_t digitalRead0(void)
Definition: b15f.cpp:172
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:241
+
1 #include "b15f.h"
2 
3 B15F* B15F::instance = nullptr;
4 errorhandler_t B15F::errorhandler = nullptr;
5 
6 B15F::B15F()
7 {
8  init();
9 }
10 
11 void B15F::init()
12 {
13 
14  std::string device = exec("bash -c 'ls /dev/ttyUSB*'");
15  while(device.find(' ') != std::string::npos || device.find('\n') != std::string::npos || device.find('\t') != std::string::npos)
16  device.pop_back();
17 
18  if(device.length() == 0)
19  abort("Adapter nicht gefunden");
20 
21  std::cout << PRE << "Verwende Adapter: " << device << std::endl;
22 
23 
24 
25  std::cout << PRE << "Stelle Verbindung mit Adapter her... " << std::flush;
26  usart.setBaudrate(BAUDRATE);
27  usart.openDevice(device);
28  std::cout << "OK" << std::endl;
29 
30 
31 
32  std::cout << PRE << "Teste Verbindung... " << std::flush;
33  uint8_t tries = 3;
34  while(tries--)
35  {
36  // verwerfe Daten, die µC noch hat
37  //discard();
38 
39  if(!testConnection())
40  continue;
41 
42  if(!testIntConv())
43  continue;
44 
45  break;
46  }
47  if(tries == 0)
48  abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
49  std::cout << "OK" << std::endl;
50 
51 
52  // Gib board info aus
53  std::vector<std::string> info = getBoardInfo();
54  std::cout << PRE << "AVR Firmware Version: " << info[0] << " um " << info[1] << " Uhr (" << info[2] << ")" << std::endl;
55 }
56 
58 {
59  uint8_t tries = RECONNECT_TRIES;
60  while(tries--)
61  {
63  discard();
64 
65  if(testConnection())
66  return;
67  }
68 
69  abort("Verbindung kann nicht repariert werden");
70 }
71 
72 void B15F::discard(void)
73 {
74  try
75  {
76  usart.clearOutputBuffer();
77  for(uint8_t i = 0; i < 16; i++)
78  {
79  usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
80  delay_ms(4);
81  }
82  usart.clearInputBuffer();
83  }
84  catch(std::exception& ex)
85  {
86  abort(ex);
87  }
88 }
89 
91 {
92  // erzeuge zufälliges Byte
93  srand(time(NULL));
94  uint8_t dummy = rand() % 256;
95 
96  usart.writeByte(RQ_TEST);
97  usart.writeByte(dummy);
98 
99  uint8_t aw = usart.readByte();
100  uint8_t mirror = usart.readByte();
101 
102  return aw == MSG_OK && mirror == dummy;
103 }
104 
106 {
107  srand(time(NULL));
108  uint16_t dummy = rand() % (0xFFFF / 3);
109 
110  usart.writeByte(RQ_INT);
111  usart.writeInt(dummy);
112 
113  uint16_t aw = usart.readInt();
114  return aw == dummy * 3;
115 }
116 
117 
118 std::vector<std::string> B15F::getBoardInfo(void)
119 {
120  std::vector<std::string> info;
121 
122  usart.writeByte(RQ_INFO);
123 
124  uint8_t n = usart.readByte();
125  while(n--)
126  {
127  uint8_t len = usart.readByte();
128  std::string str;
129 
130  while(len--)
131  {
132  str += static_cast<char>(usart.readByte());
133  }
134 
135  info.push_back(str);
136  }
137 
138  uint8_t aw = usart.readByte();
139  if(aw != MSG_OK)
140  abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
141 
142  return info;
143 }
144 
146 {
147  usart.writeByte(RQ_ST);
148 
149  uint8_t aw = usart.readByte();
150  return aw == MSG_OK;
151 }
152 
153 bool B15F::digitalWrite0(uint8_t port)
154 {
155  usart.writeByte(RQ_BA0);
156  usart.writeByte(port);
157 
158  uint8_t aw = usart.readByte();
159  delay_us(10);
160  return aw == MSG_OK;
161 }
162 
163 bool B15F::digitalWrite1(uint8_t port)
164 {
165  usart.writeByte(RQ_BA1);
166  usart.writeByte(port);
167 
168  uint8_t aw = usart.readByte();
169  delay_us(10);
170  return aw == MSG_OK;
171 }
172 
174 {
175  usart.clearInputBuffer();
176  usart.writeByte(RQ_BE0);
177  uint8_t byte = usart.readByte();
178  delay_us(10);
179  return byte;
180 }
181 
183 {
184  usart.clearInputBuffer();
185  usart.writeByte(RQ_BE1);
186  uint8_t byte = usart.readByte();
187  delay_us(10);
188  return byte;
189 }
190 
192 {
193  usart.clearInputBuffer();
194  usart.writeByte(RQ_DSW);
195  uint8_t byte = usart.readByte();
196  delay_us(10);
197  return byte;
198 }
199 
200 bool B15F::analogWrite0(uint16_t value)
201 {
202  usart.writeByte(RQ_AA0);
203  usart.writeInt(value);
204 
205  uint8_t aw = usart.readByte();
206  delay_us(10);
207  return aw == MSG_OK;
208 }
209 
210 bool B15F::analogWrite1(uint16_t value)
211 {
212  usart.writeByte(RQ_AA1);
213  usart.writeInt(value);
214 
215  uint8_t aw = usart.readByte();
216  delay_us(10);
217  return aw == MSG_OK;
218 }
219 
220 uint16_t B15F::analogRead(uint8_t channel)
221 {
222  usart.clearInputBuffer();
223  if(channel > 7)
224  abort("Bad ADC channel: " + std::to_string(channel));
225 
226  uint8_t rq[] =
227  {
228  RQ_ADC,
229  channel
230  };
231 
232  int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
233  if(n_sent != sizeof(rq))
234  abort("Sent failed");
235 
236  uint16_t adc = usart.readInt();
237 
238  if(adc > 1023)
239  abort("Bad ADC data detected (1)");
240  return adc;
241 }
242 
243 void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
244 {
245  // check pointers
246  buffer_a += offset_a;
247  buffer_b += offset_b;
248 
249 
250  usart.clearInputBuffer();
251  usart.writeByte(RQ_ADC_DAC_STROKE);
252  usart.writeByte(channel_a);
253  usart.writeByte(channel_b);
254  usart.writeInt(start);
255  usart.writeInt(static_cast<uint16_t>(delta));
256  usart.writeInt(count);
257 
258  for(uint16_t i = 0; i < count; i++)
259  {
260  if(buffer_a)
261  {
262  buffer_a[i] = usart.readInt();
263 
264  if(buffer_a[i] > 1023) // check for broken usart connection
265  abort("Bad ADC data detected (2)");
266  }
267  else
268  {
269  usart.readInt();
270  }
271 
272  if(buffer_b)
273  {
274  buffer_b[i] = usart.readInt();
275 
276  if(buffer_b[i] > 1023) // check for broken usart connection
277  abort("Bad ADC data detected (3)");
278  }
279  else
280  {
281  usart.readInt();
282  }
283  }
284 
285  uint8_t aw = usart.readByte();
286  if(aw != MSG_OK)
287  abort("Sequenz unterbrochen");
288 
289  delay_us(10);
290 }
291 
292 void B15F::delay_ms(uint16_t ms)
293 {
294  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
295 }
296 
297 void B15F::delay_us(uint16_t us)
298 {
299  std::this_thread::sleep_for(std::chrono::microseconds(us));
300 }
301 
303 {
304  if(!instance)
305  instance = new B15F();
306 
307  return *instance;
308 }
309 
310 // https://stackoverflow.com/a/478960
311 std::string B15F::exec(std::string cmd)
312 {
313  std::array<char, 128> buffer;
314  std::string result;
315  std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
316  if (!pipe)
317  {
318  throw std::runtime_error("popen() failed!");
319  }
320  while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr)
321  {
322  result += buffer.data();
323  }
324  return result;
325 }
326 
327 void B15F::abort(std::string msg)
328 {
329  DriverException ex(msg);
330  abort(ex);
331 }
332 void B15F::abort(std::exception& ex)
333 {
334  if(errorhandler)
335  errorhandler(ex);
336  else
337  {
338  std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
339  std::cout << ex.what() << std::endl;
340  throw DriverException(ex.what());
341  }
342 }
343 
344 void B15F::setAbortHandler(errorhandler_t func)
345 {
346  errorhandler = func;
347 }
+
static std::string exec(std::string cmd)
Definition: b15f.cpp:311
+
uint8_t readByte(void)
Definition: usart.cpp:211
+
void delay_us(uint16_t us)
Definition: b15f.cpp:297
+
uint8_t digitalRead0(void)
Definition: b15f.cpp:173
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:243
bool testConnection(void)
Definition: b15f.cpp:90
-
uint8_t readDipSwitch(void)
Definition: b15f.cpp:190
-
void delay_ms(uint16_t ms)
Definition: b15f.cpp:290
-
bool analogWrite1(uint16_t)
Definition: b15f.cpp:209
-
static B15F & getInstance(void)
Definition: b15f.cpp:300
-
Definition: b15f.h:24
-
static void abort(std::string msg)
Definition: b15f.cpp:322
+
uint8_t readDipSwitch(void)
Definition: b15f.cpp:191
+
void delay_ms(uint16_t ms)
Definition: b15f.cpp:292
+
static B15F & getInstance(void)
Definition: b15f.cpp:302
+
Definition: b15f.h:26
+
static void abort(std::string msg)
Definition: b15f.cpp:327
void clearInputBuffer(void)
Definition: usart.cpp:39
void clearOutputBuffer(void)
Definition: usart.cpp:46
-
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:219
-
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:152
-
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:316
-
bool activateSelfTestMode(void)
Definition: b15f.cpp:144
+
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:220
+
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:153
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:199
+
void setBaudrate(uint32_t baudrate)
Definition: usart.cpp:317
+
bool activateSelfTestMode(void)
Definition: b15f.cpp:145
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:202
+
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:210
void writeByte(uint8_t b)
Definition: usart.cpp:67
-
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:162
+
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:163
void discard(void)
Definition: b15f.cpp:72
-
bool analogWrite0(uint16_t)
Definition: b15f.cpp:199
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:200
void openDevice(std::string device)
Definition: usart.cpp:3
-
uint16_t readInt(void)
Definition: usart.cpp:229
-
uint8_t digitalRead1(void)
Definition: b15f.cpp:181
+
uint16_t readInt(void)
Definition: usart.cpp:230
+
uint8_t digitalRead1(void)
Definition: b15f.cpp:182
void reconnect(void)
Definition: b15f.cpp:57
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:339
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:205
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:344
+
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:200
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:204
void writeInt(uint16_t d)
Definition: usart.cpp:81
bool testIntConv(void)
Definition: b15f.cpp:105
- + diff --git a/docs/html/b15f_8h_source.html b/docs/html/b15f_8h_source.html index 030198d..0f9eff8 100644 --- a/docs/html/b15f_8h_source.html +++ b/docs/html/b15f_8h_source.html @@ -70,33 +70,40 @@ $(function() {
b15f.h
-
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
24 class B15F
25 {
26 private:
27  // privater Konstruktor
28  B15F(void);
29 public:
30 
31  /*************************************
32  * Grundfunktionen des B15F Treibers *
33  *************************************/
34 
39  void reconnect(void);
40 
45  void discard(void);
46 
51  bool testConnection(void);
52 
57  bool testIntConv(void);
58 
63  std::vector<std::string> getBoardInfo(void);
64 
69  void delay_ms(uint16_t ms);
70 
75  void delay_us(uint16_t us);
76 
81  static B15F& getInstance(void);
82 
87  static std::string exec(std::string cmd);
88 
93  static void abort(std::string msg);
94 
99  static void abort(std::exception& ex);
100 
105  static void setAbortHandler(errorhandler_t func);
106 
107  /*************************************/
108 
109 
110 
111  /*************************
112  * Steuerbefehle für B15 *
113  *************************/
114 
120  bool activateSelfTestMode(void);
121 
127  bool digitalWrite0(uint8_t);
128 
134  bool digitalWrite1(uint8_t);
135 
141  uint8_t digitalRead0(void);
142 
148  uint8_t digitalRead1(void);
149 
155  uint8_t readDipSwitch(void);
156 
162  bool analogWrite0(uint16_t);
163 
169  bool analogWrite1(uint16_t);
170 
176  uint16_t analogRead(uint8_t channel);
177 
193  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
194 
195  /*************************/
196 
197 
198  // CONSTANTS
199  const std::string PRE = "[B15F] ";
200  constexpr static uint8_t MSG_OK = 0xFF;
201  constexpr static uint8_t MSG_FAIL = 0xFE;
202  constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
203  constexpr static uint16_t WDT_TIMEOUT = 15; // ms
204  constexpr static uint8_t RECONNECT_TRIES = 3;
205  constexpr static uint32_t BAUDRATE = 57600;
206 
207 private:
208 
213  void init(void);
214 
215  USART usart;
216  static B15F* instance;
217  static errorhandler_t errorhandler;
218 
219  // REQUESTS
220  constexpr static uint8_t RQ_DISC = 0;
221  constexpr static uint8_t RQ_TEST = 1;
222  constexpr static uint8_t RQ_INFO = 2;
223  constexpr static uint8_t RQ_INT = 3;
224  constexpr static uint8_t RQ_ST = 4;
225  constexpr static uint8_t RQ_BA0 = 5;
226  constexpr static uint8_t RQ_BA1 = 6;
227  constexpr static uint8_t RQ_BE0 = 7;
228  constexpr static uint8_t RQ_BE1 = 8;
229  constexpr static uint8_t RQ_DSW = 9;
230  constexpr static uint8_t RQ_AA0 = 10;
231  constexpr static uint8_t RQ_AA1 = 11;
232  constexpr static uint8_t RQ_ADC = 12;
233  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
234 };
235 
236 #endif // B15F_H
-
static std::string exec(std::string cmd)
Definition: b15f.cpp:309
-
void delay_us(uint16_t us)
Definition: b15f.cpp:295
-
uint8_t digitalRead0(void)
Definition: b15f.cpp:172
-
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:241
+
1 #ifndef B15F_H
2 #define B15F_H
3 
4 #include <iostream>
5 #include <bits/stdc++.h>
6 #include <string>
7 #include <fstream>
8 #include <cstdlib>
9 #include <chrono>
10 #include <cstdint>
11 #include <vector>
12 
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <termios.h>
17 #include "usart.h"
18 #include "driverexception.h"
19 #include "timeoutexception.h"
20 
21 typedef std::function<void(std::exception&)> errorhandler_t;
22 
23 
26 class B15F
27 {
28 private:
29  // privater Konstruktor
30  B15F(void);
31 public:
32 
33  /*************************************
34  * Grundfunktionen des B15F Treibers *
35  *************************************/
36 
41  void reconnect(void);
42 
47  void discard(void);
48 
53  bool testConnection(void);
54 
59  bool testIntConv(void);
60 
65  std::vector<std::string> getBoardInfo(void);
66 
71  void delay_ms(uint16_t ms);
72 
77  void delay_us(uint16_t us);
78 
83  static B15F& getInstance(void);
84 
89  static std::string exec(std::string cmd);
90 
95  static void abort(std::string msg);
96 
101  static void abort(std::exception& ex);
102 
107  static void setAbortHandler(errorhandler_t func);
108 
109  /*************************************/
110 
111 
112 
113  /*************************
114  * Steuerbefehle für B15 *
115  *************************/
116 
122  bool activateSelfTestMode(void);
123 
129  bool digitalWrite0(uint8_t);
130 
136  bool digitalWrite1(uint8_t);
137 
143  uint8_t digitalRead0(void);
144 
150  uint8_t digitalRead1(void);
151 
157  uint8_t readDipSwitch(void);
158 
164  bool analogWrite0(uint16_t port);
165 
171  bool analogWrite1(uint16_t port);
172 
178  uint16_t analogRead(uint8_t channel);
179 
195  void analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count);
196 
197  /*************************/
198 
199 
200  // CONSTANTS
201  const std::string PRE = "[B15F] ";
202  constexpr static uint8_t MSG_OK = 0xFF;
203  constexpr static uint8_t MSG_FAIL = 0xFE;
204  constexpr static uint16_t RECONNECT_TIMEOUT = 64;
205  constexpr static uint16_t WDT_TIMEOUT = 15;
206  constexpr static uint8_t RECONNECT_TRIES = 3;
207  constexpr static uint32_t BAUDRATE = 57600;
208 
209 private:
210 
215  void init(void);
216 
217  USART usart;
218  static B15F* instance;
219  static errorhandler_t errorhandler;
220 
221  // REQUESTS
222  constexpr static uint8_t RQ_DISC = 0;
223  constexpr static uint8_t RQ_TEST = 1;
224  constexpr static uint8_t RQ_INFO = 2;
225  constexpr static uint8_t RQ_INT = 3;
226  constexpr static uint8_t RQ_ST = 4;
227  constexpr static uint8_t RQ_BA0 = 5;
228  constexpr static uint8_t RQ_BA1 = 6;
229  constexpr static uint8_t RQ_BE0 = 7;
230  constexpr static uint8_t RQ_BE1 = 8;
231  constexpr static uint8_t RQ_DSW = 9;
232  constexpr static uint8_t RQ_AA0 = 10;
233  constexpr static uint8_t RQ_AA1 = 11;
234  constexpr static uint8_t RQ_ADC = 12;
235  constexpr static uint8_t RQ_ADC_DAC_STROKE = 13;
236 };
237 
238 #endif // B15F_H
+
static std::string exec(std::string cmd)
Definition: b15f.cpp:311
+
constexpr static uint8_t MSG_FAIL
Value to reject a received command.
Definition: b15f.h:201
+
void delay_us(uint16_t us)
Definition: b15f.cpp:297
+
uint8_t digitalRead0(void)
Definition: b15f.cpp:173
+
void analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
Definition: b15f.cpp:243
bool testConnection(void)
Definition: b15f.cpp:90
-
uint8_t readDipSwitch(void)
Definition: b15f.cpp:190
-
void delay_ms(uint16_t ms)
Definition: b15f.cpp:290
-
bool analogWrite1(uint16_t)
Definition: b15f.cpp:209
-
static B15F & getInstance(void)
Definition: b15f.cpp:300
-
Definition: b15f.h:24
-
static void abort(std::string msg)
Definition: b15f.cpp:322
-
Definition: usart.h:16
-
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:219
-
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:152
-
bool activateSelfTestMode(void)
Definition: b15f.cpp:144
+
uint8_t readDipSwitch(void)
Definition: b15f.cpp:191
+
void delay_ms(uint16_t ms)
Definition: b15f.cpp:292
+
static B15F & getInstance(void)
Definition: b15f.cpp:302
+
Definition: b15f.h:26
+
static void abort(std::string msg)
Definition: b15f.cpp:327
+
Definition: usart.h:18
+
uint16_t analogRead(uint8_t channel)
Definition: b15f.cpp:220
+
bool digitalWrite0(uint8_t)
Definition: b15f.cpp:153
+
const std::string PRE
B15F stdout prefix.
Definition: b15f.h:199
+
bool activateSelfTestMode(void)
Definition: b15f.cpp:145
std::vector< std::string > getBoardInfo(void)
Definition: b15f.cpp:118
-
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:162
+
constexpr static uint16_t RECONNECT_TIMEOUT
Time in ms after which a reconnect attempt aborts.
Definition: b15f.h:202
+
bool analogWrite1(uint16_t port)
Definition: b15f.cpp:210
+
bool digitalWrite1(uint8_t)
Definition: b15f.cpp:163
void discard(void)
Definition: b15f.cpp:72
-
bool analogWrite0(uint16_t)
Definition: b15f.cpp:199
-
uint8_t digitalRead1(void)
Definition: b15f.cpp:181
+
constexpr static uint8_t MSG_OK
Value to acknowledge a received command.
Definition: b15f.h:200
+
uint8_t digitalRead1(void)
Definition: b15f.cpp:182
+
constexpr static uint16_t WDT_TIMEOUT
Time in ms after which the watch dog timer resets the MCU.
Definition: b15f.h:203
void reconnect(void)
Definition: b15f.cpp:57
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:339
+
constexpr static uint32_t BAUDRATE
USART baudrate for communication with the MCU.
Definition: b15f.h:205
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:344
+
bool analogWrite0(uint16_t port)
Definition: b15f.cpp:200
+
constexpr static uint8_t RECONNECT_TRIES
Maximum count of reconnect attempts after which the driver stops.
Definition: b15f.h:204
bool testIntConv(void)
Definition: b15f.cpp:105
diff --git a/docs/html/classB15F-members.html b/docs/html/classB15F-members.html index 6ad79a3..1c32f74 100644 --- a/docs/html/classB15F-members.html +++ b/docs/html/classB15F-members.html @@ -74,9 +74,9 @@ $(function() { activateSelfTestMode(void)B15F analogRead(uint8_t channel)B15F analogSequence(uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)B15F - analogWrite0(uint16_t)B15F - analogWrite1(uint16_t)B15F - BAUDRATE (defined in B15F)B15Fstatic + analogWrite0(uint16_t port)B15F + analogWrite1(uint16_t port)B15F + BAUDRATEB15Fstatic delay_ms(uint16_t ms)B15F delay_us(uint16_t us)B15F digitalRead0(void)B15F @@ -87,21 +87,21 @@ $(function() { exec(std::string cmd)B15Fstatic getBoardInfo(void)B15F getInstance(void)B15Fstatic - MSG_FAIL (defined in B15F)B15Fstatic - MSG_OK (defined in B15F)B15Fstatic - PRE (defined in B15F)B15F + MSG_FAILB15Fstatic + MSG_OKB15Fstatic + PREB15F readDipSwitch(void)B15F reconnect(void)B15F - RECONNECT_TIMEOUT (defined in B15F)B15Fstatic - RECONNECT_TRIES (defined in B15F)B15Fstatic + RECONNECT_TIMEOUTB15Fstatic + RECONNECT_TRIESB15Fstatic setAbortHandler(errorhandler_t func)B15Fstatic testConnection(void)B15F testIntConv(void)B15F - WDT_TIMEOUT (defined in B15F)B15Fstatic + WDT_TIMEOUTB15Fstatic diff --git a/docs/html/classB15F.html b/docs/html/classB15F.html index d2c9e9b..7271305 100644 --- a/docs/html/classB15F.html +++ b/docs/html/classB15F.html @@ -72,6 +72,8 @@ $(function() {
B15F Class Reference
+ +

#include <b15f.h>

@@ -101,10 +103,10 @@ Public Member Functions - - - - + + + + @@ -126,33 +128,41 @@ Static Public Member Functions +const std::string  +

Public Member Functions

 
uint8_t readDipSwitch (void)
 
bool analogWrite0 (uint16_t)
 
bool analogWrite1 (uint16_t)
 
bool analogWrite0 (uint16_t port)
 
bool analogWrite1 (uint16_t port)
 
uint16_t analogRead (uint8_t channel)
 
void analogSequence (uint8_t channel_a, uint16_t *buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t *buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)

Public Attributes

-const std::string PRE = "[B15F] "
PRE = "[B15F] "
 B15F stdout prefix.
 
+constexpr static uint8_t  + +constexpr static uint8_t  + +constexpr static uint16_t  + +constexpr static uint16_t  + +constexpr static uint8_t  + +constexpr static uint32_t  +

Static Public Attributes

-constexpr static uint8_t MSG_OK = 0xFF
MSG_OK = 0xFF
 Value to acknowledge a received command.
 
-constexpr static uint8_t MSG_FAIL = 0xFE
MSG_FAIL = 0xFE
 Value to reject a received command.
 
-constexpr static uint16_t RECONNECT_TIMEOUT = 64
RECONNECT_TIMEOUT = 64
 Time in ms after which a reconnect attempt aborts.
 
-constexpr static uint16_t WDT_TIMEOUT = 15
WDT_TIMEOUT = 15
 Time in ms after which the watch dog timer resets the MCU.
 
-constexpr static uint8_t RECONNECT_TRIES = 3
RECONNECT_TRIES = 3
 Maximum count of reconnect attempts after which the driver stops.
 
-constexpr static uint32_t BAUDRATE = 57600
BAUDRATE = 57600
 USART baudrate for communication with the MCU.
 

Detailed Description

-
-

Definition at line 24 of file b15f.h.

+

main driver class

+ +

Definition at line 26 of file b15f.h.

Member Function Documentation

◆ abort() [1/2]

@@ -184,7 +194,7 @@ constexpr static uint32_t  -

Definition at line 327 of file b15f.cpp.

+

Definition at line 332 of file b15f.cpp.

@@ -218,7 +228,7 @@ constexpr static uint32_t  -

Definition at line 322 of file b15f.cpp.

+

Definition at line 327 of file b15f.cpp.

@@ -244,7 +254,7 @@ constexpr static uint32_t  -

Definition at line 144 of file b15f.cpp.

+

Definition at line 145 of file b15f.cpp.

@@ -276,7 +286,7 @@ constexpr static uint32_t  -

Definition at line 219 of file b15f.cpp.

+

Definition at line 220 of file b15f.cpp.

@@ -368,12 +378,12 @@ constexpr static uint32_t  -

Definition at line 241 of file b15f.cpp.

+

Definition at line 243 of file b15f.cpp.

- -

◆ analogWrite0()

+ +

◆ analogWrite0()

@@ -382,7 +392,7 @@ constexpr static uint32_t  bool B15F::analogWrite0 ( uint16_t  - value) + port) @@ -400,12 +410,12 @@ constexpr static uint32_t  -

Definition at line 199 of file b15f.cpp.

+

Definition at line 200 of file b15f.cpp.

- -

◆ analogWrite1()

+ +

◆ analogWrite1()

@@ -414,7 +424,7 @@ constexpr static uint32_t  bool B15F::analogWrite1 ( uint16_t  - value) + port) @@ -432,7 +442,7 @@ constexpr static uint32_t  -

Definition at line 209 of file b15f.cpp.

+

Definition at line 210 of file b15f.cpp.

@@ -458,7 +468,7 @@ constexpr static uint32_t  -

Definition at line 290 of file b15f.cpp.

+

Definition at line 292 of file b15f.cpp.

@@ -484,7 +494,7 @@ constexpr static uint32_t  -

Definition at line 295 of file b15f.cpp.

+

Definition at line 297 of file b15f.cpp.

@@ -511,7 +521,7 @@ constexpr static uint32_t  -

Definition at line 172 of file b15f.cpp.

+

Definition at line 173 of file b15f.cpp.

@@ -538,7 +548,7 @@ constexpr static uint32_t  -

Definition at line 181 of file b15f.cpp.

+

Definition at line 182 of file b15f.cpp.

@@ -570,7 +580,7 @@ constexpr static uint32_t  -

Definition at line 152 of file b15f.cpp.

+

Definition at line 153 of file b15f.cpp.

@@ -602,7 +612,7 @@ constexpr static uint32_t  -

Definition at line 162 of file b15f.cpp.

+

Definition at line 163 of file b15f.cpp.

@@ -662,7 +672,7 @@ constexpr static uint32_t  -

Definition at line 309 of file b15f.cpp.

+

Definition at line 311 of file b15f.cpp.

@@ -722,7 +732,7 @@ constexpr static uint32_t  -

Definition at line 300 of file b15f.cpp.

+

Definition at line 302 of file b15f.cpp.

@@ -749,7 +759,7 @@ constexpr static uint32_t  -

Definition at line 190 of file b15f.cpp.

+

Definition at line 191 of file b15f.cpp.

@@ -809,7 +819,7 @@ constexpr static uint32_t  -

Definition at line 339 of file b15f.cpp.

+

Definition at line 344 of file b15f.cpp.

@@ -872,7 +882,7 @@ constexpr static uint32_t  diff --git a/docs/html/classDot-members.html b/docs/html/classDot-members.html index 414ff4f..c1464ba 100644 --- a/docs/html/classDot-members.html +++ b/docs/html/classDot-members.html @@ -69,14 +69,14 @@ $(function() {

This is the complete list of members for Dot, including all inherited members.

- - - - + + + +
Dot(uint16_t x, uint16_t y, uint8_t curve) (defined in Dot)Dot
getCurve(void) const (defined in Dot)Dot
getX(void) const (defined in Dot)Dot
getY(void) const (defined in Dot)Dot
Dot(uint16_t x, uint16_t y, uint8_t curve)Dot
getCurve(void) constDot
getX(void) constDot
getY(void) constDot
diff --git a/docs/html/classDot.html b/docs/html/classDot.html index 537f60a..318fa5d 100644 --- a/docs/html/classDot.html +++ b/docs/html/classDot.html @@ -69,33 +69,134 @@ $(function() {
Dot Class Reference
+ +

#include <dot.h>

- + - + - + - +

Public Member Functions

Dot (uint16_t x, uint16_t y, uint8_t curve)
 Dot (uint16_t x, uint16_t y, uint8_t curve)
 
-uint16_t getX (void) const
uint16_t getX (void) const
 
-uint16_t getY (void) const
uint16_t getY (void) const
 
-uint8_t getCurve (void) const
uint8_t getCurve (void) const
 

Detailed Description

-
-

Definition at line 7 of file dot.h.

-

The documentation for this class was generated from the following files:
    +

    Immutable dot class with x and y coordinate and curve index. Dots with the same curve index get the same color by plotty.

    + +

    Definition at line 12 of file dot.h.

    +

    Constructor & Destructor Documentation

    + +

    ◆ Dot()

    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    Dot::Dot (uint16_t x,
    uint16_t y,
    uint8_t curve 
    )
    +
    +

    Constructor with x and y coordinate and curve index.

    + +

    Definition at line 3 of file dot.cpp.

    + +
    +
    +

    Member Function Documentation

    + +

    ◆ getCurve()

    + +
    +
    + + + + + + + + +
    uint8_t Dot::getCurve (void ) const
    +
    +

    Returns the curve index.

    + +

    Definition at line 19 of file dot.cpp.

    + +
    +
    + +

    ◆ getX()

    + +
    +
    + + + + + + + + +
    uint16_t Dot::getX (void ) const
    +
    +

    Returns the x coordinate.

    + +

    Definition at line 9 of file dot.cpp.

    + +
    +
    + +

    ◆ getY()

    + +
    +
    + + + + + + + + +
    uint16_t Dot::getY (void ) const
    +
    +

    Returns the y coordinate.

    + +

    Definition at line 14 of file dot.cpp.

    + +
    +
    +
    The documentation for this class was generated from the following files:
diff --git a/docs/html/classDriverException-members.html b/docs/html/classDriverException-members.html index d4c2560..848c1ce 100644 --- a/docs/html/classDriverException-members.html +++ b/docs/html/classDriverException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classDriverException.html b/docs/html/classDriverException.html index 1f469b3..5df8380 100644 --- a/docs/html/classDriverException.html +++ b/docs/html/classDriverException.html @@ -70,9 +70,13 @@ $(function() {
DriverException Class Reference
-
-Inheritance diagram for DriverException:
-
+ +

#include <driverexception.h>

+
+ + Inheritance diagram for DriverException:
+
+
+ @@ -96,15 +100,16 @@ std::string msg_<  

Detailed Description

-
-

Definition at line 8 of file driverexception.h.

+

Exception driver problems, for instance incompatible firmware version.

+ +

Definition at line 10 of file driverexception.h.


The documentation for this class was generated from the following file:
diff --git a/docs/html/classPlottyFile-members.html b/docs/html/classPlottyFile-members.html index 2486957..3e7bb5c 100644 --- a/docs/html/classPlottyFile-members.html +++ b/docs/html/classPlottyFile-members.html @@ -69,38 +69,38 @@ $(function() {

This is the complete list of members for PlottyFile, including all inherited members.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
addDot(Dot &dot) (defined in PlottyFile)PlottyFile
addDot(Dot dot) (defined in PlottyFile)PlottyFile
getDescPara(void) const (defined in PlottyFile)PlottyFile
getDescX(void) const (defined in PlottyFile)PlottyFile
getDescY(void) const (defined in PlottyFile)PlottyFile
getFunctionType(void) const (defined in PlottyFile)PlottyFile
getParaFirstCurve(void) const (defined in PlottyFile)PlottyFile
getParaStepWidth(void) const (defined in PlottyFile)PlottyFile
getQuadrant(void) const (defined in PlottyFile)PlottyFile
getRefX(void) const (defined in PlottyFile)PlottyFile
getRefY(void) const (defined in PlottyFile)PlottyFile
getUnitPara(void) const (defined in PlottyFile)PlottyFile
getUnitX(void) const (defined in PlottyFile)PlottyFile
getUnitY(void) const (defined in PlottyFile)PlottyFile
setDescPara(std::string) (defined in PlottyFile)PlottyFile
setDescX(std::string) (defined in PlottyFile)PlottyFile
setDescY(std::string) (defined in PlottyFile)PlottyFile
setFunctionType(FunctionType) (defined in PlottyFile)PlottyFile
setParaFirstCurve(uint16_t) (defined in PlottyFile)PlottyFile
setParaStepWidth(uint16_t) (defined in PlottyFile)PlottyFile
setQuadrant(uint8_t) (defined in PlottyFile)PlottyFile
setRefX(uint16_t) (defined in PlottyFile)PlottyFile
setRefY(uint16_t) (defined in PlottyFile)PlottyFile
setUnitPara(std::string) (defined in PlottyFile)PlottyFile
setUnitX(std::string) (defined in PlottyFile)PlottyFile
setUnitY(std::string) (defined in PlottyFile)PlottyFile
startPlotty(std::string filename) (defined in PlottyFile)PlottyFile
writeToFile(std::string filename) (defined in PlottyFile)PlottyFile
addDot(Dot &dot)PlottyFile
addDot(Dot dot)PlottyFile
getDescPara(void) constPlottyFile
getDescX(void) constPlottyFile
getDescY(void) constPlottyFile
getFunctionType(void) constPlottyFile
getParaFirstCurve(void) constPlottyFile
getParaStepWidth(void) constPlottyFile
getQuadrant(void) constPlottyFile
getRefX(void) constPlottyFile
getRefY(void) constPlottyFile
getUnitPara(void) constPlottyFile
getUnitX(void) constPlottyFile
getUnitY(void) constPlottyFile
setDescPara(std::string desc_para)PlottyFile
setDescX(std::string desc_x)PlottyFile
setDescY(std::string desc_y)PlottyFile
setFunctionType(FunctionType function_type)PlottyFile
setParaFirstCurve(uint16_t para_first)PlottyFile
setParaStepWidth(uint16_t para_stepwidth)PlottyFile
setQuadrant(uint8_t quadrant)PlottyFile
setRefX(uint16_t ref_x)PlottyFile
setRefY(uint16_t ref_y)PlottyFile
setUnitPara(std::string unit_para)PlottyFile
setUnitX(std::string unit_x)PlottyFile
setUnitY(std::string unit_y)PlottyFile
startPlotty(std::string filename)PlottyFile
writeToFile(std::string filename)PlottyFile
diff --git a/docs/html/classPlottyFile.html b/docs/html/classPlottyFile.html index e3e9672..d68ad8e 100644 --- a/docs/html/classPlottyFile.html +++ b/docs/html/classPlottyFile.html @@ -69,105 +69,749 @@ $(function() {
PlottyFile Class Reference
+ +

#include <plottyfile.h>

- + - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - +

Public Member Functions

-void addDot (Dot &dot)
void addDot (Dot &dot)
 
-void addDot (Dot dot)
void addDot (Dot dot)
 
-void setFunctionType (FunctionType)
 
-void setQuadrant (uint8_t)
 
-void setRefX (uint16_t)
 
-void setRefY (uint16_t)
 
-void setParaFirstCurve (uint16_t)
 
-void setParaStepWidth (uint16_t)
 
-void setUnitX (std::string)
 
-void setDescX (std::string)
 
-void setUnitY (std::string)
 
-void setDescY (std::string)
 
-void setUnitPara (std::string)
 
-void setDescPara (std::string)
 
-FunctionType getFunctionType (void) const
void setFunctionType (FunctionType function_type)
 
void setQuadrant (uint8_t quadrant)
 
void setRefX (uint16_t ref_x)
 
void setRefY (uint16_t ref_y)
 
void setParaFirstCurve (uint16_t para_first)
 
void setParaStepWidth (uint16_t para_stepwidth)
 
void setUnitX (std::string unit_x)
 
void setDescX (std::string desc_x)
 
void setUnitY (std::string unit_y)
 
void setDescY (std::string desc_y)
 
void setUnitPara (std::string unit_para)
 
void setDescPara (std::string desc_para)
 
FunctionType getFunctionType (void) const
 
-uint8_t getQuadrant (void) const
uint8_t getQuadrant (void) const
 
-uint16_t getRefX (void) const
uint16_t getRefX (void) const
 
-uint16_t getRefY (void) const
uint16_t getRefY (void) const
 
-uint16_t getParaFirstCurve (void) const
uint16_t getParaFirstCurve (void) const
 
-uint16_t getParaStepWidth (void) const
uint16_t getParaStepWidth (void) const
 
-std::string getUnitX (void) const
std::string getUnitX (void) const
 
-std::string getDescX (void) const
std::string getDescX (void) const
 
-std::string getUnitY (void) const
std::string getUnitY (void) const
 
-std::string getDescY (void) const
std::string getDescY (void) const
 
-std::string getUnitPara (void) const
std::string getUnitPara (void) const
 
-std::string getDescPara (void) const
std::string getDescPara (void) const
 
-void writeToFile (std::string filename)
void writeToFile (std::string filename)
 
-void startPlotty (std::string filename)
void startPlotty (std::string filename)
 

Detailed Description

-
-

Definition at line 17 of file plottyfile.h.

-

The documentation for this class was generated from the following files:
    +

    Wrapper class for convenient plot file creation, needed to display graphs using plotty.

    + +

    Definition at line 19 of file plottyfile.h.

    +

    Member Function Documentation

    + +

    ◆ addDot() [1/2]

    + +
    +
    + + + + + + + + +
    void PlottyFile::addDot (Dotdot)
    +
    +

    Adds a dot to the plotty file.

    Parameters
    + + +
    dotthe dot
    +
    +
    + +

    Definition at line 3 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ addDot() [2/2]

    + +
    +
    + + + + + + + + +
    void PlottyFile::addDot (Dot dot)
    +
    +

    Adds a dot by reference to the plotty file.

    Parameters
    + + +
    dotthe dot
    +
    +
    + +

    Definition at line 8 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getDescPara()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getDescPara (void ) const
    +
    +
    Returns
    description of parameter
    + +

    Definition at line 130 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getDescX()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getDescX (void ) const
    +
    +
    Returns
    description of x axis
    + +

    Definition at line 110 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getDescY()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getDescY (void ) const
    +
    +
    Returns
    description of y axis
    + +

    Definition at line 120 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getFunctionType()

    + +
    +
    + + + + + + + + +
    FunctionType PlottyFile::getFunctionType (void ) const
    +
    +
    Returns
    the FunctionType
    + +

    Definition at line 75 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getParaFirstCurve()

    + +
    +
    + + + + + + + + +
    uint16_t PlottyFile::getParaFirstCurve (void ) const
    +
    +
    Returns
    initial parameter value
    + +

    Definition at line 95 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getParaStepWidth()

    + +
    +
    + + + + + + + + +
    uint16_t PlottyFile::getParaStepWidth (void ) const
    +
    +
    Returns
    parameter stepwith
    + +

    Definition at line 100 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getQuadrant()

    + +
    +
    + + + + + + + + +
    uint8_t PlottyFile::getQuadrant (void ) const
    +
    +
    Returns
    the quadrant
    + +

    Definition at line 80 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getRefX()

    + +
    +
    + + + + + + + + +
    uint16_t PlottyFile::getRefX (void ) const
    +
    +
    Returns
    x reference (max) value
    + +

    Definition at line 85 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getRefY()

    + +
    +
    + + + + + + + + +
    uint16_t PlottyFile::getRefY (void ) const
    +
    +
    Returns
    y reference (max) value
    + +

    Definition at line 90 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getUnitPara()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getUnitPara (void ) const
    +
    +
    Returns
    unit of parameter
    + +

    Definition at line 125 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getUnitX()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getUnitX (void ) const
    +
    +
    Returns
    unit of x axis
    + +

    Definition at line 105 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ getUnitY()

    + +
    +
    + + + + + + + + +
    std::string PlottyFile::getUnitY (void ) const
    +
    +
    Returns
    unit of y axis
    + +

    Definition at line 115 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setDescPara()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setDescPara (std::string desc_para)
    +
    +

    Sets the description of the parameter.

    Parameters
    + + +
    para_firstdescription
    +
    +
    + +

    Definition at line 70 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setDescX()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setDescX (std::string desc_x)
    +
    +

    Sets the description of the x axis.

    Parameters
    + + +
    para_firstdescription
    +
    +
    + +

    Definition at line 50 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setDescY()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setDescY (std::string desc_y)
    +
    +

    Sets the description of the y axis.

    Parameters
    + + +
    para_firstdescription
    +
    +
    + +

    Definition at line 60 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setFunctionType()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setFunctionType (FunctionType function_type)
    +
    +

    Sets the FunctionType of this plotty file.

    Parameters
    + + +
    function_typeenum value
    +
    +
    + +

    Definition at line 13 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setParaFirstCurve()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setParaFirstCurve (uint16_t para_first)
    +
    +

    Sets initial value of the parameter. Gets used together with the stepwith to label the curves.

    Parameters
    + + +
    para_firstinitial parameter value
    +
    +
    + +

    Definition at line 35 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setParaStepWidth()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setParaStepWidth (uint16_t para_stepwidth)
    +
    +

    Sets the stepwith the parameter got increased with each curve.

    Parameters
    + + +
    para_firstparameter stepwith
    +
    +
    + +

    Definition at line 40 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setQuadrant()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setQuadrant (uint8_t quadrant)
    +
    +

    Sets the quadrant of this plot.

    Parameters
    + + +
    quadrantquadrant number (1..4)
    +
    +
    + +

    Definition at line 18 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setRefX()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setRefX (uint16_t ref_x)
    +
    +

    Sets reference (max) value of the x axis

    Parameters
    + + +
    ref_xreference value
    +
    +
    + +

    Definition at line 25 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setRefY()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setRefY (uint16_t ref_y)
    +
    +

    Sets reference (max) value of the y axis

    Parameters
    + + +
    ref_yreference value
    +
    +
    + +

    Definition at line 30 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setUnitPara()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setUnitPara (std::string unit_para)
    +
    +

    Sets the unit of the parameter.

    Parameters
    + + +
    para_firstunit
    +
    +
    + +

    Definition at line 65 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setUnitX()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setUnitX (std::string unit_x)
    +
    +

    Sets the unit of the x axis.

    Parameters
    + + +
    para_firstunit
    +
    +
    + +

    Definition at line 45 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ setUnitY()

    + +
    +
    + + + + + + + + +
    void PlottyFile::setUnitY (std::string unit_y)
    +
    +

    Sets the unit of the y axis.

    Parameters
    + + +
    para_firstunit
    +
    +
    + +

    Definition at line 55 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ startPlotty()

    + +
    +
    + + + + + + + + +
    void PlottyFile::startPlotty (std::string filename)
    +
    +

    Starts plotty with a plot file.

    Parameters
    + + +
    filenameplot path
    +
    +
    + +

    Definition at line 193 of file plottyfile.cpp.

    + +
    +
    + +

    ◆ writeToFile()

    + +
    +
    + + + + + + + + +
    void PlottyFile::writeToFile (std::string filename)
    +
    +

    Saves the PlottyFile in a binary format, ready to open with plotty.

    Parameters
    + + +
    filenamedesired plot path
    +
    +
    + +

    Definition at line 147 of file plottyfile.cpp.

    + +
    +
    +
    The documentation for this class was generated from the following files:
diff --git a/docs/html/classTimeoutException-members.html b/docs/html/classTimeoutException-members.html index 511f555..a656c56 100644 --- a/docs/html/classTimeoutException-members.html +++ b/docs/html/classTimeoutException-members.html @@ -78,7 +78,7 @@ $(function() { diff --git a/docs/html/classTimeoutException.html b/docs/html/classTimeoutException.html index 8419517..77727db 100644 --- a/docs/html/classTimeoutException.html +++ b/docs/html/classTimeoutException.html @@ -70,9 +70,13 @@ $(function() {
TimeoutException Class Reference
-
-Inheritance diagram for TimeoutException:
-
+ +

#include <timeoutexception.h>

+
+ + Inheritance diagram for TimeoutException:
+
+
+ @@ -99,15 +103,16 @@ int m_timeout 

Detailed Description

-
-

Definition at line 8 of file timeoutexception.h.

+

Exception for USART related timeouts.

+ +

Definition at line 10 of file timeoutexception.h.


The documentation for this class was generated from the following file:
diff --git a/docs/html/classUSART-members.html b/docs/html/classUSART-members.html index b80ed02..4dc25df 100644 --- a/docs/html/classUSART-members.html +++ b/docs/html/classUSART-members.html @@ -93,7 +93,7 @@ $(function() {
diff --git a/docs/html/classUSART.html b/docs/html/classUSART.html index 965f784..89274cc 100644 --- a/docs/html/classUSART.html +++ b/docs/html/classUSART.html @@ -70,6 +70,8 @@ $(function() {
USART Class Reference
+ +

#include <usart.h>

@@ -127,8 +129,9 @@ constexpr static uint8_t 

Public Member Functions

B
 

Detailed Description

-
-

Definition at line 16 of file usart.h.

+

C++ Wrapper class for termios usart library.

+ +

Definition at line 18 of file usart.h.

Member Function Documentation

◆ clearInputBuffer()

@@ -251,7 +254,7 @@ constexpr static uint8_t B

Liefert die eingestellte Baudrate Änderungen werden erst nach einem open() wirksam

-

Definition at line 306 of file usart.cpp.

+

Definition at line 307 of file usart.cpp.

@@ -272,7 +275,7 @@ constexpr static uint8_t B

Liefert den eingestellten Timeout (in Dezisekunden) Änderungen werden erst nach einem open() wirksam

-

Definition at line 311 of file usart.cpp.

+

Definition at line 312 of file usart.cpp.

@@ -351,7 +354,7 @@ constexpr static uint8_t B -

Definition at line 210 of file usart.cpp.

+

Definition at line 211 of file usart.cpp.

@@ -377,7 +380,7 @@ constexpr static uint8_t B -

Definition at line 229 of file usart.cpp.

+

Definition at line 230 of file usart.cpp.

@@ -398,7 +401,7 @@ constexpr static uint8_t B

Setzt die Baudrate Änderungen werden erst nach einem open() wirksam

-

Definition at line 316 of file usart.cpp.

+

Definition at line 317 of file usart.cpp.

@@ -419,7 +422,7 @@ constexpr static uint8_t B

Setzt den Timeout (in Dezisekunden) Änderungen werden erst nach einem open() wirksam

-

Definition at line 321 of file usart.cpp.

+

Definition at line 322 of file usart.cpp.

@@ -494,7 +497,7 @@ constexpr static uint8_t B diff --git a/docs/html/classUSARTException-members.html b/docs/html/classUSARTException-members.html index 2ec12b3..03df1bd 100644 --- a/docs/html/classUSARTException-members.html +++ b/docs/html/classUSARTException-members.html @@ -77,7 +77,7 @@ $(function() { diff --git a/docs/html/classUSARTException.html b/docs/html/classUSARTException.html index 956a359..4b9bc80 100644 --- a/docs/html/classUSARTException.html +++ b/docs/html/classUSARTException.html @@ -70,9 +70,13 @@ $(function() {
USARTException Class Reference
-
-Inheritance diagram for USARTException:
-
+ +

#include <usartexception.h>

+
+ + Inheritance diagram for USARTException:
+
+
+ @@ -96,15 +100,16 @@ std::string msg 

Detailed Description

-
-

Definition at line 9 of file usartexception.h.

+

Exception for USART problems, for instance buffer overflow.

+ +

Definition at line 11 of file usartexception.h.


The documentation for this class was generated from the following file:
diff --git a/docs/html/classView-members.html b/docs/html/classView-members.html index 2ce3664..94750c9 100644 --- a/docs/html/classView-members.html +++ b/docs/html/classView-members.html @@ -89,7 +89,7 @@ $(function() {
diff --git a/docs/html/classView.html b/docs/html/classView.html index cdc2f42..5c420fa 100644 --- a/docs/html/classView.html +++ b/docs/html/classView.html @@ -72,9 +72,13 @@ $(function() {
View Class Referenceabstract
-
-Inheritance diagram for View:
-
+ +

#include <view.h>

+
+ + Inheritance diagram for View:
+
+
+
-
-Inheritance diagram for ViewInfo:
-
+ +

#include <view_info.h>

+
+ + Inheritance diagram for ViewInfo:
+
+
+
-
-Inheritance diagram for ViewMonitor:
-
+ +

#include <view_monitor.h>

+
+ + Inheritance diagram for ViewMonitor:
+
+
+
-
-Inheritance diagram for ViewPromt:
-
+ +

#include <view_promt.h>

+
+ + Inheritance diagram for ViewPromt:
+
+
+
-
-Inheritance diagram for ViewSelection:
-
+ +

#include <view_selection.h>

+
+ + Inheritance diagram for ViewSelection:
+
+
+
-
1 #define B15F_CLI_DEBUG
2 
3 #include <stdio.h>
4 #include <ncurses.h> // sudo apt-get install libncurses5-dev
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <signal.h>
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include <future>
13 #include <thread>
14 #include <chrono>
15 #include "drv/b15f.h"
16 #include "ui/ui.h"
17 #include "ui/view_selection.h"
18 #include "ui/view_info.h"
19 #include "ui/view_monitor.h"
20 #include "ui/view_promt.h"
21 
22 volatile int win_changed_cooldown = 0;
23 volatile bool t_refresh_active = false;
24 
25 void signal_handler(int signal)
26 {
27  if(signal == SIGWINCH)
28  {
29  win_changed_cooldown = 10; // 100ms
30 
31  if (!t_refresh_active)
32  {
33  if(t_refresh.joinable())
34  t_refresh.join();
35  t_refresh_active = true;
36  t_refresh = std::thread([](){
37 
38  while(win_changed_cooldown--)
39  std::this_thread::sleep_for(std::chrono::milliseconds(10));
40 
41  t_refresh_active = false;
42 
43  if(win_stack.size())
44  win_stack.back()->repaint();
45 
46  });
47  }
48 
49  }
50  else if(signal == SIGINT)
51  {
52  cleanup();
53  std::cout << "SIGINT - Abbruch." << std::endl;
54  exit(EXIT_FAILURE);
55  }
56 }
57 
58 void abort_handler(std::exception& ex)
59 {
60  ViewInfo* view = new ViewInfo();
61  view->setTitle("Fehler");
62  std::string msg(ex.what());
63  msg += "\n\nBeende in 5 Sekunden.";
64  view->setText(msg.c_str());
65  view->setLabelClose("");
66  view->repaint();
67 
68  std::this_thread::sleep_for(std::chrono::milliseconds(5000));
69 
70  cleanup();
71  std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
72  exit(EXIT_FAILURE);
73 }
74 
75 void init()
76 {
77  // init b15 driver
79 #ifndef B15F_CLI_DEBUG
80  std::cout << std::endl << "Starte in 3s ..." << std::endl;
81  sleep(3);
82 #endif
83  B15F::setAbortHandler(&abort_handler);
84 
85  // init all ncurses stuff
86  initscr();
87  start_color();
88  curs_set(0); // 0: invisible, 1: normal, 2: very visible
89  clear();
90  noecho();
91  cbreak(); // Line buffering disabled. pass on everything
92  mousemask(ALL_MOUSE_EVENTS, NULL);
93 
94  // connect signals to handler
95  signal(SIGWINCH, signal_handler);
96  signal(SIGINT, signal_handler);
97 
98  // set view context
99  View::setWinContext(newwin(25, 85, 0, 0));
100 }
101 
102 
103 int main()
104 {
105  init();
106 
107  int exit_code = EXIT_SUCCESS;
108 
109  show_main(0);
110 
111  cleanup();
112 
113  return exit_code;
114 }
- -
static B15F & getInstance(void)
Definition: b15f.cpp:300
-
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:339
+
1 #define B15F_CLI_DEBUG
2 
3 #include <stdio.h>
4 #include <ncurses.h> // sudo apt-get install libncurses5-dev
5 #include <vector>
6 #include <string>
7 #include <iostream>
8 #include <signal.h>
9 #include <sys/ioctl.h>
10 #include <unistd.h>
11 #include <signal.h>
12 #include <future>
13 #include <thread>
14 #include <chrono>
15 #include "drv/b15f.h"
16 #include "ui/ui.h"
17 #include "ui/view_selection.h"
18 #include "ui/view_info.h"
19 #include "ui/view_monitor.h"
20 #include "ui/view_promt.h"
21 
22 volatile int win_changed_cooldown = 0;
23 volatile bool t_refresh_active = false;
24 
25 void signal_handler(int signal)
26 {
27  if(signal == SIGWINCH)
28  {
29  win_changed_cooldown = 10; // 100ms
30 
31  if (!t_refresh_active)
32  {
33  if(t_refresh.joinable())
34  t_refresh.join();
35  t_refresh_active = true;
36  t_refresh = std::thread([]()
37  {
38 
39  while(win_changed_cooldown--)
40  std::this_thread::sleep_for(std::chrono::milliseconds(10));
41 
42  t_refresh_active = false;
43 
44  if(win_stack.size())
45  win_stack.back()->repaint();
46 
47  });
48  }
49 
50  }
51  else if(signal == SIGINT)
52  {
53  cleanup();
54  std::cout << "SIGINT - Abbruch." << std::endl;
55  exit(EXIT_FAILURE);
56  }
57 }
58 
59 void abort_handler(std::exception& ex)
60 {
61  ViewInfo* view = new ViewInfo();
62  view->setTitle("Fehler");
63  std::string msg(ex.what());
64  msg += "\n\nBeende in 5 Sekunden.";
65  view->setText(msg.c_str());
66  view->setLabelClose("");
67  view->repaint();
68 
69  std::this_thread::sleep_for(std::chrono::milliseconds(5000));
70 
71  cleanup();
72  std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
73  exit(EXIT_FAILURE);
74 }
75 
76 void init()
77 {
78  // init b15 driver
80 #ifndef B15F_CLI_DEBUG
81  std::cout << std::endl << "Starte in 3s ..." << std::endl;
82  sleep(3);
83 #endif
84  B15F::setAbortHandler(&abort_handler);
85 
86  // init all ncurses stuff
87  initscr();
88  start_color();
89  curs_set(0); // 0: invisible, 1: normal, 2: very visible
90  clear();
91  noecho();
92  cbreak(); // Line buffering disabled. pass on everything
93  mousemask(ALL_MOUSE_EVENTS, NULL);
94 
95  // connect signals to handler
96  signal(SIGWINCH, signal_handler);
97  signal(SIGINT, signal_handler);
98 
99  // set view context
100  View::setWinContext(newwin(25, 85, 0, 0));
101 }
102 
103 
104 int main()
105 {
106  init();
107 
108  int exit_code = EXIT_SUCCESS;
109 
110  show_main(0);
111 
112  cleanup();
113 
114  return exit_code;
115 }
+ +
static B15F & getInstance(void)
Definition: b15f.cpp:302
+
static void setAbortHandler(errorhandler_t func)
Definition: b15f.cpp:344
diff --git a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html index f35095c..bebf28d 100644 --- a/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html +++ b/docs/html/dir_1788f8309b1a812dcb800a185471cf6c.html @@ -73,7 +73,7 @@ $(function() {
diff --git a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html index 10f6872..52fcf49 100644 --- a/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html +++ b/docs/html/dir_587c94d866dbb2f408f78cf41f9b2f8d.html @@ -73,7 +73,7 @@ $(function() {
diff --git a/docs/html/dot_8cpp_source.html b/docs/html/dot_8cpp_source.html index b5442fc..853835b 100644 --- a/docs/html/dot_8cpp_source.html +++ b/docs/html/dot_8cpp_source.html @@ -70,10 +70,14 @@ $(function() {
dot.cpp
-
1 #include "dot.h"
2 
3 Dot::Dot(uint16_t x, uint16_t y, uint8_t curve) : x(x), y(y), curve(curve)
4 {
5  if(curve >= 64)
6  throw std::range_error("Kurvenindex muss im Bereich [0, 63] liegen");
7 }
8 
9 uint16_t Dot::getX() const
10 {
11  return x;
12 }
13 
14 uint16_t Dot::getY() const
15 {
16  return y;
17 }
18 
19 uint8_t Dot::getCurve(void) const
20 {
21  return curve;
22 }
+
1 #include "dot.h"
2 
3 Dot::Dot(uint16_t x, uint16_t y, uint8_t curve) : x(x), y(y), curve(curve)
4 {
5  if(curve >= 64)
6  throw std::range_error("Kurvenindex muss im Bereich [0, 63] liegen");
7 }
8 
9 uint16_t Dot::getX() const
10 {
11  return x;
12 }
13 
14 uint16_t Dot::getY() const
15 {
16  return y;
17 }
18 
19 uint8_t Dot::getCurve(void) const
20 {
21  return curve;
22 }
+
uint16_t getX(void) const
Definition: dot.cpp:9
+
uint16_t getY(void) const
Definition: dot.cpp:14
+
uint8_t getCurve(void) const
Definition: dot.cpp:19
+
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/dot_8h_source.html b/docs/html/dot_8h_source.html index 695f88e..46b7ae7 100644 --- a/docs/html/dot_8h_source.html +++ b/docs/html/dot_8h_source.html @@ -70,11 +70,15 @@ $(function() {
dot.h
-
1 #ifndef DOT_H
2 #define DOT_H
3 
4 #include <cstdint>
5 #include <stdexcept>
6 
7 class Dot
8 {
9 public:
10  Dot(uint16_t x, uint16_t y, uint8_t curve);
11  uint16_t getX(void) const;
12  uint16_t getY(void) const;
13  uint8_t getCurve(void) const;
14 
15 private:
16  uint16_t x, y;
17  uint8_t curve;
18 };
19 
20 
21 #endif // DOT_H
-
Definition: dot.h:7
+
1 #ifndef DOT_H
2 #define DOT_H
3 
4 #include <cstdint>
5 #include <stdexcept>
6 
12 class Dot
13 {
14 public:
18  Dot(uint16_t x, uint16_t y, uint8_t curve);
19 
23  uint16_t getX(void) const;
24 
28  uint16_t getY(void) const;
29 
33  uint8_t getCurve(void) const;
34 
35 private:
36  uint16_t x, y;
37  uint8_t curve;
38 };
39 
40 
41 #endif // DOT_H
+
uint16_t getX(void) const
Definition: dot.cpp:9
+
Definition: dot.h:12
+
uint16_t getY(void) const
Definition: dot.cpp:14
+
uint8_t getCurve(void) const
Definition: dot.cpp:19
+
Dot(uint16_t x, uint16_t y, uint8_t curve)
Definition: dot.cpp:3
diff --git a/docs/html/driverexception_8h_source.html b/docs/html/driverexception_8h_source.html index a9c7385..25897b6 100644 --- a/docs/html/driverexception_8h_source.html +++ b/docs/html/driverexception_8h_source.html @@ -70,11 +70,11 @@ $(function() {
driverexception.h
-
1 #ifndef DRIVEREXCEPTION_H
2 #define DRIVEREXCEPTION_H
3 
4 #include <exception>
5 
6 // SOURCE: https://stackoverflow.com/a/8152888
7 
8 class DriverException: public std::exception
9 {
10 public:
11  explicit DriverException(const char* message) : msg_(message)
12  {
13  }
14 
15  explicit DriverException(const std::string& message) : msg_(message)
16  {
17  }
18 
19  virtual ~DriverException() throw ()
20  {
21  }
22 
23  virtual const char* what() const throw ()
24  {
25  return msg_.c_str();
26  }
27 
28 protected:
29  std::string msg_;
30 };
31 
32 #endif // DRIVEREXCEPTION_H
33 
- +
1 #ifndef DRIVEREXCEPTION_H
2 #define DRIVEREXCEPTION_H
3 
4 #include <exception>
5 
6 // SOURCE: https://stackoverflow.com/a/8152888
7 
10 class DriverException: public std::exception
11 {
12 public:
13  explicit DriverException(const char* message) : msg_(message)
14  {
15  }
16 
17  explicit DriverException(const std::string& message) : msg_(message)
18  {
19  }
20 
21  virtual ~DriverException() throw ()
22  {
23  }
24 
25  virtual const char* what() const throw ()
26  {
27  return msg_.c_str();
28  }
29 
30 protected:
31  std::string msg_;
32 };
33 
34 #endif // DRIVEREXCEPTION_H
35 
+ diff --git a/docs/html/files.html b/docs/html/files.html index e4b7368..92b9ab6 100644 --- a/docs/html/files.html +++ b/docs/html/files.html @@ -99,7 +99,7 @@ $(function() { diff --git a/docs/html/functions.html b/docs/html/functions.html index 1c5c177..1df7c12 100644 --- a/docs/html/functions.html +++ b/docs/html/functions.html @@ -71,6 +71,9 @@ $(function() {
  • activateSelfTestMode() : B15F
  • +
  • addDot() +: PlottyFile +
  • analogRead() : B15F
  • @@ -78,10 +81,17 @@ $(function() { : B15F
  • analogWrite0() -: B15F +: B15F
  • analogWrite1() -: B15F +: B15F +
  • + + + +

    - b -

    @@ -121,6 +131,9 @@ $(function() {
  • discard() : B15F
  • +
  • Dot() +: Dot +
  • @@ -145,12 +158,67 @@ $(function() {
  • getBoardInfo() : B15F
  • +
  • getCurve() +: Dot +
  • +
  • getDescPara() +: PlottyFile +
  • +
  • getDescX() +: PlottyFile +
  • +
  • getDescY() +: PlottyFile +
  • +
  • getFunctionType() +: PlottyFile +
  • getInstance() : B15F
  • +
  • getParaFirstCurve() +: PlottyFile +
  • +
  • getParaStepWidth() +: PlottyFile +
  • +
  • getQuadrant() +: PlottyFile +
  • +
  • getRefX() +: PlottyFile +
  • +
  • getRefY() +: PlottyFile +
  • getTimeout() : USART
  • +
  • getUnitPara() +: PlottyFile +
  • +
  • getUnitX() +: PlottyFile +
  • +
  • getUnitY() +: PlottyFile +
  • +
  • getX() +: Dot +
  • +
  • getY() +: Dot +
  • + + + +

    - m -

    @@ -162,6 +230,9 @@ $(function() {

    - p -

      +
    • PRE +: B15F +
    • printStatistics() : USART
    • @@ -181,6 +252,12 @@ $(function() {
    • reconnect() : B15F
    • +
    • RECONNECT_TIMEOUT +: B15F +
    • +
    • RECONNECT_TRIES +: B15F +
    @@ -191,9 +268,48 @@ $(function() {
  • setBaudrate() : USART
  • +
  • setDescPara() +: PlottyFile +
  • +
  • setDescX() +: PlottyFile +
  • +
  • setDescY() +: PlottyFile +
  • +
  • setFunctionType() +: PlottyFile +
  • +
  • setParaFirstCurve() +: PlottyFile +
  • +
  • setParaStepWidth() +: PlottyFile +
  • +
  • setQuadrant() +: PlottyFile +
  • +
  • setRefX() +: PlottyFile +
  • +
  • setRefY() +: PlottyFile +
  • setTimeout() : USART
  • +
  • setUnitPara() +: PlottyFile +
  • +
  • setUnitX() +: PlottyFile +
  • +
  • setUnitY() +: PlottyFile +
  • +
  • startPlotty() +: PlottyFile +
  • @@ -208,17 +324,23 @@ $(function() {

    - w -

    diff --git a/docs/html/functions_func.html b/docs/html/functions_func.html index 0a45dfa..4fbff3f 100644 --- a/docs/html/functions_func.html +++ b/docs/html/functions_func.html @@ -71,6 +71,9 @@ $(function() {
  • activateSelfTestMode() : B15F
  • +
  • addDot() +: PlottyFile +
  • analogRead() : B15F
  • @@ -78,10 +81,10 @@ $(function() { : B15F
  • analogWrite0() -: B15F +: B15F
  • analogWrite1() -: B15F +: B15F
  • @@ -121,6 +124,9 @@ $(function() {
  • discard() : B15F
  • +
  • Dot() +: Dot +
  • @@ -145,12 +151,57 @@ $(function() {
  • getBoardInfo() : B15F
  • +
  • getCurve() +: Dot +
  • +
  • getDescPara() +: PlottyFile +
  • +
  • getDescX() +: PlottyFile +
  • +
  • getDescY() +: PlottyFile +
  • +
  • getFunctionType() +: PlottyFile +
  • getInstance() : B15F
  • +
  • getParaFirstCurve() +: PlottyFile +
  • +
  • getParaStepWidth() +: PlottyFile +
  • +
  • getQuadrant() +: PlottyFile +
  • +
  • getRefX() +: PlottyFile +
  • +
  • getRefY() +: PlottyFile +
  • getTimeout() : USART
  • +
  • getUnitPara() +: PlottyFile +
  • +
  • getUnitX() +: PlottyFile +
  • +
  • getUnitY() +: PlottyFile +
  • +
  • getX() +: Dot +
  • +
  • getY() +: Dot +
  • @@ -191,9 +242,48 @@ $(function() {
  • setBaudrate() : USART
  • +
  • setDescPara() +: PlottyFile +
  • +
  • setDescX() +: PlottyFile +
  • +
  • setDescY() +: PlottyFile +
  • +
  • setFunctionType() +: PlottyFile +
  • +
  • setParaFirstCurve() +: PlottyFile +
  • +
  • setParaStepWidth() +: PlottyFile +
  • +
  • setQuadrant() +: PlottyFile +
  • +
  • setRefX() +: PlottyFile +
  • +
  • setRefY() +: PlottyFile +
  • setTimeout() : USART
  • +
  • setUnitPara() +: PlottyFile +
  • +
  • setUnitX() +: PlottyFile +
  • +
  • setUnitY() +: PlottyFile +
  • +
  • startPlotty() +: PlottyFile +
  • @@ -214,11 +304,14 @@ $(function() {
  • writeInt() : USART
  • +
  • writeToFile() +: PlottyFile +
  • diff --git a/docs/html/functions_vars.html b/docs/html/functions_vars.html new file mode 100644 index 0000000..c646f33 --- /dev/null +++ b/docs/html/functions_vars.html @@ -0,0 +1,96 @@ + + + + + + + +B15F: Class Members - Variables + + + + + + + + + +
    +
    + + + + + + +
    +
    B15F +
    +
    Board 15 Famulus Edition
    +
    +
    + + + + + + + +
    + +
    +
    + + +
    + +
    + +
      +
    • BAUDRATE +: B15F +
    • +
    • MSG_FAIL +: B15F +
    • +
    • MSG_OK +: B15F +
    • +
    • PRE +: B15F +
    • +
    • RECONNECT_TIMEOUT +: B15F +
    • +
    • RECONNECT_TRIES +: B15F +
    • +
    • WDT_TIMEOUT +: B15F +
    • +
    +
    + + + + diff --git a/docs/html/hierarchy.html b/docs/html/hierarchy.html index 5c42834..c8df567 100644 --- a/docs/html/hierarchy.html +++ b/docs/html/hierarchy.html @@ -86,7 +86,7 @@ $(function() { diff --git a/docs/html/index.html b/docs/html/index.html index 39eaa17..aa89bbd 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -72,7 +72,7 @@ Dort befindet sich auch eine Übersicht der verfügbaren Befehle.

    diff --git a/docs/html/menudata.js b/docs/html/menudata.js index 3c52b9d..311e0c2 100644 --- a/docs/html/menudata.js +++ b/docs/html/menudata.js @@ -29,11 +29,13 @@ var menudata={children:[ {text:"Class Members",url:"functions.html",children:[ {text:"All",url:"functions.html",children:[ {text:"a",url:"functions.html#index_a"}, +{text:"b",url:"functions.html#index_b"}, {text:"c",url:"functions.html#index_c"}, {text:"d",url:"functions.html#index_d"}, {text:"e",url:"functions.html#index_e"}, {text:"f",url:"functions.html#index_f"}, {text:"g",url:"functions.html#index_g"}, +{text:"m",url:"functions.html#index_m"}, {text:"o",url:"functions.html#index_o"}, {text:"p",url:"functions.html#index_p"}, {text:"r",url:"functions.html#index_r"}, @@ -52,6 +54,7 @@ var menudata={children:[ {text:"r",url:"functions_func.html#index_r"}, {text:"s",url:"functions_func.html#index_s"}, {text:"t",url:"functions_func.html#index_t"}, -{text:"w",url:"functions_func.html#index_w"}]}]}]}, +{text:"w",url:"functions_func.html#index_w"}]}, +{text:"Variables",url:"functions_vars.html"}]}]}, {text:"Files",url:"files.html",children:[ {text:"File List",url:"files.html"}]}]} diff --git a/docs/html/plottyfile_8cpp_source.html b/docs/html/plottyfile_8cpp_source.html index 75db2c6..c31ae5e 100644 --- a/docs/html/plottyfile_8cpp_source.html +++ b/docs/html/plottyfile_8cpp_source.html @@ -70,11 +70,38 @@ $(function() {
    plottyfile.cpp
    -
    1 #include "plottyfile.h"
    2 
    3 void PlottyFile::addDot(Dot& dot)
    4 {
    5  dots.push_back(dot);
    6 }
    7 
    8 void PlottyFile::addDot(Dot dot)
    9 {
    10  dots.push_back(dot);
    11 }
    12 
    13 void PlottyFile::setFunctionType(FunctionType function_type)
    14 {
    15  this->function_type = function_type;
    16 }
    17 
    18 void PlottyFile::setQuadrant(uint8_t quadrant)
    19 {
    20  if(quadrant < 1 || quadrant > 4)
    21  throw std::range_error("Ungueltiger Quadrant");
    22  this->quadrant = quadrant;
    23 }
    24 
    25 void PlottyFile::setRefX(uint16_t ref_x)
    26 {
    27  this->ref_x = ref_x;
    28 }
    29 
    30 void PlottyFile::setRefY(uint16_t ref_y)
    31 {
    32  this->ref_y = ref_y;
    33 }
    34 
    35 void PlottyFile::setParaFirstCurve(uint16_t para_first)
    36 {
    37  this->para_first = para_first;
    38 }
    39 
    40 void PlottyFile::setParaStepWidth(uint16_t para_stepwidth)
    41 {
    42  this->para_stepwidth = para_stepwidth;
    43 }
    44 
    45 void PlottyFile::setUnitX(std::string unit_x)
    46 {
    47  this->unit_x = unit_x;
    48 }
    49 
    50 void PlottyFile::setDescX(std::string desc_x)
    51 {
    52  this->desc_x = desc_x;
    53 }
    54 
    55 void PlottyFile::setUnitY(std::string unit_y)
    56 {
    57  this->unit_y = unit_y;
    58 }
    59 
    60 void PlottyFile::setDescY(std::string desc_y)
    61 {
    62  this->desc_y = desc_y;
    63 }
    64 
    65 void PlottyFile::setUnitPara(std::string unit_para)
    66 {
    67  this->unit_para = unit_para;
    68 }
    69 
    70 void PlottyFile::setDescPara(std::string desc_para)
    71 {
    72  this->desc_para = desc_para;
    73 }
    74 
    75 FunctionType PlottyFile::getFunctionType() const
    76 {
    77  return function_type;
    78 }
    79 
    80 uint8_t PlottyFile::getQuadrant() const
    81 {
    82  return quadrant;
    83 }
    84 
    85 uint16_t PlottyFile::getRefX() const
    86 {
    87  return ref_x;
    88 }
    89 
    90 uint16_t PlottyFile::getRefY() const
    91 {
    92  return ref_y;
    93 }
    94 
    95 uint16_t PlottyFile::getParaFirstCurve() const
    96 {
    97  return para_first;
    98 }
    99 
    100 uint16_t PlottyFile::getParaStepWidth() const
    101 {
    102  return para_stepwidth;
    103 }
    104 
    105 std::string PlottyFile::getUnitX() const
    106 {
    107  return unit_x;
    108 }
    109 
    110 std::string PlottyFile::getDescX() const
    111 {
    112  return desc_x;
    113 }
    114 
    115 std::string PlottyFile::getUnitY() const
    116 {
    117  return unit_y;
    118 }
    119 
    120 std::string PlottyFile::getDescY() const
    121 {
    122  return desc_y;
    123 }
    124 
    125 std::string PlottyFile::getUnitPara() const
    126 {
    127  return unit_para;
    128 }
    129 
    130 std::string PlottyFile::getDescPara() const
    131 {
    132  return desc_para;
    133 }
    134 
    135 void PlottyFile::prepStr(std::string& str, uint8_t len)
    136 {
    137  if(str.length() > len)
    138  throw std::runtime_error("Zu grosser String.");
    139 
    140  if(str.length() != len)
    141  str += '\n';
    142 
    143  while(str.length() < len)
    144  str += '\0';
    145 }
    146 
    147 void PlottyFile::writeToFile(std::string filename)
    148 {
    149  prepStr(unit_x, STR_LEN_SHORT);
    150  prepStr(desc_x, STR_LEN_LARGE);
    151  prepStr(unit_y, STR_LEN_SHORT);
    152  prepStr(desc_y, STR_LEN_LARGE);
    153  prepStr(unit_para, STR_LEN_SHORT);
    154  prepStr(desc_para, STR_LEN_LARGE);
    155 
    156  std::ofstream file(filename);
    157 
    158  // write file header
    159  file.write(reinterpret_cast<char*>(&command), 1);
    160  file.write(head.c_str(), head.length());
    161  file.write(filetype.c_str(), filetype.length());
    162  file.write(reinterpret_cast<char*>(&version), 2);
    163  file.write(reinterpret_cast<char*>(&subversion), 2);
    164  file.put(static_cast<uint8_t>(function_type));
    165  file.write(reinterpret_cast<char*>(&quadrant), 1);
    166  file.write(reinterpret_cast<char*>(&ref_x), 2);
    167  file.write(reinterpret_cast<char*>(&ref_y), 2);
    168  file.write(reinterpret_cast<char*>(&para_first), 2);
    169  file.write(reinterpret_cast<char*>(&para_stepwidth), 2);
    170  file.write(unit_x.c_str(), unit_x.length());
    171  file.write(desc_x.c_str(), desc_x.length());
    172  file.write(unit_y.c_str(), unit_y.length());
    173  file.write(desc_y.c_str(), desc_y.length());
    174  file.write(unit_para.c_str(), unit_para.length());
    175  file.write(desc_para.c_str(), desc_para.length());
    176  file.write(reinterpret_cast<const char*>(&eof), 1);
    177 
    178  // make sure header size is 256 Byte
    179  while(file.tellp() < 256)
    180  file.put(0);
    181 
    182  for(Dot& dot : dots)
    183  {
    184  file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getCurve()) << 2));
    185  file.put(dot.getX() & 0xFF);
    186  file.put(dot.getY() >> 8);
    187  file.put(dot.getY() & 0xFF);
    188  }
    189 
    190  file.close();
    191 }
    192 
    193 void PlottyFile::startPlotty(std::string filename)
    194 {
    195  int code = system(("plotty --in " + filename).c_str());
    196  if(code)
    197  throw std::runtime_error("Fehler beim Aufruf von plotty");
    198 }
    -
    Definition: dot.h:7
    +
    1 #include "plottyfile.h"
    2 
    4 {
    5  dots.push_back(dot);
    6 }
    7 
    9 {
    10  dots.push_back(dot);
    11 }
    12 
    13 void PlottyFile::setFunctionType(FunctionType function_type)
    14 {
    15  this->function_type = function_type;
    16 }
    17 
    18 void PlottyFile::setQuadrant(uint8_t quadrant)
    19 {
    20  if(quadrant < 1 || quadrant > 4)
    21  throw std::range_error("Ungueltiger Quadrant");
    22  this->quadrant = quadrant;
    23 }
    24 
    25 void PlottyFile::setRefX(uint16_t ref_x)
    26 {
    27  this->ref_x = ref_x;
    28 }
    29 
    30 void PlottyFile::setRefY(uint16_t ref_y)
    31 {
    32  this->ref_y = ref_y;
    33 }
    34 
    35 void PlottyFile::setParaFirstCurve(uint16_t para_first)
    36 {
    37  this->para_first = para_first;
    38 }
    39 
    40 void PlottyFile::setParaStepWidth(uint16_t para_stepwidth)
    41 {
    42  this->para_stepwidth = para_stepwidth;
    43 }
    44 
    45 void PlottyFile::setUnitX(std::string unit_x)
    46 {
    47  this->unit_x = unit_x;
    48 }
    49 
    50 void PlottyFile::setDescX(std::string desc_x)
    51 {
    52  this->desc_x = desc_x;
    53 }
    54 
    55 void PlottyFile::setUnitY(std::string unit_y)
    56 {
    57  this->unit_y = unit_y;
    58 }
    59 
    60 void PlottyFile::setDescY(std::string desc_y)
    61 {
    62  this->desc_y = desc_y;
    63 }
    64 
    65 void PlottyFile::setUnitPara(std::string unit_para)
    66 {
    67  this->unit_para = unit_para;
    68 }
    69 
    70 void PlottyFile::setDescPara(std::string desc_para)
    71 {
    72  this->desc_para = desc_para;
    73 }
    74 
    75 FunctionType PlottyFile::getFunctionType() const
    76 {
    77  return function_type;
    78 }
    79 
    80 uint8_t PlottyFile::getQuadrant() const
    81 {
    82  return quadrant;
    83 }
    84 
    85 uint16_t PlottyFile::getRefX() const
    86 {
    87  return ref_x;
    88 }
    89 
    90 uint16_t PlottyFile::getRefY() const
    91 {
    92  return ref_y;
    93 }
    94 
    96 {
    97  return para_first;
    98 }
    99 
    101 {
    102  return para_stepwidth;
    103 }
    104 
    105 std::string PlottyFile::getUnitX() const
    106 {
    107  return unit_x;
    108 }
    109 
    110 std::string PlottyFile::getDescX() const
    111 {
    112  return desc_x;
    113 }
    114 
    115 std::string PlottyFile::getUnitY() const
    116 {
    117  return unit_y;
    118 }
    119 
    120 std::string PlottyFile::getDescY() const
    121 {
    122  return desc_y;
    123 }
    124 
    125 std::string PlottyFile::getUnitPara() const
    126 {
    127  return unit_para;
    128 }
    129 
    130 std::string PlottyFile::getDescPara() const
    131 {
    132  return desc_para;
    133 }
    134 
    135 void PlottyFile::prepStr(std::string& str, uint8_t len)
    136 {
    137  if(str.length() > len)
    138  throw std::runtime_error("Zu grosser String.");
    139 
    140  if(str.length() != len)
    141  str += '\n';
    142 
    143  while(str.length() < len)
    144  str += '\0';
    145 }
    146 
    147 void PlottyFile::writeToFile(std::string filename)
    148 {
    149  prepStr(unit_x, STR_LEN_SHORT);
    150  prepStr(desc_x, STR_LEN_LARGE);
    151  prepStr(unit_y, STR_LEN_SHORT);
    152  prepStr(desc_y, STR_LEN_LARGE);
    153  prepStr(unit_para, STR_LEN_SHORT);
    154  prepStr(desc_para, STR_LEN_LARGE);
    155 
    156  std::ofstream file(filename);
    157 
    158  // write file header
    159  file.write(reinterpret_cast<char*>(&command), 1);
    160  file.write(head.c_str(), head.length());
    161  file.write(filetype.c_str(), filetype.length());
    162  file.write(reinterpret_cast<char*>(&version), 2);
    163  file.write(reinterpret_cast<char*>(&subversion), 2);
    164  file.put(static_cast<uint8_t>(function_type));
    165  file.write(reinterpret_cast<char*>(&quadrant), 1);
    166  file.write(reinterpret_cast<char*>(&ref_x), 2);
    167  file.write(reinterpret_cast<char*>(&ref_y), 2);
    168  file.write(reinterpret_cast<char*>(&para_first), 2);
    169  file.write(reinterpret_cast<char*>(&para_stepwidth), 2);
    170  file.write(unit_x.c_str(), unit_x.length());
    171  file.write(desc_x.c_str(), desc_x.length());
    172  file.write(unit_y.c_str(), unit_y.length());
    173  file.write(desc_y.c_str(), desc_y.length());
    174  file.write(unit_para.c_str(), unit_para.length());
    175  file.write(desc_para.c_str(), desc_para.length());
    176  file.write(reinterpret_cast<const char*>(&eof), 1);
    177 
    178  // make sure header size is 256 Byte
    179  while(file.tellp() < 256)
    180  file.put(0);
    181 
    182  for(Dot& dot : dots)
    183  {
    184  file.put((dot.getX() >> 8) | (static_cast<uint8_t>(dot.getCurve()) << 2));
    185  file.put(dot.getX() & 0xFF);
    186  file.put(dot.getY() >> 8);
    187  file.put(dot.getY() & 0xFF);
    188  }
    189 
    190  file.close();
    191 }
    192 
    193 void PlottyFile::startPlotty(std::string filename)
    194 {
    195  int code = system(("plotty --in " + filename).c_str());
    196  if(code)
    197  throw std::runtime_error("Fehler beim Aufruf von plotty");
    198 }
    +
    void setParaStepWidth(uint16_t para_stepwidth)
    Definition: plottyfile.cpp:40
    +
    uint8_t getQuadrant(void) const
    Definition: plottyfile.cpp:80
    +
    void startPlotty(std::string filename)
    Definition: plottyfile.cpp:193
    +
    void writeToFile(std::string filename)
    Definition: plottyfile.cpp:147
    +
    void setUnitX(std::string unit_x)
    Definition: plottyfile.cpp:45
    +
    void setUnitPara(std::string unit_para)
    Definition: plottyfile.cpp:65
    +
    void setDescY(std::string desc_y)
    Definition: plottyfile.cpp:60
    +
    void setQuadrant(uint8_t quadrant)
    Definition: plottyfile.cpp:18
    +
    std::string getDescY(void) const
    Definition: plottyfile.cpp:120
    +
    void setRefY(uint16_t ref_y)
    Definition: plottyfile.cpp:30
    +
    std::string getDescX(void) const
    Definition: plottyfile.cpp:110
    +
    void setFunctionType(FunctionType function_type)
    Definition: plottyfile.cpp:13
    +
    void setDescX(std::string desc_x)
    Definition: plottyfile.cpp:50
    +
    Definition: dot.h:12
    +
    void setRefX(uint16_t ref_x)
    Definition: plottyfile.cpp:25
    +
    void setUnitY(std::string unit_y)
    Definition: plottyfile.cpp:55
    +
    void addDot(Dot &dot)
    Definition: plottyfile.cpp:3
    +
    void setDescPara(std::string desc_para)
    Definition: plottyfile.cpp:70
    +
    uint16_t getParaStepWidth(void) const
    Definition: plottyfile.cpp:100
    +
    std::string getDescPara(void) const
    Definition: plottyfile.cpp:130
    +
    void setParaFirstCurve(uint16_t para_first)
    Definition: plottyfile.cpp:35
    +
    std::string getUnitY(void) const
    Definition: plottyfile.cpp:115
    +
    uint16_t getParaFirstCurve(void) const
    Definition: plottyfile.cpp:95
    +
    uint16_t getRefX(void) const
    Definition: plottyfile.cpp:85
    +
    std::string getUnitPara(void) const
    Definition: plottyfile.cpp:125
    +
    FunctionType getFunctionType(void) const
    Definition: plottyfile.cpp:75
    +
    uint16_t getRefY(void) const
    Definition: plottyfile.cpp:90
    +
    std::string getUnitX(void) const
    Definition: plottyfile.cpp:105
    diff --git a/docs/html/plottyfile_8h_source.html b/docs/html/plottyfile_8h_source.html index a263325..4fdc771 100644 --- a/docs/html/plottyfile_8h_source.html +++ b/docs/html/plottyfile_8h_source.html @@ -70,12 +70,39 @@ $(function() {
    plottyfile.h
    -
    1 #ifndef PLOTTYFILE_H
    2 #define PLOTTYFILE_H
    3 
    4 #include <iostream>
    5 #include <fstream>
    6 #include <exception>
    7 #include <vector>
    8 #include "dot.h"
    9 
    10 enum FunctionType
    11 {
    12  CurveFamily = 'S',
    13  Curve = 'C',
    14  Level = 'P'
    15 };
    16 
    18 {
    19 public:
    20  void addDot(Dot& dot);
    21  void addDot(Dot dot);
    22 
    23  void setFunctionType(FunctionType);
    24  void setQuadrant(uint8_t);
    25  void setRefX(uint16_t);
    26  void setRefY(uint16_t);
    27  void setParaFirstCurve(uint16_t);
    28  void setParaStepWidth(uint16_t);
    29  void setUnitX(std::string);
    30  void setDescX(std::string);
    31  void setUnitY(std::string);
    32  void setDescY(std::string);
    33  void setUnitPara(std::string);
    34  void setDescPara(std::string);
    35 
    36  FunctionType getFunctionType(void) const;
    37  uint8_t getQuadrant(void) const;
    38  uint16_t getRefX(void) const;
    39  uint16_t getRefY(void) const;
    40  uint16_t getParaFirstCurve(void) const;
    41  uint16_t getParaStepWidth(void) const;
    42  std::string getUnitX(void) const;
    43  std::string getDescX(void) const;
    44  std::string getUnitY(void) const;
    45  std::string getDescY(void) const;
    46  std::string getUnitPara(void) const;
    47  std::string getDescPara(void) const;
    48 
    49  void writeToFile(std::string filename);
    50  void startPlotty(std::string filename);
    51 private:
    52  void prepStr(std::string& str, uint8_t len);
    53 
    54  std::vector<Dot> dots;
    55 
    56  int8_t command = 0x1D;
    57  const std::string head = "HTWK-HWLab";
    58  const std::string filetype = "MD";
    59  int16_t version = 1;
    60  int16_t subversion = 0;
    61  FunctionType function_type = FunctionType::Curve;
    62  uint8_t quadrant = 1;
    63  uint16_t ref_x = 1023;
    64  uint16_t ref_y = 1023;
    65  uint16_t para_first = 1;
    66  uint16_t para_stepwidth = 1;
    67  std::string unit_x;
    68  std::string desc_x;
    69  std::string unit_y;
    70  std::string desc_y;
    71  std::string unit_para;
    72  std::string desc_para;
    73  const uint8_t eof = 0xD;
    74 
    75  constexpr static uint8_t STR_LEN_SHORT = 10;
    76  constexpr static uint8_t STR_LEN_LARGE = 20;
    77 };
    78 
    79 #endif // PLOTTYFILE_H
    - -
    Definition: dot.h:7
    +
    1 #ifndef PLOTTYFILE_H
    2 #define PLOTTYFILE_H
    3 
    4 #include <iostream>
    5 #include <fstream>
    6 #include <exception>
    7 #include <vector>
    8 #include "dot.h"
    9 
    10 enum FunctionType
    11 {
    12  CurveFamily = 'S',
    13  Curve = 'C',
    14  Level = 'P'
    15 };
    16 
    20 {
    21 public:
    26  void addDot(Dot& dot);
    27 
    32  void addDot(Dot dot);
    33 
    38  void setFunctionType(FunctionType function_type);
    39 
    44  void setQuadrant(uint8_t quadrant);
    45 
    50  void setRefX(uint16_t ref_x);
    51 
    56  void setRefY(uint16_t ref_y);
    57 
    63  void setParaFirstCurve(uint16_t para_first);
    64 
    69  void setParaStepWidth(uint16_t para_stepwidth);
    70 
    75  void setUnitX(std::string unit_x);
    76 
    81  void setDescX(std::string desc_x);
    82 
    87  void setUnitY(std::string unit_y);
    88 
    93  void setDescY(std::string desc_y);
    94 
    99  void setUnitPara(std::string unit_para);
    104  void setDescPara(std::string desc_para);
    105 
    106 
    107 
    111  FunctionType getFunctionType(void) const;
    112 
    116  uint8_t getQuadrant(void) const;
    117 
    121  uint16_t getRefX(void) const;
    122 
    126  uint16_t getRefY(void) const;
    127 
    131  uint16_t getParaFirstCurve(void) const;
    132 
    136  uint16_t getParaStepWidth(void) const;
    137 
    141  std::string getUnitX(void) const;
    142 
    146  std::string getDescX(void) const;
    147 
    151  std::string getUnitY(void) const;
    152 
    156  std::string getDescY(void) const;
    157 
    161  std::string getUnitPara(void) const;
    162 
    166  std::string getDescPara(void) const;
    167 
    168 
    173  void writeToFile(std::string filename);
    174 
    179  void startPlotty(std::string filename);
    180 private:
    181  void prepStr(std::string& str, uint8_t len);
    182 
    183  std::vector<Dot> dots;
    184 
    185  int8_t command = 0x1D;
    186  const std::string head = "HTWK-HWLab";
    187  const std::string filetype = "MD";
    188  int16_t version = 1;
    189  int16_t subversion = 0;
    190  FunctionType function_type = FunctionType::Curve;
    191  uint8_t quadrant = 1;
    192  uint16_t ref_x = 1023;
    193  uint16_t ref_y = 1023;
    194  uint16_t para_first = 1;
    195  uint16_t para_stepwidth = 1;
    196  std::string unit_x;
    197  std::string desc_x;
    198  std::string unit_y;
    199  std::string desc_y;
    200  std::string unit_para;
    201  std::string desc_para;
    202  const uint8_t eof = 0xD;
    203 
    204  constexpr static uint8_t STR_LEN_SHORT = 10;
    205  constexpr static uint8_t STR_LEN_LARGE = 20;
    206 };
    207 
    208 #endif // PLOTTYFILE_H
    +
    void setParaStepWidth(uint16_t para_stepwidth)
    Definition: plottyfile.cpp:40
    +
    uint8_t getQuadrant(void) const
    Definition: plottyfile.cpp:80
    +
    void startPlotty(std::string filename)
    Definition: plottyfile.cpp:193
    +
    void writeToFile(std::string filename)
    Definition: plottyfile.cpp:147
    +
    void setUnitX(std::string unit_x)
    Definition: plottyfile.cpp:45
    +
    void setUnitPara(std::string unit_para)
    Definition: plottyfile.cpp:65
    +
    void setDescY(std::string desc_y)
    Definition: plottyfile.cpp:60
    +
    void setQuadrant(uint8_t quadrant)
    Definition: plottyfile.cpp:18
    +
    std::string getDescY(void) const
    Definition: plottyfile.cpp:120
    + +
    void setRefY(uint16_t ref_y)
    Definition: plottyfile.cpp:30
    +
    std::string getDescX(void) const
    Definition: plottyfile.cpp:110
    +
    void setFunctionType(FunctionType function_type)
    Definition: plottyfile.cpp:13
    +
    void setDescX(std::string desc_x)
    Definition: plottyfile.cpp:50
    +
    Definition: dot.h:12
    +
    void setRefX(uint16_t ref_x)
    Definition: plottyfile.cpp:25
    +
    void setUnitY(std::string unit_y)
    Definition: plottyfile.cpp:55
    +
    void addDot(Dot &dot)
    Definition: plottyfile.cpp:3
    +
    void setDescPara(std::string desc_para)
    Definition: plottyfile.cpp:70
    +
    uint16_t getParaStepWidth(void) const
    Definition: plottyfile.cpp:100
    +
    std::string getDescPara(void) const
    Definition: plottyfile.cpp:130
    +
    void setParaFirstCurve(uint16_t para_first)
    Definition: plottyfile.cpp:35
    +
    std::string getUnitY(void) const
    Definition: plottyfile.cpp:115
    +
    uint16_t getParaFirstCurve(void) const
    Definition: plottyfile.cpp:95
    +
    uint16_t getRefX(void) const
    Definition: plottyfile.cpp:85
    +
    std::string getUnitPara(void) const
    Definition: plottyfile.cpp:125
    +
    FunctionType getFunctionType(void) const
    Definition: plottyfile.cpp:75
    +
    uint16_t getRefY(void) const
    Definition: plottyfile.cpp:90
    +
    std::string getUnitX(void) const
    Definition: plottyfile.cpp:105
    diff --git a/docs/html/search/all_0.js b/docs/html/search/all_0.js index ebee3d5..c4bd927 100644 --- a/docs/html/search/all_0.js +++ b/docs/html/search/all_0.js @@ -2,8 +2,9 @@ var searchData= [ ['abort',['abort',['../classB15F.html#a3f09a418f9e3be5d1d750e4515c96f1e',1,'B15F::abort(std::string msg)'],['../classB15F.html#ac962a6a49bddd0e261a8c7d3aded23f8',1,'B15F::abort(std::exception &ex)']]], ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#ad9bf80ee2485fb5aac9926c6ef0731f1',1,'B15F']]], + ['adddot',['addDot',['../classPlottyFile.html#ae091e6eaaca16302f17572ac7dec6f7c',1,'PlottyFile::addDot(Dot &dot)'],['../classPlottyFile.html#a80e4b45219b4e9571992edfc28a28568',1,'PlottyFile::addDot(Dot dot)']]], ['analogread',['analogRead',['../classB15F.html#ae0bd1f69751e2dc3c462db9213fc4627',1,'B15F']]], ['analogsequence',['analogSequence',['../classB15F.html#ab82a324426c3063318c6cafb3089ae02',1,'B15F']]], - ['analogwrite0',['analogWrite0',['../classB15F.html#a5c5583d591afdd3f9501856c6b0ba3e3',1,'B15F']]], - ['analogwrite1',['analogWrite1',['../classB15F.html#a63d67795879cdc0b035c9c970e7d6fc3',1,'B15F']]] + ['analogwrite0',['analogWrite0',['../classB15F.html#afc55fd590c7fa5c942d100cb60c4b0d3',1,'B15F']]], + ['analogwrite1',['analogWrite1',['../classB15F.html#a7f1becceac744f5cd2ad529748fd836f',1,'B15F']]] ]; diff --git a/docs/html/search/all_1.js b/docs/html/search/all_1.js index 7622f87..4a50fd7 100644 --- a/docs/html/search/all_1.js +++ b/docs/html/search/all_1.js @@ -1,4 +1,5 @@ var searchData= [ - ['b15f',['B15F',['../classB15F.html',1,'']]] + ['b15f',['B15F',['../classB15F.html',1,'']]], + ['baudrate',['BAUDRATE',['../classB15F.html#a7d548d6861cfc69753161bf9cda14f87',1,'B15F']]] ]; diff --git a/docs/html/search/all_3.js b/docs/html/search/all_3.js index 196425e..08afc23 100644 --- a/docs/html/search/all_3.js +++ b/docs/html/search/all_3.js @@ -7,6 +7,6 @@ var searchData= ['digitalwrite0',['digitalWrite0',['../classB15F.html#a13797edea1c50278988373acbd110064',1,'B15F']]], ['digitalwrite1',['digitalWrite1',['../classB15F.html#aa225e7fc813849634063e071ef25db1b',1,'B15F']]], ['discard',['discard',['../classB15F.html#ae4740cd473f40a1a4121dfa66b25e1d5',1,'B15F']]], - ['dot',['Dot',['../classDot.html',1,'']]], + ['dot',['Dot',['../classDot.html',1,'Dot'],['../classDot.html#ad975f119c0627a928790b3cd5ca6da05',1,'Dot::Dot()']]], ['driverexception',['DriverException',['../classDriverException.html',1,'']]] ]; diff --git a/docs/html/search/all_6.js b/docs/html/search/all_6.js index fc75b8c..c269a53 100644 --- a/docs/html/search/all_6.js +++ b/docs/html/search/all_6.js @@ -2,6 +2,21 @@ var searchData= [ ['getbaudrate',['getBaudrate',['../classUSART.html#a4918672d8069df205378a528b1892db3',1,'USART']]], ['getboardinfo',['getBoardInfo',['../classB15F.html#a4f01677e73d6d172a2c1cae9427a591b',1,'B15F']]], + ['getcurve',['getCurve',['../classDot.html#ad0ae7dc1a9be3d8d985affc089b34396',1,'Dot']]], + ['getdescpara',['getDescPara',['../classPlottyFile.html#a536967daae3b382a5d6575f55450e198',1,'PlottyFile']]], + ['getdescx',['getDescX',['../classPlottyFile.html#a9cf7baa569be308c2cf6e07cadded09d',1,'PlottyFile']]], + ['getdescy',['getDescY',['../classPlottyFile.html#ab4a847fd71a804182f211233e194df45',1,'PlottyFile']]], + ['getfunctiontype',['getFunctionType',['../classPlottyFile.html#a88bb7d8350ed5fbc7a40e8d903c94bdb',1,'PlottyFile']]], ['getinstance',['getInstance',['../classB15F.html#a8b4533d232c55ef2aa967e39e2d23380',1,'B15F']]], - ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]] + ['getparafirstcurve',['getParaFirstCurve',['../classPlottyFile.html#a40828c93d66fe80166c4f603d5bdfa48',1,'PlottyFile']]], + ['getparastepwidth',['getParaStepWidth',['../classPlottyFile.html#a9da23f2bb8e6eb1837fc992ffd4057db',1,'PlottyFile']]], + ['getquadrant',['getQuadrant',['../classPlottyFile.html#a54e94e80061a27614f2d4d63697d3376',1,'PlottyFile']]], + ['getrefx',['getRefX',['../classPlottyFile.html#a7dd84b9f0826f3220fc6b5a4f1ce9890',1,'PlottyFile']]], + ['getrefy',['getRefY',['../classPlottyFile.html#ae6650c61a3b1a610ce716253418bd7f2',1,'PlottyFile']]], + ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]], + ['getunitpara',['getUnitPara',['../classPlottyFile.html#abcda4139adf8c5ab8a93b13b84ac097c',1,'PlottyFile']]], + ['getunitx',['getUnitX',['../classPlottyFile.html#af952ac5e2c40896acaf6a86063874fe3',1,'PlottyFile']]], + ['getunity',['getUnitY',['../classPlottyFile.html#a746b96036872dbece204e9739f3413b6',1,'PlottyFile']]], + ['getx',['getX',['../classDot.html#a029f0cc99c474122b77a708a317e7f77',1,'Dot']]], + ['gety',['getY',['../classDot.html#a8fcb987e6308d8184d1a2c8692227e58',1,'Dot']]] ]; diff --git a/docs/html/search/all_7.js b/docs/html/search/all_7.js index bd75d34..fd5dff3 100644 --- a/docs/html/search/all_7.js +++ b/docs/html/search/all_7.js @@ -1,4 +1,5 @@ var searchData= [ - ['opendevice',['openDevice',['../classUSART.html#a5f7e2abda2ec4a68a5fdb8ee2f8a940a',1,'USART']]] + ['msg_5ffail',['MSG_FAIL',['../classB15F.html#a77d1ecf24b406c9204665d3b09c36f1e',1,'B15F']]], + ['msg_5fok',['MSG_OK',['../classB15F.html#ab01299858f74a6cec598688562e0ad02',1,'B15F']]] ]; diff --git a/docs/html/search/all_8.js b/docs/html/search/all_8.js index 8232ab7..bd75d34 100644 --- a/docs/html/search/all_8.js +++ b/docs/html/search/all_8.js @@ -1,5 +1,4 @@ var searchData= [ - ['plottyfile',['PlottyFile',['../classPlottyFile.html',1,'']]], - ['printstatistics',['printStatistics',['../classUSART.html#a33559bb8f0eda33a489d47b9c9227b59',1,'USART']]] + ['opendevice',['openDevice',['../classUSART.html#a5f7e2abda2ec4a68a5fdb8ee2f8a940a',1,'USART']]] ]; diff --git a/docs/html/search/all_9.js b/docs/html/search/all_9.js index 5d35f1d..b1c5b0a 100644 --- a/docs/html/search/all_9.js +++ b/docs/html/search/all_9.js @@ -1,7 +1,6 @@ var searchData= [ - ['readbyte',['readByte',['../classUSART.html#a8f54b98b26bfe084359a5604bda82562',1,'USART']]], - ['readdipswitch',['readDipSwitch',['../classB15F.html#a6f858f21ea81d491b5031b3644a2239a',1,'B15F']]], - ['readint',['readInt',['../classUSART.html#a1534c229db71a375e556cf1e7d0b8119',1,'USART']]], - ['reconnect',['reconnect',['../classB15F.html#a52557b375443c180a044e7d4e80a1ae7',1,'B15F']]] + ['plottyfile',['PlottyFile',['../classPlottyFile.html',1,'']]], + ['pre',['PRE',['../classB15F.html#a3b0fc1f85954b2d9c145af4a3af5b1ec',1,'B15F']]], + ['printstatistics',['printStatistics',['../classUSART.html#a33559bb8f0eda33a489d47b9c9227b59',1,'USART']]] ]; diff --git a/docs/html/search/all_a.js b/docs/html/search/all_a.js index 4f4d28c..9759958 100644 --- a/docs/html/search/all_a.js +++ b/docs/html/search/all_a.js @@ -1,6 +1,9 @@ var searchData= [ - ['setaborthandler',['setAbortHandler',['../classB15F.html#a55b0cd1ea582bda53d6979442640f8e9',1,'B15F']]], - ['setbaudrate',['setBaudrate',['../classUSART.html#aac63918a8b97ae63ee607cfa39e6d88d',1,'USART']]], - ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]] + ['readbyte',['readByte',['../classUSART.html#a8f54b98b26bfe084359a5604bda82562',1,'USART']]], + ['readdipswitch',['readDipSwitch',['../classB15F.html#a6f858f21ea81d491b5031b3644a2239a',1,'B15F']]], + ['readint',['readInt',['../classUSART.html#a1534c229db71a375e556cf1e7d0b8119',1,'USART']]], + ['reconnect',['reconnect',['../classB15F.html#a52557b375443c180a044e7d4e80a1ae7',1,'B15F']]], + ['reconnect_5ftimeout',['RECONNECT_TIMEOUT',['../classB15F.html#a040951746fbfd632e12bd1ad14578816',1,'B15F']]], + ['reconnect_5ftries',['RECONNECT_TRIES',['../classB15F.html#a6c4895bdbcd71ff6743becf97985c2dc',1,'B15F']]] ]; diff --git a/docs/html/search/all_b.js b/docs/html/search/all_b.js index 57a58a5..588c06f 100644 --- a/docs/html/search/all_b.js +++ b/docs/html/search/all_b.js @@ -1,6 +1,19 @@ var searchData= [ - ['testconnection',['testConnection',['../classB15F.html#af01983594f2af98ab2b1e514aa036a5d',1,'B15F']]], - ['testintconv',['testIntConv',['../classB15F.html#a7b8a0e2a9156f7dcb05d097f23666a78',1,'B15F']]], - ['timeoutexception',['TimeoutException',['../classTimeoutException.html',1,'']]] + ['setaborthandler',['setAbortHandler',['../classB15F.html#a55b0cd1ea582bda53d6979442640f8e9',1,'B15F']]], + ['setbaudrate',['setBaudrate',['../classUSART.html#aac63918a8b97ae63ee607cfa39e6d88d',1,'USART']]], + ['setdescpara',['setDescPara',['../classPlottyFile.html#a431904143c3c1164a2e8b8cfec3c77ab',1,'PlottyFile']]], + ['setdescx',['setDescX',['../classPlottyFile.html#aa0449c290265d55d6223b19cf0a88b0a',1,'PlottyFile']]], + ['setdescy',['setDescY',['../classPlottyFile.html#a38a3a4dfc76bc70523727584bf01d590',1,'PlottyFile']]], + ['setfunctiontype',['setFunctionType',['../classPlottyFile.html#a4e5ab1ebb012a5cc1a3d6458a4cd512f',1,'PlottyFile']]], + ['setparafirstcurve',['setParaFirstCurve',['../classPlottyFile.html#aa676414793becb975506f48d6e949dd0',1,'PlottyFile']]], + ['setparastepwidth',['setParaStepWidth',['../classPlottyFile.html#a6caebd31e04e2e7081cc007047350355',1,'PlottyFile']]], + ['setquadrant',['setQuadrant',['../classPlottyFile.html#a1953ee0d9a87b7353c16139584e9c2ae',1,'PlottyFile']]], + ['setrefx',['setRefX',['../classPlottyFile.html#a80c2c2e97a454566f9c1f2c51e1d7f3e',1,'PlottyFile']]], + ['setrefy',['setRefY',['../classPlottyFile.html#a3a371228ddcc007e97eebe7cc04dffc2',1,'PlottyFile']]], + ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]], + ['setunitpara',['setUnitPara',['../classPlottyFile.html#abbac84109a1e0958a4ca5c270fac0986',1,'PlottyFile']]], + ['setunitx',['setUnitX',['../classPlottyFile.html#ab8d35a841ca9c325fca671cf34e03527',1,'PlottyFile']]], + ['setunity',['setUnitY',['../classPlottyFile.html#abb18c814f435926f741f7ceb310f3059',1,'PlottyFile']]], + ['startplotty',['startPlotty',['../classPlottyFile.html#a08a115ef10458cadfe76077d623313df',1,'PlottyFile']]] ]; diff --git a/docs/html/search/all_c.js b/docs/html/search/all_c.js index c030e1b..57a58a5 100644 --- a/docs/html/search/all_c.js +++ b/docs/html/search/all_c.js @@ -1,5 +1,6 @@ var searchData= [ - ['usart',['USART',['../classUSART.html',1,'']]], - ['usartexception',['USARTException',['../classUSARTException.html',1,'']]] + ['testconnection',['testConnection',['../classB15F.html#af01983594f2af98ab2b1e514aa036a5d',1,'B15F']]], + ['testintconv',['testIntConv',['../classB15F.html#a7b8a0e2a9156f7dcb05d097f23666a78',1,'B15F']]], + ['timeoutexception',['TimeoutException',['../classTimeoutException.html',1,'']]] ]; diff --git a/docs/html/search/all_d.js b/docs/html/search/all_d.js index 27f785f..c030e1b 100644 --- a/docs/html/search/all_d.js +++ b/docs/html/search/all_d.js @@ -1,8 +1,5 @@ var searchData= [ - ['view',['View',['../classView.html',1,'']]], - ['viewinfo',['ViewInfo',['../classViewInfo.html',1,'']]], - ['viewmonitor',['ViewMonitor',['../classViewMonitor.html',1,'']]], - ['viewpromt',['ViewPromt',['../classViewPromt.html',1,'']]], - ['viewselection',['ViewSelection',['../classViewSelection.html',1,'']]] + ['usart',['USART',['../classUSART.html',1,'']]], + ['usartexception',['USARTException',['../classUSARTException.html',1,'']]] ]; diff --git a/docs/html/search/all_e.js b/docs/html/search/all_e.js index 88b07d9..27f785f 100644 --- a/docs/html/search/all_e.js +++ b/docs/html/search/all_e.js @@ -1,5 +1,8 @@ var searchData= [ - ['writebyte',['writeByte',['../classUSART.html#a60eadbe9956bab8144ee96d89eacd9f5',1,'USART']]], - ['writeint',['writeInt',['../classUSART.html#a78b30d9aa863f38745e982860392599a',1,'USART']]] + ['view',['View',['../classView.html',1,'']]], + ['viewinfo',['ViewInfo',['../classViewInfo.html',1,'']]], + ['viewmonitor',['ViewMonitor',['../classViewMonitor.html',1,'']]], + ['viewpromt',['ViewPromt',['../classViewPromt.html',1,'']]], + ['viewselection',['ViewSelection',['../classViewSelection.html',1,'']]] ]; diff --git a/docs/html/search/all_f.html b/docs/html/search/all_f.html new file mode 100644 index 0000000..ca42a52 --- /dev/null +++ b/docs/html/search/all_f.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/all_f.js b/docs/html/search/all_f.js new file mode 100644 index 0000000..021aad6 --- /dev/null +++ b/docs/html/search/all_f.js @@ -0,0 +1,7 @@ +var searchData= +[ + ['wdt_5ftimeout',['WDT_TIMEOUT',['../classB15F.html#a158d13bc84aed6430cdede1396384e06',1,'B15F']]], + ['writebyte',['writeByte',['../classUSART.html#a60eadbe9956bab8144ee96d89eacd9f5',1,'USART']]], + ['writeint',['writeInt',['../classUSART.html#a78b30d9aa863f38745e982860392599a',1,'USART']]], + ['writetofile',['writeToFile',['../classPlottyFile.html#a82c348e7fade2edcbc907e7c2bc2e305',1,'PlottyFile']]] +]; diff --git a/docs/html/search/functions_0.js b/docs/html/search/functions_0.js index ebee3d5..c4bd927 100644 --- a/docs/html/search/functions_0.js +++ b/docs/html/search/functions_0.js @@ -2,8 +2,9 @@ var searchData= [ ['abort',['abort',['../classB15F.html#a3f09a418f9e3be5d1d750e4515c96f1e',1,'B15F::abort(std::string msg)'],['../classB15F.html#ac962a6a49bddd0e261a8c7d3aded23f8',1,'B15F::abort(std::exception &ex)']]], ['activateselftestmode',['activateSelfTestMode',['../classB15F.html#ad9bf80ee2485fb5aac9926c6ef0731f1',1,'B15F']]], + ['adddot',['addDot',['../classPlottyFile.html#ae091e6eaaca16302f17572ac7dec6f7c',1,'PlottyFile::addDot(Dot &dot)'],['../classPlottyFile.html#a80e4b45219b4e9571992edfc28a28568',1,'PlottyFile::addDot(Dot dot)']]], ['analogread',['analogRead',['../classB15F.html#ae0bd1f69751e2dc3c462db9213fc4627',1,'B15F']]], ['analogsequence',['analogSequence',['../classB15F.html#ab82a324426c3063318c6cafb3089ae02',1,'B15F']]], - ['analogwrite0',['analogWrite0',['../classB15F.html#a5c5583d591afdd3f9501856c6b0ba3e3',1,'B15F']]], - ['analogwrite1',['analogWrite1',['../classB15F.html#a63d67795879cdc0b035c9c970e7d6fc3',1,'B15F']]] + ['analogwrite0',['analogWrite0',['../classB15F.html#afc55fd590c7fa5c942d100cb60c4b0d3',1,'B15F']]], + ['analogwrite1',['analogWrite1',['../classB15F.html#a7f1becceac744f5cd2ad529748fd836f',1,'B15F']]] ]; diff --git a/docs/html/search/functions_2.js b/docs/html/search/functions_2.js index 970150a..7c01e06 100644 --- a/docs/html/search/functions_2.js +++ b/docs/html/search/functions_2.js @@ -6,5 +6,6 @@ var searchData= ['digitalread1',['digitalRead1',['../classB15F.html#afc76b612dd4faeee0ac02a66b65af5f2',1,'B15F']]], ['digitalwrite0',['digitalWrite0',['../classB15F.html#a13797edea1c50278988373acbd110064',1,'B15F']]], ['digitalwrite1',['digitalWrite1',['../classB15F.html#aa225e7fc813849634063e071ef25db1b',1,'B15F']]], - ['discard',['discard',['../classB15F.html#ae4740cd473f40a1a4121dfa66b25e1d5',1,'B15F']]] + ['discard',['discard',['../classB15F.html#ae4740cd473f40a1a4121dfa66b25e1d5',1,'B15F']]], + ['dot',['Dot',['../classDot.html#ad975f119c0627a928790b3cd5ca6da05',1,'Dot']]] ]; diff --git a/docs/html/search/functions_5.js b/docs/html/search/functions_5.js index fc75b8c..c269a53 100644 --- a/docs/html/search/functions_5.js +++ b/docs/html/search/functions_5.js @@ -2,6 +2,21 @@ var searchData= [ ['getbaudrate',['getBaudrate',['../classUSART.html#a4918672d8069df205378a528b1892db3',1,'USART']]], ['getboardinfo',['getBoardInfo',['../classB15F.html#a4f01677e73d6d172a2c1cae9427a591b',1,'B15F']]], + ['getcurve',['getCurve',['../classDot.html#ad0ae7dc1a9be3d8d985affc089b34396',1,'Dot']]], + ['getdescpara',['getDescPara',['../classPlottyFile.html#a536967daae3b382a5d6575f55450e198',1,'PlottyFile']]], + ['getdescx',['getDescX',['../classPlottyFile.html#a9cf7baa569be308c2cf6e07cadded09d',1,'PlottyFile']]], + ['getdescy',['getDescY',['../classPlottyFile.html#ab4a847fd71a804182f211233e194df45',1,'PlottyFile']]], + ['getfunctiontype',['getFunctionType',['../classPlottyFile.html#a88bb7d8350ed5fbc7a40e8d903c94bdb',1,'PlottyFile']]], ['getinstance',['getInstance',['../classB15F.html#a8b4533d232c55ef2aa967e39e2d23380',1,'B15F']]], - ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]] + ['getparafirstcurve',['getParaFirstCurve',['../classPlottyFile.html#a40828c93d66fe80166c4f603d5bdfa48',1,'PlottyFile']]], + ['getparastepwidth',['getParaStepWidth',['../classPlottyFile.html#a9da23f2bb8e6eb1837fc992ffd4057db',1,'PlottyFile']]], + ['getquadrant',['getQuadrant',['../classPlottyFile.html#a54e94e80061a27614f2d4d63697d3376',1,'PlottyFile']]], + ['getrefx',['getRefX',['../classPlottyFile.html#a7dd84b9f0826f3220fc6b5a4f1ce9890',1,'PlottyFile']]], + ['getrefy',['getRefY',['../classPlottyFile.html#ae6650c61a3b1a610ce716253418bd7f2',1,'PlottyFile']]], + ['gettimeout',['getTimeout',['../classUSART.html#a19cf777956a038878fc2d2b58c3d2b41',1,'USART']]], + ['getunitpara',['getUnitPara',['../classPlottyFile.html#abcda4139adf8c5ab8a93b13b84ac097c',1,'PlottyFile']]], + ['getunitx',['getUnitX',['../classPlottyFile.html#af952ac5e2c40896acaf6a86063874fe3',1,'PlottyFile']]], + ['getunity',['getUnitY',['../classPlottyFile.html#a746b96036872dbece204e9739f3413b6',1,'PlottyFile']]], + ['getx',['getX',['../classDot.html#a029f0cc99c474122b77a708a317e7f77',1,'Dot']]], + ['gety',['getY',['../classDot.html#a8fcb987e6308d8184d1a2c8692227e58',1,'Dot']]] ]; diff --git a/docs/html/search/functions_9.js b/docs/html/search/functions_9.js index 4f4d28c..588c06f 100644 --- a/docs/html/search/functions_9.js +++ b/docs/html/search/functions_9.js @@ -2,5 +2,18 @@ var searchData= [ ['setaborthandler',['setAbortHandler',['../classB15F.html#a55b0cd1ea582bda53d6979442640f8e9',1,'B15F']]], ['setbaudrate',['setBaudrate',['../classUSART.html#aac63918a8b97ae63ee607cfa39e6d88d',1,'USART']]], - ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]] + ['setdescpara',['setDescPara',['../classPlottyFile.html#a431904143c3c1164a2e8b8cfec3c77ab',1,'PlottyFile']]], + ['setdescx',['setDescX',['../classPlottyFile.html#aa0449c290265d55d6223b19cf0a88b0a',1,'PlottyFile']]], + ['setdescy',['setDescY',['../classPlottyFile.html#a38a3a4dfc76bc70523727584bf01d590',1,'PlottyFile']]], + ['setfunctiontype',['setFunctionType',['../classPlottyFile.html#a4e5ab1ebb012a5cc1a3d6458a4cd512f',1,'PlottyFile']]], + ['setparafirstcurve',['setParaFirstCurve',['../classPlottyFile.html#aa676414793becb975506f48d6e949dd0',1,'PlottyFile']]], + ['setparastepwidth',['setParaStepWidth',['../classPlottyFile.html#a6caebd31e04e2e7081cc007047350355',1,'PlottyFile']]], + ['setquadrant',['setQuadrant',['../classPlottyFile.html#a1953ee0d9a87b7353c16139584e9c2ae',1,'PlottyFile']]], + ['setrefx',['setRefX',['../classPlottyFile.html#a80c2c2e97a454566f9c1f2c51e1d7f3e',1,'PlottyFile']]], + ['setrefy',['setRefY',['../classPlottyFile.html#a3a371228ddcc007e97eebe7cc04dffc2',1,'PlottyFile']]], + ['settimeout',['setTimeout',['../classUSART.html#ad7fe866cebe920784d2b17602824c7ff',1,'USART']]], + ['setunitpara',['setUnitPara',['../classPlottyFile.html#abbac84109a1e0958a4ca5c270fac0986',1,'PlottyFile']]], + ['setunitx',['setUnitX',['../classPlottyFile.html#ab8d35a841ca9c325fca671cf34e03527',1,'PlottyFile']]], + ['setunity',['setUnitY',['../classPlottyFile.html#abb18c814f435926f741f7ceb310f3059',1,'PlottyFile']]], + ['startplotty',['startPlotty',['../classPlottyFile.html#a08a115ef10458cadfe76077d623313df',1,'PlottyFile']]] ]; diff --git a/docs/html/search/functions_b.js b/docs/html/search/functions_b.js index 88b07d9..cbf06ef 100644 --- a/docs/html/search/functions_b.js +++ b/docs/html/search/functions_b.js @@ -1,5 +1,6 @@ var searchData= [ ['writebyte',['writeByte',['../classUSART.html#a60eadbe9956bab8144ee96d89eacd9f5',1,'USART']]], - ['writeint',['writeInt',['../classUSART.html#a78b30d9aa863f38745e982860392599a',1,'USART']]] + ['writeint',['writeInt',['../classUSART.html#a78b30d9aa863f38745e982860392599a',1,'USART']]], + ['writetofile',['writeToFile',['../classPlottyFile.html#a82c348e7fade2edcbc907e7c2bc2e305',1,'PlottyFile']]] ]; diff --git a/docs/html/search/searchdata.js b/docs/html/search/searchdata.js index 522aa5c..c99c8bb 100644 --- a/docs/html/search/searchdata.js +++ b/docs/html/search/searchdata.js @@ -1,9 +1,10 @@ var indexSectionsWithContent = { - 0: "abcdefgoprstuvw", + 0: "abcdefgmoprstuvw", 1: "bdptuv", 2: "acdefgoprstw", - 3: "e" + 3: "bmprw", + 4: "e" }; var indexSectionNames = @@ -11,7 +12,8 @@ var indexSectionNames = 0: "all", 1: "classes", 2: "functions", - 3: "pages" + 3: "variables", + 4: "pages" }; var indexSectionLabels = @@ -19,6 +21,7 @@ var indexSectionLabels = 0: "All", 1: "Classes", 2: "Functions", - 3: "Pages" + 3: "Variables", + 4: "Pages" }; diff --git a/docs/html/search/variables_0.html b/docs/html/search/variables_0.html new file mode 100644 index 0000000..a2a3ae6 --- /dev/null +++ b/docs/html/search/variables_0.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/variables_0.js b/docs/html/search/variables_0.js new file mode 100644 index 0000000..d1fd2cf --- /dev/null +++ b/docs/html/search/variables_0.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['baudrate',['BAUDRATE',['../classB15F.html#a7d548d6861cfc69753161bf9cda14f87',1,'B15F']]] +]; diff --git a/docs/html/search/variables_1.html b/docs/html/search/variables_1.html new file mode 100644 index 0000000..b243c42 --- /dev/null +++ b/docs/html/search/variables_1.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/variables_1.js b/docs/html/search/variables_1.js new file mode 100644 index 0000000..fd5dff3 --- /dev/null +++ b/docs/html/search/variables_1.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['msg_5ffail',['MSG_FAIL',['../classB15F.html#a77d1ecf24b406c9204665d3b09c36f1e',1,'B15F']]], + ['msg_5fok',['MSG_OK',['../classB15F.html#ab01299858f74a6cec598688562e0ad02',1,'B15F']]] +]; diff --git a/docs/html/search/variables_2.html b/docs/html/search/variables_2.html new file mode 100644 index 0000000..647df20 --- /dev/null +++ b/docs/html/search/variables_2.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/variables_2.js b/docs/html/search/variables_2.js new file mode 100644 index 0000000..570beea --- /dev/null +++ b/docs/html/search/variables_2.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['pre',['PRE',['../classB15F.html#a3b0fc1f85954b2d9c145af4a3af5b1ec',1,'B15F']]] +]; diff --git a/docs/html/search/variables_3.html b/docs/html/search/variables_3.html new file mode 100644 index 0000000..9dc9b89 --- /dev/null +++ b/docs/html/search/variables_3.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/variables_3.js b/docs/html/search/variables_3.js new file mode 100644 index 0000000..fbf0a47 --- /dev/null +++ b/docs/html/search/variables_3.js @@ -0,0 +1,5 @@ +var searchData= +[ + ['reconnect_5ftimeout',['RECONNECT_TIMEOUT',['../classB15F.html#a040951746fbfd632e12bd1ad14578816',1,'B15F']]], + ['reconnect_5ftries',['RECONNECT_TRIES',['../classB15F.html#a6c4895bdbcd71ff6743becf97985c2dc',1,'B15F']]] +]; diff --git a/docs/html/search/variables_4.html b/docs/html/search/variables_4.html new file mode 100644 index 0000000..78cc2c7 --- /dev/null +++ b/docs/html/search/variables_4.html @@ -0,0 +1,30 @@ + + + + + + + + + +
    +
    Loading...
    +
    + +
    Searching...
    +
    No Matches
    + +
    + + diff --git a/docs/html/search/variables_4.js b/docs/html/search/variables_4.js new file mode 100644 index 0000000..9a9c561 --- /dev/null +++ b/docs/html/search/variables_4.js @@ -0,0 +1,4 @@ +var searchData= +[ + ['wdt_5ftimeout',['WDT_TIMEOUT',['../classB15F.html#a158d13bc84aed6430cdede1396384e06',1,'B15F']]] +]; diff --git a/docs/html/timeoutexception_8h_source.html b/docs/html/timeoutexception_8h_source.html index cfb9642..84fffd2 100644 --- a/docs/html/timeoutexception_8h_source.html +++ b/docs/html/timeoutexception_8h_source.html @@ -70,11 +70,11 @@ $(function() {
    timeoutexception.h
    -
    1 #ifndef TIMEOUTEXCEPTION_H
    2 #define TIMEOUTEXCEPTION_H
    3 
    4 #include <exception>
    5 
    6 // SOURCE: https://stackoverflow.com/a/8152888
    7 
    8 class TimeoutException: public std::exception
    9 {
    10 public:
    11  explicit TimeoutException(const char* message, int timeout) : TimeoutException(std::string(message), timeout)
    12  {
    13  }
    14 
    15  explicit TimeoutException(const std::string& message, int timeout) : msg(message), m_timeout(timeout)
    16  {
    17  if(!msg.length())
    18  msg = "Timeout reached (" + std::to_string(m_timeout) + ")";
    19  }
    20 
    21  virtual ~TimeoutException() throw ()
    22  {
    23  }
    24 
    25  virtual const char* what() const throw ()
    26  {
    27  return msg.c_str();
    28  }
    29 
    30 protected:
    31  std::string msg;
    32  int m_timeout;
    33 };
    34 
    35 #endif // TIMEOUTEXCEPTION_H
    - +
    1 #ifndef TIMEOUTEXCEPTION_H
    2 #define TIMEOUTEXCEPTION_H
    3 
    4 #include <exception>
    5 
    6 // SOURCE: https://stackoverflow.com/a/8152888
    7 
    10 class TimeoutException: public std::exception
    11 {
    12 public:
    13  explicit TimeoutException(const char* message, int timeout) : TimeoutException(std::string(message), timeout)
    14  {
    15  }
    16 
    17  explicit TimeoutException(const std::string& message, int timeout) : msg(message), m_timeout(timeout)
    18  {
    19  if(!msg.length())
    20  msg = "Timeout reached (" + std::to_string(m_timeout) + ")";
    21  }
    22 
    23  virtual ~TimeoutException() throw ()
    24  {
    25  }
    26 
    27  virtual const char* what() const throw ()
    28  {
    29  return msg.c_str();
    30  }
    31 
    32 protected:
    33  std::string msg;
    34  int m_timeout;
    35 };
    36 
    37 #endif // TIMEOUTEXCEPTION_H
    + diff --git a/docs/html/ui_8cpp_source.html b/docs/html/ui_8cpp_source.html index 07d853b..760c88e 100644 --- a/docs/html/ui_8cpp_source.html +++ b/docs/html/ui_8cpp_source.html @@ -70,24 +70,25 @@ $(function() {
    ui.cpp
    -
    1 #include "ui.h"
    2 #include "../drv/b15f.h"
    3 
    4 std::vector<View*> win_stack;
    5 std::thread t_refresh;
    6 
    7 void show_main(int)
    8 {
    9  ViewSelection* view = new ViewSelection();
    10  view->setTitle("B15F - Command Line Interface");
    11  view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor);
    12  view->addChoice("[ Digitale Ausgabe BE0 ]", &show_digital_output0);
    13  view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1);
    14  view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
    15  view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
    16  view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info);
    17  view->addChoice("[ Informationen ]", &show_info);
    18  view->addChoice("", nullptr);
    19  view->addChoice("[ Beenden ]", &finish);
    20  view->repaint();
    21 
    22  win_stack.push_back(view);
    23  input(0);
    24 }
    25 
    26 void input(int)
    27 {
    28  call_t nextCall;
    29  int key;
    30  do
    31  {
    32  key = wgetch(View::getWinContext());
    33  win_stack.back()->repaint();
    34  nextCall = win_stack.back()->keypress(key);
    35 
    36  if(key == -1)
    37  view_back(key);
    38 
    39  if(nextCall)
    40  nextCall(key);
    41  }
    42  while(win_stack.size());
    43 }
    44 
    45 void view_back(int)
    46 {
    47  if(win_stack.size())
    48  {
    49  delete win_stack.back();
    50  win_stack.pop_back();
    51  }
    52  if(win_stack.size())
    53  win_stack.back()->repaint();
    54 }
    55 
    56 void finish(int)
    57 {
    58  cleanup();
    59  exit(EXIT_SUCCESS);
    60 }
    61 
    62 void cleanup()
    63 {
    64  if(t_refresh.joinable())
    65  t_refresh.join();
    66  clrtoeol();
    67  refresh();
    68  endwin();
    69 }
    70 
    71 void show_info(int)
    72 {
    73  ViewInfo* view = new ViewInfo();
    74  view->setTitle("Info");
    75  view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal...");
    76  view->setLabelClose("[ Zurueck ]");
    77  view->repaint();
    78 
    79  win_stack.push_back(view);
    80  input(0);
    81 }
    82 
    83 void show_monitor(int)
    84 {
    85  ViewMonitor* view = new ViewMonitor();
    86  view->setTitle("Monitor");
    87  view->setText("\nErfasse Messwerte...");
    88  view->setLabelClose("[ Zurueck ]");
    89  view->repaint();
    90 
    91  win_stack.push_back(view);
    92  input(0);
    93 }
    94 
    95 void show_invalid_port_input(int)
    96 {
    97  ViewInfo* view = new ViewInfo();
    98  view->setTitle("Falsche Eingabe");
    99  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an.");
    100  view->setLabelClose("[ Schliessen ]");
    101  view->repaint();
    102 
    103  win_stack.push_back(view);
    104  input(0);
    105 }
    106 
    107 void show_invalid_dac_input(int)
    108 {
    109  ViewInfo* view = new ViewInfo();
    110  view->setTitle("Falsche Eingabe");
    111  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an.");
    112  view->setLabelClose("[ Schliessen ]");
    113  view->repaint();
    114 
    115  win_stack.push_back(view);
    116  input(0);
    117 }
    118 
    119 void write_digital_output0(int)
    120 {
    121  try
    122  {
    123  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    124  if(d > 255 || 0 > d)
    125  throw std::invalid_argument("bad value");
    126  uint8_t port = static_cast<uint8_t>(d);
    127 
    128  B15F& drv = B15F::getInstance();
    129  drv.digitalWrite0(port);
    130  view_back(0);
    131  }
    132  catch(std::invalid_argument& ex)
    133  {
    134  show_invalid_port_input(0);
    135  }
    136 }
    137 
    138 void write_digital_output1(int)
    139 {
    140  try
    141  {
    142  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    143  if(d > 255 || 0 > d)
    144  throw std::invalid_argument("bad value");
    145  uint8_t port = static_cast<uint8_t>(d);
    146 
    147  B15F& drv = B15F::getInstance();
    148  drv.digitalWrite1(port);
    149  view_back(0);
    150  }
    151  catch(std::invalid_argument& ex)
    152  {
    153  show_invalid_port_input(0);
    154  }
    155 }
    156 
    157 void write_analog_output0(int)
    158 {
    159  try
    160  {
    161  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    162  if(port > 1023)
    163  throw std::invalid_argument("bad value");
    164 
    165  B15F& drv = B15F::getInstance();
    166  drv.analogWrite0(port);
    167  view_back(0);
    168  }
    169  catch(std::invalid_argument& ex)
    170  {
    171  show_invalid_dac_input(0);
    172  }
    173 }
    174 
    175 void write_analog_output1(int)
    176 {
    177  try
    178  {
    179  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    180  if(port > 1023)
    181  throw std::invalid_argument("bad value");
    182 
    183  B15F& drv = B15F::getInstance();
    184  drv.analogWrite1(port);
    185  view_back(0);
    186  }
    187  catch(std::invalid_argument& ex)
    188  {
    189  show_invalid_dac_input(0);
    190  }
    191 }
    192 
    193 void show_digital_output0(int)
    194 {
    195  ViewPromt* view = new ViewPromt();
    196  view->setTitle("Digitale Ausgabe BE0");
    197  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    198  view->setCancel("[ Zurueck ]", true);
    199  view->setConfirm("[ OK ]", &write_digital_output0);
    200  view->repaint();
    201 
    202  win_stack.push_back(view);
    203  input(0);
    204 }
    205 
    206 void show_digital_output1(int)
    207 {
    208  ViewPromt* view = new ViewPromt();
    209  view->setTitle("Digitale Ausgabe BE1");
    210  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    211  view->setCancel("[ Zurueck ]", true);
    212  view->setConfirm("[ OK ]", &write_digital_output1);
    213  view->repaint();
    214 
    215  win_stack.push_back(view);
    216  input(0);
    217 }
    218 
    219 void show_analog_output0(int)
    220 {
    221  ViewPromt* view = new ViewPromt();
    222  view->setTitle("Analoge Ausgabe AA0");
    223  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    224  view->setCancel("[ Zurueck ]", true);
    225  view->setConfirm("[ OK ]", &write_analog_output0);
    226  view->repaint();
    227 
    228  win_stack.push_back(view);
    229  input(0);
    230 }
    231 
    232 void show_analog_output1(int)
    233 {
    234  ViewPromt* view = new ViewPromt();
    235  view->setTitle("Analoge Ausgabe AA1");
    236  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    237  view->setCancel("[ Zurueck ]", true);
    238  view->setConfirm("[ OK ]", &write_analog_output1);
    239  view->repaint();
    240 
    241  win_stack.push_back(view);
    242  input(0);
    243 }
    244 
    245 void start_selftest(int)
    246 {
    247  B15F& drv = B15F::getInstance();
    248  drv.activateSelfTestMode();
    249 
    250  ViewInfo* view = new ViewInfo();
    251  view->setTitle("Selbsttest aktiv");
    252  view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1");
    253  view->setLabelClose("[ Selbsttest Beenden ]");
    254  view->setCall(&stop_selftest);
    255  view->repaint();
    256 
    257  win_stack.push_back(view);
    258  input(0);
    259 }
    260 
    261 void stop_selftest(int)
    262 {
    263  B15F& drv = B15F::getInstance();
    264  drv.discard();
    265  drv.delay_ms(B15F::WDT_TIMEOUT);
    266  drv.reconnect();
    267  drv.digitalWrite0(0);
    268  drv.digitalWrite1(0);
    269 }
    270 
    271 void show_selftest_info(int)
    272 {
    273  ViewInfo* view = new ViewInfo();
    274  view->setTitle("Selbsttest");
    275  view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und bestaetigen\nmit Enter.");
    276  view->setLabelClose("[ Weiter ]");
    277  view->setCall(&start_selftest);
    278  view->repaint();
    279 
    280  win_stack.push_back(view);
    281  input(0);
    282 }
    - - -
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:290
    -
    bool analogWrite1(uint16_t)
    Definition: b15f.cpp:209
    -
    static B15F & getInstance(void)
    Definition: b15f.cpp:300
    -
    Definition: b15f.h:24
    -
    bool digitalWrite0(uint8_t)
    Definition: b15f.cpp:152
    -
    bool activateSelfTestMode(void)
    Definition: b15f.cpp:144
    - - -
    bool digitalWrite1(uint8_t)
    Definition: b15f.cpp:162
    +
    1 #include "ui.h"
    2 #include "../drv/b15f.h"
    3 
    4 std::vector<View*> win_stack;
    5 std::thread t_refresh;
    6 
    7 void show_main(int)
    8 {
    9  ViewSelection* view = new ViewSelection();
    10  view->setTitle("B15F - Command Line Interface");
    11  view->addChoice("[ Monitor - Eingaben beobachten ]", &show_monitor);
    12  view->addChoice("[ Digitale Ausgabe BE0 ]", &show_digital_output0);
    13  view->addChoice("[ Digitale Ausgabe BE1 ]", &show_digital_output1);
    14  view->addChoice("[ Analoge Ausgabe AA0 ]", &show_analog_output0);
    15  view->addChoice("[ Analoge Ausgabe AA1 ]", &show_analog_output1);
    16  view->addChoice("[ Selbsttest des B15 ]", &show_selftest_info);
    17  view->addChoice("[ Informationen ]", &show_info);
    18  view->addChoice("", nullptr);
    19  view->addChoice("[ Beenden ]", &finish);
    20  view->repaint();
    21 
    22  win_stack.push_back(view);
    23  input(0);
    24 }
    25 
    26 void input(int)
    27 {
    28  call_t nextCall;
    29  int key;
    30  do
    31  {
    32  key = wgetch(View::getWinContext());
    33  win_stack.back()->repaint();
    34  nextCall = win_stack.back()->keypress(key);
    35 
    36  if(key == -1)
    37  view_back(key);
    38 
    39  if(nextCall)
    40  nextCall(key);
    41  }
    42  while(win_stack.size());
    43 }
    44 
    45 void view_back(int)
    46 {
    47  if(win_stack.size())
    48  {
    49  delete win_stack.back();
    50  win_stack.pop_back();
    51  }
    52  if(win_stack.size())
    53  win_stack.back()->repaint();
    54 }
    55 
    56 void finish(int)
    57 {
    58  cleanup();
    59  exit(EXIT_SUCCESS);
    60 }
    61 
    62 void cleanup()
    63 {
    64  if(t_refresh.joinable())
    65  t_refresh.join();
    66  clrtoeol();
    67  refresh();
    68  endwin();
    69 }
    70 
    71 void show_info(int)
    72 {
    73  ViewInfo* view = new ViewInfo();
    74  view->setTitle("Info");
    75  view->setText("Informationen zu Board 15 Famulus Edition\nEs war einmal...");
    76  view->setLabelClose("[ Zurueck ]");
    77  view->repaint();
    78 
    79  win_stack.push_back(view);
    80  input(0);
    81 }
    82 
    83 void show_monitor(int)
    84 {
    85  ViewMonitor* view = new ViewMonitor();
    86  view->setTitle("Monitor");
    87  view->setText("\nErfasse Messwerte...");
    88  view->setLabelClose("[ Zurueck ]");
    89  view->repaint();
    90 
    91  win_stack.push_back(view);
    92  input(0);
    93 }
    94 
    95 void show_invalid_port_input(int)
    96 {
    97  ViewInfo* view = new ViewInfo();
    98  view->setTitle("Falsche Eingabe");
    99  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, FF] an.");
    100  view->setLabelClose("[ Schliessen ]");
    101  view->repaint();
    102 
    103  win_stack.push_back(view);
    104  input(0);
    105 }
    106 
    107 void show_invalid_dac_input(int)
    108 {
    109  ViewInfo* view = new ViewInfo();
    110  view->setTitle("Falsche Eingabe");
    111  view->setText("Bitte geben Sie einen Wert aus dem Intervall [0, 1023] an.");
    112  view->setLabelClose("[ Schliessen ]");
    113  view->repaint();
    114 
    115  win_stack.push_back(view);
    116  input(0);
    117 }
    118 
    119 void write_digital_output0(int)
    120 {
    121  try
    122  {
    123  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    124  if(d > 255 || 0 > d)
    125  throw std::invalid_argument("bad value");
    126  uint8_t port = static_cast<uint8_t>(d);
    127 
    128  B15F& drv = B15F::getInstance();
    129  drv.digitalWrite0(port);
    130  view_back(0);
    131  }
    132  catch(std::invalid_argument& ex)
    133  {
    134  show_invalid_port_input(0);
    135  }
    136 }
    137 
    138 void write_digital_output1(int)
    139 {
    140  try
    141  {
    142  int d = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput(), 0, 16);
    143  if(d > 255 || 0 > d)
    144  throw std::invalid_argument("bad value");
    145  uint8_t port = static_cast<uint8_t>(d);
    146 
    147  B15F& drv = B15F::getInstance();
    148  drv.digitalWrite1(port);
    149  view_back(0);
    150  }
    151  catch(std::invalid_argument& ex)
    152  {
    153  show_invalid_port_input(0);
    154  }
    155 }
    156 
    157 void write_analog_output0(int)
    158 {
    159  try
    160  {
    161  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    162  if(port > 1023)
    163  throw std::invalid_argument("bad value");
    164 
    165  B15F& drv = B15F::getInstance();
    166  drv.analogWrite0(port);
    167  view_back(0);
    168  }
    169  catch(std::invalid_argument& ex)
    170  {
    171  show_invalid_dac_input(0);
    172  }
    173 }
    174 
    175 void write_analog_output1(int)
    176 {
    177  try
    178  {
    179  uint16_t port = std::stoi(static_cast<ViewPromt*>(win_stack.back())->getInput());
    180  if(port > 1023)
    181  throw std::invalid_argument("bad value");
    182 
    183  B15F& drv = B15F::getInstance();
    184  drv.analogWrite1(port);
    185  view_back(0);
    186  }
    187  catch(std::invalid_argument& ex)
    188  {
    189  show_invalid_dac_input(0);
    190  }
    191 }
    192 
    193 void show_digital_output0(int)
    194 {
    195  ViewPromt* view = new ViewPromt();
    196  view->setTitle("Digitale Ausgabe BE0");
    197  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    198  view->setCancel("[ Zurueck ]", true);
    199  view->setConfirm("[ OK ]", &write_digital_output0);
    200  view->repaint();
    201 
    202  win_stack.push_back(view);
    203  input(0);
    204 }
    205 
    206 void show_digital_output1(int)
    207 {
    208  ViewPromt* view = new ViewPromt();
    209  view->setTitle("Digitale Ausgabe BE1");
    210  view->setMessage("\nAusgabe Port-Wert (hex): 0x");
    211  view->setCancel("[ Zurueck ]", true);
    212  view->setConfirm("[ OK ]", &write_digital_output1);
    213  view->repaint();
    214 
    215  win_stack.push_back(view);
    216  input(0);
    217 }
    218 
    219 void show_analog_output0(int)
    220 {
    221  ViewPromt* view = new ViewPromt();
    222  view->setTitle("Analoge Ausgabe AA0");
    223  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    224  view->setCancel("[ Zurueck ]", true);
    225  view->setConfirm("[ OK ]", &write_analog_output0);
    226  view->repaint();
    227 
    228  win_stack.push_back(view);
    229  input(0);
    230 }
    231 
    232 void show_analog_output1(int)
    233 {
    234  ViewPromt* view = new ViewPromt();
    235  view->setTitle("Analoge Ausgabe AA1");
    236  view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
    237  view->setCancel("[ Zurueck ]", true);
    238  view->setConfirm("[ OK ]", &write_analog_output1);
    239  view->repaint();
    240 
    241  win_stack.push_back(view);
    242  input(0);
    243 }
    244 
    245 void start_selftest(int)
    246 {
    247  B15F& drv = B15F::getInstance();
    248  drv.activateSelfTestMode();
    249 
    250  ViewInfo* view = new ViewInfo();
    251  view->setTitle("Selbsttest aktiv");
    252  view->setText("Das B15 befindet sich jetzt im Selbsttestmodus.\n \nSelbsttest:\nZu Beginn geht der Reihe nach jede LED von BA0 bis BA1 an.\nDanach leuchten die LEDs an AA0 und AA1 kurz auf.\nZum Schluss spiegelt in einer Endlosschleife:\n* BA0 Port BE0\n* BA1 die DIP-Schalter S7\n* AA0 ADC0\n* AA1 ADC1");
    253  view->setLabelClose("[ Selbsttest Beenden ]");
    254  view->setCall(&stop_selftest);
    255  view->repaint();
    256 
    257  win_stack.push_back(view);
    258  input(0);
    259 }
    260 
    261 void stop_selftest(int)
    262 {
    263  B15F& drv = B15F::getInstance();
    264  drv.discard();
    266  drv.reconnect();
    267  drv.digitalWrite0(0);
    268  drv.digitalWrite1(0);
    269 }
    270 
    271 void show_selftest_info(int)
    272 {
    273  ViewInfo* view = new ViewInfo();
    274  view->setTitle("Selbsttest");
    275  view->setText("Bitte entfernen Sie jetzt alle Draehte von den Anschlussklemmen und bestaetigen\nmit Enter.");
    276  view->setLabelClose("[ Weiter ]");
    277  view->setCall(&start_selftest);
    278  view->repaint();
    279 
    280  win_stack.push_back(view);
    281  input(0);
    282 }
    + + +
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:292
    +
    static B15F & getInstance(void)
    Definition: b15f.cpp:302
    +
    Definition: b15f.h:26
    +
    bool digitalWrite0(uint8_t)
    Definition: b15f.cpp:153
    +
    bool activateSelfTestMode(void)
    Definition: b15f.cpp:145
    + +
    bool analogWrite1(uint16_t port)
    Definition: b15f.cpp:210
    + +
    bool digitalWrite1(uint8_t)
    Definition: b15f.cpp:163
    void discard(void)
    Definition: b15f.cpp:72
    -
    bool analogWrite0(uint16_t)
    Definition: b15f.cpp:199
    +
    constexpr static uint16_t WDT_TIMEOUT
    Time in ms after which the watch dog timer resets the MCU.
    Definition: b15f.h:203
    void reconnect(void)
    Definition: b15f.cpp:57
    +
    bool analogWrite0(uint16_t port)
    Definition: b15f.cpp:200
    diff --git a/docs/html/ui_8h_source.html b/docs/html/ui_8h_source.html index 4edb2a9..6b5ee6b 100644 --- a/docs/html/ui_8h_source.html +++ b/docs/html/ui_8h_source.html @@ -73,7 +73,7 @@ $(function() {
    1 #ifndef UI_H
    2 #define UI_H
    3 
    4 #include <vector>
    5 #include "view_selection.h"
    6 #include "view_info.h"
    7 #include "view_monitor.h"
    8 #include "view_promt.h"
    9 
    10 void show_main(int);
    11 void input(int);
    12 void view_back(int);
    13 void finish(int);
    14 void cleanup();
    15 
    16 void show_info(int);
    17 void show_monitor(int);
    18 void show_invalid_port_input(int);
    19 void show_invalid_dac_input(int);
    20 void write_digital_output0(int);
    21 void write_digital_output1(int);
    22 void write_analog_output0(int);
    23 void write_analog_output1(int);
    24 void show_digital_output0(int);
    25 void show_digital_output1(int);
    26 void show_analog_output0(int);
    27 void show_analog_output1(int);
    28 
    29 // selftest group
    30 void show_selftest_info(int);
    31 void start_selftest(int);
    32 void stop_selftest(int);
    33 
    34 
    35 extern std::vector<View*> win_stack;
    36 extern std::thread t_refresh;
    37 
    38 #endif // UI_H
    diff --git a/docs/html/usart_8cpp_source.html b/docs/html/usart_8cpp_source.html index 87f2c09..5456252 100644 --- a/docs/html/usart_8cpp_source.html +++ b/docs/html/usart_8cpp_source.html @@ -70,26 +70,26 @@ $(function() {
    usart.cpp
    -
    1 #include "usart.h"
    2 
    3 void USART::openDevice(std::string device)
    4 {
    5  file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/);
    6  if(file_desc <= 0)
    7  throw USARTException("Fehler beim Öffnen des Gerätes");
    8 
    9  struct termios options;
    10  int code = tcgetattr(file_desc, &options);
    11  if(code)
    12  throw USARTException("Fehler beim Lesen der Geräteparameter");
    13 
    14  options.c_cflag = CS8 | CLOCAL | CREAD;
    15  options.c_iflag = IGNPAR;
    16  options.c_oflag = 0;
    17  options.c_lflag = 0;
    18  options.c_cc[VMIN] = 0; // #bytes read returns at least
    19  options.c_cc[VTIME] = timeout;
    20  code = cfsetspeed(&options, baudrate);
    21  if(code)
    22  throw USARTException("Fehler beim Setzen der Baudrate");
    23 
    24  code = tcsetattr(file_desc, TCSANOW, &options);
    25  if(code)
    26  throw USARTException("Fehler beim Setzen der Geräteparameter");
    27 
    30 }
    31 
    33 {
    34  int code = close(file_desc);
    35  if(code)
    36  throw USARTException("Fehler beim Schließen des Gerätes");
    37 }
    38 
    40 {
    41  int code = tcflush(file_desc, TCIFLUSH);
    42  if(code)
    43  throw USARTException("Fehler beim Leeren des Eingangspuffers");
    44 }
    45 
    47 {
    48  int code = tcflush(file_desc, TCOFLUSH);
    49  if(code)
    50  throw USARTException("Fehler beim Leeren des Ausgangspuffers");
    51 }
    52 
    54 {
    55  int code = tcdrain(file_desc);
    56  if(code)
    57  throw USARTException("Fehler beim Versenden des Ausgangspuffers");
    58 }
    59 
    61 {
    62  double pz = 1e2 * n_blocks_failed / n_blocks_total;
    63  pz = std::round(pz * 1e2) / 1e2;
    64  std::cout << "blocks total: " << n_blocks_total << " ok: " << (n_blocks_total - n_blocks_failed) << " failed: " << n_blocks_failed << " (" << pz << "%)" << std::endl;
    65 }
    66 
    67 void USART::writeByte(uint8_t b)
    68 {
    69  int sent = write(file_desc, &b, 1);
    70  if(sent != 1)
    71  {
    72  std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl;
    73  usleep(100000);
    74  sent = write(file_desc, &b, 1);
    75  if(sent != 1)
    76  throw USARTException("Fehler beim Senden: writeByte()");
    77  }
    78 
    79 }
    80 
    81 void USART::writeInt(uint16_t d)
    82 {
    83  int sent = write(file_desc, reinterpret_cast<char*>(&d), 2);
    84  if(sent != 2)
    85  throw USARTException("Fehler beim Senden: writeInt()");
    86 }
    87 
    88 
    89 
    90 int USART::read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
    91 {
    92  uint32_t elapsed = 0;
    93  int n_read = -1;
    94  auto start = std::chrono::steady_clock::now();
    95  auto end = start;
    96  while(elapsed < timeout)
    97  {
    98  n_read = read(file_desc, buffer + offset, len);
    99  if (n_read == len)
    100  return n_read;
    101 
    102  end = std::chrono::steady_clock::now();
    103  elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
    104  }
    105 
    106  return 0;
    107 }
    108 
    109 int USART::write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
    110 {
    111  uint32_t elapsed = 0;
    112  int n_sent = -1;
    113  auto start = std::chrono::steady_clock::now();
    114  auto end = start;
    115  while(elapsed < timeout)
    116  {
    117  n_sent = write(file_desc, buffer + offset, len);
    119  if (n_sent == len)
    120  return n_sent;
    121 
    122  end = std::chrono::steady_clock::now();
    123  elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
    124  }
    125 
    126  return n_sent;
    127 }
    128 
    129 void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
    130 {
    131  uint8_t crc;
    132  uint8_t aw;
    133  const uint16_t us_per_bit = (1000000 / baudrate) * 16;
    134  const uint16_t n_total = len + 3;
    135 
    136  n_blocks_total++;
    137  bool failed = false;
    138 
    139  do
    140  {
    141  // calc crc
    142  crc = 0;
    143  for(uint8_t i = 0; i < len; i++)
    144  {
    145  crc ^= buffer[i];
    146  for (uint8_t k = 0; k < 8; k++)
    147  {
    148  if (crc & 1)
    149  crc ^= CRC7_POLY;
    150  crc >>= 1;
    151  }
    152  }
    153 
    154  // construct block
    155  block_buffer[0] = len;
    156  std::memcpy(&block_buffer[1], buffer + offset, len);
    157  block_buffer[len + 1] = crc;
    158  block_buffer[len + 2] = BLOCK_END;
    159 
    160  // send block
    163  int n_sent = write_timeout(&block_buffer[0], 0, len + 3, us_per_bit * n_total);
    164  if(n_sent != n_total)
    165  throw std::runtime_error("fatal (send): " + std::to_string(n_sent));
    166 
    167  /*for(uint8_t i = 0; i < len + 3; i++)
    168  {
    169  write_timeout(&block_buffer[i], 0, 1, us_per_bit * n_total);
    170  //tcdrain(file_desc);
    171  //usleep(1000);
    172  }*/
    173 
    174  // flush output data
    175  tcdrain(file_desc);
    176 
    177  //usleep(us_per_bit * n_total * 10);
    178 
    179  // check response
    180  int n_read = read_timeout(&aw, 0, 1, us_per_bit * n_blocks_total * 10);
    181  for(uint16_t i = 0; i < 255 && n_read != 1; i++)
    182  {
    183  writeByte(0x80); // Stoppzeichen für Block
    184  if(tcdrain(file_desc))
    185  {
    186  std::cout << "drain failed" << std::endl;
    187  }
    188  std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl;
    189  usleep(us_per_bit*100);
    190  n_read = read_timeout(&aw, 0, 1, us_per_bit);
    191  }
    192 
    193  if(n_read != 1)
    194  throw std::runtime_error("fatal: " + std::to_string(n_read));
    195 
    196  //clearInputBuffer();
    197 
    198  if(aw != 0xFF) {
    199  if(!failed)
    200  n_blocks_failed++;
    201  failed = true;
    202  std::cout << "block failed, retry" << std::endl;
    203  }
    204  }
    205  while(aw != 0xFF);
    206 
    207  //std::cout << "OK" << std::endl;
    208 }
    209 
    210 uint8_t USART::readByte(void)
    211 {
    212  char b;
    213  auto start = std::chrono::steady_clock::now();
    214  auto end = start;
    215  uint16_t elapsed = 0;
    216  while(elapsed < timeout * 100)
    217  {
    218  int code = read(file_desc, &b, 1);
    219  if (code > 0)
    220  return static_cast<uint8_t>(b);
    221 
    222  end = std::chrono::steady_clock::now();
    223  elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    224  }
    225 
    226  throw TimeoutException("Verbindung unterbrochen.", timeout);
    227 }
    228 
    229 uint16_t USART::readInt(void)
    230 {
    231  return readByte() | readByte() << 8;
    232 }
    233 
    234 bool USART::readBlock(uint8_t* buffer, uint16_t offset)
    235 {
    236  uint8_t len = readByte();
    237  uint8_t crc = 0;
    238  buffer += offset;
    239 
    240  uint32_t block_timeout = timeout / 10;
    241 
    242  // wait for block
    243  int n_ready;
    244  uint16_t elapsed = 0;
    245  auto start = std::chrono::steady_clock::now();
    246  auto end = start;
    247  while(elapsed < block_timeout)
    248  {
    249  int code = ioctl(file_desc, FIONREAD, &n_ready);
    250  if(code != 0)
    251  {
    252  std::cout << "n_ready code: " << code << std::endl;
    253  return false;
    254  }
    255 
    256  if(n_ready >= len + 1)
    257  break;
    258 
    259  end = std::chrono::steady_clock::now();
    260  elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    261  }
    262  if(elapsed >= timeout)
    263  {
    264  std::cout << "block timeout: " << std::endl;
    265  return false;
    266  }
    267 
    268  while(len--)
    269  {
    270  *buffer = readByte();
    271 
    272  crc ^= *buffer++;
    273  for (uint8_t i = 0; i < 8; i++)
    274  {
    275  if (crc & 1)
    276  crc ^= CRC7_POLY;
    277  crc >>= 1;
    278  }
    279  }
    280 
    281  crc ^= readByte();
    282  for (uint8_t i = 0; i < 8; i++)
    283  {
    284  if (crc & 1)
    285  crc ^= CRC7_POLY;
    286  crc >>= 1;
    287  }
    288 
    289  if(TEST == 1)
    290  crc = 1;
    291  if(TEST > 100)
    292  TEST = 0;
    293 
    294  if (crc == 0)
    295  {
    296  writeByte(0xFF);
    297  return true;
    298  }
    299  else
    300  {
    301  writeByte(0xFE);
    302  return false;
    303  }
    304 }
    305 
    307 {
    308  return baudrate;
    309 }
    310 
    312 {
    313  return timeout;
    314 }
    315 
    316 void USART::setBaudrate(uint32_t baudrate)
    317 {
    318  this->baudrate = baudrate;
    319 }
    320 
    321 void USART::setTimeout(uint8_t timeout)
    322 {
    323  this->timeout = timeout;
    324 }
    -
    uint32_t getBaudrate(void)
    Definition: usart.cpp:306
    -
    uint8_t readByte(void)
    Definition: usart.cpp:210
    - +
    1 #include "usart.h"
    2 
    3 void USART::openDevice(std::string device)
    4 {
    5  file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/);
    6  if(file_desc <= 0)
    7  throw USARTException("Fehler beim Öffnen des Gerätes");
    8 
    9  struct termios options;
    10  int code = tcgetattr(file_desc, &options);
    11  if(code)
    12  throw USARTException("Fehler beim Lesen der Geräteparameter");
    13 
    14  options.c_cflag = CS8 | CLOCAL | CREAD;
    15  options.c_iflag = IGNPAR;
    16  options.c_oflag = 0;
    17  options.c_lflag = 0;
    18  options.c_cc[VMIN] = 0; // #bytes read returns at least
    19  options.c_cc[VTIME] = timeout;
    20  code = cfsetspeed(&options, baudrate);
    21  if(code)
    22  throw USARTException("Fehler beim Setzen der Baudrate");
    23 
    24  code = tcsetattr(file_desc, TCSANOW, &options);
    25  if(code)
    26  throw USARTException("Fehler beim Setzen der Geräteparameter");
    27 
    30 }
    31 
    33 {
    34  int code = close(file_desc);
    35  if(code)
    36  throw USARTException("Fehler beim Schließen des Gerätes");
    37 }
    38 
    40 {
    41  int code = tcflush(file_desc, TCIFLUSH);
    42  if(code)
    43  throw USARTException("Fehler beim Leeren des Eingangspuffers");
    44 }
    45 
    47 {
    48  int code = tcflush(file_desc, TCOFLUSH);
    49  if(code)
    50  throw USARTException("Fehler beim Leeren des Ausgangspuffers");
    51 }
    52 
    54 {
    55  int code = tcdrain(file_desc);
    56  if(code)
    57  throw USARTException("Fehler beim Versenden des Ausgangspuffers");
    58 }
    59 
    61 {
    62  double pz = 1e2 * n_blocks_failed / n_blocks_total;
    63  pz = std::round(pz * 1e2) / 1e2;
    64  std::cout << "blocks total: " << n_blocks_total << " ok: " << (n_blocks_total - n_blocks_failed) << " failed: " << n_blocks_failed << " (" << pz << "%)" << std::endl;
    65 }
    66 
    67 void USART::writeByte(uint8_t b)
    68 {
    69  int sent = write(file_desc, &b, 1);
    70  if(sent != 1)
    71  {
    72  std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl;
    73  usleep(100000);
    74  sent = write(file_desc, &b, 1);
    75  if(sent != 1)
    76  throw USARTException("Fehler beim Senden: writeByte()");
    77  }
    78 
    79 }
    80 
    81 void USART::writeInt(uint16_t d)
    82 {
    83  int sent = write(file_desc, reinterpret_cast<char*>(&d), 2);
    84  if(sent != 2)
    85  throw USARTException("Fehler beim Senden: writeInt()");
    86 }
    87 
    88 
    89 
    90 int USART::read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
    91 {
    92  uint32_t elapsed = 0;
    93  int n_read = -1;
    94  auto start = std::chrono::steady_clock::now();
    95  auto end = start;
    96  while(elapsed < timeout)
    97  {
    98  n_read = read(file_desc, buffer + offset, len);
    99  if (n_read == len)
    100  return n_read;
    101 
    102  end = std::chrono::steady_clock::now();
    103  elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
    104  }
    105 
    106  return 0;
    107 }
    108 
    109 int USART::write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
    110 {
    111  uint32_t elapsed = 0;
    112  int n_sent = -1;
    113  auto start = std::chrono::steady_clock::now();
    114  auto end = start;
    115  while(elapsed < timeout)
    116  {
    117  n_sent = write(file_desc, buffer + offset, len);
    119  if (n_sent == len)
    120  return n_sent;
    121 
    122  end = std::chrono::steady_clock::now();
    123  elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
    124  }
    125 
    126  return n_sent;
    127 }
    128 
    129 void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
    130 {
    131  uint8_t crc;
    132  uint8_t aw;
    133  const uint16_t us_per_bit = (1000000 / baudrate) * 16;
    134  const uint16_t n_total = len + 3;
    135 
    136  n_blocks_total++;
    137  bool failed = false;
    138 
    139  do
    140  {
    141  // calc crc
    142  crc = 0;
    143  for(uint8_t i = 0; i < len; i++)
    144  {
    145  crc ^= buffer[i];
    146  for (uint8_t k = 0; k < 8; k++)
    147  {
    148  if (crc & 1)
    149  crc ^= CRC7_POLY;
    150  crc >>= 1;
    151  }
    152  }
    153 
    154  // construct block
    155  block_buffer[0] = len;
    156  std::memcpy(&block_buffer[1], buffer + offset, len);
    157  block_buffer[len + 1] = crc;
    158  block_buffer[len + 2] = BLOCK_END;
    159 
    160  // send block
    163  int n_sent = write_timeout(&block_buffer[0], 0, len + 3, us_per_bit * n_total);
    164  if(n_sent != n_total)
    165  throw std::runtime_error("fatal (send): " + std::to_string(n_sent));
    166 
    167  /*for(uint8_t i = 0; i < len + 3; i++)
    168  {
    169  write_timeout(&block_buffer[i], 0, 1, us_per_bit * n_total);
    170  //tcdrain(file_desc);
    171  //usleep(1000);
    172  }*/
    173 
    174  // flush output data
    175  tcdrain(file_desc);
    176 
    177  //usleep(us_per_bit * n_total * 10);
    178 
    179  // check response
    180  int n_read = read_timeout(&aw, 0, 1, us_per_bit * n_blocks_total * 10);
    181  for(uint16_t i = 0; i < 255 && n_read != 1; i++)
    182  {
    183  writeByte(0x80); // Stoppzeichen für Block
    184  if(tcdrain(file_desc))
    185  {
    186  std::cout << "drain failed" << std::endl;
    187  }
    188  std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl;
    189  usleep(us_per_bit*100);
    190  n_read = read_timeout(&aw, 0, 1, us_per_bit);
    191  }
    192 
    193  if(n_read != 1)
    194  throw std::runtime_error("fatal: " + std::to_string(n_read));
    195 
    196  //clearInputBuffer();
    197 
    198  if(aw != 0xFF)
    199  {
    200  if(!failed)
    201  n_blocks_failed++;
    202  failed = true;
    203  std::cout << "block failed, retry" << std::endl;
    204  }
    205  }
    206  while(aw != 0xFF);
    207 
    208  //std::cout << "OK" << std::endl;
    209 }
    210 
    211 uint8_t USART::readByte(void)
    212 {
    213  char b;
    214  auto start = std::chrono::steady_clock::now();
    215  auto end = start;
    216  uint16_t elapsed = 0;
    217  while(elapsed < timeout * 100)
    218  {
    219  int code = read(file_desc, &b, 1);
    220  if (code > 0)
    221  return static_cast<uint8_t>(b);
    222 
    223  end = std::chrono::steady_clock::now();
    224  elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    225  }
    226 
    227  throw TimeoutException("Verbindung unterbrochen.", timeout);
    228 }
    229 
    230 uint16_t USART::readInt(void)
    231 {
    232  return readByte() | readByte() << 8;
    233 }
    234 
    235 bool USART::readBlock(uint8_t* buffer, uint16_t offset)
    236 {
    237  uint8_t len = readByte();
    238  uint8_t crc = 0;
    239  buffer += offset;
    240 
    241  uint32_t block_timeout = timeout / 10;
    242 
    243  // wait for block
    244  int n_ready;
    245  uint16_t elapsed = 0;
    246  auto start = std::chrono::steady_clock::now();
    247  auto end = start;
    248  while(elapsed < block_timeout)
    249  {
    250  int code = ioctl(file_desc, FIONREAD, &n_ready);
    251  if(code != 0)
    252  {
    253  std::cout << "n_ready code: " << code << std::endl;
    254  return false;
    255  }
    256 
    257  if(n_ready >= len + 1)
    258  break;
    259 
    260  end = std::chrono::steady_clock::now();
    261  elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    262  }
    263  if(elapsed >= timeout)
    264  {
    265  std::cout << "block timeout: " << std::endl;
    266  return false;
    267  }
    268 
    269  while(len--)
    270  {
    271  *buffer = readByte();
    272 
    273  crc ^= *buffer++;
    274  for (uint8_t i = 0; i < 8; i++)
    275  {
    276  if (crc & 1)
    277  crc ^= CRC7_POLY;
    278  crc >>= 1;
    279  }
    280  }
    281 
    282  crc ^= readByte();
    283  for (uint8_t i = 0; i < 8; i++)
    284  {
    285  if (crc & 1)
    286  crc ^= CRC7_POLY;
    287  crc >>= 1;
    288  }
    289 
    290  if(TEST == 1)
    291  crc = 1;
    292  if(TEST > 100)
    293  TEST = 0;
    294 
    295  if (crc == 0)
    296  {
    297  writeByte(0xFF);
    298  return true;
    299  }
    300  else
    301  {
    302  writeByte(0xFE);
    303  return false;
    304  }
    305 }
    306 
    308 {
    309  return baudrate;
    310 }
    311 
    313 {
    314  return timeout;
    315 }
    316 
    317 void USART::setBaudrate(uint32_t baudrate)
    318 {
    319  this->baudrate = baudrate;
    320 }
    321 
    322 void USART::setTimeout(uint8_t timeout)
    323 {
    324  this->timeout = timeout;
    325 }
    +
    uint32_t getBaudrate(void)
    Definition: usart.cpp:307
    +
    uint8_t readByte(void)
    Definition: usart.cpp:211
    +
    void printStatistics(void)
    Definition: usart.cpp:60
    void closeDevice(void)
    Definition: usart.cpp:32
    void clearInputBuffer(void)
    Definition: usart.cpp:39
    -
    uint8_t getTimeout(void)
    Definition: usart.cpp:311
    +
    uint8_t getTimeout(void)
    Definition: usart.cpp:312
    void clearOutputBuffer(void)
    Definition: usart.cpp:46
    -
    void setBaudrate(uint32_t baudrate)
    Definition: usart.cpp:316
    +
    void setBaudrate(uint32_t baudrate)
    Definition: usart.cpp:317
    void writeByte(uint8_t b)
    Definition: usart.cpp:67
    void openDevice(std::string device)
    Definition: usart.cpp:3
    -
    uint16_t readInt(void)
    Definition: usart.cpp:229
    -
    void setTimeout(uint8_t timeout)
    Definition: usart.cpp:321
    +
    uint16_t readInt(void)
    Definition: usart.cpp:230
    +
    void setTimeout(uint8_t timeout)
    Definition: usart.cpp:322
    void flushOutputBuffer(void)
    Definition: usart.cpp:53
    - +
    void writeInt(uint16_t d)
    Definition: usart.cpp:81
    diff --git a/docs/html/usart_8h_source.html b/docs/html/usart_8h_source.html index 7c8572b..31b8729 100644 --- a/docs/html/usart_8h_source.html +++ b/docs/html/usart_8h_source.html @@ -70,25 +70,25 @@ $(function() {
    usart.h
    -
    1 #ifndef USART_H
    2 #define USART_H
    3 
    4 #include <iostream>
    5 #include <cstdint>
    6 #include <chrono>
    7 #include <unistd.h>
    8 #include <cstring>
    9 #include <fcntl.h>
    10 #include <sys/ioctl.h>
    11 #include <termios.h>
    12 #include <cmath>
    13 #include "usartexception.h"
    14 #include "timeoutexception.h"
    15 
    16 class USART
    17 {
    18 public:
    19 
    20  /*************************************************
    21  * Methoden für die Verwaltung der Schnittstelle *
    22  *************************************************/
    23 
    29  void openDevice(std::string device);
    30 
    35  void closeDevice(void);
    36 
    41  void clearInputBuffer(void);
    42 
    47  void clearOutputBuffer(void);
    48 
    53  void flushOutputBuffer(void);
    54 
    58  void printStatistics(void);
    59 
    60  /*************************************************/
    61 
    62 
    63 
    64  /*************************************
    65  * Methoden für die Datenübertragung *
    66  *************************************/
    67 
    73  void writeByte(uint8_t b);
    74 
    80  void writeInt(uint16_t d);
    81 
    86  uint8_t readByte(void);
    87 
    92  uint16_t readInt(void);
    93 
    94  int read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
    95  int write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
    96  void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len);
    97  bool readBlock(uint8_t* buffer, uint16_t offset);
    98 
    99  /*************************************/
    100 
    101 
    102 
    103  /***************************************
    104  * Methoden für einstellbare Parameter *
    105  ***************************************/
    106 
    111  uint32_t getBaudrate(void);
    112 
    117  uint8_t getTimeout(void);
    118 
    123  void setBaudrate(uint32_t baudrate);
    124 
    129  void setTimeout(uint8_t timeout);
    130 
    131  /***************************************/
    132 
    133  constexpr static uint8_t CRC7_POLY = 0x91;
    134  constexpr static uint8_t MAX_BLOCK_SIZE = 64;
    135  constexpr static uint8_t BLOCK_END = 0x80;
    136 private:
    137 
    138  int file_desc = -1; // Linux Dateideskriptor
    139  uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden!
    140  int TEST = 0;
    141  uint8_t timeout = 10; // in Dezisekunden
    142  uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
    143 
    144  // debug statistics
    145  uint32_t n_blocks_total = 0;
    146  uint32_t n_blocks_failed = 0;
    147 };
    148 
    149 
    150 #endif // USART_H
    -
    uint32_t getBaudrate(void)
    Definition: usart.cpp:306
    -
    uint8_t readByte(void)
    Definition: usart.cpp:210
    +
    1 #ifndef USART_H
    2 #define USART_H
    3 
    4 #include <iostream>
    5 #include <cstdint>
    6 #include <chrono>
    7 #include <unistd.h>
    8 #include <cstring>
    9 #include <fcntl.h>
    10 #include <sys/ioctl.h>
    11 #include <termios.h>
    12 #include <cmath>
    13 #include "usartexception.h"
    14 #include "timeoutexception.h"
    15 
    18 class USART
    19 {
    20 public:
    21 
    22  /*************************************************
    23  * Methoden für die Verwaltung der Schnittstelle *
    24  *************************************************/
    25 
    31  void openDevice(std::string device);
    32 
    37  void closeDevice(void);
    38 
    43  void clearInputBuffer(void);
    44 
    49  void clearOutputBuffer(void);
    50 
    55  void flushOutputBuffer(void);
    56 
    60  void printStatistics(void);
    61 
    62  /*************************************************/
    63 
    64 
    65 
    66  /*************************************
    67  * Methoden für die Datenübertragung *
    68  *************************************/
    69 
    75  void writeByte(uint8_t b);
    76 
    82  void writeInt(uint16_t d);
    83 
    88  uint8_t readByte(void);
    89 
    94  uint16_t readInt(void);
    95 
    96  int read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
    97  int write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout);
    98  void writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len);
    99  bool readBlock(uint8_t* buffer, uint16_t offset);
    100 
    101  /*************************************/
    102 
    103 
    104 
    105  /***************************************
    106  * Methoden für einstellbare Parameter *
    107  ***************************************/
    108 
    113  uint32_t getBaudrate(void);
    114 
    119  uint8_t getTimeout(void);
    120 
    125  void setBaudrate(uint32_t baudrate);
    126 
    131  void setTimeout(uint8_t timeout);
    132 
    133  /***************************************/
    134 
    135  constexpr static uint8_t CRC7_POLY = 0x91;
    136  constexpr static uint8_t MAX_BLOCK_SIZE = 64;
    137  constexpr static uint8_t BLOCK_END = 0x80;
    138 private:
    139 
    140  int file_desc = -1; // Linux Dateideskriptor
    141  uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden!
    142  int TEST = 0;
    143  uint8_t timeout = 10; // in Dezisekunden
    144  uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
    145 
    146  // debug statistics
    147  uint32_t n_blocks_total = 0;
    148  uint32_t n_blocks_failed = 0;
    149 };
    150 
    151 
    152 #endif // USART_H
    +
    uint32_t getBaudrate(void)
    Definition: usart.cpp:307
    +
    uint8_t readByte(void)
    Definition: usart.cpp:211
    void printStatistics(void)
    Definition: usart.cpp:60
    void closeDevice(void)
    Definition: usart.cpp:32
    void clearInputBuffer(void)
    Definition: usart.cpp:39
    -
    uint8_t getTimeout(void)
    Definition: usart.cpp:311
    -
    Definition: usart.h:16
    +
    uint8_t getTimeout(void)
    Definition: usart.cpp:312
    +
    Definition: usart.h:18
    void clearOutputBuffer(void)
    Definition: usart.cpp:46
    -
    void setBaudrate(uint32_t baudrate)
    Definition: usart.cpp:316
    +
    void setBaudrate(uint32_t baudrate)
    Definition: usart.cpp:317
    void writeByte(uint8_t b)
    Definition: usart.cpp:67
    void openDevice(std::string device)
    Definition: usart.cpp:3
    -
    uint16_t readInt(void)
    Definition: usart.cpp:229
    -
    void setTimeout(uint8_t timeout)
    Definition: usart.cpp:321
    +
    uint16_t readInt(void)
    Definition: usart.cpp:230
    +
    void setTimeout(uint8_t timeout)
    Definition: usart.cpp:322
    void flushOutputBuffer(void)
    Definition: usart.cpp:53
    void writeInt(uint16_t d)
    Definition: usart.cpp:81
    diff --git a/docs/html/usartexception_8h_source.html b/docs/html/usartexception_8h_source.html index aa66137..c067c44 100644 --- a/docs/html/usartexception_8h_source.html +++ b/docs/html/usartexception_8h_source.html @@ -70,11 +70,11 @@ $(function() {
    usartexception.h
    -
    1 #ifndef USARTEXCEPTION_H
    2 #define USARTEXCEPTION_H
    3 
    4 #include <exception>
    5 #include <string>
    6 
    7 // SOURCE: https://stackoverflow.com/a/8152888
    8 
    9 class USARTException: public std::exception
    10 {
    11 public:
    12  explicit USARTException(const char* message) : msg(message)
    13  {
    14  }
    15 
    16  explicit USARTException(const std::string& message) : msg(message)
    17  {
    18  }
    19 
    20  virtual ~USARTException() throw ()
    21  {
    22  }
    23 
    24  virtual const char* what() const throw ()
    25  {
    26  return msg.c_str();
    27  }
    28 
    29 protected:
    30  std::string msg;
    31 };
    32 
    33 #endif // USARTEXCEPTION_H
    - +
    1 #ifndef USARTEXCEPTION_H
    2 #define USARTEXCEPTION_H
    3 
    4 #include <exception>
    5 #include <string>
    6 
    7 // SOURCE: https://stackoverflow.com/a/8152888
    8 
    11 class USARTException: public std::exception
    12 {
    13 public:
    14  explicit USARTException(const char* message) : msg(message)
    15  {
    16  }
    17 
    18  explicit USARTException(const std::string& message) : msg(message)
    19  {
    20  }
    21 
    22  virtual ~USARTException() throw ()
    23  {
    24  }
    25 
    26  virtual const char* what() const throw ()
    27  {
    28  return msg.c_str();
    29  }
    30 
    31 protected:
    32  std::string msg;
    33 };
    34 
    35 #endif // USARTEXCEPTION_H
    + diff --git a/docs/html/view_8cpp_source.html b/docs/html/view_8cpp_source.html index bb203a4..0de8167 100644 --- a/docs/html/view_8cpp_source.html +++ b/docs/html/view_8cpp_source.html @@ -70,11 +70,11 @@ $(function() {
    view.cpp
    -
    1 #include "view.h"
    2 
    3 WINDOW* View::win = nullptr;
    4 
    5 View::View()
    6 {
    7  if(!win)
    8  {
    9  B15F::abort("View::win not initialized, missing context");
    10  }
    11  getmaxyx(win, height, width); // init width and height
    12  keypad(win, TRUE);
    13 }
    14 
    15 View::~View()
    16 {
    17 }
    18 
    19 void View::setWinContext(WINDOW* win)
    20 {
    21  View::win = win;
    22 }
    23 
    24 WINDOW* View::getWinContext()
    25 {
    26  return win;
    27 }
    28 
    29 // from: https://stackoverflow.com/a/37454181
    30 std::vector<std::string> View::str_split(const std::string& str, const std::string delim)
    31 {
    32  std::vector<std::string> tokens;
    33  size_t prev = 0, pos = 0;
    34  do
    35  {
    36  pos = str.find(delim, prev);
    37  if (pos == std::string::npos) pos = str.length();
    38  std::string token = str.substr(prev, pos-prev);
    39  if (!token.empty()) tokens.push_back(token);
    40  prev = pos + delim.length();
    41  }
    42  while (pos < str.length() && prev < str.length());
    43  return tokens;
    44 }
    45 
    46 
    47 void View::setTitle(std::string title)
    48 {
    49  this->title = title;
    50 }
    51 
    52 void View::repaint()
    53 {
    54  // get screen size
    55  struct winsize size;
    56  if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0)
    57  throw std::runtime_error("TIOCGWINSZ error");
    58 
    59 
    60  start_x = floor((size.ws_col - width) / 2.);
    61  start_y = floor((size.ws_row - height) / 2.);
    62 
    63  curs_set(0); // hide cursor
    64  mvwin(win, start_y, start_x);
    65  clear();
    66  wclear(win);
    67 
    68  // generic draw
    69  box(win, 0, 0);
    70  int offset_x = (width - title.length()) / 2;
    71  mvwprintw(win, 1, offset_x, "%s", title.c_str());
    72 
    73  // specific draw
    74  draw();
    75 
    76  refresh();
    77  wrefresh(win);
    78 }
    -
    static void abort(std::string msg)
    Definition: b15f.cpp:322
    +
    1 #include "view.h"
    2 
    3 WINDOW* View::win = nullptr;
    4 
    5 View::View()
    6 {
    7  if(!win)
    8  {
    9  B15F::abort("View::win not initialized, missing context");
    10  }
    11  getmaxyx(win, height, width); // init width and height
    12  keypad(win, TRUE);
    13 }
    14 
    15 View::~View()
    16 {
    17 }
    18 
    19 void View::setWinContext(WINDOW* win)
    20 {
    21  View::win = win;
    22 }
    23 
    24 WINDOW* View::getWinContext()
    25 {
    26  return win;
    27 }
    28 
    29 // from: https://stackoverflow.com/a/37454181
    30 std::vector<std::string> View::str_split(const std::string& str, const std::string delim)
    31 {
    32  std::vector<std::string> tokens;
    33  size_t prev = 0, pos = 0;
    34  do
    35  {
    36  pos = str.find(delim, prev);
    37  if (pos == std::string::npos) pos = str.length();
    38  std::string token = str.substr(prev, pos-prev);
    39  if (!token.empty()) tokens.push_back(token);
    40  prev = pos + delim.length();
    41  }
    42  while (pos < str.length() && prev < str.length());
    43  return tokens;
    44 }
    45 
    46 
    47 void View::setTitle(std::string title)
    48 {
    49  this->title = title;
    50 }
    51 
    52 void View::repaint()
    53 {
    54  // get screen size
    55  struct winsize size;
    56  if (ioctl(0, TIOCGWINSZ, (char *) &size) < 0)
    57  throw std::runtime_error("TIOCGWINSZ error");
    58 
    59 
    60  start_x = floor((size.ws_col - width) / 2.);
    61  start_y = floor((size.ws_row - height) / 2.);
    62 
    63  curs_set(0); // hide cursor
    64  mvwin(win, start_y, start_x);
    65  clear();
    66  wclear(win);
    67 
    68  // generic draw
    69  box(win, 0, 0);
    70  int offset_x = (width - title.length()) / 2;
    71  mvwprintw(win, 1, offset_x, "%s", title.c_str());
    72 
    73  // specific draw
    74  draw();
    75 
    76  refresh();
    77  wrefresh(win);
    78 }
    +
    static void abort(std::string msg)
    Definition: b15f.cpp:327
    diff --git a/docs/html/view_8h_source.html b/docs/html/view_8h_source.html index 0cdb246..92e566e 100644 --- a/docs/html/view_8h_source.html +++ b/docs/html/view_8h_source.html @@ -70,11 +70,11 @@ $(function() {
    view.h
    -
    1 #ifndef VIEW_H
    2 #define VIEW_H
    3 
    4 #include <iostream>
    5 #include <cmath>
    6 #include <vector>
    7 #include <functional>
    8 #include <ncurses.h> // sudo apt-get install libncurses5-dev
    9 #include <sys/ioctl.h>
    10 #include <unistd.h>
    11 #include <signal.h>
    12 #include "../drv/b15f.h"
    13 
    14 extern std::string ERR_MSG;
    15 typedef std::function<void(int)> call_t;
    16 
    17 class View
    18 {
    19 public:
    20  View(void);
    21  virtual ~View(void);
    22 
    23  static void setWinContext(WINDOW* win);
    24  static WINDOW* getWinContext(void);
    25  static std::vector<std::string> str_split(const std::string& str, const std::string delim);
    26 
    27  virtual void setTitle(std::string title);
    28 
    29  virtual void repaint(void);
    30 
    31  virtual void draw(void) = 0;
    32  virtual call_t keypress(int& key) = 0;
    33 
    34 
    35 protected:
    36  int width, height;
    37  int start_x = 0, start_y = 0;
    38  std::string title;
    39  std::vector<call_t> calls;
    40 
    41  static WINDOW* win;
    42  constexpr static int KEY_ENT = 10;
    43 };
    44 
    45 #endif // VIEW_H
    -
    Definition: view.h:17
    +
    1 #ifndef VIEW_H
    2 #define VIEW_H
    3 
    4 #include <iostream>
    5 #include <cmath>
    6 #include <vector>
    7 #include <functional>
    8 #include <ncurses.h> // sudo apt-get install libncurses5-dev
    9 #include <sys/ioctl.h>
    10 #include <unistd.h>
    11 #include <signal.h>
    12 #include "../drv/b15f.h"
    13 
    14 extern std::string ERR_MSG;
    15 typedef std::function<void(int)> call_t;
    16 
    19 class View
    20 {
    21 public:
    22  View(void);
    23  virtual ~View(void);
    24 
    25  static void setWinContext(WINDOW* win);
    26  static WINDOW* getWinContext(void);
    27  static std::vector<std::string> str_split(const std::string& str, const std::string delim);
    28 
    29  virtual void setTitle(std::string title);
    30 
    31  virtual void repaint(void);
    32 
    33  virtual void draw(void) = 0;
    34  virtual call_t keypress(int& key) = 0;
    35 
    36 
    37 protected:
    38  int width, height;
    39  int start_x = 0, start_y = 0;
    40  std::string title;
    41  std::vector<call_t> calls;
    42 
    43  static WINDOW* win;
    44  constexpr static int KEY_ENT = 10;
    45 };
    46 
    47 #endif // VIEW_H
    +
    Definition: view.h:19
    diff --git a/docs/html/view__info_8cpp_source.html b/docs/html/view__info_8cpp_source.html index aaf6b4c..2370daf 100644 --- a/docs/html/view__info_8cpp_source.html +++ b/docs/html/view__info_8cpp_source.html @@ -70,10 +70,10 @@ $(function() {
    view_info.cpp
    -
    1 #include "view_info.h"
    2 
    3 ViewInfo::ViewInfo()
    4 {
    5  calls.push_back(nullptr);
    6 }
    7 
    8 void ViewInfo::setText(std::string text)
    9 {
    10  this->text = text;
    11 }
    12 
    13 void ViewInfo::setLabelClose(std::string label)
    14 {
    15  this->label_close = label;
    16 }
    17 
    18 void ViewInfo::setCall(call_t call)
    19 {
    20  calls[0] = call;
    21 }
    22 
    23 void ViewInfo::draw()
    24 {
    25  int li = 0;
    26  for(std::string line : str_split(text, "\n"))
    27  mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str());
    28 
    29  close_offset_x = (width - label_close.length()) / 2;
    30  close_offset_y = height - 2;
    31 
    32  wattron(win, A_REVERSE);
    33  mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str());
    34  wattroff(win, A_REVERSE);
    35 }
    36 
    37 call_t ViewInfo::keypress(int& key)
    38 {
    39  switch(key)
    40  {
    41 
    42  case KEY_MOUSE:
    43  {
    44  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    45  MEVENT event;
    46  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    47  {
    48  size_t column = start_x + close_offset_x;
    49  size_t row = start_y + close_offset_y;
    50  size_t mouse_x = event.x, mouse_y = event.y;
    51  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    52  key = -1; // do return from view
    53  }
    54  break;
    55  }
    56  case KEY_ENT:
    57  key = -1; // do return from view
    58  break;
    59  default:
    60  break;
    61  }
    62  return calls[0];
    63 }
    +
    1 #include "view_info.h"
    2 
    3 ViewInfo::ViewInfo()
    4 {
    5  calls.push_back(nullptr);
    6 }
    7 
    8 void ViewInfo::setText(std::string text)
    9 {
    10  this->text = text;
    11 }
    12 
    13 void ViewInfo::setLabelClose(std::string label)
    14 {
    15  this->label_close = label;
    16 }
    17 
    18 void ViewInfo::setCall(call_t call)
    19 {
    20  calls[0] = call;
    21 }
    22 
    23 void ViewInfo::draw()
    24 {
    25  int li = 0;
    26  for(std::string line : str_split(text, "\n"))
    27  mvwprintw(win, text_offset_y + li++, text_offset_x, "%s", line.c_str());
    28 
    29  close_offset_x = (width - label_close.length()) / 2;
    30  close_offset_y = height - 2;
    31 
    32  wattron(win, A_REVERSE);
    33  mvwprintw(win, close_offset_y, close_offset_x, "%s", label_close.c_str());
    34  wattroff(win, A_REVERSE);
    35 }
    36 
    37 call_t ViewInfo::keypress(int& key)
    38 {
    39  switch(key)
    40  {
    41 
    42  case KEY_MOUSE:
    43  {
    44  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    45  MEVENT event;
    46  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    47  {
    48  size_t column = start_x + close_offset_x;
    49  size_t row = start_y + close_offset_y;
    50  size_t mouse_x = event.x, mouse_y = event.y;
    51  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    52  key = -1; // do return from view
    53  }
    54  break;
    55  }
    56  case KEY_ENT:
    57  key = -1; // do return from view
    58  break;
    59  default:
    60  break;
    61  }
    62  return calls[0];
    63 }
    diff --git a/docs/html/view__info_8h_source.html b/docs/html/view__info_8h_source.html index 0cdd6e1..992f9d7 100644 --- a/docs/html/view__info_8h_source.html +++ b/docs/html/view__info_8h_source.html @@ -70,12 +70,12 @@ $(function() {
    view_info.h
    -
    1 #ifndef VIEW_INFO
    2 #define VIEW_INFO
    3 
    4 #include "view.h"
    5 
    6 class ViewInfo : public View
    7 {
    8 public:
    9  ViewInfo(void);
    10  virtual void setText(std::string text);
    11  virtual void setLabelClose(std::string label);;
    12  virtual void setCall(call_t call);
    13  virtual void draw(void) override;
    14  virtual call_t keypress(int& key) override;
    15 
    16 protected:
    17  std::string text;
    18  std::string label_close;
    19  int close_offset_x = 0;
    20  int close_offset_y = 0;
    21  constexpr static int text_offset_x = 2;
    22  constexpr static int text_offset_y = 3;
    23 };
    24 
    25 #endif // VIEW_INFO
    - -
    Definition: view.h:17
    +
    1 #ifndef VIEW_INFO
    2 #define VIEW_INFO
    3 
    4 #include "view.h"
    5 
    8 class ViewInfo : public View
    9 {
    10 public:
    11  ViewInfo(void);
    12  virtual void setText(std::string text);
    13  virtual void setLabelClose(std::string label);;
    14  virtual void setCall(call_t call);
    15  virtual void draw(void) override;
    16  virtual call_t keypress(int& key) override;
    17 
    18 protected:
    19  std::string text;
    20  std::string label_close;
    21  int close_offset_x = 0;
    22  int close_offset_y = 0;
    23  constexpr static int text_offset_x = 2;
    24  constexpr static int text_offset_y = 3;
    25 };
    26 
    27 #endif // VIEW_INFO
    + +
    Definition: view.h:19
    diff --git a/docs/html/view__monitor_8cpp_source.html b/docs/html/view__monitor_8cpp_source.html index 4513007..5c600ac 100644 --- a/docs/html/view__monitor_8cpp_source.html +++ b/docs/html/view__monitor_8cpp_source.html @@ -70,21 +70,21 @@ $(function() {
    view_monitor.cpp
    -
    1 #include "view_monitor.h"
    2 
    3 ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this)
    4 {
    5 }
    6 
    7 call_t ViewMonitor::keypress(int& key)
    8 {
    9  switch(key)
    10  {
    11 
    12  case KEY_MOUSE:
    13  {
    14  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    15  MEVENT event;
    16  bool hit = false;
    17  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    18  {
    19  size_t column = start_x + close_offset_x;
    20  size_t row = start_y + close_offset_y;
    21  size_t mouse_x = event.x, mouse_y = event.y;
    22  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    23  hit = true;
    24  }
    25  if(!hit)
    26  break;
    27 
    28  // fall through to next case
    29  [[fallthrough]];
    30  }
    31  case KEY_ENT:
    32  run_worker = false;
    33  key = -1; // do return from view
    34  wclear(win);
    35  wrefresh(win);
    36  t_worker.join();
    37  break;
    38  default:
    39  break;
    40  }
    41  return calls[0];
    42 }
    43 
    44 std::string ViewMonitor::fancyDigitalString(uint8_t& b)
    45 {
    46  std::stringstream str;
    47  str << std::bitset<8>(b).to_string();
    48  str << " ";
    49  str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec;
    50  return str.str();
    51 }
    52 
    53 std::string ViewMonitor::fancyAnalogString(uint16_t& v)
    54 {
    55  std::stringstream str;
    56  double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
    57 
    58  str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V ";
    59 
    60  str << "[";
    61  uint8_t p = round(v * 40.0 / 1023.0);
    62  for(uint8_t i = 0; i < p; i++)
    63  str << "X";
    64  for(uint8_t i = 0; i < 40 - p; i++)
    65  str << " ";
    66  str << "]" << std::endl;
    67 
    68  return str.str();
    69 }
    70 
    71 void ViewMonitor::worker()
    72 {
    73  B15F& drv = B15F::getInstance();
    74  while(run_worker)
    75  {
    76  try
    77  {
    78  std::this_thread::sleep_for(std::chrono::milliseconds(100));
    79 
    80  uint8_t be0 = drv.digitalRead0();
    81  uint8_t be1 = drv.digitalRead1();
    82  uint8_t dsw = drv.readDipSwitch();
    83  uint16_t adc[8];
    84  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    85  adc[i] = drv.analogRead(i);
    86 
    87 
    88  std::stringstream str;
    89 
    90  // hline
    91  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    92  if(i % 2 == 0)
    93  str << "-";
    94  else
    95  str << " ";
    96  str << std::endl;
    97 
    98  str << "Digitale Enigaenge:" << std::endl;
    99  str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
    100  str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
    101  str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
    102 
    103  // hline
    104  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    105  if(i % 2 == 0)
    106  str << "-";
    107  else
    108  str << " ";
    109  str << std::endl;
    110 
    111  str << "Analoge Eingaenge:" << std::endl;
    112  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    113  {
    114  str << "Kanal " << std::to_string((int) i) << ": ";
    115  str << fancyAnalogString(adc[i]) << std::endl;
    116  }
    117 
    118  text = str.str();
    119  repaint();
    120  }
    121  catch(DriverException& ex)
    122  {
    123  std::cout << "DriverException: " << ex.what() << std::endl;
    124  drv.delay_ms(1000);
    125  }
    126  catch(...)
    127  {
    128  try
    129  {
    130  drv.reconnect();
    131  }
    132  catch(...)
    133  {
    134  B15F::abort("yoho meine dudes");
    135  return;
    136  }
    137  }
    138  }
    139 }
    - -
    uint8_t digitalRead0(void)
    Definition: b15f.cpp:172
    -
    uint8_t readDipSwitch(void)
    Definition: b15f.cpp:190
    -
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:290
    -
    static B15F & getInstance(void)
    Definition: b15f.cpp:300
    -
    Definition: b15f.h:24
    -
    static void abort(std::string msg)
    Definition: b15f.cpp:322
    -
    uint16_t analogRead(uint8_t channel)
    Definition: b15f.cpp:219
    -
    uint8_t digitalRead1(void)
    Definition: b15f.cpp:181
    +
    1 #include "view_monitor.h"
    2 
    3 ViewMonitor::ViewMonitor() : t_worker(&ViewMonitor::worker, this)
    4 {
    5 }
    6 
    7 call_t ViewMonitor::keypress(int& key)
    8 {
    9  switch(key)
    10  {
    11 
    12  case KEY_MOUSE:
    13  {
    14  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    15  MEVENT event;
    16  bool hit = false;
    17  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    18  {
    19  size_t column = start_x + close_offset_x;
    20  size_t row = start_y + close_offset_y;
    21  size_t mouse_x = event.x, mouse_y = event.y;
    22  if(mouse_y == row && mouse_x >= column && mouse_x < column + label_close.length())
    23  hit = true;
    24  }
    25  if(!hit)
    26  break;
    27 
    28  // fall through to next case
    29  [[fallthrough]];
    30  }
    31  case KEY_ENT:
    32  run_worker = false;
    33  key = -1; // do return from view
    34  wclear(win);
    35  wrefresh(win);
    36  t_worker.join();
    37  break;
    38  default:
    39  break;
    40  }
    41  return calls[0];
    42 }
    43 
    44 std::string ViewMonitor::fancyDigitalString(uint8_t& b)
    45 {
    46  std::stringstream str;
    47  str << std::bitset<8>(b).to_string();
    48  str << " ";
    49  str << "0x" << std::setfill ('0') << std::setw(2) << std::hex << (int) b << std::dec;
    50  return str.str();
    51 }
    52 
    53 std::string ViewMonitor::fancyAnalogString(uint16_t& v)
    54 {
    55  std::stringstream str;
    56  double volt = round(v * 100.0 * 5.0 / 1023.0) / 100.0;
    57 
    58  str << std::setfill ('0') << std::setw(4) << (int) v << " " << std::fixed << std::setprecision(2) << volt << " V ";
    59 
    60  str << "[";
    61  uint8_t p = round(v * 40.0 / 1023.0);
    62  for(uint8_t i = 0; i < p; i++)
    63  str << "X";
    64  for(uint8_t i = 0; i < 40 - p; i++)
    65  str << " ";
    66  str << "]" << std::endl;
    67 
    68  return str.str();
    69 }
    70 
    71 void ViewMonitor::worker()
    72 {
    73  B15F& drv = B15F::getInstance();
    74  while(run_worker)
    75  {
    76  try
    77  {
    78  std::this_thread::sleep_for(std::chrono::milliseconds(100));
    79 
    80  uint8_t be0 = drv.digitalRead0();
    81  uint8_t be1 = drv.digitalRead1();
    82  uint8_t dsw = drv.readDipSwitch();
    83  uint16_t adc[8];
    84  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    85  adc[i] = drv.analogRead(i);
    86 
    87 
    88  std::stringstream str;
    89 
    90  // hline
    91  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    92  if(i % 2 == 0)
    93  str << "-";
    94  else
    95  str << " ";
    96  str << std::endl;
    97 
    98  str << "Digitale Enigaenge:" << std::endl;
    99  str << "Binaere Eingabe 0: " << fancyDigitalString(be0) << std::endl;
    100  str << "Binaere Eingabe 1: " << fancyDigitalString(be1) << std::endl;
    101  str << "Dip Schalter (S7): " << fancyDigitalString(dsw) << std::endl;
    102 
    103  // hline
    104  for(uint8_t i = 0; i < width - 2 * text_offset_x; i++)
    105  if(i % 2 == 0)
    106  str << "-";
    107  else
    108  str << " ";
    109  str << std::endl;
    110 
    111  str << "Analoge Eingaenge:" << std::endl;
    112  for(uint8_t i = 0; i < sizeof(adc) / sizeof(adc[0]); i++)
    113  {
    114  str << "Kanal " << std::to_string((int) i) << ": ";
    115  str << fancyAnalogString(adc[i]) << std::endl;
    116  }
    117 
    118  text = str.str();
    119  repaint();
    120  }
    121  catch(DriverException& ex)
    122  {
    123  std::cout << "DriverException: " << ex.what() << std::endl;
    124  drv.delay_ms(1000);
    125  }
    126  catch(...)
    127  {
    128  try
    129  {
    130  drv.reconnect();
    131  }
    132  catch(...)
    133  {
    134  B15F::abort("yoho meine dudes");
    135  return;
    136  }
    137  }
    138  }
    139 }
    + +
    uint8_t digitalRead0(void)
    Definition: b15f.cpp:173
    +
    uint8_t readDipSwitch(void)
    Definition: b15f.cpp:191
    +
    void delay_ms(uint16_t ms)
    Definition: b15f.cpp:292
    +
    static B15F & getInstance(void)
    Definition: b15f.cpp:302
    +
    Definition: b15f.h:26
    +
    static void abort(std::string msg)
    Definition: b15f.cpp:327
    +
    uint16_t analogRead(uint8_t channel)
    Definition: b15f.cpp:220
    +
    uint8_t digitalRead1(void)
    Definition: b15f.cpp:182
    void reconnect(void)
    Definition: b15f.cpp:57
    - + diff --git a/docs/html/view__monitor_8h_source.html b/docs/html/view__monitor_8h_source.html index e224df6..0c48289 100644 --- a/docs/html/view__monitor_8h_source.html +++ b/docs/html/view__monitor_8h_source.html @@ -70,12 +70,12 @@ $(function() {
    view_monitor.h
    -
    1 #ifndef VIEW_MONITOR_H
    2 #define VIEW_MONITOR_H
    3 
    4 #include <thread>
    5 #include <chrono>
    6 #include <sstream>
    7 #include <bitset>
    8 #include "view_info.h"
    9 #include "../drv/b15f.h"
    10 
    11 class ViewMonitor : public ViewInfo
    12 {
    13 
    14 public:
    15  ViewMonitor(void);
    16  virtual call_t keypress(int& key) override;
    17 
    18 private:
    19  std::string fancyDigitalString(uint8_t& b);
    20  std::string fancyAnalogString(uint16_t& v);
    21 
    22 protected:
    23  virtual void worker(void);
    24  volatile bool run_worker = true;
    25  std::thread t_worker;
    26 
    27 };
    28 
    29 #endif // VIEW_MONITOR_H
    - - +
    1 #ifndef VIEW_MONITOR_H
    2 #define VIEW_MONITOR_H
    3 
    4 #include <thread>
    5 #include <chrono>
    6 #include <sstream>
    7 #include <bitset>
    8 #include "view_info.h"
    9 #include "../drv/b15f.h"
    10 
    13 class ViewMonitor : public ViewInfo
    14 {
    15 
    16 public:
    17  ViewMonitor(void);
    18  virtual call_t keypress(int& key) override;
    19 
    20 private:
    21  std::string fancyDigitalString(uint8_t& b);
    22  std::string fancyAnalogString(uint16_t& v);
    23 
    24 protected:
    25  virtual void worker(void);
    26  volatile bool run_worker = true;
    27  std::thread t_worker;
    28 
    29 };
    30 
    31 #endif // VIEW_MONITOR_H
    + + diff --git a/docs/html/view__promt_8cpp_source.html b/docs/html/view__promt_8cpp_source.html index ce44e4d..cef242a 100644 --- a/docs/html/view__promt_8cpp_source.html +++ b/docs/html/view__promt_8cpp_source.html @@ -70,10 +70,10 @@ $(function() {
    view_promt.cpp
    -
    1 #include "view_promt.h"
    2 
    3 void ViewPromt::draw()
    4 {
    5  curs_set(1); // show cursor
    6 
    7  int li = text_offset_y;
    8  int ci = 0;
    9  for(std::string line : str_split(message + input, "\n"))
    10  {
    11  mvwprintw(win, ++li, text_offset_x, "%s", line.c_str());
    12  ci = line.length() + text_offset_x;
    13  }
    14 
    15  button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
    16  button_offset_y = height - text_offset_y;
    17 
    18  if(selection == 0)
    19  {
    20  wattron(win, A_REVERSE);
    21  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    22  wattroff(win, A_REVERSE);
    23  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    24  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    25  }
    26  else
    27  {
    28  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    29  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    30  wattron(win, A_REVERSE);
    31  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    32  wattroff(win, A_REVERSE);
    33  }
    34  wmove(win, li, ci);
    35 }
    36 
    37 void ViewPromt::setMessage(std::string message)
    38 {
    39  this->message = message;
    40 }
    41 
    42 void ViewPromt::setConfirm(std::string name, std::function<void(int)> call)
    43 {
    44  label_confirm = name;
    45  call_confirm = call;
    46 }
    47 
    48 void ViewPromt::setCancel(std::string name, bool cancelable)
    49 {
    50  label_cancel = name;
    51  this->cancelable = cancelable;
    52 }
    53 
    54 std::string ViewPromt::getInput()
    55 {
    56  return input;
    57 }
    58 
    59 std::function<void(int)> ViewPromt::keypress(int& key)
    60 {
    61  std::function<void(int)> ret = nullptr;
    62  switch(key)
    63  {
    64  case KEY_BACKSPACE:
    65  if(input.length())
    66  input.pop_back();
    67  break;
    68  case '\t':
    69  case KEY_LEFT:
    70  case KEY_RIGHT:
    71  selection = (selection + 1 ) % 2;
    72  break;
    73  case KEY_MOUSE:
    74  {
    75  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    76  MEVENT event;
    77  bool hit = false;
    78  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    79  {
    80  size_t column_start = start_x + button_offset_x;
    81  size_t row_start = start_y + button_offset_y;
    82  size_t mouse_x = event.x, mouse_y = event.y;
    83  if(mouse_y == row_start)
    84  {
    85  if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length())
    86  {
    87  if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    88  hit = true;
    89  selection = 0;
    90  }
    91  if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length())
    92  {
    93  if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    94  hit = true;
    95  selection = 1;
    96  }
    97  }
    98  }
    99  if(!hit)
    100  break;
    101 
    102  // fall through to next case
    103  [[fallthrough]];
    104  }
    105  case KEY_ENT:
    106  if(selection == 0) // exit
    107  key = -1; // do return from view
    108  else
    109  ret = call_confirm;
    110  break;
    111  default:
    112  break;
    113  }
    114 
    115  if(key >= ' ' && key <= '~')
    116  input += (char) key;
    117 
    118  if(key != KEY_ENT)
    119  repaint();
    120  return ret;
    121 }
    +
    1 #include "view_promt.h"
    2 
    3 void ViewPromt::draw()
    4 {
    5  curs_set(1); // show cursor
    6 
    7  int li = text_offset_y;
    8  int ci = 0;
    9  for(std::string line : str_split(message + input, "\n"))
    10  {
    11  mvwprintw(win, ++li, text_offset_x, "%s", line.c_str());
    12  ci = line.length() + text_offset_x;
    13  }
    14 
    15  button_offset_x = (width - label_cancel.length() - sep.length() - label_confirm.length()) / 2;
    16  button_offset_y = height - text_offset_y;
    17 
    18  if(selection == 0)
    19  {
    20  wattron(win, A_REVERSE);
    21  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    22  wattroff(win, A_REVERSE);
    23  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    24  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    25  }
    26  else
    27  {
    28  mvwprintw(win, button_offset_y, button_offset_x, "%s", label_cancel.c_str());
    29  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length(), "%s", sep.c_str());
    30  wattron(win, A_REVERSE);
    31  mvwprintw(win, button_offset_y, button_offset_x + label_cancel.length() + sep.length(), "%s", label_confirm.c_str());
    32  wattroff(win, A_REVERSE);
    33  }
    34  wmove(win, li, ci);
    35 }
    36 
    37 void ViewPromt::setMessage(std::string message)
    38 {
    39  this->message = message;
    40 }
    41 
    42 void ViewPromt::setConfirm(std::string name, std::function<void(int)> call)
    43 {
    44  label_confirm = name;
    45  call_confirm = call;
    46 }
    47 
    48 void ViewPromt::setCancel(std::string name, bool cancelable)
    49 {
    50  label_cancel = name;
    51  this->cancelable = cancelable;
    52 }
    53 
    54 std::string ViewPromt::getInput()
    55 {
    56  return input;
    57 }
    58 
    59 std::function<void(int)> ViewPromt::keypress(int& key)
    60 {
    61  std::function<void(int)> ret = nullptr;
    62  switch(key)
    63  {
    64  case KEY_BACKSPACE:
    65  if(input.length())
    66  input.pop_back();
    67  break;
    68  case '\t':
    69  case KEY_LEFT:
    70  case KEY_RIGHT:
    71  selection = (selection + 1 ) % 2;
    72  break;
    73  case KEY_MOUSE:
    74  {
    75  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    76  MEVENT event;
    77  bool hit = false;
    78  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    79  {
    80  size_t column_start = start_x + button_offset_x;
    81  size_t row_start = start_y + button_offset_y;
    82  size_t mouse_x = event.x, mouse_y = event.y;
    83  if(mouse_y == row_start)
    84  {
    85  if(cancelable && mouse_x >= column_start && mouse_x < column_start + label_cancel.length())
    86  {
    87  if(selection == 0 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    88  hit = true;
    89  selection = 0;
    90  }
    91  if(mouse_x >= column_start + label_cancel.length() + sep.length() && mouse_x < column_start + label_cancel.length() + sep.length() + label_confirm.length())
    92  {
    93  if(selection == 1 || event.bstate & BUTTON1_DOUBLE_CLICKED)
    94  hit = true;
    95  selection = 1;
    96  }
    97  }
    98  }
    99  if(!hit)
    100  break;
    101 
    102  // fall through to next case
    103  [[fallthrough]];
    104  }
    105  case KEY_ENT:
    106  if(selection == 0) // exit
    107  key = -1; // do return from view
    108  else
    109  ret = call_confirm;
    110  break;
    111  default:
    112  break;
    113  }
    114 
    115  if(key >= ' ' && key <= '~')
    116  input += (char) key;
    117 
    118  if(key != KEY_ENT)
    119  repaint();
    120  return ret;
    121 }
    diff --git a/docs/html/view__promt_8h_source.html b/docs/html/view__promt_8h_source.html index f09c0c1..df2d726 100644 --- a/docs/html/view__promt_8h_source.html +++ b/docs/html/view__promt_8h_source.html @@ -70,12 +70,12 @@ $(function() {
    view_promt.h
    -
    1 #ifndef VIEW_PROMT_H
    2 #define VIEW_PROMT_H
    3 
    4 #include <vector>
    5 #include <string>
    6 #include "view.h"
    7 
    8 class ViewPromt : public View
    9 {
    10 public:
    11  virtual void draw(void) override;
    12  virtual void setMessage(std::string message);
    13  virtual void setConfirm(std::string name, call_t call);
    14  virtual void setCancel(std::string name, bool cancelable);
    15  virtual std::string getInput(void);
    16  virtual call_t keypress(int& key) override;
    17 
    18 protected:
    19  size_t selection = 1;
    20  std::string input;
    21  std::string message = "Input";
    22  std::string label_confirm = "[ OK ]";
    23  std::string sep = " ";
    24  std::string label_cancel = "[ Cancel ]";
    25  call_t call_confirm = nullptr;
    26  bool cancelable = true;
    27  int button_offset_x = 0, button_offset_y = 0;
    28  constexpr static int text_offset_x = 2;
    29  constexpr static int text_offset_y = 2;
    30 };
    31 
    32 #endif // VIEW_PROMT_H
    -
    Definition: view.h:17
    - +
    1 #ifndef VIEW_PROMT_H
    2 #define VIEW_PROMT_H
    3 
    4 #include <vector>
    5 #include <string>
    6 #include "view.h"
    7 
    10 class ViewPromt : public View
    11 {
    12 public:
    13  virtual void draw(void) override;
    14  virtual void setMessage(std::string message);
    15  virtual void setConfirm(std::string name, call_t call);
    16  virtual void setCancel(std::string name, bool cancelable);
    17  virtual std::string getInput(void);
    18  virtual call_t keypress(int& key) override;
    19 
    20 protected:
    21  size_t selection = 1;
    22  std::string input;
    23  std::string message = "Input";
    24  std::string label_confirm = "[ OK ]";
    25  std::string sep = " ";
    26  std::string label_cancel = "[ Cancel ]";
    27  call_t call_confirm = nullptr;
    28  bool cancelable = true;
    29  int button_offset_x = 0, button_offset_y = 0;
    30  constexpr static int text_offset_x = 2;
    31  constexpr static int text_offset_y = 2;
    32 };
    33 
    34 #endif // VIEW_PROMT_H
    +
    Definition: view.h:19
    + diff --git a/docs/html/view__selection_8cpp_source.html b/docs/html/view__selection_8cpp_source.html index 4a45641..bd16c53 100644 --- a/docs/html/view__selection_8cpp_source.html +++ b/docs/html/view__selection_8cpp_source.html @@ -70,10 +70,10 @@ $(function() {
    view_selection.cpp
    -
    1 #include "view_selection.h"
    2 
    3 void ViewSelection::draw()
    4 {
    5  //curs_set(0); // hide cursor
    6  for(size_t i = 0; i < choices.size(); i++)
    7  {
    8  if(selection == i)
    9  wattron(win, A_REVERSE);
    10  mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str());
    11  if(selection == i)
    12  wattroff(win, A_REVERSE);
    13  }
    14 }
    15 
    16 void ViewSelection::addChoice(std::string name, call_t call)
    17 {
    18  choices.push_back(name);
    19  calls.push_back(call);
    20 }
    21 
    22 call_t ViewSelection::keypress(int& key)
    23 {
    24  call_t ret = nullptr;
    25  switch(key)
    26  {
    27  case KEY_UP:
    28  do
    29  selection = (selection - 1 + choices.size()) % choices.size();
    30  while(!choices[selection].length() && choices.size());
    31  break;
    32 
    33  case '\t':
    34  case KEY_DOWN:
    35  do
    36  selection = (selection + 1) % choices.size();
    37  while(!choices[selection].length() && choices.size());
    38  break;
    39 
    40  case KEY_MOUSE:
    41  {
    42  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    43  MEVENT event;
    44  bool hit = false;
    45  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    46  {
    47  size_t column_start = start_x + choice_offset_x;
    48  size_t row_start = start_y + choice_offset_y;
    49  size_t mouse_x = event.x, mouse_y = event.y;
    50  for(size_t i = 0; i < choices.size(); i++)
    51  if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length())
    52  {
    53  if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED)
    54  hit = true;
    55  selection = i;
    56  }
    57  }
    58  if(!hit)
    59  break;
    60 
    61  // fall through to next case
    62  [[fallthrough]];
    63  }
    64 
    65  case KEY_ENT:
    66  if(selection == choices.size() - 1) // exit
    67  key = -1; // do return from view
    68  else
    69  ret = calls[selection];
    70  break;
    71  default:
    72  break;
    73  }
    74  repaint();
    75  return ret;
    76 }
    +
    1 #include "view_selection.h"
    2 
    3 void ViewSelection::draw()
    4 {
    5  //curs_set(0); // hide cursor
    6  for(size_t i = 0; i < choices.size(); i++)
    7  {
    8  if(selection == i)
    9  wattron(win, A_REVERSE);
    10  mvwprintw(win, i + choice_offset_y, choice_offset_x, "%s", choices[i].c_str());
    11  if(selection == i)
    12  wattroff(win, A_REVERSE);
    13  }
    14 }
    15 
    16 void ViewSelection::addChoice(std::string name, call_t call)
    17 {
    18  choices.push_back(name);
    19  calls.push_back(call);
    20 }
    21 
    22 call_t ViewSelection::keypress(int& key)
    23 {
    24  call_t ret = nullptr;
    25  switch(key)
    26  {
    27  case KEY_UP:
    28  do
    29  selection = (selection - 1 + choices.size()) % choices.size();
    30  while(!choices[selection].length() && choices.size());
    31  break;
    32 
    33  case '\t':
    34  case KEY_DOWN:
    35  do
    36  selection = (selection + 1) % choices.size();
    37  while(!choices[selection].length() && choices.size());
    38  break;
    39 
    40  case KEY_MOUSE:
    41  {
    42  // http://pronix.linuxdelta.de/C/Linuxprogrammierung/Linuxsystemprogrammieren_C_Kurs_Kapitel10b.shtml
    43  MEVENT event;
    44  bool hit = false;
    45  if(getmouse(&event) == OK && event.bstate & (BUTTON1_CLICKED | BUTTON1_DOUBLE_CLICKED))
    46  {
    47  size_t column_start = start_x + choice_offset_x;
    48  size_t row_start = start_y + choice_offset_y;
    49  size_t mouse_x = event.x, mouse_y = event.y;
    50  for(size_t i = 0; i < choices.size(); i++)
    51  if(choices[i].length() && mouse_y == row_start + i && mouse_x >= column_start && mouse_x < column_start + choices[i].length())
    52  {
    53  if(selection == i || event.bstate & BUTTON1_DOUBLE_CLICKED)
    54  hit = true;
    55  selection = i;
    56  }
    57  }
    58  if(!hit)
    59  break;
    60 
    61  // fall through to next case
    62  [[fallthrough]];
    63  }
    64 
    65  case KEY_ENT:
    66  if(selection == choices.size() - 1) // exit
    67  key = -1; // do return from view
    68  else
    69  ret = calls[selection];
    70  break;
    71  default:
    72  break;
    73  }
    74  repaint();
    75  return ret;
    76 }
    diff --git a/docs/html/view__selection_8h_source.html b/docs/html/view__selection_8h_source.html index 9cfd46e..ece3b9c 100644 --- a/docs/html/view__selection_8h_source.html +++ b/docs/html/view__selection_8h_source.html @@ -70,12 +70,12 @@ $(function() {
    view_selection.h
    -
    1 #ifndef VIEW_SELECTION_H
    2 #define VIEW_SELECTION_H
    3 
    4 #include <vector>
    5 #include <string>
    6 #include "view.h"
    7 
    8 class ViewSelection : public View
    9 {
    10 public:
    11  virtual void draw(void) override;
    12  virtual void addChoice(std::string name, call_t call);
    13  virtual call_t keypress(int& key) override;
    14 
    15 
    16 protected:
    17  size_t selection = 0;
    18  std::vector<std::string> choices;
    19 
    20  constexpr static int choice_offset_x = 2;
    21  constexpr static int choice_offset_y = 3;
    22 };
    23 
    24 #endif // VIEW_SELECTION_H
    -
    Definition: view.h:17
    - +
    1 #ifndef VIEW_SELECTION_H
    2 #define VIEW_SELECTION_H
    3 
    4 #include <vector>
    5 #include <string>
    6 #include "view.h"
    7 
    10 class ViewSelection : public View
    11 {
    12 public:
    13  virtual void draw(void) override;
    14  virtual void addChoice(std::string name, call_t call);
    15  virtual call_t keypress(int& key) override;
    16 
    17 
    18 protected:
    19  size_t selection = 0;
    20  std::vector<std::string> choices;
    21 
    22  constexpr static int choice_offset_x = 2;
    23  constexpr static int choice_offset_y = 3;
    24 };
    25 
    26 #endif // VIEW_SELECTION_H
    +
    Definition: view.h:19
    + diff --git a/docs/index.html b/docs/index.html index 1324b98..f4f7ec6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,14 +2,14 @@ - + Page Redirection - If you are not redirected automatically, follow this link to example. + If you are not redirected automatically, follow this link to example.