Merge branch 'master' into mueller_tcPacketBase
This commit is contained in:
commit
b2677ae040
@ -1,5 +1,6 @@
|
||||
#include "ActionHelper.h"
|
||||
#include "HasActionsIF.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
|
||||
ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) :
|
||||
|
@ -72,11 +72,15 @@ public:
|
||||
return tmp;
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
T& operator*(){
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
const T& operator*() const{
|
||||
return *value;
|
||||
}
|
||||
|
||||
T *operator->(){
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -27,14 +27,27 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Custom copy constructor which prevents setting the
|
||||
* underlying pointer wrong.
|
||||
* underlying pointer wrong. This function allocates memory!
|
||||
* @details This is a very heavy operation so try to avoid this!
|
||||
*
|
||||
*/
|
||||
DynamicFIFO(const DynamicFIFO& other): FIFOBase<T>(other),
|
||||
fifoVector(other.maxCapacity) {
|
||||
this->fifoVector = other.fifoVector;
|
||||
this->setContainer(fifoVector.data());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Custom assignment operator
|
||||
* @details This is a very heavy operation so try to avoid this!
|
||||
* @param other DyamicFIFO to copy from
|
||||
*/
|
||||
DynamicFIFO& operator=(const DynamicFIFO& other){
|
||||
FIFOBase<T>::operator=(other);
|
||||
this->fifoVector = other.fifoVector;
|
||||
this->setContainer(fifoVector.data());
|
||||
return *this;
|
||||
}
|
||||
private:
|
||||
std::vector<T> fifoVector;
|
||||
};
|
||||
|
@ -25,9 +25,21 @@ public:
|
||||
* @param other
|
||||
*/
|
||||
FIFO(const FIFO& other): FIFOBase<T>(other) {
|
||||
this->fifoArray = other.fifoArray;
|
||||
this->setContainer(fifoArray.data());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Custom assignment operator
|
||||
* @param other
|
||||
*/
|
||||
FIFO& operator=(const FIFO& other){
|
||||
FIFOBase<T>::operator=(other);
|
||||
this->fifoArray = other.fifoArray;
|
||||
this->setContainer(fifoArray.data());
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<T, capacity> fifoArray;
|
||||
};
|
||||
|
@ -1,15 +1,20 @@
|
||||
#ifndef FIXEDMAP_H_
|
||||
#define FIXEDMAP_H_
|
||||
#ifndef FSFW_CONTAINER_FIXEDMAP_H_
|
||||
#define FSFW_CONTAINER_FIXEDMAP_H_
|
||||
|
||||
#include "ArrayList.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* \ingroup container
|
||||
* @warning Iterators return a non-const key_t in the pair.
|
||||
* @warning A User is not allowed to change the key, otherwise the map is corrupted.
|
||||
* @ingroup container
|
||||
*/
|
||||
template<typename key_t, typename T>
|
||||
class FixedMap: public SerializeIF {
|
||||
static_assert (std::is_trivially_copyable<T>::value or std::is_base_of<SerializeIF, T>::value,
|
||||
"Types used in FixedMap must either be trivial copy-able or a derived Class from SerializeIF to be serialize-able");
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP;
|
||||
static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01);
|
||||
@ -47,15 +52,6 @@ public:
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Iterator begin() const {
|
||||
@ -70,7 +66,7 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) {
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
if (exists(key) == HasReturnvaluesIF::RETURN_OK) {
|
||||
return KEY_ALREADY_EXISTS;
|
||||
}
|
||||
@ -79,7 +75,7 @@ public:
|
||||
}
|
||||
theMap[_size].first = key;
|
||||
theMap[_size].second = value;
|
||||
if (storedValue != NULL) {
|
||||
if (storedValue != nullptr) {
|
||||
*storedValue = Iterator(&theMap[_size]);
|
||||
}
|
||||
++_size;
|
||||
@ -87,7 +83,7 @@ public:
|
||||
}
|
||||
|
||||
ReturnValue_t insert(std::pair<key_t, T> pair) {
|
||||
return insert(pair.fist, pair.second);
|
||||
return insert(pair.first, pair.second);
|
||||
}
|
||||
|
||||
ReturnValue_t exists(key_t key) const {
|
||||
@ -196,4 +192,4 @@ public:
|
||||
|
||||
};
|
||||
|
||||
#endif /* FIXEDMAP_H_ */
|
||||
#endif /* FSFW_CONTAINER_FIXEDMAP_H_ */
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
if (_size <= position) {
|
||||
return;
|
||||
}
|
||||
memmove(&theMap[position], &theMap[position + 1],
|
||||
memmove(static_cast<void*>(&theMap[position]), static_cast<void*>(&theMap[position + 1]),
|
||||
(_size - position - 1) * sizeof(std::pair<key_t,T>));
|
||||
--_size;
|
||||
}
|
||||
@ -68,15 +68,6 @@ public:
|
||||
Iterator(std::pair<key_t, T> *pair) :
|
||||
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair) {
|
||||
}
|
||||
|
||||
T operator*() {
|
||||
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
T *operator->() {
|
||||
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Iterator begin() const {
|
||||
@ -91,17 +82,17 @@ public:
|
||||
return _size;
|
||||
}
|
||||
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) {
|
||||
ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) {
|
||||
if (_size == theMap.maxSize()) {
|
||||
return MAP_FULL;
|
||||
}
|
||||
uint32_t position = findNicePlace(key);
|
||||
memmove(&theMap[position + 1], &theMap[position],
|
||||
memmove(static_cast<void*>(&theMap[position + 1]),static_cast<void*>(&theMap[position]),
|
||||
(_size - position) * sizeof(std::pair<key_t,T>));
|
||||
theMap[position].first = key;
|
||||
theMap[position].second = value;
|
||||
++_size;
|
||||
if (storedValue != NULL) {
|
||||
if (storedValue != nullptr) {
|
||||
*storedValue = Iterator(&theMap[position]);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -145,12 +136,6 @@ public:
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
//This is potentially unsafe
|
||||
// T *findValue(key_t key) const {
|
||||
// return &theMap[findFirstIndex(key)].second;
|
||||
// }
|
||||
|
||||
|
||||
Iterator find(key_t key) const {
|
||||
ReturnValue_t result = exists(key);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
|
@ -1,41 +0,0 @@
|
||||
#ifndef ISDERIVEDFROM_H_
|
||||
#define ISDERIVEDFROM_H_
|
||||
|
||||
template<typename D, typename B>
|
||||
class IsDerivedFrom {
|
||||
class No {
|
||||
};
|
||||
class Yes {
|
||||
No no[3];
|
||||
};
|
||||
|
||||
static Yes Test(B*); // declared, but not defined
|
||||
static No Test(... ); // declared, but not defined
|
||||
|
||||
public:
|
||||
enum {
|
||||
Is = sizeof(Test(static_cast<D*>(0))) == sizeof(Yes)
|
||||
};
|
||||
};
|
||||
|
||||
template<typename, typename>
|
||||
struct is_same {
|
||||
static bool const value = false;
|
||||
};
|
||||
|
||||
template<typename A>
|
||||
struct is_same<A, A> {
|
||||
static bool const value = true;
|
||||
};
|
||||
|
||||
|
||||
template<bool C, typename T = void>
|
||||
struct enable_if {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct enable_if<false, T> { };
|
||||
|
||||
|
||||
#endif /* ISDERIVEDFROM_H_ */
|
@ -1,96 +1,113 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_
|
||||
#define FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_
|
||||
#ifndef FSFW_CONTAINER_RINGBUFFERBASE_H_
|
||||
#define FSFW_CONTAINER_RINGBUFFERBASE_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
template<uint8_t N_READ_PTRS = 1>
|
||||
class RingBufferBase {
|
||||
public:
|
||||
RingBufferBase(uint32_t startAddress, uint32_t size, bool overwriteOld) :
|
||||
start(startAddress), write(startAddress), size(size), overwriteOld(overwriteOld) {
|
||||
RingBufferBase(size_t startAddress, const size_t size, bool overwriteOld) :
|
||||
start(startAddress), write(startAddress), size(size),
|
||||
overwriteOld(overwriteOld) {
|
||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||
read[count] = startAddress;
|
||||
}
|
||||
}
|
||||
ReturnValue_t readData(uint32_t amount, uint8_t n = 0) {
|
||||
if (availableReadData(n) >= amount) {
|
||||
incrementRead(amount, n);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
ReturnValue_t writeData(uint32_t amount) {
|
||||
if (availableWriteSpace() >= amount || overwriteOld) {
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
uint32_t availableReadData(uint8_t n = 0) const {
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
||||
uint32_t availableWriteSpace(uint8_t n = 0) const {
|
||||
//One less to avoid ambiguous full/empty problem.
|
||||
return (((read[n] + size) - write - 1) % size);
|
||||
}
|
||||
|
||||
virtual ~RingBufferBase() {}
|
||||
|
||||
bool isFull(uint8_t n = 0) {
|
||||
return (availableWriteSpace(n) == 0);
|
||||
}
|
||||
bool isEmpty(uint8_t n = 0) {
|
||||
return (availableReadData(n) == 0);
|
||||
return (getAvailableReadData(n) == 0);
|
||||
}
|
||||
virtual ~RingBufferBase() {
|
||||
|
||||
size_t getAvailableReadData(uint8_t n = 0) const {
|
||||
return ((write + size) - read[n]) % size;
|
||||
}
|
||||
uint32_t getRead(uint8_t n = 0) const {
|
||||
return read[n];
|
||||
size_t availableWriteSpace(uint8_t n = 0) const {
|
||||
//One less to avoid ambiguous full/empty problem.
|
||||
return (((read[n] + size) - write - 1) % size);
|
||||
}
|
||||
void setRead(uint32_t read, uint8_t n = 0) {
|
||||
if (read >= start && read < (start+size)) {
|
||||
this->read[n] = read;
|
||||
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
|
||||
size_t getMaxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
uint32_t getWrite() const {
|
||||
return write;
|
||||
}
|
||||
void setWrite(uint32_t write) {
|
||||
this->write = write;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
write = start;
|
||||
for (uint8_t count = 0; count < N_READ_PTRS; count++) {
|
||||
read[count] = start;
|
||||
}
|
||||
}
|
||||
uint32_t writeTillWrap() {
|
||||
|
||||
size_t writeTillWrap() {
|
||||
return (start + size) - write;
|
||||
}
|
||||
uint32_t readTillWrap(uint8_t n = 0) {
|
||||
|
||||
size_t readTillWrap(uint8_t n = 0) {
|
||||
return (start + size) - read[n];
|
||||
}
|
||||
uint32_t getStart() const {
|
||||
|
||||
size_t getStart() const {
|
||||
return start;
|
||||
}
|
||||
bool overwritesOld() const {
|
||||
return overwriteOld;
|
||||
}
|
||||
uint32_t maxSize() const {
|
||||
return size - 1;
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint32_t start;
|
||||
uint32_t write;
|
||||
uint32_t read[N_READ_PTRS];
|
||||
const uint32_t size;
|
||||
const size_t start;
|
||||
size_t write;
|
||||
size_t read[N_READ_PTRS];
|
||||
const size_t size;
|
||||
const bool overwriteOld;
|
||||
|
||||
void incrementWrite(uint32_t amount) {
|
||||
write = ((write + amount - start) % size) + start;
|
||||
}
|
||||
void incrementRead(uint32_t amount, uint8_t n = 0) {
|
||||
read[n] = ((read[n] + amount - start) % size) + start;
|
||||
}
|
||||
|
||||
ReturnValue_t readData(uint32_t amount, uint8_t n = 0) {
|
||||
if (getAvailableReadData(n) >= amount) {
|
||||
incrementRead(amount, n);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t writeData(uint32_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
incrementWrite(amount);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
size_t getRead(uint8_t n = 0) const {
|
||||
return read[n];
|
||||
}
|
||||
|
||||
void setRead(uint32_t read, uint8_t n = 0) {
|
||||
if (read >= start && read < (start+size)) {
|
||||
this->read[n] = read;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getWrite() const {
|
||||
return write;
|
||||
}
|
||||
|
||||
void setWrite(uint32_t write) {
|
||||
this->write = write;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_RINGBUFFERBASE_H_ */
|
||||
#endif /* FSFW_CONTAINER_RINGBUFFERBASE_H_ */
|
||||
|
30
container/SharedRingBuffer.cpp
Normal file
30
container/SharedRingBuffer.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "SharedRingBuffer.h"
|
||||
#include "../ipc/MutexFactory.h"
|
||||
#include "../ipc/MutexHelper.h"
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes):
|
||||
SystemObject(objectId), SimpleRingBuffer(size, overwriteOld,
|
||||
maxExcessBytes) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer,
|
||||
const size_t size, bool overwriteOld, size_t maxExcessBytes):
|
||||
SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld,
|
||||
maxExcessBytes) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::lockRingBufferMutex(
|
||||
MutexIF::TimeoutType timeoutType, dur_millis_t timeout) {
|
||||
return mutex->lockMutex(timeoutType, timeout);
|
||||
}
|
||||
|
||||
ReturnValue_t SharedRingBuffer::unlockRingBufferMutex() {
|
||||
return mutex->unlockMutex();
|
||||
}
|
||||
|
||||
MutexIF* SharedRingBuffer::getMutexHandle() const {
|
||||
return mutex;
|
||||
}
|
68
container/SharedRingBuffer.h
Normal file
68
container/SharedRingBuffer.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef FSFW_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
#define FSFW_CONTAINER_SHAREDRINGBUFFER_H_
|
||||
|
||||
#include "SimpleRingBuffer.h"
|
||||
#include "../ipc/MutexIF.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
|
||||
/**
|
||||
* @brief Ring buffer which can be shared among multiple objects
|
||||
* @details
|
||||
* This class offers a mutex to perform thread-safe operation on the ring
|
||||
* buffer. It is still up to the developer to actually perform the lock
|
||||
* and unlock operations.
|
||||
*/
|
||||
class SharedRingBuffer: public SystemObject,
|
||||
public SimpleRingBuffer {
|
||||
public:
|
||||
/**
|
||||
* This constructor allocates a new internal buffer with the supplied size.
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(object_id_t objectId, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes);
|
||||
|
||||
/**
|
||||
* This constructor takes an external buffer with the specified size.
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
*/
|
||||
SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size,
|
||||
bool overwriteOld, size_t maxExcessBytes);
|
||||
|
||||
/**
|
||||
* Unless a read-only constant value is read, all operations on the
|
||||
* shared ring buffer should be protected by calling this function.
|
||||
* @param timeoutType
|
||||
* @param timeout
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t lockRingBufferMutex(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t timeout);
|
||||
/**
|
||||
* Any locked mutex also has to be unlocked, otherwise, access to the
|
||||
* shared ring buffer will be blocked.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t unlockRingBufferMutex();
|
||||
|
||||
/**
|
||||
* The mutex handle can be accessed directly, for example to perform
|
||||
* the lock with the #MutexHelper for a RAII compliant lock operation.
|
||||
* @return
|
||||
*/
|
||||
MutexIF* getMutexHandle() const;
|
||||
private:
|
||||
MutexIF* mutex = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_CONTAINER_SHAREDRINGBUFFER_H_ */
|
@ -1,27 +1,69 @@
|
||||
#include "SimpleRingBuffer.h"
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld) :
|
||||
RingBufferBase<>(0, size, overwriteOld) {
|
||||
buffer = new uint8_t[size];
|
||||
SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes) :
|
||||
RingBufferBase<>(0, size, overwriteOld),
|
||||
maxExcessBytes(maxExcessBytes) {
|
||||
if(maxExcessBytes > size) {
|
||||
this->maxExcessBytes = size;
|
||||
}
|
||||
else {
|
||||
this->maxExcessBytes = maxExcessBytes;
|
||||
}
|
||||
buffer = new uint8_t[size + maxExcessBytes];
|
||||
}
|
||||
|
||||
SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size,
|
||||
bool overwriteOld):
|
||||
RingBufferBase<>(0, size, overwriteOld), buffer(buffer) {}
|
||||
|
||||
bool overwriteOld, size_t maxExcessBytes):
|
||||
RingBufferBase<>(0, size, overwriteOld), buffer(buffer) {
|
||||
if(maxExcessBytes > size) {
|
||||
this->maxExcessBytes = size;
|
||||
}
|
||||
else {
|
||||
this->maxExcessBytes = maxExcessBytes;
|
||||
}
|
||||
}
|
||||
|
||||
SimpleRingBuffer::~SimpleRingBuffer() {
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
uint32_t amount) {
|
||||
ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer,
|
||||
size_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
uint32_t amountTillWrap = writeTillWrap();
|
||||
size_t amountTillWrap = writeTillWrap();
|
||||
if (amountTillWrap < amount) {
|
||||
if((amount - amountTillWrap + excessBytes) > maxExcessBytes) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
excessBytes = amount - amountTillWrap;
|
||||
}
|
||||
*writePointer = &buffer[write];
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleRingBuffer::confirmBytesWritten(size_t amount) {
|
||||
if(getExcessBytes() > 0) {
|
||||
moveExcessBytesToStart();
|
||||
}
|
||||
incrementWrite(amount);
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
size_t amount) {
|
||||
if (availableWriteSpace() >= amount or overwriteOld) {
|
||||
size_t amountTillWrap = writeTillWrap();
|
||||
if (amountTillWrap >= amount) {
|
||||
// remaining size in buffer is sufficient to fit full amount.
|
||||
memcpy(&buffer[write], data, amount);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
memcpy(&buffer[write], data, amountTillWrap);
|
||||
memcpy(buffer, data + amountTillWrap, amount - amountTillWrap);
|
||||
}
|
||||
@ -32,12 +74,13 @@ ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data,
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
|
||||
bool readRemaining, uint32_t* trueAmount) {
|
||||
uint32_t availableData = availableReadData(READ_PTR);
|
||||
uint32_t amountTillWrap = readTillWrap(READ_PTR);
|
||||
ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, size_t amount,
|
||||
bool incrementReadPtr, bool readRemaining, size_t* trueAmount) {
|
||||
size_t availableData = getAvailableReadData(READ_PTR);
|
||||
size_t amountTillWrap = readTillWrap(READ_PTR);
|
||||
if (availableData < amount) {
|
||||
if (readRemaining) {
|
||||
// more data available than amount specified.
|
||||
amount = availableData;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -52,12 +95,27 @@ ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, uint32_t amount,
|
||||
memcpy(data, &buffer[read[READ_PTR]], amountTillWrap);
|
||||
memcpy(data + amountTillWrap, buffer, amount - amountTillWrap);
|
||||
}
|
||||
|
||||
if(incrementReadPtr) {
|
||||
deleteData(amount, readRemaining);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
||||
bool deleteRemaining, uint32_t* trueAmount) {
|
||||
uint32_t availableData = availableReadData(READ_PTR);
|
||||
size_t SimpleRingBuffer::getExcessBytes() const {
|
||||
return excessBytes;
|
||||
}
|
||||
|
||||
void SimpleRingBuffer::moveExcessBytesToStart() {
|
||||
if(excessBytes > 0) {
|
||||
std::memcpy(buffer, &buffer[size], excessBytes);
|
||||
excessBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t SimpleRingBuffer::deleteData(size_t amount,
|
||||
bool deleteRemaining, size_t* trueAmount) {
|
||||
size_t availableData = getAvailableReadData(READ_PTR);
|
||||
if (availableData < amount) {
|
||||
if (deleteRemaining) {
|
||||
amount = availableData;
|
||||
@ -71,4 +129,3 @@ ReturnValue_t SimpleRingBuffer::deleteData(uint32_t amount,
|
||||
incrementRead(amount, READ_PTR);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
#define FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
#ifndef FSFW_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
#define FSFW_CONTAINER_SIMPLERINGBUFFER_H_
|
||||
|
||||
#include "RingBufferBase.h"
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief Circular buffer implementation, useful for buffering
|
||||
@ -16,53 +16,114 @@ class SimpleRingBuffer: public RingBufferBase<> {
|
||||
public:
|
||||
/**
|
||||
* This constructor allocates a new internal buffer with the supplied size.
|
||||
*
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* @param overwriteOld If the ring buffer is overflowing at a write
|
||||
* operation, the oldest data will be overwritten.
|
||||
* @param maxExcessBytes These additional bytes will be allocated in addtion
|
||||
* to the specified size to accomodate contiguous write operations
|
||||
* with getFreeElement.
|
||||
*
|
||||
*/
|
||||
SimpleRingBuffer(const size_t size, bool overwriteOld);
|
||||
SimpleRingBuffer(const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes = 0);
|
||||
/**
|
||||
* This constructor takes an external buffer with the specified size.
|
||||
* @param buffer
|
||||
* @param size
|
||||
* @param overwriteOld
|
||||
* If the ring buffer is overflowing at a write operartion, the oldest data
|
||||
* will be overwritten.
|
||||
* @param maxExcessBytes
|
||||
* If the buffer can accomodate additional bytes for contigous write
|
||||
* operations with getFreeElement, this is the maximum allowed additional
|
||||
* size
|
||||
*/
|
||||
SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld);
|
||||
SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld,
|
||||
size_t maxExcessBytes = 0);
|
||||
|
||||
virtual ~SimpleRingBuffer();
|
||||
|
||||
/**
|
||||
* Write to circular buffer and increment write pointer by amount
|
||||
* Write to circular buffer and increment write pointer by amount.
|
||||
* @param data
|
||||
* @param amount
|
||||
* @return -@c RETURN_OK if write operation was successfull
|
||||
* -@c RETURN_FAILED if
|
||||
*/
|
||||
ReturnValue_t writeData(const uint8_t* data, size_t amount);
|
||||
|
||||
/**
|
||||
* Returns a pointer to a free element. If the remaining buffer is
|
||||
* not large enough, the data will be written past the actual size
|
||||
* and the amount of excess bytes will be cached. This function
|
||||
* does not increment the write pointer!
|
||||
* @param writePointer Pointer to a pointer which can be used to write
|
||||
* contiguous blocks into the ring buffer
|
||||
* @param amount
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t writeData(const uint8_t* data, uint32_t amount);
|
||||
ReturnValue_t getFreeElement(uint8_t** writePointer, size_t amount);
|
||||
|
||||
/**
|
||||
* Read from circular buffer at read pointer
|
||||
* This increments the write pointer and also copies the excess bytes
|
||||
* to the beginning. It should be called if the write operation
|
||||
* conducted after calling getFreeElement() was performed.
|
||||
* @return
|
||||
*/
|
||||
void confirmBytesWritten(size_t amount);
|
||||
|
||||
virtual size_t getExcessBytes() const;
|
||||
/**
|
||||
* Helper functions which moves any excess bytes to the start
|
||||
* of the ring buffer.
|
||||
* @return
|
||||
*/
|
||||
virtual void moveExcessBytesToStart();
|
||||
|
||||
/**
|
||||
* Read from circular buffer at read pointer.
|
||||
* @param data
|
||||
* @param amount
|
||||
* @param incrementReadPtr
|
||||
* If this is set to true, the read pointer will be incremented.
|
||||
* If readRemaining is set to true, the read pointer will be incremented
|
||||
* accordingly.
|
||||
* @param readRemaining
|
||||
* @param trueAmount
|
||||
* If this is set to true, the data will be read even if the amount
|
||||
* specified exceeds the read data available.
|
||||
* @param trueAmount [out]
|
||||
* If readRemaining was set to true, the true amount read will be assigned
|
||||
* to the passed value.
|
||||
* @return
|
||||
* - @c RETURN_OK if data was read successfully
|
||||
* - @c RETURN_FAILED if not enough data was available and readRemaining
|
||||
* was set to false.
|
||||
*/
|
||||
ReturnValue_t readData(uint8_t* data, uint32_t amount,
|
||||
bool readRemaining = false, uint32_t* trueAmount = nullptr);
|
||||
ReturnValue_t readData(uint8_t* data, size_t amount,
|
||||
bool incrementReadPtr = false, bool readRemaining = false,
|
||||
size_t* trueAmount = nullptr);
|
||||
|
||||
/**
|
||||
* Delete data starting by incrementing read pointer
|
||||
* Delete data by incrementing read pointer.
|
||||
* @param amount
|
||||
* @param deleteRemaining
|
||||
* @param trueAmount
|
||||
* If the amount specified is larger than the remaing size to read and this
|
||||
* is set to true, the remaining amount will be deleted as well
|
||||
* @param trueAmount [out]
|
||||
* If deleteRemaining was set to true, the amount deleted will be assigned
|
||||
* to the passed value.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false,
|
||||
uint32_t* trueAmount = nullptr);
|
||||
ReturnValue_t deleteData(size_t amount, bool deleteRemaining = false,
|
||||
size_t* trueAmount = nullptr);
|
||||
|
||||
private:
|
||||
// static const uint8_t TEMP_READ_PTR = 1;
|
||||
static const uint8_t READ_PTR = 0;
|
||||
uint8_t* buffer = nullptr;
|
||||
size_t maxExcessBytes;
|
||||
size_t excessBytes = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||
#endif /* FSFW_CONTAINER_SIMPLERINGBUFFER_H_ */
|
||||
|
||||
|
@ -18,7 +18,7 @@ MapPacketExtraction::MapPacketExtraction(uint8_t setMapId,
|
||||
object_id_t setPacketDestination) :
|
||||
lastSegmentationFlag(NO_SEGMENTATION), mapId(setMapId), packetLength(0), bufferPosition(
|
||||
packetBuffer), packetDestination(setPacketDestination), packetStore(
|
||||
NULL), tcQueueId(MessageQueueSenderIF::NO_QUEUE) {
|
||||
NULL), tcQueueId(MessageQueueIF::NO_QUEUE) {
|
||||
memset(packetBuffer, 0, sizeof(packetBuffer));
|
||||
}
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @file PollingSlot.cpp
|
||||
* @brief This file defines the PollingSlot class.
|
||||
* @date 19.12.2012
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
handler(NULL), pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -5,7 +5,7 @@ HealthDevice::HealthDevice(object_id_t setObjectId,
|
||||
MessageQueueId_t parentQueue) :
|
||||
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
|
||||
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::COMMAND_MESSAGE_SIZE);
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(3);
|
||||
}
|
||||
|
||||
HealthDevice::~HealthDevice() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
#define FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
#ifndef FSFW_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
#define FSFW_EVENTS_FWSUBSYSTEMIDRANGES_H_
|
||||
|
||||
namespace SUBSYSTEM_ID {
|
||||
enum {
|
||||
@ -19,10 +19,12 @@ enum {
|
||||
SYSTEM_MANAGER_1 = 75,
|
||||
SYSTEM_1 = 79,
|
||||
PUS_SERVICE_1 = 80,
|
||||
PUS_SERVICE_9 = 89,
|
||||
PUS_SERVICE_17 = 97,
|
||||
FW_SUBSYSTEM_ID_RANGE
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_FWSUBSYSTEMIDRANGES_H_ */
|
||||
#endif /* FSFW_EVENTS_FWSUBSYSTEMIDRANGES_H_ */
|
||||
|
@ -1,95 +1,124 @@
|
||||
#include "DleEncoder.h"
|
||||
#include "../globalfunctions/DleEncoder.h"
|
||||
|
||||
DleEncoder::DleEncoder() {
|
||||
}
|
||||
DleEncoder::DleEncoder() {}
|
||||
|
||||
DleEncoder::~DleEncoder() {
|
||||
DleEncoder::~DleEncoder() {}
|
||||
|
||||
ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
||||
size_t sourceLen, uint8_t* destStream, size_t maxDestLen,
|
||||
size_t* encodedLen, bool addStxEtx) {
|
||||
if (maxDestLen < 2) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
size_t encodedIndex = 0, sourceIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (addStxEtx) {
|
||||
destStream[0] = STX_CHAR;
|
||||
++encodedIndex;
|
||||
}
|
||||
|
||||
while (encodedIndex < maxDestLen and sourceIndex < sourceLen)
|
||||
{
|
||||
nextByte = sourceStream[sourceIndex];
|
||||
// STX, ETX and CR characters in the stream need to be escaped with DLE
|
||||
if (nextByte == STX_CHAR or nextByte == ETX_CHAR or nextByte == CARRIAGE_RETURN) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = DLE_CHAR;
|
||||
++encodedIndex;
|
||||
/* Escaped byte will be actual byte + 0x40. This prevents
|
||||
* STX, ETX, and carriage return characters from appearing
|
||||
* in the encoded data stream at all, so when polling an
|
||||
* encoded stream, the transmission can be stopped at ETX.
|
||||
* 0x40 was chosen at random with special requirements:
|
||||
* - Prevent going from one control char to another
|
||||
* - Prevent overflow for common characters */
|
||||
destStream[encodedIndex] = nextByte + 0x40;
|
||||
}
|
||||
}
|
||||
// DLE characters are simply escaped with DLE.
|
||||
else if (nextByte == DLE_CHAR) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = DLE_CHAR;
|
||||
++encodedIndex;
|
||||
destStream[encodedIndex] = DLE_CHAR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
destStream[encodedIndex] = nextByte;
|
||||
}
|
||||
++encodedIndex;
|
||||
++sourceIndex;
|
||||
}
|
||||
|
||||
if (sourceIndex == sourceLen and encodedIndex < maxDestLen) {
|
||||
if (addStxEtx) {
|
||||
destStream[encodedIndex] = ETX_CHAR;
|
||||
++encodedIndex;
|
||||
}
|
||||
*encodedLen = encodedIndex;
|
||||
return RETURN_OK;
|
||||
}
|
||||
else {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DleEncoder::decode(const uint8_t *sourceStream,
|
||||
uint32_t sourceStreamLen, uint32_t *readLen, uint8_t *destStream,
|
||||
uint32_t maxDestStreamlen, uint32_t *decodedLen) {
|
||||
uint32_t encodedIndex = 0, decodedIndex = 0;
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen) {
|
||||
size_t encodedIndex = 0, decodedIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (*sourceStream != STX) {
|
||||
return RETURN_FAILED;
|
||||
if (*sourceStream != STX_CHAR) {
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
++encodedIndex;
|
||||
|
||||
while ((encodedIndex < sourceStreamLen) && (decodedIndex < maxDestStreamlen)
|
||||
&& (sourceStream[encodedIndex] != ETX)
|
||||
&& (sourceStream[encodedIndex] != STX)) {
|
||||
if (sourceStream[encodedIndex] == DLE) {
|
||||
&& (sourceStream[encodedIndex] != ETX_CHAR)
|
||||
&& (sourceStream[encodedIndex] != STX_CHAR)) {
|
||||
if (sourceStream[encodedIndex] == DLE_CHAR) {
|
||||
nextByte = sourceStream[encodedIndex + 1];
|
||||
if (nextByte == 0x10) {
|
||||
// The next byte is a DLE character that was escaped by another
|
||||
// DLE character, so we can write it to the destination stream.
|
||||
if (nextByte == DLE_CHAR) {
|
||||
destStream[decodedIndex] = nextByte;
|
||||
} else {
|
||||
if ((nextByte == 0x42) || (nextByte == 0x43)
|
||||
|| (nextByte == 0x4D)) {
|
||||
}
|
||||
else {
|
||||
/* The next byte is a STX, DTX or 0x0D character which
|
||||
* was escaped by a DLE character. The actual byte was
|
||||
* also encoded by adding + 0x40 to prevent having control chars,
|
||||
* in the stream at all, so we convert it back. */
|
||||
if (nextByte == 0x42 or nextByte == 0x43 or nextByte == 0x4D) {
|
||||
destStream[decodedIndex] = nextByte - 0x40;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
else {
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
}
|
||||
++encodedIndex;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
destStream[decodedIndex] = sourceStream[encodedIndex];
|
||||
}
|
||||
|
||||
++encodedIndex;
|
||||
++decodedIndex;
|
||||
}
|
||||
if (sourceStream[encodedIndex] != ETX) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
|
||||
if (sourceStream[encodedIndex] != ETX_CHAR) {
|
||||
*readLen = ++encodedIndex;
|
||||
return DECODING_ERROR;
|
||||
}
|
||||
else {
|
||||
*readLen = ++encodedIndex;
|
||||
*decodedLen = decodedIndex;
|
||||
return RETURN_OK;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t DleEncoder::encode(const uint8_t* sourceStream,
|
||||
uint32_t sourceLen, uint8_t* destStream, uint32_t maxDestLen,
|
||||
uint32_t* encodedLen, bool addStxEtx) {
|
||||
if (maxDestLen < 2) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
uint32_t encodedIndex = 0, sourceIndex = 0;
|
||||
uint8_t nextByte;
|
||||
if (addStxEtx) {
|
||||
destStream[0] = STX;
|
||||
++encodedIndex;
|
||||
}
|
||||
while ((encodedIndex < maxDestLen) && (sourceIndex < sourceLen)) {
|
||||
nextByte = sourceStream[sourceIndex];
|
||||
if ((nextByte == STX) || (nextByte == ETX) || (nextByte == 0x0D)) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
destStream[encodedIndex] = DLE;
|
||||
++encodedIndex;
|
||||
destStream[encodedIndex] = nextByte + 0x40;
|
||||
}
|
||||
} else if (nextByte == DLE) {
|
||||
if (encodedIndex + 1 >= maxDestLen) {
|
||||
return RETURN_FAILED;
|
||||
} else {
|
||||
destStream[encodedIndex] = DLE;
|
||||
++encodedIndex;
|
||||
destStream[encodedIndex] = DLE;
|
||||
}
|
||||
} else {
|
||||
destStream[encodedIndex] = nextByte;
|
||||
}
|
||||
++encodedIndex;
|
||||
++sourceIndex;
|
||||
}
|
||||
if ((sourceIndex == sourceLen) && (encodedIndex < maxDestLen)) {
|
||||
if (addStxEtx) {
|
||||
destStream[encodedIndex] = ETX;
|
||||
++encodedIndex;
|
||||
}
|
||||
*encodedLen = encodedIndex;
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,79 @@
|
||||
#ifndef DLEENCODER_H_
|
||||
#define DLEENCODER_H_
|
||||
#ifndef FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
#define FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @brief This DLE Encoder (Data Link Encoder) can be used to encode and
|
||||
* decode arbitrary data with ASCII control characters
|
||||
* @details
|
||||
* List of control codes:
|
||||
* https://en.wikipedia.org/wiki/C0_and_C1_control_codes
|
||||
*
|
||||
* This encoder can be used to achieve a basic transport layer when using
|
||||
* char based transmission systems.
|
||||
* The passed source strean is converted into a encoded stream by adding
|
||||
* a STX marker at the start of the stream and an ETX marker at the end of
|
||||
* the stream. Any STX, ETX, DLE and CR occurrences in the source stream are
|
||||
* escaped by a DLE character. The encoder also replaces escaped control chars
|
||||
* by another char, so STX, ETX and CR should not appear anywhere in the actual
|
||||
* encoded data stream.
|
||||
*
|
||||
* When using a strictly char based reception of packets encoded with DLE,
|
||||
* STX can be used to notify a reader that actual data will start to arrive
|
||||
* while ETX can be used to notify the reader that the data has ended.
|
||||
*/
|
||||
class DleEncoder: public HasReturnvaluesIF {
|
||||
private:
|
||||
DleEncoder();
|
||||
virtual ~DleEncoder();
|
||||
|
||||
public:
|
||||
static const uint8_t STX = 0x02;
|
||||
static const uint8_t ETX = 0x03;
|
||||
static const uint8_t DLE = 0x10;
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::DLE_ENCODER;
|
||||
static constexpr ReturnValue_t STREAM_TOO_SHORT = MAKE_RETURN_CODE(0x01);
|
||||
static constexpr ReturnValue_t DECODING_ERROR = MAKE_RETURN_CODE(0x02);
|
||||
|
||||
static ReturnValue_t decode(const uint8_t *sourceStream,
|
||||
uint32_t sourceStreamLen, uint32_t *readLen, uint8_t *destStream,
|
||||
uint32_t maxDestStreamlen, uint32_t *decodedLen);
|
||||
//! Start Of Text character. First character is encoded stream
|
||||
static constexpr uint8_t STX_CHAR = 0x02;
|
||||
//! End Of Text character. Last character in encoded stream
|
||||
static constexpr uint8_t ETX_CHAR = 0x03;
|
||||
//! Data Link Escape character. Used to escape STX, ETX and DLE occurrences
|
||||
//! in the source stream.
|
||||
static constexpr uint8_t DLE_CHAR = 0x10;
|
||||
static constexpr uint8_t CARRIAGE_RETURN = 0x0D;
|
||||
|
||||
static ReturnValue_t encode(const uint8_t *sourceStream, uint32_t sourceLen,
|
||||
uint8_t *destStream, uint32_t maxDestLen, uint32_t *encodedLen,
|
||||
/**
|
||||
* Encodes the give data stream by preceding it with the STX marker
|
||||
* and ending it with an ETX marker. STX, ETX and DLE characters inside
|
||||
* the stream are escaped by DLE characters and also replaced by adding
|
||||
* 0x40 (which is reverted in the decoding process).
|
||||
* @param sourceStream
|
||||
* @param sourceLen
|
||||
* @param destStream
|
||||
* @param maxDestLen
|
||||
* @param encodedLen
|
||||
* @param addStxEtx
|
||||
* Adding STX and ETX can be omitted, if they are added manually.
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t encode(const uint8_t *sourceStream, size_t sourceLen,
|
||||
uint8_t *destStream, size_t maxDestLen, size_t *encodedLen,
|
||||
bool addStxEtx = true);
|
||||
|
||||
/**
|
||||
* Converts an encoded stream back.
|
||||
* @param sourceStream
|
||||
* @param sourceStreamLen
|
||||
* @param readLen
|
||||
* @param destStream
|
||||
* @param maxDestStreamlen
|
||||
* @param decodedLen
|
||||
* @return
|
||||
*/
|
||||
static ReturnValue_t decode(const uint8_t *sourceStream,
|
||||
size_t sourceStreamLen, size_t *readLen, uint8_t *destStream,
|
||||
size_t maxDestStreamlen, size_t *decodedLen);
|
||||
};
|
||||
|
||||
#endif /* DLEENCODER_H_ */
|
||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_DLEENCODER_H_ */
|
||||
|
34
globalfunctions/PeriodicOperationDivider.cpp
Normal file
34
globalfunctions/PeriodicOperationDivider.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "PeriodicOperationDivider.h"
|
||||
|
||||
|
||||
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
|
||||
bool resetAutomatically): resetAutomatically(resetAutomatically),
|
||||
counter(divider), divider(divider) {
|
||||
}
|
||||
|
||||
bool PeriodicOperationDivider::checkAndIncrement() {
|
||||
if(counter >= divider) {
|
||||
if(resetAutomatically) {
|
||||
counter = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
counter ++;
|
||||
return false;
|
||||
}
|
||||
|
||||
void PeriodicOperationDivider::resetCounter() {
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
|
||||
divider = newDivider;
|
||||
}
|
||||
|
||||
uint32_t PeriodicOperationDivider::getCounter() const {
|
||||
return counter;
|
||||
}
|
||||
|
||||
uint32_t PeriodicOperationDivider::getDivider() const {
|
||||
return divider;
|
||||
}
|
55
globalfunctions/PeriodicOperationDivider.h
Normal file
55
globalfunctions/PeriodicOperationDivider.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef FSFW_GLOBALFUNCTIONS_PERIODICOPERATIONDIVIDER_H_
|
||||
#define FSFW_GLOBALFUNCTIONS_PERIODICOPERATIONDIVIDER_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Lightweight helper class to facilitate periodic operation with
|
||||
* decreased frequencies.
|
||||
* @details
|
||||
* This class is useful to perform operations which have to be performed
|
||||
* with a reduced frequency, like debugging printouts in high periodic tasks
|
||||
* or low priority operations.
|
||||
*/
|
||||
class PeriodicOperationDivider {
|
||||
public:
|
||||
/**
|
||||
* Initialize with the desired divider and specify whether the internal
|
||||
* counter will be reset automatically.
|
||||
* @param divider
|
||||
* @param resetAutomatically
|
||||
*/
|
||||
PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true);
|
||||
|
||||
/**
|
||||
* Check whether operation is necessary.
|
||||
* If an operation is necessary and the class has been
|
||||
* configured to be reset automatically, the counter will be reset.
|
||||
* If not, the counter will be incremented.
|
||||
* @return
|
||||
* -@c true if the counter is larger or equal to the divider
|
||||
* -@c false otherwise
|
||||
*/
|
||||
bool checkAndIncrement();
|
||||
|
||||
/**
|
||||
* Can be used to reset the counter to 0 manually.
|
||||
*/
|
||||
void resetCounter();
|
||||
uint32_t getCounter() const;
|
||||
|
||||
/**
|
||||
* Can be used to set a new divider value.
|
||||
* @param newDivider
|
||||
*/
|
||||
void setDivider(uint32_t newDivider);
|
||||
uint32_t getDivider() const;
|
||||
private:
|
||||
bool resetAutomatically = true;
|
||||
uint32_t counter = 0;
|
||||
uint32_t divider = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_GLOBALFUNCTIONS_PERIODICOPERATIONDIVIDER_H_ */
|
@ -90,3 +90,10 @@ double timevalOperations::toDouble(const timeval timeval) {
|
||||
double result = timeval.tv_sec * 1000000. + timeval.tv_usec;
|
||||
return result / 1000000.;
|
||||
}
|
||||
|
||||
timeval timevalOperations::toTimeval(const double seconds) {
|
||||
timeval tval;
|
||||
tval.tv_sec = seconds;
|
||||
tval.tv_usec = seconds *(double) 1e6 - (tval.tv_sec *1e6);
|
||||
return tval;
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ namespace timevalOperations {
|
||||
* @return seconds
|
||||
*/
|
||||
double toDouble(const timeval timeval);
|
||||
timeval toTimeval(const double seconds);
|
||||
}
|
||||
|
||||
#endif /* TIMEVALOPERATIONS_H_ */
|
||||
|
@ -1,9 +1,8 @@
|
||||
#include "HealthHelper.h"
|
||||
#include "../ipc/MessageQueueSenderIF.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) :
|
||||
healthTable(NULL), eventSender(NULL), objectId(objectId), parentQueue(
|
||||
0), owner(owner) {
|
||||
objectId(objectId), owner(owner) {
|
||||
}
|
||||
|
||||
HealthHelper::~HealthHelper() {
|
||||
@ -40,9 +39,19 @@ void HealthHelper::setParentQueue(MessageQueueId_t parentQueue) {
|
||||
ReturnValue_t HealthHelper::initialize() {
|
||||
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
|
||||
eventSender = objectManager->get<EventReportingProxyIF>(objectId);
|
||||
if ((healthTable == NULL) || eventSender == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
||||
if (healthTable == nullptr) {
|
||||
sif::error << "HealthHelper::initialize: Health table object needs"
|
||||
"to be created in factory." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
if(eventSender == nullptr) {
|
||||
sif::error << "HealthHelper::initialize: Owner has to implement "
|
||||
"ReportingProxyIF." << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t result = healthTable->registerObject(objectId,
|
||||
HasHealthIF::HEALTHY);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
@ -62,22 +71,22 @@ void HealthHelper::setHealth(HasHealthIF::HealthState health) {
|
||||
|
||||
void HealthHelper::informParent(HasHealthIF::HealthState health,
|
||||
HasHealthIF::HealthState oldHealth) {
|
||||
if (parentQueue == 0) {
|
||||
if (parentQueue == MessageQueueIF::NO_QUEUE) {
|
||||
return;
|
||||
}
|
||||
CommandMessage message;
|
||||
HealthMessage::setHealthMessage(&message, HealthMessage::HEALTH_INFO,
|
||||
CommandMessage information;
|
||||
HealthMessage::setHealthMessage(&information, HealthMessage::HEALTH_INFO,
|
||||
health, oldHealth);
|
||||
if (MessageQueueSenderIF::sendMessage(parentQueue, &message,
|
||||
if (MessageQueueSenderIF::sendMessage(parentQueue, &information,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "HealthHelper::informParent: sending health reply failed."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
|
||||
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(message));
|
||||
if (message->getSender() == 0) {
|
||||
void HealthHelper::handleSetHealthCommand(CommandMessage* command) {
|
||||
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(command));
|
||||
if (command->getSender() == MessageQueueIF::NO_QUEUE) {
|
||||
return;
|
||||
}
|
||||
CommandMessage reply;
|
||||
@ -85,12 +94,12 @@ void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
|
||||
HealthMessage::setHealthMessage(&reply,
|
||||
HealthMessage::REPLY_HEALTH_SET);
|
||||
} else {
|
||||
reply.setReplyRejected(result, message->getCommand());
|
||||
reply.setReplyRejected(result, command->getCommand());
|
||||
}
|
||||
if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply,
|
||||
if (MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
|
||||
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug
|
||||
<< "HealthHelper::handleHealthCommand: sending health reply failed."
|
||||
<< std::endl;
|
||||
sif::debug << "HealthHelper::handleHealthCommand: sending health "
|
||||
"reply failed." << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
#ifndef HEALTHHELPER_H_
|
||||
#define HEALTHHELPER_H_
|
||||
#ifndef FSFW_HEALTH_HEALTHHELPER_H_
|
||||
#define FSFW_HEALTH_HEALTHHELPER_H_
|
||||
|
||||
#include "../events/EventManagerIF.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "HasHealthIF.h"
|
||||
#include "HealthMessage.h"
|
||||
#include "HealthTableIF.h"
|
||||
|
||||
#include "../events/EventManagerIF.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
@ -27,8 +29,8 @@ public:
|
||||
/**
|
||||
* ctor
|
||||
*
|
||||
* @param owner
|
||||
* @param objectId the object Id to use when communication with the HealthTable
|
||||
* @param useAsFrom id to use as from id when sending replies, can be set to 0
|
||||
*/
|
||||
HealthHelper(HasHealthIF* owner, object_id_t objectId);
|
||||
|
||||
@ -39,12 +41,12 @@ public:
|
||||
*
|
||||
* only valid after initialize() has been called
|
||||
*/
|
||||
HealthTableIF *healthTable;
|
||||
HealthTableIF *healthTable = nullptr;
|
||||
|
||||
/**
|
||||
* Proxy to forward events.
|
||||
*/
|
||||
EventReportingProxyIF* eventSender;
|
||||
EventReportingProxyIF* eventSender = nullptr;
|
||||
|
||||
/**
|
||||
* Try to handle the message.
|
||||
@ -100,7 +102,7 @@ private:
|
||||
/**
|
||||
* The Queue of the parent
|
||||
*/
|
||||
MessageQueueId_t parentQueue;
|
||||
MessageQueueId_t parentQueue = MessageQueueIF::NO_QUEUE;
|
||||
|
||||
/**
|
||||
* The one using the healthHelper.
|
||||
@ -117,4 +119,4 @@ private:
|
||||
void handleSetHealthCommand(CommandMessage *message);
|
||||
};
|
||||
|
||||
#endif /* HEALTHHELPER_H_ */
|
||||
#endif /* FSFW_HEALTH_HEALTHHELPER_H_ */
|
||||
|
@ -1,33 +1,15 @@
|
||||
/**
|
||||
* @file CommandMessage.cpp
|
||||
* @brief This file defines the CommandMessage class.
|
||||
* @date 20.06.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "../health/HealthMessage.h"
|
||||
#include "CommandMessage.h"
|
||||
#include "../memory/MemoryMessage.h"
|
||||
#include "../modes/ModeMessage.h"
|
||||
#include "../monitoring/MonitoringMessage.h"
|
||||
#include "../subsystem/modes/ModeSequenceMessage.h"
|
||||
#include "../tmstorage/TmStoreMessage.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
|
||||
namespace messagetypes {
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
#include "CommandMessageCleaner.h"
|
||||
#include <cstring>
|
||||
|
||||
CommandMessage::CommandMessage() {
|
||||
this->messageSize = COMMAND_MESSAGE_SIZE;
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(CMD_NONE);
|
||||
}
|
||||
|
||||
CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
|
||||
uint32_t parameter2) {
|
||||
this->messageSize = COMMAND_MESSAGE_SIZE;
|
||||
MessageQueueMessage::setMessageSize(DEFAULT_COMMAND_MESSAGE_SIZE);
|
||||
setCommand(command);
|
||||
setParameter(parameter1);
|
||||
setParameter2(parameter2);
|
||||
@ -35,82 +17,72 @@ CommandMessage::CommandMessage(Command_t command, uint32_t parameter1,
|
||||
|
||||
Command_t CommandMessage::getCommand() const {
|
||||
Command_t command;
|
||||
memcpy(&command, getData(), sizeof(Command_t));
|
||||
std::memcpy(&command, MessageQueueMessage::getData(), sizeof(Command_t));
|
||||
return command;
|
||||
}
|
||||
|
||||
void CommandMessage::setCommand(Command_t command) {
|
||||
memcpy(getData(), &command, sizeof(command));
|
||||
std::memcpy(MessageQueueMessage::getData(), &command, sizeof(Command_t));
|
||||
}
|
||||
|
||||
uint8_t CommandMessage::getMessageType() const {
|
||||
// first byte of command ID.
|
||||
return getCommand() >> 8 & 0xff;
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter() const {
|
||||
uint32_t parameter1;
|
||||
memcpy(¶meter1, getData() + sizeof(Command_t), sizeof(parameter1));
|
||||
std::memcpy(¶meter1, this->getData(), sizeof(parameter1));
|
||||
return parameter1;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter(uint32_t parameter1) {
|
||||
memcpy(getData() + sizeof(Command_t), ¶meter1, sizeof(parameter1));
|
||||
std::memcpy(this->getData(), ¶meter1, sizeof(parameter1));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter2() const {
|
||||
uint32_t parameter2;
|
||||
memcpy(¶meter2, getData() + sizeof(Command_t) + sizeof(uint32_t),
|
||||
std::memcpy(¶meter2, this->getData() + sizeof(uint32_t),
|
||||
sizeof(parameter2));
|
||||
return parameter2;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter2(uint32_t parameter2) {
|
||||
memcpy(getData() + sizeof(Command_t) + sizeof(uint32_t), ¶meter2,
|
||||
std::memcpy(this->getData() + sizeof(uint32_t), ¶meter2,
|
||||
sizeof(parameter2));
|
||||
}
|
||||
|
||||
uint32_t CommandMessage::getParameter3() const {
|
||||
uint32_t parameter3;
|
||||
std::memcpy(¶meter3, this->getData() + 2 * sizeof(uint32_t),
|
||||
sizeof(parameter3));
|
||||
return parameter3;
|
||||
}
|
||||
|
||||
void CommandMessage::setParameter3(uint32_t parameter3) {
|
||||
std::memcpy(this->getData() + 2 * sizeof(uint32_t), ¶meter3,
|
||||
sizeof(parameter3));
|
||||
}
|
||||
|
||||
size_t CommandMessage::getMinimumMessageSize() const {
|
||||
return MINIMUM_COMMAND_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
void CommandMessage::clearCommandMessage() {
|
||||
switch((getCommand()>>8) & 0xff){
|
||||
case messagetypes::MODE_COMMAND:
|
||||
ModeMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::HEALTH_COMMAND:
|
||||
HealthMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::MODE_SEQUENCE:
|
||||
ModeSequenceMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::ACTION:
|
||||
ActionMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::DEVICE_HANDLER_COMMAND:
|
||||
DeviceHandlerMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::MEMORY:
|
||||
MemoryMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::MONITORING:
|
||||
MonitoringMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::TM_STORE:
|
||||
TmStoreMessage::clear(this);
|
||||
break;
|
||||
case messagetypes::PARAMETER:
|
||||
ParameterMessage::clear(this);
|
||||
break;
|
||||
default:
|
||||
messagetypes::clearMissionMessage(this);
|
||||
break;
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
void CommandMessage::clear() {
|
||||
CommandMessageCleaner::clearCommandMessage(this);
|
||||
}
|
||||
|
||||
bool CommandMessage::isClearedCommandMessage() {
|
||||
return getCommand() == CMD_NONE;
|
||||
}
|
||||
|
||||
size_t CommandMessage::getMinimumMessageSize() const {
|
||||
return COMMAND_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
void CommandMessage::setToUnknownCommand() {
|
||||
Command_t initialCommand = getCommand();
|
||||
clearCommandMessage();
|
||||
this->clear();
|
||||
setReplyRejected(UNKNOWN_COMMAND, initialCommand);
|
||||
}
|
||||
|
||||
@ -129,3 +101,11 @@ ReturnValue_t CommandMessage::getReplyRejectedReason(
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
|
||||
uint8_t* CommandMessage::getData() {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
|
||||
const uint8_t* CommandMessage::getData() const {
|
||||
return MessageQueueMessage::getData() + sizeof(Command_t);
|
||||
}
|
||||
|
@ -1,114 +1,87 @@
|
||||
/**
|
||||
* @file CommandMessage.h
|
||||
* @brief This file defines the CommandMessage class.
|
||||
* @date 20.06.2013
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef COMMANDMESSAGE_H_
|
||||
#define COMMANDMESSAGE_H_
|
||||
|
||||
|
||||
#include "FwMessageTypes.h"
|
||||
#include <config/ipc/MissionMessageTypes.h>
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGE_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGE_H_
|
||||
|
||||
#include "CommandMessageIF.h"
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "FwMessageTypes.h"
|
||||
|
||||
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
|
||||
typedef ReturnValue_t Command_t;
|
||||
|
||||
class CommandMessage : public MessageQueueMessage {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE;
|
||||
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
|
||||
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
||||
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );//!< Used internally, will be ignored
|
||||
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 3 );
|
||||
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 );//!< Reply indicating that the current command was rejected, par1 should contain the error code
|
||||
|
||||
/**
|
||||
* This is the size of a message as it is seen by the MessageQueue
|
||||
*/
|
||||
static const size_t COMMAND_MESSAGE_SIZE = HEADER_SIZE
|
||||
+ sizeof(Command_t) + 2 * sizeof(uint32_t);
|
||||
|
||||
/**
|
||||
* Default Constructor, does not initialize anything.
|
||||
/**
|
||||
* @brief Default command message used to pass command messages between tasks.
|
||||
* Primary message type for IPC. Contains sender, 2-byte command ID
|
||||
* field, and 3 4-byte parameter
|
||||
* @details
|
||||
* It operates on an external memory which is contained inside a
|
||||
* class implementing MessageQueueMessageIF by taking its address.
|
||||
* This allows for a more flexible designs of message implementations.
|
||||
* The pointer can be passed to different message implementations without
|
||||
* the need of unnecessary copying.
|
||||
*
|
||||
* This constructor should be used when receiving a Message, as the content is filled by the MessageQueue.
|
||||
* The command message is based of the generic MessageQueueMessage which
|
||||
* currently has an internal message size of 28 bytes.
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class CommandMessage: public MessageQueueMessage, public CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* Default size can accomodate 3 4-byte parameters.
|
||||
*/
|
||||
static constexpr size_t DEFAULT_COMMAND_MESSAGE_SIZE =
|
||||
CommandMessageIF::MINIMUM_COMMAND_MESSAGE_SIZE +
|
||||
3 * sizeof(uint32_t);
|
||||
|
||||
/**
|
||||
* @brief Default Constructor, does not initialize anything.
|
||||
* @details
|
||||
* This constructor should be used when receiving a Message, as the
|
||||
* content is filled by the MessageQueue.
|
||||
*/
|
||||
CommandMessage();
|
||||
/**
|
||||
* This constructor creates a new message with all message content initialized
|
||||
* This constructor creates a new message with all message content
|
||||
* initialized
|
||||
*
|
||||
* @param command The DeviceHandlerCommand_t that will be sent
|
||||
* @param parameter1 The first parameter
|
||||
* @param parameter2 The second parameter
|
||||
*/
|
||||
CommandMessage(Command_t command,
|
||||
uint32_t parameter1, uint32_t parameter2);
|
||||
CommandMessage(Command_t command, uint32_t parameter1, uint32_t parameter2);
|
||||
|
||||
/**
|
||||
* Default Destructor
|
||||
* @brief Default Destructor
|
||||
*/
|
||||
virtual ~CommandMessage() {
|
||||
}
|
||||
virtual ~CommandMessage() {}
|
||||
|
||||
/**
|
||||
* Read the DeviceHandlerCommand_t that is stored in the message, usually used after receiving
|
||||
* Read the DeviceHandlerCommand_t that is stored in the message,
|
||||
* usually used after receiving.
|
||||
*
|
||||
* @return the Command stored in the Message
|
||||
*/
|
||||
Command_t getCommand() const;
|
||||
|
||||
virtual Command_t getCommand() const override;
|
||||
/**
|
||||
* Set the DeviceHandlerCOmmand_t of the message
|
||||
*
|
||||
* Set the command type of the message. Default implementation also
|
||||
* sets the message type, which will be the first byte of the command ID.
|
||||
* @param the Command to be sent
|
||||
*/
|
||||
void setCommand(Command_t command);
|
||||
virtual void setCommand(Command_t command);
|
||||
|
||||
virtual uint8_t* getData() override;
|
||||
virtual const uint8_t* getData() const override;
|
||||
|
||||
/**
|
||||
* Get the first parameter of the message
|
||||
*
|
||||
* @return the first Parameter of the message
|
||||
*/
|
||||
uint32_t getParameter() const;
|
||||
|
||||
/**
|
||||
* Set the first parameter of the message
|
||||
*
|
||||
* @param the first parameter of the message
|
||||
*/
|
||||
void setParameter(uint32_t parameter1);
|
||||
|
||||
/**
|
||||
* Get the second parameter of the message
|
||||
*
|
||||
* @return the second Parameter of the message
|
||||
*/
|
||||
uint32_t getParameter2() const;
|
||||
|
||||
/**
|
||||
* Set the second parameter of the message
|
||||
*
|
||||
* @param the second parameter of the message
|
||||
*/
|
||||
void setParameter2(uint32_t parameter2);
|
||||
|
||||
/**
|
||||
* Set the command to CMD_NONE and try to find
|
||||
* the correct class to handle a more detailed
|
||||
* clear.
|
||||
* Also, calls a mission-specific clearMissionMessage
|
||||
* function to separate between framework and mission
|
||||
* messages. Not optimal, may be replaced by totally
|
||||
* different auto-delete solution (e.g. smart pointers).
|
||||
*
|
||||
*/
|
||||
void clearCommandMessage();
|
||||
uint32_t getParameter3() const;
|
||||
void setParameter3(uint32_t parameter3);
|
||||
|
||||
/**
|
||||
* check if a message was cleared
|
||||
@ -117,18 +90,41 @@ public:
|
||||
*/
|
||||
bool isClearedCommandMessage();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the command to REPLY_REJECTED with parameter UNKNOWN_COMMAND.
|
||||
* Is needed quite often, so we better code it once only.
|
||||
*/
|
||||
void setToUnknownCommand();
|
||||
void setReplyRejected(ReturnValue_t reason, Command_t initialCommand = CMD_NONE);
|
||||
ReturnValue_t getReplyRejectedReason(
|
||||
Command_t *initialCommand = nullptr) const;
|
||||
void setToUnknownCommand() override;
|
||||
|
||||
size_t getMinimumMessageSize() const;
|
||||
/**
|
||||
* A command message can be rejected and needs to offer a function
|
||||
* to set a rejected reply
|
||||
* @param reason
|
||||
* @param initialCommand
|
||||
*/
|
||||
void setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) override;
|
||||
/**
|
||||
* Corrensonding getter function.
|
||||
* @param initialCommand
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t getReplyRejectedReason(
|
||||
Command_t* initialCommand = nullptr) const override;
|
||||
|
||||
|
||||
virtual void clear() override;
|
||||
void clearCommandMessage();
|
||||
|
||||
/**
|
||||
* Extract message ID, which is the first byte of the command ID for the
|
||||
* default implementation.
|
||||
* @return
|
||||
*/
|
||||
virtual uint8_t getMessageType() const override;
|
||||
|
||||
/** MessageQueueMessageIF functions used for minimum size check. */
|
||||
size_t getMinimumMessageSize() const override;
|
||||
};
|
||||
|
||||
|
||||
#endif /* COMMANDMESSAGE_H_ */
|
||||
#endif /* FSFW_IPC_COMMANDMESSAGE_H_ */
|
||||
|
45
ipc/CommandMessageCleaner.cpp
Normal file
45
ipc/CommandMessageCleaner.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "../ipc/CommandMessageCleaner.h"
|
||||
|
||||
#include "../devicehandlers/DeviceHandlerMessage.h"
|
||||
#include "../health/HealthMessage.h"
|
||||
#include "../memory/MemoryMessage.h"
|
||||
#include "../modes/ModeMessage.h"
|
||||
#include "../monitoring/MonitoringMessage.h"
|
||||
#include "../subsystem/modes/ModeSequenceMessage.h"
|
||||
#include "../tmstorage/TmStoreMessage.h"
|
||||
#include "../parameters/ParameterMessage.h"
|
||||
|
||||
void CommandMessageCleaner::clearCommandMessage(CommandMessage* message) {
|
||||
switch(message->getMessageType()){
|
||||
case messagetypes::MODE_COMMAND:
|
||||
ModeMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::HEALTH_COMMAND:
|
||||
HealthMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MODE_SEQUENCE:
|
||||
ModeSequenceMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::ACTION:
|
||||
ActionMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::DEVICE_HANDLER_COMMAND:
|
||||
DeviceHandlerMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MEMORY:
|
||||
MemoryMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::MONITORING:
|
||||
MonitoringMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::TM_STORE:
|
||||
TmStoreMessage::clear(message);
|
||||
break;
|
||||
case messagetypes::PARAMETER:
|
||||
ParameterMessage::clear(message);
|
||||
break;
|
||||
default:
|
||||
messagetypes::clearMissionMessage(message);
|
||||
break;
|
||||
}
|
||||
}
|
16
ipc/CommandMessageCleaner.h
Normal file
16
ipc/CommandMessageCleaner.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#define FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_
|
||||
#include "../ipc/CommandMessage.h"
|
||||
|
||||
namespace messagetypes {
|
||||
// Implemented in config.
|
||||
void clearMissionMessage(CommandMessage* message);
|
||||
}
|
||||
|
||||
class CommandMessageCleaner {
|
||||
public:
|
||||
static void clearCommandMessage(CommandMessage* message);
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_COMMANDMESSAGECLEANER_H_ */
|
73
ipc/CommandMessageIF.h
Normal file
73
ipc/CommandMessageIF.h
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
#define FSFW_IPC_COMMANDMESSAGEIF_H_
|
||||
|
||||
#include "MessageQueueMessageIF.h"
|
||||
#include "FwMessageTypes.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number))
|
||||
typedef uint16_t Command_t;
|
||||
|
||||
class CommandMessageIF {
|
||||
public:
|
||||
/**
|
||||
* Header consists of sender ID and command ID.
|
||||
*/
|
||||
static constexpr size_t HEADER_SIZE = MessageQueueMessageIF::HEADER_SIZE +
|
||||
sizeof(Command_t);
|
||||
/**
|
||||
* This minimum size is derived from the interface requirement to be able
|
||||
* to set a rejected reply, which contains a returnvalue and the initial
|
||||
* command.
|
||||
*/
|
||||
static constexpr size_t MINIMUM_COMMAND_MESSAGE_SIZE =
|
||||
CommandMessageIF::HEADER_SIZE + sizeof(ReturnValue_t) +
|
||||
sizeof(Command_t);
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE;
|
||||
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
||||
//! Used internally, shall be ignored
|
||||
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );
|
||||
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 1 );
|
||||
//! Reply indicating that the current command was rejected,
|
||||
//! par1 should contain the error code
|
||||
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 2 );
|
||||
|
||||
virtual ~CommandMessageIF() {};
|
||||
|
||||
/**
|
||||
* A command message shall have a uint16_t command ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual Command_t getCommand() const = 0;
|
||||
/**
|
||||
* A command message shall have a uint8_t message type ID field.
|
||||
* @return
|
||||
*/
|
||||
virtual uint8_t getMessageType() const = 0;
|
||||
|
||||
/**
|
||||
* A command message can be rejected and needs to offer a function
|
||||
* to set a rejected reply
|
||||
* @param reason
|
||||
* @param initialCommand
|
||||
*/
|
||||
virtual void setReplyRejected(ReturnValue_t reason,
|
||||
Command_t initialCommand) = 0;
|
||||
/**
|
||||
* Corrensonding getter function.
|
||||
* @param initialCommand
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t getReplyRejectedReason(
|
||||
Command_t* initialCommand = nullptr) const = 0;
|
||||
|
||||
virtual void setToUnknownCommand() = 0;
|
||||
|
||||
virtual void clear() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* FSFW_IPC_COMMANDMESSAGEIF_H_ */
|
@ -1,15 +1,15 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUEIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUEIF_H_
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEIF_H_
|
||||
|
||||
// COULDDO: We could support blocking calls
|
||||
|
||||
#include "messageQueueDefinitions.h"
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "MessageQueueSenderIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
class MessageQueueIF {
|
||||
public:
|
||||
|
||||
static const MessageQueueId_t NO_QUEUE = MessageQueueSenderIF::NO_QUEUE; //!< Ugly hack.
|
||||
static const MessageQueueId_t NO_QUEUE = 0;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF;
|
||||
/**
|
||||
|
@ -1,13 +1,27 @@
|
||||
#include "MessageQueueMessage.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "../globalfunctions/arrayprinter.h"
|
||||
#include <cstring>
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage() :
|
||||
messageSize(this->HEADER_SIZE) {
|
||||
messageSize(getMinimumMessageSize()) {
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
}
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage(uint8_t* data, size_t size) :
|
||||
messageSize(this->HEADER_SIZE + size) {
|
||||
if (size <= this->MAX_DATA_SIZE) {
|
||||
memcpy(this->getData(), data, size);
|
||||
this->messageSize = this->HEADER_SIZE + size;
|
||||
}
|
||||
else {
|
||||
sif::warning << "MessageQueueMessage: Passed size larger than maximum"
|
||||
"allowed size! Setting content to 0" << std::endl;
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
this->messageSize = this->HEADER_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueMessage::~MessageQueueMessage() {
|
||||
}
|
||||
|
||||
@ -37,29 +51,34 @@ void MessageQueueMessage::setSender(MessageQueueId_t setId) {
|
||||
memcpy(this->internalBuffer, &setId, sizeof(MessageQueueId_t));
|
||||
}
|
||||
|
||||
MessageQueueMessage::MessageQueueMessage(uint8_t* data, uint32_t size) :
|
||||
messageSize(this->HEADER_SIZE + size) {
|
||||
if (size <= this->MAX_DATA_SIZE) {
|
||||
memcpy(this->getData(), data, size);
|
||||
} else {
|
||||
memset(this->internalBuffer, 0, sizeof(this->internalBuffer));
|
||||
this->messageSize = this->HEADER_SIZE;
|
||||
void MessageQueueMessage::print(bool printWholeMessage) {
|
||||
sif::debug << "MessageQueueMessage content: " << std::endl;
|
||||
if(printWholeMessage) {
|
||||
arrayprinter::print(getData(), getMaximumMessageSize());
|
||||
}
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMinimumMessageSize() {
|
||||
return this->HEADER_SIZE;
|
||||
}
|
||||
|
||||
void MessageQueueMessage::print() {
|
||||
sif::debug << "MessageQueueMessage has size: " << this->messageSize << std::hex
|
||||
<< std::endl;
|
||||
for (uint8_t count = 0; count < this->messageSize; count++) {
|
||||
sif::debug << (uint32_t) this->internalBuffer[count] << ":";
|
||||
else {
|
||||
arrayprinter::print(getData(), getMessageSize());
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
|
||||
}
|
||||
|
||||
void MessageQueueMessage::clear() {
|
||||
memset(this->getBuffer(), 0, this->MAX_MESSAGE_SIZE);
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMessageSize() const {
|
||||
return this->messageSize;
|
||||
}
|
||||
|
||||
void MessageQueueMessage::setMessageSize(size_t messageSize) {
|
||||
this->messageSize = messageSize;
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMinimumMessageSize() const {
|
||||
return this->MIN_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
size_t MessageQueueMessage::getMaximumMessageSize() const {
|
||||
return this->MAX_MESSAGE_SIZE;
|
||||
}
|
||||
|
||||
|
@ -1,118 +1,149 @@
|
||||
#ifndef MESSAGEQUEUEMESSAGE_H_
|
||||
#define MESSAGEQUEUEMESSAGE_H_
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEMESSAGE_H_
|
||||
|
||||
#include "MessageQueueSenderIF.h"
|
||||
#include <stddef.h>
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* \brief This class is the representation and data organizer for interprocess messages.
|
||||
* @brief This class is the representation and data organizer
|
||||
* for interprocess messages.
|
||||
* @details
|
||||
* To facilitate and standardize interprocess communication, this class was
|
||||
* created to handle a lightweight "interprocess message protocol".
|
||||
*
|
||||
* \details To facilitate and standardize interprocess communication, this class was created
|
||||
* to handle a lightweight "interprocess message protocol". It adds a header with the
|
||||
* sender's queue id to every sent message and defines the maximum total message size.
|
||||
* Specialized messages, such as device commanding messages, can be created by inheriting
|
||||
* from this class and filling the buffer provided by getData with additional content.
|
||||
* If larger amounts of data must be sent between processes, the data shall be stored in
|
||||
* the IPC Store object and only the storage id is passed in a queue message.
|
||||
* The class is used both to generate and send messages and to receive messages from
|
||||
* other tasks.
|
||||
* \ingroup message_queue
|
||||
* It adds a header with the sender's queue id to every sent message and
|
||||
* defines the maximum total message size. Specialized messages, such as
|
||||
* device commanding messages, can be created by inheriting from this class
|
||||
* and filling the buffer provided by getData with additional content.
|
||||
*
|
||||
* If larger amounts of data must be sent between processes, the data shall
|
||||
* be stored in the IPC Store object and only the storage id is passed in a
|
||||
* queue message.The class is used both to generate and send messages and to
|
||||
* receive messages from other tasks.
|
||||
* @ingroup message_queue
|
||||
*/
|
||||
class MessageQueueMessage {
|
||||
class MessageQueueMessage: public MessageQueueMessageIF {
|
||||
public:
|
||||
/**
|
||||
* \brief This constant defines the maximum size of the data content, excluding the header.
|
||||
* \details It may be changed if necessary, but in general should be kept as small as possible.
|
||||
* @brief The class is initialized empty with this constructor.
|
||||
* @details
|
||||
* The messageSize attribute is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
*/
|
||||
MessageQueueMessage();
|
||||
/**
|
||||
* @brief With this constructor the class is initialized with
|
||||
* the given content.
|
||||
* @details
|
||||
* If the passed message size fits into the buffer, the passed data is
|
||||
* copied to the internal buffer and the messageSize information is set.
|
||||
* Otherwise, messageSize is set to the header's size and the whole
|
||||
* content is set to zero.
|
||||
* @param data The data to be put in the message.
|
||||
* @param size Size of the data to be copied. Must be smaller than
|
||||
* MAX_MESSAGE_SIZE and larger than MIN_MESSAGE_SIZE.
|
||||
*/
|
||||
MessageQueueMessage(uint8_t* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief As no memory is allocated in this class,
|
||||
* the destructor is empty.
|
||||
*/
|
||||
virtual ~MessageQueueMessage();
|
||||
|
||||
/**
|
||||
* @brief The size information of each message is stored in
|
||||
* this attribute.
|
||||
* @details
|
||||
* It is public to simplify usage and to allow for passing the size
|
||||
* address as a pointer. Care must be taken when inheriting from this class,
|
||||
* as every child class is responsible for managing the size information by
|
||||
* itself. When using the class to receive a message, the size information
|
||||
* is updated automatically.
|
||||
*
|
||||
* Please note that the minimum size is limited by the size of the header
|
||||
* while the maximum size is limited by the maximum allowed message size.
|
||||
*/
|
||||
size_t messageSize;
|
||||
/**
|
||||
* @brief This constant defines the maximum size of the data content,
|
||||
* excluding the header.
|
||||
* @details
|
||||
* It may be changed if necessary, but in general should be kept
|
||||
* as small as possible.
|
||||
*/
|
||||
static const size_t MAX_DATA_SIZE = 24;
|
||||
|
||||
/**
|
||||
* \brief This constants defines the size of the header, which is added to every message.
|
||||
* @brief This constant defines the maximum total size in bytes
|
||||
* of a sent message.
|
||||
* @details
|
||||
* It is the sum of the maximum data and the header size. Be aware that
|
||||
* this constant is used to define the buffer sizes for every message
|
||||
* queue in the system. So, a change here may have significant impact on
|
||||
* the required resources.
|
||||
*/
|
||||
static const size_t HEADER_SIZE = sizeof(MessageQueueId_t);
|
||||
static constexpr size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
|
||||
/**
|
||||
* \brief This constant defines the maximum total size in bytes of a sent message.
|
||||
* \details It is the sum of the maximum data and the header size. Be aware that this constant
|
||||
* is used to define the buffer sizes for every message queue in the system. So, a change
|
||||
* here may have significant impact on the required resources.
|
||||
* @brief Defines the minimum size of a message where only the
|
||||
* header is included
|
||||
*/
|
||||
static const size_t MAX_MESSAGE_SIZE = MAX_DATA_SIZE + HEADER_SIZE;
|
||||
static constexpr size_t MIN_MESSAGE_SIZE = HEADER_SIZE;
|
||||
private:
|
||||
/**
|
||||
* \brief This is the internal buffer that contains the actual message data.
|
||||
* @brief This is the internal buffer that contains the
|
||||
* actual message data.
|
||||
*/
|
||||
uint8_t internalBuffer[MAX_MESSAGE_SIZE];
|
||||
public:
|
||||
/**
|
||||
* \brief The size information of each message is stored in this attribute.
|
||||
* \details It is public to simplify usage and to allow for passing the variable's address as a
|
||||
* pointer. Care must be taken when inheriting from this class, as every child class is
|
||||
* responsible for managing the size information by itself. When using the class to
|
||||
* receive a message, the size information is updated automatically.
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
size_t messageSize;
|
||||
const uint8_t* getBuffer() const override;
|
||||
/**
|
||||
* \brief The class is initialized empty with this constructor.
|
||||
* \details The messageSize attribute is set to the header's size and the whole content is set to
|
||||
* zero.
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
MessageQueueMessage();
|
||||
uint8_t* getBuffer() override;
|
||||
/**
|
||||
* \brief With this constructor the class is initialized with the given content.
|
||||
* \details If the passed message size fits into the buffer, the passed data is copied to the
|
||||
* internal buffer and the messageSize information is set. Otherwise, messageSize
|
||||
* is set to the header's size and the whole content is set to zero.
|
||||
* \param data The data to be put in the message.
|
||||
* \param size Size of the data to be copied. Must be smaller than MAX_MESSAGE_SIZE.
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
MessageQueueMessage(uint8_t* data, uint32_t size);
|
||||
const uint8_t* getData() const override;
|
||||
/**
|
||||
* \brief As no memory is allocated in this class, the destructor is empty.
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
virtual ~MessageQueueMessage();
|
||||
uint8_t* getData() override;
|
||||
/**
|
||||
* \brief This method is used to get the complete data of the message.
|
||||
* @brief This method is used to extract the sender's message
|
||||
* queue id information from a received message.
|
||||
*/
|
||||
const uint8_t* getBuffer() const;
|
||||
MessageQueueId_t getSender() const override;
|
||||
/**
|
||||
* \brief This method is used to get the complete data of the message.
|
||||
* @brief With this method, the whole content
|
||||
* and the message size is set to zero.
|
||||
*/
|
||||
uint8_t* getBuffer();
|
||||
void clear() override;
|
||||
|
||||
/**
|
||||
* \brief This method is used to fetch the data content of the message.
|
||||
* \details It shall be used by child classes to add data at the right position.
|
||||
* @brief This method is used to set the sender's message queue id
|
||||
* information prior to ing the message.
|
||||
* @param setId
|
||||
* The message queue id that identifies the sending message queue.
|
||||
*/
|
||||
const uint8_t* getData() const;
|
||||
void setSender(MessageQueueId_t setId) override;
|
||||
|
||||
virtual size_t getMessageSize() const override;
|
||||
virtual void setMessageSize(size_t messageSize) override;
|
||||
virtual size_t getMinimumMessageSize() const override;
|
||||
virtual size_t getMaximumMessageSize() const override;
|
||||
|
||||
/**
|
||||
* \brief This method is used to fetch the data content of the message.
|
||||
* \details It shall be used by child classes to add data at the right position.
|
||||
* @brief This is a debug method that prints the content.
|
||||
*/
|
||||
uint8_t* getData();
|
||||
/**
|
||||
* \brief This method is used to extract the sender's message queue id information from a
|
||||
* received message.
|
||||
*/
|
||||
MessageQueueId_t getSender() const;
|
||||
/**
|
||||
* \brief With this method, the whole content and the message size is set to zero.
|
||||
*/
|
||||
void clear();
|
||||
/**
|
||||
* \brief This is a debug method that prints the content (till messageSize) to the debug output.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* \brief This method is used to set the sender's message queue id information prior to
|
||||
* sending the message.
|
||||
* \param setId The message queue id that identifies the sending message queue.
|
||||
*/
|
||||
void setSender(MessageQueueId_t setId);
|
||||
/**
|
||||
* \brief This helper function is used by the MessageQueue class to check the size of an
|
||||
* incoming message.
|
||||
* \details The method must be overwritten by child classes if size checks shall be more strict.
|
||||
* @return The default implementation returns HEADER_SIZE.
|
||||
*/
|
||||
virtual size_t getMinimumMessageSize();
|
||||
void print(bool printWholeMessage);
|
||||
};
|
||||
|
||||
#endif /* MESSAGEQUEUEMESSAGE_H_ */
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ */
|
||||
|
80
ipc/MessageQueueMessageIF.h
Normal file
80
ipc/MessageQueueMessageIF.h
Normal file
@ -0,0 +1,80 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_
|
||||
|
||||
#include <fsfw/ipc/messageQueueDefinitions.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class MessageQueueMessageIF {
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief This constants defines the size of the header,
|
||||
* which is added to every message.
|
||||
*/
|
||||
static const size_t HEADER_SIZE = sizeof(MessageQueueId_t);
|
||||
|
||||
virtual ~MessageQueueMessageIF() {};
|
||||
|
||||
/**
|
||||
* @brief With this method, the whole content and the message
|
||||
* size is set to zero.
|
||||
* @details
|
||||
* Implementations should also take care to clear data which is stored
|
||||
* indirectly (e.g. storage data).
|
||||
*/
|
||||
virtual void clear() = 0;
|
||||
|
||||
/**
|
||||
* @brief Get read-only pointer to the complete data of the message.
|
||||
* @return
|
||||
*/
|
||||
virtual const uint8_t* getBuffer() const = 0;
|
||||
|
||||
/**
|
||||
* @brief This method is used to get the complete data of the message.
|
||||
*/
|
||||
virtual uint8_t* getBuffer() = 0;
|
||||
|
||||
/**
|
||||
* @brief This method is used to set the sender's message queue id
|
||||
* information prior to sending the message.
|
||||
* @param setId
|
||||
* The message queue id that identifies the sending message queue.
|
||||
*/
|
||||
virtual void setSender(MessageQueueId_t setId) = 0;
|
||||
|
||||
/**
|
||||
* @brief This method is used to extract the sender's message queue id
|
||||
* information from a received message.
|
||||
*/
|
||||
virtual MessageQueueId_t getSender() const = 0;
|
||||
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
virtual const uint8_t* getData() const = 0;
|
||||
/**
|
||||
* @brief This method is used to fetch the data content of the message.
|
||||
* @details
|
||||
* It shall be used by child classes to add data at the right position.
|
||||
*/
|
||||
virtual uint8_t* getData() = 0;
|
||||
|
||||
/**
|
||||
* Get constant message size of current message implementation.
|
||||
* @return
|
||||
*/
|
||||
virtual size_t getMessageSize() const = 0;
|
||||
|
||||
virtual void setMessageSize(size_t messageSize) = 0;
|
||||
virtual size_t getMinimumMessageSize() const = 0;
|
||||
virtual size_t getMaximumMessageSize() const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MESSAGEQUEUEMESSAGEIF_H_ */
|
@ -1,37 +1,26 @@
|
||||
#ifndef FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#define FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUESENDERIF_H_
|
||||
|
||||
#include "../ipc/MessageQueueIF.h"
|
||||
#include "../ipc/MessageQueueMessageIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
class MessageQueueMessage;
|
||||
|
||||
|
||||
//TODO: Actually, the definition of this ID to be a uint32_t is not ideal and breaks layering.
|
||||
//However, it is difficult to keep layering, as the ID is stored in many places and sent around in
|
||||
//MessageQueueMessage.
|
||||
//Ideally, one would use the (current) object_id_t only, however, doing a lookup of queueIDs for every
|
||||
//call does not sound ideal.
|
||||
//In a first step, I'll circumvent the issue by not touching it, maybe in a second step.
|
||||
//This also influences Interface design (getCommandQueue) and some other issues..
|
||||
typedef uint32_t MessageQueueId_t;
|
||||
|
||||
class MessageQueueSenderIF {
|
||||
public:
|
||||
static const MessageQueueId_t NO_QUEUE = 0;
|
||||
|
||||
virtual ~MessageQueueSenderIF() {}
|
||||
|
||||
/**
|
||||
* Allows sending messages without actually "owing" a message queue.
|
||||
* Allows sending messages without actually "owning" a message queue.
|
||||
* Not sure whether this is actually a good idea.
|
||||
* Must be implemented by a subclass.
|
||||
*/
|
||||
static ReturnValue_t sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom =
|
||||
MessageQueueSenderIF::NO_QUEUE, bool ignoreFault=false);
|
||||
MessageQueueMessage* message,
|
||||
MessageQueueId_t sentFrom = MessageQueueIF::NO_QUEUE,
|
||||
bool ignoreFault = false);
|
||||
private:
|
||||
MessageQueueSenderIF() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_IPC_MESSAGEQUEUESENDERIF_H_ */
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUESENDERIF_H_ */
|
||||
|
19
ipc/messageQueueDefinitions.h
Normal file
19
ipc/messageQueueDefinitions.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef FSFW_IPC_MESSAGEQUEUEDEFINITIONS_H_
|
||||
#define FSFW_IPC_MESSAGEQUEUEDEFINITIONS_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/*
|
||||
* TODO: Actually, the definition of this ID to be a uint32_t is not ideal and
|
||||
* breaks layering. However, it is difficult to keep layering, as the ID is
|
||||
* stored in many places and sent around in MessageQueueMessage.
|
||||
* Ideally, one would use the (current) object_id_t only, however, doing a
|
||||
* lookup of queueIDs for every call does not sound ideal.
|
||||
* In a first step, I'll circumvent the issue by not touching it,
|
||||
* maybe in a second step. This also influences Interface design
|
||||
* (getCommandQueue) and some other issues..
|
||||
*/
|
||||
using MessageQueueId_t = uint32_t;
|
||||
|
||||
|
||||
#endif /* FSFW_IPC_MESSAGEQUEUEDEFINITIONS_H_ */
|
@ -36,7 +36,7 @@ ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* message) {
|
||||
commandedMode = mode;
|
||||
commandedSubmode = submode;
|
||||
|
||||
if ((parentQueueId != MessageQueueSenderIF::NO_QUEUE)
|
||||
if ((parentQueueId != MessageQueueIF::NO_QUEUE)
|
||||
&& (theOneWhoCommandedAMode != parentQueueId)) {
|
||||
owner->setToExternalControl();
|
||||
}
|
||||
@ -74,7 +74,7 @@ ReturnValue_t ModeHelper::initialize(MessageQueueId_t parentQueueId) {
|
||||
void ModeHelper::modeChanged(Mode_t mode, Submode_t submode) {
|
||||
forced = false;
|
||||
CommandMessage reply;
|
||||
if (theOneWhoCommandedAMode != MessageQueueSenderIF::NO_QUEUE) {
|
||||
if (theOneWhoCommandedAMode != MessageQueueIF::NO_QUEUE) {
|
||||
if ((mode != commandedMode) || (submode != commandedSubmode)) {
|
||||
ModeMessage::setModeMessage(&reply,
|
||||
ModeMessage::REPLY_WRONG_MODE_REPLY, mode, submode);
|
||||
@ -86,12 +86,12 @@ void ModeHelper::modeChanged(Mode_t mode, Submode_t submode) {
|
||||
owner->getCommandQueue());
|
||||
}
|
||||
if (theOneWhoCommandedAMode != parentQueueId
|
||||
&& parentQueueId != MessageQueueSenderIF::NO_QUEUE) {
|
||||
&& parentQueueId != MessageQueueIF::NO_QUEUE) {
|
||||
ModeMessage::setModeMessage(&reply, ModeMessage::REPLY_MODE_INFO, mode,
|
||||
submode);
|
||||
MessageQueueSenderIF::sendMessage(parentQueueId, &reply, owner->getCommandQueue());
|
||||
}
|
||||
theOneWhoCommandedAMode = MessageQueueSenderIF::NO_QUEUE;
|
||||
theOneWhoCommandedAMode = MessageQueueIF::NO_QUEUE;
|
||||
}
|
||||
|
||||
void ModeHelper::startTimer(uint32_t timeoutMs) {
|
||||
|
@ -1,12 +1,5 @@
|
||||
/**
|
||||
* @file ObjectManager.h
|
||||
* @brief This file contains the implementation of the ObjectManager class
|
||||
* @date 18.09.2012
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef OBJECTMANAGER_H_
|
||||
#define OBJECTMANAGER_H_
|
||||
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGER_H_
|
||||
#define FSFW_OBJECTMANAGER_OBJECTMANAGER_H_
|
||||
|
||||
#include "ObjectManagerIF.h"
|
||||
#include "SystemObjectIF.h"
|
||||
@ -22,14 +15,15 @@
|
||||
* most of the system initialization.
|
||||
* As the system is static after initialization, no new objects are
|
||||
* created or inserted into the list after startup.
|
||||
* \ingroup system_objects
|
||||
* @ingroup system_objects
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class ObjectManager : public ObjectManagerIF {
|
||||
private:
|
||||
//comparison?
|
||||
/**
|
||||
* \brief This is the map of all initialized objects in the manager.
|
||||
* \details Objects in the List must inherit the SystemObjectIF.
|
||||
* @brief This is the map of all initialized objects in the manager.
|
||||
* @details Objects in the List must inherit the SystemObjectIF.
|
||||
*/
|
||||
std::map<object_id_t, SystemObjectIF*> objectList;
|
||||
protected:
|
||||
@ -54,7 +48,8 @@ public:
|
||||
/**
|
||||
* @brief In the class's destructor, all objects in the list are deleted.
|
||||
*/
|
||||
//SHOULDDO: If, for some reason, deleting an ObjectManager instance is required, check if this works.
|
||||
// SHOULDDO: If, for some reason, deleting an ObjectManager instance is
|
||||
// required, check if this works.
|
||||
virtual ~ObjectManager( void );
|
||||
ReturnValue_t insert( object_id_t id, SystemObjectIF* object );
|
||||
ReturnValue_t remove( object_id_t id );
|
||||
@ -64,4 +59,4 @@ public:
|
||||
|
||||
|
||||
|
||||
#endif /* OBJECTMANAGER_H_ */
|
||||
#endif /* FSFW_OBJECTMANAGER_OBJECTMANAGER_H_ */
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
#define FRAMEWORK_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
#define FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||
|
||||
#include "frameworkObjects.h"
|
||||
#include "SystemObjectIF.h"
|
||||
@ -21,7 +21,6 @@ public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::OBJECT_MANAGER_IF;
|
||||
static constexpr ReturnValue_t INSERTION_FAILED = MAKE_RETURN_CODE( 1 );
|
||||
static constexpr ReturnValue_t NOT_FOUND = MAKE_RETURN_CODE( 2 );
|
||||
|
||||
static constexpr ReturnValue_t CHILD_INIT_FAILED = MAKE_RETURN_CODE( 3 ); //!< Can be used if the initialization of a SystemObject failed.
|
||||
static constexpr ReturnValue_t INTERNAL_ERR_REPORTER_UNINIT = MAKE_RETURN_CODE( 4 );
|
||||
|
||||
@ -80,6 +79,7 @@ public:
|
||||
/**
|
||||
* @brief This is the forward declaration of the global objectManager instance.
|
||||
*/
|
||||
// SHOULDDO: maybe put this in the glob namespace to explicitely mark it global?
|
||||
extern ObjectManagerIF *objectManager;
|
||||
|
||||
/*Documentation can be found in the class method declaration above.*/
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "../events/EventManagerIF.h"
|
||||
#include "ObjectManager.h"
|
||||
#include "SystemObject.h"
|
||||
#include "../events/EventManagerIF.h"
|
||||
|
||||
SystemObject::SystemObject(object_id_t setObjectId, bool doRegister) :
|
||||
objectId(setObjectId), registered(doRegister) {
|
||||
|
@ -1,16 +1,9 @@
|
||||
/**
|
||||
* @file SystemObject.h
|
||||
* @brief This file contains the definition of the SystemObject class.
|
||||
* @date 07.11.2012
|
||||
* @author Ulrich Mohr
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMOBJECT_H_
|
||||
#define SYSTEMOBJECT_H_
|
||||
#ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_
|
||||
#define FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_
|
||||
|
||||
#include "SystemObjectIF.h"
|
||||
#include "../events/Event.h"
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "SystemObjectIF.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
|
||||
/**
|
||||
@ -20,7 +13,8 @@
|
||||
* class that is announced to ObjectManager. It automatically includes
|
||||
* itself (and therefore the inheriting class) in the object manager's
|
||||
* list.
|
||||
* \ingroup system_objects
|
||||
* @author Ulrich Mohr
|
||||
* @ingroup system_objects
|
||||
*/
|
||||
class SystemObject: public SystemObjectIF {
|
||||
private:
|
||||
@ -37,25 +31,28 @@ public:
|
||||
* @param parameter1
|
||||
* @param parameter2
|
||||
*/
|
||||
virtual void triggerEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0);
|
||||
virtual void triggerEvent(Event event, uint32_t parameter1 = 0,
|
||||
uint32_t parameter2 = 0);
|
||||
|
||||
/**
|
||||
* @brief The class's constructor.
|
||||
* @details In the constructor, the object id is set and the class is
|
||||
* inserted in the object manager.
|
||||
* @param setObjectId The id the object shall have.
|
||||
* @param doRegister Determines if the object is registered in the global object manager.
|
||||
* @param doRegister Determines if the object is registered in
|
||||
* the global object manager.
|
||||
*/
|
||||
SystemObject(object_id_t setObjectId, bool doRegister = true);
|
||||
/**
|
||||
* @brief On destruction, the object removes itself from the list.
|
||||
*/
|
||||
virtual ~SystemObject();
|
||||
object_id_t getObjectId() const;
|
||||
virtual ReturnValue_t initialize();
|
||||
object_id_t getObjectId() const override;
|
||||
virtual ReturnValue_t initialize() override;
|
||||
virtual ReturnValue_t checkObjectConnections();
|
||||
|
||||
virtual void forwardEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0) const;
|
||||
virtual void forwardEvent(Event event, uint32_t parameter1 = 0,
|
||||
uint32_t parameter2 = 0) const;
|
||||
};
|
||||
|
||||
#endif /* SYSTEMOBJECT_H_ */
|
||||
#endif /* FSFW_OBJECTMANAGER_SYSTEMOBJECT_H_ */
|
||||
|
@ -1,26 +1,19 @@
|
||||
/**
|
||||
* @file SystemObjectIF.h
|
||||
* @brief This file contains the definition of the SystemObjectIF interface.
|
||||
* @date 18.09.2012
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMOBJECTIF_H_
|
||||
#define SYSTEMOBJECTIF_H_
|
||||
#ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_
|
||||
#define FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_
|
||||
|
||||
#include "../events/EventReportingProxyIF.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
/**
|
||||
* \defgroup system_objects Software System Object Management
|
||||
* The classes to create System Objects and classes to manage these are contained in this group.
|
||||
* System Objects are software elements that can be controlled externally. They all have a unique
|
||||
* object identifier.
|
||||
* @defgroup system_objects Software System Object Management
|
||||
* The classes to create System Objects and classes to manage these are
|
||||
* contained in this group. System Objects are software elements that can be
|
||||
* controlled externally. They all have a unique object identifier.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the typedef for object identifiers.
|
||||
* \ingroup system_objects
|
||||
* @ingroup system_objects
|
||||
*/
|
||||
typedef uint32_t object_id_t;
|
||||
|
||||
@ -29,7 +22,8 @@ typedef uint32_t object_id_t;
|
||||
* list.
|
||||
* It does not provide any method definitions, still it is required to
|
||||
* perform a type check with dynamic_cast.
|
||||
* \ingroup system_objects
|
||||
* @author Bastian Baetz
|
||||
* @ingroup system_objects
|
||||
*/
|
||||
class SystemObjectIF : public EventReportingProxyIF {
|
||||
public:
|
||||
@ -41,24 +35,28 @@ public:
|
||||
/**
|
||||
* The empty virtual destructor as required for C++ interfaces.
|
||||
*/
|
||||
virtual ~SystemObjectIF() {
|
||||
}
|
||||
virtual ~SystemObjectIF() {}
|
||||
/**
|
||||
* Initializes all inter-object dependencies.
|
||||
* This is necessary to avoid circular dependencies of not-fully
|
||||
* initialized objects on start up.
|
||||
* @return - \c RETURN_OK in case the initialization was successful
|
||||
* - \c RETURN_FAILED otherwise
|
||||
* @brief Initializes the object.
|
||||
* There are initialization steps which can also be done in the constructor.
|
||||
* However, there is no clean way to get a returnvalue from a constructor.
|
||||
* Furthermore some components require other system object to be created
|
||||
* which might not have been built yet.
|
||||
* Therefore, a two-step initialization resolves this problem and prevents
|
||||
* circular dependencies of not-fully initialized objects on start up.
|
||||
* @return - @c RETURN_OK in case the initialization was successful
|
||||
* - @c RETURN_FAILED otherwise
|
||||
*/
|
||||
virtual ReturnValue_t initialize() = 0;
|
||||
/**
|
||||
* Checks, if all object-object interconnections are satisfying for operation.
|
||||
* Some objects need certain other objects (or a certain number), to be registered as children.
|
||||
* These checks can be done in this method.
|
||||
* @return - \c RETURN_OK in case the check was successful
|
||||
* - \c any other code otherwise
|
||||
* @brief Checks if all object-object interconnections are satisfying
|
||||
* for operation.
|
||||
* Some objects need certain other objects (or a certain number), to be
|
||||
* registered as children. These checks can be done in this method.
|
||||
* @return - @c RETURN_OK in case the check was successful
|
||||
* - @c any other code otherwise
|
||||
*/
|
||||
virtual ReturnValue_t checkObjectConnections() = 0;
|
||||
};
|
||||
|
||||
#endif /* SYSTEMOBJECTIF_H_ */
|
||||
#endif /* #ifndef FSFW_OBJECTMANAGER_SYSTEMOBJECTIF_H_ */
|
||||
|
@ -1,8 +1,17 @@
|
||||
#ifndef FRAMEWORK_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
|
||||
#define FRAMEWORK_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
|
||||
#ifndef FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
|
||||
#define FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_
|
||||
|
||||
namespace objects {
|
||||
enum framework_objects {
|
||||
// Default verification reporter.
|
||||
PUS_SERVICE_1_VERIFICATION = 0x53000001,
|
||||
PUS_SERVICE_2_DEVICE_ACCESS = 0x53000002,
|
||||
PUS_SERVICE_5_EVENT_REPORTING = 0x53000005,
|
||||
PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008,
|
||||
PUS_SERVICE_9_TIME_MGMT = 0x53000009,
|
||||
PUS_SERVICE_17_TEST = 0x53000017,
|
||||
PUS_SERVICE_200_MODE_MGMT = 0x53000200,
|
||||
|
||||
//Generic IDs for IPC, modes, health, events
|
||||
HEALTH_TABLE = 0x53010000,
|
||||
// MODE_STORE = 0x53010100,
|
||||
@ -12,10 +21,11 @@ enum framework_objects {
|
||||
//IDs for PUS Packet Communication
|
||||
TC_STORE = 0x534f0100,
|
||||
TM_STORE = 0x534f0200,
|
||||
|
||||
NO_OBJECT = 0xFFFFFFFF
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_OBJECTMANAGER_FRAMEWORKOBJECTS_H_ */
|
||||
#endif /* FSFW_OBJECTMANAGER_FRAMEWORKOBJECTS_H_ */
|
||||
|
@ -8,7 +8,7 @@ const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE;
|
||||
FixedTimeslotTask::FixedTimeslotTask(TaskName name, TaskPriority setPriority,
|
||||
TaskStackSize setStack, TaskPeriod overallPeriod,
|
||||
void (*setDeadlineMissedFunc)()) :
|
||||
started(false), handle(NULL), pst(overallPeriod * 1000) {
|
||||
started(false), handle(nullptr), pst(overallPeriod * 1000) {
|
||||
configSTACK_DEPTH_TYPE stackSize = setStack / sizeof(configSTACK_DEPTH_TYPE);
|
||||
xTaskCreate(taskEntryPoint, name, stackSize, this, setPriority, &handle);
|
||||
// All additional attributes are applied to the object.
|
||||
@ -62,8 +62,10 @@ ReturnValue_t FixedTimeslotTask::startTask() {
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
ExecutableObjectIF* handler =
|
||||
objectManager->get<ExecutableObjectIF>(componentId);
|
||||
if (handler != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, handler, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -85,6 +87,8 @@ void FixedTimeslotTask::taskFunctionality() {
|
||||
// start time for the first entry.
|
||||
auto slotListIter = pst.current;
|
||||
|
||||
pst.intializeSequenceAfterTaskCreation();
|
||||
|
||||
//The start time for the first entry is read.
|
||||
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
||||
TickType_t interval = pdMS_TO_TICKS(intervalMs);
|
||||
@ -143,10 +147,6 @@ void FixedTimeslotTask::checkMissedDeadline(const TickType_t xLastWakeTime,
|
||||
}
|
||||
|
||||
void FixedTimeslotTask::handleMissedDeadline() {
|
||||
#ifdef DEBUG
|
||||
sif::warning << "FixedTimeslotTask: " << pcTaskGetName(NULL) <<
|
||||
" missed deadline!\n" << std::flush;
|
||||
#endif
|
||||
if(deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
#ifndef FSFW_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
#define FSFW_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
|
||||
#include "FreeRTOSTaskIF.h"
|
||||
#include "../../devicehandlers/FixedSlotSequence.h"
|
||||
#include "../../tasks/FixedSlotSequence.h"
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../../tasks/Typedef.h"
|
||||
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
@ -99,4 +98,4 @@ protected:
|
||||
void handleMissedDeadline();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_ */
|
||||
#endif /* FSFW_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_ */
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "MessageQueue.h"
|
||||
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
// TODO I guess we should have a way of checking if we are in an ISR and then use the "fromISR" versions of all calls
|
||||
@ -101,7 +102,8 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
reinterpret_cast<const void*>(message->getBuffer()), 0);
|
||||
if (result != pdPASS) {
|
||||
if (!ignoreFault) {
|
||||
InternalErrorReporterIF* internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||
InternalErrorReporterIF* internalErrorReporter =
|
||||
objectManager->get<InternalErrorReporterIF>(
|
||||
objects::INTERNAL_ERROR_REPORTER);
|
||||
if (internalErrorReporter != NULL) {
|
||||
internalErrorReporter->queueMessageNotSent();
|
||||
|
@ -64,6 +64,11 @@ ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
|
||||
void PeriodicTask::taskFunctionality() {
|
||||
TickType_t xLastWakeTime;
|
||||
const TickType_t xPeriod = pdMS_TO_TICKS(this->period * 1000.);
|
||||
|
||||
for (auto const &object: objectList) {
|
||||
object->initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
/* The xLastWakeTime variable needs to be initialized with the current tick
|
||||
count. Note that this is the only time the variable is written to
|
||||
explicitly. After this assignment, xLastWakeTime is updated automatically
|
||||
@ -128,10 +133,6 @@ TaskHandle_t PeriodicTask::getTaskHandle() {
|
||||
}
|
||||
|
||||
void PeriodicTask::handleMissedDeadline() {
|
||||
#ifdef DEBUG
|
||||
sif::warning << "PeriodicTask: " << pcTaskGetName(NULL) <<
|
||||
" missed deadline!\n" << std::flush;
|
||||
#endif
|
||||
if(deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
|
||||
#ifndef FSFW_OSAL_FREERTOS_PERIODICTASK_H_
|
||||
#define FSFW_OSAL_FREERTOS_PERIODICTASK_H_
|
||||
|
||||
#include "FreeRTOSTaskIF.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
#include "../../tasks/Typedef.h"
|
||||
#include "FreeRTOSTaskIF.h"
|
||||
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
@ -24,7 +23,6 @@ public:
|
||||
/**
|
||||
* Keep in Mind that you need to call before this vTaskStartScheduler()!
|
||||
* A lot of task parameters are set in "FreeRTOSConfig.h".
|
||||
* TODO: why does this need to be called before vTaskStartScheduler?
|
||||
* @details
|
||||
* The class is initialized without allocated objects.
|
||||
* These need to be added with #addComponent.
|
||||
@ -125,4 +123,4 @@ protected:
|
||||
void handleMissedDeadline();
|
||||
};
|
||||
|
||||
#endif /* PERIODICTASK_H_ */
|
||||
#endif /* FSFW_OSAL_FREERTOS_PERIODICTASK_H_ */
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
#include "../../ipc/QueueFactory.h"
|
||||
|
||||
#include "MessageQueue.h"
|
||||
|
||||
|
||||
QueueFactory* QueueFactory::factoryInstance = NULL;
|
||||
QueueFactory* QueueFactory::factoryInstance = nullptr;
|
||||
|
||||
|
||||
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom,bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault);
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
|
||||
sentFrom,ignoreFault);
|
||||
}
|
||||
|
||||
QueueFactory* QueueFactory::instance() {
|
||||
if (factoryInstance == NULL) {
|
||||
if (factoryInstance == nullptr) {
|
||||
factoryInstance = new QueueFactory;
|
||||
}
|
||||
return factoryInstance;
|
||||
@ -24,9 +27,9 @@ QueueFactory::QueueFactory() {
|
||||
QueueFactory::~QueueFactory() {
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t message_depth,
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
|
||||
size_t maxMessageSize) {
|
||||
return new MessageQueue(message_depth, maxMessageSize);
|
||||
return new MessageQueue(messageDepth, maxMessageSize);
|
||||
}
|
||||
|
||||
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
||||
|
227
osal/host/Clock.cpp
Normal file
227
osal/host/Clock.cpp
Normal file
@ -0,0 +1,227 @@
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../timemanager/Clock.h"
|
||||
|
||||
#include <chrono>
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(LINUX)
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
uint16_t Clock::leapSeconds = 0;
|
||||
MutexIF* Clock::timeMutex = NULL;
|
||||
|
||||
using SystemClock = std::chrono::system_clock;
|
||||
|
||||
uint32_t Clock::getTicksPerSecond(void){
|
||||
sif::warning << "Clock::getTicksPerSecond: not implemented yet" << std::endl;
|
||||
return 0;
|
||||
//return CLOCKS_PER_SEC;
|
||||
//uint32_t ticks = sysconf(_SC_CLK_TCK);
|
||||
//return ticks;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
|
||||
// do some magic with chrono
|
||||
sif::warning << "Clock::setClock: not implemented yet" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::setClock(const timeval* time) {
|
||||
// do some magic with chrono
|
||||
#if defined(WIN32)
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#elif defined(LINUX)
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#else
|
||||
|
||||
#endif
|
||||
sif::warning << "Clock::getUptime: Not implemented for found OS" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||
#if defined(WIN32)
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto secondsChrono = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||
auto epoch = now.time_since_epoch();
|
||||
time->tv_sec = std::chrono::duration_cast<std::chrono::seconds>(epoch).count();
|
||||
auto fraction = now - secondsChrono;
|
||||
time->tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
fraction).count();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#elif defined(LINUX)
|
||||
timespec timeUnix;
|
||||
int status = clock_gettime(CLOCK_REALTIME,&timeUnix);
|
||||
if(status!=0){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
time->tv_sec = timeUnix.tv_sec;
|
||||
time->tv_usec = timeUnix.tv_nsec / 1000.0;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
#else
|
||||
sif::warning << "Clock::getUptime: Not implemented for found OS" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
||||
// do some magic with chrono
|
||||
sif::warning << "Clock::gerClock_usecs: not implemented yet" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
timeval Clock::getUptime() {
|
||||
timeval timeval;
|
||||
#if defined(WIN32)
|
||||
auto uptime = std::chrono::milliseconds(GetTickCount64());
|
||||
auto secondsChrono = std::chrono::duration_cast<std::chrono::seconds>(uptime);
|
||||
timeval.tv_sec = secondsChrono.count();
|
||||
auto fraction = uptime - secondsChrono;
|
||||
timeval.tv_usec = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
fraction).count();
|
||||
#elif defined(LINUX)
|
||||
double uptimeSeconds;
|
||||
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds)
|
||||
{
|
||||
// value is rounded down automatically
|
||||
timeval.tv_sec = uptimeSeconds;
|
||||
timeval.tv_usec = uptimeSeconds *(double) 1e6 - (timeval.tv_sec *1e6);
|
||||
}
|
||||
#else
|
||||
sif::warning << "Clock::getUptime: Not implemented for found OS" << std::endl;
|
||||
#endif
|
||||
return timeval;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getUptime(timeval* uptime) {
|
||||
*uptime = getUptime();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
||||
timeval uptime = getUptime();
|
||||
*uptimeMs = uptime.tv_sec * 1000 + uptime.tv_usec / 1000;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) {
|
||||
// do some magic with chrono (C++20!)
|
||||
// Right now, the library doesn't have the new features yet.
|
||||
// so we work around that for now.
|
||||
auto now = SystemClock::now();
|
||||
auto seconds = std::chrono::time_point_cast<std::chrono::seconds>(now);
|
||||
auto fraction = now - seconds;
|
||||
time_t tt = SystemClock::to_time_t(now);
|
||||
struct tm* timeInfo;
|
||||
timeInfo = gmtime(&tt);
|
||||
time->year = timeInfo->tm_year + 1900;
|
||||
time->month = timeInfo->tm_mon+1;
|
||||
time->day = timeInfo->tm_mday;
|
||||
time->hour = timeInfo->tm_hour;
|
||||
time->minute = timeInfo->tm_min;
|
||||
time->second = timeInfo->tm_sec;
|
||||
auto usecond = std::chrono::duration_cast<std::chrono::microseconds>(fraction);
|
||||
time->usecond = usecond.count();
|
||||
|
||||
//sif::warning << "Clock::getDateAndTime: not implemented yet" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from,
|
||||
timeval* to) {
|
||||
struct tm time_tm;
|
||||
|
||||
time_tm.tm_year = from->year - 1900;
|
||||
time_tm.tm_mon = from->month - 1;
|
||||
time_tm.tm_mday = from->day;
|
||||
|
||||
time_tm.tm_hour = from->hour;
|
||||
time_tm.tm_min = from->minute;
|
||||
time_tm.tm_sec = from->second;
|
||||
|
||||
time_t seconds = mktime(&time_tm);
|
||||
|
||||
to->tv_sec = seconds;
|
||||
to->tv_usec = from->usecond;
|
||||
//Fails in 2038..
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
sif::warning << "Clock::convertTimeBla: not implemented yet" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {
|
||||
*JD2000 = (time.tv_sec - 946728000. + time.tv_usec / 1000000.) / 24.
|
||||
/ 3600.;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval* tt) {
|
||||
//SHOULDDO: works not for dates in the past (might have less leap seconds)
|
||||
if (timeMutex == NULL) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
uint16_t leapSeconds;
|
||||
ReturnValue_t result = getLeapSeconds(&leapSeconds);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
timeval leapSeconds_timeval = { 0, 0 };
|
||||
leapSeconds_timeval.tv_sec = leapSeconds;
|
||||
|
||||
//initial offset between UTC and TAI
|
||||
timeval UTCtoTAI1972 = { 10, 0 };
|
||||
|
||||
timeval TAItoTT = { 32, 184000 };
|
||||
|
||||
*tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT;
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
|
||||
if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
leapSeconds = leapSeconds_;
|
||||
|
||||
result = timeMutex->unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
|
||||
if(timeMutex == nullptr){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
*leapSeconds_ = leapSeconds;
|
||||
|
||||
result = timeMutex->unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t Clock::checkOrCreateClockMutex(){
|
||||
if(timeMutex == nullptr){
|
||||
MutexFactory* mutexFactory = MutexFactory::instance();
|
||||
if (mutexFactory == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
timeMutex = mutexFactory->createMutex();
|
||||
if (timeMutex == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
197
osal/host/FixedTimeslotTask.cpp
Normal file
197
osal/host/FixedTimeslotTask.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../osal/host/Mutex.h"
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(LINUX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||
void (*setDeadlineMissedFunc)()) :
|
||||
started(false), pollingSeqTable(setPeriod*1000), taskName(name),
|
||||
period(setPeriod), deadlineMissedFunc(setDeadlineMissedFunc) {
|
||||
// It is propably possible to set task priorities by using the native
|
||||
// task handles for Windows / Linux
|
||||
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
|
||||
#if defined(WIN32)
|
||||
/* List of possible priority classes:
|
||||
* https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/
|
||||
* nf-processthreadsapi-setpriorityclass
|
||||
* And respective thread priority numbers:
|
||||
* https://docs.microsoft.com/en-us/windows/
|
||||
* win32/procthread/scheduling-priorities */
|
||||
int result = SetPriorityClass(
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
ABOVE_NORMAL_PRIORITY_CLASS);
|
||||
if(result != 0) {
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
}
|
||||
result = SetThreadPriority(
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
THREAD_PRIORITY_NORMAL);
|
||||
if(result != 0) {
|
||||
sif::error << "FixedTimeslotTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
}
|
||||
#elif defined(LINUX)
|
||||
// we can just copy and paste the code from linux here.
|
||||
#endif
|
||||
}
|
||||
|
||||
FixedTimeslotTask::~FixedTimeslotTask(void) {
|
||||
//Do not delete objects, we were responsible for ptrs only.
|
||||
terminateThread = true;
|
||||
if(mainThread.joinable()) {
|
||||
mainThread.join();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
||||
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||
|
||||
if (not originalTask->started) {
|
||||
// we have to suspend/block here until the task is started.
|
||||
// if semaphores are implemented, use them here.
|
||||
std::unique_lock<std::mutex> lock(initMutex);
|
||||
initCondition.wait(lock);
|
||||
}
|
||||
|
||||
this->taskFunctionality();
|
||||
sif::debug << "FixedTimeslotTask::taskEntryPoint: "
|
||||
"Returned from taskFunctionality." << std::endl;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::startTask() {
|
||||
started = true;
|
||||
|
||||
// Notify task to start.
|
||||
std::lock_guard<std::mutex> lock(initMutex);
|
||||
initCondition.notify_one();
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FixedTimeslotTask::taskFunctionality() {
|
||||
pollingSeqTable.intializeSequenceAfterTaskCreation();
|
||||
|
||||
// A local iterator for the Polling Sequence Table is created to
|
||||
// find the start time for the first entry.
|
||||
auto slotListIter = pollingSeqTable.current;
|
||||
|
||||
// Get start time for first entry.
|
||||
chron_ms interval(slotListIter->pollingTimeMs);
|
||||
auto currentStartTime {
|
||||
std::chrono::duration_cast<chron_ms>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
};
|
||||
if(interval.count() > 0) {
|
||||
delayForInterval(¤tStartTime, interval);
|
||||
}
|
||||
|
||||
/* Enter the loop that defines the task behavior. */
|
||||
for (;;) {
|
||||
if(terminateThread.load()) {
|
||||
break;
|
||||
}
|
||||
//The component for this slot is executed and the next one is chosen.
|
||||
this->pollingSeqTable.executeAndAdvance();
|
||||
if (not pollingSeqTable.slotFollowsImmediately()) {
|
||||
// we need to wait before executing the current slot
|
||||
//this gives us the time to wait:
|
||||
interval = chron_ms(this->pollingSeqTable.getIntervalToPreviousSlotMs());
|
||||
delayForInterval(¤tStartTime, interval);
|
||||
//TODO deadline missed check
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
ExecutableObjectIF* executableObject = objectManager->
|
||||
get<ExecutableObjectIF>(componentId);
|
||||
if (executableObject != nullptr) {
|
||||
pollingSeqTable.addSlot(componentId, slotTimeMs, executionStep,
|
||||
executableObject, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
sif::error << "Component " << std::hex << componentId <<
|
||||
" not found, not adding it to pst" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::checkSequence() const {
|
||||
return pollingSeqTable.checkSequence();
|
||||
}
|
||||
|
||||
uint32_t FixedTimeslotTask::getPeriodMs() const {
|
||||
return period * 1000;
|
||||
}
|
||||
|
||||
bool FixedTimeslotTask::delayForInterval(chron_ms * previousWakeTimeMs,
|
||||
const chron_ms interval) {
|
||||
bool shouldDelay = false;
|
||||
//Get current wakeup time
|
||||
auto currentStartTime =
|
||||
std::chrono::duration_cast<chron_ms>(
|
||||
std::chrono::system_clock::now().time_since_epoch());
|
||||
/* Generate the tick time at which the task wants to wake. */
|
||||
auto nextTimeToWake_ms = (*previousWakeTimeMs) + interval;
|
||||
|
||||
if (currentStartTime < *previousWakeTimeMs) {
|
||||
/* The tick count has overflowed since this function was
|
||||
lasted called. In this case the only time we should ever
|
||||
actually delay is if the wake time has also overflowed,
|
||||
and the wake time is greater than the tick time. When this
|
||||
is the case it is as if neither time had overflowed. */
|
||||
if ((nextTimeToWake_ms < *previousWakeTimeMs)
|
||||
&& (nextTimeToWake_ms > currentStartTime)) {
|
||||
shouldDelay = true;
|
||||
}
|
||||
} else {
|
||||
/* The tick time has not overflowed. In this case we will
|
||||
delay if either the wake time has overflowed, and/or the
|
||||
tick time is less than the wake time. */
|
||||
if ((nextTimeToWake_ms < *previousWakeTimeMs)
|
||||
|| (nextTimeToWake_ms > currentStartTime)) {
|
||||
shouldDelay = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the wake time ready for the next call. */
|
||||
|
||||
(*previousWakeTimeMs) = nextTimeToWake_ms;
|
||||
|
||||
if (shouldDelay) {
|
||||
auto sleepTime = std::chrono::duration_cast<chron_ms>(
|
||||
nextTimeToWake_ms - currentStartTime);
|
||||
std::this_thread::sleep_for(sleepTime);
|
||||
return true;
|
||||
}
|
||||
//We are shifting the time in case the deadline was missed like rtems
|
||||
(*previousWakeTimeMs) = currentStartTime;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
130
osal/host/FixedTimeslotTask.h
Normal file
130
osal/host/FixedTimeslotTask.h
Normal file
@ -0,0 +1,130 @@
|
||||
#ifndef FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_
|
||||
#define FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_
|
||||
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../tasks/FixedSlotSequence.h"
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../../tasks/Typedef.h"
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
class ExecutableObjectIF;
|
||||
|
||||
/**
|
||||
* @brief This class represents a task for periodic activities with multiple
|
||||
* steps and strict timeslot requirements for these steps.
|
||||
* @details
|
||||
* @ingroup task_handling
|
||||
*/
|
||||
class FixedTimeslotTask: public FixedTimeslotTaskIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Standard constructor of the class.
|
||||
* @details
|
||||
* The class is initialized without allocated objects. These need to be
|
||||
* added with #addComponent.
|
||||
* @param priority
|
||||
* @param stack_size
|
||||
* @param setPeriod
|
||||
* @param setDeadlineMissedFunc
|
||||
* The function pointer to the deadline missed function that shall be
|
||||
* assigned.
|
||||
*/
|
||||
FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||
void (*setDeadlineMissedFunc)());
|
||||
/**
|
||||
* @brief Currently, the executed object's lifetime is not coupled with
|
||||
* the task object's lifetime, so the destructor is empty.
|
||||
*/
|
||||
virtual ~FixedTimeslotTask(void);
|
||||
|
||||
/**
|
||||
* @brief The method to start the task.
|
||||
* @details The method starts the task with the respective system call.
|
||||
* Entry point is the taskEntryPoint method described below.
|
||||
* The address of the task object is passed as an argument
|
||||
* to the system call.
|
||||
*/
|
||||
ReturnValue_t startTask(void);
|
||||
|
||||
/**
|
||||
* Add timeslot to the polling sequence table.
|
||||
* @param componentId
|
||||
* @param slotTimeMs
|
||||
* @param executionStep
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep);
|
||||
|
||||
ReturnValue_t checkSequence() const override;
|
||||
|
||||
uint32_t getPeriodMs() const;
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms);
|
||||
|
||||
protected:
|
||||
using chron_ms = std::chrono::milliseconds;
|
||||
|
||||
bool started;
|
||||
//!< Typedef for the List of objects.
|
||||
typedef std::vector<ExecutableObjectIF*> ObjectList;
|
||||
std::thread mainThread;
|
||||
std::atomic<bool> terminateThread = false;
|
||||
|
||||
//! Polling sequence table which contains the object to execute
|
||||
//! and information like the timeslots and the passed execution step.
|
||||
FixedSlotSequence pollingSeqTable;
|
||||
|
||||
std::condition_variable initCondition;
|
||||
std::mutex initMutex;
|
||||
std::string taskName;
|
||||
/**
|
||||
* @brief The period of the task.
|
||||
* @details
|
||||
* The period determines the frequency of the task's execution.
|
||||
* It is expressed in clock ticks.
|
||||
*/
|
||||
TaskPeriod period;
|
||||
|
||||
/**
|
||||
* @brief The pointer to the deadline-missed function.
|
||||
* @details
|
||||
* This pointer stores the function that is executed if the task's deadline
|
||||
* is missed. So, each may react individually on a timing failure.
|
||||
* The pointer may be NULL, then nothing happens on missing the deadline.
|
||||
* The deadline is equal to the next execution of the periodic task.
|
||||
*/
|
||||
void (*deadlineMissedFunc)(void);
|
||||
/**
|
||||
* @brief This is the function executed in the new task's context.
|
||||
* @details
|
||||
* It converts the argument back to the thread object type and copies the
|
||||
* class instance to the task context.
|
||||
* The taskFunctionality method is called afterwards.
|
||||
* @param A pointer to the task object itself is passed as argument.
|
||||
*/
|
||||
|
||||
void taskEntryPoint(void* argument);
|
||||
/**
|
||||
* @brief The function containing the actual functionality of the task.
|
||||
* @details
|
||||
* The method sets and starts the task's period, then enters a loop that is
|
||||
* repeated as long as the isRunning attribute is true. Within the loop,
|
||||
* all performOperation methods of the added objects are called. Afterwards
|
||||
* the checkAndRestartPeriod system call blocks the task until the next
|
||||
* period. On missing the deadline, the deadlineMissedFunction is executed.
|
||||
*/
|
||||
void taskFunctionality(void);
|
||||
|
||||
bool delayForInterval(chron_ms * previousWakeTimeMs,
|
||||
const chron_ms interval);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_ */
|
159
osal/host/MessageQueue.cpp
Normal file
159
osal/host/MessageQueue.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
#include "MessageQueue.h"
|
||||
#include "QueueMapManager.h"
|
||||
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../ipc/MutexHelper.h"
|
||||
|
||||
MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize):
|
||||
messageSize(maxMessageSize), messageDepth(messageDepth) {
|
||||
queueLock = MutexFactory::instance()->createMutex();
|
||||
auto result = QueueMapManager::instance()->addMessageQueue(this, &mqId);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "MessageQueue::MessageQueue:"
|
||||
<< " Could not be created" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueue::~MessageQueue() {
|
||||
MutexFactory::instance()->deleteMutex(queueLock);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, bool ignoreFault) {
|
||||
return sendMessageFrom(sendTo, message, this->getId(), ignoreFault);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessageIF* message) {
|
||||
return sendToDefaultFrom(message, this->getId());
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom, bool ignoreFault) {
|
||||
return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::reply(MessageQueueMessageIF* message) {
|
||||
if (this->lastPartner != 0) {
|
||||
return sendMessageFrom(this->lastPartner, message, this->getId());
|
||||
} else {
|
||||
return MessageQueueIF::NO_REPLY_PARTNER;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return sendMessageFromMessageQueue(sendTo, message, sentFrom,
|
||||
ignoreFault);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t* receivedFrom) {
|
||||
ReturnValue_t status = this->receiveMessage(message);
|
||||
if(status == HasReturnvaluesIF::RETURN_OK) {
|
||||
*receivedFrom = this->lastPartner;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
|
||||
if(messageQueue.empty()) {
|
||||
return MessageQueueIF::EMPTY;
|
||||
}
|
||||
// not sure this will work..
|
||||
//*message = std::move(messageQueue.front());
|
||||
MutexHelper mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20);
|
||||
MessageQueueMessage* currentMessage = &messageQueue.front();
|
||||
std::copy(currentMessage->getBuffer(),
|
||||
currentMessage->getBuffer() + messageSize, message->getBuffer());
|
||||
messageQueue.pop();
|
||||
// The last partner is the first uint32_t field in the message
|
||||
this->lastPartner = message->getSender();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueue::getLastPartner() const {
|
||||
return lastPartner;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::flush(uint32_t* count) {
|
||||
*count = messageQueue.size();
|
||||
// Clears the queue.
|
||||
messageQueue = std::queue<MessageQueueMessage>();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueue::getId() const {
|
||||
return mqId;
|
||||
}
|
||||
|
||||
void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) {
|
||||
defaultDestinationSet = true;
|
||||
this->defaultDestination = defaultDestination;
|
||||
}
|
||||
|
||||
MessageQueueId_t MessageQueue::getDefaultDestination() const {
|
||||
return defaultDestination;
|
||||
}
|
||||
|
||||
bool MessageQueue::isDefaultDestinationSet() const {
|
||||
return defaultDestinationSet;
|
||||
}
|
||||
|
||||
|
||||
// static core function to send messages.
|
||||
ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
if(message->getMessageSize() > message->getMaximumMessageSize()) {
|
||||
// Actually, this should never happen or an error will be emitted
|
||||
// in MessageQueueMessage.
|
||||
// But I will still return a failure here.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
MessageQueue* targetQueue = dynamic_cast<MessageQueue*>(
|
||||
QueueMapManager::instance()->getMessageQueue(sendTo));
|
||||
if(targetQueue == nullptr) {
|
||||
if(not ignoreFault) {
|
||||
InternalErrorReporterIF* internalErrorReporter =
|
||||
objectManager->get<InternalErrorReporterIF>(
|
||||
objects::INTERNAL_ERROR_REPORTER);
|
||||
if (internalErrorReporter != nullptr) {
|
||||
internalErrorReporter->queueMessageNotSent();
|
||||
}
|
||||
}
|
||||
// TODO: Better returnvalue
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
if(targetQueue->messageQueue.size() < targetQueue->messageDepth) {
|
||||
MutexHelper mutexLock(targetQueue->queueLock,
|
||||
MutexIF::TimeoutType::WAITING, 20);
|
||||
// not ideal, works for now though.
|
||||
MessageQueueMessage* mqmMessage =
|
||||
dynamic_cast<MessageQueueMessage*>(message);
|
||||
if(message != nullptr) {
|
||||
targetQueue->messageQueue.push(*mqmMessage);
|
||||
}
|
||||
else {
|
||||
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message"
|
||||
"is not MessageQueueMessage!" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
return MessageQueueIF::FULL;
|
||||
}
|
||||
message->setSender(sentFrom);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::lockQueue(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t lockTimeout) {
|
||||
return queueLock->lockMutex(timeoutType, lockTimeout);
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::unlockQueue() {
|
||||
return queueLock->unlockMutex();
|
||||
}
|
231
osal/host/MessageQueue.h
Normal file
231
osal/host/MessageQueue.h
Normal file
@ -0,0 +1,231 @@
|
||||
#ifndef FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_
|
||||
#define FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_
|
||||
|
||||
#include "../../internalError/InternalErrorReporterIF.h"
|
||||
#include "../../ipc/MessageQueueIF.h"
|
||||
#include "../../ipc/MessageQueueMessage.h"
|
||||
#include "../../ipc/MutexIF.h"
|
||||
#include "../../timemanager/Clock.h"
|
||||
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
|
||||
/**
|
||||
* @brief This class manages sending and receiving of
|
||||
* message queue messages.
|
||||
* @details
|
||||
* Message queues are used to pass asynchronous messages between processes.
|
||||
* They work like post boxes, where all incoming messages are stored in FIFO
|
||||
* order. This class creates a new receiving queue and provides methods to fetch
|
||||
* received messages. Being a child of MessageQueueSender, this class also
|
||||
* provides methods to send a message to a user-defined or a default destination.
|
||||
* In addition it also provides a reply method to answer to the queue it
|
||||
* received its last message from.
|
||||
*
|
||||
* The MessageQueue should be used as "post box" for a single owning object.
|
||||
* So all message queue communication is "n-to-one".
|
||||
* For creating the queue, as well as sending and receiving messages, the class
|
||||
* makes use of the operating system calls provided.
|
||||
*
|
||||
* Please keep in mind that FreeRTOS offers different calls for message queue
|
||||
* operations if called from an ISR.
|
||||
* For now, the system context needs to be switched manually.
|
||||
* @ingroup osal
|
||||
* @ingroup message_queue
|
||||
*/
|
||||
class MessageQueue : public MessageQueueIF {
|
||||
friend class MessageQueueSenderIF;
|
||||
public:
|
||||
/**
|
||||
* @brief The constructor initializes and configures the message queue.
|
||||
* @details
|
||||
* By making use of the according operating system call, a message queue is
|
||||
* created and initialized. The message depth - the maximum number of
|
||||
* messages to be buffered - may be set with the help of a parameter,
|
||||
* whereas the message size is automatically set to the maximum message
|
||||
* queue message size. The operating system sets the message queue id, or
|
||||
* in case of failure, it is set to zero.
|
||||
* @param message_depth
|
||||
* The number of messages to be buffered before passing an error to the
|
||||
* sender. Default is three.
|
||||
* @param max_message_size
|
||||
* With this parameter, the maximum message size can be adjusted.
|
||||
* This should be left default.
|
||||
*/
|
||||
MessageQueue(size_t messageDepth = 3,
|
||||
size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE);
|
||||
|
||||
/** Copying message queues forbidden */
|
||||
MessageQueue(const MessageQueue&) = delete;
|
||||
MessageQueue& operator=(const MessageQueue&) = delete;
|
||||
|
||||
/**
|
||||
* @brief The destructor deletes the formerly created message queue.
|
||||
* @details This is accomplished by using the delete call provided
|
||||
* by the operating system.
|
||||
*/
|
||||
virtual ~MessageQueue();
|
||||
|
||||
/**
|
||||
* @brief This operation sends a message to the given destination.
|
||||
* @details It directly uses the sendMessage call of the MessageQueueSender
|
||||
* parent, but passes its queue id as "sentFrom" parameter.
|
||||
* @param sendTo This parameter specifies the message queue id of the
|
||||
* destination message queue.
|
||||
* @param message A pointer to a previously created message, which is sent.
|
||||
* @param ignoreFault If set to true, the internal software fault counter
|
||||
* is not incremented if queue is full.
|
||||
*/
|
||||
ReturnValue_t sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, bool ignoreFault = false) override;
|
||||
/**
|
||||
* @brief This operation sends a message to the default destination.
|
||||
* @details As in the sendMessage method, this function uses the
|
||||
* sendToDefault call of the MessageQueueSender parent class and adds its
|
||||
* queue id as "sentFrom" information.
|
||||
* @param message A pointer to a previously created message, which is sent.
|
||||
*/
|
||||
ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override;
|
||||
/**
|
||||
* @brief This operation sends a message to the last communication partner.
|
||||
* @details This operation simplifies answering an incoming message by using
|
||||
* the stored lastPartner information as destination. If there was no
|
||||
* message received yet (i.e. lastPartner is zero), an error code is returned.
|
||||
* @param message A pointer to a previously created message, which is sent.
|
||||
*/
|
||||
ReturnValue_t reply(MessageQueueMessageIF* message) override;
|
||||
|
||||
/**
|
||||
* @brief With the sendMessage call, a queue message is sent to a
|
||||
* receiving queue.
|
||||
* @details
|
||||
* This method takes the message provided, adds the sentFrom information and
|
||||
* passes it on to the destination provided with an operating system call.
|
||||
* The OS's return value is returned.
|
||||
* @param sendTo This parameter specifies the message queue id to send
|
||||
* the message to.
|
||||
* @param message This is a pointer to a previously created message,
|
||||
* which is sent.
|
||||
* @param sentFrom The sentFrom information can be set to inject the
|
||||
* sender's queue id into the message. This variable is set to zero by
|
||||
* default.
|
||||
* @param ignoreFault If set to true, the internal software fault counter
|
||||
* is not incremented if queue is full.
|
||||
*/
|
||||
virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
|
||||
bool ignoreFault = false) override;
|
||||
|
||||
/**
|
||||
* @brief The sendToDefault method sends a queue message to the default
|
||||
* destination.
|
||||
* @details
|
||||
* In all other aspects, it works identical to the sendMessage method.
|
||||
* @param message This is a pointer to a previously created message,
|
||||
* which is sent.
|
||||
* @param sentFrom The sentFrom information can be set to inject the
|
||||
* sender's queue id into the message. This variable is set to zero by
|
||||
* default.
|
||||
*/
|
||||
virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message,
|
||||
MessageQueueId_t sentFrom = NO_QUEUE,
|
||||
bool ignoreFault = false) override;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue
|
||||
* and returns the sender.
|
||||
* @details
|
||||
* It works identically to the other receiveMessage call, but in addition
|
||||
* returns the sender's queue id.
|
||||
* @param message A pointer to a message in which the received data is stored.
|
||||
* @param receivedFrom A pointer to a queue id in which the sender's id is stored.
|
||||
*/
|
||||
ReturnValue_t receiveMessage(MessageQueueMessageIF* message,
|
||||
MessageQueueId_t *receivedFrom) override;
|
||||
|
||||
/**
|
||||
* @brief This function reads available messages from the message queue.
|
||||
* @details
|
||||
* If data is available it is stored in the passed message pointer.
|
||||
* The message's original content is overwritten and the sendFrom
|
||||
* information is stored in the lastPartner attribute. Else, the lastPartner
|
||||
* information remains untouched, the message's content is cleared and the
|
||||
* function returns immediately.
|
||||
* @param message A pointer to a message in which the received data is stored.
|
||||
*/
|
||||
ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override;
|
||||
/**
|
||||
* Deletes all pending messages in the queue.
|
||||
* @param count The number of flushed messages.
|
||||
* @return RETURN_OK on success.
|
||||
*/
|
||||
ReturnValue_t flush(uint32_t* count) override;
|
||||
/**
|
||||
* @brief This method returns the message queue id of the last
|
||||
* communication partner.
|
||||
*/
|
||||
MessageQueueId_t getLastPartner() const override;
|
||||
/**
|
||||
* @brief This method returns the message queue id of this class's
|
||||
* message queue.
|
||||
*/
|
||||
MessageQueueId_t getId() const override;
|
||||
|
||||
/**
|
||||
* @brief This method is a simple setter for the default destination.
|
||||
*/
|
||||
void setDefaultDestination(MessageQueueId_t defaultDestination) override;
|
||||
/**
|
||||
* @brief This method is a simple getter for the default destination.
|
||||
*/
|
||||
MessageQueueId_t getDefaultDestination() const override;
|
||||
|
||||
bool isDefaultDestinationSet() const override;
|
||||
|
||||
ReturnValue_t lockQueue(MutexIF::TimeoutType timeoutType,
|
||||
dur_millis_t lockTimeout);
|
||||
ReturnValue_t unlockQueue();
|
||||
protected:
|
||||
/**
|
||||
* @brief Implementation to be called from any send Call within
|
||||
* MessageQueue and MessageQueueSenderIF.
|
||||
* @details
|
||||
* This method takes the message provided, adds the sentFrom information and
|
||||
* passes it on to the destination provided with an operating system call.
|
||||
* The OS's return value is returned.
|
||||
* @param sendTo
|
||||
* This parameter specifies the message queue id to send the message to.
|
||||
* @param message
|
||||
* This is a pointer to a previously created message, which is sent.
|
||||
* @param sentFrom
|
||||
* The sentFrom information can be set to inject the sender's queue id into
|
||||
* the message. This variable is set to zero by default.
|
||||
* @param ignoreFault
|
||||
* If set to true, the internal software fault counter is not incremented
|
||||
* if queue is full.
|
||||
* @param context Specify whether call is made from task or from an ISR.
|
||||
*/
|
||||
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE,
|
||||
bool ignoreFault=false);
|
||||
|
||||
//static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault);
|
||||
|
||||
private:
|
||||
std::queue<MessageQueueMessage> messageQueue;
|
||||
/**
|
||||
* @brief The class stores the queue id it got assigned.
|
||||
* If initialization fails, the queue id is set to zero.
|
||||
*/
|
||||
MessageQueueId_t mqId = 0;
|
||||
size_t messageSize = 0;
|
||||
size_t messageDepth = 0;
|
||||
|
||||
MutexIF* queueLock;
|
||||
|
||||
bool defaultDestinationSet = false;
|
||||
MessageQueueId_t defaultDestination = 0;
|
||||
MessageQueueId_t lastPartner = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_HOST_MESSAGEQUEUE_H_ */
|
39
osal/host/Mutex.cpp
Normal file
39
osal/host/Mutex.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "Mutex.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
Mutex::Mutex() {}
|
||||
|
||||
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType, uint32_t timeoutMs) {
|
||||
if(timeoutMs == MutexIF::BLOCKING) {
|
||||
mutex.lock();
|
||||
locked = true;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
else if(timeoutMs == MutexIF::POLLING) {
|
||||
if(mutex.try_lock()) {
|
||||
locked = true;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
else if(timeoutMs > MutexIF::POLLING){
|
||||
auto chronoMs = std::chrono::milliseconds(timeoutMs);
|
||||
if(mutex.try_lock_for(chronoMs)) {
|
||||
locked = true;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
return MutexIF::MUTEX_TIMEOUT;
|
||||
}
|
||||
|
||||
ReturnValue_t Mutex::unlockMutex() {
|
||||
if(not locked) {
|
||||
return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX;
|
||||
}
|
||||
mutex.unlock();
|
||||
locked = false;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
std::timed_mutex* Mutex::getMutexHandle() {
|
||||
return &mutex;
|
||||
}
|
29
osal/host/Mutex.h
Normal file
29
osal/host/Mutex.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef FSFW_OSAL_HOSTED_MUTEX_H_
|
||||
#define FSFW_OSAL_HOSTED_MUTEX_H_
|
||||
|
||||
#include "../../ipc/MutexIF.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
/**
|
||||
* @brief OS component to implement MUTual EXclusion
|
||||
*
|
||||
* @details
|
||||
* Mutexes are binary semaphores which include a priority inheritance mechanism.
|
||||
* Documentation: https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html
|
||||
* @ingroup osal
|
||||
*/
|
||||
class Mutex : public MutexIF {
|
||||
public:
|
||||
Mutex();
|
||||
ReturnValue_t lockMutex(TimeoutType timeoutType =
|
||||
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) override;
|
||||
ReturnValue_t unlockMutex() override;
|
||||
|
||||
std::timed_mutex* getMutexHandle();
|
||||
private:
|
||||
bool locked = false;
|
||||
std::timed_mutex mutex;
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_HOSTED_MUTEX_H_ */
|
28
osal/host/MutexFactory.cpp
Normal file
28
osal/host/MutexFactory.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../osal/host/Mutex.h"
|
||||
|
||||
//TODO: Different variant than the lazy loading in QueueFactory.
|
||||
//What's better and why? -> one is on heap the other on bss/data
|
||||
//MutexFactory* MutexFactory::factoryInstance = new MutexFactory();
|
||||
MutexFactory* MutexFactory::factoryInstance = nullptr;
|
||||
|
||||
MutexFactory::MutexFactory() {
|
||||
}
|
||||
|
||||
MutexFactory::~MutexFactory() {
|
||||
}
|
||||
|
||||
MutexFactory* MutexFactory::instance() {
|
||||
if (factoryInstance == nullptr){
|
||||
factoryInstance = new MutexFactory();
|
||||
}
|
||||
return MutexFactory::factoryInstance;
|
||||
}
|
||||
|
||||
MutexIF* MutexFactory::createMutex() {
|
||||
return new Mutex();
|
||||
}
|
||||
|
||||
void MutexFactory::deleteMutex(MutexIF* mutex) {
|
||||
delete mutex;
|
||||
}
|
176
osal/host/PeriodicTask.cpp
Normal file
176
osal/host/PeriodicTask.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
#include "Mutex.h"
|
||||
#include "PeriodicTask.h"
|
||||
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(LINUX)
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||
void (*setDeadlineMissedFunc)()) :
|
||||
started(false), taskName(name), period(setPeriod),
|
||||
deadlineMissedFunc(setDeadlineMissedFunc) {
|
||||
// It is propably possible to set task priorities by using the native
|
||||
// task handles for Windows / Linux
|
||||
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
|
||||
#if defined(WIN32)
|
||||
/* List of possible priority classes:
|
||||
* https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/
|
||||
* nf-processthreadsapi-setpriorityclass
|
||||
* And respective thread priority numbers:
|
||||
* https://docs.microsoft.com/en-us/windows/
|
||||
* win32/procthread/scheduling-priorities */
|
||||
int result = SetPriorityClass(
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
ABOVE_NORMAL_PRIORITY_CLASS);
|
||||
if(result != 0) {
|
||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
}
|
||||
result = SetThreadPriority(
|
||||
reinterpret_cast<HANDLE>(mainThread.native_handle()),
|
||||
THREAD_PRIORITY_NORMAL);
|
||||
if(result != 0) {
|
||||
sif::error << "PeriodicTask: Windows SetPriorityClass failed with code "
|
||||
<< GetLastError() << std::endl;
|
||||
}
|
||||
#elif defined(LINUX)
|
||||
// we can just copy and paste the code from linux here.
|
||||
#endif
|
||||
}
|
||||
|
||||
PeriodicTask::~PeriodicTask(void) {
|
||||
//Do not delete objects, we were responsible for ptrs only.
|
||||
terminateThread = true;
|
||||
if(mainThread.joinable()) {
|
||||
mainThread.join();
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
void PeriodicTask::taskEntryPoint(void* argument) {
|
||||
PeriodicTask *originalTask(reinterpret_cast<PeriodicTask*>(argument));
|
||||
|
||||
|
||||
if (not originalTask->started) {
|
||||
// we have to suspend/block here until the task is started.
|
||||
// if semaphores are implemented, use them here.
|
||||
std::unique_lock<std::mutex> lock(initMutex);
|
||||
initCondition.wait(lock);
|
||||
}
|
||||
|
||||
this->taskFunctionality();
|
||||
sif::debug << "PeriodicTask::taskEntryPoint: "
|
||||
"Returned from taskFunctionality." << std::endl;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::startTask() {
|
||||
started = true;
|
||||
|
||||
// Notify task to start.
|
||||
std::lock_guard<std::mutex> lock(initMutex);
|
||||
initCondition.notify_one();
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void PeriodicTask::taskFunctionality() {
|
||||
std::chrono::milliseconds periodChrono(static_cast<uint32_t>(period*1000));
|
||||
auto currentStartTime {
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch())
|
||||
};
|
||||
auto nextStartTime{ currentStartTime };
|
||||
|
||||
/* Enter the loop that defines the task behavior. */
|
||||
for (;;) {
|
||||
if(terminateThread.load()) {
|
||||
break;
|
||||
}
|
||||
for (ObjectList::iterator it = objectList.begin();
|
||||
it != objectList.end(); ++it) {
|
||||
(*it)->performOperation();
|
||||
}
|
||||
if(not delayForInterval(¤tStartTime, periodChrono)) {
|
||||
sif::warning << "PeriodicTask: " << taskName <<
|
||||
" missed deadline!\n" << std::flush;
|
||||
if(deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
|
||||
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
|
||||
object);
|
||||
if (newObject == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t PeriodicTask::getPeriodMs() const {
|
||||
return period * 1000;
|
||||
}
|
||||
|
||||
bool PeriodicTask::delayForInterval(chron_ms* previousWakeTimeMs,
|
||||
const chron_ms interval) {
|
||||
bool shouldDelay = false;
|
||||
//Get current wakeup time
|
||||
auto currentStartTime =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::system_clock::now().time_since_epoch());
|
||||
/* Generate the tick time at which the task wants to wake. */
|
||||
auto nextTimeToWake_ms = (*previousWakeTimeMs) + interval;
|
||||
|
||||
if (currentStartTime < *previousWakeTimeMs) {
|
||||
/* The tick count has overflowed since this function was
|
||||
lasted called. In this case the only time we should ever
|
||||
actually delay is if the wake time has also overflowed,
|
||||
and the wake time is greater than the tick time. When this
|
||||
is the case it is as if neither time had overflowed. */
|
||||
if ((nextTimeToWake_ms < *previousWakeTimeMs)
|
||||
&& (nextTimeToWake_ms > currentStartTime)) {
|
||||
shouldDelay = true;
|
||||
}
|
||||
} else {
|
||||
/* The tick time has not overflowed. In this case we will
|
||||
delay if either the wake time has overflowed, and/or the
|
||||
tick time is less than the wake time. */
|
||||
if ((nextTimeToWake_ms < *previousWakeTimeMs)
|
||||
|| (nextTimeToWake_ms > currentStartTime)) {
|
||||
shouldDelay = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the wake time ready for the next call. */
|
||||
|
||||
(*previousWakeTimeMs) = nextTimeToWake_ms;
|
||||
|
||||
if (shouldDelay) {
|
||||
auto sleepTime = std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
nextTimeToWake_ms - currentStartTime);
|
||||
std::this_thread::sleep_for(sleepTime);
|
||||
return true;
|
||||
}
|
||||
//We are shifting the time in case the deadline was missed like rtems
|
||||
(*previousWakeTimeMs) = currentStartTime;
|
||||
return false;
|
||||
|
||||
}
|
123
osal/host/PeriodicTask.h
Normal file
123
osal/host/PeriodicTask.h
Normal file
@ -0,0 +1,123 @@
|
||||
#ifndef FRAMEWORK_OSAL_HOST_PERIODICTASK_H_
|
||||
#define FRAMEWORK_OSAL_HOST_PERIODICTASK_H_
|
||||
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
#include "../../tasks/Typedef.h"
|
||||
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <atomic>
|
||||
|
||||
class ExecutableObjectIF;
|
||||
|
||||
/**
|
||||
* @brief This class represents a specialized task for
|
||||
* periodic activities of multiple objects.
|
||||
* @details
|
||||
*
|
||||
* @ingroup task_handling
|
||||
*/
|
||||
class PeriodicTask: public PeriodicTaskIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Standard constructor of the class.
|
||||
* @details
|
||||
* The class is initialized without allocated objects. These need to be
|
||||
* added with #addComponent.
|
||||
* @param priority
|
||||
* @param stack_size
|
||||
* @param setPeriod
|
||||
* @param setDeadlineMissedFunc
|
||||
* The function pointer to the deadline missed function that shall be
|
||||
* assigned.
|
||||
*/
|
||||
PeriodicTask(const char *name, TaskPriority setPriority, TaskStackSize setStack,
|
||||
TaskPeriod setPeriod,void (*setDeadlineMissedFunc)());
|
||||
/**
|
||||
* @brief Currently, the executed object's lifetime is not coupled with
|
||||
* the task object's lifetime, so the destructor is empty.
|
||||
*/
|
||||
virtual ~PeriodicTask(void);
|
||||
|
||||
/**
|
||||
* @brief The method to start the task.
|
||||
* @details The method starts the task with the respective system call.
|
||||
* Entry point is the taskEntryPoint method described below.
|
||||
* The address of the task object is passed as an argument
|
||||
* to the system call.
|
||||
*/
|
||||
ReturnValue_t startTask(void);
|
||||
/**
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
* @param object Id of the object to add.
|
||||
* @return
|
||||
* -@c RETURN_OK on success
|
||||
* -@c RETURN_FAILED if the object could not be added.
|
||||
*/
|
||||
ReturnValue_t addComponent(object_id_t object);
|
||||
|
||||
uint32_t getPeriodMs() const;
|
||||
|
||||
ReturnValue_t sleepFor(uint32_t ms);
|
||||
|
||||
protected:
|
||||
using chron_ms = std::chrono::milliseconds;
|
||||
bool started;
|
||||
//!< Typedef for the List of objects.
|
||||
typedef std::vector<ExecutableObjectIF*> ObjectList;
|
||||
std::thread mainThread;
|
||||
std::atomic<bool> terminateThread = false;
|
||||
|
||||
/**
|
||||
* @brief This attribute holds a list of objects to be executed.
|
||||
*/
|
||||
ObjectList objectList;
|
||||
|
||||
std::condition_variable initCondition;
|
||||
std::mutex initMutex;
|
||||
std::string taskName;
|
||||
/**
|
||||
* @brief The period of the task.
|
||||
* @details
|
||||
* The period determines the frequency of the task's execution.
|
||||
* It is expressed in clock ticks.
|
||||
*/
|
||||
TaskPeriod period;
|
||||
/**
|
||||
* @brief The pointer to the deadline-missed function.
|
||||
* @details
|
||||
* This pointer stores the function that is executed if the task's deadline
|
||||
* is missed. So, each may react individually on a timing failure.
|
||||
* The pointer may be NULL, then nothing happens on missing the deadline.
|
||||
* The deadline is equal to the next execution of the periodic task.
|
||||
*/
|
||||
void (*deadlineMissedFunc)(void);
|
||||
/**
|
||||
* @brief This is the function executed in the new task's context.
|
||||
* @details
|
||||
* It converts the argument back to the thread object type and copies the
|
||||
* class instance to the task context.
|
||||
* The taskFunctionality method is called afterwards.
|
||||
* @param A pointer to the task object itself is passed as argument.
|
||||
*/
|
||||
|
||||
void taskEntryPoint(void* argument);
|
||||
/**
|
||||
* @brief The function containing the actual functionality of the task.
|
||||
* @details
|
||||
* The method sets and starts the task's period, then enters a loop that is
|
||||
* repeated as long as the isRunning attribute is true. Within the loop,
|
||||
* all performOperation methods of the added objects are called. Afterwards
|
||||
* the checkAndRestartPeriod system call blocks the task until the next
|
||||
* period. On missing the deadline, the deadlineMissedFunction is executed.
|
||||
*/
|
||||
void taskFunctionality(void);
|
||||
|
||||
bool delayForInterval(chron_ms * previousWakeTimeMs,
|
||||
const chron_ms interval);
|
||||
};
|
||||
|
||||
#endif /* PERIODICTASK_H_ */
|
41
osal/host/QueueFactory.cpp
Normal file
41
osal/host/QueueFactory.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "../../ipc/QueueFactory.h"
|
||||
#include "../../osal/host/MessageQueue.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <cstring>
|
||||
|
||||
QueueFactory* QueueFactory::factoryInstance = nullptr;
|
||||
|
||||
|
||||
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessageIF* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
|
||||
sentFrom,ignoreFault);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
QueueFactory* QueueFactory::instance() {
|
||||
if (factoryInstance == nullptr) {
|
||||
factoryInstance = new QueueFactory;
|
||||
}
|
||||
return factoryInstance;
|
||||
}
|
||||
|
||||
QueueFactory::QueueFactory() {
|
||||
}
|
||||
|
||||
QueueFactory::~QueueFactory() {
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
|
||||
size_t maxMessageSize) {
|
||||
// A thread-safe queue can be implemented by using a combination
|
||||
// of std::queue and std::mutex. This uses dynamic memory allocation
|
||||
// which could be alleviated by using a custom allocator, external library
|
||||
// (etl::queue) or simply using std::queue, we're on a host machine anyway.
|
||||
return new MessageQueue(messageDepth, maxMessageSize);
|
||||
}
|
||||
|
||||
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
||||
delete queue;
|
||||
}
|
52
osal/host/QueueMapManager.cpp
Normal file
52
osal/host/QueueMapManager.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "QueueMapManager.h"
|
||||
|
||||
#include "../../ipc/MutexFactory.h"
|
||||
#include "../../ipc/MutexHelper.h"
|
||||
|
||||
QueueMapManager* QueueMapManager::mqManagerInstance = nullptr;
|
||||
|
||||
QueueMapManager::QueueMapManager() {
|
||||
mapLock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
QueueMapManager* QueueMapManager::instance() {
|
||||
if (mqManagerInstance == nullptr){
|
||||
mqManagerInstance = new QueueMapManager();
|
||||
}
|
||||
return QueueMapManager::mqManagerInstance;
|
||||
}
|
||||
|
||||
ReturnValue_t QueueMapManager::addMessageQueue(
|
||||
MessageQueueIF* queueToInsert, MessageQueueId_t* id) {
|
||||
// Not thread-safe, but it is assumed all message queues are created
|
||||
// at software initialization now. If this is to be made thread-safe in
|
||||
// the future, it propably would be sufficient to lock the increment
|
||||
// operation here
|
||||
uint32_t currentId = queueCounter++;
|
||||
auto returnPair = queueMap.emplace(currentId, queueToInsert);
|
||||
if(not returnPair.second) {
|
||||
// this should never happen for the atomic variable.
|
||||
sif::error << "QueueMapManager: This ID is already inside the map!"
|
||||
<< std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (id != nullptr) {
|
||||
*id = currentId;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueMapManager::getMessageQueue(
|
||||
MessageQueueId_t messageQueueId) const {
|
||||
MutexHelper(mapLock, MutexIF::TimeoutType::WAITING, 50);
|
||||
auto queueIter = queueMap.find(messageQueueId);
|
||||
if(queueIter != queueMap.end()) {
|
||||
return queueIter->second;
|
||||
}
|
||||
else {
|
||||
sif::warning << "QueueMapManager::getQueueHandle: The ID" <<
|
||||
messageQueueId << " does not exists in the map" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
47
osal/host/QueueMapManager.h
Normal file
47
osal/host/QueueMapManager.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_
|
||||
#define FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_
|
||||
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
#include "../../osal/host/MessageQueue.h"
|
||||
#include <unordered_map>
|
||||
#include <atomic>
|
||||
|
||||
using QueueMap = std::unordered_map<MessageQueueId_t, MessageQueueIF*>;
|
||||
|
||||
|
||||
/**
|
||||
* An internal map to map message queue IDs to message queues.
|
||||
* This propably should be a singleton..
|
||||
*/
|
||||
class QueueMapManager {
|
||||
public:
|
||||
//! Returns the single instance of SemaphoreFactory.
|
||||
static QueueMapManager* instance();
|
||||
|
||||
/**
|
||||
* Insert a message queue into the map and returns a message queue ID
|
||||
* @param queue The message queue to insert.
|
||||
* @param id The passed value will be set unless a nullptr is passed
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t addMessageQueue(MessageQueueIF* queue, MessageQueueId_t*
|
||||
id = nullptr);
|
||||
/**
|
||||
* Get the message queue handle by providing a message queue ID.
|
||||
* @param messageQueueId
|
||||
* @return
|
||||
*/
|
||||
MessageQueueIF* getMessageQueue(MessageQueueId_t messageQueueId) const;
|
||||
|
||||
private:
|
||||
//! External instantiation is forbidden.
|
||||
QueueMapManager();
|
||||
uint32_t queueCounter = 1;
|
||||
MutexIF* mapLock;
|
||||
QueueMap queueMap;
|
||||
static QueueMapManager* mqManagerInstance;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_OSAL_HOST_QUEUEMAPMANAGER_H_ */
|
39
osal/host/SemaphoreFactory.cpp
Normal file
39
osal/host/SemaphoreFactory.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "../../tasks/SemaphoreFactory.h"
|
||||
#include "../../osal/linux/BinarySemaphore.h"
|
||||
#include "../../osal/linux/CountingSemaphore.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
||||
|
||||
SemaphoreFactory::SemaphoreFactory() {
|
||||
}
|
||||
|
||||
SemaphoreFactory::~SemaphoreFactory() {
|
||||
delete factoryInstance;
|
||||
}
|
||||
|
||||
SemaphoreFactory* SemaphoreFactory::instance() {
|
||||
if (factoryInstance == nullptr){
|
||||
factoryInstance = new SemaphoreFactory();
|
||||
}
|
||||
return SemaphoreFactory::factoryInstance;
|
||||
}
|
||||
|
||||
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t arguments) {
|
||||
// Just gonna wait for full C++20 for now.
|
||||
sif::error << "SemaphoreFactory: Binary Semaphore not implemented yet."
|
||||
" Returning nullptr!\n" << std::flush;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(const uint8_t maxCount,
|
||||
uint8_t initCount, uint32_t arguments) {
|
||||
// Just gonna wait for full C++20 for now.
|
||||
sif::error << "SemaphoreFactory: Counting Semaphore not implemented yet."
|
||||
" Returning nullptr!\n" << std::flush;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
||||
delete semaphore;
|
||||
}
|
51
osal/host/TaskFactory.cpp
Normal file
51
osal/host/TaskFactory.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "../../osal/host/FixedTimeslotTask.h"
|
||||
#include "../../osal/host/PeriodicTask.h"
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
||||
|
||||
// Will propably not be used for hosted implementation
|
||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = 0;
|
||||
|
||||
TaskFactory::TaskFactory() {
|
||||
}
|
||||
|
||||
TaskFactory::~TaskFactory() {
|
||||
}
|
||||
|
||||
TaskFactory* TaskFactory::instance() {
|
||||
return TaskFactory::factoryInstance;
|
||||
}
|
||||
|
||||
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,
|
||||
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return new PeriodicTask(name_, taskPriority_, stackSize_, periodInSeconds_,
|
||||
deadLineMissedFunction_);
|
||||
}
|
||||
|
||||
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,
|
||||
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return new FixedTimeslotTask(name_, taskPriority_, stackSize_,
|
||||
periodInSeconds_, deadLineMissedFunction_);
|
||||
}
|
||||
|
||||
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
|
||||
// This might block for some time!
|
||||
delete task;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
#include <linux/sysinfo.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
|
||||
//#include <fstream>
|
||||
uint16_t Clock::leapSeconds = 0;
|
||||
MutexIF* Clock::timeMutex = NULL;
|
||||
|
||||
@ -76,22 +76,23 @@ timeval Clock::getUptime() {
|
||||
|
||||
ReturnValue_t Clock::getUptime(timeval* uptime) {
|
||||
//TODO This is not posix compatible and delivers only seconds precision
|
||||
struct sysinfo sysInfo;
|
||||
int result = sysinfo(&sysInfo);
|
||||
if(result != 0){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
uptime->tv_sec = sysInfo.uptime;
|
||||
uptime->tv_usec = 0;
|
||||
|
||||
|
||||
// is the OS not called Linux?
|
||||
//Linux specific file read but more precise
|
||||
// double uptimeSeconds;
|
||||
// if(std::ifstream("/proc/uptime",std::ios::in) >> uptimeSeconds){
|
||||
// uptime->tv_sec = uptimeSeconds;
|
||||
// uptime->tv_usec = uptimeSeconds *(double) 1e6 - (uptime->tv_sec *1e6);
|
||||
// }
|
||||
double uptimeSeconds;
|
||||
if(std::ifstream("/proc/uptime",std::ios::in) >> uptimeSeconds){
|
||||
uptime->tv_sec = uptimeSeconds;
|
||||
uptime->tv_usec = uptimeSeconds *(double) 1e6 - (uptime->tv_sec *1e6);
|
||||
}
|
||||
|
||||
//TODO This is not posix compatible and delivers only seconds precision
|
||||
// I suggest this is moved into another clock function which will
|
||||
// deliver second precision later.
|
||||
// struct sysinfo sysInfo;
|
||||
// int result = sysinfo(&sysInfo);
|
||||
// if(result != 0){
|
||||
// return HasReturnvaluesIF::RETURN_FAILED;
|
||||
// }
|
||||
// return sysInfo.uptime;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "FixedTimeslotTask.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
@ -39,13 +39,16 @@ uint32_t FixedTimeslotTask::getPeriodMs() const {
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
ExecutableObjectIF* executableObject =
|
||||
objectManager->get<ExecutableObjectIF>(componentId);
|
||||
if (executableObject != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep,
|
||||
executableObject,this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
sif::error << "Component " << std::hex << componentId <<
|
||||
" not found, not adding it to pst" << std::endl;
|
||||
" not found, not adding it to pst" << std::dec << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
@ -58,6 +61,9 @@ void FixedTimeslotTask::taskFunctionality() {
|
||||
if (!started) {
|
||||
suspend();
|
||||
}
|
||||
|
||||
pst.intializeSequenceAfterTaskCreation();
|
||||
|
||||
//The start time for the first entry is read.
|
||||
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
|
||||
uint64_t interval = pst.getIntervalToNextSlotMs();
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef FRAMEWORK_OSAL_LINUX_FIXEDTIMESLOTTASK_H_
|
||||
#define FRAMEWORK_OSAL_LINUX_FIXEDTIMESLOTTASK_H_
|
||||
#ifndef FSFW_OSAL_LINUX_FIXEDTIMESLOTTASK_H_
|
||||
#define FSFW_OSAL_LINUX_FIXEDTIMESLOTTASK_H_
|
||||
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../../devicehandlers/FixedSlotSequence.h"
|
||||
#include "PosixThread.h"
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../../tasks/FixedSlotSequence.h"
|
||||
#include <pthread.h>
|
||||
|
||||
class FixedTimeslotTask: public FixedTimeslotTaskIF, public PosixThread {
|
||||
@ -74,4 +74,4 @@ private:
|
||||
bool started;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_FIXEDTIMESLOTTASK_H_ */
|
||||
#endif /* FSFW_OSAL_LINUX_FIXEDTIMESLOTTASK_H_ */
|
||||
|
@ -5,8 +5,8 @@
|
||||
|
||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
||||
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
||||
PosixThread(name_,priority_,stackSize_),objectList(),started(false),
|
||||
periodMs(period_),deadlineMissedFunc(deadlineMissedFunc_) {
|
||||
PosixThread(name_, priority_, stackSize_), objectList(), started(false),
|
||||
periodMs(period_), deadlineMissedFunc(deadlineMissedFunc_) {
|
||||
}
|
||||
|
||||
PeriodicPosixTask::~PeriodicPosixTask() {
|
||||
@ -25,6 +25,8 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
|
||||
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
|
||||
object);
|
||||
if (newObject == nullptr) {
|
||||
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||
<< " it implements ExecutableObjectIF!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
@ -38,35 +40,41 @@ ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void){
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void) {
|
||||
started = true;
|
||||
//sif::info << stackSize << std::endl;
|
||||
PosixThread::createTask(&taskEntryPoint,this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void PeriodicPosixTask::taskFunctionality(void){
|
||||
if(!started){
|
||||
void PeriodicPosixTask::taskFunctionality(void) {
|
||||
if(not started) {
|
||||
suspend();
|
||||
}
|
||||
|
||||
for (auto const &object: objectList) {
|
||||
object->initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
|
||||
//The task's "infinite" inner loop is entered.
|
||||
while (1) {
|
||||
for (ObjectList::iterator it = objectList.begin();
|
||||
it != objectList.end(); ++it) {
|
||||
(*it)->performOperation();
|
||||
for (auto const &object: objectList) {
|
||||
object->performOperation();
|
||||
}
|
||||
if(!PosixThread::delayUntil(&lastWakeTime,periodMs)){
|
||||
|
||||
if(not PosixThread::delayUntil(&lastWakeTime, periodMs)){
|
||||
char name[20] = {0};
|
||||
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
|
||||
if(status==0){
|
||||
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
|
||||
if(status == 0) {
|
||||
sif::error << "PeriodicPosixTask " << name << ": Deadline "
|
||||
"missed." << std::endl;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
|
||||
status << std::endl;
|
||||
}
|
||||
if (this->deadlineMissedFunc != NULL) {
|
||||
if (this->deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
* The address of the task object is passed as an argument
|
||||
* to the system call.
|
||||
*/
|
||||
ReturnValue_t startTask(void);
|
||||
ReturnValue_t startTask() override;
|
||||
/**
|
||||
* Adds an object to the list of objects to be executed.
|
||||
* The objects are executed in the order added.
|
||||
|
@ -1,8 +1,14 @@
|
||||
#include "../../ipc/QueueFactory.h"
|
||||
#include "MessageQueue.h"
|
||||
|
||||
#include "../../ipc/messageQueueDefinitions.h"
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
#include <mqueue.h>
|
||||
#include <errno.h>
|
||||
#include "MessageQueue.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
|
||||
#include <cstring>
|
||||
|
||||
QueueFactory* QueueFactory::factoryInstance = nullptr;
|
||||
|
138
osal/linux/TcUnixUdpPollingTask.cpp
Normal file
138
osal/linux/TcUnixUdpPollingTask.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
#include "TcUnixUdpPollingTask.h"
|
||||
#include "../../globalfunctions/arrayprinter.h"
|
||||
|
||||
TcUnixUdpPollingTask::TcUnixUdpPollingTask(object_id_t objectId,
|
||||
object_id_t tmtcUnixUdpBridge, size_t frameSize,
|
||||
double timeoutSeconds): SystemObject(objectId),
|
||||
tmtcBridgeId(tmtcUnixUdpBridge) {
|
||||
|
||||
if(frameSize > 0) {
|
||||
this->frameSize = frameSize;
|
||||
}
|
||||
else {
|
||||
this->frameSize = DEFAULT_MAX_FRAME_SIZE;
|
||||
}
|
||||
|
||||
// Set up reception buffer with specified frame size.
|
||||
// For now, it is assumed that only one frame is held in the buffer!
|
||||
receptionBuffer.reserve(this->frameSize);
|
||||
receptionBuffer.resize(this->frameSize);
|
||||
|
||||
if(timeoutSeconds == -1) {
|
||||
receptionTimeout = DEFAULT_TIMEOUT;
|
||||
}
|
||||
else {
|
||||
receptionTimeout = timevalOperations::toTimeval(timeoutSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
TcUnixUdpPollingTask::~TcUnixUdpPollingTask() {}
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::performOperation(uint8_t opCode) {
|
||||
// Poll for new UDP datagrams in permanent loop.
|
||||
while(1) {
|
||||
//! Sender Address is cached here.
|
||||
struct sockaddr_in senderAddress;
|
||||
socklen_t senderSockLen = 0;
|
||||
ssize_t bytesReceived = recvfrom(serverUdpSocket,
|
||||
receptionBuffer.data(), frameSize, receptionFlags,
|
||||
reinterpret_cast<sockaddr*>(&senderAddress), &senderSockLen);
|
||||
if(bytesReceived < 0) {
|
||||
// handle error
|
||||
sif::error << "TcSocketPollingTask::performOperation: Reception"
|
||||
"error." << std::endl;
|
||||
handleReadError();
|
||||
|
||||
continue;
|
||||
}
|
||||
// sif::debug << "TcSocketPollingTask::performOperation: " << bytesReceived
|
||||
// << " bytes received" << std::endl;
|
||||
|
||||
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
|
||||
if(result != HasReturnvaluesIF::RETURN_FAILED) {
|
||||
|
||||
}
|
||||
tmtcBridge->registerCommConnect();
|
||||
tmtcBridge->checkAndSetClientAddress(senderAddress);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
|
||||
store_address_t storeId;
|
||||
ReturnValue_t result = tcStore->addData(&storeId,
|
||||
receptionBuffer.data(), bytesRead);
|
||||
// arrayprinter::print(receptionBuffer.data(), bytesRead);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "TcSerialPollingTask::transferPusToSoftwareBus: Data "
|
||||
"storage failed" << std::endl;
|
||||
sif::error << "Packet size: " << bytesRead << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
TmTcMessage message(storeId);
|
||||
|
||||
result = MessageQueueSenderIF::sendMessage(targetTcDestination, &message);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "Serial Polling: Sending message to queue failed"
|
||||
<< std::endl;
|
||||
tcStore->deleteData(storeId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::initialize() {
|
||||
tcStore = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (tcStore == nullptr) {
|
||||
sif::error << "TcSerialPollingTask::initialize: TC Store uninitialized!"
|
||||
<< std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
tmtcBridge = objectManager->get<TmTcUnixUdpBridge>(tmtcBridgeId);
|
||||
if(tmtcBridge == nullptr) {
|
||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Invalid"
|
||||
" TMTC bridge object!" << std::endl;
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
serverUdpSocket = tmtcBridge->serverSocket;
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t TcUnixUdpPollingTask::initializeAfterTaskCreation() {
|
||||
// Initialize the destination after task creation. This ensures
|
||||
// that the destination will be set in the TMTC bridge.
|
||||
targetTcDestination = tmtcBridge->getRequestQueue();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TcUnixUdpPollingTask::setTimeout(double timeoutSeconds) {
|
||||
timeval tval;
|
||||
tval = timevalOperations::toTimeval(timeoutSeconds);
|
||||
int result = setsockopt(serverUdpSocket, SOL_SOCKET, SO_RCVTIMEO,
|
||||
&tval, sizeof(receptionTimeout));
|
||||
if(result == -1) {
|
||||
sif::error << "TcSocketPollingTask::TcSocketPollingTask: Setting "
|
||||
"receive timeout failed with " << strerror(errno) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: sleep after error detection to prevent spam
|
||||
void TcUnixUdpPollingTask::handleReadError() {
|
||||
switch(errno) {
|
||||
case(EAGAIN): {
|
||||
// todo: When working in timeout mode, this will occur more often
|
||||
// and is not an error.
|
||||
sif::error << "TcUnixUdpPollingTask::handleReadError: Timeout."
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::error << "TcUnixUdpPollingTask::handleReadError: "
|
||||
<< strerror(errno) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
67
osal/linux/TcUnixUdpPollingTask.h
Normal file
67
osal/linux/TcUnixUdpPollingTask.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
||||
#define FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_
|
||||
|
||||
#include "../../objectmanager/SystemObject.h"
|
||||
#include "../../osal/linux/TmTcUnixUdpBridge.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief This class can be used to implement the polling of a Unix socket,
|
||||
* using UDP for now.
|
||||
* @details
|
||||
* The task will be blocked while the specified number of bytes has not been
|
||||
* received, so TC reception is handled inside a separate task.
|
||||
* This class caches the IP address of the sender. It is assumed there
|
||||
* is only one sender for now.
|
||||
*/
|
||||
class TcUnixUdpPollingTask: public SystemObject,
|
||||
public ExecutableObjectIF {
|
||||
friend class TmTcUnixUdpBridge;
|
||||
public:
|
||||
static constexpr size_t DEFAULT_MAX_FRAME_SIZE = 2048;
|
||||
//! 0.5 default milliseconds timeout for now.
|
||||
static constexpr timeval DEFAULT_TIMEOUT = {.tv_sec = 0, .tv_usec = 500};
|
||||
|
||||
TcUnixUdpPollingTask(object_id_t objectId, object_id_t tmtcUnixUdpBridge,
|
||||
size_t frameSize = 0, double timeoutSeconds = -1);
|
||||
virtual~ TcUnixUdpPollingTask();
|
||||
|
||||
/**
|
||||
* Turn on optional timeout for UDP polling. In the default mode,
|
||||
* the receive function will block until a packet is received.
|
||||
* @param timeoutSeconds
|
||||
*/
|
||||
void setTimeout(double timeoutSeconds);
|
||||
|
||||
virtual ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
virtual ReturnValue_t initialize() override;
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() override;
|
||||
|
||||
protected:
|
||||
StorageManagerIF* tcStore = nullptr;
|
||||
|
||||
private:
|
||||
//! TMTC bridge is cached.
|
||||
object_id_t tmtcBridgeId = objects::NO_OBJECT;
|
||||
TmTcUnixUdpBridge* tmtcBridge = nullptr;
|
||||
MessageQueueId_t targetTcDestination = MessageQueueIF::NO_QUEUE;
|
||||
//! Reception flags: https://linux.die.net/man/2/recvfrom.
|
||||
int receptionFlags = 0;
|
||||
|
||||
//! Server socket, which is member of TMTC bridge and is assigned in
|
||||
//! constructor
|
||||
int serverUdpSocket = 0;
|
||||
|
||||
std::vector<uint8_t> receptionBuffer;
|
||||
|
||||
size_t frameSize = 0;
|
||||
timeval receptionTimeout;
|
||||
|
||||
ReturnValue_t handleSuccessfullTcRead(size_t bytesRead);
|
||||
void handleReadError();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_TCSOCKETPOLLINGTASK_H_ */
|
170
osal/linux/TmTcUnixUdpBridge.cpp
Normal file
170
osal/linux/TmTcUnixUdpBridge.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
#include "TmTcUnixUdpBridge.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../ipc/MutexHelper.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
TmTcUnixUdpBridge::TmTcUnixUdpBridge(object_id_t objectId,
|
||||
object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId,
|
||||
uint16_t serverPort, uint16_t clientPort):
|
||||
TmTcBridge(objectId, tcDestination, tmStoreId, tcStoreId) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
|
||||
uint16_t setServerPort = DEFAULT_UDP_SERVER_PORT;
|
||||
if(serverPort != 0xFFFF) {
|
||||
setServerPort = serverPort;
|
||||
}
|
||||
|
||||
uint16_t setClientPort = DEFAULT_UDP_CLIENT_PORT;
|
||||
if(clientPort != 0xFFFF) {
|
||||
setClientPort = clientPort;
|
||||
}
|
||||
|
||||
// Set up UDP socket: https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
//clientSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(serverSocket < 0) {
|
||||
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not open"
|
||||
" UDP socket!" << std::endl;
|
||||
handleSocketError();
|
||||
return;
|
||||
}
|
||||
|
||||
serverAddress.sin_family = AF_INET;
|
||||
|
||||
// Accept packets from any interface.
|
||||
//serverAddress.sin_addr.s_addr = inet_addr("127.73.73.0");
|
||||
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serverAddress.sin_port = htons(setServerPort);
|
||||
serverAddressLen = sizeof(serverAddress);
|
||||
setsockopt(serverSocket, SOL_SOCKET, SO_REUSEADDR, &serverSocketOptions,
|
||||
sizeof(serverSocketOptions));
|
||||
|
||||
clientAddress.sin_family = AF_INET;
|
||||
clientAddress.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
clientAddress.sin_port = htons(setClientPort);
|
||||
clientAddressLen = sizeof(clientAddress);
|
||||
|
||||
int result = bind(serverSocket,
|
||||
reinterpret_cast<struct sockaddr*>(&serverAddress),
|
||||
serverAddressLen);
|
||||
if(result == -1) {
|
||||
sif::error << "TmTcUnixUdpBridge::TmTcUnixUdpBridge: Could not bind "
|
||||
"local port " << setServerPort << " to server socket!"
|
||||
<< std::endl;
|
||||
handleBindError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TmTcUnixUdpBridge::~TmTcUnixUdpBridge() {
|
||||
}
|
||||
|
||||
ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
|
||||
int flags = 0;
|
||||
|
||||
clientAddress.sin_addr.s_addr = htons(INADDR_ANY);
|
||||
//clientAddress.sin_addr.s_addr = inet_addr("127.73.73.1");
|
||||
clientAddressLen = sizeof(serverAddress);
|
||||
|
||||
// char ipAddress [15];
|
||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
|
||||
ssize_t bytesSent = sendto(serverSocket, data, dataLen, flags,
|
||||
reinterpret_cast<sockaddr*>(&clientAddress), clientAddressLen);
|
||||
if(bytesSent < 0) {
|
||||
sif::error << "TmTcUnixUdpBridge::sendTm: Send operation failed."
|
||||
<< std::endl;
|
||||
handleSendError();
|
||||
}
|
||||
// sif::debug << "TmTcUnixUdpBridge::sendTm: " << bytesSent << " bytes were"
|
||||
// " sent." << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in newAddress) {
|
||||
MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10);
|
||||
|
||||
// char ipAddress [15];
|
||||
// sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
|
||||
// &newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
// sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
|
||||
// &clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
|
||||
|
||||
// Set new IP address if it has changed.
|
||||
if(clientAddress.sin_addr.s_addr != newAddress.sin_addr.s_addr) {
|
||||
clientAddress.sin_addr.s_addr = newAddress.sin_addr.s_addr;
|
||||
clientAddressLen = sizeof(clientAddress);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TmTcUnixUdpBridge::handleSocketError() {
|
||||
// See: https://man7.org/linux/man-pages/man2/socket.2.html
|
||||
switch(errno) {
|
||||
case(EACCES):
|
||||
case(EINVAL):
|
||||
case(EMFILE):
|
||||
case(ENFILE):
|
||||
case(EAFNOSUPPORT):
|
||||
case(ENOBUFS):
|
||||
case(ENOMEM):
|
||||
case(EPROTONOSUPPORT):
|
||||
sif::error << "TmTcUnixBridge::handleSocketError: Socket creation failed"
|
||||
<< " with " << strerror(errno) << std::endl;
|
||||
break;
|
||||
default:
|
||||
sif::error << "TmTcUnixBridge::handleSocketError: Unknown error"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TmTcUnixUdpBridge::handleBindError() {
|
||||
// See: https://man7.org/linux/man-pages/man2/bind.2.html
|
||||
switch(errno) {
|
||||
case(EACCES): {
|
||||
/*
|
||||
Ephermeral ports can be shown with following command:
|
||||
sysctl -A | grep ip_local_port_range
|
||||
*/
|
||||
sif::error << "TmTcUnixBridge::handleBindError: Port access issue."
|
||||
"Ports 1-1024 are reserved on UNIX systems and require root "
|
||||
"rights while ephermeral ports should not be used as well."
|
||||
<< std::endl;
|
||||
}
|
||||
break;
|
||||
case(EADDRINUSE):
|
||||
case(EBADF):
|
||||
case(EINVAL):
|
||||
case(ENOTSOCK):
|
||||
case(EADDRNOTAVAIL):
|
||||
case(EFAULT):
|
||||
case(ELOOP):
|
||||
case(ENAMETOOLONG):
|
||||
case(ENOENT):
|
||||
case(ENOMEM):
|
||||
case(ENOTDIR):
|
||||
case(EROFS): {
|
||||
sif::error << "TmTcUnixBridge::handleBindError: Socket creation failed"
|
||||
<< " with " << strerror(errno) << std::endl;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::error << "TmTcUnixBridge::handleBindError: Unknown error"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TmTcUnixUdpBridge::handleSendError() {
|
||||
switch(errno) {
|
||||
default:
|
||||
sif::error << "TmTcUnixBridge::handleSendError: "
|
||||
<< strerror(errno) << std::endl;
|
||||
}
|
||||
}
|
||||
|
48
osal/linux/TmTcUnixUdpBridge.h
Normal file
48
osal/linux/TmTcUnixUdpBridge.h
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
|
||||
#define FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_
|
||||
|
||||
#include "../../tmtcservices/AcceptsTelecommandsIF.h"
|
||||
#include "../../tmtcservices/TmTcBridge.h"
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/udp.h>
|
||||
|
||||
class TmTcUnixUdpBridge: public TmTcBridge {
|
||||
friend class TcUnixUdpPollingTask;
|
||||
public:
|
||||
// The ports chosen here should not be used by any other process.
|
||||
// List of used ports on Linux: /etc/services
|
||||
static constexpr uint16_t DEFAULT_UDP_SERVER_PORT = 7301;
|
||||
static constexpr uint16_t DEFAULT_UDP_CLIENT_PORT = 7302;
|
||||
|
||||
TmTcUnixUdpBridge(object_id_t objectId, object_id_t tcDestination,
|
||||
object_id_t tmStoreId, object_id_t tcStoreId,
|
||||
uint16_t serverPort = 0xFFFF,uint16_t clientPort = 0xFFFF);
|
||||
virtual~ TmTcUnixUdpBridge();
|
||||
|
||||
void checkAndSetClientAddress(sockaddr_in clientAddress);
|
||||
|
||||
protected:
|
||||
virtual ReturnValue_t sendTm(const uint8_t * data, size_t dataLen) override;
|
||||
|
||||
private:
|
||||
int serverSocket = 0;
|
||||
|
||||
const int serverSocketOptions = 0;
|
||||
|
||||
struct sockaddr_in clientAddress;
|
||||
socklen_t clientAddressLen = 0;
|
||||
|
||||
struct sockaddr_in serverAddress;
|
||||
socklen_t serverAddressLen = 0;
|
||||
|
||||
//! Access to the client address is mutex protected as it is set
|
||||
//! by another task.
|
||||
MutexIF* mutex;
|
||||
|
||||
void handleSocketError();
|
||||
void handleBindError();
|
||||
void handleSendError();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_TMTCUNIXUDPBRIDGE_H_ */
|
41
pus/Service17Test.cpp
Normal file
41
pus/Service17Test.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "Service17Test.h"
|
||||
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../tmtcpacket/pus/TmPacketStored.h"
|
||||
|
||||
|
||||
Service17Test::Service17Test(object_id_t objectId,
|
||||
uint16_t apid, uint8_t serviceId):
|
||||
PusServiceBase(objectId, apid, serviceId),
|
||||
packetSubCounter(0) {
|
||||
}
|
||||
|
||||
Service17Test::~Service17Test() {
|
||||
}
|
||||
|
||||
ReturnValue_t Service17Test::handleRequest(uint8_t subservice) {
|
||||
switch(subservice){
|
||||
case Subservice::CONNECTION_TEST: {
|
||||
TmPacketStored connectionPacket(apid, serviceId,
|
||||
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
|
||||
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
|
||||
requestQueue->getId());
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
case Subservice::EVENT_TRIGGER_TEST: {
|
||||
TmPacketStored connectionPacket(apid, serviceId,
|
||||
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
|
||||
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
|
||||
requestQueue->getId());
|
||||
triggerEvent(TEST, 1234, 5678);
|
||||
return RETURN_OK;
|
||||
}
|
||||
default:
|
||||
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Service17Test::performService() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
44
pus/Service17Test.h
Normal file
44
pus/Service17Test.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef FSFW_PUS_SERVICE17TEST_H_
|
||||
#define FSFW_PUS_SERVICE17TEST_H_
|
||||
|
||||
#include "../tmtcservices/PusServiceBase.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
|
||||
/**
|
||||
* @brief Test Service
|
||||
* Full Documentation: ECSS-E70-41A p.167
|
||||
*
|
||||
* The test service provides the capability to activate test functions
|
||||
* implemented on-board and to report the results of such tests.
|
||||
* Service capability:
|
||||
* - TC[17,1]: Perform connection test
|
||||
* - TM[17,2]: Send Connection Test Report
|
||||
* - TC[17,128]: Perform connection test and trigger event
|
||||
*
|
||||
* @ingroup pus_services
|
||||
*/
|
||||
class Service17Test: public PusServiceBase {
|
||||
public:
|
||||
// Custom events which can be triggered
|
||||
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_17;
|
||||
static constexpr Event TEST = MAKE_EVENT(0, SEVERITY::INFO);
|
||||
|
||||
enum Subservice: uint8_t {
|
||||
//! [EXPORT] : [COMMAND] Perform connection test
|
||||
CONNECTION_TEST = 1,
|
||||
//! [EXPORT] : [REPLY] Connection test reply
|
||||
CONNECTION_TEST_REPORT = 2,
|
||||
//! [EXPORT] : [COMMAND] Trigger test reply and test event
|
||||
EVENT_TRIGGER_TEST = 128,
|
||||
};
|
||||
|
||||
Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId);
|
||||
virtual ~Service17Test();
|
||||
virtual ReturnValue_t handleRequest(uint8_t subservice) override;
|
||||
virtual ReturnValue_t performService() override;
|
||||
|
||||
protected:
|
||||
uint16_t packetSubCounter = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_PUS_SERVICE17TEST_H_ */
|
58
pus/Service9TimeManagement.cpp
Normal file
58
pus/Service9TimeManagement.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#include "Service9TimeManagement.h"
|
||||
#include "servicepackets/Service9Packets.h"
|
||||
|
||||
#include "../timemanager/CCSDSTime.h"
|
||||
#include "../events/EventManagerIF.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
|
||||
|
||||
Service9TimeManagement::Service9TimeManagement(object_id_t objectId,
|
||||
uint16_t apid, uint8_t serviceId) :
|
||||
PusServiceBase(objectId, apid , serviceId) {
|
||||
}
|
||||
|
||||
Service9TimeManagement::~Service9TimeManagement() {}
|
||||
|
||||
ReturnValue_t Service9TimeManagement::performService() {
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
|
||||
switch(subservice){
|
||||
case SUBSERVICE::SET_TIME:{
|
||||
return setTime();
|
||||
}
|
||||
default:
|
||||
return AcceptsTelecommandsIF::INVALID_SUBSERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Service9TimeManagement::setTime() {
|
||||
Clock::TimeOfDay_t timeToSet;
|
||||
TimePacket timePacket(currentPacket.getApplicationData(),
|
||||
currentPacket.getApplicationDataSize());
|
||||
ReturnValue_t result = CCSDSTime::convertFromCcsds(&timeToSet,
|
||||
timePacket.getTime(), timePacket.getTimeSize());
|
||||
if(result != RETURN_OK) {
|
||||
triggerEvent(CLOCK_SET_FAILURE, result, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t formerUptime;
|
||||
Clock::getUptime(&formerUptime);
|
||||
result = Clock::setClock(&timeToSet);
|
||||
|
||||
if(result == RETURN_OK) {
|
||||
uint32_t newUptime;
|
||||
Clock::getUptime(&newUptime);
|
||||
triggerEvent(CLOCK_SET,newUptime,formerUptime);
|
||||
return RETURN_OK;
|
||||
}
|
||||
else {
|
||||
triggerEvent(CLOCK_SET_FAILURE, result, 0);
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
41
pus/Service9TimeManagement.h
Normal file
41
pus/Service9TimeManagement.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
|
||||
#define FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
|
||||
|
||||
#include "../tmtcservices/PusServiceBase.h"
|
||||
|
||||
class Service9TimeManagement: public PusServiceBase {
|
||||
public:
|
||||
|
||||
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_9;
|
||||
static constexpr Event CLOCK_SET = MAKE_EVENT(0, SEVERITY::INFO); //!< Clock has been set. P1: New Uptime. P2: Old Uptime
|
||||
static constexpr Event CLOCK_SET_FAILURE = MAKE_EVENT(1, SEVERITY::LOW); //!< Clock could not be set. P1: Returncode.
|
||||
|
||||
static constexpr uint8_t CLASS_ID = CLASS_ID::PUS_SERVICE_9;
|
||||
|
||||
/**
|
||||
* @brief This service provides the capability to set the on-board time.
|
||||
*/
|
||||
Service9TimeManagement(object_id_t objectId, uint16_t apid,
|
||||
uint8_t serviceId);
|
||||
|
||||
virtual ~Service9TimeManagement();
|
||||
|
||||
virtual ReturnValue_t performService() override;
|
||||
|
||||
/**
|
||||
* @brief Sets the onboard-time by retrieving the time to set from TC[9,128].
|
||||
*/
|
||||
virtual ReturnValue_t handleRequest(uint8_t subservice) override;
|
||||
|
||||
virtual ReturnValue_t setTime();
|
||||
private:
|
||||
|
||||
enum SUBSERVICE {
|
||||
SET_TIME = 128 //!< [EXPORT] : [COMMAND] Time command in ASCII, CUC or CDS format
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_ */
|
32
pus/servicepackets/Service9Packets.h
Normal file
32
pus/servicepackets/Service9Packets.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef FSFW_PUS_SERVICEPACKETS_SERVICE9PACKETS_H_
|
||||
#define FSFW_PUS_SERVICEPACKETS_SERVICE9PACKETS_H_
|
||||
|
||||
#include "../../serialize/SerialLinkedListAdapter.h"
|
||||
|
||||
/**
|
||||
* @brief Subservice 128
|
||||
* @details
|
||||
* It only contains the time encoded as ASCII, CRC, CUC or CDS
|
||||
* @ingroup spacepackets
|
||||
*/
|
||||
class TimePacket : SerialLinkedListAdapter<SerializeIF> { //!< [EXPORT] : [SUBSERVICE] 128
|
||||
public:
|
||||
TimePacket(const uint8_t * timeBuffer_, uint32_t timeSize_) {
|
||||
timeBuffer = timeBuffer_;
|
||||
timeSize = timeSize_;
|
||||
}
|
||||
const uint8_t* getTime() {
|
||||
return timeBuffer;
|
||||
}
|
||||
|
||||
uint32_t getTimeSize() const {
|
||||
return timeSize;
|
||||
}
|
||||
|
||||
private:
|
||||
TimePacket(const TimePacket &command);
|
||||
const uint8_t * timeBuffer;
|
||||
uint32_t timeSize; //!< [EXPORT] : [IGNORE]
|
||||
};
|
||||
|
||||
#endif /* FSFW_PUS_SERVICEPACKETS_SERVICE9PACKETS_H_ */
|
@ -1,5 +1,5 @@
|
||||
#ifndef FRAMEWORK_RETURNVALUES_FWCLASSIDS_H_
|
||||
#define FRAMEWORK_RETURNVALUES_FWCLASSIDS_H_
|
||||
#ifndef FSFW_RETURNVALUES_FWCLASSIDS_H_
|
||||
#define FSFW_RETURNVALUES_FWCLASSIDS_H_
|
||||
|
||||
namespace CLASS_ID {
|
||||
enum {
|
||||
@ -56,7 +56,6 @@ enum {
|
||||
DEVICE_COMMUNICATION_IF, //DC
|
||||
BSP, //BSP
|
||||
TIME_STAMPER_IF, //TSI 53
|
||||
//TODO This will shift all IDs for FLP
|
||||
SGP4PROPAGATOR_CLASS, //SGP4 54
|
||||
MUTEX_IF, //MUX 55
|
||||
MESSAGE_QUEUE_IF,//MQI 56
|
||||
@ -64,9 +63,11 @@ enum {
|
||||
LOCAL_POOL_OWNER_IF, //LPIF 58
|
||||
POOL_VARIABLE_IF, //PVA 59
|
||||
HOUSEKEEPING_MANAGER, //HKM 60
|
||||
DLE_ENCODER, //DLEE 61
|
||||
PUS_SERVICE_9, //PUS9 62
|
||||
FW_CLASS_ID_COUNT //is actually count + 1 !
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* FRAMEWORK_RETURNVALUES_FWCLASSIDS_H_ */
|
||||
#endif /* FSFW_RETURNVALUES_FWCLASSIDS_H_ */
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef ENDIANSWAPPER_H_
|
||||
#define ENDIANSWAPPER_H_
|
||||
#ifndef FSFW_SERIALIZE_ENDIANCONVERTER_H_
|
||||
#define FSFW_SERIALIZE_ENDIANCONVERTER_H_
|
||||
|
||||
#include "../osal/Endiness.h"
|
||||
#include <cstring>
|
||||
@ -35,9 +35,7 @@
|
||||
*/
|
||||
class EndianConverter {
|
||||
private:
|
||||
EndianConverter() {
|
||||
}
|
||||
;
|
||||
EndianConverter() {};
|
||||
public:
|
||||
/**
|
||||
* Convert a typed variable between big endian and machine endian.
|
||||
@ -123,4 +121,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ENDIANSWAPPER_H_ */
|
||||
#endif /* FSFW_SERIALIZE_ENDIANCONVERTER_H_ */
|
||||
|
@ -1,13 +1,14 @@
|
||||
#ifndef FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
#define FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
#ifndef FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
#define FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_
|
||||
|
||||
#include "../container/ArrayList.h"
|
||||
#include "SerializeIF.h"
|
||||
#include "../container/ArrayList.h"
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* @ingroup serialize
|
||||
* Also serializes length field !
|
||||
* @author baetz
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
class SerialArrayListAdapter : public SerializeIF {
|
||||
@ -27,8 +28,8 @@ public:
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
count_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
|
||||
result = SerializeAdapter::serialize(&list->entries[i], buffer,
|
||||
size, maxSize, streamEndianness);
|
||||
result = SerializeAdapter::serialize(&list->entries[i], buffer, size,
|
||||
maxSize, streamEndianness);
|
||||
++i;
|
||||
}
|
||||
return result;
|
||||
@ -66,6 +67,7 @@ public:
|
||||
if (tempSize > list->maxSize()) {
|
||||
return SerializeIF::TOO_MANY_ELEMENTS;
|
||||
}
|
||||
|
||||
list->size = tempSize;
|
||||
count_t i = 0;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) {
|
||||
@ -76,10 +78,9 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
ArrayList<T, count_t> *adaptee;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_SERIALIZE_SERIALARRAYLISTADAPTER_H_ */
|
||||
#endif /* FSFW_SERIALIZE_SERIALARRAYLISTADAPTER_H_ */
|
||||
|
@ -1,31 +1,57 @@
|
||||
#ifndef SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
#define SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
#ifndef FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
#define FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_
|
||||
|
||||
#include "../container/FixedArrayList.h"
|
||||
#include "SerialArrayListAdapter.h"
|
||||
#include "../container/FixedArrayList.h"
|
||||
|
||||
/**
|
||||
* \ingroup serialize
|
||||
* @brief This adapter provides an interface for SerializeIF to serialize and
|
||||
* deserialize buffers with a header containing the buffer length.
|
||||
* @details
|
||||
* Can be used by SerialLinkedListAdapter by declaring
|
||||
* as a linked element with SerializeElement<SerialFixedArrayListAdapter<...>>.
|
||||
* The sequence of objects is defined in the constructor by
|
||||
* using the setStart and setNext functions.
|
||||
*
|
||||
* @tparam BUFFER_TYPE: Specifies the data type of the buffer
|
||||
* @tparam MAX_SIZE: Specifies the maximum allowed number of elements
|
||||
* (not bytes!)
|
||||
* @tparam count_t: specifies the type/size of the length field which defaults
|
||||
* to one byte.
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class SerialFixedArrayListAdapter : public FixedArrayList<T, MAX_SIZE, count_t>, public SerializeIF {
|
||||
template<typename BUFFER_TYPE, uint32_t MAX_SIZE, typename count_t = uint8_t>
|
||||
class SerialFixedArrayListAdapter :
|
||||
public FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>,
|
||||
public SerializeIF {
|
||||
public:
|
||||
/**
|
||||
* Constructor arguments are forwarded to FixedArrayList constructor.
|
||||
* Refer to the fixed array list constructors for different options.
|
||||
* @param args
|
||||
*/
|
||||
template<typename... Args>
|
||||
SerialFixedArrayListAdapter(Args... args) : FixedArrayList<T, MAX_SIZE, count_t>(std::forward<Args>(args)...) {
|
||||
}
|
||||
SerialFixedArrayListAdapter(Args... args) :
|
||||
FixedArrayList<BUFFER_TYPE, MAX_SIZE, count_t>(
|
||||
std::forward<Args>(args)...){}
|
||||
|
||||
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||
size_t maxSize, Endianness streamEndianness) const {
|
||||
return SerialArrayListAdapter<T, count_t>::serialize(this, buffer, size, maxSize, streamEndianness);
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::serialize(this,
|
||||
buffer, size, maxSize, streamEndianness);
|
||||
}
|
||||
|
||||
size_t getSerializedSize() const {
|
||||
return SerialArrayListAdapter<T, count_t>::getSerializedSize(this);
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::
|
||||
getSerializedSize(this);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
return SerialArrayListAdapter<T, count_t>::deSerialize(this, buffer, size, streamEndianness);
|
||||
return SerialArrayListAdapter<BUFFER_TYPE, count_t>::deSerialize(this,
|
||||
buffer, size, streamEndianness);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SERIALFIXEDARRAYLISTADAPTER_H_ */
|
||||
#endif /* FSFW_SERIALIZE_SERIALFIXEDARRAYLISTADAPTER_H_ */
|
||||
|
@ -1,32 +1,52 @@
|
||||
/**
|
||||
* @file SerialLinkedListAdapter.h
|
||||
* @brief This file defines the SerialLinkedListAdapter class.
|
||||
* @date 22.07.2014
|
||||
* @author baetz
|
||||
*/
|
||||
#ifndef SERIALLINKEDLISTADAPTER_H_
|
||||
#define SERIALLINKEDLISTADAPTER_H_
|
||||
#ifndef FSFW_SERIALIZE_SERIALLINKEDLISTADAPTER_H_
|
||||
#define FSFW_SERIALIZE_SERIALLINKEDLISTADAPTER_H_
|
||||
|
||||
#include "../container/SinglyLinkedList.h"
|
||||
#include "SerializeAdapter.h"
|
||||
#include "SerializeElement.h"
|
||||
#include "SerializeIF.h"
|
||||
//This is where we need the SerializeAdapter!
|
||||
|
||||
/**
|
||||
* \ingroup serialize
|
||||
/**
|
||||
* @brief Implement the conversion of object data to data streams
|
||||
* or vice-versa, using linked lists.
|
||||
* @details
|
||||
* An alternative to the AutoSerializeAdapter functions
|
||||
* - All object members with a datatype are declared as
|
||||
* SerializeElement<element_type> members inside the class
|
||||
* implementing this adapter.
|
||||
* - The element type can also be a SerialBufferAdapter to
|
||||
* de-/serialize buffers.
|
||||
* - The element type can also be a SerialFixedArrayListAdapter to
|
||||
* de-/serialize buffers with a size header, which is scanned automatically.
|
||||
*
|
||||
* The sequence of objects is defined in the constructor by using
|
||||
* the setStart and setNext functions.
|
||||
*
|
||||
* 1. The serialization process is done by instantiating the class and
|
||||
* calling serialize after all SerializeElement entries have been set by
|
||||
* using the constructor or setter functions. An additional size variable
|
||||
* can be supplied which is calculated/incremented automatically.
|
||||
* 2. The deserialization process is done by instantiating the class and
|
||||
* supplying a buffer with the data which is converted into an object.
|
||||
* The size of data to serialize can be supplied and is
|
||||
* decremented in the function. Range checking is done internally.
|
||||
* @author baetz
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T, typename count_t = uint8_t>
|
||||
class SerialLinkedListAdapter: public SinglyLinkedList<T>, public SerializeIF {
|
||||
public:
|
||||
|
||||
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start,
|
||||
bool printCount = false) :
|
||||
SinglyLinkedList<T>(start), printCount(printCount) {
|
||||
}
|
||||
|
||||
SerialLinkedListAdapter(LinkedElement<T>* first, bool printCount = false) :
|
||||
SinglyLinkedList<T>(first), printCount(printCount) {
|
||||
|
||||
}
|
||||
|
||||
SerialLinkedListAdapter(bool printCount = false) :
|
||||
SinglyLinkedList<T>(), printCount(printCount) {
|
||||
}
|
||||
@ -49,13 +69,14 @@ public:
|
||||
uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) {
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->serialize(buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
if (printCount) {
|
||||
return SerialLinkedListAdapter<T>::getSerializedSize()
|
||||
@ -64,32 +85,44 @@ public:
|
||||
return getSerializedSize(SinglyLinkedList<T>::start);
|
||||
}
|
||||
}
|
||||
|
||||
static size_t getSerializedSize(const LinkedElement<T> *element) {
|
||||
size_t size = 0;
|
||||
while (element != NULL) {
|
||||
while (element != nullptr) {
|
||||
size += element->value->getSerializedSize();
|
||||
element = element->getNext();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) override {
|
||||
return deSerialize(SinglyLinkedList<T>::start, buffer, size, streamEndianness);
|
||||
return deSerialize(SinglyLinkedList<T>::start, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
static ReturnValue_t deSerialize(LinkedElement<T>* element,
|
||||
const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) {
|
||||
while ((result == HasReturnvaluesIF::RETURN_OK) and (element != nullptr)) {
|
||||
result = element->value->deSerialize(buffer, size, streamEndianness);
|
||||
element = element->getNext();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool printCount;
|
||||
/**
|
||||
* Copying is forbidden by deleting the copy constructor and the copy
|
||||
* assignment operator because of the pointers to the linked list members.
|
||||
* Unless the child class implements an own copy constructor or
|
||||
* copy assignment operator, these operation will throw a compiler error.
|
||||
* @param
|
||||
*/
|
||||
SerialLinkedListAdapter(const SerialLinkedListAdapter &) = delete;
|
||||
SerialLinkedListAdapter& operator=(const SerialLinkedListAdapter&) = delete;
|
||||
|
||||
bool printCount;
|
||||
};
|
||||
|
||||
#endif /* SERIALLINKEDLISTADAPTER_H_ */
|
||||
#endif /* FSFW_SERIALIZE_SERIALLINKEDLISTADAPTER_H_ */
|
||||
|
@ -1,48 +1,114 @@
|
||||
#ifndef SERIALIZEADAPTER_H_
|
||||
#define SERIALIZEADAPTER_H_
|
||||
#ifndef _FSFW_SERIALIZE_SERIALIZEADAPTER_H_
|
||||
#define _FSFW_SERIALIZE_SERIALIZEADAPTER_H_
|
||||
|
||||
#include "../container/IsDerivedFrom.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "EndianConverter.h"
|
||||
#include "SerializeIF.h"
|
||||
#include <string.h>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
/**
|
||||
* \ingroup serialize
|
||||
/**
|
||||
* @brief These adapters provides an interface to use the SerializeIF functions
|
||||
* with arbitrary template objects to facilitate and simplify the
|
||||
* serialization of classes with different multiple different data types
|
||||
* into buffers and vice-versa.
|
||||
* @details
|
||||
* The correct serialization or deserialization function is chosen at
|
||||
* compile time with template type deduction.
|
||||
*
|
||||
* @ingroup serialize
|
||||
*/
|
||||
|
||||
class SerializeAdapter {
|
||||
public:
|
||||
/***
|
||||
* This function can be used to serialize a trivial copy-able type or a
|
||||
* child of SerializeIF.
|
||||
* The right template to be called is determined in the function itself.
|
||||
* For objects of non trivial copy-able type this function is almost never
|
||||
* called by the user directly. Instead helpers for specific types like
|
||||
* SerialArrayListAdapter or SerialLinkedListAdapter is the right choice here.
|
||||
*
|
||||
* @param[in] object Object to serialize, the used type is deduced from this pointer
|
||||
* @param[in/out] buffer Buffer to serialize into. Will be moved by the function.
|
||||
* @param[in/out] size Size of current written buffer. Will be incremented by the function.
|
||||
* @param[in] maxSize Max size of Buffer
|
||||
* @param[in] streamEndianness Endianness of serialized element as in according to SerializeIF::Endianness
|
||||
* @return
|
||||
* - @c BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic Error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t maxSize, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, IsDerivedFrom<T, SerializeIF>::Is> adapter;
|
||||
size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.serialize(object, buffer, size, maxSize,
|
||||
streamEndianness);
|
||||
}
|
||||
/**
|
||||
* Function to return the serialized size of the object in the pointer.
|
||||
* May be a trivially copy-able object or a Child of SerializeIF
|
||||
*
|
||||
* @param object Pointer to Object
|
||||
* @return Serialized size of object
|
||||
*/
|
||||
template<typename T>
|
||||
static uint32_t getSerializedSize(const T *object) {
|
||||
InternalSerializeAdapter<T, IsDerivedFrom<T, SerializeIF>::Is> adapter;
|
||||
static size_t getSerializedSize(const T *object){
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.getSerializedSize(object);
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* Deserializes a object from a given buffer of given size.
|
||||
* Object Must be trivially copy-able or a child of SerializeIF.
|
||||
*
|
||||
* @details
|
||||
* Buffer will be moved to the current read location. Size will be decreased by the function.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
template<typename T>
|
||||
static ReturnValue_t deSerialize(T *object, const uint8_t **buffer,
|
||||
size_t *size, SerializeIF::Endianness streamEndianness) {
|
||||
InternalSerializeAdapter<T, IsDerivedFrom<T, SerializeIF>::Is> adapter;
|
||||
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
|
||||
return adapter.deSerialize(object, buffer, size, streamEndianness);
|
||||
}
|
||||
private:
|
||||
template<typename T, int>
|
||||
class InternalSerializeAdapter {
|
||||
/**
|
||||
* Internal template to deduce the right function calls at compile time
|
||||
*/
|
||||
template<typename T, bool> class InternalSerializeAdapter;
|
||||
|
||||
/**
|
||||
* Template to be used if T is not a child of SerializeIF
|
||||
*
|
||||
* @tparam T T must be trivially_copyable
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, false> {
|
||||
static_assert (std::is_trivially_copyable<T>::value,
|
||||
"If a type needs to be serialized it must be a child of "
|
||||
"SerializeIF or trivially copy-able");
|
||||
public:
|
||||
static ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size, SerializeIF::Endianness streamEndianness) {
|
||||
size_t *size, size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == NULL) {
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
//TODO check integer overflow of *size
|
||||
if (sizeof(T) + *size <= max_size) {
|
||||
// Check remaining size is large enough and check integer
|
||||
// overflow of *size
|
||||
size_t newSize = sizeof(T) + *size;
|
||||
if ((newSize <= max_size) and (newSize > *size)) {
|
||||
T tmp;
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
@ -56,7 +122,7 @@ private:
|
||||
tmp = *object;
|
||||
break;
|
||||
}
|
||||
memcpy(*buffer, &tmp, sizeof(T));
|
||||
std::memcpy(*buffer, &tmp, sizeof(T));
|
||||
*size += sizeof(T);
|
||||
(*buffer) += sizeof(T);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -70,7 +136,7 @@ private:
|
||||
T tmp;
|
||||
if (*size >= sizeof(T)) {
|
||||
*size -= sizeof(T);
|
||||
memcpy(&tmp, *buffer, sizeof(T));
|
||||
std::memcpy(&tmp, *buffer, sizeof(T));
|
||||
switch (streamEndianness) {
|
||||
case SerializeIF::Endianness::BIG:
|
||||
*object = EndianConverter::convertBigEndian<T>(tmp);
|
||||
@ -94,22 +160,26 @@ private:
|
||||
uint32_t getSerializedSize(const T *object) {
|
||||
return sizeof(T);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Template for objects that inherit from SerializeIF
|
||||
*
|
||||
* @tparam T A child of SerializeIF
|
||||
*/
|
||||
template<typename T>
|
||||
class InternalSerializeAdapter<T, 1> {
|
||||
class InternalSerializeAdapter<T, true> {
|
||||
public:
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer,
|
||||
size_t *size, size_t max_size,
|
||||
ReturnValue_t serialize(const T *object, uint8_t **buffer, size_t *size,
|
||||
size_t max_size,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
size_t ignoredSize = 0;
|
||||
if (size == NULL) {
|
||||
if (size == nullptr) {
|
||||
size = &ignoredSize;
|
||||
}
|
||||
return object->serialize(buffer, size, max_size, streamEndianness);
|
||||
}
|
||||
uint32_t getSerializedSize(const T *object) const {
|
||||
size_t getSerializedSize(const T *object) const {
|
||||
return object->getSerializedSize();
|
||||
}
|
||||
|
||||
@ -120,4 +190,4 @@ private:
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* SERIALIZEADAPTER_H_ */
|
||||
#endif /* _FSFW_SERIALIZE_SERIALIZEADAPTER_H_ */
|
||||
|
@ -1,12 +1,20 @@
|
||||
#ifndef SERIALIZEELEMENT_H_
|
||||
#define SERIALIZEELEMENT_H_
|
||||
#ifndef FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
||||
#define FSFW_SERIALIZE_SERIALIZEELEMENT_H_
|
||||
|
||||
#include "../container/SinglyLinkedList.h"
|
||||
#include "SerializeAdapter.h"
|
||||
#include "../container/SinglyLinkedList.h"
|
||||
#include <utility>
|
||||
|
||||
/**
|
||||
* \ingroup serialize
|
||||
* @brief This class is used to mark datatypes for serialization with the
|
||||
* SerialLinkedListAdapter
|
||||
* @details
|
||||
* Used by declaring any arbitrary datatype with SerializeElement<T> myVariable,
|
||||
* inside a SerialLinkedListAdapter implementation and setting the sequence
|
||||
* of objects with setNext() and setStart().
|
||||
* Serialization and Deserialization is then performed automatically in
|
||||
* specified sequence order.
|
||||
* @ingroup serialize
|
||||
*/
|
||||
template<typename T>
|
||||
class SerializeElement: public SerializeIF, public LinkedElement<SerializeIF> {
|
||||
@ -19,7 +27,7 @@ public:
|
||||
SerializeElement() :
|
||||
LinkedElement<SerializeIF>(this) {
|
||||
}
|
||||
T entry;
|
||||
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override {
|
||||
return SerializeAdapter::serialize(&entry, buffer, size, maxSize,
|
||||
@ -35,6 +43,7 @@ public:
|
||||
return SerializeAdapter::deSerialize(&entry, buffer, size,
|
||||
streamEndianness);
|
||||
}
|
||||
|
||||
operator T() {
|
||||
return entry;
|
||||
}
|
||||
@ -43,9 +52,12 @@ public:
|
||||
entry = newValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T* operator->() {
|
||||
return &entry;
|
||||
}
|
||||
|
||||
T entry;
|
||||
};
|
||||
|
||||
#endif /* SERIALIZEELEMENT_H_ */
|
||||
#endif /* FSFW_SERIALIZE_SERIALIZEELEMENT_H_ */
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define FSFW_SERIALIZE_SERIALIZEIF_H_
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <stddef.h>
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @defgroup serialize Serialization
|
||||
@ -10,7 +10,10 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Translation of objects into data streams and from data streams.
|
||||
* @brief Translation of objects into data streams and from data streams.
|
||||
* @details
|
||||
* Also provides options to convert from/to data with different endianness.
|
||||
* variables.
|
||||
* @ingroup serialize
|
||||
*/
|
||||
class SerializeIF {
|
||||
@ -43,7 +46,7 @@ public:
|
||||
* @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 BUFFER_TOO_SHORT The given buffer in is too short
|
||||
* - @c RETURN_FAILED Generic error
|
||||
* - @c RETURN_OK Successful serialization
|
||||
*/
|
||||
|
@ -550,7 +550,7 @@ Mode_t Subsystem::getFallbackSequence(Mode_t sequence) {
|
||||
for (FixedMap<Mode_t, SequenceInfo>::Iterator iter = modeSequences.begin();
|
||||
iter != modeSequences.end(); ++iter) {
|
||||
if (iter.value->first == sequence) {
|
||||
return iter->fallbackSequence;
|
||||
return iter->second.fallbackSequence;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
@ -559,7 +559,7 @@ Mode_t Subsystem::getFallbackSequence(Mode_t sequence) {
|
||||
bool Subsystem::isFallbackSequence(Mode_t SequenceId) {
|
||||
for (FixedMap<Mode_t, SequenceInfo>::Iterator iter = modeSequences.begin();
|
||||
iter != modeSequences.end(); iter++) {
|
||||
if (iter->fallbackSequence == SequenceId) {
|
||||
if (iter->second.fallbackSequence == SequenceId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
17
tasks/FixedSequenceSlot.cpp
Normal file
17
tasks/FixedSequenceSlot.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "PeriodicTaskIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) : handlerId(handlerId),
|
||||
pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
if(executableObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
this->executableObject = executableObject;
|
||||
this->executableObject->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -1,39 +1,39 @@
|
||||
/**
|
||||
* @file FixedSequenceSlot.h
|
||||
* @brief This file defines the PollingSlot class.
|
||||
* @date 19.12.2012
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FIXEDSEQUENCESLOT_H_
|
||||
#define FIXEDSEQUENCESLOT_H_
|
||||
#ifndef FSFW_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
#define FSFW_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
|
||||
#include "ExecutableObjectIF.h"
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
|
||||
class PeriodicTaskIF;
|
||||
|
||||
/**
|
||||
* @brief This class is the representation of a single polling sequence table entry.
|
||||
*
|
||||
* @details The PollingSlot class is the representation of a single polling
|
||||
* @brief This class is the representation of a single polling sequence
|
||||
* table entry.
|
||||
* @details
|
||||
* The PollingSlot class is the representation of a single polling
|
||||
* sequence table entry.
|
||||
* @author baetz
|
||||
*/
|
||||
class FixedSequenceSlot {
|
||||
public:
|
||||
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask );
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask);
|
||||
virtual ~FixedSequenceSlot();
|
||||
|
||||
object_id_t handlerId;
|
||||
|
||||
/**
|
||||
* @brief Handler identifies which device handler object is executed in this slot.
|
||||
* @brief Handler identifies which object is executed in this slot.
|
||||
*/
|
||||
ExecutableObjectIF* handler;
|
||||
ExecutableObjectIF* executableObject = nullptr;
|
||||
|
||||
/**
|
||||
* @brief This attribute defines when a device handler object is executed.
|
||||
*
|
||||
* @details The pollingTime attribute identifies the time the handler is executed in ms.
|
||||
* It must be smaller than the period length of the polling sequence.
|
||||
* @details
|
||||
* The pollingTime attribute identifies the time the handler is
|
||||
* executed in ms. It must be smaller than the period length of the
|
||||
* polling sequence.
|
||||
*/
|
||||
uint32_t pollingTimeMs;
|
||||
|
||||
@ -57,4 +57,4 @@ public:
|
||||
};
|
||||
|
||||
|
||||
#endif /* FIXEDSEQUENCESLOT_H_ */
|
||||
#endif /* FSFW_TASKS_FIXEDSEQUENCESLOT_H_ */
|
@ -1,5 +1,6 @@
|
||||
#include "FixedSlotSequence.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <cstdlib>
|
||||
|
||||
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :
|
||||
lengthMs(setLengthMs) {
|
||||
@ -12,7 +13,7 @@ FixedSlotSequence::~FixedSlotSequence() {
|
||||
}
|
||||
|
||||
void FixedSlotSequence::executeAndAdvance() {
|
||||
current->handler->performOperation(current->opcode);
|
||||
current->executableObject->performOperation(current->opcode);
|
||||
// if (returnValue != RETURN_OK) {
|
||||
// this->sendErrorMessage( returnValue );
|
||||
// }
|
||||
@ -80,44 +81,82 @@ uint32_t FixedSlotSequence::getLengthMs() const {
|
||||
return this->lengthMs;
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs,
|
||||
executionStep, executableObject, executingTask));
|
||||
this->current = slotList.begin();
|
||||
}
|
||||
|
||||
ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||
if(slotList.empty()) {
|
||||
sif::error << "Fixed Slot Sequence: Slot list is empty!" << std::endl;
|
||||
sif::error << "FixedSlotSequence::checkSequence:"
|
||||
<< " Slot list is empty!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto slotIt = slotList.begin();
|
||||
uint32_t count = 0;
|
||||
if(customCheckFunction != nullptr) {
|
||||
ReturnValue_t result = customCheckFunction(slotList);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
// Continue for now but print error output.
|
||||
sif::error << "FixedSlotSequence::checkSequence:"
|
||||
<< " Custom check failed!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t errorCount = 0;
|
||||
uint32_t time = 0;
|
||||
while (slotIt != slotList.end()) {
|
||||
if (slotIt->handler == nullptr) {
|
||||
sif::error << "FixedSlotSequene::initialize: ObjectId does not exist!"
|
||||
<< std::endl;
|
||||
count++;
|
||||
} else if (slotIt->pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slotIt->pollingTimeMs
|
||||
<< " is smaller than previous with " << time << std::endl;
|
||||
count++;
|
||||
} else {
|
||||
for(const auto& slot: slotList) {
|
||||
if (slot.executableObject == nullptr) {
|
||||
errorCount++;
|
||||
}
|
||||
else if (slot.pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::checkSequence: Time: "
|
||||
<< slot.pollingTimeMs << " is smaller than previous with "
|
||||
<< time << std::endl;
|
||||
errorCount++;
|
||||
}
|
||||
else {
|
||||
// All ok, print slot.
|
||||
//info << "Current slot polling time: " << std::endl;
|
||||
//info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
//sif::info << "Current slot polling time: " << std::endl;
|
||||
//sif::info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
}
|
||||
time = slotIt->pollingTimeMs;
|
||||
slotIt++;
|
||||
time = slot.pollingTimeMs;
|
||||
|
||||
}
|
||||
//info << "Number of elements in slot list: "
|
||||
//sif::info << "Number of elements in slot list: "
|
||||
// << slotList.size() << std::endl;
|
||||
if (count > 0) {
|
||||
if (errorCount > 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep, PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs, executionStep,
|
||||
executingTask));
|
||||
this->current = slotList.begin();
|
||||
|
||||
ReturnValue_t FixedSlotSequence::intializeSequenceAfterTaskCreation() const {
|
||||
std::set<ExecutableObjectIF*> uniqueObjects;
|
||||
uint32_t count = 0;
|
||||
for(const auto& slot: slotList) {
|
||||
// Ensure that each unique object is initialized once.
|
||||
if(uniqueObjects.find(slot.executableObject) == uniqueObjects.end()) {
|
||||
ReturnValue_t result =
|
||||
slot.executableObject->initializeAfterTaskCreation();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
count++;
|
||||
}
|
||||
uniqueObjects.emplace(slot.executableObject);
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
sif::error << "FixedSlotSequence::intializeSequenceAfterTaskCreation:"
|
||||
"Counted " << count << " failed initializations!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addCustomCheck(ReturnValue_t
|
||||
(*customCheckFunction)(const SlotList&)) {
|
||||
this->customCheckFunction = customCheckFunction;
|
||||
}
|
@ -1,26 +1,30 @@
|
||||
#ifndef FRAMEWORK_DEVICEHANDLERS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FRAMEWORK_DEVICEHANDLERS_FIXEDSLOTSEQUENCE_H_
|
||||
#ifndef FSFW_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FSFW_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
/**
|
||||
* @brief This class is the representation of a Polling Sequence Table in software.
|
||||
*
|
||||
* @brief This class is the representation of a
|
||||
* Polling Sequence Table in software.
|
||||
* @details
|
||||
* The FixedSlotSequence object maintains the dynamic execution of
|
||||
* device handler objects.
|
||||
* objects with stricter timing requirements for the FixedTimeslotTask.
|
||||
*
|
||||
* The main idea is to create a list of device handlers, to announce all
|
||||
* handlers to thepolling sequence and to maintain a list of
|
||||
* polling slot objects. This slot list represents the Polling Sequence Table
|
||||
* in software.
|
||||
* The main idea is to create a list of executable objects (for example
|
||||
* device handlers), to announce all handlers to the polling sequence and to
|
||||
* maintain a list of polling slot objects.
|
||||
* This slot list represents the Polling Sequence Table in software.
|
||||
*
|
||||
* Each polling slot contains information to indicate when and
|
||||
* which device handler shall be executed within a given polling period.
|
||||
* The sequence is then executed by iterating through this slot list.
|
||||
* Handlers are invoking by calling a certain function stored in the handler list.
|
||||
* which executable object shall be executed within a given polling period.
|
||||
* When adding a slot, a pointer to the executing task, a pointer to the
|
||||
* executable object and a step number can be passed. The step number will be
|
||||
* passed to the periodic handler.
|
||||
* The sequence is executed by iterating through the slot sequence and
|
||||
* executing the executable object in the correct timeslot.
|
||||
*/
|
||||
class FixedSlotSequence {
|
||||
public:
|
||||
@ -29,41 +33,44 @@ public:
|
||||
|
||||
/**
|
||||
* @brief The constructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The constructor takes two arguments, the period length and the init function.
|
||||
*
|
||||
* @param setLength The period length, expressed in ms.
|
||||
*/
|
||||
FixedSlotSequence(uint32_t setLengthMs);
|
||||
|
||||
/**
|
||||
* @brief The destructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The destructor frees all allocated memory by iterating through the slotList
|
||||
* and deleting all allocated resources.
|
||||
* @details
|
||||
* The destructor frees all allocated memory by iterating through the
|
||||
* slotList and deleting all allocated resources.
|
||||
*/
|
||||
virtual ~FixedSlotSequence();
|
||||
|
||||
/**
|
||||
* @brief This is a method to add an PollingSlot object to slotList.
|
||||
*
|
||||
* @details Here, a polling slot object is added to the slot list. It is appended
|
||||
* @details
|
||||
* Here, a polling slot object is added to the slot list. It is appended
|
||||
* to the end of the list. The list is currently NOT reordered.
|
||||
* Afterwards, the iterator current is set to the beginning of the list.
|
||||
* @param Object ID of the object to add
|
||||
* @param setTime Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask
|
||||
* @param handlerId ID of the object to add
|
||||
* @param setTime
|
||||
* Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask
|
||||
* will be called inside the slot period.
|
||||
* @param setSequenceId ID which can be used to distinguish
|
||||
* different task operations
|
||||
* @param setSequenceId
|
||||
* ID which can be used to distinguish different task operations. This
|
||||
* value will be passed to the executable function.
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
||||
ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask);
|
||||
|
||||
/**
|
||||
* Checks if the current slot shall be executed immediately after the one before.
|
||||
* This allows to distinguish between grouped and not grouped handlers.
|
||||
* @brief Checks if the current slot shall be executed immediately
|
||||
* after the one before.
|
||||
* @details
|
||||
* This allows to distinguish between grouped and separated handlers.
|
||||
* @return - @c true if the slot has the same polling time as the previous
|
||||
* - @c false else
|
||||
*/
|
||||
@ -125,12 +132,32 @@ public:
|
||||
SlotListIter current;
|
||||
|
||||
/**
|
||||
* Iterate through slotList and check successful creation.
|
||||
* @brief Check and initialize slot list.
|
||||
* @details
|
||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t checkSequence() const;
|
||||
|
||||
/**
|
||||
* @brief A custom check can be injected for the respective slot list.
|
||||
* @details
|
||||
* This can be used by the developer to check the validity of a certain
|
||||
* sequence. The function will be run in the #checkSequence function.
|
||||
* The general check will be continued for now if the custom check function
|
||||
* fails but a diagnostic debug output will be given.
|
||||
* @param customCheckFunction
|
||||
*/
|
||||
void addCustomCheck(ReturnValue_t (*customCheckFunction)(const SlotList &));
|
||||
|
||||
/**
|
||||
* @brief Perform any initialization steps required after the executing
|
||||
* task has been created. This function should be called from the
|
||||
* executing task!
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t intializeSequenceAfterTaskCreation() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@ -146,7 +173,9 @@ protected:
|
||||
*/
|
||||
SlotList slotList;
|
||||
|
||||
ReturnValue_t (*customCheckFunction)(const SlotList&) = nullptr;
|
||||
|
||||
uint32_t lengthMs;
|
||||
};
|
||||
|
||||
#endif /* FIXEDSLOTSEQUENCE_H_ */
|
||||
#endif /* FSFW_TASKS_FIXEDSLOTSEQUENCE_H_ */
|
@ -1,7 +1,8 @@
|
||||
#include "CCSDSTime.h"
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include "../timemanager/CCSDSTime.h"
|
||||
#include <cstdio>
|
||||
#include <cinttypes>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
CCSDSTime::CCSDSTime() {
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "Clock.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
bool operator<(const timeval& lhs, const timeval& rhs);
|
||||
bool operator<=(const timeval& lhs, const timeval& rhs);
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
//! Don't use these for time points, type is not large enough for UNIX epoch.
|
||||
typedef uint32_t dur_millis_t;
|
||||
typedef double dur_seconds_t;
|
||||
using dur_millis_t = uint32_t;
|
||||
|
||||
class Clock {
|
||||
public:
|
||||
|
@ -6,19 +6,22 @@ Stopwatch::Stopwatch(bool displayOnDestruction,
|
||||
StopwatchDisplayMode displayMode): displayOnDestruction(
|
||||
displayOnDestruction), displayMode(displayMode) {
|
||||
// Measures start time on initialization.
|
||||
Clock::getClock_timeval(&startTime);
|
||||
Clock::getUptime(&startTime);
|
||||
}
|
||||
|
||||
void Stopwatch::start() {
|
||||
Clock::getClock_timeval(&startTime);
|
||||
Clock::getUptime(&startTime);
|
||||
}
|
||||
|
||||
dur_millis_t Stopwatch::stop() {
|
||||
dur_millis_t Stopwatch::stop(bool display) {
|
||||
stopInternal();
|
||||
if(display) {
|
||||
this->display();
|
||||
}
|
||||
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
|
||||
}
|
||||
|
||||
dur_seconds_t Stopwatch::stopSeconds() {
|
||||
double Stopwatch::stopSeconds() {
|
||||
stopInternal();
|
||||
return timevalOperations::toDouble(elapsedTime);
|
||||
}
|
||||
@ -52,6 +55,6 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const {
|
||||
|
||||
void Stopwatch::stopInternal() {
|
||||
timeval endTime;
|
||||
Clock::getClock_timeval(&endTime);
|
||||
Clock::getUptime(&endTime);
|
||||
elapsedTime = endTime - startTime;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
||||
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
|
||||
#ifndef FSFW_TIMEMANAGER_STOPWATCH_H_
|
||||
#define FSFW_TIMEMANAGER_STOPWATCH_H_
|
||||
|
||||
#include "Clock.h"
|
||||
|
||||
enum class StopwatchDisplayMode {
|
||||
@ -40,12 +41,12 @@ public:
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in milliseconds (rounded)
|
||||
*/
|
||||
dur_millis_t stop();
|
||||
dur_millis_t stop(bool display = false);
|
||||
/**
|
||||
* Calculates the elapsed time since start and returns it
|
||||
* @return elapsed time in seconds (double precision)
|
||||
*/
|
||||
dur_seconds_t stopSeconds();
|
||||
double stopSeconds();
|
||||
|
||||
/**
|
||||
* Displays the elapsed times on the osstream, depending on internal display
|
||||
@ -66,6 +67,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */
|
||||
#endif /* FSFW_TIMEMANAGER_STOPWATCH_H_ */
|
||||
|
23
timemanager/TimeStamper.cpp
Normal file
23
timemanager/TimeStamper.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "TimeStamper.h"
|
||||
#include "Clock.h"
|
||||
#include <cstring>
|
||||
|
||||
TimeStamper::TimeStamper(object_id_t objectId): SystemObject(objectId) {}
|
||||
|
||||
|
||||
ReturnValue_t TimeStamper::addTimeStamp(uint8_t* buffer,
|
||||
const uint8_t maxSize) {
|
||||
if(maxSize < TimeStamperIF::MISSION_TIMESTAMP_SIZE){
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
timeval now;
|
||||
Clock::getClock_timeval(&now);
|
||||
CCSDSTime::CDS_short cds;
|
||||
ReturnValue_t result = CCSDSTime::convertToCcsds(&cds,&now);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK){
|
||||
return result;
|
||||
}
|
||||
std::memcpy(buffer,&cds,sizeof(cds));
|
||||
return result;
|
||||
}
|
36
timemanager/TimeStamper.h
Normal file
36
timemanager/TimeStamper.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef FSFW_TIMEMANAGER_TIMESTAMPER_H_
|
||||
#define FSFW_TIMEMANAGER_TIMESTAMPER_H_
|
||||
|
||||
#include "TimeStamperIF.h"
|
||||
#include "CCSDSTime.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
|
||||
/**
|
||||
* @brief Time stamper which can be used to add any timestamp to a
|
||||
* given buffer.
|
||||
* @details
|
||||
* This time stamper uses the CCSDS CDC short timestamp as a fault timestamp.
|
||||
* This timestamp has a size of 8 bytes. A custom timestamp can be used by
|
||||
* overriding the #addTimeStamp function.
|
||||
* @ingroup utility
|
||||
*/
|
||||
class TimeStamper: public TimeStamperIF, public SystemObject {
|
||||
public:
|
||||
/**
|
||||
* @brief Default constructor which also registers the time stamper as a
|
||||
* system object so it can be found with the #objectManager.
|
||||
* @param objectId
|
||||
*/
|
||||
TimeStamper(object_id_t objectId);
|
||||
|
||||
/**
|
||||
* Adds a CCSDS CDC short 8 byte timestamp to the given buffer.
|
||||
* This function can be overriden to use a custom timestamp.
|
||||
* @param buffer
|
||||
* @param maxSize
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize);
|
||||
};
|
||||
|
||||
#endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */
|
@ -122,8 +122,8 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
|
||||
|
||||
|
||||
// Implemented by child class, specifies what to do with reply.
|
||||
ReturnValue_t result = handleReply(reply, iter->command, &iter->state,
|
||||
&nextCommand, iter->objectId, &isStep);
|
||||
ReturnValue_t result = handleReply(reply, iter->second.command, &iter->second.state,
|
||||
&nextCommand, iter->second.objectId, &isStep);
|
||||
|
||||
/* If the child implementation does not implement special handling for
|
||||
* rejected replies (RETURN_FAILED or INVALID_REPLY is returned), a
|
||||
@ -132,7 +132,7 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
|
||||
if((reply->getCommand() == CommandMessage::REPLY_REJECTED) and
|
||||
(result == RETURN_FAILED or result == INVALID_REPLY)) {
|
||||
result = reply->getReplyRejectedReason();
|
||||
failureParameter1 = iter->command;
|
||||
failureParameter1 = iter->second.command;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
@ -149,14 +149,14 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
|
||||
default:
|
||||
if (isStep) {
|
||||
verificationReporter.sendFailureReport(
|
||||
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
|
||||
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
|
||||
result, ++iter->step, failureParameter1,
|
||||
TC_VERIFY::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags,
|
||||
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
|
||||
result, ++iter->second.step, failureParameter1,
|
||||
failureParameter2);
|
||||
} else {
|
||||
verificationReporter.sendFailureReport(
|
||||
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
|
||||
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
|
||||
TC_VERIFY::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags,
|
||||
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
|
||||
result, 0, failureParameter1, failureParameter2);
|
||||
}
|
||||
failureParameter1 = 0;
|
||||
@ -170,7 +170,7 @@ void CommandingServiceBase::handleCommandMessage(CommandMessage* reply) {
|
||||
void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
|
||||
CommandMapIter iter, CommandMessage* nextCommand,
|
||||
CommandMessage* reply, bool& isStep) {
|
||||
iter->command = nextCommand->getCommand();
|
||||
iter->second.command = nextCommand->getCommand();
|
||||
|
||||
// In case a new command is to be sent immediately, this is performed here.
|
||||
// If no new command is sent, only analyse reply result by initializing
|
||||
@ -185,14 +185,14 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
|
||||
if (isStep and result != NO_STEP_MESSAGE) {
|
||||
verificationReporter.sendSuccessReport(
|
||||
TC_VERIFY::PROGRESS_SUCCESS,
|
||||
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
|
||||
iter->tcInfo.tcSequenceControl, ++iter->step);
|
||||
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
|
||||
iter->second.tcInfo.tcSequenceControl, ++iter->second.step);
|
||||
}
|
||||
else {
|
||||
verificationReporter.sendSuccessReport(
|
||||
TC_VERIFY::COMPLETION_SUCCESS,
|
||||
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
|
||||
iter->tcInfo.tcSequenceControl, 0);
|
||||
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
|
||||
iter->second.tcInfo.tcSequenceControl, 0);
|
||||
checkAndExecuteFifo(iter);
|
||||
}
|
||||
}
|
||||
@ -200,16 +200,16 @@ void CommandingServiceBase::handleReplyHandlerResult(ReturnValue_t result,
|
||||
if (isStep) {
|
||||
nextCommand->clearCommandMessage();
|
||||
verificationReporter.sendFailureReport(
|
||||
TC_VERIFY::PROGRESS_FAILURE, iter->tcInfo.ackFlags,
|
||||
iter->tcInfo.tcPacketId,
|
||||
iter->tcInfo.tcSequenceControl, sendResult,
|
||||
++iter->step, failureParameter1, failureParameter2);
|
||||
TC_VERIFY::PROGRESS_FAILURE, iter->second.tcInfo.ackFlags,
|
||||
iter->second.tcInfo.tcPacketId,
|
||||
iter->second.tcInfo.tcSequenceControl, sendResult,
|
||||
++iter->second.step, failureParameter1, failureParameter2);
|
||||
} else {
|
||||
nextCommand->clearCommandMessage();
|
||||
verificationReporter.sendFailureReport(
|
||||
TC_VERIFY::COMPLETION_FAILURE,
|
||||
iter->tcInfo.ackFlags, iter->tcInfo.tcPacketId,
|
||||
iter->tcInfo.tcSequenceControl, sendResult, 0,
|
||||
iter->second.tcInfo.ackFlags, iter->second.tcInfo.tcPacketId,
|
||||
iter->second.tcInfo.tcSequenceControl, sendResult, 0,
|
||||
failureParameter1, failureParameter2);
|
||||
}
|
||||
failureParameter1 = 0;
|
||||
@ -248,7 +248,7 @@ void CommandingServiceBase::handleRequestQueue() {
|
||||
iter = commandMap.find(queue);
|
||||
|
||||
if (iter != commandMap.end()) {
|
||||
result = iter->fifo.insert(address);
|
||||
result = iter->second.fifo.insert(address);
|
||||
if (result != RETURN_OK) {
|
||||
rejectPacket(TC_VERIFY::START_FAILURE, &packet, OBJECT_BUSY);
|
||||
}
|
||||
@ -316,11 +316,11 @@ void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
|
||||
CommandMapIter iter) {
|
||||
ReturnValue_t result = RETURN_OK;
|
||||
CommandMessage command;
|
||||
iter->subservice = storedPacket->getSubService();
|
||||
result = prepareCommand(&command, iter->subservice,
|
||||
iter->second.subservice = storedPacket->getSubService();
|
||||
result = prepareCommand(&command, iter->second.subservice,
|
||||
storedPacket->getApplicationData(),
|
||||
storedPacket->getApplicationDataSize(), &iter->state,
|
||||
iter->objectId);
|
||||
storedPacket->getApplicationDataSize(), &iter->second.state,
|
||||
iter->second.objectId);
|
||||
|
||||
ReturnValue_t sendResult = RETURN_OK;
|
||||
switch (result) {
|
||||
@ -330,13 +330,13 @@ void CommandingServiceBase::startExecution(TcPacketStored *storedPacket,
|
||||
&command);
|
||||
}
|
||||
if (sendResult == RETURN_OK) {
|
||||
Clock::getUptime(&iter->uptimeOfStart);
|
||||
iter->step = 0;
|
||||
iter->subservice = storedPacket->getSubService();
|
||||
iter->command = command.getCommand();
|
||||
iter->tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
|
||||
iter->tcInfo.tcPacketId = storedPacket->getPacketId();
|
||||
iter->tcInfo.tcSequenceControl =
|
||||
Clock::getUptime(&iter->second.uptimeOfStart);
|
||||
iter->second.step = 0;
|
||||
iter->second.subservice = storedPacket->getSubService();
|
||||
iter->second.command = command.getCommand();
|
||||
iter->second.tcInfo.ackFlags = storedPacket->getAcknowledgeFlags();
|
||||
iter->second.tcInfo.tcPacketId = storedPacket->getPacketId();
|
||||
iter->second.tcInfo.tcSequenceControl =
|
||||
storedPacket->getPacketSequenceControl();
|
||||
acceptPacket(TC_VERIFY::START_SUCCESS, storedPacket);
|
||||
} else {
|
||||
@ -384,9 +384,9 @@ void CommandingServiceBase::acceptPacket(uint8_t reportId,
|
||||
}
|
||||
|
||||
|
||||
void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter iter) {
|
||||
void CommandingServiceBase::checkAndExecuteFifo(CommandMapIter& iter) {
|
||||
store_address_t address;
|
||||
if (iter->fifo.retrieve(&address) != RETURN_OK) {
|
||||
if (iter->second.fifo.retrieve(&address) != RETURN_OK) {
|
||||
commandMap.erase(&iter);
|
||||
} else {
|
||||
TcPacketStored newPacket(address);
|
||||
@ -412,10 +412,10 @@ void CommandingServiceBase::checkTimeout() {
|
||||
Clock::getUptime(&uptime);
|
||||
CommandMapIter iter;
|
||||
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
|
||||
if ((iter->uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
|
||||
if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
|
||||
verificationReporter.sendFailureReport(
|
||||
TC_VERIFY::COMPLETION_FAILURE, iter->tcInfo.ackFlags,
|
||||
iter->tcInfo.tcPacketId, iter->tcInfo.tcSequenceControl,
|
||||
TC_VERIFY::COMPLETION_FAILURE, iter->second.tcInfo.ackFlags,
|
||||
iter->second.tcInfo.tcPacketId, iter->second.tcInfo.tcSequenceControl,
|
||||
TIMEOUT);
|
||||
checkAndExecuteFifo(iter);
|
||||
}
|
||||
|
@ -39,7 +39,11 @@ class CommandingServiceBase: public SystemObject,
|
||||
public HasReturnvaluesIF {
|
||||
friend void (Factory::setStaticFrameworkObjectIds)();
|
||||
public:
|
||||
// We could make this configurable via preprocessor and the FSFWConfig file.
|
||||
static constexpr uint8_t COMMAND_INFO_FIFO_DEPTH = 3;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_SERVICE_BASE;
|
||||
|
||||
static const ReturnValue_t EXECUTION_COMPLETE = MAKE_RETURN_CODE(1);
|
||||
static const ReturnValue_t NO_STEP_MESSAGE = MAKE_RETURN_CODE(2);
|
||||
static const ReturnValue_t OBJECT_BUSY = MAKE_RETURN_CODE(3);
|
||||
@ -211,8 +215,7 @@ protected:
|
||||
|
||||
virtual void doPeriodicOperation();
|
||||
|
||||
|
||||
struct CommandInfo {
|
||||
struct CommandInfo: public SerializeIF{
|
||||
struct tcInfo {
|
||||
uint8_t ackFlags;
|
||||
uint16_t tcPacketId;
|
||||
@ -224,7 +227,21 @@ protected:
|
||||
uint32_t state;
|
||||
Command_t command;
|
||||
object_id_t objectId;
|
||||
FIFO<store_address_t, 3> fifo;
|
||||
FIFO<store_address_t, COMMAND_INFO_FIFO_DEPTH> fifo;
|
||||
|
||||
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
||||
size_t maxSize, Endianness streamEndianness) const override{
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
virtual size_t getSerializedSize() const override {
|
||||
return 0;
|
||||
};
|
||||
|
||||
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness) override {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
};
|
||||
|
||||
using CommandMapIter = FixedMap<MessageQueueId_t,
|
||||
@ -299,7 +316,7 @@ protected:
|
||||
ReturnValue_t sendTmPacket(uint8_t subservice, SerializeIF* content,
|
||||
SerializeIF* header = nullptr);
|
||||
|
||||
void checkAndExecuteFifo(CommandMapIter iter);
|
||||
void checkAndExecuteFifo(CommandMapIter& iter);
|
||||
|
||||
private:
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user