Skip to content

Commit

Permalink
Config on dev announce moved to AbeilleCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Mar 17, 2024
1 parent 0f02767 commit 3b70f2c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
30 changes: 21 additions & 9 deletions core/class/AbeilleCmdQueue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
Expand Down
86 changes: 43 additions & 43 deletions core/class/AbeilleParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion core/php/AbeilleCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -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})");

Expand Down
16 changes: 10 additions & 6 deletions core/php/AbeilleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions docs/fr_FR/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down

0 comments on commit 3b70f2c

Please sign in to comment.