From de0c39582f8cc0cc9775fb5e8c03b895103d818d Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Sat, 30 Dec 2023 18:14:56 +1000 Subject: [PATCH] don't send commands to the AC while reading data from the AC. (#20352) on some units it can take around 250ms to reply to a request, by which time we're shoving another command to the unit. if this happens, the unit gives up and starts replying to the new command, which can again take 250ms. in this situation effectively nothing gets through. avoid this by checking if we're in the parser state machine. this also gives us timeout handling. tested on 4 different AC units. one which was unusable before is now functioning as expected, and the other 3 appear just as functional as they were before. --- tasmota/tasmota_xdrv_driver/xdrv_44_miel_hvac.ino | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_44_miel_hvac.ino b/tasmota/tasmota_xdrv_driver/xdrv_44_miel_hvac.ino index 36baa3749..a51166ae6 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_44_miel_hvac.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_44_miel_hvac.ino @@ -329,6 +329,7 @@ enum miel_hvac_parser_state { struct miel_hvac_parser { enum miel_hvac_parser_state p_state; + uint8_t p_tmo; uint8_t p_type; uint8_t p_sum; uint8_t p_len; @@ -386,6 +387,7 @@ miel_hvac_parse(struct miel_hvac_softc *sc, uint8_t byte) /* reset state */ p->p_sum = 0; + p->p_tmo = 0; nstate = MIEL_HVAC_P_TYPE; break; @@ -1234,8 +1236,20 @@ miel_hvac_tick(struct miel_hvac_softc *sc) MIEL_HVAC_REQUEST_STAGE, }; + struct miel_hvac_parser *p = &sc->sc_parser; unsigned int i; + if (p->p_state != MIEL_HVAC_P_START) { + if (p->p_tmo) { + AddLog(LOG_LEVEL_DEBUG, PSTR(MIEL_HVAC_LOGNAME + ": read timeout")); + sc->sc_parser.p_state = MIEL_HVAC_P_START; + } else { + p->p_tmo = 1; + return; + } + } + if (miel_hvac_update_pending(sc)) { struct miel_hvac_msg_update *update = &sc->sc_update;