Commit b0a52ad2 authored by Pavel Vainerman's avatar Pavel Vainerman

fized bug in MBTCPMaster

parent 705343d1
...@@ -21,7 +21,8 @@ mbregFromID(false), ...@@ -21,7 +21,8 @@ mbregFromID(false),
activated(false), activated(false),
noQueryOptimization(false), noQueryOptimization(false),
allNotRespond(false), allNotRespond(false),
prefix(prefix) prefix(prefix),
no_extimer(false)
{ {
// cout << "$ $" << endl; // cout << "$ $" << endl;
...@@ -119,7 +120,7 @@ prefix(prefix) ...@@ -119,7 +120,7 @@ prefix(prefix)
activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 20000); activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 20000);
initMB(false); // initMB(false);
printMap(rmap); printMap(rmap);
// abort(); // abort();
...@@ -163,6 +164,9 @@ void MBTCPMaster::initMB( bool reopen ) ...@@ -163,6 +164,9 @@ void MBTCPMaster::initMB( bool reopen )
mb->setTimeout(recv_timeout); mb->setTimeout(recv_timeout);
dlog[Debug::INFO] << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl; dlog[Debug::INFO] << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl;
if( dlog.debugging(Debug::LEVEL9) )
mb->setLog(dlog);
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
...@@ -197,7 +201,12 @@ void MBTCPMaster::waitSMReady() ...@@ -197,7 +201,12 @@ void MBTCPMaster::waitSMReady()
void MBTCPMaster::timerInfo( TimerMessage *tm ) void MBTCPMaster::timerInfo( TimerMessage *tm )
{ {
if( tm->id == tmExchange ) if( tm->id == tmExchange )
step(); {
if( no_extimer )
askTimer(tm->id,0);
else
step();
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::step() void MBTCPMaster::step()
...@@ -1515,6 +1524,9 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1515,6 +1524,9 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only )
if( !save && write_only ) if( !save && write_only )
return; return;
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "udpateP: sid=" << p->si.id << " mbval=" << r->mbval << endl;
try try
{ {
if( p->vType == VTypes::vtUnknown ) if( p->vType == VTypes::vtUnknown )
...@@ -1715,4 +1727,34 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1715,4 +1727,34 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only )
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void MBTCPMaster::execute()
{
no_extimer = true;
try
{
askTimer(tmExchange,0);
}
catch(...){}
initMB(false);
while(1)
{
try
{
step();
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(execute): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::CRIT] << myname << "(execute): catch ..." << endl;
}
msleep(polltime);
}
}
// -----------------------------------------------------------------------------
...@@ -37,6 +37,8 @@ class MBTCPMaster: ...@@ -37,6 +37,8 @@ class MBTCPMaster:
/*! help- */ /*! help- */
static void help_print( int argc, const char* const* argv ); static void help_print( int argc, const char* const* argv );
void execute();
static const int NoSafetyState=-1; static const int NoSafetyState=-1;
enum Timer enum Timer
...@@ -235,6 +237,8 @@ class MBTCPMaster: ...@@ -235,6 +237,8 @@ class MBTCPMaster:
Trigger trAllNotRespond; Trigger trAllNotRespond;
PassiveTimer ptAllNotRespond; PassiveTimer ptAllNotRespond;
std::string prefix; std::string prefix;
bool no_extimer;
}; };
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#endif // _MBTCPMaster_H_ #endif // _MBTCPMaster_H_
......
...@@ -1546,7 +1546,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX ...@@ -1546,7 +1546,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void RTUExchange::printMap( RTUExchange::RTUDeviceMap& m ) void RTUExchange::printMap( RTUExchange::RTUDeviceMap& m )
{ {
cout << "devices: " << endl; cout << "devices: num=" << m.size() << endl;
for( RTUExchange::RTUDeviceMap::iterator it=m.begin(); it!=m.end(); ++it ) for( RTUExchange::RTUDeviceMap::iterator it=m.begin(); it!=m.end(); ++it )
{ {
cout << " " << *(it->second) << endl; cout << " " << *(it->second) << endl;
......
...@@ -17,7 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ): ...@@ -17,7 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
activated(false), activated(false),
workready(false), workready(false),
dblogging(false), dblogging(false),
msecPulsar(0) msecPulsar(0),
iotypePulsar(UniversalIO::DigitalInput)
{ {
// cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl; // cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl;
...@@ -100,6 +101,19 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ): ...@@ -100,6 +101,19 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
siPulsar.node = conf->getLocalNode(); siPulsar.node = conf->getLocalNode();
msecPulsar = conf->getArgPInt("--pulsar-msec",it.getProp("pulsar_msec"), 5000); msecPulsar = conf->getArgPInt("--pulsar-msec",it.getProp("pulsar_msec"), 5000);
string t = conf->getArgParam("--pulsar-iotype",it.getProp("pulsar_iotype"));
if( !t.empty() )
{
iotypePulsar = UniSetTypes::getIOType(t);
if( iotypePulsar == UniversalIO::UnknownIOType )
{
ostringstream err;
err << myname << ": Unknown iotype '" << t << "' for pulsar. Must be 'DI' or 'DO'";
dlog[Debug::CRIT] << myname << "(init): " << err.str() << endl;
throw SystemError(err.str());
}
}
} }
} }
...@@ -184,7 +198,10 @@ void SharedMemory::timerInfo( TimerMessage *tm ) ...@@ -184,7 +198,10 @@ void SharedMemory::timerInfo( TimerMessage *tm )
{ {
bool st = localGetState(ditPulsar,siPulsar); bool st = localGetState(ditPulsar,siPulsar);
st ^= true; st ^= true;
localSaveState(ditPulsar,siPulsar,st,getId()); if( iotypePulsar == UniversalIO::DigitalInput )
localSaveState(ditPulsar,siPulsar,st,getId());
else if( iotypePulsar == UniversalIO::DigitalOutput )
localSetState(ditPulsar,siPulsar,st,getId());
} }
} }
} }
......
...@@ -189,6 +189,7 @@ class SharedMemory: ...@@ -189,6 +189,7 @@ class SharedMemory:
DIOStateList::iterator ditPulsar; DIOStateList::iterator ditPulsar;
IOController_i::SensorInfo siPulsar; IOController_i::SensorInfo siPulsar;
UniversalIO::IOTypes iotypePulsar;
int msecPulsar; int msecPulsar;
private: private:
......
...@@ -4,7 +4,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs" ...@@ -4,7 +4,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000 ulimit -Sc 10000000000
./uniset-start.sh -f ./uniset-smemory --smemory-id SharedMemory --pulsar-id TestMode_S \ ./uniset-start.sh -f ./uniset-smemory --smemory-id SharedMemory --pulsar-id DO_C \
--confile test.xml --datfile test.xml \ --confile test.xml --datfile test.xml \
--unideb-add-levels info,crit,warn,level9,system \ --unideb-add-levels info,crit,warn,level9,system \
--dlog-add-levels info,crit,warn --dlog-add-levels info,crit,warn
......
...@@ -35,7 +35,7 @@ class ModbusTCPMaster: ...@@ -35,7 +35,7 @@ class ModbusTCPMaster:
private: private:
ost::TCPStream* tcp; ost::TCPStream* tcp;
static int nTransaction; int nTransaction;
std::queue<unsigned char> qrecv; std::queue<unsigned char> qrecv;
PassiveTimer ptTimeout; PassiveTimer ptTimeout;
std::string iaddr; std::string iaddr;
......
...@@ -14,6 +14,7 @@ using namespace UniSetTypes; ...@@ -14,6 +14,7 @@ using namespace UniSetTypes;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusTCPMaster::ModbusTCPMaster(): ModbusTCPMaster::ModbusTCPMaster():
tcp(0), tcp(0),
nTransaction(0),
iaddr("") iaddr("")
{ {
setCRCNoCheckit(true); setCRCNoCheckit(true);
...@@ -56,7 +57,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, ...@@ -56,7 +57,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
} }
reconnect(); if( !isConnection() )
reconnect();
assert(timeout); assert(timeout);
ptTimeout.setTiming(timeout); ptTimeout.setTiming(timeout);
...@@ -67,7 +69,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, ...@@ -67,7 +69,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
try try
{ {
if( nTransaction >= numeric_limits<int>::max() ) if( nTransaction >= numeric_limits<ModbusRTU::ModbusData>::max() )
nTransaction = 0; nTransaction = 0;
ModbusTCP::MBAPHeader mh; ModbusTCP::MBAPHeader mh;
...@@ -122,7 +124,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, ...@@ -122,7 +124,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
} }
if( ret < (int)sizeof(rmh) ) if( ret < (int)sizeof(rmh) )
return erHardwareError; return erTimeOut; // return erHardwareError;
rmh.swapdata(); rmh.swapdata();
......
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