diff --git a/hardwaresetup.cpp b/hardwaresetup.cpp index b93a098..f7d6a07 100644 --- a/hardwaresetup.cpp +++ b/hardwaresetup.cpp @@ -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 received = std::make_shared(); 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(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 received = + std::make_shared(); + 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(length) < sizeof(struct TransCheck)) { + tcflush(fd, TCIFLUSH); + } + } +} + bool HardwareSetup::getShell() { // int zahl[8] = {0}; diff --git a/hardwaresetup.h b/hardwaresetup.h index 2ee80b8..be6cf07 100644 --- a/hardwaresetup.h +++ b/hardwaresetup.h @@ -38,6 +38,8 @@ class HardwareSetup : public QThread { #endif int fd; + void connectSTM32(); + bool getShell(); bool getDea(); int * findBit(int * array, int zahl);