Commit 3779a007 authored by Pavel Vainerman's avatar Pavel Vainerman

Merge commit 'origin/master' into eterbook

Conflicts: extentions/SharedMemory/SharedMemory.cc
parents 6eb79ccc c80772a1
......@@ -16,7 +16,8 @@ MBSlave::MBSlave( ModbusRTU::ModbusAddr addr, const std::string dev, const std::
addr(addr),
// prev(ModbusRTU::erNoError),
// askCount(0),
verbose(false)
verbose(false),
replyVal(0)
{
cout << "$Id: MBSlave.cc,v 1.7 2009/02/24 20:27:24 vpashka Exp $" << endl;
......@@ -109,7 +110,10 @@ ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query,
if( query.count <= 1 )
{
reply.addData(d);
if( replyVal )
reply.addData(replyVal);
else
reply.addData(d);
return ModbusRTU::erNoError;
}
......@@ -117,8 +121,12 @@ ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query,
int num=0; //
ModbusData reg = query.start;
for( ; num<query.count; num++, reg++ )
reply.addData(d);
{
if( replyVal )
reply.addData(replyVal);
else
reply.addData(d);
}
// , ۣ
// ...
if( reply.bcnt < query.count )
......@@ -144,7 +152,10 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
if( query.count <= 1 )
{
reply.addData(d);
if( replyVal )
reply.addData(replyVal);
else
reply.addData(d);
return ModbusRTU::erNoError;
}
......@@ -152,8 +163,12 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
int num=0; //
ModbusData reg = query.start;
for( ; num<query.count; num++, reg++ )
reply.addData(d);
{
if( replyVal )
reply.addData(replyVal);
else
reply.addData(d);
}
// , ۣ
// ...
if( reply.bcnt < query.count )
......@@ -173,7 +188,10 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query,
if( query.count <= 1 )
{
reply.addData(query.start);
if( replyVal )
reply.addData(replyVal);
else
reply.addData(query.start);
return ModbusRTU::erNoError;
}
......@@ -181,7 +199,12 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query,
int num=0; //
ModbusData reg = query.start;
for( ; num<query.count; num++, reg++ )
reply.addData(reg);
{
if( replyVal )
reply.addData(replyVal);
else
reply.addData(reg);
}
// , ۣ
// ...
......@@ -202,7 +225,10 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters(
if( query.count <= 1 )
{
reply.addData(query.start);
if( replyVal )
reply.addData(replyVal);
else
reply.addData(query.start);
return ModbusRTU::erNoError;
}
......@@ -210,8 +236,12 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters(
int num=0; //
ModbusData reg = query.start;
for( ; num<query.count; num++, reg++ )
reply.addData(reg);
{
if( replyVal )
reply.addData(replyVal);
else
reply.addData(reg);
}
// , ۣ
// ...
if( reply.count < query.count )
......
......@@ -20,6 +20,11 @@ class MBSlave
verbose = state;
}
inline void setReply( long val )
{
replyVal = val;
}
void execute(); /*!< */
......@@ -96,7 +101,7 @@ class MBSlave
typedef std::map<int,std::string> FileList;
FileList flist;
#endif
long replyVal;
private:
};
......
......@@ -16,6 +16,7 @@ static struct option longopts[] = {
{ "myaddr", required_argument, 0, 'a' },
{ "speed", required_argument, 0, 's' },
{ "use485F", no_argument, 0, 'y' },
{ "const-reply", required_argument, 0, 'c' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -29,6 +30,7 @@ static void print_help()
printf("[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.\n");
printf("[-y|--use485F] - use RS485 Fastwel.\n");
printf("[-v|--verbose] - Print all messages to stdout\n");
printf("[-c|--const-reply] val - Reply val for all queries\n");
}
// --------------------------------------------------------------------------
int main( int argc, char **argv )
......@@ -42,10 +44,11 @@ int main( int argc, char **argv )
int tout = 2000;
DebugStream dlog;
int use485 = 0;
int replyVal=0;
try
{
while( (opt = getopt_long(argc, argv, "hva:d:s:y",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hva:d:s:yc:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......@@ -77,6 +80,10 @@ int main( int argc, char **argv )
use485 = 1;
break;
case 'c':
replyVal = atoi(optarg);
break;
case '?':
default:
printf("? argumnet\n");
......@@ -97,6 +104,7 @@ int main( int argc, char **argv )
MBSlave mbs(myaddr,dev,speed,use485);
mbs.setLog(dlog);
mbs.setVerbose(verb);
mbs.setReply(replyVal);
mbs.execute();
}
catch( ModbusRTU::mbException& ex )
......
......@@ -44,9 +44,10 @@ int main( int argc, char **argv )
int tout = 2000;
DebugStream dlog;
try
{
while( (opt = getopt_long(argc, argv, "hva:d:s:",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hva:d:s:c:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......
......@@ -60,10 +60,10 @@
<xsl:call-template name="settype"><xsl:with-param name="iotype" select="../../@iotype" /></xsl:call-template><xsl:text> prev_</xsl:text><xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/>; /*!&lt; */
</xsl:when>
<xsl:when test="$GENTYPE='C'"><xsl:value-of select="../../@name"/>(<xsl:value-of select="../../@id"/>),
<xsl:if test="normalize-space(../../@node)=''">
<xsl:if test="not(normalize-space(../../@node)='')">
node_<xsl:value-of select="../../@name"/>(<xsl:value-of select="../../@node"/>),
</xsl:if>
<xsl:if test="not(normalize-space(../../@node)='')">
<xsl:if test="normalize-space(../../@node)=''">
node_<xsl:value-of select="../../@name"/>(UniSetTypes::conf->getLocalNode()),
</xsl:if>
<xsl:if test="normalize-space(../../@default)=''">
......
......@@ -68,7 +68,15 @@
</MBSlave1>
<RTUExchange name="RTUExchange"/>
<RTUExchange name="RTUExchange">
<RespondList>
<!--
<item addr="0x01" respondSensor="RespondRTU_S" timeout="5000"/>
<item addr="0x02" respondSensor="NoRespondRTU2_S" timeout="5000" invert="1"/>
-->
</RespondList>
</RTUExchange>
<UDPExchange name="UDPExchange"/>
<UDPExchange2 name="UDPExchange2"/>
......@@ -92,9 +100,9 @@
<!-- ************************ ********************** -->
<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="0x31" mbfunc="0x04" mbreg="0x02" rs="1" />
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium" mbtcp="1" mbaddr="0x31" mbfunc="0x04" mbreg="0x02"/>
<item name="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" udp="1"/>
<item name="Input2_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x02" rs="2" />
<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">
<depends>
......@@ -103,8 +111,11 @@
</item>
<item name="DO_C" textname="Digital output" node="" iotype="DO" priority="Medium"/>
<item name="DO1_C" textname="Digital output" node="" iotype="DO" priority="Medium"/>
<item name="AO_AS" textname="Analog output" node="" iotype="AO" priority="Medium"/>
<item name="AI_AS" textname="Analog input" node="" iotype="AI" default="378" priority="Medium">
<item name="AO_AS" textname="Analog output" node="" iotype="AO" priority="Medium"
mbtype="rtu" mbaddr="0x01" mbfunc="0x06" mbreg="0x02" rs="2" default="10" />
/>
<item name="AI_AS" textname="Analog input" node="" iotype="AI" default="378" priority="Medium"
mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x01" rs="1" vtype="F2" precision="45">
<consumers>
<consumer name="TestProc" type="objects" cfilter="test1"/>
<consumer name="PLCProcessor" type="objects"/>
......@@ -112,6 +123,10 @@
</item>
<item name="Threshold1_S" textname="" node="" iotype="DI" priority="Medium"/>
<item name="TestMode_S" textname="test" node="" iotype="DI" priority="Medium"/>
<item name="RespondRTU_S" textname="respond rtu" node="" iotype="DI"/>
<item name="NoRespondRTU2_S" textname="no respond rtu" node="" iotype="DI"/>
</sensors>
<thresholds name="thresholds">
......
......@@ -43,41 +43,6 @@ int ComediInterface::getAnalogChannel( int subdev, int channel, int range, int a
return data;
}
// -----------------------------------------------------------------------------
std::vector<lsampl_t> ComediInterface::getAnalogPacket( int subdev, int channel, int range, int aref )
throw(UniSetTypes::Exception)
{
lsampl_t* data = new lsampl_t[1024]; /* FIFO size, maximum possible samples */
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
insn.n = 1024;
insn.data = data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(channel, range, aref);
int ret = comedi_do_insn(card, &insn);
if( ret < 0 )
{
delete[] data;
ostringstream err;
err << "(ComediInterface:getAnalogPacket): can`t read data from subdev=" << subdev
<< " channel=" << channel << " range=" << range <<" aref="<< aref
<< " err: " << ret << " (" << strerror(ret) << ")";
throw Exception(err.str());
// return std::vector<lsampl_t>(0);
}
std::vector<lsampl_t> result(ret);
if(ret > 0)
memcpy(&result[0], data, ret * sizeof(lsampl_t));
delete[] data;
return result;
}
// -----------------------------------------------------------------------------
void ComediInterface::setAnalogChannel( int subdev, int channel, int data, int range, int aref )
throw(UniSetTypes::Exception)
{
......@@ -117,41 +82,6 @@ void ComediInterface::setDigitalChannel( int subdev, int channel, bool bit )
throw Exception(err.str());
}
}
// -----------------------------------------------------------------------------
void ComediInterface::instrChannel( int subdev, int channel, const std::string instr,
std::vector<lsampl_t> args, int range, int aref )
throw(UniSetTypes::Exception)
{
lsampl_t ins = instr2type(instr);
comedi_insn insn;
if(ins < 0)
{
ostringstream err;
err << "(ComediInterface:instrChannel): unknown instruction "
<< " subdev=" << subdev << " channel=" << channel << " instruction=" << instr;
throw Exception(err.str());
}
args.insert(args.begin(), ins);
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = args.size();
insn.data = &args[0];
insn.subdev = subdev;
insn.chanspec = CR_PACK(channel,range,aref);
if( comedi_do_insn(card,&insn) < 0 )
{
ostringstream err;
err << "(ComediInterface:instrChannel): can`t execute the instruction "
<< " subdev=" << subdev << " channel=" << channel << " instruction=" << instr;
throw Exception(err.str());
}
return;
}
// -----------------------------------------------------------------------------
void ComediInterface::configureChannel( int subdev, int channel, ChannelType t,
int range, int aref )
......@@ -209,39 +139,21 @@ void ComediInterface::configureChannel( int subdev, int channel, ChannelType t,
void ComediInterface::configureSubdev( int subdev, SubdevType t )
throw(UniSetTypes::Exception)
{
static const unsigned char chans[4] = {0, 8, 16, 20}; /* We can configure only one channel per 8-bit port (4-bit for CL and CH). */
lsampl_t cmd[4]; /* Ports A, B, CL, CH */
lsampl_t cmd = 102;
comedi_insn insn;
switch(t)
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
insn.data = &cmd;
insn.unused[0] = t;
insn.subdev = subdev;
insn.chanspec = 0;
if( comedi_do_insn(card,&insn) < 0 )
{
case TBI24_0:
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_INPUT;
break;
case TBI0_24:
default:
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
break;
case TBI16_8:
cmd[0] = cmd[1] = INSN_CONFIG_DIO_INPUT;
cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
break;
}
for(int i = 0; i < 4; i++) {
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
insn.data = &cmd[i];
insn.subdev = subdev;
insn.chanspec = CR_PACK(chans[i], 0, 0);
if( comedi_do_insn(card,&insn) < 0 )
{
ostringstream err;
err << "(ComediInterface:configureSubdev): can`t configure subdev "
<< " subdev=" << subdev << " type=" << t;
throw Exception(err.str());
}
ostringstream err;
err << "(ComediInterface:configureSubdev): can`t configure subdev "
<< " subdev=" << subdev << " type=" << t;
throw Exception(err.str());
}
}
// -----------------------------------------------------------------------------
......@@ -279,46 +191,3 @@ ComediInterface::SubdevType ComediInterface::str2type( const std::string s )
return Unknown;
}
// -----------------------------------------------------------------------------
ComediInterface::EventType ComediInterface::event2type( const std::string s )
{
if( s == "Front" )
return Front;
if( s == "Rear" )
return Rear;
if( s == "FrontThenRear" )
return FrontThenRear;
return No;
}
// -----------------------------------------------------------------------------
lsampl_t ComediInterface::instr2type( const std::string s )
{
if( s == "AVERAGING" || s == "BOUNCE_SUPPRESSION" ) /* This are the same instructions, one for AI, another for DI */
return INSN_CONFIG_AVERAGING;
if( s == "TIMER" )
return INSN_CONFIG_TIMER_1;
if( s == "INPUT_MASK" )
return INSN_CONFIG_INPUT_MASK;
if( s == "FILTER" )
return INSN_CONFIG_FILTER;
if( s == "0mA" )
return INSN_CONFIG_0MA;
if( s == "COMPL" )
return INSN_CONFIG_COMPL;
if( s == "COUNTER" )
return INSN_CONFIG_COUNTER;
if( s == "DI_MODE" )
return INSN_CONFIG_DI_MODE;
return -1;
}
// -----------------------------------------------------------------------------
......@@ -4,9 +4,7 @@
#define ComediInterface_H_
// -----------------------------------------------------------------------------
#include <string>
#include <vector>
#include <comedilib.h>
#include <fastwel.h>
#include "Exceptions.h"
// -----------------------------------------------------------------------------
/*! / */
......@@ -19,9 +17,6 @@ class ComediInterface
int getAnalogChannel( int subdev, int channel, int range=0, int aref=AREF_GROUND )
throw(UniSetTypes::Exception);
std::vector<lsampl_t> getAnalogPacket( int subdev, int channel, int range=0, int aref=AREF_GROUND )
throw(UniSetTypes::Exception);
void setAnalogChannel( int subdev, int channel, int data, int range=0, int aref=AREF_GROUND )
throw(UniSetTypes::Exception);
......@@ -37,10 +32,10 @@ class ComediInterface
{
DI = INSN_CONFIG_DIO_INPUT,
DO = INSN_CONFIG_DIO_OUTPUT,
AI = INSN_CONFIG_AIO_INPUT,
AO = INSN_CONFIG_AIO_OUTPUT
AI = 100, // INSN_CONFIG_AIO_INPUT,
AO = 101 // INSN_CONFIG_AIO_OUTPUT
};
enum SubdevType
{
Unknown = 0,
......@@ -48,31 +43,18 @@ class ComediInterface
TBI0_24 = 2,
TBI16_8 = 3
};
enum EventType
{
No = 0,
Front = 1,
Rear = 2,
FrontThenRear = 3
};
static std::string type2str( SubdevType t );
static SubdevType str2type( const std::string s );
static EventType event2type( const std::string s );
static lsampl_t instr2type( const std::string s );
void configureSubdev( int subdev, SubdevType type ) throw(UniSetTypes::Exception);
void configureChannel( int subdev, int channel, ChannelType type, int range=0, int aref=0 )
throw(UniSetTypes::Exception);
/* Perform extended instruction at the channel. Arguments are being taken as C++ vector. */
void instrChannel( int subdev, int channel, const std::string instr, std::vector<lsampl_t> args, int range=0, int aref=0 )
throw(UniSetTypes::Exception);
inline const std::string devname(){ return dname; }
protected:
comedi_t* card; /*!< / */
......
......@@ -278,7 +278,7 @@ void IOControl::execute()
try
{
// init first time....
if( !force )
if( !force && !noCards )
{
uniset_mutex_lock l(iopollMutex,5000);
force = true;
......@@ -743,7 +743,7 @@ void IOControl::initIOCard()
if( noCards )
return;
ComediInterface* card(0);
ComediInterface* card = 0;
for( IOMap::iterator it=iomap.begin(); it!=iomap.end(); ++it )
{
......
......@@ -3,7 +3,6 @@
#include <stdlib.h>
#include <string.h>
#include <comedilib.h>
#include <fastwel.h>
#include <getopt.h>
int subdev = 0;
......@@ -17,7 +16,6 @@ static struct option longopts[] = {
{ "read", required_argument, 0, 'r' },
{ "write", required_argument, 0, 'w' },
{ "aread", required_argument, 0, 'i' },
{ "anread", required_argument, 0, 'n' },
{ "awrite", required_argument, 0, 'o' },
{ "subdev", required_argument, 0, 's' },
{ "device", required_argument, 0, 'd' },
......@@ -25,9 +23,6 @@ static struct option longopts[] = {
{ "aref", required_argument, 0, 'z' },
{ "range", required_argument, 0, 'x' },
{ "config", required_argument, 0, 'c' },
{ "extconfig", required_argument, 0, 'e' },
{ "timer", required_argument, 0, 't' },
{ "autoscan", no_argument, 0, 'u' },
{ "autoconf", no_argument, 0, 'a' },
{ "plus", required_argument, 0, 'p' },
{ "blink", no_argument, 0, 'b' },
......@@ -44,22 +39,18 @@ enum Command
cmdARead,
cmdAWrite,
cmdConfig,
cmdSubConfig,
cmdAnRead,
cmdExtConfig,
cmdTimer
cmdSubConfig
} cmd;
// --------------------------------------------------------------------------
static void insn_config( comedi_t* card, int subdev, int channel, lsampl_t iotype, int range, int aref );
static void insn_subdev_config( comedi_t* card, int subdev, lsampl_t type );
static void insn_config_extra( comedi_t* card, int subdev, int channel, lsampl_t data, int range, int aref, int val );
// --------------------------------------------------------------------------
int main(int argc, char* argv[])
{
comedi_t* card;
lsampl_t data = 0;
lsampl_t darr[20];
int optindex = 0;
int opt = 0;
char* dev = "/dev/comedi0";
......@@ -70,14 +61,10 @@ int main(int argc, char* argv[])
int cnum = 0;
int blink = 0;
int exret = EXIT_SUCCESS;
int instruction;
int autoscan = 0;
int n_data;
memset(chan,-1,sizeof(chan));
while( (opt = getopt_long(argc, argv, "habur:w:i:o:s:d:c:p:m:q:e:t:n:",longopts,&optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "habr:w:i:o:s:d:c:p:m:q:",longopts,&optindex)) != -1 )
{
switch (opt)
{
......@@ -87,7 +74,6 @@ int main(int argc, char* argv[])
printf("[-r|--read] chan - read from digital channel\n");
printf("[-o|--awrite] chan val - write to analog channel\n");
printf("[-i|--aread] chan - read from analog channel\n");
printf("[-n|--anread] chan - read N values (n = 20) from analog channel\n");
printf("[-s|--subdev] sub - use subdev number sub. (Default: 0)\n");
printf("[-d|--device] dev - use device dev. (Default: /dev/comedi0)\n");
printf("[--aref] val - AREF (Default: %d)\n",aref);
......@@ -108,14 +94,11 @@ int main(int argc, char* argv[])
printf(" 1 - -5 - 5\n");
printf(" 2 - -2.5 - 2.5\n");
printf(" 3 - -1.25 - 1.25\n");
printf("[-e|--extconfig] channel instruction [parameters] - perform configuring instruction at given channel\n");
printf("[-t|--timer] channel interval - start acquisition by timer at given channel or stop it (if interval = 0)\n");
printf("[-u|--autoscan] - (together with -t) set autoscan mode for acquisition by timer\n");
printf("[--blink] - (blink output): ONLY FOR 'write': 0-1-0-1-0-...\n");
printf("[--blink-msec] val - Blink pause [msec]. Default: 300 msec\n");
return 0;
case 'r':
case 'r':
chan[0] = atoi(optarg);
cmd = cmdDRead;
break;
......@@ -127,16 +110,7 @@ int main(int argc, char* argv[])
val = atoi(argv[optind]);
break;
case 'n':
chan[0] = atoi(optarg);
cmd = cmdAnRead;
break;
case 'u':
autoscan = 1;
break;
case 'i':
case 'i':
chan[0] = atoi(optarg);
cmd = cmdARead;
break;
......@@ -148,23 +122,7 @@ int main(int argc, char* argv[])
val = atoi(argv[optind]);
break;
case 'e':
chan[0] = atoi(optarg);
cmd = cmdExtConfig;
n_data = 0;
for(; optind < argc && (argv[optind])[0]!='-'; optind++, n_data++) {
darr[n_data] = atoi(argv[optind]);
}
break;
case 't':
chan[0] = atoi(optarg);
cmd = cmdTimer;
if( optind < argc && (argv[optind])[0]!='-' )
val = atoi(argv[optind++]);
break;
case 'd':
case 'd':
dev = optarg;
break;
......@@ -239,6 +197,12 @@ int main(int argc, char* argv[])
{
for( int k=0; chan[k]!=-1; k++ )
{
if( comedi_dio_config(card, subdev, chan[k],INSN_CONFIG_DIO_INPUT) < 0)
{
comedi_perror("can't configure DI channels");
exret = EXIT_FAILURE;
}
if( comedi_dio_read(card, subdev, chan[k],&data) < 0)
{
fprintf(stderr, "can't read from channel %d\n",chan[k]);
......@@ -252,6 +216,14 @@ int main(int argc, char* argv[])
case cmdDWrite:
{
for( int k=0; chan[k]!=-1; k++ )
{
if( comedi_dio_config(card, subdev, chan[k],INSN_CONFIG_DIO_OUTPUT) < 0 )
{
comedi_perror("can't configure DO channels");
exret = EXIT_FAILURE;
}
}
//
while(1)
{
......@@ -295,35 +267,6 @@ int main(int argc, char* argv[])
}
break;
case cmdAnRead:
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_READ;
insn.n = 20;
insn.data = darr;
insn.subdev = subdev;
for( int k=0; chan[k]!=-1; k++ )
{
if( autoconf )
insn_config(card, subdev,chan[k],100,range,aref);
insn.chanspec = CR_PACK(chan[k], range, aref);
int ret = comedi_do_insn(card, &insn);
if( ret < 0)
{
fprintf(stderr, "can't read from channel %d: (%d) %s\n",chan,ret,strerror(ret));
exret = EXIT_FAILURE;
}
printf("Readed from channel %d: expected 20 samples, got %d samples\n", chan[k], ret);
for(int i = 0; i < ret; i++)
printf("Data[%d] = %d\n", i, darr[i]);
}
}
break;
case cmdAWrite:
{
for( int k=0; chan[k]!=-1; k++ )
......@@ -346,10 +289,10 @@ int main(int argc, char* argv[])
for( int k=0; chan[k]!=-1; k++ )
{
if( val != INSN_CONFIG_DIO_INPUT
&& val != INSN_CONFIG_DIO_OUTPUT
&& val != INSN_CONFIG_AIO_INPUT
&& val != INSN_CONFIG_AIO_OUTPUT
if( val != INSN_CONFIG_DIO_INPUT
&& val != INSN_CONFIG_DIO_OUTPUT
&& val != 100 /* INSN_CONFIG_AIO_INPUT */
&& val != 101 /* INSN_CONFIG_AIO_OUTPUT */
)
{
fprintf(stderr, "can't config channel %d for type = %d (val=[%d,%d,%d,%d])\n"
......@@ -358,45 +301,6 @@ int main(int argc, char* argv[])
}
}
}
case cmdExtConfig:
{
for( int k=0; chan[k]!=-1; k++ )
{
comedi_insn insn;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = n_data;
insn.data = darr;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan[k], 0, 0);
comedi_do_insn(card, &insn);
}
break;
}
case cmdTimer:
{
for( int k=0; chan[k]!=-1; k++ )
{
comedi_insn insn;
lsampl_t data[3];
data[0] = INSN_CONFIG_TIMER_1;
data[1] = val;
data[2] = autoscan;
memset(&insn, 0, sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 3;
insn.data = data;
insn.subdev = subdev;
insn.chanspec = CR_PACK(chan[k], 0, 0);
comedi_do_insn(card, &insn);
}
break;
}
case cmdSubConfig:
insn_subdev_config(card, subdev, val);
......@@ -429,38 +333,38 @@ void insn_config( comedi_t* card, int subdev, int channel, lsampl_t iotype, int
void insn_subdev_config( comedi_t* card, int subdev, lsampl_t type )
{
static const unsigned char chans[4] = {0, 8, 16, 20}; /* We can configure only one channel per 8-bit port (4-bit for CL and CH). */
lsampl_t cmd[4]; /* Ports A, B, CL, CH */
lsampl_t cmd = 102;
comedi_insn insn;
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
insn.data = &cmd;
insn.unused[0] = type;
insn.subdev = subdev;
insn.chanspec = 0;
switch(type)
{
case 1: /* TBI 24_0 */
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_INPUT;
case 1:
printf("set subdev %d type: 'TBI 24/0'\n",subdev);
break;
case 2: /* TBI 0_24 */
default:
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
break;
case 2:
printf("set subdev %d type: 'TBI 0/24'\n",subdev);
break;
case 3: /* TBI 16_8 */
cmd[0] = cmd[1] = INSN_CONFIG_DIO_INPUT;
cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
break;
case 3:
printf("set subdev %d type: 'TBI 16/8'\n",subdev);
break;
break;
default:
printf("set subdev %d type: UNKNOWN\n",subdev);
break;
}
for(int i = 0; i < 4; i++) {
memset(&insn,0,sizeof(insn));
insn.insn = INSN_CONFIG;
insn.n = 1;
insn.data = &cmd[i];
insn.subdev = subdev;
insn.chanspec = CR_PACK(chans[i], 0, 0);
if( comedi_do_insn(card,&insn) < 0 ) {
fprintf(stderr, "can`t configure subdev subdev=%d type=%d",subdev,type);
exit(EXIT_FAILURE);
}
if( comedi_do_insn(card,&insn) < 0 )
{
fprintf(stderr, "can`t configure subdev subdev=%d type=%d",subdev,type);
exit(EXIT_FAILURE);
}
}
// $Id: MBMaster.cc,v 1.11 2009/03/03 10:33:27 pv Exp $
// -----------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include <sstream>
#include "Exceptions.h"
#include "Extentions.h"
......
// $Id: MBSlave.cc,v 1.1 2009/01/11 19:08:45 vpashka Exp $
// -----------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include <sstream>
#include "Exceptions.h"
#include "Extentions.h"
......
bin_PROGRAMS = @PACKAGE@-rtuexchange mtrconv rtustate
bin_PROGRAMS = @PACKAGE@-rtuexchange mtrconv rtustate vtconv
lib_LTLIBRARIES = libUniSetRTU.la
libUniSetRTU_la_LIBADD = $(top_builddir)/lib/libUniSet.la \
......@@ -19,6 +19,10 @@ mtrconv_SOURCES = mtrconv.cc
mtrconv_LDADD = $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
mtrconv_CXXFLAGS = -I$(top_builddir)/extentions/include
vtconv_SOURCES = vtconv.cc
vtconv_LDADD = $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
vtconv_CXXFLAGS = -I$(top_builddir)/extentions/include
rtustate_LDADD = libUniSetRTU.la $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
rtustate__CXXFLAGS = -I$(top_builddir)/extentions/include
rtustate_SOURCES = rtustate.cc
......
......@@ -19,6 +19,7 @@
#include "MTR.h"
#include "RTUStorage.h"
#include "IOBase.h"
#include "VTypes.h"
// -----------------------------------------------------------------------------
class RTUExchange:
public UniSetObject_LT
......@@ -51,7 +52,6 @@ class RTUExchange:
friend std::ostream& operator<<( std::ostream& os, const DeviceType& dt );
struct RSProperty:
public IOBase
{
......@@ -60,8 +60,11 @@ class RTUExchange:
ModbusRTU::ModbusData mbreg; /*!< */
ModbusRTU::SlaveFunctionCode mbfunc; /*!< / */
// only for RTU
short nbit; /*!< bit number (for func=[0x01,0x02]) */
short nbit; /*!< bit number (for func=[0x01,0x02]) */
VTypes::VType vType; /*!< type of value */
short rnum; /*!< count of registers */
// only for MTR
MTR::MTRType mtrType; /*!< ( MTR) */
......@@ -74,7 +77,9 @@ class RTUExchange:
RSProperty():
devtype(dtUnknown),
mbaddr(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown),
nbit(-1),rtu(0),rtuJack(RTUStorage::nUnknown),rtuChan(0)
nbit(-1),vType(VTypes::vtUnknown),
rnum(VTypes::wsize(VTypes::vtUnknown)),
rtu(0),rtuJack(RTUStorage::nUnknown),rtuChan(0)
{}
friend std::ostream& operator<<( std::ostream& os, RSProperty& p );
......@@ -100,6 +105,7 @@ class RTUExchange:
long pollRTU188( RSMap::iterator& p );
long pollMTR( RSMap::iterator& p );
long pollRTU( RSMap::iterator& p );
void setRespond(ModbusRTU::ModbusAddr addr, bool respond );
virtual void processingMessage( UniSetTypes::VoidMessage *msg );
void sysCommand( UniSetTypes::SystemMessage *msg );
......@@ -153,8 +159,25 @@ class RTUExchange:
UniSetTypes::ObjectId test_id;
UniSetTypes::uniset_mutex pollMutex;
Trigger trTimeout;
PassiveTimer ptTimeout;
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;
......
......@@ -2,7 +2,7 @@
//! \version $Id: RTUStorage.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
......
......@@ -3,12 +3,10 @@
// --------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include <math.h>
#include "Configuration.h"
#include "UniSetTypes.h"
#include "MTR.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace MTR;
// --------------------------------------------------------------------------
static void print_help()
......@@ -45,7 +43,7 @@ int main( int argc, char **argv )
else if( !strcmp(type,"T3") )
{
T3 t(v1,v2);
cout << "(T3): v1=" << t.raw.u.v1 << " v2=" << t.raw.u.v2
cout << "(T3): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << (long)t << endl;
}
else if( !strcmp(type,"T4") )
......@@ -57,21 +55,21 @@ int main( int argc, char **argv )
else if( !strcmp(type,"T5") )
{
T5 t(v1,v2);
cout << "(T5): v1=" << t.raw.u1.v1 << " v2=" << t.raw.u1.v2
cout << "(T5): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
}
else if( !strcmp(type,"T6") )
{
T6 t(v1,v2);
cout << "(T6): v1=" << t.raw.u1.v1 << " v2=" << t.raw.u1.v2
cout << "(T6): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " --> " << t.raw.u2.val << " * 10^" << (int)t.raw.u2.exp
<< " ===> " << t.val << endl;
}
else if( !strcmp(type,"T7") )
{
T7 t(v1,v2);
cout << "(T7): v1=" << t.raw.u1.v1 << " v2=" << t.raw.u1.v2
cout << "(T7): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
// << " --> " << T7.val << " * 10^-4"
<< " ===> " << t.val
<< " [" << ( t.raw.u2.ic == 0xFF ? "CAP" : "IND" ) << "|"
......@@ -81,7 +79,7 @@ int main( int argc, char **argv )
else if( !strcmp(type,"T8") )
{
T8 t(v1,v2);
cout << "(T8): v1=" << t.raw.u1.v1 << " v2=" << t.raw.u1.v2
cout << "(T8): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< " " << setw(2) << t.day() << "/" << setw(2) << t.mon()
......@@ -90,7 +88,7 @@ int main( int argc, char **argv )
else if( !strcmp(type,"T9") )
{
T9 t(v1,v2);
cout << "(T9): v1=" << t.raw.u1.v1 << " v2=" << t.raw.u1.v2
cout << "(T9): v1=" << t.raw.v[0] << " v2=" << t.raw.v[1]
<< " ===> " << setfill('0') << hex
<< setw(2) << t.hour() << ":" << setw(2) << t.min()
<< ":" << setw(2) << t.sec() << "." << setw(2) << t.ssec()
......@@ -99,7 +97,7 @@ int main( int argc, char **argv )
else if( !strcmp(type,"F1") )
{
F1 f(v1,v2);
cout << "(F1): v1=" << f.raw.u.v1 << " v2=" << f.raw.u.v2
cout << "(F1): v1=" << f.raw.v[0] << " v2=" << f.raw.v[1]
<< " ===> " << f.raw.val << endl;
}
else
......
......@@ -2,6 +2,7 @@
uniset-start.sh -f ./uniset-rtuexchange --rs-name RTUExchange --confile test.xml \
--rs-filter-field rs --rs-filter-value 1 \
--rs-dev /dev/cbsideB0 --rs-reg-from-id 1 \
--rs-dev /dev/cbsideA0 --rs-reg-from-id 1 \
--dlog-add-levels info,crit,warn
#level3
// --------------------------------------------------------------------------
//! \version $Id: mtrconv.cc,v 1.2 2009/01/22 02:11:23 vpashka Exp $
// --------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include "UniSetTypes.h"
#include "VTypes.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace VTypes;
// --------------------------------------------------------------------------
static void print_help()
{
printf("Usage: vtconv TYPE[F2|F4] hex1 hex2 [hex3 hex4]\n");
}
// --------------------------------------------------------------------------
int main( int argc, char **argv )
{
VTypes::F2 f2;
f2.raw.val = 2.345;
cout << "Example(F2): float=" << f2.raw.val
<< " regs:"
<< " v[0]=" << f2.raw.v[0]
<< " v[1]=" << f2.raw.v[1]
<< endl;
VTypes::F4 f4;
f4.raw.val = 2.345123123;
cout << "Example(F4): float=" << f4.raw.val
<< " regs:"
<< " v[0]=" << f4.raw.v[0]
<< " v[1]=" << f4.raw.v[1]
<< " v[2]=" << f4.raw.v[2]
<< " v[3]=" << f4.raw.v[3]
<< endl;
cout << "-------------" << endl << endl;
// return 0;
unsigned short v[4];
memset(v,0,sizeof(v));
char* type="";
if( argc<3 )
{
print_help();
return 1;
}
type = argv[1];
v[0] = UniSetTypes::uni_atoi(argv[2]);
if( argc>3 )
v[1] = UniSetTypes::uni_atoi(argv[3]);
if( argc>4 )
v[2] = UniSetTypes::uni_atoi(argv[4]);
if( argc>5 )
v[3] = UniSetTypes::uni_atoi(argv[5]);
if( !strcmp(type,"F2") )
{
VTypes::F2 f(v,sizeof(v));
cout << "(F2): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F4") )
{
VTypes::F4 f(v,sizeof(v));
cout << "(F4): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " v[2]=" << v[2]
<< " v[3]=" << v[3]
<< " --> (float) " << (float)f << endl;
}
else
{
cout << " Unknown type: " << type << endl;
}
return 0;
}
// --------------------------------------------------------------------------
......@@ -411,9 +411,10 @@ 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());
dlog[Debug::INFO] << "(smemory): datfile = " << dfile << endl;
if( dfile[0]!='.' && dfile[0]!='/' )
dfile = conf->getConfDir() + dfile;
dlog[Debug::INFO] << "(smemory): datfile = " << dfile << endl;
UniSetTypes::ObjectId ID = conf->getControllerID(conf->getArgParam("--smemory-id","SharedMemory"));
if( ID == UniSetTypes::DefaultObjectId )
......
#ifndef Calibration_H_
#define Calibration_H_
// -----------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include <string>
#include <list>
#include <ostream>
......
......@@ -81,6 +81,7 @@ static const int NoSafety = -1;
friend std::ostream& operator<<(std::ostream& os, IOBase& inf );
static void processingFasAI( IOBase* it, float new_val, SMInterface* shm, bool force );
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 );
......
// --------------------------------------------------------------------------
//! \version $Id: RTUTypes.h,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// --------------------------------------------------------------------------
#ifndef _RTUTypes_H_
#define _RTUTypes_H_
// -----------------------------------------------------------------------------
#include <string>
#include <cmath>
#include <cstring>
#include <ostream>
#include "modbus/ModbusTypes.h"
// -----------------------------------------------------------------------------
namespace VTypes
{
enum VType
{
vtUnknown,
vtF2,
vtF4
};
std::ostream& operator<<( std::ostream& os, const VType& vt );
// -------------------------------------------------------------------------
std::string type2str( VType t ); /*!< */
VType str2type( const std::string s ); /*!< */
int wsize( VType t ); /*!< */
// -------------------------------------------------------------------------
class F2
{
public:
// ------------------------------------------
static const int f2Size=2;
/*! */
typedef union
{
unsigned short v[f2Size];
float val; //
} F2mem;
// ------------------------------------------
// ...
F2(){ memset(raw.v,0,sizeof(raw.v)); }
F2( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
raw.v[i] = data[i];
}
~F2(){}
// ------------------------------------------
/*! */
static int wsize(){ return f2Size; }
/*! */
static VType type(){ return vtF2; }
// ------------------------------------------
operator float(){ return raw.val; }
operator long(){ return lroundf(raw.val); }
F2mem raw;
};
// --------------------------------------------------------------------------
class F4
{
public:
// ------------------------------------------
static const int f4Size=4;
/*! */
typedef union
{
unsigned short v[f4Size];
float val; //
} F4mem;
// ------------------------------------------
// ...
F4(){ memset(raw.v,0,sizeof(raw.v)); }
F4( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
raw.v[i] = data[i];
}
~F4(){}
// ------------------------------------------
/*! */
static int wsize(){ return f4Size; }
/*! */
static VType type(){ return vtF4; }
// ------------------------------------------
operator float(){ return raw.val; }
operator long(){ return lroundf(raw.val); }
F4mem raw;
};
// --------------------------------------------------------------------------
} // end of namespace VTypes
// --------------------------------------------------------------------------
#endif // _RTUTypes_H_
// -----------------------------------------------------------------------------
// --------------------------------------------------------------------------
/*! $Id: DigitalFilter.cc,v 1.2 2009/01/16 23:16:42 vpashka Exp $ */
// --------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <iostream>
......
......@@ -110,8 +110,8 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
{
if( it->df.size() > 1 )
it->df.add(val);
else
val = it->df.filterRC(val);
val = it->df.filterRC(val);
}
if( it->cdiagram ) //
......@@ -140,7 +140,53 @@ void IOBase::processingAsAI( IOBase* it, long val, SMInterface* shm, bool force
shm->localSetUndefinedState(it->ait,false,it->si.id);
if( it->cal.precision > 0 )
it->value *= lround(pow10(it->cal.precision));
val *= lround(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() );
it->value = val;
}
}
}
// -----------------------------------------------------------------------------
void IOBase::processingFasAI( IOBase* it, float val, SMInterface* shm, bool force )
{
//
if( it->check_channel_break(val) )
{
uniset_spin_lock lock(it->val_lock);
it->value = ChannelBreakValue;
shm->localSetUndefinedState(it->ait,true,it->si.id);
return;
}
// ...
if( !it->nofilter )
{
if( it->df.size() > 1 )
it->df.add(val);
val = it->df.filterRC(val);
}
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);
// "",
//
{
uniset_spin_lock lock(it->val_lock);
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 )
{
......
// --------------------------------------------------------------------------
//! \version $Id: MTR.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// --------------------------------------------------------------------------
#include <math.h>
#include <cmath>
#include "modbus/ModbusRTUMaster.h"
#include "MTR.h"
// --------------------------------------------------------------------------
......@@ -177,7 +177,7 @@ bool setDataBits( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr, mtrDataBits d
return false;
}
// -----------------------------------------------------------------------------
std::string getModeNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr )
std::string getModelNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr )
{
try
{
......
......@@ -2,6 +2,6 @@ lib_LTLIBRARIES = libUniSetExtentions.la
libUniSetExtentions_la_CPPFLAGS = $(SIGC_CFLAGS) -I$(top_builddir)/extentions/include
libUniSetExtentions_la_LIBADD = $(SIGC_LIBS) $(top_builddir)/lib/libUniSet.la
libUniSetExtentions_la_SOURCES = Extentions.cc SMInterface.cc Calibration.cc SingleProcess.cc \
IOBase.cc DigitalFilter.cc PID.cc MTR.cc
IOBase.cc DigitalFilter.cc PID.cc MTR.cc VTypes.cc
#UObject_SK.cc
\ No newline at end of file
// --------------------------------------------------------------------------
//! \version $Id: VType.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// --------------------------------------------------------------------------
#include <cmath>
#include "VTypes.h"
// --------------------------------------------------------------------------
using namespace std;
// --------------------------------------------------------------------------
namespace VTypes
{
std::ostream& operator<<( std::ostream& os, const VType& vt )
{
return os << type2str(vt);
}
VType str2type( const std::string s )
{
if( s == "F2" )
return vtF2;
if( s == "F4" )
return vtF4;
return vtUnknown;
}
// -------------------------------------------------------------------------
string type2str( VType t )
{
if( t == vtF2 )
return "F2";
if( t == vtF4 )
return "F4";
return "vtUnknown";
}
// -------------------------------------------------------------------------
int wsize( VType t )
{
if( t == vtF2 )
return F2::wsize();
if( t == vtF4 )
return F4::wsize();
return 0;
}
// -----------------------------------------------------------------------------
} // end of namespace VTypes
// -----------------------------------------------------------------------------
......@@ -45,7 +45,7 @@ namespace UniSetTypes
LimitTimers():Exception("LimitTimers"){ printException(); }
/*! err */
LimitTimers(const string err):Exception(err){ printException(); }
LimitTimers(const std::string err):Exception(err){ printException(); }
};
};
//@}
......@@ -135,7 +135,7 @@ class CallBackTimer
PassiveTimer pt;
};
typedef list<TimerInfo> TimersList;
typedef std::list<TimerInfo> TimersList;
TimersList lst;
// - id
......
......@@ -28,7 +28,6 @@
#define Configuration_H_
// --------------------------------------------------------------------------
// UniXML.h, unixml !!!!!!!!
#include <string>
#include <ostream>
#include "UniXML.h"
......@@ -39,7 +38,6 @@
#include "Debug.h"
class SystemGuard;
/*
main Configuration
fileConf - ,
......@@ -57,7 +55,7 @@ namespace UniSetTypes
class Configuration
{
public:
virtual ~Configuration();
virtual ~Configuration();
/*! xml- ( ) */
Configuration( int argc, char** argv, const std::string xmlfile="" );
......@@ -78,7 +76,7 @@ namespace UniSetTypes
//
std::string getProp(xmlNode*, const std::string name);
//
std::string getPropByNodeName(const std::string& nodename, const std::string& prop);
std::string getPropByNodeName(const std::string& nodename, const std::string& prop);
static std::ostream& help(std::ostream& os);
......@@ -213,7 +211,7 @@ namespace UniSetTypes
ObjectId localNode;
std::string fileConfName;
std::string imagesDir;
std::string imagesDir;
std::string confDir;
std::string dataDir;
......@@ -239,6 +237,4 @@ namespace UniSetTypes
} // end of UniSetTypes namespace
#endif // Configuration_H_
......@@ -14,11 +14,12 @@
#ifndef DEBUGSTREAM_H
#define DEBUGSTREAM_H
#ifdef __GNUG__
#pragma interface
#endif
//#ifdef __GNUG__
//#pragma interface
//#endif
#include <iostream>
#include <string>
#ifdef TEST_DEBUGSTREAM
#include <string>
......@@ -30,7 +31,7 @@ struct Debug {
CRIT = (1 << 2) // 4
};
static const type ANY = type(INFO | WARN | CRIT);
static Debug::type value(string const & val) {
static Debug::type value(std::string const & val) {
if (val == "NONE") return Debug::NONE;
if (val == "INFO") return Debug::INFO;
if (val == "WARN") return Debug::WARN;
......@@ -113,7 +114,7 @@ public:
/// Sets the debugstreams' logfile to f.
void logFile(char const * f);
inline string getLogFile(){ return fname; }
inline std::string getLogFile(){ return fname; }
/// Returns true if t is part of the current debug level.
bool debugging(Debug::type t = Debug::ANY) const
......@@ -180,7 +181,7 @@ private:
///
debugstream_internal * internal;
bool show_datetime;
string fname;
std::string fname;
};
......
......@@ -35,12 +35,12 @@
class MessageInterface
{
public:
virtual ~MessageInterface(){};
virtual ~MessageInterface(){}
virtual std::string getMessage( UniSetTypes::MessageCode code )=0;
virtual bool isExist(UniSetTypes::MessageCode code)=0;
virtual UniSetTypes::MessageCode getCode( const std::string& msg ){ return UniSetTypes::DefaultMessageCode; };
virtual UniSetTypes::MessageCode getCodeByIdName( const std::string& name ){ return UniSetTypes::DefaultMessageCode; };
virtual UniSetTypes::MessageCode getCode( const std::string& msg ){ return UniSetTypes::DefaultMessageCode; }
virtual UniSetTypes::MessageCode getCodeByIdName( const std::string& name ){ return UniSetTypes::DefaultMessageCode; }
virtual std::ostream& printMessagesMap(std::ostream& os)=0;
};
......
......@@ -18,14 +18,12 @@ class SMonitor:
// -----
protected:
virtual void processingMessage( UniSetTypes::VoidMessage *msg );
virtual void processingMessage( UniSetTypes::VoidMessage *msg );
virtual void sysCommand( UniSetTypes::SystemMessage *sm );
virtual void sensorInfo( UniSetTypes::SensorMessage *si );
virtual void sensorInfo( UniSetTypes::SensorMessage *si );
virtual void timerInfo( UniSetTypes::TimerMessage *tm );
virtual void sigterm( int signo );
SMonitor();
UniSetTypes::IDList explode( const string str, char sep=',' );
private:
UniSetTypes::IDList lst;
......
......@@ -28,13 +28,14 @@
#define UniSetTypes_H_
// --------------------------------------------------------------------------
#include <cstdlib>
#include <cstdio>
#include <string>
#include <list>
#include <limits>
#include <omniORB4/CORBA.h>
#include "UniSetTypes_i.hh"
#include "Mutex.h"
// -----------------------------------------------------------------------------------------
/*! */
inline void msleep( unsigned int m ) { usleep(m*1000); }
......@@ -208,9 +209,12 @@ namespace UniSetTypes
return std::atoi(str);
unsigned int n;
sscanf(str,"%x",&n);
std::sscanf(str,"%x",&n);
return n;
}
IDList explode( const std::string str, char sep=',' );
}
// -----------------------------------------------------------------------------------------
......
......@@ -42,7 +42,7 @@ class UniXML
{
public:
xmlNode* getFirstNode()
inline xmlNode* getFirstNode()
{
return xmlDocGetRootElement(doc);
}
......
......@@ -23,12 +23,13 @@
* \version $Id: UniSetTypes.cc,v 1.4 2009/01/16 23:16:42 vpashka Exp $
*/
// -----------------------------------------------------------------------------
#include <math.h>
#include "Configuration.h"
#include <cmath>
#include "UniSetTypes.h"
#include "Configuration.h"
// -----------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
// -----------------------------------------------------------------------------
float UniSetTypes::fcalibrate( float raw, float rawMin, float rawMax,
float calMin, float calMax, bool limit )
......@@ -162,3 +163,24 @@ using namespace UniSetTypes;
return seq;
}
// -------------------------------------------------------------------------
UniSetTypes::IDList UniSetTypes::explode( const string str, char sep )
{
UniSetTypes::IDList l;
string::size_type prev = 0;
string::size_type pos = 0;
do
{
pos = str.find(sep,prev);
string s(str.substr(prev,pos-prev));
if( !s.empty() )
{
l.add( uni_atoi(s.c_str()) );
prev=pos+1;
}
}
while( pos!=string::npos );
return l;
}
// ------------------------------------------------------------------------------------------
......@@ -25,7 +25,7 @@
// --------------------------------------------------------------------------
//#include <stream.h>
#include <sstream>
#include <math.h>
#include <cmath>
#include "UniversalInterface.h"
#include "IOController.h"
#include "Debug.h"
......
......@@ -20,7 +20,7 @@ SMonitor::SMonitor(ObjectId id):
script("")
{
string sid(conf->getArgParam("--sid"));
lst = explode(sid);
lst = UniSetTypes::explode(sid);
if( lst.empty() )
throw SystemError(" (--sid)");
......@@ -191,25 +191,3 @@ void SMonitor::timerInfo( UniSetTypes::TimerMessage *tm )
}
// ------------------------------------------------------------------------------------------
UniSetTypes::IDList SMonitor::explode( const string str, char sep )
{
UniSetTypes::IDList l;
string::size_type prev = 0;
string::size_type pos = 0;
do
{
pos = str.find(sep,prev);
// cout << "add " << str.substr(prev,pos-prev) << endl;
string s(str.substr(prev,pos-prev));
if( !s.empty() )
{
l.add( uni_atoi(s.c_str()) );
prev=pos+1;
}
}
while( pos!=string::npos );
return l;
}
// ------------------------------------------------------------------------------------------
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