Merge branch 'mueller_framework' into front_branch

This commit is contained in:
Robin Müller 2020-06-04 20:41:30 +02:00
commit 405e1149e5
13 changed files with 218 additions and 107 deletions

View File

@ -28,11 +28,11 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/objectmanager/*.cpp)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/*.cpp)
# select the OS # select the OS
ifeq ($(OS),rtems) ifeq ($(OS_FSFW),rtems)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/rtems/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/rtems/*.cpp)
else ifeq ($(OS),linux) else ifeq ($(OS_FSFW),linux)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/linux/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/linux/*.cpp)
else ifeq ($(OS),freeRTOS) else ifeq ($(OS_FSFW),freeRTOS)
CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/FreeRTOS/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/osal/FreeRTOS/*.cpp)
else else
$(error invalid OS specified, valid OS are rtems, linux, freeRTOS) $(error invalid OS specified, valid OS are rtems, linux, freeRTOS)

View File

@ -14,8 +14,9 @@ enum FW_MESSAGE_TYPE {
MONITORING, MONITORING,
MEMORY, MEMORY,
PARAMETER, PARAMETER,
FILE_SYSTEM_MESSAGE,
FW_MESSAGES_COUNT, FW_MESSAGES_COUNT,
FILE_SYSTEM_MESSAGE
}; };
} }

View File

@ -18,7 +18,7 @@ public:
*/ */
static QueueFactory* instance(); static QueueFactory* instance();
MessageQueueIF* createMessageQueue(size_t messageDepth = 3, MessageQueueIF* createMessageQueue(uint32_t messageDepth = 3,
size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE); size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE);
void deleteMessageQueue(MessageQueueIF* queue); void deleteMessageQueue(MessageQueueIF* queue);

View File

@ -26,7 +26,7 @@ QueueFactory::QueueFactory() {
QueueFactory::~QueueFactory() { QueueFactory::~QueueFactory() {
} }
MessageQueueIF* QueueFactory::createMessageQueue(size_t messageDepth, MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
size_t maxMessageSize) { size_t maxMessageSize) {
return new MessageQueue(messageDepth, maxMessageSize); return new MessageQueue(messageDepth, maxMessageSize);
} }

View File

@ -28,7 +28,7 @@ QueueFactory::QueueFactory() {
QueueFactory::~QueueFactory() { QueueFactory::~QueueFactory() {
} }
MessageQueueIF* QueueFactory::createMessageQueue(size_t messageDepth, MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
size_t maxMessageSize) { size_t maxMessageSize) {
return new MessageQueue(messageDepth, maxMessageSize); return new MessageQueue(messageDepth, maxMessageSize);
} }

View File

@ -1,11 +1,58 @@
#include <framework/timemanager/Clock.h> #include <framework/timemanager/Clock.h>
#include <framework/serviceinterface/ServiceInterfaceBuffer.h> #include <framework/serviceinterface/ServiceInterfaceBuffer.h>
#include <cstring> #include <cstring>
#include <inttypes.h>
// to be implemented by bsp // to be implemented by bsp
extern "C" void printChar(const char*); extern "C" void printChar(const char*, bool errStream);
#ifndef UT699
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage,
bool addCrToPreamble, bool buffered , bool errStream, uint16_t port):
isActive(true), logMessage(setMessage),
addCrToPreamble(addCrToPreamble), buffered(buffered),
errStream(errStream) {
if(buffered) {
// Set pointers if the stream is buffered.
setp( buf, buf + BUF_SIZE );
}
preamble.reserve(MAX_PREAMBLE_SIZE);
preamble.resize(MAX_PREAMBLE_SIZE);
}
void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
char array[BUF_SIZE];
uint32_t length = end - begin;
if (length > sizeof(array)) {
length = sizeof(array);
}
memcpy(array, begin, length);
for(; begin != end; begin++){
if(errStream) {
printChar(begin, true);
}
else {
printChar(begin, false);
}
}
}
#endif
int ServiceInterfaceBuffer::overflow(int c) { int ServiceInterfaceBuffer::overflow(int c) {
if(not buffered and this->isActive) {
if (c != Traits::eof()) {
if(errStream) {
printChar(reinterpret_cast<const char*>(&c), true);
}
else {
printChar(reinterpret_cast<const char*>(&c), false);
}
}
return 0;
}
// Handle output // Handle output
putChars(pbase(), pptr()); putChars(pbase(), pptr());
if (c != Traits::eof()) { if (c != Traits::eof()) {
@ -20,53 +67,63 @@ int ServiceInterfaceBuffer::overflow(int c) {
} }
int ServiceInterfaceBuffer::sync(void) { int ServiceInterfaceBuffer::sync(void) {
if (this->isActive) { if(not this->isActive and not buffered) {
Clock::TimeOfDay_t loggerTime; if(not buffered) {
Clock::getDateAndTime(&loggerTime); setp(buf, buf + BUF_SIZE - 1);
std::string preamble;
if(addCrToPreamble) {
preamble += "\r";
} }
preamble += log_message + ": | " + zero_padded(loggerTime.hour, 2) return 0;
+ ":" + zero_padded(loggerTime.minute, 2) + ":" }
+ zero_padded(loggerTime.second, 2) + "." if(not buffered) {
+ zero_padded(loggerTime.usecond/1000, 3) + " | "; return 0;
// Write log_message and time }
this->putChars(preamble.c_str(), preamble.c_str() + preamble.size());
size_t preambleSize = 0;
auto preamble = getPreamble(&preambleSize);
// Write logMessage and time
this->putChars(preamble.data(), preamble.data() + preambleSize);
// Handle output // Handle output
this->putChars(pbase(), pptr()); this->putChars(pbase(), pptr());
}
// This tells that buffer is empty again // This tells that buffer is empty again
setp(buf, buf + BUF_SIZE - 1); setp(buf, buf + BUF_SIZE - 1);
return 0; return 0;
} }
bool ServiceInterfaceBuffer::isBuffered() const {
return buffered;
#ifndef UT699
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message,
uint16_t port, bool addCrToPreamble) {
this->addCrToPreamble = addCrToPreamble;
this->log_message = set_message;
this->isActive = true;
setp( buf, buf + BUF_SIZE );
} }
void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) { std::string ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) {
char array[BUF_SIZE]; Clock::TimeOfDay_t loggerTime;
uint32_t length = end - begin; Clock::getDateAndTime(&loggerTime);
if (length > sizeof(array)) { size_t currentSize = 0;
length = sizeof(array); char* parsePosition = &preamble[0];
if(addCrToPreamble) {
preamble[0] = '\r';
currentSize += 1;
parsePosition += 1;
} }
memcpy(array, begin, length); int32_t charCount = sprintf(parsePosition,
"%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ",
for(; begin != end; begin++){ this->logMessage.c_str(), loggerTime.hour,
printChar(begin); loggerTime.minute,
loggerTime.second,
loggerTime.usecond /1000);
if(charCount < 0) {
printf("ServiceInterfaceBuffer: Failure parsing preamble\r\n");
return "";
}
if(charCount > MAX_PREAMBLE_SIZE) {
printf("ServiceInterfaceBuffer: Char count too large for maximum "
"preamble size");
return "";
}
currentSize += charCount;
if(preambleSize != nullptr) {
*preambleSize = currentSize;
}
return preamble;
} }
}
#endif
#ifdef UT699 #ifdef UT699

View File

@ -1,67 +1,71 @@
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <cstdio>
#include <iomanip> #include <iomanip>
#ifndef UT699 #ifndef UT699
/**
* @brief This is the underlying stream buffer which implements the
* streambuf class and overloads the overflow() and sync() methods
* @details
* This class is used to modify the output of the stream, for example by adding.
* It also calls the char printing function which is implemented in the
* board supply package (BSP).
*/
class ServiceInterfaceBuffer: class ServiceInterfaceBuffer:
public std::basic_streambuf<char,std::char_traits<char>> { public std::streambuf {
friend class ServiceInterfaceStream; friend class ServiceInterfaceStream;
public: public:
ServiceInterfaceBuffer(std::string set_message, uint16_t port, static constexpr uint8_t MAX_PREAMBLE_SIZE = 40;
bool addCrToPreamble);
ServiceInterfaceBuffer(std::string setMessage, bool addCrToPreamble,
bool buffered, bool errStream, uint16_t port);
protected: protected:
bool isActive; bool isActive;
// This is called when buffer becomes full. If //! This is called when buffer becomes full. If
// buffer is not used, then this is called every //! buffer is not used, then this is called every
// time when characters are put to stream. //! time when characters are put to stream.
int overflow(int c = Traits::eof()) override; int overflow(int c = Traits::eof()) override;
// This function is called when stream is flushed, //! This function is called when stream is flushed,
// for example when std::endl is put to stream. //! for example when std::endl is put to stream.
int sync(void) override; int sync(void) override;
bool isBuffered() const;
private: private:
// For additional message information //! For additional message information
std::string log_message; std::string logMessage;
std::string preamble;
// For EOF detection // For EOF detection
typedef std::char_traits<char> Traits; typedef std::char_traits<char> Traits;
// This is useful for some terminal programs which do not have
// implicit carriage return with newline characters. //! This is useful for some terminal programs which do not have
//! implicit carriage return with newline characters.
bool addCrToPreamble; bool addCrToPreamble;
// Work in buffer mode. It is also possible to work without buffer. //! Specifies whether the stream operates in buffered or unbuffered mode.
bool buffered;
//! This specifies to print to stderr and work in unbuffered mode.
bool errStream;
//! Needed for buffered mode.
static size_t const BUF_SIZE = 128; static size_t const BUF_SIZE = 128;
char buf[BUF_SIZE]; char buf[BUF_SIZE];
// In this function, the characters are parsed. //! In this function, the characters are parsed.
void putChars(char const* begin, char const* end); void putChars(char const* begin, char const* end);
template<typename T> std::string getPreamble(size_t * preambleSize = nullptr);
std::string zero_padded(const T& num, uint8_t width) {
std::ostringstream string_to_pad;
string_to_pad << std::setw(width) << std::setfill('0') << num;
std::string result = string_to_pad.str();
if (result.length() > width)
{
result.erase(0, result.length() - width);
}
return result;
}
}; };
#endif #endif
#ifdef UT699 #ifdef UT699
class ServiceInterfaceBuffer: public std::basic_streambuf<char, class ServiceInterfaceBuffer: public std::basic_streambuf<char,
std::char_traits<char> > { std::char_traits<char> > {

View File

@ -1,11 +1,32 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
ServiceInterfaceStream::ServiceInterfaceStream(std::string setMessage,
bool addCrToPreamble, bool buffered, bool errStream, uint16_t port) :
std::ostream(&streambuf),
streambuf(setMessage, addCrToPreamble, buffered, errStream, port) {}
void ServiceInterfaceStream::setActive( bool myActive) { void ServiceInterfaceStream::setActive( bool myActive) {
this->buf.isActive = myActive; this->streambuf.isActive = myActive;
} }
ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message, std::string ServiceInterfaceStream::getPreamble() {
bool addCrToPreamble, uint16_t port) : return streambuf.getPreamble();
std::basic_ostream<char, std::char_traits<char>>(&buf), }
buf(set_message, port, addCrToPreamble) {
void ServiceInterfaceStream::print(std::string error,
bool withPreamble, bool withNewline, bool flush) {
if(not streambuf.isBuffered() and withPreamble) {
*this << getPreamble() << error;
}
else {
*this << error;
}
if(withNewline) {
*this << "\n";
}
// if mode is non-buffered, no need to flush.
if(flush and streambuf.isBuffered()) {
this->flush();
}
} }

View File

@ -3,29 +3,56 @@
#include <framework/serviceinterface/ServiceInterfaceBuffer.h> #include <framework/serviceinterface/ServiceInterfaceBuffer.h>
#include <iostream> #include <iostream>
#include <iosfwd>
#include <sstream>
#include <cstdio> #include <cstdio>
// Unfortunately, there must be a forward declaration of log_fe /**
// (MUST be defined in main), to let the system know where to write to. * Generic service interface stream which can be used like std::cout or
namespace sif { * std::cerr but has additional capability. Add preamble and timestamp
extern std::ostream debug; * to output. Can be run in buffered or unbuffered mode.
extern std::ostream info; */
extern std::ostream warning; class ServiceInterfaceStream : public std::ostream {
extern std::ostream error;
}
class ServiceInterfaceStream :
public std::basic_ostream<char, std::char_traits<char>> {
protected:
ServiceInterfaceBuffer buf;
public: public:
ServiceInterfaceStream( std::string set_message, /**
bool addCrToPreamble = false, uint16_t port = 1234); * This constructor is used by specifying the preamble message.
* Optionally, the output can be directed to stderr and a CR character
* can be prepended to the preamble.
* @param setMessage message of preamble.
* @param addCrToPreamble Useful for applications like Puttty.
* @param buffered specify whether to use buffered mode.
* @param errStream specify which output stream to use (stderr or stdout).
*/
ServiceInterfaceStream(std::string setMessage,
bool addCrToPreamble = false, bool buffered = true,
bool errStream = false, uint16_t port = 1234);
//! An inactive stream will not print anything.
void setActive( bool ); void setActive( bool );
/**
* This can be used to retrieve the preamble in case it should be printed in
* the unbuffered mode.
* @return Preamle consisting of log message and timestamp.
*/
std::string getPreamble();
/**
* This prints an error with a preamble. Useful if using the unbuffered
* mode. Flushes in default mode (prints immediately).
*/
void print(std::string error, bool withPreamble = true,
bool withNewline = true, bool flush = true);
protected:
ServiceInterfaceBuffer streambuf;
}; };
// Forward declaration of interface streams. These should be instantiated in
// main. They can then be used like std::cout or std::cerr.
namespace sif {
extern ServiceInterfaceStream debug;
extern ServiceInterfaceStream info;
extern ServiceInterfaceStream warning;
extern ServiceInterfaceStream error;
}
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */ #endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */

View File

@ -24,7 +24,6 @@
* The local pool is NOT thread-safe. * The local pool is NOT thread-safe.
* @author Bastian Baetz * @author Bastian Baetz
*/ */
template<uint8_t NUMBER_OF_POOLS = 5> template<uint8_t NUMBER_OF_POOLS = 5>
class LocalPool: public SystemObject, public StorageManagerIF { class LocalPool: public SystemObject, public StorageManagerIF {
public: public:
@ -48,9 +47,10 @@ public:
* number of elements for each pool is determined. * number of elements for each pool is determined.
* The position of these values correspond to those in * The position of these values correspond to those in
* element_sizes. * element_sizes.
* @param registered Register the pool in object manager or not. Default is false (local pool). * @param registered Register the pool in object manager or not.
* @param spillsToHigherPools * Default is false (local pool).
* A variable to determine whether higher n pools are used if the store is full. * @param spillsToHigherPools A variable to determine whether
* higher n pools are used if the store is full.
*/ */
LocalPool(object_id_t setObjectId, LocalPool(object_id_t setObjectId,
const uint16_t element_sizes[NUMBER_OF_POOLS], const uint16_t element_sizes[NUMBER_OF_POOLS],
@ -117,7 +117,7 @@ private:
/** /**
* @brief store represents the actual memory pool. * @brief store represents the actual memory pool.
* @details It is an array of pointers to memory, which was allocated with * @details It is an array of pointers to memory, which was allocated with
* a \c new call on construction. * a @c new call on construction.
*/ */
uint8_t* store[NUMBER_OF_POOLS]; uint8_t* store[NUMBER_OF_POOLS];
/** /**

View File

@ -12,7 +12,7 @@
* with a lock. * with a lock.
* @author Bastian Baetz * @author Bastian Baetz
*/ */
template <uint8_t NUMBER_OF_POOLS> template <uint8_t NUMBER_OF_POOLS = 5>
class PoolManager : public LocalPool<NUMBER_OF_POOLS> { class PoolManager : public LocalPool<NUMBER_OF_POOLS> {
public: public:
PoolManager(object_id_t setObjectId, PoolManager(object_id_t setObjectId,
@ -27,6 +27,7 @@ public:
ReturnValue_t deleteData(store_address_t) override; ReturnValue_t deleteData(store_address_t) override;
ReturnValue_t deleteData(uint8_t* buffer, size_t size, ReturnValue_t deleteData(uint8_t* buffer, size_t size,
store_address_t* storeId = nullptr) override; store_address_t* storeId = nullptr) override;
protected: protected:
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address,
bool ignoreFault) override; bool ignoreFault) override;

View File

@ -48,4 +48,3 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer,
} }
#endif #endif

View File

@ -11,7 +11,6 @@
using AccessorPair = std::pair<ReturnValue_t, StorageAccessor>; using AccessorPair = std::pair<ReturnValue_t, StorageAccessor>;
using ConstAccessorPair = std::pair<ReturnValue_t, ConstStorageAccessor>; using ConstAccessorPair = std::pair<ReturnValue_t, ConstStorageAccessor>;
/** /**
* @brief This class provides an interface for intermediate data storage. * @brief This class provides an interface for intermediate data storage.
* @details The Storage manager classes shall be used to store larger chunks of * @details The Storage manager classes shall be used to store larger chunks of
@ -80,6 +79,7 @@ public:
virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size, virtual ReturnValue_t deleteData(uint8_t* buffer, size_t size,
store_address_t* storeId = nullptr) = 0; store_address_t* storeId = nullptr) = 0;
/** /**
* @brief Access the data by supplying a store ID. * @brief Access the data by supplying a store ID.
* @details * @details
@ -100,6 +100,7 @@ public:
virtual ReturnValue_t getData(store_address_t storeId, virtual ReturnValue_t getData(store_address_t storeId,
ConstStorageAccessor& constAccessor) = 0; ConstStorageAccessor& constAccessor) = 0;
/** /**
* @brief getData returns an address to data and the size of the data * @brief getData returns an address to data and the size of the data
* for a given packet_id. * for a given packet_id.