1
0
forked from fsfw/fsfw

Using C++ to implement preamble. adding optional flag for carriage return

This commit is contained in:
2020-04-12 23:06:57 +02:00
parent 69e9710bf1
commit eb2df3d88c
6 changed files with 47 additions and 22 deletions

View File

@ -1,13 +1,10 @@
#include <framework/timemanager/Clock.h>
#include <framework/serviceinterface/ServiceInterfaceBuffer.h>
#include <cstring>
#include <inttypes.h>
// to be implemented by bsp
extern "C" void printChar(const char*);
int ServiceInterfaceBuffer::overflow(int c) {
// Handle output
putChars(pbase(), pptr());
@ -26,15 +23,16 @@ int ServiceInterfaceBuffer::sync(void) {
if (this->isActive) {
Clock::TimeOfDay_t loggerTime;
Clock::getDateAndTime(&loggerTime);
char preamble[96] = { 0 };
sprintf(preamble, "\r%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32
".%03" PRIu32 " | ", this->log_message.c_str(),
loggerTime.hour,
loggerTime.minute,
loggerTime.second,
loggerTime.usecond /1000);
std::string preamble;
if(addCrToPreamble) {
preamble += "\r";
}
preamble += log_message + ": | " + zero_padded(loggerTime.hour, 2)
+ ":" + zero_padded(loggerTime.minute, 2) + ":"
+ zero_padded(loggerTime.second, 2) + "."
+ zero_padded(loggerTime.usecond/1000, 3) + " | ";
// Write log_message and time
this->putChars(preamble, preamble + sizeof(preamble));
this->putChars(preamble.c_str(), preamble.c_str() + preamble.size());
// Handle output
this->putChars(pbase(), pptr());
}
@ -43,10 +41,13 @@ int ServiceInterfaceBuffer::sync(void) {
return 0;
}
#ifndef UT699
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message,
uint16_t port) {
uint16_t port, bool addCrToPreamble) {
this->addCrToPreamble = addCrToPreamble;
this->log_message = set_message;
this->isActive = true;
setp( buf, buf + BUF_SIZE );
@ -67,10 +68,15 @@ void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
}
#endif
/**
* TODO: This is architecture specific. Maybe there is a better solution
* to move this into the Bsp folder..
*/
#ifdef UT699
#include <framework/osal/rtems/Interrupt.h>
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, uint16_t port) {
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message,
uint16_t port) {
this->log_message = set_message;
this->isActive = true;
setp( buf, buf + BUF_SIZE );