mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 15:27:17 +00:00
Fix 32 device issue
This commit is contained in:
parent
e6cafcfa42
commit
202f83b4ff
@ -255,27 +255,25 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len)
|
||||
}
|
||||
}
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CMD: Grp %d, Cmnd '%s', Idx %d, Len %d, Data '%s'"),
|
||||
grpflg, type, index, data_len, (binary_data) ? HexToString((uint8_t*)dataBuf, data_len).c_str() : dataBuf);
|
||||
int32_t payload = -99;
|
||||
if (!binary_data) {
|
||||
if (!strcmp(dataBuf,"?")) { data_len = 0; }
|
||||
|
||||
char *p;
|
||||
payload = strtol(dataBuf, &p, 0); // decimal, octal (0) or hex (0x)
|
||||
if (p == dataBuf) { payload = -99; }
|
||||
int temp_payload = GetStateNumber(dataBuf);
|
||||
if (temp_payload > -1) { payload = temp_payload; }
|
||||
}
|
||||
|
||||
AddLog(LOG_LEVEL_DEBUG, PSTR("CMD: Grp %d, Cmd '%s', Idx %d, Len %d, Pld %d, Data '%s'"),
|
||||
grpflg, type, index, data_len, payload, (binary_data) ? HexToString((uint8_t*)dataBuf, data_len).c_str() : dataBuf);
|
||||
|
||||
if (type != nullptr) {
|
||||
Response_P(PSTR("{\"" D_JSON_COMMAND "\":\"" D_JSON_ERROR "\"}"));
|
||||
|
||||
if (Settings->ledstate &0x02) { TasmotaGlobal.blinks++; }
|
||||
|
||||
int32_t payload = -99;
|
||||
if (!binary_data) {
|
||||
if (!strcmp(dataBuf,"?")) { data_len = 0; }
|
||||
|
||||
char *p;
|
||||
payload = strtol(dataBuf, &p, 0); // decimal, octal (0) or hex (0x)
|
||||
if (p == dataBuf) { payload = -99; }
|
||||
int temp_payload = GetStateNumber(dataBuf);
|
||||
if (temp_payload > -1) { payload = temp_payload; }
|
||||
}
|
||||
|
||||
DEBUG_CORE_LOG(PSTR("CMD: Payload %d"), payload);
|
||||
|
||||
// TasmotaGlobal.backlog_timer = millis() + (100 * MIN_BACKLOG_DELAY);
|
||||
TasmotaGlobal.backlog_timer = millis() + Settings->param[P_BACKLOG_DELAY]; // SetOption34
|
||||
|
||||
|
@ -246,7 +246,7 @@ void SetDevicePower(power_t rpower, uint32_t source)
|
||||
TasmotaGlobal.last_source = source;
|
||||
|
||||
if (POWER_ALL_ALWAYS_ON == Settings->poweronstate) { // All on and stay on
|
||||
TasmotaGlobal.power = (1 << TasmotaGlobal.devices_present) -1;
|
||||
TasmotaGlobal.power = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present);
|
||||
rpower = TasmotaGlobal.power;
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ void SetAllPower(uint32_t state, uint32_t source)
|
||||
publish_power = false;
|
||||
}
|
||||
if ((state >= POWER_OFF) && (state <= POWER_TOGGLE)) {
|
||||
power_t all_on = (1 << TasmotaGlobal.devices_present) -1;
|
||||
power_t all_on = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present);
|
||||
switch (state) {
|
||||
case POWER_OFF:
|
||||
TasmotaGlobal.power = 0;
|
||||
@ -365,6 +365,7 @@ void SetPowerOnState(void)
|
||||
if (POWER_ALL_ALWAYS_ON == Settings->poweronstate) {
|
||||
SetDevicePower(1, SRC_RESTART);
|
||||
} else {
|
||||
power_t devices_mask = POWER_MASK >> (POWER_SIZE - TasmotaGlobal.devices_present);
|
||||
if ((ResetReason() == REASON_DEFAULT_RST) || (ResetReason() == REASON_EXT_SYS_RST)) {
|
||||
switch (Settings->poweronstate) {
|
||||
case POWER_ALL_OFF:
|
||||
@ -373,24 +374,24 @@ void SetPowerOnState(void)
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
break;
|
||||
case POWER_ALL_ON: // All on
|
||||
TasmotaGlobal.power = (1 << TasmotaGlobal.devices_present) -1;
|
||||
TasmotaGlobal.power = devices_mask;
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
break;
|
||||
case POWER_ALL_SAVED_TOGGLE:
|
||||
TasmotaGlobal.power = (Settings->power & ((1 << TasmotaGlobal.devices_present) -1)) ^ POWER_MASK;
|
||||
TasmotaGlobal.power = (Settings->power & devices_mask) ^ POWER_MASK;
|
||||
if (Settings->flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
case POWER_ALL_SAVED:
|
||||
TasmotaGlobal.power = Settings->power & ((1 << TasmotaGlobal.devices_present) -1);
|
||||
TasmotaGlobal.power = Settings->power & devices_mask;
|
||||
if (Settings->flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
TasmotaGlobal.power = Settings->power & ((1 << TasmotaGlobal.devices_present) -1);
|
||||
TasmotaGlobal.power = Settings->power & devices_mask;
|
||||
if (Settings->flag.save_state) { // SetOption0 - Save power state and use after restart
|
||||
SetDevicePower(TasmotaGlobal.power, SRC_RESTART);
|
||||
}
|
||||
|
@ -37,8 +37,9 @@
|
||||
* Power Type
|
||||
\*********************************************************************************************/
|
||||
|
||||
typedef unsigned long power_t; // Power (Relay) type
|
||||
const uint32_t POWER_MASK = 0xffffffffUL; // Power (Relay) full mask
|
||||
typedef uint32_t power_t; // Power (Relay) type
|
||||
const uint32_t POWER_MASK = 0xFFFFFFFFUL; // Power (Relay) full mask
|
||||
const uint32_t POWER_SIZE = 32; // Power (relay) bit count
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Constants
|
||||
|
@ -257,8 +257,8 @@ typedef struct {
|
||||
uint8_t history_day[SSPM_MAX_MODULES][4];
|
||||
|
||||
#ifdef SSPM_SIMULATE
|
||||
uint8_t emulate;
|
||||
uint8_t emulated_module;
|
||||
uint8_t simulate;
|
||||
uint8_t simulated_module;
|
||||
#endif
|
||||
uint8_t allow_updates;
|
||||
uint8_t get_energy_relay;
|
||||
@ -398,8 +398,8 @@ uint32_t SSPMGetMappedModuleId(uint32_t module) {
|
||||
module_nr = module; // input module number if not found used as fallback
|
||||
}
|
||||
#ifdef SSPM_SIMULATE
|
||||
Sspm->emulated_module = module_nr;
|
||||
if (Sspm->emulate && (module_nr > 0) && (module_nr <= Sspm->emulate)) {
|
||||
Sspm->simulated_module = module_nr;
|
||||
if (Sspm->simulate && (module_nr > 0) && (module_nr <= Sspm->simulate)) {
|
||||
module_nr = 0; // Emulate modules by 0
|
||||
}
|
||||
#endif
|
||||
@ -1067,18 +1067,15 @@ void SSPMHandleReceivedData(void) {
|
||||
*/
|
||||
if (!status && (0x06 == expected_bytes)) {
|
||||
// SspmBuffer[20] & 0x0F // Relays operational
|
||||
power_t current_state = SspmBuffer[20] >> 4; // Relays state
|
||||
power_t mask = 0x0000000F;
|
||||
for (uint32_t i = 0; i < Sspm->module_max; i++) {
|
||||
uint32_t module = SSPMGetMappedModuleId(i);
|
||||
if ((SspmBuffer[3] == Sspm->module[module][0]) && (SspmBuffer[4] == Sspm->module[module][1])) {
|
||||
current_state <<= (i * 4);
|
||||
mask <<= (i * 4);
|
||||
TasmotaGlobal.power &= (POWER_MASK ^ mask);
|
||||
TasmotaGlobal.power |= current_state;
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[3] << 8 | SspmBuffer[4]);
|
||||
#ifdef SSPM_SIMULATE
|
||||
module = Sspm->simulated_module;
|
||||
#endif
|
||||
power_t current_state = (SspmBuffer[20] >> 4) << (module * 4); // Relays state
|
||||
power_t mask = 0x0000000F << (module * 4);
|
||||
TasmotaGlobal.power &= (POWER_MASK ^ mask);
|
||||
TasmotaGlobal.power |= current_state;
|
||||
|
||||
Sspm->old_power = TasmotaGlobal.power;
|
||||
TasmotaGlobal.devices_present += 4;
|
||||
}
|
||||
@ -1161,7 +1158,7 @@ void SSPMHandleReceivedData(void) {
|
||||
uint32_t channel = SspmBuffer[32];
|
||||
uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[20] << 8 | SspmBuffer[21]);
|
||||
#ifdef SSPM_SIMULATE
|
||||
module = Sspm->emulated_module;
|
||||
module = Sspm->simulated_module;
|
||||
#endif
|
||||
if (Sspm->history_relay < 255) {
|
||||
uint32_t history_module = Sspm->history_relay >> 2;
|
||||
@ -1344,7 +1341,7 @@ void SSPMHandleReceivedData(void) {
|
||||
}
|
||||
uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[19] << 8 | SspmBuffer[20]);
|
||||
#ifdef SSPM_SIMULATE
|
||||
module = Sspm->emulated_module;
|
||||
module = Sspm->simulated_module;
|
||||
#endif
|
||||
Sspm->current[module][channel] = SspmBuffer[32] + (float)SspmBuffer[33] / 100; // x.xxA
|
||||
Sspm->voltage[module][channel] = SSPMGetValue(&SspmBuffer[34]); // x.xxV
|
||||
@ -1368,16 +1365,13 @@ void SSPMHandleReceivedData(void) {
|
||||
aa 55 01 00 00 00 00 00 00 00 00 00 00 00 00 00 07 00 0d 8b 34 32 37 39 37 34 13 4b 35 36 37 02 2d bb 08 - L2 Overload triggered power off
|
||||
*/
|
||||
if (!Sspm->no_send_key) {
|
||||
power_t relay = SspmBuffer[31] & 0x0F; // Relays active
|
||||
power_t relay_state = SspmBuffer[31] >> 4; // Relays state
|
||||
for (uint32_t i = 0; i < Sspm->module_max; i++) {
|
||||
uint32_t module = SSPMGetMappedModuleId(i);
|
||||
if ((SspmBuffer[19] == Sspm->module[module][0]) && (SspmBuffer[20] == Sspm->module[module][1])) {
|
||||
relay <<= (i * 4);
|
||||
relay_state <<= (i * 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint32_t module = SSPMGetModuleNumberFromMap(SspmBuffer[19] << 8 | SspmBuffer[20]);
|
||||
#ifdef SSPM_SIMULATE
|
||||
// module = Sspm->simulated_module; // Won't work as this is initiated from device
|
||||
#endif
|
||||
power_t relay = (SspmBuffer[31] & 0x0F) << (module * 4); // Relays active
|
||||
power_t relay_state = (SspmBuffer[31] >> 4) << (module * 4); // Relays state
|
||||
|
||||
for (uint32_t i = 1; i <= TasmotaGlobal.devices_present; i++) {
|
||||
if (relay &1) {
|
||||
ExecuteCommandPower(i, relay_state &1, SRC_BUTTON);
|
||||
@ -1458,10 +1452,10 @@ void SSPMHandleReceivedData(void) {
|
||||
if (0x24 == expected_bytes) {
|
||||
SSPMAddModule();
|
||||
#ifdef SSPM_SIMULATE
|
||||
if (0 == Sspm->emulate) {
|
||||
if (0 == Sspm->simulate) {
|
||||
uint8_t current_idl = SspmBuffer[20];
|
||||
for (Sspm->emulate = 0; Sspm->emulate < SSPM_SIMULATE; Sspm->emulate++) {
|
||||
SspmBuffer[20] = Sspm->emulate +1;
|
||||
for (Sspm->simulate = 0; Sspm->simulate < SSPM_SIMULATE; Sspm->simulate++) {
|
||||
SspmBuffer[20] = Sspm->simulate +1;
|
||||
SSPMAddModule();
|
||||
}
|
||||
SspmBuffer[20] = current_idl;
|
||||
|
Loading…
x
Reference in New Issue
Block a user