📄 readpacket.m
字号:
function [id, data] = ReadPacket(gps, type)
% READPACKET Read a single packet from the device
global pid_ack_byte pid_nak_byte
if (nargin < 2)
type = 'uint8';
end
% Initialize output data
data = [];
% Read the packet header (id and size)
[id, sz] = ReadPacketHeader(gps);
% Read data, if non-zero size
if (sz > 0)
[data, d] = ReadData(gps, id, sz / sizeof(type), type);
end
% Read checksum and packet terminator
cksum = ReadPacketTerminator(gps);
% Verify checksum
csum = ComputeChecksum(id, d);
if (csum ~= cksum)
WritePacket(gps, pid_nak_byte, id);
error(['Checksum mismatch. Got ', num2str(cksum), ', expecting ', num2str(csum)]);
end
% Send ACK, unless we just read an ACK or NAK
if ((pid_ack_byte ~= id) && (pid_nak_byte ~= id))
WritePacket(gps, pid_ack_byte, id);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -