Skip to content

Things that should already be fixed in ConfigurableFirmata #136

@jcvillegasfernandez

Description

@jcvillegasfernandez

Bugs reported long ago and not fixed yet:

Fix the compatibility problem of FirmataScheduler and OnewireFirmata with devices other than Arduino Uno, like ESP8266, ESP32 and probably others due to different sizes of pointer, Int and long.

New bug detected:

A bug (hard to detect) when the size of the SYSEX command to send is 64 (buffer size), the last byte is lost, works fine with any other value, solution at the end.

Modify file FirmataScheduler.cpp in this way

inside this function
boolean FirmataScheduler::handleSysex(byte command, byte argc, byte* argv)

case DELAY_FIRMATA_TASK:
          {
            if (argc == 6) {
              argv++;
              Encoder7BitClass::readBinary(4, argv, argv); //decode inplace
     **// long is different on ESP8266 (or ESP32) and arduino**
              _delayTask((long)argv[0] | (long)argv[1]<<8 | (long)argv[2]<<16 | (long)argv[3]<<24);
            }
            break;
          }
        case SCHEDULE_FIRMATA_TASK:
          {
            if (argc == 7) { //one byte taskid, 5 bytes to encode 4 bytes of long
              Encoder7BitClass::readBinary(4, argv + 2, argv + 2); //decode inplace
    **// long is different on ESP8266 (or ESP32) and arduino**
              _schedule(argv[1], (long)argv[2] | (long)argv[3]<<8 | (long)argv[4]<<16 | (long)argv[5]<<24);
            }
            break;
          }

void FirmataScheduler::reportTask(byte id, firmata_task* task, boolean error)

if (task) {
        encoder.startBinaryWrite();
    **// because long and int are different on ESP8266 (or ESP32) and arduino**
            // write time_ms
        encoder.writeBinary(task->time_ms & 0xFF); 
        encoder.writeBinary((task->time_ms >> 8) & 0xFF);  
        encoder.writeBinary((task->time_ms >> 16) & 0xFF); 
        encoder.writeBinary((task->time_ms >> 24) & 0xFF); 
           // write len
        encoder.writeBinary(task->len & 0xFF); 
        encoder.writeBinary((task->len >> 8) & 0xFF);
            // write pos
        encoder.writeBinary(task->pos & 0xFF); 
        encoder.writeBinary((task->pos >> 8) & 0xFF); 
            // write messages
        for (unsigned int i = 0; i < task->len; i++) {
          encoder.writeBinary(task->messages[i]); 
        }        
    encoder.endBinaryWrite();
    }

Modify file OnwwireFirmata.cpp in this way

inside this function
boolean OneWireFirmata::handleSysex(byte command, byte argc, byte* argv)

 if (subcommand & ONEWIRE_READ_REQUEST_BIT) {
                  if (numBytes < 4) break;
                  //numReadBytes = *((int*)argv);
                  //correlationId = *((int*)argv);
   **// int is different on ESP8266 (or ESP32) and arduino**
                  numReadBytes = (int)argv[0] | ((int)argv[1]<<8);  
                  correlationId = (int)argv[2] | ((int)argv[3]<<8); 
		  argv += 4;
                  numBytes -= 4;
                }
  if (subcommand & ONEWIRE_DELAY_REQUEST_BIT) {
                  if (numBytes < 4) break;
                  //Firmata.delayTask(*((long*)argv));
   **// long is different on ESP8266 (or ESP32) and arduino**
                  Firmata.delayTask((long)argv[0] | ((long)argv[1] << 8) | ((long)argv[2] << 16) | ((long)argv[3] << 24));
                  argv += 4;
                  numBytes -= 4;
                }

Change ConfigurableFirmata.cpp (lost last byte when command size is 64)

Change inside this function

void FirmataClass::parse(byte inputData)

else {
       //normal data byte - add to buffer
       storedInputData[sysexBytesRead] = inputData;
       sysexBytesRead++;
if (sysexBytesRead == MAX_DATA_BYTES)
{
Firmata.sendString(F("Discarding input message, out of buffer"));
parsingSysex = false;
sysexBytesRead = 0;
 waitForData = 0;
       }
  }

For this

else {
if (sysexBytesRead == MAX_DATA_BYTES)
{
Firmata.sendString(F("Discarding input message, out of buffer"));
parsingSysex = false;
sysexBytesRead = 0;
           waitForData = 0;
         }
else {
           //normal data byte - add to buffer
           storedInputData[sysexBytesRead] = inputData;
           sysexBytesRead++;
         }
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions