taken over datalinklayer form upstream
This commit is contained in:
parent
5ce954672b
commit
d2ef2b2be4
@ -1,62 +1,62 @@
|
||||
/**
|
||||
* @file BCFrame.h
|
||||
* @brief This file defines the BCFrame class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef BCFRAME_H_
|
||||
#define BCFRAME_H_
|
||||
|
||||
#include "../datalinklayer/CCSDSReturnValuesIF.h"
|
||||
|
||||
/**
|
||||
* Small helper class to identify a BcFrame.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class BcFrame: public CCSDSReturnValuesIF {
|
||||
private:
|
||||
static const uint8_t UNLOCK_COMMAND = 0b00000000;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_1 = 0b10000010;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_2 = 0b00000000;//! Identifier for a certain BC Command.
|
||||
|
||||
public:
|
||||
uint8_t byte1; //!< First content byte
|
||||
uint8_t byte2; //!< Second content byte
|
||||
uint8_t vR; //!< vR byte
|
||||
/**
|
||||
* Simple default constructor.
|
||||
*/
|
||||
BcFrame() :
|
||||
byte1(0), byte2(0), vR(0) {
|
||||
}
|
||||
/**
|
||||
* Main and only useful method of the class.
|
||||
* With the buffer and size information passed, the class passes the content
|
||||
* and checks if it is one of the two valid BC Command Frames.
|
||||
* @param inBuffer Content of the frame to check,
|
||||
* @param inSize Size of the data to check.
|
||||
* @return - #BC_ILLEGAL_COMMAND if it is no command.
|
||||
* - #BC_IS_UNLOCK_COMMAND if it is an unlock command.
|
||||
* - #BC_IS_SET_VR_COMMAND if it is such.
|
||||
*/
|
||||
ReturnValue_t initialize(const uint8_t* inBuffer, uint16_t inSize) {
|
||||
ReturnValue_t returnValue = BC_ILLEGAL_COMMAND;
|
||||
if (inSize == 1) {
|
||||
byte1 = inBuffer[0];
|
||||
if (byte1 == UNLOCK_COMMAND) {
|
||||
returnValue = BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
} else if (inSize == 3) {
|
||||
byte1 = inBuffer[0];
|
||||
byte2 = inBuffer[1];
|
||||
vR = inBuffer[2];
|
||||
if (byte1 == SET_V_R_1 && byte2 == SET_V_R_2) {
|
||||
returnValue = BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BCFRAME_H_ */
|
||||
/**
|
||||
* @file BCFrame.h
|
||||
* @brief This file defines the BCFrame class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef BCFRAME_H_
|
||||
#define BCFRAME_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
|
||||
/**
|
||||
* Small helper class to identify a BcFrame.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class BcFrame: public CCSDSReturnValuesIF {
|
||||
private:
|
||||
static const uint8_t UNLOCK_COMMAND = 0b00000000;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_1 = 0b10000010;//! Identifier for a certain BC Command.
|
||||
static const uint8_t SET_V_R_2 = 0b00000000;//! Identifier for a certain BC Command.
|
||||
|
||||
public:
|
||||
uint8_t byte1; //!< First content byte
|
||||
uint8_t byte2; //!< Second content byte
|
||||
uint8_t vR; //!< vR byte
|
||||
/**
|
||||
* Simple default constructor.
|
||||
*/
|
||||
BcFrame() :
|
||||
byte1(0), byte2(0), vR(0) {
|
||||
}
|
||||
/**
|
||||
* Main and only useful method of the class.
|
||||
* With the buffer and size information passed, the class passes the content
|
||||
* and checks if it is one of the two valid BC Command Frames.
|
||||
* @param inBuffer Content of the frame to check,
|
||||
* @param inSize Size of the data to check.
|
||||
* @return - #BC_ILLEGAL_COMMAND if it is no command.
|
||||
* - #BC_IS_UNLOCK_COMMAND if it is an unlock command.
|
||||
* - #BC_IS_SET_VR_COMMAND if it is such.
|
||||
*/
|
||||
ReturnValue_t initialize(const uint8_t* inBuffer, uint16_t inSize) {
|
||||
ReturnValue_t returnValue = BC_ILLEGAL_COMMAND;
|
||||
if (inSize == 1) {
|
||||
byte1 = inBuffer[0];
|
||||
if (byte1 == UNLOCK_COMMAND) {
|
||||
returnValue = BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
} else if (inSize == 3) {
|
||||
byte1 = inBuffer[0];
|
||||
byte2 = inBuffer[1];
|
||||
vR = inBuffer[2];
|
||||
if (byte1 == SET_V_R_1 && byte2 == SET_V_R_2) {
|
||||
returnValue = BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* BCFRAME_H_ */
|
||||
|
@ -1,56 +1,56 @@
|
||||
/**
|
||||
* @file CCSDSReturnValuesIF.h
|
||||
* @brief This file defines the CCSDSReturnValuesIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CCSDSRETURNVALUESIF_H_
|
||||
#define CCSDSRETURNVALUESIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
/**
|
||||
* This is a helper class to collect special return values that come up during CCSDS Handling.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class CCSDSReturnValuesIF: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_HANDLER_IF; //!< Basic ID of the interface.
|
||||
|
||||
static const ReturnValue_t BC_IS_SET_VR_COMMAND = MAKE_RETURN_CODE( 0x01 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_IS_UNLOCK_COMMAND = MAKE_RETURN_CODE( 0x02 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_ILLEGAL_COMMAND = MAKE_RETURN_CODE( 0xB0 );//!< A value to describe an illegal BC frame.
|
||||
static const ReturnValue_t BOARD_READING_NOT_FINISHED = MAKE_RETURN_CODE( 0xB1 ); //! The CCSDS Board is not yet finished reading, it requires another cycle.
|
||||
|
||||
static const ReturnValue_t NS_POSITIVE_W = MAKE_RETURN_CODE( 0xF0 );//!< NS is in the positive window
|
||||
static const ReturnValue_t NS_NEGATIVE_W = MAKE_RETURN_CODE( 0xF1 );//!< NS is in the negative window
|
||||
static const ReturnValue_t NS_LOCKOUT = MAKE_RETURN_CODE( 0xF2 ); //!< NS is in lockout state
|
||||
static const ReturnValue_t FARM_IN_LOCKOUT = MAKE_RETURN_CODE( 0xF3 );//!< FARM-1 is currently in lockout state
|
||||
static const ReturnValue_t FARM_IN_WAIT = MAKE_RETURN_CODE( 0xF4 ); //!< FARM-1 is currently in wait state
|
||||
|
||||
static const ReturnValue_t WRONG_SYMBOL = MAKE_RETURN_CODE( 0xE0 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t DOUBLE_START = MAKE_RETURN_CODE( 0xE1 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t START_SYMBOL_MISSED = MAKE_RETURN_CODE( 0xE2 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t END_WITHOUT_START = MAKE_RETURN_CODE( 0xE3 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t TOO_LARGE = MAKE_RETURN_CODE( 0xE4 );//!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE( 0xE5 );//!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_TF_VERSION = MAKE_RETURN_CODE( 0xE6 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_SPACECRAFT_ID = MAKE_RETURN_CODE( 0xE7 );//!< An error code for a frame.
|
||||
static const ReturnValue_t NO_VALID_FRAME_TYPE = MAKE_RETURN_CODE( 0xE8 );//!< An error code for a frame.
|
||||
static const ReturnValue_t CRC_FAILED = MAKE_RETURN_CODE( 0xE9 );//!< An error code for a frame.
|
||||
static const ReturnValue_t VC_NOT_FOUND = MAKE_RETURN_CODE( 0xEA ); //!< An error code for a frame.
|
||||
static const ReturnValue_t FORWARDING_FAILED = MAKE_RETURN_CODE( 0xEB );//!< An error code for a frame.
|
||||
static const ReturnValue_t CONTENT_TOO_LARGE = MAKE_RETURN_CODE( 0xEC );//!< An error code for a frame.
|
||||
static const ReturnValue_t RESIDUAL_DATA = MAKE_RETURN_CODE( 0xED );//!< An error code for a frame.
|
||||
static const ReturnValue_t DATA_CORRUPTED = MAKE_RETURN_CODE( 0xEE );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_SEGMENTATION_FLAG = MAKE_RETURN_CODE( 0xEF );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_FLAG_COMBINATION = MAKE_RETURN_CODE( 0xD0 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t SHORTER_THAN_HEADER = MAKE_RETURN_CODE( 0xD1 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_BLOCKED_PACKET = MAKE_RETURN_CODE( 0xD2 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_MAP_EXTRACTION = MAKE_RETURN_CODE( 0xD3 ); //!< An error code for a frame.
|
||||
|
||||
virtual ~CCSDSReturnValuesIF() {
|
||||
} //!< Empty virtual destructor
|
||||
};
|
||||
|
||||
#endif /* CCSDSRETURNVALUESIF_H_ */
|
||||
/**
|
||||
* @file CCSDSReturnValuesIF.h
|
||||
* @brief This file defines the CCSDSReturnValuesIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CCSDSRETURNVALUESIF_H_
|
||||
#define CCSDSRETURNVALUESIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
/**
|
||||
* This is a helper class to collect special return values that come up during CCSDS Handling.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class CCSDSReturnValuesIF: public HasReturnvaluesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_HANDLER_IF; //!< Basic ID of the interface.
|
||||
|
||||
static const ReturnValue_t BC_IS_SET_VR_COMMAND = MAKE_RETURN_CODE( 0x01 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_IS_UNLOCK_COMMAND = MAKE_RETURN_CODE( 0x02 ); //!< A value to describe a BC frame.
|
||||
static const ReturnValue_t BC_ILLEGAL_COMMAND = MAKE_RETURN_CODE( 0xB0 );//!< A value to describe an illegal BC frame.
|
||||
static const ReturnValue_t BOARD_READING_NOT_FINISHED = MAKE_RETURN_CODE( 0xB1 ); //! The CCSDS Board is not yet finished reading, it requires another cycle.
|
||||
|
||||
static const ReturnValue_t NS_POSITIVE_W = MAKE_RETURN_CODE( 0xF0 );//!< NS is in the positive window
|
||||
static const ReturnValue_t NS_NEGATIVE_W = MAKE_RETURN_CODE( 0xF1 );//!< NS is in the negative window
|
||||
static const ReturnValue_t NS_LOCKOUT = MAKE_RETURN_CODE( 0xF2 ); //!< NS is in lockout state
|
||||
static const ReturnValue_t FARM_IN_LOCKOUT = MAKE_RETURN_CODE( 0xF3 );//!< FARM-1 is currently in lockout state
|
||||
static const ReturnValue_t FARM_IN_WAIT = MAKE_RETURN_CODE( 0xF4 ); //!< FARM-1 is currently in wait state
|
||||
|
||||
static const ReturnValue_t WRONG_SYMBOL = MAKE_RETURN_CODE( 0xE0 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t DOUBLE_START = MAKE_RETURN_CODE( 0xE1 ); //!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t START_SYMBOL_MISSED = MAKE_RETURN_CODE( 0xE2 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t END_WITHOUT_START = MAKE_RETURN_CODE( 0xE3 );//!< An error code in the FrameFinder.
|
||||
static const ReturnValue_t TOO_LARGE = MAKE_RETURN_CODE( 0xE4 );//!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE( 0xE5 );//!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_TF_VERSION = MAKE_RETURN_CODE( 0xE6 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t WRONG_SPACECRAFT_ID = MAKE_RETURN_CODE( 0xE7 );//!< An error code for a frame.
|
||||
static const ReturnValue_t NO_VALID_FRAME_TYPE = MAKE_RETURN_CODE( 0xE8 );//!< An error code for a frame.
|
||||
static const ReturnValue_t CRC_FAILED = MAKE_RETURN_CODE( 0xE9 );//!< An error code for a frame.
|
||||
static const ReturnValue_t VC_NOT_FOUND = MAKE_RETURN_CODE( 0xEA ); //!< An error code for a frame.
|
||||
static const ReturnValue_t FORWARDING_FAILED = MAKE_RETURN_CODE( 0xEB );//!< An error code for a frame.
|
||||
static const ReturnValue_t CONTENT_TOO_LARGE = MAKE_RETURN_CODE( 0xEC );//!< An error code for a frame.
|
||||
static const ReturnValue_t RESIDUAL_DATA = MAKE_RETURN_CODE( 0xED );//!< An error code for a frame.
|
||||
static const ReturnValue_t DATA_CORRUPTED = MAKE_RETURN_CODE( 0xEE );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_SEGMENTATION_FLAG = MAKE_RETURN_CODE( 0xEF );//!< An error code for a frame.
|
||||
static const ReturnValue_t ILLEGAL_FLAG_COMBINATION = MAKE_RETURN_CODE( 0xD0 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t SHORTER_THAN_HEADER = MAKE_RETURN_CODE( 0xD1 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_BLOCKED_PACKET = MAKE_RETURN_CODE( 0xD2 ); //!< An error code for a frame.
|
||||
static const ReturnValue_t TOO_SHORT_MAP_EXTRACTION = MAKE_RETURN_CODE( 0xD3 ); //!< An error code for a frame.
|
||||
|
||||
virtual ~CCSDSReturnValuesIF() {
|
||||
} //!< Empty virtual destructor
|
||||
};
|
||||
|
||||
#endif /* CCSDSRETURNVALUESIF_H_ */
|
||||
|
@ -1,63 +1,63 @@
|
||||
/**
|
||||
* @file Clcw.cpp
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "../datalinklayer/Clcw.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
Clcw::Clcw() {
|
||||
content.raw = 0;
|
||||
content.status = STATUS_FIELD_DEFAULT;
|
||||
}
|
||||
|
||||
Clcw::~Clcw() {
|
||||
}
|
||||
|
||||
void Clcw::setVirtualChannel(uint8_t setChannel) {
|
||||
content.virtualChannelIdSpare = ((setChannel & 0x3F) << 2);
|
||||
}
|
||||
|
||||
void Clcw::setLockoutFlag(bool lockout) {
|
||||
content.flags = (content.flags & LOCKOUT_FLAG_MASK) | (lockout << LOCKOUT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setWaitFlag(bool waitFlag) {
|
||||
content.flags = (content.flags & WAIT_FLAG_MASK) | (waitFlag << WAIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setRetransmitFlag(bool retransmitFlag) {
|
||||
content.flags = (content.flags & RETRANSMIT_FLAG_MASK) | (retransmitFlag << RETRANSMIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setFarmBCount(uint8_t count) {
|
||||
content.flags = (content.flags & FARM_B_COUNT_MASK) | ((count & 0x03) << 1);
|
||||
}
|
||||
|
||||
void Clcw::setReceiverFrameSequenceNumber(uint8_t vR) {
|
||||
content.vRValue = vR;
|
||||
}
|
||||
|
||||
uint32_t Clcw::getAsWhole() {
|
||||
return content.raw;
|
||||
}
|
||||
|
||||
void Clcw::setRFAvailable(bool rfAvailable) {
|
||||
content.flags = (content.flags & NO_RF_AVIALABLE_MASK) | (!rfAvailable << NO_RF_AVIALABLE_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setBitLock(bool bitLock) {
|
||||
content.flags = (content.flags & NO_BIT_LOCK_MASK) | (!bitLock << NO_BIT_LOCK_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::print() {
|
||||
sif::debug << "Clcw::print: Clcw is: " << std::hex << getAsWhole() << std::dec << std::endl;
|
||||
}
|
||||
|
||||
void Clcw::setWhole(uint32_t rawClcw) {
|
||||
content.raw = rawClcw;
|
||||
}
|
||||
/**
|
||||
* @file Clcw.cpp
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "Clcw.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
Clcw::Clcw() {
|
||||
content.raw = 0;
|
||||
content.status = STATUS_FIELD_DEFAULT;
|
||||
}
|
||||
|
||||
Clcw::~Clcw() {
|
||||
}
|
||||
|
||||
void Clcw::setVirtualChannel(uint8_t setChannel) {
|
||||
content.virtualChannelIdSpare = ((setChannel & 0x3F) << 2);
|
||||
}
|
||||
|
||||
void Clcw::setLockoutFlag(bool lockout) {
|
||||
content.flags = (content.flags & LOCKOUT_FLAG_MASK) | (lockout << LOCKOUT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setWaitFlag(bool waitFlag) {
|
||||
content.flags = (content.flags & WAIT_FLAG_MASK) | (waitFlag << WAIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setRetransmitFlag(bool retransmitFlag) {
|
||||
content.flags = (content.flags & RETRANSMIT_FLAG_MASK) | (retransmitFlag << RETRANSMIT_FLAG_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setFarmBCount(uint8_t count) {
|
||||
content.flags = (content.flags & FARM_B_COUNT_MASK) | ((count & 0x03) << 1);
|
||||
}
|
||||
|
||||
void Clcw::setReceiverFrameSequenceNumber(uint8_t vR) {
|
||||
content.vRValue = vR;
|
||||
}
|
||||
|
||||
uint32_t Clcw::getAsWhole() {
|
||||
return content.raw;
|
||||
}
|
||||
|
||||
void Clcw::setRFAvailable(bool rfAvailable) {
|
||||
content.flags = (content.flags & NO_RF_AVIALABLE_MASK) | (!rfAvailable << NO_RF_AVIALABLE_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::setBitLock(bool bitLock) {
|
||||
content.flags = (content.flags & NO_BIT_LOCK_MASK) | (!bitLock << NO_BIT_LOCK_POSITION);
|
||||
}
|
||||
|
||||
void Clcw::print() {
|
||||
sif::debug << "Clcw::print: Clcw is: " << std::hex << getAsWhole() << std::dec << std::endl;
|
||||
}
|
||||
|
||||
void Clcw::setWhole(uint32_t rawClcw) {
|
||||
content.raw = rawClcw;
|
||||
}
|
||||
|
@ -1,66 +1,66 @@
|
||||
/**
|
||||
* @file Clcw.h
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CLCW_H_
|
||||
#define CLCW_H_
|
||||
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
/**
|
||||
* Small helper method to handle the Clcw values.
|
||||
* It has a content struct that manages the register and can be set externally.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class Clcw : public ClcwIF {
|
||||
private:
|
||||
static const uint8_t STATUS_FIELD_DEFAULT = 0b00000001; //!< Default for the status field.
|
||||
static const uint8_t NO_RF_AVIALABLE_POSITION = 7; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_BIT_LOCK_POSITION = 6; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t LOCKOUT_FLAG_POSITION = 5; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t WAIT_FLAG_POSITION = 4; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t RETRANSMIT_FLAG_POSITION = 3; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_RF_AVIALABLE_MASK = 0xFF xor (1 << NO_RF_AVIALABLE_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t NO_BIT_LOCK_MASK = 0xFF xor (1 << NO_BIT_LOCK_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t LOCKOUT_FLAG_MASK = 0xFF xor (1 << LOCKOUT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t WAIT_FLAG_MASK = 0xFF xor (1 << WAIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t RETRANSMIT_FLAG_MASK = 0xFF xor (1 << RETRANSMIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t FARM_B_COUNT_MASK = 0b11111001; //!< Mask for a counter in the register.
|
||||
/**
|
||||
* This is the data structure of the CLCW register.
|
||||
*/
|
||||
union clcwContent {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t status;
|
||||
uint8_t virtualChannelIdSpare;
|
||||
uint8_t flags;
|
||||
uint8_t vRValue;
|
||||
};
|
||||
};
|
||||
clcwContent content; //!< Represents the content of the register.
|
||||
public:
|
||||
/**
|
||||
* The constructor sets everything to default values.
|
||||
*/
|
||||
Clcw();
|
||||
/**
|
||||
* Nothing happens in the destructor.
|
||||
*/
|
||||
~Clcw();
|
||||
void setVirtualChannel( uint8_t setChannel );
|
||||
void setLockoutFlag( bool lockout );
|
||||
void setWaitFlag( bool waitFlag );
|
||||
void setRetransmitFlag( bool retransmitFlag );
|
||||
void setFarmBCount( uint8_t count );
|
||||
void setReceiverFrameSequenceNumber( uint8_t vR );
|
||||
void setRFAvailable( bool rfAvailable );
|
||||
void setBitLock( bool bitLock );
|
||||
uint32_t getAsWhole();
|
||||
void setWhole( uint32_t rawClcw );
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif /* CLCW_H_ */
|
||||
/**
|
||||
* @file Clcw.h
|
||||
* @brief This file defines the Clcw class.
|
||||
* @date 17.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef CLCW_H_
|
||||
#define CLCW_H_
|
||||
|
||||
#include "ClcwIF.h"
|
||||
/**
|
||||
* Small helper method to handle the Clcw values.
|
||||
* It has a content struct that manages the register and can be set externally.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class Clcw : public ClcwIF {
|
||||
private:
|
||||
static const uint8_t STATUS_FIELD_DEFAULT = 0b00000001; //!< Default for the status field.
|
||||
static const uint8_t NO_RF_AVIALABLE_POSITION = 7; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_BIT_LOCK_POSITION = 6; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t LOCKOUT_FLAG_POSITION = 5; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t WAIT_FLAG_POSITION = 4; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t RETRANSMIT_FLAG_POSITION = 3; //!< Position of a flag in the register (starting with 0).
|
||||
static const uint8_t NO_RF_AVIALABLE_MASK = 0xFF xor (1 << NO_RF_AVIALABLE_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t NO_BIT_LOCK_MASK = 0xFF xor (1 << NO_BIT_LOCK_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t LOCKOUT_FLAG_MASK = 0xFF xor (1 << LOCKOUT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t WAIT_FLAG_MASK = 0xFF xor (1 << WAIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t RETRANSMIT_FLAG_MASK = 0xFF xor (1 << RETRANSMIT_FLAG_POSITION); //!< Mask for a flag in the register.
|
||||
static const uint8_t FARM_B_COUNT_MASK = 0b11111001; //!< Mask for a counter in the register.
|
||||
/**
|
||||
* This is the data structure of the CLCW register.
|
||||
*/
|
||||
union clcwContent {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t status;
|
||||
uint8_t virtualChannelIdSpare;
|
||||
uint8_t flags;
|
||||
uint8_t vRValue;
|
||||
};
|
||||
};
|
||||
clcwContent content; //!< Represents the content of the register.
|
||||
public:
|
||||
/**
|
||||
* The constructor sets everything to default values.
|
||||
*/
|
||||
Clcw();
|
||||
/**
|
||||
* Nothing happens in the destructor.
|
||||
*/
|
||||
~Clcw();
|
||||
void setVirtualChannel( uint8_t setChannel );
|
||||
void setLockoutFlag( bool lockout );
|
||||
void setWaitFlag( bool waitFlag );
|
||||
void setRetransmitFlag( bool retransmitFlag );
|
||||
void setFarmBCount( uint8_t count );
|
||||
void setReceiverFrameSequenceNumber( uint8_t vR );
|
||||
void setRFAvailable( bool rfAvailable );
|
||||
void setBitLock( bool bitLock );
|
||||
uint32_t getAsWhole();
|
||||
void setWhole( uint32_t rawClcw );
|
||||
void print();
|
||||
};
|
||||
|
||||
#endif /* CLCW_H_ */
|
||||
|
@ -1,139 +1,139 @@
|
||||
#include "../datalinklayer/DataLinkLayer.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
DataLinkLayer::DataLinkLayer(uint8_t* set_frame_buffer, ClcwIF* setClcw,
|
||||
uint8_t set_start_sequence_length, uint16_t set_scid) :
|
||||
spacecraftId(set_scid), frameBuffer(set_frame_buffer), clcw(setClcw), receivedDataLength(0), currentFrame(
|
||||
NULL), startSequenceLength(set_start_sequence_length) {
|
||||
//Nothing to do except from setting the values above.
|
||||
}
|
||||
|
||||
DataLinkLayer::~DataLinkLayer() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameDelimitingAndFillRemoval() {
|
||||
if ((receivedDataLength - startSequenceLength) < FRAME_PRIMARY_HEADER_LENGTH) {
|
||||
return SHORTER_THAN_HEADER;
|
||||
}
|
||||
//Removing start sequence.
|
||||
//SHOULDDO: Not implemented here.
|
||||
while ( *frameBuffer == START_SEQUENCE_PATTERN ) {
|
||||
frameBuffer++;
|
||||
}
|
||||
TcTransferFrame frame_candidate(frameBuffer);
|
||||
this->currentFrame = frame_candidate; //should work with shallow copy.
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameValidationCheck() {
|
||||
//Check TF_version number
|
||||
if (this->currentFrame.getVersionNumber() != FRAME_VERSION_NUMBER_DEFAULT) {
|
||||
return WRONG_TF_VERSION;
|
||||
}
|
||||
//Check SpaceCraft ID
|
||||
if (this->currentFrame.getSpacecraftId() != this->spacecraftId) {
|
||||
return WRONG_SPACECRAFT_ID;
|
||||
}
|
||||
//Check other header limitations:
|
||||
if (!this->currentFrame.bypassFlagSet() && this->currentFrame.controlCommandFlagSet()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//- Spares are zero
|
||||
if (!this->currentFrame.spareIsZero()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//Compare detected frame length with the one in the header
|
||||
uint16_t length = currentFrame.getFullSize();
|
||||
if (length > receivedDataLength) {
|
||||
//Frame is too long or just right
|
||||
// error << "frameValidationCheck: Too short.";
|
||||
// currentFrame.print();
|
||||
return TOO_SHORT;
|
||||
}
|
||||
if (USE_CRC) {
|
||||
return this->frameCheckCRC();
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameCheckCRC() {
|
||||
uint16_t checkValue = CRC::crc16ccitt(this->currentFrame.getFullFrame(),
|
||||
this->currentFrame.getFullSize());
|
||||
if (checkValue == 0) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return CRC_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::allFramesReception() {
|
||||
ReturnValue_t status = this->frameDelimitingAndFillRemoval();
|
||||
if (status != RETURN_OK) {
|
||||
return status;
|
||||
}
|
||||
return this->frameValidationCheck();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::masterChannelDemultiplexing() {
|
||||
//Nothing to do at present. Ideally, there would be a map of MCID's identifying which MC to use.
|
||||
return virtualChannelDemultiplexing();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::virtualChannelDemultiplexing() {
|
||||
uint8_t vcId = currentFrame.getVirtualChannelId();
|
||||
virtualChannelIterator iter = virtualChannels.find(vcId);
|
||||
if (iter == virtualChannels.end()) {
|
||||
//Do not report because passive board will get this error all the time.
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return (iter->second)->frameAcceptanceAndReportingMechanism(¤tFrame, clcw);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::processFrame(uint16_t length) {
|
||||
receivedDataLength = length;
|
||||
ReturnValue_t status = allFramesReception();
|
||||
if (status != RETURN_OK) {
|
||||
sif::error << "DataLinkLayer::processFrame: frame reception failed. "
|
||||
"Error code: " << std::hex << status << std::dec << std::endl;
|
||||
// currentFrame.print();
|
||||
return status;
|
||||
} else {
|
||||
return masterChannelDemultiplexing();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::addVirtualChannel(uint8_t virtualChannelId,
|
||||
VirtualChannelReceptionIF* object) {
|
||||
std::pair<virtualChannelIterator, bool> returnValue = virtualChannels.insert(
|
||||
std::pair<uint8_t, VirtualChannelReceptionIF*>(virtualChannelId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
//Set Virtual Channel ID to first virtual channel instance in this DataLinkLayer instance to avoid faulty information (e.g. 0) in the VCID.
|
||||
if ( virtualChannels.begin() != virtualChannels.end() ) {
|
||||
clcw->setVirtualChannel( virtualChannels.begin()->second->getChannelId() );
|
||||
} else {
|
||||
sif::error << "DataLinkLayer::initialize: No VC assigned to this DLL instance! " << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
for (virtualChannelIterator iterator = virtualChannels.begin();
|
||||
iterator != virtualChannels.end(); iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
}
|
||||
#include "DataLinkLayer.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
DataLinkLayer::DataLinkLayer(uint8_t* set_frame_buffer, ClcwIF* setClcw,
|
||||
uint8_t set_start_sequence_length, uint16_t set_scid) :
|
||||
spacecraftId(set_scid), frameBuffer(set_frame_buffer), clcw(setClcw), receivedDataLength(0), currentFrame(
|
||||
NULL), startSequenceLength(set_start_sequence_length) {
|
||||
//Nothing to do except from setting the values above.
|
||||
}
|
||||
|
||||
DataLinkLayer::~DataLinkLayer() {
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameDelimitingAndFillRemoval() {
|
||||
if ((receivedDataLength - startSequenceLength) < FRAME_PRIMARY_HEADER_LENGTH) {
|
||||
return SHORTER_THAN_HEADER;
|
||||
}
|
||||
//Removing start sequence.
|
||||
//SHOULDDO: Not implemented here.
|
||||
while ( *frameBuffer == START_SEQUENCE_PATTERN ) {
|
||||
frameBuffer++;
|
||||
}
|
||||
TcTransferFrame frame_candidate(frameBuffer);
|
||||
this->currentFrame = frame_candidate; //should work with shallow copy.
|
||||
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameValidationCheck() {
|
||||
//Check TF_version number
|
||||
if (this->currentFrame.getVersionNumber() != FRAME_VERSION_NUMBER_DEFAULT) {
|
||||
return WRONG_TF_VERSION;
|
||||
}
|
||||
//Check SpaceCraft ID
|
||||
if (this->currentFrame.getSpacecraftId() != this->spacecraftId) {
|
||||
return WRONG_SPACECRAFT_ID;
|
||||
}
|
||||
//Check other header limitations:
|
||||
if (!this->currentFrame.bypassFlagSet() && this->currentFrame.controlCommandFlagSet()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//- Spares are zero
|
||||
if (!this->currentFrame.spareIsZero()) {
|
||||
return NO_VALID_FRAME_TYPE;
|
||||
}
|
||||
//Compare detected frame length with the one in the header
|
||||
uint16_t length = currentFrame.getFullSize();
|
||||
if (length > receivedDataLength) {
|
||||
//Frame is too long or just right
|
||||
// error << "frameValidationCheck: Too short.";
|
||||
// currentFrame.print();
|
||||
return TOO_SHORT;
|
||||
}
|
||||
if (USE_CRC) {
|
||||
return this->frameCheckCRC();
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::frameCheckCRC() {
|
||||
uint16_t checkValue = CRC::crc16ccitt(this->currentFrame.getFullFrame(),
|
||||
this->currentFrame.getFullSize());
|
||||
if (checkValue == 0) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return CRC_FAILED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::allFramesReception() {
|
||||
ReturnValue_t status = this->frameDelimitingAndFillRemoval();
|
||||
if (status != RETURN_OK) {
|
||||
return status;
|
||||
}
|
||||
return this->frameValidationCheck();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::masterChannelDemultiplexing() {
|
||||
//Nothing to do at present. Ideally, there would be a map of MCID's identifying which MC to use.
|
||||
return virtualChannelDemultiplexing();
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::virtualChannelDemultiplexing() {
|
||||
uint8_t vcId = currentFrame.getVirtualChannelId();
|
||||
virtualChannelIterator iter = virtualChannels.find(vcId);
|
||||
if (iter == virtualChannels.end()) {
|
||||
//Do not report because passive board will get this error all the time.
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return (iter->second)->frameAcceptanceAndReportingMechanism(¤tFrame, clcw);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::processFrame(uint16_t length) {
|
||||
receivedDataLength = length;
|
||||
ReturnValue_t status = allFramesReception();
|
||||
if (status != RETURN_OK) {
|
||||
sif::error << "DataLinkLayer::processFrame: frame reception failed. "
|
||||
"Error code: " << std::hex << status << std::dec << std::endl;
|
||||
// currentFrame.print();
|
||||
return status;
|
||||
} else {
|
||||
return masterChannelDemultiplexing();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::addVirtualChannel(uint8_t virtualChannelId,
|
||||
VirtualChannelReceptionIF* object) {
|
||||
std::pair<virtualChannelIterator, bool> returnValue = virtualChannels.insert(
|
||||
std::pair<uint8_t, VirtualChannelReceptionIF*>(virtualChannelId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DataLinkLayer::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
//Set Virtual Channel ID to first virtual channel instance in this DataLinkLayer instance to avoid faulty information (e.g. 0) in the VCID.
|
||||
if ( virtualChannels.begin() != virtualChannels.end() ) {
|
||||
clcw->setVirtualChannel( virtualChannels.begin()->second->getChannelId() );
|
||||
} else {
|
||||
sif::error << "DataLinkLayer::initialize: No VC assigned to this DLL instance! " << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
|
||||
for (virtualChannelIterator iterator = virtualChannels.begin();
|
||||
iterator != virtualChannels.end(); iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
|
||||
}
|
||||
|
@ -1,112 +1,112 @@
|
||||
#ifndef DATALINKLAYER_H_
|
||||
#define DATALINKLAYER_H_
|
||||
|
||||
#include "../datalinklayer/CCSDSReturnValuesIF.h"
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../datalinklayer/VirtualChannelReceptionIF.h"
|
||||
#include "../events/Event.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
class VirtualChannelReception;
|
||||
/**
|
||||
* A complete representation of the CCSDS Data Link Layer.
|
||||
* The operations of this layer are defined in the CCSDS TC Space Data Link Protocol
|
||||
* document. It is configured to handle a VC Demultiplexing function. All reception
|
||||
* steps are performed.
|
||||
*/
|
||||
class DataLinkLayer : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1;
|
||||
static const Event RF_AVAILABLE = MAKE_EVENT(0, SEVERITY::INFO); //!< A RF available signal was detected. P1: raw RFA state, P2: 0
|
||||
static const Event RF_LOST = MAKE_EVENT(1, SEVERITY::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0
|
||||
static const Event BIT_LOCK = MAKE_EVENT(2, SEVERITY::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0
|
||||
static const Event BIT_LOCK_LOST = MAKE_EVENT(3, SEVERITY::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0
|
||||
// static const Event RF_CHAIN_LOST = MAKE_EVENT(4, SEVERITY::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters.
|
||||
static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, SEVERITY::LOW); //!< The CCSDS Board could not interpret a TC
|
||||
/**
|
||||
* The Constructor sets the passed parameters and nothing else.
|
||||
* @param set_frame_buffer The buffer in which incoming frame candidates are stored.
|
||||
* @param setClcw The CLCW class to work on when returning CLCW information.
|
||||
* @param set_start_sequence_length Length of the Start sequence in front of every TC Transfer Frame.
|
||||
* @param set_scid The SCID to operate on.
|
||||
*/
|
||||
DataLinkLayer( uint8_t* set_frame_buffer, ClcwIF* setClcw, uint8_t set_start_sequence_length, uint16_t set_scid );
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
~DataLinkLayer();
|
||||
/**
|
||||
* This method tries to process a frame that is placed in #frameBuffer.
|
||||
* The procedures described in the Standard are performed.
|
||||
* @param length Length of the incoming frame candidate.
|
||||
* @return @c RETURN_OK on successful handling, otherwise the return codes of the higher methods.
|
||||
*/
|
||||
ReturnValue_t processFrame( uint16_t length );
|
||||
/**
|
||||
* Configuration method to add a new TC Virtual Channel.
|
||||
* Shall only be called during initialization. As soon as the method was called, the layer can
|
||||
* handle Frames directed to this VC.
|
||||
* @param virtualChannelId Id of the VC. Shall be smaller than 64.
|
||||
* @param object Reference to the object that handles the Frame.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addVirtualChannel( uint8_t virtualChannelId, VirtualChannelReceptionIF* object );
|
||||
/**
|
||||
* The initialization method calls the @c initialize routine of all virtual channels.
|
||||
* @return The return code of the first failed VC initialization or @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
private:
|
||||
typedef std::map<uint8_t, VirtualChannelReceptionIF*>::iterator virtualChannelIterator; //!< Typedef to simplify handling the #virtualChannels map.
|
||||
static const uint8_t FRAME_VERSION_NUMBER_DEFAULT = 0x00; //!< Constant for the default value of Frame Version Numbers.
|
||||
static const uint8_t FRAME_PRIMARY_HEADER_LENGTH = 5; //!< Length of the frame's primary header.
|
||||
static const uint8_t START_SEQUENCE_PATTERN = 0x00; //!< The start sequence pattern which might be with the frame.
|
||||
static const bool USE_CRC = true; //!< A global, so called "Managed Parameter" that identifies if incoming frames have CRC's or not.
|
||||
uint16_t spacecraftId; //!< The Space Craft Identifier (SCID) configured.
|
||||
uint8_t* frameBuffer; //!< A pointer to point to the current incoming frame.
|
||||
ClcwIF* clcw; //!< Pointer to store the CLCW to work on.
|
||||
uint16_t receivedDataLength; //!< Stores the length of the currently processed frame.
|
||||
TcTransferFrame currentFrame; //!< Stores a more convenient access to the current frame.
|
||||
uint8_t startSequenceLength; //!< Configured length of the start sequence. Maybe this must be done more variable.
|
||||
std::map<uint8_t, VirtualChannelReceptionIF*> virtualChannels; //!< Map of all virtual channels assigned.
|
||||
/**
|
||||
* Method that performs all possible frame validity checks (as specified).
|
||||
* @return Various error codes or @c RETURN_OK on success.
|
||||
*/
|
||||
ReturnValue_t frameValidationCheck();
|
||||
/**
|
||||
* First method to call.
|
||||
* Removes start sequence bytes and checks if the complete frame was received.
|
||||
* SHOULDDO: Maybe handling the start sequence must be done more variable.
|
||||
* @return @c RETURN_OK or @c TOO_SHORT.
|
||||
*/
|
||||
ReturnValue_t frameDelimitingAndFillRemoval();
|
||||
/**
|
||||
* Small helper method to check the CRC of the Frame.
|
||||
* @return @c RETURN_OK or @c CRC_FAILED.
|
||||
*/
|
||||
ReturnValue_t frameCheckCRC();
|
||||
/**
|
||||
* Method that groups the reception process of all Frames.
|
||||
* Calls #frameDelimitingAndFillRemoval and #frameValidationCheck.
|
||||
* @return The return codes of the sub calls.
|
||||
*/
|
||||
ReturnValue_t allFramesReception();
|
||||
/**
|
||||
* Dummy method for master channel demultiplexing.
|
||||
* As there's only one Master Channel here, the method calls #virtualChannelDemultiplexing.
|
||||
* @return The return codes of #virtualChannelDemultiplexing.
|
||||
*/
|
||||
ReturnValue_t masterChannelDemultiplexing();
|
||||
/**
|
||||
* Method to demultiplex the Frames to Virtual Channels (VC's).
|
||||
* Looks up the requested VC in #virtualChannels and forwards the Frame to its
|
||||
* #frameAcceptanceAndReportingMechanism method, if found.
|
||||
* @return The higher method codes or @c VC_NOT_FOUND.
|
||||
*/
|
||||
ReturnValue_t virtualChannelDemultiplexing();
|
||||
};
|
||||
|
||||
#endif /* DATALINKLAYER_H_ */
|
||||
#ifndef DATALINKLAYER_H_
|
||||
#define DATALINKLAYER_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "ClcwIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReceptionIF.h"
|
||||
#include "../events/Event.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
class VirtualChannelReception;
|
||||
/**
|
||||
* A complete representation of the CCSDS Data Link Layer.
|
||||
* The operations of this layer are defined in the CCSDS TC Space Data Link Protocol
|
||||
* document. It is configured to handle a VC Demultiplexing function. All reception
|
||||
* steps are performed.
|
||||
*/
|
||||
class DataLinkLayer : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SYSTEM_1;
|
||||
static const Event RF_AVAILABLE = MAKE_EVENT(0, SEVERITY::INFO); //!< A RF available signal was detected. P1: raw RFA state, P2: 0
|
||||
static const Event RF_LOST = MAKE_EVENT(1, SEVERITY::INFO); //!< A previously found RF available signal was lost. P1: raw RFA state, P2: 0
|
||||
static const Event BIT_LOCK = MAKE_EVENT(2, SEVERITY::INFO); //!< A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0
|
||||
static const Event BIT_LOCK_LOST = MAKE_EVENT(3, SEVERITY::INFO); //!< A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0
|
||||
// static const Event RF_CHAIN_LOST = MAKE_EVENT(4, SEVERITY::INFO); //!< The CCSDS Board detected that either bit lock or RF available or both are lost. No parameters.
|
||||
static const Event FRAME_PROCESSING_FAILED = MAKE_EVENT(5, SEVERITY::LOW); //!< The CCSDS Board could not interpret a TC
|
||||
/**
|
||||
* The Constructor sets the passed parameters and nothing else.
|
||||
* @param set_frame_buffer The buffer in which incoming frame candidates are stored.
|
||||
* @param setClcw The CLCW class to work on when returning CLCW information.
|
||||
* @param set_start_sequence_length Length of the Start sequence in front of every TC Transfer Frame.
|
||||
* @param set_scid The SCID to operate on.
|
||||
*/
|
||||
DataLinkLayer( uint8_t* set_frame_buffer, ClcwIF* setClcw, uint8_t set_start_sequence_length, uint16_t set_scid );
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
~DataLinkLayer();
|
||||
/**
|
||||
* This method tries to process a frame that is placed in #frameBuffer.
|
||||
* The procedures described in the Standard are performed.
|
||||
* @param length Length of the incoming frame candidate.
|
||||
* @return @c RETURN_OK on successful handling, otherwise the return codes of the higher methods.
|
||||
*/
|
||||
ReturnValue_t processFrame( uint16_t length );
|
||||
/**
|
||||
* Configuration method to add a new TC Virtual Channel.
|
||||
* Shall only be called during initialization. As soon as the method was called, the layer can
|
||||
* handle Frames directed to this VC.
|
||||
* @param virtualChannelId Id of the VC. Shall be smaller than 64.
|
||||
* @param object Reference to the object that handles the Frame.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addVirtualChannel( uint8_t virtualChannelId, VirtualChannelReceptionIF* object );
|
||||
/**
|
||||
* The initialization method calls the @c initialize routine of all virtual channels.
|
||||
* @return The return code of the first failed VC initialization or @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
private:
|
||||
typedef std::map<uint8_t, VirtualChannelReceptionIF*>::iterator virtualChannelIterator; //!< Typedef to simplify handling the #virtualChannels map.
|
||||
static const uint8_t FRAME_VERSION_NUMBER_DEFAULT = 0x00; //!< Constant for the default value of Frame Version Numbers.
|
||||
static const uint8_t FRAME_PRIMARY_HEADER_LENGTH = 5; //!< Length of the frame's primary header.
|
||||
static const uint8_t START_SEQUENCE_PATTERN = 0x00; //!< The start sequence pattern which might be with the frame.
|
||||
static const bool USE_CRC = true; //!< A global, so called "Managed Parameter" that identifies if incoming frames have CRC's or not.
|
||||
uint16_t spacecraftId; //!< The Space Craft Identifier (SCID) configured.
|
||||
uint8_t* frameBuffer; //!< A pointer to point to the current incoming frame.
|
||||
ClcwIF* clcw; //!< Pointer to store the CLCW to work on.
|
||||
uint16_t receivedDataLength; //!< Stores the length of the currently processed frame.
|
||||
TcTransferFrame currentFrame; //!< Stores a more convenient access to the current frame.
|
||||
uint8_t startSequenceLength; //!< Configured length of the start sequence. Maybe this must be done more variable.
|
||||
std::map<uint8_t, VirtualChannelReceptionIF*> virtualChannels; //!< Map of all virtual channels assigned.
|
||||
/**
|
||||
* Method that performs all possible frame validity checks (as specified).
|
||||
* @return Various error codes or @c RETURN_OK on success.
|
||||
*/
|
||||
ReturnValue_t frameValidationCheck();
|
||||
/**
|
||||
* First method to call.
|
||||
* Removes start sequence bytes and checks if the complete frame was received.
|
||||
* SHOULDDO: Maybe handling the start sequence must be done more variable.
|
||||
* @return @c RETURN_OK or @c TOO_SHORT.
|
||||
*/
|
||||
ReturnValue_t frameDelimitingAndFillRemoval();
|
||||
/**
|
||||
* Small helper method to check the CRC of the Frame.
|
||||
* @return @c RETURN_OK or @c CRC_FAILED.
|
||||
*/
|
||||
ReturnValue_t frameCheckCRC();
|
||||
/**
|
||||
* Method that groups the reception process of all Frames.
|
||||
* Calls #frameDelimitingAndFillRemoval and #frameValidationCheck.
|
||||
* @return The return codes of the sub calls.
|
||||
*/
|
||||
ReturnValue_t allFramesReception();
|
||||
/**
|
||||
* Dummy method for master channel demultiplexing.
|
||||
* As there's only one Master Channel here, the method calls #virtualChannelDemultiplexing.
|
||||
* @return The return codes of #virtualChannelDemultiplexing.
|
||||
*/
|
||||
ReturnValue_t masterChannelDemultiplexing();
|
||||
/**
|
||||
* Method to demultiplex the Frames to Virtual Channels (VC's).
|
||||
* Looks up the requested VC in #virtualChannels and forwards the Frame to its
|
||||
* #frameAcceptanceAndReportingMechanism method, if found.
|
||||
* @return The higher method codes or @c VC_NOT_FOUND.
|
||||
*/
|
||||
ReturnValue_t virtualChannelDemultiplexing();
|
||||
};
|
||||
|
||||
#endif /* DATALINKLAYER_H_ */
|
||||
|
@ -1,54 +1,54 @@
|
||||
/**
|
||||
* @file Farm1StateIF.h
|
||||
* @brief This file defines the Farm1StateIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEIF_H_
|
||||
#define FARM1STATEIF_H_
|
||||
|
||||
#include "../datalinklayer/CCSDSReturnValuesIF.h"
|
||||
class VirtualChannelReception;
|
||||
class TcTransferFrame;
|
||||
class ClcwIF;
|
||||
|
||||
/**
|
||||
* This is the interface for states of the FARM-1 state machine.
|
||||
* Classes implementing this interface can be used as FARM-1 states. This is a simple implementation
|
||||
* of the state pattern.
|
||||
*/
|
||||
class Farm1StateIF : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
/**
|
||||
* A method that shall handle an incoming frame as AD Frame.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Unlock frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Set VR frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) = 0;
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~Farm1StateIF() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FARM1STATEIF_H_ */
|
||||
/**
|
||||
* @file Farm1StateIF.h
|
||||
* @brief This file defines the Farm1StateIF class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEIF_H_
|
||||
#define FARM1STATEIF_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
class VirtualChannelReception;
|
||||
class TcTransferFrame;
|
||||
class ClcwIF;
|
||||
|
||||
/**
|
||||
* This is the interface for states of the FARM-1 state machine.
|
||||
* Classes implementing this interface can be used as FARM-1 states. This is a simple implementation
|
||||
* of the state pattern.
|
||||
*/
|
||||
class Farm1StateIF : public CCSDSReturnValuesIF {
|
||||
public:
|
||||
/**
|
||||
* A method that shall handle an incoming frame as AD Frame.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Unlock frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* This method shall handle frames that have been successfully identified as BC Set VR frames.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return If forwarding to a MAP Channel is required, the return value shall be #FRAME_OK.
|
||||
* Otherwise, an appropriate return value or error code shall be generated.
|
||||
*/
|
||||
virtual ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) = 0;
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~Farm1StateIF() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FARM1STATEIF_H_ */
|
||||
|
@ -1,35 +1,35 @@
|
||||
/**
|
||||
* @file Farm1StateLockout.cpp
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
#include "../datalinklayer/Farm1StateLockout.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../datalinklayer/VirtualChannelReception.h"
|
||||
Farm1StateLockout::Farm1StateLockout(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
return FARM_IN_LOCKOUT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setLockoutFlag( false );
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCSetVrCommand(ClcwIF* clcw,
|
||||
uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
/**
|
||||
* @file Farm1StateLockout.cpp
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateLockout.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
Farm1StateLockout::Farm1StateLockout(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
return FARM_IN_LOCKOUT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setLockoutFlag( false );
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateLockout::handleBCSetVrCommand(ClcwIF* clcw,
|
||||
uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
|
@ -1,59 +1,59 @@
|
||||
/**
|
||||
* @file Farm1StateLockout.h
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATELOCKOUT_H_
|
||||
#define FARM1STATELOCKOUT_H_
|
||||
|
||||
#include "../datalinklayer/Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Lockout" State.
|
||||
* The Lockout state is reached if the received Transfer Frame Sequence Number is completely wrong
|
||||
* (i.e. within the Lockout Window). No AD Frames are forwarded. To leave the State, a BC Unlock
|
||||
* command is required.
|
||||
*/
|
||||
class Farm1StateLockout : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateLockout( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* All AD Frames are rejected with FARM_IN_LOCKOUT
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return FARM_IN_LOCKOUT
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* The V(r) value is not set in Lockout State, even though the Command itself is accepted.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATELOCKOUT_H_ */
|
||||
/**
|
||||
* @file Farm1StateLockout.h
|
||||
* @brief This file defines the Farm1StateLockout class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATELOCKOUT_H_
|
||||
#define FARM1STATELOCKOUT_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Lockout" State.
|
||||
* The Lockout state is reached if the received Transfer Frame Sequence Number is completely wrong
|
||||
* (i.e. within the Lockout Window). No AD Frames are forwarded. To leave the State, a BC Unlock
|
||||
* command is required.
|
||||
*/
|
||||
class Farm1StateLockout : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateLockout( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* All AD Frames are rejected with FARM_IN_LOCKOUT
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return FARM_IN_LOCKOUT
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* The V(r) value is not set in Lockout State, even though the Command itself is accepted.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATELOCKOUT_H_ */
|
||||
|
@ -1,49 +1,49 @@
|
||||
/**
|
||||
* @file Farm1StateOpen.cpp
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
#include "../datalinklayer/Farm1StateOpen.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../datalinklayer/VirtualChannelReception.h"
|
||||
|
||||
Farm1StateOpen::Farm1StateOpen(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if (diff == 0 ) {
|
||||
myVC->vR++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return RETURN_OK;
|
||||
} else if (diff < myVC->positiveWindow && diff > 0 ) {
|
||||
clcw->setRetransmitFlag(true);
|
||||
return NS_POSITIVE_W;
|
||||
} else if (diff < 0 && diff >= -myVC->negativeWindow) {
|
||||
return NS_NEGATIVE_W;
|
||||
} else {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
return NS_LOCKOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCUnlockCommand( ClcwIF* clcw ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
/**
|
||||
* @file Farm1StateOpen.cpp
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateOpen.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
|
||||
Farm1StateOpen::Farm1StateOpen(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if (diff == 0 ) {
|
||||
myVC->vR++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return RETURN_OK;
|
||||
} else if (diff < myVC->positiveWindow && diff > 0 ) {
|
||||
clcw->setRetransmitFlag(true);
|
||||
return NS_POSITIVE_W;
|
||||
} else if (diff < 0 && diff >= -myVC->negativeWindow) {
|
||||
return NS_NEGATIVE_W;
|
||||
} else {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
return NS_LOCKOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCUnlockCommand( ClcwIF* clcw ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateOpen::handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr ) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
/**
|
||||
* @file Farm1StateOpen.h
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEOPEN_H_
|
||||
#define FARM1STATEOPEN_H_
|
||||
|
||||
#include "../datalinklayer/Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Open" State.
|
||||
* The Open state is the state of normal operation. It handles all types of frames,
|
||||
* including AD Frames. If a wrong Frame Sequence Number is detected in an AD Frame, the
|
||||
* State reacts as specified.
|
||||
*/
|
||||
class Farm1StateOpen : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateOpen( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* Method to check the validity of AD Frames.
|
||||
* It checks the Frame Sequence Number and reacts as specified in the standard. The state may
|
||||
* change to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If the Sequence Number is ok, it returns #RETURN_OK. Otherwise either #NS_POSITIVE_W,
|
||||
* #NS_NEGATIVE_W or NS_LOCKOUT is returned.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEOPEN_H_ */
|
||||
/**
|
||||
* @file Farm1StateOpen.h
|
||||
* @brief This file defines the Farm1StateOpen class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEOPEN_H_
|
||||
#define FARM1STATEOPEN_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Open" State.
|
||||
* The Open state is the state of normal operation. It handles all types of frames,
|
||||
* including AD Frames. If a wrong Frame Sequence Number is detected in an AD Frame, the
|
||||
* State reacts as specified.
|
||||
*/
|
||||
class Farm1StateOpen : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateOpen( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* Method to check the validity of AD Frames.
|
||||
* It checks the Frame Sequence Number and reacts as specified in the standard. The state may
|
||||
* change to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return If the Sequence Number is ok, it returns #RETURN_OK. Otherwise either #NS_POSITIVE_W,
|
||||
* #NS_NEGATIVE_W or NS_LOCKOUT is returned.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State does not change.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEOPEN_H_ */
|
||||
|
@ -1,43 +1,43 @@
|
||||
/**
|
||||
* @file Farm1StateWait.cpp
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
#include "../datalinklayer/Farm1StateWait.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../datalinklayer/VirtualChannelReception.h"
|
||||
|
||||
Farm1StateWait::Farm1StateWait(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if ( diff < -myVC->negativeWindow || diff >= myVC->positiveWindow ) {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
}
|
||||
return FARM_IN_WAIT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCSetVrCommand(ClcwIF* clcw, uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setWaitFlag( false );
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
/**
|
||||
* @file Farm1StateWait.cpp
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "Farm1StateWait.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
|
||||
Farm1StateWait::Farm1StateWait(VirtualChannelReception* setMyVC) : myVC(setMyVC) {
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleADFrame(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
|
||||
int8_t diff = frame->getSequenceNumber() - myVC->vR;
|
||||
if ( diff < -myVC->negativeWindow || diff >= myVC->positiveWindow ) {
|
||||
clcw->setLockoutFlag(true);
|
||||
myVC->currentState = &(myVC->lockoutState);
|
||||
}
|
||||
return FARM_IN_WAIT;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCUnlockCommand(ClcwIF* clcw) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setRetransmitFlag(false);
|
||||
clcw->setWaitFlag( false );
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_UNLOCK_COMMAND;
|
||||
}
|
||||
|
||||
ReturnValue_t Farm1StateWait::handleBCSetVrCommand(ClcwIF* clcw, uint8_t vr) {
|
||||
myVC->farmBCounter++;
|
||||
clcw->setWaitFlag( false );
|
||||
clcw->setRetransmitFlag(false);
|
||||
myVC->vR = vr;
|
||||
myVC->currentState = &(myVC->openState);
|
||||
return BC_IS_SET_VR_COMMAND;
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
/**
|
||||
* @file Farm1StateWait.h
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEWAIT_H_
|
||||
#define FARM1STATEWAIT_H_
|
||||
|
||||
#include "../datalinklayer/Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Wait" State.
|
||||
* The Wait state is reached if higher level procedures inform the FARM-1 Machine to wait
|
||||
* for a certain period. Currently, it is not in use.
|
||||
*/
|
||||
class Farm1StateWait : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateWait( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* AD Frames are always discarded.
|
||||
* If the frame number is in the lockout window, the state changes to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return Always returns FARM_IN_WAIT.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEWAIT_H_ */
|
||||
/**
|
||||
* @file Farm1StateWait.h
|
||||
* @brief This file defines the Farm1StateWait class.
|
||||
* @date 24.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FARM1STATEWAIT_H_
|
||||
#define FARM1STATEWAIT_H_
|
||||
|
||||
#include "Farm1StateIF.h"
|
||||
|
||||
/**
|
||||
* This class represents the FARM-1 "Wait" State.
|
||||
* The Wait state is reached if higher level procedures inform the FARM-1 Machine to wait
|
||||
* for a certain period. Currently, it is not in use.
|
||||
*/
|
||||
class Farm1StateWait : public Farm1StateIF {
|
||||
private:
|
||||
/**
|
||||
* This is a reference to the "owner" class the State works on.
|
||||
*/
|
||||
VirtualChannelReception* myVC;
|
||||
public:
|
||||
/**
|
||||
* The default constructor if the State.
|
||||
* Sets the "owner" of the State.
|
||||
* @param setMyVC The "owner" class.
|
||||
*/
|
||||
Farm1StateWait( VirtualChannelReception* setMyVC );
|
||||
/**
|
||||
* AD Frames are always discarded.
|
||||
* If the frame number is in the lockout window, the state changes to Farm1StateLockout.
|
||||
* @param frame The frame to handle.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return Always returns FARM_IN_WAIT.
|
||||
*/
|
||||
ReturnValue_t handleADFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* State changes to Farm1StateOpen.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_UNLOCK_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCUnlockCommand( ClcwIF* clcw );
|
||||
/**
|
||||
* These commands are handled as specified.
|
||||
* @param clcw Any changes to the CLCW shall be done with the help of this interface.
|
||||
* @param vr The V(r) value found in the frame.
|
||||
* @return As the frame needs no forwarding to a MAP Channel, #BC_IS_SET_VR_COMMAND
|
||||
* is returned.
|
||||
*/
|
||||
ReturnValue_t handleBCSetVrCommand( ClcwIF* clcw, uint8_t vr );
|
||||
};
|
||||
|
||||
|
||||
#endif /* FARM1STATEWAIT_H_ */
|
||||
|
@ -1,154 +1,154 @@
|
||||
/**
|
||||
* @file MapPacketExtraction.cpp
|
||||
* @brief This file defines the MapPacketExtraction class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../datalinklayer/MapPacketExtraction.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../tmtcservices/AcceptsTelecommandsIF.h"
|
||||
#include "../tmtcservices/TmTcMessage.h"
|
||||
#include <string.h>
|
||||
|
||||
MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0),
|
||||
bufferPosition(packetBuffer), packetDestination(setPacketDestination),
|
||||
packetStore(nullptr), tcQueueId(MessageQueueMessageIF::NO_QUEUE) {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::extractPackets(TcTransferFrame* frame) {
|
||||
uint8_t segmentationFlag = frame->getSequenceFlags();
|
||||
ReturnValue_t status = TOO_SHORT_MAP_EXTRACTION;
|
||||
switch (segmentationFlag) {
|
||||
case NO_SEGMENTATION:
|
||||
status = unpackBlockingPackets(frame);
|
||||
break;
|
||||
case FIRST_PORTION:
|
||||
packetLength = frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(packetBuffer, frame->getDataField(), packetLength);
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
break;
|
||||
case CONTINUING_PORTION:
|
||||
case LAST_PORTION:
|
||||
if (lastSegmentationFlag == FIRST_PORTION
|
||||
|| lastSegmentationFlag == CONTINUING_PORTION) {
|
||||
packetLength += frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(bufferPosition, frame->getDataField(),
|
||||
frame->getDataLength());
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
if (segmentationFlag == LAST_PORTION) {
|
||||
status = sendCompletePacket(packetBuffer, packetLength);
|
||||
clearBuffers();
|
||||
}
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segment! Last flag: "
|
||||
<< (int) lastSegmentationFlag << std::endl;
|
||||
clearBuffers();
|
||||
status = ILLEGAL_SEGMENTATION_FLAG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segmentationFlag: "
|
||||
<< (int) segmentationFlag << std::endl;
|
||||
clearBuffers();
|
||||
status = DATA_CORRUPTED;
|
||||
break;
|
||||
}
|
||||
lastSegmentationFlag = segmentationFlag;
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::unpackBlockingPackets(
|
||||
TcTransferFrame* frame) {
|
||||
ReturnValue_t status = TOO_SHORT_BLOCKED_PACKET;
|
||||
uint32_t totalLength = frame->getDataLength();
|
||||
if (totalLength > MAX_PACKET_SIZE)
|
||||
return CONTENT_TOO_LARGE;
|
||||
uint8_t* position = frame->getDataField();
|
||||
while ((totalLength > SpacePacketBase::MINIMUM_SIZE)) {
|
||||
SpacePacketBase packet(position);
|
||||
uint32_t packetSize = packet.getFullSize();
|
||||
if (packetSize <= totalLength) {
|
||||
status = sendCompletePacket(packet.getWholeData(),
|
||||
packet.getFullSize());
|
||||
totalLength -= packet.getFullSize();
|
||||
position += packet.getFullSize();
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
status = DATA_CORRUPTED;
|
||||
totalLength = 0;
|
||||
}
|
||||
}
|
||||
if (totalLength > 0) {
|
||||
status = RESIDUAL_DATA;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::sendCompletePacket(uint8_t* data,
|
||||
uint32_t size) {
|
||||
store_address_t store_id;
|
||||
ReturnValue_t status = this->packetStore->addData(&store_id, data, size);
|
||||
if (status == RETURN_OK) {
|
||||
TmTcMessage message(store_id);
|
||||
status = MessageQueueSenderIF::sendMessage(tcQueueId,&message);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void MapPacketExtraction::clearBuffers() {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
bufferPosition = packetBuffer;
|
||||
packetLength = 0;
|
||||
lastSegmentationFlag = NO_SEGMENTATION;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::initialize() {
|
||||
packetStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
AcceptsTelecommandsIF* distributor = objectManager->get<
|
||||
AcceptsTelecommandsIF>(packetDestination);
|
||||
if ((packetStore != NULL) && (distributor != NULL)) {
|
||||
tcQueueId = distributor->getRequestQueue();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void MapPacketExtraction::printPacketBuffer(void) {
|
||||
sif::debug << "DLL: packet_buffer contains: " << std::endl;
|
||||
for (uint32_t i = 0; i < this->packetLength; ++i) {
|
||||
sif::debug << "packet_buffer[" << std::dec << i << "]: 0x" << std::hex
|
||||
<< (uint16_t) this->packetBuffer[i] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MapPacketExtraction::getMapId() const {
|
||||
return mapId;
|
||||
}
|
||||
/**
|
||||
* @file MapPacketExtraction.cpp
|
||||
* @brief This file defines the MapPacketExtraction class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "MapPacketExtraction.h"
|
||||
#include "../ipc/QueueFactory.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../storagemanager/StorageManagerIF.h"
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../tmtcservices/AcceptsTelecommandsIF.h"
|
||||
#include "../tmtcservices/TmTcMessage.h"
|
||||
#include <string.h>
|
||||
|
||||
MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0), bufferPosition(
|
||||
packetBuffer), packetDestination(setPacketDestination), packetStore(
|
||||
NULL), tcQueueId(MessageQueueSenderIF::NO_QUEUE) {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::extractPackets(TcTransferFrame* frame) {
|
||||
uint8_t segmentationFlag = frame->getSequenceFlags();
|
||||
ReturnValue_t status = TOO_SHORT_MAP_EXTRACTION;
|
||||
switch (segmentationFlag) {
|
||||
case NO_SEGMENTATION:
|
||||
status = unpackBlockingPackets(frame);
|
||||
break;
|
||||
case FIRST_PORTION:
|
||||
packetLength = frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(packetBuffer, frame->getDataField(), packetLength);
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
break;
|
||||
case CONTINUING_PORTION:
|
||||
case LAST_PORTION:
|
||||
if (lastSegmentationFlag == FIRST_PORTION
|
||||
|| lastSegmentationFlag == CONTINUING_PORTION) {
|
||||
packetLength += frame->getDataLength();
|
||||
if (packetLength <= MAX_PACKET_SIZE) {
|
||||
memcpy(bufferPosition, frame->getDataField(),
|
||||
frame->getDataLength());
|
||||
bufferPosition = &packetBuffer[packetLength];
|
||||
if (segmentationFlag == LAST_PORTION) {
|
||||
status = sendCompletePacket(packetBuffer, packetLength);
|
||||
clearBuffers();
|
||||
}
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Packet too large! Size: "
|
||||
<< packetLength << std::endl;
|
||||
clearBuffers();
|
||||
status = CONTENT_TOO_LARGE;
|
||||
}
|
||||
} else {
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segment! Last flag: "
|
||||
<< (int) lastSegmentationFlag << std::endl;
|
||||
clearBuffers();
|
||||
status = ILLEGAL_SEGMENTATION_FLAG;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sif::error
|
||||
<< "MapPacketExtraction::extractPackets. Illegal segmentationFlag: "
|
||||
<< (int) segmentationFlag << std::endl;
|
||||
clearBuffers();
|
||||
status = DATA_CORRUPTED;
|
||||
break;
|
||||
}
|
||||
lastSegmentationFlag = segmentationFlag;
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::unpackBlockingPackets(
|
||||
TcTransferFrame* frame) {
|
||||
ReturnValue_t status = TOO_SHORT_BLOCKED_PACKET;
|
||||
uint32_t totalLength = frame->getDataLength();
|
||||
if (totalLength > MAX_PACKET_SIZE)
|
||||
return CONTENT_TOO_LARGE;
|
||||
uint8_t* position = frame->getDataField();
|
||||
while ((totalLength > SpacePacketBase::MINIMUM_SIZE)) {
|
||||
SpacePacketBase packet(position);
|
||||
uint32_t packetSize = packet.getFullSize();
|
||||
if (packetSize <= totalLength) {
|
||||
status = sendCompletePacket(packet.getWholeData(),
|
||||
packet.getFullSize());
|
||||
totalLength -= packet.getFullSize();
|
||||
position += packet.getFullSize();
|
||||
status = RETURN_OK;
|
||||
} else {
|
||||
status = DATA_CORRUPTED;
|
||||
totalLength = 0;
|
||||
}
|
||||
}
|
||||
if (totalLength > 0) {
|
||||
status = RESIDUAL_DATA;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::sendCompletePacket(uint8_t* data,
|
||||
uint32_t size) {
|
||||
store_address_t store_id;
|
||||
ReturnValue_t status = this->packetStore->addData(&store_id, data, size);
|
||||
if (status == RETURN_OK) {
|
||||
TmTcMessage message(store_id);
|
||||
status = MessageQueueSenderIF::sendMessage(tcQueueId,&message);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void MapPacketExtraction::clearBuffers() {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
bufferPosition = packetBuffer;
|
||||
packetLength = 0;
|
||||
lastSegmentationFlag = NO_SEGMENTATION;
|
||||
}
|
||||
|
||||
ReturnValue_t MapPacketExtraction::initialize() {
|
||||
packetStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
AcceptsTelecommandsIF* distributor = objectManager->get<
|
||||
AcceptsTelecommandsIF>(packetDestination);
|
||||
if ((packetStore != NULL) && (distributor != NULL)) {
|
||||
tcQueueId = distributor->getRequestQueue();
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void MapPacketExtraction::printPacketBuffer(void) {
|
||||
sif::debug << "DLL: packet_buffer contains: " << std::endl;
|
||||
for (uint32_t i = 0; i < this->packetLength; ++i) {
|
||||
sif::debug << "packet_buffer[" << std::dec << i << "]: 0x" << std::hex
|
||||
<< (uint16_t) this->packetBuffer[i] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t MapPacketExtraction::getMapId() const {
|
||||
return mapId;
|
||||
}
|
||||
|
@ -1,78 +1,78 @@
|
||||
/**
|
||||
* @file MapPacketExtraction.h
|
||||
* @brief This file defines the MapPacketExtraction class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef MAPPACKETEXTRACTION_H_
|
||||
#define MAPPACKETEXTRACTION_H_
|
||||
|
||||
#include "../datalinklayer/MapPacketExtractionIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class StorageManagerIF;
|
||||
|
||||
/**
|
||||
* Implementation of a MAP Packet Extraction class.
|
||||
* The class implements the full MAP Packet Extraction functionality as described in the CCSDS
|
||||
* TC Space Data Link Protocol. It internally stores incomplete segmented packets until they are
|
||||
* fully received. All found packets are forwarded to a single distribution entity.
|
||||
*/
|
||||
class MapPacketExtraction: public MapPacketExtractionIF {
|
||||
private:
|
||||
static const uint32_t MAX_PACKET_SIZE = 4096;
|
||||
uint8_t lastSegmentationFlag; //!< The segmentation flag of the last received frame.
|
||||
uint8_t mapId; //!< MAP ID of this MAP Channel.
|
||||
uint32_t packetLength; //!< Complete length of the current Space Packet.
|
||||
uint8_t* bufferPosition; //!< Position to write to in the internal Packet buffer.
|
||||
uint8_t packetBuffer[MAX_PACKET_SIZE]; //!< The internal Space Packet Buffer.
|
||||
object_id_t packetDestination;
|
||||
StorageManagerIF* packetStore; //!< Pointer to the store where full TC packets are stored.
|
||||
MessageQueueId_t tcQueueId; //!< QueueId to send found packets to the distributor.
|
||||
/**
|
||||
* Debug method to print the packet Buffer's content.
|
||||
*/
|
||||
void printPacketBuffer();
|
||||
/**
|
||||
* Method that is called if the segmentation flag is @c NO_SEGMENTATION.
|
||||
* The method extracts one or more packets within the frame and forwards them to the OBSW.
|
||||
* @param frame The TC Transfer Frame to work on.
|
||||
* @return @c RETURN_OK if all Packets were extracted. If something is entirely wrong,
|
||||
* @c DATA_CORRUPTED is returned, if some bytes are left over @c RESIDUAL_DATA.
|
||||
*/
|
||||
ReturnValue_t unpackBlockingPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* Helper method to forward a complete packet to the OBSW.
|
||||
* @param data Pointer to the data, either directly from the frame or from the packetBuffer.
|
||||
* @param size Complete total size of the packet.
|
||||
* @return Return Code of the Packet Store or the Message Queue.
|
||||
*/
|
||||
ReturnValue_t sendCompletePacket( uint8_t* data, uint32_t size );
|
||||
/**
|
||||
* Helper method to reset the internal buffer.
|
||||
*/
|
||||
void clearBuffers();
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Members are set to default values.
|
||||
* @param setMapId The MAP ID of the instance.
|
||||
*/
|
||||
MapPacketExtraction( uint8_t setMapId, object_id_t setPacketDestination );
|
||||
ReturnValue_t extractPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* The #packetStore and the default destination of #tcQueue are initialized here.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The MAP ID of this instance.
|
||||
*/
|
||||
uint8_t getMapId() const;
|
||||
};
|
||||
|
||||
#endif /* MAPPACKETEXTRACTION_H_ */
|
||||
/**
|
||||
* @file MapPacketExtraction.h
|
||||
* @brief This file defines the MapPacketExtraction class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef MAPPACKETEXTRACTION_H_
|
||||
#define MAPPACKETEXTRACTION_H_
|
||||
|
||||
#include "MapPacketExtractionIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
class StorageManagerIF;
|
||||
|
||||
/**
|
||||
* Implementation of a MAP Packet Extraction class.
|
||||
* The class implements the full MAP Packet Extraction functionality as described in the CCSDS
|
||||
* TC Space Data Link Protocol. It internally stores incomplete segmented packets until they are
|
||||
* fully received. All found packets are forwarded to a single distribution entity.
|
||||
*/
|
||||
class MapPacketExtraction: public MapPacketExtractionIF {
|
||||
private:
|
||||
static const uint32_t MAX_PACKET_SIZE = 4096;
|
||||
uint8_t lastSegmentationFlag; //!< The segmentation flag of the last received frame.
|
||||
uint8_t mapId; //!< MAP ID of this MAP Channel.
|
||||
uint32_t packetLength; //!< Complete length of the current Space Packet.
|
||||
uint8_t* bufferPosition; //!< Position to write to in the internal Packet buffer.
|
||||
uint8_t packetBuffer[MAX_PACKET_SIZE]; //!< The internal Space Packet Buffer.
|
||||
object_id_t packetDestination;
|
||||
StorageManagerIF* packetStore; //!< Pointer to the store where full TC packets are stored.
|
||||
MessageQueueId_t tcQueueId; //!< QueueId to send found packets to the distributor.
|
||||
/**
|
||||
* Debug method to print the packet Buffer's content.
|
||||
*/
|
||||
void printPacketBuffer();
|
||||
/**
|
||||
* Method that is called if the segmentation flag is @c NO_SEGMENTATION.
|
||||
* The method extracts one or more packets within the frame and forwards them to the OBSW.
|
||||
* @param frame The TC Transfer Frame to work on.
|
||||
* @return @c RETURN_OK if all Packets were extracted. If something is entirely wrong,
|
||||
* @c DATA_CORRUPTED is returned, if some bytes are left over @c RESIDUAL_DATA.
|
||||
*/
|
||||
ReturnValue_t unpackBlockingPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* Helper method to forward a complete packet to the OBSW.
|
||||
* @param data Pointer to the data, either directly from the frame or from the packetBuffer.
|
||||
* @param size Complete total size of the packet.
|
||||
* @return Return Code of the Packet Store or the Message Queue.
|
||||
*/
|
||||
ReturnValue_t sendCompletePacket( uint8_t* data, uint32_t size );
|
||||
/**
|
||||
* Helper method to reset the internal buffer.
|
||||
*/
|
||||
void clearBuffers();
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Members are set to default values.
|
||||
* @param setMapId The MAP ID of the instance.
|
||||
*/
|
||||
MapPacketExtraction( uint8_t setMapId, object_id_t setPacketDestination );
|
||||
ReturnValue_t extractPackets(TcTransferFrame* frame);
|
||||
/**
|
||||
* The #packetStore and the default destination of #tcQueue are initialized here.
|
||||
* @return @c RETURN_OK on success, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter.
|
||||
* @return The MAP ID of this instance.
|
||||
*/
|
||||
uint8_t getMapId() const;
|
||||
};
|
||||
|
||||
#endif /* MAPPACKETEXTRACTION_H_ */
|
||||
|
@ -1,47 +1,47 @@
|
||||
/**
|
||||
* @file MapPacketExtractionIF.h
|
||||
* @brief This file defines the MapPacketExtractionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef MAPPACKETEXTRACTIONIF_H_
|
||||
#define MAPPACKETEXTRACTIONIF_H_
|
||||
|
||||
#include "../datalinklayer/CCSDSReturnValuesIF.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is the interface for MAP Packet Extraction classes.
|
||||
* All classes implementing this interface shall be able to extract blocked or segmented Space
|
||||
* Packets on a certain MAP channel. This is done in accordance with the CCSDS TC Space Data Link
|
||||
* Protocol.
|
||||
*/
|
||||
class MapPacketExtractionIF : public CCSDSReturnValuesIF {
|
||||
protected:
|
||||
static const uint8_t FIRST_PORTION = 0b01; //!< Identification of the first part of a segmented Packet.
|
||||
static const uint8_t CONTINUING_PORTION = 0b00; //!< Identification of a continuing part of segmented Packets.
|
||||
static const uint8_t LAST_PORTION = 0b10; //!< The last portion of a segmented Packet.
|
||||
static const uint8_t NO_SEGMENTATION = 0b11; //!< A Frame without segmentation but maybe with blocking.
|
||||
public:
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~MapPacketExtractionIF() {
|
||||
}
|
||||
/**
|
||||
* Method to call to handle a single Transfer Frame.
|
||||
* The method tries to extract Packets from the frame as stated in the Standard.
|
||||
* @param frame
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t extractPackets( TcTransferFrame* frame ) = 0;
|
||||
/**
|
||||
* Any post-instantiation initialization shall be done in this method.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MAPPACKETEXTRACTIONIF_H_ */
|
||||
/**
|
||||
* @file MapPacketExtractionIF.h
|
||||
* @brief This file defines the MapPacketExtractionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef MAPPACKETEXTRACTIONIF_H_
|
||||
#define MAPPACKETEXTRACTIONIF_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is the interface for MAP Packet Extraction classes.
|
||||
* All classes implementing this interface shall be able to extract blocked or segmented Space
|
||||
* Packets on a certain MAP channel. This is done in accordance with the CCSDS TC Space Data Link
|
||||
* Protocol.
|
||||
*/
|
||||
class MapPacketExtractionIF : public CCSDSReturnValuesIF {
|
||||
protected:
|
||||
static const uint8_t FIRST_PORTION = 0b01; //!< Identification of the first part of a segmented Packet.
|
||||
static const uint8_t CONTINUING_PORTION = 0b00; //!< Identification of a continuing part of segmented Packets.
|
||||
static const uint8_t LAST_PORTION = 0b10; //!< The last portion of a segmented Packet.
|
||||
static const uint8_t NO_SEGMENTATION = 0b11; //!< A Frame without segmentation but maybe with blocking.
|
||||
public:
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~MapPacketExtractionIF() {
|
||||
}
|
||||
/**
|
||||
* Method to call to handle a single Transfer Frame.
|
||||
* The method tries to extract Packets from the frame as stated in the Standard.
|
||||
* @param frame
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t extractPackets( TcTransferFrame* frame ) = 0;
|
||||
/**
|
||||
* Any post-instantiation initialization shall be done in this method.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MAPPACKETEXTRACTIONIF_H_ */
|
||||
|
@ -1,102 +1,102 @@
|
||||
/**
|
||||
* @file TcTransferFrame.cpp
|
||||
* @brief This file defines the TcTransferFrame class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
TcTransferFrame::TcTransferFrame() {
|
||||
frame = NULL;
|
||||
}
|
||||
|
||||
TcTransferFrame::TcTransferFrame(uint8_t* setData) {
|
||||
this->frame = (tc_transfer_frame*)setData;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVersionNumber() {
|
||||
return (this->frame->header.flagsAndScid & 0b11000000) >> 6;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::bypassFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00100000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::controlCommandFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00010000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::spareIsZero() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00001100) == 0 );
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getSpacecraftId() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00000011) << 8 ) + this->frame->header.spacecraftId_l;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVirtualChannelId() {
|
||||
return (this->frame->header.vcidAndLength_h & 0b11111100) >> 2;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFrameLength() {
|
||||
return ( (this->frame->header.vcidAndLength_h & 0b00000011) << 8 ) + this->frame->header.length_l;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() -1 - FRAME_CRC_SIZE + 1; // -1 for the segment header.
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceNumber() {
|
||||
return this->frame->header.sequenceNumber;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceFlags() {
|
||||
return (this->frame->dataField & 0b11000000)>>6;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getMAPId() {
|
||||
return this->frame->dataField & 0b00111111;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getDataField() {
|
||||
return &(this->frame->dataField) + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullFrame() {
|
||||
return (uint8_t*)this->frame;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullSize() {
|
||||
return this->getFrameLength() + 1;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getHeaderSize() {
|
||||
return sizeof(frame->header);
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() - FRAME_CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullDataField() {
|
||||
return &frame->dataField;
|
||||
}
|
||||
|
||||
void TcTransferFrame::print() {
|
||||
sif::debug << "Raw Frame: " << std::hex << std::endl;
|
||||
for (uint16_t count = 0; count < this->getFullSize(); count++ ) {
|
||||
sif::debug << (uint16_t)this->getFullFrame()[count] << " ";
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
// debug << "Frame Header:" << std::endl;
|
||||
// debug << "Version Number: " << std::hex << (uint16_t)this->current_frame.getVersionNumber() << std::endl;
|
||||
// debug << "Bypass Flag set?| Ctrl Cmd Flag set?: " << (uint16_t)this->current_frame.bypassFlagSet() << " | " << (uint16_t)this->current_frame.controlCommandFlagSet() << std::endl;
|
||||
// debug << "SCID : " << this->current_frame.getSpacecraftId() << std::endl;
|
||||
// debug << "VCID : " << (uint16_t)this->current_frame.getVirtualChannelId() << std::endl;
|
||||
// debug << "Frame length: " << std::dec << this->current_frame.getFrameLength() << std::endl;
|
||||
// debug << "Sequence Number: " << (uint16_t)this->current_frame.getSequenceNumber() << std::endl;
|
||||
}
|
||||
/**
|
||||
* @file TcTransferFrame.cpp
|
||||
* @brief This file defines the TcTransferFrame class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "TcTransferFrame.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
TcTransferFrame::TcTransferFrame() {
|
||||
frame = NULL;
|
||||
}
|
||||
|
||||
TcTransferFrame::TcTransferFrame(uint8_t* setData) {
|
||||
this->frame = (tc_transfer_frame*)setData;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVersionNumber() {
|
||||
return (this->frame->header.flagsAndScid & 0b11000000) >> 6;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::bypassFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00100000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::controlCommandFlagSet() {
|
||||
return (this->frame->header.flagsAndScid & 0b00010000) != 0;
|
||||
}
|
||||
|
||||
bool TcTransferFrame::spareIsZero() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00001100) == 0 );
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getSpacecraftId() {
|
||||
return ( (this->frame->header.flagsAndScid & 0b00000011) << 8 ) + this->frame->header.spacecraftId_l;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getVirtualChannelId() {
|
||||
return (this->frame->header.vcidAndLength_h & 0b11111100) >> 2;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFrameLength() {
|
||||
return ( (this->frame->header.vcidAndLength_h & 0b00000011) << 8 ) + this->frame->header.length_l;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() -1 - FRAME_CRC_SIZE + 1; // -1 for the segment header.
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceNumber() {
|
||||
return this->frame->header.sequenceNumber;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getSequenceFlags() {
|
||||
return (this->frame->dataField & 0b11000000)>>6;
|
||||
}
|
||||
|
||||
uint8_t TcTransferFrame::getMAPId() {
|
||||
return this->frame->dataField & 0b00111111;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getDataField() {
|
||||
return &(this->frame->dataField) + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullFrame() {
|
||||
return (uint8_t*)this->frame;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullSize() {
|
||||
return this->getFrameLength() + 1;
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getHeaderSize() {
|
||||
return sizeof(frame->header);
|
||||
}
|
||||
|
||||
uint16_t TcTransferFrame::getFullDataLength() {
|
||||
return this->getFrameLength() - this->getHeaderSize() - FRAME_CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint8_t* TcTransferFrame::getFullDataField() {
|
||||
return &frame->dataField;
|
||||
}
|
||||
|
||||
void TcTransferFrame::print() {
|
||||
sif::debug << "Raw Frame: " << std::hex << std::endl;
|
||||
for (uint16_t count = 0; count < this->getFullSize(); count++ ) {
|
||||
sif::debug << (uint16_t)this->getFullFrame()[count] << " ";
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
// debug << "Frame Header:" << std::endl;
|
||||
// debug << "Version Number: " << std::hex << (uint16_t)this->current_frame.getVersionNumber() << std::endl;
|
||||
// debug << "Bypass Flag set?| Ctrl Cmd Flag set?: " << (uint16_t)this->current_frame.bypassFlagSet() << " | " << (uint16_t)this->current_frame.controlCommandFlagSet() << std::endl;
|
||||
// debug << "SCID : " << this->current_frame.getSpacecraftId() << std::endl;
|
||||
// debug << "VCID : " << (uint16_t)this->current_frame.getVirtualChannelId() << std::endl;
|
||||
// debug << "Frame length: " << std::dec << this->current_frame.getFrameLength() << std::endl;
|
||||
// debug << "Sequence Number: " << (uint16_t)this->current_frame.getSequenceNumber() << std::endl;
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
/**
|
||||
* @file TcTransferFrameLocal.cpp
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../datalinklayer/TcTransferFrameLocal.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <string.h>
|
||||
|
||||
TcTransferFrameLocal::TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid,
|
||||
uint8_t vcId, uint8_t sequenceNumber, uint8_t setSegmentHeader, uint8_t* data, uint16_t dataSize, uint16_t forceCrc) {
|
||||
this->frame = (tc_transfer_frame*)&localData;
|
||||
frame->header.flagsAndScid = (bypass << 5) + (controlCommand << 4) + ((scid & 0x0300) >> 8);
|
||||
frame->header.spacecraftId_l = (scid & 0x00FF);
|
||||
frame->header.vcidAndLength_h = (vcId & 0b00111111) << 2;
|
||||
frame->header.length_l = sizeof(TcTransferFramePrimaryHeader) -1;
|
||||
frame->header.sequenceNumber = sequenceNumber;
|
||||
frame->dataField = setSegmentHeader;
|
||||
if (data != NULL) {
|
||||
if (bypass && controlCommand) {
|
||||
memcpy(&(frame->dataField), data, dataSize);
|
||||
uint16_t totalSize = sizeof(TcTransferFramePrimaryHeader) + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (totalSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (totalSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else if (dataSize <= 1016) {
|
||||
memcpy(&(frame->dataField) +1, data, dataSize);
|
||||
uint16_t dataCrcSize = sizeof(TcTransferFramePrimaryHeader) + 1 + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (dataCrcSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (dataCrcSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else {
|
||||
sif::debug << "TcTransferFrameLocal: dataSize too large: " << dataSize << std::endl;
|
||||
}
|
||||
} else {
|
||||
//No data in frame
|
||||
}
|
||||
if (forceCrc != 0 ) {
|
||||
localData.data[getFullSize()-2] = (forceCrc & 0xFF00) >> 8;
|
||||
localData.data[getFullSize()-1] = (forceCrc & 0x00FF);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @file TcTransferFrameLocal.cpp
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "TcTransferFrameLocal.h"
|
||||
#include "../globalfunctions/CRC.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <string.h>
|
||||
|
||||
TcTransferFrameLocal::TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid,
|
||||
uint8_t vcId, uint8_t sequenceNumber, uint8_t setSegmentHeader, uint8_t* data, uint16_t dataSize, uint16_t forceCrc) {
|
||||
this->frame = (tc_transfer_frame*)&localData;
|
||||
frame->header.flagsAndScid = (bypass << 5) + (controlCommand << 4) + ((scid & 0x0300) >> 8);
|
||||
frame->header.spacecraftId_l = (scid & 0x00FF);
|
||||
frame->header.vcidAndLength_h = (vcId & 0b00111111) << 2;
|
||||
frame->header.length_l = sizeof(TcTransferFramePrimaryHeader) -1;
|
||||
frame->header.sequenceNumber = sequenceNumber;
|
||||
frame->dataField = setSegmentHeader;
|
||||
if (data != NULL) {
|
||||
if (bypass && controlCommand) {
|
||||
memcpy(&(frame->dataField), data, dataSize);
|
||||
uint16_t totalSize = sizeof(TcTransferFramePrimaryHeader) + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (totalSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (totalSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else if (dataSize <= 1016) {
|
||||
memcpy(&(frame->dataField) +1, data, dataSize);
|
||||
uint16_t dataCrcSize = sizeof(TcTransferFramePrimaryHeader) + 1 + dataSize + FRAME_CRC_SIZE -1;
|
||||
frame->header.vcidAndLength_h |= (dataCrcSize & 0x0300) >> 8;
|
||||
frame->header.length_l = (dataCrcSize & 0x00FF);
|
||||
uint16_t crc = CRC::crc16ccitt(getFullFrame(), getFullSize() -2);
|
||||
this->getFullFrame()[getFullSize()-2] = (crc & 0xFF00) >> 8;
|
||||
this->getFullFrame()[getFullSize()-1] = (crc & 0x00FF);
|
||||
} else {
|
||||
sif::debug << "TcTransferFrameLocal: dataSize too large: " << dataSize << std::endl;
|
||||
}
|
||||
} else {
|
||||
//No data in frame
|
||||
}
|
||||
if (forceCrc != 0 ) {
|
||||
localData.data[getFullSize()-2] = (forceCrc & 0xFF00) >> 8;
|
||||
localData.data[getFullSize()-1] = (forceCrc & 0x00FF);
|
||||
}
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
/**
|
||||
* @file TcTransferFrameLocal.h
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef TCTRANSFERFRAMELOCAL_H_
|
||||
#define TCTRANSFERFRAMELOCAL_H_
|
||||
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is a helper class to locally create TC Transfer Frames.
|
||||
* This is mainly required for testing purposes and therefore not very sophisticated.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class TcTransferFrameLocal : public TcTransferFrame {
|
||||
private:
|
||||
/**
|
||||
* A stuct to locally store the complete data.
|
||||
*/
|
||||
struct frameData {
|
||||
TcTransferFramePrimaryHeader header; //!< The primary header.
|
||||
uint8_t data[1019]; //!< The data field.
|
||||
};
|
||||
public:
|
||||
frameData localData; //!< The local data in the Frame.
|
||||
/**
|
||||
* The default Constructor.
|
||||
* All parameters in the Header are passed.
|
||||
* If a BC Frame is detected no segment header is created.
|
||||
* Otherwise (AD and BD), the Segment Header is set.
|
||||
* @param bypass The bypass flag.
|
||||
* @param controlCommand The Control Command flag.
|
||||
* @param scid The SCID.
|
||||
* @param vcId The VCID.
|
||||
* @param sequenceNumber The Frame Sequence Number N(s)
|
||||
* @param setSegmentHeader A value for the Segment Header.
|
||||
* @param data Data to put into the Frame Data Field.
|
||||
* @param dataSize Size of the Data.
|
||||
* @param forceCrc if != 0, the value is used as CRC.
|
||||
*/
|
||||
TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid, uint8_t vcId, uint8_t sequenceNumber,
|
||||
uint8_t setSegmentHeader = 0xC0, uint8_t* data = NULL, uint16_t dataSize = 0, uint16_t forceCrc = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCTRANSFERFRAMELOCAL_H_ */
|
||||
/**
|
||||
* @file TcTransferFrameLocal.h
|
||||
* @brief This file defines the TcTransferFrameLocal class.
|
||||
* @date 27.04.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef TCTRANSFERFRAMELOCAL_H_
|
||||
#define TCTRANSFERFRAMELOCAL_H_
|
||||
|
||||
#include "TcTransferFrame.h"
|
||||
|
||||
/**
|
||||
* This is a helper class to locally create TC Transfer Frames.
|
||||
* This is mainly required for testing purposes and therefore not very sophisticated.
|
||||
* @ingroup ccsds_handling
|
||||
*/
|
||||
class TcTransferFrameLocal : public TcTransferFrame {
|
||||
private:
|
||||
/**
|
||||
* A stuct to locally store the complete data.
|
||||
*/
|
||||
struct frameData {
|
||||
TcTransferFramePrimaryHeader header; //!< The primary header.
|
||||
uint8_t data[1019]; //!< The data field.
|
||||
};
|
||||
public:
|
||||
frameData localData; //!< The local data in the Frame.
|
||||
/**
|
||||
* The default Constructor.
|
||||
* All parameters in the Header are passed.
|
||||
* If a BC Frame is detected no segment header is created.
|
||||
* Otherwise (AD and BD), the Segment Header is set.
|
||||
* @param bypass The bypass flag.
|
||||
* @param controlCommand The Control Command flag.
|
||||
* @param scid The SCID.
|
||||
* @param vcId The VCID.
|
||||
* @param sequenceNumber The Frame Sequence Number N(s)
|
||||
* @param setSegmentHeader A value for the Segment Header.
|
||||
* @param data Data to put into the Frame Data Field.
|
||||
* @param dataSize Size of the Data.
|
||||
* @param forceCrc if != 0, the value is used as CRC.
|
||||
*/
|
||||
TcTransferFrameLocal(bool bypass, bool controlCommand, uint16_t scid, uint8_t vcId, uint8_t sequenceNumber,
|
||||
uint8_t setSegmentHeader = 0xC0, uint8_t* data = NULL, uint16_t dataSize = 0, uint16_t forceCrc = 0);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCTRANSFERFRAMELOCAL_H_ */
|
||||
|
@ -1,121 +1,121 @@
|
||||
/**
|
||||
* @file VirtualChannelReception.cpp
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../datalinklayer/BCFrame.h"
|
||||
#include "../datalinklayer/VirtualChannelReception.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
VirtualChannelReception::VirtualChannelReception(uint8_t setChannelId,
|
||||
uint8_t setSlidingWindowWidth) :
|
||||
channelId(setChannelId), slidingWindowWidth(setSlidingWindowWidth), positiveWindow(
|
||||
setSlidingWindowWidth / 2), negativeWindow(setSlidingWindowWidth / 2), currentState(
|
||||
&openState), openState(this), waitState(this), lockoutState(this), vR(0), farmBCounter(
|
||||
0) {
|
||||
internalClcw.setVirtualChannel(channelId);
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::mapDemultiplexing(TcTransferFrame* frame) {
|
||||
uint8_t mapId = frame->getMAPId();
|
||||
mapChannelIterator iter = mapChannels.find(mapId);
|
||||
if (iter == mapChannels.end()) {
|
||||
// error << "VirtualChannelReception::mapDemultiplexing on VC " << std::hex << (int) channelId
|
||||
// << ": MapChannel " << (int) mapId << std::dec << " not found." << std::endl;
|
||||
return VC_NOT_FOUND;
|
||||
} else {
|
||||
return (iter->second)->extractPackets(frame);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::doFARM(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
uint8_t bypass = frame->bypassFlagSet();
|
||||
uint8_t controlCommand = frame->controlCommandFlagSet();
|
||||
uint8_t typeValue = (bypass << 1) + controlCommand;
|
||||
switch (typeValue) {
|
||||
case AD_FRAME:
|
||||
return currentState->handleADFrame(frame, clcw);
|
||||
case BD_FRAME:
|
||||
return handleBDFrame(frame, clcw);
|
||||
case BC_FRAME:
|
||||
return handleBCFrame(frame, clcw);
|
||||
default:
|
||||
return ILLEGAL_FLAG_COMBINATION;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::frameAcceptanceAndReportingMechanism(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = doFARM(frame, &internalClcw);
|
||||
internalClcw.setReceiverFrameSequenceNumber(vR);
|
||||
internalClcw.setFarmBCount(farmBCounter);
|
||||
clcw->setWhole(internalClcw.getAsWhole());
|
||||
switch (result) {
|
||||
case RETURN_OK:
|
||||
return mapDemultiplexing(frame);
|
||||
case BC_IS_SET_VR_COMMAND:
|
||||
case BC_IS_UNLOCK_COMMAND:
|
||||
//Need to catch these codes to avoid error reporting later.
|
||||
return RETURN_OK;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::addMapChannel(uint8_t mapId, MapPacketExtractionIF* object) {
|
||||
std::pair<mapChannelIterator, bool> returnValue = mapChannels.insert(
|
||||
std::pair<uint8_t, MapPacketExtractionIF*>(mapId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBDFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
farmBCounter++;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBCFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
BcFrame content;
|
||||
ReturnValue_t returnValue = content.initialize(frame->getFullDataField(),
|
||||
frame->getFullDataLength());
|
||||
if (returnValue == BC_IS_UNLOCK_COMMAND) {
|
||||
returnValue = currentState->handleBCUnlockCommand(clcw);
|
||||
} else if (returnValue == BC_IS_SET_VR_COMMAND) {
|
||||
returnValue = currentState->handleBCSetVrCommand(clcw, content.vR);
|
||||
} else {
|
||||
//Do nothing
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
uint8_t VirtualChannelReception::getChannelId() const {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
if ((slidingWindowWidth > 254) || (slidingWindowWidth % 2 != 0)) {
|
||||
sif::error << "VirtualChannelReception::initialize: Illegal sliding window width: "
|
||||
<< (int) slidingWindowWidth << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
for (mapChannelIterator iterator = mapChannels.begin(); iterator != mapChannels.end();
|
||||
iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void VirtualChannelReception::setToWaitState() {
|
||||
internalClcw.setWaitFlag(true);
|
||||
this->currentState = &waitState;
|
||||
}
|
||||
/**
|
||||
* @file VirtualChannelReception.cpp
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 26.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "BCFrame.h"
|
||||
#include "VirtualChannelReception.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
VirtualChannelReception::VirtualChannelReception(uint8_t setChannelId,
|
||||
uint8_t setSlidingWindowWidth) :
|
||||
channelId(setChannelId), slidingWindowWidth(setSlidingWindowWidth), positiveWindow(
|
||||
setSlidingWindowWidth / 2), negativeWindow(setSlidingWindowWidth / 2), currentState(
|
||||
&openState), openState(this), waitState(this), lockoutState(this), vR(0), farmBCounter(
|
||||
0) {
|
||||
internalClcw.setVirtualChannel(channelId);
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::mapDemultiplexing(TcTransferFrame* frame) {
|
||||
uint8_t mapId = frame->getMAPId();
|
||||
mapChannelIterator iter = mapChannels.find(mapId);
|
||||
if (iter == mapChannels.end()) {
|
||||
// error << "VirtualChannelReception::mapDemultiplexing on VC " << std::hex << (int) channelId
|
||||
// << ": MapChannel " << (int) mapId << std::dec << " not found." << std::endl;
|
||||
return VC_NOT_FOUND;
|
||||
} else {
|
||||
return (iter->second)->extractPackets(frame);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::doFARM(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
uint8_t bypass = frame->bypassFlagSet();
|
||||
uint8_t controlCommand = frame->controlCommandFlagSet();
|
||||
uint8_t typeValue = (bypass << 1) + controlCommand;
|
||||
switch (typeValue) {
|
||||
case AD_FRAME:
|
||||
return currentState->handleADFrame(frame, clcw);
|
||||
case BD_FRAME:
|
||||
return handleBDFrame(frame, clcw);
|
||||
case BC_FRAME:
|
||||
return handleBCFrame(frame, clcw);
|
||||
default:
|
||||
return ILLEGAL_FLAG_COMBINATION;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::frameAcceptanceAndReportingMechanism(TcTransferFrame* frame,
|
||||
ClcwIF* clcw) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
result = doFARM(frame, &internalClcw);
|
||||
internalClcw.setReceiverFrameSequenceNumber(vR);
|
||||
internalClcw.setFarmBCount(farmBCounter);
|
||||
clcw->setWhole(internalClcw.getAsWhole());
|
||||
switch (result) {
|
||||
case RETURN_OK:
|
||||
return mapDemultiplexing(frame);
|
||||
case BC_IS_SET_VR_COMMAND:
|
||||
case BC_IS_UNLOCK_COMMAND:
|
||||
//Need to catch these codes to avoid error reporting later.
|
||||
return RETURN_OK;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::addMapChannel(uint8_t mapId, MapPacketExtractionIF* object) {
|
||||
std::pair<mapChannelIterator, bool> returnValue = mapChannels.insert(
|
||||
std::pair<uint8_t, MapPacketExtractionIF*>(mapId, object));
|
||||
if (returnValue.second == true) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBDFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
farmBCounter++;
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::handleBCFrame(TcTransferFrame* frame, ClcwIF* clcw) {
|
||||
BcFrame content;
|
||||
ReturnValue_t returnValue = content.initialize(frame->getFullDataField(),
|
||||
frame->getFullDataLength());
|
||||
if (returnValue == BC_IS_UNLOCK_COMMAND) {
|
||||
returnValue = currentState->handleBCUnlockCommand(clcw);
|
||||
} else if (returnValue == BC_IS_SET_VR_COMMAND) {
|
||||
returnValue = currentState->handleBCSetVrCommand(clcw, content.vR);
|
||||
} else {
|
||||
//Do nothing
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
uint8_t VirtualChannelReception::getChannelId() const {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannelReception::initialize() {
|
||||
ReturnValue_t returnValue = RETURN_FAILED;
|
||||
if ((slidingWindowWidth > 254) || (slidingWindowWidth % 2 != 0)) {
|
||||
sif::error << "VirtualChannelReception::initialize: Illegal sliding window width: "
|
||||
<< (int) slidingWindowWidth << std::endl;
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
for (mapChannelIterator iterator = mapChannels.begin(); iterator != mapChannels.end();
|
||||
iterator++) {
|
||||
returnValue = iterator->second->initialize();
|
||||
if (returnValue != RETURN_OK)
|
||||
break;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
void VirtualChannelReception::setToWaitState() {
|
||||
internalClcw.setWaitFlag(true);
|
||||
this->currentState = &waitState;
|
||||
}
|
||||
|
@ -1,114 +1,114 @@
|
||||
/**
|
||||
* @file VirtualChannelReception.h
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTION_H_
|
||||
#define VIRTUALCHANNELRECEPTION_H_
|
||||
|
||||
#include "../datalinklayer/CCSDSReturnValuesIF.h"
|
||||
#include "../datalinklayer/Clcw.h"
|
||||
#include "../datalinklayer/Farm1StateIF.h"
|
||||
#include "../datalinklayer/Farm1StateLockout.h"
|
||||
#include "../datalinklayer/Farm1StateOpen.h"
|
||||
#include "../datalinklayer/Farm1StateWait.h"
|
||||
#include "../datalinklayer/MapPacketExtractionIF.h"
|
||||
#include "../datalinklayer/VirtualChannelReceptionIF.h"
|
||||
#include <map>
|
||||
/**
|
||||
* Implementation of a TC Virtual Channel.
|
||||
* This is a full implementation of a virtual channel as specified in the CCSDS TC Space Data Link
|
||||
* Protocol. It is designed to operate within an instance of the @c DataLinkLayer class.
|
||||
* Features:
|
||||
* - any (6bit) Virtual Channel ID is assignable.
|
||||
* - Supports an arbitrary number of MAP Channels (with a map).
|
||||
* - Has a complete FARM-1 Machine built-in.
|
||||
*
|
||||
* The FARM-1 state machine uses the State Pattern.
|
||||
*/
|
||||
class VirtualChannelReception : public VirtualChannelReceptionIF, public CCSDSReturnValuesIF {
|
||||
friend class Farm1StateOpen;
|
||||
friend class Farm1StateWait;
|
||||
friend class Farm1StateLockout;
|
||||
private:
|
||||
uint8_t channelId; //!< Stores the VCID that was assigned on construction.
|
||||
uint8_t slidingWindowWidth; //!< A constant to set the FARM-1 sliding window width.
|
||||
uint8_t positiveWindow; //!< The positive window for the FARM-1 machine.
|
||||
uint8_t negativeWindow; //!< The negative window for the FARM-1 machine.
|
||||
protected:
|
||||
Farm1StateIF* currentState; //!< The current state. To change, one of the other states must be assigned to this pointer.
|
||||
Farm1StateOpen openState; //!< Instance of the FARM-1 State "Open".
|
||||
Farm1StateWait waitState; //!< Instance of the FARM-1 State "Wait".
|
||||
Farm1StateLockout lockoutState; //!< Instance of the FARM-1 State "Lockout".
|
||||
Clcw internalClcw; //!< A CLCW class to internally set the values before writing them back to the TTC System.
|
||||
uint8_t vR; //!< The Receiver Frame Sequence Number V(R) as it shall be maintained for every Virtual Channel.
|
||||
uint8_t farmBCounter; //!< The FARM-B COunter as it shall be maintained for every Virtual Channel.
|
||||
typedef std::map<uint8_t, MapPacketExtractionIF*>::iterator mapChannelIterator; //!< Typedef to simplify handling of the mapChannels map.
|
||||
std::map<uint8_t, MapPacketExtractionIF*> mapChannels; //!< A map that maintains all map Channels. Channels must be configured on initialization. MAy be omitted in a simplified version.
|
||||
/**
|
||||
* This method handles demultiplexing to different map channels.
|
||||
* It parses the entries of #mapChannels and forwards the Frame to a found MAP Channel.
|
||||
* @param frame The frame to forward.
|
||||
* @return #VC_NOT_FOUND or the return value of the map channel extraction.
|
||||
*/
|
||||
ReturnValue_t mapDemultiplexing( TcTransferFrame* frame );
|
||||
/**
|
||||
* A sub-method that actually does the FARM-1 handling for different Frame types.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The return code of higher methods or @c ILLEGAL_FLAG_COMBINATION.
|
||||
*/
|
||||
ReturnValue_t doFARM(TcTransferFrame* frame, ClcwIF* clcw);
|
||||
/**
|
||||
* Handles incoming BD Frames.
|
||||
* Handling these Frames is independent of the State, so no subcall to #currentState is
|
||||
* required.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return Always returns @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t handleBDFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Handles incoming BC Frames.
|
||||
* The type of the BC Frame is detected and checked first, then methods of #currentState are called.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The failure code of BC Frame interpretation or the return code of higher methods.
|
||||
*/
|
||||
ReturnValue_t handleBCFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Only sets the channelId of the channel. Setting the Sliding Window width is possible as well.
|
||||
* @param setChannelId Virtual Channel Identifier (VCID) of the channel.
|
||||
*/
|
||||
VirtualChannelReception( uint8_t setChannelId, uint8_t setSlidingWindowWidth );
|
||||
ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Helper method to simplify adding a mapChannel during construction.
|
||||
* @param mapId The mapId of the object to add.
|
||||
* @param object Pointer to the MapPacketExtraction object itself.
|
||||
* @return @c RETURN_OK if the channel was successfully inserted, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addMapChannel( uint8_t mapId, MapPacketExtractionIF* object );
|
||||
/**
|
||||
* The initialization routine checks the set #slidingWindowWidth and initializes all MAP
|
||||
* channels.
|
||||
* @return @c RETURN_OK on successful initialization, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
uint8_t getChannelId() const;
|
||||
/**
|
||||
* Small method to set the state to Farm1StateWait.
|
||||
*/
|
||||
void setToWaitState();
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTION_H_ */
|
||||
/**
|
||||
* @file VirtualChannelReception.h
|
||||
* @brief This file defines the VirtualChannelReception class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTION_H_
|
||||
#define VIRTUALCHANNELRECEPTION_H_
|
||||
|
||||
#include "CCSDSReturnValuesIF.h"
|
||||
#include "Clcw.h"
|
||||
#include "Farm1StateIF.h"
|
||||
#include "Farm1StateLockout.h"
|
||||
#include "Farm1StateOpen.h"
|
||||
#include "Farm1StateWait.h"
|
||||
#include "MapPacketExtractionIF.h"
|
||||
#include "VirtualChannelReceptionIF.h"
|
||||
#include <map>
|
||||
/**
|
||||
* Implementation of a TC Virtual Channel.
|
||||
* This is a full implementation of a virtual channel as specified in the CCSDS TC Space Data Link
|
||||
* Protocol. It is designed to operate within an instance of the @c DataLinkLayer class.
|
||||
* Features:
|
||||
* - any (6bit) Virtual Channel ID is assignable.
|
||||
* - Supports an arbitrary number of MAP Channels (with a map).
|
||||
* - Has a complete FARM-1 Machine built-in.
|
||||
*
|
||||
* The FARM-1 state machine uses the State Pattern.
|
||||
*/
|
||||
class VirtualChannelReception : public VirtualChannelReceptionIF, public CCSDSReturnValuesIF {
|
||||
friend class Farm1StateOpen;
|
||||
friend class Farm1StateWait;
|
||||
friend class Farm1StateLockout;
|
||||
private:
|
||||
uint8_t channelId; //!< Stores the VCID that was assigned on construction.
|
||||
uint8_t slidingWindowWidth; //!< A constant to set the FARM-1 sliding window width.
|
||||
uint8_t positiveWindow; //!< The positive window for the FARM-1 machine.
|
||||
uint8_t negativeWindow; //!< The negative window for the FARM-1 machine.
|
||||
protected:
|
||||
Farm1StateIF* currentState; //!< The current state. To change, one of the other states must be assigned to this pointer.
|
||||
Farm1StateOpen openState; //!< Instance of the FARM-1 State "Open".
|
||||
Farm1StateWait waitState; //!< Instance of the FARM-1 State "Wait".
|
||||
Farm1StateLockout lockoutState; //!< Instance of the FARM-1 State "Lockout".
|
||||
Clcw internalClcw; //!< A CLCW class to internally set the values before writing them back to the TTC System.
|
||||
uint8_t vR; //!< The Receiver Frame Sequence Number V(R) as it shall be maintained for every Virtual Channel.
|
||||
uint8_t farmBCounter; //!< The FARM-B COunter as it shall be maintained for every Virtual Channel.
|
||||
typedef std::map<uint8_t, MapPacketExtractionIF*>::iterator mapChannelIterator; //!< Typedef to simplify handling of the mapChannels map.
|
||||
std::map<uint8_t, MapPacketExtractionIF*> mapChannels; //!< A map that maintains all map Channels. Channels must be configured on initialization. MAy be omitted in a simplified version.
|
||||
/**
|
||||
* This method handles demultiplexing to different map channels.
|
||||
* It parses the entries of #mapChannels and forwards the Frame to a found MAP Channel.
|
||||
* @param frame The frame to forward.
|
||||
* @return #VC_NOT_FOUND or the return value of the map channel extraction.
|
||||
*/
|
||||
ReturnValue_t mapDemultiplexing( TcTransferFrame* frame );
|
||||
/**
|
||||
* A sub-method that actually does the FARM-1 handling for different Frame types.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The return code of higher methods or @c ILLEGAL_FLAG_COMBINATION.
|
||||
*/
|
||||
ReturnValue_t doFARM(TcTransferFrame* frame, ClcwIF* clcw);
|
||||
/**
|
||||
* Handles incoming BD Frames.
|
||||
* Handling these Frames is independent of the State, so no subcall to #currentState is
|
||||
* required.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return Always returns @c RETURN_OK.
|
||||
*/
|
||||
ReturnValue_t handleBDFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Handles incoming BC Frames.
|
||||
* The type of the BC Frame is detected and checked first, then methods of #currentState are called.
|
||||
* @param frame The Tc Transfer Frame to handle.
|
||||
* @param clcw Any changes on the CLCW shall be done with this method.
|
||||
* @return The failure code of BC Frame interpretation or the return code of higher methods.
|
||||
*/
|
||||
ReturnValue_t handleBCFrame( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
public:
|
||||
/**
|
||||
* Default constructor.
|
||||
* Only sets the channelId of the channel. Setting the Sliding Window width is possible as well.
|
||||
* @param setChannelId Virtual Channel Identifier (VCID) of the channel.
|
||||
*/
|
||||
VirtualChannelReception( uint8_t setChannelId, uint8_t setSlidingWindowWidth );
|
||||
ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw );
|
||||
/**
|
||||
* Helper method to simplify adding a mapChannel during construction.
|
||||
* @param mapId The mapId of the object to add.
|
||||
* @param object Pointer to the MapPacketExtraction object itself.
|
||||
* @return @c RETURN_OK if the channel was successfully inserted, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t addMapChannel( uint8_t mapId, MapPacketExtractionIF* object );
|
||||
/**
|
||||
* The initialization routine checks the set #slidingWindowWidth and initializes all MAP
|
||||
* channels.
|
||||
* @return @c RETURN_OK on successful initialization, @c RETURN_FAILED otherwise.
|
||||
*/
|
||||
ReturnValue_t initialize();
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
uint8_t getChannelId() const;
|
||||
/**
|
||||
* Small method to set the state to Farm1StateWait.
|
||||
*/
|
||||
void setToWaitState();
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTION_H_ */
|
||||
|
@ -1,57 +1,57 @@
|
||||
/**
|
||||
* @file VirtualChannelReceptionIF.h
|
||||
* @brief This file defines the VirtualChannelReceptionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTIONIF_H_
|
||||
#define VIRTUALCHANNELRECEPTIONIF_H_
|
||||
|
||||
#include "../datalinklayer/ClcwIF.h"
|
||||
#include "../datalinklayer/TcTransferFrame.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* This is the interface for Virtual Channel reception classes.
|
||||
* It represents a single TC Virtual Channel that operates on one IO
|
||||
*/
|
||||
class VirtualChannelReceptionIF {
|
||||
public:
|
||||
/**
|
||||
* Enum including all valid types of frames.
|
||||
* The type is made up by two flags, so 0b1111 is definitely illegal.
|
||||
*/
|
||||
enum frameType {
|
||||
AD_FRAME = 0b00,
|
||||
BC_FRAME = 0b11,
|
||||
BD_FRAME = 0b10,
|
||||
ILLEGAL_FRAME = 0b1111
|
||||
};
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~VirtualChannelReceptionIF() {
|
||||
}
|
||||
/**
|
||||
* This method shall accept frames and do all FARM-1 stuff.
|
||||
* Handling the Frame includes forwarding to higher-level procedures.
|
||||
* @param frame The Tc Transfer Frame that was received and checked.
|
||||
* @param clcw Any changes to the CLCW value are forwarded by using this parameter.
|
||||
* @return The return Value shall indicate successful processing with @c RETURN_OK.
|
||||
*/
|
||||
virtual ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* If any other System Objects are required for operation they shall be initialized here.
|
||||
* @return @c RETURN_OK for successful initialization.
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
virtual uint8_t getChannelId() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTIONIF_H_ */
|
||||
/**
|
||||
* @file VirtualChannelReceptionIF.h
|
||||
* @brief This file defines the VirtualChannelReceptionIF class.
|
||||
* @date 25.03.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef VIRTUALCHANNELRECEPTIONIF_H_
|
||||
#define VIRTUALCHANNELRECEPTIONIF_H_
|
||||
|
||||
#include "ClcwIF.h"
|
||||
#include "TcTransferFrame.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
/**
|
||||
* This is the interface for Virtual Channel reception classes.
|
||||
* It represents a single TC Virtual Channel that operates on one IO
|
||||
*/
|
||||
class VirtualChannelReceptionIF {
|
||||
public:
|
||||
/**
|
||||
* Enum including all valid types of frames.
|
||||
* The type is made up by two flags, so 0b1111 is definitely illegal.
|
||||
*/
|
||||
enum frameType {
|
||||
AD_FRAME = 0b00,
|
||||
BC_FRAME = 0b11,
|
||||
BD_FRAME = 0b10,
|
||||
ILLEGAL_FRAME = 0b1111
|
||||
};
|
||||
/**
|
||||
* Empty virtual destructor.
|
||||
*/
|
||||
virtual ~VirtualChannelReceptionIF() {
|
||||
}
|
||||
/**
|
||||
* This method shall accept frames and do all FARM-1 stuff.
|
||||
* Handling the Frame includes forwarding to higher-level procedures.
|
||||
* @param frame The Tc Transfer Frame that was received and checked.
|
||||
* @param clcw Any changes to the CLCW value are forwarded by using this parameter.
|
||||
* @return The return Value shall indicate successful processing with @c RETURN_OK.
|
||||
*/
|
||||
virtual ReturnValue_t frameAcceptanceAndReportingMechanism( TcTransferFrame* frame, ClcwIF* clcw ) = 0;
|
||||
/**
|
||||
* If any other System Objects are required for operation they shall be initialized here.
|
||||
* @return @c RETURN_OK for successful initialization.
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
/**
|
||||
* Getter for the VCID.
|
||||
* @return The #channelId.
|
||||
*/
|
||||
virtual uint8_t getChannelId() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* VIRTUALCHANNELRECEPTIONIF_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user