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 );
70 friend std::string to_string(
const SafeMode& m );
71 friend std::ostream& operator<<( std::ostream& os,
const SafeMode& m );
81 static DeviceType getDeviceType(
const std::string& dtype )
noexcept;
82 friend std::ostream& operator<<( std::ostream& os,
const DeviceType& dt );
91 VTypes::VType
vType = { VTypes::vtUnknown };
101 RSProperty(
const RSProperty& r ) =
delete;
102 RSProperty& operator=(
const RSProperty& r) =
delete;
103 RSProperty( RSProperty&& r ) =
default;
104 RSProperty& operator=(RSProperty&& r) =
default;
106 std::shared_ptr<RegInfo> reg;
109 friend std::ostream& operator<<( std::ostream& os,
const RSProperty& p );
111 typedef std::list<RSProperty> PList;
113 typedef std::map<ModbusRTU::RegID, std::shared_ptr<RegInfo>> RegMap;
124 ModbusRTU::ModbusData mbval = { 0 };
125 inline bool setMBVal(ModbusRTU::ModbusData nv)
133 ModbusRTU::ModbusData
mbreg = { 0 };
134 ModbusRTU::SlaveFunctionCode
mbfunc = { ModbusRTU::fnUnknown };
136 ModbusRTU::RegID regID = { 0 };
138 std::shared_ptr<RTUDevice> dev;
141 RTUStorage::RTUJack rtuJack = { RTUStorage::nUnknown };
151 RegMap::iterator rit;
174 friend std::ostream& operator<<( std::ostream& os,
const RegInfo& r );
175 friend std::ostream& operator<<( std::ostream& os,
const RegInfo* r );
180 std::unordered_map<size_t, std::shared_ptr<RegMap>> pollmap;
186 IOController::IOStateList::iterator resp_it;
189 bool resp_state = {
false };
190 bool resp_invert = {
false };
191 bool resp_force = {
false };
193 std::atomic<size_t> numreply = { 0 };
194 std::atomic<size_t> prev_numreply = { 0 };
201 IOController::IOStateList::iterator mode_it;
207 IOController::IOStateList::iterator safemode_it;
208 long safemode_value = { 1 };
211 bool checkRespond( std::shared_ptr<DebugStream>& log );
214 ComPort::Speed speed = { ComPort::ComSpeed38400 };
215 std::shared_ptr<RTUStorage> rtu188;
216 ComPort::Parity parity = { ComPort::NoParity };
217 ComPort::CharacterSize csize = { ComPort::CSize8 };
218 ComPort::StopBits stopBits = { ComPort::OneBit };
220 std::string getShortInfo()
const;
223 friend std::ostream& operator<<( std::ostream& os, RTUDevice& d );
225 typedef std::unordered_map<ModbusRTU::ModbusAddr, std::shared_ptr<RTUDevice>> RTUDeviceMap;
227 friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
228 static void printMap(RTUDeviceMap& d);
230 typedef std::list<IOBase> ThresholdList;
236 mbfunc(ModbusRTU::fnUnknown),
240 std::shared_ptr<RTUDevice> dev;
241 ModbusRTU::ModbusData mbreg;
242 ModbusRTU::SlaveFunctionCode mbfunc;
244 std::shared_ptr<RegInfo> ri;
246 typedef std::list<InitRegInfo> InitList;
248 static void rtuQueryOptimization( RTUDeviceMap& m,
size_t maxQueryCount );
249 static void rtuQueryOptimizationForDevice(
const std::shared_ptr<RTUDevice>& d,
size_t maxQueryCount );
250 static void rtuQueryOptimizationForRegMap(
const std::shared_ptr<RegMap>& regmap,
size_t maxQueryCount );
254 ThresholdList thrlist;
255 RTUDeviceMap devices;
258 void loadConfig(
const std::shared_ptr<uniset::UniXML>& xml,
UniXML::iterator sensorsSection );
259 void initDeviceList(
const std::shared_ptr<UniXML>& xml );
263 std::string s_fvalue;
266 timeout_t recv_timeout = { 500 };
267 timeout_t default_timeout = { 5000 };
268 timeout_t aftersend_pause = { 0 };
270 timeout_t sleepPause_msec = { 10 };
273 xmlNode* cnode = { 0 };
274 std::shared_ptr<DebugStream> mblog;
278 std::string defaultMBtype;
279 std::string defaultMBaddr;
280 bool mbregFromID = {
false };
281 bool defaultMBinitOK = {
false };
282 bool noQueryOptimization = {
false };
283 std::shared_ptr<uniset::Configuration> conf;
284 std::shared_ptr<SMInterface> shm;
286 void cloneParams(
const std::shared_ptr<MBConfig>& conf );
287 std::string getShortInfo()
const;
292 bool checkDuplicationRegID(
const ModbusRTU::RegID
id,
const std::shared_ptr<RTUDevice>& dev,
const std::shared_ptr<RegMap>& rmap )
const;
296 bool initSMValue( ModbusRTU::ModbusData* data,
int count, RSProperty* p );
298 void readConfiguration(
const std::shared_ptr<uniset::UniXML>& xml,
UniXML::iterator sensorsSection );
299 void initOffsetList();
301 std::shared_ptr<RTUDevice> addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );
302 std::shared_ptr<RegInfo> addReg(std::shared_ptr<RegMap>& devices, ModbusRTU::RegID
id, ModbusRTU::ModbusData r,
UniXML::iterator& it, std::shared_ptr<RTUDevice> dev );
303 RSProperty* addProp( PList& plist, RSProperty&& p );
308 bool initRegInfo(std::shared_ptr<RegInfo>& r,
UniXML::iterator& it, std::shared_ptr<RTUDevice>& dev );
310 bool initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a,
UniXML::iterator& it );