Skip to content

Commit

Permalink
AbeilleCmd: refresh from eqLogic DB updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Nov 14, 2023
1 parent daac981 commit 8efca3a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 30 deletions.
40 changes: 21 additions & 19 deletions core/class/AbeilleCmdQueue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ function processAcks() {
if ($lastSent && ($cmd['waitFor'] == "ACK")) {
$removeCmd = true;

$eqStatusChanged = '';
$net = $msg['net'];
$addr = $msg['addr'];
$eq = &getDevice($net, $addr); // By ref
Expand All @@ -758,24 +757,27 @@ function processAcks() {
cmdLog('debug', " eq=".json_encode($eq));
// Note: TX status makes sense only if device is always listening (rxOnWhenIdle=TRUE)
// For other devices any interrogation without waking up device may lead to NO-ACK which is normal
if ($msg['status'] == '00') { // Ok ?
if ($eq['txStatus'] !== 'ok')
$eqStatusChanged = 'ok';
} else { // NO ACK ?
if ($eq['txStatus'] !== 'noack')
$eqStatusChanged = 'noack';
}
if ($eq['rxOnWhenIdle'] && ($eqStatusChanged != '')) {
$eq['txStatus'] = $eqStatusChanged;
$msg = array(
// 'src' => 'cmd',
'type' => 'eqTxStatusUpdate',
'net' => $net,
'addr' => $addr,
'txStatus' => $eqStatusChanged // 'ok', or 'noack'
);
msgToAbeille($msg);
cmdLog2('debug', $addr, " ${net}-${addr} status changed to '${eqStatusChanged}'");
if (isset($eq['rxOnWhenIdle']) && $eq['rxOnWhenIdle']) {
$newTxStatus = '';
if ($msg['status'] == '00') { // Ok ?
if ($eq['txStatus'] !== 'ok')
$newTxStatus = 'ok';
} else { // NO ACK ?
if ($eq['txStatus'] !== 'noack')
$newTxStatus = 'noack';
}
if ($newTxStatus != '') {
$eq['txStatus'] = $newTxStatus;
$msg = array(
// 'src' => 'cmd',
'type' => 'eqTxStatusUpdate',
'net' => $net,
'addr' => $addr,
'txStatus' => $newTxStatus // 'ok', or 'noack'
);
msgToAbeille($msg);
cmdLog2('debug', $addr, " ${net}-${addr} status changed to '${newTxStatus}'");
}
}
}
}
Expand Down
39 changes: 28 additions & 11 deletions core/php/AbeilleCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ function &getDevice($net, $addr) {
// Note: A delay is required prior to this if DB has to be updated (createDevice() in Abeille.class)
function updateDeviceFromDB($eqId) {
$eqLogic = eqLogic::byId($eqId);
if (!is_object($eqLogic)) {
logMessage('debug', " ERROR: updateDeviceFromDB(): Equipment ID ${eqId} does not exist");
return;
}
$eqLogicId = $eqLogic->getLogicalId();
list($net, $addr) = explode("/", $eqLogicId);

$ieee = $eqLogic->getConfiguration('IEEE', '');
if (!isset($GLOBALS['devices'][$net][$addr]) && ($ieee == '')) {
logMessage('debug', " updateDeviceFromDB() WARNING: Unknown addr ${addr} and IEEE is undefined");
logMessage('debug', " ERROR: updateDeviceFromDB(): Unknown addr '${net}/${addr}' and IEEE is undefined");
return;
}

Expand All @@ -75,7 +79,7 @@ function updateDeviceFromDB($eqId) {
$found = true;
$GLOBALS['devices'][$net][$addr] = $GLOBALS['devices'][$net][$addr2];
unset($GLOBALS['devices'][$net][$addr2]);
logMessage('debug', " Device ID ${eqId} address changed from ${addr2} to ${addr}.");
logMessage('debug', " Device ID ${eqId} address changed from '${net}/${addr2}' to '${net}/${addr}'.");
break;
}
}
Expand All @@ -90,23 +94,36 @@ function updateDeviceFromDB($eqId) {
$found = true;
$GLOBALS['devices'][$net][$addr] = $GLOBALS['devices'][$net2][$addr2];
unset($GLOBALS['devices'][$net2][$addr2]);
logMessage('debug', " Device ID ${eqId} migrated from ${net2}/${addr2} to ${net2}/${addr}.");
logMessage('debug', " Device ID ${eqId} migrated from '${net2}/${addr2}' to '${net}/${addr}'.");
break;
}
}
}
}

// Whatever found or new... updating infos used by cmd process
if (!isset($GLOBALS['devices'][$net]))
$GLOBALS['devices'][$net] = [];
$eqModel = $eqLogic->getConfiguration('ab::eqModel', []);
$zigbee = $eqLogic->getConfiguration('ab::zigbee', []);
$rwOnWhenIdle = isset($zigbee['rwOnWhenIdle']) ? $zigbee['rwOnWhenIdle'] : 0;
$GLOBALS['devices'][$net][$addr]['rwOnWhenIdle'] = $rwOnWhenIdle ? true : false;
// $GLOBALS['devices'][$net][$addr]['tuyaEF00'] = $eqLogic->getConfiguration('ab::tuyaEF00', null);
// parserLog('debug', " 'tuyaEF00' updated to ".json_encode($GLOBALS['devices'][$net][$addr]['tuyaEF00']));
// $GLOBALS['devices'][$net][$addr]['xiaomi'] = $eqLogic->getConfiguration('ab::xiaomi', null);
// parserLog('debug', " 'xiaomi' updated to ".json_encode($GLOBALS['devices'][$net][$addr]['xiaomi']));
// $GLOBALS['devices'][$net][$addr]['customization'] = $eqLogic->getConfiguration('ab::customization', null);
// parserLog('debug', " 'customization' updated to ".json_encode($GLOBALS['devices'][$net][$addr]['customization']));
// TO BE COMPLETED if any other key info
$eq = array(
'ieee' => $ieee,
'txStatus' => $eqLogic->getStatus('ab::txAck', 'ok'), // Transmit status: 'ok' or 'noack'
'jsonId' => isset($eqModel['id']) ? $eqModel['id'] : '',
'jsonLocation' => isset($eqModel['location']) ? $eqModel['location'] : 'Abeille',
'rxOnWhenIdle' => $rwOnWhenIdle ? true : false
);
if ($eq['jsonId'] != '') {
// Read JSON to get list of commands to execute
$model = AbeilleTools::getDeviceModel('', $eq['jsonId'], $eq['jsonLocation']);
if ($model !== false) {
$eq['mainEp'] = isset($model['mainEP']) ? $model['mainEP'] : "01";
$eq['commands'] = isset($model['commands']) ? $model['commands'] : [];
}
}

$GLOBALS['devices'][$net][$addr] = $eq;
}

/* Send msg to 'xToCmd' queue. */
Expand Down

0 comments on commit 8efca3a

Please sign in to comment.