source: trunk/FACT++/scripts/handleFadConnected.js@ 16827

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