FSFW Update #21

Merged
meierj merged 26 commits from mueller/unittest-fixes into eive/develop 2021-09-29 15:45:40 +02:00
3 changed files with 70 additions and 63 deletions
Showing only changes of commit c7ce568a30 - Show all commits

View File

@ -324,26 +324,23 @@ ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) {
size_t startIdx = 0; size_t startIdx = 0;
size_t foundSize = 0; size_t foundSize = 0;
size_t readLen = 0; size_t readLen = 0;
while(readLen <= readAmount) { while(readLen < readAmount) {
result = spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount, result = spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount,
startIdx, foundSize, readLen); startIdx, foundSize, readLen);
if(result == SpacePacketParser::NO_PACKET_FOUND) { switch(result) {
ringBuffer.deleteData(foundSize); case(SpacePacketParser::NO_PACKET_FOUND):
lastRingBufferSize = ringBuffer.getAvailableReadData(); case(SpacePacketParser::SPLIT_PACKET): {
break;
} }
else if(result == SpacePacketParser::SPLIT_PACKET) { case(HasReturnvaluesIF::RETURN_OK): {
// might be half of a packet? Skip it for now
ringBuffer.deleteData(foundSize);
lastRingBufferSize = ringBuffer.getAvailableReadData();
}
else if(result == HasReturnvaluesIF::RETURN_OK) {
result = handleTcReception(receptionBuffer.data() + startIdx, foundSize); result = handleTcReception(receptionBuffer.data() + startIdx, foundSize);
ringBuffer.deleteData(foundSize);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
status = result; status = result;
} }
lastRingBufferSize = ringBuffer.getAvailableReadData();
} }
}
ringBuffer.deleteData(foundSize);
lastRingBufferSize = ringBuffer.getAvailableReadData();
std::memset(receptionBuffer.data() + startIdx, 0, foundSize); std::memset(receptionBuffer.data() + startIdx, 0, foundSize);
} }
return status; return status;

View File

@ -127,7 +127,7 @@ private:
SpacePacketParser* spacePacketParser = nullptr; SpacePacketParser* spacePacketParser = nullptr;
uint8_t lastRingBufferSize = 0; uint8_t lastRingBufferSize = 0;
void handleServerOperation(socket_t& connSocket); virtual void handleServerOperation(socket_t& connSocket);
ReturnValue_t handleTcReception(uint8_t* spacePacket, size_t packetSize); ReturnValue_t handleTcReception(uint8_t* spacePacket, size_t packetSize);
ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent); ReturnValue_t handleTmSending(socket_t connSocket, bool& tmSent);
ReturnValue_t handleTcRingBufferData(size_t availableReadData); ReturnValue_t handleTcRingBufferData(size_t availableReadData);

View File

@ -15,57 +15,67 @@
*/ */
class SpacePacket: public SpacePacketBase { class SpacePacket: public SpacePacketBase {
public: public:
static const uint16_t PACKET_MAX_SIZE = 1024; static const uint16_t PACKET_MAX_SIZE = 1024;
/** /**
* The constructor initializes the packet and sets all header information * The constructor initializes the packet and sets all header information
* according to the passed parameters. * according to the passed parameters.
* @param packetDataLength Sets the packet data length field and therefore specifies * @param packetDataLength Sets the packet data length field and therefore specifies
* the size of the packet. * the size of the packet.
* @param isTelecommand Sets the packet type field to either TC (true) or TM (false). * @param isTelecommand Sets the packet type field to either TC (true) or TM (false).
* @param apid Sets the packet's APID field. The default value describes an idle packet. * @param apid Sets the packet's APID field. The default value describes an idle packet.
* @param sequenceCount ets the packet's Source Sequence Count field. * @param sequenceCount ets the packet's Source Sequence Count field.
*/ */
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false, SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0); uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
/** /**
* The class's default destructor. * The class's default destructor.
*/ */
virtual ~SpacePacket(); virtual ~SpacePacket();
/**
* With this call, the complete data content (including the CCSDS Primary static constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) {
* Header) is overwritten with the byte stream given. uint16_t tcPacketId = (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff);
* @param p_data Pointer to data to overwrite the content with return tcPacketId;
* @param packet_size Size of the data }
* @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE. static constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) {
* @li \c false else. uint16_t tmPacketId = (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff);
*/ return tmPacketId;
bool addWholeData(const uint8_t* p_data, uint32_t packet_size); }
/**
* With this call, the complete data content (including the CCSDS Primary
* Header) is overwritten with the byte stream given.
* @param p_data Pointer to data to overwrite the content with
* @param packet_size Size of the data
* @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE.
* @li \c false else.
*/
bool addWholeData(const uint8_t* p_data, uint32_t packet_size);
protected: protected:
/** /**
* This structure defines the data structure of a Space Packet as local data. * This structure defines the data structure of a Space Packet as local data.
* There's a buffer which corresponds to the Space Packet Data Field with a * There's a buffer which corresponds to the Space Packet Data Field with a
* maximum size of \c PACKET_MAX_SIZE. * maximum size of \c PACKET_MAX_SIZE.
*/ */
struct PacketStructured { struct PacketStructured {
CCSDSPrimaryHeader header; CCSDSPrimaryHeader header;
uint8_t buffer[PACKET_MAX_SIZE]; uint8_t buffer[PACKET_MAX_SIZE];
}; };
/** /**
* This union simplifies accessing the full data content of the Space Packet. * This union simplifies accessing the full data content of the Space Packet.
* This is achieved by putting the \c PacketStructured struct in a union with * This is achieved by putting the \c PacketStructured struct in a union with
* a plain buffer. * a plain buffer.
*/ */
union SpacePacketData { union SpacePacketData {
PacketStructured fields; PacketStructured fields;
uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)]; uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)];
}; };
/** /**
* This is the data representation of the class. * This is the data representation of the class.
* It is a struct of CCSDS Primary Header and a data field, which again is * It is a struct of CCSDS Primary Header and a data field, which again is
* packed in an union, so the data can be accessed as a byte stream without * packed in an union, so the data can be accessed as a byte stream without
* a cast. * a cast.
*/ */
SpacePacketData localData; SpacePacketData localData;
}; };
#endif /* SPACEPACKET_H_ */ #endif /* SPACEPACKET_H_ */