#This is an awk script that will order a Magellan 315 to download its #track data. It can easily be modified to make the Magellan jump through #hoops. # # You probably need to get your serial port set up for 4800 8N1 - try the # following from a bash shell (change to /dev/ttyS1 if needed): # stty -F /dev/ttyS0 0:4:ebc:a30:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 # # You can also edit the DEVICE name below to aim at /dev/ttyS1 # # Execute this by: "awk -f gettracks.awk" # Data is written to the screen ("/dev/tty") and to the file "gpsdata.out" # # B.D.D. 15 Jan. 2002 ############################################################################## # GET SETUP TO GET CHECKSUM - INITIATE THE MATRIX ord # 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) } function getchecksum(var) { L=length(var) C = 0 i = 1 while ( i <= L ) { B = substr(var, i, 1) B1= ord(B) C = xor(C,B1) i = i + 1 } checkout = sprintf("%X",C) return checkout } function getcheck(aline) { N=length(aline) N=N-2 checksum=substr(aline,N,2) return checksum } # END OF SETUP ############################################################################## # MAIN ROUTINE BEGIN { # # SET THE DEVICE TO BE /dev/ttyS0 # DEVICE="/dev/ttyS0" print "$PMGNCMD,VERSION*28\r\n" > DEVICE getline aline < DEVICE #test in case the thing is stuck in handon mode A=substr(aline,6,3) if (A=="CSM") { #get another line, which will have the version in it getline aline < DEVICE #and acknowledge that you got it (7B*10 is for Magellan 315) getcheck(aline) #defines the value of the checksum sendback=("PMGNCSM," checksum) getchecksum(sendback) #gets the value of the new, outgoing checksum in "checkout" print ("$" sendback "*" checkout) > DEVICE print "starting out in HANDON mode" > "/dev/tty" } print aline > "/dev/tty" print "$PMGNCMD,HANDON*70\r\n" > DEVICE if (A=="CSM") { #get another line, which will have the acknowledgement in it getline aline < DEVICE } #print "$PMGNCMD,TON*27\r\n" #getline aline < DEVICE #we need a small pause here for the unit to go to hand on mode system("sleep 2") #o.k. ready to send another command #SEND THE GETTRACK COMMAND print "$PMGNCMD,TRACK*3D\r\n" > DEVICE #now read the CSM line which is not used (and assumed to be o.k.). getline aline < DEVICE STOP = 0 while ( STOP == 0 ) { getline aline < DEVICE A=substr(aline,6,3) B=substr(aline,10,3) if ( B == "END" ) { STOP = 1 print "$PMGNCSM,3D*12\r\n" > DEVICE } else if (A == "CSM") {print "Got a CSM" > "/dev/tty"} # do nothing for now, but read another line of data else if (A == "TRK") { latd= substr(aline,10,2) latm= substr(aline,12,6) latlab=substr(aline,19,1) lond= substr(aline,21,3) lonm= substr(aline,24,6) lonlab=substr(aline,31,1) elev= substr(aline,33,5) elevl= substr(aline,39,1) hh= substr(aline,41,2) mm= substr(aline,43,2) ss= substr(aline,45,5) valid= substr(aline,51,1) # valid should be A for o.k. - it is V for not valid print latd " " latm " "latlab " " lond " " lonm " " lonlab " " elev " " elevl " " hh ":" mm ":" ss " " valid > "/dev/tty" if (valid=="A") print latd " " latm " " lond " " lonm " " elev " " hh " " mm " " ss > "gpsdata.out" # print aline > "/dev/tty" getcheck(aline) #gets the value of the "checksum" from the line L=length(aline) N=L-5 aline=substr(aline,2,N) getchecksum(aline) #calculates the value of the checksum of the line (in "checkout") # checkout and checksum are defined - check that they are the same # if they are not the same, then do nothing and read another line # because the unit will resend the line without the reply. if (checkout == checksum) { sendstr=( "PMGNCSM," checksum ) #MAGELLAN DOES NOT USE THE $ OR * IN THE CHECKSUM, CONTRARY TO WHAT THE BOOK SEZ getchecksum(sendstr) print ("$" sendstr "*" checkout "\r\n") > DEVICE } } # END of ELSE } # end of while STOP ==0 #NOW PUT THE MAGELLAN BACK TO THE STATE YOU FOUND IT print "$PMGNCMD,HANDOFF*3E\r\n" > DEVICE } # end of BEGIN procedure