23 static const unsigned int TABLE_CRC24Q[] =
25 0x000000,0x864CFB,0x8AD50D,0x0C99F6,0x93E6E1,0x15AA1A,0x1933EC,0x9F7F17,
26 0xA18139,0x27CDC2,0x2B5434,0xAD18CF,0x3267D8,0xB42B23,0xB8B2D5,0x3EFE2E,
27 0xC54E89,0x430272,0x4F9B84,0xC9D77F,0x56A868,0xD0E493,0xDC7D65,0x5A319E,
28 0x64CFB0,0xE2834B,0xEE1ABD,0x685646,0xF72951,0x7165AA,0x7DFC5C,0xFBB0A7,
29 0x0CD1E9,0x8A9D12,0x8604E4,0x00481F,0x9F3708,0x197BF3,0x15E205,0x93AEFE,
30 0xAD50D0,0x2B1C2B,0x2785DD,0xA1C926,0x3EB631,0xB8FACA,0xB4633C,0x322FC7,
31 0xC99F60,0x4FD39B,0x434A6D,0xC50696,0x5A7981,0xDC357A,0xD0AC8C,0x56E077,
32 0x681E59,0xEE52A2,0xE2CB54,0x6487AF,0xFBF8B8,0x7DB443,0x712DB5,0xF7614E,
33 0x19A3D2,0x9FEF29,0x9376DF,0x153A24,0x8A4533,0x0C09C8,0x00903E,0x86DCC5,
34 0xB822EB,0x3E6E10,0x32F7E6,0xB4BB1D,0x2BC40A,0xAD88F1,0xA11107,0x275DFC,
35 0xDCED5B,0x5AA1A0,0x563856,0xD074AD,0x4F0BBA,0xC94741,0xC5DEB7,0x43924C,
36 0x7D6C62,0xFB2099,0xF7B96F,0x71F594,0xEE8A83,0x68C678,0x645F8E,0xE21375,
37 0x15723B,0x933EC0,0x9FA736,0x19EBCD,0x8694DA,0x00D821,0x0C41D7,0x8A0D2C,
38 0xB4F302,0x32BFF9,0x3E260F,0xB86AF4,0x2715E3,0xA15918,0xADC0EE,0x2B8C15,
39 0xD03CB2,0x567049,0x5AE9BF,0xDCA544,0x43DA53,0xC596A8,0xC90F5E,0x4F43A5,
40 0x71BD8B,0xF7F170,0xFB6886,0x7D247D,0xE25B6A,0x641791,0x688E67,0xEEC29C,
41 0x3347A4,0xB50B5F,0xB992A9,0x3FDE52,0xA0A145,0x26EDBE,0x2A7448,0xAC38B3,
42 0x92C69D,0x148A66,0x181390,0x9E5F6B,0x01207C,0x876C87,0x8BF571,0x0DB98A,
43 0xF6092D,0x7045D6,0x7CDC20,0xFA90DB,0x65EFCC,0xE3A337,0xEF3AC1,0x69763A,
44 0x578814,0xD1C4EF,0xDD5D19,0x5B11E2,0xC46EF5,0x42220E,0x4EBBF8,0xC8F703,
45 0x3F964D,0xB9DAB6,0xB54340,0x330FBB,0xAC70AC,0x2A3C57,0x26A5A1,0xA0E95A,
46 0x9E1774,0x185B8F,0x14C279,0x928E82,0x0DF195,0x8BBD6E,0x872498,0x016863,
47 0xFAD8C4,0x7C943F,0x700DC9,0xF64132,0x693E25,0xEF72DE,0xE3EB28,0x65A7D3,
48 0x5B59FD,0xDD1506,0xD18CF0,0x57C00B,0xC8BF1C,0x4EF3E7,0x426A11,0xC426EA,
49 0x2AE476,0xACA88D,0xA0317B,0x267D80,0xB90297,0x3F4E6C,0x33D79A,0xB59B61,
50 0x8B654F,0x0D29B4,0x01B042,0x87FCB9,0x1883AE,0x9ECF55,0x9256A3,0x141A58,
51 0xEFAAFF,0x69E604,0x657FF2,0xE33309,0x7C4C1E,0xFA00E5,0xF69913,0x70D5E8,
52 0x4E2BC6,0xC8673D,0xC4FECB,0x42B230,0xDDCD27,0x5B81DC,0x57182A,0xD154D1,
53 0x26359F,0xA07964,0xACE092,0x2AAC69,0xB5D37E,0x339F85,0x3F0673,0xB94A88,
54 0x87B4A6,0x01F85D,0x0D61AB,0x8B2D50,0x145247,0x921EBC,0x9E874A,0x18CBB1,
55 0xE37B16,0x6537ED,0x69AE1B,0xEFE2E0,0x709DF7,0xF6D10C,0xFA48FA,0x7C0401,
56 0x42FA2F,0xC4B6D4,0xC82F22,0x4E63D9,0xD11CCE,0x575035,0x5BC9C3,0xDD8538
60 for (uint32_t i = 0; i != len; i++)
62 crc = ((crc << 8) & 0xFFFFFF) ^ TABLE_CRC24Q[(crc >> 16) ^ buffer[i]];
74 unsigned int getBitsAsUInt32(
const unsigned char* buffer,
unsigned int pos,
unsigned int len)
76 unsigned int bits = 0;
77 for (
unsigned int i = pos; i < pos + len; i++)
79 bits = (bits << 1) + ((buffer[i / 8] >> (7 - i % 8)) & 1u);
102 *ptrDest++ = (uint8_t)~val;
106 *ptrDest++ = (uint8_t)val;
110 *ptrDest++ = (uint8_t)val;
167 uint16_t offsetsLength;
188 memset(buffer, 0, bufferSize);
189 instance->
buf.
size = bufferSize;
191 instance->
buf.
end = buffer + bufferSize;
296 uint8_t* head = instance->
buf.
head;
300 if (instance->
buf.
scan - head > 7)
303 uint8_t tmp = *(instance->
buf.
scan - 2);
305 int actualCheckSum = (int)strtol((
const char*)instance->
buf.
scan - 4, 0, 16);
306 *(instance->
buf.
scan - 2) = tmp;
307 int dataCheckSum = 0;
308 for (uint8_t* ptr = head + 1, *ptrEnd = instance->
buf.
scan - 5; ptr < ptrEnd; ptr++)
310 dataCheckSum ^= (int)*ptr;
312 if (actualCheckSum == dataCheckSum)
356 if (len > instance->
buf.
size - 6)
371 uint8_t actualChecksum1 = *(instance->
buf.
scan - 2);
372 uint8_t actualChecksum2 = *(instance->
buf.
scan - 1);
373 uint8_t calcChecksum1 = 0;
374 uint8_t calcChecksum2 = 0;
377 for (uint8_t* ptr = instance->
buf.
head + 2, *ptrEnd = instance->
buf.
scan - 2; ptr < ptrEnd; ptr++)
379 calcChecksum1 += *ptr;
380 calcChecksum2 += calcChecksum1;
382 if (actualChecksum1 == calcChecksum1 && actualChecksum2 == calcChecksum2)
419 if (msgLength > 1023 || msgLength > instance->
buf.
size - 6)
428 instance->
parseState = -((int32_t)msgLength + 3);
435 int lenWithoutCrc = (int)((instance->
buf.
scan - instance->
buf.
head) - 3);
439 if (actualCRC == correctCRC)
471 int bytesFree = (int)(buf->
end - buf->
tail);
486 int shift = (int)(buf->
head - buf->
start);
493 bytesFree = (int)(buf->
end - buf->
tail);
511 #define FOUND_START_BYTE(init) if(init){ instance->hasStartByte = byte; instance->buf.head = instance->buf.scan-1; } 512 #define START_BYTE_SEARCH_ERROR() 521 uint8_t byte = *(buf->
scan++);
621 dataHdr->
id = dataId;
622 dataHdr->
size = size;
627 hdr.
pid = (uint8_t)pid;
695 data.
ptr = (
unsigned char*)&ack;
707 uint8_t* currentPtr = (*ptrSrcEnd) - 1;
708 memset(ftr, 0,
sizeof(uint32_t));
711 while (state != 7 && currentPtr > ptrSrc)
721 ftr->
cksum1 = *currentPtr--;
732 ftr->
cksum2 = *currentPtr--;
743 ftr->
cksum3 = *currentPtr;
757 *ptrSrcEnd = currentPtr;
758 *checksum = ((uint32_t)ftr->
cksum1) | (0x0000FF00 & ((uint32_t)ftr->
cksum2 << 8)) | (0x00FF0000 & ((uint32_t)ftr->
cksum3 << 16));
763 uint8_t* ptrSrc = *_ptrSrc;
766 uint32_t val = *ptrSrc++;
780 val = (~(*ptrSrc++) & 0x000000FF);
783 *checksum ^= (val << shift);
784 *((*_ptrDest)++) = (uint8_t)val;
802 uint8_t* ptrDest = (uint8_t*)encodedPacket;
803 uint8_t* ptrDestEnd = ptrDest + encodedPacketLength;
804 uint32_t shifter = 0;
808 if (ptrDest >= ptrDestEnd)
816 if (ptrDest >= ptrDestEnd)
822 checkSumValue ^= val;
825 if (ptrDest >= ptrDestEnd)
831 checkSumValue ^= (val << 8);
834 if (ptrDest >= ptrDestEnd)
840 checkSumValue ^= (val << 16);
843 if (srcBufferLength > 0)
845 ptrSrc = (uint8_t*)srcBuffer;
846 ptrSrcEnd = ptrSrc + srcBufferLength;
849 while (ptrSrc != ptrSrcEnd && ptrDest < ptrDestEnd)
852 checkSumValue ^= (val << shifter);
858 shifter *= (shifter != 24);
867 if (ptrDest >= ptrDestEnd)
871 val = (uint8_t)((checkSumValue >> 16) & 0xFF);
875 if (ptrDest >= ptrDestEnd)
879 val = (uint8_t)(checkSumValue >> 8) & 0xFF;
883 if (ptrDest >= ptrDestEnd)
887 val = (uint8_t)(checkSumValue & 0xFF);
891 if (ptrDest >= ptrDestEnd)
896 return (
int)(ptrDest - (uint8_t*)encodedPacket);
911 uint8_t* ptrSrc = pbuf;
912 uint8_t* ptrSrcEnd = pbuf + pbufSize;
914 uint32_t actualCheckSumValue;
917 uint32_t shifter = 0;
921 uint8_t* ptrDest = (uint8_t*)&pkt->
hdr;
922 *ptrDest++ = *ptrSrc++;
941 while (ptrSrc < ptrSrcEnd)
951 shifter *= (shifter != 24);
954 if (actualCheckSumValue != checkSumValue)
991 if ((dataHdr->
size + dataHdr->
offset) <= maxsize)
993 memcpy((uint8_t*)sptr + dataHdr->
offset, dataBuf, dataHdr->
size);
uint16_t * getDoubleOffsets(eDataIDs dataId, uint16_t *offsetsLength)
void is_decode_binary_packet_footer(packet_ftr_t *ftr, uint8_t *ptrSrc, uint8_t **ptrSrcEnd, uint32_t *checksum)
static int dataIdShouldSwap(uint32_t dataId)
static __inline void reset_parser(is_comm_instance_t *instance)
#define MAX_PKT_BODY_SIZE
void is_enable_packet_encoding(int enabled)
#define PID_STOP_BROADCASTS_ALL_PORTS
static protocol_type_t processUbloxByte(is_comm_instance_t *instance)
static void swapPacket(packet_t *pkt)
static int sendData(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data, uint32_t pid)
uint16_t * getStringOffsetsLengths(eDataIDs dataId, uint16_t *offsetsLength)
protocol_type_t is_comm_parse_byte(is_comm_instance_t *instance, uint8_t byte)
int is_comm_get_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, uint32_t periodMultiple)
char copyDataPToStructP(void *sptr, const p_data_t *data, const unsigned int maxsize)
unsigned int getBitsAsUInt32(const unsigned char *buffer, unsigned int pos, unsigned int len)
char is_comm_copy_to_struct(void *sptr, const is_comm_instance_t *instance, const unsigned int maxsize)
static int s_packetEncodingEnabled
void flipDoubles(uint8_t *data, int dataLength, int offset, uint16_t *offsets, uint16_t offsetsLength)
int is_decode_binary_packet_byte(uint8_t **_ptrSrc, uint8_t **_ptrDest, uint32_t *checksum, uint32_t shift)
void flipEndianess32(uint8_t *data, int dataLength)
int is_comm_set_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
#define PID_STOP_BROADCASTS_CURRENT_PORT
unsigned int calculate24BitCRCQ(unsigned char *buffer, unsigned int len)
int is_encode_binary_packet(void *srcBuffer, unsigned int srcBufferLength, packet_hdr_t *hdr, uint8_t additionalPktFlags, void *encodedPacket, int encodedPacketLength)
static uint8_t * encodeByteAddToBuffer(uint32_t val, uint8_t *ptrDest)
int is_comm_free(is_comm_instance_t *instance)
static protocol_type_t processRtcm3Byte(is_comm_instance_t *instance)
const unsigned int g_validBaudRates[IS_BAUDRATE_COUNT]
void flipStrings(uint8_t *data, int dataLength, int offset, uint16_t *offsets, uint16_t offsetsLength)
USBInterfaceDescriptor data
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
int is_decode_binary_packet(packet_t *pkt, unsigned char *pbuf, int pbufSize)
#define PID_STOP_DID_BROADCAST
protocol_type_t is_comm_parse(is_comm_instance_t *instance)
int is_comm_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
uint8_t buf[MAX_DATASET_SIZE]
static protocol_type_t processAsciiPkt(is_comm_instance_t *instance)
int is_comm_stop_broadcasts_all_ports(is_comm_instance_t *instance)
uint32_t bc_period_multiple
static protocol_type_t processInertialSensePkt(is_comm_instance_t *instance)
int is_comm_stop_broadcasts_current_port(is_comm_instance_t *instance)
char copyDataPToStructP2(void *sptr, const p_data_hdr_t *dataHdr, const uint8_t *dataBuf, const unsigned int maxsize)
int is_comm_get_data_rmc(is_comm_instance_t *instance, uint64_t rmcBits)