@@ -60,7 +60,7 @@ FirmataParser::FirmataParser(uint8_t * const dataBuffer, size_t dataBufferSize)
6060 currentDataBufferOverflowCallback((dataBufferOverflowCallbackFunction)NULL),
6161 currentStringCallback((stringCallbackFunction)NULL),
6262 currentSysexCallback((sysexCallbackFunction)NULL),
63- currentReportFirmwareCallback((systemCallbackFunction )NULL),
63+ currentReportFirmwareCallback((versionCallbackFunction )NULL),
6464 currentReportVersionCallback((systemCallbackFunction)NULL),
6565 currentSystemResetCallback((systemCallbackFunction)NULL)
6666{
@@ -244,21 +244,34 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void *
244244}
245245
246246/* *
247- * Attach a system callback function (options are: REPORT_FIRMWARE, REPORT_VERSION
248- * and SYSTEM_RESET).
247+ * Attach a version callback function (supported option: REPORT_FIRMWARE).
249248 * @param command The ID of the command to attach a callback function to.
250249 * @param newFunction A reference to the callback function to attach.
251250 * @param context An optional context to be provided to the callback function (NULL by default).
252251 * @note The context parameter is provided so you can pass a parameter, by reference, to
253252 * your callback function.
254253 */
255- void FirmataParser::attach (uint8_t command, systemCallbackFunction newFunction, void * context)
254+ void FirmataParser::attach (uint8_t command, versionCallbackFunction newFunction, void * context)
256255{
257256 switch (command) {
258257 case REPORT_FIRMWARE:
259258 currentReportFirmwareCallback = newFunction;
260259 currentReportFirmwareCallbackContext = context;
261260 break ;
261+ }
262+ }
263+
264+ /* *
265+ * Attach a system callback function (supported options are: SYSTEM_RESET, REPORT_VERSION).
266+ * @param command The ID of the command to attach a callback function to.
267+ * @param newFunction A reference to the callback function to attach.
268+ * @param context An optional context to be provided to the callback function (NULL by default).
269+ * @note The context parameter is provided so you can pass a parameter, by reference, to
270+ * your callback function.
271+ */
272+ void FirmataParser::attach (uint8_t command, systemCallbackFunction newFunction, void * context)
273+ {
274+ switch (command) {
262275 case REPORT_VERSION:
263276 currentReportVersionCallback = newFunction;
264277 currentReportVersionCallbackContext = context;
@@ -325,6 +338,8 @@ void FirmataParser::detach(uint8_t command)
325338{
326339 switch (command) {
327340 case REPORT_FIRMWARE:
341+ attach (command, (versionCallbackFunction)NULL , NULL );
342+ break ;
328343 case REPORT_VERSION:
329344 case SYSTEM_RESET:
330345 attach (command, (systemCallbackFunction)NULL , NULL );
@@ -394,14 +409,24 @@ void FirmataParser::processSysexMessage(void)
394409{
395410 switch (dataBuffer[0 ]) { // first byte in buffer is command
396411 case REPORT_FIRMWARE:
397- if (currentReportFirmwareCallback)
398- (*currentReportFirmwareCallback)(currentReportFirmwareCallbackContext);
412+ if (currentReportFirmwareCallback) {
413+ size_t sv_major = dataBuffer[1 ], sv_minor = dataBuffer[2 ];
414+ size_t i = 0 , j = 3 ;
415+ while (j < sysexBytesRead) {
416+ // The string length will only be at most half the size of the
417+ // stored input buffer so we can decode the string within the buffer.
418+ bufferDataAtPosition (dataBuffer[j], i);
419+ ++i;
420+ ++j;
421+ }
422+ bufferDataAtPosition (' \0 ' , i); // Terminate the string
423+ (*currentReportFirmwareCallback)(currentReportFirmwareCallbackContext, sv_major, sv_minor, (const char *)&dataBuffer[0 ]);
424+ }
399425 break ;
400426 case STRING_DATA:
401427 if (currentStringCallback) {
402428 size_t bufferLength = (sysexBytesRead - 1 ) / 2 ;
403- size_t i = 1 ;
404- size_t j = 0 ;
429+ size_t i = 1 , j = 0 ;
405430 while (j < bufferLength) {
406431 // The string length will only be at most half the size of the
407432 // stored input buffer so we can decode the string within the buffer.
@@ -417,7 +442,7 @@ void FirmataParser::processSysexMessage(void)
417442 if (dataBuffer[j - 1 ] != ' \0 ' ) {
418443 bufferDataAtPosition (' \0 ' , j);
419444 }
420- (*currentStringCallback)(currentStringCallbackContext, (char *)&dataBuffer[0 ]);
445+ (*currentStringCallback)(currentStringCallbackContext, (const char *)&dataBuffer[0 ]);
421446 }
422447 break ;
423448 default :
0 commit comments