From 3b70f2c73f766d739903a665c3d904f27200c7aa Mon Sep 17 00:00:00 2001 From: Tcharp38 Date: Sun, 17 Mar 2024 21:12:25 +0100 Subject: [PATCH] Config on dev announce moved to AbeilleCmd --- core/class/AbeilleCmdQueue.class.php | 30 +++++++--- core/class/AbeilleParser.class.php | 86 ++++++++++++++-------------- core/php/AbeilleCmd.php | 1 - core/php/AbeilleParser.php | 16 ++++-- docs/fr_FR/Changelog.rst | 1 + 5 files changed, 75 insertions(+), 59 deletions(-) diff --git a/core/class/AbeilleCmdQueue.class.php b/core/class/AbeilleCmdQueue.class.php index ca9d8f073d..839003481c 100755 --- a/core/class/AbeilleCmdQueue.class.php +++ b/core/class/AbeilleCmdQueue.class.php @@ -671,6 +671,27 @@ function processAcksQueue() { cmdLog("debug", 'processAcks(): msg='.$msgJson); $msg = json_decode($msgJson, true); + + // Clear all pending messages for net/addr device. + // This is useful when short addr changed, due to (multiple) device announce, + // or device migrated to another network. + if ($msg['type'] == "shortAddrChange") { + $oldNet = $msg['oldNet']; + $newNet = $msg['newNet']; + $oldAddr = $msg['oldAddr']; + $newAddr = $msg['newAddr']; + cmdLog("debug", " shortAddrChange: ${oldNet}/${oldAddr} to ${newNet}/${newAddr}"); + // Remove any pending messages to be sent to old address + $zgId = substr($msg['oldNet'], 7); + clearPending($zgId, $msg['oldAddr']); + // Update local infos + if (isset($GLOBALS['devices'][$oldNet]) && isset($GLOBALS['devices'][$oldNet][$oldAddr])) { + $GLOBALS['devices'][$newNet][$newAddr] = $GLOBALS['devices'][$oldNet][$oldAddr]; + unset($GLOBALS['devices'][$oldNet][$oldAddr]); + } + continue; + } // End type=='shortAddrChange' + $zgId = substr($msg['net'], 7); $this->zgId = $zgId; @@ -713,15 +734,6 @@ function processAcksQueue() { continue; } - // Clear all pending messages for net/addr device. - // This is useful when short addr changed, due to (multiple) device announce, - // or device migrated to another network. - if ($msg['type'] == "clearMessages") { - cmdLog("debug", " clearMessages for ".$msg['net']."/".$msg['addr']); - clearPending($zgId, $msg['addr']); - continue; - } // End type=='clearMessages' - // PDM restore response (Abeille's ABxx-yyyy specific FW) if ($msg['type'] == "AB03") { cmdLog("debug", " AB03 msg: ID=".$msg['id'].", Status=".$msg['status']); diff --git a/core/class/AbeilleParser.class.php b/core/class/AbeilleParser.class.php index 230d693467..cd2a8a8dc9 100755 --- a/core/class/AbeilleParser.class.php +++ b/core/class/AbeilleParser.class.php @@ -175,7 +175,8 @@ function checkNpdu($net, $nPdu) { /* Send message to 'AbeilleCmd' thru 'xToCmd' queue */ function msgToCmd2($prio, $msg) { $errCode = 0; - if (msg_send($this->queueXToCmd, 1, json_encode($msg, JSON_UNESCAPED_SLASHES), false, false, $errCode) == false) { + $msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES); + if (msg_send($this->queueXToCmd, 1, $msgJson, false, false, $errCode) == false) { parserLog("debug", " ERROR: msgToCmd2(): Can't write to 'queueXToCmd', error=".$errCode); } } @@ -860,51 +861,50 @@ function deviceConfigure($net, $addr) { $msg['modelPath'] = $eq['modelPath']; msgToAbeille2($msg); - // TODO - // $msg = array( - // 'type' => 'configureDevice', - // 'net' => $net, - // 'addr' => $addr - // ); - // $this->msgToCmd2(PRIO_NORM, $msg); - if (!isset($eqModel['commands'])) { - parserLog('debug', " No cmds in JSON model."); - // return; + parserLog('debug', " No cmds for configuration in JSON model."); } else { - $cmds = $eqModel['commands']; - - parserLog('debug', " cmds=".json_encode($cmds)); - foreach ($cmds as $cmdJName => $cmd) { - if (!isset($cmd['configuration'])) - continue; // No 'configuration' section then no 'execAtCreation' - $c = $cmd['configuration']; - if (!isset($c['execAtCreation'])) - continue; + parserLog('debug', " Requesting device configuration."); + $msg = array( + 'type' => 'configureDevice', + 'net' => $net, + 'addr' => $addr + ); + $this->msgToCmd2(PRIO_NORM, $msg); - if (isset($c['execAtCreationDelay'])) - $delay = $c['execAtCreationDelay']; - else - $delay = 0; - parserLog('debug', " exec cmd '".$cmdJName."' with delay ".$delay); - $topic = $c['topic']; - $request = $c['request']; - // TODO: #EP# defaulted to first EP but should be - // defined in cmd use if different target EP - // $request = str_ireplace('#EP#', $eq['epFirst'], $request); - $request = str_ireplace('#EP#', $eq['mainEp'], $request); - $request = str_ireplace('#addrIEEE#', $eq['ieee'], $request); - $request = str_ireplace('#IEEE#', $eq['ieee'], $request); - $zgId = substr($net, 7); // 'AbeilleX' => 'X' - $request = str_ireplace('#ZiGateIEEE#', $GLOBALS['zigate'.$zgId]['ieee'], $request); - parserLog('debug', ' topic='.$topic.", request='".$request."'"); - if ($delay == 0) - msgToCmd(PRIO_NORM, "Cmd".$net."/".$addr."/".$topic, $request); - else { - $delay = time() + $delay; - msgToCmd(PRIO_NORM, "TempoCmd".$net."/".$addr."/".$topic.'&time='.$delay, $request); - } - } + // $cmds = $eqModel['commands']; + + // parserLog('debug', " cmds=".json_encode($cmds)); + // foreach ($cmds as $cmdJName => $cmd) { + // if (!isset($cmd['configuration'])) + // continue; // No 'configuration' section then no 'execAtCreation' + // $c = $cmd['configuration']; + // if (!isset($c['execAtCreation'])) + // continue; + + // if (isset($c['execAtCreationDelay'])) + // $delay = $c['execAtCreationDelay']; + // else + // $delay = 0; + // parserLog('debug', " exec cmd '".$cmdJName."' with delay ".$delay); + // $topic = $c['topic']; + // $request = $c['request']; + // // TODO: #EP# defaulted to first EP but should be + // // defined in cmd use if different target EP + // // $request = str_ireplace('#EP#', $eq['epFirst'], $request); + // $request = str_ireplace('#EP#', $eq['mainEp'], $request); + // $request = str_ireplace('#addrIEEE#', $eq['ieee'], $request); + // $request = str_ireplace('#IEEE#', $eq['ieee'], $request); + // $zgId = substr($net, 7); // 'AbeilleX' => 'X' + // $request = str_ireplace('#ZiGateIEEE#', $GLOBALS['zigate'.$zgId]['ieee'], $request); + // parserLog('debug', ' topic='.$topic.", request='".$request."'"); + // if ($delay == 0) + // msgToCmd(PRIO_NORM, "Cmd".$net."/".$addr."/".$topic, $request); + // else { + // $delay = time() + $delay; + // msgToCmd(PRIO_NORM, "TempoCmd".$net."/".$addr."/".$topic.'&time='.$delay, $request); + // } + // } // TODO: WORK ONGOING // For each 'info', attempting to read corresponding cluster/attribute diff --git a/core/php/AbeilleCmd.php b/core/php/AbeilleCmd.php index e979b131e9..386c34fc43 100644 --- a/core/php/AbeilleCmd.php +++ b/core/php/AbeilleCmd.php @@ -195,7 +195,6 @@ function configureZigate($zgId) { // Configure device // Returns: true=ok, false=error - // WORK ONGOING: Not used yet. Currently same function in AbeilleParser.class.php. function configureDevice($net, $addr) { cmdLog('debug', " configureDevice(${net}, ${addr})"); diff --git a/core/php/AbeilleParser.php b/core/php/AbeilleParser.php index 3d8812262a..c4f81fb2b6 100644 --- a/core/php/AbeilleParser.php +++ b/core/php/AbeilleParser.php @@ -301,9 +301,11 @@ function &getDevice($net, $addr, $ieee = null, &$new = false) { // Removing any cmd pending message for old address since device would no longer answer $msg = array( - 'type' => 'clearMessages', - 'net' => $net, - 'addr' => $oldAddr + 'type' => 'shortAddrChange', + 'oldNet' => $net, + 'newNet' => $net, + 'oldAddr' => $oldAddr, + 'newAddr' => $addr ); msgToCmdAck($msg); @@ -336,9 +338,11 @@ function &getDevice($net, $addr, $ieee = null, &$new = false) { // Removing any cmd pending message for old net/address since device would no longer answer $msg = array( - 'type' => 'clearMessages', - 'net' => $oldNet, - 'addr' => $oldAddr + 'type' => 'shortAddrChange', + 'oldNet' => $oldNet, + 'newNet' => $net, + 'oldAddr' => $oldAddr, + 'newAddr' => $addr ); msgToCmdAck($msg); diff --git a/docs/fr_FR/Changelog.rst b/docs/fr_FR/Changelog.rst index dca90ebeee..5ce76d558e 100644 --- a/docs/fr_FR/Changelog.rst +++ b/docs/fr_FR/Changelog.rst @@ -10,6 +10,7 @@ ChangeLog - Page EQ/avancé: Ajout d'une section 'variables'. Suppression cas 'telecommande7groups'. - Tuya compteur d'énergie: Modèle préliminaire (2691). - Page EQuipement: 'variables' migrées sur onglet principal. +- Interne: Configuration sur 'device announce' déplacée de Parser vers Cmd. 240308-BETA-1 -------------