⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readpacket.m

📁 基于串行接口的GPS驱动程序
💻 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 + -