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:
parent
359c9acd22
commit
ba7c598a52
|
|
@ -62,7 +62,6 @@ void loop()
|
||||||
{
|
{
|
||||||
t0 = millis();
|
t0 = millis();
|
||||||
|
|
||||||
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 127 on channel 1
|
|
||||||
MIDI.sendSysEx(sizeof(sysex11), sysex11, true);
|
MIDI.sendSysEx(sizeof(sysex11), sysex11, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,21 @@ private:
|
||||||
byte mRxBuffer[Settings::MaxBufferSize];
|
byte mRxBuffer[Settings::MaxBufferSize];
|
||||||
unsigned mRxIndex = 0;
|
unsigned mRxIndex = 0;
|
||||||
|
|
||||||
byte mTxBuffer[Settings::MaxBufferSize];
|
byte mTxBuffer[Settings::MaxBufferSize]; // minimum 5 bytes
|
||||||
unsigned mTxIndex = 0;
|
unsigned mTxIndex = 0;
|
||||||
|
|
||||||
char mDeviceName[24];
|
char mDeviceName[24];
|
||||||
|
|
||||||
|
bool mIsSysEx;
|
||||||
|
uint8_t mTimestampLow;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
T mBleClass;
|
T mBleClass;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BLEMIDITransport(const char* deviceName)
|
BLEMIDITransport(const char* deviceName)
|
||||||
{
|
{
|
||||||
strncpy(mDeviceName, deviceName, 24);
|
strncpy(mDeviceName, deviceName, sizeof(mDeviceName));
|
||||||
|
|
||||||
mRxIndex = 0;
|
mRxIndex = 0;
|
||||||
mTxIndex = 0;
|
mTxIndex = 0;
|
||||||
|
|
@ -47,34 +50,44 @@ public:
|
||||||
mBleClass.begin(mDeviceName, this);
|
mBleClass.begin(mDeviceName, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool beginTransmission(MidiType)
|
bool beginTransmission(MidiType type)
|
||||||
{
|
{
|
||||||
getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]);
|
getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]);
|
||||||
mTxIndex = 2;
|
mTxIndex = 2;
|
||||||
|
mTimestampLow = mTxBuffer[1];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(byte inData)
|
void write(byte inData)
|
||||||
{
|
{
|
||||||
// check for size! SysEx!!!
|
if (mTxIndex >= sizeof(mTxBuffer))
|
||||||
if (false)
|
|
||||||
{
|
{
|
||||||
// should only happen from SysEx!
|
mBleClass.write(mTxBuffer, sizeof(mTxBuffer));
|
||||||
// if we approach the end of the buffer, chop-up in segments until
|
mTxIndex = 1; // keep header
|
||||||
// we reach F7 (end of SysEx)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inData == MidiType::SystemExclusiveEnd)
|
|
||||||
{
|
|
||||||
mTxBuffer[mTxIndex++] = mTxBuffer[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
mTxBuffer[mTxIndex++] = inData;
|
mTxBuffer[mTxIndex++] = inData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endTransmission()
|
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);
|
mBleClass.write(mTxBuffer, mTxIndex);
|
||||||
mTxIndex = 0;
|
mTxIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue