Annotation of libaitpelco/inc/aitpelco.h, revision 1.1.1.1.2.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 $
1.1.1.1.2.1! misho 6: * $Id: aitpelco.h,v 1.1.1.1 2010/01/22 00:57:32 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:
150:
151: /*
152: * pelco_GetVersion() Return Pelco protocol version
153: * @p = Packet structure
154: * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
155: */
156: inline u_char pelco_GetVersion(void * __restrict p);
157:
158: /*
159: * pelco_GetCamNo() Get Camera number and check for valid packet
160: * @p = Packet structure
161: * return: 0xFF and pelco_GetErrno() == ENOEXEC - error,
162: any number is camera address
163: */
164: inline u_char pelco_GetCamNo(void * __restrict p);
165:
166: /*
167: * pelco_GetCamCmdData() Get from Camera commands and datas with verify packet
168: * @p = Input Packet structure
169: * @cam = Output camera number
170: * @cmd[2] = Output Commands 1 & 2
171: * @data[2] = Output Data for commands 1 & 2
172: * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
173: */
174: inline u_char pelco_GetCamCmdData(void * __restrict p, u_char * __restrict cam,
175: u_char * __restrict cmd, u_char * __restrict data);
176:
177:
178: /*
179: * pelco_D_toCmd() Convert to Pelco D commands
180: * @cmd[2] = Input Commands 1 & 2
181: * @cmd1 = Output typecasted commands 1
182: * @cmd2 = Output typecasted commands 2
183: * return: 0xFF - error, !=0 return number arguments
184: */
185: inline u_char pelco_D_toCmd(u_char * __restrict cmd,
186: struct bitD_Cmd1 * __restrict cmd1, struct bitD_Cmd2 * __restrict cmd2);
187:
188: /*
189: * pelco_P_toCmd() Convert to Pelco P commands
190: * @cmd[2] = Input Commands 1 & 2
191: * @cmd1 = Output typecasted commands 1
192: * @cmd2 = Output typecasted commands 2
193: * return: 0xFF - error, !=0 return number arguments
194: */
195: inline u_char pelco_P_toCmd(u_char * __restrict cmd,
196: struct bitP_Cmd1 * __restrict cmd1, struct bitP_Cmd2 * __restrict cmd2);
197:
198: /*
199: * pelco_D_fromCmd() Convert from Pelco D commands
200: * @cmd1 = Input typecasted commands 1
201: * @cmd2 = Input typecasted commands 2
202: * @cmd[2] = Output Commands 1 & 2
203: * return: 0xFF - error, 0 - ok
204: */
205: inline u_char pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2,
206: u_char * __restrict cmd);
207:
208: /*
209: * pelco_P_fromCmd() Convert from Pelco P commands
210: * @cmd1 = Input typecasted commands 1
211: * @cmd2 = Input typecasted commands 2
212: * @cmd[2] = Output Commands 1 & 2
213: * return: 0xFF - error, 0 - ok
214: */
215: inline u_char pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2,
216: u_char * __restrict cmd);
217:
218: /*
219: * pelco_SetCamCmdData() Set Camera commands and datas
220: * @ver = Input Pelco (d | p) version
221: * @cam = Input camera number
222: * @cmd[2] = Input Commands 1 & 2
223: * @data[2] = Input Data for commands 1 & 2
224: * @p = Output Packet structure
225: * return: 0xFF - error, 0 - ok
226: */
227: inline u_char pelco_SetCamCmdData(u_char ver, u_char __restrict cam,
228: u_char * __restrict cmd, u_char * __restrict data, void * __restrict p);
229:
230:
231: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>