stabil ueber 2 Minuten

This commit is contained in:
Tristan Krause 2019-04-01 16:08:32 +02:00
parent c278274ed0
commit 84fe8b72eb
8 changed files with 31057 additions and 26 deletions

1
b15f.aws Normal file
View file

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA1284"/><Files><File00000 Name="E:\Makefile" Position="267 101 1369 494" LineCol="36 0" State="Maximized"/><File00001 Name="E:\main.cpp" Position="289 130 1383 493" LineCol="0 0" State="Maximized"/><File00002 Name="E:\requests.h" Position="311 159 1405 522" LineCol="14 31" State="Maximized"/><File00003 Name="requests.cpp" Position="333 188 1427 551" LineCol="106 38" State="Maximized"/><File00004 Name="E:\usart.cpp" Position="263 71 1501 646" LineCol="109 29" State="Maximized"/><File00005 Name="E:\adu.h" Position="267 101 1361 464" LineCol="15 0" State="Maximized"/><File00006 Name="E:\usart.h" Position="289 130 1387 497" LineCol="9 38" State="Maximized"/></Files></AVRWorkspace>

31029
docs/atmega1284p.pdf Normal file

File diff suppressed because one or more lines are too long

View file

@ -15,6 +15,7 @@ void USART::openDevice(std::string device)
options.c_iflag = IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_cc[VMIN] = 0; // #bytes read returns at least
options.c_cc[VTIME] = timeout;
code = cfsetspeed(&options, baudrate);
if(code)
@ -142,37 +143,30 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
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));
flushOutputBuffer();
// flush output data
tcdrain(file_desc);
usleep(1000);
usleep(us_per_bit * n_total);
// check response
int n_read = read_timeout(&aw, 0, 1, us_per_bit);
for(uint8_t i = 0; i < 10 && n_read != 1; i++)
for(uint16_t i = 0; i < 255 && n_read != 1; i++)
{
flushOutputBuffer();
flushInputBuffer();
writeByte(0x80); // Stoppzeichen für Block
tcdrain(file_desc);
std::cout << "WARNING: read error (" << n_read << "), retry #" << (int) i << std::endl;
usleep(1000000);
n_read = read_timeout(&aw, 0, 1, us_per_bit * 2);
usleep(us_per_bit);
n_read = read_timeout(&aw, 0, 1, us_per_bit);
}
if(n_read == 0)
{
std::cout << "timeout info" << std::endl;
for(uint8_t i = 0; i < MAX_BLOCK_SIZE; i++)
{
writeByte(0x80); // Stoppzeichen für Block
n_read = read_timeout(&aw, 0, 1, us_per_bit * 2);
if(n_read == 1)
break;
}
}
else if(n_read != 1)
if(n_read != 1)
throw std::runtime_error("fatal: " + std::to_string(n_read));
flushInputBuffer();
//flushInputBuffer();
if(aw != 0xFF)
std::cout << "block failed, retry" << std::endl;
}
while(aw != 0xFF);

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -186,7 +186,7 @@
:100B90000E94180241E063E371E084E291E00C946A
:100BA0001802EE0FFF1F0024001C0BBE0790F691E9
:080BB000E02D0994F894FFCF39
:100BB800626F617264696E666F2E680030383A3110
:100BC800363A3531004170722020312032303139C7
:100BB800626F617264696E666F2E680031353A3211
:100BC800393A3032004170722020312032303139C8
:020BD80000001B
:00000001FF

View file

@ -97,14 +97,21 @@ uint16_t USART::readInt()
void USART::readBlock(uint8_t* ptr, uint8_t offset)
{
ptr += offset;
uint8_t crc;
uint8_t crc = 0x7F;
do
{
crc = 0;
uint8_t len = readByte();
if(len > MAX_BLOCK_SIZE)
if(len == 0x80) // out of sync, war bereits stoppbyte
{
writeByte(MSG_FAIL);
continue;
}
else if(len > MAX_BLOCK_SIZE)
len = 0;
crc = 0;
for(uint8_t k = 0; k <= len; k++) // len + 1 Durchgänge (+ crc)
{
uint8_t next = readByte();