mirror of https://github.com/arendst/Tasmota.git
Added macro for SO synonyms and MQTT
This commit is contained in:
parent
a6217c2b7c
commit
a436dd416d
|
@ -349,7 +349,11 @@
|
|||
#define D_CMND_CPU_FREQUENCY "CpuFrequency"
|
||||
#endif // ESP32
|
||||
|
||||
// Commands xdrv_01_mqtt.ino
|
||||
// Commands xdrv_02_mqtt.ino
|
||||
#define D_SO_MQTTJSONONLY "MqttJSONOnly"
|
||||
#define D_SO_MQTTTLS "MqttTLS"
|
||||
#define D_SO_MQTTNORETAIN "MqttNoRetain"
|
||||
#define D_SO_MQTTDETACHRELAY "MqttDetachRelay"
|
||||
#define D_CMND_MQTTLOG "MqttLog"
|
||||
#define D_CMND_MQTTHOST "MqttHost"
|
||||
#define D_CMND_MQTTPORT "MqttPort"
|
||||
|
@ -375,7 +379,7 @@
|
|||
#define D_CMND_SENSORRETAIN "SensorRetain"
|
||||
#define D_CMND_PUBLISH "Publish"
|
||||
|
||||
// Commands xdrv_02_webserver.ino
|
||||
// Commands xdrv_01_webserver.ino
|
||||
#define D_CMND_WEBSERVER "Webserver"
|
||||
#define D_JSON_WEBSERVER_MODE "WebServerMode"
|
||||
#define D_JSON_ACTIVE_FOR "Active for"
|
||||
|
|
|
@ -472,6 +472,43 @@ bool first_device_group_is_local = true;
|
|||
#define DEBUG_TRACE_LOG(...)
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Macro for SetOption synonyms
|
||||
*
|
||||
* SetOption synonyms come first in the list of commands, right after the prefix.
|
||||
* They don't need any matching function pointer, since they are handled internally.
|
||||
* So don't forget to NOT put pointers in the functions pointers list.
|
||||
*
|
||||
* The additionnal list of unsigned bytes contains the Option numbers of each synonyms
|
||||
* in the same order. The first byte of the list contains the number of synonyms
|
||||
* (not including the number itself). The is the number of names to skip to find the first command.
|
||||
*
|
||||
* As it si cumbersome to calculate the first byte (number of synonyms), we provide the following
|
||||
* macro `SO_SYNONYMS(<name>, <list of bytes>)`
|
||||
*
|
||||
* For example:
|
||||
* ```
|
||||
* SO_SYNONYMS(kLightSynonyms,
|
||||
* 37, 68, 82, 91, 92, 105,
|
||||
* 106,
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* is equivalent to:
|
||||
* ```
|
||||
* const static uint8_t kLightSynonyms[] PROGMEM = {
|
||||
* 7, // number of synonyms, automatically calculated
|
||||
* 37, 68, 82, 91, 92, 105,
|
||||
* 106,
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* This comes very handy if you need to adjust the number of synonyms depending on #defines
|
||||
\*********************************************************************************************/
|
||||
|
||||
#define SO_SYNONYMS(N,...) const static uint8_t __syn_array_len_ ## N[] = { __VA_ARGS__ }; /* this first array will not be kept by linker, just used for sizeof() */ const static uint8_t N[] PROGMEM = { sizeof(__syn_array_len_ ## N), __VA_ARGS__ };
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
#endif // _TASMOTA_GLOBALS_H_
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
WiFiClient EspClient; // Wifi Client - non-TLS
|
||||
|
||||
const char kMqttCommands[] PROGMEM = "|" // No prefix
|
||||
// SetOption synonyms
|
||||
D_SO_MQTTJSONONLY "|"
|
||||
#ifdef USE_MQTT_TLS
|
||||
D_SO_MQTTTLS "|"
|
||||
#endif
|
||||
D_SO_MQTTNORETAIN "|" D_SO_MQTTDETACHRELAY "|"
|
||||
// regular commands
|
||||
#if defined(USE_MQTT_TLS) && !defined(USE_MQTT_TLS_CA_CERT)
|
||||
D_CMND_MQTTFINGERPRINT "|"
|
||||
#endif
|
||||
|
@ -43,6 +50,19 @@ const char kMqttCommands[] PROGMEM = "|" // No prefix
|
|||
D_CMND_FULLTOPIC "|" D_CMND_PREFIX "|" D_CMND_GROUPTOPIC "|" D_CMND_TOPIC "|" D_CMND_PUBLISH "|" D_CMND_MQTTLOG "|"
|
||||
D_CMND_BUTTONTOPIC "|" D_CMND_SWITCHTOPIC "|" D_CMND_BUTTONRETAIN "|" D_CMND_SWITCHRETAIN "|" D_CMND_POWERRETAIN "|" D_CMND_SENSORRETAIN ;
|
||||
|
||||
SO_SYNONYMS(kMqttSynonyms,
|
||||
90,
|
||||
#ifdef USE_MQTT_TLS
|
||||
103,
|
||||
#endif
|
||||
104, 114
|
||||
);
|
||||
|
||||
// const uint8_t kMqttSynonyms[] PROGMEM = {
|
||||
// 4, // number of synonyms
|
||||
// 90, 103, 104, 114,
|
||||
// };
|
||||
|
||||
void (* const MqttCommand[])(void) PROGMEM = {
|
||||
#if defined(USE_MQTT_TLS) && !defined(USE_MQTT_TLS_CA_CERT)
|
||||
&CmndMqttFingerprint,
|
||||
|
@ -1353,7 +1373,7 @@ bool Xdrv02(uint8_t function)
|
|||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
case FUNC_COMMAND:
|
||||
result = DecodeCommand(kMqttCommands, MqttCommand);
|
||||
result = DecodeCommand(kMqttCommands, MqttCommand, kMqttSynonyms);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -148,11 +148,10 @@ const char kLightCommands[] PROGMEM = "|" // No prefix
|
|||
#endif // USE_DGR_LIGHT_SEQUENCE
|
||||
"|UNDOCA" ;
|
||||
|
||||
const uint8_t kLightSynonyms[] PROGMEM = {
|
||||
7, // number of entries
|
||||
SO_SYNONYMS(kLightSynonyms,
|
||||
37, 68, 82, 91, 92,
|
||||
105, 106,
|
||||
};
|
||||
);
|
||||
|
||||
void (* const LightCommand[])(void) PROGMEM = {
|
||||
&CmndColor, &CmndColorTemperature, &CmndDimmer, &CmndDimmerRange, &CmndDimmerStep, &CmndLedTable, &CmndFade,
|
||||
|
|
|
@ -42,11 +42,10 @@ const char kZbCommands[] PROGMEM = D_PRFX_ZB "|" // prefix
|
|||
D_CMND_ZIGBEE_CONFIG "|" D_CMND_ZIGBEE_DATA
|
||||
;
|
||||
|
||||
const uint8_t kZbSynonyms[] PROGMEM = {
|
||||
6, // number of synonyms
|
||||
SO_SYNONYMS(kZbSynonyms,
|
||||
83, 89, 100, 101, 110,
|
||||
112,
|
||||
};
|
||||
112,
|
||||
);
|
||||
|
||||
void (* const ZigbeeCommand[])(void) PROGMEM = {
|
||||
#ifdef USE_ZIGBEE_ZNP
|
||||
|
|
Loading…
Reference in New Issue