Repository navigation
Expand file tree
/
Copy pathofficebot-controller.php
More file actions
179 lines (163 loc) · 2.76 KB
/
Copy pathofficebot-controller.php
File metadata and controls
179 lines (163 loc) · 2.76 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
require_once ('officebot-include.php');
function is_valid_create_command($cmd)
// make sure it's a command we understand
{
switch ($cmd)
{
case 'i':
case 'o':
case 'c':
case 'l':
case 's':
case 'x':
case 'I':
case 'O':
case 'C':
case 'L':
case 'S':
case 'X':
case 'a':
case 'A':
case 'd':
case 'D':
case 'aa':
case 'ddd':
return ($cmd);
default:
return (false);
}
}
function is_valid_pantilt_command($cmd)
// make sure it's a command we understand
{
switch ($cmd)
{
case 'u':
case 'd':
case 'l':
case 'r':
return ($cmd);
default:
return (false);
}
}
function robot_command($cmd)
{
global $conn, $createActionTable, $robotname;
$commandSocket = socket_create (AF_INET, SOCK_STREAM, 0);
socket_bind($commandSocket, '127.0.0.1');
socket_connect($commandSocket, '127.0.0.1', '49440');
socket_write($commandSocket, "$cmd\n");
socket_close($commandSocket);
// if (is_valid_create_command($cmd))
// {
// mysql_query("update $createActionTable set command = '$cmd', last_update = " . microtime (true));
// } else {
// syslog (LOG_NOTICE, "invalid robot command issued: $cmd");
// }
}
function pantilt_command($cmd)
{
robot_command($cmd);
}
function pantilt_up()
{
pantilt_command ('u');
}
function pantilt_down()
{
pantilt_command ('n');
}
function pantilt_left()
{
pantilt_command ('h');
}
function pantilt_right()
{
pantilt_command ('k');
}
function pantilt_center()
{
pantilt_command ('j');
}
function robot_forward()
{
robot_command('o');
}
function robot_backward()
{
robot_command('l');
}
function robot_left()
{
robot_command('aa');
}
function robot_right()
{
robot_command('dd');
}
function robot_stop()
{
robot_command('x');
}
header("Content-type: text/json");
if (isset ($_REQUEST['cmd']))
{
switch ($_REQUEST['cmd'])
// switch ('l')
{
case 'o':
robot_forward();
$retval = 'f';
break;
case 'l':
robot_backward();
$retval = 'b';
break;
case 'a':
case 'i':
robot_left();
$retval = 'l';
break;
case 'd':
robot_right();
$retval = 'c';
break;
case 's':
case 'x':
robot_stop();
$retval = 's';
break;
default:
$retval = "none";
break;
}
}
if (isset ($_REQUEST['pantilt']))
{
switch ($_REQUEST['pantilt'])
{
case 'l': // pan left
pantilt_left();
break;
case 'r': // pan right
pantilt_right();
break;
case 'u': // tilt up
pantilt_up();
break;
case 'd': // tilt down
pantilt_down();
break;
case 'j': // center
pantilt_center();
break;
default:
$cmd = NULL;
break;
}
}
header ("Content-type: text/plain\n");
echo (json_encode(array('commandSent' => isset($_REQUEST['cmd']) ? $_REQUEST['cmd'] : $_REQUEST['pantilt'] )));
?>