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();
......
......@@ -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;
......
......@@ -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;
// }
// }
}
// ------------------------------------------------------------------------------------------
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;
......
......@@ -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;
// }
}
// -----------------------------------------------------------------------------
......
......@@ -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);
......
......@@ -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);
}
......@@ -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);
}
......@@ -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; /*!< список входов/выходов по адресам */
......
......@@ -156,6 +156,7 @@ void RRDServer::initRRD( xmlNode* cnode, int tmID )
}
std::string dsname(it1.getProp(ds));
if( dsname.empty() )
dsname = it1.getProp("name");
......
......@@ -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;
......
......@@ -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 )
{
......
......@@ -29,7 +29,7 @@ class UObject_SK:
public UniSetObject
{
public:
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node=UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix="" );
UObject_SK( UniSetTypes::ObjectId id, xmlNode* node = UniSetTypes::uniset_conf()->getNode("UObject"), const std::string& argprefix = "" );
UObject_SK();
virtual ~UObject_SK();
......@@ -43,54 +43,60 @@ class UObject_SK:
virtual bool setMsg( UniSetTypes::ObjectId code, bool state = true );
inline std::shared_ptr<DebugStream> log(){ return mylog; }
inline std::shared_ptr<LogAgregator> logAgregator(){ return loga; }
inline std::shared_ptr<DebugStream> log()
{
return mylog;
}
inline std::shared_ptr<LogAgregator> logAgregator()
{
return loga;
}
void init_dlog( std::shared_ptr<DebugStream> d );
// "синтаксический сахар"..для логов
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
#ifndef myinfo
#define myinfo if( log()->debugging(Debug::INFO) ) log()->info()
#endif
#ifndef mywarn
#define mywarn if( log()->debugging(Debug::WARN) ) log()->warn()
#endif
#ifndef mycrit
#define mycrit if( log()->debugging(Debug::CRIT) ) log()->crit()
#endif
#ifndef mylog1
#define mylog1 if( log()->debugging(Debug::LEVEL1) ) log()->level1()
#endif
#ifndef mylog2
#define mylog2 if( log()->debugging(Debug::LEVEL2) ) log()->level2()
#endif
#ifndef mylog3
#define mylog3 if( log()->debugging(Debug::LEVEL3) ) log()->level3()
#endif
#ifndef mylog4
#define mylog4 if( log()->debugging(Debug::LEVEL4) ) log()->level4()
#endif
#ifndef mylog5
#define mylog5 if( log()->debugging(Debug::LEVEL5) ) log()->level5()
#endif
#ifndef mylog6
#define mylog6 if( log()->debugging(Debug::LEVEL6) ) log()->level6()
#endif
#ifndef mylog7
#define mylog7 if( log()->debugging(Debug::LEVEL7) ) log()->level7()
#endif
#ifndef mylog8
#define mylog8 if( log()->debugging(Debug::LEVEL8) ) log()->level8()
#endif
#ifndef mylog9
#define mylog9 if( log()->debugging(Debug::LEVEL9) ) log()->level9()
#endif
#ifndef mylogany
#define mylogany log()->any()
#endif
#ifndef vmonit
#define vmonit( var ) vmon.add( #var, var )
#endif
// Вспомогательные функции для удобства логирования
// ------------------------------------------------------------
......@@ -107,16 +113,19 @@ class UObject_SK:
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std::string str( UniSetTypes::ObjectId id, bool showLinkName=true );
std::string str( UniSetTypes::ObjectId id, bool showLinkName = true );
/*! Вывод значения входа/выхода в формате: in_xxx(SensorName)=val
\param id - идентификатор датчика
\param showLinkName - TRUE - выводить SensorName, FALSE - не выводить
*/
std::string strval( UniSetTypes::ObjectId id, bool showLinkName=true );
std::string strval( UniSetTypes::ObjectId id, bool showLinkName = true );
/*! Вывод состояния внутренних переменных */
inline std::string dumpVars(){ return std::move(vmon.pretty_str()); }
inline std::string dumpVars()
{
return std::move(vmon.pretty_str());
}
// ------------------------------------------------------------
std::string help();
......@@ -145,13 +154,16 @@ class UObject_SK:
virtual void callback() override;
virtual void processingMessage( UniSetTypes::VoidMessage* msg ) override;
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ){};
virtual void askSensors( UniversalIO::UIOCommand cmd ){}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override{}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override{}
virtual void sysCommand( const UniSetTypes::SystemMessage* sm ) {};
virtual void askSensors( UniversalIO::UIOCommand cmd ) {}
virtual void sensorInfo( const UniSetTypes::SensorMessage* sm ) override {}
virtual void timerInfo( const UniSetTypes::TimerMessage* tm ) override {}
virtual void sigterm( int signo ) override;
virtual bool activateObject() override;
virtual std::string getMonitInfo(){ return ""; } /*!< пользовательская информация выводимая в getInfo() */
virtual std::string getMonitInfo()
{
return ""; /*!< пользовательская информация выводимая в getInfo() */
}
virtual void testMode( bool state );
void updatePreviousValues();
......@@ -171,7 +183,7 @@ class UObject_SK:
int resetMsgTime;
// Выполнение очередного шага программы
virtual void step(){}
virtual void step() {}
int sleep_msec; /*!< пауза между итерациями */
bool active;
......@@ -186,9 +198,15 @@ class UObject_SK:
xmlNode* confnode;
/*! получить числовое свойство из конф. файла по привязанной confnode */
int getIntProp(const std::string& name) { return UniSetTypes::uniset_conf()->getIntProp(confnode, name); }
int getIntProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getIntProp(confnode, name);
}
/*! получить текстовое свойство из конф. файла по привязанной confnode */
inline const std::string getProp(const std::string& name) { return UniSetTypes::uniset_conf()->getProp(confnode, name); }
inline const std::string getProp(const std::string& name)
{
return UniSetTypes::uniset_conf()->getProp(confnode, name);
}
timeout_t smReadyTimeout; /*!< время ожидания готовности SM */
std::atomic_bool activated;
......
......@@ -579,7 +579,7 @@ 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): "
dlog->warn() << myname << "(IOBase::readItem): "
<< " 'debouncedelay' is used in conjunction with the 'ondelay' and 'offdelay'. Sure?"
<< " [ debouncedelay=" << d_msec
<< " ondelay=" << d_on_msec
......
......@@ -72,7 +72,10 @@ class Trigger
return false;
}
inline bool get(){ return oldstate; }
inline bool get()
{
return oldstate;
}
private:
bool oldstate; /*!< предыдущее состояние */
......
......@@ -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 );
......
......@@ -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 )
{
// подтверждаем сохранение
// в ответе возвращаем установленное время...
......
......@@ -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))
// {
......
......@@ -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;
......
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