From 46b3372b1aa293d23d29aa58ce1caed195c25560 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Wed, 5 Feb 2003 19:04:53 +0000 Subject: [PATCH] added a couple convenience functions --- comedi_calibrate/calib.h | 20 +++++++++++++------ comedi_calibrate/cb.c | 36 +++++++++++---------------------- comedi_calibrate/save_cal.c | 40 ++++++++++++++++++++++++++++++++++++- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 84f0171..5efa2d2 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -191,30 +191,38 @@ int new_sv_measure(comedi_t *dev, new_sv_t *sv); int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,unsigned int chanspec); /* saving calibrations to file */ -#define CAL_MAX_CHANNELS_LENGTH 128 -#define CAL_MAX_RANGES_LENGTH 128 -#define CAL_MAX_AREFS_LENGTH 16 +#define SC_MAX_CHANNELS_LENGTH 128 +#define SC_MAX_RANGES_LENGTH 128 +#define SC_MAX_AREFS_LENGTH 4 typedef struct { unsigned int subdevice; caldac_t caldacs[ N_CALDACS ]; unsigned int caldacs_length; /* channels that caldac settings are restricted to */ - int channels[ CAL_MAX_CHANNELS_LENGTH ]; + int channels[ SC_MAX_CHANNELS_LENGTH ]; /* number of elements in channels array, 0 means allow all channels */ unsigned int channels_length; /* ranges that caldac settings are restricted to */ - int ranges[ CAL_MAX_RANGES_LENGTH ]; + int ranges[ SC_MAX_RANGES_LENGTH ]; /* number of elements in ranges array, 0 means allow all ranges */ unsigned int ranges_length; /* arefs that caldac settings are used restricted to */ - int arefs[ CAL_MAX_AREFS_LENGTH ]; + int arefs[ SC_MAX_AREFS_LENGTH ]; /* number of elements in arefs array, 0 means allow any aref */ unsigned int arefs_length; } saved_calibration_t; +static const int SC_ALL_CHANNELS = -1; +static const int SC_ALL_RANGES = -1; +static const int SC_ALL_AREFS = -1; + int write_calibration_file( comedi_t *dev, saved_calibration_t settings[], unsigned int num_settings ); +void sc_push_caldac( saved_calibration_t *saved_cal, caldac_t caldac ); +void sc_push_channel( saved_calibration_t *saved_cal, int channel ); +void sc_push_range( saved_calibration_t *saved_cal, int range ); +void sc_push_aref( saved_calibration_t *saved_cal, int aref ); #endif diff --git a/comedi_calibrate/cb.c b/comedi_calibrate/cb.c index 0467b56..25e0b8d 100644 --- a/comedi_calibrate/cb.c +++ b/comedi_calibrate/cb.c @@ -768,32 +768,20 @@ int cal_cb_pci_60xx( calibration_setup_t *setup ) ADC_GAIN_FINE, }; - cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE ); - cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE ); - - cal1( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE ); - cal1_fine( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE ); - - cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE ); - cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE ); - - cal1( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE ); - cal1_fine( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE ); + cal_binary( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_COARSE ); + cal_binary( setup, OBS_0V_RANGE_10V_BIP_60XX, ADC_OFFSET_FINE ); + cal_binary( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_COARSE ); + cal_binary( setup, OBS_5V_RANGE_10V_BIP_60XX, ADC_GAIN_FINE ); + memset( &saved_cals[ 0 ], 0, sizeof( saved_calibration_t ) ); saved_cals[ 0 ].subdevice = setup->ad_subdev; - saved_cals[ 0 ].caldacs_length = 0; - saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] = - setup->caldacs[ ADC_OFFSET_FINE ]; - saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] = - setup->caldacs[ ADC_OFFSET_COARSE ]; - saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] = - setup->caldacs[ ADC_GAIN_COARSE ]; - saved_cals[ 0 ].caldacs[ saved_cals[ 0 ].caldacs_length++ ] = - setup->caldacs[ ADC_GAIN_FINE ]; - saved_cals[ 0 ].channels_length = 0; - saved_cals[ 0 ].ranges[ 0 ] = 0; - saved_cals[ 0 ].ranges_length = 1; - saved_cals[ 0 ].arefs_length = 0; + sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_OFFSET_FINE ] ); + sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_OFFSET_COARSE ] ); + sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_GAIN_FINE ] ); + sc_push_caldac( &saved_cals[ 0 ], setup->caldacs[ ADC_GAIN_COARSE ] ); + sc_push_channel( &saved_cals[ 0 ], SC_ALL_CHANNELS ); + sc_push_range( &saved_cals[ 0 ], 0 ); + sc_push_aref( &saved_cals[ 0 ], SC_ALL_AREFS ); return write_calibration_file( setup->dev, saved_cals, 1 ); } diff --git a/comedi_calibrate/save_cal.c b/comedi_calibrate/save_cal.c index 29ae984..e35605c 100644 --- a/comedi_calibrate/save_cal.c +++ b/comedi_calibrate/save_cal.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include #include @@ -117,7 +118,7 @@ int write_calibration_file( comedi_t *dev, saved_calibration_t settings[], if( fstat( comedi_fileno( dev ), &file_stats ) < 0 ) { - fprintf( stderr, "failed to get dev_t of comedi device file\n" ); + fprintf( stderr, "failed to get file stats of comedi device file\n" ); return -1; } @@ -144,3 +145,40 @@ int write_calibration_file( comedi_t *dev, saved_calibration_t settings[], return retval; } + +void sc_push_caldac( saved_calibration_t *saved_cal, caldac_t caldac ) +{ + assert( saved_cal->caldacs_length < N_CALDACS ); + + saved_cal->caldacs[ saved_cal->caldacs_length++ ] = caldac; +} + +void sc_push_channel( saved_calibration_t *saved_cal, int channel ) +{ + assert( saved_cal->channels_length < SC_MAX_CHANNELS_LENGTH ); + + if( channel == SC_ALL_CHANNELS ) + saved_cal->channels_length = 0; + else + saved_cal->channels[ saved_cal->channels_length++ ] = channel; +} + +void sc_push_range( saved_calibration_t *saved_cal, int range ) +{ + assert( saved_cal->ranges_length < SC_MAX_RANGES_LENGTH ); + + if( range == SC_ALL_RANGES ) + saved_cal->ranges_length = 0; + else + saved_cal->ranges[ saved_cal->ranges_length++ ] = range; +} + +void sc_push_aref( saved_calibration_t *saved_cal, int aref ) +{ + assert( saved_cal->arefs_length < SC_MAX_AREFS_LENGTH ); + + if( aref == SC_ALL_AREFS ) + saved_cal->arefs_length = 0; + else + saved_cal->arefs[ saved_cal->arefs_length++ ] = aref; +}