source: firmware/InterlockArduino/src/webserver/webserver.ino@ 15699

Last change on this file since 15699 was 14517, checked in by neise, 12 years ago
more HMTL conformity ...
File size: 10.4 KB
Line 
1/*
2 Arduino Ethernet for FACT Interlock
3
4 Written by Dominik Neise
5 June 2012
6 TU Dortmund
7
8 The FACT Camera as well as the bias voltage supply for its G-APDs
9 may only be switched on, if the dedicated cooling systems are running.
10 This arduino is connected via optocouplers to some status LEDs,
11 and other coolings system output signals, which show
12 the status of both cooling systems:
13 * water cooling pump
14 - flow meter
15 - level meter
16 * bias crate fans
17 - rotation frequency
18 A simple WebServer is implemented for showing the
19 status and access the actual switches.
20
21 In order to switch on the camera one needs to switch on
22 the water pump first. In case this pump is running, the
23 Camera power suplly (51VDC Agilent) gets an enable signal
24 and will power the camera.
25 In order to enable the bias voltage supply, one needs to swtich on
26 the Bias Crate Fans.
27
28 Circuit:
29 IL_ON : Interlock on : digital input D1
30 FL_OK : level ok : digital input D2
31 FC_OK : current ok : digital input D3
32 FP_EN : pump enabled : digital input D4
33
34 FC_ON : enable pump : digital output D5
35 FC_OFF: disable pump : digital output D6
36 */
37#include <SPI.h>
38#include <Ethernet.h>
39
40// inputs
41int FC_OK = 2;
42int BP_ON = 3;
43
44int IL_ON = 14;
45int FL_OK = 15;
46int FP_EN = 16;
47int X_ON = 17;
48int Y_ON = 18;
49int Z_OK = 19;
50
51int my_inputs[] = {FC_OK, BP_ON, IL_ON, FL_OK, FP_EN, X_ON, Y_ON, Z_OK};
52//char * my_input_names[] = {"FC_OK", "BP_ON", "IL_ON", "FL_OK", "FP_EN", "X_ON", "Y_ON", "Z_OK"};
53
54char * my_input_names[] = { "Is the cooling liquid flow meter measuring enough throuput? ",
55 "Is Bias Power enabled? ",
56 "Is 24VDC Interlock power supply enabled? ",
57 "Is the Level of the cooling liquid ok? ",
58 "Is the Pump powered? ",
59 "<br />Is the Drive Cabinet Enable Signal on? ",
60 "Is the Drive Cabinet Power Signal on? ",
61 "Is Drive Container Enabled? "};
62
63char * my_input_span_id[] = {"flow_meter", "bias_power", "power_24v", "level", "pump", "drive_enable", "drive_power", "drive_on"};
64
65int Number_of_Buttons = 3;
66// This is in HTML called the VALUE of the button,
67// but it is in fact what is written on it.
68char * button_caption[] = {
69 "Camera ON",
70 "Camera OFF",
71 "Drive ON/OFF"};
72
73// This is in HTML called the NAME of the button, and it is, what is transmit
74// within the request. So this is a kind of reference string .. which i searh for
75// in the request ... so the strings schould be nice ... no capital letters no spaces
76char * button_name[] = {
77 "cam_on",
78 "cam_off",
79 "dt"}; // read drive_toggle
80
81 // outputs
82int FC_ON = 4;
83int FC_OFF = 5;
84int X = 6;
85int Y = 7;
86
87
88unsigned long last_time = millis();
89unsigned long current_time = millis();
90unsigned int fc_on_time = 0; // time in ms, for FC_ON to be HIGH
91unsigned int fc_off_time = 0;// time in ms, for FC_OFF to be HIGH
92
93
94byte mac[] = { 0xFA, 0xC7, 0xFC, 0xB1, 0x00, 0x01 }; // FACT internal network
95
96
97
98// Initialize the Ethernet server library
99// with the IP address and port you want to use
100// (port 80 is default for HTTP):
101EthernetServer server(80);
102
103
104boolean x_signal = false;
105boolean y_signal = false;
106
107
108void setup() {
109 // Open serial communications and wait for port to open:
110// Serial.begin(9600);
111 Serial.begin(19200);
112
113
114 // start the Ethernet connection and the server:
115 Ethernet.begin(mac);
116 server.begin();
117 Serial.print("server is at ");
118 Serial.println(Ethernet.localIP());
119
120 pinMode( FC_ON, OUTPUT );
121 pinMode( FC_OFF,OUTPUT );
122 pinMode( X, OUTPUT );
123 pinMode( Y,OUTPUT );
124 // the others are all INPUTs
125}
126
127
128
129
130void loop() {
131 Check_n_Set_FC_ON_OFF();
132
133 unsigned long before = millis();
134
135 if (Check_for_clients() )
136 {
137 unsigned long duration = millis() - before;
138
139 Serial.println( duration, DEC);
140 }
141
142 delay(300);
143}
144
145
146
147
148/////////////////////////////////////////////////////////////////////////////////////////////
149int Check_for_clients()
150{
151
152 int got_client = 0;
153 // listen for incoming clients
154 EthernetClient client = server.available();
155 if (client) {
156 got_client = 1;
157 Serial.println("new client");
158 // an http request ends with a blank line
159 boolean currentLineIsBlank = true;
160 boolean get_http_found = false;
161 String eth = "";
162
163 while (client.connected()) {
164 if (client.available()) {
165 char c = client.read();
166 if (!get_http_found)
167 {
168 eth += c;
169 //Serial.write(c);
170 //Serial.print(' ');
171 //Serial.print(c, HEX);
172 //Serial.print(' ');
173 //Serial.println(eth.length(), DEC);
174 if ( eth.indexOf('\n') != -1 )
175 {
176 if (eth.indexOf(String("GET /")) !=-1 && eth.indexOf(String("HTTP")) !=-1 )
177 {
178 get_http_found = true;
179 // -- Cam on --
180 if (eth.indexOf(String(button_name[0])) !=-1){
181 Serial.println("User request: Enable Pump");
182 digitalWrite( FC_ON, HIGH);
183 if ((fc_on_time+3000) > fc_on_time)
184 fc_on_time += 3000;
185 }
186 // -- Cam Off --
187 else if (eth.indexOf(String(button_name[1])) !=-1)
188 {
189 Serial.println("User request: Disable Pump");
190 digitalWrite( FC_OFF, HIGH);
191 fc_off_time = 500;
192 }
193 // -- Drive Toggle --
194 else if (eth.indexOf(String(button_name[2])) !=-1)
195 {
196 Serial.println("User request: Toggle Drive");
197 x_signal = !x_signal;
198 digitalWrite( X, x_signal );
199 y_signal = !y_signal;
200 digitalWrite( Y, y_signal );
201 }
202 //else if (eth.indexOf(String("toggle_y=")) !=-1)
203 //{
204 // Serial.println("User request: Toggle Y");
205 // y_signal = !y_signal;
206 // digitalWrite( Y, y_signal );
207 //}
208 else
209 {
210 Serial.println("No User request - just sending webpage");
211 }
212
213 Serial.println("found it");
214 }
215 }
216 }
217
218 // if you've gotten to the end of the line (received a newline
219 // character) and the line is blank, the http request has ended,
220 // so you can send a reply
221 if (c == '\n' && currentLineIsBlank) {
222 // send a standard http response header
223 html_header( &client );
224 html_page( &client );
225 html_footer( &client );
226 break; // this breaks out of the while loop!!!
227 }
228 if (c == '\n') {
229 // you're starting a new line
230 currentLineIsBlank = true;
231 }
232 else if (c != '\r') {
233 // you've gotten a character on the current line
234 currentLineIsBlank = false;
235 }
236 }
237 }
238 // give the web browser time to receive the data
239 delay(1);
240 // close the connection:
241 client.stop();
242 Serial.println("client disonnected");
243 }
244 return got_client;
245}
246/////////////////////////////////////////////////////////////////////////////////////////////
247
248//////////// HTML Generators ////////////////////////////////////////////////////////////////
249void html_header(EthernetClient *client)
250{
251 // send a standard http response header
252 client->print("HTTP/1.1 200 OK\r\n");
253 client->print("Content-Type: text/html\r\n");
254 client->print("Connnection: close\r\n");
255 client->print("\r\n");
256 client->print("<!DOCTYPE HTML>\r\n");
257 client->print("<html><head>\r\n");
258
259 // add a meta refresh tag, so the browser pulls again every 5 seconds:
260 client->print("<meta http-equiv=\"refresh\" content=\"5; URL=index.html\" />\r\n");
261 client->print("<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\r\n");
262
263 client->print("<title>FACT camera power interlock control</title></head><body>\r\n");
264 client->print("<FORM NAME=\"Form\">\r\n");
265}
266
267void print_input_status( EthernetClient *client)
268{
269 for (int ch = 0; ch < 8; ch++)
270 {
271 client->print(my_input_names[ch]);
272 client->print(" :");
273 client->print(" ");
274 client->print("<span id=\"");
275 client->print(my_input_span_id[ch]);
276 client->print("\" title=\"");
277 if ( digitalRead(my_inputs[ch]) )
278 {
279 client->print("1\"> Yes");
280 //client->print(" Yes ");
281 }
282 else
283 {
284 client->print("0\"> No ");
285 //client->print(" No ");
286 }
287 client->print("</span> <br />\r\n");
288 }
289}
290
291void make_buttons( EthernetClient *client )
292{
293 for ( int button_id = 0; button_id < Number_of_Buttons; ++button_id )
294 {
295 client->print("<P><INPUT TYPE=\"SUBMIT\" NAME=\"");
296 client->print(button_name[button_id]);
297 client->print("\" VALUE=\"");
298 client->print(button_caption[button_id]);
299 client->print("\" ");
300
301 // the 'OFF' button should be disabled
302 // in case somebody just pressed the 'ON' button.
303 if (fc_on_time != 0 && button_id == 1){
304 client->print("disabled");
305 }
306
307 client->print(" /></P><br />\r\n");
308 }
309}
310
311
312void html_page( EthernetClient *client)
313{
314 make_buttons( client );
315 print_input_status( client );
316}
317
318void html_footer(EthernetClient *client)
319{
320 client->print("</FORM></body></html>\r\n\r\n\r\n");
321}
322
323
324//////////// HTML Generators ---- END /////////////////////////////////////////////////////////
325
326void
327Check_n_Set_FC_ON_OFF()
328{
329
330 unsigned long since_last = millis() - last_time;
331
332 if (since_last == 0)
333 {
334 // not even a milisecond passed by
335 // strange, should not happen
336 }
337 else if (since_last >= fc_on_time)
338 {
339 // FC_ON was long enough HIGH
340 fc_on_time = 0;
341 }
342 else if (since_last < fc_on_time)
343 {
344 // fc_on_time is decreased
345 fc_on_time -= since_last;
346 }
347
348 if (fc_on_time == 0)
349 {
350 digitalWrite( FC_ON, LOW);
351 }
352 else
353 {
354 //digitalWrite( FC_ON, HIGH);
355 }
356
357 if (since_last == 0)
358 {
359 // not even a milisecond passed by
360 // strange, should not happen
361 }
362 else if (since_last >= fc_off_time)
363 {
364 // FC_OFF was long enough HIGH
365 fc_off_time = 0;
366 }
367 else if (since_last < fc_off_time)
368 {
369 // fc_on_time is decreased
370 fc_off_time -= since_last;
371 }
372
373 if (fc_off_time == 0)
374 {
375 digitalWrite( FC_OFF, LOW);
376 }
377 else
378 {
379 //digitalWrite( FC_OFF, HIGH);
380 }
381
382 last_time = millis();
383}
384/////////////////////////////////////////////////////////////////////////////////////////////
385
Note: See TracBrowser for help on using the repository browser.