diff --git a/driver/drv/b15f.cpp b/driver/drv/b15f.cpp index f53d066..fc3f804 100644 --- a/driver/drv/b15f.cpp +++ b/driver/drv/b15f.cpp @@ -30,7 +30,10 @@ void B15F::init() // Temporärer Test uint8_t block[] = {0, 1, 2, 3}; while(1) + { usart.writeBlock(&block[0], 0, sizeof(block)); + usart.printStatistics(); + } throw std::runtime_error("SCHLUSS"); @@ -83,13 +86,13 @@ void B15F::reconnect() void B15F::discard(void) { - usart.flushOutputBuffer(); + usart.clearOutputBuffer(); for(uint8_t i = 0; i < 8; i++) { usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input) delay_ms((16000 / BAUDRATE) + 1); // warte mindestens eine Millisekunde, gegebenenfalls mehr } - usart.flushInputBuffer(); + usart.clearInputBuffer(); } bool B15F::testConnection() @@ -147,7 +150,7 @@ std::vector B15F::getBoardInfo(void) bool B15F::digitalWrite0(uint8_t port) { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_BA0); usart.writeByte(port); @@ -157,7 +160,7 @@ bool B15F::digitalWrite0(uint8_t port) bool B15F::digitalWrite1(uint8_t port) { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_BA1); usart.writeByte(port); @@ -167,21 +170,21 @@ bool B15F::digitalWrite1(uint8_t port) uint8_t B15F::digitalRead0() { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_BE0); return usart.readByte(); } uint8_t B15F::digitalRead1() { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_BE1); return usart.readByte(); } bool B15F::analogWrite0(uint16_t value) { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_AA0); usart.writeInt(value); @@ -191,7 +194,7 @@ bool B15F::analogWrite0(uint16_t value) bool B15F::analogWrite1(uint16_t value) { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_AA1); usart.writeInt(value); @@ -201,7 +204,7 @@ bool B15F::analogWrite1(uint16_t value) uint16_t B15F::analogRead(uint8_t channel) { - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_ADC); usart.writeByte(channel); return usart.readInt(); @@ -212,7 +215,7 @@ bool B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset buffer_a += offset_a; buffer_b += offset_b; - usart.flushInputBuffer(); + usart.clearInputBuffer(); usart.writeByte(RQ_ADC_DAC_STROKE); usart.writeByte(channel_a); usart.writeByte(channel_b); diff --git a/driver/drv/b15f.o b/driver/drv/b15f.o index 0bd67cc..79f3e7b 100644 Binary files a/driver/drv/b15f.o and b/driver/drv/b15f.o differ diff --git a/driver/drv/usart.cpp b/driver/drv/usart.cpp index d2e8bdd..1516c59 100644 --- a/driver/drv/usart.cpp +++ b/driver/drv/usart.cpp @@ -25,8 +25,8 @@ void USART::openDevice(std::string device) if(code) throw USARTException("Fehler beim Setzen der Geräteparameter"); - flushOutputBuffer(); - flushInputBuffer(); + clearOutputBuffer(); + clearInputBuffer(); } void USART::closeDevice() @@ -36,20 +36,27 @@ void USART::closeDevice() throw USARTException("Fehler beim Schließen des Gerätes"); } -void USART::flushInputBuffer() +void USART::clearInputBuffer() { int code = tcflush(file_desc, TCIFLUSH); if(code) throw USARTException("Fehler beim Leeren des Eingangspuffers"); } -void USART::flushOutputBuffer() +void USART::clearOutputBuffer() { int code = tcflush(file_desc, TCOFLUSH); if(code) throw USARTException("Fehler beim Leeren 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; +} + void USART::writeByte(uint8_t b) { int sent = write(file_desc, &b, 1); @@ -118,6 +125,9 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len) 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 @@ -163,10 +173,14 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len) if(n_read != 1) throw std::runtime_error("fatal: " + std::to_string(n_read)); - //flushInputBuffer(); + //clearInputBuffer(); - if(aw != 0xFF) + if(aw != 0xFF) { + if(!failed) + n_blocks_failed++; + failed = true; std::cout << "block failed, retry" << std::endl; + } } while(aw != 0xFF); diff --git a/driver/drv/usart.h b/driver/drv/usart.h index 006ffef..e375e8c 100644 --- a/driver/drv/usart.h +++ b/driver/drv/usart.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "usartexception.h" #include "timeoutexception.h" @@ -37,13 +38,18 @@ public: * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gelesen wurden * \throws USARTException */ - void flushInputBuffer(void); + void clearInputBuffer(void); /** * Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden * \throws USARTException */ - void flushOutputBuffer(void); + void clearOutputBuffer(void); + + /** + * Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an + */ + void printStatistics(void); /*************************************************/ @@ -128,6 +134,10 @@ private: 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/driver/drv/usart.o b/driver/drv/usart.o index ef05e38..ed30f7a 100644 Binary files a/driver/drv/usart.o and b/driver/drv/usart.o differ diff --git a/driver/main b/driver/main index 83512de..307f0d1 100755 Binary files a/driver/main and b/driver/main differ