#This is an awk program to get checksums for the Magellan GPS #strings. Execute "awk -f getchecksum.awk" and enter your #favorite Magellan command to get its #"byte-wise exclusive OR of allbytes in the message" checksum. # #B.D.D. 15 January 2002 # ord.awk -- do ord and chr # Global identifiers: # _ord_: numerical values indexed by characters # _ord_init: function to initialize _ord_ BEGIN { _ord_init() } function _ord_init( low, high, i, t) { low = sprintf("%c", 7) # BEL is ascii 7 if (low == "\a") { # regular ascii low = 0 high = 127 } else if (sprintf("%c", 128 + 7) == "\a") { # ascii, mark parity low = 128 high = 255 } else { # ebcdic(!) low = 0 high = 255 } for (i = low; i <= high; i++) { t = sprintf("%c", i) _ord_[t] = i } } function ord(str, c) { # only first character is of interest c = substr(str, 1, 1) return _ord_[c] } function chr(c) { # force c to be numeric by adding 0 return sprintf("%c", c + 0) } #### test code #### BEGIN \ { for (;;) { printf("enter a string: ") if (getline var <= 0) break L=length(var) C = 0 i = 1 while ( i <= L ) { B = substr(var, i, 1) B=ord(B) C = xor(C,B) i = i + 1 } printf("%x \n",C) } }