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


function WritePacketTerminator(gps, id, data, type) 
% WRITEPACKETTERMINATOR Send the two byte packet terminator: (DLE, ETX) 
 
global pid_dle_byte pid_etx_byte pid_ack_byte pid_nak_byte 
 
% Checksum: 2s complement of sum of data 
cksum = ComputeChecksum(id, data, type); 
fwrite(gps, cksum); 
if (pid_dle_byte == cksum) 
    fwrite(gps, pid_dle_byte); 
end 
     
% Send the terminating characters 
fwrite(gps, pid_dle_byte); 
fwrite(gps, pid_etx_byte); 
 
% Wait for the acknowledgement packet. Don't wait if this was 
% an ACK or NAK packet 
if ((pid_ack_byte ~= id) && (pid_nak_byte ~= id)) 
    [pid, data] = ReadPacket(gps); 
    if (pid_ack_byte ~= pid) 
        error(['Write packet (id: ', num2str(id), ') failed.']); 
    end 
end