#include "modbus.h"

int Mb_calcul_crc(byte trame[],int n)
{
	unsigned int crc,i,j,carry_flag,a;
	crc=0xffff;
	for (i=0;i<n;i++)
	{
		crc=crc^trame[i];
		for (j=0;j<8;j++)
		{
			a=crc;
			carry_flag=a&0x0001;
			crc=crc>>1;
			if (carry_flag==1)
				crc=crc^0xa001;
		}
	}
	trame[n+1]=crc>>8;
	trame[n]=crc&255;
	return crc;
}

main(argc, argv)
int argc;
char *argv[];
{ 
byte trame[100];
 int i,n,crc;
 trame[0]=2;
 trame[1]=7;
 for (i=1;i<argc;i++) trame[i-1]=atoi(argv[i]);

crc= Mb_calcul_crc(trame, argc-1);
printf("%d %d \n",crc%256,crc/256);
}














