Beispiel #1
0
function createSocketSendHexMsgWaitReply($mac, $hexMsg, $s20Table)
{
    //
    // Sends msg specified by $hexMsg, in hexadecimal, to device
    // sepcified by $mac and waits for reply.
    //
    // Returns the reply in hex format after checking major conditions
    //
    $ip = $s20Table[$mac]['ip'];
    $s = createSocketAndBind($ip);
    $hexRecMsg = sendHexMsgWaitReply($s, $hexMsg, $ip);
    socket_close($s);
    return $hexRecMsg;
}
Beispiel #2
0
function sendAction($mac, $action, $s20Table)
{
    //
    // Sends an $action (ON=1, OFF = 0) to S20 specified by $mac
    // It retries until a proper reply is received with the desired
    // power status
    // However, we have detected that the reported power status just
    // after an action fails sometimes, and therefore you should not
    // use this function alone. Prefer switchAndCheck() below, which
    // performs a double check of the final state.
    //
    subscribe($mac, $s20Table);
    $msg = ACTION . $mac . TWENTIES;
    if ($action) {
        $msg .= ON;
    } else {
        $msg .= OFF;
    }
    $ip = $s20Table[$mac]['ip'];
    $s = createSocketAndBind($ip);
    $hexRecMsg = sendHexMsgWaitReply($s, $msg, $ip);
    $status = (int) hexdec(substr($hexRecMsg, -2, 2));
    socket_close($s);
}