2020-10-28 02:20:12 +01:00
|
|
|
#include "TmPacketBase.h"
|
|
|
|
|
2021-06-14 10:19:01 +02:00
|
|
|
#include "../../../globalfunctions/CRC.h"
|
|
|
|
#include "../../../globalfunctions/arrayprinter.h"
|
|
|
|
#include "../../../objectmanager/ObjectManager.h"
|
|
|
|
#include "../../../serviceinterface/ServiceInterface.h"
|
|
|
|
#include "../../../timemanager/CCSDSTime.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-06-14 15:14:57 +02:00
|
|
|
TmPacketBase::TmPacketBase(uint8_t* setData): SpacePacketBase(setData) {}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
TmPacketBase::~TmPacketBase() {
|
2021-04-12 21:17:53 +02:00
|
|
|
//Nothing to do.
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t TmPacketBase::getSourceDataSize() {
|
2021-04-12 21:17:53 +02:00
|
|
|
return getPacketDataLength() - getDataFieldSize() - CRC_SIZE + 1;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t TmPacketBase::getErrorControl() {
|
2021-04-12 21:17:53 +02: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];
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TmPacketBase::setErrorControl() {
|
2021-04-12 21:17:53 +02: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
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 23:55:33 +02:00
|
|
|
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
|
|
|
|
size_t tempSize = 0;
|
|
|
|
return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(),
|
|
|
|
&tempSize, getTimestampSize());
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
bool TmPacketBase::checkAndSetStamper() {
|
2021-04-12 21:17:53 +02:00
|
|
|
if (timeStamper == NULL) {
|
2021-06-05 19:52:38 +02:00
|
|
|
timeStamper = ObjectManager::instance()->get<TimeStamperIF>(timeStamperId);
|
2021-04-12 21:17:53 +02:00
|
|
|
if (timeStamper == NULL) {
|
2021-01-03 14:16:52 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2021-04-12 23:55:33 +02:00
|
|
|
sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
|
2021-04-12 22:24:11 +02:00
|
|
|
#else
|
|
|
|
sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n");
|
2021-01-03 13:58:18 +01:00
|
|
|
#endif
|
2021-04-12 21:17:53 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2021-06-13 16:29:13 +02:00
|
|
|
void TmPacketBase::print() {
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
|
|
sif::info << "TmPacketBase::print:" << std::endl;
|
|
|
|
#else
|
|
|
|
sif::printInfo("TmPacketBase::print:\n");
|
|
|
|
#endif
|
|
|
|
arrayprinter::print(getWholeData(), getFullSize());
|
|
|
|
}
|