Commit e216ff95 authored by Pavel Vainerman's avatar Pavel Vainerman

Merge commit 'origin/master'

parents ecd9973a 9860cfce
...@@ -43,41 +43,6 @@ int ComediInterface::getAnalogChannel( int subdev, int channel, int range, int a ...@@ -43,41 +43,6 @@ int ComediInterface::getAnalogChannel( int subdev, int channel, int range, int a
return data; 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 ) void ComediInterface::setAnalogChannel( int subdev, int channel, int data, int range, int aref )
throw(UniSetTypes::Exception) throw(UniSetTypes::Exception)
{ {
...@@ -117,41 +82,6 @@ void ComediInterface::setDigitalChannel( int subdev, int channel, bool bit ) ...@@ -117,41 +82,6 @@ void ComediInterface::setDigitalChannel( int subdev, int channel, bool bit )
throw Exception(err.str()); 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, void ComediInterface::configureChannel( int subdev, int channel, ChannelType t,
int range, int aref ) int range, int aref )
...@@ -209,39 +139,21 @@ void ComediInterface::configureChannel( int subdev, int channel, ChannelType t, ...@@ -209,39 +139,21 @@ void ComediInterface::configureChannel( int subdev, int channel, ChannelType t,
void ComediInterface::configureSubdev( int subdev, SubdevType t ) void ComediInterface::configureSubdev( int subdev, SubdevType t )
throw(UniSetTypes::Exception) 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 = 102;
lsampl_t cmd[4]; /* Ports A, B, CL, CH */
comedi_insn insn; comedi_insn insn;
memset(&insn,0,sizeof(insn));
switch(t) 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: ostringstream err;
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_INPUT; err << "(ComediInterface:configureSubdev): can`t configure subdev "
break; << " subdev=" << subdev << " type=" << t;
case TBI0_24: throw Exception(err.str());
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());
}
} }
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -279,46 +191,3 @@ ComediInterface::SubdevType ComediInterface::str2type( const std::string s ) ...@@ -279,46 +191,3 @@ ComediInterface::SubdevType ComediInterface::str2type( const std::string s )
return Unknown; 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 @@ ...@@ -4,9 +4,7 @@
#define ComediInterface_H_ #define ComediInterface_H_
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <string> #include <string>
#include <vector>
#include <comedilib.h> #include <comedilib.h>
#include <fastwel.h>
#include "Exceptions.h" #include "Exceptions.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*! / */ /*! / */
...@@ -19,9 +17,6 @@ class ComediInterface ...@@ -19,9 +17,6 @@ class ComediInterface
int getAnalogChannel( int subdev, int channel, int range=0, int aref=AREF_GROUND ) int getAnalogChannel( int subdev, int channel, int range=0, int aref=AREF_GROUND )
throw(UniSetTypes::Exception); 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 ) void setAnalogChannel( int subdev, int channel, int data, int range=0, int aref=AREF_GROUND )
throw(UniSetTypes::Exception); throw(UniSetTypes::Exception);
...@@ -37,10 +32,10 @@ class ComediInterface ...@@ -37,10 +32,10 @@ class ComediInterface
{ {
DI = INSN_CONFIG_DIO_INPUT, DI = INSN_CONFIG_DIO_INPUT,
DO = INSN_CONFIG_DIO_OUTPUT, DO = INSN_CONFIG_DIO_OUTPUT,
AI = INSN_CONFIG_AIO_INPUT, AI = 100, // INSN_CONFIG_AIO_INPUT,
AO = INSN_CONFIG_AIO_OUTPUT AO = 101 // INSN_CONFIG_AIO_OUTPUT
}; };
enum SubdevType enum SubdevType
{ {
Unknown = 0, Unknown = 0,
...@@ -48,31 +43,18 @@ class ComediInterface ...@@ -48,31 +43,18 @@ class ComediInterface
TBI0_24 = 2, TBI0_24 = 2,
TBI16_8 = 3 TBI16_8 = 3
}; };
enum EventType
{
No = 0,
Front = 1,
Rear = 2,
FrontThenRear = 3
};
static std::string type2str( SubdevType t ); static std::string type2str( SubdevType t );
static SubdevType str2type( const std::string s ); 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 configureSubdev( int subdev, SubdevType type ) throw(UniSetTypes::Exception);
void configureChannel( int subdev, int channel, ChannelType type, int range=0, int aref=0 ) void configureChannel( int subdev, int channel, ChannelType type, int range=0, int aref=0 )
throw(UniSetTypes::Exception); 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; } inline const std::string devname(){ return dname; }
protected: protected:
comedi_t* card; /*!< / */ comedi_t* card; /*!< / */
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <comedilib.h> #include <comedilib.h>
#include <fastwel.h>
#include <getopt.h> #include <getopt.h>
int subdev = 0; int subdev = 0;
...@@ -17,7 +16,6 @@ static struct option longopts[] = { ...@@ -17,7 +16,6 @@ static struct option longopts[] = {
{ "read", required_argument, 0, 'r' }, { "read", required_argument, 0, 'r' },
{ "write", required_argument, 0, 'w' }, { "write", required_argument, 0, 'w' },
{ "aread", required_argument, 0, 'i' }, { "aread", required_argument, 0, 'i' },
{ "anread", required_argument, 0, 'n' },
{ "awrite", required_argument, 0, 'o' }, { "awrite", required_argument, 0, 'o' },
{ "subdev", required_argument, 0, 's' }, { "subdev", required_argument, 0, 's' },
{ "device", required_argument, 0, 'd' }, { "device", required_argument, 0, 'd' },
...@@ -25,9 +23,6 @@ static struct option longopts[] = { ...@@ -25,9 +23,6 @@ static struct option longopts[] = {
{ "aref", required_argument, 0, 'z' }, { "aref", required_argument, 0, 'z' },
{ "range", required_argument, 0, 'x' }, { "range", required_argument, 0, 'x' },
{ "config", required_argument, 0, 'c' }, { "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' }, { "autoconf", no_argument, 0, 'a' },
{ "plus", required_argument, 0, 'p' }, { "plus", required_argument, 0, 'p' },
{ "blink", no_argument, 0, 'b' }, { "blink", no_argument, 0, 'b' },
...@@ -44,22 +39,18 @@ enum Command ...@@ -44,22 +39,18 @@ enum Command
cmdARead, cmdARead,
cmdAWrite, cmdAWrite,
cmdConfig, cmdConfig,
cmdSubConfig, cmdSubConfig
cmdAnRead,
cmdExtConfig,
cmdTimer
} cmd; } cmd;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
static void insn_config( comedi_t* card, int subdev, int channel, lsampl_t iotype, int range, int aref ); 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_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[]) int main(int argc, char* argv[])
{ {
comedi_t* card; comedi_t* card;
lsampl_t data = 0; lsampl_t data = 0;
lsampl_t darr[20];
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
char* dev = "/dev/comedi0"; char* dev = "/dev/comedi0";
...@@ -70,14 +61,10 @@ int main(int argc, char* argv[]) ...@@ -70,14 +61,10 @@ int main(int argc, char* argv[])
int cnum = 0; int cnum = 0;
int blink = 0; int blink = 0;
int exret = EXIT_SUCCESS; int exret = EXIT_SUCCESS;
int instruction;
int autoscan = 0;
int n_data;
memset(chan,-1,sizeof(chan)); 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) switch (opt)
{ {
...@@ -87,7 +74,6 @@ int main(int argc, char* argv[]) ...@@ -87,7 +74,6 @@ int main(int argc, char* argv[])
printf("[-r|--read] chan - read from digital channel\n"); printf("[-r|--read] chan - read from digital channel\n");
printf("[-o|--awrite] chan val - write to analog channel\n"); printf("[-o|--awrite] chan val - write to analog channel\n");
printf("[-i|--aread] chan - read from 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("[-s|--subdev] sub - use subdev number sub. (Default: 0)\n");
printf("[-d|--device] dev - use device dev. (Default: /dev/comedi0)\n"); printf("[-d|--device] dev - use device dev. (Default: /dev/comedi0)\n");
printf("[--aref] val - AREF (Default: %d)\n",aref); printf("[--aref] val - AREF (Default: %d)\n",aref);
...@@ -108,14 +94,11 @@ int main(int argc, char* argv[]) ...@@ -108,14 +94,11 @@ int main(int argc, char* argv[])
printf(" 1 - -5 - 5\n"); printf(" 1 - -5 - 5\n");
printf(" 2 - -2.5 - 2.5\n"); printf(" 2 - -2.5 - 2.5\n");
printf(" 3 - -1.25 - 1.25\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] - (blink output): ONLY FOR 'write': 0-1-0-1-0-...\n");
printf("[--blink-msec] val - Blink pause [msec]. Default: 300 msec\n"); printf("[--blink-msec] val - Blink pause [msec]. Default: 300 msec\n");
return 0; return 0;
case 'r': case 'r':
chan[0] = atoi(optarg); chan[0] = atoi(optarg);
cmd = cmdDRead; cmd = cmdDRead;
break; break;
...@@ -127,16 +110,7 @@ int main(int argc, char* argv[]) ...@@ -127,16 +110,7 @@ int main(int argc, char* argv[])
val = atoi(argv[optind]); val = atoi(argv[optind]);
break; break;
case 'n': case 'i':
chan[0] = atoi(optarg);
cmd = cmdAnRead;
break;
case 'u':
autoscan = 1;
break;
case 'i':
chan[0] = atoi(optarg); chan[0] = atoi(optarg);
cmd = cmdARead; cmd = cmdARead;
break; break;
...@@ -148,23 +122,7 @@ int main(int argc, char* argv[]) ...@@ -148,23 +122,7 @@ int main(int argc, char* argv[])
val = atoi(argv[optind]); val = atoi(argv[optind]);
break; break;
case 'e': case 'd':
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':
dev = optarg; dev = optarg;
break; break;
...@@ -239,6 +197,12 @@ int main(int argc, char* argv[]) ...@@ -239,6 +197,12 @@ int main(int argc, char* argv[])
{ {
for( int k=0; chan[k]!=-1; k++ ) 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) if( comedi_dio_read(card, subdev, chan[k],&data) < 0)
{ {
fprintf(stderr, "can't read from channel %d\n",chan[k]); fprintf(stderr, "can't read from channel %d\n",chan[k]);
...@@ -252,6 +216,14 @@ int main(int argc, char* argv[]) ...@@ -252,6 +216,14 @@ int main(int argc, char* argv[])
case cmdDWrite: 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) while(1)
{ {
...@@ -295,35 +267,6 @@ int main(int argc, char* argv[]) ...@@ -295,35 +267,6 @@ int main(int argc, char* argv[])
} }
break; 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: case cmdAWrite:
{ {
for( int k=0; chan[k]!=-1; k++ ) for( int k=0; chan[k]!=-1; k++ )
...@@ -346,10 +289,10 @@ int main(int argc, char* argv[]) ...@@ -346,10 +289,10 @@ int main(int argc, char* argv[])
for( int k=0; chan[k]!=-1; k++ ) for( int k=0; chan[k]!=-1; k++ )
{ {
if( val != INSN_CONFIG_DIO_INPUT if( val != INSN_CONFIG_DIO_INPUT
&& val != INSN_CONFIG_DIO_OUTPUT && val != INSN_CONFIG_DIO_OUTPUT
&& val != INSN_CONFIG_AIO_INPUT && val != 100 /* INSN_CONFIG_AIO_INPUT */
&& val != INSN_CONFIG_AIO_OUTPUT && val != 101 /* INSN_CONFIG_AIO_OUTPUT */
) )
{ {
fprintf(stderr, "can't config channel %d for type = %d (val=[%d,%d,%d,%d])\n" 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[]) ...@@ -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: case cmdSubConfig:
insn_subdev_config(card, subdev, val); insn_subdev_config(card, subdev, val);
...@@ -429,38 +333,38 @@ void insn_config( comedi_t* card, int subdev, int channel, lsampl_t iotype, int ...@@ -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 ) 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 = 102;
lsampl_t cmd[4]; /* Ports A, B, CL, CH */
comedi_insn insn; 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) switch(type)
{ {
case 1: /* TBI 24_0 */ case 1:
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_INPUT;
printf("set subdev %d type: 'TBI 24/0'\n",subdev); printf("set subdev %d type: 'TBI 24/0'\n",subdev);
break; break;
case 2: /* TBI 0_24 */
default: case 2:
cmd[0] = cmd[1] = cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
printf("set subdev %d type: 'TBI 0/24'\n",subdev); printf("set subdev %d type: 'TBI 0/24'\n",subdev);
break; break;
case 3: /* TBI 16_8 */
cmd[0] = cmd[1] = INSN_CONFIG_DIO_INPUT; case 3:
cmd[2] = cmd[3] = INSN_CONFIG_DIO_OUTPUT;
printf("set subdev %d type: 'TBI 16/8'\n",subdev); 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++) { if( comedi_do_insn(card,&insn) < 0 )
memset(&insn,0,sizeof(insn)); {
insn.insn = INSN_CONFIG; fprintf(stderr, "can`t configure subdev subdev=%d type=%d",subdev,type);
insn.n = 1; exit(EXIT_FAILURE);
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);
}
} }
} }
// $Id: MBMaster.cc,v 1.11 2009/03/03 10:33:27 pv Exp $ // $Id: MBMaster.cc,v 1.11 2009/03/03 10:33:27 pv Exp $
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <sstream> #include <sstream>
#include "Exceptions.h" #include "Exceptions.h"
#include "Extentions.h" #include "Extentions.h"
......
// $Id: MBSlave.cc,v 1.1 2009/01/11 19:08:45 vpashka Exp $ // $Id: MBSlave.cc,v 1.1 2009/01/11 19:08:45 vpashka Exp $
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <sstream> #include <sstream>
#include "Exceptions.h" #include "Exceptions.h"
#include "Extentions.h" #include "Extentions.h"
......
// $Id: RTUExchange.cc,v 1.4 2009/01/23 23:56:54 vpashka Exp $ // $Id: RTUExchange.cc,v 1.4 2009/01/23 23:56:54 vpashka Exp $
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <sstream> #include <sstream>
#include "Exceptions.h" #include "Exceptions.h"
#include "Extentions.h" #include "Extentions.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
//! \version $Id: RTUStorage.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $ //! \version $Id: RTUStorage.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <string> #include <string>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <math.h> #include <cmath>
#include "Configuration.h" #include "Configuration.h"
#include "MTR.h" #include "MTR.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
#ifndef Calibration_H_ #ifndef Calibration_H_
#define Calibration_H_ #define Calibration_H_
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <string> #include <string>
#include <list> #include <list>
#include <ostream> #include <ostream>
......
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/*! $Id: DigitalFilter.cc,v 1.2 2009/01/16 23:16:42 vpashka Exp $ */ /*! $Id: DigitalFilter.cc,v 1.2 2009/01/16 23:16:42 vpashka Exp $ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include <iomanip> #include <iomanip>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
......
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
//! \version $Id: MTR.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $ //! \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 "modbus/ModbusRTUMaster.h"
#include "MTR.h" #include "MTR.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
...@@ -45,7 +45,7 @@ namespace UniSetTypes ...@@ -45,7 +45,7 @@ namespace UniSetTypes
LimitTimers():Exception("LimitTimers"){ printException(); } LimitTimers():Exception("LimitTimers"){ printException(); }
/*! err */ /*! err */
LimitTimers(const string err):Exception(err){ printException(); } LimitTimers(const std::string err):Exception(err){ printException(); }
}; };
}; };
//@} //@}
...@@ -135,7 +135,7 @@ class CallBackTimer ...@@ -135,7 +135,7 @@ class CallBackTimer
PassiveTimer pt; PassiveTimer pt;
}; };
typedef list<TimerInfo> TimersList; typedef std::list<TimerInfo> TimersList;
TimersList lst; TimersList lst;
// - id // - id
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#define Configuration_H_ #define Configuration_H_
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// UniXML.h, unixml !!!!!!!! // UniXML.h, unixml !!!!!!!!
#include <string> #include <string>
#include <ostream> #include <ostream>
#include "UniXML.h" #include "UniXML.h"
...@@ -39,7 +38,6 @@ ...@@ -39,7 +38,6 @@
#include "Debug.h" #include "Debug.h"
class SystemGuard; class SystemGuard;
/* /*
main Configuration main Configuration
fileConf - , fileConf - ,
...@@ -57,7 +55,7 @@ namespace UniSetTypes ...@@ -57,7 +55,7 @@ namespace UniSetTypes
class Configuration class Configuration
{ {
public: public:
virtual ~Configuration(); virtual ~Configuration();
/*! xml- ( ) */ /*! xml- ( ) */
Configuration( int argc, char** argv, const std::string xmlfile="" ); Configuration( int argc, char** argv, const std::string xmlfile="" );
...@@ -78,7 +76,7 @@ namespace UniSetTypes ...@@ -78,7 +76,7 @@ namespace UniSetTypes
// //
std::string getProp(xmlNode*, const std::string name); 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); static std::ostream& help(std::ostream& os);
...@@ -213,7 +211,7 @@ namespace UniSetTypes ...@@ -213,7 +211,7 @@ namespace UniSetTypes
ObjectId localNode; ObjectId localNode;
std::string fileConfName; std::string fileConfName;
std::string imagesDir; std::string imagesDir;
std::string confDir; std::string confDir;
std::string dataDir; std::string dataDir;
...@@ -239,6 +237,4 @@ namespace UniSetTypes ...@@ -239,6 +237,4 @@ namespace UniSetTypes
} // end of UniSetTypes namespace } // end of UniSetTypes namespace
#endif // Configuration_H_ #endif // Configuration_H_
...@@ -14,11 +14,12 @@ ...@@ -14,11 +14,12 @@
#ifndef DEBUGSTREAM_H #ifndef DEBUGSTREAM_H
#define DEBUGSTREAM_H #define DEBUGSTREAM_H
#ifdef __GNUG__ //#ifdef __GNUG__
#pragma interface //#pragma interface
#endif //#endif
#include <iostream> #include <iostream>
#include <string>
#ifdef TEST_DEBUGSTREAM #ifdef TEST_DEBUGSTREAM
#include <string> #include <string>
...@@ -30,7 +31,7 @@ struct Debug { ...@@ -30,7 +31,7 @@ struct Debug {
CRIT = (1 << 2) // 4 CRIT = (1 << 2) // 4
}; };
static const type ANY = type(INFO | WARN | CRIT); 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 == "NONE") return Debug::NONE;
if (val == "INFO") return Debug::INFO; if (val == "INFO") return Debug::INFO;
if (val == "WARN") return Debug::WARN; if (val == "WARN") return Debug::WARN;
...@@ -113,7 +114,7 @@ public: ...@@ -113,7 +114,7 @@ public:
/// Sets the debugstreams' logfile to f. /// Sets the debugstreams' logfile to f.
void logFile(char const * 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. /// Returns true if t is part of the current debug level.
bool debugging(Debug::type t = Debug::ANY) const bool debugging(Debug::type t = Debug::ANY) const
...@@ -180,7 +181,7 @@ private: ...@@ -180,7 +181,7 @@ private:
/// ///
debugstream_internal * internal; debugstream_internal * internal;
bool show_datetime; bool show_datetime;
string fname; std::string fname;
}; };
......
...@@ -35,12 +35,12 @@ ...@@ -35,12 +35,12 @@
class MessageInterface class MessageInterface
{ {
public: public:
virtual ~MessageInterface(){}; virtual ~MessageInterface(){}
virtual std::string getMessage( UniSetTypes::MessageCode code )=0; virtual std::string getMessage( UniSetTypes::MessageCode code )=0;
virtual bool isExist(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 getCode( const std::string& msg ){ return UniSetTypes::DefaultMessageCode; }
virtual UniSetTypes::MessageCode getCodeByIdName( const std::string& name ){ return UniSetTypes::DefaultMessageCode; }; virtual UniSetTypes::MessageCode getCodeByIdName( const std::string& name ){ return UniSetTypes::DefaultMessageCode; }
virtual std::ostream& printMessagesMap(std::ostream& os)=0; virtual std::ostream& printMessagesMap(std::ostream& os)=0;
}; };
......
...@@ -18,14 +18,12 @@ class SMonitor: ...@@ -18,14 +18,12 @@ class SMonitor:
// ----- // -----
protected: protected:
virtual void processingMessage( UniSetTypes::VoidMessage *msg ); virtual void processingMessage( UniSetTypes::VoidMessage *msg );
virtual void sysCommand( UniSetTypes::SystemMessage *sm ); 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 timerInfo( UniSetTypes::TimerMessage *tm );
virtual void sigterm( int signo ); virtual void sigterm( int signo );
SMonitor(); SMonitor();
UniSetTypes::IDList explode( const string str, char sep=',' );
private: private:
UniSetTypes::IDList lst; UniSetTypes::IDList lst;
......
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
#define UniSetTypes_H_ #define UniSetTypes_H_
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#include <cstdlib> #include <cstdlib>
#include <cstdio>
#include <string> #include <string>
#include <list> #include <list>
#include <limits> #include <limits>
#include <omniORB4/CORBA.h> #include <omniORB4/CORBA.h>
#include "UniSetTypes_i.hh" #include "UniSetTypes_i.hh"
#include "Mutex.h" #include "Mutex.h"
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
/*! */ /*! */
inline void msleep( unsigned int m ) { usleep(m*1000); } inline void msleep( unsigned int m ) { usleep(m*1000); }
...@@ -208,9 +209,12 @@ namespace UniSetTypes ...@@ -208,9 +209,12 @@ namespace UniSetTypes
return std::atoi(str); return std::atoi(str);
unsigned int n; unsigned int n;
sscanf(str,"%x",&n);
std::sscanf(str,"%x",&n);
return n; return n;
} }
IDList explode( const std::string str, char sep=',' );
} }
// ----------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------
......
...@@ -42,7 +42,7 @@ class UniXML ...@@ -42,7 +42,7 @@ class UniXML
{ {
public: public:
xmlNode* getFirstNode() inline xmlNode* getFirstNode()
{ {
return xmlDocGetRootElement(doc); return xmlDocGetRootElement(doc);
} }
......
...@@ -23,12 +23,13 @@ ...@@ -23,12 +23,13 @@
* \version $Id: UniSetTypes.cc,v 1.4 2009/01/16 23:16:42 vpashka Exp $ * \version $Id: UniSetTypes.cc,v 1.4 2009/01/16 23:16:42 vpashka Exp $
*/ */
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <math.h> #include <cmath>
#include "Configuration.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "Configuration.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
float UniSetTypes::fcalibrate( float raw, float rawMin, float rawMax, float UniSetTypes::fcalibrate( float raw, float rawMin, float rawMax,
float calMin, float calMax, bool limit ) float calMin, float calMax, bool limit )
...@@ -162,3 +163,24 @@ using namespace UniSetTypes; ...@@ -162,3 +163,24 @@ using namespace UniSetTypes;
return seq; 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 @@ ...@@ -25,7 +25,7 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
//#include <stream.h> //#include <stream.h>
#include <sstream> #include <sstream>
#include <math.h> #include <cmath>
#include "UniversalInterface.h" #include "UniversalInterface.h"
#include "IOController.h" #include "IOController.h"
#include "Debug.h" #include "Debug.h"
......
...@@ -191,25 +191,3 @@ void SMonitor::timerInfo( UniSetTypes::TimerMessage *tm ) ...@@ -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