Annotation of libaitpelco/src/set.c, revision 1.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.2 ! misho 6: * $Id: set.c,v 1.1.1.1.2.3 2011/05/10 20:25:41 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:
! 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
! 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: #include "global.h"
47:
48:
49: /*
50: * pelco_D_fromCmd() Convert from Pelco D commands
51: * @cmd1 = Input typecasted commands 1
52: * @cmd2 = Input typecasted commands 2
53: * @cmd[2] = Output Commands 1 & 2
54: * return: 0xFF - error, 0 - ok
55: */
1.2 ! misho 56: inline u_char
! 57: pelco_D_fromCmd(struct bitD_Cmd1 cmd1, struct bitD_Cmd2 cmd2, u_char * __restrict cmd)
1.1 misho 58: {
59: u_char ret = 0;
60:
61: if (!cmd) {
1.2 ! misho 62: pelcoSetErr(EINVAL, "invalid argument!\n");
1.1 misho 63: return 0xFF;
64: }
65:
66: memcpy(&cmd[0], &cmd1, 1);
67: memcpy(&cmd[1], &cmd2, 1);
68:
69: return ret;
70: }
71:
72: /*
73: * pelco_P_fromCmd() Convert from Pelco P commands
74: * @cmd1 = Input typecasted commands 1
75: * @cmd2 = Input typecasted commands 2
76: * @cmd[2] = Output Commands 1 & 2
77: * return: 0xFF - error, 0 - ok
78: */
1.2 ! misho 79: inline u_char
! 80: pelco_P_fromCmd(struct bitP_Cmd1 cmd1, struct bitP_Cmd2 cmd2, u_char * __restrict cmd)
1.1 misho 81: {
82: u_char ret = 0;
83:
84: if (!cmd) {
1.2 ! misho 85: pelcoSetErr(EINVAL, "invalid argument!\n");
1.1 misho 86: return 0xFF;
87: }
88:
89: memcpy(&cmd[0], &cmd1, 1);
90: memcpy(&cmd[1], &cmd2, 1);
91:
92: return ret;
93: }
94:
95: /*
96: * pelco_SetCamCmdData() Set Camera commands and datas
97: * @ver = Input Pelco (d | p) version
98: * @cam = Input camera number
99: * @cmd[2] = Input Commands 1 & 2
100: * @data[2] = Input Data for commands 1 & 2
101: * @p = Output Packet structure
102: * return: 0xFF - error, 0 - ok
103: */
1.2 ! misho 104: inline u_char
! 105: pelco_SetCamCmdData(u_char ver, u_char cam, u_char * __restrict cmd,
! 106: u_char * __restrict data, void * __restrict p)
1.1 misho 107: {
108: u_char ret = 0;
109: pelco_d_t *pd = (pelco_d_t*) p;
110: pelco_p_t *pp = (pelco_p_t*) p;
111:
112: if (!p) {
1.2 ! misho 113: pelcoSetErr(EINVAL, "invalid argument!\n");
1.1 misho 114: return 0xFF;
115: }
116:
117: switch (ver) {
118: case 'D':
119: case 'd':
120: memset(pd, 0, sizeof(pelco_d_t));
121: pd->d_sync = VER_D_SYNC;
122: pd->d_cam = cam;
123: if (cmd)
124: memcpy(&pd->d_cmd1, cmd, 2);
125: if (data)
126: memcpy(&pd->d_data, data, 2);
127: pd->d_crc = crcPelco(ver, p);
128: break;
129: case 'P':
130: case 'p':
131: memset(pp, 0, sizeof(pelco_p_t));
132: pp->p_stx = VER_P_STX;
133: pp->p_cam = !cam ? cam : cam - 1;
134: if (cmd)
135: memcpy(&pp->p_cmd1, cmd, 2);
136: if (data)
137: memcpy(&pp->p_data, data, 2);
138: pp->p_etx = VER_P_ETX;
139: pp->p_crc = crcPelco(ver, p);
140: break;
141: default:
1.2 ! misho 142: pelcoSetErr(ENOEXEC, "Invalid protocol!\n");
1.1 misho 143: return 0xFF;
144: }
145:
146: return ret;
147: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>