Commit dd3b30d8 authored by Pavel Vainerman's avatar Pavel Vainerman

отладка на стенде

parent 9f8ee6f2
......@@ -23,3 +23,7 @@
( ConsumerInfo ..). uniset-codegen,
SensorInfo ObjectId.
----------
RTUExchabge: vtype="Byte"
smonit: processing "precision"
admin: processing "precision"
\ No newline at end of file
......@@ -61,7 +61,7 @@
<ObjectsMap idfromfile="1" no_dep="0">
<nodes port="2809">
<item id="3000" name="LocalhostNode" alias="" textname=" " ip="127.0.0.1" CANnodeID="" host="localhost" dbserver="DBServer1"/>
<item id="3000" name="LocalhostNode" alias="" textname=" " ip="127.0.0.1" CANnodeID="" host="localhost" dbserver=""/>
</nodes>
<!-- ************************ ********************** -->
......@@ -87,7 +87,7 @@
<item id="465002" name="HC_out" textname="HC_out"
iotype="DO" character="Info"
rs="2" mbtype="rtu" mbaddr="0x02" mbreg="0x3000" mbfunc="0x06">
rs="1" mbtype="rtu" mbaddr="0x02" mbreg="0x3000" mbfunc="0x06">
<consumers>
</consumers>
</item>
......
......@@ -2,7 +2,7 @@
Name: uniset
Version: 0.96
Release: eter23
Release: eter26
Summary: UniSet
License: GPL
Group: Development/C++
......@@ -181,6 +181,9 @@ Libraries needed to develop for uniset extentions
%_bindir/%name-smviewer
%changelog
* Mon Jun 08 2009 Pavel Vainerman <pv@aeu> 0.96-eter25
- new build
* Thu Jun 04 2009 Pavel Vainerman <pv@aeu> 0.96-eter23
- new build
......
......@@ -47,7 +47,7 @@ int main(int argc, char **argv)
}
IOControl* ic = IOControl::init_iocontrol(argc,argv,shmID,0);
IOControl* ic = IOControl::init_iocontrol(argc,argv,shmID);
if( !ic )
{
dlog[Debug::CRIT] << "(iocontrol): init ۣ..." << endl;
......
......@@ -52,6 +52,8 @@ noQueryOptimization(false)
speed = "38400";
recv_timeout = atoi(conf->getArgParam("--rs-recv-timeout",it.getProp("recv_timeout")).c_str());
if( recv_timeout <= 0 )
recv_timeout = 100;
rs_pre_clean = atoi(conf->getArgParam("--rs-pre-clean",it.getProp("pre_clean")).c_str());
noQueryOptimization = atoi(conf->getArgParam("--rs-no-query-optimization",it.getProp("no_query_optimization")).c_str());
......@@ -68,6 +70,7 @@ noQueryOptimization(false)
initPause = 3000;
force = atoi(conf->getArgParam("--rs-force",it.getProp("force")).c_str());
force_out = atoi(conf->getArgParam("--rs-force-out",it.getProp("force_out")).c_str());
if( shm->isLocalwork() )
{
......@@ -347,7 +350,6 @@ bool RTUExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it )
ModbusRTU::ReadInputRetMessage ret = mb->read04(dev->mbaddr,p->mbreg+p->offset,p->q_count);
for( int i=0; i<p->q_count; i++,it++ )
it->second->mbval = ret.data[i];
it--;
}
break;
......@@ -387,7 +389,6 @@ bool RTUExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it )
<< " IGNORE WRITE SINGLE REGISTER q_count=" << p->q_count << " ..." << endl;
return false;
}
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(dev->mbaddr,p->mbreg+p->offset,p->mbval);
}
break;
......@@ -521,8 +522,8 @@ void RTUExchange::processingMessage(UniSetTypes::VoidMessage *msg)
{
TimerMessage tm(msg);
timerInfo(&tm);
break;
}
break;
case Message::SensorInfo:
{
......@@ -558,7 +559,7 @@ void RTUExchange::sysCommand( UniSetTypes::SystemMessage *sm )
{
if( rmap.empty() )
{
dlog[Debug::CRIT] << myname << "(sysCommand): rmap EMPTY! terminated..." << endl;
dlog[Debug::CRIT] << myname << "(sysCommand): ************* rmap EMPTY! terminated... *************" << endl;
raise(SIGTERM);
return;
}
......@@ -591,19 +592,18 @@ void RTUExchange::sysCommand( UniSetTypes::SystemMessage *sm )
askSensors(UniversalIO::UIONotify);
initOutput();
}
askTimer(tmExchange,polltime);
//
if( !force )
{
uniset_mutex_lock l(pollMutex,2000);
uniset_mutex_lock l(pollMutex,2000);
force = true;
poll();
force = false;
}
askTimer(tmExchange,polltime);
break;
}
}
case SystemMessage::FoldUp:
case SystemMessage::Finish:
......@@ -676,55 +676,60 @@ void RTUExchange::askSensors( UniversalIO::UIOCommand cmd )
throw SystemError(err.str());
}
/*
RSMap::iterator it=rsmap.begin();
for( ; it!=rsmap.end(); ++it )
{
if( it->stype != UniversalIO::DigitalOutput && it->stype != UniversalIO::AnalogOutput )
continue;
// if( it->safety == NoSafetyState )
// continue;
if( force_out )
return;
try
{
shm->askSensor(it->si.id,cmd);
}
catch( UniSetTypes::Exception& ex )
for( RTUExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{
RTUDevice* d(it1->second);
for( RTUExchange::RegMap::iterator it=d->regmap.begin(); it!=d->regmap.end(); ++it )
{
dlog[Debug::WARN] << myname << "(askSensors): " << ex << std::endl;
if( it->second->mbfunc != ModbusRTU::fnWriteOutputRegisters &&
it->second->mbfunc != ModbusRTU::fnWriteOutputSingleRegister )
continue;
for( PList::iterator i=it->second->slst.begin(); i!=it->second->slst.end(); ++i )
{
try
{
shm->askSensor(i->si.id,cmd);
}
catch( UniSetTypes::Exception& ex )
{
dlog[Debug::WARN] << myname << "(askSensors): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::WARN] << myname << "(askSensors): catch..." << std::endl;
}
}
}
catch(...){}
}
*/
}
// ------------------------------------------------------------------------------------------
void RTUExchange::sensorInfo( UniSetTypes::SensorMessage* sm )
{
/*
RSMap::iterator it=rsmap.begin();
for( ; it!=rsmap.end(); ++it )
{
if( it->stype != UniversalIO::DigitalOutput && it->stype != UniversalIO::AnalogOutput )
continue;
if( force_out )
return;
if( it->si.id == sm->id )
for( RTUExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{
RTUDevice* d(it1->second);
for( RTUExchange::RegMap::iterator it=d->regmap.begin(); it!=d->regmap.end(); ++it )
{
if( it->stype == UniversalIO::DigitalOutput ) // || it->stype == UniversalIO::DigitalInput )
{
uniset_spin_lock lock(it->val_lock);
it->value = sm->state ? 1 : 0;
}
else if( it->stype == UniversalIO::AnalogOutput ) // || it->stype == UniversalIO::AnalogInput )
if( it->second->mbfunc != ModbusRTU::fnWriteOutputRegisters &&
it->second->mbfunc != ModbusRTU::fnWriteOutputSingleRegister )
continue;
for( PList::iterator i=it->second->slst.begin(); i!=it->second->slst.end(); ++i )
{
uniset_spin_lock lock(it->val_lock);
it->value = sm->value;
// cerr << myname << "(sensorInfo): ************ update si.id=" << sm->id
// << " reg=" << ModbusRTU::dat2str(i->reg->mbreg) << endl;
updateRSProperty( &(*i),true);
return;
}
break;
}
}
*/
}
// ------------------------------------------------------------------------------------------
bool RTUExchange::activateObject()
......@@ -882,9 +887,13 @@ RTUExchange::RegInfo* RTUExchange::addReg( RegMap& mp, ModbusRTU::ModbusData r,
return 0;
}
dlog[Debug::INFO] << myname << "(addReg): reg=" << ModbusRTU::dat2str(r)
<< " already added. Ignore register params for " << xmlit.getProp("name") << " ..." << endl;
if( dlog.debugging(Debug::INFO) )
{
dlog[Debug::INFO] << myname << "(addReg): reg=" << ModbusRTU::dat2str(r)
<< " already added. Ignore register params for " << xmlit.getProp("name") << " ..." << endl;
}
it->second->rit = it;
return it->second;
}
......@@ -907,6 +916,8 @@ RTUExchange::RegInfo* RTUExchange::addReg( RegMap& mp, ModbusRTU::ModbusData r,
}
mp.insert(RegMap::value_type(r,ri));
ri->rit = mp.find(r);
return ri;
}
// ------------------------------------------------------------------------------------------
......@@ -948,6 +959,18 @@ bool RTUExchange::initRSProperty( RSProperty& p, UniXML_iterator& it )
dlog[Debug::WARN] << "(initRSProperty): (ignore) uncorrect param`s nbit>1 (" << p.nbit << ")"
<< " but iotype=" << p.stype << " for " << it.getProp("name") << endl;
}
string sbyte(it.getProp("nbyte"));
if( !sbyte.empty() )
{
p.nbyte = UniSetTypes::uni_atoi(sbyte.c_str());
if( p.nbyte < 0 || p.nbyte > VTypes::Byte::bsize )
{
dlog[Debug::CRIT] << myname << "(initRSProperty): BAD nbyte=" << p.nbyte
<< ". (0 >= nbyte < " << VTypes::Byte::bsize << ")." << endl;
return false;
}
}
string vt(it.getProp("vtype"));
if( vt.empty() )
......@@ -1335,34 +1358,10 @@ std::ostream& operator<<( std::ostream& os, const RTUExchange::DeviceType& dt )
// -----------------------------------------------------------------------------
std::ostream& operator<<( std::ostream& os, const RTUExchange::RSProperty& p )
{
// os << " mbaddr=(" << (int)p.mbaddr << ")" << ModbusRTU::addr2str(p.mbaddr)
// << " mbreg=" << ModbusRTU::dat2str(p.mbreg)
// << " mbfunc=" << p.mbfunc
// << " dtype=" << p.dtype;
/*
switch(p.dtype)
{
case RTUExchange::dtRTU:
os << " nbit=" << p.nbit;
break;
case RTUExchange::dtRTU188:
os << " jack=" << RTUStorage::j2s(p.rtuJack)
<< " chan=" << p.rtuChan;
break;
case RTUExchange::dtMTR:
os << " mtrType=" << MTR::type2str(p.mtrType);
break;
default:
os << "Unknown type parameters ???!!!" << endl;
break;
}
*/
os << " sid=" << p.si.id
<< " stype=" << p.stype
<< " nbit=" << p.nbit
<< " nbyte=" << p.nbyte
<< " rnum=" << p.rnum
<< " safety=" << p.safety
<< " invert=" << p.invert;
......@@ -1550,49 +1549,91 @@ void RTUExchange::updateRTU( RegMap::iterator& rit )
if( r->mbfunc == fnWriteOutputRegisters || r->mbfunc == fnWriteOutputSingleRegister )
save = true;
// if( !force_out_up && save )
// return;
ModbusRTU::DataBits16 b(r->mbval);
for( PList::iterator it=r->slst.begin(); it!=r->slst.end(); ++it )
{
updateRSProperty( &(*it),false );
}
// -----------------------------------------------------------------------------
void RTUExchange::updateRSProperty( RSProperty* p, bool write_only )
{
using namespace ModbusRTU;
RegInfo* r(p->reg->rit->second);
bool save = false;
if( r->mbfunc == fnWriteOutputRegisters || r->mbfunc == fnWriteOutputSingleRegister )
save = true;
else if( write_only )
return;
try
{
if( it->vType == VTypes::vtUnknown )
if( p->vType == VTypes::vtUnknown )
{
if( it->nbit >= 0 )
ModbusRTU::DataBits16 b(r->mbval);
if( p->nbit >= 0 )
{
if( save )
{
bool set = IOBase::processingAsDO( &(*it), shm, force );
b.set(it->nbit,set);
bool set = IOBase::processingAsDO( p, shm, force_out );
b.set(p->nbit,set);
r->mbval = b.mdata();
}
else
{
bool set = b[it->nbit];
IOBase::processingAsDI( &(*it), set, shm, force );
bool set = b[p->nbit];
IOBase::processingAsDI( p, set, shm, force );
}
continue;
return;
}
if( it->rnum <= 1 )
if( p->rnum <= 1 )
{
if( save )
r->mbval = IOBase::processingAsAO( &(*it), shm, force );
r->mbval = IOBase::processingAsAO( p, shm, force_out );
else
IOBase::processingAsAI( &(*it), r->mbval, shm, force );
IOBase::processingAsAI( p, r->mbval, shm, force );
continue;
return;
}
dlog[Debug::CRIT] << myname << "(updateRTU): IGNORE item: rnum=" << it->rnum
<< " > 1 ?!! for id=" << it->si.id << endl;
continue;
dlog[Debug::CRIT] << myname << "(updateRSProperty): IGNORE item: rnum=" << p->rnum
<< " > 1 ?!! for id=" << p->si.id << endl;
return;
}
else if( it->vType == VTypes::vtF2 )
else if( p->vType == VTypes::vtByte )
{
RegMap::iterator i(rit);
if( p->nbyte <= 0 || p->nbyte > VTypes::Byte::bsize )
{
dlog[Debug::CRIT] << myname << "(updateRSProperty): IGNORE item: reg=" << ModbusRTU::dat2str(r->mbreg)
<< " vtype=" << p->vType << " but nbyte=" << p->nbyte << endl;
return;
}
if( save )
{
float f = IOBase::processingFasAO( &(*it), shm, force );
long v = IOBase::processingAsAO( p, shm, force_out );
VTypes::Byte b(r->mbval);
b.raw.b[p->nbyte-1] = v;
r->mbval = b.raw.w;
}
else
{
VTypes::Byte b(r->mbval);
IOBase::processingAsAI( p, b.raw.b[p->nbyte-1], shm, force );
}
return;
}
else if( p->vType == VTypes::vtF2 )
{
RegMap::iterator i(p->reg->rit);
if( save )
{
float f = IOBase::processingFasAO( p, shm, force_out );
VTypes::F2 f2(f);
for( int k=0; k<VTypes::F2::wsize(); k++, i++ )
i->second->mbval = f2.raw.v[k];
......@@ -1606,15 +1647,15 @@ void RTUExchange::updateRTU( RegMap::iterator& rit )
VTypes::F2 f(data,VTypes::F2::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)f, shm, force );
IOBase::processingFasAI( p, (float)f, shm, force );
}
}
else if( it->vType == VTypes::vtF4 )
else if( p->vType == VTypes::vtF4 )
{
RegMap::iterator i(rit);
RegMap::iterator i(p->reg->rit);
if( save )
{
float f = IOBase::processingFasAO( &(*it), shm, force );
float f = IOBase::processingFasAO( p, shm, force_out );
VTypes::F4 f4(f);
for( int k=0; k<VTypes::F4::wsize(); k++, i++ )
i->second->mbval = f4.raw.v[k];
......@@ -1628,38 +1669,38 @@ void RTUExchange::updateRTU( RegMap::iterator& rit )
VTypes::F4 f(data,VTypes::F4::wsize());
delete[] data;
IOBase::processingFasAI( &(*it), (float)f, shm, force );
IOBase::processingFasAI( p, (float)f, shm, force );
}
}
}
catch(IOController_i::NameNotFound &ex)
{
dlog[Debug::LEVEL3] << myname << "(updateRTU):(NameNotFound) " << ex.err << endl;
dlog[Debug::LEVEL3] << myname << "(updateRSProperty):(NameNotFound) " << ex.err << endl;
}
catch(IOController_i::IOBadParam& ex )
{
dlog[Debug::LEVEL3] << myname << "(updateRTU):(IOBadParam) " << ex.err << endl;
dlog[Debug::LEVEL3] << myname << "(updateRSProperty):(IOBadParam) " << ex.err << endl;
}
catch(IONotifyController_i::BadRange )
{
dlog[Debug::LEVEL3] << myname << "(updateRTU): (BadRange)..." << endl;
dlog[Debug::LEVEL3] << myname << "(updateRSProperty): (BadRange)..." << endl;
}
catch( Exception& ex )
{
dlog[Debug::LEVEL3] << myname << "(updateRTU): " << ex << endl;
dlog[Debug::LEVEL3] << myname << "(updateRSProperty): " << ex << endl;
}
catch(CORBA::SystemException& ex)
{
dlog[Debug::LEVEL3] << myname << "(updateRTU): CORBA::SystemException: "
dlog[Debug::LEVEL3] << myname << "(updateRSProperty): CORBA::SystemException: "
<< ex.NP_minorString() << endl;
}
catch(...)
{
dlog[Debug::LEVEL3] << myname << "(updateRTU): catch ..." << endl;
dlog[Debug::LEVEL3] << myname << "(updateRSProperty): catch ..." << endl;
}
}
}
// -----------------------------------------------------------------------------
void RTUExchange::updateMTR( RegMap::iterator& rit )
{
RegInfo* r(rit->second);
......@@ -1676,7 +1717,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
if( r->mtrType == MTR::mtT1 )
{
if( save )
r->mbval = IOBase::processingAsAO( &(*it), shm, force );
r->mbval = IOBase::processingAsAO( &(*it), shm, force_out );
else
{
MTR::T1 t(r->mbval);
......@@ -1689,7 +1730,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
{
if( save )
{
MTR::T2 t(IOBase::processingAsAO( &(*it), shm, force ));
MTR::T2 t(IOBase::processingAsAO( &(*it), shm, force_out ));
r->mbval = t.val;
}
else
......@@ -1705,7 +1746,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
RegMap::iterator i(rit);
if( save )
{
MTR::T3 t(IOBase::processingAsAO( &(*it), shm, force ));
MTR::T3 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T3::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
......@@ -1739,7 +1780,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
RegMap::iterator i(rit);
if( save )
{
MTR::T5 t(IOBase::processingAsAO( &(*it), shm, force ));
MTR::T5 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T5::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
......@@ -1762,7 +1803,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
RegMap::iterator i(rit);
if( save )
{
MTR::T6 t(IOBase::processingAsAO( &(*it), shm, force ));
MTR::T6 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T6::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
......@@ -1785,7 +1826,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
RegMap::iterator i(rit);
if( save )
{
MTR::T7 t(IOBase::processingAsAO( &(*it), shm, force ));
MTR::T7 t(IOBase::processingAsAO( &(*it), shm, force_out ));
for( int k=0; k<MTR::T7::wsize(); k++, i++ )
i->second->mbval = t.raw.v[k];
}
......@@ -1808,7 +1849,7 @@ void RTUExchange::updateMTR( RegMap::iterator& rit )
RegMap::iterator i(rit);
if( save )
{
float f = IOBase::processingFasAO( &(*it), shm, force );
float f = IOBase::processingFasAO( &(*it), shm, force_out );
MTR::F1 f1(f);
for( int k=0; k<MTR::F1::wsize(); k++, i++ )
i->second->mbval = f1.raw.v[k];
......
......@@ -60,14 +60,15 @@ class RTUExchange:
public IOBase
{
// only for RTU
short nbit; /*!< bit number (for func=[0x01,0x02]) */
short nbit; /*!< bit number) */
VTypes::VType vType; /*!< type of value */
short rnum; /*!< count of registers */
short nbyte; /*!< byte number (1-2) */
RSProperty():
nbit(-1),vType(VTypes::vtUnknown),
rnum(VTypes::wsize(VTypes::vtUnknown)),
reg(0)
nbyte(0),reg(0)
{}
RegInfo* reg;
......@@ -76,7 +77,8 @@ class RTUExchange:
friend std::ostream& operator<<( std::ostream& os, const RSProperty& p );
typedef std::list<RSProperty> PList;
typedef std::map<ModbusRTU::ModbusData,RegInfo*> RegMap;
struct RegInfo
{
RegInfo():
......@@ -106,11 +108,13 @@ class RTUExchange:
// optimization
int q_num; /*! number in query */
int q_count; /*! count registers for query */
RegMap::iterator rit;
};
friend std::ostream& operator<<( std::ostream& os, RegInfo& r );
typedef std::map<ModbusRTU::ModbusData,RegInfo*> RegMap;
struct RTUDevice
{
......@@ -177,6 +181,7 @@ class RTUExchange:
void updateRTU(RegMap::iterator& it);
void updateMTR(RegMap::iterator& it);
void updateRTU188(RegMap::iterator& it);
void updateRSProperty( RSProperty* p, bool write_only=false );
virtual void processingMessage( UniSetTypes::VoidMessage *msg );
void sysCommand( UniSetTypes::SystemMessage *msg );
......
#!/bin/sh
uniset-start.sh -f ./uniset-rtuexchange --confile test.xml \
--rs-dev /dev/cbsideA0 \
--rs-dev /dev/ttyS0 \
--rs-name RSExchange \
--rs-speed 38400 \
--rs-filter-field rs \
--rs-filter-value 2 \
--dlog-add-levels info,crit,warn,level1
--rs-filter-value 3 \
--dlog-add-levels info,crit,warn \
--rs-force 0 \
--rs-force-out 0 \
#,level3
# --rs-force 1 \
......@@ -3,6 +3,6 @@
ulimit -Sc 1000000000000
uniset-start.sh -f ./uniset-smemory --smemory-id SharedMemory1 \
--confile test.xml \
--confile test.xml --datfile /etc/AEU/configure.xml \
--unideb-add-levels info,crit,warn,level9,system
......@@ -33,7 +33,9 @@ static const int NoSafety = -1;
invert(false),
jar_state(false),
ondelay_state(false),
offdelay_state(false)
offdelay_state(false),
t_ai(UniSetTypes::DefaultObjectId),
initOK(false)
{}
......@@ -75,6 +77,14 @@ static const int NoSafety = -1;
bool ondelay_state; /*!< */
bool offdelay_state; /*!< */
//
UniSetTypes::ObjectId t_ai; /*!< ,
,
*/
IONotifyController_i::ThresholdInfo ti;
IOController::AIOStateList::iterator ait;
IOController::DIOStateList::iterator dit;
UniSetTypes::uniset_spin_mutex val_lock; /*!< */
......@@ -87,6 +97,7 @@ static const int NoSafety = -1;
static long processingAsAO( IOBase* it, SMInterface* shm, bool force );
static float processingFasAO( IOBase* it, SMInterface* shm, bool force );
static bool processingAsDO( IOBase* it, SMInterface* shm, bool force );
static void processingThreshold( IOBase* it, SMInterface* shm, bool force );
static bool initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
DebugStream* dlog=0, std::string myname="",
int def_filtersize=0, float def_filterT=0.0 );
......
......@@ -16,7 +16,8 @@ namespace VTypes
{
vtUnknown,
vtF2,
vtF4
vtF4,
vtByte
};
std::ostream& operator<<( std::ostream& os, const VType& vt );
......@@ -97,6 +98,48 @@ namespace VTypes
F4mem raw;
};
// --------------------------------------------------------------------------
class Byte
{
public:
static const int bsize = 2;
// ------------------------------------------
/*! */
typedef union
{
unsigned short w;
unsigned char b[bsize];
} Bytemem;
// ------------------------------------------
// ...
Byte(){ raw.w = 0; }
Byte( unsigned char b1, unsigned char b2 ){ raw.b[0]=b1; raw.b[1]=b2; }
Byte( const long val )
{
raw.w = val;
}
Byte( const ModbusRTU::ModbusData dat )
{
raw.w = dat;
}
~Byte(){}
// ------------------------------------------
/*! */
static int wsize(){ return 1; }
/*! */
static VType type(){ return vtByte; }
// ------------------------------------------
operator long(){ return lroundf(raw.w); }
unsigned char operator[]( const int i ){ return raw.b[i]; }
Bytemem raw;
};
// --------------------------------------------------------------------------
} // end of namespace VTypes
// --------------------------------------------------------------------------
......
......@@ -105,17 +105,18 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
return;
}
// ...
if( !it->nofilter )
{
if( it->df.size() > 1 )
it->df.add(val);
val = it->df.filterRC(val);
}
if( it->cdiagram ) //
{
// ,
// ,
if( !it->nofilter && it->df.size() > 1 )
{
if( it->f_median )
val = it->df.median(val);
else
val = it->df.filterRC(val);
}
if( it->craw != val )
{
it->craw = val;
......@@ -130,6 +131,16 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw!=0 && cal->maxRaw!=cal->minRaw ) //
val = UniSetTypes::lcalibrate(val,cal->minRaw,cal->maxRaw,cal->minCal,cal->maxCal,true);
// ,
// ,
if( !it->nofilter && it->df.size() > 1 )
{
if( it->f_median )
val = it->df.median(val);
else
val = it->df.filterRC(val);
}
}
// "",
......@@ -185,7 +196,7 @@ void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool for
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw!=0 && cal->maxRaw!=cal->minRaw ) //
val = UniSetTypes::fcalibrate(val,cal->minRaw,cal->maxRaw,cal->minCal,cal->maxCal,true);
val = UniSetTypes::lcalibrate(val,cal->minRaw,cal->maxRaw,cal->minCal,cal->maxCal,true);
// "",
//
......@@ -246,12 +257,15 @@ void IOBase::processingAsDI( IOBase* it, bool set, SMInterface* shm, bool force
long IOBase::processingAsAO( IOBase* it, SMInterface* shm, bool force )
{
uniset_spin_lock lock(it->val_lock);
long val = it->value;
if( force )
{
val = shm->localGetValue(it->ait,it->si.id);
if( it->stype == UniversalIO::DigitalInput || it->stype == UniversalIO::DigitalOutput )
val = shm->localGetState(it->dit,it->si.id) ? 1 : 0;
else if( it->stype == UniversalIO::AnalogInput || it->stype == UniversalIO::AnalogOutput )
val = shm->localGetValue(it->ait,it->si.id);
it->value = val;
}
......@@ -272,7 +286,7 @@ long IOBase::processingAsAO( IOBase* it, SMInterface* shm, bool force )
else
{
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw!=0 && cal->maxRaw!=cal->minRaw ) //
if( cal && cal->maxRaw!=0 && cal->maxRaw!=cal->minRaw ) //
{
// !!!
val = UniSetTypes::lcalibrate(it->value,
......@@ -291,19 +305,19 @@ long IOBase::processingAsAO( IOBase* it, SMInterface* shm, bool force )
// -----------------------------------------------------------------------------
bool IOBase::processingAsDO( IOBase* it, SMInterface* shm, bool force )
{
uniset_spin_lock lock(it->val_lock);
bool set = it->value;
if( it->stype == UniversalIO::DigitalOutput ||
it->stype == UniversalIO::DigitalInput )
{
uniset_spin_lock lock(it->val_lock);
bool set = it->value;
if( force )
set = shm->localGetState(it->dit,it->si.id);
{
if( it->stype == UniversalIO::DigitalInput || it->stype == UniversalIO::DigitalOutput )
set = shm->localGetState(it->dit,it->si.id);
else if( it->stype == UniversalIO::AnalogInput || it->stype == UniversalIO::AnalogOutput )
set = shm->localGetValue(it->ait,it->si.id) ? true : false;
}
set = it->invert ? !set : set;
return set;
}
return false;
}
// -----------------------------------------------------------------------------
float IOBase::processingFasAO( IOBase* it, SMInterface* shm, bool force )
......@@ -351,6 +365,33 @@ float IOBase::processingFasAO( IOBase* it, SMInterface* shm, bool force )
return val;
}
// -----------------------------------------------------------------------------
void IOBase::processingThreshold( IOBase* it, SMInterface* shm, bool force )
{
if( it->t_ai == DefaultObjectId )
return;
if( !it->initOK )
{
shm->initAIterator(it->ait);
shm->initDIterator(it->dit);
it->initOK = true;
}
long val = shm->localGetValue(it->ait,it->t_ai);
bool set = it->value ? true : false;
cout << "val=" << val << " set=" << set << endl;
//
// lowLimit-
if( val <= (it->ti.lowlimit-it->ti.sensibility) )
set = false;
else if( val >= (it->ti.hilimit+it->ti.sensibility) )
set = true;
cout << "thresh: set=" << set << endl;
processingDI(it,set,shm,force);
}
// -----------------------------------------------------------------------------
bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
DebugStream* dlog, std::string myname,
......@@ -456,9 +497,6 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
}
}
for( int i=0; i<f_size; i++ )
b->df.add( b->defval );
if( !it.getProp("filterT").empty() )
{
f_T = atof(it.getProp("filterT").c_str());
......@@ -469,10 +507,36 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
if( b->stype == UniversalIO::AnalogInput )
b->df.setSettings( f_size, f_T );
b->df.init(b->defval);
std::string caldiagram( it.getProp("caldiagram") );
if( !caldiagram.empty() )
b->cdiagram = UniSetExtentions::buildCalibrationDiagram(caldiagram);
}
else if( b->stype == UniversalIO::DigitalInput || b->stype == UniversalIO::DigitalOutput )
{
string tai(it.getProp("threshold_aid"));
if( !tai.empty() )
{
b->t_ai = conf->getSensorID(tai);
if( b->t_ai == DefaultObjectId )
{
if( dlog )
dlog[Debug::CRIT] << myname << "(IOBase::readItem): unknown ID for threshold_ai "
<< tai << endl;
return false;
}
b->ti.lowlimit = uni_atoi( it.getProp("lowlimit").c_str() );
b->ti.hilimit = uni_atoi( it.getProp("hilimit").c_str() );
b->ti.sensibility = uni_atoi( it.getProp("sensibility").c_str() );
}
}
// else
// {
// dlog[Debug::CRIT] << myname << "(IOBase::readItem): iotype=: " << stype << " " << sname << endl;
// return false;
// }
return true;
}
......
......@@ -16,6 +16,9 @@ std::ostream& operator<<( std::ostream& os, const VType& vt )
VType str2type( const std::string s )
{
if( s == "Byte" )
return vtByte;
if( s == "F2" )
return vtF2;
if( s == "F4" )
......@@ -26,6 +29,8 @@ VType str2type( const std::string s )
// -------------------------------------------------------------------------
string type2str( VType t )
{
if( t == vtByte )
return "Byte";
if( t == vtF2 )
return "F2";
if( t == vtF4 )
......@@ -36,6 +41,8 @@ string type2str( VType t )
// -------------------------------------------------------------------------
int wsize( VType t )
{
if( t == vtByte )
return Byte::wsize();
if( t == vtF2 )
return F2::wsize();
if( t == vtF4 )
......
......@@ -207,11 +207,16 @@ DebugStream::~DebugStream()
//--------------------------------------------------------------------------
const DebugStream& DebugStream::operator=( const DebugStream& r )
{
if( r == *this )
return *this;
dt = r.dt;
show_datetime = r.show_datetime;
fname = r.fname;
if( !r.fname.empty() )
logFile(fname.c_str());
return *this;
}
//--------------------------------------------------------------------------
/// Sets the debugstreams' logfile to f.
......
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