@@ -52,36 +52,41 @@ void loop()
52
52
* FUNCTION DEFINITION
53
53
**************************************************************************************/
54
54
55
- void serial_thread_func ( )
55
+ String nmea_message_prefix (String const & /* msg */ )
56
56
{
57
- Serial.begin (9600 );
57
+ return String (" $" );
58
+ }
58
59
59
- Serial.prefix ([](String const & /* msg */ ) -> String
60
- {
61
- return String (" $" );
62
- });
63
- Serial.suffix ([](String const & prefix, String const & msg) -> String
60
+ String nmea_message_suffix (String const & prefix, String const & msg)
61
+ {
62
+ /* NMEA checksum is calculated over the complete message
63
+ * starting with '$' and ending with the end of the message.
64
+ */
65
+ byte checksum = 0 ;
66
+ std::for_each (msg.c_str (),
67
+ msg.c_str () + msg.length (),
68
+ [&checksum](char const c)
64
69
{
65
- /* NMEA checksum is calculated over the complete message
66
- * starting with '$' and ending with the end of the message.
67
- */
68
- byte checksum = 0 ;
69
- std::for_each (msg.c_str (),
70
- msg.c_str () + msg.length (),
71
- [&checksum](char const c)
72
- {
73
- checksum ^= static_cast <uint8_t >(c);
74
- });
75
- /* Assemble the footer of the NMEA message. */
76
- char footer[16 ] = {0 };
77
- snprintf (footer, sizeof (footer), " *%02X\r\n " , checksum);
78
- return String (footer);
70
+ checksum ^= static_cast <uint8_t >(c);
79
71
});
72
+ /* Assemble the footer of the NMEA message. */
73
+ char footer[16 ] = {0 };
74
+ snprintf (footer, sizeof (footer), " *%02X\r\n " , checksum);
75
+ return String (footer);
76
+ }
77
+
78
+ void serial_thread_func ()
79
+ {
80
+ Serial.begin (9600 );
81
+
82
+ Serial.prefix (nmea_message_prefix);
83
+ Serial.suffix (nmea_message_suffix);
80
84
81
85
for (;;)
82
86
{
83
87
/* Sleep between 5 and 500 ms */
84
88
rtos::ThisThread::sleep_for (rtos::Kernel::Clock::duration_u32 (random (5 ,500 )));
89
+
85
90
/* Print a fake NMEA GPRMC message:
86
91
* $GPRMC,062101.714,A,5001.869,N,01912.114,E,955535.7,116.2,290520,000.0,W*45\r\n
87
92
*/
0 commit comments