www.pudn.com > SerialGPS.zip > ReadRoutes.m


function routes = ReadRoutes(gps) 
% READROUTES Read all the route data from the GPS 
 
global pid_command_data cmd_transfer_rte pid_xfer_cmplt 
 
routes = []; 
 
% Tell the GPS to send the route data to us 
WritePacket(gps, pid_command_data, cmd_transfer_rte); 
 
% Read standard beginning packet -- count is the number of waypoints in the 
% route 
[id, sz] = ReadPacket(gps); 
 
% Until the transfer is complete 
routeCount = 0; 
while (1) 
 
   [id, sz] = ReadPacketHeader(gps); 
   csum = -1; 
    
   if (pid_rte_hdr == id) 
       % Start a new route 
       routeCount = routeCount + 1; 
       waypoints = 0; 
        
       % Read the header data 
        
       % Compute the checksum 
       csum = ComputeChecksum(id,  
        
   elseif (pid_rte_wpt_data == id) 
       % Read waypoint data into the current route 
       waypoints = waypoints+1; 
        
       % Read the waypoint data 
        
       % Compute the checksum 
         csum = ComputeChecksum(id,  
      
   end
 
   cksum = ReadPacketTerminator(gps); 
   if (csum ~= cksum) 
       error(['Checksum mismatch in ReadRoutes. Expected: ' num2str(csum) ', Received: ' num2str(cksum)]); 
   end 
    
end 
 
% Read the standard ending packet 
[id, cmd] = ReadPacket(gps); 
if (pid_command_data ~= cmd) 
    error 
end