This commit is contained in:
Thomas Kunze 2018-08-11 23:54:56 +02:00
parent cee0eb74f2
commit 349b49299e
2 changed files with 23 additions and 11 deletions

View File

@ -24,7 +24,7 @@ public:
virtual void setupUart(); virtual void setupUart();
virtual void closeUart(); virtual void closeUart();
int uartAvailable(); virtual int uartAvailable();
virtual size_t writeUart(const uint8_t data); virtual size_t writeUart(const uint8_t data);
virtual size_t writeUart(const uint8_t *buffer, size_t size); virtual size_t writeUart(const uint8_t *buffer, size_t size);
virtual int readUart(); virtual int readUart();

View File

@ -37,7 +37,7 @@
//serices to host controller //serices to host controller
// DLL services (device is transparent) // 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_EXTENDED_IND 0x10
#define L_DATA_MASK 0xD3 #define L_DATA_MASK 0xD3
#define L_POLL_DATA_IND 0xF0 #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) void TpUartDataLinkLayer::setAddress(uint16_t addr)
{ {
if (addr == 0) if (addr == 0)
@ -207,8 +210,10 @@ bool TpUartDataLinkLayer::checkDataInd(uint8_t firstByte)
//convert to extended frame format //convert to extended frame format
_platform.readBytesUart(buffer + 2, 5); _platform.readBytesUart(buffer + 2, 5);
payloadLength = buffer[6] & 0xF; payloadLength = buffer[6] & 0xF;
_platform.readBytesUart(buffer + 6, payloadLength + 2); //+1 for TCPI +1 for CRC _platform.readBytesUart(buffer + 7, payloadLength + 2); //+1 for TCPI +1 for CRC
len = payloadLength + 9; printHex("->", buffer, 1);
printHex("->", buffer + 2, 5);
printHex("->", buffer + 7, payloadLength + 3);
buffer[1] = buffer[6] & 0xF0; buffer[1] = buffer[6] & 0xF0;
buffer[6] = payloadLength; buffer[6] = payloadLength;
} }
@ -218,10 +223,23 @@ bool TpUartDataLinkLayer::checkDataInd(uint8_t firstByte)
_platform.readBytesUart(buffer + 1, 6); _platform.readBytesUart(buffer + 1, 6);
payloadLength = buffer[6]; payloadLength = buffer[6];
_platform.readBytesUart(buffer + 7, payloadLength + 2); //+1 for TCPI +1 for CRC _platform.readBytesUart(buffer + 7, payloadLength + 2); //+1 for TCPI +1 for CRC
len = payloadLength + 9;
} }
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; const uint8_t queueLength = 5;
static uint8_t buffers[queueLength][bufferSize]; static uint8_t buffers[queueLength][bufferSize];
static uint16_t bufferLengths[queueLength]; static uint16_t bufferLengths[queueLength];
@ -276,12 +294,6 @@ void TpUartDataLinkLayer::frameBytesReceived(uint8_t* buffer, uint16_t length)
{ {
CemiFrame frame(buffer, 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); frameRecieved(frame);
} }