important bugfix for CRC calculation
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Robin Müller 2022-08-18 15:32:24 +02:00
parent 732602a4cc
commit ec47d7eeef
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 66 additions and 45 deletions

View File

@ -259,7 +259,6 @@ class TcMemWrite : public TcBase {
: TcBase(params, apid::TC_MEM_WRITE, sequenceCount) {}
protected:
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
result = lengthCheck(commandDataLen);
@ -284,16 +283,15 @@ class TcMemWrite : public TcBase {
// Min length consists of 4 byte address, 2 byte mem length field, 4 byte data (1 word)
static const size_t MIN_COMMAND_DATA_LENGTH = MIN_FIXED_PAYLOAD_LENGTH + 4;
ReturnValue_t lengthCheck(size_t commandDataLen) {
if (commandDataLen < MIN_COMMAND_DATA_LENGTH) {
sif::warning << "TcMemWrite: Length " << commandDataLen << " smaller than minimum " <<
MIN_COMMAND_DATA_LENGTH << std::endl;
sif::warning << "TcMemWrite: Length " << commandDataLen << " smaller than minimum "
<< MIN_COMMAND_DATA_LENGTH << std::endl;
return INVALID_LENGTH;
}
if (commandDataLen + CRC_SIZE > spParams.maxSize) {
sif::warning << "TcMemWrite: Length " << commandDataLen << " larger than allowed " <<
spParams.maxSize - CRC_SIZE << std::endl;
sif::warning << "TcMemWrite: Length " << commandDataLen << " larger than allowed "
<< spParams.maxSize - CRC_SIZE << std::endl;
return INVALID_LENGTH;
}
return HasReturnvaluesIF::RETURN_OK;
@ -460,7 +458,8 @@ class TcReplayStart : public TcBase {
static const uint8_t ONCE = 1;
ReturnValue_t lengthCheck(size_t commandDataLen) {
if (commandDataLen != COMMAND_DATA_LENGTH or checkPayloadLen() != HasReturnvaluesIF::RETURN_OK) {
if (commandDataLen != COMMAND_DATA_LENGTH or
checkPayloadLen() != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl;
return INVALID_LENGTH;
}

View File

@ -405,7 +405,10 @@ class SetTimeRef : public ploc::SpTcBase {
if (res != result::OK) {
return res;
}
initPacket(time);
res = initPacket(time);
if (res != result::OK) {
return res;
}
return calcCrc();
}
@ -414,29 +417,48 @@ class SetTimeRef : public ploc::SpTcBase {
static const uint16_t CRC_OFFSET = DATA_FIELD_LENGTH - 2;
static const uint16_t SYNC = 0x8000;
void initPacket(Clock::TimeOfDay_t* time) {
size_t serializedSize = 0;
ReturnValue_t initPacket(Clock::TimeOfDay_t* time) {
size_t serializedSize = 6;
uint8_t* dataFieldPtr = payloadStart;
uint16_t milliseconds = static_cast<uint16_t>(time->usecond / 1000) | SYNC;
SerializeAdapter::serialize(&milliseconds, &dataFieldPtr, &serializedSize,
sizeof(milliseconds), SerializeIF::Endianness::BIG);
ReturnValue_t result =
SerializeAdapter::serialize(&milliseconds, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t second = static_cast<uint8_t>(time->second);
SerializeAdapter::serialize(&second, &dataFieldPtr, &serializedSize,
sizeof(time->second), SerializeIF::Endianness::BIG);
result = SerializeAdapter::serialize(&second, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t minute = static_cast<uint8_t>(time->minute);
SerializeAdapter::serialize(&minute, &dataFieldPtr, &serializedSize,
sizeof(time->minute), SerializeIF::Endianness::BIG);
result = SerializeAdapter::serialize(&minute, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t hour = static_cast<uint8_t>(time->hour);
SerializeAdapter::serialize(&hour, &dataFieldPtr, &serializedSize, sizeof(time->hour),
result = SerializeAdapter::serialize(&hour, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t day = static_cast<uint8_t>(time->day);
SerializeAdapter::serialize(&day, &dataFieldPtr, &serializedSize, sizeof(time->day),
result = SerializeAdapter::serialize(&day, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t month = static_cast<uint8_t>(time->month);
SerializeAdapter::serialize(&month, &dataFieldPtr, &serializedSize,
sizeof(time->month), SerializeIF::Endianness::BIG);
result = SerializeAdapter::serialize(&month, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
uint8_t year = static_cast<uint8_t>(time->year - 1900);
SerializeAdapter::serialize(&year, &dataFieldPtr, &serializedSize, sizeof(time->year),
return SerializeAdapter::serialize(&year, &dataFieldPtr, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
}
};
@ -1311,38 +1333,38 @@ class AcknowledgmentReport : public VerificationReport {
void printStatusInformation() {
StatusCode statusCode = static_cast<StatusCode>(getStatusCode());
const char* prefix = "Supervisor acknowledgment report status: ";
switch (statusCode) {
case StatusCode::OK: {
sif::warning << "Supervisor acknowledgment report status: Ok" << std::endl;
sif::warning << prefix << "Ok" << std::endl;
break;
}
case StatusCode::BAD_PARAM: {
sif::warning << "Supervisor acknowledgment report status: Bad param" << std::endl;
sif::warning << prefix << "Bad param" << std::endl;
break;
}
case StatusCode::TIMEOUT: {
sif::warning << "Supervisor acknowledgment report status: Timeout" << std::endl;
sif::warning << prefix << "Timeout" << std::endl;
break;
}
case StatusCode::RX_ERROR: {
sif::warning << "Supervisor acknowledgment report status: RX error" << std::endl;
sif::warning << prefix << "RX error" << std::endl;
break;
}
case StatusCode::TX_ERROR: {
sif::warning << "Supervisor acknowledgment report status: TX error" << std::endl;
sif::warning << prefix << "TX error" << std::endl;
break;
}
case StatusCode::HEADER_EMPTY: {
sif::warning << "Supervisor acknowledgment report status: Header empty" << std::endl;
sif::warning << prefix << "Header empty" << std::endl;
break;
}
case StatusCode::DEFAULT_NAK: {
sif::warning << "Supervisor acknowledgment report status: Default code for nak"
<< std::endl;
sif::warning << prefix << "Default code for NAK" << std::endl;
break;
}
case StatusCode::ROUTE_PACKET: {
sif::warning << "Supervisor acknowledgment report status: Route packet error" << std::endl;
sif::warning << prefix << "Route packet error" << std::endl;
break;
}
default:

View File

@ -73,12 +73,12 @@ class SpTcBase {
ReturnValue_t calcCrc() {
/* Calculate crc */
uint16_t crc = CRC::crc16ccitt(spParams.buf, ccsds::HEADER_LEN + spParams.dataFieldLen - 2);
uint16_t crc = CRC::crc16ccitt(spParams.buf, getFullPacketLen() - 2);
/* Add crc to packet data field of space packet */
size_t serializedSize = 0;
return SerializeAdapter::serialize<uint16_t>(&crc, &payloadStart, &serializedSize, sizeof(crc),
SerializeIF::Endianness::BIG);
return SerializeAdapter::serialize(&crc, spParams.buf + getFullPacketLen() - 2, &serializedSize,
spParams.maxSize, SerializeIF::Endianness::BIG);
}
protected: