44 MBConfig(
const std::shared_ptr<uniset::Configuration>& conf
46 , std::shared_ptr<SMInterface> _shm );
59 friend std::ostream& operator<<( std::ostream& os,
const ExchangeMode& em );
62 static std::vector<std::string> supported_modes();
73 friend std::string to_string(
const SafeMode& m );
74 friend std::ostream& operator<<( std::ostream& os,
const SafeMode& m );
84 static DeviceType getDeviceType(
const std::string& dtype )
noexcept;
85 friend std::ostream& operator<<( std::ostream& os,
const DeviceType& dt );
94 VTypes::VType
vType = { VTypes::vtUnknown };
104 RSProperty(
const RSProperty& r ) =
delete;
105 RSProperty& operator=(
const RSProperty& r) =
delete;
106 RSProperty( RSProperty&& r ) =
default;
107 RSProperty& operator=(RSProperty&& r) =
default;
109 std::shared_ptr<RegInfo> reg;
112 friend std::ostream& operator<<( std::ostream& os,
const RSProperty& p );
114 typedef std::list<RSProperty> PList;
116 typedef std::map<ModbusRTU::RegID, std::shared_ptr<RegInfo>> RegMap;
127 ModbusRTU::ModbusData mbval = { 0 };
128 inline bool setMBVal(ModbusRTU::ModbusData nv)
136 ModbusRTU::ModbusData
mbreg = { 0 };
137 ModbusRTU::SlaveFunctionCode
mbfunc = { ModbusRTU::fnUnknown };
139 ModbusRTU::RegID regID = { 0 };
141 std::shared_ptr<RTUDevice> dev;
144 RTUStorage::RTUJack rtuJack = { RTUStorage::nUnknown };
154 RegMap::iterator rit;
177 friend std::ostream& operator<<( std::ostream& os,
const RegInfo& r );
178 friend std::ostream& operator<<( std::ostream& os,
const RegInfo* r );
183 std::unordered_map<size_t, std::shared_ptr<RegMap>> pollmap;
189 IOController::IOStateList::iterator resp_it;
192 bool resp_state = {
false };
193 bool resp_invert = {
false };
194 bool resp_force = {
false };
196 std::atomic<size_t> numreply = { 0 };
197 std::atomic<size_t> prev_numreply = { 0 };
204 IOController::IOStateList::iterator mode_it;
210 IOController::IOStateList::iterator safemode_it;
211 long safemode_value = { 1 };
214 bool checkRespond( std::shared_ptr<DebugStream>& log );
217 ComPort::Speed speed = { ComPort::ComSpeed38400 };
218 std::shared_ptr<RTUStorage> rtu188;
219 ComPort::Parity parity = { ComPort::NoParity };
220 ComPort::CharacterSize csize = { ComPort::CSize8 };
221 ComPort::StopBits stopBits = { ComPort::OneBit };
223 std::string getShortInfo()
const;
226 friend std::ostream& operator<<( std::ostream& os, RTUDevice& d );
228 typedef std::unordered_map<ModbusRTU::ModbusAddr, std::shared_ptr<RTUDevice>> RTUDeviceMap;
230 friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
231 static void printMap(RTUDeviceMap& d);
233 typedef std::list<IOBase> ThresholdList;
239 mbfunc(ModbusRTU::fnUnknown),
243 std::shared_ptr<RTUDevice> dev;
244 ModbusRTU::ModbusData mbreg;
245 ModbusRTU::SlaveFunctionCode mbfunc;
247 std::shared_ptr<RegInfo> ri;
249 typedef std::list<InitRegInfo> InitList;
251 static void rtuQueryOptimization( RTUDeviceMap& m,
size_t maxQueryCount );
252 static void rtuQueryOptimizationForDevice(
const std::shared_ptr<RTUDevice>& d,
size_t maxQueryCount );
253 static void rtuQueryOptimizationForRegMap(
const std::shared_ptr<RegMap>& regmap,
size_t maxQueryCount );
257 ThresholdList thrlist;
258 RTUDeviceMap devices;
261 void loadConfig(
const std::shared_ptr<uniset::UniXML>& xml,
UniXML::iterator sensorsSection );
262 void initDeviceList(
const std::shared_ptr<UniXML>& xml );
266 std::string s_fvalue;
269 timeout_t recv_timeout = { 500 };
270 timeout_t default_timeout = { 5000 };
271 timeout_t aftersend_pause = { 0 };
273 timeout_t sleepPause_msec = { 10 };
276 xmlNode* cnode = { 0 };
277 std::shared_ptr<DebugStream> mblog;
281 std::string defaultMBtype;
282 std::string defaultMBaddr;
283 bool mbregFromID = {
false };
284 bool defaultMBinitOK = {
false };
285 bool noQueryOptimization = {
false };
286 std::shared_ptr<uniset::Configuration> conf;
287 std::shared_ptr<SMInterface> shm;
289 void cloneParams(
const std::shared_ptr<MBConfig>& conf );
290 std::string getShortInfo()
const;
295 bool checkDuplicationRegID(
const ModbusRTU::RegID
id,
const std::shared_ptr<RTUDevice>& dev,
const std::shared_ptr<RegMap>& rmap )
const;
299 bool initSMValue( ModbusRTU::ModbusData* data,
int count, RSProperty* p );
301 void readConfiguration(
const std::shared_ptr<uniset::UniXML>& xml,
UniXML::iterator sensorsSection );
302 void initOffsetList();
304 std::shared_ptr<RTUDevice> addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
305 std::shared_ptr<RegInfo> addReg(std::shared_ptr<RegMap>& devices, ModbusRTU::RegID
id, ModbusRTU::ModbusData r,
UniXML::iterator& it, std::shared_ptr<RTUDevice> dev );
306 RSProperty* addProp( PList& plist, RSProperty&& p );
311 bool initRegInfo(std::shared_ptr<RegInfo>& r,
UniXML::iterator& it, std::shared_ptr<RTUDevice>& dev );
313 bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );