Commit 1b6f351e authored by Pavel Vainerman's avatar Pavel Vainerman

Merge commit 'origin/newRTUExchange' into eterbook

Conflicts: extentions/SharedMemory/SharedMemory.cc
parents f7b192be 9263e5a0
......@@ -98,6 +98,7 @@
*/
enum IOTypes
{
UnknownIOType,
DigitalInput,
DigitalOutput,
AnalogInput,
......
......@@ -18,6 +18,11 @@
<DumpStateTime name="10"/><!-- [] -->
<SleepTickMS name="500"/><!-- [] -->
<ServicesSection name="Services"/>
<NameService host="localhost" port="2809"/>
<SizeOfMessageQueue name="2000"/>
<LocalIOR name="0"/>
<!-- Debug, logs -->
<UniSetDebug name="unideb" levels="crit,warn" file=""/>
......@@ -83,6 +88,8 @@
<HeartBeatTime time_msec="5000"/>
<IOControl name="IOControl" />
<ObjectsMap idfromfile="0">
<!--
'sensors'
......@@ -100,11 +107,38 @@
<!-- ************************ ********************** -->
<sensors name="Sensors">
<item name="Input1_S" textname=" 1" node="" iotype="DI" priority="Medium" default="1" />
<item name="Input2_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x02" rs="2" />
<item name="Input2_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x02" rs="1" />
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium" mbtcp="1" mbaddr="0x02" mbfunc="0x04" mbreg="0x02"/>
<item name="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x04" mbreg="0x02" rs="2" />
<item name="Input5_S" textname=" 5" node="" iotype="DI" priority="Medium" udp="2"/>
<item name="Input6_S" textname=" 6" node="" iotype="DI" priority="Medium" udp="2">
<item name="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x04" mbreg="0x05" rs="1" />
<item name="RS_Test1_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x02" nbit="1" rs="1" />
<item name="RS_Test2_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x02" nbit="2" rs="1" />
<item name="RS_Test3_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x02" nbit="3" rs="1" />
<item name="RS_Test4_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x02" nbit="4" rs="1" />
<item name="RS_Test5_S" textname=" 5" node="" iotype="DI" priority="Medium" mbtype="rtu188" mbaddr="0x03" jack="J1" channel="23" rs="1" />
<item name="RS_Test6_S" textname=" 5" node="" iotype="DI" priority="Medium" mbtype="rtu188" mbaddr="0x03" jack="J1" channel="23" rs="1" />
<item name="RS_Test7_S" textname=" 5" node="" iotype="DI" priority="Medium" mbtype="rtu188" mbaddr="0x04" jack="J1" channel="23" rs="1" />
<item name="RS_Test8_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x05" rs="1" />
<item name="RS_Test9_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x06" rs="1" />
<item name="RS_Test10_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x07" rs="1" />
<item name="RS_Test11_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" vtype="F2" mbaddr="0x01" mbfunc="0x03" mbreg="0x08" rs="1" />
<item name="RS_Test12_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0xA" rs="1" />
<item name="RS_Test13_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0xB" rs="1" />
<item name="RS_Test14_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0xC" rs="1" />
<item name="RS_Test15_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0xD" rs="1" />
<item name="RS_Test16_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="mtr" mtrtype="F1" mbaddr="0x05" mbfunc="0x03" mbreg="0x10" rs="1" />
<item name="RS_Test17_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x03" mbreg="0x10" rs="1" />
<item name="IO_Test1_S" textname="io test" node="" iotype="DO" priority="Medium" io="1"/>
<item name="IO_Test2_S" textname="io test" node="" iotype="DI" priority="Medium" io="1"/>
<item name="IO_Test3_S" textname="io test" node="" iotype="AO" priority="Medium" io="1"/>
<item name="IO_Test4_S" textname="io test" node="" iotype="AI" priority="Medium" io="1"/>
<item name="W_Test2_S" textname="io test" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x03" mbreg="0x3001" rs="wago" />
<item name="W_Test3_S" textname="io test" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x03" mbreg="0x3002" rs="wago" />
<item name="W_Test4_S" textname="io test" node="" iotype="AI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x06" mbreg="0x3008" rs="wago" default="4"/>
<item name="Input6_S" textname=" 6" node="" iotype="DI" priority="Medium">
<depends>
<depend name="Input4_S"/>
</depends>
......
......@@ -2,7 +2,11 @@
Name: uniset
Version: 0.96
<<<<<<< HEAD:conf/uniset.spec
Release: eter6
=======
Release: eter9
>>>>>>> 6eb79ccca4b348cddaa393aae9cb34b9fcf2a001:conf/uniset.spec
Summary: UniSet
License: GPL
Group: Development/C++
......@@ -180,10 +184,14 @@ Libraries needed to develop for uniset extentions
%_bindir/%name-smviewer
%changelog
<<<<<<< HEAD:conf/uniset.spec
* Wed May 20 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter5
=======
* Tue Apr 21 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter6
- new build
* Tue Apr 21 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter5
>>>>>>> 6eb79ccca4b348cddaa393aae9cb34b9fcf2a001:conf/uniset.spec
- new build
* Mon Apr 06 2009 Pavel Vainerman <pv@altlinux.ru> 0.96-eter4
......
......@@ -56,7 +56,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
UniXML_iterator it(cnode);
noCards = true;
for( unsigned int i=0; i<cards.size(); i++ )
for( unsigned int i=0; i=<cards.size(); i++ )
{
stringstream s1;
s1 << "--iodev" << i;
......
......@@ -68,9 +68,9 @@ class IOControl:
{}
short subdev; /*!< (UNIO) (. comedi_test /) */
short channel; /*!< (UNIO) [0...23] */
short ncard; /*!< [1|2]. 0 - */
int subdev; /*!< (UNIO) (. comedi_test /) */
int channel; /*!< (UNIO) [0...23] */
int ncard; /*!< [1|2]. 0 - */
/*!
0 - analog ref = analog ground
......
#!/bin/sh
ln -s -f /usr/bin/uniset-stop.sh stop.sh
ln -s -f ../../conf/test.xml test.xml
......@@ -30,7 +30,7 @@ int main(int argc, char **argv)
string logfilename = conf->getArgParam("--io-logfile","iocontrol.log");
string logname( conf->getLogDir() + logfilename );
dlog.logFile( logname.c_str() );
unideb.logFile( logname.c_str() );
unideb.logFile( logname.c_str() );
ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id");
......
#!/bin/sh
#ulimit -Sc 1000000000000
uniset-start.sh -f ./uniset-iocontrol --smemory-id SharedMemory \
--confile test.xml \
--io-name IOControl \
--io-polltime 100 \
--io-s-filter-field io \
--io-s-filter-value 1 \
--iodev1 /dev/null \
--iodev2 /dev/null \
--io-test-lamp RS_Test9_S \
--io-heartbeat-id AI_AS \
--io-sm-ready-test-sid RS_Test9_S \
--unideb-add-levels info,crit,warn,level9,system \
......@@ -76,7 +76,7 @@ class Element
ChildInfo():el(0),num(0){}
Element* el;
int num;
int num;
};
typedef std::list<ChildInfo> OutputList;
......
......@@ -50,49 +50,116 @@ class RTUExchange:
dtMTR /*!< MTR (DEIF) */
};
static DeviceType getDeviceType( const std::string dtype );
friend std::ostream& operator<<( std::ostream& os, const DeviceType& dt );
// -------------------------------------------------------------------------------
struct RTUDevice;
struct RegInfo;
struct RSProperty:
public IOBase
{
DeviceType devtype; /*!< */
ModbusRTU::ModbusAddr mbaddr; /*!< */
ModbusRTU::ModbusData mbreg; /*!< */
ModbusRTU::SlaveFunctionCode mbfunc; /*!< / */
// only for RTU
short nbit; /*!< bit number (for func=[0x01,0x02]) */
VTypes::VType vType; /*!< type of value */
short rnum; /*!< count of registers */
RSProperty():
nbit(-1),vType(VTypes::vtUnknown),
rnum(VTypes::wsize(VTypes::vtUnknown)),
reg(0)
{}
RegInfo* reg;
};
friend std::ostream& operator<<( std::ostream& os, const RSProperty& p );
typedef std::list<RSProperty> PList;
struct RegInfo
{
RegInfo():
mbval(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown),
mtrType(MTR::mtUnknown),
rtuJack(RTUStorage::nUnknown),rtuChan(0),
dev(0),
q_num(0),q_count(1)
{}
ModbusRTU::ModbusData mbval;
ModbusRTU::ModbusData mbreg; /*!< */
ModbusRTU::SlaveFunctionCode mbfunc; /*!< / */
PList slst;
// only for MTR
MTR::MTRType mtrType; /*!< ( MTR) */
// only for RTU188
RTUStorage* rtu;
RTUStorage::RTUJack rtuJack;
int rtuChan;
RTUDevice* dev;
RSProperty():
devtype(dtUnknown),
mbaddr(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown),
nbit(-1),vType(VTypes::vtUnknown),
rnum(VTypes::wsize(VTypes::vtUnknown)),
rtu(0),rtuJack(RTUStorage::nUnknown),rtuChan(0)
// optimization
int q_num; /*! number in query */
int q_count; /*! count registers for query */
};
friend std::ostream& operator<<( std::ostream& os, RegInfo& r );
typedef std::map<ModbusRTU::ModbusData,RegInfo*> RegMap;
struct RTUDevice
{
RTUDevice():
respnond(false),
mbaddr(0),
dtype(dtUnknown),
resp_id(UniSetTypes::DefaultObjectId),
resp_state(false),
resp_invert(false),
resp_real(false),
rtu(0)
{}
bool respnond;
ModbusRTU::ModbusAddr mbaddr; /*!< */
RegMap regmap;
DeviceType dtype; /*!< */
UniSetTypes::ObjectId resp_id;
IOController::DIOStateList::iterator resp_dit;
PassiveTimer resp_ptTimeout;
Trigger resp_trTimeout;
bool resp_state;
bool resp_invert;
bool resp_real;
RTUStorage* rtu;
// return TRUE if state changed
bool checkRespond();
friend std::ostream& operator<<( std::ostream& os, RSProperty& p );
};
protected:
friend std::ostream& operator<<( std::ostream& os, RTUDevice& d );
typedef std::map<ModbusRTU::ModbusAddr,RTUDevice*> RTUDeviceMap;
typedef std::vector<RSProperty> RSMap;
RSMap rsmap; /*!< / */
unsigned int maxItem; /*!< ( ) */
friend std::ostream& operator<<( std::ostream& os, RTUDeviceMap& d );
void printMap(RTUDeviceMap& d);
// ----------------------------------
protected:
RTUDeviceMap rmap;
ModbusRTUMaster* mb;
UniSetTypes::uniset_mutex mbMutex;
std::string devname;
std::string speed;
int recv_timeout;
xmlNode* cnode;
std::string s_field;
......@@ -102,10 +169,12 @@ class RTUExchange:
void step();
void poll();
long pollRTU188( RSMap::iterator& p );
long pollMTR( RSMap::iterator& p );
long pollRTU( RSMap::iterator& p );
void setRespond(ModbusRTU::ModbusAddr addr, bool respond );
void pollRTU( RTUDevice* dev, RegMap::iterator& it );
void updateSM();
void updateRTU(RegMap::iterator& it);
void updateMTR(RegMap::iterator& it);
void updateRTU188(RegMap::iterator& it);
virtual void processingMessage( UniSetTypes::VoidMessage *msg );
void sysCommand( UniSetTypes::SystemMessage *msg );
......@@ -119,30 +188,30 @@ class RTUExchange:
//
virtual void sigterm( int signo );
void initMB();
void initIterators();
bool initItem( UniXML_iterator& it );
bool readItem( UniXML& xml, UniXML_iterator& it, xmlNode* sec );
bool initCommParam( UniXML_iterator& it, RSProperty& p );
bool initMTRitem( UniXML_iterator& it, RSProperty& p );
bool initRTU188item( UniXML_iterator& it, RSProperty& p );
bool initRTUitem( UniXML_iterator& it, RSProperty& p );
RTUDevice* addDev( RTUDeviceMap& dmap, ModbusRTU::ModbusAddr a, UniXML_iterator& it );
RegInfo* addReg( RegMap& rmap, ModbusRTU::ModbusData r, UniXML_iterator& it,
RTUDevice* dev, RegInfo* rcopy=0 );
RSProperty* addProp(PList& plist, RSProperty& p );
bool initMTRitem( UniXML_iterator& it, RegInfo* p );
bool initRTU188item( UniXML_iterator& it, RegInfo* p );
bool initRSProperty( RSProperty& p, UniXML_iterator& it );
bool initRegInfo( RegInfo* r, UniXML_iterator& it, RTUDevice* dev );
bool initRTUDevice( RTUDevice* d, UniXML_iterator& it );
bool initRespondInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniXML_iterator& it );
void rtuQueryOptimization( RTUDeviceMap& m );
void readConfiguration();
bool check_item( UniXML_iterator& it );
/*
struct RTUInfo
{
RTUInfo():rtu(0),sid_conn(UniSetTypes::DefaultObjectId){}
RTUStorage* rtu;
UniSetTypes::ObjectId sid_conn;
};
*/
typedef std::map<int,RTUStorage*> RTUMap;
RTUMap rtulist;
private:
RTUExchange();
bool initPause;
......@@ -152,6 +221,7 @@ class RTUExchange:
bool force_out; /*!< , */
bool mbregFromID;
int polltime; /*!< , [] */
PassiveTimer ptHeartBeat;
UniSetTypes::ObjectId sidHeartBeat;
int maxHeartBeat;
......@@ -160,28 +230,6 @@ class RTUExchange:
UniSetTypes::uniset_mutex pollMutex;
struct RespondInfo
{
RespondInfo():
id(UniSetTypes::DefaultObjectId),
state(false),
invert(false)
{}
UniSetTypes::ObjectId id;
IOController::DIOStateList::iterator dit;
PassiveTimer ptTimeout;
Trigger trTimeout;
bool state;
bool invert;
};
typedef std::map<ModbusRTU::ModbusAddr,RespondInfo> RespondMap;
RespondMap respMap;
PassiveTimer aiTimer;
int ai_polltime;
bool activated;
int activateTimeout;
};
......
......@@ -267,6 +267,95 @@ bool RTUStorage::getState( RTUJack jack, unsigned short int chan, UniversalIO::I
return false;
}
// -----------------------------------------------------------------------------
ModbusRTU::ModbusData RTUStorage::getRegister( RTUJack jack, unsigned short chan, UniversalIO::IOTypes t )
{
if( t == UniversalIO::AnalogInput )
{
switch( jack )
{
case nJ1:
return 1032+chan;
case nJ2:
return 1032+24+chan;
case nJ5:
return 1000+chan;
case nX1:
return 1016+chan;
case nX2:
return 1016+4+chan;
default:
break;
}
return -1;
}
if( t == UniversalIO::AnalogOutput )
{
switch( jack )
{
case nJ1:
return 1016+chan;
case nJ2:
return 1016+24+chan;
case nJ5:
return 1000+chan;
case nX1:
return 1016+chan;
case nX2:
return 1016+4+chan;
default:
break;
}
return -1;
}
if( t == UniversalIO::DigitalInput )
{
switch( jack )
{
case nJ1:
return 32+chan;
case nJ2:
return 32+24+chan;
case nJ5:
return 16+chan;
case nX4:
return chan;
case nX5:
return 8+chan;
default:
break;
}
return -1;
}
if( t == UniversalIO::DigitalOutput )
{
switch( jack )
{
case nJ1:
return 16+chan;
case nJ2:
return 16+24+chan;
case nJ5:
return chan;
default:
break;
}
return -1;
}
return -1;
}
// -----------------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, RTUStorage& m )
{
os << "-------------------" << endl
......
......@@ -46,6 +46,8 @@ class RTUStorage
long getInt( RTUJack jack, unsigned short channel, UniversalIO::IOTypes t );
float getFloat( RTUJack jack, unsigned short channel, UniversalIO::IOTypes t );
bool getState( RTUJack jack, unsigned short channel, UniversalIO::IOTypes t );
static ModbusRTU::ModbusData getRegister( RTUJack jack, unsigned short channel, UniversalIO::IOTypes t );
// : setState, setValue
void print();
......
#!/bin/sh
uniset-start.sh -f ./uniset-rtuexchange --rs-name RTUExchange --confile test.xml \
--rs-filter-field rs --rs-filter-value 1 \
--rs-dev /dev/cbsideA0 --rs-reg-from-id 1 \
--rs-filter-field rs --rs-filter-value wago \
--rs-dev /dev/ttyUSB0 \
--dlog-add-levels info,crit,warn
#level3
#,level3
......@@ -411,6 +411,7 @@ void SharedMemory::fastSaveValue(const IOController_i::SensorInfo& si, CORBA::Lo
SharedMemory* SharedMemory::init_smemory( int argc, char* argv[] )
{
string dfile = conf->getArgParam("--datfile",conf->getConfFileName());
if( dfile[0]!='.' && dfile[0]!='/' )
dfile = conf->getConfDir() + dfile;
......
#!/bin/sh
ln -s -f /usr/bin/uniset-stop.sh stop.sh
ln -s -f ../../conf/test.xml test.xml
......@@ -4,22 +4,21 @@ ulimit -Sc 10000000
START=uniset-start.sh
${START} -f ./uniset-smemory-plus --smemory-id SharedMemory --confile test.xml \
--unideb-add-levels info,crit,warn,level9,system \
--unideb-add-levels info,crit,warn,level9,system,level3,level2,level1 \
--add-io \
--io-force 1 \
--io-name IOControl1 \
--io-name IOControl \
--io-polltime 100 \
--io-s-filter-field io \
--io-s-filter-value ts \
--iodev1 /dev/null
--io-s-filter-value 1 \
--iodev1 /dev/null \
--iodev2 /dev/null \
--io-test-lamp TS_TestLamp_S \
--io-heartbeat-id _31_11_AS \
--io-sm-ready-test-sid TestMode_S \
--add-rtu \
--rtu-device /dev/cbsideA1 \
--rtu-id RTUExchange \
--add-mbslave \
--io-test-lamp RS_Test9_S \
--io-heartbeat-id AI_AS \
--io-sm-ready-test-sid RS_Test9_S
# --add-rtu \
# --rs-dev /dev/cbsideA1 \
# --rs-id RTUExchange \
# --add-mbslave \
#--skip-rtu1 --skip-rtu2 --skip-can --dlog-add-levels info,warn,crit
......
......@@ -85,6 +85,7 @@ static const int NoSafety = -1;
static void processingAsAI( IOBase* it, long new_val, SMInterface* shm, bool force );
static void processingAsDI( IOBase* it, bool new_set, SMInterface* shm, bool force );
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 bool initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
DebugStream* dlog=0, std::string myname="",
......
......@@ -81,7 +81,7 @@ namespace MTR
bool setDataBits( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr, mtrDataBits d );
// -------------------------------------------------------------------------
static const int u2size = 2*sizeof(unsigned short);
static const int u2size = 2;
// -------------------------------------------------------------------------
class T1
{
......@@ -128,6 +128,8 @@ namespace MTR
// ------------------------------------------
// ...
T3(){ memset(raw.v,0,sizeof(raw.v)); }
T3( signed int i ){ raw.val = i; }
T3( unsigned short v1, unsigned short v2 )
{
......@@ -177,7 +179,7 @@ namespace MTR
memcpy(c,&(data[0]),sizeof(c));
sval = std::string(c);
}
~T4(){}
// ------------------------------------------
/*! */
......@@ -202,6 +204,7 @@ namespace MTR
unsigned int val:24;
signed char exp; // :8
} __attribute__( ( packed ) ) u2;
long lval;
} T5mem;
// ------------------------------------------
// ...
......@@ -213,6 +216,11 @@ namespace MTR
val = raw.u2.val * pow(10,raw.u2.exp);
}
T5( long v )
{
raw.lval = v;
}
T5( const ModbusRTU::ModbusData* data )
{
if( sizeof(data) >=u2size )
......@@ -247,6 +255,7 @@ namespace MTR
signed int val:24;
signed char exp; // :8
} u2;
long lval;
} T6mem;
// ------------------------------------------
// ...
......@@ -257,6 +266,11 @@ namespace MTR
raw.v[1] = v2;
val = raw.u2.val * pow(10,raw.u2.exp);
}
T6( long v )
{
raw.lval = v;
}
T6( const ModbusRTU::ModbusData* data )
{
......@@ -293,6 +307,7 @@ namespace MTR
unsigned char ic; // :8 - Inductive/capacitive
unsigned char ie; // :8 - Import/export
}__attribute__( ( packed ) ) u2;
long lval;
} T7mem;
// ------------------------------------------
// ...
......@@ -303,6 +318,10 @@ namespace MTR
raw.v[1] = v2;
val = raw.u2.val * pow(10,-4);
}
T7( const long v )
{
raw.lval = v;
}
T7( const ModbusRTU::ModbusData* data )
{
......@@ -442,6 +461,11 @@ namespace MTR
raw.v[1] = v2;
}
F1( float f )
{
raw.val = f;
}
F1( const ModbusRTU::ModbusData* data )
{
if( sizeof(data) >=u2size )
......
......@@ -42,6 +42,7 @@ namespace VTypes
// ...
F2(){ memset(raw.v,0,sizeof(raw.v)); }
F2( float f ){ raw.val = f; }
F2( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
......@@ -76,6 +77,7 @@ namespace VTypes
// ...
F4(){ memset(raw.v,0,sizeof(raw.v)); }
F4( float f ){ raw.val = f; }
F4( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
......
......@@ -148,14 +148,23 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
shm->localSaveValue( it->ait,it->si.id,val,shm->ID() );
else if( it->stype == UniversalIO::AnalogOutput )
shm->localSetValue( it->ait,it->si.id,val,shm->ID() );
else if( it->stype == UniversalIO::DigitalOutput )
shm->localSetState( it->dit,it->si.id,(bool)val,shm->ID() );
else if( it->stype == UniversalIO::DigitalInput )
shm->localSaveState( it->dit,it->si.id,(bool)val,shm->ID() );
it->value = val;
}
}
}
// -----------------------------------------------------------------------------
void IOBase::processingFasAI( IOBase* it, float val, SMInterface* shm, bool force )
void IOBase::processingFasAI( IOBase* it, float fval, SMInterface* shm, bool force )
{
long val = lroundf(fval);
if( it->cal.precision > 0 )
val = lroundf( fval * pow10(it->cal.precision) );
//
if( it->check_channel_break(val) )
{
......@@ -185,15 +194,16 @@ void IOBase::processingFasAI( IOBase* it, float val, SMInterface* shm, bool forc
if( it->value == ChannelBreakValue )
shm->localSetUndefinedState(it->ait,false,it->si.id);
if( it->cal.precision > 0 )
val *= lroundf(pow10(it->cal.precision));
if( force || it->value != val )
{
if( it->stype == UniversalIO::AnalogInput )
shm->localSaveValue( it->ait,it->si.id,val,shm->ID() );
else if( it->stype == UniversalIO::AnalogOutput )
shm->localSetValue( it->ait,it->si.id,val,shm->ID() );
else if( it->stype == UniversalIO::DigitalOutput )
shm->localSetState( it->dit,it->si.id,(bool)val,shm->ID() );
else if( it->stype == UniversalIO::DigitalInput )
shm->localSaveState( it->dit,it->si.id,(bool)val,shm->ID() );
it->value = val;
}
......@@ -223,6 +233,10 @@ void IOBase::processingAsDI( IOBase* it, bool set, SMInterface* shm, bool force
shm->localSaveState(it->dit,it->si.id,set,shm->ID());
else if( it->stype == UniversalIO::DigitalOutput )
shm->localSetState(it->dit,it->si.id,set,shm->ID());
else if( it->stype == UniversalIO::AnalogInput )
shm->localSaveValue( it->ait,it->si.id,(set ? 1:0),shm->ID() );
else if( it->stype == UniversalIO::AnalogOutput )
shm->localSetValue( it->ait,it->si.id,(set ? 1:0),shm->ID() );
it->value = set ? 1 : 0;
}
......@@ -292,6 +306,52 @@ bool IOBase::processingAsDO( IOBase* it, SMInterface* shm, bool force )
return false;
}
// -----------------------------------------------------------------------------
float IOBase::processingFasAO( 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);
it->value = val;
}
if( it->stype == UniversalIO::AnalogOutput ||
it->stype == UniversalIO::AnalogInput )
{
if( it->cdiagram ) //
{
if( it->cprev != it->value )
{
it->cprev = it->value;
val = it->cdiagram->getRawValue(val);
it->craw = val;
}
else
val = it->craw; //
}
else
{
float fval = val;
IOController_i::CalibrateInfo* cal( &(it->cal) );
if( cal->maxRaw!=0 && cal->maxRaw!=cal->minRaw ) //
{
// !!!
fval = UniSetTypes::fcalibrate(fval,
cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, true );
}
if( it->cal.precision > 0 )
return ( fval / pow10(it->cal.precision) );
}
}
return val;
}
// -----------------------------------------------------------------------------
bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
DebugStream* dlog, std::string myname,
int def_filtersize, float def_filterT )
......@@ -347,20 +407,12 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
else
b->safety = NoSafety;
string stype( it.getProp("iotype") );
if( stype == "AI" )
b->stype = UniversalIO::AnalogInput;
else if ( stype == "AO" )
b->stype = UniversalIO::AnalogOutput;
else if ( stype == "DO" )
b->stype = UniversalIO::DigitalOutput;
else if ( stype == "DI" )
b->stype = UniversalIO::DigitalInput;
else
b->stype = UniSetTypes::getIOType(it.getProp("iotype"));
if( b->stype == UniversalIO::UnknownIOType )
{
if( dlog )
dlog[Debug::CRIT] << myname << "(IOBase::readItem): iotype=: "
<< stype << " " << sname << endl;
<< it.getProp("iotype") << " " << sname << endl;
return false;
}
......
......@@ -41,7 +41,7 @@ int wsize( VType t )
if( t == vtF4 )
return F4::wsize();
return 0;
return 1;
}
// -----------------------------------------------------------------------------
} // end of namespace VTypes
......
......@@ -130,8 +130,6 @@ namespace UniSetTypes
std::string getArgParam(const std::string name, const std::string defval="");
xmlNode* initDebug( DebugStream& deb, const std::string& nodename );
static bool file_exist( const std::string filename );
UniSetTypes::ListOfNode::const_iterator listNodesBegin()
{
return lnodes.begin();
......
......@@ -32,6 +32,7 @@
#include <string>
#include <list>
#include <limits>
#include <ostream>
#include <omniORB4/CORBA.h>
#include "UniSetTypes_i.hh"
......@@ -49,6 +50,9 @@ namespace UniSetTypes
typedef CORBA::Object_ptr ObjectPtr; /*!< ObjectRepository */
typedef CORBA::Object_var ObjectVar; /*!< ObjectRepository */
UniversalIO::IOTypes getIOType( const std::string s );
std::ostream& operator<<( std::ostream& os, const UniversalIO::IOTypes t );
/*! */
enum LampCommand
{
......@@ -213,6 +217,8 @@ namespace UniSetTypes
std::sscanf(str,"%x",&n);
return n;
}
bool file_exist( const std::string filename );
IDList explode( const std::string str, char sep=',' );
}
......
......@@ -139,7 +139,7 @@ namespace ModbusRTU
const DataBits& operator=(const ModbusByte& r);
operator ModbusByte();
operator ModbusByte();
ModbusByte mbyte();
bool operator[]( const int i ){ return b[i]; }
......@@ -158,9 +158,12 @@ namespace ModbusRTU
const DataBits16& operator=(const ModbusData& r);
operator ModbusData();
operator ModbusData();
ModbusData mdata();
bool operator[]( const int i ){ return b[i]; }
void set( int n, bool s ){ b.set(n,s); }
std::bitset<BitsPerData> b;
};
......
......@@ -78,6 +78,7 @@ void UniversalInterface::init()
// NameSerivice
// . ޣ
// localIOR
localctx=CosNaming::NamingContext::_nil();
try
{
if( CORBA::is_nil(orb) )
......@@ -88,13 +89,20 @@ void UniversalInterface::init()
else
localctx = ORepHelpers::getRootNamingContext( orb, oind->getRealNodeName(uconf->getLocalNode()) );
}
catch(Exception& ex )
catch( Exception& ex )
{
if( !uconf->isLocalIOR() )
throw ex;
localctx=CosNaming::NamingContext::_nil();
}
catch( ... )
{
if( !uconf->isLocalIOR() )
throw;
localctx=CosNaming::NamingContext::_nil();
}
}
// ------------------------------------------------------------------------------------------------------------
void UniversalInterface::initBackId( UniSetTypes::ObjectId backid )
......@@ -1563,27 +1571,22 @@ void UniversalInterface::registered( UniSetTypes::ObjectId id, UniSetTypes::Obje
{
// ޣ
// IOR
// ݣ
// NameService (omniNames)
if( uconf->isLocalIOR() )
{
if( CORBA::is_nil(orb) )
orb = uconf->getORB();
string sior(orb->object_to_string(oRef));
uconf->iorfile.setIOR(id,node,sior);
uconf->iorfile.setIOR(id,node,orb->object_to_string(oRef));
return;
}
try
{
string nm=oind->getNameById(id, node);
rep.registration(nm,oRef,(bool)force);
rep.registration(oind->getNameById(id, node),oRef,(bool)force);
}
catch(Exception& ex )
{
if( !uconf->isLocalIOR() )
throw;
throw;
}
}
......@@ -1591,17 +1594,18 @@ void UniversalInterface::registered( UniSetTypes::ObjectId id, UniSetTypes::Obje
void UniversalInterface::unregister(UniSetTypes::ObjectId id, UniSetTypes::ObjectId node)throw(ORepFailed)
{
if( uconf->isLocalIOR() )
{
uconf->iorfile.unlinkIOR(id,node);
return;
}
try
{
string nm = oind->getNameById(id,node);
rep.unregistration(nm);
rep.unregistration(oind->getNameById(id,node));
}
catch(Exception& ex )
{
if( !uconf->isLocalIOR() )
throw;
throw;
}
}
......@@ -1638,14 +1642,17 @@ ObjectPtr UniversalInterface::resolve( ObjectId rid , ObjectId node, int timeout
{
// NameService ,
//
if( CORBA::is_nil(localctx) )
{
unideb[Debug::WARN] << " IOR- " << uconf->oind->getNameById(rid,node) << endl;
// if( CORBA::is_nil(localctx) )
// {
if( unideb.debugging(Debug::WARN) )
{
unideb[Debug::WARN] << " IOR- " << uconf->oind->getNameById(rid,node) << endl;
}
throw UniSetTypes::ResolveNameError();
}
// }
// NameService (omniNames)
unideb[Debug::WARN] << " IOR- " << uconf->oind->getNameById(rid,node)
<< " NameService \n";
// unideb[Debug::WARN] << " IOR- " << uconf->oind->getNameById(rid,node)
// << " NameService \n";
}
}
......@@ -2314,17 +2321,21 @@ bool UniversalInterface::isExist( UniSetTypes::ObjectId id )
{
try
{
/*
try
if( uconf->isLocalIOR() )
{
oref = rcache.resolve(id, uconf->getLocalNode());
}
catch(NameNotFound){}
if( CORBA::is_nil(orb) )
orb = uconf->getORB();
if(!oref)
oref = resolve(id, uconf->getLocalNode());
return rep.isExist( oref );
*/
string sior(uconf->iorfile.getIOR(id,uconf->getLocalNode()));
if( !sior.empty() )
{
CORBA::Object_var oref = orb->string_to_object(sior.c_str());
return rep.isExist( oref );
}
return false;
}
string nm = oind->getNameById(id);
return rep.isExist(nm);
}
......@@ -2332,7 +2343,7 @@ bool UniversalInterface::isExist( UniSetTypes::ObjectId id )
{
// unideb[Debug::WARN] << "UI(isExist): " << ex << endl;
}
catch(...){}
catch(...){}
return false;
}
// ------------------------------------------------------------------------------------------------------------
......@@ -2350,7 +2361,7 @@ bool UniversalInterface::isExist( UniSetTypes::ObjectId id, UniSetTypes::ObjectI
}
catch(NameNotFound){}
if( CORBA::is_nil(oref) )
if( CORBA::is_nil(oref) )
oref = resolve(id, node);
return rep.isExist( oref );
......
......@@ -24,6 +24,7 @@
*/
// -----------------------------------------------------------------------------
#include <cmath>
#include <fstream>
#include "UniSetTypes.h"
#include "Configuration.h"
// -----------------------------------------------------------------------------
......@@ -163,6 +164,23 @@ using namespace UniSetTypes;
return seq;
}
// -------------------------------------------------------------------------
bool UniSetTypes::file_exist( const std::string filename )
{
std::ifstream file;
#ifdef HAVE_IOS_NOCREATE
file.open( filename.c_str(), std::ios::in | std::ios::nocreate );
#else
file.open( filename.c_str(), std::ios::in );
#endif
bool result = false;
if( file )
result = true;
file.close();
return result;
}
// -------------------------------------------------------------------------
UniSetTypes::IDList UniSetTypes::explode( const string str, char sep )
{
UniSetTypes::IDList l;
......@@ -184,3 +202,34 @@ using namespace UniSetTypes;
return l;
}
// ------------------------------------------------------------------------------------------
UniversalIO::IOTypes UniSetTypes::getIOType( const std::string stype )
{
if( stype == "AI" )
return UniversalIO::AnalogInput;
if ( stype == "AO" )
return UniversalIO::AnalogOutput;
if ( stype == "DO" )
return UniversalIO::DigitalOutput;
if ( stype == "DI" )
return UniversalIO::DigitalInput;
return UniversalIO::UnknownIOType;
}
// ------------------------------------------------------------------------------------------
std::ostream& UniSetTypes::operator<<( std::ostream& os, const UniversalIO::IOTypes t )
{
if( t == UniversalIO::AnalogInput )
return os << "AI";
if( t == UniversalIO::DigitalInput )
return os << "DI";
if( t == UniversalIO::AnalogOutput )
return os << "AO";
if( t == UniversalIO::DigitalOutput )
return os << "DO";
return os << "UnknownIOType";
}
// ------------------------------------------------------------------------------------------
......@@ -890,23 +890,6 @@ string Configuration::getPort()
return UniSetDefaultPort;
}
// -------------------------------------------------------------------------
bool Configuration::file_exist( const string filename )
{
std::ifstream file;
#ifdef HAVE_IOS_NOCREATE
file.open( filename.c_str(), std::ios::in | std::ios::nocreate );
#else
file.open( filename.c_str(), std::ios::in );
#endif
bool result(false);
if( file )
result = true;
file.close();
return result;
}
// -------------------------------------------------------------------------
ObjectId Configuration::getSensorID( const std::string name )
{
return oind->getIdByName(conf->getSensorsSection()+"/"+name);
......
......@@ -147,6 +147,9 @@ void NCRestorer_XML::read_list( UniXML& xml, xmlNode* node, IONotifyController*
}
}
break;
default:
break;
}
rslot(xml,it,node);
......@@ -276,21 +279,12 @@ bool NCRestorer_XML::getSensorInfo( UniXML& xml, xmlNode* it, SInfo& inf )
}
}
string iotype(xml.getProp(it,"iotype"));
if( iotype=="DI" )
inf.type=UniversalIO::DigitalInput;
else if( iotype=="AI" )
inf.type=UniversalIO::AnalogInput;
else if( iotype=="AO" )
inf.type=UniversalIO::AnalogOutput;
else if( iotype=="DO" )
inf.type=UniversalIO::DigitalOutput;
else
inf.type = UniSetTypes::getIOType(xml.getProp(it,"iotype"));
if( inf.type == UniversalIO::UnknownIOType )
{
unideb[Debug::CRIT] << "(NCRestorer_XML:getSensorInfo): ("
<< iotype << ") / "
<< xml.getProp(it,"name") << endl;
unideb[Debug::CRIT] << "(NCRestorer_XML:getSensorInfo): unknown iotype=" << xml.getProp(it,"iotype")
<< " for " << xml.getProp(it,"name") << endl;
return false;
}
......
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