diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5647ba3fff89342046b3003602187df893325887 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.nse_depinfo* +bin/ +obj/ +*~ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..162403554bfa47c17114180b138c00f845e63026 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/vmeauxclasses"] + path = deps/vmeauxclasses + url = https://gitlab.elettra.eu/cs/cls/vmeauxclasses.git diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5d7ef1cdf093cbdce8574c8e9eefe73129851cdb --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +NAME_SRV = rfinp-srv + +SRC_FILES = $(wildcard deps/vmeauxclasses/src/*.cpp) +CXXFLAGS = -Ideps/vmeauxclasses/src +LDFLAGS = + +include ../makefiles/Make-9.3.4.in diff --git a/README.md b/README.md index 9276626e8514d0689d7cb43ab3c976dd2c5fdc6c..411792bca2c65ea897d6d386a238c6a07e4e2d34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,2 @@ -# rfinput - -Elettra RF input +# input diff --git a/deps/vmeauxclasses b/deps/vmeauxclasses new file mode 160000 index 0000000000000000000000000000000000000000..7d041e7d941e80523c03058e0413eeff6a9cc8bb --- /dev/null +++ b/deps/vmeauxclasses @@ -0,0 +1 @@ +Subproject commit 7d041e7d941e80523c03058e0413eeff6a9cc8bb diff --git a/old-src/chrfinp.h b/old-src/chrfinp.h new file mode 100644 index 0000000000000000000000000000000000000000..5b0d76e02fa91908df638c30da84ea6b5169ceb3 --- /dev/null +++ b/old-src/chrfinp.h @@ -0,0 +1,52 @@ +/* + * chrfinp.h + * + * include file for RF ramping device server + * + * + */ + +/* max number of call-routines in the server */ +#define N_AM 9 + +/* loop parameters */ +#define N_LOOPS 2 /* number of loops in server, see after */ +#define VLT_RAMP 0 /* loop index of voltage ramp */ +#define FAST_RAMP 1 /* loop index of voltage fast ramp */ +#define RAMP_TICKS 10 /* loop ticks */ + +#define RAMP_MSK 0x2 /* mask used to set "ramp running" bit in status call */ + +typedef char devname_t[20]; /* type for device name */ + +/* ADIO (adc/dac) structure channel */ +typedef struct adioch_s { + double a, /* calibration parameters: ax^3 + bx^2 + cx + d */ + b, + c, + d, + min, /* min voltage value */ + max; /* max voltage value */ +} adioch_t; + +/* RF voltage ramping resources structure */ +typedef struct adio_s{ + devname_t devname; /* device name */ + double max_vel, + max_fast_ramp; + int fast_time; /* sec. */ + unsigned short in_mask, /* inputs definition */ + enable_mask; /* enable command mask */ + adioch_t adc, + dac, + dac_set; +} adio_t; + +/* + * resource struct definition + */ +typedef struct { + adio_t adio; /* one ADIO */ +} resource_type; + +/* EOF */ diff --git a/old-src/cmrfinp.c b/old-src/cmrfinp.c new file mode 100644 index 0000000000000000000000000000000000000000..5d043199c03cc8237e27685f92125eafdd0548e1 --- /dev/null +++ b/old-src/cmrfinp.c @@ -0,0 +1,900 @@ +/* + * cmrfinp.c + * + * Device server specific code for RF ramping control boards. + * + * 12.03.2003 - GG: first implementation + */ + +/* + * system includes + */ +#include <setsys.h> +#include <stdio.h> +#include <math.h> /* for fabs() */ +#include <module.h> +#include <modes.h> +#include <stdlib.h> /* for atoi() */ +#include <string.h> /* for strcmp() */ +#include <errno.h> + +/* + * elettra includes + */ +#include <cherrs.h> /* error numbers */ +#include <cherrt.h> /* error types */ +#include "chlogs.h" /* logging funcs */ +#include "chmodule.h" + +/* + * felix includes + */ +#include "chdevsrv.h" /* generic device server stuff */ +#include "chgetres.h" /* resource reading stuff */ + +/* + * driver includes + */ +#include "chadio.h" /* ioctl codes */ + +/* + * device server includes + */ +#include "chrfinp.h" /* specific device server stuff */ + + +/* + * global vars + */ +resource_type resources; +short start_vlt, end_vlt; +int start_time, end_time; /* loop starting and ending time in ticks */ +int enable_flag = 0; +int start_time_fast,end_time_fast; +short end_vlt_fast = 0; +int delta; + +/* + * vars from generic part + */ +extern char loc_msg[200]; +extern srvmod_type *srv_mod; /* pointer to server module data structure */ +extern loop_type *loop_var; +extern call_type *call_pnt; +extern str_typ res_err; /* resource reading global error string */ + +/* + * function prototypes + */ +void iniz_hw(void); /* HW initializations */ +void iniz_sw(void); /* SW initializations */ +int check_enable(void); /* check if enabled */ +void felix_terminat(int); /* specific part resources deallocation */ +void go_on_loop(int); /* server loops stuff */ +void go_on_loop0(void); /* voltage ramping loop */ +void go_on_loop0(void); /* fast ramping loop */ +int read_resources(char *); /* routine di lettura delle risorse */ + +/* + * server routines + */ +void abort_wp(void); /* abort ramping */ +void vlt_rr(void); /* read cavity voltage */ +void vltset_rr(void); /* read cavity voltage setting */ +void linrmp_wrrr(void); /* start voltage ramp */ +void fstrmp_wp(void); /* start fast ramp */ +void dvlt_wr(void); /* set cavity voltage (DANGEROUS) */ +void enable_wb(void); /* enable power */ +void stat_rf(void); /* read status (enable/ramping) */ +void limits_rr(void); /* read limits */ + +/* + * action mode table + */ +act_mod_typ amtab[] = { + "ABORT", "WP", abort_wp, /* 1 */ + "VLT", "RR", vlt_rr, /* 2 */ + "VLTSET", "RR", vltset_rr, /* 3 */ + "LINRMP", "WRRR", linrmp_wrrr, /* 4 */ + "FSTRMP", "WP", fstrmp_wp, /* 5 */ + "DVLT", "WR", dvlt_wr, /* 6 */ + "ENABLE", "WB", enable_wb, /* 7 */ + "STAT", "RF", stat_rf, /* 8 */ + "LIMITS", "RR", limits_rr /* 9 */ +}; + +/* + * felix_terminat() + * specific part resources deallocation + */ +void felix_terminat(int sig) +{ + return; +} + + +/* + * read_resources() + * open and read the resources file + */ +int read_resources(char *filename) +{ + int i; + + if (read_res(filename) < 0) { + printf("%s: cannot read resource file %s\n", \ + gettime(), filename); + return -1; /* some file handling error? */ + } + + if (get_res(resources.adio.devname, "adio.devname", STRING) || \ + get_res(&resources.adio.in_mask, "adio.in_mask", USHORT) || \ + get_res(&resources.adio.enable_mask,"adio.enable_mask", USHORT) || \ + get_res(&resources.adio.dac.a, "adio.dac.a", DOUBLE) || \ + get_res(&resources.adio.dac.b, "adio.dac.b", DOUBLE) || \ + get_res(&resources.adio.dac.c, "adio.dac.c", DOUBLE) || \ + get_res(&resources.adio.dac.d, "adio.dac.d", DOUBLE) || \ + get_res(&resources.adio.dac.min, "adio.dac.min", DOUBLE) || \ + get_res(&resources.adio.dac.max, "adio.dac.max", DOUBLE) || \ + get_res(&resources.adio.dac_set.a, "adio.dac_set.a", DOUBLE) || \ + get_res(&resources.adio.dac_set.b, "adio.dac_set.b", DOUBLE) || \ + get_res(&resources.adio.dac_set.c, "adio.dac_set.c", DOUBLE) || \ + get_res(&resources.adio.dac_set.d, "adio.dac_set.d", DOUBLE) || \ + get_res(&resources.adio.dac_set.min, "adio.dac_set.min", DOUBLE) || \ + get_res(&resources.adio.dac_set.max, "adio.dac_set.max", DOUBLE) || \ + get_res(&resources.adio.adc.a, "adio.adc.a", DOUBLE) || \ + get_res(&resources.adio.adc.b, "adio.adc.b", DOUBLE) || \ + get_res(&resources.adio.adc.c, "adio.adc.c", DOUBLE) || \ + get_res(&resources.adio.adc.d, "adio.adc.d", DOUBLE) || \ + get_res(&resources.adio.adc.min, "adio.adc.min", DOUBLE) || \ + get_res(&resources.adio.adc.max, "adio.adc.max", DOUBLE) || \ + get_res(&resources.adio.max_vel, "adio.max_vel", DOUBLE) || \ + get_res(&resources.adio.max_fast_ramp, "adio.max_fast_ramp", DOUBLE) || \ + get_res(&resources.adio.fast_time, "adio.fast_time", INTEGER)) { + return -1; + } + +#ifdef DEBUGRES + fprintf(stderr, "adio.devname = %s\n", resources.adio.devname); + fprintf(stderr, "adio.in_mask = 0x%x\n", resources.adio.in_mask); + fprintf(stderr, "adio.enable_mask = 0x%x\n", resources.adio.enable_mask); + fprintf(stderr, "adio.dac.a = %f\n", resources.adio.dac.a); + fprintf(stderr, "adio.dac.b = %f\n", resources.adio.dac.b); + fprintf(stderr, "adio.dac.c = %f\n", resources.adio.dac.c); + fprintf(stderr, "adio.dac.d = %f\n", resources.adio.dac.d); + fprintf(stderr, "adio.dac.min = %f\n", resources.adio.dac.min); + fprintf(stderr, "adio.dac.max = %f\n", resources.adio.dac.max); + fprintf(stderr, "adio.dac_set.a = %f\n", resources.adio.dac_set.a); + fprintf(stderr, "adio.dac_set.b = %f\n", resources.adio.dac_set.b); + fprintf(stderr, "adio.dac_set.c = %f\n", resources.adio.dac_set.c); + fprintf(stderr, "adio.dac_set.d = %f\n", resources.adio.dac_set.d); + fprintf(stderr, "adio.dac_set.min = %f\n", resources.adio.dac_set.min); + fprintf(stderr, "adio.dac_set.max = %f\n", resources.adio.dac_set.max); + fprintf(stderr, "adio.adc.a = %f\n", resources.adio.adc.a); + fprintf(stderr, "adio.adc.b = %f\n", resources.adio.adc.b); + fprintf(stderr, "adio.adc.c = %f\n", resources.adio.adc.c); + fprintf(stderr, "adio.adc.d = %f\n", resources.adio.adc.d); + fprintf(stderr, "adio.adc.min = %f\n", resources.adio.adc.min); + fprintf(stderr, "adio.adc.max = %f\n", resources.adio.adc.max); + fprintf(stderr, "adio.max_vel = %f\n", resources.adio.max_vel); + fprintf(stderr, "adio.max_fast_ramp = %f\n", resources.adio.max_fast_ramp); + fprintf(stderr, "adio.fast_time = %d\n", resources.adio.fast_time); + +#endif + free_res(); /* free memory */ + + return 0; + +} /* end read_resources() */ + + +/* + * iniz_hw() + * hardware inizialization + */ +void iniz_hw(void) +{ + /* define the digital inputs */ + if (equip(resources.adio.devname, ADIO_DIGIT, \ + (char *)&resources.adio.in_mask)) { + printf("%s: error during initialization: dev= %s, errno= %d\n", \ + gettime(), resources.adio.devname, errno); + die(errno); + } + +} /* end iniz_hw() */ + + +/* + * iniz_sw() + * Software inizialization + */ +void iniz_sw(void) +{ + int int_val; + double double_vlt; + + /* calculate the last value to set on the DAC during fast ramp */ + double_vlt = resources.adio.max_fast_ramp; + double_vlt = double_vlt * double_vlt * double_vlt * resources.adio.dac.a + \ + double_vlt * double_vlt * resources.adio.dac.b + \ + double_vlt * resources.adio.dac.c + \ + resources.adio.dac.d; + /* rounding */ + if (double_vlt >= 0) + int_val = (int)(double_vlt + 0.5); + else + int_val = (int)(double_vlt - 0.5); + + /* if values overcome the hard limits set the limits */ + if (int_val > ADIO_HIGHTHR) + end_vlt_fast = ADIO_HIGHTHR; + else if (int_val < -ADIO_LOWTHR) + end_vlt_fast = -ADIO_LOWTHR; + else + end_vlt_fast = (short)int_val; + +} /* end iniz_sw() */ + + +/* + * check_enable() + * Check if enabled (to change voltage) + */ +int check_enable(void) +{ + short s_data; + + /* read the status from ADIO */ + if (equip(resources.adio.devname, ADIO_DIGIN , (char *)&s_data) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_DIGIN); + return -1; + } + + if ((~s_data) & resources.adio.in_mask) + return 0; + else { + set_err(call_pnt, ER_BADSTATUS, ETERROR + ETAPPL, \ + "RFinp disabled", "", 0); + return -1; + } + +} /* end check_enable() + + +/* + * abort_wp() + * Abort ramping + */ +void abort_wp(void) +{ + int stop_flag = 0; + + /* abort any active loop */ + if (loop_var[VLT_RAMP].loop) { + stop_loop(VLT_RAMP); + stop_flag++; + } + if (loop_var[FAST_RAMP].loop) { + stop_loop(FAST_RAMP); + stop_flag++; + } + + if (!stop_flag) { + set_err(call_pnt, ER_RAMPABORT, ETERROR+ETAPPL, \ + "Ramp Not Running ", "", 0 ); + return; + } + call_pnt->bytecount = 0; + +} /* end abort_wp() */ + + +/* + * vlt_rr() + * Read cavity voltage + */ +void vlt_rr(void) +{ + short s_data; + double d_data; + + /* read the ADC */ + if (equip(resources.adio.devname, ADIO_RDADC , (char *)&s_data) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_RDADC); + return; + } + + /* calculate voltage value with calibration parameters */ + d_data = (double) s_data; + d_data = d_data * d_data * d_data * resources.adio.adc.a + \ + d_data * d_data * resources.adio.adc.b + \ + d_data * resources.adio.adc.c + \ + resources.adio.adc.d; + + /* return value */ + call_pnt->bytecount = sizeof(d_data); + *((double*)call_pnt->data) = d_data; + +#ifdef DEBUG + fprintf(stderr, "vlt_rr(): data = 0x%x - %3.3f, bytecount = %d\n", \ + s_data, *(double *)call_pnt->data, call_pnt->bytecount); +#endif + +} /* end vlt_rr() */ + + +/* + * vltset_rr() + * Read cavity setting voltage + */ +void vltset_rr(void) +{ + short s_data; + double d_data; + + /* read the DAC */ + if (equip(resources.adio.devname, ADIO_RDDAC, (char *)&s_data) != 0) { + set_err(call_pnt, errno, ETERROR+ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_RDDAC); + return; + } + + /* calculate voltage value setting */ + d_data = s_data; + d_data = d_data * d_data * d_data * resources.adio.dac_set.a + \ + d_data * d_data * resources.adio.dac_set.b + \ + d_data * resources.adio.dac_set.c + \ + resources.adio.dac_set.d; + + /* return value */ + call_pnt->bytecount = sizeof(d_data); + *((double*)call_pnt->data) = d_data; + +#ifdef DEBUG + fprintf(stderr, "vltset_rr(): data = 0x%x - %3.3f, bytecount = %d\n", \ + s_data, *(double *)call_pnt->data, call_pnt->bytecount); +#endif + +} /* end vltset_rr() */ + + +/* + * dvlt_wr() + * Direct voltage setting (DANGEROUS) + */ +void dvlt_wr(void) +{ + short s_data; + double d_data; + int int_val; + + if (check_enable() < 0) + return; + + /* ramp already running ? */ + if (loop_var[VLT_RAMP].loop) { + set_err(call_pnt, ER_POINTBUSY, ETERROR+ETAPPL, \ + "Ramp Already Running ", "", 0 ); + return; + } + /* ramp already running ? */ + if (loop_var[FAST_RAMP].loop) { + set_err(call_pnt, ER_POINTBUSY, ETERROR+ETAPPL, \ + "Ramp Already Running ", "", 0 ); + return; + } + + /* get the value from the data module */ + d_data = *((double *)call_pnt->data); + + /* max min check */ + if ((d_data > resources.adio.dac.max) || \ + (d_data < resources.adio.dac.min)) { + set_err(call_pnt, ER_OUTOFRANGE, ETERROR + ETAPPL, \ + "Value Out Of Range: ", "", (int)d_data); + return; + } + + /* set DAC output value */ + d_data = d_data * d_data * d_data * resources.adio.dac.a + \ + d_data * d_data * resources.adio.dac.b + \ + d_data * resources.adio.dac.c + \ + resources.adio.dac.d; + + /* rounding */ + if (d_data >= 0) + int_val = (int)(d_data + 0.5); + else + int_val = (int)(d_data - 0.5); + + /* if values overcome the limits set the limits */ + if ( (int_val > ADIO_HIGHTHR) ) + s_data = ADIO_HIGHTHR; + else if ( (int_val < -ADIO_LOWTHR) ) + s_data = -ADIO_LOWTHR; + else + s_data = (short)int_val; + + /* set the DAC */ + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&s_data) != 0) { + set_err(call_pnt, errno, ETERROR+ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_WRDAC); + return; + } + call_pnt->bytecount = 0; + +#ifdef DEBUG + fprintf(stderr, "dvlt_wr(): data = 0x%x - %3.3f, bytecount = %d\n", \ + s_data,*(double *)call_pnt->data, call_pnt->bytecount); +#endif + +} /* end dvlt_wr() */ + + +/* + * limits_rr() + */ +void limits_rr(void) +{ + double *d_data; + + d_data = (double *)call_pnt->data; /* point data */ + *(d_data++) = resources.adio.dac.min; /* min voltage (kV) */ + *(d_data++) = resources.adio.dac.max; /* max voltage (kV) */ + *d_data = resources.adio.max_vel; /* max rate (kV*sec) */ + + call_pnt->bytecount = 3 * sizeof(*d_data); /* set bytecount */ +} /* end limits_rr() */ + + +/* + * linrmp_wrrr() + * Start ramping + */ +void linrmp_wrrr(void) +{ + short short_val; + double double_vlt, double_vel, double1; + int int_val; + double time_to_finish; + + if (check_enable() < 0) + return; + + /* fast ramp already running ? */ + if (loop_var[FAST_RAMP].loop) { + set_err(call_pnt, ER_POINTBUSY, ETERROR+ETAPPL, \ + "Ramp Already Running ", "", 0 ); + return; + } + + if (loop_var[VLT_RAMP].loop) + stop_loop(VLT_RAMP); + + /* read the voltage value and velocity from the data module */ + double_vlt = *((double *)call_pnt->data); + double_vel = *((double *)&call_pnt->data[sizeof(double_vlt)]); + double1 = double_vlt; + +#ifdef MYDEBUG + fprintf(stderr, "linrmp_wr(): vlt = %f [kV], speed = %f [kV/s]\n", \ + double_vlt, double_vel); +#endif + + /* limits check */ + if ((double_vlt > resources.adio.dac.max) || \ + (double_vlt < resources.adio.dac.min)) { + set_err(call_pnt, ER_OUTOFRANGE, ETERROR + ETAPPL, \ + "Value Out Of Range: ", "", (int)double_vlt); + return; + } + + if ((double_vel > resources.adio.max_vel) || (double_vel <= 0.)) { + set_err(call_pnt, ER_OUTOFRANGE, ETERROR + ETAPPL, \ + "Slope Out Of Range: ", "", (int)double_vel ); + return; + } + + /* calculate the value to set on the DAC, calibrated */ + double_vlt = double_vlt * double_vlt * double_vlt * resources.adio.dac.a + \ + double_vlt * double_vlt * resources.adio.dac.b + \ + double_vlt * resources.adio.dac.c + \ + resources.adio.dac.d; + + /* rounding */ + if (double_vlt >= 0) + int_val = (int)(double_vlt + 0.5); + else + int_val = (int)(double_vlt - 0.5); + + /* if values overcome the hard limits set the limits */ + if (int_val > ADIO_HIGHTHR) + short_val = ADIO_HIGHTHR; + else if (int_val < -ADIO_LOWTHR) + short_val = -ADIO_LOWTHR; + else + short_val = (short)int_val; + + end_vlt = short_val; + +#ifdef MYDEBUG + fprintf(stderr, "linrmp_wr(): end_vlt = 0x%x\n", end_vlt); +#endif + + /* read the voltage DAC setting value */ + if (equip(resources.adio.devname, ADIO_RDDAC, (char *)&short_val) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_RDDAC); + return; + } + + start_vlt = short_val; + +#ifdef MYDEBUG + fprintf(stderr, "linrmp_wr(): start_vlt = 0x%x\n", start_vlt); +#endif + + /* calculate voltage, calibrated */ + double_vlt = start_vlt; + double_vlt = double_vlt * double_vlt * double_vlt * resources.adio.dac_set.a + \ + double_vlt * double_vlt * resources.adio.dac_set.b + \ + double_vlt * resources.adio.dac_set.c + \ + resources.adio.dac_set.d; + + /* if values overcome the limits set the limits */ + if (double_vlt > resources.adio.dac_set.max) + double_vlt = resources.adio.dac_set.max; + + if (double_vlt < resources.adio.dac_set.min) + double_vlt = resources.adio.dac_set.min; + + /* calculate the time to finish the ramp */ + time_to_finish = fabs(double1 - double_vlt) / double_vel; + +#ifdef MYDEBUG + fprintf(stderr, "linrmp_wr(): time_to_finish = %f\n", time_to_finish); + fflush(stderr); +#endif + + /* return the time to finish */ + *((double *)call_pnt->data) = time_to_finish; + call_pnt->bytecount = sizeof(time_to_finish); + + /* get the initial time */ + if ((start_time = get_ticks()) < 0) { + set_err(call_pnt, errno, ETERROR+ETAPPL, \ + "get_ticks() error:", resources.adio.devname, 0); + return; + } + + /* calculate the final time */ + end_time = start_time + (int)(time_to_finish * TICKS_SEC); + + /* start the loop */ + start_loop(VLT_RAMP); + +} /* end linrmp_wrrr() */ + + +/* + * fstrmp_wp() + * Start fast ramping + */ +void fstrmp_wp(void) +{ + double double_vlt,double1; + int int_val; + short short_val; + + if (check_enable() < 0) + return; + + /* another ramp already running ? */ + if ((loop_var[VLT_RAMP].loop) || (loop_var[FAST_RAMP].loop)) { + set_err(call_pnt, ER_POINTBUSY, ETERROR+ETAPPL, \ + "Ramp Already Running ", "", 0 ); + return; + } + + /* read the voltage DAC setting value to calc "time to finish" and start value*/ + if (equip(resources.adio.devname, ADIO_RDDAC, (char *)&short_val) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_RDDAC); + return; + } + + double1 = short_val; + double1 = double1 * double1 * double1 * resources.adio.dac_set.a + \ + double1 * double1 * resources.adio.dac_set.b + \ + double1 * resources.adio.dac_set.c + \ + resources.adio.dac_set.d; + /* if values overcome the limits set the limits */ + if (double1 > resources.adio.dac_set.max) { + set_err(call_pnt, errno, ER_RAMPABORT, \ + "Cannot start fastramp, final value exceeded", "", 0); + return; + } + if (double1 < resources.adio.dac_set.min) + double1 = resources.adio.dac_set.min; + + start_time_fast = get_ticks(); + delta = pow(double1/resources.adio.max_fast_ramp,2) * (double) resources.adio.fast_time*100; + end_time_fast = start_time_fast + resources.adio.fast_time*100 - delta; + + /* start the loop */ + start_loop(FAST_RAMP); + +} /* end vltrmp_wrrr() */ + + +/* + * enable_wb() + * Enable power + */ +void enable_wb(void) +{ + char *loc_val; + short zero = 0; + +#ifdef DEBUG + fprintf(stderr, "enable_wb(): data = %d, bytecount = %d\n", \ + call_pnt->data, call_pnt->bytecount); +#endif + + /* 0 or 1 to set */ + loc_val = call_pnt->data; + + if ((*loc_val != 0) && (*loc_val != 1)) { + set_err(call_pnt, ER_OUTOFRANGE, ETERROR + ETAPPL, \ + "Value Must Be 0 or 1, Not", "", *loc_val); + return; + } + + /* depending on the value, call the ioctl with the proper number */ + if (*loc_val) { /* on */ + /* stop ramping */ + if (loop_var[VLT_RAMP].loop) + stop_loop(VLT_RAMP); + if (loop_var[FAST_RAMP].loop) + stop_loop(FAST_RAMP); + /* always set DAC to 0x0 */ + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&zero) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_WRDAC); + return; + } + /* call the physical driver with the mask */ + if (equip(resources.adio.devname, ADIO_WRDIGOLON, \ + (char *)&resources.adio.enable_mask)) { + set_err(call_pnt, errno, ETERROR + ETAPPL, "Open/Ioctl Error in Devsrv:", \ + resources.adio.devname, ADIO_WRDIGOLON); + return; + } + + } + else { /* off, set DAC to 0x0 too */ + /* stop ramping */ + if (loop_var[VLT_RAMP].loop) + stop_loop(VLT_RAMP); + if (loop_var[FAST_RAMP].loop) + stop_loop(FAST_RAMP); + + if (equip(resources.adio.devname, ADIO_WRDIGOLOFF, \ + (char *)&resources.adio.enable_mask)) { + set_err(call_pnt, errno, ETERROR + ETAPPL, "Open/Ioctl Error in Devsrv:", \ + resources.adio.devname, ADIO_WRDIGOLOFF); + return; + } + /* always set DAC to 0x0 */ + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&zero) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_WRDAC); + return; + } + + } + + call_pnt->bytecount = 0; + +} /* end enable_wb() */ + + +/* + * stat_rf() + * Read status + * bit 0: 0=disable - 1=enable + * bit 1: 0=not ramping - 1= fast ramping + */ +void stat_rf(void) +{ + unsigned short s_data = 0; + unsigned int i_data = 0; + + /* read the status from ADIO */ + if (equip(resources.adio.devname, ADIO_DIGIN , (char *)&s_data) != 0) { + set_err(call_pnt, errno, ETERROR + ETAPPL, \ + "Open/Ioctl Error in Devsrv:", resources.adio.devname, ADIO_DIGIN); + return; + } + + if ((~s_data) & resources.adio.in_mask) + i_data = 1; + + /* add the Ramp status bit */ + if (loop_var[FAST_RAMP].loop) + i_data |= RAMP_MSK; + + *((unsigned int*)call_pnt->data) = i_data; + call_pnt->bytecount = sizeof(i_data); + +#ifdef DEBUG + fprintf(stderr,"stat_rf: 0x%x, bytecount = %d\n", \ + i_data,call_pnt->bytecount); +#endif + +} /* end stat_rf() */ + + +/* + * go_on_loop0() + * VLT RAMP loop + */ +void go_on_loop0(void) +{ + int time; + short vlt_val; + + switch (loop_var[VLT_RAMP].step) { + case 0: + /* get current ticks; if fails stop ramp */ + if ((time = get_ticks()) < 0) { + set_msg("get_ticks() error in lin ramp", "", errno); + stop_loop(VLT_RAMP); + return; + } + + /* if ramp already finished set the last value and stop the loop */ + if (time >= end_time) { + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&end_vlt) != 0) + set_msg("EQUIP Error in Ramp", "", errno); + stop_loop(VLT_RAMP); + return; + } + + /* calculate the value to set */ + vlt_val = (double)start_vlt + (double)(end_vlt - start_vlt) * \ + (double)(time - start_time) / (double)(end_time - start_time); + + /* set the value */ + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&vlt_val) != 0) { + set_msg("EQUIP Error in Ramp","", errno); + stop_loop(VLT_RAMP); + return; + } + + /* wait and continue */ + WAIT_POINT(VLT_RAMP, RAMP_TICKS, 0) + default: + LOOP_DEFAULT(VLT_RAMP) + } /* end switch */ + +} /* end go_on_loop0() */ + + +/* + * go_on_loop1() + * FAST RAMP loop + */ +void go_on_loop1(void) +{ + int time,int_val; + short vlt_val; + double double_vlt; + + switch (loop_var[FAST_RAMP].step) { + case 0: + /* get current ticks; if fails stop ramp */ + if ((time = get_ticks()) < 0) { + set_msg("get_ticks() error in fast ramp", "", errno); + stop_loop(FAST_RAMP); + return; + } + + /* if ramp already finished set the last value and stop the loop */ + if (time >= end_time_fast) { + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&end_vlt_fast) != 0) + set_msg("EQUIP Error in Ramp", "", errno); + stop_loop(FAST_RAMP); + return; + } + + double_vlt = (double) resources.adio.max_fast_ramp * \ + pow((double)(delta + time - start_time_fast) / (double)resources.adio.fast_time / 100 ,0.5); + /* calculate the value to set on the DAC, calibrated */ + double_vlt = double_vlt * double_vlt * double_vlt * resources.adio.dac.a + \ + double_vlt * double_vlt * resources.adio.dac.b + \ + double_vlt * resources.adio.dac.c + \ + resources.adio.dac.d; + + /* rounding */ + if (double_vlt >= 0) + int_val = (int)(double_vlt + 0.5); + else + int_val = (int)(double_vlt - 0.5); + /* if values overcome the hard limits set the limits */ + if (int_val > ADIO_HIGHTHR) + vlt_val = ADIO_HIGHTHR; + else if (int_val < -ADIO_LOWTHR) + vlt_val = -ADIO_LOWTHR; + else + vlt_val = (short)int_val; + + /* set the value */ + if (equip(resources.adio.devname, ADIO_WRDAC, (char *)&vlt_val) != 0) { + set_msg("EQUIP Error in Ramp","", errno); + stop_loop(FAST_RAMP); + return; + } + + /* wait and continue */ + WAIT_POINT(FAST_RAMP, RAMP_TICKS, 0) + default: + LOOP_DEFAULT(VLT_RAMP) + } /* end switch */ + +} /* end go_on_loop1() */ + + +/* + * go_on_loop() + * discriminate loop and call proper function + */ +void go_on_loop(int loop_num) +{ + switch (loop_num) { + case VLT_RAMP: + go_on_loop0(); + break; + case FAST_RAMP: + go_on_loop1(); + break; + default: + printf("%s: loop %d not implemented!", gettime(), loop_num); + } /* end switch */ +} /* end go_on_loop() */ + + +/* + * main() + */ +int main(int argc, char *argv[]) +{ + /* Check the input parameters */ + if (argc < 3) { + printf("Usage: %s <channel number> <resource file>\n", argv[0]); + exit(0); + } + + /* generic part initialization */ + iniz(argv[1], N_LOOPS, amtab, N_AM); + + /* read resources from resource file */ + if (read_resources(argv[2]) < 0) { + printf("%s: %s: error reading resource file: %s\n", \ + gettime(), argv[0], res_err); + free_res(); + die(0); + } + + /* HW initialization */ + iniz_hw(); + iniz_sw(); + + server_loop(); /* server main loop */ + +} /* end main() */ + +/* EOF */ diff --git a/old-src/makefile b/old-src/makefile new file mode 100644 index 0000000000000000000000000000000000000000..ac8829c26d7b11c01701c0d9878e5de68926a9b7 --- /dev/null +++ b/old-src/makefile @@ -0,0 +1,57 @@ +# +# makefile for rfinp directory using ultrac +# use gmake (not make) to make +# + +# use executable cc; -mode must be the first argument! (c89 = ANSI) +CC = cc -mode=c89 +RM = del + +# strictly ANSI, verbose +COPTS = -a=warn -b -tp=68040 -td=/r0 + +# additional debug printings +#DEBUG = -DDEBUG -DDEBUGRES +DEBUG = -DDEBUGRES + +# for _mkdata_nodule(), modlink() in ANSI mode +LIBSYSC = -l /dd/MWOS/OS9/68020/LIB/sys_clib.l + +# define root of ELETTRA source tree +ELETTRA = ../../.. + +# these are not relly libraries so DON'T use -l +LIBIOCTL = $(ELETTRA)/LIB/ioctl.r +LIBMOD = $(ELETTRA)/LIB/csmodule.o +LIBLOGS = $(ELETTRA)/LIB/cslogs.o +LIBACCESS = $(ELETTRA)/FELIX/RTDB/csaccess.o +LIBSEM = $(ELETTRA)/FELIX/RTDB/cssem.o + +LIBS = $(LIBIOCTL) $(LIBMOD) $(LIBLOGS) $(LIBACCESS) \ + $(LIBSEM) $(LIBSYSC) + +CDEFS = -I../DEFS \ + -I$(ELETTRA)/DEFS \ + -I$(ELETTRA)/FELIX/DEFS \ + -I$(ELETTRA)/DRIVERS/DEFS + +CFLAGS = -g $(COPTS) $(DEBUG) $(CDEFS) +LFLAGS = -g -Wl,-M=8 +#LFLAGS = -g + +PLIB = $(ELETTRA)/FELIX/DEVSRV/LIB/ +ODEPS = $(PLIB)csdevsrv.o $(PLIB)csgetres.o $(LIBACCESS) + +all : cmrfinp + +cmrfinp : cmrfinp.o $(ODEPS) + $(CC) $(LFLAGS) cmrfinp.o $(PLIB)csdevsrv.o \ + $(PLIB)csgetres.o $(LIBS) -f cmrfinp + +cmrfinp.o : cmrfinp.c + $(CC) -c $(CFLAGS) cmrfinp.c + +clean : + $(RM) cmrfinp *.o *.stb *.dbg + +# EOF diff --git a/old-src/rfinp07.res b/old-src/rfinp07.res new file mode 100644 index 0000000000000000000000000000000000000000..21fe58f5ceffa6b771d1c07f183da3c4728e95a0 --- /dev/null +++ b/old-src/rfinp07.res @@ -0,0 +1,44 @@ +* +* rfinp07.res +* +* GG - 24.02.2003 +* + +* kV per sec. +adio.max_vel = .6 +* kV +adio.max_fast_ramp = 600 +* sec +adio.fast_time = 300 + +adio.devname = "/adio84" +adio.in_mask = 0x10 +adio.enable_mask = 0x1 +adio.stat_mask = 0x10 + +* from kV to bit (vlt_wr) +adio.dac.a = 0. +adio.dac.b = 0. +adio.dac.c = 3.789042e+1 +adio.dac.d = -2.637146e+3 +adio.dac.min = 0. +adio.dac.max = 700. + + +* from bit to kV (vltset_rr) +adio.dac_set.a = 0. +adio.dac_set.b = 0. +adio.dac_set.c = 2.6390e-2 +adio.dac_set.d = 6.970456e+1 +adio.dac_set.min = 0. +adio.dac_set.max = 700. + +* from bit to kV (vlt_rr) +adio.adc.a = 0. +adio.adc.b = 0. +adio.adc.c = 2.13623e-2 +adio.adc.d = 0. +adio.adc.min = 0. +adio.adc.max = 700. + +* EOF diff --git a/old-src/rfinp07.res.other b/old-src/rfinp07.res.other new file mode 100644 index 0000000000000000000000000000000000000000..095eb0be2b544ef5085a04df8dcfc724fad48784 --- /dev/null +++ b/old-src/rfinp07.res.other @@ -0,0 +1,40 @@ +* +* rfinp07.res +* + +* kV per sec. +adio.max_vel = .6 +* kV +adio.max_fast_ramp = 575 +* sec +adio.fast_time = 360 + +adio.devname = "/adio84" +adio.in_mask = 0x10 +adio.enable_mask = 0x1 + +* from kV to bit (vlt_wr) +adio.dac.a = 0. +adio.dac.b = 0. +adio.dac.c = 29.1253 +adio.dac.d = -1656.44 +adio.dac.min = 0. +adio.dac.max = 700. + +* from bit to kV (vltset_rr) +adio.dac_set.a = 0. +adio.dac_set.b = 0. +adio.dac_set.c = 0.0343306 +adio.dac_set.d = 56.9113 +adio.dac_set.min = 0. +adio.dac_set.max = 700. + +* from bit to kV (vlt_rr) +adio.adc.a = 0. +adio.adc.b = 0. +adio.adc.c = 0.0313 +adio.adc.d = 24.9062 +adio.adc.min = 0. +adio.adc.max = 700. + +* EOF diff --git a/src/ClassFactory.cpp b/src/ClassFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..efdb347481731029c40d0ecbb739171f972c6f01 --- /dev/null +++ b/src/ClassFactory.cpp @@ -0,0 +1,52 @@ +/*----- PROTECTED REGION ID(RfInp::ClassFactory.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : ClassFactory.cpp +// +// description : C++ source for the class_factory method of the DServer +// device class. This method is responsible for the creation of +// all class singleton for a device server. It is called +// at device server startup. +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include <tango.h> +#include "RfInpClass.h" + +// Add class header files if needed + + +/** + * Create RfInp Class singleton and store it in DServer object. + */ + +void Tango::DServer::class_factory() +{ + // Add method class init if needed + add_class(RfInp_ns::RfInpClass::init("RfInp")); +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::ClassFactory.cpp diff --git a/src/RfInp.cpp b/src/RfInp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3c49954f98d24cc89e4714c1c0e3b744c6f6ac3f --- /dev/null +++ b/src/RfInp.cpp @@ -0,0 +1,831 @@ +/*----- PROTECTED REGION ID(RfInp.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : RfInp.cpp +// +// description : C++ source for the RfInp class and its commands. +// The class is derived from Device. It represents the +// CORBA servant object which will be accessed from the +// network. All commands which can be executed on the +// RfInp are implemented in this file. +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include "RfInp.h" +#include "RfInpClass.h" + +#include <math.h> +#include <sys/time.h> + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp.cpp + +/** + * RfInp class description: + * + */ + +//================================================================ +// The following table gives the correspondence +// between command and method names. +// +// Command name | Method name +//================================================================ +// State | Inherited (no method) +// Status | Inherited (no method) +// Abort | abort +// Enable | enable +// Disable | disable +// FastRamp | fast_ramp +//================================================================ + +//================================================================ +// Attributes managed are: +//================================================================ +// vlt | Tango::DevDouble Scalar +// vltSet | Tango::DevDouble Scalar +// OutputEnable | Tango::DevBoolean Scalar +//================================================================ + +namespace RfInp_ns +{ +/*----- PROTECTED REGION ID(RfInp::namespace_starting) ENABLED START -----*/ +/* clang-format on */ +// static initializations +double calibrate(const std::vector<Tango::DevDouble> &calibration, + const double &value) +{ + return calibration[0] * value * value * value + \ + calibration[1] * value * value + \ + calibration[2] * value + \ + calibration[3]; +} +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::namespace_starting + +//-------------------------------------------------------- +/** + * Method : RfInp::RfInp() + * Description: Constructors for a Tango device + * implementing the classRfInp + */ +//-------------------------------------------------------- +RfInp::RfInp(Tango::DeviceClass *cl, std::string &s) + : TANGO_BASE_CLASS(cl, s.c_str()) +{ + /*----- PROTECTED REGION ID(RfInp::constructor_1) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::constructor_1 +} +//-------------------------------------------------------- +RfInp::RfInp(Tango::DeviceClass *cl, const char *s) + : TANGO_BASE_CLASS(cl, s) +{ + /*----- PROTECTED REGION ID(RfInp::constructor_2) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::constructor_2 +} +//-------------------------------------------------------- +RfInp::RfInp(Tango::DeviceClass *cl, const char *s, const char *d) + : TANGO_BASE_CLASS(cl, s, d) +{ + /*----- PROTECTED REGION ID(RfInp::constructor_3) ENABLED START -----*/ + /* clang-format on */ + init_device(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::constructor_3 +} +//-------------------------------------------------------- +RfInp::~RfInp() +{ + delete_device(); +} + +//-------------------------------------------------------- +/** + * Method : RfInp::delete_device() + * Description: will be called at device destruction or at init command + */ +//-------------------------------------------------------- +void RfInp::delete_device() +{ + DEBUG_STREAM << "RfInp::delete_device() " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::delete_device) ENABLED START -----*/ + /* clang-format on */ + // Delete device allocated objects + if (worker) { + worker->stop(); + worker->join(NULL); + } + + if (vltADC) + delete vltADC; + if (enableInDIO) + delete enableInDIO; + if (enableOutDIO) + delete enableOutDIO; + if (vltDAC) + delete vltDAC; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::delete_device + delete[] attr_vlt_read; + delete[] attr_vltSet_read; + delete[] attr_OutputEnable_read; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::init_device() + * Description: will be called at device initialization. + */ +//-------------------------------------------------------- +void RfInp::init_device() +{ + DEBUG_STREAM << "RfInp::init_device() create device " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::init_device_before) ENABLED START -----*/ + /* clang-format on */ + initError.clear(); + vltADC = NULL; + enableInDIO = enableOutDIO = NULL; + vltDAC = NULL; + worker = NULL; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::init_device_before + + + // Get the device properties from database + get_device_property(); + + attr_vlt_read = new Tango::DevDouble[1]; + attr_vltSet_read = new Tango::DevDouble[1]; + attr_OutputEnable_read = new Tango::DevBoolean[1]; + // No longer if mandatory property not set. + if (mandatoryNotDefined) + return; + + /*----- PROTECTED REGION ID(RfInp::init_device) ENABLED START -----*/ + /* clang-format on */ + // Initialize device + try { + vltADC = new ADC(adcDevice); + enableInDIO = new DIO(enableInDevice); + enableOutDIO = new DIO(enableOutDevice); + vltDAC = new DAC(dacDevice); + + /* Start the poller */ + worker = new RfInpWorker(this); + worker->start(); + } catch (Tango::DevFailed &e) { + initError = "Initialization failed: " + string(e.errors[0].desc); + } catch (...) { + initError = "Initialization failed: Unknown error"; + } + + if (! initError.empty()) { + ERROR_STREAM << initError << endl; + set_state(Tango::UNKNOWN); + set_status(initError); + assert(false); + } else { + set_state(Tango::ON); + } + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::init_device +} + +//-------------------------------------------------------- +/** + * Method : RfInp::get_device_property() + * Description: Read database to initialize property data members. + */ +//-------------------------------------------------------- +void RfInp::get_device_property() +{ + /*----- PROTECTED REGION ID(RfInp::get_device_property_before) ENABLED START -----*/ + /* clang-format on */ + // Initialize property data members + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::get_device_property_before + + mandatoryNotDefined = false; + + // Read device properties from database. + Tango::DbData dev_prop; + dev_prop.push_back(Tango::DbDatum("EnableInDevice")); + dev_prop.push_back(Tango::DbDatum("EnableOutDevice")); + dev_prop.push_back(Tango::DbDatum("MaxVltStep")); + dev_prop.push_back(Tango::DbDatum("adcCalibration")); + dev_prop.push_back(Tango::DbDatum("adcDevice")); + dev_prop.push_back(Tango::DbDatum("dacCalibration")); + dev_prop.push_back(Tango::DbDatum("dacDevice")); + dev_prop.push_back(Tango::DbDatum("dacSetCalibration")); + dev_prop.push_back(Tango::DbDatum("fastRampTarget")); + dev_prop.push_back(Tango::DbDatum("fastRampTime")); + dev_prop.push_back(Tango::DbDatum("pollingSleep")); + + // is there at least one property to be read ? + if (dev_prop.size()>0) + { + // Call database and extract values + if (Tango::Util::instance()->_UseDb==true) + get_db_device()->get_property(dev_prop); + + // get instance on RfInpClass to get class property + Tango::DbDatum def_prop, cl_prop; + RfInpClass *ds_class = + (static_cast<RfInpClass *>(get_device_class())); + int i = -1; + + // Try to initialize EnableInDevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> enableInDevice; + else { + // Try to initialize EnableInDevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> enableInDevice; + } + // And try to extract EnableInDevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> enableInDevice; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize EnableOutDevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> enableOutDevice; + else { + // Try to initialize EnableOutDevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> enableOutDevice; + } + // And try to extract EnableOutDevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> enableOutDevice; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize MaxVltStep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> maxVltStep; + else { + // Try to initialize MaxVltStep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> maxVltStep; + } + // And try to extract MaxVltStep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> maxVltStep; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize adcCalibration from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> adcCalibration; + else { + // Try to initialize adcCalibration from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> adcCalibration; + } + // And try to extract adcCalibration value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> adcCalibration; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize adcDevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> adcDevice; + else { + // Try to initialize adcDevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> adcDevice; + } + // And try to extract adcDevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> adcDevice; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize dacCalibration from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> dacCalibration; + else { + // Try to initialize dacCalibration from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> dacCalibration; + } + // And try to extract dacCalibration value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> dacCalibration; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize dacDevice from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> dacDevice; + else { + // Try to initialize dacDevice from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> dacDevice; + } + // And try to extract dacDevice value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> dacDevice; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize dacSetCalibration from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> dacSetCalibration; + else { + // Try to initialize dacSetCalibration from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> dacSetCalibration; + } + // And try to extract dacSetCalibration value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> dacSetCalibration; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize fastRampTarget from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> fastRampTarget; + else { + // Try to initialize fastRampTarget from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> fastRampTarget; + } + // And try to extract fastRampTarget value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> fastRampTarget; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize fastRampTime from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> fastRampTime; + else { + // Try to initialize fastRampTime from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> fastRampTime; + } + // And try to extract fastRampTime value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> fastRampTime; + // Property StartDsPath is mandatory, check if has been defined in database. + check_mandatory_property(cl_prop, dev_prop[i]); + + // Try to initialize pollingSleep from class property + cl_prop = ds_class->get_class_property(dev_prop[++i].name); + if (cl_prop.is_empty()==false) cl_prop >> pollingSleep; + else { + // Try to initialize pollingSleep from default device value + def_prop = ds_class->get_default_device_property(dev_prop[i].name); + if (def_prop.is_empty()==false) def_prop >> pollingSleep; + } + // And try to extract pollingSleep value from database + if (dev_prop[i].is_empty()==false) dev_prop[i] >> pollingSleep; + + } + + /*----- PROTECTED REGION ID(RfInp::get_device_property_after) ENABLED START -----*/ + /* clang-format on */ + // Check device property data members init + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::get_device_property_after +} +//-------------------------------------------------------- +/** + * Method : RfInp::check_mandatory_property() + * Description: For mandatory properties check if defined in database. + */ +//-------------------------------------------------------- +void RfInp::check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop) +{ + // Check if all properties are empty + if (class_prop.is_empty() && dev_prop.is_empty()) + { + TangoSys_OMemStream tms; + tms << std::endl <<"Property \'" << dev_prop.name; + if (Tango::Util::instance()->_UseDb==true) + tms << "\' is mandatory but not defined in database"; + else + tms << "\' is mandatory but cannot be defined without database"; + append_status(tms.str()); + mandatoryNotDefined = true; + /*----- PROTECTED REGION ID(RfInp::check_mandatory_property) ENABLED START -----*/ + /* clang-format on */ + std::cerr << tms.str() << " for " << device_name << std::endl; + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::check_mandatory_property + } +} + + +//-------------------------------------------------------- +/** + * Method : RfInp::always_executed_hook() + * Description: method always executed before any command is executed + */ +//-------------------------------------------------------- +void RfInp::always_executed_hook() +{ + DEBUG_STREAM << "RfInp::always_executed_hook() " << device_name << std::endl; + if (mandatoryNotDefined) + { + Tango::Except::throw_exception( + (const char *)"PROPERTY_NOT_SET", + get_status().c_str(), + (const char *)"RfInp::always_executed_hook()"); + } + /*----- PROTECTED REGION ID(RfInp::always_executed_hook) ENABLED START -----*/ + /* clang-format on */ + if (! initError.empty()) { + ERROR_STREAM << initError << endl; + set_status(initError); + set_state(Tango::UNKNOWN); + assert(false); + return; + } + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::always_executed_hook +} + +//-------------------------------------------------------- +/** + * Method : RfInp::read_attr_hardware() + * Description: Hardware acquisition for attributes + */ +//-------------------------------------------------------- +void RfInp::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "RfInp::read_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(RfInp::read_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + check_init(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::read_attr_hardware +} +//-------------------------------------------------------- +/** + * Method : RfInp::write_attr_hardware() + * Description: Hardware writing for attributes + */ +//-------------------------------------------------------- +void RfInp::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list)) +{ + DEBUG_STREAM << "RfInp::write_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl; + /*----- PROTECTED REGION ID(RfInp::write_attr_hardware) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::write_attr_hardware +} + +//-------------------------------------------------------- +/** + * Read attribute vlt related method + * Description: Cavity Voltage-Direct Setting kV + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void RfInp::read_vlt(Tango::Attribute &attr) +{ + DEBUG_STREAM << "RfInp::read_vlt(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(RfInp::read_vlt) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_vlt_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::read_vlt +} +//-------------------------------------------------------- +/** + * Write attribute vlt related method + * Description: Cavity Voltage-Direct Setting kV + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void RfInp::write_vlt(Tango::WAttribute &attr) +{ + DEBUG_STREAM << "RfInp::write_vlt(Tango::WAttribute &attr) entering... " << std::endl; + // Retrieve write value + Tango::DevDouble w_val; + attr.get_write_value(w_val); + /*----- PROTECTED REGION ID(RfInp::write_vlt) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + check_init(); + + if (fabs(attr_vlt_read[0] - w_val) > maxVltStep) + Tango::Except::throw_exception( "", + "Value is above MaxVltStep property", + "RfInp::write_vlt()"); + write_vlt(w_val); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::write_vlt +} +//-------------------------------------------------------- +/** + * Read attribute vltSet related method + * Description: Input Level Setting kV + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ +//-------------------------------------------------------- +void RfInp::read_vltSet(Tango::Attribute &attr) +{ + DEBUG_STREAM << "RfInp::read_vltSet(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(RfInp::read_vltSet) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_vltSet_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::read_vltSet +} +//-------------------------------------------------------- +/** + * Read attribute OutputEnable related method + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ +//-------------------------------------------------------- +void RfInp::read_OutputEnable(Tango::Attribute &attr) +{ + DEBUG_STREAM << "RfInp::read_OutputEnable(Tango::Attribute &attr) entering... " << std::endl; + /*----- PROTECTED REGION ID(RfInp::read_OutputEnable) ENABLED START -----*/ + /* clang-format on */ + // Set the attribute value + attr.set_value(attr_OutputEnable_read); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::read_OutputEnable +} + +//-------------------------------------------------------- +/** + * Method : RfInp::add_dynamic_attributes() + * Description: Create the dynamic attributes if any + * for specified device. + */ +//-------------------------------------------------------- +void RfInp::add_dynamic_attributes() +{ + /*----- PROTECTED REGION ID(RfInp::add_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + // Add your own code to create and add dynamic attributes if any + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::add_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Command Abort related method + * Description: Abort Ramp + * + */ +//-------------------------------------------------------- +void RfInp::abort() +{ + DEBUG_STREAM << "RfInp::Abort() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::abort) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + check_init(); + + worker->abort(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::abort +} +//-------------------------------------------------------- +/** + * Command Enable related method + * + * + */ +//-------------------------------------------------------- +void RfInp::enable() +{ + DEBUG_STREAM << "RfInp::Enable() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::enable) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + check_init(); + + write_vlt(0); + write_enableOut(1); + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::enable +} +//-------------------------------------------------------- +/** + * Command Disable related method + * + * + */ +//-------------------------------------------------------- +void RfInp::disable() +{ + DEBUG_STREAM << "RfInp::Disable() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::disable) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + check_init(); + + write_vlt(0); + write_enableOut(0); + + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::disable +} +//-------------------------------------------------------- +/** + * Command FastRamp related method + * Description: Start Fast Ramp + * + */ +//-------------------------------------------------------- +void RfInp::fast_ramp() +{ + DEBUG_STREAM << "RfInp::FastRamp() - " << device_name << std::endl; + /*----- PROTECTED REGION ID(RfInp::fast_ramp) ENABLED START -----*/ + /* clang-format on */ + + // Add your own code + check_init(); + + if (! attr_OutputEnable_read[0]) + Tango::Except::throw_exception( "", + "Output is disabled", + "RfInp::fast_ramp()"); + + worker->ramp(); + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::fast_ramp +} +//-------------------------------------------------------- +/** + * Method : RfInp::add_dynamic_commands() + * Description: Create the dynamic commands if any + * for specified device. + */ +//-------------------------------------------------------- +void RfInp::add_dynamic_commands() +{ + /*----- PROTECTED REGION ID(RfInp::add_dynamic_commands) ENABLED START -----*/ + /* clang-format on */ + // Add your own code to create and add dynamic commands if any + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::add_dynamic_commands +} + +/*----- PROTECTED REGION ID(RfInp::namespace_ending) ENABLED START -----*/ +/* clang-format on */ +void RfInp::check_init() +{ + if (! initError.empty()) + Tango::Except::throw_exception( "", + initError.c_str(), + "RfInp::check_init()"); +} + +void RfInp::read_vlt() +{ + double value = vltADC->readRaw(); + attr_vlt_read[0] = calibrate(adcCalibration, value); +} + +void RfInp::write_vlt(const double &w_val) +{ + short calibrated_value = calibrate(dacCalibration, w_val); + vltDAC->writeRaw(calibrated_value); +} + +void RfInp::read_vltSet() +{ + double value = vltDAC->readRaw(); + attr_vltSet_read[0] = calibrate(dacSetCalibration, value); +} + +void RfInp::read_enableIn() +{ + attr_OutputEnable_read[0] = enableInDIO->read(); +} + +void RfInp::write_enableOut(const int &w_val) +{ + enableOutDIO->write(w_val); +} + +void RfInpWorker::ramp() +{ + double delta; + device->read_vlt(); + istep = device->attr_vlt_read[0]; + delta = device->fastRampTarget - istep; + steps = device->fastRampTime * 100; // Assume 10ms + vstep = delta / steps; + + if (delta > 0) + action = RAMP; +} + +void RfInpWorker::abort() +{ + action = POLL; +} + +void* RfInpWorker::run_undetached(void*) +{ + DEBUG_STREAM << "RfInpWorker::run() - enter" << endl; + long i, b; + + while(cont) { + try { + switch(action) { + case POLL: + device->read_vlt(); + device->read_vltSet(); + device->read_enableIn(); + device->set_state(Tango::ON); + usleep(device->pollingSleep * 1000); + break; + case RAMP: + device->set_state(Tango::MOVING); + for (b=0, i=1; ((cont && action == RAMP) && i <= steps); ++b, ++i) { + struct timeval start, end, diff; + gettimeofday(&start, NULL); + device->write_vlt(istep + vstep * i); + switch(b) { + case 0: + device->read_vlt(); + break; + case 1: + device->read_vltSet(); + break; + case 2: + device->read_enableIn(); + b = -1; + break; + } + gettimeofday(&end, NULL); + timersub(&end, &start, &diff); + if (diff.tv_sec == 0 && diff.tv_usec < 10000) + usleep(10000 - diff.tv_usec); + } + action = POLL; + break; + } + } catch(Tango::DevFailed &e) { + action = POLL; + ERROR_STREAM << string(e.errors[0].desc) << endl; + device->set_state(Tango::UNKNOWN); + device->set_status(string(e.errors[0].desc)); + assert(false); + } catch(...) { + action = POLL; + ERROR_STREAM << "Unknown error" << endl; + device->set_state(Tango::UNKNOWN); + device->set_status("Unknown error"); + assert(false); + } + } + + DEBUG_STREAM << "RfInpWorker::run() - exit" << endl; + + return NULL; +} + +/*----- PROTECTED REGION END -----*/ // RfInp::namespace_ending +} // namespace diff --git a/src/RfInp.h b/src/RfInp.h new file mode 100644 index 0000000000000000000000000000000000000000..0c8565322eea216565c1778f1a9ec1f296c422f2 --- /dev/null +++ b/src/RfInp.h @@ -0,0 +1,316 @@ +/*----- PROTECTED REGION ID(RfInp.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : RfInp.h +// +// description : Include file for the RfInp class +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef RfInp_H +#define RfInp_H + +#include <tango/tango.h> + +#include "dio.h" +#include "adc.h" +#include "dac.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp.h + +#ifdef TANGO_LOG + // cppTango after c934adea (Merge branch 'remove-cout-definition' into 'main', 2022-05-23) + // nothing to do +#else + // cppTango 9.3-backports and older + #define TANGO_LOG cout + #define TANGO_LOG_INFO cout2 + #define TANGO_LOG_DEBUG cout3 +#endif // TANGO_LOG + +/** + * RfInp class description: + * + */ + + +namespace RfInp_ns +{ +/*----- PROTECTED REGION ID(RfInp::Additional Class Declarations) ENABLED START -----*/ +/* clang-format on */ +class RfInpWorker; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::Additional Class Declarations + +class RfInp : public TANGO_BASE_CLASS +{ + +/*----- PROTECTED REGION ID(RfInp::Data Members) ENABLED START -----*/ +/* clang-format on */ + string initError; + + ADC *vltADC; + DAC *vltDAC; + DIO *enableInDIO, *enableOutDIO; + + RfInpWorker *worker; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::Data Members + +// Device property data members +public: + // EnableInDevice: + std::string enableInDevice; + // EnableOutDevice: + std::string enableOutDevice; + // MaxVltStep: + Tango::DevDouble maxVltStep; + // adcCalibration: + std::vector<Tango::DevDouble> adcCalibration; + // adcDevice: + std::string adcDevice; + // dacCalibration: + std::vector<Tango::DevDouble> dacCalibration; + // dacDevice: + std::string dacDevice; + // dacSetCalibration: + std::vector<Tango::DevDouble> dacSetCalibration; + // fastRampTarget: Fast ramp target in kV + Tango::DevDouble fastRampTarget; + // fastRampTime: Fast ramp duration in seconds + Tango::DevUShort fastRampTime; + // pollingSleep: Sleep in ms between hardware interaction + Tango::DevUShort pollingSleep; + + bool mandatoryNotDefined; + +// Attribute data members +public: + Tango::DevDouble *attr_vlt_read; + Tango::DevDouble *attr_vltSet_read; + Tango::DevBoolean *attr_OutputEnable_read; + +// Constructors and destructors +public: + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + RfInp(Tango::DeviceClass *cl,std::string &s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device Name + */ + RfInp(Tango::DeviceClass *cl,const char *s); + /** + * Constructs a newly device object. + * + * @param cl Class. + * @param s Device name + * @param d Device description. + */ + RfInp(Tango::DeviceClass *cl,const char *s,const char *d); + /** + * The device object destructor. + */ + ~RfInp(); + + +// Miscellaneous methods +public: + /* + * will be called at device destruction or at init command. + */ + void delete_device(); + /* + * Initialize the device + */ + virtual void init_device(); + /* + * Read the device properties from database + */ + void get_device_property(); + /* + * Always executed method before execution command method. + */ + virtual void always_executed_hook(); + + /* + * Check if mandatory property has been set + */ + void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop); + +// Attribute methods +public: + //-------------------------------------------------------- + /* + * Method : RfInp::read_attr_hardware() + * Description: Hardware acquisition for attributes. + */ + //-------------------------------------------------------- + virtual void read_attr_hardware(std::vector<long> &attr_list); + //-------------------------------------------------------- + /* + * Method : RfInp::write_attr_hardware() + * Description: Hardware writing for attributes. + */ + //-------------------------------------------------------- + virtual void write_attr_hardware(std::vector<long> &attr_list); + +/** + * Attribute vlt related methods + * Description: Cavity Voltage-Direct Setting kV + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_vlt(Tango::Attribute &attr); + virtual void write_vlt(Tango::WAttribute &attr); + virtual bool is_vlt_allowed(Tango::AttReqType type); +/** + * Attribute vltSet related methods + * Description: Input Level Setting kV + * + * Data type: Tango::DevDouble + * Attr type: Scalar + */ + virtual void read_vltSet(Tango::Attribute &attr); + virtual bool is_vltSet_allowed(Tango::AttReqType type); +/** + * Attribute OutputEnable related methods + * + * + * Data type: Tango::DevBoolean + * Attr type: Scalar + */ + virtual void read_OutputEnable(Tango::Attribute &attr); + virtual bool is_OutputEnable_allowed(Tango::AttReqType type); + + + //-------------------------------------------------------- + /** + * Method : RfInp::add_dynamic_attributes() + * Description: Add dynamic attributes if any. + */ + //-------------------------------------------------------- + void add_dynamic_attributes(); + + + + +// Command related methods +public: + /** + * Command Abort related method + * Description: Abort Ramp + * + */ + virtual void abort(); + virtual bool is_Abort_allowed(const CORBA::Any &any); + /** + * Command Enable related method + * + * + */ + virtual void enable(); + virtual bool is_Enable_allowed(const CORBA::Any &any); + /** + * Command Disable related method + * + * + */ + virtual void disable(); + virtual bool is_Disable_allowed(const CORBA::Any &any); + /** + * Command FastRamp related method + * Description: Start Fast Ramp + * + */ + virtual void fast_ramp(); + virtual bool is_FastRamp_allowed(const CORBA::Any &any); + + + //-------------------------------------------------------- + /** + * Method : RfInp::add_dynamic_commands() + * Description: Add dynamic commands if any. + */ + //-------------------------------------------------------- + void add_dynamic_commands(); + +/*----- PROTECTED REGION ID(RfInp::Additional Method prototypes) ENABLED START -----*/ +/* clang-format on */ + void check_init(); + void read_vlt(); + void write_vlt(const double &w_val); + void read_vltSet(); + void read_enableIn(); + void write_enableOut(const int &w_val); + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::Additional Method prototypes +}; + +/*----- PROTECTED REGION ID(RfInp::Additional Classes Definitions) ENABLED START -----*/ +/* clang-format on */ +// Additional Classes Definitions +class RfInpWorker : public omni_thread, public Tango::LogAdapter +{ + RfInp *device; + void* run_undetached(void*); + bool cont; + enum { POLL, RAMP } action; + // For ramping + long steps; + double vstep; + double istep; + +public: + RfInpWorker(RfInp *device_) : + LogAdapter((Tango::DeviceImpl*)device_), + device(device_), cont(false), action(POLL) {} + void start() { + cont = true; + start_undetached(); + } + void ramp(); + void abort(); + void stop() { + cont = false; + } +}; +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::Additional Classes Definitions + +} // End of namespace + +#endif // RfInp_H diff --git a/src/RfInp.xmi b/src/RfInp.xmi new file mode 100644 index 0000000000000000000000000000000000000000..50aa43cf32325a77f39a1b7af535c7b73e77ca49 --- /dev/null +++ b/src/RfInp.xmi @@ -0,0 +1,166 @@ +<?xml version="1.0" encoding="ASCII"?> +<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl"> + <classes name="RfInp" pogoRevision="9.7"> + <description description="" title="" sourcePath="/home/alessio/Sources/git-trees/rfinp/src" language="Cpp" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false"> + <inheritances classname="Device_Impl" sourcePath=""/> + <identification contact="at elettra.eu> - Alessio Igor Bogani <alessio.bogani" author="Alessio Igor Bogani <alessio.bogani" emailDomain="elettra.eu>" classFamily="OtherInstruments" siteSpecific="" platform="Unix Like" bus="VME" manufacturer="none" reference=""/> + </description> + <deviceProperties name="EnableInDevice" mandatory="true" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="EnableOutDevice" mandatory="true" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="MaxVltStep" mandatory="true" description=""> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="adcCalibration" mandatory="true" description=""> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="adcDevice" mandatory="true" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="dacCalibration" mandatory="true" description=""> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="dacDevice" mandatory="true" description=""> + <type xsi:type="pogoDsl:StringType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="dacSetCalibration" mandatory="true" description=""> + <type xsi:type="pogoDsl:DoubleVectorType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="fastRampTarget" mandatory="true" description="Fast ramp target in kV"> + <type xsi:type="pogoDsl:DoubleType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="fastRampTime" mandatory="true" description="Fast ramp duration in seconds"> + <type xsi:type="pogoDsl:UShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </deviceProperties> + <deviceProperties name="pollingSleep" description="Sleep in ms between hardware interaction"> + <type xsi:type="pogoDsl:UShortType"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <DefaultPropValue>100</DefaultPropValue> + </deviceProperties> + <commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device state"> + <type xsi:type="pogoDsl:StateType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Status" description="This command gets the device status (stored in its device_status data member) and returns it to the caller." execMethod="dev_status" displayLevel="OPERATOR" polledPeriod="0"> + <argin description="none"> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description="Device status"> + <type xsi:type="pogoDsl:ConstStringType"/> + </argout> + <status abstract="true" inherited="true" concrete="true"/> + </commands> + <commands name="Abort" description="Abort Ramp" execMethod="abort" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <excludedStates>ON</excludedStates> + <excludedStates>OFF</excludedStates> + <excludedStates>UNKNOWN</excludedStates> + <excludedStates>FAULT</excludedStates> + <excludedStates>ALARM</excludedStates> + </commands> + <commands name="Enable" description="" execMethod="enable" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <excludedStates>UNKNOWN</excludedStates> + <excludedStates>MOVING</excludedStates> + </commands> + <commands name="Disable" description="" execMethod="disable" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <excludedStates>UNKNOWN</excludedStates> + <excludedStates>MOVING</excludedStates> + </commands> + <commands name="FastRamp" description="Start Fast Ramp" execMethod="fast_ramp" displayLevel="OPERATOR" polledPeriod="0" isDynamic="false"> + <argin description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argin> + <argout description=""> + <type xsi:type="pogoDsl:VoidType"/> + </argout> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <excludedStates>UNKNOWN</excludedStates> + <excludedStates>MOVING</excludedStates> + </commands> + <attributes name="vlt" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Cavity Voltage-Direct Setting kV" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + <readExcludedStates>UNKNOWN</readExcludedStates> + <writeExcludedStates>UNKNOWN</writeExcludedStates> + <writeExcludedStates>MOVING</writeExcludedStates> + </attributes> + <attributes name="vltSet" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:DoubleType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="Input Level Setting kV" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + <readExcludedStates>UNKNOWN</readExcludedStates> + </attributes> + <attributes name="OutputEnable" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false"> + <dataType xsi:type="pogoDsl:BooleanType"/> + <changeEvent fire="false" libCheckCriteria="false"/> + <archiveEvent fire="false" libCheckCriteria="false"/> + <dataReadyEvent fire="false" libCheckCriteria="true"/> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + <properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/> + </attributes> + <states name="ON" description="The decice is in ON state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="OFF" description="The decice is in OFF state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="UNKNOWN" description="The decice is in UNKNOWN state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="FAULT" description="The decice is in FAULT state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="ALARM" description="The decice is in ALARM state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <states name="MOVING" description="The decice is in MOVING state"> + <status abstract="false" inherited="false" concrete="true" concreteHere="true"/> + </states> + <preferences docHome="./doc_html" makefileHome="$(TANGO_HOME)"/> + </classes> +</pogoDsl:PogoSystem> diff --git a/src/RfInpClass.cpp b/src/RfInpClass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2edb2cfe7a3ac95e394ba1ea8cb87d74b689a32 --- /dev/null +++ b/src/RfInpClass.cpp @@ -0,0 +1,796 @@ +/*----- PROTECTED REGION ID(RfInpClass.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : RfInpClass.cpp +// +// description : C++ source for the RfInpClass. +// A singleton class derived from DeviceClass. +// It implements the command and attribute list +// and all properties and methods required +// by the RfInp once per process. +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#include "RfInpClass.h" +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInpClass.cpp + +//------------------------------------------------------------------- +/** + * Create RfInpClass singleton and + * return it in a C function for Python usage + */ +//------------------------------------------------------------------- +extern "C" { +#ifdef _TG_WINDOWS_ + +__declspec(dllexport) + +#endif + + Tango::DeviceClass *_create_RfInp_class(const char *name) { + return RfInp_ns::RfInpClass::init(name); + } +} + +namespace RfInp_ns +{ +//=================================================================== +// Initialize pointer for singleton pattern +//=================================================================== +RfInpClass *RfInpClass::_instance = NULL; + +//=================================================================== +// Class constants +//=================================================================== +//-------------------------------------------------------- +/** + * method : RfInpClass::RfInpClass(std::string &s) + * description : constructor for the RfInpClass + * + * @param s The class name + */ +//-------------------------------------------------------- +RfInpClass::RfInpClass(std::string &s):Tango::DeviceClass(s) +{ + TANGO_LOG_INFO << "Entering RfInpClass constructor" << std::endl; + set_default_property(); + write_class_property(); + + /*----- PROTECTED REGION ID(RfInpClass::constructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::constructor + + TANGO_LOG_INFO << "Leaving RfInpClass constructor" << std::endl; +} + +//-------------------------------------------------------- +/** + * method : RfInpClass::~RfInpClass() + * description : destructor for the RfInpClass + */ +//-------------------------------------------------------- +RfInpClass::~RfInpClass() +{ + /*----- PROTECTED REGION ID(RfInpClass::destructor) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::destructor + + _instance = NULL; +} + + +//-------------------------------------------------------- +/** + * method : RfInpClass::init + * description : Create the object if not already done. + * Otherwise, just return a pointer to the object + * + * @param name The class name + */ +//-------------------------------------------------------- +RfInpClass *RfInpClass::init(const char *name) +{ + if (_instance == NULL) + { + try + { + std::string s(name); + _instance = new RfInpClass(s); + } + catch (std::bad_alloc &) + { + throw; + } + } + return _instance; +} + +//-------------------------------------------------------- +/** + * method : RfInpClass::instance + * description : Check if object already created, + * and return a pointer to the object + */ +//-------------------------------------------------------- +RfInpClass *RfInpClass::instance() +{ + if (_instance == NULL) + { + std::cerr << "Class is not initialized !!" << std::endl; + exit(-1); + } + return _instance; +} + + + +//=================================================================== +// Command execution method calls +//=================================================================== +//-------------------------------------------------------- +/** + * method : AbortClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *AbortClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "AbortClass::execute(): arrived" << std::endl; + ((static_cast<RfInp *>(device))->abort()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : EnableClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *EnableClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "EnableClass::execute(): arrived" << std::endl; + ((static_cast<RfInp *>(device))->enable()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : DisableClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *DisableClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "DisableClass::execute(): arrived" << std::endl; + ((static_cast<RfInp *>(device))->disable()); + return new CORBA::Any(); +} + +//-------------------------------------------------------- +/** + * method : FastRampClass::execute() + * description : method to trigger the execution of the command. + * + * @param device The device on which the command must be executed + * @param in_any The command input data + * + * returns The command output data (packed in the Any object) + */ +//-------------------------------------------------------- +CORBA::Any *FastRampClass::execute(Tango::DeviceImpl *device, TANGO_UNUSED(const CORBA::Any &in_any)) +{ + TANGO_LOG_INFO << "FastRampClass::execute(): arrived" << std::endl; + ((static_cast<RfInp *>(device))->fast_ramp()); + return new CORBA::Any(); +} + + +//=================================================================== +// Properties management +//=================================================================== +//-------------------------------------------------------- +/** + * Method : RfInpClass::get_class_property() + * Description: Get the class property for specified name. + */ +//-------------------------------------------------------- +Tango::DbDatum RfInpClass::get_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_prop.size() ; i++) + if (cl_prop[i].name == prop_name) + return cl_prop[i]; + // if not found, returns an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : RfInpClass::get_default_device_property() + * Description: Return the default value for device property. + */ +//-------------------------------------------------------- +Tango::DbDatum RfInpClass::get_default_device_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<dev_def_prop.size() ; i++) + if (dev_def_prop[i].name == prop_name) + return dev_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + +//-------------------------------------------------------- +/** + * Method : RfInpClass::get_default_class_property() + * Description: Return the default value for class property. + */ +//-------------------------------------------------------- +Tango::DbDatum RfInpClass::get_default_class_property(std::string &prop_name) +{ + for (unsigned int i=0 ; i<cl_def_prop.size() ; i++) + if (cl_def_prop[i].name == prop_name) + return cl_def_prop[i]; + // if not found, return an empty DbDatum + return Tango::DbDatum(prop_name); +} + + +//-------------------------------------------------------- +/** + * Method : RfInpClass::set_default_property() + * Description: Set default property (class and device) for wizard. + * For each property, add to wizard property name and description. + * If default value has been set, add it to wizard property and + * store it in a DbDatum. + */ +//-------------------------------------------------------- +void RfInpClass::set_default_property() +{ + std::string prop_name; + std::string prop_desc; + std::string prop_def; + std::vector<std::string> vect_data; + + // Set Default Class Properties + + // Set Default device Properties + prop_name = "EnableInDevice"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "EnableOutDevice"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "MaxVltStep"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "adcCalibration"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "adcDevice"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "dacCalibration"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "dacDevice"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "dacSetCalibration"; + prop_desc = ""; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "fastRampTarget"; + prop_desc = "Fast ramp target in kV"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "fastRampTime"; + prop_desc = "Fast ramp duration in seconds"; + prop_def = ""; + vect_data.clear(); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); + prop_name = "pollingSleep"; + prop_desc = "Sleep in ms between hardware interaction"; + prop_def = "100"; + vect_data.clear(); + vect_data.push_back("100"); + if (prop_def.length()>0) + { + Tango::DbDatum data(prop_name); + data << vect_data ; + dev_def_prop.push_back(data); + add_wiz_dev_prop(prop_name, prop_desc, prop_def); + } + else + add_wiz_dev_prop(prop_name, prop_desc); +} + +//-------------------------------------------------------- +/** + * Method : RfInpClass::write_class_property() + * Description: Set class description fields as property in database + */ +//-------------------------------------------------------- +void RfInpClass::write_class_property() +{ + // First time, check if database used + if (Tango::Util::_UseDb == false) + return; + + Tango::DbData data; + std::string classname = get_name(); + std::string header; + + // Put title + Tango::DbDatum title("ProjectTitle"); + std::string str_title(""); + title << str_title; + data.push_back(title); + + // Put Description + Tango::DbDatum description("Description"); + std::vector<std::string> str_desc; + str_desc.push_back(""); + description << str_desc; + data.push_back(description); + + // Put inheritance + Tango::DbDatum inher_datum("InheritedFrom"); + std::vector<std::string> inheritance; + inheritance.push_back("TANGO_BASE_CLASS"); + inher_datum << inheritance; + data.push_back(inher_datum); + + // Call database and and values + get_db_class()->put_property(data); +} + +//=================================================================== +// Factory methods +//=================================================================== + +//-------------------------------------------------------- +/** + * Method : RfInpClass::device_factory() + * Description: Create the device object(s) + * and store them in the device list + */ +//-------------------------------------------------------- +void RfInpClass::device_factory(const Tango::DevVarStringArray *devlist_ptr) +{ + /*----- PROTECTED REGION ID(RfInpClass::device_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::device_factory_before + + // Create devices and add it into the device list + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + TANGO_LOG_DEBUG << "Device name : " << (*devlist_ptr)[i].in() << std::endl; + device_list.push_back(new RfInp(this, (*devlist_ptr)[i])); + } + + // Manage dynamic attributes if any + erase_dynamic_attributes(devlist_ptr, get_class_attr()->get_attr_list()); + + // Export devices to the outside world + for (unsigned long i=1 ; i<=devlist_ptr->length() ; i++) + { + // Add dynamic attributes if any + RfInp *dev = static_cast<RfInp *>(device_list[device_list.size()-i]); + dev->add_dynamic_attributes(); + + // Check before if database used. + if ((Tango::Util::_UseDb == true) && (Tango::Util::_FileDb == false)) + export_device(dev); + else + export_device(dev, dev->get_name().c_str()); + } + + /*----- PROTECTED REGION ID(RfInpClass::device_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::device_factory_after +} +//-------------------------------------------------------- +/** + * Method : RfInpClass::attribute_factory() + * Description: Create the attribute object(s) + * and store them in the attribute list + */ +//-------------------------------------------------------- +void RfInpClass::attribute_factory(std::vector<Tango::Attr *> &att_list) +{ + /*----- PROTECTED REGION ID(RfInpClass::attribute_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::attribute_factory_before + // Attribute : vlt + vltAttrib *vlt = new vltAttrib(); + Tango::UserDefaultAttrProp vlt_prop; + vlt_prop.set_description("Cavity Voltage-Direct Setting kV"); + // label not set for vlt + // unit not set for vlt + // standard_unit not set for vlt + // display_unit not set for vlt + // format not set for vlt + // max_value not set for vlt + // min_value not set for vlt + // max_alarm not set for vlt + // min_alarm not set for vlt + // max_warning not set for vlt + // min_warning not set for vlt + // delta_t not set for vlt + // delta_val not set for vlt + vlt->set_default_properties(vlt_prop); + // Not Polled + vlt->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(vlt); + + // Attribute : vltSet + vltSetAttrib *vltset = new vltSetAttrib(); + Tango::UserDefaultAttrProp vltset_prop; + vltset_prop.set_description("Input Level Setting kV"); + // label not set for vltSet + // unit not set for vltSet + // standard_unit not set for vltSet + // display_unit not set for vltSet + // format not set for vltSet + // max_value not set for vltSet + // min_value not set for vltSet + // max_alarm not set for vltSet + // min_alarm not set for vltSet + // max_warning not set for vltSet + // min_warning not set for vltSet + // delta_t not set for vltSet + // delta_val not set for vltSet + vltset->set_default_properties(vltset_prop); + // Not Polled + vltset->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(vltset); + + // Attribute : OutputEnable + OutputEnableAttrib *outputenable = new OutputEnableAttrib(); + Tango::UserDefaultAttrProp outputenable_prop; + // description not set for OutputEnable + // label not set for OutputEnable + // unit not set for OutputEnable + // standard_unit not set for OutputEnable + // display_unit not set for OutputEnable + // format not set for OutputEnable + // max_value not set for OutputEnable + // min_value not set for OutputEnable + // max_alarm not set for OutputEnable + // min_alarm not set for OutputEnable + // max_warning not set for OutputEnable + // min_warning not set for OutputEnable + // delta_t not set for OutputEnable + // delta_val not set for OutputEnable + outputenable->set_default_properties(outputenable_prop); + // Not Polled + outputenable->set_disp_level(Tango::OPERATOR); + // Not Memorized + att_list.push_back(outputenable); + + + // Create a list of static attributes + create_static_attribute_list(get_class_attr()->get_attr_list()); + /*----- PROTECTED REGION ID(RfInpClass::attribute_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::attribute_factory_after +} +//-------------------------------------------------------- +/** + * Method : RfInpClass::pipe_factory() + * Description: Create the pipe object(s) + * and store them in the pipe list + */ +//-------------------------------------------------------- +void RfInpClass::pipe_factory() +{ + /*----- PROTECTED REGION ID(RfInpClass::pipe_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::pipe_factory_before + /*----- PROTECTED REGION ID(RfInpClass::pipe_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::pipe_factory_after +} +//-------------------------------------------------------- +/** + * Method : RfInpClass::command_factory() + * Description: Create the command object(s) + * and store them in the command list + */ +//-------------------------------------------------------- +void RfInpClass::command_factory() +{ + /*----- PROTECTED REGION ID(RfInpClass::command_factory_before) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::command_factory_before + + + // Command Abort + AbortClass *pAbortCmd = + new AbortClass("Abort", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pAbortCmd); + + // Command Enable + EnableClass *pEnableCmd = + new EnableClass("Enable", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pEnableCmd); + + // Command Disable + DisableClass *pDisableCmd = + new DisableClass("Disable", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pDisableCmd); + + // Command FastRamp + FastRampClass *pFastRampCmd = + new FastRampClass("FastRamp", + Tango::DEV_VOID, Tango::DEV_VOID, + "", + "", + Tango::OPERATOR); + command_list.push_back(pFastRampCmd); + + /*----- PROTECTED REGION ID(RfInpClass::command_factory_after) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::command_factory_after +} + +//=================================================================== +// Dynamic attributes related methods +//=================================================================== + +//-------------------------------------------------------- +/** + * method : RfInpClass::create_static_attribute_list + * description : Create the a list of static attributes + * + * @param att_list the created attribute list + */ +//-------------------------------------------------------- +void RfInpClass::create_static_attribute_list(std::vector<Tango::Attr *> &att_list) +{ + for (unsigned long i=0 ; i<att_list.size() ; i++) + { + std::string att_name(att_list[i]->get_name()); + transform(att_name.begin(), att_name.end(), att_name.begin(), ::tolower); + defaultAttList.push_back(att_name); + } + + TANGO_LOG_INFO << defaultAttList.size() << " attributes in default list" << std::endl; + + /*----- PROTECTED REGION ID(RfInpClass::create_static_att_list) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::create_static_att_list +} + + +//-------------------------------------------------------- +/** + * method : RfInpClass::erase_dynamic_attributes + * description : delete the dynamic attributes if any. + * + * @param devlist_ptr the device list pointer + * @param list of all attributes + */ +//-------------------------------------------------------- +void RfInpClass::erase_dynamic_attributes(const Tango::DevVarStringArray *devlist_ptr, std::vector<Tango::Attr *> &att_list) +{ + Tango::Util *tg = Tango::Util::instance(); + + for (unsigned long i=0 ; i<devlist_ptr->length() ; i++) + { + Tango::DeviceImpl *dev_impl = tg->get_device_by_name(((std::string)(*devlist_ptr)[i]).c_str()); + RfInp *dev = static_cast<RfInp *> (dev_impl); + + std::vector<Tango::Attribute *> &dev_att_list = dev->get_device_attr()->get_attribute_list(); + std::vector<Tango::Attribute *>::iterator ite_att; + for (ite_att=dev_att_list.begin() ; ite_att != dev_att_list.end() ; ++ite_att) + { + std::string att_name((*ite_att)->get_name_lower()); + if ((att_name == "state") || (att_name == "status")) + continue; + std::vector<std::string>::iterator ite_str = find(defaultAttList.begin(), defaultAttList.end(), att_name); + if (ite_str == defaultAttList.end()) + { + TANGO_LOG_INFO << att_name << " is a UNWANTED dynamic attribute for device " << (*devlist_ptr)[i] << std::endl; + Tango::Attribute &att = dev->get_device_attr()->get_attr_by_name(att_name.c_str()); + dev->remove_attribute(att_list[att.get_attr_idx()], true, false); + --ite_att; + } + } + } + /*----- PROTECTED REGION ID(RfInpClass::erase_dynamic_attributes) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::erase_dynamic_attributes +} + +//-------------------------------------------------------- +/** + * Method : RfInpClass::get_attr_object_by_name() + * Description: returns Tango::Attr * object found by name + */ +//-------------------------------------------------------- +Tango::Attr *RfInpClass::get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname) +{ + std::vector<Tango::Attr *>::iterator it; + for (it=att_list.begin() ; it<att_list.end() ; ++it) + if ((*it)->get_name()==attname) + return (*it); + // Attr does not exist + return NULL; +} + + +/*----- PROTECTED REGION ID(RfInpClass::Additional Methods) ENABLED START -----*/ +/* clang-format on */ +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInpClass::Additional Methods +} // namespace diff --git a/src/RfInpClass.h b/src/RfInpClass.h new file mode 100644 index 0000000000000000000000000000000000000000..45498f36478b5c0e7fa226b22bc70c7671f506df --- /dev/null +++ b/src/RfInpClass.h @@ -0,0 +1,248 @@ +/*----- PROTECTED REGION ID(RfInpClass.h) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : RfInpClass.h +// +// description : Include for the RfInp root class. +// This class is the singleton class for +// the RfInp device class. +// It contains all properties and methods which the +// RfInp requires only once e.g. the commands. +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + + +#ifndef RfInpClass_H +#define RfInpClass_H + +#include <tango.h> +#include "RfInp.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInpClass.h + + +namespace RfInp_ns +{ +/*----- PROTECTED REGION ID(RfInpClass::classes for dynamic creation) ENABLED START -----*/ +/* clang-format on */ + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInpClass::classes for dynamic creation + +//========================================= +// Define classes for attributes +//========================================= +// Attribute vlt class definition +class vltAttrib: public Tango::Attr +{ +public: + vltAttrib():Attr("vlt", + Tango::DEV_DOUBLE, Tango::READ_WRITE) {} + ~vltAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<RfInp *>(dev))->read_vlt(att);} + virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att) + {(static_cast<RfInp *>(dev))->write_vlt(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<RfInp *>(dev))->is_vlt_allowed(ty);} +}; + +// Attribute vltSet class definition +class vltSetAttrib: public Tango::Attr +{ +public: + vltSetAttrib():Attr("vltSet", + Tango::DEV_DOUBLE, Tango::READ) {} + ~vltSetAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<RfInp *>(dev))->read_vltSet(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<RfInp *>(dev))->is_vltSet_allowed(ty);} +}; + +// Attribute OutputEnable class definition +class OutputEnableAttrib: public Tango::Attr +{ +public: + OutputEnableAttrib():Attr("OutputEnable", + Tango::DEV_BOOLEAN, Tango::READ) {} + ~OutputEnableAttrib() {} + virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att) + {(static_cast<RfInp *>(dev))->read_OutputEnable(att);} + virtual bool is_allowed(Tango::DeviceImpl *dev,Tango::AttReqType ty) + {return (static_cast<RfInp *>(dev))->is_OutputEnable_allowed(ty);} +}; + + +//========================================= +// Define classes for commands +//========================================= +// Command Abort class definition +class AbortClass : public Tango::Command +{ +public: + AbortClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + AbortClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~AbortClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<RfInp *>(dev))->is_Abort_allowed(any);} +}; + +// Command Enable class definition +class EnableClass : public Tango::Command +{ +public: + EnableClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + EnableClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~EnableClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<RfInp *>(dev))->is_Enable_allowed(any);} +}; + +// Command Disable class definition +class DisableClass : public Tango::Command +{ +public: + DisableClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + DisableClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~DisableClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<RfInp *>(dev))->is_Disable_allowed(any);} +}; + +// Command FastRamp class definition +class FastRampClass : public Tango::Command +{ +public: + FastRampClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out, + const char *in_desc, + const char *out_desc, + Tango::DispLevel level) + :Command(cmd_name,in,out,in_desc,out_desc, level) {} + + FastRampClass(const char *cmd_name, + Tango::CmdArgType in, + Tango::CmdArgType out) + :Command(cmd_name,in,out) {} + ~FastRampClass() {} + + virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any); + virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any) + {return (static_cast<RfInp *>(dev))->is_FastRamp_allowed(any);} +}; + + +/** + * The RfInpClass singleton definition + */ + +#ifdef _TG_WINDOWS_ +class __declspec(dllexport) RfInpClass : public Tango::DeviceClass +#else +class RfInpClass : public Tango::DeviceClass +#endif +{ + /*----- PROTECTED REGION ID(RfInpClass::Additional DServer data members) ENABLED START -----*/ + /* clang-format on */ + // Add your own code + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInpClass::Additional DServer data members + + public: + // write class properties data members + Tango::DbData cl_prop; + Tango::DbData cl_def_prop; + Tango::DbData dev_def_prop; + // Method prototypes + static RfInpClass *init(const char *); + static RfInpClass *instance(); + ~RfInpClass(); + Tango::DbDatum get_class_property(std::string &); + Tango::DbDatum get_default_device_property(std::string &); + Tango::DbDatum get_default_class_property(std::string &); + + protected: + RfInpClass(std::string &); + static RfInpClass *_instance; + void command_factory(); + void attribute_factory(std::vector<Tango::Attr *> &); + void pipe_factory(); + void write_class_property(); + void set_default_property(); + void get_class_property(); + std::string get_cvstag(); + std::string get_cvsroot(); + + private: + void device_factory(TANGO_UNUSED(const Tango::DevVarStringArray *)); + void create_static_attribute_list(std::vector<Tango::Attr *> &); + void erase_dynamic_attributes(const Tango::DevVarStringArray *,std::vector<Tango::Attr *> &); + std::vector<std::string> defaultAttList; + Tango::Attr *get_attr_object_by_name(std::vector<Tango::Attr *> &att_list, std::string attname); +}; + +} // End of namespace + +#endif // RfInp_H diff --git a/src/RfInpStateMachine.cpp b/src/RfInpStateMachine.cpp new file mode 100644 index 0000000000000000000000000000000000000000..153bee015d13fa542895464ef8f6bf98dd20ebeb --- /dev/null +++ b/src/RfInpStateMachine.cpp @@ -0,0 +1,239 @@ +/*----- PROTECTED REGION ID(RfInpStateMachine.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : RfInpStateMachine.cpp +// +// description : State machine file for the RfInp class +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= + +#include "RfInp.h" + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::RfInpStateMachine.cpp + +//================================================================ +// States | Description +//================================================================ +// ON | The decice is in ON state +// OFF | The decice is in OFF state +// UNKNOWN | The decice is in UNKNOWN state +// FAULT | The decice is in FAULT state +// ALARM | The decice is in ALARM state +// MOVING | The decice is in MOVING state + + +namespace RfInp_ns +{ +//================================================= +// Attributes Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : RfInp::is_vlt_allowed() + * Description: Execution allowed for vlt attribute + */ +//-------------------------------------------------------- +bool RfInp::is_vlt_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + // Check access type. + if ( type!=Tango::READ_REQ ) + { + // Compare device state with not allowed states for WRITE + if (get_state()==Tango::UNKNOWN || + get_state()==Tango::MOVING) + { + /*----- PROTECTED REGION ID(RfInp::vltStateAllowed_WRITE) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::vltStateAllowed_WRITE + return false; + } + return true; + } + else + + // Check access type. + if ( type==Tango::READ_REQ ) + { + // Compare device state with not allowed states for READ + if (get_state()==Tango::UNKNOWN) + { + /*----- PROTECTED REGION ID(RfInp::vltStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::vltStateAllowed_READ + return false; + } + return true; + } + return true; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::is_vltSet_allowed() + * Description: Execution allowed for vltSet attribute + */ +//-------------------------------------------------------- +bool RfInp::is_vltSet_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Check access type. + if ( type==Tango::READ_REQ ) + { + // Compare device state with not allowed states for READ + if (get_state()==Tango::UNKNOWN) + { + /*----- PROTECTED REGION ID(RfInp::vltSetStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::vltSetStateAllowed_READ + return false; + } + return true; + } + return true; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::is_OutputEnable_allowed() + * Description: Execution allowed for OutputEnable attribute + */ +//-------------------------------------------------------- +bool RfInp::is_OutputEnable_allowed(TANGO_UNUSED(Tango::AttReqType type)) +{ + + // Not any excluded states for OutputEnable attribute in read access. + /*----- PROTECTED REGION ID(RfInp::OutputEnableStateAllowed_READ) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::OutputEnableStateAllowed_READ + return true; +} + + +//================================================= +// Commands Allowed Methods +//================================================= + +//-------------------------------------------------------- +/** + * Method : RfInp::is_Abort_allowed() + * Description: Execution allowed for Abort attribute + */ +//-------------------------------------------------------- +bool RfInp::is_Abort_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Compare device state with not allowed states. + if (get_state()==Tango::ON || + get_state()==Tango::OFF || + get_state()==Tango::UNKNOWN || + get_state()==Tango::FAULT || + get_state()==Tango::ALARM) + { + /*----- PROTECTED REGION ID(RfInp::AbortStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::AbortStateAllowed + return false; + } + return true; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::is_Enable_allowed() + * Description: Execution allowed for Enable attribute + */ +//-------------------------------------------------------- +bool RfInp::is_Enable_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Compare device state with not allowed states. + if (get_state()==Tango::UNKNOWN || + get_state()==Tango::MOVING) + { + /*----- PROTECTED REGION ID(RfInp::EnableStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::EnableStateAllowed + return false; + } + return true; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::is_Disable_allowed() + * Description: Execution allowed for Disable attribute + */ +//-------------------------------------------------------- +bool RfInp::is_Disable_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Compare device state with not allowed states. + if (get_state()==Tango::UNKNOWN || + get_state()==Tango::MOVING) + { + /*----- PROTECTED REGION ID(RfInp::DisableStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::DisableStateAllowed + return false; + } + return true; +} + +//-------------------------------------------------------- +/** + * Method : RfInp::is_FastRamp_allowed() + * Description: Execution allowed for FastRamp attribute + */ +//-------------------------------------------------------- +bool RfInp::is_FastRamp_allowed(TANGO_UNUSED(const CORBA::Any &any)) +{ + // Compare device state with not allowed states. + if (get_state()==Tango::UNKNOWN || + get_state()==Tango::MOVING) + { + /*----- PROTECTED REGION ID(RfInp::FastRampStateAllowed) ENABLED START -----*/ + /* clang-format on */ + /* clang-format off */ + /*----- PROTECTED REGION END -----*/ // RfInp::FastRampStateAllowed + return false; + } + return true; +} + + +/*----- PROTECTED REGION ID(RfInp::RfInpStateAllowed.AdditionalMethods) ENABLED START -----*/ +/* clang-format on */ +// Additional Methods +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::RfInpStateAllowed.AdditionalMethods + +} // End of namespace diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b48e783be1f8c84ae67edcbca1bf847c774283aa --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,88 @@ +/*----- PROTECTED REGION ID(RfInp::main.cpp) ENABLED START -----*/ +/* clang-format on */ +//============================================================================= +// +// file : main.cpp +// +// description : C++ source for the RfInp device server main. +// The main rule is to initialize (and create) the Tango +// system and to create the DServerClass singleton. +// The main should be the same for every Tango device server. +// +// +// +// This file is part of Tango device class. +// +// Tango is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Tango is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Tango. If not, see <http://www.gnu.org/licenses/>. +// +// +// +//============================================================================= +// This file is generated by POGO +// (Program Obviously used to Generate tango Object) +//============================================================================= +#include <tango.h> + +// Check if crash reporting is used. +#if defined(ENABLE_CRASH_REPORT) +# include <crashreporting/crash_report.h> +#else +# define DECLARE_CRASH_HANDLER +# define INSTALL_CRASH_HANDLER +#endif + +DECLARE_CRASH_HANDLER + +int main(int argc,char *argv[]) +{ + INSTALL_CRASH_HANDLER + Tango::Util *tg = nullptr; + try + { + // Initialize the device server + //---------------------------------------- + tg = Tango::Util::init(argc,argv); + + // Create the device server singleton + // which will create everything + //---------------------------------------- + tg->server_init(false); + + // Run the endless loop + //---------------------------------------- + std::cout << "Ready to accept request" << std::endl; + tg->server_run(); + } + catch (std::bad_alloc &) + { + std::cout << "Can't allocate memory to store device object !!!" << std::endl; + std::cout << "Exiting" << std::endl; + } + catch (CORBA::Exception &e) + { + Tango::Except::print_exception(e); + + std::cout << "Received a CORBA_Exception" << std::endl; + std::cout << "Exiting" << std::endl; + } + + if(tg) + { + tg->server_cleanup(); + } + return(0); +} + +/* clang-format off */ +/*----- PROTECTED REGION END -----*/ // RfInp::main.cpp