Changeset 18223


Ignore:
Timestamp:
06/18/15 11:31:49 (9 years ago)
Author:
dneise
Message:
made library and function from script with side-effects. function is called in Startup.js now.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FACT++_scripts_refactoring/CheckFTU.js

    r16794 r18223  
    11'use strict';
    22
    3 var service_ftm = new Subscription("FTM_CONTROL/FTU_LIST");
     3if (!("CheckFTU" in this)){
     4    var CheckFTU = {
     5        checkFTU : function(){
     6            console.out("Checking FTU: start");
    47
    5 // Make sure that we receive a 'Yes, we are connected and names are available' event
    6 service_ftm.get(5000);
     8            var service_ftm = new Subscription("FTM_CONTROL/FTU_LIST");
    79
    8 // Check for all FTUs to be connected when the next event arrives
    9 service_ftm.onchange = function(event)
    10 {
    11     var ping = event.obj['Ping'];
    12     for (var i=0; i<40; i++)
    13     {
    14         if (ping[i]==1)
    15             continue;
     10            // Make sure that we receive a 'Yes, we are connected and names are available' event
     11            service_ftm.get(5000);
    1612
    17         var str = "";
    18         for (var h=0; h<4; h++)
    19         {
    20             for (var w=0; w<10; w++)
    21                 str += ping[h*10+w];
    22             if (h!=3)
    23                 str += '|';
    24         }
     13            // Check for all FTUs to be connected when the next event arrives
     14            service_ftm.onchange = function(event)
     15            {
     16                var ping = event.obj['Ping'];
     17                for (var i=0; i<40; i++)
     18                {
     19                    if (ping[i]==1)
     20                        continue;
    2521
    26         console.out(str)
     22                    var str = "";
     23                    for (var h=0; h<4; h++)
     24                    {
     25                        for (var w=0; w<10; w++)
     26                            str += ping[h*10+w];
     27                        if (h!=3)
     28                            str += '|';
     29                    }
    2730
    28         console.out("Problems in the FTU communication found.");
    29         console.out("Send command to disable all FTUs.");
    30         console.out(" => Crate reset needed.");
     31                    console.out(str)
    3132
    32         dim.send("FTM_CONTROL/ENABLE_FTU", -1, false);
    33         throw new Error("CrateReset[FTU]");
    34     }
     33                    console.out("Problems in the FTU communication found.");
     34                    console.out("Send command to disable all FTUs.");
     35                    console.out(" => Crate reset needed.");
    3536
    36     // Signal success by closing the connection
    37     service_ftm.close();
     37                    dim.send("FTM_CONTROL/ENABLE_FTU", -1, false);
     38                    throw new Error("CrateReset[FTU]");
     39                }
     40
     41                // Signal success by closing the connection
     42                service_ftm.close();
     43            }
     44
     45            // Send ping (request FTU status)
     46            dim.send("FTM_CONTROL/PING");
     47
     48            // Wait for 1 second for the answer
     49            var timeout = new Thread(3000, function(){ if (service_ftm.isOpen) throw new Error("Could not check that all FTUs are ok within 3s."); });
     50            while (service_ftm.isOpen)
     51                v8.sleep();
     52
     53            console.out("Checking FTU: done");
     54            console.out("");
     55        },
     56    };
    3857}
    39 
    40 // Send ping (request FTU status)
    41 dim.send("FTM_CONTROL/PING");
    42 
    43 // Wait for 1 second for the answer
    44 var timeout = new Thread(3000, function(){ if (service_ftm.isOpen) throw new Error("Could not check that all FTUs are ok within 3s."); });
    45 while (service_ftm.isOpen)
    46     v8.sleep();
    47 
     58else{
     59    console.out("multiple include of 'CheckFTU.js'");
     60}
Note: See TracChangeset for help on using the changeset viewer.