Skip to content
Snippets Groups Projects
Commit 9601e043 authored by Philémon Prévot's avatar Philémon Prévot
Browse files

Get rid of checksum (there are none on Device Mode samples)

parent fc8b92c3
No related branches found
No related tags found
1 merge request!2HighBlueParser dev branch merged to empty main branch
......@@ -150,21 +150,6 @@ float IMUFileWriter::GetFloatSafe(const unsigned char *p, int index) {
return result;
}
unsigned char IMUFileWriter::CalculateChecksum(int msgFunction,
int msgPayloadLength, const unsigned char msgPayload[])
{
unsigned char checksum = 0;
checksum ^= static_cast<unsigned char>(0xFE);
checksum ^= static_cast<unsigned char>(msgFunction >> 8);
checksum ^= static_cast<unsigned char>(msgFunction >> 0);
checksum ^= static_cast<unsigned char>(msgPayloadLength >> 8);
checksum ^= static_cast<unsigned char>(msgPayloadLength >> 0);
for (int i = 0; i < msgPayloadLength; i++) {
checksum ^= msgPayload[i];
}
return checksum;
}
void IMUFileWriter::DecodeMessage(unsigned char c) {
switch (rcvState) {
case StateReception::Waiting:
......@@ -198,7 +183,7 @@ void IMUFileWriter::DecodeMessage(unsigned char c) {
rcvState = StateReception::Waiting;
}
} else
rcvState = StateReception::CheckSum;
rcvState = StateReception::Decode;
break;
case StateReception::Payload:
if (msgDecodedPayloadIndex > msgDecodedPayloadLength)
......@@ -210,21 +195,15 @@ void IMUFileWriter::DecodeMessage(unsigned char c) {
msgDecodedPayload[msgDecodedPayloadIndex++] = c;
if (msgDecodedPayloadIndex >= msgDecodedPayloadLength)
{
rcvState = StateReception::CheckSum;
rcvState = StateReception::Decode;
msgDecodedPayloadIndex = 0;
}
break;
case StateReception::CheckSum:
case StateReception::Decode:
{
unsigned char calculatedChecksum = CalculateChecksum(msgDecodedFunction, msgDecodedPayloadLength, msgDecodedPayload);
unsigned char receivedChecksum = c;
if (calculatedChecksum == receivedChecksum) {
//Lance l'event de fin de decodage
ProcessDecodedMessage(msgDecodedFunction, msgDecodedPayloadLength, msgDecodedPayload);
msgDecoded++;
} else {
std::cerr << "Checksum error" << std::endl;
}
//Lance l'event de fin de decodage
ProcessDecodedMessage(msgDecodedFunction, msgDecodedPayloadLength, msgDecodedPayload);
msgDecoded++;
rcvState = StateReception::Waiting;
}
break;
......@@ -477,27 +456,13 @@ void IMUFileWriter::ProcessDecodedMessage(int msgFunction, int msgPayloadLength,
void IMUFileWriter::write(uint8_t *sample, size_t size, uint8_t *imu_data) {
uint8_t *imu_data_cur(imu_data);
uint8_t softwareMajorRev=sample[5];
uint8_t softwareMajorRev=sample[0];
uint8_t softwareMinorRev=sample[6];
std::cerr << "sMR" << static_cast<int>(sample[10]) << std::endl;
std::cerr << "sMR" << static_cast<int>(sample[0]) << std::endl;
std::cerr << "Size : " << size << std::endl;
uint64_t timeStamp100MHzCurrentPacket=0;
if(true) {
//On recupere l'instant de fin du paquet courant
timeStamp100MHzCurrentPacket=BUILD_UINT64(sample[14],
sample[13],
sample[12],
sample[11],
sample[10],
sample[9],
sample[8],
sample[7]);
timeStamp100MHzCurrentPacket*=10; //To put the ts in ns
uint8_t enteteSize=16;
outfile << "PACKET TIMESTAMP: " << static_cast<int>(timeStamp100MHzCurrentPacket) << std::endl;
for(int i=enteteSize;i<size-enteteSize; i++)
if(softwareMajorRev > 2) {
for(int i=1; i<size-enteteSize; i++)
{
DecodeMessage(sample[i]);
}
......
......@@ -203,7 +203,7 @@ private:
PayloadLengthMSB,
PayloadLengthLSB,
Payload,
CheckSum
Decode
};
StateReception rcvState;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment