Annotation of libaitpelco/inc/aitpelco.h, revision 1.1.1.1

1.1       misho       1: /*************************************************************************
                      2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
                      3: *  by Michael Pounov <misho@openbsd-bg.org>
                      4: *
                      5: * $Author: misho $
                      6: * $Id: aitcrc.h,v 1.1.1.1.2.1 2008/11/05 17:29:19 misho Exp $
                      7: *
                      8: *************************************************************************/
                      9: #ifndef __AITPELCO_H
                     10: #define __AITPELCO_H
                     11: 
                     12: 
                     13: #include <sys/types.h>
                     14: 
                     15: 
                     16: #define PELCO_D_LEN    7
                     17: #define PELCO_P_LEN    8
                     18: 
                     19: #define FIXED_ZERO     0
                     20: 
                     21: #define VER_D_SYNC     0xFF
                     22: #define VER_P_STX      0xA0
                     23: #define VER_P_ETX      0xAF
                     24: 
                     25: #define FIRST_CAM_D    1
                     26: #define FIRST_CAM_P    0
                     27: 
                     28: #define SPEED_MIN      0x00
                     29: #define SPEED_HI       0x3F
                     30: #define SPEED_MAX      0x40
                     31: 
                     32: #define PAN_STOP       SPEED_MIN
                     33: #define PAN_FAST       SPEED_HI
                     34: #define PAN_TURBO      SPEED_MAX
                     35: #define TILT_STOP      SPEED_MIN
                     36: #define TILT_FAST      SPEED_HI
                     37: 
                     38: 
                     39: /* Pelco-D protocol */
                     40: 
                     41: // Helper Command bitField structures
                     42: 
                     43: struct bitD_Cmd1 {
                     44:        u_char focus_near:1;
                     45:        u_char iris_open:1;
                     46:        u_char iris_close:1;
                     47:        u_char cam_on:1;
                     48:        u_char auto_scan:1;
                     49:        u_char reserved:2;
                     50:        u_char sense:1;
                     51: };
                     52: 
                     53: struct bitD_Cmd2 {
                     54:        u_char fixed:1;
                     55:        u_char pan_right:1;
                     56:        u_char pan_left:1;
                     57:        u_char tilt_up:1;
                     58:        u_char tilt_down:1;
                     59:        u_char zoom_tele:1;
                     60:        u_char zoom_wide:1;
                     61:        u_char focus_far:1;
                     62: };
                     63: 
                     64: typedef struct tagPelcoD {
                     65:        u_char d_sync;
                     66:        u_char d_cam;
                     67:        struct bitD_Cmd1 d_cmd1;
                     68:        struct bitD_Cmd2 d_cmd2;
                     69:        u_char d_data[2];
                     70:        u_char d_crc;
                     71: } pelco_d_t;   // 7 bytes packet
                     72: 
                     73: 
                     74: /* Pelco-P protocol */
                     75: 
                     76: // Helper Data bitField structures
                     77: 
                     78: struct bitP_Cmd1 {
                     79:        u_char focus_far:1;
                     80:        u_char focus_near:1;
                     81:        u_char iris_open:1;
                     82:        u_char iris_close:1;
                     83:        u_char cam_on:1;
                     84:        u_char auto_scan:1;
                     85:        u_char camera:1;
                     86:        u_char fixed:1;
                     87: };
                     88: 
                     89: struct bitP_Cmd2 {
                     90:        u_char for_pan_tilt:1;
                     91:        u_char pan_right:1;
                     92:        u_char pan_left:1;
                     93:        u_char tilt_up:1;
                     94:        u_char tilt_down:1;
                     95:        u_char zoom_tele:1;
                     96:        u_char zoom_wide:1;
                     97:        u_char fixed:1;
                     98: };
                     99: 
                    100: typedef struct tagPelcoP {
                    101:        u_char p_stx;
                    102:        u_char p_cam;
                    103:        struct bitP_Cmd1 p_cmd1;
                    104:        struct bitP_Cmd2 p_cmd2;
                    105:        u_char p_data[2];
                    106:        u_char p_etx;
                    107:        u_char p_crc;
                    108: } pelco_p_t;   // 8 bytes packet
                    109: 
                    110: 
                    111: // -------------------------------------------------------
                    112: // pelco_GetErrno() Get error code of last operation
                    113: inline int pelco_GetErrno();
                    114: // pelco_GetError() Get error text of last operation
                    115: inline const char *pelco_GetError();
                    116: // -------------------------------------------------------
                    117: 
                    118: 
                    119: /*
                    120:  * pelcoOpen() Open packet record for camera number with Pelco version D/P
                    121:  * @pelcoVer = Pelco protocol version Dd | Pp
                    122:  * @camNo = Packet for camera number address
                    123:  * return: NULL error, !=NULL ok, allocated memory for packet
                    124:  */
                    125: inline void *pelcoOpen(u_char pelcoVer, u_char camNo);
                    126: 
                    127: /*
                    128:  * pelcoClose() Close packet record and free memory
                    129:  * @p = Packet structure for close
                    130:  */
                    131: inline void pelcoClose(void * __restrict p);
                    132: 
                    133: /*
                    134:  * pelcoAddCmdData() Add commands and datas for already opened packet
                    135:  * @p = Input Packet structure
                    136:  * @cmd[2] = Input Commands 1 & 2
                    137:  * @data[2] = Input Data for commands 1 & 2
                    138:  * return: 0xFF - error, 0 - ok
                    139:  */
                    140: inline u_char pelcoAddCmdData(void * __restrict p, u_char * __restrict cmd, u_char * __restrict data);
                    141: 
                    142: 
                    143: /*
                    144:  * pelco_GetVersion() Return Pelco protocol version
                    145:  * @p = Packet structure
                    146:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    147:  */
                    148: inline u_char pelco_GetVersion(void * __restrict p);
                    149: 
                    150: /*
                    151:  * pelco_GetCamNo() Get Camera number and check for valid packet
                    152:  * @p = Packet structure
                    153:  * return: 0xFF and pelco_GetErrno() == ENOEXEC - error, 
                    154:        any number is camera address
                    155:  */
                    156: inline u_char pelco_GetCamNo(void * __restrict p);
                    157: 
                    158: /*
                    159:  * pelco_GetCamCmdData() Get from Camera commands and datas with verify packet
                    160:  * @p = Input Packet structure
                    161:  * @cam = Output camera number
                    162:  * @cmd[2] = Output Commands 1 & 2
                    163:  * @data[2] = Output Data for commands 1 & 2
                    164:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    165:  */
                    166: inline u_char pelco_GetCamCmdData(void * __restrict p, u_char * __restrict cam, 
                    167:                u_char * __restrict cmd, u_char * __restrict data);
                    168: 
                    169: 
                    170: /*
                    171:  * pelco_D_toCmd() Convert to Pelco D commands
                    172:  * @cmd[2] = Input Commands 1 & 2
                    173:  * @cmd1 = Output typecasted commands 1
                    174:  * @cmd2 = Output typecasted commands 2
                    175:  * return: 0xFF - error, !=0 return number arguments
                    176:  */
                    177: inline u_char pelco_D_toCmd(u_char * __restrict cmd, 
                    178:                struct bitD_Cmd1 * __restrict cmd1, struct bitD_Cmd2 * __restrict cmd2);
                    179: 
                    180: /*
                    181:  * pelco_P_toCmd() Convert to Pelco P commands
                    182:  * @cmd[2] = Input Commands 1 & 2
                    183:  * @cmd1 = Output typecasted commands 1
                    184:  * @cmd2 = Output typecasted commands 2
                    185:  * return: 0xFF - error, !=0 return number arguments
                    186:  */
                    187: inline u_char pelco_P_toCmd(u_char * __restrict cmd, 
                    188:                struct bitP_Cmd1 * __restrict cmd1, struct bitP_Cmd2 * __restrict cmd2);
                    189: 
                    190: /*
                    191:  * pelco_D_fromCmd() Convert from Pelco D commands
                    192:  * @cmd1 = Input typecasted commands 1
                    193:  * @cmd2 = Input typecasted commands 2
                    194:  * @cmd[2] = Output Commands 1 & 2
                    195:  * return: 0xFF - error, 0 - ok
                    196:  */
                    197: inline u_char pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2, 
                    198:                u_char * __restrict cmd);
                    199: 
                    200: /*
                    201:  * pelco_P_fromCmd() Convert from Pelco P commands
                    202:  * @cmd1 = Input typecasted commands 1
                    203:  * @cmd2 = Input typecasted commands 2
                    204:  * @cmd[2] = Output Commands 1 & 2
                    205:  * return: 0xFF - error, 0 - ok
                    206:  */
                    207: inline u_char pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2, 
                    208:                u_char * __restrict cmd);
                    209: 
                    210: /*
                    211:  * pelco_SetCamCmdData() Set Camera commands and datas
                    212:  * @ver = Input Pelco (d | p) version
                    213:  * @cam = Input camera number
                    214:  * @cmd[2] = Input Commands 1 & 2
                    215:  * @data[2] = Input Data for commands 1 & 2
                    216:  * @p = Output Packet structure
                    217:  * return: 0xFF - error, 0 - ok
                    218:  */
                    219: inline u_char pelco_SetCamCmdData(u_char ver, u_char __restrict cam, 
                    220:                u_char * __restrict cmd, u_char * __restrict data, void * __restrict p);
                    221: 
                    222: 
                    223: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>