6 template<
unsigned packetSize>
10 static const unsigned kPacketSize=packetSize;
11 UartBlock() : qosMsg(0), qosSync(0), qosFullSync(0), pos(0) { }
12 virtual void onMsg(uint8_t* buffer) = 0;
13 virtual void send(
const uint8_t* buffer,
unsigned len) = 0;
14 void onChar(uint8_t c)
16 if (!(pos || (c==kMarker)))
19 if (pos != kPacketSize)
21 uint16_t packetCrc = (buffer[kPacketSize-2]<<8)+buffer[kPacketSize-1];
22 if (packetCrc == CRC16::compute(buffer+1, kPacketSize-3)) {
28 while ((i<kPacketSize) && (buffer[i]!=kMarker))
30 for (
unsigned j=0; j<kPacketSize-i; j++)
31 buffer[j] = buffer[j+i];
32 pos = kPacketSize - i;
40 void sendMsg(
const uint8_t* buffer)
44 send(buffer, kPacketSize-3);
45 uint16_t packetCrc = CRC16::compute(buffer, kPacketSize-3);
53 unsigned long qosSync;
54 unsigned long qosFullSync;
57 static const uint8_t kMarker = 0x3A;
59 uint8_t buffer[kPacketSize];