WIP: somethings wrong.. #19
@ -69,7 +69,7 @@ private:
|
|||||||
struct SerializationArgs {
|
struct SerializationArgs {
|
||||||
uint8_t ** buffer;
|
uint8_t ** buffer;
|
||||||
size_t * size;
|
size_t * size;
|
||||||
const uint32_t max_size;
|
const size_t max_size;
|
||||||
bool bigEndian;
|
bool bigEndian;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
||||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = PTHREAD_STACK_MIN;
|
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = PTHREAD_STACK_MIN;
|
||||||
|
|
||||||
FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, uint32_t periodMs_):PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) {
|
FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_,
|
||||||
|
size_t stackSize_, uint32_t periodMs_):
|
||||||
|
PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedTimeslotTask::~FixedTimeslotTask() {
|
FixedTimeslotTask::~FixedTimeslotTask() {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
#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*);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int ServiceInterfaceBuffer::overflow(int c) {
|
int ServiceInterfaceBuffer::overflow(int c) {
|
||||||
// Handle output
|
// Handle output
|
||||||
putChars(pbase(), pptr());
|
putChars(pbase(), pptr());
|
||||||
@ -26,15 +23,16 @@ int ServiceInterfaceBuffer::sync(void) {
|
|||||||
if (this->isActive) {
|
if (this->isActive) {
|
||||||
Clock::TimeOfDay_t loggerTime;
|
Clock::TimeOfDay_t loggerTime;
|
||||||
Clock::getDateAndTime(&loggerTime);
|
Clock::getDateAndTime(&loggerTime);
|
||||||
char preamble[96] = { 0 };
|
std::string preamble;
|
||||||
sprintf(preamble, "\r%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32
|
if(addCrToPreamble) {
|
||||||
".%03" PRIu32 " | ", this->log_message.c_str(),
|
preamble += "\r";
|
||||||
loggerTime.hour,
|
}
|
||||||
loggerTime.minute,
|
preamble += log_message + ": | " + zero_padded(loggerTime.hour, 2)
|
||||||
loggerTime.second,
|
+ ":" + zero_padded(loggerTime.minute, 2) + ":"
|
||||||
loggerTime.usecond /1000);
|
+ zero_padded(loggerTime.second, 2) + "."
|
||||||
|
+ zero_padded(loggerTime.usecond/1000, 3) + " | ";
|
||||||
// Write log_message and time
|
// Write log_message and time
|
||||||
this->putChars(preamble, preamble + sizeof(preamble));
|
this->putChars(preamble.c_str(), preamble.c_str() + preamble.size());
|
||||||
// Handle output
|
// Handle output
|
||||||
this->putChars(pbase(), pptr());
|
this->putChars(pbase(), pptr());
|
||||||
}
|
}
|
||||||
@ -43,10 +41,13 @@ int ServiceInterfaceBuffer::sync(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UT699
|
#ifndef UT699
|
||||||
|
|
||||||
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message,
|
ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message,
|
||||||
uint16_t port) {
|
uint16_t port, bool addCrToPreamble) {
|
||||||
|
this->addCrToPreamble = addCrToPreamble;
|
||||||
this->log_message = set_message;
|
this->log_message = set_message;
|
||||||
this->isActive = true;
|
this->isActive = true;
|
||||||
setp( buf, buf + BUF_SIZE );
|
setp( buf, buf + BUF_SIZE );
|
||||||
@ -67,10 +68,15 @@ void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This is architecture specific. Maybe there is a better solution
|
||||||
|
* to move this into the Bsp folder..
|
||||||
|
*/
|
||||||
#ifdef UT699
|
#ifdef UT699
|
||||||
#include <framework/osal/rtems/Interrupt.h>
|
#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->log_message = set_message;
|
||||||
this->isActive = true;
|
this->isActive = true;
|
||||||
setp( buf, buf + BUF_SIZE );
|
setp( buf, buf + BUF_SIZE );
|
||||||
|
@ -2,16 +2,17 @@
|
|||||||
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
|
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iosfwd>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
#ifndef UT699
|
#ifndef UT699
|
||||||
class ServiceInterfaceBuffer:
|
class ServiceInterfaceBuffer:
|
||||||
public std::basic_streambuf<char,std::char_traits<char>> {
|
public std::basic_streambuf<char,std::char_traits<char>> {
|
||||||
friend class ServiceInterfaceStream;
|
friend class ServiceInterfaceStream;
|
||||||
public:
|
public:
|
||||||
ServiceInterfaceBuffer(std::string set_message, uint16_t port);
|
ServiceInterfaceBuffer(std::string set_message, uint16_t port,
|
||||||
|
bool addCrToPreamble);
|
||||||
protected:
|
protected:
|
||||||
bool isActive;
|
bool isActive;
|
||||||
// This is called when buffer becomes full. If
|
// This is called when buffer becomes full. If
|
||||||
@ -28,13 +29,28 @@ private:
|
|||||||
std::string log_message;
|
std::string log_message;
|
||||||
// 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.
|
||||||
|
bool addCrToPreamble;
|
||||||
|
|
||||||
// Work in buffer mode. It is also possible to work without buffer.
|
// Work in buffer mode. It is also possible to work without buffer.
|
||||||
static size_t const BUF_SIZE = 150;
|
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 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
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ void ServiceInterfaceStream::setActive( bool myActive) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message,
|
ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message,
|
||||||
uint16_t port) :
|
bool addCrToPreamble, uint16_t port) :
|
||||||
std::basic_ostream<char, std::char_traits<char>>(&buf),
|
std::basic_ostream<char, std::char_traits<char>>(&buf),
|
||||||
buf(set_message, port) {
|
buf(set_message, port, addCrToPreamble) {
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
//Unfortunately, there must be a forward declaration of log_fe
|
// Unfortunately, there must be a forward declaration of log_fe
|
||||||
// (MUST be defined in main), to let the system know where to write to.
|
// (MUST be defined in main), to let the system know where to write to.
|
||||||
extern std::ostream debug;
|
extern std::ostream debug;
|
||||||
extern std::ostream info;
|
extern std::ostream info;
|
||||||
@ -19,7 +19,8 @@ class ServiceInterfaceStream :
|
|||||||
protected:
|
protected:
|
||||||
ServiceInterfaceBuffer buf;
|
ServiceInterfaceBuffer buf;
|
||||||
public:
|
public:
|
||||||
ServiceInterfaceStream( std::string set_message, uint16_t port = 1234 );
|
ServiceInterfaceStream( std::string set_message,
|
||||||
|
bool addCrToPreamble = false, uint16_t port = 1234);
|
||||||
void setActive( bool );
|
void setActive( bool );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user