Commit b2cf6d77 authored by Pavel Vainerman's avatar Pavel Vainerman

move UniSetObject::askTimer to public, make style

parent b59446ed
......@@ -225,6 +225,7 @@ int main(int argc, char** argv)
ui.initBackId(UniSetTypes::AdminID);
int userparam = 0;
if( optind < argc )
userparam = uni_atoi(argv[optind]);
......@@ -538,6 +539,7 @@ static void createSections( const std::shared_ptr<UniSetTypes::Configuration>& r
int omap()
{
std::ios_base::fmtflags old_flags = cout.flags();
try
{
cout.setf(ios::left, ios::adjustfield);
......
......@@ -398,6 +398,7 @@ ModbusRTU::mbErrCode MBTCPServer::fileTransfer( ModbusRTU::FileTransferMessage&
int seek = query.numpacket * ModbusRTU::FileTransferRetMessage::MaxDataLen;
int ret = lseek(fd, seek, SEEK_SET);
if( ret < 0 )
{
close(fd);
......
......@@ -54,6 +54,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hva:d:s:yc:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -127,6 +127,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:t:o:e:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -51,8 +51,10 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hva:d:s:c:", longopts, &optindex);
if( opt == -1 )
break;
switch (opt)
{
case 'h':
......@@ -90,9 +92,10 @@ int main( int argc, char** argv )
}
}
auto avec = UniSetTypes::explode_str(myaddr,',');
auto avec = UniSetTypes::explode_str(myaddr, ',');
std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
for( const auto& a: avec )
for( const auto& a : avec )
vaddr.emplace( ModbusRTU::str2mbAddr(a) );
if( verb )
......
......@@ -50,6 +50,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hva:p:i:bc:", longopts, &optindex);
if( opt != -1 )
break;
......@@ -86,9 +87,10 @@ int main( int argc, char** argv )
}
}
auto avec = UniSetTypes::explode_str(myaddr,',');
auto avec = UniSetTypes::explode_str(myaddr, ',');
std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
for( const auto& a: avec )
for( const auto& a : avec )
vaddr.emplace( ModbusRTU::str2mbAddr(a) );
if( verb )
......
......@@ -39,6 +39,7 @@ int main( int argc, char* argv[], char* envp[] )
while(1)
{
opt = getopt_long(argc, argv, "hvi:p:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -82,6 +82,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "chvlf:a:p:i:d:s:n:eorbx:w:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -51,6 +51,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hvi:p:d:m:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -11,6 +11,7 @@ TestGen::TestGen( UniSetTypes::ObjectId id, xmlNode* confnode ):
vmonit(bool_var);
long* i = valptr(input2_s);
if( !i )
cerr << "input2_s NOT FOUND!!!" << endl;
else
......
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.2
Release: alt12
Release: alt13
Summary: UniSet - library for building distributed industrial control systems
......@@ -451,6 +451,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Wed Dec 16 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt13
- set public for UniSetObject::askTimer
* Mon Dec 14 2015 Pavel Vainerman <pv@altlinux.ru> 2.2-alt12
- refactoring: remove xxx_LT classes
- add new function for LT_Object
......
......@@ -46,7 +46,7 @@ class PostgreSQLInterface
class PostgreSQLResult
{
public:
PostgreSQLResult(){}
PostgreSQLResult() {}
explicit PostgreSQLResult( const pqxx::result& res );
~PostgreSQLResult();
......
......@@ -24,7 +24,7 @@ std::ostream& operator<<( std::ostream& os, IOControl::IOInfo& inf )
// -----------------------------------------------------------------------------
IOControl::IOControl(UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
const std::shared_ptr<SharedMemory>& ic, int numcards, const std::string& prefix_ ):
const std::shared_ptr<SharedMemory>& ic, int numcards, const std::string& prefix_ ):
UniSetObject(id),
polltime(150),
cards(11),
......
......@@ -86,6 +86,7 @@ int main(int argc, char* argv[])
while(1)
{
opt = getopt_long(argc, argv, "hr:s:d:a:x:o:f:n:i:c:", longopts, &optindex);
if( opt == -1 )
break;
......@@ -196,6 +197,7 @@ int main(int argc, char* argv[])
cout << "\r" << "data: " << setw(5) << data << " " << flush;
ssize_t temp = read(fd, &buf, sizeof(buf));
if( temp == -1 )
{
close(fd);
......@@ -347,6 +349,7 @@ void readCalibr(int fixed)
close(f);
return;
}
if (temp > 1)
{
int s;
......
......@@ -71,6 +71,7 @@ int main(int argc, char* argv[])
while(1)
{
opt = getopt_long(argc, argv, "habvr:w:i:o:s:d:c:p:m:q:x:z:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -19,7 +19,7 @@ class PassiveLProcessor:
public:
PassiveLProcessor(UniSetTypes::ObjectId objId,
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "lproc" );
UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr, const std::string& prefix = "lproc" );
virtual ~PassiveLProcessor();
enum Timers
......
......@@ -14,7 +14,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
MBExchange::MBExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId,
const std::shared_ptr<SharedMemory>& _ic, const std::string& prefix ):
const std::shared_ptr<SharedMemory>& _ic, const std::string& prefix ):
UniSetObject(objId),
allInitOK(false),
initPause(3000),
......@@ -270,6 +270,7 @@ void MBExchange::waitSMReady()
// waiting for SM is ready...
int tout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
timeout_t ready_timeout = 15000;
if( tout > 0 )
ready_timeout = tout;
else if( tout < 0 )
......@@ -333,10 +334,11 @@ void MBExchange::sigterm( int signo )
{
mbwarn << myname << "SIGTERM(" << signo << "): " << ex.what() << endl;
}
// {
// std::exception_ptr p = std::current_exception();
// std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
// }
// {
// std::exception_ptr p = std::current_exception();
// std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
// }
}
// ------------------------------------------------------------------------------------------
void MBExchange::readConfiguration()
......@@ -405,9 +407,10 @@ void MBExchange::initIterators()
shm->initIterator(d->resp_it);
shm->initIterator(d->mode_it);
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
auto& regmap = m.second;
for( auto it = regmap->begin(); it != regmap->end(); ++it )
{
for( auto it2 = it->second->slst.begin(); it2 != it->second->slst.end(); ++it2 )
......@@ -432,9 +435,10 @@ void MBExchange::initValues()
{
auto d = it1->second;
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
auto regmap = m.second;
for( auto it = regmap->begin(); it != regmap->end(); ++it )
{
for( auto it2 = it->second->slst.begin(); it2 != it->second->slst.end(); ++it2 )
......@@ -543,9 +547,9 @@ std::ostream& operator<<( std::ostream& os, MBExchange::RTUDevice& d )
os << " regs: " << endl;
for( const auto& m: d.pollmap )
for( const auto& m : d.pollmap )
{
for( const auto& it: *(m.second) )
for( const auto& it : * (m.second) )
os << " " << it.second << endl;
}
......@@ -581,11 +585,11 @@ void MBExchange::rtuQueryOptimization( RTUDeviceMap& dm )
mbinfo << myname << "(rtuQueryOptimization): optimization..." << endl;
for( auto&& it1: dm )
for( auto && it1 : dm )
{
auto d = it1.second;
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
auto& regmap = m.second;
......@@ -1184,7 +1188,7 @@ void MBExchange::updateSM()
}
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
auto& regmap = m.second;
......@@ -1242,7 +1246,7 @@ void MBExchange::updateRTU( RegMap::iterator& rit )
{
auto& r = rit->second;
for( auto&& it: r->slst )
for( auto && it : r->slst )
updateRSProperty( &it, false );
}
......@@ -2375,10 +2379,11 @@ bool MBExchange::initItem( UniXML::iterator& it )
std::shared_ptr<RegMap> rmap;
auto rit = dev->pollmap.find(pollfactor);
if( rit == dev->pollmap.end() )
{
rmap = make_shared<RegMap>();
dev->pollmap.emplace(pollfactor,rmap);
dev->pollmap.emplace(pollfactor, rmap);
}
else
rmap = rit->second;
......@@ -2933,9 +2938,10 @@ void MBExchange::askSensors( UniversalIO::UIOCommand cmd )
if( force_out )
return;
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
auto& regmap = m.second;
for( auto it = regmap->begin(); it != regmap->end(); ++it )
{
if( !isWriteFunction(it->second->mbfunc) )
......@@ -2984,7 +2990,7 @@ void MBExchange::sensorInfo( const UniSetTypes::SensorMessage* sm )
{
auto&& regmap = m.second;
for( const auto& it: (*regmap) )
for( const auto& it : (*regmap) )
{
if( !isWriteFunction(it.second->mbfunc) )
continue;
......@@ -3062,9 +3068,9 @@ bool MBExchange::poll()
d->prev_numreply.store(d->numreply);
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
if( m.first>1 && (ncycle % m.first) != 0 )
if( m.first > 1 && (ncycle % m.first) != 0 )
continue;
auto&& regmap = m.second;
......
......@@ -12,7 +12,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
MBTCPMaster::MBTCPMaster(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId,
const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
MBExchange(objId, shmId, ic, prefix),
force_disconnect(true)
{
......
......@@ -451,11 +451,12 @@ void MBTCPMultiMaster::sigterm( int signo )
{
mbcrit << myname << "(sigterm): " << ex.what() << std::endl;
}
// catch( ... )
// {
// std::exception_ptr p = std::current_exception();
// std::clog << (p ? p.__cxa_exception_type()->name() : "null") << std::endl;
// }
// catch( ... )
// {
// std::exception_ptr p = std::current_exception();
// std::clog << (p ? p.__cxa_exception_type()->name() : "null") << std::endl;
// }
}
// -----------------------------------------------------------------------------
......@@ -508,7 +509,7 @@ const std::string MBTCPMultiMaster::MBSlaveInfo::getShortInfo() const
s << myname << " respond=" << respond
<< " (respond_id=" << respond_id << " respond_invert=" << respond_invert
<< " recv_timeout=" << recv_timeout << " resp_force=" << respond_force
<< " use=" << use << " ignore=" << ignore << " priority=" << priority
<< " use=" << use << " ignore=" << ignore << " priority=" << priority
<< " persistent-connection=" << !force_disconnect
<< ")";
......
......@@ -10,7 +10,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
RTUExchange::RTUExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory>& ic,
const std::string& prefix_ ):
const std::string& prefix_ ):
MBExchange(objId, shmId, ic, prefix_),
mbrtu(0),
defSpeed(ComPort::ComSpeed38400),
......@@ -251,14 +251,14 @@ bool RTUExchange::poll()
dlog3 << myname << "(poll): ask addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " regs=" << d->pollmap.size() << endl;
for( auto&& m: d->pollmap )
for( auto && m : d->pollmap )
{
if( m.first!=0 && (ncycle % m.first) != 0 )
if( m.first != 0 && (ncycle % m.first) != 0 )
continue;
auto rmap = m.second;
for( auto&& it = rmap->begin(); it != rmap->end(); ++it )
for( auto && it = rmap->begin(); it != rmap->end(); ++it )
{
try
{
......
......@@ -132,8 +132,10 @@ void RTUStorage::poll( const std::shared_ptr<ModbusRTUMaster>& mb ) throw( Modbu
for( unsigned int i = 0; i < 8; i++ )
{
int k = i + 8 * b;
if( k>=48 )
if( k >= 48 )
break;
unio_do[k] = bits[i];
}
}
......@@ -152,8 +154,10 @@ void RTUStorage::poll( const std::shared_ptr<ModbusRTUMaster>& mb ) throw( Modbu
for( unsigned int i = 0; i < 8; i++ )
{
int k = i + 8 * b;
if( k>=48 )
if( k >= 48 )
break;
unio_di[k] = bits[i];
}
}
......
......@@ -79,6 +79,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hvyq:r:d:s:t:x:m:n:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -105,6 +105,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hvw:r:x:d:s:t:l:n:yb:e:x:z:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -47,6 +47,7 @@ int main( int argc, char** argv )
while(1)
{
opt = getopt_long(argc, argv, "hva:d:s:t:q:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -483,6 +483,7 @@ ModbusRTU::mbErrCode MBTCPTestServer::fileTransfer( ModbusRTU::FileTransferMessa
int seek = query.numpacket * ModbusRTU::FileTransferRetMessage::MaxDataLen;
int ret = lseek(fd, seek, SEEK_SET);
if( ret < 0 )
{
close(fd);
......
......@@ -217,7 +217,7 @@ MBSlave::MBSlave(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const
{
readConfiguration();
mbinfo << myname << "(init): iomap size = " << iomap.size()
<< " myaddr=" << ModbusServer::vaddr2str(vaddr) << endl;
<< " myaddr=" << ModbusServer::vaddr2str(vaddr) << endl;
}
else
{
......@@ -463,6 +463,7 @@ void MBSlave::waitSMReady()
// waiting for SM is ready...
int tout = uniset_conf()->getArgInt("--" + prefix + "-sm-ready-timeout", "15000");
timeout_t ready_timeout = 15000;
if( tout > 0 )
ready_timeout = tout;
else if( tout < 0 )
......@@ -491,6 +492,7 @@ void MBSlave::execute_rtu()
if( !shm->isLocalwork() )
{
std::unique_lock<std::mutex> locker(mutexStartNotify);
while( !activated )
startNotifyEvent.wait(locker);
}
......@@ -503,8 +505,8 @@ void MBSlave::execute_rtu()
}
mbinfo << myname << "(execute_rtu): thread running.."
<< " iomap size = " << iomap.size()
<< " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< " iomap size = " << iomap.size()
<< " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< endl;
while( !cancelled )
......@@ -577,9 +579,9 @@ void MBSlave::execute_rtu()
}
}
for( auto&& rmap: iomap )
for( auto && rmap : iomap )
{
for( auto&& it: rmap.second )
for( auto && it : rmap.second )
IOBase::processingThreshold(&it.second, shm, force);
}
}
......@@ -598,6 +600,7 @@ void MBSlave::execute_tcp()
if( !shm->isLocalwork() )
{
std::unique_lock<std::mutex> locker(mutexStartNotify);
while( !activated )
startNotifyEvent.wait(locker);
}
......@@ -610,8 +613,8 @@ void MBSlave::execute_tcp()
}
mbinfo << myname << "(execute_tcp): thread running.."
<< " iomap size = " << iomap.size()
<< " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< " iomap size = " << iomap.size()
<< " myaddr=" << ModbusServer::vaddr2str(vaddr)
<< endl;
while( !cancelled )
......@@ -685,9 +688,9 @@ void MBSlave::execute_tcp()
}
}
for( auto&& rmap: iomap )
for( auto && rmap : iomap )
{
for( auto&& it : rmap.second )
for( auto && it : rmap.second )
IOBase::processingThreshold(&it.second, shm, force);
}
}
......@@ -802,7 +805,7 @@ void MBSlave::askSensors( UniversalIO::UIOCommand cmd )
if( force )
return;
for( const auto& rmap: iomap )
for( const auto& rmap : iomap )
{
for( const auto& it : rmap.second )
{
......@@ -823,10 +826,11 @@ void MBSlave::askSensors( UniversalIO::UIOCommand cmd )
// ------------------------------------------------------------------------------------------
void MBSlave::sensorInfo( const UniSetTypes::SensorMessage* sm )
{
for( auto&& regs: iomap )
for( auto && regs : iomap )
{
auto& rmap = regs.second;
for( auto it =rmap.begin(); it != rmap.end(); ++it )
for( auto it = rmap.begin(); it != rmap.end(); ++it )
{
if( it->second.si.id == sm->id )
{
......@@ -1229,7 +1233,7 @@ bool MBSlave::BitRegProperty::check( const IOController_i::SensorInfo& si )
// ------------------------------------------------------------------------------------------
void MBSlave::initIterators()
{
for( auto&& regs: iomap )
for( auto && regs : iomap )
{
auto& rmap = regs.second;
......@@ -1377,6 +1381,7 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters( ModbusRTU::ReadOutputMessage&
mbinfo << myname << "(readOutputRegisters): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(readOutputRegisters): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -1415,6 +1420,7 @@ ModbusRTU::mbErrCode MBSlave::writeOutputRegisters( ModbusRTU::WriteOutputMessag
mbinfo << myname << "(writeOutputRegisters): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(writeOutputRegisters): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -1437,6 +1443,7 @@ ModbusRTU::mbErrCode MBSlave::writeOutputSingleRegister( ModbusRTU::WriteSingleO
mbinfo << myname << "(writeOutputSingleRegisters): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(writeOutputRegisters): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -2046,6 +2053,7 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query, ReadInputRetMess
mbinfo << myname << "(readInputRegisters): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(readInputRegisters): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -2110,6 +2118,7 @@ ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query,
mbinfo << myname << "(readCoilStatus): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(readCoilStatus): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -2121,7 +2130,7 @@ ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query,
if( query.count <= 1 )
{
ModbusRTU::ModbusData d = 0;
ModbusRTU::mbErrCode ret = real_read(regmap->second,query.start, d, query.func);
ModbusRTU::mbErrCode ret = real_read(regmap->second, query.start, d, query.func);
reply.addData(0);
if( ret == ModbusRTU::erNoError )
......@@ -2182,6 +2191,7 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
mbinfo << myname << "(readInputStatus): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(readInputStatus): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -2254,6 +2264,7 @@ ModbusRTU::mbErrCode MBSlave::forceMultipleCoils( ModbusRTU::ForceCoilsMessage&
mbinfo << myname << "(forceMultipleCoils): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(forceMultipleCoils): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......@@ -2290,6 +2301,7 @@ ModbusRTU::mbErrCode MBSlave::forceSingleCoil( ModbusRTU::ForceSingleCoilMessage
mbinfo << myname << "(forceSingleCoil): " << query << endl;
auto regmap = iomap.find(query.addr);
if( regmap == iomap.end() )
{
mbinfo << myname << "(forceSingleCoil): Unknown addr=" << ModbusRTU::addr2str(query.addr) << endl;
......
......@@ -439,7 +439,7 @@ class MBSlave:
// то использовать unordered_map нельзя
typedef std::map<ModbusRTU::RegID, IOProperty> RegMap;
typedef std::unordered_map<ModbusRTU::ModbusAddr,RegMap> IOMap;
typedef std::unordered_map<ModbusRTU::ModbusAddr, RegMap> IOMap;
IOMap iomap; /*!< список входов/выходов по адресам */
......
......@@ -12,7 +12,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
RRDServer::RRDServer(UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory>& ic,
const string& prefix ):
const string& prefix ):
UObject_SK(objId, cnode, string(prefix + "-")),
prefix(prefix)
{
......@@ -156,6 +156,7 @@ void RRDServer::initRRD( xmlNode* cnode, int tmID )
}
std::string dsname(it1.getProp(ds));
if( dsname.empty() )
dsname = it1.getProp("name");
......
......@@ -415,26 +415,26 @@ class SharedMemory:
class HeartBeatInfo
{
public:
HeartBeatInfo():
a_sid(UniSetTypes::DefaultObjectId),
d_sid(UniSetTypes::DefaultObjectId),
reboot_msec(UniSetTimer::WaitUpTime),
timer_running(false),
ptReboot(UniSetTimer::WaitUpTime)
{}
UniSetTypes::ObjectId a_sid; // аналоговый счётчик
UniSetTypes::ObjectId d_sid; // дискретный датчик состояния процесса
IOStateList::iterator a_it;
IOStateList::iterator d_it;
timeout_t reboot_msec; /*!< Время в течение которого процесс обязан подтвердить своё существование,
HeartBeatInfo():
a_sid(UniSetTypes::DefaultObjectId),
d_sid(UniSetTypes::DefaultObjectId),
reboot_msec(UniSetTimer::WaitUpTime),
timer_running(false),
ptReboot(UniSetTimer::WaitUpTime)
{}
UniSetTypes::ObjectId a_sid; // аналоговый счётчик
UniSetTypes::ObjectId d_sid; // дискретный датчик состояния процесса
IOStateList::iterator a_it;
IOStateList::iterator d_it;
timeout_t reboot_msec; /*!< Время в течение которого процесс обязан подтвердить своё существование,
иначе будет произведена перезагрузка контроллера по WDT (в случае если он включён).
Если данный параметр не указывать, то "не живость" процесса просто игнорируется
(т.е. только сброс датчика heartbeat (d_sid) в ноль). */
bool timer_running;
PassiveTimer ptReboot;
bool timer_running;
PassiveTimer ptReboot;
};
enum Timers
......
......@@ -457,6 +457,7 @@ void UNetExchange::waitSMReady()
int tout = uniset_conf()->getArgInt("--unet-sm-ready-timeout", "15000");
timeout_t ready_timeout = 15000;
if( tout > 0 )
ready_timeout = tout;
else if( tout < 0 )
......
......@@ -76,6 +76,7 @@ int main(int argc, char* argv[])
while(1)
{
opt = getopt_long(argc, argv, "hs:c:r:p:n:t:x:blvdz:y:", longopts, &optindex);
if( opt == -1 )
break;
......
......@@ -18,7 +18,7 @@ UniExchange::NetNodeInfo::NetNodeInfo():
}
// --------------------------------------------------------------------------
UniExchange::UniExchange(UniSetTypes::ObjectId id, UniSetTypes::ObjectId shmID,
const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
const std::shared_ptr<SharedMemory>& ic, const std::string& prefix ):
IOController(id),
polltime(200),
mymap(1),
......
......@@ -296,7 +296,7 @@ namespace MTR
val = raw.u2.val * pow( (long)10, (long)raw.u2.exp );
}
T5( const ModbusRTU::ModbusData* data, int size ):val(0)
T5( const ModbusRTU::ModbusData* data, int size ): val(0)
{
if( size >= u2size )
{
......
......@@ -579,12 +579,12 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
&& d_on_msec != UniSetTimer::WaitUpTime
&& d_off_msec != UniSetTimer::WaitUpTime )
{
dlog->warn() << myname <<"(IOBase::readItem): "
<< " 'debouncedelay' is used in conjunction with the 'ondelay' and 'offdelay'. Sure?"
<< " [ debouncedelay=" << d_msec
<< " ondelay=" << d_on_msec
<< " offdelay=" << d_off_msec
<< " ]" << endl;
dlog->warn() << myname << "(IOBase::readItem): "
<< " 'debouncedelay' is used in conjunction with the 'ondelay' and 'offdelay'. Sure?"
<< " [ debouncedelay=" << d_msec
<< " ondelay=" << d_on_msec
<< " offdelay=" << d_off_msec
<< " ]" << endl;
}
......
......@@ -614,8 +614,8 @@ namespace MTR
{
std::ios_base::fmtflags old_flags = os.flags();
os << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< " " << setw(2) << t.day() << "/" << setw(2) << t.mon();
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< " " << setw(2) << t.day() << "/" << setw(2) << t.mon();
os.setf(old_flags);
return os;
}
......@@ -623,8 +623,8 @@ namespace MTR
{
std::ios_base::fmtflags old_flags = os.flags();
os << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< ":" << setw(2) << t.sec() << "." << setw(2) << t.ssec();
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< ":" << setw(2) << t.sec() << "." << setw(2) << t.ssec();
os.setf(old_flags);
return os;
}
......@@ -632,8 +632,8 @@ namespace MTR
{
std::ios_base::fmtflags old_flags = os.flags();
os << setfill('0') << dec
<< setw(4) << t.year() << "/" << setw(2) << t.mon()
<< "/" << setw(2) << t.day();
<< setw(4) << t.year() << "/" << setw(2) << t.mon()
<< "/" << setw(2) << t.day();
os.setf(old_flags);
return os;
}
......
......@@ -109,7 +109,7 @@ class LT_Object
\return Возвращает время [мсек] оставшееся до срабатывания очередного таймера
*/
virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
UniSetTypes::Message::Priority p = UniSetTypes::Message::High );
/*!
......
......@@ -72,7 +72,10 @@ class Trigger
return false;
}
inline bool get(){ return oldstate; }
inline bool get()
{
return oldstate;
}
private:
bool oldstate; /*!< предыдущее состояние */
......
......@@ -152,7 +152,7 @@ class UniSetManager:
typedef UniSetManagerList::iterator MListIterator;
int getObjectsInfo(const std::shared_ptr<UniSetManager>& mngr, UniSetTypes::SimpleInfoSeq* seq,
int begin, const long uplimit, CORBA::Long userparam );
int begin, const long uplimit, CORBA::Long userparam );
PortableServer::POA_var poa;
PortableServer::POAManager_var pman;
......
......@@ -116,6 +116,9 @@ class UniSetObject:
return (UniSetTypes::ObjectPtr)CORBA::Object::_duplicate(oref);
}
virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High ) override;
protected:
/*! обработка приходящих сообщений */
virtual void processingMessage( UniSetTypes::VoidMessage* msg );
......@@ -123,9 +126,6 @@ class UniSetObject:
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) {}
virtual timeout_t askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, clock_t ticks = -1,
UniSetTypes::Message::Priority p = UniSetTypes::Message::High ) override;
/*! Получить сообщение */
bool receiveMessage( UniSetTypes::VoidMessage& vm );
......
......@@ -123,7 +123,7 @@ bool UModbus::getBit( int addr, int mbreg, int mbfunc )throw(UException)
}
// --------------------------------------------------------------------------
long UModbus::mbread(int mbaddr, int mbreg, int mbfunc, const string& s_vtype, int nbit,
const string& new_ip, int new_port )throw(UException)
const string& new_ip, int new_port )throw(UException)
{
using namespace VTypes;
......
......@@ -994,7 +994,7 @@ mbErrCode ModbusClient::recv_pdu( ModbusByte qfunc, ModbusMessage& rbuf, timeout
{
size_t onum = 0;
while( (rlen+2) < sizeof(rbuf.data) && onum < mPreRDI.objNum )
while( (rlen + 2) < sizeof(rbuf.data) && onum < mPreRDI.objNum )
{
// сперва получаем два байта, для определения длины последующих данных
size_t szDataLen = 2; // object id + len
......
......@@ -96,7 +96,8 @@ mbErrCode ModbusRTUSlave::receive(const std::unordered_set<ModbusAddr>& vmbaddr,
if( aftersend_msec > 0 )
msleep(aftersend_msec);
// usleep(10000);
// usleep(10000);
return res;
}
......
......@@ -72,16 +72,18 @@ bool ModbusServer::checkAddr(const std::unordered_set<ModbusAddr>& vaddr, const
return true;
auto i = vaddr.find(addr);
return (i!=vaddr.end());
return (i != vaddr.end());
}
// --------------------------------------------------------------------------------
std::string ModbusServer::vaddr2str( const std::unordered_set<ModbusAddr>& vaddr )
{
ostringstream s;
s << "[ ";
for( const auto& a: vaddr )
for( const auto& a : vaddr )
s << addr2str(a) << " ";
s <<"]";
s << "]";
return std::move(s.str());
}
......@@ -583,7 +585,7 @@ mbErrCode ModbusServer::recv( const std::unordered_set<ModbusRTU::ModbusAddr>& v
{
bcnt = getNextData((unsigned char*)(&rbuf), sizeof(ModbusAddr));
if( bcnt > 0 && checkAddr(vaddr,rbuf.addr) )
if( bcnt > 0 && checkAddr(vaddr, rbuf.addr) )
{
begin = true;
break;
......@@ -599,7 +601,7 @@ mbErrCode ModbusServer::recv( const std::unordered_set<ModbusRTU::ModbusAddr>& v
// Lav: конечно стоит, нам же надо буфер чистить
*/
// Проверка кому адресован пакет... (только если не включён режим отвечать на любые адреса)
if( !(onBroadcast && rbuf.addr == BroadcastAddr) && !checkAddr(vaddr,rbuf.addr) )
if( !(onBroadcast && rbuf.addr == BroadcastAddr) && !checkAddr(vaddr, rbuf.addr) )
{
if( dlog->is_warn() )
{
......@@ -1505,7 +1507,7 @@ std::unordered_set<ModbusAddr> ModbusServer::addr2vaddr(ModbusAddr& mbaddr)
mbErrCode ModbusServer::receive_one( ModbusAddr a, timeout_t msec )
{
auto v = addr2vaddr(a);
return receive(v,msec);
return receive(v, msec);
}
// -------------------------------------------------------------------------
......@@ -1548,6 +1550,7 @@ ModbusRTU::mbErrCode ModbusServer::replyFileTransfer( const std::string& fname,
if( ret == -1 )
{
close(fd);
if( dlog && dlog->is_warn() )
(*dlog)[Debug::WARN] << "(replyFileTransfer): open '" << fname << "' with error: " << strerror(errno) << endl;
......@@ -1561,6 +1564,7 @@ ModbusRTU::mbErrCode ModbusServer::replyFileTransfer( const std::string& fname,
if( ret < 0 )
{
close(fd);
if( dlog && dlog->is_warn() )
(*dlog)[Debug::WARN] << "(replyFileTransfer): read from '" << fname << "' with error: " << strerror(errno) << endl;
......@@ -1572,6 +1576,7 @@ ModbusRTU::mbErrCode ModbusServer::replyFileTransfer( const std::string& fname,
if( fstat(fd, &fs) < 0 )
{
close(fd);
if( dlog && dlog->is_warn() )
(*dlog)[Debug::WARN] << "(replyFileTransfer): fstat for '" << fname << "' with error: " << strerror(errno) << endl;
......@@ -1620,7 +1625,7 @@ ModbusRTU::mbErrCode ModbusServer::replySetDateTime( ModbusRTU::SetDateTimeMessa
set.tv_sec = mktime(&t); // может вернуть -1 (!)
set.tv_usec = 0;
if( set.tv_sec >=0 && settimeofday(&set, &tz) == 0 )
if( set.tv_sec >= 0 && settimeofday(&set, &tz) == 0 )
{
// подтверждаем сохранение
// в ответе возвращаем установленное время...
......
......@@ -4,7 +4,7 @@ using namespace std;
using namespace ModbusRTU;
// -------------------------------------------------------------------------
size_t ModbusTCPCore::readNextData( ost::TCPStream* tcp,
std::queue<unsigned char>& qrecv, int max )
std::queue<unsigned char>& qrecv, int max )
{
if( !tcp || !tcp->isConnected() )
return 0;
......@@ -26,8 +26,8 @@ size_t ModbusTCPCore::readNextData( ost::TCPStream* tcp,
}
// ------------------------------------------------------------------------
size_t ModbusTCPCore::getNextData(ost::TCPStream* tcp,
std::queue<unsigned char>& qrecv,
unsigned char* buf, size_t len )
std::queue<unsigned char>& qrecv,
unsigned char* buf, size_t len )
{
if( !tcp || !tcp->isConnected() )
return 0;
......
......@@ -232,6 +232,7 @@ mbErrCode ModbusTCPServer::receive(const std::unordered_set<ModbusAddr>& vmbaddr
{
if( dlog->is_crit() )
dlog->crit() << "(ModbusTCPServer): " << e.what() << endl;
return erInternalErrorCode;
}
......
......@@ -33,8 +33,9 @@ ModbusTCPSession::ModbusTCPSession(ost::TCPSocket& server, const std::unordered_
{
setCRCNoCheckit(true);
timeout_t tout = timeout/1000;
if( tout <=0 )
timeout_t tout = timeout / 1000;
if( tout <= 0 )
tout = 3;
setKeepAlive(true);
......
......@@ -997,6 +997,7 @@ ModbusMessage ReadOutputRetMessage::transport_msg()
ind += bcnt;
}
// пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm), szModbusHeader + sizeof(bcnt) + bcnt );
......@@ -1209,6 +1210,7 @@ ModbusMessage ReadInputRetMessage::transport_msg()
ind += bcnt;
}
// пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm), szModbusHeader + sizeof(bcnt) + bcnt );
......
......@@ -28,6 +28,7 @@ bool UTCPStream::setKeepAliveParams(timeout_t timeout_sec, int keepcnt, int keep
SOCKET fd = TCPStream::so;
int enable = 1;
bool ok = true;
if( setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&enable, sizeof(enable)) == -1 )
ok = false;
......
......@@ -307,7 +307,7 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
log << buf;
}
else if( n == 0 && readcount <=0 )
else if( n == 0 && readcount <= 0 )
break;
if( rcount > 0 && readcount > 0 )
......
......@@ -31,6 +31,7 @@ LogServer::~LogServer()
if( thr )
{
thr->stop();
if( thr->isRunning() )
thr->join();
}
......
......@@ -19,6 +19,7 @@ using namespace UniSetTypes;
LogSession::~LogSession()
{
cancelled = true;
if( isRunning() )
{
ost::Thread::join();
......@@ -310,6 +311,7 @@ void LogSession::run()
disconnect();
cancelled = true;
if( slog.debugging(Debug::INFO) )
slog[Debug::INFO] << peername << "(run): thread stopping..." << endl;
......@@ -325,6 +327,7 @@ void LogSession::final()
try
{
auto s = shared_from_this();
if( s )
slFin(s);
}
......@@ -350,8 +353,8 @@ NullLogSession::~NullLogSession()
{
cancelled = true;
// if( isRunning() )
// exit(); // terminate();
// if( isRunning() )
// exit(); // terminate();
}
// ---------------------------------------------------------------------
void NullLogSession::add( ost::TCPSocket& sock )
......
......@@ -204,11 +204,14 @@ void terminate_thread()
g_act->terminated(g_signo);
#if 0
try
{
ulogsys << "TERMINATE THREAD: orb shutdown.." << endl;
if( g_act->orb )
g_act->orb->shutdown(true);
ulogsys << "TERMINATE THREAD: orb shutdown ok.." << endl;
}
catch( const omniORB::fatalException& fe )
......@@ -222,7 +225,9 @@ void terminate_thread()
{
ulogsys << "(TERMINATE THREAD): " << ex.what() << endl;
}
#endif
if( g_fini_thread && g_fini_thread->joinable() )
g_fini_thread->join();
......@@ -385,8 +390,10 @@ void UniSetActivator::uaDestroy(int signo)
try
{
ulogsys << myname << "(uaDestroy): shutdown orb... " << endl;
if( orb )
orb->shutdown(true);
ulogsys << myname << "(uaDestroy): shutdown ok." << endl;
}
catch( const omniORB::fatalException& fe )
......
......@@ -133,6 +133,7 @@ UniSetObject::UniSetObject( const string& name, const string& section ):
UniSetObject::~UniSetObject()
{
#if 0
try
{
deactivate();
......@@ -156,6 +157,7 @@ UniSetObject::~UniSetObject()
}
catch(...) {}
}
#endif
}
// ------------------------------------------------------------------------------------------
......
......@@ -196,6 +196,7 @@ namespace UniSetTypes
xmlNodesSec = 0;
// -------------------------------------------------------------------------
char curdir[FILENAME_MAX];
if( getcwd(curdir, FILENAME_MAX) == NULL )
rootDir = "";
else
......
......@@ -130,7 +130,8 @@ timeout_t LT_Object::getTimeInterval( TimerId timerid )
{
// lock
uniset_rwmutex_rlock lock(lstMutex);
for( const auto& li: tlst )
for( const auto& li : tlst )
{
if( li.id == timerid )
return li.tmr.getInterval();
......@@ -143,7 +144,8 @@ timeout_t LT_Object::getTimeLeft(TimerId timerid)
{
// lock
uniset_rwmutex_rlock lock(lstMutex);
for( const auto& li: tlst )
for( const auto& li : tlst )
{
if( li.id == timerid )
return li.curTimeMS;
......
......@@ -48,6 +48,7 @@ bool RunLock::isLocked( const string& name )
char ptr[10];
int n = fscanf( out, "%9s", ptr );
if( n < 1 )
{
fclose(out);
......
......@@ -117,8 +117,9 @@ void SMonitor::sensorInfo( const SensorMessage* si )
int ret = system(cmd.str().c_str());
int res = WEXITSTATUS(ret);
if( res != 0 )
cerr << "run script '" <<cmd.str() << "' failed.." << endl;
cerr << "run script '" << cmd.str() << "' failed.." << endl;
// if( WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
// {
......
......@@ -70,13 +70,13 @@
#define VMON_MAKE_PAIR(vlist, T) \
{\
for( const auto& e: m_##T ) \
vlist.push_back( std::make_pair(e.second, std::to_string(*(e.first))) );\
vlist.push_back( std::make_pair(e.second, std::to_string(*(e.first))) );\
}
// --------------------------------------------------------------------------
#define VMON_MAKE_PAIR_S(vlist, T) \
{\
for( const auto& e: m_##T ) \
vlist.push_back( std::make_pair(e.second,*e.first) );\
vlist.push_back( std::make_pair(e.second,*e.first) );\
}
// --------------------------------------------------------------------------
#define VMON_MAKE_PAIR2(vlist, T) \
......@@ -113,9 +113,12 @@ std::ostream& operator<<( std::ostream& os, VMonitor& m )
{
auto vlist = m.getList();
// сортируем по алфавиту
vlist.sort( []( const std::pair<std::string,std::string> &a, const std::pair<std::string,std::string> &b ) { return a.first < b.first; });
vlist.sort( []( const std::pair<std::string, std::string>& a, const std::pair<std::string, std::string>& b )
{
return a.first < b.first;
});
for( const auto& e: vlist )
for( const auto& e : vlist )
os << e.first << " = " << e.second;
return os;
......@@ -130,15 +133,15 @@ std::string VMonitor::str()
// --------------------------------------------------------------------------
std::list<std::pair<std::string, std::string> > VMonitor::getList()
{
std::list<std::pair<std::string,std::string>> vlist;
VMON_MAKE_PAIR2(vlist,int);
VMON_MAKE_PAIR2(vlist,long);
VMON_MAKE_PAIR2(vlist,short);
std::list<std::pair<std::string, std::string>> vlist;
VMON_MAKE_PAIR2(vlist, int);
VMON_MAKE_PAIR2(vlist, long);
VMON_MAKE_PAIR2(vlist, short);
VMON_MAKE_PAIR_CHAR(vlist);
VMON_MAKE_PAIR(vlist,bool);
VMON_MAKE_PAIR(vlist,float);
VMON_MAKE_PAIR(vlist,double);
VMON_MAKE_PAIR_S(vlist,string);
VMON_MAKE_PAIR(vlist, bool);
VMON_MAKE_PAIR(vlist, float);
VMON_MAKE_PAIR(vlist, double);
VMON_MAKE_PAIR_S(vlist, string);
return std::move(vlist);
}
// --------------------------------------------------------------------------
......@@ -148,13 +151,18 @@ std::string VMonitor::pretty_str( int namewidth, int colnum )
std::ostringstream os;
// сортируем по алфавиту
vlist.sort( []( const std::pair<std::string,std::string> &a, const std::pair<std::string,std::string> &b ) { return a.first < b.first; });
vlist.sort( []( const std::pair<std::string, std::string>& a, const std::pair<std::string, std::string>& b )
{
return a.first < b.first;
});
int n = 0;
for( const auto& e: vlist )
for( const auto& e : vlist )
{
os << std::right << std::setw(namewidth) << e.first << std::left << " = " << std::right << std::setw(10) << e.second;
if( (n++)%colnum )
if( (n++) % colnum )
os << std::endl;
}
......
......@@ -32,6 +32,7 @@ bool WDTInterface::ping()
}
int ret = write(fd, (void*)CMD_PING, sizeof(CMD_PING));
if( ret == -1 )
{
cerr << ": Unable to open device " << dev << " with err: " << strerror(errno) << endl;
......@@ -54,6 +55,7 @@ bool WDTInterface::stop()
}
int ret = write(fd, (void*)CMD_STOP, sizeof(CMD_STOP));
if( ret == -1 )
{
cerr << ": Unable to open device " << dev << " with err: " << strerror(errno) << endl;
......
......@@ -10,7 +10,7 @@ TEST_CASE("Pulse", "[Test for class 'Pulse' - impulse generator]" )
{
// Работа без задержки..(нулевые задержки)
Pulse p;
REQUIRE( p.getT1() == 0 );
REQUIRE( p.getT0() == 0 );
......
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