writepacket.m

来自「Serial Application of GPS」· M 代码 · 共 27 行

M
27
字号
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);

   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?