I am running a customized mote firmware that I assembled using pieces of bm_protocol user_code.cpp examples: hello_world, serial_payload_example and serial_payload_guide. The main difference is that I cannot do line-oriented input, mostly because my sensor sends a blank line immediately following every data line. Instead I am doing character-oriented input. In simplest terms I have swapped PLUART::lineAvailable() and PLUART::readLine() for PLUART::byteAvailable and PLUART::readByte().
That all seems to work beautifully. Except when it crashes.
During longer tests the buoy drops a measurement every fifth reading, like clockwork. By watching the bmdk terminal output, the spotter terminal output, and whatās written to the SD card, I know the whole buoy is rebooting when this happens. My best guess is a segmentation fault in my mote firmware.
In these linesā¦
// Print the payload data to a file, to the bm_printf console, and to the printf console.
bm_fprintf(0, āsami_data.logā, ātick: %ā PRIu64 ā, rtc: %s, line: %.*s\nā, uptimeGetMs(), rtcTimeBuffer, payload_size, payload_buffer);
bm_printf(0, ā[sami] | tick: %ā PRIu64 ā, rtc: %s, line: %.*sā, uptimeGetMs(), rtcTimeBuffer, payload_size, payload_buffer);
printf(ā[sami] | tick: %ā PRIu64 ā, rtc: %s, line: %.*s\nā, uptimeGetMs(), rtcTimeBuffer, payload_size, payload_buffer);
ā¦it is the bm_printf() line that crashes things. Which is driving me nuts. The bm_fprintf() line successfully writes its output to the SD card, and I believe the next line is trying to write a message to the bmdk terminal. The printf() line, if it got that far, would send its message to the spotter terminal.
My current theory is that something about the payload_buffer isnāt properly reset after each measurement. Simple resetting payload_size to 0 isnāt having the intended effect. So, when enough input has been received (in this context it happens predictably at the fifth measurement received from the payload), it crashes.
I can share the entire firmware source if necessary, itās only 153 lines right now, but what is it about my payload_buffer or payload_size, which are defined asā¦
// A buffer for our data from the payload uart
u_int8_t payload_buffer[2048];
static u_int32_t payload_size = 0;
ā¦could be segfaulting in that second line when the first line is perfectly happy?
[Heads-up to @Taylor.gill who will be following this convo too.]
Mike J+