ifw-fcf  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
deviceConfig.hpp
Go to the documentation of this file.
1 
9 #ifndef FCF_DEVMGR_COMMON_DEVICECONFIG_HPP_
10 #define FCF_DEVMGR_COMMON_DEVICECONFIG_HPP_
11 
12 // System headers
13 #include <string>
14 #include <unordered_map>
15 
16 // Third party headers
17 #include <yaml-cpp/yaml.h>
18 
19 #include <fcf/common/iComm.hpp>
22 
23 namespace fcf {
24  namespace devmgr {
25  namespace common {
26 
27  // Constants for common configuration
28  constexpr auto CI_IDENTIFIER = "identifier";
29  constexpr auto CI_SIMULATED = "simulated";
30  constexpr auto CI_IGNORED = "ignored";
31  constexpr auto CI_ADDRESS = "address";
32  constexpr auto CI_SIM_ADDRESS = "simaddr";
33  constexpr auto CI_TYPE = "type";
34  constexpr auto CI_PREFIX = "prefix";
35  constexpr auto CI_NAMESPACE = "namespace";
36  constexpr auto CI_MAP_FILE = "mapfile";
37  constexpr auto CI_FITS_PREFIX = "fits_prefix";
38  constexpr auto CI_ALIAS = "alias";
39  constexpr auto CI_CFG_FILE = "cfgfile";
40  constexpr auto CI_CTRL_CONFIG = "ctrl_config";
41 
42  // Constants for common RPC calls
43  constexpr auto RPC_INIT = "rpcInit";
44  constexpr auto RPC_ENABLE = "rpcEnable";
45  constexpr auto RPC_DISABLE = "rpcDisable";
46  constexpr auto RPC_STOP = "rpcStop";
47  constexpr auto RPC_RESET = "rpcReset";
48 
49  // Constants for common status attributes
50  constexpr auto CI_STAT_SUBSTATE = "substate";
51  constexpr auto CI_STAT_STATE = "state";
52  constexpr auto CI_STAT_STATU = "status";
53  constexpr auto CI_STAT_LOCAL = "local";
54  constexpr auto CI_STAT_ERROR_CODE = "error_code";
55  constexpr auto CI_STAT_ERROR_STR = "error_str";
56  constexpr auto DB_CONTROLLER_PREFIX = "lcs";
57 
58  // Constants for address categories
59  constexpr auto CAT_STAT = "stat";
60  constexpr auto CAT_CFG = "cfg";
61  constexpr auto CAT_RPC = "rpc";
62 
63  // Constants for state values
64  constexpr int STATE_NOT_OPERATIONAL = 1;
65  constexpr int STATE_OPERATIONAL = 2;
66 
67  constexpr auto STATE_NOT_OPERATIONAL_STR = "NotOperational";
68  constexpr auto STATE_OPERATIONAL_STR = "Operational";
69  constexpr auto STATE_UNAVAILABLE_STR = "Unavailable";
70 
71  const std::unordered_map<short, std::string> StateMap = {
74  };
75 
76  const std::unordered_map<std::string, short> StateStrMap = {
79  };
80 
81  // Constants for substate values
82  constexpr int SUBSTATE_NOTREADY = 100;
83  constexpr int SUBSTATE_READY = 101;
84  constexpr int SUBSTATE_INITIALISING = 102;
85  constexpr int SUBSTATE_ERROR = 199;
86 
87  constexpr auto SUBSTATE_NOTREADY_STR = "NotReady";
88  constexpr auto SUBSTATE_INITIALISING_STR = "Initialising";
89  constexpr auto SUBSTATE_READY_STR = "Ready";
90  constexpr auto SUBSTATE_ERROR_STR = "Error";
91 
92  constexpr int SUBSTATE_OP_DISABLING = 205;
93  constexpr int SUBSTATE_OP_ERROR = 299;
94 
95  constexpr auto SUBSTATE_OP_DISABLING_STR = "Disabling";
96  constexpr auto SUBSTATE_OP_ERROR_STR = "OpError";
97 
98  constexpr auto FITS_PARAM_ID = "ID";
99  constexpr auto FITS_PARAM_NAME = "NAME";
100  constexpr auto FITS_PARAM_STAT = "STAT";
101  constexpr auto FITS_PARAM_DEVSIM = "DEVSIM";
102  constexpr auto FITS_PARAM_DEVIGN = "DEVIGN";
103 
104  // Type definitions
110 
111 
112  using MapCfgBool = std::map<int, CfgBool>;
113  using MapCfgShort = std::map<int, CfgShort>;
114  using MapCfgInt = std::map<int, CfgInt>;
115  using MapCfgUInt = std::map<int, CfgUInt>;
116  using MapCfgDouble = std::map<int, CfgDouble>;
117 
125  class DeviceConfig : public IDeviceConfig {
126 
127  public:
133  DeviceConfig(const std::string& filename, const std::string& name);
134 
138  virtual ~DeviceConfig();
139 
144  bool Init();
145 
154  virtual void ReadConfig();
155 
163  virtual void GetConfig(fcf::common::VectorVariant& params);
164 
169  std::string GetIdentifier();
170 
174  std::string GetPrefix();
175 
180  std::string GetAddress();
181 
186  std::string GetSimAddress();
187 
192  std::string GetFitsPrefix();
193 
194 
198  std::string GetType();
199 
204  int GetNamespace();
205 
210  std::string GetAlias();
211 
216  std::string GetName();
217 
226  std::string GetNodeId(const std::string& attrib);
227 
238  std::string GetProcId(const std::string& attrib);
239 
249  std::string GetObjId();
250 
260  virtual void GetConfigList(std::vector<std::string>& cfg_list, std::string prefix);
261 
266  std::string GetCfgFile();
267 
268 
273  virtual void SetSimulateFlag(bool flag);
274 
279  virtual void SetIgnoreFlag(bool flag);
280 
285  virtual bool GetIgnored();
286 
291  virtual bool GetSimulated();
292 
297  virtual std::string GetMapFile();
298 
299  protected:
300  // All configuration parameters related to the LCS are stored in
301  // dedicated STL maps to make them easilly accessible when downloading
302  // the configuration to the LCS.
308 
309  std::string m_filename;
310  std::string m_name;
311  YAML::Node m_config_node;
312  std::string m_identifier;
313  std::string m_type;
314  std::string m_fits_prefix;
316  bool m_ignored;
317  std::string m_lcs_prefix;
318  std::string m_address;
319  std::string m_sim_address;
320  std::string m_map_file;
321  std::string m_alias;
323  };
324 
325  }
326  }
327 }
328 
329 
330 #endif //FCF_DEVMGR_COMMON_DEVICECONFIG_HPP_
constexpr auto CI_TYPE
Definition: deviceConfig.hpp:33
constexpr auto CI_STAT_LOCAL
Definition: deviceConfig.hpp:53
virtual void GetConfig(fcf::common::VectorVariant &params)
Obtain the list of configuration parameters.
Definition: deviceConfig.cpp:258
constexpr auto CI_MAP_FILE
Definition: deviceConfig.hpp:36
constexpr auto RPC_INIT
Definition: deviceConfig.hpp:43
constexpr auto CI_IGNORED
Definition: deviceConfig.hpp:30
constexpr auto FITS_PARAM_NAME
Definition: deviceConfig.hpp:99
constexpr auto CI_SIMULATED
Definition: deviceConfig.hpp:29
constexpr auto CAT_CFG
Definition: deviceConfig.hpp:60
constexpr int SUBSTATE_INITIALISING
Definition: deviceConfig.hpp:84
constexpr auto SUBSTATE_NOTREADY_STR
Definition: deviceConfig.hpp:87
bool m_simulated
Definition: deviceConfig.hpp:315
std::string m_address
Definition: deviceConfig.hpp:318
MapCfgInt m_map_cfg_int
Definition: deviceConfig.hpp:305
std::map< int, CfgShort > MapCfgShort
Definition: deviceConfig.hpp:113
constexpr auto CI_STAT_ERROR_STR
Definition: deviceConfig.hpp:55
std::string m_type
Device type.
Definition: deviceConfig.hpp:313
constexpr auto CAT_RPC
Definition: deviceConfig.hpp:61
int m_lcs_namespace
Definition: deviceConfig.hpp:322
MapCfgUInt m_map_cfg_uint
Definition: deviceConfig.hpp:306
std::string GetNodeId(const std::string &attrib)
Get node id.
Definition: deviceConfig.cpp:372
std::string m_identifier
Address space identifier.
Definition: deviceConfig.hpp:312
constexpr auto SUBSTATE_OP_DISABLING_STR
Definition: deviceConfig.hpp:95
const std::unordered_map< short, std::string > StateMap
Definition: deviceConfig.hpp:71
constexpr auto DB_CONTROLLER_PREFIX
Definition: deviceConfig.hpp:56
constexpr auto CI_ALIAS
Definition: deviceConfig.hpp:38
constexpr auto CI_STAT_SUBSTATE
Definition: deviceConfig.hpp:50
bool Init()
Initialises a device.
Definition: deviceConfig.cpp:43
constexpr auto RPC_DISABLE
Definition: deviceConfig.hpp:45
constexpr auto FITS_PARAM_ID
Definition: deviceConfig.hpp:98
MapCfgShort m_map_cfg_short
Definition: deviceConfig.hpp:304
constexpr int SUBSTATE_OP_DISABLING
Definition: deviceConfig.hpp:92
std::string GetProcId(const std::string &attrib)
Get procedure id.
Definition: deviceConfig.cpp:379
std::string m_sim_address
Definition: deviceConfig.hpp:319
MapCfgDouble m_map_cfg_double
Definition: deviceConfig.hpp:307
constexpr auto CAT_STAT
Definition: deviceConfig.hpp:59
std::string GetSimAddress()
Definition: deviceConfig.cpp:324
constexpr auto STATE_NOT_OPERATIONAL_STR
Definition: deviceConfig.hpp:67
constexpr int STATE_OPERATIONAL
Definition: deviceConfig.hpp:65
std::string GetType()
Definition: deviceConfig.cpp:343
constexpr auto FITS_PARAM_STAT
Definition: deviceConfig.hpp:100
virtual bool GetIgnored()
Get ignored flag.
Definition: deviceConfig.cpp:336
DeviceConfig(const std::string &filename, const std::string &name)
DeviceConfig constructor.
Definition: deviceConfig.cpp:28
constexpr auto CI_CTRL_CONFIG
Definition: deviceConfig.hpp:40
constexpr auto FITS_PARAM_DEVSIM
Definition: deviceConfig.hpp:101
constexpr auto STATE_UNAVAILABLE_STR
Definition: deviceConfig.hpp:69
YAML::Node m_config_node
YAML node object for configuration file.
Definition: deviceConfig.hpp:311
std::string GetAddress()
Definition: deviceConfig.cpp:318
virtual void GetConfigList(std::vector< std::string > &cfg_list, std::string prefix)
Get configuration list.
Definition: deviceConfig.cpp:392
MapCfgBool m_map_cfg_bool
Definition: deviceConfig.hpp:303
constexpr auto STATE_OPERATIONAL_STR
Definition: deviceConfig.hpp:68
configSet class header file.
std::map< int, CfgBool > MapCfgBool
Definition: deviceConfig.hpp:112
constexpr auto CI_ADDRESS
Definition: deviceConfig.hpp:31
std::string m_fits_prefix
Definition: deviceConfig.hpp:314
constexpr auto RPC_STOP
Definition: deviceConfig.hpp:46
std::string GetIdentifier()
Definition: deviceConfig.cpp:306
std::string GetAlias()
Definition: deviceConfig.cpp:367
constexpr auto CI_STAT_STATE
Definition: deviceConfig.hpp:51
virtual void SetIgnoreFlag(bool flag)
Set ignore flag.
Definition: deviceConfig.cpp:460
IDeviceConfig class header file.
constexpr int SUBSTATE_NOTREADY
Definition: deviceConfig.hpp:82
std::string m_name
device identifier
Definition: deviceConfig.hpp:310
std::string m_alias
Definition: deviceConfig.hpp:321
virtual void ReadConfig()
Read the configuration.
Definition: deviceConfig.cpp:154
constexpr auto CI_NAMESPACE
Definition: deviceConfig.hpp:35
constexpr auto CI_IDENTIFIER
Definition: deviceConfig.hpp:28
std::string GetName()
Definition: deviceConfig.cpp:362
std::map< int, CfgUInt > MapCfgUInt
Definition: deviceConfig.hpp:115
std::string m_filename
filename of device configuration file
Definition: deviceConfig.hpp:309
std::map< int, CfgInt > MapCfgInt
Definition: deviceConfig.hpp:114
constexpr auto SUBSTATE_OP_ERROR_STR
Definition: deviceConfig.hpp:96
std::string GetCfgFile()
GetCfgFile.
Definition: deviceConfig.cpp:450
constexpr auto SUBSTATE_INITIALISING_STR
Definition: deviceConfig.hpp:88
std::string m_map_file
Definition: deviceConfig.hpp:320
constexpr auto CI_PREFIX
Definition: deviceConfig.hpp:34
std::map< int, CfgDouble > MapCfgDouble
Definition: deviceConfig.hpp:116
constexpr auto SUBSTATE_READY_STR
Definition: deviceConfig.hpp:89
constexpr auto CI_STAT_STATU
Definition: deviceConfig.hpp:52
constexpr auto CI_SIM_ADDRESS
Definition: deviceConfig.hpp:32
constexpr int SUBSTATE_OP_ERROR
Definition: deviceConfig.hpp:93
const std::unordered_map< std::string, short > StateStrMap
Definition: deviceConfig.hpp:76
std::string GetPrefix()
Definition: deviceConfig.cpp:312
constexpr auto RPC_RESET
Definition: deviceConfig.hpp:47
virtual ~DeviceConfig()
DeviceConfig destructor.
Definition: deviceConfig.cpp:39
std::string GetObjId()
Get object id.
Definition: deviceConfig.cpp:385
Device Configuration class.
Definition: deviceConfig.hpp:125
constexpr auto FITS_PARAM_DEVIGN
Definition: deviceConfig.hpp:102
bool m_ignored
Definition: deviceConfig.hpp:316
constexpr auto CI_STAT_ERROR_CODE
Definition: deviceConfig.hpp:54
constexpr int SUBSTATE_ERROR
Definition: deviceConfig.hpp:85
std::string m_lcs_prefix
Definition: deviceConfig.hpp:317
virtual void SetSimulateFlag(bool flag)
Set simulation flag.
Definition: deviceConfig.cpp:455
constexpr auto CI_FITS_PREFIX
Definition: deviceConfig.hpp:37
Definition: configSet.hpp:17
constexpr auto CI_CFG_FILE
Definition: deviceConfig.hpp:39
constexpr auto RPC_ENABLE
Definition: deviceConfig.hpp:44
constexpr int STATE_NOT_OPERATIONAL
Definition: deviceConfig.hpp:64
std::string GetFitsPrefix()
Get Fits Prefix.
Definition: deviceConfig.cpp:349
int GetNamespace()
Definition: deviceConfig.cpp:355
Device Configuration class.
Definition: iDeviceConfig.hpp:32
virtual bool GetSimulated()
Get simulated flag.
Definition: deviceConfig.cpp:330
constexpr auto SUBSTATE_ERROR_STR
Definition: deviceConfig.hpp:90
constexpr int SUBSTATE_READY
Definition: deviceConfig.hpp:83
virtual std::string GetMapFile()
Get name of the device mapping file.
Definition: deviceConfig.cpp:465