• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

plugin/src/NxCalibrModule.cxx (r4864/r3096)

Go to the documentation of this file.
00001 #include "roc/NxCalibrModule.h"
00002 
00003 #include "dabc/Command.h"
00004 #include "dabc/CommandsSet.h"
00005 
00006 //#include "roc/Commands.h"
00007 #include "roc/Message.h"
00008 #include "roc/Board.h"
00009 
00010 #include "roc/defines_roc.h"
00011 #include "roc/defines_udp.h"
00012 
00013 roc::NxCalibrModule::NxCalibrModule(const char* name, dabc::Command cmd, roc::Board* brd) :
00014    dabc::ModuleAsync(name, cmd),
00015    fBrd(brd),
00016    fWorkPeriod(100.),
00017    fCalibrPeriod(1.),
00018    fLoopCounts(0),
00019    fState(0)
00020 {
00021    CreateTimer("CalibrTimer", -1., false);
00022 
00023    fWorkPeriod = Cfg("WorkPeriod", cmd).AsDouble(100.);
00024    fCalibrPeriod = Cfg("CalibrPeriod", cmd).AsDouble(1.);
00025 
00026    fLoopCounts = Cfg("CalibrLoops", cmd).AsInt(0);
00027 }
00028 
00029 roc::NxCalibrModule::~NxCalibrModule()
00030 {
00031 }
00032 
00033 int roc::NxCalibrModule::ExecuteCommand(dabc::Command cmd)
00034 {
00035    if (cmd.IsName("enableCalibration")) {
00036       fWorkPeriod = cmd.GetDouble("WorkPeriod", 100.);
00037       fCalibrPeriod = cmd.GetDouble("CalibrPeriod", 1.);
00038       fLoopCounts = cmd.GetInt("CalibrLoops", 0);
00039 
00040 //      DOUT0(("Executing enableCalibration cnt:%d  state:%d", fLoopCounts, fState));
00041 
00042       if ((fLoopCounts!=0) && (fState==0)) {
00043          fState = 1;
00044          ShootTimer("CalibrTimer", fWorkPeriod);
00045          DOUT0(("Shoot timer %f", fWorkPeriod));
00046 
00047       } else
00048       if (fLoopCounts==0) {
00049         if (fState==2) {
00050            // when disabling, ensure that commands are executed
00051            fState = 0;
00052            return switchCalibration(false);
00053         } else
00054            fState = 0;
00055       }
00056       return dabc::cmd_true;
00057    }
00058    return dabc::ModuleAsync::ExecuteCommand(cmd);
00059 }
00060 
00061 
00062 void roc::NxCalibrModule::ProcessTimerEvent(dabc::Timer* timer)
00063 {
00064 //   DOUT0(("ProcessTimerEvent state:%d", fState));
00065 
00066    if (fState==0) return;
00067 
00068    if (fState==1) {
00069       if (fLoopCounts==0)
00070          fState = 0;
00071       else {
00072          switchCalibration(true);
00073          fState = 2;
00074          ShootTimer("CalibrTimer", fCalibrPeriod);
00075       }
00076    } else {
00077       switchCalibration(false);
00078 
00079       if (fLoopCounts>0) fLoopCounts--;
00080       if (fLoopCounts==0) {
00081          fState = 0;
00082       } else {
00083          ShootTimer("CalibrTimer", fWorkPeriod);
00084          fState = 1;
00085       }
00086    }
00087 }
00088 
00089 
00090 int roc::NxCalibrModule::switchCalibration(bool on)
00091 {
00092 //   DOUT0(("switchCalibration %s", DBOOL(on)));
00093 
00094    if (fBrd==0) return dabc::cmd_false;
00095 
00096    base::OperList lst;
00097 
00098    lst.addPut(ROC_ADDSYSMSG, roc::SYSMSG_USER_RECONFIGURE);
00099    lst.addPut(ROC_NX_FIFO_RESET, 1);
00100    lst.addPut(ROC_NX_FIFO_RESET, 0);
00101 //   for (int n=0;n<1000;n++) 
00102    lst.addGet(ROC_HWV);
00103    
00104    lst.addPut(ROC_ADDSYSMSG, on ? roc::SYSMSG_USER_CALIBR_ON : roc::SYSMSG_USER_CALIBR_OFF);
00105 
00106    int res = fBrd->operGen(lst);
00107 
00108    return res==0 ? dabc::cmd_true : dabc::cmd_false;
00109 }

Generated on Tue Dec 10 2013 04:52:23 for ROCsoft by  doxygen 1.7.1