Monitoring system for electric vehicles (log various sensors, such as consumed power, solar production, speed, slope, apparent wind, etc.)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
829 B

#include "DebugLog.h"
detail::DebugLog DebugLog;
namespace detail
{
DebugLog::DebugLog()
{
buffer[sizeof(buffer)-1] = 0;
}
DebugLog::~DebugLog()
{
}
void DebugLog::append(uint8_t b)
{
buffer[end] = b;
end = (end + 1) % (sizeof(buffer)-1);
if(end == start) start = (start + 1) % (sizeof(buffer)-1);
}
size_t DebugLog::write(uint8_t b)
{
append(b);
return Serial.write(b);
}
size_t DebugLog::write(const uint8_t *buffer, size_t size)
{
for(size_t i = 0; i < size; ++i)
{
append(buffer[i]);
}
return Serial.write(buffer, size);
}
const char* DebugLog::get(int partIdx)
{
buffer[end] = 0;
if(partIdx == 0)
{
return (const char*)&buffer[start];
}
else if(partIdx == 1)
{
if(end < start)
return (const char*)&buffer[0];
}
return (const char*)&buffer[end];
}
}