/
switcher.php
executable file
·176 lines (122 loc) · 4.37 KB
/
switcher.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
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
#!/usr/bin/php
<?php
//error_reporting(0);
include 'php_serial.class.php';
include_once('switcherCommands.inc');
$skipJSsettings = 1;
$fppWWWPath = '/opt/fpp/www/';
set_include_path(get_include_path() . PATH_SEPARATOR . $fppWWWPath);
require("common.php");
$pluginName = "Switcher";
include_once 'functions.inc.php';
include_once 'commonFunctions.inc.php';
$pluginConfigFile = $settings['configDirectory'] . "/plugin." .$pluginName;
if (file_exists($pluginConfigFile))
$pluginSettings = parse_ini_file($pluginConfigFile);
$logFile = $settings['logDirectory'] . "/".$pluginName.".log";
$myPid = getmypid();
$DEBUG=false;
$SERIAL_DEVICE="";
$callBackPid="";
//$DEVICE = ReadSettingFromFile("DEVICE",$pluginName);
$DEVICE = $pluginSettings['DEVICE'];
//$DEVICE_CONNECTION_TYPE = ReadSettingFromFile("DEVICE_CONNECTION_TYPE",$pluginName);
$DEVICE_CONNECTION_TYPE = $pluginSettings['DEVICE_CONNECTION_TYPE'];
//$IP = ReadSettingFromFile("IP",$pluginName);
$IP = $pluginSettings['IP'];
//$PORT = ReadSettingFromFile("PORT",$pluginName);
$PORT = $pluginSettings['PORT'];
//$ENABLED = ReadSettingFromFile("ENABLED",$pluginName);
$ENABLED = $pluginSettings['ENABLED'];
//$SWITCHER = urldecode(ReadSettingFromFile("SWITCHER",$pluginName));
$SWITCHER = urldecode($pluginSettings['SWITCHER']);
$IP = urldecode($pluginSettings['IP']);
$PROJ_PASSWORD = urldecode($pluginSettings['PROJ_PASSWORD']);
logEntry("SWITCHER: ".$SWITCHER);
if(trim($SWITCHER == "" )) {
logEntry("No Switcher configured in plugin, exiting");
exit(0);
}
$options = getopt("c:");
$SERIAL_DEVICE="/dev/".$DEVICE;
logEntry("option C: ".$options["c"]);
$cmd= strtoupper(trim($options["c"]));
//loop through the array of SWITCHERS to get the command
$switcherIndex = 0;
//set the found flag, do not send a command if the name and command cannot be found
//print_r($SWITCHERS);
$SWITCHER_FOUND=false;
for($switcherIndex=0;$switcherIndex<=count($SWITCHERS)-1;$switcherIndex++) {
if($SWITCHERS[$switcherIndex]['NAME'] == $SWITCHER) {
logEntry("Switcher index: ".$switcherIndex);
logEntry("Looking for command string for cmd: ".$cmd);
while (list($key, $val) = each($SWITCHERS[$switcherIndex])) {
//logEntry( "Key: ".$key. " \t VAL:".$val);
if(strtoupper(trim($key)) == $cmd) {
$SWITCHER_FOUND=true;
$SWITCHER_CMD = $val;
logEntry("--------------");
logEntry("SWITCHER FOUND");
logEntry("SWITCHER: ".$SWITCHER_FOUND);
if($pluginSettings['BAUD_RATE'] !="")
{
$SWITCHER_BAUD = $pluginSettings['BAUD_RATE'];
} else {
$SWITCHER_BAUD=$SWITCHERS[$switcherIndex]['BAUD_RATE'];
}
if($pluginSettings['CHAR_BITS'] !="")
{
$SWITCHER_CHAR_BITS = $pluginSettings['CHAR_BITS'];
} else {
$SWITCHER_CHAR_BITS=$SWITCHERS[$switcherIndex]['CHAR_BITS'];
}
if($pluginSettings['STOP_BITS'] !="")
{
$SWITCHER_STOP_BITS = $pluginSettings['STOP_BITS'];
} else {
$SWITCHER_STOP_BITS=$SWITCHERS[$switcherIndex]['STOP_BITS'];
}
if($pluginSettings['PARITY'] !="")
{
$SWITCHER_PARITY = $pluginSettings['PARITY'];
} else {
$SWITCHER_PARITY=$SWITCHERS[$switcherIndex]['PARITY'];
}
logEntry("BAUD RATE: ".$SWITCHER_BAUD);
logEntry("CHAR BITS: ".$SWITCHER_CHAR_BITS);
logEntry("STOP BITS: ".$SWITCHER_STOP_BITS);
logEntry("PARITY: ".$SWITCHER_PARITY);
}
}
}
}
if(!$SWITCHER_FOUND) {
logEntry("switcher command not found: exiting");
exit(0);
}
$cmd = explode(",",$SWITCHER_CMD);
//print_r($cmd);
$i=0;
for($i=0;$i<=count($cmd);$i++) {
$switcher_cmd .= chr($cmd[$i]);
}
$SWITCHER_CMD = $switcher_cmd;
logEntry("-------");
logEntry("Sending command");
logEntry("Switcher cmd: ".$SWITCHER_CMD);
logEntry("Sending SERIAL COMMAND");
logEntry("SERIAL DEVICE: ".$SERIAL_DEVICE);
$serial = new phpSerial;
$serial->deviceSet($SERIAL_DEVICE);
$serial->confBaudRate($SWITCHER_BAUD);
$serial->confParity($SWITCHER_PARITY);
// $serial->confFlowControl("none");
$serial->confCharacterLength($SWITCHER_CHAR_BITS);
$serial->confStopBits($SWITCHER_STOP_BITS);
$serial->deviceOpen();
$serial->sendMessage($SWITCHER_CMD);
sleep(1);
logEntry("RETURN DATA: ".hex_dump($serial->readPort()));
logEntry("RETURN DATA: ".$serial->readPort());
$serial->deviceClose();
?>