From 349b49299e34473133717c6f775d221392c7ae87 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Sat, 11 Aug 2018 23:54:56 +0200 Subject: [PATCH] more wip --- platform.h | 2 +- tpuart_data_link_layer.cpp | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/platform.h b/platform.h index 598b887..73db16e 100644 --- a/platform.h +++ b/platform.h @@ -24,7 +24,7 @@ public: virtual void setupUart(); virtual void closeUart(); - int uartAvailable(); + virtual int uartAvailable(); virtual size_t writeUart(const uint8_t data); virtual size_t writeUart(const uint8_t *buffer, size_t size); virtual int readUart(); diff --git a/tpuart_data_link_layer.cpp b/tpuart_data_link_layer.cpp index 47d7356..798f264 100644 --- a/tpuart_data_link_layer.cpp +++ b/tpuart_data_link_layer.cpp @@ -37,7 +37,7 @@ //serices to host controller // DLL services (device is transparent) -#define L_DATA_STANDARD_IND 0x81 +#define L_DATA_STANDARD_IND 0x90 #define L_DATA_EXTENDED_IND 0x10 #define L_DATA_MASK 0xD3 #define L_POLL_DATA_IND 0xF0 @@ -96,6 +96,9 @@ void TpUartDataLinkLayer::stopChip() } } +void printHex(const char* suffix, const uint8_t *data, size_t length); + + void TpUartDataLinkLayer::setAddress(uint16_t addr) { if (addr == 0) @@ -207,8 +210,10 @@ bool TpUartDataLinkLayer::checkDataInd(uint8_t firstByte) //convert to extended frame format _platform.readBytesUart(buffer + 2, 5); payloadLength = buffer[6] & 0xF; - _platform.readBytesUart(buffer + 6, payloadLength + 2); //+1 for TCPI +1 for CRC - len = payloadLength + 9; + _platform.readBytesUart(buffer + 7, payloadLength + 2); //+1 for TCPI +1 for CRC + printHex("->", buffer, 1); + printHex("->", buffer + 2, 5); + printHex("->", buffer + 7, payloadLength + 3); buffer[1] = buffer[6] & 0xF0; buffer[6] = payloadLength; } @@ -218,10 +223,23 @@ bool TpUartDataLinkLayer::checkDataInd(uint8_t firstByte) _platform.readBytesUart(buffer + 1, 6); payloadLength = buffer[6]; _platform.readBytesUart(buffer + 7, payloadLength + 2); //+1 for TCPI +1 for CRC - len = payloadLength + 9; } len = payloadLength + 9; + printHex("=>", buffer, len); + CemiFrame frame(buffer, len); + if (_deviceObject.induvidualAddress() == 0 && frame.destinationAddress() == 0) + { + //send ack. Otherwise we have autoacknowledge + _platform.writeUart(U_ACK_REQ + 1); + } + else + { + // send not addressed + _platform.writeUart(U_ACK_REQ); + } + + const uint8_t queueLength = 5; static uint8_t buffers[queueLength][bufferSize]; static uint16_t bufferLengths[queueLength]; @@ -276,12 +294,6 @@ void TpUartDataLinkLayer::frameBytesReceived(uint8_t* buffer, uint16_t length) { CemiFrame frame(buffer, length); - if (_deviceObject.induvidualAddress() == 0 && frame.destinationAddress() == 0) - { - //send ack. Otherwise we have autoacknowledge - _platform.writeUart(U_ACK_REQ + 1); - } - frameRecieved(frame); }