1 | 'use strict';
|
---|
2 |
|
---|
3 | // ==========================================================================
|
---|
4 | // Reset Crate
|
---|
5 | // ==========================================================================
|
---|
6 |
|
---|
7 | // call it with: .js doCrateReset.js crate0=true crate3=true
|
---|
8 | // or: DIM_CONTROL/START doCrateReset.js crate0=true crate3=true
|
---|
9 |
|
---|
10 | // -------------------------------------------------------------------------
|
---|
11 |
|
---|
12 | include('scripts/CheckStates.js');
|
---|
13 |
|
---|
14 | function crateReset(crate)
|
---|
15 | {
|
---|
16 | var msg = "Starting crate reset:";
|
---|
17 |
|
---|
18 | var cnt = 0;
|
---|
19 | for (var i=0; i<4; i++)
|
---|
20 | if (crate[i])
|
---|
21 | {
|
---|
22 | cnt++;
|
---|
23 | msg += " "+i;
|
---|
24 | }
|
---|
25 |
|
---|
26 | if (cnt==0)
|
---|
27 | {
|
---|
28 | console.out("No crate to reset.");
|
---|
29 | return;
|
---|
30 | }
|
---|
31 |
|
---|
32 | dim.log(msg);
|
---|
33 |
|
---|
34 | console.out("Checking availability of servers...");
|
---|
35 |
|
---|
36 | var table =
|
---|
37 | [
|
---|
38 | [ "MCP" ],
|
---|
39 | [ "FTM_CONTROL" ],
|
---|
40 | [ "FAD_CONTROL" ],
|
---|
41 | ];
|
---|
42 | if (!checkStates(table, 3000))
|
---|
43 | throw new Error("Either MCP, FTM_CONTROL or FAD_CONTROL not online.");
|
---|
44 |
|
---|
45 | // No data taking should be in progress
|
---|
46 | // Trigger must be switched off
|
---|
47 |
|
---|
48 | checkSend(["MCP", "FAD_CONTROL", "FTM_CONTROL" ]);
|
---|
49 |
|
---|
50 |
|
---|
51 | var mcp = dim.state("MCP");
|
---|
52 | if (mcp.name=="TriggerOn" || mcp.state=="TakingData")
|
---|
53 | dim.send("MCP/STOP");
|
---|
54 | if (mcp.name.substr(0,7)=="kConfig")
|
---|
55 | dim.send("MCP/RESET");
|
---|
56 | if (dim.state("FTM_CONTROL").name=="TriggerOn")
|
---|
57 | dim.send("FTM_CONTROL/STOP_TRIGGER");
|
---|
58 |
|
---|
59 | console.out("Checking status of servers...");
|
---|
60 |
|
---|
61 | var table =
|
---|
62 | [
|
---|
63 | [ "MCP", [ "Idle", "Connected" ]],
|
---|
64 | [ "FTM_CONTROL", [ "Valid" ] ],
|
---|
65 | [ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connecting", "Connected" ] ],
|
---|
66 | ];
|
---|
67 | if (!checkStates(table))
|
---|
68 | throw new Error("Either MCP, FTM_CONTROL or FAD_CONTROL not in a state in which it ought to be.");
|
---|
69 |
|
---|
70 | // FTUs must be switched off
|
---|
71 |
|
---|
72 | console.out("Disable FTUs...");
|
---|
73 |
|
---|
74 | //checkSend(["FTM_CONTROL"]);
|
---|
75 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, false);
|
---|
76 | v8.sleep(1000);
|
---|
77 |
|
---|
78 | // Boards in the crates must be disconnected
|
---|
79 |
|
---|
80 | //checkSend(["FAD_CONTROL"]);
|
---|
81 |
|
---|
82 | dim.log("Disconnecting crates.");
|
---|
83 |
|
---|
84 | if (dim.state("FAD_CONTROL").name=="Connecting" || dim.state("FAD_CONTROL").name=="Connected")
|
---|
85 | for (var i=0; i<10; i++)
|
---|
86 | {
|
---|
87 | for (var j=0; j<4; j++)
|
---|
88 | if (crate[j])
|
---|
89 | {
|
---|
90 | console.out("Sending DISCONNECT "+(j*10+i));
|
---|
91 | dim.send("FAD_CONTROL/DISCONNECT", j*10+i);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | v8.sleep(2000);
|
---|
96 | if (!checkStates([[ "FAD_CONTROL", [ "Disengaged", "Disconnected", "Connected" ] ]]))
|
---|
97 | throw new Error("FAD_CONTROL neither Disengaged, Disconnected not Connected.");
|
---|
98 |
|
---|
99 |
|
---|
100 | // Reset crates
|
---|
101 |
|
---|
102 | dim.log("Sending reset.");
|
---|
103 |
|
---|
104 | if (cnt==4)
|
---|
105 | dim.send("FTM_CONTROL/RESET_CAMERA");
|
---|
106 | else
|
---|
107 | {
|
---|
108 | for (var i=0; i<4; i++)
|
---|
109 | if (crate[i])
|
---|
110 | {
|
---|
111 | console.out("Sending RESET_CRATE "+i);
|
---|
112 | dim.send("FTM_CONTROL/RESET_CRATE", i);
|
---|
113 | }
|
---|
114 | }
|
---|
115 |
|
---|
116 | // We have to wait a bit
|
---|
117 |
|
---|
118 | v8.sleep(3200);
|
---|
119 |
|
---|
120 | // Reconnect all boards
|
---|
121 |
|
---|
122 | dim.log("Waiting for connection.");
|
---|
123 |
|
---|
124 | if (dim.state("FAD_CONTROL").name=="Disengaged")
|
---|
125 | {
|
---|
126 | dim.send("Waiting 38s for crates to finish reset.");
|
---|
127 | v8.sleep(38000);
|
---|
128 | dim.send("FAD_CONTROL", "START");
|
---|
129 | }
|
---|
130 | else
|
---|
131 | for (var i=0; i<10; i++)
|
---|
132 | {
|
---|
133 | v8.sleep(3200);
|
---|
134 | for (var j=0; j<4; j++)
|
---|
135 | if (crate[j])
|
---|
136 | {
|
---|
137 | console.out("Sending CONNECT "+(j*10+i));
|
---|
138 | dim.send("FAD_CONTROL/CONNECT", j*10+i);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | // Reconnect all FTUs
|
---|
144 |
|
---|
145 | console.out("Enable FTUs...");
|
---|
146 |
|
---|
147 | v8.sleep(1000);
|
---|
148 | dim.send("FTM_CONTROL/ENABLE_FTU", -1, true);
|
---|
149 | v8.sleep(3000);
|
---|
150 | dim.send("FTM_CONTROL/PING");
|
---|
151 | v8.sleep(1000);
|
---|
152 |
|
---|
153 | dim.wait("FAD_CONTROL", "Connected", 3000);
|
---|
154 |
|
---|
155 | // Done
|
---|
156 |
|
---|
157 | dim.log("Crate reset finished.");
|
---|
158 | }
|
---|