at91sam9g20 uses custom stdio.c, unsigned long cast in sprintf does not seem to work, casting (unsigned int) does, timestamp now visible in debug output

This commit is contained in:
Robin Müller 2019-10-23 12:03:32 +02:00
parent 07950b0c2b
commit 1631e739b8

View File

@ -5,6 +5,8 @@
// to be implemented by bsp
extern "C" void printChar(const char*);
int ServiceInterfaceBuffer::overflow(int c) {
// Handle output
putChars(pbase(), pptr());
@ -19,16 +21,18 @@ int ServiceInterfaceBuffer::overflow(int c) {
return 0;
}
// custom stdio.c library for at91sam9g20 chip which does not support unsigned long
// So I cast (unsigned int) on loggerTimes
int ServiceInterfaceBuffer::sync(void) {
if (this->isActive) {
Clock::TimeOfDay_t loggerTime;
Clock::getDateAndTime(&loggerTime);
char preamble[96] = { 0 };
sprintf(preamble, "%s: | %lu:%02lu:%02lu.%03lu | ",
this->log_message.c_str(), (unsigned long) loggerTime.hour,
(unsigned long) loggerTime.minute,
(unsigned long) loggerTime.second,
(unsigned long) loggerTime.usecond /1000);
sprintf(preamble, "%s: | %u:%02u:%02u.%03u | ",
this->log_message.c_str(), (unsigned int) loggerTime.hour,
(unsigned int) loggerTime.minute,
(unsigned int) loggerTime.second,
(unsigned int) loggerTime.usecond /1000);
// Write log_message and time
this->putChars(preamble, preamble + sizeof(preamble));
// Handle output