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

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 $
1.1.1.1.2.2! misho       6: * $Id: aitpelco.h,v 1.1.1.1.2.1 2010/03/11 13:39:28 misho Exp $
1.1       misho       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: /*
1.1.1.1.2.1  misho     134:  * pelcoLoad() Load packet from input buffer
                    135:  * @buffer = Pelco packet from input buffer
                    136:  * return: NULL error, !=NULL ok, allocated memory for packet
                    137:  */
                    138: inline void *pelcoLoad(u_char *buffer);
                    139: 
                    140: 
                    141: /*
1.1       misho     142:  * pelcoAddCmdData() Add commands and datas for already opened packet
                    143:  * @p = Input Packet structure
                    144:  * @cmd[2] = Input Commands 1 & 2
                    145:  * @data[2] = Input Data for commands 1 & 2
                    146:  * return: 0xFF - error, 0 - ok
                    147:  */
                    148: inline u_char pelcoAddCmdData(void * __restrict p, u_char * __restrict cmd, u_char * __restrict data);
                    149: 
1.1.1.1.2.2! misho     150: /*
        !           151:  * pelcoGetCmdData() Get from packet commands and datas with verify packet
        !           152:  * @p = Input Packet structure
        !           153:  * @cmd[2] = Output Commands 1 & 2
        !           154:  * @data[2] = Output Data for commands 1 & 2
        !           155:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
        !           156:  */
        !           157: inline u_char pelcoGetCmdData(void * __restrict p, u_char * __restrict cmd, u_char * __restrict data);
        !           158: 
1.1       misho     159: 
                    160: /*
                    161:  * pelco_GetVersion() Return Pelco protocol version
                    162:  * @p = Packet structure
                    163:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    164:  */
                    165: inline u_char pelco_GetVersion(void * __restrict p);
                    166: 
                    167: /*
                    168:  * pelco_GetCamNo() Get Camera number and check for valid packet
                    169:  * @p = Packet structure
                    170:  * return: 0xFF and pelco_GetErrno() == ENOEXEC - error, 
                    171:        any number is camera address
                    172:  */
                    173: inline u_char pelco_GetCamNo(void * __restrict p);
                    174: 
                    175: /*
                    176:  * pelco_GetCamCmdData() Get from Camera commands and datas with verify packet
                    177:  * @p = Input Packet structure
                    178:  * @cam = Output camera number
                    179:  * @cmd[2] = Output Commands 1 & 2
                    180:  * @data[2] = Output Data for commands 1 & 2
                    181:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    182:  */
                    183: inline u_char pelco_GetCamCmdData(void * __restrict p, u_char * __restrict cam, 
                    184:                u_char * __restrict cmd, u_char * __restrict data);
                    185: 
                    186: /*
                    187:  * pelco_D_toCmd() Convert to Pelco D commands
                    188:  * @cmd[2] = Input Commands 1 & 2
                    189:  * @cmd1 = Output typecasted commands 1
                    190:  * @cmd2 = Output typecasted commands 2
                    191:  * return: 0xFF - error, !=0 return number arguments
                    192:  */
                    193: inline u_char pelco_D_toCmd(u_char * __restrict cmd, 
                    194:                struct bitD_Cmd1 * __restrict cmd1, struct bitD_Cmd2 * __restrict cmd2);
                    195: 
                    196: /*
                    197:  * pelco_P_toCmd() Convert to Pelco P commands
                    198:  * @cmd[2] = Input Commands 1 & 2
                    199:  * @cmd1 = Output typecasted commands 1
                    200:  * @cmd2 = Output typecasted commands 2
                    201:  * return: 0xFF - error, !=0 return number arguments
                    202:  */
                    203: inline u_char pelco_P_toCmd(u_char * __restrict cmd, 
                    204:                struct bitP_Cmd1 * __restrict cmd1, struct bitP_Cmd2 * __restrict cmd2);
                    205: 
                    206: /*
                    207:  * pelco_D_fromCmd() Convert from Pelco D commands
                    208:  * @cmd1 = Input typecasted commands 1
                    209:  * @cmd2 = Input typecasted commands 2
                    210:  * @cmd[2] = Output Commands 1 & 2
                    211:  * return: 0xFF - error, 0 - ok
                    212:  */
                    213: inline u_char pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2, 
                    214:                u_char * __restrict cmd);
                    215: 
                    216: /*
                    217:  * pelco_P_fromCmd() Convert from Pelco P commands
                    218:  * @cmd1 = Input typecasted commands 1
                    219:  * @cmd2 = Input typecasted commands 2
                    220:  * @cmd[2] = Output Commands 1 & 2
                    221:  * return: 0xFF - error, 0 - ok
                    222:  */
                    223: inline u_char pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2, 
                    224:                u_char * __restrict cmd);
                    225: 
                    226: /*
                    227:  * pelco_SetCamCmdData() Set Camera commands and datas
                    228:  * @ver = Input Pelco (d | p) version
                    229:  * @cam = Input camera number
                    230:  * @cmd[2] = Input Commands 1 & 2
                    231:  * @data[2] = Input Data for commands 1 & 2
                    232:  * @p = Output Packet structure
                    233:  * return: 0xFF - error, 0 - ok
                    234:  */
                    235: inline u_char pelco_SetCamCmdData(u_char ver, u_char __restrict cam, 
                    236:                u_char * __restrict cmd, u_char * __restrict data, void * __restrict p);
                    237: 
                    238: 
                    239: #endif

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