Skip to content

Allow subclassing #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move instance pointer to lzss_download function
  • Loading branch information
pennam committed Nov 22, 2023
commit 3ba4f9bad764d8f345e99c88dbe10459ccfca5d3
23 changes: 1 addition & 22 deletions src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@
#include "decompress/utility.h"
#include "esp_ota_ops.h"

/* Used to bind local module function to actual class instance */
static Arduino_ESP32_OTA * _esp_ota_obj_ptr = 0;

/******************************************************************************
LOCAL MODULE FUNCTIONS
******************************************************************************/

static uint8_t read_byte() {
if(_esp_ota_obj_ptr) {
return _esp_ota_obj_ptr->read_byte_from_network();
}
return -1;
}

static void write_byte(uint8_t data) {
if(_esp_ota_obj_ptr) {
_esp_ota_obj_ptr->write_byte_to_flash(data);
}
}

/******************************************************************************
CTOR/DTOR
******************************************************************************/
Expand All @@ -67,7 +47,6 @@ Arduino_ESP32_OTA::Arduino_ESP32_OTA()

Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin()
{
_esp_ota_obj_ptr = this;

/* ... initialize CRC ... */
_crc32 = 0xFFFFFFFF;
Expand Down Expand Up @@ -273,7 +252,7 @@ int Arduino_ESP32_OTA::download(const char * ota_url)
_crc32 = crc_update(_crc32, &_ota_header.header.magic_number, 12);

/* Download and decode OTA file */
_ota_size = lzss_download(read_byte, write_byte, content_length_val - sizeof(_ota_header));
_ota_size = lzss_download(this, content_length_val - sizeof(_ota_header));

if(_ota_size <= content_length_val - sizeof(_ota_header))
{
Expand Down
7 changes: 0 additions & 7 deletions src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ static uint32_t const ARDUINO_ESP32_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms = 10000;
static uint32_t const ARDUINO_ESP32_OTA_BINARY_HEADER_RECEIVE_TIMEOUT_ms = 10000;
static uint32_t const ARDUINO_ESP32_OTA_BINARY_BYTE_RECEIVE_TIMEOUT_ms = 2000;

/******************************************************************************
* TYPEDEF
******************************************************************************/

typedef uint8_t(*ArduinoEsp32OtaReadByteFuncPointer)(void);
typedef void(*ArduinoEsp32OtaWriteByteFuncPointer)(uint8_t);

/******************************************************************************
* CLASS DECLARATION
******************************************************************************/
Expand Down
14 changes: 7 additions & 7 deletions src/decompress/lzss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
GLOBAL VARIABLES
**************************************************************************************/

/* Used to bind local module function to actual class instance */
static Arduino_ESP32_OTA * esp_ota_obj_ptr = 0;

static size_t LZSS_FILE_SIZE = 0;
static ArduinoEsp32OtaReadByteFuncPointer read_byte_fptr = 0;
static ArduinoEsp32OtaWriteByteFuncPointer write_byte_fptr = 0;

int bit_buffer = 0, bit_mask = 128;
unsigned char buffer[N * 2];
Expand All @@ -38,7 +39,7 @@ static size_t bytes_read_fgetc = 0;

void lzss_fputc(int const c)
{
write_byte_fptr((uint8_t)c);
esp_ota_obj_ptr->write_byte_to_flash((uint8_t)c);

/* write byte callback */
bytes_written_fputc++;
Expand All @@ -56,7 +57,7 @@ int lzss_fgetc()
return LZSS_EOF;

/* read byte callback */
uint8_t const c = read_byte_fptr();
uint8_t const c = esp_ota_obj_ptr->read_byte_from_network();
bytes_read_fgetc++;

return c;
Expand Down Expand Up @@ -157,10 +158,9 @@ void lzss_decode(void)
PUBLIC FUNCTIONS
**************************************************************************************/

int lzss_download(ArduinoEsp32OtaReadByteFuncPointer read_byte, ArduinoEsp32OtaWriteByteFuncPointer write_byte, size_t const lzss_file_size)
int lzss_download(Arduino_ESP32_OTA * instance, size_t const lzss_file_size)
{
read_byte_fptr = read_byte;
write_byte_fptr = write_byte;
esp_ota_obj_ptr = instance;
LZSS_FILE_SIZE = lzss_file_size;
bytes_written_fputc = 0;
bytes_read_fgetc = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/decompress/lzss.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
FUNCTION DEFINITION
**************************************************************************************/

int lzss_download(ArduinoEsp32OtaReadByteFuncPointer read_byte, ArduinoEsp32OtaWriteByteFuncPointer write_byte, size_t const lzss_file_size);
int lzss_download(Arduino_ESP32_OTA * instance, size_t const lzss_file_size);

#endif /* SSU_LZSS_H_ */