added some transmission safety
This commit is contained in:
+39
-20
@@ -323,8 +323,8 @@ void HardwareSetup::run() {
|
|||||||
cout << "Port opened" << endl;
|
cout << "Port opened" << endl;
|
||||||
|
|
||||||
// prepare buffer
|
// prepare buffer
|
||||||
struct TransStruct * received;
|
struct TransCheck * received;
|
||||||
uint8_t uintBuf[4 * 6];
|
uint8_t uintBuf[4 * 6 + 2];
|
||||||
void * voidBuf;
|
void * voidBuf;
|
||||||
|
|
||||||
// configure among others non-canonical mode (important)
|
// configure among others non-canonical mode (important)
|
||||||
@@ -334,7 +334,7 @@ void HardwareSetup::run() {
|
|||||||
tcsetattr(fd, TCSANOW, &config);
|
tcsetattr(fd, TCSANOW, &config);
|
||||||
|
|
||||||
// read raw data to buffer
|
// read raw data to buffer
|
||||||
ssize_t length = read(fd, uintBuf, 24);
|
ssize_t length = read(fd, uintBuf, 24 + 2);
|
||||||
|
|
||||||
// flush existing data
|
// flush existing data
|
||||||
if (length < 24) {
|
if (length < 24) {
|
||||||
@@ -345,48 +345,67 @@ void HardwareSetup::run() {
|
|||||||
|
|
||||||
// read data
|
// read data
|
||||||
cout << "try to read data" << endl;
|
cout << "try to read data" << endl;
|
||||||
read(this->fd, uintBuf, 4 * 6);
|
read(this->fd, uintBuf, 4 * 6 + 2);
|
||||||
cout << "data read" << endl;
|
cout << "data read" << endl;
|
||||||
voidBuf = static_cast<void *>(uintBuf);
|
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++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
if (received[i].update != 0) {
|
if (received->begin == '#' && received->end == '!') {
|
||||||
switch (received[i].id) {
|
|
||||||
|
if (received->data[i].update != 0) {
|
||||||
|
switch (received->data[i].id) {
|
||||||
case 0:
|
case 0:
|
||||||
cout << "Shell Zeit 1: "
|
cout << "Shell Zeit 1: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Shell(static_cast<int>(received[i].time), 1);
|
<< endl;
|
||||||
|
emit Shell(static_cast<int>(received->data[i].time),
|
||||||
|
1);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
cout << "Dea Zeit 1: "
|
cout << "Dea Zeit 1: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Dea(static_cast<int>(received[i].time), 1);
|
<< endl;
|
||||||
|
emit Dea(static_cast<int>(received->data[i].time),
|
||||||
|
1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
cout << "Shell Zeit 2: "
|
cout << "Shell Zeit 2: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Shell(static_cast<int>(received[i].time), 2);
|
<< endl;
|
||||||
|
emit Shell(static_cast<int>(received->data[i].time),
|
||||||
|
2);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
cout << "Dea Zeit 2: "
|
cout << "Dea Zeit 2: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Dea(static_cast<int>(received[i].time), 2);
|
<< endl;
|
||||||
|
emit Dea(static_cast<int>(received->data[i].time),
|
||||||
|
2);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
cout << "Shell Zeit 2: "
|
cout << "Shell Zeit 2: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Shell(static_cast<int>(received[i].time), 3);
|
<< endl;
|
||||||
|
emit Shell(static_cast<int>(received->data[i].time),
|
||||||
|
3);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
cout << "Dea Zeit 3: "
|
cout << "Dea Zeit 3: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received->data[i].time)
|
||||||
emit Dea(static_cast<int>(received[i].time), 3);
|
<< endl;
|
||||||
|
emit Dea(static_cast<int>(received->data[i].time),
|
||||||
|
3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} // dataframe ok
|
||||||
|
else {
|
||||||
|
// dataframe not ok
|
||||||
|
tcflush(fd, TCIFLUSH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -6,7 +6,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef ATMEGA
|
#ifdef ATMEGA
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
#endif
|
#endif
|
||||||
struct TransStruct {
|
struct TransStruct {
|
||||||
uint16_t time;
|
uint16_t time;
|
||||||
@@ -14,6 +14,12 @@ struct TransStruct {
|
|||||||
uint8_t update;
|
uint8_t update;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TransCheck {
|
||||||
|
char begin;
|
||||||
|
struct TransStruct data[6];
|
||||||
|
char end;
|
||||||
|
};
|
||||||
|
|
||||||
class HardwareSetup : public QThread {
|
class HardwareSetup : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user