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

📄 parsermc.m

📁 此功能包用于各种GPS坐标和时间的转换
💻 M
字号:
function rmc_out = parsermc(line)% rmc_out = parsermc_new(line);%% Function to parse RMC NMEA messages.% % Input:%   line    - string with one NMEA RMC data message% Output:%   rmc_out - output data message for RMC data type (nx8)%                        1  2  3   4   5   6    7       8  %           columns are [hh mm ss lat lon SOG course mag_var]%             hh, mm, ss are UTC HMS%             lat and lon are in deg%             SOG in knts%             COG in deg - true% % Written by: Jimmy LaMance 7/26/00 % Copyright (c) 2000 by Constell, Inc.% functions called: none%%%%% BEGIN VARIABLE CHECKING CODE %%%%%% declare the global debug modeglobal DEBUG_MODE% Initialize the output variablesgsa_out=[];% Check the number of input arguments and issues a message if invalidmsg = nargchk(1,1,nargin);if ~isempty(msg)  fprintf('%s  See help on PARSERMC for details.\n',msg);  fprintf('Returning with empty outputs.\n\n');  returnend% verify that line is a stringif ~isstr(line)  fprintf('NMEA line input to PARSERMC must be a string. \n');  fprintf('See help PARSERMC for details.')   if DEBUG_MODE    fprintf('Error from PARSERMC:  ')    fprintf('Wrong type of line variable to PARSERMC.\n');    % return to the calling function without filling in the output variables    return  else    error('Wrong type of line variable to PARSERMC.');  end % if DEBUG_MODEend % if ~isstr(line)%%%% END VARIABLE CHECKING CODE %%%%%%%%%% BEGIN ALGORITHM CODE %%%%%ll = size(line,2);     % length of linermc_out = [];                 % default size of message outputrmc_size = 8;if strcmp(line(1:6),'$GPRMC') == 1    % found an Ashtech RMC message     % Find all of the commas in the line  I_comma = findstr(line,',');    % A valid RMC message has 11 commas  if length(I_comma) ~= 11    return  end    % parse out the time  time_field = str2num(line(I_comma(1)+1:I_comma(2)-1));  if (length(time_field) ~= 1)     rmc_out = [];     return  end    rmc_out(1) = fix(time_field / 10000);    % hours  rmc_out(2) = fix(time_field / 100) - rmc_out(1) * 100;    % minutes  rmc_out(3) = time_field - rmc_out(1) * 10000 - rmc_out(2) * 100;   % seconds  lat = str2num(line(I_comma(3)+1:I_comma(4)-1));  North = line(I_comma(4)+1:I_comma(5)-1);  deg = fix(lat / 100);  min = lat - deg * 100;  if (length(deg) ~= 1) | (length(min) ~= 1)     fprintf('Failure getting latitude\n');     rmc = [];     return;  end    if strcmp(North,'N')    rmc_out(4) = deg + min / 60;      % latitude in degrees  elseif strcmp(North,'S')    rmc_out(4) = -1 * (deg + min / 60);      % (south) latitude in degrees  else    rmc_out(4) = inf;  end % if    lon = str2num(line(I_comma(5)+1:I_comma(6)-1));   East = line(I_comma(6)+1:I_comma(7)-1);    deg = fix(lon / 100);  min = lon - deg * 100;  if (length(deg) ~= 1) | (length(min) ~= 1)     pos_out = [];     return;  end    if strcmp(East,'E')    rmc_out(5) = deg + min / 60;      % longitude in degrees   elseif strcmp(East,'W')    rmc_out(5) = -1 * (deg + min / 60);      % (west) longitude in degrees   else    rmc_out(5) = inf;  end % if  % Speed over ground    sog = str2num(line(I_comma(7)+1:I_comma(8)-1));    % SOG   if ~isempty(sog)    rmc_out(6) = sog;  else    rmc_out(6) = inf;  end    % Course over ground (COG)  cog = str2num(line(I_comma(8)+1:I_comma(9)-1));    % number of satellite   if ~isempty(cog)    rmc_out(7) = cog;  else    rmc_out(7) = inf;  end    % UTC date field - toss for now  utc_date = str2num(line(I_comma(9)+1:I_comma(10)-1));      %if ~isempty(hdop)  %  rmc_out(9) = hdop;  %else  %  rmc_out(9) = inf;  %end    % magnetic variation  I_star = findstr(line,'*');   mag_var = str2num(line(I_comma(10)+1:I_comma(11)-1));   East = line(I_comma(11)+1:I_star-1);      if strcmp(East,'E')    rmc_out(8) = mag_var;      % longitude in degrees   elseif strcmp(East,'W')    rmc_out(8) = -mag_var;      % (west) longitude in degrees   else    rmc_out(8) = inf;  end % if  if length(I_star) ~= 1   % too many star characters    rmc = [];    return  end    % checksum  check_sum = line(I_star+1:length(line));    % get all of the characters between the header and the star before the check sum  start_ind = 2;                    % exclude the $ sign  stop_ind = length(line) - 3;      % remove the * and 2 digit hex check sum    chk_line = line(start_ind:stop_ind);    % Compute the check sum  s_chk = double(chk_line(1));  for i = 2:length(chk_line)    s_chk = bitxor(double(chk_line(i)),s_chk);  end          valid = 0;    % set this as an invalid message until the checksum has passed  s_chk = dec2hex(s_chk);    % convert to hex    if ~isstr(check_sum)    check_sum = num2str(check_sum);  end % if ~isstr(check_sum)  if strcmp(check_sum,s_chk)    valid = 1;  else    valid = 0;  end % if strcmp(check_sum,s_chk)      % make sure that at least valid time, lat and lon data were obtained,   % otherwise return a blank message  if any(find(rmc_out(1:8) == inf)) | valid == 0%    fprintf('Error parsing RMC message\n  %s\n',line);%    keyboard    rmc_out = [];  end % if any(find(rmc_out(1:9) == inf))  else  fprintf('Warning from PARSERMC. RMC message not found in the current line.\n')  fprintf('  %s\n\n',line);end % if strcmp(line(1:6),'$GPRMC') == 1   %%%%% END ALGORITHM CODE %%%%%% end of PARSERMC    

⌨️ 快捷键说明

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