2020-08-13 20:53:35 +02:00
|
|
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
|
|
|
#include "SpacePacketBase.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) {
|
|
|
|
this->data = (SpacePacketPointer*) set_address;
|
|
|
|
}
|
|
|
|
|
|
|
|
SpacePacketBase::~SpacePacketBase() {
|
|
|
|
};
|
|
|
|
|
|
|
|
//CCSDS Methods:
|
|
|
|
uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
|
|
|
|
return (this->data->header.packet_id_h & 0b11100000) >> 5;
|
|
|
|
}
|
|
|
|
|
2020-05-15 19:44:14 +02:00
|
|
|
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
|
|
|
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
|
2018-07-12 16:29:32 +02:00
|
|
|
//reset header to zero:
|
|
|
|
memset(data,0, sizeof(this->data->header) );
|
|
|
|
//Set TC/TM bit.
|
|
|
|
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4;
|
|
|
|
//Set secondaryHeader bit
|
|
|
|
data->header.packet_id_h |= ((hasSecondaryHeader? 1 : 0)) << 3;
|
|
|
|
this->setAPID( apid );
|
|
|
|
//Always initialize as standalone packets.
|
|
|
|
data->header.sequence_control_h = 0b11000000;
|
|
|
|
setPacketSequenceCount(sequenceCount);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
bool SpacePacketBase::isTelecommand( void ) {
|
|
|
|
return (this->data->header.packet_id_h & 0b00010000) >> 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpacePacketBase::hasSecondaryHeader( void ) {
|
|
|
|
return (this->data->header.packet_id_h & 0b00001000) >> 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t SpacePacketBase::getPacketId() {
|
|
|
|
return ( (this->data->header.packet_id_h) << 8 ) +
|
|
|
|
this->data->header.packet_id_l;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
uint16_t SpacePacketBase::getAPID( void ) const {
|
2016-06-15 23:48:41 +02:00
|
|
|
return ( (this->data->header.packet_id_h & 0b00000111) << 8 ) +
|
|
|
|
this->data->header.packet_id_l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpacePacketBase::setAPID( uint16_t new_apid ) {
|
|
|
|
//Use first three bits of new APID, but keep rest of packet id as it was (see specification).
|
|
|
|
this->data->header.packet_id_h = (this->data->header.packet_id_h & 0b11111000) | ( ( new_apid & 0x0700 ) >> 8 );
|
|
|
|
this->data->header.packet_id_l = ( new_apid & 0x00FF );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t SpacePacketBase::getPacketSequenceControl( void ) {
|
|
|
|
return ( (this->data->header.sequence_control_h) << 8 )
|
|
|
|
+ this->data->header.sequence_control_l;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t SpacePacketBase::getSequenceFlags( void ) {
|
|
|
|
return (this->data->header.sequence_control_h & 0b11000000) >> 6 ;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
uint16_t SpacePacketBase::getPacketSequenceCount( void ) const {
|
2016-06-15 23:48:41 +02:00
|
|
|
return ( (this->data->header.sequence_control_h & 0b00111111) << 8 )
|
|
|
|
+ this->data->header.sequence_control_l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpacePacketBase::setPacketSequenceCount( uint16_t new_count) {
|
|
|
|
this->data->header.sequence_control_h = ( this->data->header.sequence_control_h & 0b11000000 ) | ( ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x3F00 ) >> 8 );
|
|
|
|
this->data->header.sequence_control_l = ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x00FF );
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t SpacePacketBase::getPacketDataLength( void ) {
|
|
|
|
return ( (this->data->header.packet_length_h) << 8 )
|
|
|
|
+ this->data->header.packet_length_l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpacePacketBase::setPacketDataLength( uint16_t new_length) {
|
|
|
|
this->data->header.packet_length_h = ( ( new_length & 0xFF00 ) >> 8 );
|
|
|
|
this->data->header.packet_length_l = ( new_length & 0x00FF );
|
|
|
|
}
|
|
|
|
|
2020-05-15 19:51:39 +02:00
|
|
|
size_t SpacePacketBase::getFullSize() {
|
2016-06-15 23:48:41 +02:00
|
|
|
//+1 is done because size in packet data length field is: size of data field -1
|
|
|
|
return this->getPacketDataLength() + sizeof(this->data->header) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* SpacePacketBase::getWholeData() {
|
|
|
|
return (uint8_t*)this->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpacePacketBase::setData( const uint8_t* p_Data ) {
|
|
|
|
this->data = (SpacePacketPointer*)p_Data;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
uint32_t SpacePacketBase::getApidAndSequenceCount() const {
|
|
|
|
return (getAPID() << 16) + getPacketSequenceCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* SpacePacketBase::getPacketData() {
|
|
|
|
return &(data->packet_data);
|
|
|
|
}
|