Skip to content

Commit

Permalink
added binary part splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
pingdynasty committed Mar 4, 2020
1 parent 2f64d83 commit d9e0d95
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions Source/FirmwareSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class FirmwareSender {
bool doFlash = false;
uint32_t flashChecksum;
uint8_t deviceNum = MIDI_SYSEX_OMNI_DEVICE;
uint32_t partSize = 0;
uint32_t slotSize = 128*1024;
public:
void listDevices(const StringArray& names){
for(int i=0; i<names.size(); ++i)
Expand Down Expand Up @@ -93,6 +95,7 @@ class FirmwareSender {
<< "-in FILE\tinput FILE" << std::endl
<< "-out DEVICE\tsend output to MIDI interface DEVICE" << std::endl
<< "-id NUM\t\tsend to OWL device NUM" << std::endl
<< "-split NUM\tsplit into parts of no more than NUM kilobytes of data" << std::endl
<< "-save FILE\twrite output to FILE" << std::endl
<< "-store NUM\tstore in slot NUM" << std::endl
<< "-run\t\tstart patch after upload" << std::endl
Expand Down Expand Up @@ -146,10 +149,10 @@ class FirmwareSender {
juce::String name = juce::String(argv[i]);
fileout = new File(File::getCurrentWorkingDirectory().getChildFile(name));
// fileout = new juce::File(name);
fileout->deleteFile();
fileout->create();
}else if(arg.compare("-id") == 0 && ++i < argc){
deviceNum = juce::String(argv[i]).getIntValue();
}else if(arg.compare("-split") == 0 && ++i < argc){
partSize = juce::String(argv[i]).getIntValue() * 1024;
}else{
usage();
throw CommandLineException(juce::String::empty);
Expand All @@ -172,27 +175,48 @@ class FirmwareSender {
if(fileout != NULL)
std::cout << "\tto SysEx file " << fileout->getFullPathName() << std::endl;
}
juce::ScopedPointer<InputStream> in = input->createInputStream();
int size = input->getSize(); // amount of data, excluding checksum
int part = 0;
while(partSize && size > partSize){
sendPart(in, partSize);
size -= partSize;
if(fileout != NULL){
fileout = new File(fileout->getNonexistentSibling());
std::cout << "\tto SysEx file " << fileout->getFullPathName() << std::endl;
}
if(storeSlot >= 0)
storeSlot += partSize/slotSize;
}
sendPart(in, size);
stop();
}

void sendPart(InputStream* in, int size){
if(verbose)
std::cout << "sending " << std::dec << size << " bytes" << std::endl;

const uint8_t header[] = { MIDI_SYSEX_MANUFACTURER, deviceNum, SYSEX_FIRMWARE_UPLOAD };
int binblock = (int)floor(blockSize*7/8);
// int sysblock = (int)ceil(binblock*8/7);

juce::ScopedPointer<InputStream> in = input->createInputStream();
if(fileout != NULL)
if(fileout != NULL){
fileout->deleteFile();
fileout->create();
out = fileout->createOutputStream();

}
int packageIndex = 0;
MemoryBlock block;
block.append(header, sizeof(header));
encodeInt(block, packageIndex++);
unsigned char* buffer = (unsigned char*)alloca(binblock*sizeof(unsigned char));
unsigned char* sysex = (unsigned char*)alloca(blockSize*sizeof(unsigned char));
int size = input->getSize(); // amount of data, excluding checksum
encodeInt(block, size);
// send first message with index and length
send(block);

uint32_t checksum = 0;
for(int i=0; i < size && running;){
binblock = std::min(binblock, size-i);
block = MemoryBlock();
block.append(header, sizeof(header));
encodeInt(block, packageIndex++);
Expand Down Expand Up @@ -245,7 +269,6 @@ class FirmwareSender {
send(block);
}
}
stop();
}

void encodeInt(MemoryBlock& block, uint32_t data){
Expand Down

0 comments on commit d9e0d95

Please sign in to comment.