mirror of https://github.com/arendst/Tasmota.git
Merge pull request #8632 from Staars/unishox
unify USE_*_COMPRESSION to USE_UNISHOX_COMPRESSION
This commit is contained in:
commit
54ab26439e
|
@ -394,12 +394,14 @@
|
|||
// -- Ping ----------------------------------------
|
||||
// #define USE_PING // Enable Ping command (+2k code)
|
||||
|
||||
#define USE_UNISHOX_COMPRESSION // add support for string compression for RULES or SCRIPT
|
||||
|
||||
// -- Rules or Script ----------------------------
|
||||
// Select none or only one of the below defines USE_RULES or USE_SCRIPT
|
||||
#define USE_RULES // Add support for rules (+8k code)
|
||||
#define USE_RULES_COMPRESSION // Compresses rules in Flash at about ~50% (+3.3k code)
|
||||
// with USE_UNISHOX_COMPRESSION // Compresses rules in Flash at about ~50% (+3.3k code)
|
||||
//#define USE_SCRIPT // Add support for script (+17k code)
|
||||
#define USE_SCRIPT_COMPRESSION
|
||||
// supports USE_UNISHOX_COMPRESSION
|
||||
//#define USE_SCRIPT_FATFS 4 // Script: Add FAT FileSystem Support
|
||||
|
||||
// #define USE_EXPRESSION // Add support for expression evaluation in rules (+3k2 code, +64 bytes mem)
|
||||
|
|
|
@ -1882,7 +1882,7 @@ void AddLogBufferSize(uint32_t loglevel, uint8_t *buffer, uint32_t count, uint32
|
|||
* Uncompress static PROGMEM strings
|
||||
\*********************************************************************************************/
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
|
||||
#include <unishox.h>
|
||||
|
||||
|
@ -1908,4 +1908,4 @@ String Decompress(const char * compressed, size_t uncompressed_size) {
|
|||
return content;
|
||||
}
|
||||
|
||||
#endif // defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
|
@ -210,15 +210,15 @@ char rules_vars[MAX_RULE_VARS][33] = {{ 0 }};
|
|||
*/
|
||||
/*******************************************************************************************/
|
||||
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
// Statically allocate one String per rule
|
||||
String k_rules[MAX_RULE_SETS] = { String(), String(), String() }; // Strings are created empty
|
||||
// Unishox compressor; // singleton
|
||||
#endif // USE_RULES_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
// Returns whether the rule is uncompressed, which means the first byte is not NULL
|
||||
inline bool IsRuleUncompressed(uint32_t idx) {
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
return Settings.rules[idx][0] ? true : false; // first byte not NULL, the rule is not empty and not compressed
|
||||
#else
|
||||
return true;
|
||||
|
@ -227,7 +227,7 @@ inline bool IsRuleUncompressed(uint32_t idx) {
|
|||
|
||||
// Returns whether the rule is empty, which requires two consecutive NULL
|
||||
inline bool IsRuleEmpty(uint32_t idx) {
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
return (Settings.rules[idx][0] == 0) && (Settings.rules[idx][1] == 0) ? true : false;
|
||||
#else
|
||||
return (Settings.rules[idx][0] == 0) ? true : false;
|
||||
|
@ -236,7 +236,7 @@ inline bool IsRuleEmpty(uint32_t idx) {
|
|||
|
||||
// Returns the approximate (+3-0) length of the rule, not counting the trailing NULL
|
||||
size_t GetRuleLen(uint32_t idx) {
|
||||
// no need to use #ifdef USE_RULES_COMPRESSION, the compiler will optimize since first test is always true
|
||||
// no need to use #ifdef USE_UNISHOX_COMPRESSION, the compiler will optimize since first test is always true
|
||||
if (IsRuleUncompressed(idx)) {
|
||||
return strlen(Settings.rules[idx]);
|
||||
} else { // either empty or compressed
|
||||
|
@ -246,7 +246,7 @@ size_t GetRuleLen(uint32_t idx) {
|
|||
|
||||
// Returns the actual Flash storage for the Rule, including trailing NULL
|
||||
size_t GetRuleLenStorage(uint32_t idx) {
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
if (Settings.rules[idx][0] || !Settings.rules[idx][1]) { // if first byte is non-NULL it is uncompressed, if second byte is NULL, then it's either uncompressed or empty
|
||||
return 1 + strlen(Settings.rules[idx]); // uncompressed or empty
|
||||
} else {
|
||||
|
@ -257,7 +257,7 @@ size_t GetRuleLenStorage(uint32_t idx) {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
// internal function, do the actual decompression
|
||||
void GetRule_decompress(String &rule, const char *rule_head) {
|
||||
size_t buf_len = 1 + *rule_head * 8; // the first byte contains size of buffer for uncompressed rule / 8, buf_len may overshoot by 7
|
||||
|
@ -265,7 +265,7 @@ void GetRule_decompress(String &rule, const char *rule_head) {
|
|||
|
||||
rule = Decompress(rule_head, buf_len);
|
||||
}
|
||||
#endif // USE_RULES_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
//
|
||||
// Read rule in memory, uncompress if needed
|
||||
|
@ -275,7 +275,7 @@ String GetRule(uint32_t idx) {
|
|||
if (IsRuleUncompressed(idx)) {
|
||||
return String(Settings.rules[idx]);
|
||||
} else {
|
||||
#ifdef USE_RULES_COMPRESSION // we still do #ifdef to make sure we don't link unnecessary code
|
||||
#ifdef USE_UNISHOX_COMPRESSION // we still do #ifdef to make sure we don't link unnecessary code
|
||||
|
||||
String rule("");
|
||||
if (Settings.rules[idx][1] == 0) { return rule; } // the rule is empty
|
||||
|
@ -295,7 +295,7 @@ String GetRule(uint32_t idx) {
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
// internal function, comrpess rule and store a cached version uncompressed (except if SetOption94 1)
|
||||
// If out == nullptr, we are in dry-run mode, so don't keep rule in cache
|
||||
int32_t SetRule_compress(uint32_t idx, const char *in, size_t in_len, char *out, size_t out_len) {
|
||||
|
@ -312,7 +312,7 @@ int32_t SetRule_compress(uint32_t idx, const char *in, size_t in_len, char *out,
|
|||
}
|
||||
return len_compressed;
|
||||
}
|
||||
#endif // USE_RULES_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
// Returns:
|
||||
// >= 0 : the actual stored size
|
||||
|
@ -343,7 +343,7 @@ int32_t SetRule(uint32_t idx, const char *content, bool append = false) {
|
|||
Settings.rules[idx][1] = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
if (0 != len_in + offset) {
|
||||
// do a dry-run compression to display how much it would be compressed
|
||||
int32_t len_compressed, len_uncompressed;
|
||||
|
@ -353,11 +353,11 @@ int32_t SetRule(uint32_t idx, const char *content, bool append = false) {
|
|||
AddLog_P2(LOG_LEVEL_INFO, PSTR("RUL: Stored uncompressed, would compress from %d to %d (-%d%%)"), len_uncompressed, len_compressed, 100 - changeUIntScale(len_compressed, 0, len_uncompressed, 0, 100));
|
||||
}
|
||||
|
||||
#endif // USE_RULES_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
return len_in + offset;
|
||||
} else {
|
||||
#ifdef USE_RULES_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
int32_t len_compressed;
|
||||
// allocate temp buffer so we don't nuke the rule if it's too big to fit
|
||||
char *buf_out = (char*) malloc(MAX_RULE_SIZE + 8); // take some margin
|
||||
|
@ -390,9 +390,9 @@ int32_t SetRule(uint32_t idx, const char *content, bool append = false) {
|
|||
free(buf_out);
|
||||
return len_compressed;
|
||||
|
||||
#else // USE_RULES_COMPRESSION
|
||||
#else // USE_UNISHOX_COMPRESSION
|
||||
return -1; // the rule does not fit and we can't compress
|
||||
#endif // USE_RULES_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ uint32_t DecodeLightId(uint32_t hue_id);
|
|||
#ifdef USE_SCRIPT_FATFS
|
||||
#undef LITTLEFS_SCRIPT_SIZE
|
||||
#undef EEP_SCRIPT_SIZE
|
||||
#undef USE_SCRIPT_COMPRESSION
|
||||
#undef USE_UNISHOX_COMPRESSION
|
||||
#if USE_SCRIPT_FATFS==-1
|
||||
#ifdef ESP32
|
||||
#error "script fat file option -1 currently not supported for ESP32"
|
||||
|
@ -88,13 +88,13 @@ uint32_t DecodeLightId(uint32_t hue_id);
|
|||
// lfs on esp8266 spiffs on esp32
|
||||
#ifdef LITTLEFS_SCRIPT_SIZE
|
||||
#undef EEP_SCRIPT_SIZE
|
||||
#undef USE_SCRIPT_COMPRESSION
|
||||
#undef USE_UNISHOX_COMPRESSION
|
||||
#pragma message "script little file system option used"
|
||||
#endif // LITTLEFS_SCRIPT_SIZE
|
||||
|
||||
// eeprom script
|
||||
#ifdef EEP_SCRIPT_SIZE
|
||||
#undef USE_SCRIPT_COMPRESSION
|
||||
#undef USE_UNISHOX_COMPRESSION
|
||||
#ifdef USE_24C256
|
||||
#pragma message "script 24c256 file option used"
|
||||
#else
|
||||
|
@ -104,12 +104,12 @@ uint32_t DecodeLightId(uint32_t hue_id);
|
|||
#endif // EEP_SCRIPT_SIZE
|
||||
|
||||
// compression last option before default
|
||||
#ifdef USE_SCRIPT_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
#pragma message "script compression option used"
|
||||
#endif // USE_SCRIPT_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
|
||||
#ifdef USE_SCRIPT_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
#include <unishox.h>
|
||||
|
||||
#define SCRIPT_COMPRESS compressor.unishox_compress
|
||||
|
@ -117,7 +117,7 @@ uint32_t DecodeLightId(uint32_t hue_id);
|
|||
#ifndef UNISHOXRSIZE
|
||||
#define UNISHOXRSIZE 2560
|
||||
#endif
|
||||
#endif // USE_SCRIPT_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
|
||||
#if defined(LITTLEFS_SCRIPT_SIZE) || (USE_SCRIPT_FATFS==-1)
|
||||
|
@ -4178,7 +4178,7 @@ void ScriptSaveSettings(void) {
|
|||
glob_script_mem.script_mem_size=0;
|
||||
}
|
||||
|
||||
#ifdef USE_SCRIPT_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
//AddLog_P2(LOG_LEVEL_INFO,PSTR("in string: %s len = %d"),glob_script_mem.script_ram,strlen(glob_script_mem.script_ram));
|
||||
uint32_t len_compressed = SCRIPT_COMPRESS(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram), Settings.rules[0], MAX_SCRIPT_SIZE-1);
|
||||
if (len_compressed > 0) {
|
||||
|
@ -4187,7 +4187,7 @@ void ScriptSaveSettings(void) {
|
|||
} else {
|
||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed);
|
||||
}
|
||||
#endif // USE_SCRIPT_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
if (bitRead(Settings.rule_enabled, 0)) {
|
||||
int16_t res=Init_Scripter();
|
||||
|
@ -5830,7 +5830,7 @@ bool Xdrv10(uint8_t function)
|
|||
glob_script_mem.script_pram=(uint8_t*)Settings.script_pram[0];
|
||||
glob_script_mem.script_pram_size=PMEM_SIZE;
|
||||
|
||||
#ifdef USE_SCRIPT_COMPRESSION
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
int32_t len_decompressed;
|
||||
sprt=(char*)calloc(UNISHOXRSIZE+8,1);
|
||||
if (!sprt) { break; }
|
||||
|
@ -5839,7 +5839,7 @@ bool Xdrv10(uint8_t function)
|
|||
len_decompressed = SCRIPT_DECOMPRESS(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, glob_script_mem.script_size);
|
||||
if (len_decompressed>0) glob_script_mem.script_ram[len_decompressed]=0;
|
||||
//AddLog_P2(LOG_LEVEL_INFO, PSTR("decompressed script len %d"),len_decompressed);
|
||||
#endif // USE_SCRIPT_COMPRESSION
|
||||
#endif // USE_UNISHOX_COMPRESSION
|
||||
|
||||
#ifdef USE_BUTTON_EVENT
|
||||
for (uint32_t cnt=0;cnt<MAX_KEYS;cnt++) {
|
||||
|
|
|
@ -85,7 +85,7 @@ void WemoRespondToMSearch(int echo_type)
|
|||
* Wemo web server additions
|
||||
\*********************************************************************************************/
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
|
||||
//<scpd xmlns="urn:Belkin:service-1-0"><actionList><action><name>SetBinaryState</name><argumentList><argument><retval/><name>BinaryState</name><relatedStateVariable>BinaryState</relatedStateVariable><direction>in</direction></argument></argumentList></action><action><name>GetBinaryState</name><argumentList><argument><retval/><name>BinaryState</name><relatedStateVariable>BinaryState</relatedStateVariable><direction>out</direction></argument></argumentList></action></actionList><serviceStateTable><stateVariable sendEvents="yes"><name>BinaryState</name><dataType>bool</dataType><defaultValue>0</defaultValue></stateVariable><stateVariable sendEvents="yes"><name>level</name><dataType>string</dataType><defaultValue>0</defaultValue></stateVariable></serviceStateTable></scpd>\r\n\r\n
|
||||
//Successfully compressed from 779 to 249 bytes (-68%)
|
||||
|
@ -293,7 +293,7 @@ void HandleUpnpEvent(void)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
snprintf_P(event, sizeof(event), Decompress(WEMO_RESPONSE_STATE_SOAP, WEMO_RESPONSE_STATE_SOAP_SIZE).c_str(), state, bitRead(power, devices_present -1), state);
|
||||
#else
|
||||
snprintf_P(event, sizeof(event), WEMO_RESPONSE_STATE_SOAP, state, bitRead(power, devices_present -1), state);
|
||||
|
@ -305,7 +305,7 @@ void HandleUpnpService(void)
|
|||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_EVENT_SERVICE));
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
WSSend(200, CT_PLAIN, Decompress(WEMO_EVENTSERVICE_XML, WEMO_EVENTSERVICE_XML_SIZE));
|
||||
#else
|
||||
WSSend(200, CT_PLAIN, FPSTR(WEMO_EVENTSERVICE_XML));
|
||||
|
@ -316,7 +316,7 @@ void HandleUpnpMetaService(void)
|
|||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_META_SERVICE));
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
WSSend(200, CT_PLAIN, Decompress(WEMO_METASERVICE_XML, WEMO_METASERVICE_XML_SIZE));
|
||||
#else
|
||||
WSSend(200, CT_PLAIN, FPSTR(WEMO_METASERVICE_XML));
|
||||
|
@ -327,7 +327,7 @@ void HandleUpnpSetupWemo(void)
|
|||
{
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_SETUP));
|
||||
|
||||
#if defined(USE_RULES_COMPRESSION) || defined(USE_SCRIPT_COMPRESSION)
|
||||
#ifdef USE_UNISHOX_COMPRESSION
|
||||
String setup_xml = Decompress(WEMO_SETUP_XML, WEMO_SETUP_XML_SIZE);
|
||||
#else
|
||||
String setup_xml = FPSTR(WEMO_SETUP_XML);
|
||||
|
|
Loading…
Reference in New Issue