@@ -77,25 +77,53 @@ extern "C" {
77
77
#if __has_include(<flashz.hpp>)
78
78
#pragma message "Using FlashZ as Update agent"
79
79
#include < flashz.hpp>
80
- #define F_Update FlashZ::getInstance ()
80
+ #define F_Compression " zlib "
81
81
#define F_hasZlib () true
82
- #define F_isZlibStream () (_stream->peek () == ZLIB_HEADER && ((partition == U_SPIFFS && _flashFileSystemUrl.indexOf(" zz" )>-1) || (partition == U_FLASH && _firmwareUrl.indexOf(" zz" )>-1)))
83
- #define F_canBegin () (mode_z ? F_Update.beginz(UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin(updateSize, partition))
82
+ #define F_Update FlashZ::getInstance ()
84
83
#define F_UpdateEnd () (mode_z ? F_Update.endz() : F_Update.end())
85
84
#define F_abort () if (mode_z) F_Update.abortz(); else F_Update.abort()
86
85
#define F_writeStream () (mode_z ? F_Update.writezStream(*_stream, updateSize) : F_Update.writeStream(*_stream))
86
+ // #define DEBUG_ESP32_FLASHZ
87
+ #if !defined DEBUG_ESP32_FLASHZ
88
+ #define F_isZlibStream () (_stream->peek () == ZLIB_HEADER && ((partition == U_SPIFFS && _flashFileSystemUrl.indexOf(" zz" )>-1) || (partition == U_FLASH && _firmwareUrl.indexOf(" zz" )>-1)))
89
+ #define F_canBegin () (mode_z ? F_Update.beginz(UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin(updateSize, partition))
90
+ #else
91
+ __attribute__ ((unused)) static bool F_canBegin_cb(bool mode_z, int updateSize, int partition) { // implement debug here
92
+ return (mode_z ? F_Update.beginz (UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin (updateSize, partition));
93
+ }
94
+ __attribute__ ((unused)) static bool F_isZlibStream_cb( Stream* stream, int partition, String flashFileSystemUrl, String firmwareUrl ) { // implement debug here
95
+ return (stream->peek () == ZLIB_HEADER && ((partition == U_SPIFFS && flashFileSystemUrl.indexOf (" zz" )>-1 ) || (partition == U_FLASH && firmwareUrl.indexOf (" zz" )>-1 )));
96
+ }
97
+ #define F_isZlibStream () F_isZlibStream_cb( _stream, partition, _flashFileSystemUrl, _firmwareUrl )
98
+ #define F_canBegin () F_canBegin_cb(mode_z, updateSize, partition)
99
+ #endif
100
+
87
101
#elif __has_include("ESP32-targz.h")
88
102
#pragma message "Using GzUpdateClass as Update agent"
89
103
#include < ESP32-targz.h>
90
- #define F_Update GzUpdateClass::getInstance ()
104
+ #define F_Compression " gzip "
91
105
#define F_hasZlib () true
92
- #define F_isZlibStream () (_stream->peek () == 0x1f && ((partition == U_SPIFFS && _flashFileSystemUrl.indexOf(" gz" )>-1) || (partition == U_FLASH && _firmwareUrl.indexOf(" gz" )>-1)) )
93
- #define F_canBegin () (mode_z ? F_Update.begingz(UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin(updateSize, partition))
106
+ #define F_Update GzUpdateClass::getInstance ()
94
107
#define F_UpdateEnd () (mode_z ? F_Update.endgz() : F_Update.end())
95
108
#define F_abort () if (mode_z) F_Update.abortgz(); else F_Update.abort()
96
109
#define F_writeStream () (mode_z ? F_Update.writeGzStream(*_stream, updateSize) : F_Update.writeStream(*_stream))
110
+ // #define DEBUG_ESP32_TARGZ
111
+ #if !defined DEBUG_ESP32_TARGZ
112
+ #define F_isZlibStream () (_stream->peek () == 0x1f && ((partition == U_SPIFFS && _flashFileSystemUrl.indexOf(" gz" )>-1) || (partition == U_FLASH && _firmwareUrl.indexOf(" gz" )>-1)) )
113
+ #define F_canBegin () (mode_z ? F_Update.begingz(UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin(updateSize, partition))
114
+ #else
115
+ __attribute__ ((unused)) static bool F_canBegin_cb(bool mode_z, int updateSize, int partition) { // implement debug here
116
+ return (mode_z ? F_Update.begingz (UPDATE_SIZE_UNKNOWN, partition) : F_Update.begin (updateSize, partition));
117
+ }
118
+ __attribute__ ((unused)) static bool F_isZlibStream_cb( Stream* stream, int partition, String flashFileSystemUrl, String firmwareUrl ) { // implement debug here
119
+ return (stream->peek () == 0x1f && ((partition == U_SPIFFS && flashFileSystemUrl.indexOf (" gz" )>-1 ) || (partition == U_FLASH && firmwareUrl.indexOf (" gz" )>-1 )) );
120
+ }
121
+ #define F_isZlibStream () F_isZlibStream_cb( _stream, partition, _flashFileSystemUrl, _firmwareUrl )
122
+ #define F_canBegin () F_canBegin_cb(mode_z, updateSize, partition)
123
+ #endif
97
124
#else
98
125
#include < Update.h>
126
+ #define F_Compression " none"
99
127
#define F_Update Update
100
128
#define F_hasZlib () false
101
129
#define F_isZlibStream () false
@@ -259,6 +287,7 @@ class esp32FOTA
259
287
260
288
// updating from a File or from Serial?
261
289
void setStreamType ( FOTAStreamType_t stream_type ) { _stream_type = stream_type; }
290
+ void setStreamTimeout ( uint32_t timeout ) { _stream_timeout = timeout; }
262
291
263
292
const char * getManifestURL () { return _manifestUrl.c_str (); }
264
293
const char * getFirmwareURL () { return _firmwareUrl.c_str (); }
@@ -296,6 +325,7 @@ class esp32FOTA
296
325
bool mode_z = F_hasZlib();
297
326
298
327
FOTAStreamType_t _stream_type = FOTA_HTTP_STREAM; // defaults to HTTP
328
+ uint32_t _stream_timeout = 10000 ; // max wait for stream->available()
299
329
300
330
void setupStream ();
301
331
void stopStream ();
0 commit comments