Skip to content

Commit

Permalink
Return number of bytes in OTA receive buffer when calling 'onOTADataR…
Browse files Browse the repository at this point in the history
…eceived'
  • Loading branch information
aentinger committed Jul 27, 2020
1 parent 336f33a commit 8b64fea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/utility/ota/OTALogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,20 @@ OTAError OTALogic::update()
return _ota_error;
}

void OTALogic::onOTADataReceived(uint8_t const * const data, size_t const length)
uint32_t OTALogic::onOTADataReceived(uint8_t const * const data, size_t const length)
{
size_t const bytes_available = (MQTT_OTA_BUF_SIZE - _mqtt_ota_buf.num_bytes);
if(length <= bytes_available)
{
memcpy(_mqtt_ota_buf.buf + _mqtt_ota_buf.num_bytes, data, length);
_mqtt_ota_buf.num_bytes += length;
return _mqtt_ota_buf.num_bytes;
}
else
{
_ota_state = OTAState::Error;
_ota_error = OTAError::ReceivedDataOverrun;
return 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/utility/ota/OTALogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OTALogic


OTAError update();
void onOTADataReceived(uint8_t const * const data, size_t const length);
uint32_t onOTADataReceived(uint8_t const * const data, size_t const length);

#ifdef HOST
inline OTAState state() const { return _ota_state; }
Expand Down

0 comments on commit 8b64fea

Please sign in to comment.