source: branches/FACT++_lidctrl_new_eth/scripts/handleFadConnected.js@ 18910

Last change on this file since 18910 was 18110, checked in by tbretz, 10 years ago
Fixed a typo in a log-text.
File size: 2.0 KB
Line 
1'use strict';
2
3// Get fad control connected
4function handleFadConnected(wait_state)
5{
6 var state = dim.state("FAD_CONTROL");
7 if (state===undefined)
8 return undefined;
9
10 if (wait_state && wait_state.length>0 && state.name!=wait_state)
11 return wait_state;
12
13 //dim.log("BIAS_CONTROL: "+state.name+"["+state.index+"]");
14
15 switch (state.name)
16 {
17 case "Offline":
18 return undefined;
19
20 case "Disconnected":
21 console.out("Fadctrl in 'Disconnected'... sending START... waiting for 'Connected'.");
22 dim.send("FAD_CONTROL/START");
23 return "Connected";
24
25 // Do-nothing conditions
26 case "Connecting":
27 return wait_state;
28
29 // Do-something conditions
30 case "Configuring1":
31 case "Configuring2":
32 case "Configuring3":
33 case "Configured":
34 console.out("Fadctrl in Configure state... sending RESET_CONFIGURE... waiting for 'Connected'.");
35 dim.send("FAD_CONTROL/RESET_CONFIGURE");
36 return "Connected";
37
38 case "Disengaged":
39 console.out("Fadctrl in 'Disengaged'... sending START... waiting for 'Connected'.");
40 dim.send("FAD_CONTROL/START");
41 return "Connected";
42
43 case "RunInProgress":
44 console.out("Fadctrl in 'RunInProgress'... sending CLOSE_OPEN_FILES... waiting for 'Connected'.");
45 dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
46 return "Connected";
47
48 // Final state reached condition
49 case "Connected":
50 var sub_con = new Subscription("FAD_CONTROL/CONNECTIONS");
51 var con = sub_con.get(5000);
52 var all = true;
53 for (var i=0; i<40; i++)
54 if (con.obj['status'][i]&66!=66)
55 {
56 console.out("Board "+i+" not connected... sending CONNECT... waiting for 'Connected'.");
57 dim.send("FAD_CONTROL/CONNECT", i);
58 all = false;
59 }
60 sub_con.close();
61 return all ? "" : "Connected";
62 }
63
64 throw new Error("FAD_CONTROL:"+state.name+"["+state.index+"] unknown or not handled.");
65}
Note: See TracBrowser for help on using the repository browser.