ifw-fcf  4.1.0-pre2
iodevConfig.hpp
Go to the documentation of this file.
1 
10 #ifndef FCF_DEVMGR_DEVICE_IODEV_CONFIG_HPP
11 #define FCF_DEVMGR_DEVICE_IODEV_CONFIG_HPP
12 
13 // System headers
14 #include <string>
15 #include <vector>
16 #include <utility>
17 
18 
19 // Third party headers
20 #include <yaml-cpp/yaml.h>
21 
22 #include <utils/bat/logger.hpp>
23 #include <fcf/common/iComm.hpp>
29 
30 namespace fcf::devmgr::iodev {
31 
32 constexpr auto LOGGER_NAME = "iodev";
33 constexpr auto CI_NO_RPC = "norpc";
34 constexpr auto CI_SENSOR = "sensor";
35 
36 // Constants for internal mapping
37 constexpr auto CI_CHANNELS = "channels";
38 constexpr auto CI_NAME = "name";
39 constexpr auto CI_DESCRIPTION = "description";
40 constexpr auto CI_ALIAS = "alias";
41 constexpr auto CI_TYPE = "type";
42 constexpr auto CI_HEADER = "header";
43 constexpr auto CI_LOG = "log";
44 constexpr auto CI_UNIT = "unit";
45 constexpr auto CI_MAP = "map";
46 constexpr auto CI_VALUE = "value";
47 constexpr auto CI_NAMED_MAPPING = "named_values";
48 
49 
50 // Specific constant values for Sensor device state/substate
51 constexpr int SUBSTATE_OP_MONITORING = 200;
52 constexpr auto SUBSTATE_OP_MONITORING_STR = "Monitoring";
53 
54 const std::unordered_map<short, std::string> SubstateMap = {
60 };
61 
62 constexpr auto DI_TYPE_STR = "DI";
63 constexpr auto AI_TYPE_STR = "AI";
64 constexpr auto II_TYPE_STR = "II";
65 constexpr auto SI_TYPE_STR = "SI";
66 
67 constexpr auto DO_TYPE_STR = "DO";
68 constexpr auto AO_TYPE_STR = "AO";
69 constexpr auto IO_TYPE_STR = "IO";
70 constexpr auto SO_TYPE_STR = "SO";
71 
72 constexpr auto DI_CAT_STR = "diChannels";
73 constexpr auto AI_CAT_STR = "aiChannels";
74 constexpr auto II_CAT_STR = "iiChannels";
75 constexpr auto SI_CAT_STR = "siChannels";
76 
77 constexpr auto DO_CAT_STR = "doChannels";
78 constexpr auto AO_CAT_STR = "aoChannels";
79 constexpr auto IO_CAT_STR = "ioChannels";
80 constexpr auto SO_CAT_STR = "soChannels";
81 
82 // Specific iodev RPC
83 constexpr auto RPC_SET_OUTPUTS = "rpcSetOutputs";
84 
85 
86 const std::unordered_map<std::string, std::string> IODevTypeMap = {
95 };
96 
97 
98 struct IODevChannel {
99 public:
100  IODevChannel();
101  virtual ~IODevChannel() = default;
102 
103  inline std::string GetDescription() const;
104  inline std::string GetAlias() const;
105  inline std::string GetType() const;
106  inline bool GetHeaderFlag() const;
107  inline bool GetLogFlag() const;
108  inline std::string GetUnit() const;
109  inline std::string GetMap() const;
110  inline std::string GetCat() const;
111  inline std::string GetFitsPrefix() const;
112  inline std::string GetNamedValue(std::string value) const;
113 
114  inline void SetDescription(std::string description);
115  inline void SetAlias(std::string alias);
116  inline void SetType(std::string type);
117  inline void SetHeaderFlag(bool flag);
118  inline void SetLogFlag(bool flag);
119  inline void SetUnit(std::string unit);
120  inline void SetMap(std::string map);
121  inline void SetFitsPrefix(std::string prefix);
122  inline void AddNamedValue(std::string value, std::string name);
123 
124 
125 protected:
126  std::string m_description;
127  std::string m_alias;
128  std::string m_type;
129  bool m_header;
130  bool m_log;
131  std::string m_unit;
132  std::string m_map;
133  std::string m_prefix;
134  std::unordered_map<std::string, string> m_named_values_map;
135 };
136 
137 class IODev;
146 
147  friend class IODev;
148  friend class IODevLcsIf;
149 
150 public:
151 
157  IODevConfig(const std::string filename,
158  const std::string name);
159 
164  IODevConfig(const std::string name);
165 
169  virtual ~IODevConfig() = default;
170 
179  virtual void Init();
180 
188  virtual void GetConfig(fcf::common::VectorVariant& params) const override;
189 
199  virtual void GetConfigList(utils::bat::DbVector& cfg_list,
200  std::string prefix) const override;
201 
209  virtual void GetInputList(std::vector<std::string>& channel_list) const ;
210 
218  virtual void GetOutputList(std::vector<std::pair<std::string, std::string>>& channel_list) const ;
219 
230  bool IsNoRpc() const;
231 
238  bool IsSensor() const;
239 
240  std::string GetChannelType(const std::string& channel) const;
241  std::string GetChannelDescription(const std::string& channel) const;
242  std::string GetChannelNamedValue(const std::string& channel,
243  const std::string& value) const;
244 
245  std::optional<IODevChannel> GetChannelConfig(const std::string& channel) const;
246 
247 private:
248  std::map<std::string, IODevChannel> m_channel_map;
249  log4cplus::Logger m_logger;
250 };
251 
252 }
253 
254 #include "iodevConfig.ipp"
255 #endif //FCF_DEVMGR_DEVICE_IODEV_CONFIG_HPP
dataContext.hpp
DataContext class header file.
fcf::devmgr::iodev::AO_CAT_STR
constexpr auto AO_CAT_STR
Definition: iodevConfig.hpp:78
fcf::devmgr::iodev::IODevChannel::SetAlias
void SetAlias(std::string alias)
fcf::devmgr::iodev::CI_NAME
constexpr auto CI_NAME
Definition: iodevConfig.hpp:38
fcf::devmgr::iodev::CI_TYPE
constexpr auto CI_TYPE
Definition: iodevConfig.hpp:41
fcf::devmgr::iodev::IODevChannel::GetMap
std::string GetMap() const
fcf::devmgr::iodev::IODevChannel::SetLogFlag
void SetLogFlag(bool flag)
fcf::devmgr::iodev::CI_DESCRIPTION
constexpr auto CI_DESCRIPTION
Definition: iodevConfig.hpp:39
fcf::devmgr::iodev::IODevChannel::GetLogFlag
bool GetLogFlag() const
m_logger
m_logger(log4cplus::Logger::getInstance(LOGGER_NAME))
Definition: {{cookiecutter.device_name}}.cpp:32
fcf::devmgr::iodev::IODevConfig::IsNoRpc
bool IsNoRpc() const
Get NO RPC flag.
Definition: iodevConfig.cpp:249
fcf::devmgr::iodev::DI_TYPE_STR
constexpr auto DI_TYPE_STR
Definition: iodevConfig.hpp:62
fcf::devmgr::iodev::IODevChannel::m_description
std::string m_description
Definition: iodevConfig.hpp:126
fcf::devmgr::iodev::CI_MAP
constexpr auto CI_MAP
Definition: iodevConfig.hpp:45
fcf::devmgr::iodev::II_TYPE_STR
constexpr auto II_TYPE_STR
Definition: iodevConfig.hpp:64
fcf::devmgr::iodev::IODevChannel::SetHeaderFlag
void SetHeaderFlag(bool flag)
fcf::devmgr::iodev::IODevChannel::SetType
void SetType(std::string type)
fcf::devmgr::iodev::SO_TYPE_STR
constexpr auto SO_TYPE_STR
Definition: iodevConfig.hpp:70
fcf::devmgr::iodev::IODev
The IODev class.
Definition: iodev.hpp:40
deviceConfig.hpp
DeviceConfig class header file.
fcf::devmgr::iodev::IODevChannel::m_map
std::string m_map
Definition: iodevConfig.hpp:132
fcf::devmgr::iodev::II_CAT_STR
constexpr auto II_CAT_STR
Definition: iodevConfig.hpp:74
fcf::devmgr::iodev::IODevChannel::GetHeaderFlag
bool GetHeaderFlag() const
fcf::devmgr::iodev::IODevConfig::GetConfig
virtual void GetConfig(fcf::common::VectorVariant &params) const override
Obtain the list of configuration parameters.
Definition: iodevConfig.cpp:143
fcf::devmgr::iodev::CI_NAMED_MAPPING
constexpr auto CI_NAMED_MAPPING
Definition: iodevConfig.hpp:47
fcf::devmgr::iodev::IODevChannel::AddNamedValue
void AddNamedValue(std::string value, std::string name)
fcf::devmgr::iodev::IODevChannel::m_prefix
std::string m_prefix
Definition: iodevConfig.hpp:133
fcf::devmgr::iodev::IODevChannel::GetNamedValue
std::string GetNamedValue(std::string value) const
fcf::devmgr::iodev::IO_TYPE_STR
constexpr auto IO_TYPE_STR
Definition: iodevConfig.hpp:69
fcf::devmgr::iodev::AI_CAT_STR
constexpr auto AI_CAT_STR
Definition: iodevConfig.hpp:73
fcf::devmgr::iodev
Definition: iodev.hpp:20
fcf::devmgr::iodev::CI_SENSOR
constexpr auto CI_SENSOR
Definition: iodevConfig.hpp:34
fcf::devmgr::iodev::IODevConfig
sensor Configuration class
Definition: iodevConfig.hpp:145
fcf::devmgr::iodev::IODevChannel::GetDescription
std::string GetDescription() const
fcf::devmgr::iodev::IODevChannel::SetUnit
void SetUnit(std::string unit)
fcf::devmgr::iodev::IODevChannel::m_named_values_map
std::unordered_map< std::string, string > m_named_values_map
Definition: iodevConfig.hpp:134
fcf::devmgr::iodev::IODevChannel::GetCat
std::string GetCat() const
fcf::devmgr::iodev::IODevChannel::m_unit
std::string m_unit
Definition: iodevConfig.hpp:131
fcf::devmgr::iodev::SI_CAT_STR
constexpr auto SI_CAT_STR
Definition: iodevConfig.hpp:75
fcf::devmgr::iodev::IODevConfig::GetInputList
virtual void GetInputList(std::vector< std::string > &channel_list) const
Get input channel list.
Definition: iodevConfig.cpp:223
fcf::devmgr::iodev::IODevConfig::IsSensor
bool IsSensor() const
Get Sensor flag.
Definition: iodevConfig.cpp:256
fcf::devmgr::common::SUBSTATE_NOTREADY_STR
constexpr auto SUBSTATE_NOTREADY_STR
Definition: deviceConfig.hpp:103
configSet.hpp
configSet class header file.
fcf::devmgr::iodev::AI_TYPE_STR
constexpr auto AI_TYPE_STR
Definition: iodevConfig.hpp:63
fcf::devmgr::iodev::IODevChannel::m_type
std::string m_type
Definition: iodevConfig.hpp:128
fcf::devmgr::iodev::IODevChannel
Definition: iodevConfig.hpp:98
fcf::devmgr::common::SUBSTATE_NOTREADY
constexpr int SUBSTATE_NOTREADY
Definition: deviceConfig.hpp:98
fcf::devmgr::iodev::CI_CHANNELS
constexpr auto CI_CHANNELS
Definition: iodevConfig.hpp:37
fcf::devmgr::iodev::IODevConfig::GetChannelConfig
std::optional< IODevChannel > GetChannelConfig(const std::string &channel) const
Definition: iodevConfig.cpp:304
fcf::devmgr::iodev::IODevChannel::GetAlias
std::string GetAlias() const
fcf::devmgr::iodev::AO_TYPE_STR
constexpr auto AO_TYPE_STR
Definition: iodevConfig.hpp:68
fcf::devmgr::iodev::IODevConfig::GetChannelNamedValue
std::string GetChannelNamedValue(const std::string &channel, const std::string &value) const
Definition: iodevConfig.cpp:290
fcf::devmgr::common::SUBSTATE_OP_ERROR
constexpr int SUBSTATE_OP_ERROR
Definition: deviceConfig.hpp:109
fcf::devmgr::iodev::IODevTypeMap
const std::unordered_map< std::string, std::string > IODevTypeMap
Definition: iodevConfig.hpp:86
fcf::devmgr::iodev::IODevChannel::m_log
bool m_log
Definition: iodevConfig.hpp:130
fcf::devmgr::iodev::IODevLcsIf
Sensor Local Control System (LCS) Interface (IF) class.
Definition: iodevLcsIf.hpp:103
fcf::devmgr::iodev::IODevChannel::IODevChannel
IODevChannel()
Definition: iodevConfig.cpp:27
fcf::devmgr::common::SUBSTATE_OP_ERROR_STR
constexpr auto SUBSTATE_OP_ERROR_STR
Definition: deviceConfig.hpp:112
fcf::devmgr::iodev::SUBSTATE_OP_MONITORING_STR
constexpr auto SUBSTATE_OP_MONITORING_STR
Definition: iodevConfig.hpp:52
fcf::devmgr::iodev::IODevConfig::Init
virtual void Init()
Read the configuration.
Definition: iodevConfig.cpp:54
fcf::devmgr::iodev::SI_TYPE_STR
constexpr auto SI_TYPE_STR
Definition: iodevConfig.hpp:65
fcf::devmgr::iodev::IODevConfig::GetChannelDescription
std::string GetChannelDescription(const std::string &channel) const
Definition: iodevConfig.cpp:277
fcf::devmgr::common::SUBSTATE_ERROR
constexpr int SUBSTATE_ERROR
Definition: deviceConfig.hpp:101
fcf::devmgr::iodev::CI_VALUE
constexpr auto CI_VALUE
Definition: iodevConfig.hpp:46
fcf::devmgr::iodev::IODevChannel::GetUnit
std::string GetUnit() const
fcf::devmgr::iodev::CI_NO_RPC
constexpr auto CI_NO_RPC
Definition: iodevConfig.hpp:33
fcf::devmgr::iodev::IODevConfig::GetChannelType
std::string GetChannelType(const std::string &channel) const
Definition: iodevConfig.cpp:264
fcf::devmgr::common::DeviceConfig
Device Configuration class.
Definition: deviceConfig.hpp:127
fcf::devmgr::iodev::IODevChannel::m_header
bool m_header
Definition: iodevConfig.hpp:129
fcf::devmgr::iodev::CI_LOG
constexpr auto CI_LOG
Definition: iodevConfig.hpp:43
fcf::devmgr::iodev::DI_CAT_STR
constexpr auto DI_CAT_STR
Definition: iodevConfig.hpp:72
fcf::devmgr::iodev::DO_TYPE_STR
constexpr auto DO_TYPE_STR
Definition: iodevConfig.hpp:67
fcf::devmgr::iodev::CI_HEADER
constexpr auto CI_HEADER
Definition: iodevConfig.hpp:42
fcf::devmgr::common::SUBSTATE_READY_STR
constexpr auto SUBSTATE_READY_STR
Definition: deviceConfig.hpp:105
fcf::devmgr::iodev::IODevConfig::IODevConfig
IODevConfig(const std::string filename, const std::string name)
IODevConfig constructor.
Definition: iodevConfig.cpp:37
fcf::devmgr::iodev::SO_CAT_STR
constexpr auto SO_CAT_STR
Definition: iodevConfig.hpp:80
fcf::devmgr::common::SUBSTATE_READY
constexpr int SUBSTATE_READY
Definition: deviceConfig.hpp:99
fcf::devmgr::iodev::IODevChannel::m_alias
std::string m_alias
Definition: iodevConfig.hpp:127
fcf::devmgr::iodev::IODevChannel::SetFitsPrefix
void SetFitsPrefix(std::string prefix)
fcf::devmgr::iodev::SUBSTATE_OP_MONITORING
constexpr int SUBSTATE_OP_MONITORING
Definition: iodevConfig.hpp:51
fcf::devmgr::iodev::IODevConfig::GetOutputList
virtual void GetOutputList(std::vector< std::pair< std::string, std::string >> &channel_list) const
Get output channel list.
Definition: iodevConfig.cpp:236
fcf::devmgr::iodev::RPC_SET_OUTPUTS
constexpr auto RPC_SET_OUTPUTS
Definition: iodevConfig.hpp:83
iodevRpcErrors.hpp
SensorRpcErrors header file.
fcf::devmgr::iodev::LOGGER_NAME
constexpr auto LOGGER_NAME
Definition: iodevConfig.hpp:32
fcf::devmgr::iodev::IODevChannel::GetType
std::string GetType() const
fcf::devmgr::iodev::IODevConfig::GetConfigList
virtual void GetConfigList(utils::bat::DbVector &cfg_list, std::string prefix) const override
Get configuration list.
Definition: iodevConfig.cpp:151
fcf::devmgr::iodev::IODevConfig::~IODevConfig
virtual ~IODevConfig()=default
DeviceConfig destructor.
fcf::devmgr::iodev::IODevChannel::SetDescription
void SetDescription(std::string description)
fcf::devmgr::common::SUBSTATE_ERROR_STR
constexpr auto SUBSTATE_ERROR_STR
Definition: deviceConfig.hpp:106
fcf::devmgr::iodev::CI_UNIT
constexpr auto CI_UNIT
Definition: iodevConfig.hpp:44
fcf::devmgr::iodev::IODevChannel::GetFitsPrefix
std::string GetFitsPrefix() const
iodevHwErrors.hpp
SensorHwErrors header file.
fcf::devmgr::iodev::IO_CAT_STR
constexpr auto IO_CAT_STR
Definition: iodevConfig.hpp:79
fcf::devmgr::iodev::IODevChannel::SetMap
void SetMap(std::string map)
fcf::devmgr::iodev::CI_ALIAS
constexpr auto CI_ALIAS
Definition: iodevConfig.hpp:40
fcf::devmgr::iodev::SubstateMap
const std::unordered_map< short, std::string > SubstateMap
Definition: iodevConfig.hpp:54
fcfcli.type
type
Definition: fcfcli.py:32
fcf::devmgr::iodev::DO_CAT_STR
constexpr auto DO_CAT_STR
Definition: iodevConfig.hpp:77
fcf::devmgr::iodev::IODevChannel::~IODevChannel
virtual ~IODevChannel()=default