arduino icon indicating copy to clipboard operation
arduino copied to clipboard

move error messages out of SRAM

Open soundanalogous opened this issue 12 years ago • 1 comments

The error messages in StandardFirmata are all stored in SRAM. I'd like to move them out. There are a couple of options.

1 Move the error strings to program memory. The issue here is the PROGMEM macro only applies to AVR micros. However the following (stolen from ArduinoUnit) may work:

#if defined(__arm__) && !defined(PROGMEM)
#define PROGMEM
#define PSTR(s) s
#define memcpy_P(a, b, c) memcpy(a, b, c)
#define strlen_P(a) strlen(a)
#endif

You'd still need a buffer to copy the error string to in order to send it, but one 50 byte buffer takes up much less ram than all of the existing error strings. I implemented this in a test and it saved 93 bytes of ram.

2 Create a new sysexMessage type for error messages and send a numeric error code rather than a string. Client library developers would then need to provide a lookup to the string matching the error code. This would be documented on Firmata.org and within the Firmata code.

0  START_SYSEX
1  ERROR_MSG    (0x68)
2  error code
3  END_SYSEX

Personally I prefer option 2. It makes error messages explicit (so you don't have to weed them out of general string messages) and saves a lot of ram. See proposal on Firmata.org: http://firmata.org/wiki/Proposals#Error_Msg_Proposal The only issue here would be if any client library is actually doing anything in response to the existing string messages.

soundanalogous avatar Aug 04 '13 16:08 soundanalogous

see https://github.com/firmata/arduino/pull/80

soundanalogous avatar Aug 11 '13 20:08 soundanalogous