FP CRC Calc
FP CRC Calc
h>
#include <stdint.h>
#include <string.h>
/*******************************************************************************
* Definitions
******************************************************************************/
#define MAX_PACKET_SIZE 255 // Maximum packet size in bytes, adjust as needed
// Protocol-specific constants
#define FRAME_SYNC_BYTE 0xAA
ProtocolPacket packet;
uint16_t packetLength = 0;
uint8_t parameter[MAX_PACKET_SIZE - 4] = {0};
uint8_t paramLength = 0x01;
uint8_t command = 0;
// CRC8 calculation function (you can use your own CRC8 function)
static uint8_t crc8_check(const uint8_t *ptr, uint16_t len)
{
uint8_t i;
uint8_t crc = 0x00; /* Initialize the CRC value to 0x00 */
while (len--)
{
crc ^= *ptr++; /* XOR each byte of data with the current CRC value */
for (i = 8; i > 0; --i)
{
if (crc & 0x80)
crc = (crc << 1) ^ 0x31;
else
crc = (crc << 1);
}
}
return crc; /* Return the calculated CRC value */
}
// memcpy(sendBuff, 0, sizeof(sendBuff));
//Single line
printf("0x%02X ", packet->frameSync);
printf("0x%02X ", packet->command);
printf("0x%02X ", packet->remainingDataLength);
for (int i = 0; i < packetLength - 4; i++)
{
printf("0x%02X ", packet->parameter[i]);
}
printf("0x%02X \n\n", packet->crc);
int main()
{
while (1)
{
printf("CRC calculation\n");
printf("Enter command:\n");
scanf("%hhx", &command);
}
return 0;
}