FSFW Update #21
@ -324,26 +324,23 @@ ReturnValue_t TcpTmTcServer::handleTcRingBufferData(size_t availableReadData) {
|
||||
size_t startIdx = 0;
|
||||
size_t foundSize = 0;
|
||||
size_t readLen = 0;
|
||||
while(readLen <= readAmount) {
|
||||
while(readLen < readAmount) {
|
||||
result = spacePacketParser->parseSpacePackets(bufPtrPtr, readAmount,
|
||||
startIdx, foundSize, readLen);
|
||||
if(result == SpacePacketParser::NO_PACKET_FOUND) {
|
||||
ringBuffer.deleteData(foundSize);
|
||||
lastRingBufferSize = ringBuffer.getAvailableReadData();
|
||||
switch(result) {
|
||||
case(SpacePacketParser::NO_PACKET_FOUND):
|
||||
case(SpacePacketParser::SPLIT_PACKET): {
|
||||
break;
|
||||
}
|
||||
else if(result == SpacePacketParser::SPLIT_PACKET) {
|
||||
// might be half of a packet? Skip it for now
|
||||
ringBuffer.deleteData(foundSize);
|
||||
lastRingBufferSize = ringBuffer.getAvailableReadData();
|
||||
}
|
||||
else if(result == HasReturnvaluesIF::RETURN_OK) {
|
||||
case(HasReturnvaluesIF::RETURN_OK): {
|
||||
result = handleTcReception(receptionBuffer.data() + startIdx, foundSize);
|
||||
ringBuffer.deleteData(foundSize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
status = result;
|
||||
}
|
||||
lastRingBufferSize = ringBuffer.getAvailableReadData();
|
||||
}
|
||||
}
|
||||
ringBuffer.deleteData(foundSize);
|
||||
lastRingBufferSize = ringBuffer.getAvailableReadData();
|
||||
std::memset(receptionBuffer.data() + startIdx, 0, foundSize);
|
||||
}
|
||||
return status;
|
||||
|
@ -127,7 +127,7 @@ private:
|
||||
SpacePacketParser* spacePacketParser = nullptr;
|
||||
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 handleTmSending(socket_t connSocket, bool& tmSent);
|
||||
ReturnValue_t handleTcRingBufferData(size_t availableReadData);
|
||||
|
@ -15,57 +15,67 @@
|
||||
*/
|
||||
class SpacePacket: public SpacePacketBase {
|
||||
public:
|
||||
static const uint16_t PACKET_MAX_SIZE = 1024;
|
||||
/**
|
||||
* The constructor initializes the packet and sets all header information
|
||||
* according to the passed parameters.
|
||||
* @param packetDataLength Sets the packet data length field and therefore specifies
|
||||
* the size of the packet.
|
||||
* @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 sequenceCount ets the packet's Source Sequence Count field.
|
||||
*/
|
||||
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
|
||||
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
|
||||
/**
|
||||
* The class's default destructor.
|
||||
*/
|
||||
virtual ~SpacePacket();
|
||||
/**
|
||||
* 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);
|
||||
static const uint16_t PACKET_MAX_SIZE = 1024;
|
||||
/**
|
||||
* The constructor initializes the packet and sets all header information
|
||||
* according to the passed parameters.
|
||||
* @param packetDataLength Sets the packet data length field and therefore specifies
|
||||
* the size of the packet.
|
||||
* @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 sequenceCount ets the packet's Source Sequence Count field.
|
||||
*/
|
||||
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
|
||||
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
|
||||
/**
|
||||
* The class's default destructor.
|
||||
*/
|
||||
virtual ~SpacePacket();
|
||||
|
||||
static constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid) {
|
||||
uint16_t tcPacketId = (0x18 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff);
|
||||
return tcPacketId;
|
||||
}
|
||||
static constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid) {
|
||||
uint16_t tmPacketId = (0x08 << 8) | (((apid >> 8) & 0x07) << 8) | (apid & 0x00ff);
|
||||
return tmPacketId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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:
|
||||
/**
|
||||
* 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
|
||||
* maximum size of \c PACKET_MAX_SIZE.
|
||||
*/
|
||||
struct PacketStructured {
|
||||
CCSDSPrimaryHeader header;
|
||||
uint8_t buffer[PACKET_MAX_SIZE];
|
||||
};
|
||||
/**
|
||||
* 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
|
||||
* a plain buffer.
|
||||
*/
|
||||
union SpacePacketData {
|
||||
PacketStructured fields;
|
||||
uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)];
|
||||
};
|
||||
/**
|
||||
* This is the data representation of the class.
|
||||
* 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
|
||||
* a cast.
|
||||
*/
|
||||
SpacePacketData localData;
|
||||
/**
|
||||
* 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
|
||||
* maximum size of \c PACKET_MAX_SIZE.
|
||||
*/
|
||||
struct PacketStructured {
|
||||
CCSDSPrimaryHeader header;
|
||||
uint8_t buffer[PACKET_MAX_SIZE];
|
||||
};
|
||||
/**
|
||||
* 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
|
||||
* a plain buffer.
|
||||
*/
|
||||
union SpacePacketData {
|
||||
PacketStructured fields;
|
||||
uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)];
|
||||
};
|
||||
/**
|
||||
* This is the data representation of the class.
|
||||
* 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
|
||||
* a cast.
|
||||
*/
|
||||
SpacePacketData localData;
|
||||
};
|
||||
|
||||
#endif /* SPACEPACKET_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user