Last active
November 7, 2017 20:33
-
-
Save njv299/988f4f827ee4ad4943062cdd740eaf29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------- | |
// From cgc_packet.h: | |
#define MAX_PACKET_LENGTH (48) | |
typedef struct PACKET_INFO_STRUCT | |
{ | |
uint8_t packetData[MAX_PACKET_LENGTH]; | |
uint32_t dataLen; | |
struct PACKET_INFO_STRUCT *pNextPacket; | |
fpPacketTypeHandler fpHandler; | |
uint8_t packetType; | |
} tSinglePacketData; | |
//---------------- | |
// From packet.c: | |
void cgc_receive_packet( uint8_t *pData, uint8_t dataLen, uint16_t packetCRC ) | |
{ | |
if ( pData == NULL ) | |
return; | |
if ( dataLen == 0 ) | |
return; | |
// Perform Checksum check | |
uint16_t check_checksum = cgc_simple_checksum16( pData, dataLen ); | |
// Validate Checksum | |
if ( packetCRC != check_checksum ) | |
return; | |
cgc_printf( "Packet received %d!\n", pData[0] ); | |
// Handle packet type | |
uint8_t packetType = pData[0]; | |
uint8_t found = 0; | |
for ( uint32_t i = 0; i < cgc_g_packetHandlers.handlerCount; i++ ) | |
{ | |
if ( cgc_g_packetHandlers.pHandlers[i].packetType == packetType ) | |
{ | |
// ... | |
cgc_add_new_packet( packetType, cgc_g_packetHandlers.pHandlers[i].fpHandler, pData+1, dataLen-1 ); | |
// ... | |
} | |
} | |
// ... | |
} | |
void cgc_add_new_packet( uint8_t packetType, fpPacketTypeHandler fpHandler, uint8_t *pData, uint8_t dataLen ) | |
{ | |
tSinglePacketData *pNewPacket = (tSinglePacketData *)cgc_malloc( sizeof(tSinglePacketData) ); | |
// ... | |
// Copy in the data | |
cgc_memcpy( pNewPacket->packetData, pData, dataLen ); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment