File:  [ELWIX - Embedded LightWeight unIX -] / libaitpelco / inc / aitpelco.h
Revision 1.1.1.1.2.4: download - view: text, annotated - select for diffs - revision graph
Thu Mar 17 08:36:14 2011 UTC (13 years, 5 months ago) by misho
Branches: pelco1_0
Diff to: branchpoint 1.1.1.1: preferred, unified
fix unwanted restrict

    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: aitpelco.h,v 1.1.1.1.2.4 2011/03/17 08:36:14 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:  * 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: /*
  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:  * 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: 
  159: /*
  160:  * pelcoChkSum() Check ot Correct check sum in packet
  161:  * @p = Input Packet structure
  162:  * @correct = Calculate new check sum if incorrect !=0, if ==0 only check
  163:  * return: 0xFF - bad packet, invalid check sum, 0 check sum is correct.
  164:  */
  165: inline u_char pelcoChkSum(void * __restrict p, u_char correct);
  166: 
  167: 
  168: /*
  169:  * pelco_GetVersion() Return Pelco protocol version
  170:  * @p = Packet structure
  171:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
  172:  */
  173: inline u_char pelco_GetVersion(void * __restrict p);
  174: 
  175: /*
  176:  * pelco_GetCamNo() Get Camera number and check for valid packet
  177:  * @p = Packet structure
  178:  * return: 0xFF and pelco_GetErrno() == ENOEXEC - error, 
  179:  	any number is camera address
  180:  */
  181: inline u_char pelco_GetCamNo(void * __restrict p);
  182: 
  183: /*
  184:  * pelco_GetCamCmdData() Get from Camera commands and datas with verify packet
  185:  * @p = Input Packet structure
  186:  * @cam = Output camera number
  187:  * @cmd[2] = Output Commands 1 & 2
  188:  * @data[2] = Output Data for commands 1 & 2
  189:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
  190:  */
  191: inline u_char pelco_GetCamCmdData(void * __restrict p, u_char * __restrict cam, 
  192: 		u_char * __restrict cmd, u_char * __restrict data);
  193: 
  194: /*
  195:  * pelco_D_toCmd() Convert to Pelco D commands
  196:  * @cmd[2] = Input Commands 1 & 2
  197:  * @cmd1 = Output typecasted commands 1
  198:  * @cmd2 = Output typecasted commands 2
  199:  * return: 0xFF - error, !=0 return number arguments
  200:  */
  201: inline u_char pelco_D_toCmd(u_char * __restrict cmd, 
  202: 		struct bitD_Cmd1 * __restrict cmd1, struct bitD_Cmd2 * __restrict cmd2);
  203: 
  204: /*
  205:  * pelco_P_toCmd() Convert to Pelco P commands
  206:  * @cmd[2] = Input Commands 1 & 2
  207:  * @cmd1 = Output typecasted commands 1
  208:  * @cmd2 = Output typecasted commands 2
  209:  * return: 0xFF - error, !=0 return number arguments
  210:  */
  211: inline u_char pelco_P_toCmd(u_char * __restrict cmd, 
  212: 		struct bitP_Cmd1 * __restrict cmd1, struct bitP_Cmd2 * __restrict cmd2);
  213: 
  214: /*
  215:  * pelco_D_fromCmd() Convert from Pelco D commands
  216:  * @cmd1 = Input typecasted commands 1
  217:  * @cmd2 = Input typecasted commands 2
  218:  * @cmd[2] = Output Commands 1 & 2
  219:  * return: 0xFF - error, 0 - ok
  220:  */
  221: inline u_char pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2, 
  222: 		u_char * __restrict cmd);
  223: 
  224: /*
  225:  * pelco_P_fromCmd() Convert from Pelco P commands
  226:  * @cmd1 = Input typecasted commands 1
  227:  * @cmd2 = Input typecasted commands 2
  228:  * @cmd[2] = Output Commands 1 & 2
  229:  * return: 0xFF - error, 0 - ok
  230:  */
  231: inline u_char pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2, 
  232: 		u_char * __restrict cmd);
  233: 
  234: /*
  235:  * pelco_SetCamCmdData() Set Camera commands and datas
  236:  * @ver = Input Pelco (d | p) version
  237:  * @cam = Input camera number
  238:  * @cmd[2] = Input Commands 1 & 2
  239:  * @data[2] = Input Data for commands 1 & 2
  240:  * @p = Output Packet structure
  241:  * return: 0xFF - error, 0 - ok
  242:  */
  243: inline u_char pelco_SetCamCmdData(u_char ver, u_char cam, 
  244: 		u_char * __restrict cmd, u_char * __restrict data, void * __restrict p);
  245: 
  246: 
  247: #endif

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