tm packet stored

This commit is contained in:
Robin Müller 2020-10-28 19:44:37 +01:00
parent cb71a18277
commit 53e98df37d
2 changed files with 74 additions and 60 deletions

View File

@ -1,11 +1,16 @@
#include "TmPacketStored.h"
#include "../../objectmanager/ObjectManagerIF.h" #include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../serviceinterface/ServiceInterfaceStream.h"
#include "TmPacketStored.h"
#include "../../tmtcservices/TmTcMessage.h" #include "../../tmtcservices/TmTcMessage.h"
#include <string.h>
#include <cstring>
StorageManagerIF *TmPacketStored::store = nullptr;
InternalErrorReporterIF *TmPacketStored::internalErrorReporter = nullptr;
TmPacketStored::TmPacketStored(store_address_t setAddress) : TmPacketStored::TmPacketStored(store_address_t setAddress) :
TmPacketBase(NULL), storeAddress(setAddress) { TmPacketBase(nullptr), storeAddress(setAddress) {
setStoreAddress(storeAddress); setStoreAddress(storeAddress);
} }
@ -14,10 +19,10 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) : uint32_t size, const uint8_t *headerData, uint32_t headerSize) :
TmPacketBase(NULL) { TmPacketBase(NULL) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (!checkAndSetStore()) { if (not checkAndSetStore()) {
return; return;
} }
uint8_t *pData = NULL; uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData); (TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData);
@ -38,7 +43,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
SerializeIF *header) : SerializeIF *header) :
TmPacketBase(NULL) { TmPacketBase(NULL) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (!checkAndSetStore()) { if (not checkAndSetStore()) {
return; return;
} }
size_t sourceDataSize = 0; size_t sourceDataSize = 0;
@ -77,29 +82,29 @@ store_address_t TmPacketStored::getStoreAddress() {
void TmPacketStored::deletePacket() { void TmPacketStored::deletePacket() {
store->deleteData(storeAddress); store->deleteData(storeAddress);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
setData(NULL); setData(nullptr);
} }
void TmPacketStored::setStoreAddress(store_address_t setAddress) { void TmPacketStored::setStoreAddress(store_address_t setAddress) {
storeAddress = setAddress; storeAddress = setAddress;
const uint8_t* temp_data = NULL; const uint8_t* tempData = nullptr;
size_t temp_size; size_t tempSize;
if (!checkAndSetStore()) { if (not checkAndSetStore()) {
return; return;
} }
ReturnValue_t status = store->getData(storeAddress, &temp_data, &temp_size); ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize);
if (status == StorageManagerIF::RETURN_OK) { if (status == StorageManagerIF::RETURN_OK) {
setData(temp_data); setData(tempData);
} else { } else {
setData(NULL); setData(nullptr);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
} }
} }
bool TmPacketStored::checkAndSetStore() { bool TmPacketStored::checkAndSetStore() {
if (store == NULL) { if (store == nullptr) {
store = objectManager->get<StorageManagerIF>(objects::TM_STORE); store = objectManager->get<StorageManagerIF>(objects::TM_STORE);
if (store == NULL) { if (store == nullptr) {
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!" sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
<< std::endl; << std::endl;
return false; return false;
@ -108,12 +113,9 @@ bool TmPacketStored::checkAndSetStore() {
return true; return true;
} }
StorageManagerIF *TmPacketStored::store = NULL;
InternalErrorReporterIF *TmPacketStored::internalErrorReporter = NULL;
ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination, ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting) { MessageQueueId_t sentFrom, bool doErrorReporting) {
if (getWholeData() == NULL) { if (getWholeData() == nullptr) {
//SHOULDDO: More decent code. //SHOULDDO: More decent code.
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -133,11 +135,11 @@ ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination,
} }
void TmPacketStored::checkAndReportLostTm() { void TmPacketStored::checkAndReportLostTm() {
if (internalErrorReporter == NULL) { if (internalErrorReporter == nullptr) {
internalErrorReporter = objectManager->get<InternalErrorReporterIF>( internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER); objects::INTERNAL_ERROR_REPORTER);
} }
if (internalErrorReporter != NULL) { if (internalErrorReporter != nullptr) {
internalErrorReporter->lostTm(); internalErrorReporter->lostTm();
} }
} }

View File

@ -1,9 +1,10 @@
#ifndef TMPACKETSTORED_H_ #ifndef TMTCPACKET_PUS_TMPACKETSTORED_H_
#define TMPACKETSTORED_H_ #define TMTCPACKET_PUS_TMPACKETSTORED_H_
#include "TmPacketBase.h"
#include "../../serialize/SerializeIF.h" #include "../../serialize/SerializeIF.h"
#include "../../storagemanager/StorageManagerIF.h" #include "../../storagemanager/StorageManagerIF.h"
#include "TmPacketBase.h"
#include "../../internalError/InternalErrorReporterIF.h" #include "../../internalError/InternalErrorReporterIF.h"
#include "../../ipc/MessageQueueSenderIF.h" #include "../../ipc/MessageQueueSenderIF.h"
@ -18,31 +19,6 @@
* @ingroup tmtcpackets * @ingroup tmtcpackets
*/ */
class TmPacketStored : public TmPacketBase { class TmPacketStored : public TmPacketBase {
private:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. \c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
static InternalErrorReporterIF *internalErrorReporter;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li \c true if the store is linked or could be created.
* @li \c false otherwise.
*/
bool checkAndSetStore();
void checkAndReportLostTm();
public: public:
/** /**
* This is a default constructor which does not set the data pointer. * This is a default constructor which does not set the data pointer.
@ -52,28 +28,38 @@ public:
/** /**
* With this constructor, new space is allocated in the packet store and * With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there. * a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet. The Application data is * Packet Application Data passed in data is copied into the packet.
* passed in two parts, first a header, then a data field. This allows building a Telemetry * The Application data is passed in two parts, first a header, then a
* Packet from two separate data sources. * data field. This allows building a Telemetry Packet from two separate
* data sources.
* @param apid Sets the packet's APID field. * @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field. * @param service Sets the packet's Service ID field.
* This specifies the source service. * This specifies the source service.
* @param subservice Sets the packet's Service Subtype field. * @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service. * This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet * @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the Application Data Field * @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied. * @param size The amount of data to be copied.
* @param headerData The header Data of the Application field; will be copied in front of data * @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF * @param headerSize The size of the headerDataF
*/ */
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0, const uint8_t* data = NULL, uint32_t size = 0, const uint8_t* headerData = NULL, uint32_t headerSize = 0); TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0);
/** /**
* Another ctor to directly pass structured content and header data to the packet to avoid additional buffers. * Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/ */
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter, SerializeIF* content, SerializeIF* header = NULL); TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr);
/** /**
* This is a getter for the current store address of the packet. * This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is \c StorageManagerIF::INVALID_ADDRESS if * @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked. * the packet is not linked.
*/ */
store_address_t getStoreAddress(); store_address_t getStoreAddress();
@ -89,8 +75,34 @@ public:
*/ */
void setStoreAddress( store_address_t setAddress ); void setStoreAddress( store_address_t setAddress );
ReturnValue_t sendPacket( MessageQueueId_t destination, MessageQueueId_t sentFrom, bool doErrorReporting = true ); ReturnValue_t sendPacket( MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting = true );
private:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
static InternalErrorReporterIF *internalErrorReporter;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
void checkAndReportLostTm();
}; };
#endif /* TMPACKETSTORED_H_ */ #endif /* TMTCPACKET_PUS_TMPACKETSTORED_H_ */