I am developing a code in which I need to pass a structure pointer value to a function as a parameter. I am calling function "proto485Compare()" in "RS485TaskSlave()". "rs485Msg" contains my data for which I need to verify for checksum, I am checking it in "RS485TaskSlave()" using "if(proto485ValidCheckSum(rs485_message_t ((uint8_t*)message)))" but it is showing error on this line.
Please help me to get the values of "rs485Msg" & check for checksum on this line
Below is my code snippet:
typedef struct
{
uint8_t AB; ///< Address byte (Start byte)
uint8_t CB; ///< Command (index) "ASCII-byte"
uint8_t SI; ///< Action (sub index) "ASCII-byte"
uint8_t PH1; ///< Payload "ASCII-byte" of the high nibble of the high byte of the raw payload
uint8_t PH0; ///< Payload "ASCII-byte" of the low nibble of the high byte of the raw payload
uint8_t PL1; ///< Payload "ASCII-byte" of the high nibble of the low byte of the raw payload
uint8_t PL0; ///< Payload "ASCII-byte" of the low nibble of the low byte of the raw payload
uint8_t CS1; ///< Checksum "ASCII-byte" of the high nibble of the raw checksum
uint8_t CS0; ///< Checksum "ASCII-byte" of the low nibble of the raw checksum
} rs485_message_t;
uint8_t proto485ValidCheckSum(rs485_message_t message)
{
uint8_t rawChecksum = (message.CB - OFFSET_ASCII) + (message.SI - OFFSET_ASCII) +
(message.PH1 - OFFSET_ASCII) + (message.PH0 - OFFSET_ASCII) +
(message.PL1 - OFFSET_ASCII) + (message.PL0 - OFFSET_ASCII);
uint8_t res = (((rawChecksum & 0xF0) >> 4) + OFFSET_ASCII) == message.CS1 &&
((rawChecksum & 0x0F) + OFFSET_ASCII) == message.CS0;
return res;
}
void RS485TaskSlave(void *p_arg) //b - RS485 communication Task
{
uint8_t res;
rs485_message_t rs485Msg;
uint8_t command, action, value;
(void)p_arg;
while(1)
{
res = driver485Read((uint8_t *)&rs485Msg, RS485_MSG_LENGTH);
if(RS485_MSG_LENGTH == 9)
{
res = proto485Compare((uint8_t *)&rs485Msg, command, action, value);
}
}
}
int16_t proto485Compare(uint8_t* message, uint8_t* comparec, uint8_t* comparea, uint8_t* comaprev)
{ int j = 0;
rs485_message_t rs485Msg;
char res;
uint8_t FWmsg[9] = {0x09,0x31,0x30,0x30,0x30,0x30,0x33,0x30,0x34};
uint8_t arduinodata[9] = {0x09,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30};
if(proto485ValidCheckSum(rs485_message_t ((uint8_t*)message))) //
/*GETTING ERRORVON THIS LINE please help how to pass message value to verify checksum at this line*/
{
printf("compare command..........");
for (j=0; j<9; j++)
{
arduinodata[j] = message[j];
printf("%d ",arduinodata[j]);
}
printf("\n");
if(compareArray(FWmsg,arduinodata,7)==0)
{
uint8_t add, fwc, fwa;
uint16_t fwv;
res = GetABFWversion(&add, &fwc, &fwa, &fwv);
res = proto485OnlyWrite(add,fwc, fwa, fwv);
}
}
else
{
printf("Arrays have different elements.\n");
}
return res;
}