-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgps_scan.m
More file actions
112 lines (104 loc) · 3.48 KB
/
gps_scan.m
File metadata and controls
112 lines (104 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function [gprmc, gpgga, igps] = gps_scan(str)
% Usage: [gprmc, gpgga, igps] = gps_scan(str)
%
% Scans a GPS string for messages $GPRMC and $GPGGA.
% Examples of such messages:
% $GPRMC,015409,A,4555.9652,N,12333.2382,W,000.0,000.0,190807,017.8,E*66
% $GPGGA,015409,4555.9652,N,12333.2382,W,1,03,3.1,,M,-20.5,M,,*5E
%
% str - GPS character string
% gprmc, gpgga - character arrays containing the information
% stored in the respective GPS messages
% igps - indices in the input GPS string of all
% occurences of all GPS messages
%
% Uses function strsplit, which is stored in Toolbox/system_tools
% We could also check the checksums at the ends of the GPS messages
% but we are ignoring them for now.
%
% Author: Anna Kelbert, 21 Aug 2007
%
% Last edited in 2020 by Brady Fry and Anna Kelbert. The following edits
% to the GNSS NMEA sentence contained in the NGF NIMS binary data file
% format have been implemented. Backward compatibility has been maintained.
%
% NMEA Total Length:
% Because of the limitations inherent in the NIMS system, the NMEA sentences total
% length is limited to 140 bytes. This causes the end of the GPGGA NMEA sentence
% to be truncated.
%
% NMEA Sentence Differences:
% RMC
% -Added '.00' to the data format
% -Latitude and Longitude increased to 5 decimal places
% -Declination is not provided (Currently calculated in SS/SSM)
% -Two new fields at the end
%
% GGA
% -Added '.00' to the data format
% -Latitude and Longitude increased to 5 decimal places
% -Sentence truncated
%
% Old NMEA Sentence Example:
% $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
% $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47
%
% New NMEA Sentence Example:
% $GPRMC,211510.00,A,4435.51438,N,12317.96682,W,0.073,,170420,,,A,V*12
% $GPGGA,211510.00,4435.51438,N,12317.96682,W,1,06,2.09,105.9,M,-22.6,M
%
% Finally, modified to use the native Matlab R2013a strsplit function
% (functionality was broken with default configuration so edits needed)
% and modified Toolbox/system_tools strsplit for compatibility.
gprmc = {};
nGPRMC = 12;
gpgga = {};
nGPGGA = 12;
igps = {};
good = [];
gpsStart = strfind(str,'$GPRMC');
if isempty(gpsStart)
disp('The string contains no GPS messages.');
return;
elseif length(gpsStart) == 1
% The string contains exactly one GPS message
gpsstr{1} = str;
else
gpsstr = {};
for k = 1:length(gpsStart) - 1
gpsstr{k} = str(gpsStart(k):gpsStart(k+1)-1);
end
gpsstr{k+1} = str(gpsStart(k+1):end);
end
i = 1;
for k = 1:length(gpsstr)
if length(gpsstr{k}) < 139
continue
end
temp = gpsstr{k}(1:139);
s = strfind(temp,'$');
if length(s) <= 1
continue % skip the GPS message: it is not complete
end
% GPRMC
values = strsplit(temp(s(1):s(2)), ',', 'CollapseDelimiters', false);
if length(values) >= nGPRMC % i.e. no transient errors
gprmc(i, :) = values(1:nGPRMC);
else
continue
end
% GPGGA (if exists)
values = strsplit(temp(s(2):end), ',', 'CollapseDelimiters', false);
if length(values) >= nGPGGA % i.e. no transient errors
gpgga(i,:) = values(1:nGPGGA);
else
gpgga(i,1:nGPGGA) = {''};
end
% go to next iteration
good = [good; k];
i = i + 1;
end
% compute the indices of all GPS messages in the GPS string
igps = gpsStart(good);
% compute the indices of all fixed (locked) GPS messages in the GPS string
%ifixed = igps(strcmp(gprmc(:,3),'A'));