changed hardware setup for stm32
This commit is contained in:
@@ -264,38 +264,12 @@ void HardwareSetup::run() {
|
||||
else if (HARDWARE_VERSION == 3) {
|
||||
uint8_t dummy[sizeof(struct TransCheck)] = {0};
|
||||
|
||||
fd = open(PORT_PATH, O_RDONLY);
|
||||
while (this->fd < 0) {
|
||||
// wait 1 second
|
||||
sleep(1);
|
||||
cout << "Port can't be opened" << endl;
|
||||
fd = open(PORT_PATH, O_RDONLY);
|
||||
if (this->stop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->connectSTM32();
|
||||
// prepare buffer
|
||||
std::shared_ptr<struct TransCheck> received =
|
||||
std::make_shared<struct TransCheck>();
|
||||
uint8_t uintBuf[sizeof(struct TransCheck)];
|
||||
// void * voidBuf;
|
||||
// configure among others non-canonical mode (important)
|
||||
struct termios config;
|
||||
tcgetattr(fd, &config);
|
||||
config.c_lflag = 0; // standard value is bad choosen
|
||||
tcsetattr(fd, TCSANOW, &config);
|
||||
|
||||
// read raw data to buffer
|
||||
ssize_t length = read(fd, uintBuf, sizeof(struct TransCheck));
|
||||
|
||||
if (this->stop == 0) {
|
||||
cout << "Port opened" << endl;
|
||||
// flush existing data
|
||||
if (static_cast<unsigned long>(length) <
|
||||
sizeof(struct TransCheck)) {
|
||||
tcflush(fd, TCIFLUSH);
|
||||
}
|
||||
}
|
||||
while (!this->stop) {
|
||||
|
||||
// read data
|
||||
@@ -367,6 +341,7 @@ void HardwareSetup::run() {
|
||||
else {
|
||||
// dataframe not ok
|
||||
tcflush(fd, TCIFLUSH);
|
||||
this->connectSTM32();
|
||||
}
|
||||
|
||||
// overwrite received data to prevent same data gets read one more
|
||||
@@ -379,6 +354,40 @@ void HardwareSetup::run() {
|
||||
}
|
||||
}
|
||||
|
||||
void HardwareSetup::connectSTM32() {
|
||||
fd = open(PORT_PATH, O_RDONLY);
|
||||
while (this->fd < 0) {
|
||||
// wait 1 second
|
||||
sleep(1);
|
||||
cout << "Port can't be opened" << endl;
|
||||
fd = open(PORT_PATH, O_RDONLY);
|
||||
if (this->stop) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// prepare buffer
|
||||
std::shared_ptr<struct TransCheck> received =
|
||||
std::make_shared<struct TransCheck>();
|
||||
uint8_t uintBuf[sizeof(struct TransCheck)];
|
||||
// void * voidBuf;
|
||||
// configure among others non-canonical mode (important)
|
||||
struct termios config;
|
||||
tcgetattr(fd, &config);
|
||||
config.c_lflag = 0; // standard value is bad choosen
|
||||
tcsetattr(fd, TCSANOW, &config);
|
||||
|
||||
// read raw data to buffer
|
||||
ssize_t length = read(fd, uintBuf, sizeof(struct TransCheck));
|
||||
|
||||
if (this->stop == 0) {
|
||||
cout << "Port opened" << endl;
|
||||
// flush existing data
|
||||
if (static_cast<unsigned long>(length) < sizeof(struct TransCheck)) {
|
||||
tcflush(fd, TCIFLUSH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HardwareSetup::getShell() {
|
||||
|
||||
// int zahl[8] = {0};
|
||||
|
||||
@@ -38,6 +38,8 @@ class HardwareSetup : public QThread {
|
||||
#endif
|
||||
int fd;
|
||||
|
||||
void connectSTM32();
|
||||
|
||||
bool getShell();
|
||||
bool getDea();
|
||||
int * findBit(int * array, int zahl);
|
||||
|
||||
Reference in New Issue
Block a user