checksum
-
hey all, I do a checksum logic on both the serial device and the Pc end to see if the correct packet is received. I do :
for (i = 0 ; i < (nMaxLenPkt2Tx - 1); i++) { cChkSum_2pc ^= txbuffer[i];} txbuffer[i] = cChkSum_2pc;
and then send the packet from the serial device to PC. and on Pc's end, I do this after receiving the packet before copying it to a local buffer.char cChkSum = 0; `for (i = 0 ; i < (PKTINFO_LEN_MPU_2PC - 1); i++) cChkSum ^= m_cBufPktInfo_mpu_2pc[i];`
and compare this checksum count with teh received checksu count in the packet to determine if it is a correct packet or not. ie.,if (cChkSum != m_cBufPktInfo_mpu_2pc[PKTINFO_LEN_MPU_2PC - 1]) { TRACE("Received a bad packet!\n"); }
But I get badpacket everytime . Waht could be wrong? the datatypes and the length of the packet sent and received are the same. I have checked that. Any ideas/help? Thanks in advance. -
hey all, I do a checksum logic on both the serial device and the Pc end to see if the correct packet is received. I do :
for (i = 0 ; i < (nMaxLenPkt2Tx - 1); i++) { cChkSum_2pc ^= txbuffer[i];} txbuffer[i] = cChkSum_2pc;
and then send the packet from the serial device to PC. and on Pc's end, I do this after receiving the packet before copying it to a local buffer.char cChkSum = 0; `for (i = 0 ; i < (PKTINFO_LEN_MPU_2PC - 1); i++) cChkSum ^= m_cBufPktInfo_mpu_2pc[i];`
and compare this checksum count with teh received checksu count in the packet to determine if it is a correct packet or not. ie.,if (cChkSum != m_cBufPktInfo_mpu_2pc[PKTINFO_LEN_MPU_2PC - 1]) { TRACE("Received a bad packet!\n"); }
But I get badpacket everytime . Waht could be wrong? the datatypes and the length of the packet sent and received are the same. I have checked that. Any ideas/help? Thanks in advance.