#ifndef KNOB_USER_EPICS_H #define KNOB_USER_EPICS_H #ifdef __cplusplus extern "C" { #endif #include "knobCtrlDef.h" #define NO_REQUEST 0 #define ATTACH_REQ 3 #define ATTACHED 2 #define DETACH_REQ 1 #define DETACHED 0 /* * First legend row is for device name, 16 characters max * second is for device value, 8 characters max */ #define LEGEND_LABEL_SIZE LEGEND_ROW0_USER_SIZE #define LEGEND_VALUE_SIZE LEGEND_ROW1_USER_SIZE #define LEGEND_LABEL_ROW 0 #define LEGEND_VALUE_ROW 1 extern int legendRowSize[MAX_ROWS_LEGEND]; #define MAX_EGU_LENGTH 16 /* Imitated EPICS base */ #define MAX_NAME_LENGTH 61 /* Imitated EPICS base */ /* Knob User error codes */ #define KNOB_OK 0 #define KNOB_CONN_FAIL 1 #define KNOB_NO_WRITE 2 #define KNOB_ILLEGAL_TYPE 3 #define KNOB_LOW_LIMIT 4 #define KNOB_HIGH_LIMIT 5 #define KNOB_USURP 6 #define KNOB_FAC_MSG 9 /* For use by facility specific callback */ extern epicsMutexId kuserBoxMtx[MAX_BOXES_LINE]; extern epicsEnum16 kuserdebug[MAX_BOXES_LINE]; extern epicsEnum16 kuserdebug_lck[MAX_BOXES_LINE]; #define KNOB_MSG_COUNT 10 extern char knobmsgarray[KNOB_MSG_COUNT][MAX_STRING_SIZE]; typedef void (*KnobUserWriteFunc)(const void *rec, void *val); /* * Data structure for device attached to knob * Variables that only the driver changes */ typedef struct { int line; int box; int knob; int state; /* Current state of knob */ int rstate; /* Requested state */ char legend[MAX_ROWS_LEGEND][LEGEND_SIZE]; /* Current legend string */ char label[LEGEND_LABEL_SIZE]; // Device label used on legend epicsInt32 prec; /* Precision for value on knob display */ char rname[MAX_NAME_LENGTH]; // PV name for attach request epicsFloat64 turns; // test this epicsFloat64 val[4]; // init, saved, last value read, last value written epicsFloat64 writeval; // last value written to device epicsFloat64 readval; // last value read from device epicsFloat64 initval; // value at time of restore epicsFloat64 saveval; // ref value saved by user epicsFloat64 hopr; epicsFloat64 lopr; epicsFloat64 drvh; epicsFloat64 drvl; int drv; /* Flag to indicate drvl/drvh have been configured */ int isfield; /* PV is field besides .VAL */ char desc[MAX_STRING_SIZE]; char egu[MAX_EGU_LENGTH]; uint32_t seqnum; /* Msg sequence number for knob<->us communication (imitates VAX implementation) */ int msg; int deviceconn; /* Device connection state, value is KNOB_OK, KNOB_CONN_FAIL, or KNOB_NO_WRITE */ void *device; /* Handle for device attached to knob */ epicsMutexId mtx; } knobdevice_ts; /* * Data structure for values that both the driver and the user interface (device support) * need to be able to change. Currently 4 cases of this (see DEVSUP_ defined at bottom of file). * * For changes from device support: when the record is processed, device support calls * a driver routine to update the value in the driver data structure (and take any other * related actions) * * For changes from driver: when the driver determines a new value, it uses the appropriate * KnobUserWriteFunc routine to send the new value to device support, which updates the record. * (Pointers to these functions are passed to the driver during device support initialization.) */ typedef struct { KnobUserWriteFunc writefunc[5]; /* Function pointer to write to EPICS records */ void *rec[5]; /* User argument for writing new name, may be pointer to record */ epicsFloat64 sens; /* Knob sensitivity: units/turn */ epicsMutexId mtx; } knobshr_ts; /* * Global data structure * * The mtx member is used for locking line, period. * (In practice, line and period are only modified at startup, so this may never be locked.) * The knobs and shr data structures have their own mutexes that must be locked. * Locking of the deviceio and ctrlio handles is handled by callbacks */ typedef struct { knobdevice_ts knobs_as[MAX_BOXES_LINE][MAX_KNOBS_BOX]; knobshr_ts shr_as[MAX_BOXES_LINE][MAX_KNOBS_BOX]; void *deviceio_p; /* Handle for comm with device, passed to callbacks, callbacks must handle locking */ void *ctrlio_p; /* Handle for comm with controller, passed to callbacks, callbacks must handle locking */ int line; /* Line number used in comm with boxes, we only support one line */ epicsInt32 period; /* Processing period */ epicsMutexId mtx; /* Must be locked for line, period. Other members have their own mutexes */ } kuserglobal_ts; extern kuserglobal_ts kuserglobal_s; /* ** Callbacks for communication with knob controller */ typedef struct { int (*init_comm) (void *io, int *parm); int (*init_line) (line_ts *line_ps, void *lineio); int (*init_box) (line_ts *line_ps, box_ts *box_ps); void (*write) (unsigned char *bufo_p, int count, uint32_t *iss, int dbg); void (*read) (unsigned char *inmsgbuf, int *inmsglen, int dbg); uint32_t (*write_uint32 ) (uint32_t); uint16_t (*write_uint16 ) (uint16_t); uint32_t (*read_uint32 ) (uint32_t); uint16_t (*read_uint16 ) (uint16_t); } kuserctrlcb_ts; /* * Callbacks for communication with knob device * void *device is private data for knob device callbacks * init_knob callback initializes it and returns it, then it is * stored in knobdevice_ts struct. Dbg flag/verbosity level * is passed to many callbacks. * * init: Called in single thread at startup * Return -1 if error, 0 if success * * init_knob: Knob device datainitialization. * Called in single thread at startup * Returns void *device * * reset_knob: Knob device data reset to defaults between attachments * * connect: Connect to device attached to knob * Return KNOBDEV_CONN_ERR if error, KNOBDEV_CONN_OK if success * * poll: Global poll all devices for updates. Seems to be needed * for Channel Access device. Currently no arguments * because not needed for CA but need to figure out better * way to handle this * * get_state: Get connection and write privilege state * Returns * KNOB_OK - connected and have write access * KNOB_CONN_FAIL - connection error * KNOBDEV_NO_WRITE - connected but no write access * KNOB_ILLEGAL_TYPE - unsupported data type * * get_info: Get device info * Set newinfo to 1 if successfully retrieved new value, * else set to 0. If no new info, leave egu, hopr, lopr, * drvh, drvl unmodified * * get_val: Get device value * Set newval to 1 if successfully retrieved new value, * else set to 0. If no new data, leave val unmodified. * * put_val: Put device value * Return -1 if error, 0 if success * * connect_get_val: Connect to device, get value, disconnect from device * Not to be used for device attached to knob, but instead for * temporary connections in order to get meta data * Return 0 if error, void * value of device if success */ typedef struct { int (*init) (void); void *(*init_knob) (void); void (*reset_knob)(void *device, int dbg); int (*connect) (void *device, char *name, int dbg); void (*poll) (void); int (*get_state) (void *device, int dbg); void (*get_info) (void *device, int *newinfo, char *egu, epicsFloat64 *hopr, epicsFloat64 *lopr, epicsFloat64 *drvh, epicsFloat64 *drvl, int dbg); void (*get_val) (void *device, int *newval, epicsFloat64 *val, int dbg); int (*put_val) (void *device, epicsFloat64 val, int dbg); void *(*connect_get_val) (void *device, char *name, int dbg); } kuserdevcb_ts; /* * Callbacks for facility-specific routines * * knob_settings: Get knob label and sensitivity * Optional routine to set these parameters. New label string is set * in data->label. New sens value is set in sens argument. flabel * and fsens arguments are flags to indicate to caller that label * or sens has been successfully determined and set. * * Note: label is string of ascii characters to print on legend, it * should not contain an end-of-string character * * Return -1 if device should NOT be attached, else return 0 */ typedef struct { int (*knob_settings) (char *name, int *fsens, epicsFloat64 *sens, int *flabel, char *label, int *fprec, epicsInt32 *prec, int dbg, epicsFloat64 drv, epicsFloat64 drvl, epicsFloat64 drvh, epicsFloat64 lopr, epicsFloat64 hopr, int *msg); }kuserfaccb_ts; extern kuserctrlcb_ts knobUserCtrlCommCallbacks; extern const void *knobUserCtrlCommCbRegistryId; extern kuserdevcb_ts knobUserDevCommCallbacks; extern const void *knobUserDevCommCbRegistryId; /* This is optional and set as global variable in st.cmd */ extern kuserfaccb_ts knobFacCallbacks; extern const void *knobFacCbRegistryId; #define DEVSUP_DEVNAME 1 #define DEVSUP_SENS 2 #define DEVSUP_LABEL 3 #define DEVSUP_PREC 4 /* Routines called by device support */ void drvKnobEpicsInitFunction(int b, int k, void *rec, void *func, int task); void drvKnobEpicsAttachRequest(int b, int k, char *name); void drvKnobEpicsDetachRequest(int b, int k); void drvKnobEpicsGetEgu(int b, int k, char *egu); void drvKnobEpicsGetMsg(int b, int k, char *msg); void drvKnobEpicsSaveVal(int b, int k); void drvKnobEpicsSetVal(int b, int k, int index); void drvKnobEpicsGetVal(int b, int k, int index, epicsFloat64 *val); void drvKnobEpicsSetSens(int b, int k, epicsFloat64 val); void drvKnobEpicsGetState(int b, int k, epicsUInt32 *state); //void drvKnobEpicsSetLabel(int b, int k, char *label); void drvKnobEpicsGetLabel(int b, int k, char *label); void drvKnobEpicsSetPrec(int b, int k, epicsInt32 prec); void drvKnobEpicsGetPrec(int b, int k, epicsInt32 *prec); #ifdef __cplusplus }; #endif #endif /* KNOB_USER_EPICS_H guard macro */