File:  [ELWIX - Embedded LightWeight unIX -] / libaitcrc / src / pelco.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Wed Jan 20 00:15:06 2010 UTC (14 years, 5 months ago) by misho
Branches: MAIN
CVS tags: crc2_0, crc1_2, HEAD, CRC1_2, CRC1_1
fix

    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: pelco.c,v 1.2 2010/01/20 00:15:06 misho Exp $
    7: *
    8: *************************************************************************/
    9: #include "global.h"
   10: 
   11: 
   12: /*
   13:  * crcPelco() Calculate Pelco D/P CRC
   14:  * @ver = Pelco protocol version (Dd | Pp)
   15:  * @pkt = Packet for calculate crc
   16:  * return: crc for packet, if is 0 check and crc_GetErrno() == 1 
   17:  	Pelco protocol not supported
   18:  */
   19: inline u_char crcPelco(u_char ver, u_char *pkt)
   20: {
   21: 	register u_char i, crc;
   22: 
   23: 	switch (ver) {
   24: 		case 'D':
   25: 		case 'd':
   26: 			for (i = 1, crc = 0; i < 6; crc += pkt[i++]);
   27: 			crc %= 0x100;
   28: 			break;
   29: 		case 'P':
   30: 		case 'p':
   31: 			for (i = 1, crc = pkt[0]; i < 7; crc ^= pkt[i++]);
   32: 			break;
   33: 		default:
   34: 			crc = 0;
   35: 			crcSetErr(1, "crcAdler(): Invalid parameters!");
   36: 	}
   37: 
   38: 	return crc;
   39: }

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