Skip to content

Commit

Permalink
Cmd: if Zigate busy, wait 1sec before retry
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Aug 8, 2024
1 parent 6095cc1 commit 86c9fd5
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 89 deletions.
28 changes: 17 additions & 11 deletions core/class/AbeilleCmdProcess.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,17 +948,6 @@ function processCmd($Command) {
// return;
// }

if (isset($Command['setExtendedPANID'])) {
cmdLog('debug', " setExtendedPANID", $this->debug['processCmd']);
$cmd = "0020";
$data = $Command['setExtendedPANID'];

// $length = sprintf("%04s", dechex(strlen($data) / 2));
// $this->addCmdToQueue($priority, $dest, $cmd, $length, $data);
$this->addCmdToQueue2(PRIO_NORM, $dest, $cmd, $data);
return;
}

//----------------------------------------------------------------------
// Bind
// Title => 000B57fffe3025ad (IEEE de l ampoule)
Expand Down Expand Up @@ -2512,6 +2501,23 @@ function processCmd($Command) {
return;
}

// Zigate specific command: Set extended PAN-ID
// Mandatory params: 'extPanId'
else if ($cmdName == 'zgSetExtendedPanId') {
$required = ['extPanId'];
if (!$this->checkRequiredParams($required, $Command))
return;

$zgCmd = "0020";
$extPanId = $Command['extPanId'];
cmdLog('debug', " zgSetExtendedPanId: extPanId=${extPanId}");

// WARNING: This does not work. Network must not be running to change ext Pan ID but how to do that ??

$this->addCmdToQueue2(PRIO_NORM, $dest, $zgCmd, $extPanId, "0000");
return;
}

// Zigate specific command: Erase PDM
else if ($cmdName == 'zgErasePdm') {
$this->addCmdToQueue2(PRIO_NORM, $dest, "0012");
Expand Down
80 changes: 13 additions & 67 deletions core/class/AbeilleCmdQueue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,13 @@ function processCmdQueues() {
// cmdLog("debug", __FUNCTION__." zgId=".$zgId.", zg=".json_encode($zg));

if (!$zg['enabled']) continue; // Disabled
if (!$zg['available']) continue; // Already treating a command
if (!$zg['available']) {
if (isset($zg['availTime']) && ($zg['availTime'] <= microtime(true))) {
$GLOBALS['zigates'][$zgId]['available'] = 1; // Available again
unset($GLOBALS['zigates'][$zgId]['availTime']);
} else
continue; // Still not available
}

// Throughput regulation
// $zg['tp_time'] gives time (in us) when Zigate can be considered available again.
Expand Down Expand Up @@ -559,7 +565,7 @@ function processCmdQueues() {
$sendIdx = 0;
} else {
// Regulation required. Looking for Zigate only cmd
cmdLog('debug', "processCmdQueues(): ZgId=${zgId}, Pri=${priority}/Idx=${cmdIdx}, Cmd=".$cmd['cmd']." => ${regulation} regulation");
cmdLog('debug', "processCmdQueues(): ZgId=${zgId}, Pri=${priority}/Idx=${cmdIdx}, Cmd=".$cmd['cmd']." => '${regulation}' regulation");
foreach ($zg['cmdQueue'][$priority] as $cmdIdx => $cmd) {
if ($cmdIdx == 0)
continue; // 1st cmd already checked
Expand Down Expand Up @@ -594,66 +600,6 @@ function processCmdQueues() {
monMsgToZigate($cmd['addr'], $cmd['cmd'].'-'.$cmd['datas']); // Monitor this addr ?
}
} // End zigates loop

// Throughput limitation
// $zg['tp_time'] gives time (in us) when Zigate can be considered available again.
// $mt = microtime(true);
// if (isset($zg['tp_time']) && ($zg['tp_time'] > $mt)) {
// cmdLog('debug', "processCmdQueues(): ZgId=${zgId} => Throughput limitation");
// break; // This zigate is not yet available
// }

// cmdLog('debug', "processCmdQueues(): ZgId=${zgId}, Pri=${priority}, NPDU=".$zg['nPDU'].", APDU=".$zg['aPDU']);

// $cmd = $zg['cmdQueue'][$priority][0]; // Takes first cmd
// cmdLog('debug', " cmd=".json_encode($cmd));
// if ($cmd['status'] != '') {
// cmdLog('debug', " WARNING: Unexpected cmd status '".$cmd['status']."'");
// }

// NDPU limitation (NDPU too high leads to extended error due to lack of resources)
// if (!$cmd['zgOnly']) { // Not a cmd for Zigate only
// if ($zg['nPDU'] > 7) {
// cmdLog('debug', " NDPU limitation (NPDU=".$zg['nPDU'].")");
// break; // This zigate is not yet available
// }
// }

/* Additional flow control with nPDU/aPDU regulation to avoid zigate internal saturation.
This must not prevent zigate internal commands (ex: read version).
If HW v1
If FW >= 3.1e, using NPDU/APDU regulation.
If FW < 3.1e, regulation based on max cmd per sec => Throughput limitation
If HW v2
No flow control. Regulation based on max cmd per sec => Throughput limitation
*/
// if (($zg['hw'] == 1) && !$cmd['zgOnly']) { // Not a cmd for Zigate only
// // cmdLog('debug', "processCmdQueues(): nPDU/aPDU regulation to be checked: ".json_encode($zg));
// if (($zg['nPDU'] > 7) || ($zg['aPDU'] > 2)) {
// cmdLog('debug', ' NPDU/APDU regulation for Zigate '.$zgId.' (NPDU='.$zg['nPDU'].', APDU='.$zg['aPDU'].')');

// // Adding a "read version" cmd as FIRST CMD to force NDPU/APDU update
// $this->pushZigateCmd($zgId, $priority, "0010", "", "0000", "00", true);
// $cmd = $GLOBALS['zigates'][$zgId]['cmdQueue'][$priority][0]; // Takes first cmd
// }
// }

// $GLOBALS['zigates'][$zgId]['available'] = 0; // Zigate no longer free
// $GLOBALS['zigates'][$zgId]['sentPri'] = $priority; // Keep the last queue used to send a cmd to this Zigate
// $GLOBALS['zigates'][$zgId]['sentIdx'] = $cmdIdx;

// $this->sendCmdToZigate($cmd['dest'], $cmd['addr'], $cmd['cmd'], $cmd['datas']);

// $GLOBALS['zigates'][$zgId]['cmdQueue'][$priority][$cmdIdx]['status'] = "SENT";
// $GLOBALS['zigates'][$zgId]['cmdQueue'][$priority][$cmdIdx]['sentTime'] = time();
// $GLOBALS['zigates'][$zgId]['cmdQueue'][$priority][$cmdIdx]['try']--;
// $GLOBALS['zigates'][$zgId]['tp_time'] = microtime(true) + 0.1; // Next avail time in 100ms

// if (isset($GLOBALS["dbgMonitorAddr"]) && ($cmd['addr'] != "") && ($GLOBALS["dbgMonitorAddr"] != "") && !strncasecmp($cmd['addr'], $GLOBALS["dbgMonitorAddr"], 4))
// monMsgToZigate($cmd['addr'], $cmd['cmd'].'-'.$cmd['datas']); // Monitor this addr ?
// break; // This zigate is no longer idle so do not check other priorities now.
// }
}

// Process high priority queue from parser (8000, 8011, 8012 or 8702 messages)
Expand Down Expand Up @@ -798,18 +744,18 @@ function processAcksQueue() {
// Status is: bad param, unhandled, failed (?), stack already started
// Status 06 = Unknown EP ? (Zigate v2)
// 14/E_ZCL_ERR_ZBUFFER_FAIL: Msg too big
// $cmd['status'] = '8000';
cmdLog("debug", " WARNING: Zigate cmd failed (status=${msgStatus})");
cmdLog("debug", " WARNING: Zigate cmd failed (err ${msgStatus})");
$removeCmd = true;
}
else {
// Something failed
// Something failed: case 04/Busy
if ($cmd['try'] == 0) {
cmdLog("debug", " WARNING: Something failed and too many retries.");
cmdLog("debug", " WARNING: Cmd ".$cmd['cmd']." to ".$cmd['addr']." failed and too many retries.");
$removeCmd = true;
}
else {
cmdLog("debug", " WARNING: Something failed. Cmd will be retried ".$cmd['try']." time(s) max.");
cmdLog("debug", " WARNING: Cmd ".$cmd['cmd']." failed (err ${msgStatus}). Will be retried ".$cmd['try']." time(s) max.");
$GLOBALS['zigates'][$zgId]['availTime'] = microtime(true) + 1.0; // Zg will be free in 1sec
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions core/php/AbeilleCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,17 @@ function msgToAbeille($msg) {
function configureZigate($zgId) {
cmdLog('debug', "configureZigate(${zgId})");

$gtwType = isset($config['ab::gtwType'.$zgId]) ? $config['ab::gtwType'.$zgId] : 'zigate';
if ($gtwType != 'zigate') {
cmdLog('error', " Gateway ${zgId} is NOT a Zigate");
return;
}

msgToCmd("CmdAbeille".$zgId."/0000/zgSoftReset", "");
// Cmds delayed by 1sec to wait for chip reset
// Following cmds delayed by 1sec to wait for chip reset

// Extended PAN ID change must be done BEFORE starting network
msgToCmd("TempoCmdAbeille".$zgId."/0000/zgSetExtendedPanId&tempo=".(time()+1), "extPanId=21758D1900481200");

global $config;
if (isset($config['ab::gtwChan'.$zgId])) {
Expand All @@ -192,9 +201,9 @@ function configureZigate($zgId) {
cmdLog('debug', " Configuring Zigate ${zgId} in ${mode} mode");
msgToCmd("TempoCmdAbeille".$zgId."/0000/zgSetMode&tempo=".(time()+1), "mode=${mode}");

msgToCmd("TempoCmdAbeille".$zgId."/0000/zgStartNetwork&tempo=".(time()+1), "");
msgToCmd("TempoCmdAbeille".$zgId."/0000/zgStartNetwork&tempo=".(time()+10), "");

msgToCmd("TempoCmdAbeille".$zgId."/0000/zgGetVersion&tempo=".(time()+1), "");
msgToCmd("TempoCmdAbeille".$zgId."/0000/zgGetVersion&tempo=".(time()+10), "");
}

// Configure device
Expand Down
13 changes: 9 additions & 4 deletions desktop/js/Abeille.js
Original file line number Diff line number Diff line change
Expand Up @@ -1598,10 +1598,15 @@ function sendZigate(action, param) {
else if (param == "Raw") payload = "mode=raw";
else payload = "mode=hybrid";
break;
case "setExtPANId": // Not critical. No need so far.
topic = "CmdAbeille" + zgId + "/0000/setExtendedPANID";
payload = "";
break;
// case "setExtPANId":
// topic = "CmdAbeille" + zgId + "/0000/zgSetExtendedPanId";
// // Note: param = cmd logic id
// cmd = eq.cmds[param];
// cmdId = cmd.id;
// extPanId = document.getElementById("cmdId-" + cmdId).value;
// console.log("Ext PAN-ID=" + extPanId);
// payload = "extPanId=" + extPanId;
// break;
case "setChannel":
msg =
"{{Vous êtes sur le point de changer le canal Zigbee de la Zigate}}<b>" +
Expand Down
8 changes: 4 additions & 4 deletions desktop/php/Abeille-Eq-Advanced-Zigate.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function addZgButton($name, $class, $onclick, $onclick2 = "", $leftMargin = true
<div class="form-group">
<label class="col-sm-3 control-label">PAN ID</label>
<div class="col-sm-5" advInfo="PAN-ID">
<input type="text" id="idPanId" value="" readonly>
<input type="text" value="" readonly>
</div>
</div>

Expand All @@ -117,9 +117,9 @@ function addZgButton($name, $class, $onclick, $onclick2 = "", $leftMargin = true
<!-- <a class="btn btn-primary btn-xs" target="_blank" href="https://kiwihc16.github.io/AbeilleDoc/Radio.html"><i class="fas fa-book"></i> ?</a> -->
</div>
<div class="col-sm-5" advInfo="Ext_PAN-ID">
<input type="text" id="idExtPanId" value="" readonly>
<!-- TODO <input type="text" name="extendedPanId" placeholder="XXXXXXXX">
<button type="button" onclick="sendZigate('setExtPANId', '')">Modifier</button> -->
<input type="text" value="">
<!-- Does not work. Unable to set a different PAN ID. Need to find a way to stop network & apply before restarting
< ?php addZgButton("{{Appliquer}}", "btn-danger", 'setExtPANId', 'Ext_PAN-ID'); ?> -->
</div>
</div>

Expand Down
2 changes: 2 additions & 0 deletions docs/fr_FR/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Amélioration: Plus besoin de redémarrer démons apres changement niveau de log.
- Amélioration: Maintenance/infos clefs.
- Correction: Cmd: Status TX corrigé en 'ok' meme si 'rx OFF when idle'.
- Amélioration: Zigate: Tentative d'ajout possibilité de changer 'Extended PAN ID' pour cas Livolo. Ne fonctionne pas !
- Amélioration: Cmd->Zigate: Cas Zigate 'busy'.

## 240802-BETA-1

Expand Down

0 comments on commit 86c9fd5

Please sign in to comment.