complete send SysEx (over multiple packets)

Test multiple packets by sending sysex11 over a buffer of 5 bytes of more (change byte mTxBuffer[Settings::MaxBufferSize];)

Interesting edge cases are with buffer len: 5,7 and 12 (with sysex11)
This commit is contained in:
lathoub 2020-10-03 10:02:49 +02:00
parent 359c9acd22
commit ba7c598a52
2 changed files with 28 additions and 16 deletions

View File

@ -62,7 +62,6 @@ void loop()
{
t0 = millis();
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 127 on channel 1
MIDI.sendSysEx(sizeof(sysex11), sysex11, true);
}
}

View File

@ -22,18 +22,21 @@ private:
byte mRxBuffer[Settings::MaxBufferSize];
unsigned mRxIndex = 0;
byte mTxBuffer[Settings::MaxBufferSize];
byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes
unsigned mTxIndex = 0;
char mDeviceName[24];
bool mIsSysEx;
uint8_t mTimestampLow;
private:
T mBleClass;
public:
BLEMIDITransport(const char* deviceName)
{
strncpy(mDeviceName, deviceName, 24);
strncpy(mDeviceName, deviceName, sizeof(mDeviceName));
mRxIndex = 0;
mTxIndex = 0;
@ -47,34 +50,44 @@ public:
mBleClass.begin(mDeviceName, this);
}
bool beginTransmission(MidiType)
bool beginTransmission(MidiType type)
{
getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]);
mTxIndex = 2;
mTimestampLow = mTxBuffer[1];
return true;
}
void write(byte inData)
{
// check for size! SysEx!!!
if (false)
if (mTxIndex >= sizeof(mTxBuffer))
{
// should only happen from SysEx!
// if we approach the end of the buffer, chop-up in segments until
// we reach F7 (end of SysEx)
mBleClass.write(mTxBuffer, sizeof(mTxBuffer));
mTxIndex = 1; // keep header
}
if (inData == MidiType::SystemExclusiveEnd)
{
mTxBuffer[mTxIndex++] = mTxBuffer[1];
}
mTxBuffer[mTxIndex++] = inData;
}
void endTransmission()
{
if (mTxBuffer[mTxIndex - 1] == 0xF7)
{
if (mTxIndex >= sizeof(mTxBuffer))
{
mBleClass.write(mTxBuffer, mTxIndex - 1);
mTxIndex = 1; // keep header
mTxBuffer[mTxIndex++] = mTimestampLow;
}
else
{
mTxBuffer[mTxIndex - 1] = mTimestampLow;
}
mTxBuffer[mTxIndex++] = 0xF7;
}
mBleClass.write(mTxBuffer, mTxIndex);
mTxIndex = 0;
}