LCOV - code coverage report
Current view: top level - drivers/device - mdevice_mscb.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 27 0
Test Date: 2025-11-11 10:26:08 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :    mdevice_mscb.h
       3              : 
       4              :    Class mdevice_mscb derived from mdevice to create proper ODB settings under
       5              :    /Equipment/<name>/Settings for MSCB devices
       6              : 
       7              :    Created S. Ritt 11.04.2022
       8              : */
       9              : 
      10              : #include <cmath>
      11              : #include <history.h>
      12              : 
      13              : class mdevice_mscb : public mdevice {
      14              : public:
      15            0 :    mdevice_mscb(std::string eq_name, std::string dev_name,
      16              :            DWORD flags,
      17              :            std::string submaster,
      18              :            std::string pwd = "",
      19              :            int pause = 0,
      20            0 :            int retries = 10) : mdevice(eq_name, dev_name, flags, mscbdev){
      21              : 
      22            0 :       if (submaster.empty()) {
      23              :          char str[256];
      24            0 :          snprintf(str, sizeof(str), "device_mscb definition for equipment \"%s\" device \"%s\" has no submaster",
      25              :                  eq_name.c_str(), dev_name.c_str());
      26            0 :          cm_msg(MERROR, "device_mscb::device_mscb", "%s", str);
      27            0 :          mthrow(str);
      28              :          return;
      29              :       }
      30              : 
      31              :       // check flags
      32            0 :       if ((flags & DF_INPUT) == 0 && (flags & DF_OUTPUT) == 0) {
      33              :          char str[256];
      34            0 :          snprintf(str, sizeof(str), "Device \"%s\" for equipment \"%s\" must be either DF_INPUT or DF_OUTPUT",
      35              :                  dev_name.c_str(), eq_name.c_str());
      36            0 :          cm_msg(MERROR, "device::device", "%s", str);
      37            0 :          mthrow(str);
      38              :          return;
      39              :       }
      40              : 
      41              :       // create Settings/Devices in ODB
      42              :       midas::odb dev = {
      43              :               {"MSCB Device",  ""},
      44              :               {"MSCB Pwd",     ""},
      45            0 :               {"MSCB Address", 0},
      46            0 :               {"MSCB Index",   (UINT8) 0},
      47            0 :               {"MSCB Debug",   (INT32) 0},
      48            0 :               {"MSCB Retries", (INT32) 10},
      49            0 :               {"MSCB Pause",   (INT32) 0}
      50            0 :       };
      51            0 :       dev.connect("/Equipment/" + eq_name + "/Settings/Devices/" + dev_name);
      52            0 :       dev["MSCB Device"] = submaster;
      53            0 :       dev["MSCB Pwd"]    = pwd;
      54            0 :       dev["MSCB Pause"]  = pause;
      55            0 :       dev["MSCB Retries"]  = retries;
      56            0 :    }
      57              : 
      58            0 :    void define_var(int address, unsigned char var_index,
      59              :                    std::string name = "", double threshold = std::nan(""),
      60              :                    double factor = std::nan(""), double offset = std::nan("")) {
      61            0 :       mdevice::define_var(name, threshold, factor, offset);
      62              : 
      63              :       // put info into device subtreee
      64            0 :       mOdbDev["MSCB Address"][mNchannels-1] = address;
      65            0 :       mOdbDev["MSCB Index"][mNchannels-1] = var_index;
      66            0 :    }
      67              : 
      68              :    void define_varf(int address, unsigned char var_index,
      69              :                    std::string name, double threshold,
      70              :                    std::string formula) {
      71              :       mdevice::define_varf(name, threshold, formula);
      72              : 
      73              :       // put info into device subtreee
      74              :       mOdbDev["MSCB Address"][mNchannels-1] = address;
      75              :       mOdbDev["MSCB Index"][mNchannels-1] = var_index;
      76              :    }
      77              : 
      78              :    void define_varf(int address, unsigned char var_index,
      79              :                     std::string name, double threshold,
      80              :                     std::string formula, std::string unit) {
      81              :       mdevice::define_varf(name, threshold, formula, unit);
      82              : 
      83              :       // put info into device subtreee
      84              :       mOdbDev["MSCB Address"][mNchannels-1] = address;
      85              :       mOdbDev["MSCB Index"][mNchannels-1] = var_index;
      86              :    }
      87              : 
      88              :    void add_func(void func(midas::odb &)) {
      89              :       mOdbVars["Input"].watch(func);
      90              :    }
      91              : 
      92              : };
        

Generated by: LCOV version 2.0-1