speichern
This commit is contained in:
parent
86da74bed0
commit
8e785e4b70
15 changed files with 443 additions and 282 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
void USART::openDevice(std::string device)
|
||||
{
|
||||
file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
file_desc = open(device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY /* | O_NONBLOCK*/);
|
||||
if(file_desc <= 0)
|
||||
throw USARTException("Fehler beim Öffnen des Gerätes");
|
||||
|
||||
|
@ -96,7 +96,7 @@ int USART::read_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t
|
|||
elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
||||
}
|
||||
|
||||
return n_read;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int USART::write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t timeout)
|
||||
|
@ -150,23 +150,35 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
|
|||
block_buffer[len + 2] = BLOCK_END;
|
||||
|
||||
// send block
|
||||
clearOutputBuffer();
|
||||
clearInputBuffer();
|
||||
int n_sent = write_timeout(&block_buffer[0], 0, len + 3, us_per_bit * n_total);
|
||||
if(n_sent != n_total)
|
||||
throw std::runtime_error("fatal (send): " + std::to_string(n_sent));
|
||||
|
||||
/*for(uint8_t i = 0; i < len + 3; i++)
|
||||
{
|
||||
write_timeout(&block_buffer[i], 0, 1, us_per_bit * n_total);
|
||||
//tcdrain(file_desc);
|
||||
//usleep(1000);
|
||||
}*/
|
||||
|
||||
// flush output data
|
||||
tcdrain(file_desc);
|
||||
|
||||
usleep(us_per_bit * n_total);
|
||||
//usleep(us_per_bit * n_total * 10);
|
||||
|
||||
// check response
|
||||
int n_read = read_timeout(&aw, 0, 1, us_per_bit);
|
||||
int n_read = read_timeout(&aw, 0, 1, us_per_bit * n_blocks_total * 10);
|
||||
for(uint16_t i = 0; i < 255 && n_read != 1; i++)
|
||||
{
|
||||
writeByte(0x80); // Stoppzeichen für Block
|
||||
tcdrain(file_desc);
|
||||
if(tcdrain(file_desc))
|
||||
{
|
||||
std::cout << "drain failed" << std::endl;
|
||||
}
|
||||
std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl;
|
||||
usleep(us_per_bit);
|
||||
usleep(us_per_bit*100);
|
||||
n_read = read_timeout(&aw, 0, 1, us_per_bit);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue