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

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.4     ! misho       6: * $Id: aitpelco.h,v 1.3.4.2 2013/05/26 20:39:13 misho Exp $
1.1       misho       7: *
1.2       misho       8: **************************************************************************
                      9: The ELWIX and AITNET software is distributed under the following
                     10: terms:
                     11: 
                     12: All of the documentation and software included in the ELWIX and AITNET
                     13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
                     14: 
1.4     ! misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
1.2       misho      16:        by Michael Pounov <misho@elwix.org>.  All rights reserved.
                     17: 
                     18: Redistribution and use in source and binary forms, with or without
                     19: modification, are permitted provided that the following conditions
                     20: are met:
                     21: 1. Redistributions of source code must retain the above copyright
                     22:    notice, this list of conditions and the following disclaimer.
                     23: 2. Redistributions in binary form must reproduce the above copyright
                     24:    notice, this list of conditions and the following disclaimer in the
                     25:    documentation and/or other materials provided with the distribution.
                     26: 3. All advertising materials mentioning features or use of this software
                     27:    must display the following acknowledgement:
                     28: This product includes software developed by Michael Pounov <misho@elwix.org>
                     29: ELWIX - Embedded LightWeight unIX and its contributors.
                     30: 4. Neither the name of AITNET nor the names of its contributors
                     31:    may be used to endorse or promote products derived from this software
                     32:    without specific prior written permission.
                     33: 
                     34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
                     35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: SUCH DAMAGE.
                     45: */
1.1       misho      46: #ifndef __AITPELCO_H
                     47: #define __AITPELCO_H
                     48: 
                     49: 
                     50: #include <sys/types.h>
                     51: 
                     52: 
                     53: #define PELCO_D_LEN    7
                     54: #define PELCO_P_LEN    8
                     55: 
                     56: #define FIXED_ZERO     0
                     57: 
                     58: #define VER_D_SYNC     0xFF
                     59: #define VER_P_STX      0xA0
                     60: #define VER_P_ETX      0xAF
                     61: 
                     62: #define FIRST_CAM_D    1
                     63: #define FIRST_CAM_P    0
                     64: 
                     65: #define SPEED_MIN      0x00
                     66: #define SPEED_HI       0x3F
                     67: #define SPEED_MAX      0x40
                     68: 
                     69: #define PAN_STOP       SPEED_MIN
                     70: #define PAN_FAST       SPEED_HI
                     71: #define PAN_TURBO      SPEED_MAX
                     72: #define TILT_STOP      SPEED_MIN
                     73: #define TILT_FAST      SPEED_HI
                     74: 
                     75: 
                     76: /* Pelco-D protocol */
                     77: 
                     78: // Helper Command bitField structures
                     79: 
                     80: struct bitD_Cmd1 {
                     81:        u_char focus_near:1;
                     82:        u_char iris_open:1;
                     83:        u_char iris_close:1;
                     84:        u_char cam_on:1;
                     85:        u_char auto_scan:1;
                     86:        u_char reserved:2;
                     87:        u_char sense:1;
                     88: };
                     89: 
                     90: struct bitD_Cmd2 {
                     91:        u_char fixed:1;
                     92:        u_char pan_right:1;
                     93:        u_char pan_left:1;
                     94:        u_char tilt_up:1;
                     95:        u_char tilt_down:1;
                     96:        u_char zoom_tele:1;
                     97:        u_char zoom_wide:1;
                     98:        u_char focus_far:1;
                     99: };
                    100: 
                    101: typedef struct tagPelcoD {
                    102:        u_char d_sync;
                    103:        u_char d_cam;
                    104:        struct bitD_Cmd1 d_cmd1;
                    105:        struct bitD_Cmd2 d_cmd2;
                    106:        u_char d_data[2];
                    107:        u_char d_crc;
                    108: } pelco_d_t;   // 7 bytes packet
                    109: 
                    110: 
                    111: /* Pelco-P protocol */
                    112: 
                    113: // Helper Data bitField structures
                    114: 
                    115: struct bitP_Cmd1 {
                    116:        u_char focus_far:1;
                    117:        u_char focus_near:1;
                    118:        u_char iris_open:1;
                    119:        u_char iris_close:1;
                    120:        u_char cam_on:1;
                    121:        u_char auto_scan:1;
                    122:        u_char camera:1;
                    123:        u_char fixed:1;
                    124: };
                    125: 
                    126: struct bitP_Cmd2 {
                    127:        u_char for_pan_tilt:1;
                    128:        u_char pan_right:1;
                    129:        u_char pan_left:1;
                    130:        u_char tilt_up:1;
                    131:        u_char tilt_down:1;
                    132:        u_char zoom_tele:1;
                    133:        u_char zoom_wide:1;
                    134:        u_char fixed:1;
                    135: };
                    136: 
                    137: typedef struct tagPelcoP {
                    138:        u_char p_stx;
                    139:        u_char p_cam;
                    140:        struct bitP_Cmd1 p_cmd1;
                    141:        struct bitP_Cmd2 p_cmd2;
                    142:        u_char p_data[2];
                    143:        u_char p_etx;
                    144:        u_char p_crc;
                    145: } pelco_p_t;   // 8 bytes packet
                    146: 
                    147: 
                    148: // -------------------------------------------------------
                    149: // pelco_GetErrno() Get error code of last operation
1.4     ! misho     150: int pelco_GetErrno();
1.1       misho     151: // pelco_GetError() Get error text of last operation
1.4     ! misho     152: const char *pelco_GetError();
1.1       misho     153: // -------------------------------------------------------
                    154: 
                    155: 
                    156: /*
                    157:  * pelcoOpen() Open packet record for camera number with Pelco version D/P
                    158:  * @pelcoVer = Pelco protocol version Dd | Pp
                    159:  * @camNo = Packet for camera number address
                    160:  * return: NULL error, !=NULL ok, allocated memory for packet
                    161:  */
1.4     ! misho     162: void *pelcoOpen(u_char pelcoVer, u_char camNo);
1.1       misho     163: 
                    164: /*
                    165:  * pelcoClose() Close packet record and free memory
                    166:  * @p = Packet structure for close
                    167:  */
1.4     ! misho     168: void pelcoClose(void * __restrict p);
1.1       misho     169: 
                    170: /*
1.2       misho     171:  * pelcoLoad() Load packet from input buffer
                    172:  * @buffer = Pelco packet from input buffer
                    173:  * return: NULL error, !=NULL ok, allocated memory for packet
                    174:  */
1.4     ! misho     175: void *pelcoLoad(u_char *buffer);
1.2       misho     176: 
                    177: 
                    178: /*
1.1       misho     179:  * pelcoAddCmdData() Add commands and datas for already opened packet
                    180:  * @p = Input Packet structure
                    181:  * @cmd[2] = Input Commands 1 & 2
                    182:  * @data[2] = Input Data for commands 1 & 2
                    183:  * return: 0xFF - error, 0 - ok
                    184:  */
1.4     ! misho     185: u_char pelcoAddCmdData(void * __restrict p, u_char * __restrict cmd, u_char * __restrict data);
1.1       misho     186: 
1.2       misho     187: /*
                    188:  * pelcoGetCmdData() Get from packet commands and datas with verify packet
                    189:  * @p = Input Packet structure
                    190:  * @cmd[2] = Output Commands 1 & 2
                    191:  * @data[2] = Output Data for commands 1 & 2
                    192:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    193:  */
1.4     ! misho     194: u_char pelcoGetCmdData(void * __restrict p, u_char * __restrict cmd, u_char * __restrict data);
1.2       misho     195: 
                    196: /*
                    197:  * pelcoChkSum() Check ot Correct check sum in packet
                    198:  * @p = Input Packet structure
                    199:  * @correct = Calculate new check sum if incorrect !=0, if ==0 only check
                    200:  * return: 0xFF - bad packet, invalid check sum, 0 check sum is correct.
                    201:  */
1.4     ! misho     202: u_char pelcoChkSum(void * __restrict p, u_char correct);
1.2       misho     203: 
1.1       misho     204: 
                    205: /*
                    206:  * pelco_GetVersion() Return Pelco protocol version
                    207:  * @p = Packet structure
                    208:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    209:  */
1.4     ! misho     210: u_char pelco_GetVersion(void * __restrict p);
1.1       misho     211: 
                    212: /*
                    213:  * pelco_GetCamNo() Get Camera number and check for valid packet
                    214:  * @p = Packet structure
                    215:  * return: 0xFF and pelco_GetErrno() == ENOEXEC - error, 
                    216:        any number is camera address
                    217:  */
1.4     ! misho     218: u_char pelco_GetCamNo(void * __restrict p);
1.1       misho     219: 
                    220: /*
                    221:  * pelco_GetCamCmdData() Get from Camera commands and datas with verify packet
                    222:  * @p = Input Packet structure
                    223:  * @cam = Output camera number
                    224:  * @cmd[2] = Output Commands 1 & 2
                    225:  * @data[2] = Output Data for commands 1 & 2
                    226:  * return: 'd' - PelcoD, 'p' - PelcoP, 0 - unknown or bad packet
                    227:  */
1.4     ! misho     228: u_char pelco_GetCamCmdData(void * __restrict p, u_char * __restrict cam, 
1.1       misho     229:                u_char * __restrict cmd, u_char * __restrict data);
                    230: 
                    231: /*
                    232:  * pelco_D_toCmd() Convert to Pelco D commands
                    233:  * @cmd[2] = Input Commands 1 & 2
                    234:  * @cmd1 = Output typecasted commands 1
                    235:  * @cmd2 = Output typecasted commands 2
                    236:  * return: 0xFF - error, !=0 return number arguments
                    237:  */
1.4     ! misho     238: u_char pelco_D_toCmd(u_char * __restrict cmd, 
1.1       misho     239:                struct bitD_Cmd1 * __restrict cmd1, struct bitD_Cmd2 * __restrict cmd2);
                    240: 
                    241: /*
                    242:  * pelco_P_toCmd() Convert to Pelco P commands
                    243:  * @cmd[2] = Input Commands 1 & 2
                    244:  * @cmd1 = Output typecasted commands 1
                    245:  * @cmd2 = Output typecasted commands 2
                    246:  * return: 0xFF - error, !=0 return number arguments
                    247:  */
1.4     ! misho     248: u_char pelco_P_toCmd(u_char * __restrict cmd, 
1.1       misho     249:                struct bitP_Cmd1 * __restrict cmd1, struct bitP_Cmd2 * __restrict cmd2);
                    250: 
                    251: /*
                    252:  * pelco_D_fromCmd() Convert from Pelco D commands
                    253:  * @cmd1 = Input typecasted commands 1
                    254:  * @cmd2 = Input typecasted commands 2
                    255:  * @cmd[2] = Output Commands 1 & 2
                    256:  * return: 0xFF - error, 0 - ok
                    257:  */
1.4     ! misho     258: u_char pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2, 
1.1       misho     259:                u_char * __restrict cmd);
                    260: 
                    261: /*
                    262:  * pelco_P_fromCmd() Convert from Pelco P commands
                    263:  * @cmd1 = Input typecasted commands 1
                    264:  * @cmd2 = Input typecasted commands 2
                    265:  * @cmd[2] = Output Commands 1 & 2
                    266:  * return: 0xFF - error, 0 - ok
                    267:  */
1.4     ! misho     268: u_char pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2, 
1.1       misho     269:                u_char * __restrict cmd);
                    270: 
                    271: /*
                    272:  * pelco_SetCamCmdData() Set Camera commands and datas
                    273:  * @ver = Input Pelco (d | p) version
                    274:  * @cam = Input camera number
                    275:  * @cmd[2] = Input Commands 1 & 2
                    276:  * @data[2] = Input Data for commands 1 & 2
                    277:  * @p = Output Packet structure
                    278:  * return: 0xFF - error, 0 - ok
                    279:  */
1.4     ! misho     280: u_char pelco_SetCamCmdData(u_char ver, u_char cam, 
1.1       misho     281:                u_char * __restrict cmd, u_char * __restrict data, void * __restrict p);
                    282: 
                    283: 
                    284: #endif

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