rainbow: fixed FILE_WRITE and FILE_APPEND commands
This commit is contained in:
parent
f264c7a8f6
commit
9826479b5d
|
@ -920,7 +920,7 @@ void BrokeStudioFirmware::processBufferedMessage()
|
|||
break;
|
||||
case toesp_cmds_t::FILE_WRITE:
|
||||
UDBG("[Rainbow] ESP received command FILE_WRITE\n");
|
||||
if (message_size >= 3 && this->working_file.active)
|
||||
if (message_size >= 2 && this->working_file.active)
|
||||
{
|
||||
this->writeFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
|
||||
this->working_file.offset += message_size - 1;
|
||||
|
@ -928,10 +928,9 @@ void BrokeStudioFirmware::processBufferedMessage()
|
|||
break;
|
||||
case toesp_cmds_t::FILE_APPEND:
|
||||
UDBG("[Rainbow] ESP received command FILE_APPEND\n");
|
||||
if (message_size >= 3 && this->working_file.active)
|
||||
if (message_size >= 2 && this->working_file.active)
|
||||
{
|
||||
UDBG("[Rainbow] ESP command FILE_APPEND not implemented\n");
|
||||
// this->appendFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
|
||||
this->appendFile(this->rx_buffer.begin() + 2, this->rx_buffer.begin() + message_size + 1);
|
||||
}
|
||||
break;
|
||||
case toesp_cmds_t::FILE_COUNT:
|
||||
|
@ -1415,6 +1414,24 @@ void BrokeStudioFirmware::writeFile(I data_begin, I data_end)
|
|||
}
|
||||
}
|
||||
|
||||
template<class I>
|
||||
void BrokeStudioFirmware::appendFile(I data_begin, I data_end)
|
||||
{
|
||||
if (this->working_file.active == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto const data_size = data_end - data_begin;
|
||||
size_t file_size = this->working_file.file->data.size();
|
||||
uint32_t const offset_end = file_size + data_size;
|
||||
this->working_file.file->data.resize(offset_end, 0);
|
||||
|
||||
for (vector<uint8_t>::size_type i = file_size; i < offset_end; ++i) {
|
||||
this->working_file.file->data[i] = *data_begin;
|
||||
++data_begin;
|
||||
}
|
||||
}
|
||||
|
||||
void BrokeStudioFirmware::saveFiles()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
|
|
@ -284,6 +284,8 @@ private:
|
|||
void readFile(uint8_t n);
|
||||
template <class I>
|
||||
void writeFile(I data_begin, I data_end);
|
||||
template <class I>
|
||||
void appendFile(I data_begin, I data_end);
|
||||
void saveFiles();
|
||||
void saveFile(uint8_t drive, char const* filename);
|
||||
void loadFiles();
|
||||
|
|
Loading…
Reference in New Issue