Commit 2b0f1aaa authored by Pavel Vainerman's avatar Pavel Vainerman

(IOBase): немного переделал инициализацию свойств в Modbus[Slave,Master].

Добавил в ModbusSlave параметр rawdata="1" (длс игнорирования свойств калибровки).
parent a2b5974b
...@@ -1909,7 +1909,7 @@ MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty& p ) ...@@ -1909,7 +1909,7 @@ MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty& p )
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it ) bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it )
{ {
if( !IOBase::initItem(&p,it,shm,prefix,false,&dlog,myname) ) if( !IOBase::initItem(&p,it,shm,prop_prefix,false,&dlog,myname) )
return false; return false;
// проверяем не пороговый ли это датчик (т.е. не связанный с обменом) // проверяем не пороговый ли это датчик (т.е. не связанный с обменом)
...@@ -1931,19 +1931,6 @@ bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it ) ...@@ -1931,19 +1931,6 @@ bool MBExchange::initRSProperty( RSProperty& p, UniXML_iterator& it )
p.cdiagram = 0; p.cdiagram = 0;
} }
string stype( it.getProp(prop_prefix + "iotype") );
if( !stype.empty() )
{
p.stype = UniSetTypes::getIOType(stype);
if( p.stype == UniversalIO::UnknownIOType )
{
if( dlog )
dlog[Debug::CRIT] << myname << "(IOBase::readItem): неизвестный iotype=: "
<< stype << " for " << it.getProp("name") << endl;
return false;
}
}
string sbit(it.getProp(prop_prefix + "nbit")); string sbit(it.getProp(prop_prefix + "nbit"));
if( !sbit.empty() ) if( !sbit.empty() )
{ {
......
...@@ -817,43 +817,44 @@ bool MBSlave::readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec ) ...@@ -817,43 +817,44 @@ bool MBSlave::readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec )
bool MBSlave::initItem( UniXML_iterator& it ) bool MBSlave::initItem( UniXML_iterator& it )
{ {
IOProperty p; IOProperty p;
string prop_prefix(prefix + "_");
if( !IOBase::initItem( static_cast<IOBase*>(&p),it,shm,prefix,false,&dlog,myname) ) if( !IOBase::initItem( static_cast<IOBase*>(&p),it,shm,prop_prefix,false,&dlog,myname) )
return false; return false;
if( it.getIntProp(prop_prefix + "rawdata") )
{
p.cal.minRaw = 0;
p.cal.maxRaw = 0;
p.cal.minCal = 0;
p.cal.maxCal = 0;
p.cal.precision = 0;
p.cdiagram = 0;
}
if( mbregFromID ) if( mbregFromID )
p.mbreg = p.si.id; p.mbreg = p.si.id;
else else
{ {
string r = it.getProp("mbreg"); string r = IOBase::initProp(it,"mbreg",prop_prefix,false);
if( r.empty() ) if( r.empty() )
{ {
dlog[Debug::CRIT] << myname << "(initItem): Unknown 'mbreg' for " << it.getProp("name") << endl; dlog[Debug::CRIT] << myname << "(initItem): Unknown 'mbreg' for " << IOBase::initProp(it,"name",prop_prefix,false) << endl;
return false; return false;
} }
p.mbreg = ModbusRTU::str2mbData(r); p.mbreg = ModbusRTU::str2mbData(r);
} }
string stype( it.getProp("mb_iotype") );
if( stype.empty() )
stype = it.getProp("iotype");
p.stype = UniSetTypes::getIOType(stype);
if( p.stype == UniversalIO::UnknownIOType )
{
dlog[Debug::CRIT] << myname << "(initItem): Unknown 'iotype' or 'mb_iotype' for " << it.getProp("name") << endl;
return false;
}
p.amode = MBSlave::amRW; p.amode = MBSlave::amRW;
string am(it.getProp("mb_accessmode")); string am(IOBase::initProp(it,"mb_accessmode",prop_prefix,false));
if( am == "ro" ) if( am == "ro" )
p.amode = MBSlave::amRO; p.amode = MBSlave::amRO;
else if( am == "rw" ) else if( am == "rw" )
p.amode = MBSlave::amRW; p.amode = MBSlave::amRW;
string vt(it.getProp("mb_vtype")); string vt(IOBase::initProp(it,"mb_vtype",prop_prefix,false));
if( vt.empty() ) if( vt.empty() )
{ {
p.vtype = VTypes::vtUnknown; p.vtype = VTypes::vtUnknown;
...@@ -869,7 +870,7 @@ bool MBSlave::initItem( UniXML_iterator& it ) ...@@ -869,7 +870,7 @@ bool MBSlave::initItem( UniXML_iterator& it )
if( v == VTypes::vtUnknown ) if( v == VTypes::vtUnknown )
{ {
dlog[Debug::CRIT] << myname << "(initItem): Unknown rtuVType=" << vt << " for " dlog[Debug::CRIT] << myname << "(initItem): Unknown rtuVType=" << vt << " for "
<< it.getProp("name") << IOBase::initProp(it,"name",prop_prefix,false)
<< endl; << endl;
return false; return false;
......
...@@ -127,6 +127,11 @@ static const int NoSafety = -1; ...@@ -127,6 +127,11 @@ static const int NoSafety = -1;
float def_lsparam=0.2, float def_iir_coeff_prev=0.5, float def_lsparam=0.2, float def_iir_coeff_prev=0.5,
float def_iir_coeff_new=0.5 ); float def_iir_coeff_new=0.5 );
// helpers
static std::string initProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval="" );
static int initIntProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval=0 );
}; };
......
...@@ -431,7 +431,7 @@ void IOBase::processingThreshold( IOBase* it, SMInterface* shm, bool force ) ...@@ -431,7 +431,7 @@ void IOBase::processingThreshold( IOBase* it, SMInterface* shm, bool force )
processingAsDI(it,set,shm,force); processingAsDI(it,set,shm,force);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static std::string initProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval="" ) std::string IOBase::initProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const std::string& defval )
{ {
if( !it.getProp(prefix+prop).empty() ) if( !it.getProp(prefix+prop).empty() )
return it.getProp(prefix+prop); return it.getProp(prefix+prop);
...@@ -445,7 +445,7 @@ static std::string initProp( UniXML_iterator& it, const std::string& prop, const ...@@ -445,7 +445,7 @@ static std::string initProp( UniXML_iterator& it, const std::string& prop, const
return defval; return defval;
} }
static int initIntProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval=0 ) int IOBase::initIntProp( UniXML_iterator& it, const std::string& prop, const std::string& prefix, bool prefonly, const int defval )
{ {
string pp(prefix+prop); string pp(prefix+prop);
......
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