Commit 562e8cd4 authored by Pavel Vainerman's avatar Pavel Vainerman

fixes after checking PVS-Studio (static anaylzer)

parent 2c035327
...@@ -19,6 +19,11 @@ clean-local: ...@@ -19,6 +19,11 @@ clean-local:
install-data-local: install-data-local:
$(MAKE) -C $(FIRSTSUBDIRS) -j1 install $(MAKE) -C $(FIRSTSUBDIRS) -j1 install
pvs-check:
make clean
pvs-studio-analyzer trace -- jmake
pvs-studio-analyzer analyze -j$(nproc)
plog-converter -a GA:1,2 -t tasklist -o uniset.pvs.tasks PVS-Studio.log
if HAVE_COVERAGE if HAVE_COVERAGE
COVERAGE_DIRS=$(COVERAGE_DEFAULT_DIRS) COVERAGE_DIRS=$(COVERAGE_DEFAULT_DIRS)
......
...@@ -27,3 +27,5 @@ More information: ...@@ -27,3 +27,5 @@ More information:
* [RU] https://habr.com/post/278535/ * [RU] https://habr.com/post/278535/
* [RU] https://habr.com/post/171711/ * [RU] https://habr.com/post/171711/
* [RU] https://wiki.etersoft.ru/UniSet2/docs/ * [RU] https://wiki.etersoft.ru/UniSet2/docs/
periodically checked by [PVS-Studio Analyzer](https://www.viva64.com/en/pvs-studio/)
...@@ -382,11 +382,6 @@ int main(int argc, char** argv) ...@@ -382,11 +382,6 @@ int main(int argc, char** argv)
return 0; return 0;
} }
catch( const uniset::Exception& ex )
{
if( !quiet )
cout << "admin(main): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( !quiet ) if( !quiet )
...@@ -407,6 +402,11 @@ int main(int argc, char** argv) ...@@ -407,6 +402,11 @@ int main(int argc, char** argv)
cerr << " mesg: " << fe.errmsg() << endl; cerr << " mesg: " << fe.errmsg() << endl;
} }
} }
catch( const uniset::Exception& ex )
{
if( !quiet )
cout << "admin(main): " << ex << endl;
}
catch( std::exception& ex ) catch( std::exception& ex )
{ {
if( !quiet ) if( !quiet )
...@@ -546,15 +546,15 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository ...@@ -546,15 +546,15 @@ static bool commandToAll(const string& section, std::shared_ptr<ObjectRepository
} }
} }
} }
catch( const uniset::Exception& ex ) catch( const CORBA::SystemException& ex )
{ {
if( !quiet ) if( !quiet )
cerr << setw(55) << oname << " <--- " << ex << endl; cerr << setw(55) << oname << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl;
} }
catch( const CORBA::SystemException& ex ) catch( const uniset::Exception& ex )
{ {
if( !quiet ) if( !quiet )
cerr << setw(55) << oname << " <--- недоступен!!(CORBA::SystemException): " << ex.NP_minorString() << endl; cerr << setw(55) << oname << " <--- " << ex << endl;
} }
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
...@@ -730,7 +730,7 @@ int getValue( const string& args, UInterface& ui ) ...@@ -730,7 +730,7 @@ int getValue( const string& args, UInterface& ui )
// до числа, то сперва получаем val // до числа, то сперва получаем val
long val = ui.getValue(it.si.id, it.si.node); long val = ui.getValue(it.si.id, it.si.node);
if( csv && num++ > 0 ) if( num++ > 0 )
cout << ","; cout << ",";
cout << val; cout << val;
...@@ -888,13 +888,6 @@ int getTimeChange( const std::string& args, UInterface& ui ) ...@@ -888,13 +888,6 @@ int getTimeChange( const std::string& args, UInterface& ui )
else else
cout << ui.getTimeChange(it.si.id, it.si.node); cout << ui.getTimeChange(it.si.id, it.si.node);
} }
catch( const uniset::Exception& ex )
{
if( !quiet )
cerr << "(getChangedTime): " << ex << endl;;
err = 1;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( !quiet ) if( !quiet )
...@@ -921,6 +914,13 @@ int getTimeChange( const std::string& args, UInterface& ui ) ...@@ -921,6 +914,13 @@ int getTimeChange( const std::string& args, UInterface& ui )
err = 1; err = 1;
} }
catch( const uniset::Exception& ex )
{
if( !quiet )
cerr << "(getChangedTime): " << ex << endl;;
err = 1;
}
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
if( !quiet ) if( !quiet )
......
...@@ -29,11 +29,11 @@ MBSlave::MBSlave(const std::unordered_set<ModbusAddr>& _vaddr, const std::string ...@@ -29,11 +29,11 @@ MBSlave::MBSlave(const std::unordered_set<ModbusAddr>& _vaddr, const std::string
// if( replyTimeout <= 0 ) // if( replyTimeout <= 0 )
// replyTimeout = 2000; // replyTimeout = 2000;
if( verbose ) // if( verbose )
cout << "(init): " // cout << "(init): "
<< " addr=" << ModbusServer::vaddr2str(vaddr) // << " addr=" << ModbusServer::vaddr2str(vaddr)
<< " dev=" << dev // << " dev=" << dev
<< " speed=" << speed; // << " speed=" << speed;
rscomm = new ModbusRTUSlaveSlot(dev, use485); rscomm = new ModbusRTUSlaveSlot(dev, use485);
......
...@@ -7,7 +7,7 @@ using namespace std; ...@@ -7,7 +7,7 @@ using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
if( argc < 2 || (argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) ) if( argc < 2 || (argc > 1 && ( !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) ) // -V560
{ {
cout << "Usage: lo2gval [ info,warn,crit,level1...level9,init,repository,system,exception | any ]" << endl; cout << "Usage: lo2gval [ info,warn,crit,level1...level9,init,repository,system,exception | any ]" << endl;
return 0; return 0;
......
...@@ -123,11 +123,6 @@ int main( int argc, char** argv ) ...@@ -123,11 +123,6 @@ int main( int argc, char** argv )
} }
} }
if( !checkfilter.empty() )
{
}
if( verb ) if( verb )
{ {
cout << "(init): listen " << addr << ":" << port cout << "(init): listen " << addr << ":" << port
......
...@@ -95,15 +95,15 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback() noexcept ...@@ -95,15 +95,15 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback() noexcept
updateOutputs(forceOut); updateOutputs(forceOut);
updatePreviousValues(); updatePreviousValues();
} }
catch( const uniset::Exception&amp; ex )
{
mycrit &lt;&lt; myname &lt;&lt; "(execute): " &lt;&lt; ex &lt;&lt; endl;
}
catch( const CORBA::SystemException&amp; ex ) catch( const CORBA::SystemException&amp; ex )
{ {
mycrit &lt;&lt; myname &lt;&lt; "(execute): СORBA::SystemException: " mycrit &lt;&lt; myname &lt;&lt; "(execute): СORBA::SystemException: "
&lt;&lt; ex.NP_minorString() &lt;&lt; endl; &lt;&lt; ex.NP_minorString() &lt;&lt; endl;
} }
catch( const uniset::Exception&amp; ex )
{
mycrit &lt;&lt; myname &lt;&lt; "(execute): " &lt;&lt; ex &lt;&lt; endl;
}
catch( const std::exception&amp; ex ) catch( const std::exception&amp; ex )
{ {
mycrit &lt;&lt; myname &lt;&lt; "(execute): catch " &lt;&lt; ex.what() &lt;&lt; endl; mycrit &lt;&lt; myname &lt;&lt; "(execute): catch " &lt;&lt; ex.what() &lt;&lt; endl;
...@@ -289,7 +289,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm ...@@ -289,7 +289,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm
</xsl:template> </xsl:template>
<xsl:template name="setdata"> <xsl:template name="setdata">
if( <xsl:value-of select="@name"/> != DefaultObjectId ) if( <xsl:value-of select="@name"/> != DefaultObjectId ) // -V547
{ {
try try
{ {
...@@ -307,7 +307,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm ...@@ -307,7 +307,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm
<xsl:template name="setdata_value"> <xsl:template name="setdata_value">
<xsl:param name="setval">0</xsl:param> <xsl:param name="setval">0</xsl:param>
if( <xsl:value-of select="@name"/> != DefaultObjectId ) if( <xsl:value-of select="@name"/> != DefaultObjectId ) // -V547
{ {
try try
{ {
......
...@@ -231,7 +231,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::initFromSM() ...@@ -231,7 +231,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::initFromSM()
<xsl:template name="setdata"> <xsl:template name="setdata">
try try
{ {
if( <xsl:value-of select="@name"/> != DefaultObjectId ) if( <xsl:value-of select="@name"/> != DefaultObjectId ) // -V547
{ {
si.id = <xsl:value-of select="@name"/>; si.id = <xsl:value-of select="@name"/>;
si.node = node_<xsl:value-of select="@name"/>; si.node = node_<xsl:value-of select="@name"/>;
......
...@@ -1263,7 +1263,7 @@ end_private(false) ...@@ -1263,7 +1263,7 @@ end_private(false)
sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'sleep-msec'"/></xsl:call-template>", <xsl:call-template name="settings"><xsl:with-param name="varname" select="'sleep-msec'"/></xsl:call-template>); sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","<xsl:call-template name="settings"><xsl:with-param name="varname" select="'sleep-msec'"/></xsl:call-template>", <xsl:call-template name="settings"><xsl:with-param name="varname" select="'sleep-msec'"/></xsl:call-template>);
string s_resetTime("<xsl:call-template name="settings"><xsl:with-param name="varname" select="'resetMsgTime'"/></xsl:call-template>"); string s_resetTime("<xsl:call-template name="settings"><xsl:with-param name="varname" select="'resetMsgTime'"/></xsl:call-template>");
if( s_resetTime.empty() ) if( s_resetTime.empty() ) // -V547
s_resetTime = "500"; s_resetTime = "500";
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime)); resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime));
...@@ -1285,7 +1285,7 @@ end_private(false) ...@@ -1285,7 +1285,7 @@ end_private(false)
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
if( smTestID == DefaultObjectId ) if( smTestID == DefaultObjectId ) // -V547
smTestID = getSMTestID(); smTestID = getSMTestID();
activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 120000); activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 120000);
......
...@@ -192,7 +192,7 @@ void DBServer_PostgreSQL::flushInsertBuffer() ...@@ -192,7 +192,7 @@ void DBServer_PostgreSQL::flushInsertBuffer()
// Чистим заданное число // Чистим заданное число
size_t delnum = lroundf(ibufSize * ibufOverflowCleanFactor); size_t delnum = lroundf(ibufSize * ibufOverflowCleanFactor);
auto end = ibuf.end(); auto end = ibuf.end();
auto beg = ibuf.end(); auto beg = ibuf.begin();
// Удаляем последние (новые) // Удаляем последние (новые)
if( lastRemove ) if( lastRemove )
...@@ -202,8 +202,6 @@ void DBServer_PostgreSQL::flushInsertBuffer() ...@@ -202,8 +202,6 @@ void DBServer_PostgreSQL::flushInsertBuffer()
else else
{ {
// Удаляем первые (старые) // Удаляем первые (старые)
beg = ibuf.begin();
end = ibuf.begin();
std::advance(end, delnum); std::advance(end, delnum);
} }
......
...@@ -158,15 +158,13 @@ namespace uniset ...@@ -158,15 +158,13 @@ namespace uniset
{ {
ComediInterface::SubdevType st = ComediInterface::str2type(stype.c_str()); ComediInterface::SubdevType st = ComediInterface::str2type(stype.c_str());
if( !stype.empty() && st == ComediInterface::Unknown ) if( st == ComediInterface::Unknown )
{ {
ostringstream err; ostringstream err;
err << "Unknown subdev type '" << stype << " for " << t1.str(); err << "Unknown subdev type '" << stype << " for " << t1.str();
throw SystemError(err.str()); throw SystemError(err.str());
} }
if( !stype.empty() )
{
ioinfo << myname ioinfo << myname
<< "(init): card" << i << "(init): card" << i
<< " subdev" << s << " set type " << stype << endl; << " subdev" << s << " set type " << stype << endl;
...@@ -176,7 +174,6 @@ namespace uniset ...@@ -176,7 +174,6 @@ namespace uniset
} }
} }
} }
}
ioinfo << myname << "(init): result numcards=" << cards.size() << endl; ioinfo << myname << "(init): result numcards=" << cards.size() << endl;
...@@ -469,15 +466,15 @@ namespace uniset ...@@ -469,15 +466,15 @@ namespace uniset
ptHeartBeat.reset(); ptHeartBeat.reset();
} }
} }
catch( const uniset::Exception& ex )
{
iolog3 << myname << "(execute): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
iolog3 << myname << "(execute): CORBA::SystemException: " iolog3 << myname << "(execute): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
iolog3 << myname << "(execute): " << ex << endl;
}
catch(...) catch(...)
{ {
iolog3 << myname << "(execute): catch ..." << endl; iolog3 << myname << "(execute): catch ..." << endl;
...@@ -733,15 +730,15 @@ namespace uniset ...@@ -733,15 +730,15 @@ namespace uniset
{ {
iolog3 << myname << "(iopoll): (BadRange)..." << endl; iolog3 << myname << "(iopoll): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
iolog3 << myname << "(iopoll): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
iolog3 << myname << "(iopoll): СORBA::SystemException: " iolog3 << myname << "(iopoll): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
iolog3 << myname << "(iopoll): " << ex << endl;
}
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void IOControl::readConfiguration() void IOControl::readConfiguration()
......
...@@ -201,6 +201,14 @@ namespace uniset ...@@ -201,6 +201,14 @@ namespace uniset
delete (*this)[i]; delete (*this)[i];
} }
inline ComediInterface* getCard( int ncard ) const
{
if( ncard > 0 && ncard < size() )
return (*this)[ncard];
return nullptr;
}
inline ComediInterface* getCard( size_t ncard ) const inline ComediInterface* getCard( size_t ncard ) const
{ {
if( ncard < size() ) if( ncard < size() )
...@@ -253,21 +261,11 @@ namespace uniset ...@@ -253,21 +261,11 @@ namespace uniset
IOInfo( IOInfo&& r ) = default; IOInfo( IOInfo&& r ) = default;
IOInfo& operator=(IOInfo&& r) = default; IOInfo& operator=(IOInfo&& r) = default;
IOInfo(): IOInfo(){}
subdev(DefaultSubdev), channel(DefaultChannel),
ncard(-1),
aref(0),
range(0),
lamp(false),
no_testlamp(false),
enable_testmode(false),
disable_testmode(false)
{}
int subdev; /*!< (UNIO) подустройство (см. comedi_test для конкретной карты в/в) */ int subdev = { DefaultSubdev }; /*!< (UNIO) подустройство (см. comedi_test для конкретной карты в/в) */
int channel; /*!< (UNIO) канал [0...23] */ int channel = { DefaultChannel }; /*!< (UNIO) канал [0...23] */
int ncard; /*!< номер карты [1|2]. -1 - не определена. */ int ncard = { DefaultCard }; /*!< номер карты [1|2]. -1 - не определена. */
/*! Вид подключения /*! Вид подключения
0 - analog ref = analog ground 0 - analog ref = analog ground
...@@ -275,9 +273,9 @@ namespace uniset ...@@ -275,9 +273,9 @@ namespace uniset
2 - analog ref = differential 2 - analog ref = differential
3 - analog ref = other (undefined) 3 - analog ref = other (undefined)
*/ */
int aref; int aref = { 0 };
int adelay; /*! Задержка на чтение аналоговых входов с мультиплексированием ( в мкс ) */ int adelay = { 0 }; /*! Задержка на чтение аналоговых входов с мультиплексированием ( в мкс ) */
/*! Измерительный диапазон /*! Измерительный диапазон
0 - -10В - 10В 0 - -10В - 10В
...@@ -285,12 +283,12 @@ namespace uniset ...@@ -285,12 +283,12 @@ namespace uniset
2 - -2.5В - 2.5В 2 - -2.5В - 2.5В
3 - -1.25В - 1.25В 3 - -1.25В - 1.25В
*/ */
int range; int range = { 0 };
bool lamp; /*!< признак, что данный выход является лампочкой (или сигнализатором) */ bool lamp = { false }; /*!< признак, что данный выход является лампочкой (или сигнализатором) */
bool no_testlamp; /*!< флаг исключения из 'проверки ламп' */ bool no_testlamp = { false }; /*!< флаг исключения из 'проверки ламп' */
bool enable_testmode; /*!< флаг для режима тестирования tmConfigEnable */ bool enable_testmode = { false }; /*!< флаг для режима тестирования tmConfigEnable */
bool disable_testmode; /*!< флаг для режима тестирования tmConfigDisable */ bool disable_testmode = { false }; /*!< флаг для режима тестирования tmConfigDisable */
friend std::ostream& operator<<(std::ostream& os, const IOInfo& inf ); friend std::ostream& operator<<(std::ostream& os, const IOInfo& inf );
friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<IOInfo>& inf ); friend std::ostream& operator<<(std::ostream& os, const std::shared_ptr<IOInfo>& inf );
......
...@@ -302,7 +302,7 @@ int main(int argc, char* argv[]) ...@@ -302,7 +302,7 @@ int main(int argc, char* argv[])
} }
} }
if( !blink ) if( blink == 0 ) // -V776
break; break;
val = val ? 0 : 1; val = val ? 0 : 1;
......
...@@ -30,22 +30,6 @@ namespace uniset ...@@ -30,22 +30,6 @@ namespace uniset
using namespace std; using namespace std;
using namespace uniset::extensions; using namespace uniset::extensions;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// вспомогательная структура для предотвращения утечки памяти
struct DataGuard
{
DataGuard( size_t sz )
{
data = new ModbusRTU::ModbusData[sz];
}
~DataGuard()
{
delete[] data;
}
ModbusRTU::ModbusData* data;
};
// -----------------------------------------------------------------------------
MBExchange::MBExchange(uniset::ObjectId objId, uniset::ObjectId shmId, MBExchange::MBExchange(uniset::ObjectId objId, uniset::ObjectId shmId,
const std::shared_ptr<SharedMemory>& _ic, const std::string& prefix ): const std::shared_ptr<SharedMemory>& _ic, const std::string& prefix ):
UniSetObject(objId), UniSetObject(objId),
...@@ -793,7 +777,7 @@ namespace uniset ...@@ -793,7 +777,7 @@ namespace uniset
case ModbusRTU::fnReadInputStatus: case ModbusRTU::fnReadInputStatus:
{ {
ModbusRTU::ReadInputStatusRetMessage ret = mb->read02(dev->mbaddr, p->mbreg, q_count); ModbusRTU::ReadInputStatusRetMessage ret = mb->read02(dev->mbaddr, p->mbreg, q_count);
DataGuard d(q_count); ModbusRTU::DataGuard d(q_count);
size_t m = 0; size_t m = 0;
for( size_t i = 0; i < ret.bcnt; i++ ) for( size_t i = 0; i < ret.bcnt; i++ )
...@@ -804,14 +788,14 @@ namespace uniset ...@@ -804,14 +788,14 @@ namespace uniset
d.data[m] = b[k]; d.data[m] = b[k];
} }
p->initOK = initSMValue(d.data, q_count, &(p->p)); p->initOK = initSMValue(d.data, d.len, &(p->p));
} }
break; break;
case ModbusRTU::fnReadCoilStatus: case ModbusRTU::fnReadCoilStatus:
{ {
ModbusRTU::ReadCoilRetMessage ret = mb->read01(dev->mbaddr, p->mbreg, q_count); ModbusRTU::ReadCoilRetMessage ret = mb->read01(dev->mbaddr, p->mbreg, q_count);
DataGuard d(q_count); ModbusRTU::DataGuard d(q_count);
size_t m = 0; size_t m = 0;
for( size_t i = 0; i < ret.bcnt; i++ ) for( size_t i = 0; i < ret.bcnt; i++ )
...@@ -822,7 +806,7 @@ namespace uniset ...@@ -822,7 +806,7 @@ namespace uniset
d.data[m] = b[k]; d.data[m] = b[k];
} }
p->initOK = initSMValue(d.data, q_count, &(p->p)); p->initOK = initSMValue(d.data, d.len, &(p->p));
} }
break; break;
...@@ -930,7 +914,7 @@ namespace uniset ...@@ -930,7 +914,7 @@ namespace uniset
else if( p->vType == VTypes::vtF4 ) else if( p->vType == VTypes::vtF4 )
{ {
VTypes::F4 f(data, VTypes::F4::wsize()); VTypes::F4 f(data, VTypes::F4::wsize());
IOBase::processingFasAI( p, (float)f, shm, true ); IOBase::processingF64asAI( p, (double)f, shm, true );
} }
else if( p->vType == VTypes::vtI2 ) else if( p->vType == VTypes::vtI2 )
{ {
...@@ -967,15 +951,15 @@ namespace uniset ...@@ -967,15 +951,15 @@ namespace uniset
{ {
mblog3 << myname << "(initSMValue): (BadRange)..." << endl; mblog3 << myname << "(initSMValue): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(initSMValue): " << ex << endl;
}
catch( const CORBA::SystemException& ex) catch( const CORBA::SystemException& ex)
{ {
mblog3 << myname << "(initSMValue): CORBA::SystemException: " mblog3 << myname << "(initSMValue): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(initSMValue): " << ex << endl;
}
catch(...) catch(...)
{ {
mblog3 << myname << "(initSMValue): catch ..." << endl; mblog3 << myname << "(initSMValue): catch ..." << endl;
...@@ -1227,15 +1211,15 @@ namespace uniset ...@@ -1227,15 +1211,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateSM): (BadRange)..." << endl; mblog3 << myname << "(updateSM): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateSM): CORBA::SystemException: " mblog3 << myname << "(updateSM): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( std::exception& ex ) catch( std::exception& ex )
{ {
mblog3 << myname << "(updateSM): check modeSensor: " << ex.what() << endl; mblog3 << myname << "(updateSM): check modeSensor: " << ex.what() << endl;
...@@ -1265,15 +1249,15 @@ namespace uniset ...@@ -1265,15 +1249,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateSM): (BadRange)..." << endl; mblog3 << myname << "(updateSM): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateSM): CORBA::SystemException: " mblog3 << myname << "(updateSM): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( std::exception& ex ) catch( std::exception& ex )
{ {
mblog3 << myname << "(updateSM): check safemodeSensor: " << ex.what() << endl; mblog3 << myname << "(updateSM): check safemodeSensor: " << ex.what() << endl;
...@@ -1313,15 +1297,15 @@ namespace uniset ...@@ -1313,15 +1297,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateSM): (BadRange)..." << endl; mblog3 << myname << "(updateSM): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateSM): CORBA::SystemException: " mblog3 << myname << "(updateSM): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateSM): " << ex << endl;
}
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
mblog3 << myname << "(updateSM): catch ..." << endl; mblog3 << myname << "(updateSM): catch ..." << endl;
...@@ -1596,7 +1580,7 @@ namespace uniset ...@@ -1596,7 +1580,7 @@ namespace uniset
if( p->vType == VTypes::vtF2 ) if( p->vType == VTypes::vtF2 )
{ {
VTypes::F2 f1(d.data, VTypes::F2::wsize()); VTypes::F2 f1(d.data, d.len);
f = (float)f1; f = (float)f1;
} }
else if( p->vType == VTypes::vtF2r ) else if( p->vType == VTypes::vtF2r )
...@@ -1640,9 +1624,9 @@ namespace uniset ...@@ -1640,9 +1624,9 @@ namespace uniset
for( size_t k = 0; k < VTypes::F4::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::F4::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
VTypes::F4 f(d.data, VTypes::F4::wsize()); VTypes::F4 f(d.data, d.len);
IOBase::processingFasAI( p, (float)f, shm, force ); IOBase::processingF64asAI( p, (double)f, shm, force );
} }
} }
} }
...@@ -1691,12 +1675,12 @@ namespace uniset ...@@ -1691,12 +1675,12 @@ namespace uniset
if( p->vType == VTypes::vtI2 ) if( p->vType == VTypes::vtI2 )
{ {
VTypes::I2 i2(d.data, VTypes::I2::wsize()); VTypes::I2 i2(d.data, d.len);
v = (int)i2; v = (int)i2;
} }
else if( p->vType == VTypes::vtI2r ) else if( p->vType == VTypes::vtI2r )
{ {
VTypes::I2r i2(d.data, VTypes::I2::wsize()); VTypes::I2r i2(d.data, d.len);
v = (int)i2; v = (int)i2;
} }
...@@ -1704,7 +1688,7 @@ namespace uniset ...@@ -1704,7 +1688,7 @@ namespace uniset
} }
} }
} }
else if( p->vType == VTypes::vtU2 || p->vType == VTypes::vtU2r ) else if( p->vType == VTypes::vtU2 || p->vType == VTypes::vtU2r ) // -V560
{ {
auto i = p->reg->rit; auto i = p->reg->rit;
...@@ -1750,12 +1734,12 @@ namespace uniset ...@@ -1750,12 +1734,12 @@ namespace uniset
if( p->vType == VTypes::vtU2 ) if( p->vType == VTypes::vtU2 )
{ {
VTypes::U2 u2(d.data, VTypes::U2::wsize()); VTypes::U2 u2(d.data, d.len);
v = (uint32_t)u2; v = (uint32_t)u2;
} }
else if( p->vType == VTypes::vtU2r ) else if( p->vType == VTypes::vtU2r )
{ {
VTypes::U2r u2(d.data, VTypes::U2::wsize()); VTypes::U2r u2(d.data, d.len);
v = (uint32_t)u2; v = (uint32_t)u2;
} }
...@@ -1778,15 +1762,15 @@ namespace uniset ...@@ -1778,15 +1762,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateRSProperty): (BadRange)..." << endl; mblog3 << myname << "(updateRSProperty): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateRSProperty): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateRSProperty): CORBA::SystemException: " mblog3 << myname << "(updateRSProperty): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateRSProperty): " << ex << endl;
}
catch(...) catch(...)
{ {
mblog3 << myname << "(updateRSProperty): catch ..." << endl; mblog3 << myname << "(updateRSProperty): catch ..." << endl;
...@@ -1886,7 +1870,7 @@ namespace uniset ...@@ -1886,7 +1870,7 @@ namespace uniset
for( size_t k = 0; k < MTR::T3::wsize(); k++, i++ ) for( size_t k = 0; k < MTR::T3::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
MTR::T3 t(d.data, MTR::T3::wsize()); MTR::T3 t(d.data, d.len);
IOBase::processingAsAI( &(*it), (long)t, shm, force ); IOBase::processingAsAI( &(*it), (long)t, shm, force );
} }
} }
...@@ -1942,7 +1926,7 @@ namespace uniset ...@@ -1942,7 +1926,7 @@ namespace uniset
for( size_t k = 0; k < MTR::T5::wsize(); k++, i++ ) for( size_t k = 0; k < MTR::T5::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
MTR::T5 t(d.data, MTR::T5::wsize()); MTR::T5 t(d.data, d.len);
IOBase::processingFasAI( &(*it), (float)t.val, shm, force ); IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
} }
...@@ -1977,7 +1961,7 @@ namespace uniset ...@@ -1977,7 +1961,7 @@ namespace uniset
for( size_t k = 0; k < MTR::T6::wsize(); k++, i++ ) for( size_t k = 0; k < MTR::T6::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
MTR::T6 t(d.data, MTR::T6::wsize()); MTR::T6 t(d.data, d.len);
IOBase::processingFasAI( &(*it), (float)t.val, shm, force ); IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
} }
...@@ -2011,7 +1995,7 @@ namespace uniset ...@@ -2011,7 +1995,7 @@ namespace uniset
for( size_t k = 0; k < MTR::T7::wsize(); k++, i++ ) for( size_t k = 0; k < MTR::T7::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
MTR::T7 t(d.data, MTR::T7::wsize()); MTR::T7 t(d.data, d.len);
IOBase::processingFasAI( &(*it), (float)t.val, shm, force ); IOBase::processingFasAI( &(*it), (float)t.val, shm, force );
} }
...@@ -2098,7 +2082,7 @@ namespace uniset ...@@ -2098,7 +2082,7 @@ namespace uniset
for( size_t k = 0; k < MTR::F1::wsize(); k++, i++ ) for( size_t k = 0; k < MTR::F1::wsize(); k++, i++ )
d.data[k] = i->second->mbval; d.data[k] = i->second->mbval;
MTR::F1 t(d.data, MTR::F1::wsize()); MTR::F1 t(d.data, d.len);
IOBase::processingFasAI( &(*it), (float)t, shm, force ); IOBase::processingFasAI( &(*it), (float)t, shm, force );
} }
} }
...@@ -2118,15 +2102,15 @@ namespace uniset ...@@ -2118,15 +2102,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateMTR): (BadRange)..." << endl; mblog3 << myname << "(updateMTR): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateMTR): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateMTR): CORBA::SystemException: " mblog3 << myname << "(updateMTR): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateMTR): " << ex << endl;
}
catch(...) catch(...)
{ {
mblog3 << myname << "(updateMTR): catch ..." << endl; mblog3 << myname << "(updateMTR): catch ..." << endl;
...@@ -2185,15 +2169,15 @@ namespace uniset ...@@ -2185,15 +2169,15 @@ namespace uniset
{ {
mblog3 << myname << "(updateRTU188): (BadRange)..." << endl; mblog3 << myname << "(updateRTU188): (BadRange)..." << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateRTU188): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mblog3 << myname << "(updateRTU188): CORBA::SystemException: " mblog3 << myname << "(updateRTU188): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mblog3 << myname << "(updateRTU188): " << ex << endl;
}
catch(...) catch(...)
{ {
mblog3 << myname << "(updateRTU188): catch ..." << endl; mblog3 << myname << "(updateRTU188): catch ..." << endl;
......
...@@ -118,7 +118,7 @@ int main( int argc, const char** argv ) ...@@ -118,7 +118,7 @@ int main( int argc, const char** argv )
<< " v[1]=" << v[1] << " v[1]=" << v[1]
<< " v[2]=" << v[2] << " v[2]=" << v[2]
<< " v[3]=" << v[3] << " v[3]=" << v[3]
<< " --> (float) " << (float)f << endl; << " --> (float64) " << (double)f << endl;
} }
else if( !strcmp(type, "I2") ) else if( !strcmp(type, "I2") )
{ {
......
...@@ -1933,13 +1933,12 @@ namespace uniset ...@@ -1933,13 +1933,12 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::I2::wsize()]; ModbusRTU::DataGuard d(VTypes::I2::wsize());
for( size_t k = 0; k < VTypes::I2::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::I2::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::I2 i2(d, VTypes::I2::wsize()); VTypes::I2 i2(d.data, d.len);
delete[] d;
IOBase::processingAsAI( p, (long)i2, shm, force ); IOBase::processingAsAI( p, (long)i2, shm, force );
} }
else if( p->vtype == VTypes::vtI2r ) else if( p->vtype == VTypes::vtI2r )
...@@ -1950,13 +1949,12 @@ namespace uniset ...@@ -1950,13 +1949,12 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::I2r::wsize()]; ModbusRTU::DataGuard d(VTypes::I2r::wsize());
for( size_t k = 0; k < VTypes::I2r::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::I2r::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::I2r i2r(d, VTypes::I2r::wsize()); VTypes::I2r i2r(d.data, d.len);
delete[] d;
IOBase::processingAsAI( p, (long)i2r, shm, force ); IOBase::processingAsAI( p, (long)i2r, shm, force );
} }
else if( p->vtype == VTypes::vtU2 ) else if( p->vtype == VTypes::vtU2 )
...@@ -1967,13 +1965,12 @@ namespace uniset ...@@ -1967,13 +1965,12 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::U2::wsize()]; ModbusRTU::DataGuard d(VTypes::U2::wsize());
for( size_t k = 0; k < VTypes::U2::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::U2::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::U2 u2(d, VTypes::U2::wsize()); VTypes::U2 u2(d.data, d.len);
delete[] d;
IOBase::processingAsAI( p, (unsigned long)u2, shm, force ); IOBase::processingAsAI( p, (unsigned long)u2, shm, force );
} }
else if( p->vtype == VTypes::vtU2r ) else if( p->vtype == VTypes::vtU2r )
...@@ -1984,13 +1981,12 @@ namespace uniset ...@@ -1984,13 +1981,12 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::U2r::wsize()]; ModbusRTU::DataGuard d(VTypes::U2r::wsize());
for( size_t k = 0; k < VTypes::U2r::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::U2r::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::U2r u2r(d, VTypes::U2r::wsize()); VTypes::U2r u2r(d.data, d.len);
delete[] d;
IOBase::processingAsAI( p, (unsigned long)u2r, shm, force ); IOBase::processingAsAI( p, (unsigned long)u2r, shm, force );
} }
else if( p->vtype == VTypes::vtF2 ) else if( p->vtype == VTypes::vtF2 )
...@@ -2001,14 +1997,12 @@ namespace uniset ...@@ -2001,14 +1997,12 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::F2::wsize()]; ModbusRTU::DataGuard d(VTypes::F2::wsize());
for( size_t k = 0; k < VTypes::F2::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::F2::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::F2 f2(d, VTypes::F2::wsize());
delete[] d;
VTypes::F2 f2(d.data, d.len);
IOBase::processingFasAI( p, (float)f2, shm, force ); IOBase::processingFasAI( p, (float)f2, shm, force );
} }
else if( p->vtype == VTypes::vtF2r ) else if( p->vtype == VTypes::vtF2r )
...@@ -2019,13 +2013,11 @@ namespace uniset ...@@ -2019,13 +2013,11 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::F2r::wsize()]; ModbusRTU::DataGuard d(VTypes::F2r::wsize());
for( size_t k = 0; k < VTypes::F2r::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::F2r::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::F2r f2r(d, VTypes::F2r::wsize()); VTypes::F2r f2r(d.data, d.len);
delete[] d;
IOBase::processingFasAI( p, (float)f2r, shm, force ); IOBase::processingFasAI( p, (float)f2r, shm, force );
} }
else if( p->vtype == VTypes::vtF4 ) else if( p->vtype == VTypes::vtF4 )
...@@ -2036,15 +2028,13 @@ namespace uniset ...@@ -2036,15 +2028,13 @@ namespace uniset
return ModbusRTU::erInvalidFormat; return ModbusRTU::erInvalidFormat;
} }
ModbusRTU::ModbusData* d = new ModbusRTU::ModbusData[VTypes::F4::wsize()]; ModbusRTU::DataGuard d(VTypes::F4::wsize());
for( size_t k = 0; k < VTypes::F4::wsize(); k++, i++ ) for( size_t k = 0; k < VTypes::F4::wsize(); k++, i++ )
d[k] = dat[i]; d.data[k] = dat[i];
VTypes::F4 f4(d, VTypes::F4::wsize());
delete[] d;
IOBase::processingFasAI( p, (float)f4, shm, force ); VTypes::F4 f4(d.data, d.len);
IOBase::processingFasAI( p, (double)f4, shm, force );
} }
else if( p->vtype == VTypes::vtByte ) else if( p->vtype == VTypes::vtByte )
{ {
...@@ -2078,17 +2068,17 @@ namespace uniset ...@@ -2078,17 +2068,17 @@ namespace uniset
mbwarn << myname << "(real_write_prop): " << ex << endl; mbwarn << myname << "(real_write_prop): " << ex << endl;
return ModbusRTU::erBadDataValue; return ModbusRTU::erBadDataValue;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(real_write_prop): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( smPingOK ) if( smPingOK )
mbcrit << myname << "(real_write_prop): СORBA::SystemException: " mbcrit << myname << "(real_write_prop): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(real_write_prop): " << ex << endl;
}
catch(...) catch(...)
{ {
if( smPingOK ) if( smPingOK )
...@@ -2456,17 +2446,17 @@ namespace uniset ...@@ -2456,17 +2446,17 @@ namespace uniset
mbwarn << myname << "(real_read_prop): " << ex << endl; mbwarn << myname << "(real_read_prop): " << ex << endl;
return ModbusRTU::erBadDataValue; return ModbusRTU::erBadDataValue;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(real_read_prop): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( smPingOK ) if( smPingOK )
mbcrit << myname << "(real_read_prop): CORBA::SystemException: " mbcrit << myname << "(real_read_prop): CORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(real_read_prop): " << ex << endl;
}
catch(...) catch(...)
{ {
if( smPingOK ) if( smPingOK )
...@@ -2608,17 +2598,17 @@ namespace uniset ...@@ -2608,17 +2598,17 @@ namespace uniset
mbwarn << myname << "(readCoilStatus): " << ex << endl; mbwarn << myname << "(readCoilStatus): " << ex << endl;
return ModbusRTU::erBadDataAddress; return ModbusRTU::erBadDataAddress;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(readCoilStatus): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( smPingOK ) if( smPingOK )
mbcrit << myname << "(readCoilStatus): СORBA::SystemException: " mbcrit << myname << "(readCoilStatus): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(readCoilStatus): " << ex << endl;
}
catch(...) catch(...)
{ {
if( smPingOK ) if( smPingOK )
...@@ -2687,17 +2677,17 @@ namespace uniset ...@@ -2687,17 +2677,17 @@ namespace uniset
mbwarn << myname << "(readInputStatus): " << ex << endl; mbwarn << myname << "(readInputStatus): " << ex << endl;
return ModbusRTU::erBadDataAddress; return ModbusRTU::erBadDataAddress;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(readInputStatus): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
if( smPingOK ) if( smPingOK )
mbcrit << myname << "(readInputStatus): СORBA::SystemException: " mbcrit << myname << "(readInputStatus): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
if( smPingOK )
mbcrit << myname << "(readInputStatus): " << ex << endl;
}
catch(...) catch(...)
{ {
if( smPingOK ) if( smPingOK )
......
...@@ -6,6 +6,7 @@ uniset2-start.sh -f ./uniset2-mbslave --confile test.xml \ ...@@ -6,6 +6,7 @@ uniset2-start.sh -f ./uniset2-mbslave --confile test.xml \
--mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 2048 --mbs-reg-from-id 1 --mbs-my-addr 0x01 \ --mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 2048 --mbs-reg-from-id 1 --mbs-my-addr 0x01 \
--mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 --ulog-add-levels system \ --mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 --ulog-add-levels system \
--mbs-log-add-levels any $* --mbs-log-add-levels any $*
# --mbs-exchangelog-add-levels any $*
# --mbs-force 1 # --mbs-force 1
#--mbs-reg-from-id 1 \ #--mbs-reg-from-id 1 \
#--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \ #--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \
\ No newline at end of file
...@@ -54,14 +54,14 @@ int main( int argc, const char** argv ) ...@@ -54,14 +54,14 @@ int main( int argc, const char** argv )
act->run(false); act->run(false);
return 0; return 0;
} }
catch(Exception& ex)
{
cerr << "(mbslave_perf_test): " << ex << endl;
}
catch( CORBA::SystemException& ex ) catch( CORBA::SystemException& ex )
{ {
cerr << "(mbslave_perf_test): " << ex.NP_minorString() << endl; cerr << "(mbslave_perf_test): " << ex.NP_minorString() << endl;
} }
catch( Exception& ex )
{
cerr << "(mbslave_perf_test): " << ex << endl;
}
catch(...) catch(...)
{ {
cerr << "(mbslave_perf_test): catch(...)" << endl; cerr << "(mbslave_perf_test): catch(...)" << endl;
......
...@@ -12,5 +12,5 @@ cd - ...@@ -12,5 +12,5 @@ cd -
--mbs-name MBSlave1 --mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 20048 \ --mbs-name MBSlave1 --mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 20048 \
--mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 \ --mbs-askcount-id SVU_AskCount_AS --mbs-respond-id RespondRTU_S --mbs-respond-invert 1 \
--mbs-filter-field mbs --mbs-filter-value 1 --mbs-initPause 100 --mbs-filter-field mbs --mbs-filter-value 1 --mbs-initPause 100
#--mbs-log-add-levels any # --mbs-log-add-levels any
\ No newline at end of file
...@@ -996,14 +996,14 @@ namespace uniset ...@@ -996,14 +996,14 @@ namespace uniset
#endif #endif
} }
catch( const uniset::Exception& ex )
{
smcrit << myname << "(initFromSM): " << ex << endl;
}
catch( const IOController_i::NameNotFound& ex ) catch( const IOController_i::NameNotFound& ex )
{ {
smcrit << myname << "(initFromSM): not found sensor id=" << ii.si.id << "'" << endl; smcrit << myname << "(initFromSM): not found sensor id=" << ii.si.id << "'" << endl;
} }
catch( const uniset::Exception& ex )
{
smcrit << myname << "(initFromSM): " << ex << endl;
}
} }
return true; return true;
......
...@@ -95,7 +95,7 @@ namespace uniset ...@@ -95,7 +95,7 @@ namespace uniset
struct UDPPacket struct UDPPacket
{ {
UDPPacket() noexcept: len(0) {} UDPPacket() noexcept: len(0) {} // -V730
size_t len; size_t len;
uint8_t data[ sizeof(UDPHeader) + MaxDCount * sizeof(long) + MaxDDataCount + MaxACount * sizeof(UDPAData) ]; uint8_t data[ sizeof(UDPHeader) + MaxDCount * sizeof(long) + MaxDDataCount + MaxACount * sizeof(UDPAData) ];
......
...@@ -471,7 +471,7 @@ namespace uniset ...@@ -471,7 +471,7 @@ namespace uniset
return false; return false;
} }
} }
else if( p.iotype == UniversalIO::AI || p.iotype == UniversalIO::AO ) else if( p.iotype == UniversalIO::AI || p.iotype == UniversalIO::AO ) // -V560
{ {
size_t anum = packs_anum[priority]; size_t anum = packs_anum[priority];
......
...@@ -70,7 +70,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20 ...@@ -70,7 +70,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
size_t ret = udp_r->receiveBytes(&(buf.data), sizeof(buf.data) ); size_t ret = udp_r->receiveBytes(&(buf.data), sizeof(buf.data) );
size_t sz = UniSetUDP::UDPMessage::getMessage(pack, buf); size_t sz = UniSetUDP::UDPMessage::getMessage(pack, buf);
if( sz == 0 || pnum == 0 || ( pnum > 0 && pack.num >= pnum ) ) if( sz == 0 || pnum == 0 || ( pnum > 0 && pack.num >= pnum ) ) // -V560
break; break;
REQUIRE( pack.magic == UniSetUDP::UNETUDP_MAGICNUM ); REQUIRE( pack.magic == UniSetUDP::UNETUDP_MAGICNUM );
......
...@@ -94,7 +94,7 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5 ...@@ -94,7 +94,7 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
size_t nc = 1; size_t nc = 1;
while( nc ) while( nc ) // -V654
{ {
mypack.num = packetnum++; mypack.num = packetnum++;
......
...@@ -115,7 +115,7 @@ UniExchange::UniExchange(uniset::ObjectId id, uniset::ObjectId shmID, ...@@ -115,7 +115,7 @@ UniExchange::UniExchange(uniset::ObjectId id, uniset::ObjectId shmID,
node = conf->getNodeID(n1); node = conf->getNodeID(n1);
} }
if( id == DefaultObjectId ) if( node == DefaultObjectId )
throw SystemError("(UniExchange): Uknown ID for node=" + n1 ); throw SystemError("(UniExchange): Uknown ID for node=" + n1 );
NetNodeInfo ni; NetNodeInfo ni;
......
...@@ -35,6 +35,7 @@ namespace uniset ...@@ -35,6 +35,7 @@ namespace uniset
{ {
static const int DefaultSubdev = -1; static const int DefaultSubdev = -1;
static const int DefaultChannel = -1; static const int DefaultChannel = -1;
static const int DefaultCard = -1;
// т.к. IOBase содержит rwmutex с запрещённым конструктором копирования // т.к. IOBase содержит rwmutex с запрещённым конструктором копирования
// приходится здесь тоже объявлять разрешенными только операции "перемещения" // приходится здесь тоже объявлять разрешенными только операции "перемещения"
...@@ -175,11 +176,13 @@ namespace uniset ...@@ -175,11 +176,13 @@ namespace uniset
friend std::ostream& operator<<(std::ostream& os, const IOBase& inf ); friend std::ostream& operator<<(std::ostream& os, const IOBase& inf );
static void processingF64asAI( IOBase* it, double new_val, const std::shared_ptr<SMInterface>& shm, bool force );
static void processingFasAI( IOBase* it, float new_val, const std::shared_ptr<SMInterface>& shm, bool force ); static void processingFasAI( IOBase* it, float new_val, const std::shared_ptr<SMInterface>& shm, bool force );
static void processingAsAI( IOBase* it, long new_val, const std::shared_ptr<SMInterface>& shm, bool force ); static void processingAsAI( IOBase* it, long new_val, const std::shared_ptr<SMInterface>& shm, bool force );
static void processingAsDI( IOBase* it, bool new_set, const std::shared_ptr<SMInterface>& shm, bool force ); static void processingAsDI( IOBase* it, bool new_set, const std::shared_ptr<SMInterface>& shm, bool force );
static long processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); static long processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
static float processingFasAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); static float processingFasAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
static double processingF64asAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
static bool processingAsDO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); static bool processingAsDO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
static void processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ); static void processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force );
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ. ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// generate timestamp: 2018-10-16+03:00 // generate timestamp: 2018-12-25+03:00
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef UObject_SK_H_ #ifndef UObject_SK_H_
#define UObject_SK_H_ #define UObject_SK_H_
......
...@@ -149,7 +149,7 @@ namespace uniset ...@@ -149,7 +149,7 @@ namespace uniset
typedef union typedef union
{ {
uint16_t v[f4Size]; uint16_t v[f4Size];
float val; // double val; //
} F4mem; } F4mem;
// ------------------------------------------ // ------------------------------------------
// конструкторы на разные случаи... // конструкторы на разные случаи...
...@@ -158,7 +158,7 @@ namespace uniset ...@@ -158,7 +158,7 @@ namespace uniset
memset(raw.v, 0, sizeof(raw.v)); memset(raw.v, 0, sizeof(raw.v));
} }
F4( const float& f ) noexcept F4( const double& f ) noexcept
{ {
memset(raw.v, 0, sizeof(raw.v)); memset(raw.v, 0, sizeof(raw.v));
raw.val = f; raw.val = f;
...@@ -182,7 +182,7 @@ namespace uniset ...@@ -182,7 +182,7 @@ namespace uniset
return vtF4; return vtF4;
} }
// ------------------------------------------ // ------------------------------------------
operator float() operator double()
{ {
return raw.val; return raw.val;
} }
......
...@@ -270,7 +270,72 @@ namespace uniset ...@@ -270,7 +270,72 @@ namespace uniset
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void IOBase::processingFasAI( IOBase* it, float fval, const std::shared_ptr<SMInterface>& shm, bool force ) void IOBase::processingFasAI(IOBase* it, float fval, const std::shared_ptr<SMInterface>& shm, bool force )
{
long val = lroundf(fval);
if( it->stype == UniversalIO::DI || it->stype == UniversalIO::DO )
val = (fval != 0 ? 1 : 0);
else
{
if( it->rawdata )
{
val = 0;
memcpy(&val, &fval, std::min(sizeof(val), sizeof(fval)));
}
else if( it->cal.precision != 0 && !it->noprecision )
val = lroundf( fval * pow(10.0, it->cal.precision) );
// проверка на обрыв
if( it->check_channel_break(val) )
{
uniset_rwmutex_wrlock lock(it->val_lock);
it->value = ChannelBreakValue;
shm->localSetUndefinedState(it->ioit, true, it->si.id);
return;
}
// проверка зависимости
if( !it->check_depend(shm) )
val = it->d_off_value;
else
{
// Читаем с использованием фильтра...
if( !it->nofilter )
{
if( it->df.size() > 1 )
it->df.add(val);
val = it->df.filterRC(val);
}
if( !it->rawdata )
{
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw != cal->minRaw ) // задана обычная калибровка
val = uniset::lcalibrate(val, cal->minRaw, cal->maxRaw, cal->minCal, cal->maxCal, it->calcrop);
}
}
}
{
uniset_rwmutex_wrlock lock(it->val_lock);
// если предыдущее значение "обрыв",
// то сбрасываем признак
if( it->value == ChannelBreakValue )
shm->localSetUndefinedState(it->ioit, false, it->si.id);
if( force || it->value != val )
{
shm->localSetValue( it->ioit, it->si.id, val, shm->ID() );
it->value = val;
}
}
}
// -----------------------------------------------------------------------------
void IOBase::processingF64asAI(IOBase* it, double fval, const std::shared_ptr<SMInterface>& shm, bool force )
{ {
long val = lroundf(fval); long val = lroundf(fval);
...@@ -398,9 +463,9 @@ namespace uniset ...@@ -398,9 +463,9 @@ namespace uniset
if( !it->noprecision && it->cal.precision != 0 ) if( !it->noprecision && it->cal.precision != 0 )
val = lroundf( (float)it->value / pow(10.0, it->cal.precision) ); val = lroundf( (float)it->value / pow(10.0, it->cal.precision) );
IOController_i::CalibrateInfo* cal( &(it->cal) ); IOController_i::CalibrateInfo* cal = &(it->cal);
if( cal && cal->maxRaw != cal->minRaw ) // задана калибровка if( cal->maxRaw != cal->minRaw ) // задана калибровка
{ {
// Калибруем в обратную сторону!!! // Калибруем в обратную сторону!!!
val = uniset::lcalibrate(val, cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop ); val = uniset::lcalibrate(val, cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop );
...@@ -470,6 +535,49 @@ namespace uniset ...@@ -470,6 +535,49 @@ namespace uniset
return fval; return fval;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
double IOBase::processingF64asAO( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force )
{
// проверка зависимости
if( !it->check_depend(shm) )
return (double)it->d_off_value;
uniset_rwmutex_rlock lock(it->val_lock);
long val = it->value;
if( force )
{
val = shm->localGetValue(it->ioit, it->si.id);
it->value = val; // обновим на всякий
}
if( it->rawdata )
{
double fval = 0;
memcpy(&fval, &val, std::min(sizeof(val), sizeof(fval)));
return fval;
}
double dval = val;
if( it->stype == UniversalIO::AO || it->stype == UniversalIO::AI )
{
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw != cal->minRaw ) // задана калибровка
{
// Калибруем в обратную сторону!!!
dval = uniset::dcalibrate(dval, cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop );
}
if( !it->noprecision && it->cal.precision != 0 )
return ( dval / pow(10.0, it->cal.precision) );
}
else // if( it->stype == UniversalIO::DI || it->stype == UniversalIO::DO )
dval = val ? 1.0 : 0.0;
return dval;
}
// -----------------------------------------------------------------------------
void IOBase::processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force ) void IOBase::processingThreshold( IOBase* it, const std::shared_ptr<SMInterface>& shm, bool force )
{ {
if( it->t_ai == DefaultObjectId ) if( it->t_ai == DefaultObjectId )
...@@ -760,7 +868,7 @@ namespace uniset ...@@ -760,7 +868,7 @@ namespace uniset
b->cdiagram->setCacheResortCycle(initIntProp(it, "cal_cacheresort", prefix, init_prefix_only)); b->cdiagram->setCacheResortCycle(initIntProp(it, "cal_cacheresort", prefix, init_prefix_only));
} }
} }
else if( b->stype == UniversalIO::DI || b->stype == UniversalIO::DO ) else if( b->stype == UniversalIO::DI || b->stype == UniversalIO::DO ) // -V560
{ {
string tai(initProp(it, "threshold_aid", prefix, init_prefix_only)); string tai(initProp(it, "threshold_aid", prefix, init_prefix_only));
......
...@@ -302,12 +302,15 @@ namespace uniset ...@@ -302,12 +302,15 @@ namespace uniset
{ {
bool start = false; bool start = false;
while( !ifs.eof() ) while(true)
{ {
std::string str; std::string str;
if( getline(ifs, str) ) if( getline(ifs, str) )
{ {
if( ifs.eof() )
break;
if( str.empty() ) if( str.empty() )
continue; continue;
...@@ -361,7 +364,7 @@ namespace uniset ...@@ -361,7 +364,7 @@ namespace uniset
dmap[reg] = dlst; dmap[reg] = dlst;
} }
} }
} };
} }
ifs.close(); ifs.close();
......
...@@ -74,16 +74,15 @@ using namespace uniset; ...@@ -74,16 +74,15 @@ using namespace uniset;
{ \ { \
uwarn << "(" << __STRING(fname) << "): " << ex.err << endl; \ uwarn << "(" << __STRING(fname) << "): " << ex.err << endl; \
} \ } \
catch( const uniset::Exception& ex ) \
{ \
uwarn << "(" << __STRING(fname) << "): " << ex << endl; \
} \
catch( const CORBA::SystemException& ex ) \ catch( const CORBA::SystemException& ex ) \
{ \ { \
uwarn << "(" << __STRING(fname) << "): CORBA::SystemException: " \ uwarn << "(" << __STRING(fname) << "): CORBA::SystemException: " \
<< ex.NP_minorString() << endl; \ << ex.NP_minorString() << endl; \
} \ } \
\ catch( const uniset::Exception& ex ) \
{ \
uwarn << "(" << __STRING(fname) << "): " << ex << endl; \
} \
oref = CORBA::Object::_nil(); \ oref = CORBA::Object::_nil(); \
throw uniset::TimeOut(); \ throw uniset::TimeOut(); \
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ. ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// generate timestamp: 2018-10-16+03:00 // generate timestamp: 2018-12-25+03:00
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <memory> #include <memory>
#include <iomanip> #include <iomanip>
...@@ -176,7 +176,7 @@ end_private(false) ...@@ -176,7 +176,7 @@ end_private(false)
sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","150", 150); sleep_msec = conf->getArgPInt("--" + argprefix + "sleep-msec","150", 150);
string s_resetTime(""); string s_resetTime("");
if( s_resetTime.empty() ) if( s_resetTime.empty() ) // -V547
s_resetTime = "500"; s_resetTime = "500";
resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime)); resetMsgTime = uni_atoi(init3_str(conf->getArgParam("--" + argprefix + "resetMsgTime"),conf->getProp(cnode,"resetMsgTime"),s_resetTime));
...@@ -193,7 +193,7 @@ end_private(false) ...@@ -193,7 +193,7 @@ end_private(false)
smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),"")); smTestID = conf->getSensorID(init3_str(conf->getArgParam("--" + argprefix + "sm-test-id"),conf->getProp(cnode,"smTestID"),""));
if( smTestID == DefaultObjectId ) if( smTestID == DefaultObjectId ) // -V547
smTestID = getSMTestID(); smTestID = getSMTestID();
activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 120000); activateTimeout = conf->getArgPInt("--" + argprefix + "activate-timeout", 120000);
...@@ -806,15 +806,15 @@ void UObject_SK::callback() noexcept ...@@ -806,15 +806,15 @@ void UObject_SK::callback() noexcept
updateOutputs(forceOut); updateOutputs(forceOut);
updatePreviousValues(); updatePreviousValues();
} }
catch( const uniset::Exception& ex )
{
mycrit << myname << "(execute): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
mycrit << myname << "(execute): СORBA::SystemException: " mycrit << myname << "(execute): СORBA::SystemException: "
<< ex.NP_minorString() << endl; << ex.NP_minorString() << endl;
} }
catch( const uniset::Exception& ex )
{
mycrit << myname << "(execute): " << ex << endl;
}
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
mycrit << myname << "(execute): catch " << ex.what() << endl; mycrit << myname << "(execute): catch " << ex.what() << endl;
......
...@@ -219,43 +219,43 @@ TEST_CASE("VTypes: F4", "[vtypes][F4]") ...@@ -219,43 +219,43 @@ TEST_CASE("VTypes: F4", "[vtypes][F4]")
SECTION("Default constructor") SECTION("Default constructor")
{ {
F4 v; F4 v;
REQUIRE( (float)v == 0 ); REQUIRE( (double)v == 0 );
} }
SECTION("'float' constructor") SECTION("'float64' constructor")
{ {
{ {
F4 v( numeric_limits<float>::max() ); F4 v( numeric_limits<double>::max() );
REQUIRE( (float)v == numeric_limits<float>::max() ); REQUIRE( (double)v == numeric_limits<double>::max() );
} }
{ {
F4 v( numeric_limits<float>::min() ); F4 v( numeric_limits<double>::min() );
REQUIRE( (float)v == numeric_limits<float>::min() ); REQUIRE( (double)v == numeric_limits<double>::min() );
} }
} }
SECTION("Modbus constructor") SECTION("Modbus constructor")
{ {
{ {
float f = numeric_limits<float>::max(); double f = numeric_limits<double>::max();
ModbusRTU::ModbusData data[4]; ModbusRTU::ModbusData data[4];
memcpy(data, &f, sizeof(data)); memcpy(data, &f, sizeof(f));
F4 v1(data, 4); F4 v1(data, 4);
REQUIRE( (float)v1 == f ); REQUIRE( (double)v1 == f );
} }
{ {
float f = numeric_limits<float>::max(); double f = numeric_limits<double>::max();
ModbusRTU::ModbusData data5[5]; ModbusRTU::ModbusData data5[5];
memset(data5, 0, sizeof(data5)); memset(data5, 0, sizeof(data5));
memcpy(data5, &f, 4 * sizeof(ModbusRTU::ModbusData)); memcpy(data5, &f, sizeof(f));
F4 v2(data5, 5); F4 v2(data5, 5);
REQUIRE( (float)v2 == f ); REQUIRE( (double)v2 == f );
} }
{ {
float f = numeric_limits<float>::min(); double f = numeric_limits<double>::min();
ModbusRTU::ModbusData data[4]; ModbusRTU::ModbusData data[4];
memcpy(data, &f, sizeof(data)); memcpy(data, &f, sizeof(data));
F4 v1(data, 4); F4 v1(data, 4);
REQUIRE( (float)v1 == f ); REQUIRE( (double)v1 == f );
} }
} }
} }
......
...@@ -180,7 +180,7 @@ namespace uniset ...@@ -180,7 +180,7 @@ namespace uniset
virtual void initNode( uniset::NodeInfo& ninfo, UniXML::iterator& it) noexcept; virtual void initNode( uniset::NodeInfo& ninfo, UniXML::iterator& it) noexcept;
void initRepSections(); void initRepSections();
std::string getRepSectionName(const std::string& sec, xmlNode* secnode = 0 ); std::pair<std::string,xmlNode*> getRepSectionName( const std::string& sec );
void setConfFileName( const std::string& fn = "" ); void setConfFileName( const std::string& fn = "" );
void initParameters(); void initParameters();
void setLocalNode( const std::string& nodename ); void setLocalNode( const std::string& nodename );
......
...@@ -96,7 +96,7 @@ namespace uniset ...@@ -96,7 +96,7 @@ namespace uniset
// для оптимизации, делаем конструктор, который не будет инициализировать свойства класса // для оптимизации, делаем конструктор, который не будет инициализировать свойства класса
// это необходимо для VoidMessage, который конструируется при помощи memcpy // это необходимо для VoidMessage, который конструируется при помощи memcpy
VoidMessage( int dummy ) noexcept : Message(dummy) {} VoidMessage( int dummy ) noexcept : Message(dummy) {} // -V730
VoidMessage( const TransportMessage& tm ) noexcept; VoidMessage( const TransportMessage& tm ) noexcept;
VoidMessage() noexcept; VoidMessage() noexcept;
......
...@@ -76,20 +76,11 @@ namespace uniset ...@@ -76,20 +76,11 @@ namespace uniset
/*! генератор уникального положительного ключа /*! генератор уникального положительного ключа
* Уникальность гарантируется только для пары значений id и node. * Уникальность гарантируется только для пары значений id и node.
* \warning что тут у нас с переполнением..
* \warning Уникальность генерируемого ключа еще не проверялась,
но нареканий по использованию тоже не было :)
* \todo Желательно продумать что-нибудь с использованием хэш. * \todo Желательно продумать что-нибудь с использованием хэш.
* \warning Уникальность не гарантирована, возможны коллизии
*/ */
inline static KeyType key( const uniset::ObjectId id, const uniset::ObjectId node ) KeyType key( const uniset::ObjectId id, const uniset::ObjectId node );
{ KeyType key( const IOController_i::SensorInfo& si );
return KeyType((id * node) + (id + 2 * node));
}
inline static KeyType key( const IOController_i::SensorInfo& si )
{
return key(si.id, si.node);
}
typedef std::list<std::string> ListObjectName; /*!< Список объектов типа ObjectName */ typedef std::list<std::string> ListObjectName; /*!< Список объектов типа ObjectName */
...@@ -318,6 +309,7 @@ namespace uniset ...@@ -318,6 +309,7 @@ namespace uniset
// limit - обрезать итоговое значение по границам // limit - обрезать итоговое значение по границам
float fcalibrate(float raw, float rawMin, float rawMax, float calMin, float calMax, bool limit = true ); float fcalibrate(float raw, float rawMin, float rawMax, float calMin, float calMax, bool limit = true );
long lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit = true ); long lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit = true );
double dcalibrate(double raw, double rawMin, double rawMax, double calMin, double calMax, bool limit = true );
// установка значения в нужный диапазон // установка значения в нужный диапазон
long setinregion(long raw, long rawMin, long rawMax); long setinregion(long raw, long rawMin, long rawMax);
......
...@@ -148,7 +148,7 @@ namespace uniset ...@@ -148,7 +148,7 @@ namespace uniset
ev::timer ioTimer; ev::timer ioTimer;
std::shared_ptr<UTCPSocket> sock; std::shared_ptr<UTCPSocket> sock;
const std::unordered_set<ModbusRTU::ModbusAddr>* vmbaddr = { nullptr }; std::unordered_set<ModbusRTU::ModbusAddr> vmbaddr;
TimerSignal m_timer_signal; TimerSignal m_timer_signal;
timeout_t tmTime_msec = { UniSetTimer::WaitUpTime }; // время по умолчанию для таймера (TimerSignal) timeout_t tmTime_msec = { UniSetTimer::WaitUpTime }; // время по умолчанию для таймера (TimerSignal)
......
...@@ -154,6 +154,24 @@ namespace uniset ...@@ -154,6 +154,24 @@ namespace uniset
float dat2f( const ModbusData dat1, const ModbusData dat2 ); float dat2f( const ModbusData dat1, const ModbusData dat2 );
size_t numBytes( const size_t nbits ); // сколько байт нужно для указанного количества бит size_t numBytes( const size_t nbits ); // сколько байт нужно для указанного количества бит
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// вспомогательная структура для предотвращения утечки памяти (RAII)
struct DataGuard
{
DataGuard( size_t sz ):
len(sz)
{
data = new ModbusRTU::ModbusData[sz];
}
~DataGuard()
{
delete[] data;
}
ModbusRTU::ModbusData* data;
size_t len;
};
// -----------------------------------------------------------------------------
bool isWriteFunction( SlaveFunctionCode c ); bool isWriteFunction( SlaveFunctionCode c );
bool isReadFunction( SlaveFunctionCode c ); bool isReadFunction( SlaveFunctionCode c );
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
#include <unistd.h> #include <cstring>
#include <termios.h> #include <termios.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
...@@ -83,6 +83,8 @@ ComPort485F::ComPort485F( const string& dev, char gpio_num, bool tmit_ctrl ): ...@@ -83,6 +83,8 @@ ComPort485F::ComPort485F( const string& dev, char gpio_num, bool tmit_ctrl ):
gpio_num(gpio_num), gpio_num(gpio_num),
tmit_ctrl_on(tmit_ctrl) tmit_ctrl_on(tmit_ctrl)
{ {
memset(tbuf,0,sizeof(tbuf));
if( tmit_ctrl_on ) if( tmit_ctrl_on )
{ {
iopl(3); iopl(3);
......
...@@ -298,15 +298,15 @@ namespace uniset ...@@ -298,15 +298,15 @@ namespace uniset
if( tcp ) if( tcp )
tcp->forceDisconnect(); tcp->forceDisconnect();
} }
catch( const uniset::Exception& ex ) catch( const Poco::Net::NetException& e )
{ {
if( dlog->is_warn() ) if( dlog->is_warn() )
dlog->warn() << "(query): " << ex << endl; dlog->warn() << "(query): tcp error: " << e.displayText() << endl;
} }
catch( const Poco::Net::NetException& e ) catch( const uniset::Exception& ex )
{ {
if( dlog->is_warn() ) if( dlog->is_warn() )
dlog->warn() << "(query): tcp error: " << e.displayText() << endl; dlog->warn() << "(query): " << ex << endl;
} }
catch( const std::exception& e ) catch( const std::exception& e )
{ {
......
...@@ -103,13 +103,13 @@ namespace uniset ...@@ -103,13 +103,13 @@ namespace uniset
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool ModbusTCPServer::run( const std::unordered_set<ModbusAddr>& _vmbaddr ) bool ModbusTCPServer::run( const std::unordered_set<ModbusAddr>& _vmbaddr )
{ {
vmbaddr = &_vmbaddr; vmbaddr = _vmbaddr;
return evrun(); return evrun();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool ModbusTCPServer::async_run( const std::unordered_set<ModbusAddr>& _vmbaddr ) bool ModbusTCPServer::async_run( const std::unordered_set<ModbusAddr>& _vmbaddr )
{ {
vmbaddr = &_vmbaddr; vmbaddr = _vmbaddr;
return async_evrun(); return async_evrun();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -296,7 +296,7 @@ namespace uniset ...@@ -296,7 +296,7 @@ namespace uniset
connCount++; connCount++;
auto s = make_shared<ModbusTCPSession>(ss, *vmbaddr, sessTimeout); auto s = make_shared<ModbusTCPSession>(ss, vmbaddr, sessTimeout);
s->connectReadCoil( sigc::mem_fun(this, &ModbusTCPServer::readCoilStatus) ); s->connectReadCoil( sigc::mem_fun(this, &ModbusTCPServer::readCoilStatus) );
s->connectReadInputStatus( sigc::mem_fun(this, &ModbusTCPServer::readInputStatus) ); s->connectReadInputStatus( sigc::mem_fun(this, &ModbusTCPServer::readInputStatus) );
s->connectReadOutput( sigc::mem_fun(this, &ModbusTCPServer::readOutputRegisters) ); s->connectReadOutput( sigc::mem_fun(this, &ModbusTCPServer::readOutputRegisters) );
......
...@@ -399,7 +399,7 @@ namespace uniset ...@@ -399,7 +399,7 @@ namespace uniset
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -428,7 +428,7 @@ namespace uniset ...@@ -428,7 +428,7 @@ namespace uniset
assert( m.pduhead.func == fnReadCoilStatus ); assert( m.pduhead.func == fnReadCoilStatus );
// memset(this, 0, sizeof(*this)); // memset(this, 0, sizeof(*this));
memcpy(this, &m.pduhead, sizeof(m.pduhead)); memcpy(this, &m.pduhead, sizeof(m.pduhead));
memcpy(&start, &(m.data[0]), szData()); memcpy(&start, m.data, szData()); // -V512
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
...@@ -731,7 +731,7 @@ namespace uniset ...@@ -731,7 +731,7 @@ namespace uniset
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -760,7 +760,7 @@ namespace uniset ...@@ -760,7 +760,7 @@ namespace uniset
assert( m.pduhead.func == fnReadInputStatus ); assert( m.pduhead.func == fnReadInputStatus );
func = m.pduhead.func; func = m.pduhead.func;
addr = m.pduhead.addr; addr = m.pduhead.addr;
memcpy(&start, &m.data, szData()); memcpy(&start, &m.data, szData()); // -V512
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
...@@ -935,7 +935,7 @@ namespace uniset ...@@ -935,7 +935,7 @@ namespace uniset
size_t last(sizeof(d)); // индекс в массиве данных ( байтовый массив!!! ) size_t last(sizeof(d)); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -967,7 +967,7 @@ namespace uniset ...@@ -967,7 +967,7 @@ namespace uniset
func = m.pduhead.func; func = m.pduhead.func;
addr = m.pduhead.addr; addr = m.pduhead.addr;
//memset(this, 0, sizeof(*this)); //memset(this, 0, sizeof(*this));
memcpy(&start, &m.data, szData()); memcpy(&start, &m.data, szData()); // -V512
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
...@@ -1012,7 +1012,7 @@ namespace uniset ...@@ -1012,7 +1012,7 @@ namespace uniset
size_t cnt = m.data[0] / sizeof(ModbusData); size_t cnt = m.data[0] / sizeof(ModbusData);
if( cnt > MAXLENPACKET / sizeof(ModbusData) ) if( cnt > MAXLENPACKET / sizeof(ModbusData) ) // -V547
throw mbException(erPacketTooLong); throw mbException(erPacketTooLong);
count = cnt; count = cnt;
...@@ -1146,7 +1146,7 @@ namespace uniset ...@@ -1146,7 +1146,7 @@ namespace uniset
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -1176,7 +1176,7 @@ namespace uniset ...@@ -1176,7 +1176,7 @@ namespace uniset
assert( m.pduhead.func == fnReadInputRegisters ); assert( m.pduhead.func == fnReadInputRegisters );
// memset(this, 0, sizeof(*this)); // memset(this, 0, sizeof(*this));
memcpy(this, &m.pduhead, sizeof(m.pduhead)); memcpy(this, &m.pduhead, sizeof(m.pduhead));
memcpy(&start, m.data, szData()); memcpy(&start, m.data, szData()); // -V512
// переворачиваем слова // переворачиваем слова
start = SWAPSHORT(start); start = SWAPSHORT(start);
...@@ -1222,7 +1222,7 @@ namespace uniset ...@@ -1222,7 +1222,7 @@ namespace uniset
// bcnt = m.data[0]; // bcnt = m.data[0];
size_t cnt = m.data[0] / sizeof(ModbusData); size_t cnt = m.data[0] / sizeof(ModbusData);
if( cnt > MAXLENPACKET / sizeof(ModbusData) ) if( cnt > MAXLENPACKET / sizeof(ModbusData) ) // -V547
throw mbException(erPacketTooLong); throw mbException(erPacketTooLong);
count = cnt; count = cnt;
...@@ -1418,7 +1418,7 @@ namespace uniset ...@@ -1418,7 +1418,7 @@ namespace uniset
ind += sizeof(d); ind += sizeof(d);
// копируем // копируем
memcpy(mm.data, &d, ind); memcpy(mm.data, &d, ind); // -V512
// copy bcnt // copy bcnt
memcpy(&(mm.data[ind]), &bcnt, sizeof(bcnt)); memcpy(&(mm.data[ind]), &bcnt, sizeof(bcnt));
...@@ -1588,7 +1588,7 @@ namespace uniset ...@@ -1588,7 +1588,7 @@ namespace uniset
ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(quant) }; ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(quant) };
size_t last = sizeof(d); size_t last = sizeof(d);
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last );
...@@ -1610,7 +1610,6 @@ namespace uniset ...@@ -1610,7 +1610,6 @@ namespace uniset
return os << (*m); return os << (*m);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// -------------------------------------------------------------------------
WriteOutputMessage::WriteOutputMessage( ModbusAddr a, ModbusData s ): WriteOutputMessage::WriteOutputMessage( ModbusAddr a, ModbusData s ):
start(s), start(s),
quant(0), quant(0),
...@@ -1618,6 +1617,7 @@ namespace uniset ...@@ -1618,6 +1617,7 @@ namespace uniset
{ {
addr = a; addr = a;
func = fnWriteOutputRegisters; func = fnWriteOutputRegisters;
memset(data,0,sizeof(data));
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool WriteOutputMessage::addData( ModbusData d ) bool WriteOutputMessage::addData( ModbusData d )
...@@ -1653,7 +1653,7 @@ namespace uniset ...@@ -1653,7 +1653,7 @@ namespace uniset
ind += sizeof(d); ind += sizeof(d);
// копируем // копируем
memcpy(mm.data, &d, ind); memcpy(mm.data, &d, ind); // -V512
// copy bcnt // copy bcnt
bcnt = quant * sizeof(ModbusData); bcnt = quant * sizeof(ModbusData);
...@@ -1847,7 +1847,7 @@ namespace uniset ...@@ -1847,7 +1847,7 @@ namespace uniset
ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(quant) }; ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(quant) };
size_t last = sizeof(d); size_t last = sizeof(d);
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last );
...@@ -1885,7 +1885,7 @@ namespace uniset ...@@ -1885,7 +1885,7 @@ namespace uniset
memcpy(&mm.pduhead, this, szModbusHeader); memcpy(&mm.pduhead, this, szModbusHeader);
ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(data) }; ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(data) };
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last );
// копируем CRC (последний элемент). Без переворачивания... // копируем CRC (последний элемент). Без переворачивания...
...@@ -2016,7 +2016,7 @@ namespace uniset ...@@ -2016,7 +2016,7 @@ namespace uniset
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -2056,7 +2056,7 @@ namespace uniset ...@@ -2056,7 +2056,7 @@ namespace uniset
memcpy(&mm.pduhead, this, szModbusHeader); memcpy(&mm.pduhead, this, szModbusHeader);
ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(data) }; ModbusData d[2] = { SWAPSHORT(start), SWAPSHORT(data) };
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + last );
// копируем CRC (последний элемент). Без переворачивания... // копируем CRC (последний элемент). Без переворачивания...
...@@ -2194,7 +2194,7 @@ namespace uniset ...@@ -2194,7 +2194,7 @@ namespace uniset
size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! ) size_t last = sizeof(d); // индекс в массиве данных ( байтовый массив!!! )
// копируем // копируем
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
...@@ -2679,7 +2679,7 @@ namespace uniset ...@@ -2679,7 +2679,7 @@ namespace uniset
RDIObjectInfo r(id, val); RDIObjectInfo r(id, val);
dlist.push_back(r); dlist.push_back(r);
objNum = dlist.size(); objNum = (ModbusByte)dlist.size(); // -V1029
bcnt += val.size() + 2; // 2 = 'id'(byte) + 'len'(byte) bcnt += val.size() + 2; // 2 = 'id'(byte) + 'len'(byte)
return true; return true;
...@@ -3132,7 +3132,7 @@ namespace uniset ...@@ -3132,7 +3132,7 @@ namespace uniset
mm.data[6] = century; mm.data[6] = century;
*/ */
size_t bcnt = 7; size_t bcnt = 7;
memcpy( mm.data, &hour, bcnt ); // копируем начиная с адреса 'hour' 7 байт. memcpy( mm.data, &hour, bcnt ); // -V512 копируем начиная с адреса 'hour' 7 байт.
// пересчитываем CRC // пересчитываем CRC
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + bcnt ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + bcnt );
...@@ -3427,7 +3427,7 @@ namespace uniset ...@@ -3427,7 +3427,7 @@ namespace uniset
// копируем данные (переворачиваем байты) // копируем данные (переворачиваем байты)
ModbusData d[2] = { SWAPSHORT(numfile), SWAPSHORT(numpacket) }; ModbusData d[2] = { SWAPSHORT(numfile), SWAPSHORT(numpacket) };
size_t last = sizeof(d); size_t last = sizeof(d);
memcpy(mm.data, &d, last); memcpy(mm.data, &d, last); // -V512
// пересчитываем CRC по перевёрнутым данным // пересчитываем CRC по перевёрнутым данным
ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) ); ModbusData crc = checkCRC( (ModbusByte*)(&mm.pduhead), szModbusHeader + sizeof(d) );
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
* \author Vitaly Lipatov, Pavel Vainerman * \author Vitaly Lipatov, Pavel Vainerman
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <utility> // for make_pair
#include <tuple> // for std::tie
#include <unistd.h> #include <unistd.h>
#include <libgen.h> #include <libgen.h>
#include <fstream> #include <fstream>
...@@ -1099,17 +1100,24 @@ namespace uniset ...@@ -1099,17 +1100,24 @@ namespace uniset
} }
secRoot = unixml->getProp(node, "name"); secRoot = unixml->getProp(node, "name");
secSensors = makeSecName(secRoot, getRepSectionName("sensors", xmlSensorsSec));
secObjects = makeSecName(secRoot, getRepSectionName("objects", xmlObjectsSec)); std::tie(secSensors, xmlSensorsSec) = getRepSectionName("sensors");
secControlles = makeSecName(secRoot, getRepSectionName("controllers", xmlControllersSec)); secSensors = makeSecName(secRoot, secSensors);
secServices = makeSecName(secRoot, getRepSectionName("services", xmlServicesSec));
std::tie(secObjects, xmlObjectsSec) = getRepSectionName("objects");
secObjects = makeSecName(secRoot, secObjects);
std::tie(secControlles, xmlControllersSec) = getRepSectionName("controllers");
secControlles = makeSecName(secRoot, secControlles);
std::tie(secServices, xmlServicesSec) = getRepSectionName("services");
secServices = makeSecName(secRoot, secServices);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// второй параметр намеренно передаётся и переопределяется
// это просто такой способ вернуть и строку и указатель на узел (одним махом) std::pair<string,xmlNode*> Configuration::getRepSectionName( const string& sec )
string Configuration::getRepSectionName( const string& sec, xmlNode* secnode )
{ {
secnode = unixml->findNode(unixml->getFirstNode(), sec); xmlNode* secnode = unixml->findNode(unixml->getFirstNode(), sec);
if( secnode == NULL ) if( secnode == NULL )
{ {
...@@ -1124,7 +1132,7 @@ namespace uniset ...@@ -1124,7 +1132,7 @@ namespace uniset
if( ret.empty() ) if( ret.empty() )
ret = unixml->getProp(secnode, "name"); ret = unixml->getProp(secnode, "name");
return ret; return std::make_pair(ret, secnode);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void Configuration::setConfFileName( const string& fn ) void Configuration::setConfFileName( const string& fn )
......
...@@ -142,6 +142,7 @@ namespace uniset ...@@ -142,6 +142,7 @@ namespace uniset
type = Message::SysCommand; type = Message::SysCommand;
this->priority = priority; this->priority = priority;
this->consumer = consumer; this->consumer = consumer;
memset(data,0,sizeof(data));
} }
SystemMessage::SystemMessage(const VoidMessage* msg) noexcept: SystemMessage::SystemMessage(const VoidMessage* msg) noexcept:
......
...@@ -919,7 +919,6 @@ namespace uniset ...@@ -919,7 +919,6 @@ namespace uniset
catch(const CosNaming::NamingContext::NotFound& nf) {} catch(const CosNaming::NamingContext::NotFound& nf) {}
catch(const CosNaming::NamingContext::InvalidName& nf) {} catch(const CosNaming::NamingContext::InvalidName& nf) {}
catch(const CosNaming::NamingContext::CannotProceed& cp) {} catch(const CosNaming::NamingContext::CannotProceed& cp) {}
catch( const uniset::Exception& ex ) {}
catch( const CORBA::OBJECT_NOT_EXIST& ex ) catch( const CORBA::OBJECT_NOT_EXIST& ex )
{ {
throw uniset::ResolveNameError("ObjectNOTExist"); throw uniset::ResolveNameError("ObjectNOTExist");
...@@ -934,6 +933,7 @@ namespace uniset ...@@ -934,6 +933,7 @@ namespace uniset
// uwarn << "UI(resolve): CORBA::SystemException" << endl; // uwarn << "UI(resolve): CORBA::SystemException" << endl;
throw uniset::TimeOut(); throw uniset::TimeOut();
} }
catch( const uniset::Exception& ex ) {}
catch( std::exception& ex ) catch( std::exception& ex )
{ {
ucrit << "UI(resolve): myID=" << myid << ": resolve id=" << rid << "@" << node ucrit << "UI(resolve): myID=" << myid << ": resolve id=" << rid << "@" << node
...@@ -2381,22 +2381,20 @@ namespace uniset ...@@ -2381,22 +2381,20 @@ namespace uniset
pmsec = 0; pmsec = 0;
PassiveTimer ptReady(msec); PassiveTimer ptReady(msec);
bool ready = false;
while( !ptReady.checkTime() && !ready ) while( !ptReady.checkTime() )
{ {
try try
{ {
getValue(id, node); getValue(id, node);
ready = true; return true;
break;
} }
catch(...) {} catch(...) {}
msleep(pmsec); msleep(pmsec);
} }
return ready; return false;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool UInterface::waitReadyWithCancellation(const ObjectId id, int msec, bool UInterface::waitReadyWithCancellation(const ObjectId id, int msec,
......
...@@ -209,10 +209,6 @@ bool UniSetManager::removeObject( const std::shared_ptr<UniSetObject>& obj ) ...@@ -209,10 +209,6 @@ bool UniSetManager::removeObject( const std::shared_ptr<UniSetObject>& obj )
if( obj ) if( obj )
obj->deactivate(); obj->deactivate();
} }
catch( const uniset::Exception& ex )
{
uwarn << myname << "(removeObject): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
uwarn << myname << "(removeObject): поймали CORBA::SystemException: " << ex.NP_minorString() << endl; uwarn << myname << "(removeObject): поймали CORBA::SystemException: " << ex.NP_minorString() << endl;
...@@ -228,6 +224,10 @@ bool UniSetManager::removeObject( const std::shared_ptr<UniSetObject>& obj ) ...@@ -228,6 +224,10 @@ bool UniSetManager::removeObject( const std::shared_ptr<UniSetObject>& obj )
<< " line: " << fe.line() << " line: " << fe.line()
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
catch( const uniset::Exception& ex )
{
uwarn << myname << "(removeObject): " << ex << endl;
}
catch(...) {} catch(...) {}
olist.erase(li); olist.erase(li);
...@@ -273,21 +273,6 @@ void UniSetManager::managers( OManagerCommand cmd ) ...@@ -273,21 +273,6 @@ void UniSetManager::managers( OManagerCommand cmd )
break; break;
} }
} }
catch( const uniset::Exception& ex )
{
ostringstream err;
err << myname << "(managers): " << ex << endl
<< " Не смог зарегистрировать (разрегистрировать) объект -->"
<< li->getName();
ucrit << err.str() << endl;
if( cmd == activ )
{
cerr << err.str();
std::terminate();
}
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
ostringstream err; ostringstream err;
...@@ -332,6 +317,21 @@ void UniSetManager::managers( OManagerCommand cmd ) ...@@ -332,6 +317,21 @@ void UniSetManager::managers( OManagerCommand cmd )
std::terminate(); std::terminate();
} }
} }
catch( const uniset::Exception& ex )
{
ostringstream err;
err << myname << "(managers): " << ex << endl
<< " Не смог зарегистрировать (разрегистрировать) объект -->"
<< li->getName();
ucrit << err.str() << endl;
if( cmd == activ )
{
cerr << err.str();
std::terminate();
}
}
} }
} // unlock } // unlock
} }
...@@ -372,20 +372,6 @@ void UniSetManager::objects(OManagerCommand cmd) ...@@ -372,20 +372,6 @@ void UniSetManager::objects(OManagerCommand cmd)
break; break;
} }
} }
catch( const uniset::Exception& ex )
{
ostringstream err;
err << myname << "(objects): " << ex << endl;
err << myname << "(objects): не смог зарегистрировать (разрегистрировать) объект -->" << li->getName() << endl;
ucrit << err.str();
if( cmd == activ )
{
cerr << err.str();
std::terminate();
}
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
ostringstream err; ostringstream err;
...@@ -430,6 +416,20 @@ void UniSetManager::objects(OManagerCommand cmd) ...@@ -430,6 +416,20 @@ void UniSetManager::objects(OManagerCommand cmd)
std::terminate(); std::terminate();
} }
} }
catch( const uniset::Exception& ex )
{
ostringstream err;
err << myname << "(objects): " << ex << endl;
err << myname << "(objects): не смог зарегистрировать (разрегистрировать) объект -->" << li->getName() << endl;
ucrit << err.str();
if( cmd == activ )
{
cerr << err.str();
std::terminate();
}
}
} }
} // unlock } // unlock
} }
...@@ -660,7 +660,7 @@ SimpleInfoSeq* UniSetManager::getObjectsInfo(CORBA::Long maxlength, const char* ...@@ -660,7 +660,7 @@ SimpleInfoSeq* UniSetManager::getObjectsInfo(CORBA::Long maxlength, const char*
int ind = 0; int ind = 0;
const int limit = length; const int limit = length;
ind = getObjectsInfo( get_mptr(), res, ind, limit, userparam ); (void)getObjectsInfo( get_mptr(), res, ind, limit, userparam );
return res; return res;
} }
......
...@@ -288,9 +288,12 @@ namespace uniset ...@@ -288,9 +288,12 @@ namespace uniset
void UniSetObject::unregistration() void UniSetObject::unregistration()
{ {
if( myid < 0 ) // || !reg ) if( myid < 0 ) // || !reg )
{
regOK = false;
return; return;
}
if( myid == uniset::DefaultObjectId ) if( myid == uniset::DefaultObjectId ) // -V547
{ {
uinfo << myname << "(unregister): myid=DefaultObjectId \n"; uinfo << myname << "(unregister): myid=DefaultObjectId \n";
regOK = false; regOK = false;
...@@ -846,10 +849,6 @@ namespace uniset ...@@ -846,10 +849,6 @@ namespace uniset
break; break;
} }
} }
catch( const uniset::Exception& ex )
{
ucrit << myname << "(processingMessage): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
ucrit << myname << "(processingMessage): CORBA::SystemException: " << ex.NP_minorString() << endl; ucrit << myname << "(processingMessage): CORBA::SystemException: " << ex.NP_minorString() << endl;
...@@ -868,6 +867,10 @@ namespace uniset ...@@ -868,6 +867,10 @@ namespace uniset
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
} }
catch( const uniset::Exception& ex )
{
ucrit << myname << "(processingMessage): " << ex << endl;
}
catch( const std::exception& ex ) catch( const std::exception& ex )
{ {
ucrit << myname << "(processingMessage): " << ex.what() << endl; ucrit << myname << "(processingMessage): " << ex.what() << endl;
......
...@@ -59,6 +59,37 @@ float uniset::fcalibrate( float raw, float rawMin, float rawMax, ...@@ -59,6 +59,37 @@ float uniset::fcalibrate( float raw, float rawMin, float rawMax,
return ret; return ret;
} }
// -----------------------------------------------------------------------------
double uniset::dcalibrate( double raw, double rawMin, double rawMax,
double calMin, double calMax, bool limit )
{
if( rawMax == rawMin ) return 0; // деление на 0!!!
double ret = (raw - rawMin) * (calMax - calMin) / ( rawMax - rawMin ) + calMin;
if( !limit )
return ret;
// Переворачиваем calMin и calMax для проверки, если calMin > calMax
if (calMin < calMax)
{
if( ret < calMin )
return calMin;
if( ret > calMax )
return calMax;
}
else
{
if( ret > calMin )
return calMin;
if( ret < calMax )
return calMax;
}
return ret;
}
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Пересчитываем из исходных пределов в заданные // Пересчитываем из исходных пределов в заданные
long uniset::lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit ) long uniset::lcalibrate(long raw, long rawMin, long rawMax, long calMin, long calMax, bool limit )
...@@ -114,7 +145,7 @@ long uniset::setoutregion(long ret, long calMin, long calMax) ...@@ -114,7 +145,7 @@ long uniset::setoutregion(long ret, long calMin, long calMax)
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
uniset::IDList::IDList( const std::vector<string>& svec ): uniset::IDList::IDList( const std::vector<string>& svec ): // -V730
uniset::IDList::IDList() uniset::IDList::IDList()
{ {
auto conf = uniset_conf(); auto conf = uniset_conf();
...@@ -662,3 +693,15 @@ string uniset::BadSymbolsToStr() ...@@ -662,3 +693,15 @@ string uniset::BadSymbolsToStr()
return bad; return bad;
} }
// --------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------
uniset::KeyType uniset::key( const uniset::ObjectId id, const uniset::ObjectId node )
{
//! \warning что тут у нас с переполнением..
return KeyType( (id * node) + (id + 2 * node) );
}
// ---------------------------------------------------------------------------------------------------------------
uniset::KeyType uniset::key( const IOController_i::SensorInfo& si )
{
return key(si.id, si.node);
}
// ---------------------------------------------------------------------------------------------------------------
...@@ -350,7 +350,7 @@ void LogReader::readlogs( const std::string& _addr, int _port, LogServerTypes::C ...@@ -350,7 +350,7 @@ void LogReader::readlogs( const std::string& _addr, int _port, LogServerTypes::C
{ {
rlog.warn() << "(LogReader): **** connection timeout.." << endl; rlog.warn() << "(LogReader): **** connection timeout.." << endl;
if( rcount > 0 && readcount > 0 ) if( readcount > 0 )
rcount--; rcount--;
if( rcount == 0 ) if( rcount == 0 )
......
...@@ -58,7 +58,7 @@ namespace uniset ...@@ -58,7 +58,7 @@ namespace uniset
thr = nullptr; thr = nullptr;
} }
if( !thr ) isrunning = false;
thr = unisetstd::make_unique<std::thread>( [&] { defaultLoop(); } ); thr = unisetstd::make_unique<std::thread>( [&] { defaultLoop(); } );
bool ret = waitDefaultLoopRunning(timeout_msec); bool ret = waitDefaultLoopRunning(timeout_msec);
...@@ -167,6 +167,9 @@ namespace uniset ...@@ -167,6 +167,9 @@ namespace uniset
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool EventLoopServer::waitDefaultLoopRunning( size_t waitTimeout_msec ) bool EventLoopServer::waitDefaultLoopRunning( size_t waitTimeout_msec )
{ {
if( isrunning )
return true;
std::unique_lock<std::mutex> lock(looprunOK_mutex); std::unique_lock<std::mutex> lock(looprunOK_mutex);
looprunOK_event.wait_for(lock, std::chrono::milliseconds(waitTimeout_msec), [&]() looprunOK_event.wait_for(lock, std::chrono::milliseconds(waitTimeout_msec), [&]()
{ {
......
...@@ -101,10 +101,6 @@ void PassiveObject::processingMessage( const uniset::VoidMessage* msg ) ...@@ -101,10 +101,6 @@ void PassiveObject::processingMessage( const uniset::VoidMessage* msg )
break; break;
} }
} }
catch( const uniset::Exception& ex )
{
ucrit << myname << "(processingMessage): " << ex << endl;
}
catch( const CORBA::SystemException& ex ) catch( const CORBA::SystemException& ex )
{ {
ucrit << myname << "(processingMessage): CORBA::SystemException: " << ex.NP_minorString() << endl; ucrit << myname << "(processingMessage): CORBA::SystemException: " << ex.NP_minorString() << endl;
...@@ -125,6 +121,10 @@ void PassiveObject::processingMessage( const uniset::VoidMessage* msg ) ...@@ -125,6 +121,10 @@ void PassiveObject::processingMessage( const uniset::VoidMessage* msg )
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
} }
catch( const uniset::Exception& ex )
{
ucrit << myname << "(processingMessage): " << ex << endl;
}
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void PassiveObject::sysCommand( const SystemMessage* sm ) void PassiveObject::sysCommand( const SystemMessage* sm )
......
...@@ -11,7 +11,7 @@ using namespace uniset; ...@@ -11,7 +11,7 @@ using namespace uniset;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("uniset_rwmutex", "[mutex][basic]" ) TEST_CASE("uniset_rwmutex", "[mutex][basic]" )
{ {
SECTION("simple lock"); SECTION("simple lock")
{ {
uniset_rwmutex m("rwmutex"); uniset_rwmutex m("rwmutex");
...@@ -34,7 +34,7 @@ TEST_CASE("uniset_rwmutex", "[mutex][basic]" ) ...@@ -34,7 +34,7 @@ TEST_CASE("uniset_rwmutex", "[mutex][basic]" )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" ) TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" )
{ {
SECTION("simple lock"); SECTION("simple lock")
{ {
uniset_rwmutex m; uniset_rwmutex m;
{ {
...@@ -46,7 +46,7 @@ TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" ) ...@@ -46,7 +46,7 @@ TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" )
CHECK_FALSE( m.try_lock() ); CHECK_FALSE( m.try_lock() );
} }
SECTION("exception lock"); SECTION("exception lock")
{ {
uniset_rwmutex m; uniset_rwmutex m;
...@@ -67,7 +67,7 @@ TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" ) ...@@ -67,7 +67,7 @@ TEST_CASE("uniset_rwmutex_wrlock", "[mutex][basic]" )
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
TEST_CASE("uniset_rwmutex_rlock", "[mutex][basic]" ) TEST_CASE("uniset_rwmutex_rlock", "[mutex][basic]" )
{ {
SECTION("simple lock"); SECTION("simple lock")
{ {
uniset_rwmutex m; uniset_rwmutex m;
{ {
...@@ -79,7 +79,7 @@ TEST_CASE("uniset_rwmutex_rlock", "[mutex][basic]" ) ...@@ -79,7 +79,7 @@ TEST_CASE("uniset_rwmutex_rlock", "[mutex][basic]" )
CHECK_FALSE( m.try_lock() ); CHECK_FALSE( m.try_lock() );
} }
SECTION("exception lock"); SECTION("exception lock")
{ {
uniset_rwmutex m; uniset_rwmutex m;
......
...@@ -14,7 +14,7 @@ TEST_CASE("sscanf hex", "[sscanf hex]") ...@@ -14,7 +14,7 @@ TEST_CASE("sscanf hex", "[sscanf hex]")
REQUIRE( check("100") == 100 ); REQUIRE( check("100") == 100 );
REQUIRE( check("0x100") == 0x100 ); REQUIRE( check("0x100") == 0x100 );
REQUIRE( check("0xFF") == 0xff ); REQUIRE( check("0xFF") == 0xff );
REQUIRE( check("010") == 010 ); REQUIRE( check("010") == 010 ); // -V536
REQUIRE( check("-10") == -10 ); REQUIRE( check("-10") == -10 );
REQUIRE( check("-1000") == -1000 ); REQUIRE( check("-1000") == -1000 );
REQUIRE( check("") == 0 ); REQUIRE( check("") == 0 );
......
...@@ -275,7 +275,7 @@ long UModbus::data2value( uniset::VTypes::VType vtype, uniset::ModbusRTU::Modbus ...@@ -275,7 +275,7 @@ long UModbus::data2value( uniset::VTypes::VType vtype, uniset::ModbusRTU::Modbus
else if( vtype == VTypes::vtF4 ) else if( vtype == VTypes::vtF4 )
{ {
VTypes::F4 f(data, VTypes::F4::wsize()); VTypes::F4 f(data, VTypes::F4::wsize());
return lroundf( (float)f ); return lroundf( (double)f );
} }
else if( vtype == VTypes::vtI2 ) else if( vtype == VTypes::vtI2 )
{ {
......
...@@ -53,6 +53,12 @@ class UProxyObject_impl: ...@@ -53,6 +53,12 @@ class UProxyObject_impl:
struct SInfo struct SInfo
{ {
SInfo()
{
si.id = uniset::DefaultObjectId;
si.node = uniset::DefaultObjectId;
}
IOController_i::SensorInfo si; IOController_i::SensorInfo si;
long value = { 0 }; long value = { 0 };
float fvalue = { 0.0 }; float fvalue = { 0.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