function toHex($s)
{
    $i = 0;
    $t = '';
    while (isset($s[$i])) {
        $t .= padHex(ord($s[$i++]), 2);
    }
    return $t;
}
Exemplo n.º 2
0
function secToHexBE($sec)
{
    //    converts sec to a Big endian hexadecimal
    //    representation of the number of second;
    //    4 hexadecimal numbers with '0' padding
    //
    $hexSec = padHex(dechex($sec), 4);
    return $hexSec;
    //return Big Endian
}
Exemplo n.º 3
0
function addTimer($mac, $h, $m, $sec, $action, $rep, &$s20Table)
{
    srand();
    $timerList = $s20Table[$mac]['details'];
    // print_r($timerList);
    $nTimers = count($timerList);
    $stay = 1;
    while ($stay) {
        $stay = 0;
        $newDecCode = rand(0, 65535);
        $newCode = padHex(dechex($newDecCode), 4);
        for ($k = 0; $k < $nTimers; $k++) {
            if ($newCode == $timerList[$k]['recCode']) {
                $stay = 1;
            }
        }
    }
    $date = getDateFromTimerCode("", $s20Table[$mac]);
    $relevant = buildSetTimerString($h, $m, $sec, $action, $rep, $date);
    $writeMsg = MAGIC_KEY . "XXXX" . WRITE_SOCKET_CODE . $mac . TWENTIES . FOUR_ZEROS . "0300001C00" . $newCode . twenties(16) . $relevant;
    $writeMsg = adjustMsgSize($writeMsg);
    $res = createSocketSendHexMsgWaitReply($mac, $writeMsg, $s20Table);
    $tt = getAndParseTimerTable($mac, $s20Table);
    $s20Table[$mac]['details'] = $tt;
    return $res;
}
Exemplo n.º 4
0
function setTimeZone($mac, $tz, &$s20Table)
{
    //
    // Sets the timezone in table 4 to $tz
    //
    $table = 4;
    $vflag = "17";
    $recTable = getTable($mac, $table, $vflag, $s20Table);
    // Set timezone
    $tzSetString = "00";
    $tzValString = padHex(dechex($tz), 2);
    $tzString = $tzSetString . $tzValString;
    $newTableAux = substr_replace($recTable, $tzString, 2 * 162, 2 * 2);
    // replace receive code with send code
    $newTableAux = substr_replace($newTableAux, WRITE_SOCKET_CODE, 2 * 4, 4);
    //
    // Delete byte 18 (??)
    // Wireshark shows...
    //
    $newTable = substr_replace($newTableAux, "", 18 * 2, 2);
    //
    // Delete byte 25 and 26 of resulting (??)
    // Wireshark shows...
    //
    $newTable = substr_replace($newTable, "", 25 * 2, 4);
    // Update msg size, just in case it has changed
    $newTable = adjustMsgSize($newTable);
    $reply = createSocketSendHexMsgWaitReply($mac, $newTable, $s20Table);
    if ($reply == "") {
        $s20Table[$mac]['off'] = time();
    }
    return $reply;
}