fsfw/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.cpp

64 lines
2.0 KiB
C++
Raw Normal View History

2021-07-13 20:58:45 +02:00
#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h"
2020-10-28 02:20:12 +01:00
2022-02-02 10:29:30 +01:00
#include <cstring>
2021-07-13 20:58:45 +02:00
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
2020-10-28 02:20:12 +01:00
TimeStamperIF* TmPacketBase::timeStamper = nullptr;
2021-04-12 22:24:11 +02:00
object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT;
2020-10-28 02:20:12 +01:00
2022-02-02 10:29:30 +01:00
TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketBase(setData) {}
2022-07-18 10:20:26 +02:00
TmPacketBase::~TmPacketBase() = default;
uint16_t TmPacketBase::getSourceDataSize() {
2022-07-18 10:20:26 +02:00
return SpacePacketBase::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {
2022-02-02 10:29:30 +01:00
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = getSourceData();
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TmPacketBase::setErrorControl() {
2022-02-02 10:29:30 +01:00
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getSourceDataSize();
getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH
getSourceData()[size + 1] = (crc)&0X00FF; // CRCL
}
2021-04-12 23:55:33 +02:00
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
2022-02-02 10:29:30 +01:00
size_t tempSize = 0;
return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(), &tempSize, getTimestampSize());
2021-04-12 23:55:33 +02:00
}
bool TmPacketBase::checkAndSetStamper() {
2022-07-18 10:20:26 +02:00
if (timeStamper == nullptr) {
2022-02-02 10:29:30 +01:00
timeStamper = ObjectManager::instance()->get<TimeStamperIF>(timeStamperId);
2022-07-18 10:20:26 +02:00
if (timeStamper == nullptr) {
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
2021-04-12 22:24:11 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n");
#endif
2022-02-02 10:29:30 +01:00
return false;
}
2022-02-02 10:29:30 +01:00
}
return true;
}
2021-06-13 16:29:13 +02:00
void TmPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-02-02 10:29:30 +01:00
sif::info << "TmPacketBase::print:" << std::endl;
2021-06-13 16:29:13 +02:00
#else
2022-02-02 10:29:30 +01:00
sif::printInfo("TmPacketBase::print:\n");
2021-06-13 16:29:13 +02:00
#endif
2022-02-02 10:29:30 +01:00
arrayprinter::print(getWholeData(), getFullSize());
2021-06-13 16:29:13 +02:00
}