3-phase PV router
Loading...
Searching...
No Matches
serial_output.h File Reference

Non-blocking serial output of the datalog. More...

#include <Arduino.h>
Include dependency graph for serial_output.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SerialOutput::DecimalsTable< N >
 The values of a float array, as integers with the given number of decimals. More...
 

Namespaces

namespace  SerialOutput
 

Typedefs

using SerialOutput::Step = bool (*)(Print& out, uint8_t step)
 One step of an output.
 

Functions

void SerialOutput::beginStartupText ()
 Serial settings for the startup text: 9600 baud 8N1, the default of serial monitors.
 
bool SerialOutput::busy ()
 Whether an output is still in progress.
 
void SerialOutput::complete ()
 Write whatever is left of the current output to Serial, waiting like a plain print.
 
template<bool IOT>
void SerialOutput::endStartupText ()
 Serial settings after the startup text: 7E1 for the IoT telemetry frames, as the mk2Wifi module expects; unchanged for the other outputs.
 
void SerialOutput::poll (Print &out=Serial)
 Write as many steps as the transmit buffer can take, without waiting.
 
void SerialOutput::printDecimals (Print &out, int32_t value, uint8_t decimals)
 Print a value given as an integer with a fixed number of decimals (see toDecimals())
 
void SerialOutput::printHundredths (Print &out, int16_t value_x100)
 Print a value given in hundredths, in its shortest decimal form.
 
void SerialOutput::runStep (Print &out)
 Run the next step of the current output.
 
bool SerialOutput::start (Step step)
 Start an output, written by later calls to poll()
 
template<uint8_t N>
constexpr DecimalsTable< N > SerialOutput::toDecimals (const float(&values)[N], uint8_t decimals)
 A float array constant as integers with the given number of decimals, rounded.
 
constexpr int32_t SerialOutput::toDecimals (float value, uint8_t decimals)
 A float constant as an integer with the given number of decimals, rounded.
 

Variables

constexpr uint32_t SerialOutput::BAUD_RATE { 9600 }
 
Step SerialOutput::current { nullptr }
 
constexpr uint8_t SerialOutput::MAX_STEP_LENGTH { 32 }
 
uint8_t SerialOutput::nextStep { 0 }
 

Detailed Description

Non-blocking serial output of the datalog.

Author
Frédéric Metrich (frede.nosp@m.ric..nosp@m.metri.nosp@m.ch@l.nosp@m.ive.f.nosp@m.r)
Version
0.1
Date
2026-11-21

At 9600 baud, a datalog line takes about 130 ms to send, and the UART's transmit buffer holds only 64 characters: a plain Serial.print() of the whole line keeps the main loop waiting for most of that time, delaying everything else it does (RF commands to the remote loads, among others).

Here, the output is cut into steps of at most MAX_STEP_LENGTH characters. poll(), called on every pass of the main loop, only runs a step when the transmit buffer has room for it: printing never waits.

Text messages (info(), debug()... in debug.h) first call complete(), so they never land in the middle of a datalog line or telemetry frame.

Definition in file serial_output.h.