@@ -60,7 +60,7 @@ FirmataParser::FirmataParser(uint8_t * const dataBuffer, size_t dataBufferSize)
60
60
currentDataBufferOverflowCallback((dataBufferOverflowCallbackFunction)NULL),
61
61
currentStringCallback((stringCallbackFunction)NULL),
62
62
currentSysexCallback((sysexCallbackFunction)NULL),
63
- currentReportFirmwareCallback((systemCallbackFunction )NULL),
63
+ currentReportFirmwareCallback((versionCallbackFunction )NULL),
64
64
currentReportVersionCallback((systemCallbackFunction)NULL),
65
65
currentSystemResetCallback((systemCallbackFunction)NULL)
66
66
{
@@ -244,21 +244,34 @@ void FirmataParser::attach(uint8_t command, callbackFunction newFunction, void *
244
244
}
245
245
246
246
/* *
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).
249
248
* @param command The ID of the command to attach a callback function to.
250
249
* @param newFunction A reference to the callback function to attach.
251
250
* @param context An optional context to be provided to the callback function (NULL by default).
252
251
* @note The context parameter is provided so you can pass a parameter, by reference, to
253
252
* your callback function.
254
253
*/
255
- void FirmataParser::attach (uint8_t command, systemCallbackFunction newFunction, void * context)
254
+ void FirmataParser::attach (uint8_t command, versionCallbackFunction newFunction, void * context)
256
255
{
257
256
switch (command) {
258
257
case REPORT_FIRMWARE:
259
258
currentReportFirmwareCallback = newFunction;
260
259
currentReportFirmwareCallbackContext = context;
261
260
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) {
262
275
case REPORT_VERSION:
263
276
currentReportVersionCallback = newFunction;
264
277
currentReportVersionCallbackContext = context;
@@ -325,6 +338,8 @@ void FirmataParser::detach(uint8_t command)
325
338
{
326
339
switch (command) {
327
340
case REPORT_FIRMWARE:
341
+ attach (command, (versionCallbackFunction)NULL , NULL );
342
+ break ;
328
343
case REPORT_VERSION:
329
344
case SYSTEM_RESET:
330
345
attach (command, (systemCallbackFunction)NULL , NULL );
@@ -394,14 +409,24 @@ void FirmataParser::processSysexMessage(void)
394
409
{
395
410
switch (dataBuffer[0 ]) { // first byte in buffer is command
396
411
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
+ }
399
425
break ;
400
426
case STRING_DATA:
401
427
if (currentStringCallback) {
402
428
size_t bufferLength = (sysexBytesRead - 1 ) / 2 ;
403
- size_t i = 1 ;
404
- size_t j = 0 ;
429
+ size_t i = 1 , j = 0 ;
405
430
while (j < bufferLength) {
406
431
// The string length will only be at most half the size of the
407
432
// stored input buffer so we can decode the string within the buffer.
@@ -417,7 +442,7 @@ void FirmataParser::processSysexMessage(void)
417
442
if (dataBuffer[j - 1 ] != ' \0 ' ) {
418
443
bufferDataAtPosition (' \0 ' , j);
419
444
}
420
- (*currentStringCallback)(currentStringCallbackContext, (char *)&dataBuffer[0 ]);
445
+ (*currentStringCallback)(currentStringCallbackContext, (const char *)&dataBuffer[0 ]);
421
446
}
422
447
break ;
423
448
default :
0 commit comments