-
Notifications
You must be signed in to change notification settings - Fork 9
/
timer-example.php
105 lines (84 loc) · 2.19 KB
/
timer-example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* User: carbonsphere
* Example code testing timer
* Date: 2019/05/27
*/
include "UHPPOTE.php";
$a = new uhppote();
/*
* Remember to set your serial number
* usually the last 4 bytes of your board's MAC address
* EX: 00:11:22:33:44:55 then the Serial Number = 22334455
*/
$a->setSn("");
/*
* addCardId['beg'] Beginning date of auth period
* addCardId['end'] End date of auth period
* beg/end format [ year month day ]
* Ex: 2000 01 01 "20000101" year 2000 jan 1st
* Max End date "20291231" 2029 Dec 31st
*/
$timer = [
"index" => '02',
"beg" => '20190524',
"end" => '20190524',
"w1" => '01',
"w2" => '01',
"w3" => '01',
"w4" => '01',
"w5" => '01',
"w6" => '01',
"w7" => '01',
"time1beg" => '1600',
"time1end" => '2359',
"time2beg" => '0000',
"time2end" => '0000',
"time3beg" => '0000',
"time3end" => '0000',
"countType" => '00'
"countDay" => '00',
"countMonth" => '00',
"countZone1" => '00',
"countZone2" => '00',
"countZone3" => '00',
"weekend" => '00'
];
/*
* Get Record Index from Command from UHPPOTE Class
*/
$cmd = $a->getCmdHex('set_timeAccess',null,$timer);
echo "Send the folling command to network\n";
$a->printCMD($cmd);
/*
* IP address can be obtained by running search.php first!
* $ip/$port of controller board
* Normally UHPPOTE controller port is static 60000
*/
$ip = "192.168.1.1";
$port = 60000;
$sock = createSocket();
/*
* Input is binary format of command
*/
$input = hex2bin($cmd);
echo "Sending....\n";
if( ! socket_sendto($sock, $input , strlen($input) , 0 , $ip , $port))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
echo "There is error\n";
exit;
}
/*
* Once the command is sent to UHPPOTE controller board, now we need to listen for return status
*/
echo "Listening for return status\n";
$reply = getReturnPacket($sock);
/*
* Process returned message. Returned message is in binary format
* So we revert it into hex before passing into procMessages
*/
echo "Processing return status\n";
$procmsg = $a->procCmd(bin2hex($reply));
?>