/*************************************************************************
* (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
* by Michael Pounov <misho@openbsd-bg.org>
*
* $Author: misho $
* $Id: pelco.c,v 1.1.2.1 2010/01/20 00:06:36 misho Exp $
*
*************************************************************************/
#include "global.h"
/*
* crcPelco() Calculate Pelco D/P CRC
* @ver = Pelco protocol version (Dd | Pp)
* @pkt = Packet for calculate crc
* return: crc for packet, if is 0 check and crc_GetErrno() == 1
Pelco protocol not supported
*/
inline u_char crcPelco(u_char ver, u_char *pkt)
{
register u_char i, crc;
switch (ver) {
case 'D':
case 'd':
for (i = 1, crc = 0; i < 6; crc += pkt[i++]);
crc %= 0x100;
break;
case 'P':
case 'p':
for (i = 1, crc = pkt[0]; i < 7; crc ^= pkt[i++]);
break;
default:
crc = 0;
crcSetErr(1, "crcAdler(): Invalid parameters!");
}
return crc;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>