Changeset 15284
- Timestamp:
- 04/09/13 09:48:54 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r15270 r15284 5 5 'use strict'; 6 6 7 dim.log("Start: "+__FILE__+" ["+__DATE__+"]"); 8 7 9 //dimctrl.defineState(37, "TimeOutBeforeTakingData", "MCP took more than 5minutes to start TakingData"); 8 10 … … 93 95 // ================================================================ 94 96 97 var sub_incomplete = new Subscription("FAD_CONTROL/INCOMPLETE"); 98 99 var incomplete = 0; 100 101 sub_incomplete.onchange = function(evt) 102 { 103 if (!evt) 104 return; 105 106 var inc = evt.data[0];//obj['incomplete']; 107 if (!inc) 108 return; 109 110 if ((evt.time - this.last_time)<5000 && this.last_inc==inc) 111 return; 112 113 incomplete = inc; 114 115 var reset = [ ]; 116 117 for (var i=0; i<40; i++) 118 if (inc&(1<<i)) 119 { 120 console.out(" FAD %2d".$(i)+" lost during data taking."); 121 reset.push(parseInt(i/10)); 122 } 123 124 if (reset.length>10) 125 return; 126 127 dim.send("MCP/RESET"); 128 129 reset = reset.filter(function(elem,pos){return reset.indexOf(elem)==pos;}); 130 131 if (reset.length>0) 132 { 133 console.out(""); 134 console.out(" FADs belong to crate(s): "+reset); 135 console.out(""); 136 } 137 138 this.last_time = evt.time; 139 this.last_inc = inc; 140 } 141 95 142 var sub_connections = new Subscription("FAD_CONTROL/CONNECTIONS"); 96 143 … … 100 147 * 101 148 */ 149 /* 102 150 sub_connections.onchange = function(evt) 103 151 { 104 return;105 106 152 // This happens, but why? 107 153 if (!evt.obj['status']) … … 121 167 dim.send("FAD_CONTROL/CLOSE_OPEN_FILES"); 122 168 } 169 */ 123 170 124 171 /** … … 234 281 console.out(""); 235 282 236 if (dim.state("MCP").name=="Configuring3" && 237 dim.state("FAD_CONTROL").name=="Configuring2") 283 if (dim.state("MCP").name!="Configuring3" || 284 dim.state("FAD_CONTROL").name!="Configuring2") 285 throw e; 286 287 console.out(""); 288 console.out("Waiting for fadctrl to get configured timed out... checking for in-run FAD loss."); 289 290 var con = sub_connections.get(); 291 var stat = con.obj['status']; 292 293 console.out("Sending MCP/RESET"); 294 dim.send("MCP/RESET"); 295 296 dim.wait("FTM_CONTROL", "Idle", 3000); 297 dim.wait("FAD_CONTROL", "Connected", 3000); 298 dim.wait("MCP", "Idle", 3000); 299 300 var reset = [ ]; 301 302 for (var i=0; i<40; i++) 303 if (stat[i]!=0x43) 304 { 305 console.out(" FAD %2d".$(i)+" not in Configured state."); 306 reset.push(parseInt(i/10)); 307 } 308 309 reset = reset.filter(function(elem,pos){return reset.indexOf(elem)==pos;}); 310 311 if (reset.length>0) 238 312 { 239 313 console.out(""); 240 console.out(" Waiting for fadctrl to get configured timed out... checking for FAD loss.");314 console.out(" FADs belong to crate(s): "+reset); 241 315 console.out(""); 242 243 var con = sub_connections.get(); 244 var stat = con.obj['status']; 245 246 var reset = [ ]; 247 248 for (var i=0; i<40; i++) 249 if (stat[i]!=0x43) 250 { 251 console.out(" FAD %2d".$(i)+" not in Configured state."); 252 reset.push(parseInt(i/10)); 253 } 254 255 reset = reset.filter(function(elem,pos){return reset.indexOf(elem)==pos;}); 256 257 if (reset.length>0) 316 } 317 318 console.out(""); 319 console.out("Trying automatic reconnect..."); 320 321 for (var i=0; i<40; i++) 322 if (stat[i]!=0x43) 258 323 { 259 console.out(""); 260 console.out(" FADs belong to crate(s): "+reset); 261 console.out(""); 324 console.out(" ...disconnect ", i); 325 dim.send("FAD_CONTROL/DISCONNECT", i); 262 326 } 263 } 264 265 console.out("Sending MCP/RESET"); 266 dim.send("MCP/RESET"); 267 268 // If it works, we can decide here what to do... 327 328 console.out(" ...waiting for 5s"); 329 v8.sleep(5000); 330 331 for (var i=0; i<40; i++) 332 if (stat[i]!=0x43) 333 { 334 console.out(" ...reconnect ", i); 335 dim.send("FAD_CONTROL/CONNECT", i); 336 } 337 338 console.out(" ...waiting for 1s"); 339 v8.sleep(1000); 340 console.out(""); 269 341 270 342 throw e; … … 272 344 273 345 dim.wait("MCP", "Idle", time>0 ? time*1250 : undefined); // run time plus 25% 346 347 if (incomplete) 348 { 349 console.out(""); 350 console.out("Trying automatic reconnect..."); 351 352 for (var i=0; i<40; i++) 353 if (incomplete&(1<<i)) 354 { 355 console.out(" ...disconnect ", i); 356 dim.send("FAD_CONTROL/DISCONNECT", i); 357 } 358 359 console.out(" ...waiting for 5s"); 360 v8.sleep(5000); 361 362 for (var i=0; i<40; i++) 363 if (incomplete&(1<<i)) 364 { 365 console.out(" ...reconnect ", i); 366 dim.send("FAD_CONTROL/CONNECT", i); 367 } 368 369 console.out(" ...waiting for 1s"); 370 v8.sleep(1000); 371 console.out(""); 372 373 incomplete = 0; 374 375 throw new Error("In-run FAD loss detected."); 376 } 274 377 275 378 //console.out(" Take run: end"); … … 331 434 function OpenLid() 332 435 { 333 var horizon_parameter = "nautical";334 while (Sun.horizon( horizon_parameter).isUp)436 /* 437 while (Sun.horizon(-13).isUp) 335 438 { 336 439 var now = new Date(); 337 var minutes_until_sunset = (Sun.horizon( horizon_parameter).set - now)/60000;440 var minutes_until_sunset = (Sun.horizon(-13).set - now)/60000; 338 441 console.out(now.toUTCString()+": Sun above FACT-horizon, lid cannot be opened: sleeping 1min, remaining %.1fmin".$(minutes_until_sunset)); 339 442 v8.sleep(60000); 340 } 443 }*/ 341 444 342 445 var isClosed = dim.state("LID_CONTROL").name=="Closed"; … … 596 699 console.out(""); 597 700 console.out("Shutdown: end ["+(new Date()-now)/1000+"s]"); 701 702 sub.close(); 598 703 } 599 704 … … 625 730 dim.send("FEEDBACK/START_CURRENT_CONTROL", 0.); 626 731 732 v8.timeout(3000, function() { var n = dim.state("FEEDBACK").name; if (n=="CurrentCtrlIdle" || n=="CurrentControl") return true; }); 733 627 734 // ---------------------------------------------------------------- 628 735 // Connect to the DRS_RUNS service … … 632 739 var sub_drsruns = new Subscription("FAD_CONTROL/DRS_RUNS"); 633 740 sub_drsruns.get(5000); 634 635 741 // FIXME: Check if the last DRS calibration was complete? 742 743 function getTimeSinceLastDrsCalib() 744 { 745 // ----- Time since last DRS Calibration [min] ------ 746 var runs = sub_drsruns.get(0); 747 var diff = (new Date()-runs.time)/60000; 748 749 // Warning: 'roi=300' is a number which is not intrisically fixed 750 // but can change depending on the taste of the observers 751 var valid = runs.obj['run'][2]>0 && runs.obj['roi']==300; 752 753 if (valid) 754 console.out(" Last DRS calib: %.1fmin ago".$(diff)); 755 else 756 console.out(" No valid drs calibration available"); 757 758 return valid ? diff : null; 759 } 636 760 637 761 // ---------------------------------------------------------------- … … 664 788 var sub; 665 789 var lastObs; 790 var sun = Sun.horizon(-13); 666 791 667 792 while (1) … … 673 798 break; 674 799 675 // FIXME: Check missing whether a shutdown is needed...676 677 800 // we are still waiting for the first observation in the schedule 678 801 if (idxObs==-1) … … 684 807 } 685 808 809 // Check if we have to take action do to sun-rise 810 var was_up = sun.isUp; 811 sun = Sun.horizon(-13); 812 if (!was_up && sun.isUp) 813 { 814 console.out("Sun rise detected.... automatic shutdown initiated!"); 815 // FIXME: State check? 816 Shutdown(); 817 continue; 818 } 819 820 // Current and next observation target 686 821 var obs = observations[idxObs]; 687 822 var nextObs = observations[idxObs+1]; … … 725 860 { 726 861 v8.sleep(1000); 862 continue; 863 } 864 865 // Check if sun is still up... only DATA and RATESCAN must be suppressed 866 if ((obs[sub].task=="DATA" || obs[sub].task=="RATESCAN") && sun.isUp) 867 { 868 var now = new Date(); 869 var remaining = (sun.set - now)/60000; 870 console.out(now.toUTCString()+" - "+obs[sub].task+": Sun above FACT-horizon: sleeping 1min, remaining %.1fmin".$(remaining)); 871 v8.sleep(60000); 727 872 continue; 728 873 } … … 805 950 console.out(" SINGLE-PE", ""); 806 951 807 // FIXME: Check whether a DRS calib is necessary.808 809 952 // The lid must be closes 810 953 CloseLid(); 954 955 // Check if DRS calibration is necessary 956 var diff = getTimeSinceLastDrsCalib(); 957 if (diff>30 || diff==null) 958 doDrsCalibration("singlepe"); // will turn voltage off 811 959 812 960 // The voltage must be on … … 886 1034 887 1035 // ----- Time since last DRS Calibration [min] ------ 888 var runs = sub_drsruns.get(0); 889 var diff = (new Date()-runs.time)/60000; 890 891 // Warning: 'roi=300' is a number which is not intrisically fixed 892 // but can change depending on the taste of the observers 893 var valid = runs.obj['run'][2]>0 && runs.obj['roi']==300; 894 895 if (valid) 896 console.out(" Last DRS calib: %.1fmin ago".$(diff)); 897 else 898 console.out(" No valid drs calibration available"); 1036 var diff = getTimeSinceLastDrsCalib(); 899 1037 900 1038 // Changine pointing position and take calibration... … … 910 1048 // ...when more than 15min of observation are left 911 1049 // ...no drs calibration was done yet 912 var drscal = (run%4==0 && (remaining>15 && diff>70)) || !valid;1050 var drscal = (run%4==0 && (remaining>15 && diff>70)) || diff==null; 913 1051 914 1052 if (point)
Note:
See TracChangeset
for help on using the changeset viewer.