added some transmission safety

This commit is contained in:
2018-12-23 21:55:03 +01:00
parent 09d69b9bb4
commit 12fd6da5f4
2 changed files with 64 additions and 39 deletions

View File

@@ -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<void *>(uintBuf);
received = static_cast<struct TransStruct *>(voidBuf);
received = static_cast<struct TransCheck *>(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<int>(received[i].time) << endl;
emit Shell(static_cast<int>(received[i].time), 1);
break;
case 1:
cout << "Dea Zeit 1: "
<< static_cast<int>(received[i].time) << endl;
emit Dea(static_cast<int>(received[i].time), 1);
break;
case 2:
cout << "Shell Zeit 2: "
<< static_cast<int>(received[i].time) << endl;
emit Shell(static_cast<int>(received[i].time), 2);
break;
case 3:
cout << "Dea Zeit 2: "
<< static_cast<int>(received[i].time) << endl;
emit Dea(static_cast<int>(received[i].time), 2);
break;
case 4:
cout << "Shell Zeit 2: "
<< static_cast<int>(received[i].time) << endl;
emit Shell(static_cast<int>(received[i].time), 3);
break;
case 5:
cout << "Dea Zeit 3: "
<< static_cast<int>(received[i].time) << endl;
emit Dea(static_cast<int>(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<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
1);
break;
case 1:
cout << "Dea Zeit 1: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
1);
break;
case 2:
cout << "Shell Zeit 2: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
2);
break;
case 3:
cout << "Dea Zeit 2: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
2);
break;
case 4:
cout << "Shell Zeit 2: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Shell(static_cast<int>(received->data[i].time),
3);
break;
case 5:
cout << "Dea Zeit 3: "
<< static_cast<int>(received->data[i].time)
<< endl;
emit Dea(static_cast<int>(received->data[i].time),
3);
break;
}
}
} // dataframe ok
else {
// dataframe not ok
tcflush(fd, TCIFLUSH);
}
}
}

View File

@@ -6,7 +6,7 @@
#include <stdio.h>
#include <string.h>
#ifdef ATMEGA
#include <usb.h>
#include <usb.h>
#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: