/* ============================================================================ Abs: Knob Controller <--> Knob Box message structures & definitions. Most copied from PC knob files pkdef.h, pkparams.h pkpcstru.h Name: knobCtrlDef.h ============================================================================= */ #ifndef KNOB_CTRL_DEF_H #define KNOB_CTRL_DEF_H #include /* integer types */ #include #include #include #include /* ** Debug verbosity levels */ #define OFF 0 #define LOW 1 #define MED 2 #define HIGH 3 #define UNKNOWN_BOX 0 #define KNOB_BOX_PRO 1 extern unsigned short debug; /* ** The following error codes are sent to the knob user, in userstat ** field of message (see knobCtrlUserCommDef.h) ** ** (An additional status, sstatus, indicates if the last message to/from ** the knob was successful.) ** */ #define CK_UNKWN_MSG ((unsigned long)0x088A8352) #define CK_BADPARAM ((unsigned long)0x088A834A) #define CK_CKSUM ((unsigned long)0x088A8342) #define CK_READ_TIMEOUT ((unsigned long)0x088A833A) #define CK_DR_TIMEOUT ((unsigned long)0x088A8332) #define CK_RECVON_TIMEOUT ((unsigned long)0x088A832A) #define CK_WCHAR_TIMEOUT ((unsigned long)0x088A8322) #define CK_OKOK ((unsigned long)0x088A8001) #define CK$_FACILITY ((unsigned short)0x0000088A) /* ** SUCCESS macro used for both userstat and sstatus */ #define SUCCESS(status) ((status)&1) /* ** The maximum lines, boxes and knobs for an instance of this program. ** We only support 1 line now (line 0) per knob controller instance. Historically, ** multiple were supported and that is why we still pass the line number in messages. */ #define LINE_ID 0 /* Line is always '0' */ #define MAX_BOXES_LINE 16 /* Maximum # knob boxes per line */ #define MAX_KNOBS_BOX 4 /* Maximum # knobs per box */ /* ** Legend info ** ** Miranova legends: 1 row of 16 characters ** Knob Box Pro legends: 2 rows of 16 characters, but only 8 characters of second row are available to user; ** other 8 characters are reserved for use by box code ** ** This setup is a little strange. To keep comm between knobCtrl and knobUser software fairly simple, ** the knobUser software does not know what hardware box it is using and just assumes it has the full ** amount of legend available to it (i.e. Knob Box Pro size). The knobCtrl software will know what kind ** of box it is, if the knobUser sends characters for row 2, knobCtrl will copy these characters into ** the end of row 1. This is not ideal, but keeps it backward-compatible with SCP code, and since the ** Miranova boxes are now the minority and slowly being replaced, the risk of this causing problems is ** pretty low. */ #define LEGEND_SIZE 16 /* Max legend size */ #define MAX_ROWS_LEGEND 2 /* Knob boxes pro have 2 rows; Miranova 1 */ #define LEGEND_ROW0_USER_SIZE 16 /* Row 0 characters available to knob user */ #define LEGEND_ROW1_USER_SIZE 8 /* Row 1 characters available to knob user */ #define LEGEND_SET_ROW(i,r) (i|(r<<7)) /* Encode row number in MSB of LED index byte */ #define LEGEND_GET_ROW(x) ((x&(1<<7))>>7) /* Extract MSB from index byte, this gives row number */ #define LEGEND_CLEAR_ROW(x) (x&(0<<7)) /* Clear row number */ #ifdef __cplusplus extern "C" { #endif typedef struct knobcbrec *knobcb_ps; typedef struct kusercbrec *kusercb_ps; /* Structure for communicating with knob users */ typedef struct { void *kuserio_p; /* Handle for communicating with knob's user */ uint32_t lkstatus; /* Last status byte sent from knob box */ uint32_t laststat; /* Last status sent to user for this knob */ uint32_t errors; /* Count of errors for this knob */ uint32_t seqnum; /* Last received message sequence number */ int32_t counts; /* Running turns count total */ }kusermsg_ts; /* Knob structure */ typedef struct { /* ledset, ledcpu are set once at startup */ unsigned char ledset; /* led set (0-3) in box aka knob number; this is accessed without locking because it is set once in single thread at startup */ unsigned char ledcpu; /* led id (cpuid) on line */ int firstuse; /* 1 = knob has not yet been used */ unsigned char attached; /* 1 = knob is attached, 0 = not */ char legend[MAX_ROWS_LEGEND][LEGEND_SIZE]; /* Legend to write to knob */ int legendtowrite[MAX_ROWS_LEGEND]; /* 1 if legend to be written, 0 if not */ unsigned char legendindex[MAX_ROWS_LEGEND]; /* Legend LED index at which legend begins */ int legendvalid[MAX_ROWS_LEGEND]; /* Indicates there is a valid legend string that should be restored after box reboot */ uint32_t legendseqnum;/* Sequence number for last legend update */ uint8_t hwrestore; /* Intermittent HW restore status */ uint32_t type; /* Box hardware type, copied from box_ts struct */ void *kuserio_p; /* Handle for communicating with knob's user */ uint32_t lkstatus; /* Last status byte sent from knob box */ uint32_t laststat; /* Last status sent to user for this knob */ uint32_t errors; /* Count of errors for this knob */ uint32_t seqnum; /* Last received message sequence number */ int32_t counts; /* Running turns count total */ epicsMutexId mtx; /* Mutex for accessing members of this struct */ }knob_ts; /* ** A knob box. Assume each box can be accessed in parallel by separate threads */ typedef struct { void *boxio_p; /* Device handle for communicating with knob box */ char exists; /* This box exists i.e. was attached */ int firstuse; /* 0 = box has not yet been initialized */ unsigned char firstcpu; /* Index of first cpu this box */ knob_ts knobs_as[MAX_KNOBS_BOX]; /* Knobs this box */ int connected; /* Successfully connected to the box */ uint32_t type; /* Box hardware type (KNOB_BOX_PRO or MIRANOVA) */ /* Version numbers not currently used by software. If we add EPICS PVs for these, will likely need to change data types */ unsigned char versmajor; /* Box major version number */ unsigned char versminor; /* Box minor version number */ unsigned char verspatch; /* Box patch version number */ int checkinfo; /* Box just powered up, must re-read box info */ epicsMutexId mtx; /* Mutex for accessing members of this struct and for communication with knob box */ int box; /* Box number; this is accessed without locking because it is set once in single thread at startup */ }box_ts; /* ** A communication line. (typically a ethernet<->serial terminal server) ** Assume the line does NOT need to be locked when communicating with a box; ** locking the box is sufficient */ typedef struct { void *lineio_p; /* Device handle for this knob communication line */ int exists; /* This line exists i.e. has boxes */ box_ts boxes_as[MAX_BOXES_LINE]; int line; /* Line number */ epicsMutexId mtx; /* Mutex for accessing members of this struct, except boxes_as structs, which have their own mutexes */ }line_ts; /* The top level global structure containing line, box, knob info */ typedef struct { void *ctrlio_p; /* Knob controller I/O; used in comm with knob users (user is client; controller is server) */ void *kuserio_p; /* I/O info for new messages from users */ line_ts line_s; /* Line struct */ uint32_t mask; /* Mask of supported boxes, see knobCtrl.c */ epicsMutexId mtx; /* Mutex for communicating with knob users, single socket is used for those messages */ }ctrlglobal_ts; #ifdef __cplusplus }; #endif #endif /* KNOB_CTRL_DEF_H guard macro */