updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
@ -1,56 +1,57 @@
|
||||
|
||||
/*
|
||||
* TcPacketStored.cpp
|
||||
*
|
||||
* Created on: 20.11.2012
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/tmtcpacket/pus/TcPacket.h>
|
||||
#include <framework/tmtcpacket/pus/TcPacketStored.h>
|
||||
#include <string.h>
|
||||
|
||||
TcPacketStored::TcPacketStored( store_address_t setAddress) : TcPacketBase(NULL), storeAddress(setAddress) {
|
||||
this->setStoreAddress( this->storeAddress );
|
||||
TcPacketStored::TcPacketStored(store_address_t setAddress) :
|
||||
TcPacketBase(NULL), storeAddress(setAddress) {
|
||||
this->setStoreAddress(this->storeAddress);
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored( uint16_t apid, uint8_t ack, uint8_t service, uint8_t subservice,
|
||||
uint8_t sequence_count, const uint8_t* data, uint32_t size) : TcPacketBase(NULL) {
|
||||
TcPacketStored::TcPacketStored(uint16_t apid, uint8_t ack, uint8_t service,
|
||||
uint8_t subservice, uint8_t sequence_count, const uint8_t* data,
|
||||
uint32_t size) :
|
||||
TcPacketBase(NULL) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if ( this->checkAndSetStore() ) {
|
||||
TcPacket<TC_PACKET_MIN_SIZE> temp_packet( apid, ack, service, subservice, sequence_count);
|
||||
uint8_t* p_data = NULL;
|
||||
ReturnValue_t returnValue = this->store->getFreeElement( &this->storeAddress, (TC_PACKET_MIN_SIZE + size), &p_data );
|
||||
if ( returnValue == this->store->RETURN_OK ) {
|
||||
memcpy(p_data, temp_packet.getWholeData(), temp_packet.getFullSize() );
|
||||
this->setData( p_data );
|
||||
memcpy( &tc_data->data, data, size );
|
||||
this->setPacketDataLength( size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1 );
|
||||
this->setErrorControl();
|
||||
}
|
||||
if (!this->checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
uint8_t* p_data = NULL;
|
||||
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
|
||||
(TC_PACKET_MIN_SIZE + size), &p_data);
|
||||
if (returnValue != this->store->RETURN_OK) {
|
||||
return;
|
||||
}
|
||||
this->setData(p_data);
|
||||
initializeTcPacket(apid, sequence_count, ack, service, subservice);
|
||||
memcpy(&tcData->data, data, size);
|
||||
this->setPacketDataLength(
|
||||
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
||||
this->setErrorControl();
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored() : TcPacketBase(NULL) {
|
||||
TcPacketStored::TcPacketStored() :
|
||||
TcPacketBase(NULL) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->checkAndSetStore();
|
||||
|
||||
}
|
||||
|
||||
//TODO: return code?
|
||||
void TcPacketStored::deletePacket() {
|
||||
this->store->deleteData( this->storeAddress );
|
||||
ReturnValue_t TcPacketStored::deletePacket() {
|
||||
ReturnValue_t result = this->store->deleteData(this->storeAddress);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->setData( NULL );
|
||||
this->setData( NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TcPacketStored::checkAndSetStore() {
|
||||
if (this->store == NULL) {
|
||||
this->store = objectManager->get<StorageManagerIF>( objects::TC_STORE );
|
||||
if ( this->store == NULL ) {
|
||||
error << "TcPacketStored::TcPacketStored: TC Store not found!" << std::endl;
|
||||
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (this->store == NULL) {
|
||||
error << "TcPacketStored::TcPacketStored: TC Store not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -62,8 +63,9 @@ void TcPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
const uint8_t* temp_data = NULL;
|
||||
uint32_t temp_size;
|
||||
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
||||
if ( this->checkAndSetStore() ) {
|
||||
status = this->store->getData(this->storeAddress, &temp_data, &temp_size );
|
||||
if (this->checkAndSetStore()) {
|
||||
status = this->store->getData(this->storeAddress, &temp_data,
|
||||
&temp_size);
|
||||
}
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
this->setData(temp_data);
|
||||
@ -80,9 +82,10 @@ store_address_t TcPacketStored::getStoreAddress() {
|
||||
bool TcPacketStored::isSizeCorrect() {
|
||||
const uint8_t* temp_data = NULL;
|
||||
uint32_t temp_size;
|
||||
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size );
|
||||
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
|
||||
&temp_size);
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
if (this->getFullSize() == temp_size ) {
|
||||
if (this->getFullSize() == temp_size) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -91,11 +94,12 @@ bool TcPacketStored::isSizeCorrect() {
|
||||
|
||||
StorageManagerIF* TcPacketStored::store = NULL;
|
||||
|
||||
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) : TcPacketBase(data) {
|
||||
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
|
||||
TcPacketBase(data) {
|
||||
if (getFullSize() != size) {
|
||||
return;
|
||||
}
|
||||
if ( this->checkAndSetStore() ) {
|
||||
if (this->checkAndSetStore()) {
|
||||
ReturnValue_t status = store->addData(&storeAddress, data, size);
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
this->setData(NULL);
|
||||
|
Reference in New Issue
Block a user