sudomesh/disaster-radio

Remove Serial.prints from Console.cpp

paidforby opened this issue · 4 comments

After progress in #48 (comment), there are still some outstanding TODOs in middleware/Console.cpp. Most notably, the use of Serial.print statements (except in the DEBUG_OUT conditions?) need to be removed and replaced with the Console print function. This way the console will not be specific to the Arduino serial interface and could use any Stream.

Part of the challenge is that LoRaLayer2 has some print functions built-in for convenience sake. So we need to decide on a good way of adapting these functions.

@beegee-tokyo made a good suggestion on how to refactor the routing table print out here, #48 (comment), might just need to be synced with the updates to the console.

Also, there is a closely related issue with the telnet client. Whenever a %s is included in a sprintf() that is then sent to the telnet client, a CR-LF (carriage return, line feed) is printed at the end of the string. For example, once a username is entered, the printPrompt function returns,

<username
>

This only happens in the telnet client, not the serial client. I have yet to find a solution.

Perhaps it makes sense to write our own printf style function for the Console printing? There is a decent example of generally how to do this here, https://arduino.stackexchange.com/questions/176/how-do-i-print-multiple-variables-in-a-string.

I've removed the remaining non-debug Serial.printf statements in two ways.

  1. I added a utility function that converts byte arrays into hexidecimal char arrays to print, see utils.cpp
  2. I created a getRoutingTable function in LoRaLayer2 that writes to a char array what was previously just printed to Serial, see here

It's possible that I will adjust the getRoutingTable to write the table to a char array of some standard format, such as JSON. This will depend heavily on how I refactor the websocket client to parse for and display the routing table.

I'm going to considered this issue solved, an further revisions to the console can be discussed in a new issue.

Also, regarding the username printing over telnet, I discovered that the issue was trailing CR-LFs that were being added upon entering the username through telnet. To deal with this at added a string tokenization right when the console receives the username here, which removes those trialing CR-LFs. The console now works well both through serial and telnet.