no dyn memory allocation, print seems to work

This commit is contained in:
Robin Müller 2020-06-04 19:07:04 +02:00
parent d466921aa0
commit c0808e71d9
3 changed files with 17 additions and 50 deletions

View File

@ -9,7 +9,6 @@
#define OBJECTMANAGERIF_H_ #define OBJECTMANAGERIF_H_
#include <framework/objectmanager/frameworkObjects.h> #include <framework/objectmanager/frameworkObjects.h>
#include <config/objects/systemObjectList.h>
#include <framework/objectmanager/SystemObjectIF.h> #include <framework/objectmanager/SystemObjectIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h> #include <framework/returnvalues/HasReturnvaluesIF.h>

View File

@ -1,6 +1,7 @@
#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*, bool errStream); extern "C" void printChar(const char*, bool errStream);
@ -17,6 +18,7 @@ ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage,
setp( buf, buf + BUF_SIZE ); setp( buf, buf + BUF_SIZE );
} }
preamble.reserve(96); preamble.reserve(96);
preamble.resize(96);
} }
void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) { void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) {
@ -78,7 +80,7 @@ int ServiceInterfaceBuffer::sync(void) {
uint8_t debugArray[96]; uint8_t debugArray[96];
memcpy(debugArray, preamble.data(), preambleSize); memcpy(debugArray, preamble.data(), preambleSize);
// Write logMessage and time // Write logMessage and time
this->putChars(preamble.c_str(), preamble.c_str() + preambleSize); 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
@ -90,47 +92,29 @@ int ServiceInterfaceBuffer::sync(void) {
std::string ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) { std::string ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) {
Clock::TimeOfDay_t loggerTime; Clock::TimeOfDay_t loggerTime;
Clock::getDateAndTime(&loggerTime); Clock::getDateAndTime(&loggerTime);
//preamble.clear(); std::string preamble (96, 0);
//std::string preamble;
size_t currentSize = 0; size_t currentSize = 0;
char* parsePosition = &preamble[0];
if(addCrToPreamble) { if(addCrToPreamble) {
preamble[0] = '\r'; preamble[0] = '\r';
currentSize += 1; currentSize += 1;
parsePosition += 1;
} }
int32_t charCount = sprintf(preamble.data() + currentSize, int32_t charCount = sprintf(parsePosition,
"%s: | %lu:%02lu:%02lu.%03lu | ", "%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ",
this->logMessage.c_str(), (unsigned long) loggerTime.hour, this->logMessage.c_str(), loggerTime.hour,
(unsigned long) loggerTime.minute, loggerTime.minute,
(unsigned long) loggerTime.second, loggerTime.second,
(unsigned long) loggerTime.usecond /1000); loggerTime.usecond /1000);
if(charCount < 0) { if(charCount < 0) {
printf("ServiceInterfaceBuffer: Failure parsing preamble"); printf("ServiceInterfaceBuffer: Failure parsing preamble");
return ""; return "";
} }
currentSize += charCount; currentSize += charCount;
// size_t currentSize = 0; if(preambleSize != nullptr) {
// if(addCrToPreamble) {
// preamble[0] = '\r';
// currentSize += 1;
// }
// logMessage.copy(preamble.data() + 1, logMessage.size());
// currentSize += logMessage.size();
// preamble[++currentSize] = ':';
// preamble[++currentSize] = ' ';
// preamble[++currentSize] = '|';
// zero_padded(loggerTime.hour, 2).copy(preamble.data() + )
// //preamble.c_str() + 1 = logMessage;
////
//// + ": | " + zero_padded(loggerTime.hour, 2)
//// + ":" + zero_padded(loggerTime.minute, 2) + ":"
//// + zero_padded(loggerTime.second, 2) + "."
//// + zero_padded(loggerTime.usecond/1000, 3) + " | ";
// currentSize += logMessage.size(); //+ 4 +2 +1 +2 +1 +2 +1 + 3 + 3;
preamble[++currentSize] = '\0';
uint8_t debugArray[96];
memcpy(debugArray, preamble.data(), currentSize);
*preambleSize = currentSize; *preambleSize = currentSize;
return std::move(preamble); }
return preamble;
} }

View File

@ -76,29 +76,13 @@ private:
stringToFill[i] = '0'; stringToFill[i] = '0';
} }
numString.copy(stringToFill.data() + i, numString.size()); numString.copy(stringToFill.data() + i, numString.size());
// std::streambuf streambuf; return HasReturnvaluesIF::RETURN_OK;
// 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;
//std::string dest = std::string( number_of_zeros, '0').append( original_string);
} }
}; };
#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> > {