www.pudn.com > SerialGPS.zip > WritePacket.m
function WritePacket(gps, id, data, type)
% WritePacket Write the a packet with the given id and data
% Since pid_dle_byte is used to delimit packet boundaries, if a data, size
% or checksum value is equal to pid_dle_byte, a second pid_dle_byte is
% immediately sent. This has the effect of "escaping" the first
% pid_dle_byte.
global pid_dle_byte
if (nargin == 3)
type = 'uchar';
end
WritePacketHeader(gps, id, length(data)*sizeof(type));
% Send the data as a stream of bytes
for i=1:length(data)
fwrite(gps, data(i), type);
if (data(i) == pid_dle_byte)
fwrite(gps, pid_dle_byte);
end
end
WritePacketTerminator(gps, id, data, type);