2020-04-06 13:22:42 +02:00
|
|
|
#include <framework/globalfunctions/CRC.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
#include <framework/tmtcpacket/pus/TcPacketBase.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <string.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
TcPacketBase::TcPacketBase(const uint8_t* set_data) :
|
|
|
|
SpacePacketBase(set_data) {
|
|
|
|
tcData = (TcPacketPointer*) set_data;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TcPacketBase::~TcPacketBase() {
|
|
|
|
//Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t TcPacketBase::getService() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return tcData->data_field.service_type;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t TcPacketBase::getSubService() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return tcData->data_field.service_subtype;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t TcPacketBase::getAcknowledgeFlags() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return tcData->data_field.version_type_ack & 0b00001111;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t* TcPacketBase::getApplicationData() const {
|
2018-07-12 16:29:32 +02:00
|
|
|
return &tcData->data;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2020-04-15 15:53:46 +02:00
|
|
|
size_t TcPacketBase::getApplicationDataSize() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return getPacketDataLength() - sizeof(tcData->data_field) - CRC_SIZE + 1;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t TcPacketBase::getErrorControl() {
|
2018-07-12 16:29:32 +02:00
|
|
|
uint16_t size = getApplicationDataSize() + CRC_SIZE;
|
|
|
|
uint8_t* p_to_buffer = &tcData->data;
|
|
|
|
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TcPacketBase::setErrorControl() {
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t full_size = getFullSize();
|
2020-04-06 13:22:42 +02:00
|
|
|
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t size = getApplicationDataSize();
|
|
|
|
(&tcData->data)[size] = (crc & 0XFF00) >> 8; // CRCH
|
|
|
|
(&tcData->data)[size + 1] = (crc) & 0X00FF; // CRCL
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TcPacketBase::setData(const uint8_t* p_Data) {
|
2018-07-12 16:29:32 +02:00
|
|
|
SpacePacketBase::setData(p_Data);
|
|
|
|
tcData = (TcPacketPointer*) p_Data;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return (tcData->data_field.version_type_ack & 0b10000000) >> 7;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t TcPacketBase::getPusVersionNumber() {
|
2018-07-12 16:29:32 +02:00
|
|
|
return (tcData->data_field.version_type_ack & 0b01110000) >> 4;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TcPacketBase::print() {
|
2018-07-12 16:29:32 +02:00
|
|
|
uint8_t * wholeData = getWholeData();
|
2016-06-15 23:48:41 +02:00
|
|
|
debug << "TcPacket contains: " << std::endl;
|
2018-07-12 16:29:32 +02:00
|
|
|
for (uint8_t count = 0; count < getFullSize(); ++count) {
|
|
|
|
debug << std::hex << (uint16_t) wholeData[count] << " ";
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
debug << std::dec << std::endl;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
|
|
|
|
uint8_t ack, uint8_t service, uint8_t subservice) {
|
|
|
|
initSpacePacketHeader(true, true, apid, sequenceCount);
|
|
|
|
memset(&tcData->data_field, 0, sizeof(tcData->data_field));
|
|
|
|
setPacketDataLength(sizeof(tcData->data_field) + CRC_SIZE);
|
|
|
|
//Data Field Header:
|
|
|
|
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
|
|
|
|
tcData->data_field.version_type_ack = 0b00010000;
|
|
|
|
tcData->data_field.version_type_ack |= (ack & 0x0F);
|
|
|
|
tcData->data_field.service_type = service;
|
|
|
|
tcData->data_field.service_subtype = subservice;
|
|
|
|
}
|