Skip to content

Commit

Permalink
msg_send() error desc
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharp38 committed Aug 14, 2024
1 parent 1004198 commit 7e21956
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
32 changes: 0 additions & 32 deletions core/class/AbeilleParser.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,38 +483,6 @@ function deviceAnnounce($net, $addr, $ieee, $macCapa, $rejoin) {
}
}

// /* Update device infos.
// As opposed to 'deviceUpdate()', info is NOT coming from the device himself. */
// function updateDevice($net, $addr, $updates) {
// parserLog('debug', ' updateDevice('.$net.', '.$addr.', '.json_encode($updates).')');
// if (isset($updates['ieee']))
// $ieee = $updates['ieee'];
// else
// $ieee = null;
// $eq = &getDevice($net, $addr, $ieee, $newDev); // By ref

// $confirmed = array();
// foreach ($updates as $updKey => $updVal) {
// if ($updKey == 'ieee')
// continue; // This is already covered
// if (!isset($eq[$updKey]) || ($eq[$updKey] != $updVal)) {
// $eq[$updKey] = $updVal;
// $confirmed[$updKey] = $updVal;
// }
// }

// // Any changes to report to Abeille ?
// if (count($confirmed) > 0) {
// $msg = array(
// 'type' => 'deviceUpdates',
// 'net' => $net,
// 'addr' => $addr,
// 'updates' => $confirmed,
// );
// msgToAbeille2($msg);
// }
// }

/* There are device infos updates (ex: endpoints, manufId, modelId, location, ...). */
function deviceUpdates($net, $addr, $ep, $updates = []) {
parserLog('debug', " deviceUpdates(${net}, ${addr}, EP=${ep}, Upd=".json_encode($updates, JSON_UNESCAPED_SLASHES).")");
Expand Down
12 changes: 12 additions & 0 deletions core/class/AbeilleTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,5 +1170,17 @@ public static function base64url2base64($data) {

return $b64;
}

// Returns 'msg_send' error description
public static function getMsgSendErr($errCode) {
$errDesc = array(
'11' => 'Queue full',
'13' => 'Permission denied'
);
if (isset($errDesc[$errCode]))
return $errDesc[$errCode];
else
return "?";
}
}
?>
10 changes: 6 additions & 4 deletions core/php/AbeilleCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ function msgToCmd($topic, $payload = '') {

global $abQueues;
$queue = msg_get_queue($abQueues["xToCmd"]["id"]);
if (msg_send($queue, 1, $msgJson, false, false, $errCode) == false) {
cmdLog("debug", "msgToCmd(): ERROR ".$errCode);
// Note: '@' to suppress PHP warning message.
if (@msg_send($queue, 1, $msgJson, false, false, $errCode) == false) {
cmdLog("debug", " msgToCmd(xToCmd) ERROR ${errCode}/".AbeilleTools::getMsgSendErr($errCode));
}
}

Expand All @@ -166,8 +167,9 @@ function msgToAbeille($msg) {
global $abQueues;

$queue = msg_get_queue($abQueues["xToAbeille"]["id"]);
if (msg_send($queue, 1, json_encode($msg), false, false, $errCode) == false) {
cmdLog("debug", "msgToAbeille(): ERROR ".$errCode);
// Note: '@' to suppress PHP warning message.
if (@msg_send($queue, 1, json_encode($msg), false, false, $errCode) == false) {
cmdLog("debug", " msgToAbeille() ERROR ${errCode}/".AbeilleTools::getMsgSendErr($errCode));
}
}

Expand Down
16 changes: 7 additions & 9 deletions core/php/AbeilleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,7 @@ function msgToAbeille2($msg) {
global $queueXToAbeille;
// Note: '@' to suppress PHP warning message.
if (@msg_send($queueXToAbeille, 1, $msgJson, false, false, $errCode) == false) {
// Err 11 = EAGAIN = Queue full ?
$errDesc = "";
if ($errCode == 11)
$errDesc = "/queue FULL";
parserLog("debug", "msgToAbeille2(): ERROR ${errCode}${errDesc}");
parserLog("debug", "msgToAbeille2() ERROR ${errCode}/".AbeilleTools::getMsgSendErr($errCode));
}
}

Expand All @@ -223,16 +219,18 @@ function msgToCmd($prio, $topic, $payload = '') {
$msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES);

global $queueXToCmd;
if (msg_send($queueXToCmd, 1, $msgJson, false, false, $errCode) == false) {
parserLog("debug", " ERROR: msgToCmd(): Can't write to 'queueXToCmd', error=".$errCode);
// Note: '@' to suppress PHP warning message.
if (@msg_send($queueXToCmd, 1, $msgJson, false, false, $errCode) == false) {
parserLog("debug", " msgToCmd(queueXToCmd) ERROR ${errCode}/".AbeilleTools::getMsgSendErr($errCode));
}
}

function msgToCmdAck($msg) {
$msgJson = json_encode($msg, JSON_UNESCAPED_SLASHES);
global $queueParserToCmdAck;
if (msg_send($queueParserToCmdAck, 1, $msgJson, false, false) == false) {
parserLog("error", " ERROR: Can't send msg to 'queueParserToCmdAck'. msg=".$msgJson);
// Note: '@' to suppress PHP warning message.
if (@msg_send($queueParserToCmdAck, 1, $msgJson, false, false, $errCode) == false) {
parserLog("debug", " msgToCmd(queueParserToCmdAck) ERROR ${errCode}/".AbeilleTools::getMsgSendErr($errCode));
}
}

Expand Down

0 comments on commit 7e21956

Please sign in to comment.