SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
Logging::Log_t Struct Reference

Base class used to log things over serial. More...

#include <Log.h>

Public Member Functions

void operator() (LOG_TAG TAG, LOG_MSG message)
 Log a string usb serial.
 
void d (LOG_TAG TAG, LOG_MSG message)
 Log a string using a debug tag.
 
void i (LOG_TAG TAG, LOG_MSG message)
 Log a string using an info tag.
 
void w (LOG_TAG TAG, LOG_MSG message)
 Log a string using a warning tag.
 
void e (LOG_TAG TAG, LOG_MSG message)
 Log a string using an error tag.
 
void f (LOG_TAG TAG, LOG_MSG message)
 Log a string using a fatal tag.
 
void operator() (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number to usb serial.
 
void d (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number using a debug tag.
 
void i (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number using an info tag.
 
void w (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number using a warning tag.
 
void e (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number using an error tag.
 
void f (LOG_TAG TAG, LOG_MSG message, const uint32_t number, int mediate=false)
 Log a string and a variable number using a fatal tag.
 
void p (LOG_TAG name, LOG_MSG prettyName, const uint32_t number, int mediate=false)
 Post a monitored value.
 

Detailed Description

Base class used to log things over serial.

Logging is centered around communicating with the companion app.

Default Mode

In its default mode, logging does not send ASCII strings but integer numbers which represent a set of defined strings.

The actual messages that are sent over serial are as follows.

Byte Number |0 |1 |2 |3 |4 |5 |6 |7 |
What it is |State Code|String ID| uint32_t |
A state machine implementation, refer to State.h for more info.
Definition State.h:38

Bytes 0-1 represent a State Code, or in other works, a unique number that is mapped to a unique string representing the name of what is making this log entry.

Bytes 2-3 represent a String ID, a unique number that is mapped to a unique string.

Bytes 4-7 represent a 32 bit value, by default it is zero, every log entry has this number sent.

Calls to the global Log can be done as follows.

C
Log(TAG, message, number);
Logging::Log_t Log
The global logging object.

TAG can be staticly defined using a LOG_TAG.

message must be a string literal as such.

C
Log("String goes here"); ✔️
Log(someStringReference); ❌

Unless TAG2NUM() is used.

And number can be any unsigned 32 bit integer.

The companion app received this messages as an 8 byte integer and decodes them by first splitting them into the structure shown, and then matching those number that Pre_Build.py generates in log_lookup.json

Debug ASCII Mode

When the prebuild script Pre_Build.py is skipped, calls to Log still function, however the message sent is instead a formatted ASCII string, no string mapping or anything else occurs.

This mode also has the option to prepend a time stamp

Logging Levels

Logging has different levels which can be logged to, this is used to differentiate between how important different log entries are.

The current types are as follows.

Func Call Log Type
Log.d() Debug log
Log.i() Info log
Log() Normal log
Log.w() Warning log
Log.e() Error log
Log.f() Fatal Log

Logging over Can

The front ECU can easily communicate with the companion app as it is connected directly with USB serial.

However, the back ECU is only connected to the front ECU through CanBus.

To enable logging on the back ECU, it has to send messages over Canbus. This method is only supported when Logging is in it's default mode.

Running Logging::enableCanbusRelay() once on the front ECU ensure that it receives and relays messages from the back ECU to the companion app.

Warning
Because of the nature of serial and its interaction with interrupts, which is how messages are relayed, it is recommended to instead use CanPins to communicate data from the back ECU to the front ECU.
See also
Pins.h for more info on CanPins
Pre_Build.py for more info on how calls to Logging related items are modified before compilation

Definition at line 157 of file Log.h.

Member Function Documentation

◆ d() [1/2]

void Logging::Log_t::d ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string using a debug tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ d() [2/2]

void Logging::Log_t::d ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number using a debug tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ e() [1/2]

void Logging::Log_t::e ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string using an error tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ e() [2/2]

void Logging::Log_t::e ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number using an error tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ f() [1/2]

void Logging::Log_t::f ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string using a fatal tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ f() [2/2]

void Logging::Log_t::f ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number using a fatal tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ i() [1/2]

void Logging::Log_t::i ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string using an info tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ i() [2/2]

void Logging::Log_t::i ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number using an info tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ operator()() [1/2]

void Logging::Log_t::operator() ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string usb serial.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ operator()() [2/2]

void Logging::Log_t::operator() ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number to usb serial.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ p()

void Logging::Log_t::p ( LOG_TAG  name,
LOG_MSG  prettyName,
const uint32_t  number,
int  mediate = false 
)

Post a monitored value.

Parameters
nameCode safe name of this value
prettyNamePretty, human readable name of this value
numberInteger number associated with this value
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

◆ w() [1/2]

void Logging::Log_t::w ( LOG_TAG  TAG,
LOG_MSG  message 
)

Log a string using a warning tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed

◆ w() [2/2]

void Logging::Log_t::w ( LOG_TAG  TAG,
LOG_MSG  message,
const uint32_t  number,
int  mediate = false 
)

Log a string and a variable number using a warning tag.

Parameters
TAGVariable of type LOG_TAG
messageInline string that should be printed
numberAny number that should be printed next to the string
mediateIndicate whether this message should only print when the number changes, only works in non-ASCII mode

The documentation for this struct was generated from the following file: