cosmetic changes
This commit is contained in:
+30
-22
@@ -3,6 +3,7 @@
|
|||||||
// filecontrol
|
// filecontrol
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -23,6 +24,8 @@
|
|||||||
|
|
||||||
#define PORT_PATH "/dev/ttyACM0"
|
#define PORT_PATH "/dev/ttyACM0"
|
||||||
|
|
||||||
|
#define LIGHT_BARRIERS 6u
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
// not needed anymore -> usb
|
// not needed anymore -> usb
|
||||||
// #define BASEPORT 0xe050 /* lp1 */
|
// #define BASEPORT 0xe050 /* lp1 */
|
||||||
@@ -324,7 +327,7 @@ void HardwareSetup::run() {
|
|||||||
|
|
||||||
// prepare buffer
|
// prepare buffer
|
||||||
struct TransStruct * received;
|
struct TransStruct * received;
|
||||||
uint8_t uintBuf[4 * 6];
|
uint8_t uintBuf[sizeof(TransStruct) * LIGHT_BARRIERS];
|
||||||
void * voidBuf;
|
void * voidBuf;
|
||||||
|
|
||||||
// configure among others non-canonical mode (important)
|
// configure among others non-canonical mode (important)
|
||||||
@@ -334,56 +337,61 @@ 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, sizeof(TransStruct)*LIGHT_BARRIERS);
|
||||||
|
if (length < 0){
|
||||||
// flush existing data
|
cout << "buffer negativ" << endl;
|
||||||
if (length < 24) {
|
|
||||||
tcflush(fd, TCIFLUSH);
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
// flush existing data
|
||||||
|
if (length < sizeof(TransStruct)*LIGHT_BARRIERS) {
|
||||||
|
tcflush(fd, TCIFLUSH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while (!this->stop) {
|
while (!this->stop) {
|
||||||
|
|
||||||
// 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, sizeof(TransStruct) * LIGHT_BARRIERS);
|
||||||
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 TransStruct *>(voidBuf);
|
||||||
|
|
||||||
usleep(150000); // 150ms
|
usleep(150000); // 150ms
|
||||||
|
|
||||||
for (int i = 0; i < 6; i++) {
|
for (uint8_t i = 0; i < LIGHT_BARRIERS; i++) {
|
||||||
if (received[i].update != 0) {
|
if (received[i].update != NO_UPDATE) {
|
||||||
switch (received[i].id) {
|
switch (received[i].id) {
|
||||||
case 0:
|
case SHELL_SECTOR_1:
|
||||||
cout << "Shell Zeit 1: "
|
cout << "Shell Zeit 1: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Shell(static_cast<int>(received[i].time), 1);
|
emit Shell(static_cast<int>(received[i].time), SECTOR_1);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case DEA_SECTOR_1:
|
||||||
cout << "Dea Zeit 1: "
|
cout << "Dea Zeit 1: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Dea(static_cast<int>(received[i].time), 1);
|
emit Dea(static_cast<int>(received[i].time), SECTOR_1);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case SHELL_SECTOR_2:
|
||||||
cout << "Shell Zeit 2: "
|
cout << "Shell Zeit 2: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Shell(static_cast<int>(received[i].time), 2);
|
emit Shell(static_cast<int>(received[i].time), SECTOR_2);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case DEA_SECTOR_2:
|
||||||
cout << "Dea Zeit 2: "
|
cout << "Dea Zeit 2: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Dea(static_cast<int>(received[i].time), 2);
|
emit Dea(static_cast<int>(received[i].time), SECTOR_2);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case SHELL_SECTOR_3:
|
||||||
cout << "Shell Zeit 2: "
|
cout << "Shell Zeit 3: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Shell(static_cast<int>(received[i].time), 3);
|
emit Shell(static_cast<int>(received[i].time), SECTOR_3);
|
||||||
break;
|
break;
|
||||||
case 5:
|
case DEA_SECTOR_3:
|
||||||
cout << "Dea Zeit 3: "
|
cout << "Dea Zeit 3: "
|
||||||
<< static_cast<int>(received[i].time) << endl;
|
<< static_cast<int>(received[i].time) << endl;
|
||||||
emit Dea(static_cast<int>(received[i].time), 3);
|
emit Dea(static_cast<int>(received[i].time), SECTOR_3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-1
@@ -2,6 +2,7 @@
|
|||||||
#define HARDWARESETUP_H
|
#define HARDWARESETUP_H
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
#include <cstdint>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -11,7 +12,27 @@
|
|||||||
struct TransStruct {
|
struct TransStruct {
|
||||||
uint16_t time;
|
uint16_t time;
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
uint8_t update;
|
uint8_t update; // 1 for update; 0 for no update
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ID{
|
||||||
|
SHELL_SECTOR_1,
|
||||||
|
DEA_SECTOR_1,
|
||||||
|
SHELL_SECTOR_2,
|
||||||
|
DEA_SECTOR_2,
|
||||||
|
SHELL_SECTOR_3,
|
||||||
|
DEA_SECTOR_3,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum SECTOR{
|
||||||
|
SECTOR_1 = 1,
|
||||||
|
SECTOR_2,
|
||||||
|
SECTOR_3,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Update{
|
||||||
|
NO_UPDATE,
|
||||||
|
UPDATE
|
||||||
};
|
};
|
||||||
|
|
||||||
class HardwareSetup : public QThread {
|
class HardwareSetup : public QThread {
|
||||||
|
|||||||
Reference in New Issue
Block a user