Merge branch 'master' into mueller/feature/TmTcUnixBridge
This commit is contained in:
commit
67b11c0535
42
container/DynamicFIFO.h
Normal file
42
container/DynamicFIFO.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef FSFW_CONTAINER_DYNAMICFIFO_H_
|
||||||
|
#define FSFW_CONTAINER_DYNAMICFIFO_H_
|
||||||
|
|
||||||
|
#include "FIFOBase.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Simple First-In-First-Out data structure. The maximum size
|
||||||
|
* can be set in the constructor.
|
||||||
|
* @details
|
||||||
|
* The maximum capacity can be determined at run-time, so this container
|
||||||
|
* performs dynamic memory allocation!
|
||||||
|
* The public interface of FIFOBase exposes the user interface for the FIFO.
|
||||||
|
* @tparam T Entry Type
|
||||||
|
* @tparam capacity Maximum capacity
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
class DynamicFIFO: public FIFOBase<T> {
|
||||||
|
public:
|
||||||
|
DynamicFIFO(size_t maxCapacity): FIFOBase<T>(nullptr, maxCapacity),
|
||||||
|
fifoVector(maxCapacity) {
|
||||||
|
// trying to pass the pointer of the uninitialized vector
|
||||||
|
// to the FIFOBase constructor directly lead to a super evil bug.
|
||||||
|
// So we do it like this now.
|
||||||
|
this->setContainer(fifoVector.data());
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Custom copy constructor which prevents setting the
|
||||||
|
* underlying pointer wrong.
|
||||||
|
*/
|
||||||
|
DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other),
|
||||||
|
fifoVector(other.maxCapacity) {
|
||||||
|
this->setContainer(fifoVector.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<T> fifoVector;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_CONTAINER_DYNAMICFIFO_H_ */
|
@ -1,82 +1,35 @@
|
|||||||
#ifndef FIFO_H_
|
#ifndef FSFW_CONTAINER_FIFO_H_
|
||||||
#define FIFO_H_
|
#define FSFW_CONTAINER_FIFO_H_
|
||||||
|
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "FIFOBase.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Simple First-In-First-Out data structure
|
* @brief Simple First-In-First-Out data structure with size fixed at
|
||||||
|
* compile time
|
||||||
|
* @details
|
||||||
|
* Performs no dynamic memory allocation.
|
||||||
|
* The public interface of FIFOBase exposes the user interface for the FIFO.
|
||||||
* @tparam T Entry Type
|
* @tparam T Entry Type
|
||||||
* @tparam capacity Maximum capacity
|
* @tparam capacity Maximum capacity
|
||||||
*/
|
*/
|
||||||
template<typename T, uint8_t capacity>
|
template<typename T, size_t capacity>
|
||||||
class FIFO {
|
class FIFO: public FIFOBase<T> {
|
||||||
private:
|
|
||||||
uint8_t readIndex, writeIndex, currentSize;
|
|
||||||
T data[capacity];
|
|
||||||
|
|
||||||
uint8_t next(uint8_t current) {
|
|
||||||
++current;
|
|
||||||
if (current == capacity) {
|
|
||||||
current = 0;
|
|
||||||
}
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
public:
|
public:
|
||||||
FIFO() :
|
FIFO(): FIFOBase<T>(nullptr, capacity) {
|
||||||
readIndex(0), writeIndex(0), currentSize(0) {
|
this->setContainer(fifoArray.data());
|
||||||
}
|
|
||||||
|
|
||||||
bool empty() {
|
|
||||||
return (currentSize == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool full() {
|
|
||||||
return (currentSize == capacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t size(){
|
|
||||||
return currentSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t insert(T value) {
|
|
||||||
if (full()) {
|
|
||||||
return FULL;
|
|
||||||
} else {
|
|
||||||
data[writeIndex] = value;
|
|
||||||
writeIndex = next(writeIndex);
|
|
||||||
++currentSize;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t retrieve(T *value) {
|
|
||||||
if (empty()) {
|
|
||||||
return EMPTY;
|
|
||||||
} else {
|
|
||||||
*value = data[readIndex];
|
|
||||||
readIndex = next(readIndex);
|
|
||||||
--currentSize;
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t peek(T * value) {
|
|
||||||
if(empty()) {
|
|
||||||
return EMPTY;
|
|
||||||
} else {
|
|
||||||
*value = data[readIndex];
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t pop() {
|
|
||||||
T value;
|
|
||||||
return this->retrieve(&value);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;
|
|
||||||
static const ReturnValue_t FULL = MAKE_RETURN_CODE(1);
|
|
||||||
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FIFO_H_ */
|
/**
|
||||||
|
* @brief Custom copy constructor to set pointer correctly.
|
||||||
|
* @param other
|
||||||
|
*/
|
||||||
|
FIFO(const FIFO& other): FIFOBase<T>(other) {
|
||||||
|
this->setContainer(fifoArray.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<T, capacity> fifoArray;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_CONTAINER_FIFO_H_ */
|
||||||
|
65
container/FIFOBase.h
Normal file
65
container/FIFOBase.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#ifndef FSFW_CONTAINER_FIFOBASE_H_
|
||||||
|
#define FSFW_CONTAINER_FIFOBASE_H_
|
||||||
|
|
||||||
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class FIFOBase {
|
||||||
|
public:
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS;
|
||||||
|
static const ReturnValue_t FULL = MAKE_RETURN_CODE(1);
|
||||||
|
static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2);
|
||||||
|
|
||||||
|
/** Default ctor, takes pointer to first entry of underlying container
|
||||||
|
* and maximum capacity */
|
||||||
|
FIFOBase(T* values, const size_t maxCapacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert value into FIFO
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t insert(T value);
|
||||||
|
/**
|
||||||
|
* Retrieve item from FIFO. This removes the item from the FIFO.
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t retrieve(T *value);
|
||||||
|
/**
|
||||||
|
* Retrieve item from FIFO without removing it from FIFO.
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t peek(T * value);
|
||||||
|
/**
|
||||||
|
* Remove item from FIFO.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t pop();
|
||||||
|
|
||||||
|
bool empty();
|
||||||
|
bool full();
|
||||||
|
size_t size();
|
||||||
|
|
||||||
|
|
||||||
|
size_t getMaxCapacity() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setContainer(T* data);
|
||||||
|
size_t maxCapacity = 0;
|
||||||
|
|
||||||
|
T* values;
|
||||||
|
|
||||||
|
size_t readIndex = 0;
|
||||||
|
size_t writeIndex = 0;
|
||||||
|
size_t currentSize = 0;
|
||||||
|
|
||||||
|
size_t next(size_t current);
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "FIFOBase.tpp"
|
||||||
|
|
||||||
|
#endif /* FSFW_CONTAINER_FIFOBASE_H_ */
|
87
container/FIFOBase.tpp
Normal file
87
container/FIFOBase.tpp
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#ifndef FSFW_CONTAINER_FIFOBASE_TPP_
|
||||||
|
#define FSFW_CONTAINER_FIFOBASE_TPP_
|
||||||
|
|
||||||
|
#ifndef FSFW_CONTAINER_FIFOBASE_H_
|
||||||
|
#error Include FIFOBase.h before FIFOBase.tpp!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline FIFOBase<T>::FIFOBase(T* values, const size_t maxCapacity):
|
||||||
|
maxCapacity(maxCapacity), values(values){};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t FIFOBase<T>::insert(T value) {
|
||||||
|
if (full()) {
|
||||||
|
return FULL;
|
||||||
|
} else {
|
||||||
|
values[writeIndex] = value;
|
||||||
|
writeIndex = next(writeIndex);
|
||||||
|
++currentSize;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t FIFOBase<T>::retrieve(T* value) {
|
||||||
|
if (empty()) {
|
||||||
|
return EMPTY;
|
||||||
|
} else {
|
||||||
|
*value = values[readIndex];
|
||||||
|
readIndex = next(readIndex);
|
||||||
|
--currentSize;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t FIFOBase<T>::peek(T* value) {
|
||||||
|
if(empty()) {
|
||||||
|
return EMPTY;
|
||||||
|
} else {
|
||||||
|
*value = values[readIndex];
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline ReturnValue_t FIFOBase<T>::pop() {
|
||||||
|
T value;
|
||||||
|
return this->retrieve(&value);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool FIFOBase<T>::empty() {
|
||||||
|
return (currentSize == 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline bool FIFOBase<T>::full() {
|
||||||
|
return (currentSize == maxCapacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline size_t FIFOBase<T>::size() {
|
||||||
|
return currentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline size_t FIFOBase<T>::next(size_t current) {
|
||||||
|
++current;
|
||||||
|
if (current == maxCapacity) {
|
||||||
|
current = 0;
|
||||||
|
}
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline size_t FIFOBase<T>::getMaxCapacity() const {
|
||||||
|
return maxCapacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline void FIFOBase<T>::setContainer(T *data) {
|
||||||
|
this->values = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,18 +1,23 @@
|
|||||||
#include "SimpleRingBuffer.h"
|
#include "SimpleRingBuffer.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
SimpleRingBuffer::SimpleRingBuffer(uint32_t size, bool overwriteOld) :
|
SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld) :
|
||||||
RingBufferBase<>(0, size, overwriteOld), buffer(NULL) {
|
RingBufferBase<>(0, size, overwriteOld) {
|
||||||
buffer = new uint8_t[size];
|
buffer = new uint8_t[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size,
|
||||||
|
bool overwriteOld):
|
||||||
|
RingBufferBase<>(0, size, overwriteOld), buffer(buffer) {}
|
||||||
|
|
||||||
|
|
||||||
SimpleRingBuffer::~SimpleRingBuffer() {
|
SimpleRingBuffer::~SimpleRingBuffer() {
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||||
uint32_t amount) {
|
uint32_t amount) {
|
||||||
if (availableWriteSpace() >= amount || overwriteOld) {
|
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||||
uint32_t amountTillWrap = writeTillWrap();
|
uint32_t amountTillWrap = writeTillWrap();
|
||||||
if (amountTillWrap >= amount) {
|
if (amountTillWrap >= amount) {
|
||||||
memcpy(&buffer[write], data, amount);
|
memcpy(&buffer[write], data, amount);
|
||||||
@ -38,7 +43,7 @@ ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trueAmount != NULL) {
|
if (trueAmount != nullptr) {
|
||||||
*trueAmount = amount;
|
*trueAmount = amount;
|
||||||
}
|
}
|
||||||
if (amountTillWrap >= amount) {
|
if (amountTillWrap >= amount) {
|
||||||
@ -60,9 +65,10 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (trueAmount != NULL) {
|
if (trueAmount != nullptr) {
|
||||||
*trueAmount = amount;
|
*trueAmount = amount;
|
||||||
}
|
}
|
||||||
incrementRead(amount, READ_PTR);
|
incrementRead(amount, READ_PTR);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,17 +4,64 @@
|
|||||||
#include "RingBufferBase.h"
|
#include "RingBufferBase.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Circular buffer implementation, useful for buffering
|
||||||
|
* into data streams.
|
||||||
|
* @details
|
||||||
|
* Note that the deleteData() has to be called to increment the read pointer.
|
||||||
|
* This class allocated dynamically, so
|
||||||
|
* @ingroup containers
|
||||||
|
*/
|
||||||
class SimpleRingBuffer: public RingBufferBase<> {
|
class SimpleRingBuffer: public RingBufferBase<> {
|
||||||
public:
|
public:
|
||||||
SimpleRingBuffer(uint32_t size, bool overwriteOld);
|
/**
|
||||||
|
* This constructor allocates a new internal buffer with the supplied size.
|
||||||
|
* @param size
|
||||||
|
* @param overwriteOld
|
||||||
|
*/
|
||||||
|
SimpleRingBuffer(const size_t size, bool overwriteOld);
|
||||||
|
/**
|
||||||
|
* This constructor takes an external buffer with the specified size.
|
||||||
|
* @param buffer
|
||||||
|
* @param size
|
||||||
|
* @param overwriteOld
|
||||||
|
*/
|
||||||
|
SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld);
|
||||||
|
|
||||||
virtual ~SimpleRingBuffer();
|
virtual ~SimpleRingBuffer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write to circular buffer and increment write pointer by amount
|
||||||
|
* @param data
|
||||||
|
* @param amount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
ReturnValue_t writeData(const uint8_t* data, uint32_t amount);
|
ReturnValue_t writeData(const uint8_t* data, uint32_t amount);
|
||||||
ReturnValue_t readData(uint8_t* data, uint32_t amount, bool readRemaining = false, uint32_t* trueAmount = NULL);
|
|
||||||
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false, uint32_t* trueAmount = NULL);
|
/**
|
||||||
|
* Read from circular buffer at read pointer
|
||||||
|
* @param data
|
||||||
|
* @param amount
|
||||||
|
* @param readRemaining
|
||||||
|
* @param trueAmount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t readData(uint8_t* data, uint32_t amount,
|
||||||
|
bool readRemaining = false, uint32_t* trueAmount = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete data starting by incrementing read pointer
|
||||||
|
* @param amount
|
||||||
|
* @param deleteRemaining
|
||||||
|
* @param trueAmount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false,
|
||||||
|
uint32_t* trueAmount = nullptr);
|
||||||
private:
|
private:
|
||||||
// static const uint8_t TEMP_READ_PTR = 1;
|
// static const uint8_t TEMP_READ_PTR = 1;
|
||||||
static const uint8_t READ_PTR = 0;
|
static const uint8_t READ_PTR = 0;
|
||||||
uint8_t* buffer;
|
uint8_t* buffer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
#include "ChildHandlerBase.h"
|
#include "../devicehandlers/ChildHandlerBase.h"
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
|
|
||||||
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
|
ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId,
|
||||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
object_id_t deviceCommunication, CookieIF * cookie,
|
||||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId,
|
||||||
uint32_t thermalRequestPoolId, uint32_t parent,
|
object_id_t parent, FailureIsolationBase* customFdir,
|
||||||
FailureIsolationBase* customFdir, size_t cmdQueueSize) :
|
size_t cmdQueueSize) :
|
||||||
DeviceHandlerBase(setObjectId, deviceCommunication, comCookie,
|
DeviceHandlerBase(setObjectId, deviceCommunication, cookie,
|
||||||
setDeviceSwitch, thermalStatePoolId,thermalRequestPoolId,
|
|
||||||
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
(customFdir == nullptr? &childHandlerFdir : customFdir),
|
||||||
cmdQueueSize),
|
cmdQueueSize),
|
||||||
parentId(parent), childHandlerFdir(setObjectId) {
|
parentId(parent), childHandlerFdir(setObjectId) {
|
||||||
|
this->setThermalStateRequestPoolIds(thermalStatePoolId,
|
||||||
|
thermalRequestPoolId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChildHandlerBase::~ChildHandlerBase() {
|
ChildHandlerBase::~ChildHandlerBase() {
|
||||||
@ -25,7 +27,7 @@ ReturnValue_t ChildHandlerBase::initialize() {
|
|||||||
|
|
||||||
MessageQueueId_t parentQueue = 0;
|
MessageQueueId_t parentQueue = 0;
|
||||||
|
|
||||||
if (parentId != 0) {
|
if (parentId != objects::NO_OBJECT) {
|
||||||
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
|
||||||
if (parent == NULL) {
|
if (parent == NULL) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#ifndef PAYLOADHANDLERBASE_H_
|
#ifndef FSFW_DEVICES_CHILDHANDLERBASE_H_
|
||||||
#define PAYLOADHANDLERBASE_H_
|
#define FSFW_DEVICES_CHILDHANDLERBASE_H_
|
||||||
|
|
||||||
#include "ChildHandlerFDIR.h"
|
#include "ChildHandlerFDIR.h"
|
||||||
#include "DeviceHandlerBase.h"
|
#include "DeviceHandlerBase.h"
|
||||||
|
|
||||||
class ChildHandlerBase: public DeviceHandlerBase {
|
class ChildHandlerBase: public DeviceHandlerBase {
|
||||||
public:
|
public:
|
||||||
ChildHandlerBase(object_id_t setObjectId,
|
ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
CookieIF * cookie, uint32_t thermalStatePoolId,
|
||||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
uint32_t thermalRequestPoolId,
|
||||||
uint32_t thermalRequestPoolId, uint32_t parent,
|
object_id_t parent = objects::NO_OBJECT,
|
||||||
FailureIsolationBase* customFdir = nullptr,
|
FailureIsolationBase* customFdir = nullptr,
|
||||||
size_t cmdQueueSize = 20);
|
size_t cmdQueueSize = 20);
|
||||||
virtual ~ChildHandlerBase();
|
virtual ~ChildHandlerBase();
|
||||||
@ -22,4 +22,5 @@ protected:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PAYLOADHANDLERBASE_H_ */
|
#endif /* FSFW_DEVICES_CHILDHANDLERBASE_H_ */
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#include "DeviceHandlerBase.h"
|
#include "DeviceHandlerBase.h"
|
||||||
|
#include "AcceptsDeviceResponsesIF.h"
|
||||||
|
#include "DeviceTmReportingWrapper.h"
|
||||||
|
|
||||||
#include "../objectmanager/ObjectManager.h"
|
#include "../objectmanager/ObjectManager.h"
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
#include "../thermal/ThermalComponentIF.h"
|
#include "../thermal/ThermalComponentIF.h"
|
||||||
#include "AcceptsDeviceResponsesIF.h"
|
|
||||||
|
|
||||||
#include "../datapool/DataSet.h"
|
#include "../datapool/DataSet.h"
|
||||||
#include "../datapool/PoolVariable.h"
|
#include "../datapool/PoolVariable.h"
|
||||||
#include "DeviceTmReportingWrapper.h"
|
|
||||||
#include "../globalfunctions/CRC.h"
|
#include "../globalfunctions/CRC.h"
|
||||||
#include "../subsystem/SubsystemBase.h"
|
#include "../subsystem/SubsystemBase.h"
|
||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
@ -14,45 +14,47 @@
|
|||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
object_id_t DeviceHandlerBase::powerSwitcherId = 0;
|
object_id_t DeviceHandlerBase::powerSwitcherId = objects::NO_OBJECT;
|
||||||
object_id_t DeviceHandlerBase::rawDataReceiverId = 0;
|
object_id_t DeviceHandlerBase::rawDataReceiverId = objects::NO_OBJECT;
|
||||||
object_id_t DeviceHandlerBase::defaultFDIRParentId = 0;
|
object_id_t DeviceHandlerBase::defaultFdirParentId = objects::NO_OBJECT;
|
||||||
|
|
||||||
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId,
|
||||||
object_id_t deviceCommunication, CookieIF * comCookie,
|
object_id_t deviceCommunication, CookieIF * comCookie,
|
||||||
uint8_t setDeviceSwitch, uint32_t thermalStatePoolId,
|
FailureIsolationBase* fdirInstance, size_t cmdQueueSize) :
|
||||||
uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance,
|
|
||||||
size_t cmdQueueSize) :
|
|
||||||
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
|
SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE),
|
||||||
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS),
|
||||||
deviceCommunicationId(deviceCommunication), comCookie(comCookie),
|
deviceCommunicationId(deviceCommunication), comCookie(comCookie),
|
||||||
deviceThermalStatePoolId(thermalStatePoolId),
|
|
||||||
deviceThermalRequestPoolId(thermalRequestPoolId),
|
|
||||||
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
healthHelper(this,setObjectId), modeHelper(this), parameterHelper(this),
|
||||||
childTransitionFailure(RETURN_OK), fdirInstance(fdirInstance),
|
actionHelper(this, nullptr), childTransitionFailure(RETURN_OK),
|
||||||
hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr),
|
fdirInstance(fdirInstance), hkSwitcher(this),
|
||||||
switchOffWasReported(false), actionHelper(this, nullptr),
|
defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false),
|
||||||
childTransitionDelay(5000),
|
childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN),
|
||||||
transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(
|
transitionSourceSubMode(SUBMODE_NONE) {
|
||||||
SUBMODE_NONE), deviceSwitch(setDeviceSwitch) {
|
|
||||||
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize,
|
||||||
CommandMessage::MAX_MESSAGE_SIZE);
|
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||||
insertInCommandMap(RAW_COMMAND_ID);
|
insertInCommandMap(RAW_COMMAND_ID);
|
||||||
cookieInfo.state = COOKIE_UNUSED;
|
cookieInfo.state = COOKIE_UNUSED;
|
||||||
cookieInfo.pendingCommand = deviceCommandMap.end();
|
cookieInfo.pendingCommand = deviceCommandMap.end();
|
||||||
if (comCookie == nullptr) {
|
if (comCookie == nullptr) {
|
||||||
sif::error << "DeviceHandlerBase: ObjectID 0x" << std::hex <<
|
sif::error << "DeviceHandlerBase: ObjectID 0x" << std::hex
|
||||||
std::setw(8) << std::setfill('0') << this->getObjectId() <<
|
<< std::setw(8) << std::setfill('0') << this->getObjectId()
|
||||||
std::dec << ": Do not pass nullptr as a cookie, consider "
|
<< std::dec << ": Do not pass nullptr as a cookie, consider "
|
||||||
<< std::setfill(' ') << "passing a dummy cookie instead!" <<
|
<< std::setfill(' ') << "passing a dummy cookie instead!"
|
||||||
std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
if (this->fdirInstance == nullptr) {
|
if (this->fdirInstance == nullptr) {
|
||||||
this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId,
|
this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId,
|
||||||
defaultFDIRParentId);
|
defaultFdirParentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceHandlerBase::setThermalStateRequestPoolIds(
|
||||||
|
uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId) {
|
||||||
|
this->deviceThermalRequestPoolId = thermalStatePoolId;
|
||||||
|
this->deviceThermalRequestPoolId = thermalRequestPoolId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DeviceHandlerBase::~DeviceHandlerBase() {
|
DeviceHandlerBase::~DeviceHandlerBase() {
|
||||||
delete comCookie;
|
delete comCookie;
|
||||||
if (defaultFDIRUsed) {
|
if (defaultFDIRUsed) {
|
||||||
@ -108,8 +110,12 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
|||||||
|
|
||||||
communicationInterface = objectManager->get<DeviceCommunicationIF>(
|
communicationInterface = objectManager->get<DeviceCommunicationIF>(
|
||||||
deviceCommunicationId);
|
deviceCommunicationId);
|
||||||
if (communicationInterface == NULL) {
|
if (communicationInterface == nullptr) {
|
||||||
return RETURN_FAILED;
|
sif::error << "DeviceHandlerBase::initialize: Communication interface "
|
||||||
|
"invalid." << std::endl;
|
||||||
|
sif::error << "Make sure it is set up properly and implements"
|
||||||
|
" DeviceCommunicationIF" << std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = communicationInterface->initializeInterface(comCookie);
|
result = communicationInterface->initializeInterface(comCookie);
|
||||||
@ -118,22 +124,35 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
IPCStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
||||||
if (IPCStore == NULL) {
|
if (IPCStore == nullptr) {
|
||||||
return RETURN_FAILED;
|
sif::error << "DeviceHandlerBase::initialize: IPC store not set up in "
|
||||||
|
"factory." << std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rawDataReceiverId != objects::NO_OBJECT) {
|
||||||
AcceptsDeviceResponsesIF *rawReceiver = objectManager->get<
|
AcceptsDeviceResponsesIF *rawReceiver = objectManager->get<
|
||||||
AcceptsDeviceResponsesIF>(rawDataReceiverId);
|
AcceptsDeviceResponsesIF>(rawDataReceiverId);
|
||||||
|
|
||||||
if (rawReceiver == NULL) {
|
if (rawReceiver == nullptr) {
|
||||||
return RETURN_FAILED;
|
sif::error << "DeviceHandlerBase::initialize: Raw receiver object "
|
||||||
|
"ID set but no valid object found." << std::endl;
|
||||||
|
sif::error << "Make sure the raw receiver object is set up properly"
|
||||||
|
" and implements AcceptsDeviceResponsesIF" << std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
}
|
||||||
|
defaultRawReceiver = rawReceiver->getDeviceQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultRawReceiver = rawReceiver->getDeviceQueue();
|
if(powerSwitcherId != objects::NO_OBJECT) {
|
||||||
|
|
||||||
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
|
powerSwitcher = objectManager->get<PowerSwitchIF>(powerSwitcherId);
|
||||||
if (powerSwitcher == NULL) {
|
if (powerSwitcher == nullptr) {
|
||||||
return RETURN_FAILED;
|
sif::error << "DeviceHandlerBase::initialize: Power switcher "
|
||||||
|
<< "object ID set but no valid object found." << std::endl;
|
||||||
|
sif::error << "Make sure the raw receiver object is set up properly"
|
||||||
|
<< " and implements PowerSwitchIF" << std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = healthHelper.initialize();
|
result = healthHelper.initialize();
|
||||||
@ -168,7 +187,7 @@ ReturnValue_t DeviceHandlerBase::initialize() {
|
|||||||
|
|
||||||
//Set temperature target state to NON_OP.
|
//Set temperature target state to NON_OP.
|
||||||
DataSet mySet;
|
DataSet mySet;
|
||||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_WRITE);
|
PoolVariableIF::VAR_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL;
|
||||||
@ -200,38 +219,43 @@ void DeviceHandlerBase::readCommandQueue() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandMessage message;
|
CommandMessage command;
|
||||||
ReturnValue_t result = commandQueue->receiveMessage(&message);
|
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = healthHelper.handleHealthCommand(&message);
|
result = healthHelper.handleHealthCommand(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = modeHelper.handleModeCommand(&message);
|
result = modeHelper.handleModeCommand(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = actionHelper.handleActionMessage(&message);
|
result = actionHelper.handleActionMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = parameterHelper.handleParameterMessage(&message);
|
result = parameterHelper.handleParameterMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = handleDeviceHandlerMessage(&message);
|
// result = hkManager.handleHousekeepingMessage(&command);
|
||||||
|
// if (result == RETURN_OK) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
result = handleDeviceHandlerMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = letChildHandleMessage(&message);
|
result = letChildHandleMessage(&command);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -273,7 +297,8 @@ void DeviceHandlerBase::doStateMachine() {
|
|||||||
case _MODE_WAIT_ON: {
|
case _MODE_WAIT_ON: {
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime;
|
||||||
Clock::getUptime(¤tUptime);
|
Clock::getUptime(¤tUptime);
|
||||||
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
if (powerSwitcher != nullptr and currentUptime - timeoutStart >=
|
||||||
|
powerSwitcher->getSwitchDelayMs()) {
|
||||||
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
||||||
0);
|
0);
|
||||||
setMode(_MODE_POWER_DOWN);
|
setMode(_MODE_POWER_DOWN);
|
||||||
@ -293,6 +318,12 @@ void DeviceHandlerBase::doStateMachine() {
|
|||||||
case _MODE_WAIT_OFF: {
|
case _MODE_WAIT_OFF: {
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime;
|
||||||
Clock::getUptime(¤tUptime);
|
Clock::getUptime(¤tUptime);
|
||||||
|
|
||||||
|
if(powerSwitcher == nullptr) {
|
||||||
|
setMode(MODE_OFF);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
if (currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
||||||
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT,
|
||||||
0);
|
0);
|
||||||
@ -343,9 +374,10 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand,
|
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
|
||||||
uint16_t maxDelayCycles, size_t replyLen, bool periodic,
|
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
|
||||||
bool hasDifferentReplyId, DeviceCommandId_t replyId) {
|
size_t replyLen, bool periodic, bool hasDifferentReplyId,
|
||||||
|
DeviceCommandId_t replyId) {
|
||||||
//No need to check, as we may try to insert multiple times.
|
//No need to check, as we may try to insert multiple times.
|
||||||
insertInCommandMap(deviceCommand);
|
insertInCommandMap(deviceCommand);
|
||||||
if (hasDifferentReplyId) {
|
if (hasDifferentReplyId) {
|
||||||
@ -371,7 +403,8 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand) {
|
ReturnValue_t DeviceHandlerBase::insertInCommandMap(
|
||||||
|
DeviceCommandId_t deviceCommand) {
|
||||||
DeviceCommandInfo info;
|
DeviceCommandInfo info;
|
||||||
info.expectedReplies = 0;
|
info.expectedReplies = 0;
|
||||||
info.isExecuting = false;
|
info.isExecuting = false;
|
||||||
@ -437,7 +470,7 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
|||||||
|
|
||||||
if (mode == MODE_OFF) {
|
if (mode == MODE_OFF) {
|
||||||
DataSet mySet;
|
DataSet mySet;
|
||||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ_WRITE);
|
PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -578,11 +611,8 @@ void DeviceHandlerBase::doSendRead() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::doGetRead() {
|
void DeviceHandlerBase::doGetRead() {
|
||||||
size_t receivedDataLen;
|
size_t receivedDataLen = 0;
|
||||||
uint8_t *receivedData;
|
uint8_t *receivedData = nullptr;
|
||||||
DeviceCommandId_t foundId = 0xFFFFFFFF;
|
|
||||||
size_t foundLen = 0;
|
|
||||||
ReturnValue_t result;
|
|
||||||
|
|
||||||
if (cookieInfo.state != COOKIE_READ_SENT) {
|
if (cookieInfo.state != COOKIE_READ_SENT) {
|
||||||
cookieInfo.state = COOKIE_UNUSED;
|
cookieInfo.state = COOKIE_UNUSED;
|
||||||
@ -591,8 +621,8 @@ void DeviceHandlerBase::doGetRead() {
|
|||||||
|
|
||||||
cookieInfo.state = COOKIE_UNUSED;
|
cookieInfo.state = COOKIE_UNUSED;
|
||||||
|
|
||||||
result = communicationInterface->readReceivedMessage(comCookie,
|
ReturnValue_t result = communicationInterface->readReceivedMessage(
|
||||||
&receivedData, &receivedDataLen);
|
comCookie, &receivedData, &receivedDataLen);
|
||||||
|
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
|
triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result);
|
||||||
@ -608,11 +638,22 @@ void DeviceHandlerBase::doGetRead() {
|
|||||||
replyRawData(receivedData, receivedDataLen, requestedRawTraffic);
|
replyRawData(receivedData, receivedDataLen, requestedRawTraffic);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == MODE_RAW) {
|
if (mode == MODE_RAW and defaultRawReceiver != MessageQueueIF::NO_QUEUE) {
|
||||||
replyRawReplyIfnotWiretapped(receivedData, receivedDataLen);
|
replyRawReplyIfnotWiretapped(receivedData, receivedDataLen);
|
||||||
} else {
|
}
|
||||||
//The loop may not execute more often than the number of received bytes (worst case).
|
else {
|
||||||
//This approach avoids infinite loops due to buggy scanForReply routines (seen in bug 1077).
|
parseReply(receivedData, receivedDataLen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceHandlerBase::parseReply(const uint8_t* receivedData,
|
||||||
|
size_t receivedDataLen) {
|
||||||
|
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
DeviceCommandId_t foundId = 0xFFFFFFFF;
|
||||||
|
size_t foundLen = 0;
|
||||||
|
// The loop may not execute more often than the number of received bytes
|
||||||
|
// (worst case). This approach avoids infinite loops due to buggy
|
||||||
|
// scanForReply routines.
|
||||||
uint32_t remainingLength = receivedDataLen;
|
uint32_t remainingLength = receivedDataLen;
|
||||||
for (uint32_t count = 0; count < receivedDataLen; count++) {
|
for (uint32_t count = 0; count < receivedDataLen; count++) {
|
||||||
result = scanForReply(receivedData, remainingLength, &foundId,
|
result = scanForReply(receivedData, remainingLength, &foundId,
|
||||||
@ -647,7 +688,46 @@ void DeviceHandlerBase::doGetRead() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
||||||
|
DeviceCommandId_t foundId, uint32_t foundLen) {
|
||||||
|
ReturnValue_t result;
|
||||||
|
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
|
||||||
|
|
||||||
|
if (iter == deviceReplyMap.end()) {
|
||||||
|
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||||
|
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceReplyInfo *info = &(iter->second);
|
||||||
|
|
||||||
|
if (info->delayCycles != 0) {
|
||||||
|
|
||||||
|
if (info->periodic != false) {
|
||||||
|
info->delayCycles = info->maxDelayCycles;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
info->delayCycles = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = interpretDeviceReply(foundId, receivedData);
|
||||||
|
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
// Report failed interpretation to FDIR.
|
||||||
|
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
||||||
|
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
|
||||||
|
}
|
||||||
|
replyToReply(iter, result);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Other completion failure messages are created by timeout.
|
||||||
|
// Powering down the device might take some time during which periodic
|
||||||
|
// replies may still come in.
|
||||||
|
if (mode != _MODE_WAIT_OFF) {
|
||||||
|
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -675,7 +755,7 @@ ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress,
|
|||||||
|
|
||||||
void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
||||||
MessageQueueId_t sendTo, bool isCommand) {
|
MessageQueueId_t sendTo, bool isCommand) {
|
||||||
if (IPCStore == NULL || len == 0) {
|
if (IPCStore == nullptr or len == 0 or sendTo == MessageQueueIF::NO_QUEUE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
store_address_t address;
|
store_address_t address;
|
||||||
@ -686,18 +766,17 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandMessage message;
|
CommandMessage command;
|
||||||
|
|
||||||
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&message,
|
DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&command,
|
||||||
getObjectId(), address, isCommand);
|
getObjectId(), address, isCommand);
|
||||||
|
|
||||||
// this->DeviceHandlerCommand = CommandMessage::CMD_NONE;
|
result = commandQueue->sendMessage(sendTo, &command);
|
||||||
|
|
||||||
result = commandQueue->sendMessage(sendTo, &message);
|
|
||||||
|
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
IPCStore->deleteData(address);
|
IPCStore->deleteData(address);
|
||||||
//Silently discard data, this indicates heavy TM traffic which should not be increased by additional events.
|
// Silently discard data, this indicates heavy TM traffic which
|
||||||
|
// should not be increased by additional events.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,57 +805,6 @@ MessageQueueId_t DeviceHandlerBase::getCommandQueue() const {
|
|||||||
return commandQueue->getId();
|
return commandQueue->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::handleReply(const uint8_t* receivedData,
|
|
||||||
DeviceCommandId_t foundId, uint32_t foundLen) {
|
|
||||||
ReturnValue_t result;
|
|
||||||
DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId);
|
|
||||||
|
|
||||||
if (iter == deviceReplyMap.end()) {
|
|
||||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
|
||||||
triggerEvent(DEVICE_UNKNOWN_REPLY, foundId);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceReplyInfo *info = &(iter->second);
|
|
||||||
|
|
||||||
if (info->delayCycles != 0) {
|
|
||||||
|
|
||||||
if (info->periodic) {
|
|
||||||
info->delayCycles = info->maxDelayCycles;
|
|
||||||
} else {
|
|
||||||
info->delayCycles = 0;
|
|
||||||
}
|
|
||||||
result = interpretDeviceReply(foundId, receivedData);
|
|
||||||
if (result != RETURN_OK) {
|
|
||||||
//Report failed interpretation to FDIR.
|
|
||||||
replyRawReplyIfnotWiretapped(receivedData, foundLen);
|
|
||||||
triggerEvent(DEVICE_INTERPRETING_REPLY_FAILED, result, foundId);
|
|
||||||
}
|
|
||||||
replyToReply(iter, result);
|
|
||||||
} else {
|
|
||||||
//Other completion failure messages are created by timeout.
|
|
||||||
//Powering down the device might take some time during which periodic replies may still come in.
|
|
||||||
if (mode != _MODE_WAIT_OFF) {
|
|
||||||
triggerEvent(DEVICE_UNREQUESTED_REPLY, foundId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) {
|
|
||||||
// DeviceCommunicationIF *newCommunication = objectManager->get<
|
|
||||||
// DeviceCommunicationIF>(newChannelId);
|
|
||||||
//
|
|
||||||
// if (newCommunication != NULL) {
|
|
||||||
// ReturnValue_t result = newCommunication->reOpen(cookie, ioBoardAddress,
|
|
||||||
// maxDeviceReplyLen);
|
|
||||||
// if (result != RETURN_OK) {
|
|
||||||
// return result;
|
|
||||||
// }
|
|
||||||
// return RETURN_OK;
|
|
||||||
// }
|
|
||||||
// return RETURN_FAILED;
|
|
||||||
//}
|
|
||||||
|
|
||||||
void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
||||||
storedRawData = DeviceHandlerMessage::getStoreAddress(commandMessage);
|
storedRawData = DeviceHandlerMessage::getStoreAddress(commandMessage);
|
||||||
ReturnValue_t result = getStorageData(storedRawData, &rawPacket,
|
ReturnValue_t result = getStorageData(storedRawData, &rawPacket,
|
||||||
@ -793,6 +821,9 @@ void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
|
void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
|
||||||
|
if(powerSwitcher == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const uint8_t *switches;
|
const uint8_t *switches;
|
||||||
uint8_t numberOfSwitches = 0;
|
uint8_t numberOfSwitches = 0;
|
||||||
ReturnValue_t result = getSwitches(&switches, &numberOfSwitches);
|
ReturnValue_t result = getSwitches(&switches, &numberOfSwitches);
|
||||||
@ -807,9 +838,7 @@ void DeviceHandlerBase::commandSwitch(ReturnValue_t onOff) {
|
|||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::getSwitches(const uint8_t **switches,
|
ReturnValue_t DeviceHandlerBase::getSwitches(const uint8_t **switches,
|
||||||
uint8_t *numberOfSwitches) {
|
uint8_t *numberOfSwitches) {
|
||||||
*switches = &deviceSwitch;
|
return DeviceHandlerBase::NO_SWITCH;
|
||||||
*numberOfSwitches = 1;
|
|
||||||
return RETURN_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerBase::modeChanged(void) {
|
void DeviceHandlerBase::modeChanged(void) {
|
||||||
@ -845,6 +874,9 @@ uint32_t DeviceHandlerBase::getTransitionDelayMs(Mode_t modeFrom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) {
|
ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) {
|
||||||
|
if(powerSwitcher == nullptr) {
|
||||||
|
return NO_SWITCH;
|
||||||
|
}
|
||||||
uint8_t numberOfSwitches = 0;
|
uint8_t numberOfSwitches = 0;
|
||||||
const uint8_t *switches;
|
const uint8_t *switches;
|
||||||
|
|
||||||
@ -895,9 +927,9 @@ ReturnValue_t DeviceHandlerBase::checkModeCommand(Mode_t commandedMode,
|
|||||||
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
if ((commandedMode == MODE_ON) && (mode == MODE_OFF)
|
||||||
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
&& (deviceThermalStatePoolId != PoolVariableIF::NO_PARAMETER)) {
|
||||||
DataSet mySet;
|
DataSet mySet;
|
||||||
PoolVariable<int8_t> thermalState(deviceThermalStatePoolId, &mySet,
|
db_int8_t thermalState(deviceThermalStatePoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId, &mySet,
|
db_int8_t thermalRequest(deviceThermalRequestPoolId, &mySet,
|
||||||
PoolVariableIF::VAR_READ);
|
PoolVariableIF::VAR_READ);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -925,7 +957,7 @@ void DeviceHandlerBase::startTransition(Mode_t commandedMode,
|
|||||||
MODE_ON);
|
MODE_ON);
|
||||||
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
triggerEvent(CHANGING_MODE, commandedMode, commandedSubmode);
|
||||||
DataSet mySet;
|
DataSet mySet;
|
||||||
PoolVariable<int8_t> thermalRequest(deviceThermalRequestPoolId,
|
db_int8_t thermalRequest(deviceThermalRequestPoolId,
|
||||||
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
&mySet, PoolVariableIF::VAR_READ_WRITE);
|
||||||
mySet.read();
|
mySet.read();
|
||||||
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
if (thermalRequest != ThermalComponentIF::STATE_REQUEST_IGNORE) {
|
||||||
@ -1111,35 +1143,47 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, data);
|
DeviceTmReportingWrapper wrapper(getObjectId(), replyId, data);
|
||||||
if (iter->second.command != deviceCommandMap.end()) {//replies to a command
|
//replies to a command
|
||||||
|
if (iter->second.command != deviceCommandMap.end())
|
||||||
|
{
|
||||||
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
|
MessageQueueId_t queueId = iter->second.command->second.sendReplyTo;
|
||||||
|
|
||||||
if (queueId != NO_COMMANDER) {
|
if (queueId != NO_COMMANDER) {
|
||||||
//This may fail, but we'll ignore the fault.
|
//This may fail, but we'll ignore the fault.
|
||||||
actionHelper.reportData(queueId, replyId, data);
|
actionHelper.reportData(queueId, replyId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
//This check should make sure we get any TM but don't get anything doubled.
|
//This check should make sure we get any TM but don't get anything doubled.
|
||||||
if (wiretappingMode == TM && (requestedRawTraffic != queueId)) {
|
if (wiretappingMode == TM && (requestedRawTraffic != queueId)) {
|
||||||
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
||||||
} else if (forceDirectTm && (defaultRawReceiver != queueId)) {
|
}
|
||||||
|
else if (forceDirectTm and (defaultRawReceiver != queueId) and
|
||||||
// hiding of sender needed so the service will handle it as unexpected Data, no matter what state
|
(defaultRawReceiver != MessageQueueIF::NO_QUEUE))
|
||||||
//(progress or completed) it is in
|
{
|
||||||
|
// hiding of sender needed so the service will handle it as
|
||||||
|
// unexpected Data, no matter what state (progress or completed)
|
||||||
|
// it is in
|
||||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else { //unrequested/aperiodic replies
|
}
|
||||||
|
//unrequested/aperiodic replies
|
||||||
|
else
|
||||||
|
{
|
||||||
if (wiretappingMode == TM) {
|
if (wiretappingMode == TM) {
|
||||||
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
actionHelper.reportData(requestedRawTraffic, replyId, &wrapper);
|
||||||
} else if (forceDirectTm) {
|
}
|
||||||
// hiding of sender needed so the service will handle it as unexpected Data, no matter what state
|
else if (forceDirectTm and defaultRawReceiver !=
|
||||||
//(progress or completed) it is in
|
MessageQueueIF::NO_QUEUE)
|
||||||
|
{
|
||||||
|
// hiding of sender needed so the service will handle it as
|
||||||
|
// unexpected Data, no matter what state (progress or completed)
|
||||||
|
// it is in
|
||||||
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
actionHelper.reportData(defaultRawReceiver, replyId, &wrapper,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Try to cast to DataSet and commit data.
|
//Try to cast to GlobDataSet and commit data.
|
||||||
if (!neverInDataPool) {
|
if (!neverInDataPool) {
|
||||||
DataSet* dataSet = dynamic_cast<DataSet*>(data);
|
DataSet* dataSet = dynamic_cast<DataSet*>(data);
|
||||||
if (dataSet != NULL) {
|
if (dataSet != NULL) {
|
||||||
@ -1178,18 +1222,23 @@ void DeviceHandlerBase::buildInternalCommand(void) {
|
|||||||
if (mode == MODE_NORMAL) {
|
if (mode == MODE_NORMAL) {
|
||||||
result = buildNormalDeviceCommand(&deviceCommandId);
|
result = buildNormalDeviceCommand(&deviceCommandId);
|
||||||
if (result == BUSY) {
|
if (result == BUSY) {
|
||||||
|
//so we can track misconfigurations
|
||||||
sif::debug << std::hex << getObjectId()
|
sif::debug << std::hex << getObjectId()
|
||||||
<< ": DHB::buildInternalCommand busy" << std::endl; //so we can track misconfigurations
|
<< ": DHB::buildInternalCommand: Busy" << std::endl;
|
||||||
result = NOTHING_TO_SEND; //no need to report this
|
result = NOTHING_TO_SEND; //no need to report this
|
||||||
}
|
}
|
||||||
} else if (mode == MODE_RAW) {
|
}
|
||||||
|
else if (mode == MODE_RAW) {
|
||||||
result = buildChildRawCommand();
|
result = buildChildRawCommand();
|
||||||
deviceCommandId = RAW_COMMAND_ID;
|
deviceCommandId = RAW_COMMAND_ID;
|
||||||
} else if (mode & TRANSITION_MODE_CHILD_ACTION_MASK) {
|
}
|
||||||
|
else if (mode & TRANSITION_MODE_CHILD_ACTION_MASK) {
|
||||||
result = buildTransitionDeviceCommand(&deviceCommandId);
|
result = buildTransitionDeviceCommand(&deviceCommandId);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == NOTHING_TO_SEND) {
|
if (result == NOTHING_TO_SEND) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1288,4 +1337,15 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){
|
|||||||
void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
|
void DeviceHandlerBase::debugInterface(uint8_t positionTracker,
|
||||||
object_id_t objectId, uint32_t parameter) {}
|
object_id_t objectId, uint32_t parameter) {}
|
||||||
|
|
||||||
void DeviceHandlerBase::performOperationHook() {}
|
void DeviceHandlerBase::performOperationHook() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() {
|
||||||
|
// In this function, the task handle should be valid if the task
|
||||||
|
// was implemented correctly. We still check to be 1000 % sure :-)
|
||||||
|
if(executingTask != nullptr) {
|
||||||
|
pstIntervalMs = executingTask->getPeriodMs();
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
#ifndef DEVICEHANDLERBASE_H_
|
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||||
#define DEVICEHANDLERBASE_H_
|
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_
|
||||||
|
|
||||||
|
#include "DeviceHandlerIF.h"
|
||||||
|
#include "DeviceCommunicationIF.h"
|
||||||
|
#include "DeviceHandlerFailureIsolation.h"
|
||||||
|
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
|
#include "../tasks/PeriodicTaskIF.h"
|
||||||
#include "../tasks/ExecutableObjectIF.h"
|
#include "../tasks/ExecutableObjectIF.h"
|
||||||
#include "DeviceHandlerIF.h"
|
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
#include "../datapool/PoolVariableIF.h"
|
#include "../datapool/PoolVariableIF.h"
|
||||||
#include "DeviceCommunicationIF.h"
|
|
||||||
#include "../modes/HasModesIF.h"
|
#include "../modes/HasModesIF.h"
|
||||||
#include "../power/PowerSwitchIF.h"
|
#include "../power/PowerSwitchIF.h"
|
||||||
#include "../ipc/MessageQueueIF.h"
|
#include "../ipc/MessageQueueIF.h"
|
||||||
|
|
||||||
#include "../action/ActionHelper.h"
|
#include "../action/ActionHelper.h"
|
||||||
#include "../health/HealthHelper.h"
|
#include "../health/HealthHelper.h"
|
||||||
#include "../parameters/ParameterHelper.h"
|
#include "../parameters/ParameterHelper.h"
|
||||||
#include "../datapool/HkSwitchHelper.h"
|
#include "../datapool/HkSwitchHelper.h"
|
||||||
#include "DeviceHandlerFailureIsolation.h"
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -46,14 +47,16 @@ class StorageManagerIF;
|
|||||||
* If data has been received (GET_READ), the data will be interpreted.
|
* If data has been received (GET_READ), the data will be interpreted.
|
||||||
* The action for each step can be defined by the child class but as most
|
* The action for each step can be defined by the child class but as most
|
||||||
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
|
* device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure,
|
||||||
* a default implementation is provided. NOTE: RMAP is a standard which is used for FLP.
|
* a default implementation is provided.
|
||||||
|
* NOTE: RMAP is a standard which is used for FLP.
|
||||||
* RMAP communication is not mandatory for projects implementing the FSFW.
|
* RMAP communication is not mandatory for projects implementing the FSFW.
|
||||||
* However, the communication principles are similar to RMAP as there are
|
* However, the communication principles are similar to RMAP as there are
|
||||||
* two write and two send calls involved.
|
* two write and two send calls involved.
|
||||||
*
|
*
|
||||||
* Device handler instances should extend this class and implement the abstract functions.
|
* Device handler instances should extend this class and implement the abstract
|
||||||
* Components and drivers can send so called cookies which are used for communication
|
* functions. Components and drivers can send so called cookies which are used
|
||||||
* and contain information about the communcation (e.g. slave address for I2C or RMAP structs).
|
* for communication and contain information about the communcation (e.g. slave
|
||||||
|
* address for I2C or RMAP structs).
|
||||||
* The following abstract methods must be implemented by a device handler:
|
* The following abstract methods must be implemented by a device handler:
|
||||||
* 1. doStartUp()
|
* 1. doStartUp()
|
||||||
* 2. doShutDown()
|
* 2. doShutDown()
|
||||||
@ -100,12 +103,12 @@ public:
|
|||||||
* @param cmdQueueSize
|
* @param cmdQueueSize
|
||||||
*/
|
*/
|
||||||
DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication,
|
||||||
CookieIF * comCookie, uint8_t setDeviceSwitch,
|
CookieIF * comCookie, FailureIsolationBase* fdirInstance = nullptr,
|
||||||
uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER,
|
|
||||||
uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER,
|
|
||||||
FailureIsolationBase* fdirInstance = nullptr,
|
|
||||||
size_t cmdQueueSize = 20);
|
size_t cmdQueueSize = 20);
|
||||||
|
|
||||||
|
void setThermalStateRequestPoolIds(uint32_t thermalStatePoolId,
|
||||||
|
uint32_t thermalRequestPoolId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is the device handler base core component and is
|
* @brief This function is the device handler base core component and is
|
||||||
* called periodically.
|
* called periodically.
|
||||||
@ -150,11 +153,9 @@ public:
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t initialize();
|
virtual ReturnValue_t initialize();
|
||||||
|
/** Destructor. */
|
||||||
/**
|
|
||||||
* Destructor.
|
|
||||||
*/
|
|
||||||
virtual ~DeviceHandlerBase();
|
virtual ~DeviceHandlerBase();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief This is used to let the child class handle the transition from
|
* @brief This is used to let the child class handle the transition from
|
||||||
@ -232,8 +233,9 @@ protected:
|
|||||||
* Build the device command to send for a transitional mode.
|
* Build the device command to send for a transitional mode.
|
||||||
*
|
*
|
||||||
* This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW,
|
* This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW,
|
||||||
* @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp()
|
* @c _MODE_START_UP and @c _MODE_SHUT_DOWN. So it is used by doStartUp()
|
||||||
* and doShutDown() as well as doTransition()
|
* and doShutDown() as well as doTransition(), by setting those
|
||||||
|
* modes in the respective functions.
|
||||||
*
|
*
|
||||||
* A good idea is to implement a flag indicating a command has to be built
|
* A good idea is to implement a flag indicating a command has to be built
|
||||||
* and a variable containing the command number to be built
|
* and a variable containing the command number to be built
|
||||||
@ -321,12 +323,11 @@ protected:
|
|||||||
* - @c RETURN_FAILED when the reply could not be interpreted,
|
* - @c RETURN_FAILED when the reply could not be interpreted,
|
||||||
* e.g. logical errors or range violations occurred
|
* e.g. logical errors or range violations occurred
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
|
||||||
const uint8_t *packet) = 0;
|
const uint8_t *packet) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief fill the #deviceCommandMap
|
* @brief fill the #DeviceCommandMap and #DeviceReplyMap
|
||||||
* called by the initialize() of the base class
|
* called by the initialize() of the base class
|
||||||
* @details
|
* @details
|
||||||
* This is used to let the base class know which replies are expected.
|
* This is used to let the base class know which replies are expected.
|
||||||
@ -470,6 +471,18 @@ protected:
|
|||||||
virtual ReturnValue_t getSwitches(const uint8_t **switches,
|
virtual ReturnValue_t getSwitches(const uint8_t **switches,
|
||||||
uint8_t *numberOfSwitches);
|
uint8_t *numberOfSwitches);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is used to initialize the local housekeeping pool
|
||||||
|
* entries. The default implementation leaves the pool empty.
|
||||||
|
* @param localDataPoolMap
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
//virtual ReturnValue_t initializePoolEntries(
|
||||||
|
// LocalDataPool& localDataPoolMap) override;
|
||||||
|
|
||||||
|
/** Get the HK manager object handle */
|
||||||
|
//virtual LocalDataPoolManager* getHkManagerHandle() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Hook function for child handlers which is called once per
|
* @brief Hook function for child handlers which is called once per
|
||||||
* performOperation(). Default implementation is empty.
|
* performOperation(). Default implementation is empty.
|
||||||
@ -493,7 +506,7 @@ public:
|
|||||||
ReturnValue_t setHealth(HealthState health);
|
ReturnValue_t setHealth(HealthState health);
|
||||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||||
ParameterWrapper *parameterWrapper,
|
ParameterWrapper *parameterWrapper,
|
||||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
const ParameterWrapper *newValues, uint16_t startAtIndex) override;
|
||||||
/**
|
/**
|
||||||
* Implementation of ExecutableObjectIF function
|
* Implementation of ExecutableObjectIF function
|
||||||
*
|
*
|
||||||
@ -505,7 +518,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* The Returnvalues ID of this class, required by HasReturnvaluesIF
|
* The Returnvalues id of this class, required by HasReturnvaluesIF
|
||||||
*/
|
*/
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
|
static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE;
|
||||||
|
|
||||||
@ -527,114 +540,138 @@ protected:
|
|||||||
static const DeviceCommandId_t NO_COMMAND_ID = -2;
|
static const DeviceCommandId_t NO_COMMAND_ID = -2;
|
||||||
static const MessageQueueId_t NO_COMMANDER = 0;
|
static const MessageQueueId_t NO_COMMANDER = 0;
|
||||||
|
|
||||||
/**
|
/** Pointer to the raw packet that will be sent.*/
|
||||||
* Pointer to the raw packet that will be sent.
|
|
||||||
*/
|
|
||||||
uint8_t *rawPacket = nullptr;
|
uint8_t *rawPacket = nullptr;
|
||||||
/**
|
/** Size of the #rawPacket. */
|
||||||
* Size of the #rawPacket.
|
|
||||||
*/
|
|
||||||
uint32_t rawPacketLen = 0;
|
uint32_t rawPacketLen = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mode the device handler is currently in.
|
* The mode the device handler is currently in.
|
||||||
*
|
|
||||||
* This should never be changed directly but only with setMode()
|
* This should never be changed directly but only with setMode()
|
||||||
*/
|
*/
|
||||||
Mode_t mode;
|
Mode_t mode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The submode the device handler is currently in.
|
* The submode the device handler is currently in.
|
||||||
*
|
|
||||||
* This should never be changed directly but only with setMode()
|
* This should never be changed directly but only with setMode()
|
||||||
*/
|
*/
|
||||||
Submode_t submode;
|
Submode_t submode;
|
||||||
|
|
||||||
/**
|
/** This is the counter value from performOperation(). */
|
||||||
* This is the counter value from performOperation().
|
|
||||||
*/
|
|
||||||
uint8_t pstStep = 0;
|
uint8_t pstStep = 0;
|
||||||
|
uint32_t pstIntervalMs = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wiretapping flag:
|
* Wiretapping flag:
|
||||||
*
|
*
|
||||||
* indicates either that all raw messages to and from the device should be sent to #theOneWhoWantsToReadRawTraffic
|
* indicates either that all raw messages to and from the device should be
|
||||||
* or that all device TM should be downlinked to #theOneWhoWantsToReadRawTraffic
|
* sent to #defaultRawReceiver
|
||||||
|
* or that all device TM should be downlinked to #defaultRawReceiver.
|
||||||
*/
|
*/
|
||||||
enum WiretappingMode {
|
enum WiretappingMode {
|
||||||
OFF = 0, RAW = 1, TM = 2
|
OFF = 0, RAW = 1, TM = 2
|
||||||
} wiretappingMode;
|
} wiretappingMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message queue that accepts raw replies
|
* @brief A message queue that accepts raw replies
|
||||||
*
|
*
|
||||||
* Statically initialized in initialize() to a configurable object. Used when there is no method
|
* Statically initialized in initialize() to a configurable object.
|
||||||
* of finding a recipient, ie raw mode and reporting erreonous replies
|
* Used when there is no method of finding a recipient, ie raw mode and
|
||||||
|
* reporting erroneous replies
|
||||||
*/
|
*/
|
||||||
MessageQueueId_t defaultRawReceiver = 0;
|
MessageQueueId_t defaultRawReceiver = MessageQueueIF::NO_QUEUE;
|
||||||
|
|
||||||
store_address_t storedRawData;
|
store_address_t storedRawData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the message queue which wants to read all raw traffic
|
* @brief The message queue which wants to read all raw traffic
|
||||||
*
|
* If #isWiretappingActive all raw communication from and to the device
|
||||||
* if #isWiretappingActive all raw communication from and to the device will be sent to this queue
|
* will be sent to this queue
|
||||||
*/
|
*/
|
||||||
MessageQueueId_t requestedRawTraffic = 0;
|
MessageQueueId_t requestedRawTraffic = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* the object used to set power switches
|
|
||||||
*/
|
|
||||||
PowerSwitchIF *powerSwitcher = nullptr;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pointer to the IPCStore.
|
* Pointer to the IPCStore.
|
||||||
*
|
|
||||||
* This caches the pointer received from the objectManager in the constructor.
|
* This caches the pointer received from the objectManager in the constructor.
|
||||||
*/
|
*/
|
||||||
StorageManagerIF *IPCStore = nullptr;
|
StorageManagerIF *IPCStore = nullptr;
|
||||||
|
/** The comIF object ID is cached for the intialize() function */
|
||||||
/**
|
|
||||||
* cached for init
|
|
||||||
*/
|
|
||||||
object_id_t deviceCommunicationId;
|
object_id_t deviceCommunicationId;
|
||||||
|
/** Communication object used for device communication */
|
||||||
/**
|
|
||||||
* Communication object used for device communication
|
|
||||||
*/
|
|
||||||
DeviceCommunicationIF * communicationInterface = nullptr;
|
DeviceCommunicationIF * communicationInterface = nullptr;
|
||||||
|
/** Cookie used for communication */
|
||||||
/**
|
|
||||||
* Cookie used for communication
|
|
||||||
*/
|
|
||||||
CookieIF * comCookie;
|
CookieIF * comCookie;
|
||||||
|
|
||||||
|
/** Health helper for HasHealthIF */
|
||||||
|
HealthHelper healthHelper;
|
||||||
|
/** Mode helper for HasModesIF */
|
||||||
|
ModeHelper modeHelper;
|
||||||
|
/** Parameter helper for ReceivesParameterMessagesIF */
|
||||||
|
ParameterHelper parameterHelper;
|
||||||
|
/** Action helper for HasActionsIF */
|
||||||
|
ActionHelper actionHelper;
|
||||||
|
/** Housekeeping Manager */
|
||||||
|
//LocalDataPoolManager hkManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Information about commands
|
||||||
|
*/
|
||||||
struct DeviceCommandInfo {
|
struct DeviceCommandInfo {
|
||||||
bool isExecuting; //!< Indicates if the command is already executing.
|
//! Indicates if the command is already executing.
|
||||||
uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0.
|
bool isExecuting;
|
||||||
MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander.
|
//! Dynamic value to indicate how many replies are expected.
|
||||||
|
//! Inititated with 0.
|
||||||
|
uint8_t expectedReplies;
|
||||||
|
//! if this is != NO_COMMANDER, DHB was commanded externally and shall
|
||||||
|
//! report everything to commander.
|
||||||
|
MessageQueueId_t sendReplyTo;
|
||||||
};
|
};
|
||||||
using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ;
|
using DeviceCommandMap = std::map<DeviceCommandId_t, DeviceCommandInfo> ;
|
||||||
|
/**
|
||||||
|
* Information about commands
|
||||||
|
*/
|
||||||
|
DeviceCommandMap deviceCommandMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Information about expected replies
|
* @brief Information about expected replies
|
||||||
*
|
* This is used to keep track of pending replies.
|
||||||
* This is used to keep track of pending replies
|
|
||||||
*/
|
*/
|
||||||
struct DeviceReplyInfo {
|
struct DeviceReplyInfo {
|
||||||
uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command.
|
//! The maximum number of cycles the handler should wait for a reply
|
||||||
uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected
|
//! to this command.
|
||||||
|
uint16_t maxDelayCycles;
|
||||||
|
//! The currently remaining cycles the handler should wait for a reply,
|
||||||
|
//! 0 means there is no reply expected
|
||||||
|
uint16_t delayCycles;
|
||||||
size_t replyLen = 0; //!< Expected size of the reply.
|
size_t replyLen = 0; //!< Expected size of the reply.
|
||||||
bool periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles
|
//! if this is !=0, the delayCycles will not be reset to 0 but to
|
||||||
DeviceCommandMap::iterator command; //!< The command that expects this reply.
|
//! maxDelayCycles
|
||||||
|
bool periodic = false;
|
||||||
|
//! The dataset used to access housekeeping data related to the
|
||||||
|
//! respective device reply. Will point to a dataset held by
|
||||||
|
//! the child handler (if one is specified)
|
||||||
|
// DataSetIF* dataSet = nullptr;
|
||||||
|
//! The command that expects this reply.
|
||||||
|
DeviceCommandMap::iterator command;
|
||||||
};
|
};
|
||||||
|
|
||||||
using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ;
|
using DeviceReplyMap = std::map<DeviceCommandId_t, DeviceReplyInfo> ;
|
||||||
using DeviceReplyIter = DeviceReplyMap::iterator;
|
using DeviceReplyIter = DeviceReplyMap::iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The MessageQueue used to receive device handler commands and to send replies.
|
* This map is used to check and track correct reception of all replies.
|
||||||
|
*
|
||||||
|
* It has multiple use:
|
||||||
|
* - It stores the information on pending replies. If a command is sent,
|
||||||
|
* the DeviceCommandInfo.count is incremented.
|
||||||
|
* - It is used to time-out missing replies. If a command is sent, the
|
||||||
|
* DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
|
||||||
|
* - It is queried to check if a reply from the device can be interpreted.
|
||||||
|
* scanForReply() returns the id of the command a reply was found for.
|
||||||
|
* The reply is ignored in the following cases:
|
||||||
|
* - No entry for the returned id was found
|
||||||
|
* - The deviceReplyInfo.delayCycles is == 0
|
||||||
*/
|
*/
|
||||||
|
DeviceReplyMap deviceReplyMap;
|
||||||
|
|
||||||
|
//! The MessageQueue used to receive device handler commands
|
||||||
|
//! and to send replies.
|
||||||
MessageQueueIF* commandQueue = nullptr;
|
MessageQueueIF* commandQueue = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -642,23 +679,14 @@ protected:
|
|||||||
*
|
*
|
||||||
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
||||||
*/
|
*/
|
||||||
uint32_t deviceThermalStatePoolId;
|
uint32_t deviceThermalStatePoolId = PoolVariableIF::NO_PARAMETER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is the datapool variable with the thermal request of the device
|
* this is the datapool variable with the thermal request of the device
|
||||||
*
|
*
|
||||||
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
* can be set to PoolVariableIF::NO_PARAMETER to deactivate thermal checking
|
||||||
*/
|
*/
|
||||||
uint32_t deviceThermalRequestPoolId;
|
uint32_t deviceThermalRequestPoolId = PoolVariableIF::NO_PARAMETER;
|
||||||
|
|
||||||
/**
|
|
||||||
* Taking care of the health
|
|
||||||
*/
|
|
||||||
HealthHelper healthHelper;
|
|
||||||
|
|
||||||
ModeHelper modeHelper;
|
|
||||||
|
|
||||||
ParameterHelper parameterHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional Error code
|
* Optional Error code
|
||||||
@ -676,13 +704,15 @@ protected:
|
|||||||
|
|
||||||
bool switchOffWasReported; //!< Indicates if SWITCH_WENT_OFF was already thrown.
|
bool switchOffWasReported; //!< Indicates if SWITCH_WENT_OFF was already thrown.
|
||||||
|
|
||||||
PeriodicTaskIF* executingTask = nullptr;//!< Pointer to the task which executes this component, is invalid before setTaskIF was called.
|
//! Pointer to the task which executes this component, is invalid
|
||||||
|
//! before setTaskIF was called.
|
||||||
|
PeriodicTaskIF* executingTask = nullptr;
|
||||||
|
|
||||||
static object_id_t powerSwitcherId; //!< Object which switches power on and off.
|
static object_id_t powerSwitcherId; //!< Object which switches power on and off.
|
||||||
|
|
||||||
static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default.
|
static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default.
|
||||||
|
|
||||||
static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault.
|
static object_id_t defaultFdirParentId; //!< Object which may be the root cause of an identified fault.
|
||||||
/**
|
/**
|
||||||
* Helper function to report a missed reply
|
* Helper function to report a missed reply
|
||||||
*
|
*
|
||||||
@ -730,28 +760,40 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW).
|
* Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW).
|
||||||
*
|
*
|
||||||
* If the transition is complete, the mode should be set to the target mode, which can be deduced from the current mode which is
|
* If the transition is complete, the mode should be set to the target mode,
|
||||||
|
* which can be deduced from the current mode which is
|
||||||
* [_MODE_TO_ON, _MODE_TO_NORMAL, _MODE_TO_RAW]
|
* [_MODE_TO_ON, _MODE_TO_NORMAL, _MODE_TO_RAW]
|
||||||
*
|
*
|
||||||
* The intended target submode is already set. The origin submode can be read in subModeFrom.
|
* The intended target submode is already set.
|
||||||
|
* The origin submode can be read in subModeFrom.
|
||||||
*
|
*
|
||||||
* If the transition can not be completed, the child class can try to reach an working mode by setting the mode either directly
|
* If the transition can not be completed, the child class can try to reach
|
||||||
* or setting the mode to an transitional mode (TO_ON, TO_NORMAL, TO_RAW) if the device needs to be reconfigured.
|
* an working mode by setting the mode either directly
|
||||||
|
* or setting the mode to an transitional mode (TO_ON, TO_NORMAL, TO_RAW)
|
||||||
|
* if the device needs to be reconfigured.
|
||||||
*
|
*
|
||||||
* If nothing works, the child class can wait for the timeout and the base class will reset the mode to the mode where the transition
|
* If nothing works, the child class can wait for the timeout and the base
|
||||||
|
* class will reset the mode to the mode where the transition
|
||||||
* originated from (the child should report the reason for the failed transition).
|
* originated from (the child should report the reason for the failed transition).
|
||||||
*
|
*
|
||||||
* The intended way to send commands is to set a flag (enum) indicating which command is to be sent here
|
* The intended way to send commands is to set a flag (enum) indicating
|
||||||
* and then to check in buildTransitionCommand() for the flag. This flag can also be used by doStartUp() and
|
* which command is to be sent here and then to check in
|
||||||
* doShutDown() to get a nice and clean implementation of buildTransitionCommand() without switching through modes.
|
* buildTransitionCommand() for the flag. This flag can also be used by
|
||||||
|
* doStartUp() and doShutDown() to get a nice and clean implementation of
|
||||||
|
* buildTransitionCommand() without switching through modes.
|
||||||
*
|
*
|
||||||
* When the the condition for the completion of the transition is met, the mode can be set, for example in the parseReply() function.
|
* When the the condition for the completion of the transition is met, the
|
||||||
|
* mode can be set, for example in the scanForReply() function.
|
||||||
*
|
*
|
||||||
* The default implementation goes into the target mode;
|
* The default implementation goes into the target mode directly.
|
||||||
*
|
*
|
||||||
* #transitionFailure can be set to a failure code indicating the reason for a failed transition
|
* #transitionFailure can be set to a failure code indicating the reason
|
||||||
|
* for a failed transition
|
||||||
*
|
*
|
||||||
* @param modeFrom the mode the transition originated from: [MODE_ON, MODE_NORMAL, MODE_RAW and _MODE_POWER_DOWN (if the mode changed from _MODE_START_UP to _MODE_TO_ON)]
|
* @param modeFrom
|
||||||
|
* The mode the transition originated from:
|
||||||
|
* [MODE_ON, MODE_NORMAL, MODE_RAW and _MODE_POWER_DOWN (if the mode changed
|
||||||
|
* from _MODE_START_UP to _MODE_TO_ON)]
|
||||||
* @param subModeFrom the subMode of modeFrom
|
* @param subModeFrom the subMode of modeFrom
|
||||||
*/
|
*/
|
||||||
virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom);
|
virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom);
|
||||||
@ -953,24 +995,11 @@ protected:
|
|||||||
bool commandIsExecuting(DeviceCommandId_t commandId);
|
bool commandIsExecuting(DeviceCommandId_t commandId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This map is used to check and track correct reception of all replies.
|
* set all switches returned by getSwitches()
|
||||||
*
|
*
|
||||||
* It has multiple use:
|
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
||||||
* - it stores the information on pending replies. If a command is sent, the DeviceCommandInfo.count is incremented.
|
|
||||||
* - it is used to time-out missing replies. If a command is sent, the DeviceCommandInfo.DelayCycles is set to MaxDelayCycles.
|
|
||||||
* - it is queried to check if a reply from the device can be interpreted. scanForReply() returns the id of the command a reply was found for.
|
|
||||||
* The reply is ignored in the following cases:
|
|
||||||
* - No entry for the returned id was found
|
|
||||||
* - The deviceReplyInfo.delayCycles is == 0
|
|
||||||
*/
|
*/
|
||||||
DeviceReplyMap deviceReplyMap;
|
void commandSwitch(ReturnValue_t onOff);
|
||||||
|
|
||||||
/**
|
|
||||||
* Information about commands
|
|
||||||
*/
|
|
||||||
DeviceCommandMap deviceCommandMap;
|
|
||||||
|
|
||||||
ActionHelper actionHelper;
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -997,15 +1026,16 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Info about the #cookie
|
* @brief Info about the #cookie
|
||||||
*
|
|
||||||
* Used to track the state of the communication
|
* Used to track the state of the communication
|
||||||
*/
|
*/
|
||||||
CookieInfo cookieInfo;
|
CookieInfo cookieInfo;
|
||||||
|
|
||||||
|
/** the object used to set power switches */
|
||||||
|
PowerSwitchIF *powerSwitcher = nullptr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for timing out mode transitions.
|
* @brief Used for timing out mode transitions.
|
||||||
*
|
|
||||||
* Set when setMode() is called.
|
* Set when setMode() is called.
|
||||||
*/
|
*/
|
||||||
uint32_t timeoutStart = 0;
|
uint32_t timeoutStart = 0;
|
||||||
@ -1016,11 +1046,12 @@ private:
|
|||||||
uint32_t childTransitionDelay;
|
uint32_t childTransitionDelay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mode the current transition originated from
|
* @brief The mode the current transition originated from
|
||||||
*
|
*
|
||||||
* This is private so the child can not change it and fuck up the timeouts
|
* This is private so the child can not change it and fuck up the timeouts
|
||||||
*
|
*
|
||||||
* IMPORTANT: This is not valid during _MODE_SHUT_DOWN and _MODE_START_UP!! (it is _MODE_POWER_DOWN during this modes)
|
* IMPORTANT: This is not valid during _MODE_SHUT_DOWN and _MODE_START_UP!!
|
||||||
|
* (it is _MODE_POWER_DOWN during this modes)
|
||||||
*
|
*
|
||||||
* is element of [MODE_ON, MODE_NORMAL, MODE_RAW]
|
* is element of [MODE_ON, MODE_NORMAL, MODE_RAW]
|
||||||
*/
|
*/
|
||||||
@ -1031,13 +1062,6 @@ private:
|
|||||||
*/
|
*/
|
||||||
Submode_t transitionSourceSubMode;
|
Submode_t transitionSourceSubMode;
|
||||||
|
|
||||||
/**
|
|
||||||
* the switch of the device
|
|
||||||
*
|
|
||||||
* for devices using two switches override getSwitches()
|
|
||||||
*/
|
|
||||||
const uint8_t deviceSwitch;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read the command queue
|
* read the command queue
|
||||||
*/
|
*/
|
||||||
@ -1135,12 +1159,6 @@ private:
|
|||||||
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data,
|
||||||
uint32_t *len);
|
uint32_t *len);
|
||||||
|
|
||||||
/**
|
|
||||||
* set all switches returned by getSwitches()
|
|
||||||
*
|
|
||||||
* @param onOff on == @c SWITCH_ON; off != @c SWITCH_ON
|
|
||||||
*/
|
|
||||||
void commandSwitch(ReturnValue_t onOff);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
|
* @param modeTo either @c MODE_ON, MODE_NORMAL or MODE_RAW NOTHING ELSE!!!
|
||||||
@ -1165,7 +1183,12 @@ private:
|
|||||||
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
|
ReturnValue_t switchCookieChannel(object_id_t newChannelId);
|
||||||
|
|
||||||
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
|
ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message);
|
||||||
|
|
||||||
|
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
|
|
||||||
|
void parseReply(const uint8_t* receivedData,
|
||||||
|
size_t receivedDataLen);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DEVICEHANDLERBASE_H_ */
|
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERBASE_H_ */
|
||||||
|
|
||||||
|
@ -1,19 +1,27 @@
|
|||||||
#include "DeviceHandlerBase.h"
|
|
||||||
#include "DeviceHandlerFailureIsolation.h"
|
#include "DeviceHandlerFailureIsolation.h"
|
||||||
|
|
||||||
|
#include "../devicehandlers/DeviceHandlerIF.h"
|
||||||
|
#include "../modes/HasModesIF.h"
|
||||||
#include "../health/HealthTableIF.h"
|
#include "../health/HealthTableIF.h"
|
||||||
#include "../power/Fuse.h"
|
#include "../power/Fuse.h"
|
||||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
#include "../thermal/ThermalComponentIF.h"
|
#include "../thermal/ThermalComponentIF.h"
|
||||||
|
|
||||||
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId = 0;
|
object_id_t DeviceHandlerFailureIsolation::powerConfirmationId =
|
||||||
|
objects::NO_OBJECT;
|
||||||
|
|
||||||
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner, object_id_t parent) :
|
DeviceHandlerFailureIsolation::DeviceHandlerFailureIsolation(object_id_t owner,
|
||||||
FailureIsolationBase(owner, parent), strangeReplyCount(MAX_STRANGE_REPLIES,
|
object_id_t parent) :
|
||||||
STRANGE_REPLIES_TIME_MS, parameterDomainBase++), missedReplyCount(
|
FailureIsolationBase(owner, parent),
|
||||||
MAX_MISSED_REPLY_COUNT, MISSED_REPLY_TIME_MS,
|
strangeReplyCount(DEFAULT_MAX_STRANGE_REPLIES,
|
||||||
parameterDomainBase++), recoveryCounter(MAX_REBOOT,
|
DEFAULT_STRANGE_REPLIES_TIME_MS,
|
||||||
REBOOT_TIME_MS, parameterDomainBase++), fdirState(NONE), powerConfirmation(
|
parameterDomainBase++),
|
||||||
0) {
|
missedReplyCount( DEFAULT_MAX_MISSED_REPLY_COUNT,
|
||||||
|
DEFAULT_MISSED_REPLY_TIME_MS,
|
||||||
|
parameterDomainBase++),
|
||||||
|
recoveryCounter(DEFAULT_MAX_REBOOT, DEFAULT_REBOOT_TIME_MS,
|
||||||
|
parameterDomainBase++),
|
||||||
|
fdirState(NONE) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {
|
DeviceHandlerFailureIsolation::~DeviceHandlerFailureIsolation() {
|
||||||
@ -68,10 +76,12 @@ ReturnValue_t DeviceHandlerFailureIsolation::eventReceived(EventMessage* event)
|
|||||||
break;
|
break;
|
||||||
//****Power*****
|
//****Power*****
|
||||||
case PowerSwitchIF::SWITCH_WENT_OFF:
|
case PowerSwitchIF::SWITCH_WENT_OFF:
|
||||||
|
if(powerConfirmation != MessageQueueIF::NO_QUEUE) {
|
||||||
result = sendConfirmationRequest(event, powerConfirmation);
|
result = sendConfirmationRequest(event, powerConfirmation);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
setFdirState(DEVICE_MIGHT_BE_OFF);
|
setFdirState(DEVICE_MIGHT_BE_OFF);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Fuse::FUSE_WENT_OFF:
|
case Fuse::FUSE_WENT_OFF:
|
||||||
//Not so good, because PCDU reacted.
|
//Not so good, because PCDU reacted.
|
||||||
@ -133,7 +143,7 @@ void DeviceHandlerFailureIsolation::decrementFaultCounters() {
|
|||||||
|
|
||||||
void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
||||||
clearFaultCounters();
|
clearFaultCounters();
|
||||||
if (!recoveryCounter.incrementAndCheck()) {
|
if (not recoveryCounter.incrementAndCheck()) {
|
||||||
startRecovery(reason);
|
startRecovery(reason);
|
||||||
} else {
|
} else {
|
||||||
setFaulty(reason);
|
setFaulty(reason);
|
||||||
@ -142,7 +152,8 @@ void DeviceHandlerFailureIsolation::handleRecovery(Event reason) {
|
|||||||
|
|
||||||
void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) {
|
void DeviceHandlerFailureIsolation::wasParentsFault(EventMessage* event) {
|
||||||
//We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset.
|
//We'll better ignore the SWITCH_WENT_OFF event and await a system-wide reset.
|
||||||
//This means, no fault message will come through until a MODE_ or HEALTH_INFO message comes through -> Is that ok?
|
//This means, no fault message will come through until a MODE_ or
|
||||||
|
//HEALTH_INFO message comes through -> Is that ok?
|
||||||
//Same issue in TxFailureIsolation!
|
//Same issue in TxFailureIsolation!
|
||||||
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
|
// if ((event->getEvent() == PowerSwitchIF::SWITCH_WENT_OFF)
|
||||||
// && (fdirState != RECOVERY_ONGOING)) {
|
// && (fdirState != RECOVERY_ONGOING)) {
|
||||||
@ -158,14 +169,16 @@ void DeviceHandlerFailureIsolation::clearFaultCounters() {
|
|||||||
ReturnValue_t DeviceHandlerFailureIsolation::initialize() {
|
ReturnValue_t DeviceHandlerFailureIsolation::initialize() {
|
||||||
ReturnValue_t result = FailureIsolationBase::initialize();
|
ReturnValue_t result = FailureIsolationBase::initialize();
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "DeviceHandlerFailureIsolation::initialize: Could not"
|
||||||
|
" initialize FailureIsolationBase." << std::endl;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
ConfirmsFailuresIF* power = objectManager->get<ConfirmsFailuresIF>(
|
ConfirmsFailuresIF* power = objectManager->get<ConfirmsFailuresIF>(
|
||||||
powerConfirmationId);
|
powerConfirmationId);
|
||||||
if (power == NULL) {
|
if (power != nullptr) {
|
||||||
return RETURN_FAILED;
|
|
||||||
}
|
|
||||||
powerConfirmation = power->getEventReceptionQueue();
|
powerConfirmation = power->getEventReceptionQueue();
|
||||||
|
}
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#ifndef FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
||||||
#define FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_
|
||||||
|
|
||||||
#include "../fdir/FaultCounter.h"
|
#include "../fdir/FaultCounter.h"
|
||||||
#include "../fdir/FailureIsolationBase.h"
|
#include "../fdir/FailureIsolationBase.h"
|
||||||
|
|
||||||
namespace Factory{
|
namespace Factory{
|
||||||
void setStaticFrameworkObjectIds();
|
void setStaticFrameworkObjectIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class DeviceHandlerFailureIsolation: public FailureIsolationBase {
|
class DeviceHandlerFailureIsolation: public FailureIsolationBase {
|
||||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||||
friend class Heater;
|
friend class Heater;
|
||||||
@ -20,22 +20,27 @@ public:
|
|||||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId,
|
||||||
ParameterWrapper *parameterWrapper,
|
ParameterWrapper *parameterWrapper,
|
||||||
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
const ParameterWrapper *newValues, uint16_t startAtIndex);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FaultCounter strangeReplyCount;
|
FaultCounter strangeReplyCount;
|
||||||
FaultCounter missedReplyCount;
|
FaultCounter missedReplyCount;
|
||||||
FaultCounter recoveryCounter;
|
FaultCounter recoveryCounter;
|
||||||
|
|
||||||
enum FDIRState {
|
enum FDIRState {
|
||||||
NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN
|
NONE, RECOVERY_ONGOING, DEVICE_MIGHT_BE_OFF, AWAIT_SHUTDOWN
|
||||||
};
|
};
|
||||||
FDIRState fdirState;
|
FDIRState fdirState;
|
||||||
MessageQueueId_t powerConfirmation;
|
|
||||||
|
MessageQueueId_t powerConfirmation = MessageQueueIF::NO_QUEUE;
|
||||||
static object_id_t powerConfirmationId;
|
static object_id_t powerConfirmationId;
|
||||||
static const uint32_t MAX_REBOOT = 1;
|
|
||||||
static const uint32_t REBOOT_TIME_MS = 180000;
|
static const uint32_t DEFAULT_MAX_REBOOT = 1;
|
||||||
static const uint32_t MAX_STRANGE_REPLIES = 10;
|
static const uint32_t DEFAULT_REBOOT_TIME_MS = 180000;
|
||||||
static const uint32_t STRANGE_REPLIES_TIME_MS = 10000;
|
static const uint32_t DEFAULT_MAX_STRANGE_REPLIES = 10;
|
||||||
static const uint32_t MAX_MISSED_REPLY_COUNT = 5;
|
static const uint32_t DEFAULT_STRANGE_REPLIES_TIME_MS = 10000;
|
||||||
static const uint32_t MISSED_REPLY_TIME_MS = 10000;
|
static const uint32_t DEFAULT_MAX_MISSED_REPLY_COUNT = 5;
|
||||||
|
static const uint32_t DEFAULT_MISSED_REPLY_TIME_MS = 10000;
|
||||||
|
|
||||||
virtual ReturnValue_t eventReceived(EventMessage* event);
|
virtual ReturnValue_t eventReceived(EventMessage* event);
|
||||||
virtual void eventConfirmed(EventMessage* event);
|
virtual void eventConfirmed(EventMessage* event);
|
||||||
void wasParentsFault(EventMessage* event);
|
void wasParentsFault(EventMessage* event);
|
||||||
@ -49,4 +54,4 @@ protected:
|
|||||||
bool isFdirInActionOrAreWeFaulty(EventMessage* event);
|
bool isFdirInActionOrAreWeFaulty(EventMessage* event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_ */
|
#endif /* FSFW_DEVICEHANDLERS_DEVICEHANDLERFAILUREISOLATION_H_ */
|
||||||
|
@ -8,13 +8,16 @@
|
|||||||
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
||||||
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
|
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
|
||||||
sizeof(ReporterRangeMatcher) };
|
sizeof(ReporterRangeMatcher) };
|
||||||
//If one checks registerListener calls, there are around 40 (to max 50) objects registering for certain events.
|
// If one checks registerListener calls, there are around 40 (to max 50)
|
||||||
//Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher. So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
// objects registering for certain events.
|
||||||
|
// Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher.
|
||||||
|
// So a good guess is 75 to a max of 100 pools required for each, which fits well.
|
||||||
|
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
|
||||||
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
||||||
|
|
||||||
EventManager::EventManager(object_id_t setObjectId) :
|
EventManager::EventManager(object_id_t setObjectId) :
|
||||||
SystemObject(setObjectId), eventReportQueue(NULL), mutex(NULL), factoryBackend(
|
SystemObject(setObjectId),
|
||||||
0, POOL_SIZES, N_ELEMENTS, false, true) {
|
factoryBackend(0, POOL_SIZES, N_ELEMENTS, false, true) {
|
||||||
mutex = MutexFactory::instance()->createMutex();
|
mutex = MutexFactory::instance()->createMutex();
|
||||||
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
eventReportQueue = QueueFactory::instance()->createMessageQueue(
|
||||||
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
|
||||||
@ -108,41 +111,45 @@ ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
//forward declaration, should be implemented by mission
|
|
||||||
const char* translateObject(object_id_t object);
|
|
||||||
const char * translateEvents(Event event);
|
|
||||||
|
|
||||||
void EventManager::printEvent(EventMessage* message) {
|
void EventManager::printEvent(EventMessage* message) {
|
||||||
const char *string = 0;
|
const char *string = 0;
|
||||||
switch (message->getSeverity()) {
|
switch (message->getSeverity()) {
|
||||||
case SEVERITY::INFO:
|
case SEVERITY::INFO:
|
||||||
// string = translateObject(message->getReporter());
|
#ifdef DEBUG_INFO_EVENT
|
||||||
// sif::info << "EVENT: ";
|
|
||||||
// if (string != 0) {
|
|
||||||
// sif::info << string;
|
|
||||||
// } else {
|
|
||||||
// sif::info << "0x" << std::hex << message->getReporter() << std::dec;
|
|
||||||
// }
|
|
||||||
// sif::info << " reported " << translateEvents(message->getEvent()) << " ("
|
|
||||||
// << std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
|
||||||
// << message->getParameter1() << " P2: 0x"
|
|
||||||
// << message->getParameter2() << std::dec << std::endl;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
string = translateObject(message->getReporter());
|
string = translateObject(message->getReporter());
|
||||||
sif::error << "EVENT: ";
|
sif::info << "EVENT: ";
|
||||||
if (string != 0) {
|
if (string != 0) {
|
||||||
sif::error << string;
|
sif::info << string;
|
||||||
} else {
|
} else {
|
||||||
sif::error << "0x" << std::hex << message->getReporter() << std::dec;
|
sif::info << "0x" << std::hex << message->getReporter() << std::dec;
|
||||||
}
|
}
|
||||||
sif::error << " reported " << translateEvents(message->getEvent()) << " ("
|
sif::info << " reported " << translateEvents(message->getEvent()) << " ("
|
||||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||||
<< message->getParameter1() << " P2: 0x"
|
<< message->getParameter1() << " P2: 0x"
|
||||||
<< message->getParameter2() << std::dec << std::endl;
|
<< message->getParameter2() << std::dec << std::endl;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
string = translateObject(message->getReporter());
|
||||||
|
sif::debug << "EventManager: ";
|
||||||
|
if (string != 0) {
|
||||||
|
sif::debug << string;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
|
||||||
|
}
|
||||||
|
sif::debug << " reported " << translateEvents(message->getEvent())
|
||||||
|
<< " (" << std::dec << message->getEventId() << ") "
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
|
||||||
|
<< ", P1 Dec: " << std::dec << message->getParameter1()
|
||||||
|
<< std::endl;
|
||||||
|
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
|
||||||
|
<< ", P2 Dec: " << std::dec << message->getParameter2()
|
||||||
|
<< std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -10,6 +10,12 @@
|
|||||||
#include "../ipc/MutexIF.h"
|
#include "../ipc/MutexIF.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
// forward declaration, should be implemented by mission
|
||||||
|
extern const char* translateObject(object_id_t object);
|
||||||
|
extern const char* translateEvents(Event event);
|
||||||
|
#endif
|
||||||
|
|
||||||
class EventManager: public EventManagerIF,
|
class EventManager: public EventManagerIF,
|
||||||
public ExecutableObjectIF,
|
public ExecutableObjectIF,
|
||||||
public SystemObject {
|
public SystemObject {
|
||||||
@ -36,11 +42,11 @@ public:
|
|||||||
ReturnValue_t performOperation(uint8_t opCode);
|
ReturnValue_t performOperation(uint8_t opCode);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
MessageQueueIF* eventReportQueue;
|
MessageQueueIF* eventReportQueue = nullptr;
|
||||||
|
|
||||||
std::map<MessageQueueId_t, EventMatchTree> listenerList;
|
std::map<MessageQueueId_t, EventMatchTree> listenerList;
|
||||||
|
|
||||||
MutexIF* mutex;
|
MutexIF* mutex = nullptr;
|
||||||
|
|
||||||
static const uint8_t N_POOLS = 3;
|
static const uint8_t N_POOLS = 3;
|
||||||
LocalPool<N_POOLS> factoryBackend;
|
LocalPool<N_POOLS> factoryBackend;
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
#include "../ipc/QueueFactory.h"
|
#include "../ipc/QueueFactory.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
FailureIsolationBase::FailureIsolationBase(object_id_t owner, object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
|
FailureIsolationBase::FailureIsolationBase(object_id_t owner,
|
||||||
eventQueue(NULL), ownerId(
|
object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
|
||||||
owner), owner(NULL), faultTreeParent(parent), parameterDomainBase(parameterDomainBase) {
|
ownerId(owner), faultTreeParent(parent),
|
||||||
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth, EventMessage::EVENT_MESSAGE_SIZE);
|
parameterDomainBase(parameterDomainBase) {
|
||||||
|
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
|
||||||
|
EventMessage::EVENT_MESSAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
FailureIsolationBase::~FailureIsolationBase() {
|
FailureIsolationBase::~FailureIsolationBase() {
|
||||||
@ -18,27 +20,36 @@ FailureIsolationBase::~FailureIsolationBase() {
|
|||||||
ReturnValue_t FailureIsolationBase::initialize() {
|
ReturnValue_t FailureIsolationBase::initialize() {
|
||||||
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
||||||
objects::EVENT_MANAGER);
|
objects::EVENT_MANAGER);
|
||||||
if (manager == NULL) {
|
if (manager == nullptr) {
|
||||||
|
sif::error << "FailureIsolationBase::initialize: Event Manager has not"
|
||||||
|
" been initialized!" << std::endl;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
ReturnValue_t result = manager->registerListener(eventQueue->getId());
|
ReturnValue_t result = manager->registerListener(eventQueue->getId());
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (ownerId != 0) {
|
if (ownerId != objects::NO_OBJECT) {
|
||||||
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), ownerId);
|
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), ownerId);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
owner = objectManager->get<HasHealthIF>(ownerId);
|
owner = objectManager->get<HasHealthIF>(ownerId);
|
||||||
if (owner == NULL) {
|
if (owner == nullptr) {
|
||||||
return RETURN_FAILED;
|
sif::error << "FailureIsolationBase::intialize: Owner object "
|
||||||
|
"invalid. Make sure it implements HasHealthIF" << std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (faultTreeParent != 0) {
|
if (faultTreeParent != objects::NO_OBJECT) {
|
||||||
ConfirmsFailuresIF* parentIF = objectManager->get<ConfirmsFailuresIF>(
|
ConfirmsFailuresIF* parentIF = objectManager->get<ConfirmsFailuresIF>(
|
||||||
faultTreeParent);
|
faultTreeParent);
|
||||||
if (parentIF == NULL) {
|
if (parentIF == nullptr) {
|
||||||
|
sif::error << "FailureIsolationBase::intialize: Parent object"
|
||||||
|
<< "invalid." << std::endl;
|
||||||
|
sif::error << "Make sure it implements ConfirmsFailuresIF."
|
||||||
|
<< std::endl;
|
||||||
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
eventQueue->setDefaultDestination(parentIF->getEventReceptionQueue());
|
eventQueue->setDefaultDestination(parentIF->getEventReceptionQueue());
|
||||||
@ -93,9 +104,9 @@ MessageQueueId_t FailureIsolationBase::getEventReceptionQueue() {
|
|||||||
ReturnValue_t FailureIsolationBase::sendConfirmationRequest(EventMessage* event,
|
ReturnValue_t FailureIsolationBase::sendConfirmationRequest(EventMessage* event,
|
||||||
MessageQueueId_t destination) {
|
MessageQueueId_t destination) {
|
||||||
event->setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
event->setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
||||||
if (destination != 0) {
|
if (destination != MessageQueueIF::NO_QUEUE) {
|
||||||
return eventQueue->sendMessage(destination, event);
|
return eventQueue->sendMessage(destination, event);
|
||||||
} else if (faultTreeParent != 0) {
|
} else if (faultTreeParent != objects::NO_OBJECT) {
|
||||||
return eventQueue->sendToDefault(event);
|
return eventQueue->sendToDefault(event);
|
||||||
}
|
}
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
|
@ -17,18 +17,25 @@ public:
|
|||||||
static const Event FDIR_CHANGED_STATE = MAKE_EVENT(1, SEVERITY::INFO); //!< FDIR has an internal state, which changed from par2 (oldState) to par1 (newState).
|
static const Event FDIR_CHANGED_STATE = MAKE_EVENT(1, SEVERITY::INFO); //!< FDIR has an internal state, which changed from par2 (oldState) to par1 (newState).
|
||||||
static const Event FDIR_STARTS_RECOVERY = MAKE_EVENT(2, SEVERITY::MEDIUM); //!< FDIR tries to restart device. Par1: event that caused recovery.
|
static const Event FDIR_STARTS_RECOVERY = MAKE_EVENT(2, SEVERITY::MEDIUM); //!< FDIR tries to restart device. Par1: event that caused recovery.
|
||||||
static const Event FDIR_TURNS_OFF_DEVICE = MAKE_EVENT(3, SEVERITY::MEDIUM); //!< FDIR turns off device. Par1: event that caused recovery.
|
static const Event FDIR_TURNS_OFF_DEVICE = MAKE_EVENT(3, SEVERITY::MEDIUM); //!< FDIR turns off device. Par1: event that caused recovery.
|
||||||
FailureIsolationBase(object_id_t owner, object_id_t parent = 0,
|
|
||||||
|
FailureIsolationBase(object_id_t owner,
|
||||||
|
object_id_t parent = objects::NO_OBJECT,
|
||||||
uint8_t messageDepth = 10, uint8_t parameterDomainBase = 0xF0);
|
uint8_t messageDepth = 10, uint8_t parameterDomainBase = 0xF0);
|
||||||
|
|
||||||
virtual ~FailureIsolationBase();
|
virtual ~FailureIsolationBase();
|
||||||
virtual ReturnValue_t initialize();
|
virtual ReturnValue_t initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is called by the DHB in performOperation()
|
||||||
|
*/
|
||||||
void checkForFailures();
|
void checkForFailures();
|
||||||
MessageQueueId_t getEventReceptionQueue();
|
MessageQueueId_t getEventReceptionQueue() override;
|
||||||
virtual void triggerEvent(Event event, uint32_t parameter1 = 0,
|
virtual void triggerEvent(Event event, uint32_t parameter1 = 0,
|
||||||
uint32_t parameter2 = 0);
|
uint32_t parameter2 = 0);
|
||||||
protected:
|
protected:
|
||||||
MessageQueueIF* eventQueue;
|
MessageQueueIF* eventQueue = nullptr;
|
||||||
object_id_t ownerId;
|
object_id_t ownerId;
|
||||||
HasHealthIF* owner;
|
HasHealthIF* owner = nullptr;
|
||||||
object_id_t faultTreeParent;
|
object_id_t faultTreeParent;
|
||||||
uint8_t parameterDomainBase;
|
uint8_t parameterDomainBase;
|
||||||
void setOwnerHealth(HasHealthIF::HealthState health);
|
void setOwnerHealth(HasHealthIF::HealthState health);
|
||||||
@ -38,7 +45,7 @@ protected:
|
|||||||
virtual ReturnValue_t confirmFault(EventMessage* event);
|
virtual ReturnValue_t confirmFault(EventMessage* event);
|
||||||
virtual void decrementFaultCounters() = 0;
|
virtual void decrementFaultCounters() = 0;
|
||||||
ReturnValue_t sendConfirmationRequest(EventMessage* event,
|
ReturnValue_t sendConfirmationRequest(EventMessage* event,
|
||||||
MessageQueueId_t destination = 0);
|
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
|
||||||
void throwFdirEvent(Event event, uint32_t parameter1 = 0,
|
void throwFdirEvent(Event event, uint32_t parameter1 = 0,
|
||||||
uint32_t parameter2 = 0);
|
uint32_t parameter2 = 0);
|
||||||
private:
|
private:
|
||||||
|
@ -1,12 +1,27 @@
|
|||||||
#ifndef HASPARAMETERSIF_H_
|
#ifndef FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||||
#define HASPARAMETERSIF_H_
|
#define FSFW_PARAMETERS_HASPARAMETERSIF_H_
|
||||||
|
|
||||||
#include "ParameterWrapper.h"
|
#include "../parameters/ParameterWrapper.h"
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/** Each parameter is identified with a unique parameter ID */
|
||||||
typedef uint32_t ParameterId_t;
|
typedef uint32_t ParameterId_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This interface is used by components which have modifiable
|
||||||
|
* parameters, e.g. atittude controllers
|
||||||
|
* @details
|
||||||
|
* Each parameter has a unique parameter ID. The first byte of the parameter
|
||||||
|
* ID is the domain ID which can be used to identify unqiue spacecraft domains
|
||||||
|
* (e.g. control and sensor domain in the AOCS controller).
|
||||||
|
*
|
||||||
|
* The second and third byte represent the matrix ID, which can represent
|
||||||
|
* a 8-bit row and column number and the last byte...
|
||||||
|
*
|
||||||
|
* Yeah, it it matrix ID oder parameter ID now and is index a 16 bit number
|
||||||
|
* of a 8 bit number now?
|
||||||
|
*/
|
||||||
class HasParametersIF {
|
class HasParametersIF {
|
||||||
public:
|
public:
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF;
|
static const uint8_t INTERFACE_ID = CLASS_ID::HAS_PARAMETERS_IF;
|
||||||
@ -32,13 +47,11 @@ public:
|
|||||||
return (domainId << 24) + (parameterId << 8) + index;
|
return (domainId << 24) + (parameterId << 8) + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~HasParametersIF() {
|
virtual ~HasParametersIF() {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Always set parameter before checking newValues!
|
* Always set parameter before checking newValues!
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param domainId
|
* @param domainId
|
||||||
* @param parameterId
|
* @param parameterId
|
||||||
* @param parameterWrapper
|
* @param parameterWrapper
|
||||||
@ -51,4 +64,4 @@ public:
|
|||||||
const ParameterWrapper *newValues, uint16_t startAtIndex) = 0;
|
const ParameterWrapper *newValues, uint16_t startAtIndex) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* HASPARAMETERSIF_H_ */
|
#endif /* FSFW_PARAMETERS_HASPARAMETERSIF_H_ */
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
#include "../objectmanager/ObjectManagerIF.h"
|
|
||||||
#include "ParameterHelper.h"
|
#include "ParameterHelper.h"
|
||||||
#include "ParameterMessage.h"
|
#include "ParameterMessage.h"
|
||||||
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) :
|
ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) :
|
||||||
owner(owner), storage(NULL) {
|
owner(owner) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ParameterHelper::~ParameterHelper() {
|
ParameterHelper::~ParameterHelper() {
|
||||||
}
|
}
|
||||||
@ -28,7 +26,6 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
case ParameterMessage::CMD_PARAMETER_LOAD: {
|
||||||
|
|
||||||
uint8_t domain = HasParametersIF::getDomain(
|
uint8_t domain = HasParametersIF::getDomain(
|
||||||
ParameterMessage::getParameterId(message));
|
ParameterMessage::getParameterId(message));
|
||||||
uint16_t parameterId = HasParametersIF::getMatrixId(
|
uint16_t parameterId = HasParametersIF::getMatrixId(
|
||||||
@ -36,12 +33,14 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) {
|
|||||||
uint8_t index = HasParametersIF::getIndex(
|
uint8_t index = HasParametersIF::getIndex(
|
||||||
ParameterMessage::getParameterId(message));
|
ParameterMessage::getParameterId(message));
|
||||||
|
|
||||||
const uint8_t *storedStream;
|
const uint8_t *storedStream = nullptr;
|
||||||
size_t storedStreamSize;
|
size_t storedStreamSize = 0;
|
||||||
result = storage->getData(
|
result = storage->getData(
|
||||||
ParameterMessage::getStoreId(message), &storedStream,
|
ParameterMessage::getStoreId(message), &storedStream,
|
||||||
&storedStreamSize);
|
&storedStreamSize);
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
sif::error << "ParameterHelper::handleParameterMessage: Getting"
|
||||||
|
" store data failed for load command." << std::endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +124,8 @@ ReturnValue_t ParameterHelper::initialize() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason, Command_t initialCommand) {
|
void ParameterHelper::rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
||||||
|
Command_t initialCommand) {
|
||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
reply.setReplyRejected(reason, initialCommand);
|
reply.setReplyRejected(reason, initialCommand);
|
||||||
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
MessageQueueSenderIF::sendMessage(to, &reply, ownerQueueId);
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
#ifndef PARAMETERHELPER_H_
|
#ifndef FSFW_PARAMETERS_PARAMETERHELPER_H_
|
||||||
#define PARAMETERHELPER_H_
|
#define FSFW_PARAMETERS_PARAMETERHELPER_H_
|
||||||
|
|
||||||
#include "ParameterMessage.h"
|
#include "ParameterMessage.h"
|
||||||
#include "ReceivesParameterMessagesIF.h"
|
#include "ReceivesParameterMessagesIF.h"
|
||||||
|
#include "../ipc/MessageQueueIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Helper class to handle parameter messages.
|
||||||
|
* @details
|
||||||
|
* This class simplfies handling of parameter messages, which are sent
|
||||||
|
* to a class which implements ReceivesParameterMessagesIF.
|
||||||
|
*/
|
||||||
class ParameterHelper {
|
class ParameterHelper {
|
||||||
public:
|
public:
|
||||||
ParameterHelper(ReceivesParameterMessagesIF *owner);
|
ParameterHelper(ReceivesParameterMessagesIF *owner);
|
||||||
@ -15,13 +22,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
ReceivesParameterMessagesIF *owner;
|
ReceivesParameterMessagesIF *owner;
|
||||||
|
|
||||||
MessageQueueId_t ownerQueueId;
|
MessageQueueId_t ownerQueueId = MessageQueueIF::NO_QUEUE;
|
||||||
|
|
||||||
StorageManagerIF *storage;
|
StorageManagerIF *storage = nullptr;
|
||||||
|
|
||||||
ReturnValue_t sendParameter(MessageQueueId_t to, uint32_t id, const ParameterWrapper *description);
|
ReturnValue_t sendParameter(MessageQueueId_t to, uint32_t id,
|
||||||
|
const ParameterWrapper *description);
|
||||||
|
|
||||||
void rejectCommand(MessageQueueId_t to, ReturnValue_t reason, Command_t initialCommand);
|
void rejectCommand(MessageQueueId_t to, ReturnValue_t reason,
|
||||||
|
Command_t initialCommand);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARAMETERHELPER_H_ */
|
#endif /* FSFW_PARAMETERS_PARAMETERHELPER_H_ */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include "ParameterMessage.h"
|
#include "../parameters/ParameterMessage.h"
|
||||||
#include "../objectmanager/ObjectManagerIF.h"
|
#include "../objectmanager/ObjectManagerIF.h"
|
||||||
|
|
||||||
ParameterId_t ParameterMessage::getParameterId(const CommandMessage* message) {
|
ParameterId_t ParameterMessage::getParameterId(const CommandMessage* message) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef PARAMETERMESSAGE_H_
|
#ifndef FSFW_PARAMETERS_PARAMETERMESSAGE_H_
|
||||||
#define PARAMETERMESSAGE_H_
|
#define FSFW_PARAMETERS_PARAMETERMESSAGE_H_
|
||||||
|
|
||||||
#include "../ipc/CommandMessage.h"
|
|
||||||
#include "HasParametersIF.h"
|
#include "HasParametersIF.h"
|
||||||
|
#include "../ipc/CommandMessage.h"
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
|
|
||||||
class ParameterMessage {
|
class ParameterMessage {
|
||||||
@ -26,4 +26,4 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARAMETERMESSAGE_H_ */
|
#endif /* FSFW_PARAMETERS_PARAMETERMESSAGE_H_ */
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
#include "ParameterWrapper.h"
|
#include "ParameterWrapper.h"
|
||||||
|
|
||||||
ParameterWrapper::ParameterWrapper() :
|
ParameterWrapper::ParameterWrapper() :
|
||||||
pointsToStream(false), type(Type::UNKNOWN_TYPE), rows(0), columns(0), data(
|
pointsToStream(false), type(Type::UNKNOWN_TYPE) {
|
||||||
NULL), readonlyData(NULL) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
||||||
void *data) :
|
void *data) :
|
||||||
pointsToStream(false), type(type), rows(rows), columns(columns), data(
|
pointsToStream(false), type(type), rows(rows), columns(columns),
|
||||||
data), readonlyData(data) {
|
data(data), readonlyData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
||||||
const void *data) :
|
const void *data) :
|
||||||
pointsToStream(false), type(type), rows(rows), columns(columns), data(
|
pointsToStream(false), type(type), rows(rows), columns(columns),
|
||||||
NULL), readonlyData(data) {
|
data(nullptr), readonlyData(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterWrapper::~ParameterWrapper() {
|
ParameterWrapper::~ParameterWrapper() {
|
||||||
@ -141,6 +140,7 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ReturnValue_t ParameterWrapper::deSerialize(const uint8_t **buffer,
|
ReturnValue_t ParameterWrapper::deSerialize(const uint8_t **buffer,
|
||||||
size_t *size, Endianness streamEndianness) {
|
size_t *size, Endianness streamEndianness) {
|
||||||
return deSerialize(buffer, size, streamEndianness, 0);
|
return deSerialize(buffer, size, streamEndianness, 0);
|
||||||
@ -184,16 +184,16 @@ ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize,
|
|||||||
return SerializeIF::STREAM_TOO_SHORT;
|
return SerializeIF::STREAM_TOO_SHORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = NULL;
|
data = nullptr;
|
||||||
readonlyData = stream;
|
readonlyData = stream;
|
||||||
pointsToStream = true;
|
pointsToStream = true;
|
||||||
|
|
||||||
stream += dataSize;
|
stream += dataSize;
|
||||||
if (remainingStream != NULL) {
|
if (remainingStream != nullptr) {
|
||||||
*remainingStream = stream;
|
*remainingStream = stream;
|
||||||
}
|
}
|
||||||
streamSize -= dataSize;
|
streamSize -= dataSize;
|
||||||
if (remainingSize != NULL) {
|
if (remainingSize != nullptr) {
|
||||||
*remainingSize = streamSize;
|
*remainingSize = streamSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,15 +265,15 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from,
|
|||||||
result = UNKNOW_DATATYPE;
|
result = UNKNOW_DATATYPE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
//need a type to do arithmetic
|
//need a type to do arithmetic
|
||||||
uint8_t *toDataWithType = (uint8_t*) data;
|
uint8_t* typedData = static_cast<uint8_t*>(data);
|
||||||
for (uint8_t fromRow = 0; fromRow < from->rows; fromRow++) {
|
for (uint8_t fromRow = 0; fromRow < from->rows; fromRow++) {
|
||||||
memcpy(
|
size_t offset = (((startingRow + fromRow) * columns) +
|
||||||
toDataWithType
|
startingColumn) * typeSize;
|
||||||
+ (((startingRow + fromRow) * columns)
|
std::memcpy(typedData + offset, from->readonlyData,
|
||||||
+ startingColumn) * typeSize,
|
typeSize * from->columns);
|
||||||
from->readonlyData, typeSize * from->columns);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
#ifndef PARAMETERWRAPPER_H_
|
#ifndef FSFW_PARAMETERS_PARAMETERWRAPPER_H_
|
||||||
#define PARAMETERWRAPPER_H_
|
#define FSFW_PARAMETERS_PARAMETERWRAPPER_H_
|
||||||
|
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include "../serialize/SerializeAdapter.h"
|
#include "../serialize/SerializeAdapter.h"
|
||||||
#include "../serialize/SerializeIF.h"
|
#include "../serialize/SerializeIF.h"
|
||||||
#include <stddef.h>
|
|
||||||
#include "../globalfunctions/Type.h"
|
#include "../globalfunctions/Type.h"
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* @details
|
||||||
|
*/
|
||||||
class ParameterWrapper: public SerializeIF {
|
class ParameterWrapper: public SerializeIF {
|
||||||
friend class DataPoolParameterWrapper;
|
friend class DataPoolParameterWrapper;
|
||||||
public:
|
public:
|
||||||
@ -36,32 +40,21 @@ public:
|
|||||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
Endianness streamEndianness, uint16_t startWritingAtIndex = 0);
|
Endianness streamEndianness, uint16_t startWritingAtIndex = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific parameter value by supplying the row and the column.
|
||||||
|
* @tparam T Type of target data
|
||||||
|
* @param value [out] Pointer to storage location
|
||||||
|
* @param row
|
||||||
|
* @param column
|
||||||
|
* @return
|
||||||
|
* -@c RETURN_OK if element was retrieved successfully
|
||||||
|
* -@c NOT_SET data has not been set yet
|
||||||
|
* -@c DATATYPE_MISSMATCH Invalid supplied type
|
||||||
|
* -@c OUT_OF_BOUNDS Invalid row and/or column.
|
||||||
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ReturnValue_t getElement(T *value, uint8_t row = 0, uint8_t column = 0) const {
|
ReturnValue_t getElement(T *value, uint8_t row = 0,
|
||||||
if (readonlyData == NULL){
|
uint8_t column = 0) const;
|
||||||
return NOT_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PodTypeConversion<T>::type != type) {
|
|
||||||
return DATATYPE_MISSMATCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((row >= rows) || (column >= columns)) {
|
|
||||||
return OUT_OF_BOUNDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pointsToStream) {
|
|
||||||
const uint8_t *streamWithtype = (const uint8_t *) readonlyData;
|
|
||||||
streamWithtype += (row * columns + column) * type.getSize();
|
|
||||||
int32_t size = type.getSize();
|
|
||||||
return SerializeAdapter::deSerialize(value, &streamWithtype,
|
|
||||||
&size, true);
|
|
||||||
} else {
|
|
||||||
const T *dataWithType = (const T *) readonlyData;
|
|
||||||
*value = dataWithType[row * columns + column];
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void set(T *data, uint8_t rows, uint8_t columns) {
|
void set(T *data, uint8_t rows, uint8_t columns) {
|
||||||
@ -111,21 +104,22 @@ public:
|
|||||||
void setMatrix(const T& member) {
|
void setMatrix(const T& member) {
|
||||||
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
|
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
|
ReturnValue_t set(const uint8_t *stream, size_t streamSize,
|
||||||
const uint8_t **remainingStream = NULL, size_t *remainingSize =
|
const uint8_t **remainingStream = nullptr,
|
||||||
NULL);
|
size_t *remainingSize = nullptr);
|
||||||
|
|
||||||
ReturnValue_t copyFrom(const ParameterWrapper *from,
|
ReturnValue_t copyFrom(const ParameterWrapper *from,
|
||||||
uint16_t startWritingAtIndex);
|
uint16_t startWritingAtIndex);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool pointsToStream;
|
bool pointsToStream = false;
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
uint8_t rows;
|
uint8_t rows = 0;
|
||||||
uint8_t columns;
|
uint8_t columns = 0;
|
||||||
void *data;
|
void *data = nullptr;
|
||||||
const void *readonlyData;
|
const void *readonlyData = nullptr;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ReturnValue_t serializeData(uint8_t** buffer, size_t* size,
|
ReturnValue_t serializeData(uint8_t** buffer, size_t* size,
|
||||||
@ -136,4 +130,33 @@ private:
|
|||||||
const void *from, uint8_t fromRows, uint8_t fromColumns);
|
const void *from, uint8_t fromRows, uint8_t fromColumns);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* PARAMETERWRAPPER_H_ */
|
template <typename T>
|
||||||
|
inline ReturnValue_t ParameterWrapper::getElement(T *value, uint8_t row,
|
||||||
|
uint8_t column) const {
|
||||||
|
if (readonlyData == nullptr){
|
||||||
|
return NOT_SET;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PodTypeConversion<T>::type != type) {
|
||||||
|
return DATATYPE_MISSMATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((row >= rows) or (column >= columns)) {
|
||||||
|
return OUT_OF_BOUNDS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pointsToStream) {
|
||||||
|
const uint8_t *streamWithType = static_cast<const uint8_t*>(readonlyData);
|
||||||
|
streamWithType += (row * columns + column) * type.getSize();
|
||||||
|
int32_t size = type.getSize();
|
||||||
|
return SerializeAdapter::deSerialize(value, &streamWithType,
|
||||||
|
&size, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const T *dataWithType = static_cast<const T*>(readonlyData);
|
||||||
|
*value = dataWithType[row * columns + column];
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FSFW_PARAMETERS_PARAMETERWRAPPER_H_ */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef RECEIVESPARAMETERMESSAGESIF_H_
|
#ifndef FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_
|
||||||
#define RECEIVESPARAMETERMESSAGESIF_H_
|
#define FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_
|
||||||
|
|
||||||
|
|
||||||
#include "HasParametersIF.h"
|
#include "HasParametersIF.h"
|
||||||
@ -16,4 +16,4 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* RECEIVESPARAMETERMESSAGESIF_H_ */
|
#endif /* FSFW_PARAMETERS_RECEIVESPARAMETERMESSAGESIF_H_ */
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
#ifndef SERIALIZEIF_H_
|
#ifndef FSFW_SERIALIZE_SERIALIZEIF_H_
|
||||||
#define SERIALIZEIF_H_
|
#define FSFW_SERIALIZE_SERIALIZEIF_H_
|
||||||
|
|
||||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \defgroup serialize Serialization
|
* @defgroup serialize Serialization
|
||||||
* Contains serialisation services.
|
* Contains serialization services.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translation of objects into data streams.
|
* Translation of objects into data streams and from data streams.
|
||||||
* \ingroup serialize
|
* @ingroup serialize
|
||||||
*/
|
*/
|
||||||
class SerializeIF {
|
class SerializeIF {
|
||||||
public:
|
public:
|
||||||
@ -20,21 +20,65 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::SERIALIZE_IF;
|
static const uint8_t INTERFACE_ID = CLASS_ID::SERIALIZE_IF;
|
||||||
static const ReturnValue_t BUFFER_TOO_SHORT = MAKE_RETURN_CODE(1);
|
static const ReturnValue_t BUFFER_TOO_SHORT = MAKE_RETURN_CODE(1); // !< The given buffer in serialize is too short
|
||||||
static const ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(2);
|
static const ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(2); // !< The input stream in deserialize is too short
|
||||||
static const ReturnValue_t TOO_MANY_ELEMENTS = MAKE_RETURN_CODE(3);
|
static const ReturnValue_t TOO_MANY_ELEMENTS = MAKE_RETURN_CODE(3);// !< There are too many elements to be deserialized
|
||||||
|
|
||||||
virtual ~SerializeIF() {
|
virtual ~SerializeIF() {
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Function to serialize the object into a buffer with maxSize. Size represents the written amount.
|
||||||
|
* If a part of the buffer has been used already, size must be set to the used amount of bytes.
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
* Implementations of this function must increase the size variable and move the buffer pointer.
|
||||||
|
* MaxSize must be checked by implementations of this function
|
||||||
|
* and BUFFER_TOO_SHORT has to be returned if size would be larger than maxSize.
|
||||||
|
*
|
||||||
|
* Custom implementations might use additional return values.
|
||||||
|
*
|
||||||
|
* @param[in/out] buffer Buffer to serialize into, will be set to the current write location
|
||||||
|
* @param[in/out] size Size that has been used in the buffer already, will be increased by the function
|
||||||
|
* @param[in] maxSize The size of the buffer that is allowed to be used for serialize.
|
||||||
|
* @param[in] streamEndianness Endianness of the serialized data according to SerializeIF::Endianness
|
||||||
|
* @return
|
||||||
|
* - @¢ BUFFER_TOO_SHORT The given buffer in is too short
|
||||||
|
* - @c RETURN_FAILED Generic error
|
||||||
|
* - @c RETURN_OK Successful serialization
|
||||||
|
*/
|
||||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||||
size_t maxSize, Endianness streamEndianness) const = 0;
|
size_t maxSize, Endianness streamEndianness) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size of a object if it would be serialized in a buffer
|
||||||
|
* @return Size of serialized object
|
||||||
|
*/
|
||||||
virtual size_t getSerializedSize() const = 0;
|
virtual size_t getSerializedSize() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Deserializes a object from a given buffer of given size.
|
||||||
|
*
|
||||||
|
* @details
|
||||||
|
* Buffer must be moved to the current read location by the implementation
|
||||||
|
* of this function. Size must be decreased by the implementation.
|
||||||
|
* Implementations are not allowed to alter the buffer as indicated by const pointer.
|
||||||
|
*
|
||||||
|
* Custom implementations might use additional return values.
|
||||||
|
*
|
||||||
|
* @param[in/out] buffer Buffer to deSerialize from. Will be moved by the function.
|
||||||
|
* @param[in/out] size Remaining size of the buffer to read from. Will be decreased by function.
|
||||||
|
* @param[in] streamEndianness Endianness as in according to SerializeIF::Endianness
|
||||||
|
* @return
|
||||||
|
* - @c STREAM_TOO_SHORT The input stream is too short to deSerialize the object
|
||||||
|
* - @c TOO_MANY_ELEMENTS The buffer has more inputs than expected
|
||||||
|
* - @c RETURN_FAILED Generic Error
|
||||||
|
* - @c RETURN_OK Successful deserialization
|
||||||
|
*/
|
||||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||||
Endianness streamEndianness) = 0;
|
Endianness streamEndianness) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SERIALIZEIF_H_ */
|
#endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#ifndef FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
#ifndef FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
||||||
#define FRAMEWORK_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
#define FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_
|
||||||
|
|
||||||
#include "../objectmanager/SystemObject.h"
|
#include "../objectmanager/SystemObject.h"
|
||||||
#include "../storagemanager/StorageManagerIF.h"
|
#include "../storagemanager/StorageManagerIF.h"
|
||||||
@ -345,4 +345,4 @@ private:
|
|||||||
void checkTimeout();
|
void checkTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* COMMANDINGSERVICEBASE_H_ */
|
#endif /* FSFW_TMTCSERVICES_COMMANDINGSERVICEBASE_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user