Commit 2ad55d55 authored by Pavel Vainerman's avatar Pavel Vainerman

add respond sensor logic to MBSlave

parent c17b06c3
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 0.97 Version: 0.97
Release: eter54 Release: eter55
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
......
...@@ -21,6 +21,8 @@ shm(0), ...@@ -21,6 +21,8 @@ shm(0),
initPause(0), initPause(0),
test_id(DefaultObjectId), test_id(DefaultObjectId),
askcount_id(DefaultObjectId), askcount_id(DefaultObjectId),
respond_id(DefaultObjectId),
respond_invert(false),
askCount(0), askCount(0),
activated(false), activated(false),
activateTimeout(500), activateTimeout(500),
...@@ -63,6 +65,9 @@ prefix(prefix) ...@@ -63,6 +65,9 @@ prefix(prefix)
mbregFromID = conf->getArgInt("--" + prefix + "-reg-from-id",it.getProp("reg_from_id")); mbregFromID = conf->getArgInt("--" + prefix + "-reg-from-id",it.getProp("reg_from_id"));
dlog[Debug::INFO] << myname << "(init): mbregFromID=" << mbregFromID << endl; dlog[Debug::INFO] << myname << "(init): mbregFromID=" << mbregFromID << endl;
respond_id = conf->getSensorID(conf->getArgParam("--" + prefix + "-respond-id",it.getProp("respond_id")));
respond_invert = conf->getArgInt("--" + prefix + "-respond-invert",it.getProp("respond_invert"));
string stype = conf->getArgParam("--" + prefix + "-type",it.getProp("type")); string stype = conf->getArgParam("--" + prefix + "-type",it.getProp("type"));
if( stype == "RTU" ) if( stype == "RTU" )
...@@ -306,6 +311,23 @@ void MBSlave::execute_rtu() ...@@ -306,6 +311,23 @@ void MBSlave::execute_rtu()
} }
} }
if( respond_id != DefaultObjectId )
{
bool state = ptTimeout.checkTime() ? false : true;
if( respond_invert )
state ^= true;
try
{
shm->localSaveState(ditRespond,respond_id,state,getId());
}
catch(Exception& ex)
{
dlog[Debug::CRIT] << myname
<< "(execute_rtu): (respond) " << ex << std::endl;
}
}
if( askcount_id!=DefaultObjectId ) if( askcount_id!=DefaultObjectId )
{ {
try try
...@@ -370,6 +392,22 @@ void MBSlave::execute_tcp() ...@@ -370,6 +392,22 @@ void MBSlave::execute_tcp()
} }
} }
if( respond_id != DefaultObjectId )
{
bool state = ptTimeout.checkTime() ? false : true;
if( respond_invert )
state ^= true;
try
{
shm->localSaveState(ditRespond,respond_id,state,getId());
}
catch(Exception& ex)
{
dlog[Debug::CRIT] << myname
<< "(execute_rtu): (respond) " << ex << std::endl;
}
}
if( askcount_id!=DefaultObjectId ) if( askcount_id!=DefaultObjectId )
{ {
try try
...@@ -729,6 +767,7 @@ void MBSlave::initIterators() ...@@ -729,6 +767,7 @@ void MBSlave::initIterators()
shm->initAIterator(aitHeartBeat); shm->initAIterator(aitHeartBeat);
shm->initAIterator(aitAskCount); shm->initAIterator(aitAskCount);
shm->initDIterator(ditRespond);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBSlave::help_print( int argc, const char* const* argv ) void MBSlave::help_print( int argc, const char* const* argv )
...@@ -738,9 +777,10 @@ void MBSlave::help_print( int argc, const char* const* argv ) ...@@ -738,9 +777,10 @@ void MBSlave::help_print( int argc, const char* const* argv )
cout << "--prefix-heartbeat-max - heartbeat-ޣ . 10." << endl; cout << "--prefix-heartbeat-max - heartbeat-ޣ . 10." << endl;
cout << "--prefix-ready-timeout - SM , . (-1 - '')" << endl; cout << "--prefix-ready-timeout - SM , . (-1 - '')" << endl;
cout << "--prefix-initPause - ( )" << endl; cout << "--prefix-initPause - ( )" << endl;
cout << "--prefix-notRespondSensor - " << endl; cout << "--prefix-respond-id - respond sensor id" << endl;
cout << "--prefix-respond-invert [0|1] - invert respond logic" << endl;
cout << "--prefix-sm-ready-timeout - SM" << endl; cout << "--prefix-sm-ready-timeout - SM" << endl;
cout << "--prefix-recv-timeout - ." << endl; cout << "--prefix-timeout msec - timeout for check link" << endl;
cout << "--prefix-allow-setdatetime - On set date and time (0x50) modbus function" << endl; cout << "--prefix-allow-setdatetime - On set date and time (0x50) modbus function" << endl;
cout << "--prefix-my-addr - " << endl; cout << "--prefix-my-addr - " << endl;
cout << "--prefix-type [RTU|TCP] - modbus server type." << endl; cout << "--prefix-type [RTU|TCP] - modbus server type." << endl;
......
...@@ -168,6 +168,10 @@ class MBSlave: ...@@ -168,6 +168,10 @@ class MBSlave:
IOController::AIOStateList::iterator aitAskCount; IOController::AIOStateList::iterator aitAskCount;
UniSetTypes::ObjectId askcount_id; UniSetTypes::ObjectId askcount_id;
IOController::DIOStateList::iterator ditRespond;
UniSetTypes::ObjectId respond_id;
bool respond_invert;
PassiveTimer ptTimeout; PassiveTimer ptTimeout;
ModbusRTU::mbErrCode prev; ModbusRTU::mbErrCode prev;
long askCount; long askCount;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment