Specifications
Sample Driver Code 67
if (!getanypacketserial(packet))
return(FALSE);
if (p == *packet)
return(TRUE);
}
}
boolean getanypacketserial(packettype packet)
{
byte sum=0,c;
int bidx=0, count=500;
comport_enable();
for (;;) {
if (!comport_receive(&c)) {
comport_disable(); /* com port timed out */
return(FALSE);
}
switch (bidx) {
case 0 : /* expecting new packet */
if (c == 'U') { /* do we have one? */
sum = 0xAA + 'U'; /* yes initialize checksum */
bidx++;
}
else {
if ( count)
continue; /* discard character */
return(FALSE); /* error 500 chars without a packet */
}
break;
case 9 : /* expecting end of packet */
if (sum == c) { /* does checksum match? */
comport_disable(); /* yes done */
return(TRUE);
}
bidx = 0; /* no start over */
break;
default : /* middle of packet */
sum += (packet[bidx++ 1] = c); /* store packet data */
}
}
}
boolean sendpacket(packettype packet)
{
int i;
char c;
byte sum=0;
currenttime = getclocktime();
do
if (timeout(2))
return(FALSE);
while (!comport_xmit_ok());
for (i= 1; i<9; i++) {
switch (i) {
case 1 : /* beginning of packet */
c = 'U';
sum = 0xAA + 'U'; /* initialize checksum */
break;
case 8 : /* end of packet */
c = sum;
break;
default: /* middle of packet */
sum += (c = packet[i]);
}
if (!comport_send(c)) {
comport_disable();
return(FALSE);
}
}
comport_disable();
return(TRUE);
}