Printing messages

Leo Selavo edited this page Jan 14, 2016 · 6 revisions

In MansOS you can easily print text messages to serial port. Actually, you could print to radio as well. This makes debugging much easier. An example of this is in the PrintADC demo application, available here: MasnOS/apps/demo/PrintADC

This is how you do it:

  1. include stdmansos.h
  2. use PRINTF(...) wherever you need to print. The syntax is similar to the popular printf() function, including the codes for the parameter types and escape codes.

Example

In the following example we read ADC value and print it using PRINTF() to the serial port. The default data transmission (Baud) rate is determined by the platform. We also print a plain text - a newline.

#include "stdmansos.h"

void appMain(void)
{
    uint16_t channel = 0;
    uint16_t val;

    adcInit();

    for (;;) {                   // Loop forever
        val = adcRead(channel);  // Read ADC value

        PRINTF("\t%i", val);     // Print value
        PRINTF("\n");            // Print text (a newline)

        mdelay(1000);            // Wait 1 second
    }
}

Receiving messages

The messages could be received on the other end of the serial port, e.g. the PC that the device is connected to.

MansOS includes a python program that allows viewing the incoming stream on the serial port: /tools/serial/ser.py

The list of options, such as the port and baud rate, is available by using -h or --help switch: $> ser.py -h

As alternative, any serial console application can be used, such as gtkterm, minicom, or an application written by you. Just remember to set the correct port, baud rate and other parameters.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.