NOTE: These examples use embedded-friendly
estd::basic_ostream
. Don't be afraid of theout
reference!
template <pgns pgn>
void print_pgn_name()
{
out << embr::j1939::pgn::traits<pgn>::name() << endl;
}
template <spns spn>
void print_spn_name()
{
out << embr::j1939::spn::traits<spn>::name() << endl;
}
Since c++11 doesn't have fold expressions, a different approach is required
to compile-time iterate. Fortunately, estd::variadic::values
helps with this.
template <spns spn>
void print_spn_name()
{
out << embr::j1939::spn::traits<spn>::name() << endl;
}
template <pgns pgn>
void print_spn_names()
{
using pgn_spns = embr::j1939::pgn::traits<pgn>::spns;
out << embr::j1939::spn::traits<spn>::name() << endl;
}
See TBD for estd documentation on the subject (malachi-iot/estdlib#44 )
What amounts to a tuned switch statement, the dispatch mechanism is a convenient way to translate a run time PGN# into a compile time PDU.
be careful, Dispatch can produce a lot of code spew
See Concepts for breakdown of internal Dispatch behavior