changed hardware setup for stm32

This commit is contained in:
2018-12-30 21:47:15 +01:00
parent 8dfece7633
commit 2ae9c45216
2 changed files with 38 additions and 27 deletions

View File

@@ -264,38 +264,12 @@ void HardwareSetup::run() {
else if (HARDWARE_VERSION == 3) { else if (HARDWARE_VERSION == 3) {
uint8_t dummy[sizeof(struct TransCheck)] = {0}; uint8_t dummy[sizeof(struct TransCheck)] = {0};
fd = open(PORT_PATH, O_RDONLY); this->connectSTM32();
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 // prepare buffer
std::shared_ptr<struct TransCheck> received = std::shared_ptr<struct TransCheck> received =
std::make_shared<struct TransCheck>(); std::make_shared<struct TransCheck>();
uint8_t uintBuf[sizeof(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) { while (!this->stop) {
// read data // read data
@@ -367,6 +341,7 @@ void HardwareSetup::run() {
else { else {
// dataframe not ok // dataframe not ok
tcflush(fd, TCIFLUSH); tcflush(fd, TCIFLUSH);
this->connectSTM32();
} }
// overwrite received data to prevent same data gets read one more // 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() { bool HardwareSetup::getShell() {
// int zahl[8] = {0}; // int zahl[8] = {0};

View File

@@ -38,6 +38,8 @@ class HardwareSetup : public QThread {
#endif #endif
int fd; int fd;
void connectSTM32();
bool getShell(); bool getShell();
bool getDea(); bool getDea();
int * findBit(int * array, int zahl); int * findBit(int * array, int zahl);