Appendix A: C Source for Command String Generator
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
void main( )
{
char inString[255],outString[261], buffer[3] ;
unsigned char checkSum;
int i;
printf(“Enter a command string: \n”);
gets(inString);
//blank input quits program
while (strlen(inString) )
{
checkSum = 0;
//get length of input string
sprintf(outString,”%02X”,strlen(inString)+ 6);
//insert length at beginning of dstring
strcat(outString, inString);
//put ‘00’ spacers at end of string
strcat(outString, “00”);
i = 0;
//sum ascii values of characters in expanded string
while (outString[i])
{
checkSum += outString[i++];
}
//twos complement
checkSum = ~(checksum) + 1;
sprintf(buffer,”%02X”,checkSum);
//append to string
strcat(outString,buffer);
printf(“%s\n”, outString);
printf(“Enter a command string: \n”);
gets(inString);
} ;
exit(0);
}
As an example of using this code, to get the checksum for the Arm to Away command, user
01, user code 1234, you would enter the string “aa011234” followed by the ENTER key.
The program should return “0Eaa011234003E.” To quit the program, just press ENTER
at the prompt.
13
Komentarze do niniejszej Instrukcji