Commit b91eda75 authored by Pavel Vainerman's avatar Pavel Vainerman

Merge remote-tracking branch 'eter/master'

Conflicts: Utilities/codegen/ctl-cpp-cc-alone-ask.xsl Utilities/codegen/ctl-cpp-cc-alone.xsl Utilities/codegen/ctl-cpp-cc-ask.xsl
parents 02444c9f 3e5a3923
...@@ -194,6 +194,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si ...@@ -194,6 +194,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
</xsl:if> </xsl:if>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
ui.setValue(_sid, _val);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::askState( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node ) void <xsl:value-of select="$CLASSNAME"/>_SK::askState( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node )
......
...@@ -173,6 +173,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si ...@@ -173,6 +173,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
</xsl:if> </xsl:if>
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
ui.setValue( _sid, _val );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -192,11 +194,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si ...@@ -192,11 +194,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
// unideb[Debug::CRIT] &lt;&lt; myname &lt;&lt; "(getState): Обращение к неизвестному ДИСКРЕТНОМУ датчику sid="
// &lt;&lt; _sid &lt;&lt; endl;
//
// return 0;
return ui.getValue(_sid); return ui.getValue(_sid);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -120,6 +120,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si ...@@ -120,6 +120,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
} }
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
ui.setValue( _sid, _val );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool _force ) void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool _force )
...@@ -218,8 +220,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si ...@@ -218,8 +220,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si
unideb[Debug::CRIT] &lt;&lt; myname &lt;&lt; "(getState): " &lt;&lt; ex &lt;&lt; endl; unideb[Debug::CRIT] &lt;&lt; myname &lt;&lt; "(getState): " &lt;&lt; ex &lt;&lt; endl;
throw; throw;
} }
return 0;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -124,6 +124,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId sid ...@@ -124,6 +124,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId sid
} }
</xsl:if> </xsl:if>
</xsl:for-each> </xsl:for-each>
ui.setValue( sid, val );
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool force ) void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool force )
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Name: libuniset Name: libuniset
Version: 1.7 Version: 1.7
Release: alt4 Release: alt10
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -335,6 +335,25 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -335,6 +335,25 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Tue Apr 01 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt10
- add new vtype: F2r, I2r, U2r (reverse data order)
* Wed Mar 19 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt9
- add thresholds processing for ModbusMaster (TCP and RTU)
- minor fixes
* Fri Mar 07 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt8
- fixed bug in ComPort class (getTimeout. eterbug #9890)
* Wed Feb 12 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt7
- revert last changes ("ModbusMaster: add thread for check connection")
* Wed Feb 12 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt6
- ModbusMaster: add thread for check connection
* Mon Feb 10 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt5
- ModbusMaster: minor fixes
* Thu Feb 06 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt4 * Thu Feb 06 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt4
- ModbusExchange: fixed bug: deadlock for pollMutex.. - ModbusExchange: fixed bug: deadlock for pollMutex..
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <cmath>
#include "ORepHelpers.h" #include "ORepHelpers.h"
#include "DBServer_MySQL.h" #include "DBServer_MySQL.h"
...@@ -281,7 +282,9 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si ) ...@@ -281,7 +282,9 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
struct timezone tz; struct timezone tz;
gettimeofday(&si->tm,&tz); gettimeofday(&si->tm,&tz);
} }
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
...@@ -289,10 +292,10 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si ) ...@@ -289,10 +292,10 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы // Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date << ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time << ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec << si->sm_tv_usec << "','" // time_usec
<< si->id << "," // sensor_id << si->id << "','" // sensor_id
<< si->value << "," // value << val << "','" // value
<< si->node << ")"; // node << si->node << "')"; // node
if( unideb.debugging(DBLEVEL) ) if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl; unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sstream> #include <sstream>
#include <iomanip> #include <iomanip>
#include <cmath>
#include "ORepHelpers.h" #include "ORepHelpers.h"
#include "DBServer_SQLite.h" #include "DBServer_SQLite.h"
...@@ -258,7 +259,9 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si ) ...@@ -258,7 +259,9 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
struct timezone tz; struct timezone tz;
gettimeofday(&si->tm,&tz); gettimeofday(&si->tm,&tz);
} }
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors // см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data; ostringstream data;
data << "INSERT INTO " << tblName(si->type) data << "INSERT INTO " << tblName(si->type)
...@@ -266,10 +269,10 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si ) ...@@ -266,10 +269,10 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы // Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date << ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time << ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec << si->sm_tv_usec << "','" // time_usec
<< si->id << "," // sensor_id << si->id << "','" // sensor_id
<< si->value << "," // value << si->value << "','" // value
<< si->node << ")"; // node << si->node << "')"; // node
if( unideb.debugging(DBLEVEL) ) if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl; unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
...@@ -80,7 +80,7 @@ pollActivated(false) ...@@ -80,7 +80,7 @@ pollActivated(false)
initPause = conf->getArgPInt("--" + prefix + "-initPause",it.getProp("initPause"), 3000); initPause = conf->getArgPInt("--" + prefix + "-initPause",it.getProp("initPause"), 3000);
sleepPause_usec = conf->getArgPInt("--" + prefix + "-sleepPause-usec",it.getProp("slepePause"), 100); sleepPause_usec = conf->getArgPInt("--" + prefix + "-sleepPause-usec",it.getProp("sleepPause"), 100);
force = conf->getArgInt("--" + prefix + "-force",it.getProp("force")); force = conf->getArgInt("--" + prefix + "-force",it.getProp("force"));
force_out = conf->getArgInt("--" + prefix + "-force-out",it.getProp("force_out")); force_out = conf->getArgInt("--" + prefix + "-force-out",it.getProp("force_out"));
...@@ -309,9 +309,17 @@ void MBExchange::initIterators() ...@@ -309,9 +309,17 @@ void MBExchange::initIterators()
{ {
shm->initDIterator(it2->dit); shm->initDIterator(it2->dit);
shm->initAIterator(it2->ait); shm->initAIterator(it2->ait);
shm->initAIterator(it2->t_ait);
} }
} }
} }
for( ThresholdList::iterator t=thrlist.begin(); t!=thrlist.end(); ++t )
{
shm->initDIterator(t->dit);
shm->initAIterator(t->ait);
shm->initAIterator(t->t_ait);
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool MBExchange::checkUpdateSM( bool wrFunc, long mdev ) bool MBExchange::checkUpdateSM( bool wrFunc, long mdev )
...@@ -661,7 +669,7 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty ...@@ -661,7 +669,7 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
if( p->nbit >= 0 ) if( p->nbit >= 0 )
{ {
bool set = b[p->nbit]; bool set = b[p->nbit];
IOBase::processingAsDI( p, set, shm, force ); IOBase::processingAsDI( p, set, shm, true );
return true; return true;
} }
...@@ -670,10 +678,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty ...@@ -670,10 +678,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
if( p->stype == UniversalIO::DigitalInput || if( p->stype == UniversalIO::DigitalInput ||
p->stype == UniversalIO::DigitalOutput ) p->stype == UniversalIO::DigitalOutput )
{ {
IOBase::processingAsDI( p, data[0], shm, force ); IOBase::processingAsDI( p, data[0], shm, true );
} }
else else
IOBase::processingAsAI( p, (signed short)(data[0]), shm, force ); IOBase::processingAsAI( p, (signed short)(data[0]), shm, true );
return true; return true;
} }
...@@ -688,10 +696,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty ...@@ -688,10 +696,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
if( p->stype == UniversalIO::DigitalInput || if( p->stype == UniversalIO::DigitalInput ||
p->stype == UniversalIO::DigitalOutput ) p->stype == UniversalIO::DigitalOutput )
{ {
IOBase::processingAsDI( p, data[0], shm, force ); IOBase::processingAsDI( p, data[0], shm, true );
} }
else else
IOBase::processingAsAI( p, (signed short)(data[0]), shm, force ); IOBase::processingAsAI( p, (signed short)(data[0]), shm, true );
return true; return true;
} }
...@@ -700,10 +708,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty ...@@ -700,10 +708,10 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
if( p->stype == UniversalIO::DigitalInput || if( p->stype == UniversalIO::DigitalInput ||
p->stype == UniversalIO::DigitalOutput ) p->stype == UniversalIO::DigitalOutput )
{ {
IOBase::processingAsDI( p, data[0], shm, force ); IOBase::processingAsDI( p, data[0], shm, true );
} }
else else
IOBase::processingAsAI( p, (unsigned short)data[0], shm, force ); IOBase::processingAsAI( p, (unsigned short)data[0], shm, true );
return true; return true;
} }
...@@ -717,28 +725,43 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty ...@@ -717,28 +725,43 @@ bool MBExchange::initSMValue( ModbusRTU::ModbusData* data, int count, RSProperty
} }
VTypes::Byte b(data[0]); VTypes::Byte b(data[0]);
IOBase::processingAsAI( p, b.raw.b[p->nbyte-1], shm, force ); IOBase::processingAsAI( p, b.raw.b[p->nbyte-1], shm, true );
return true; return true;
} }
else if( p->vType == VTypes::vtF2 ) else if( p->vType == VTypes::vtF2 )
{ {
VTypes::F2 f(data,VTypes::F2::wsize()); VTypes::F2 f(data,VTypes::F2::wsize());
IOBase::processingFasAI( p, (float)f, shm, force ); IOBase::processingFasAI( p, (float)f, shm, true );
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f(data,VTypes::F2r::wsize());
IOBase::processingFasAI( p, (float)f, shm, true );
} }
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, force ); IOBase::processingFasAI( p, (float)f, shm, true );
} }
else if( p->vType == VTypes::vtI2 ) else if( p->vType == VTypes::vtI2 )
{ {
VTypes::I2 i2(data,VTypes::I2::wsize()); VTypes::I2 i2(data,VTypes::I2::wsize());
IOBase::processingAsAI( p, (int)i2, shm, force ); IOBase::processingAsAI( p, (int)i2, shm, true );
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(data,VTypes::I2::wsize());
IOBase::processingAsAI( p, (int)i2, shm, true );
} }
else if( p->vType == VTypes::vtU2 ) else if( p->vType == VTypes::vtU2 )
{ {
VTypes::U2 u2(data,VTypes::U2::wsize()); VTypes::U2 u2(data,VTypes::U2::wsize());
IOBase::processingAsAI( p, (unsigned int)u2, shm, force ); IOBase::processingAsAI( p, (unsigned int)u2, shm, true );
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(data,VTypes::U2::wsize());
IOBase::processingAsAI( p, (unsigned int)u2, shm, true );
} }
return true; return true;
...@@ -831,7 +854,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it ) ...@@ -831,7 +854,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it )
case ModbusRTU::fnReadOutputRegisters: case ModbusRTU::fnReadOutputRegisters:
{ {
ModbusRTU::ReadOutputRetMessage ret = mb->read03(dev->mbaddr, p->mbreg,p->q_count); ModbusRTU::ReadOutputRetMessage ret = mb->read03(dev->mbaddr,p->mbreg,p->q_count);
for( int i=0; i<p->q_count; i++,it++ ) for( int i=0; i<p->q_count; i++,it++ )
it->second->mbval = ret.data[i]; it->second->mbval = ret.data[i];
it--; it--;
...@@ -1095,7 +1118,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1095,7 +1118,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
return; return;
if( dlog.debugging(Debug::LEVEL3) ) if( dlog.debugging(Debug::LEVEL3) )
dlog[Debug::LEVEL3] << "updateP: sid=" << p->si.id dlog[Debug::LEVEL3] << myname << "(updateP): sid=" << p->si.id
<< " mbval=" << r->mbval << " mbval=" << r->mbval
<< " vtype=" << p->vType << " vtype=" << p->vType
<< " rnum=" << p->rnum << " rnum=" << p->rnum
...@@ -1257,7 +1280,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1257,7 +1280,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
return; return;
} }
else if( p->vType == VTypes::vtF2 ) else if( p->vType == VTypes::vtF2 || p->vType == VTypes::vtF2r )
{ {
RegMap::iterator i(p->reg->rit); RegMap::iterator i(p->reg->rit);
if( save ) if( save )
...@@ -1265,9 +1288,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1265,9 +1288,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK ) if( r->mb_initOK )
{ {
float f = IOBase::processingFasAO( p, shm, force_out ); float f = IOBase::processingFasAO( p, shm, force_out );
VTypes::F2 f2(f); if( p->vType == VTypes::vtF2 )
for( int k=0; k<VTypes::F2::wsize(); k++, i++ ) {
i->second->mbval = f2.raw.v[k]; VTypes::F2 f2(f);
for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f2(f);
for( int k=0; k<VTypes::F2r::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
}
r->sm_initOK = true; r->sm_initOK = true;
} }
...@@ -1277,11 +1309,22 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1277,11 +1309,22 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[VTypes::F2::wsize()]; ModbusRTU::ModbusData* data = new ModbusRTU::ModbusData[VTypes::F2::wsize()];
for( int k=0; k<VTypes::F2::wsize(); k++, i++ ) for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
data[k] = i->second->mbval; data[k] = i->second->mbval;
VTypes::F2 f(data,VTypes::F2::wsize()); float f=0;
if( p->vType == VTypes::vtF2 )
{
VTypes::F2 f1(data,VTypes::F2::wsize());
f = (float)f1;
}
else if( p->vType == VTypes::vtF2r )
{
VTypes::F2r f1(data,VTypes::F2r::wsize());
f = (float)f1;
}
delete[] data; delete[] data;
IOBase::processingFasAI( p, (float)f, shm, force ); IOBase::processingFasAI( p, f, shm, force );
} }
} }
else if( p->vType == VTypes::vtF4 ) else if( p->vType == VTypes::vtF4 )
...@@ -1309,7 +1352,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1309,7 +1352,7 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
IOBase::processingFasAI( p, (float)f, shm, force ); IOBase::processingFasAI( p, (float)f, shm, force );
} }
} }
else if( p->vType == VTypes::vtI2 ) else if( p->vType == VTypes::vtI2 || p->vType == VTypes::vtI2r )
{ {
RegMap::iterator i(p->reg->rit); RegMap::iterator i(p->reg->rit);
if( save ) if( save )
...@@ -1317,10 +1360,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1317,10 +1360,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK ) if( r->mb_initOK )
{ {
long v = IOBase::processingAsAO( p, shm, force_out ); long v = IOBase::processingAsAO( p, shm, force_out );
VTypes::I2 i2(v); if( p->vType == VTypes::vtI2 )
for( int k=0; k<VTypes::I2::wsize(); k++, i++ ) {
i->second->mbval = i2.raw.v[k]; VTypes::I2 i2(v);
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
i->second->mbval = i2.raw.v[k];
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(v);
for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
i->second->mbval = i2.raw.v[k];
}
r->sm_initOK = true; r->sm_initOK = true;
} }
} }
...@@ -1330,13 +1381,23 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1330,13 +1381,23 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
for( int k=0; k<VTypes::I2::wsize(); k++, i++ ) for( int k=0; k<VTypes::I2::wsize(); k++, i++ )
data[k] = i->second->mbval; data[k] = i->second->mbval;
VTypes::I2 i2(data,VTypes::I2::wsize()); int v = 0;
if( p->vType == VTypes::vtI2 )
{
VTypes::I2 i2(data,VTypes::I2::wsize());
v = (int)i2;
}
else if( p->vType == VTypes::vtI2r )
{
VTypes::I2r i2(data,VTypes::I2::wsize());
v = (int)i2;
}
delete[] data; delete[] data;
IOBase::processingAsAI( p, v, shm, force );
IOBase::processingAsAI( p, (int)i2, shm, force );
} }
} }
else if( p->vType == VTypes::vtU2 ) else if( p->vType == VTypes::vtU2 || p->vType == VTypes::vtU2r )
{ {
RegMap::iterator i(p->reg->rit); RegMap::iterator i(p->reg->rit);
if( save ) if( save )
...@@ -1344,9 +1405,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1344,9 +1405,18 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
if( r->mb_initOK ) if( r->mb_initOK )
{ {
long v = IOBase::processingAsAO( p, shm, force_out ); long v = IOBase::processingAsAO( p, shm, force_out );
VTypes::U2 u2(v); if( p->vType == VTypes::vtU2 )
for( int k=0; k<VTypes::U2::wsize(); k++, i++ ) {
i->second->mbval = u2.raw.v[k]; VTypes::U2 u2(v);
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
i->second->mbval = u2.raw.v[k];
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(v);
for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
i->second->mbval = u2.raw.v[k];
}
r->sm_initOK = true; r->sm_initOK = true;
} }
...@@ -1357,16 +1427,26 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only ) ...@@ -1357,16 +1427,26 @@ void MBExchange::updateRSProperty( RSProperty* p, bool write_only )
for( int k=0; k<VTypes::U2::wsize(); k++, i++ ) for( int k=0; k<VTypes::U2::wsize(); k++, i++ )
data[k] = i->second->mbval; data[k] = i->second->mbval;
VTypes::U2 u2(data,VTypes::U2::wsize()); unsigned int v = 0;
if( p->vType == VTypes::vtU2 )
{
VTypes::U2 u2(data,VTypes::U2::wsize());
v = (unsigned int)u2;
}
else if( p->vType == VTypes::vtU2r )
{
VTypes::U2r u2(data,VTypes::U2::wsize());
v = (unsigned int)u2;
}
delete[] data; delete[] data;
IOBase::processingAsAI( p, v, shm, force );
IOBase::processingAsAI( p, (unsigned int)u2, shm, force );
} }
} }
return; return;
} }
catch(IOController_i::NameNotFound &ex) catch(IOController_i::NameNotFound& ex)
{ {
dlog[Debug::LEVEL3] << myname << "(updateRSProperty):(NameNotFound) " << ex.err << endl; dlog[Debug::LEVEL3] << myname << "(updateRSProperty):(NameNotFound) " << ex.err << endl;
} }
...@@ -1832,6 +1912,15 @@ bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it ) ...@@ -1832,6 +1912,15 @@ bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it )
if( !IOBase::initItem(&p,it,shm,&dlog,myname) ) if( !IOBase::initItem(&p,it,shm,&dlog,myname) )
return false; return false;
// проверяем не пороговый ли это датчик (т.е. не связанный с обменом)
// тогда заносим его в отдельный список
if( p.t_ai != DefaultObjectId )
{
thrlist.push_back(p);
return true;
}
if( it.getIntProp(prop_prefix + "rawdata") ) if( it.getIntProp(prop_prefix + "rawdata") )
{ {
p.cal.minRaw = 0; p.cal.minRaw = 0;
...@@ -2064,6 +2153,16 @@ bool MBExchange::initItem( UniXML_iterator& it ) ...@@ -2064,6 +2153,16 @@ bool MBExchange::initItem( UniXML_iterator& it )
} }
mbreg = ModbusRTU::str2mbData(reg); mbreg = ModbusRTU::str2mbData(reg);
} }
if( p.nbit != -1 )
{
if( fn == ModbusRTU::fnReadCoilStatus || fn == ModbusRTU::fnReadInputStatus )
{
dlog[Debug::CRIT] << myname << "(initItem): MISMATCHED CONFIGURATION! nbit=" << p.nbit << " func=" << fn
<< " for " << it.getProp("name") << endl;
return false;
}
}
} }
// формула для вычисления ID // формула для вычисления ID
...@@ -2828,18 +2927,12 @@ void MBExchange::poll() ...@@ -2828,18 +2927,12 @@ void MBExchange::poll()
updateSM(); updateSM();
// check thresholds // check thresholds
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 ) for( ThresholdList::iterator t=thrlist.begin(); t!=thrlist.end(); ++t )
{ {
RTUDevice* d(it1->second); if( !checkProcActive() )
for( MBExchange::RegMap::iterator it=d->regmap.begin(); it!=d->regmap.end(); ++it ) return;
{
if( !checkProcActive() ) IOBase::processingThreshold(&(*t),shm,force);
return;
RegInfo* r(it->second);
for( PList::iterator i=r->slst.begin(); i!=r->slst.end(); ++i )
IOBase::processingThreshold( &(*i),shm,force);
}
} }
if( trReopen.hi(allNotRespond) ) if( trReopen.hi(allNotRespond) )
......
...@@ -325,6 +325,11 @@ class MBExchange: ...@@ -325,6 +325,11 @@ class MBExchange:
PassiveTimer ptReopen; /*!< таймер для переоткрытия соединения */ PassiveTimer ptReopen; /*!< таймер для переоткрытия соединения */
Trigger trReopen; Trigger trReopen;
// т.к. пороговые датчики не связаны напрямую с обменом, создаём для них отдельный список
// и отдельно его проверяем потом
typedef std::list<IOBase> ThresholdList;
ThresholdList thrlist;
private: private:
MBExchange(); MBExchange();
......
...@@ -301,17 +301,14 @@ void RTUExchange::poll() ...@@ -301,17 +301,14 @@ void RTUExchange::poll()
updateSM(); updateSM();
// check thresholds // check thresholds
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 ) for( ThresholdList::iterator t=thrlist.begin(); t!=thrlist.end(); ++t )
{ {
RTUDevice* d(it1->second); if( !checkProcActive() )
for( RTUExchange::RegMap::iterator it=d->regmap.begin(); it!=d->regmap.end(); ++it ) return;
{
RegInfo* r(it->second); IOBase::processingThreshold(&(*t),shm,force);
for( PList::iterator i=r->slst.begin(); i!=r->slst.end(); ++i )
IOBase::processingThreshold( &(*i),shm,force);
}
} }
if( trReopen.hi(allNotRespond) ) if( trReopen.hi(allNotRespond) )
ptReopen.reset(); ptReopen.reset();
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
--confile test.xml \ --confile test.xml \
--mbtcp-name MBMaster1 \ --mbtcp-name MBMaster1 \
--smemory-id SharedMemory \ --smemory-id SharedMemory \
--dlog-add-levels info,crit,warn,level4,level3 \ --dlog-add-levels info,crit,warn,level4,level3,level9 \
--mbtcp-set-prop-prefix \ --mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \ --mbtcp-filter-field rs \
--mbtcp-filter-value 5 \ --mbtcp-filter-value 5 \
--mbtcp-gateway-iaddr 127.0.0.1 \ --mbtcp-gateway-iaddr 192.168.1.42 \
--mbtcp-gateway-port 2048 \ --mbtcp-gateway-port 2048 \
--mbtcp-recv-timeout 5000 \ --mbtcp-recv-timeout 5000 \
--mbtcp-force-disconnect 1 \ --mbtcp-force-disconnect 1 \
......
...@@ -9,11 +9,11 @@ using namespace VTypes; ...@@ -9,11 +9,11 @@ using namespace VTypes;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void print_help() static void print_help()
{ {
printf("Usage: vtconv TYPE[F2|F4|I2|U2] hex1 hex2 [hex3 hex4]\n"); printf("Usage: vtconv TYPE[F2|F2r|F4|I2|U2|I2r|U2r] hex1 hex2 [hex3 hex4]\n");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, const char **argv ) int main( int argc, const char **argv )
{ {
/* /*
VTypes::F2 f2; VTypes::F2 f2;
f2.raw.val = 2.345; f2.raw.val = 2.345;
...@@ -89,6 +89,13 @@ int main( int argc, const char **argv ) ...@@ -89,6 +89,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1] << " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl; << " --> (float) " << (float)f << endl;
} }
else if( !strcmp(type,"F2r") )
{
VTypes::F2r f(v,sizeof(v));
cout << "(F2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F4") ) else if( !strcmp(type,"F4") )
{ {
VTypes::F4 f(v,sizeof(v)); VTypes::F4 f(v,sizeof(v));
...@@ -105,6 +112,13 @@ int main( int argc, const char **argv ) ...@@ -105,6 +112,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1] << " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl; << " --> (int) " << (int)i << endl;
} }
else if( !strcmp(type,"I2r") )
{
VTypes::I2r i(v,sizeof(v));
cout << "(I2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl;
}
else if( !strcmp(type,"U2") ) else if( !strcmp(type,"U2") )
{ {
VTypes::U2 i(v,sizeof(v)); VTypes::U2 i(v,sizeof(v));
...@@ -112,6 +126,13 @@ int main( int argc, const char **argv ) ...@@ -112,6 +126,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1] << " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl; << " --> (unsigned int) " << (unsigned int)i << endl;
} }
else if( !strcmp(type,"U2r") )
{
VTypes::U2r i(v,sizeof(v));
cout << "(U2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl;
}
else else
{ {
cout << " Unknown type: " << type << endl; cout << " Unknown type: " << type << endl;
......
...@@ -77,8 +77,8 @@ prefix(prefix) ...@@ -77,8 +77,8 @@ prefix(prefix)
if( speed.empty() ) if( speed.empty() )
speed = "38400"; speed = "38400";
bool use485F = conf->getArgInt("--rs-use485F",it.getProp("use485F")); bool use485F = conf->getArgInt("--" + prefix +"-use485F",it.getProp("use485F"));
bool transmitCtl = conf->getArgInt("--rs-transmit-ctl",it.getProp("transmitCtl")); bool transmitCtl = conf->getArgInt("--" + prefix + "-transmit-ctl",it.getProp("transmitCtl"));
ModbusRTUSlaveSlot* rs = new ModbusRTUSlaveSlot(dev,use485F,transmitCtl); ModbusRTUSlaveSlot* rs = new ModbusRTUSlaveSlot(dev,use485F,transmitCtl);
rs->setSpeed(speed); rs->setSpeed(speed);
...@@ -1287,7 +1287,7 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb ...@@ -1287,7 +1287,7 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
{ {
val = IOBase::processingAsAO(p,shm,force); val = IOBase::processingAsAO(p,shm,force);
} }
if( p->vtype == VTypes::vtF2 ) else if( p->vtype == VTypes::vtF2 )
{ {
float f = IOBase::processingFasAO(p,shm,force); float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2 f2(f); VTypes::F2 f2(f);
...@@ -1297,6 +1297,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb ...@@ -1297,6 +1297,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < f4.wsize() // if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum]; val = f2.raw.v[p->wnum];
} }
else if( p->vtype == VTypes::vtF2r )
{
float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2r f2(f);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtF4 ) else if( p->vtype == VTypes::vtF4 )
{ {
float f = IOBase::processingFasAO(p,shm,force); float f = IOBase::processingFasAO(p,shm,force);
...@@ -1317,6 +1327,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb ...@@ -1317,6 +1327,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < i2.wsize() // if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum]; val = i2.raw.v[p->wnum];
} }
else if( p->vtype == VTypes::vtI2r )
{
long v = IOBase::processingAsAO(p,shm,force);
VTypes::I2r i2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtU2 ) else if( p->vtype == VTypes::vtU2 )
{ {
unsigned long v = IOBase::processingAsAO(p,shm,force); unsigned long v = IOBase::processingAsAO(p,shm,force);
...@@ -1327,6 +1347,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb ...@@ -1327,6 +1347,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < u2.wsize() // if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum]; val = u2.raw.v[p->wnum];
} }
else if( p->vtype == VTypes::vtU2r )
{
unsigned long v = IOBase::processingAsAO(p,shm,force);
VTypes::U2r u2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum];
}
else else
val = IOBase::processingAsAO(p,shm,force); val = IOBase::processingAsAO(p,shm,force);
} }
......
...@@ -32,6 +32,7 @@ void SharedMemory::help_print( int argc, const char* const* argv ) ...@@ -32,6 +32,7 @@ void SharedMemory::help_print( int argc, const char* const* argv )
cout << "--pulsar-id - датчик 'мигания'" << endl; cout << "--pulsar-id - датчик 'мигания'" << endl;
cout << "--pulsar-msec - период 'мигания'. По умолчанию: 5000." << endl; cout << "--pulsar-msec - период 'мигания'. По умолчанию: 5000." << endl;
cout << "--pulsar-iotype - [DI|DO]тип датчика для 'мигания'. По умолчанию DI." << endl; cout << "--pulsar-iotype - [DI|DO]тип датчика для 'мигания'. По умолчанию DI." << endl;
cout << "--db-logging [1,0] - Включение логирования в DBServer. По умолчанию 0 (выключено)" << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
SharedMemory::SharedMemory( ObjectId id, string datafile, std::string confname ): SharedMemory::SharedMemory( ObjectId id, string datafile, std::string confname ):
......
...@@ -44,19 +44,19 @@ int main(int argc, const char **argv) ...@@ -44,19 +44,19 @@ int main(int argc, const char **argv)
} }
catch( SystemError& err ) catch( SystemError& err )
{ {
unideb[Debug::CRIT] << "(smemory): " << err << endl; dlog[Debug::CRIT] << "(smemory): " << err << endl;
} }
catch( Exception& ex ) catch( Exception& ex )
{ {
unideb[Debug::CRIT] << "(smemory): " << ex << endl; dlog[Debug::CRIT] << "(smemory): " << ex << endl;
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
unideb[Debug::CRIT] << "(smemory): " << e.what() << endl; dlog[Debug::CRIT] << "(smemory): " << e.what() << endl;
} }
catch(...) catch(...)
{ {
unideb[Debug::CRIT] << "(smemory): catch(...)" << endl; dlog[Debug::CRIT] << "(smemory): catch(...)" << endl;
} }
return 1; return 1;
......
...@@ -58,15 +58,15 @@ int main(int argc, const char **argv) ...@@ -58,15 +58,15 @@ int main(int argc, const char **argv)
} }
catch(SystemError& err) catch(SystemError& err)
{ {
unideb[Debug::CRIT] << "(uninetwork): " << err << endl; dlog[Debug::CRIT] << "(uninetwork): " << err << endl;
} }
catch(Exception& ex) catch(Exception& ex)
{ {
unideb[Debug::CRIT] << "(uninetwork): " << ex << endl; dlog[Debug::CRIT] << "(uninetwork): " << ex << endl;
} }
catch(...) catch(...)
{ {
unideb[Debug::CRIT] << "(uninetwork): catch(...)" << endl; dlog[Debug::CRIT] << "(uninetwork): catch(...)" << endl;
} }
while( waitpid(-1, 0, 0) > 0 ); while( waitpid(-1, 0, 0) > 0 );
......
...@@ -101,7 +101,7 @@ static const int NoSafety = -1; ...@@ -101,7 +101,7 @@ static const int NoSafety = -1;
хранится идентификатор аналогового датчика хранится идентификатор аналогового датчика
с которым он связан */ с которым он связан */
IONotifyController_i::ThresholdInfo ti; IONotifyController_i::ThresholdInfo ti;
IOController::AIOStateList::iterator t_ait; /*! итератор на датчик по которому формируется порог */
IOController::AIOStateList::iterator ait; IOController::AIOStateList::iterator ait;
IOController::DIOStateList::iterator dit; IOController::DIOStateList::iterator dit;
......
...@@ -16,12 +16,15 @@ namespace VTypes ...@@ -16,12 +16,15 @@ namespace VTypes
{ {
vtUnknown, vtUnknown,
vtF2, /*!< двойное слово float(4 байта). В виде строки задаётся как \b "F2". */ vtF2, /*!< двойное слово float(4 байта). В виде строки задаётся как \b "F2". */
vtF2r, /*!< двойное слово float(4 байта). С перевёрнутой (reverse) последовательностью слов. \b "F2r". */
vtF4, /*!< 8-х байтовое слово (double). В виде строки задаётся как \b "F4". */ vtF4, /*!< 8-х байтовое слово (double). В виде строки задаётся как \b "F4". */
vtByte, /*!< байт. В виде строки задаётся как \b "byte". */ vtByte, /*!< байт. В виде строки задаётся как \b "byte". */
vtUnsigned, /*!< беззнаковое целое (2 байта). В виде строки задаётся как \b "unsigned". */ vtUnsigned, /*!< беззнаковое целое (2 байта). В виде строки задаётся как \b "unsigned". */
vtSigned, /*!< знаковое целое (2 байта). В виде строки задаётся как \b "signed". */ vtSigned, /*!< знаковое целое (2 байта). В виде строки задаётся как \b "signed". */
vtI2, /*!< целое (4 байта). В виде строки задаётся как \b "I2".*/ vtI2, /*!< целое (4 байта). В виде строки задаётся как \b "I2".*/
vtU2 /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/ vtI2r, /*!< целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "I2r".*/
vtU2, /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/
vtU2r /*!< беззнаковое целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "U2r".*/
}; };
std::ostream& operator<<( std::ostream& os, const VType& vt ); std::ostream& operator<<( std::ostream& os, const VType& vt );
...@@ -67,6 +70,24 @@ namespace VTypes ...@@ -67,6 +70,24 @@ namespace VTypes
F2mem raw; F2mem raw;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class F2r:
public F2
{
public:
// ------------------------------------------
// конструкторы на разные случаи...
F2r(){}
F2r( float f ):F2(f){}
F2r( const ModbusRTU::ModbusData* data, int size ):F2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~F2r(){}
};
// --------------------------------------------------------------------------
class F4 class F4
{ {
public: public:
...@@ -239,6 +260,21 @@ namespace VTypes ...@@ -239,6 +260,21 @@ namespace VTypes
I2mem raw; I2mem raw;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class I2r:
public I2
{
public:
I2r(){}
I2r( int v ):I2(v){}
I2r( const ModbusRTU::ModbusData* data, int size ):I2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~I2r(){}
};
// --------------------------------------------------------------------------
class U2 class U2
{ {
public: public:
...@@ -274,6 +310,21 @@ namespace VTypes ...@@ -274,6 +310,21 @@ namespace VTypes
U2mem raw; U2mem raw;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class U2r:
public U2
{
public:
U2r(){}
U2r( int v ):U2(v){}
U2r( const ModbusRTU::ModbusData* data, int size ):U2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~U2r(){}
};
// --------------------------------------------------------------------------
} // end of namespace VTypes } // end of namespace VTypes
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
...@@ -431,12 +431,26 @@ bool send_param( ModbusRTUMaster* mb, DataMap& dmap, ModbusRTU::ModbusAddr addr, ...@@ -431,12 +431,26 @@ bool send_param( ModbusRTUMaster* mb, DataMap& dmap, ModbusRTU::ModbusAddr addr,
// if( !ok ) // if( !ok )
// return false; // return false;
} }
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(addr,regUpdateConfiguration,1);
if( verb )
cout << "(mtr-setup): save parameters " << endl;
return true; try
{
ModbusRTU::ModbusData dat = 1;
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06( addr, regUpdateConfiguration, dat);
if( ret.start == regUpdateConfiguration && ret.data == dat )
{
if( verb )
cout << "(mtr-setup): save parameters " << endl;
return true;
}
}
catch( ModbusRTU::mbException& ex )
{
}
if( verb )
cout << "(mtr-setup): not save parameters " << endl;
return false;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
MTR::MTRError update_configuration( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr slaveaddr, MTR::MTRError update_configuration( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr slaveaddr,
......
...@@ -18,6 +18,8 @@ VType str2type( const std::string& s ) ...@@ -18,6 +18,8 @@ VType str2type( const std::string& s )
return vtByte; return vtByte;
if( s == "F2" || s == "f2" ) if( s == "F2" || s == "f2" )
return vtF2; return vtF2;
if( s == "F2r" || s == "f2r" )
return vtF2r;
if( s == "F4" || s == "f4" ) if( s == "F4" || s == "f4" )
return vtF4; return vtF4;
if( s == "Unsigned" || s == "unsigned" ) if( s == "Unsigned" || s == "unsigned" )
...@@ -26,8 +28,12 @@ VType str2type( const std::string& s ) ...@@ -26,8 +28,12 @@ VType str2type( const std::string& s )
return vtSigned; return vtSigned;
if( s == "I2" || s == "i2" ) if( s == "I2" || s == "i2" )
return vtI2; return vtI2;
if( s == "I2r" || s == "i2r" )
return vtI2r;
if( s == "U2" || s == "u2" ) if( s == "U2" || s == "u2" )
return vtU2; return vtU2;
if( s == "U2r" || s == "u2r" )
return vtU2r;
return vtUnknown; return vtUnknown;
} }
...@@ -38,6 +44,8 @@ string type2str( VType t ) ...@@ -38,6 +44,8 @@ string type2str( VType t )
return "Byte"; return "Byte";
if( t == vtF2 ) if( t == vtF2 )
return "F2"; return "F2";
if( t == vtF2r )
return "F2r";
if( t == vtF4 ) if( t == vtF4 )
return "F4"; return "F4";
if( t == vtUnsigned ) if( t == vtUnsigned )
...@@ -46,8 +54,12 @@ string type2str( VType t ) ...@@ -46,8 +54,12 @@ string type2str( VType t )
return "Signed"; return "Signed";
if( t == vtI2 ) if( t == vtI2 )
return "I2"; return "I2";
if( t == vtI2r )
return "I2r";
if( t == vtU2 ) if( t == vtU2 )
return "U2"; return "U2";
if( t == vtU2r )
return "U2r";
return "vtUnknown"; return "vtUnknown";
} }
...@@ -56,7 +68,7 @@ int wsize( VType t ) ...@@ -56,7 +68,7 @@ int wsize( VType t )
{ {
if( t == vtByte ) if( t == vtByte )
return Byte::wsize(); return Byte::wsize();
if( t == vtF2 ) if( t == vtF2 || t == vtF2r )
return F2::wsize(); return F2::wsize();
if( t == vtF4 ) if( t == vtF4 )
return F4::wsize(); return F4::wsize();
...@@ -64,9 +76,9 @@ int wsize( VType t ) ...@@ -64,9 +76,9 @@ int wsize( VType t )
return Unsigned::wsize(); return Unsigned::wsize();
if( t == vtSigned ) if( t == vtSigned )
return Signed::wsize(); return Signed::wsize();
if( t == vtI2 ) if( t == vtI2 || t == vtI2r )
return I2::wsize(); return I2::wsize();
if( t == vtU2 ) if( t == vtU2 || t == vtU2r )
return U2::wsize(); return U2::wsize();
return 1; return 1;
......
...@@ -82,9 +82,9 @@ public: ...@@ -82,9 +82,9 @@ public:
void setCharacterSize(CharacterSize); void setCharacterSize(CharacterSize);
void setStopBits(StopBits sBit); void setStopBits(StopBits sBit);
virtual void setTimeout(int timeout); virtual void setTimeout( int msec );
void setWaiting(bool waiting); inline int getTimeout(){ return uTimeout/1000; } // msec
inline int getTimeout(){ return uTimeout*1000; } // msec void setWaiting( bool waiting );
virtual unsigned char receiveByte(); virtual unsigned char receiveByte();
virtual void sendByte(unsigned char x); virtual void sendByte(unsigned char x);
......
...@@ -257,9 +257,9 @@ void ComPort::sendByte(unsigned char x) ...@@ -257,9 +257,9 @@ void ComPort::sendByte(unsigned char x)
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// Lav: убрать, переделать в receiveBlock // Lav: убрать, переделать в receiveBlock
void ComPort::setTimeout(int timeout) void ComPort::setTimeout( int msec )
{ {
uTimeout=timeout; uTimeout = msec * 1000;
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// Lav: ситуация, когда отправлено меньше запрошенного, не типична и должна // Lav: ситуация, когда отправлено меньше запрошенного, не типична и должна
......
...@@ -73,10 +73,10 @@ ComPort485F::ComPort485F( string dev, int gpio_num, bool tmit_ctrl ): ...@@ -73,10 +73,10 @@ ComPort485F::ComPort485F( string dev, int gpio_num, bool tmit_ctrl ):
} }
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void ComPort485F::setTimeout(int timeout) void ComPort485F::setTimeout( int msec )
{ {
tout_msec = timeout / 1000; tout_msec = msec;
ComPort::setTimeout(timeout); ComPort::setTimeout(msec);
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
unsigned char ComPort485F::m_receiveByte( bool wait ) unsigned char ComPort485F::m_receiveByte( bool wait )
......
...@@ -35,7 +35,7 @@ ModbusRTUMaster::ModbusRTUMaster( const string dev, bool use485, bool tr_ctl ): ...@@ -35,7 +35,7 @@ ModbusRTUMaster::ModbusRTUMaster( const string dev, bool use485, bool tr_ctl ):
port->setCharacterSize(ComPort::CSize8); port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit); port->setStopBits(ComPort::OneBit);
port->setWaiting(true); port->setWaiting(true);
port->setTimeout(replyTimeOut_ms*1000); port->setTimeout(replyTimeOut_ms);
// port->setBlocking(false); // port->setBlocking(false);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -51,7 +51,7 @@ ModbusRTUMaster::ModbusRTUMaster( ComPort* com ): ...@@ -51,7 +51,7 @@ ModbusRTUMaster::ModbusRTUMaster( ComPort* com ):
port->setCharacterSize(ComPort::CSize8); port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit); port->setStopBits(ComPort::OneBit);
port->setWaiting(true); port->setWaiting(true);
port->setTimeout(replyTimeOut_ms*1000); port->setTimeout(replyTimeOut_ms);
// port->setBlocking(false); // port->setBlocking(false);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -116,7 +116,7 @@ int ModbusRTUMaster::getNextData( unsigned char* buf, int len ) ...@@ -116,7 +116,7 @@ int ModbusRTUMaster::getNextData( unsigned char* buf, int len )
void ModbusRTUMaster::setChannelTimeout( timeout_t msec ) void ModbusRTUMaster::setChannelTimeout( timeout_t msec )
{ {
if( port ) if( port )
port->setTimeout(msec*1000); port->setTimeout(msec);
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
mbErrCode ModbusRTUMaster::sendData( unsigned char* buf, int len ) mbErrCode ModbusRTUMaster::sendData( unsigned char* buf, int len )
......
...@@ -35,7 +35,7 @@ ModbusRTUSlave::ModbusRTUSlave( const string dev, bool use485, bool tr_ctl ): ...@@ -35,7 +35,7 @@ ModbusRTUSlave::ModbusRTUSlave( const string dev, bool use485, bool tr_ctl ):
port->setCharacterSize(ComPort::CSize8); port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit); port->setStopBits(ComPort::OneBit);
port->setWaiting(true); port->setWaiting(true);
port->setTimeout(recvTimeOut_ms*1000); port->setTimeout(recvTimeOut_ms);
// port->setBlocking(false); // port->setBlocking(false);
} }
...@@ -49,7 +49,7 @@ ModbusRTUSlave::ModbusRTUSlave( ComPort* com ): ...@@ -49,7 +49,7 @@ ModbusRTUSlave::ModbusRTUSlave( ComPort* com ):
port->setCharacterSize(ComPort::CSize8); port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit); port->setStopBits(ComPort::OneBit);
port->setWaiting(true); port->setWaiting(true);
port->setTimeout(recvTimeOut_ms*1000); port->setTimeout(recvTimeOut_ms);
// port->setBlocking(false); // port->setBlocking(false);
} }
...@@ -129,9 +129,9 @@ int ModbusRTUSlave::getNextData( unsigned char* buf, int len ) ...@@ -129,9 +129,9 @@ int ModbusRTUSlave::getNextData( unsigned char* buf, int len )
void ModbusRTUSlave::setChannelTimeout( timeout_t msec ) void ModbusRTUSlave::setChannelTimeout( timeout_t msec )
{ {
if( msec == UniSetTimer::WaitUpTime ) if( msec == UniSetTimer::WaitUpTime )
port->setTimeout(15*60*1000*1000); // используем просто большое время (15 минут). Переведя его в наносекунды. port->setTimeout(15*60*1000); // используем просто большое время (15 минут).
else else
port->setTimeout(msec*1000); port->setTimeout(msec);
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
mbErrCode ModbusRTUSlave::sendData( unsigned char* buf, int len ) mbErrCode ModbusRTUSlave::sendData( unsigned char* buf, int len )
......
...@@ -173,8 +173,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, ...@@ -173,8 +173,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( dlog.debugging(Debug::INFO) ) if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster::query): ret=" << (int)ret dlog[Debug::INFO] << "(ModbusTCPMaster::query): ret=" << (int)ret
<< " < rmh=" << (int)sizeof(rmh) << " < rmh=" << (int)sizeof(rmh)
<< " err: " << tcp->getErrorNumber() << " errnum: " << tcp->getErrorNumber()
<< " perr: " << tcp->getPeer(&port) << " perr: " << tcp->getPeer(&port)
<< " err: " << string(tcp->getErrorString())
<< endl; << endl;
disconnect(); disconnect();
...@@ -313,6 +314,7 @@ void ModbusTCPMaster::reconnect() ...@@ -313,6 +314,7 @@ void ModbusTCPMaster::reconnect()
// TCPStream (const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0) // TCPStream (const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0)
tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500); tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500);
tcp->setTimeout(replyTimeOut_ms); tcp->setTimeout(replyTimeOut_ms);
tcp->setKeepAlive(true);
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
...@@ -364,6 +366,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port ) ...@@ -364,6 +366,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
{ {
tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500); tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500);
tcp->setTimeout(replyTimeOut_ms); tcp->setTimeout(replyTimeOut_ms);
tcp->setKeepAlive(true);
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
......
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