diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index 1b37840..217a4eb 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -323,8 +323,8 @@ void HardwareSetup::run() { cout << "Port opened" << endl; // prepare buffer - struct TransStruct * received; - uint8_t uintBuf[4 * 6]; + struct TransCheck * received; + uint8_t uintBuf[4 * 6 + 2]; void * voidBuf; // configure among others non-canonical mode (important) @@ -334,7 +334,7 @@ void HardwareSetup::run() { tcsetattr(fd, TCSANOW, &config); // read raw data to buffer - ssize_t length = read(fd, uintBuf, 24); + ssize_t length = read(fd, uintBuf, 24 + 2); // flush existing data if (length < 24) { @@ -345,47 +345,66 @@ void HardwareSetup::run() { // read data cout << "try to read data" << endl; - read(this->fd, uintBuf, 4 * 6); + read(this->fd, uintBuf, 4 * 6 + 2); cout << "data read" << endl; voidBuf = static_cast(uintBuf); - received = static_cast(voidBuf); + received = static_cast(voidBuf); - usleep(150000); // 150ms + usleep(50000); // 150ms for (int i = 0; i < 6; i++) { - if (received[i].update != 0) { - switch (received[i].id) { - case 0: - cout << "Shell Zeit 1: " - << static_cast(received[i].time) << endl; - emit Shell(static_cast(received[i].time), 1); - break; - case 1: - cout << "Dea Zeit 1: " - << static_cast(received[i].time) << endl; - emit Dea(static_cast(received[i].time), 1); - break; - case 2: - cout << "Shell Zeit 2: " - << static_cast(received[i].time) << endl; - emit Shell(static_cast(received[i].time), 2); - break; - case 3: - cout << "Dea Zeit 2: " - << static_cast(received[i].time) << endl; - emit Dea(static_cast(received[i].time), 2); - break; - case 4: - cout << "Shell Zeit 2: " - << static_cast(received[i].time) << endl; - emit Shell(static_cast(received[i].time), 3); - break; - case 5: - cout << "Dea Zeit 3: " - << static_cast(received[i].time) << endl; - emit Dea(static_cast(received[i].time), 3); - break; + if (received->begin == '#' && received->end == '!') { + + if (received->data[i].update != 0) { + switch (received->data[i].id) { + case 0: + cout << "Shell Zeit 1: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), + 1); + break; + case 1: + cout << "Dea Zeit 1: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), + 1); + break; + case 2: + cout << "Shell Zeit 2: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), + 2); + break; + case 3: + cout << "Dea Zeit 2: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), + 2); + break; + case 4: + cout << "Shell Zeit 2: " + << static_cast(received->data[i].time) + << endl; + emit Shell(static_cast(received->data[i].time), + 3); + break; + case 5: + cout << "Dea Zeit 3: " + << static_cast(received->data[i].time) + << endl; + emit Dea(static_cast(received->data[i].time), + 3); + break; + } } + } // dataframe ok + else { + // dataframe not ok + tcflush(fd, TCIFLUSH); } } } diff --git a/hardwaresetup.h b/hardwaresetup.h index 39cd6b6..68a5ab2 100644 --- a/hardwaresetup.h +++ b/hardwaresetup.h @@ -6,7 +6,7 @@ #include #include #ifdef ATMEGA - #include +#include #endif struct TransStruct { uint16_t time; @@ -14,6 +14,12 @@ struct TransStruct { uint8_t update; }; +struct TransCheck { + char begin; + struct TransStruct data[6]; + char end; +}; + class HardwareSetup : public QThread { Q_OBJECT protected: