forked from carbonsphere/UHPPOTE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
92 lines (71 loc) · 1.83 KB
/
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
<?php
/**
* User: carbonsphere
* Date: 15/08/2017
*/
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("");
/*
* Get Remote Monitor IP Command from UHPPOTE Class
*/
$cmd = $a->getCmdHex('get_ripp');
echo "Send the folling command to network\n$cmd\n";
/*
* 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));
var_dump($procmsg);
function createSocket()
{
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
return $sock;
}
function getReturnPacket($sock)
{
if(socket_recv ( $sock , $reply , 2045 , MSG_WAITALL ) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Receive socket Error: [$errorcode] $errormsg \n");
}
return $reply;
}
?>