cosmetic changes

This commit is contained in:
2025-01-05 18:19:30 +01:00
parent 6c01b76b9c
commit 3014a45714
2 changed files with 52 additions and 23 deletions

View File

@@ -3,6 +3,7 @@
// filecontrol
#include <fcntl.h>
#include <iostream>
#include <ostream>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -23,6 +24,8 @@
#define PORT_PATH "/dev/ttyACM0"
#define LIGHT_BARRIERS 6u
using namespace std;
// not needed anymore -> usb
// #define BASEPORT 0xe050 /* lp1 */
@@ -324,7 +327,7 @@ void HardwareSetup::run() {
// prepare buffer
struct TransStruct * received;
uint8_t uintBuf[4 * 6];
uint8_t uintBuf[sizeof(TransStruct) * LIGHT_BARRIERS];
void * voidBuf;
// configure among others non-canonical mode (important)
@@ -334,56 +337,61 @@ void HardwareSetup::run() {
tcsetattr(fd, TCSANOW, &config);
// read raw data to buffer
ssize_t length = read(fd, uintBuf, 24);
// flush existing data
if (length < 24) {
tcflush(fd, TCIFLUSH);
ssize_t length = read(fd, uintBuf, sizeof(TransStruct)*LIGHT_BARRIERS);
if (length < 0){
cout << "buffer negativ" << endl;
}
else{
// flush existing data
if (length < sizeof(TransStruct)*LIGHT_BARRIERS) {
tcflush(fd, TCIFLUSH);
}
}
while (!this->stop) {
// read data
cout << "try to read data" << endl;
read(this->fd, uintBuf, 4 * 6);
read(this->fd, uintBuf, sizeof(TransStruct) * LIGHT_BARRIERS);
cout << "data read" << endl;
voidBuf = static_cast<void *>(uintBuf);
received = static_cast<struct TransStruct *>(voidBuf);
usleep(150000); // 150ms
for (int i = 0; i < 6; i++) {
if (received[i].update != 0) {
for (uint8_t i = 0; i < LIGHT_BARRIERS; i++) {
if (received[i].update != NO_UPDATE) {
switch (received[i].id) {
case 0:
case SHELL_SECTOR_1:
cout << "Shell Zeit 1: "
<< 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;
case 1:
case DEA_SECTOR_1:
cout << "Dea Zeit 1: "
<< 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;
case 2:
case SHELL_SECTOR_2:
cout << "Shell Zeit 2: "
<< 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;
case 3:
case DEA_SECTOR_2:
cout << "Dea Zeit 2: "
<< 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;
case 4:
cout << "Shell Zeit 2: "
case SHELL_SECTOR_3:
cout << "Shell Zeit 3: "
<< 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;
case 5:
case DEA_SECTOR_3:
cout << "Dea Zeit 3: "
<< 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;
}
}

View File

@@ -2,6 +2,7 @@
#define HARDWARESETUP_H
#include <QtCore>
#include <cstdint>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -11,7 +12,27 @@
struct TransStruct {
uint16_t time;
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 {