block senden stabil
This commit is contained in:
parent
6dd836c729
commit
8dcd24adbd
2
Makefile
2
Makefile
|
@ -8,7 +8,7 @@ COMPILER_PATH = g++
|
||||||
|
|
||||||
|
|
||||||
OUTPUT = main
|
OUTPUT = main
|
||||||
CFLAGS = -std=c++14 -O3
|
CFLAGS = -std=c++14 -O3 -Wall -Wextra
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
OBJECTS = main.o drv/usart.o drv/b15f.o drv/plottyfile.o drv/dot.o
|
OBJECTS = main.o drv/usart.o drv/b15f.o drv/plottyfile.o drv/dot.o
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,13 @@ void B15F::init()
|
||||||
std::cout << "OK" << std::endl;
|
std::cout << "OK" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
// Temporärer Test
|
||||||
|
uint8_t block[] = {0, 1, 2, 3};
|
||||||
|
while(1)
|
||||||
|
usart.writeBlock(&block[0], 0, sizeof(block));
|
||||||
|
throw std::runtime_error("SCHLUSS");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << PRE << "Teste Verbindung... " << std::flush;
|
std::cout << PRE << "Teste Verbindung... " << std::flush;
|
||||||
uint8_t tries = 3;
|
uint8_t tries = 3;
|
||||||
|
|
BIN
drv/b15f.o
BIN
drv/b15f.o
Binary file not shown.
|
@ -53,7 +53,14 @@ void USART::writeByte(uint8_t b)
|
||||||
{
|
{
|
||||||
int sent = write(file_desc, &b, 1);
|
int sent = write(file_desc, &b, 1);
|
||||||
if(sent != 1)
|
if(sent != 1)
|
||||||
throw USARTException("Fehler beim Senden: writeByte()");
|
{
|
||||||
|
std::cout << "WARNUNG: Fehler beim Senden (" << sent << "): writeByte(), wiederhole..." << std::endl;
|
||||||
|
usleep(100000);
|
||||||
|
sent = write(file_desc, &b, 1);
|
||||||
|
if(sent != 1)
|
||||||
|
throw USARTException("Fehler beim Senden: writeByte()");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART::writeInt(uint16_t d)
|
void USART::writeInt(uint16_t d)
|
||||||
|
@ -66,33 +73,69 @@ void USART::writeInt(uint16_t d)
|
||||||
void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
|
void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
|
||||||
{
|
{
|
||||||
buffer += offset;
|
buffer += offset;
|
||||||
uint8_t crc = 0;
|
uint8_t crc;
|
||||||
|
uint8_t aw;
|
||||||
|
|
||||||
writeByte(len);
|
do
|
||||||
|
|
||||||
while(len--)
|
|
||||||
{
|
{
|
||||||
writeByte(*buffer);
|
crc = 0;
|
||||||
|
writeByte(len);
|
||||||
|
|
||||||
crc ^= *buffer;
|
for(uint8_t i = 0; i < len; i++)
|
||||||
for (uint8_t i = 0; i < 8; i++)
|
|
||||||
{
|
{
|
||||||
if (crc & 1)
|
writeByte(buffer[i]);
|
||||||
crc ^= CRC7_POLY;
|
usleep((1000000 / baudrate) * 16);
|
||||||
crc >>= 1;
|
|
||||||
|
crc ^= buffer[i];
|
||||||
|
for (uint8_t k = 0; k < 8; k++)
|
||||||
|
{
|
||||||
|
if (crc & 1)
|
||||||
|
crc ^= CRC7_POLY;
|
||||||
|
crc >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writeByte(crc);
|
||||||
|
usleep((1000000 / baudrate) * 16);
|
||||||
|
|
||||||
|
writeByte(0x80); // Stoppzeichen für Block
|
||||||
|
|
||||||
|
usleep((1000000 / baudrate) * 16);
|
||||||
|
|
||||||
|
int code = read(file_desc, &aw, 1);
|
||||||
|
if(code < 0)
|
||||||
|
{
|
||||||
|
std::cout << "WARNING: read error, retry..." << std::endl;
|
||||||
|
usleep(100000);
|
||||||
|
code = read(file_desc, &aw, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer++;
|
if(code == 0)
|
||||||
}
|
{
|
||||||
|
std::cout << "timeout info" << std::endl;
|
||||||
|
for(uint8_t i = 0; i < MAX_BLOCK_SIZE; i++)
|
||||||
|
{
|
||||||
|
std::cout << "i: " << (int) i << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
writeByte(0x80); // Stoppzeichen für Block
|
||||||
|
|
||||||
|
code = read(file_desc, &aw, 1);
|
||||||
|
if(code == 1)
|
||||||
|
{
|
||||||
|
std::cout << "YO HO" << std::endl;
|
||||||
|
std::cout << "aw: " << (int) aw << std::endl;
|
||||||
|
i = 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(code != 1)
|
||||||
|
throw std::runtime_error("fatal: " + std::to_string(code));
|
||||||
|
|
||||||
writeByte(crc);
|
clearInputBuffer();
|
||||||
writeByte(0x80); // Stoppzeichen für Block
|
|
||||||
|
|
||||||
uint8_t aw = readByte();
|
|
||||||
if(aw != 0xFF)
|
|
||||||
{
|
|
||||||
std::cout << "Ende Gelände" << std::endl;
|
|
||||||
}
|
}
|
||||||
|
while(aw != 0xFF);
|
||||||
|
|
||||||
|
std::cout << "OK" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t USART::readByte(void)
|
uint8_t USART::readByte(void)
|
||||||
|
|
|
@ -122,7 +122,8 @@ private:
|
||||||
int TEST = 0;
|
int TEST = 0;
|
||||||
uint8_t timeout = 10; // in Dezisekunden
|
uint8_t timeout = 10; // in Dezisekunden
|
||||||
|
|
||||||
constexpr static uint8_t CRC7_POLY = 0x91;
|
constexpr static uint8_t CRC7_POLY = 0x91;
|
||||||
|
constexpr static uint8_t MAX_BLOCK_SIZE = 16;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
drv/usart.o
BIN
drv/usart.o
Binary file not shown.
Loading…
Reference in a new issue