Merge lp:~thomas-voss/location-service/add-sirf-support into lp:location-service
- add-sirf-support
- Merge into next
Proposed by
Thomas Voß
Status: | Merged |
---|---|
Approved by: | Thomas Voß |
Approved revision: | 305 |
Merged at revision: | 304 |
Proposed branch: | lp:~thomas-voss/location-service/add-sirf-support |
Merge into: | lp:location-service |
Diff against target: |
3976 lines (+2602/-453) 58 files modified
src/location/CMakeLists.txt (+7/-1) src/location/cmds/monitor.cpp (+72/-4) src/location/cmds/monitor.h (+7/-0) src/location/nmea/cardinal_direction.h (+3/-12) src/location/nmea/date.h (+3/-12) src/location/nmea/fusion_adapt.h (+61/-61) src/location/nmea/generator.h (+12/-21) src/location/nmea/gga.h (+15/-22) src/location/nmea/gll.h (+11/-19) src/location/nmea/gps/fix_mode.h (+9/-16) src/location/nmea/grammar.h (+7/-17) src/location/nmea/gsa.h (+10/-19) src/location/nmea/gsv.h (+9/-16) src/location/nmea/latitude.h (+8/-15) src/location/nmea/longitude.h (+8/-15) src/location/nmea/mode.h (+8/-15) src/location/nmea/rmc.h (+16/-23) src/location/nmea/scanner.cpp (+2/-2) src/location/nmea/scanner.h (+8/-15) src/location/nmea/sentence.cpp (+3/-3) src/location/nmea/sentence.h (+14/-22) src/location/nmea/status.h (+8/-15) src/location/nmea/talker.h (+8/-15) src/location/nmea/txt.h (+9/-16) src/location/nmea/utc.h (+8/-15) src/location/nmea/vtg.h (+10/-17) src/location/providers/CMakeLists.txt (+1/-0) src/location/providers/config.cpp (+7/-0) src/location/providers/sirf/CMakeLists.txt (+33/-0) src/location/providers/sirf/bits.h (+49/-0) src/location/providers/sirf/checksum.cpp (+28/-0) src/location/providers/sirf/checksum.h (+42/-0) src/location/providers/sirf/codec.h (+81/-0) src/location/providers/sirf/dop.h (+64/-0) src/location/providers/sirf/geodetic_navigation_data.h (+213/-0) src/location/providers/sirf/initialize_data_source.h (+93/-0) src/location/providers/sirf/magic.h (+43/-0) src/location/providers/sirf/message.h (+53/-0) src/location/providers/sirf/provider.cpp (+353/-0) src/location/providers/sirf/provider.h (+143/-0) src/location/providers/sirf/reader.cpp (+87/-0) src/location/providers/sirf/reader.h (+52/-0) src/location/providers/sirf/receiver.cpp (+80/-0) src/location/providers/sirf/receiver.h (+92/-0) src/location/providers/sirf/scanner.cpp (+161/-0) src/location/providers/sirf/scanner.h (+76/-0) src/location/providers/sirf/serial_port_receiver.cpp (+80/-0) src/location/providers/sirf/serial_port_receiver.h (+79/-0) src/location/providers/sirf/set_protocol.h (+73/-0) src/location/providers/sirf/writer.cpp (+94/-0) src/location/providers/sirf/writer.h (+54/-0) src/location/providers/ubx/CMakeLists.txt (+5/-2) src/location/providers/ubx/_8/receiver.cpp (+1/-1) src/location/providers/ubx/_8/receiver.h (+4/-4) src/location/providers/ubx/_8/scanner.cpp (+1/-1) src/location/providers/ubx/provider.cpp (+28/-28) src/location/providers/ubx/provider.h (+9/-9) src/location/runtime_tests.cpp (+87/-0) |
To merge this branch: | bzr merge lp:~thomas-voss/location-service/add-sirf-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Simon Fels (community) | Approve | ||
Thomas Voß | Pending | ||
Review via email: mp+323629@code.launchpad.net |
Commit message
Add support for SiRF providers.
Description of the change
Add support for SiRF providers.
To post a comment you must log in.
- 305. By Thomas Voß
-
Adjust formatting of output for locationd.monitor.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/location/CMakeLists.txt' | |||
2 | --- src/location/CMakeLists.txt 2017-04-26 19:58:19 +0000 | |||
3 | +++ src/location/CMakeLists.txt 2017-05-05 09:37:41 +0000 | |||
4 | @@ -35,6 +35,12 @@ | |||
5 | 35 | COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen" "${CMAKE_CURRENT_SOURCE_DIR}/connectivity/w11t.xml") | 35 | COMMAND ${GDBUS_CODEGEN_EXECUTABLE} --generate-c-code "${CMAKE_CURRENT_BINARY_DIR}/connectivity/w11t_gen" "${CMAKE_CURRENT_SOURCE_DIR}/connectivity/w11t.xml") |
6 | 36 | 36 | ||
7 | 37 | add_library( | 37 | add_library( |
8 | 38 | nmea | ||
9 | 39 | |||
10 | 40 | nmea/scanner.cpp | ||
11 | 41 | nmea/sentence.cpp) | ||
12 | 42 | |||
13 | 43 | add_library( | ||
14 | 38 | ubuntu-location-service SHARED | 44 | ubuntu-location-service SHARED |
15 | 39 | 45 | ||
16 | 40 | ${UBUNTU_LOCATION_SERVICE_PUBLIC_HEADERS} | 46 | ${UBUNTU_LOCATION_SERVICE_PUBLIC_HEADERS} |
17 | @@ -88,7 +94,7 @@ | |||
18 | 88 | cmds/status.cpp | 94 | cmds/status.cpp |
19 | 89 | cmds/test.h | 95 | cmds/test.h |
20 | 90 | cmds/test.cpp | 96 | cmds/test.cpp |
22 | 91 | 97 | ||
23 | 92 | util/benchmark.h | 98 | util/benchmark.h |
24 | 93 | util/benchmark.cpp | 99 | util/benchmark.cpp |
25 | 94 | util/cli.h | 100 | util/cli.h |
26 | 95 | 101 | ||
27 | === modified file 'src/location/cmds/monitor.cpp' | |||
28 | --- src/location/cmds/monitor.cpp 2017-04-26 19:58:19 +0000 | |||
29 | +++ src/location/cmds/monitor.cpp 2017-05-05 09:37:41 +0000 | |||
30 | @@ -20,6 +20,7 @@ | |||
31 | 20 | #include <location/cmds/monitor.h> | 20 | #include <location/cmds/monitor.h> |
32 | 21 | 21 | ||
33 | 22 | #include <location/criteria.h> | 22 | #include <location/criteria.h> |
34 | 23 | #include <location/logging.h> | ||
35 | 23 | #include <location/dbus/stub/service.h> | 24 | #include <location/dbus/stub/service.h> |
36 | 24 | #include <location/glib/runtime.h> | 25 | #include <location/glib/runtime.h> |
37 | 25 | #include <location/runtime.h> | 26 | #include <location/runtime.h> |
38 | @@ -34,17 +35,84 @@ | |||
39 | 34 | 35 | ||
40 | 35 | void location::cmds::Monitor::PrintingDelegate::on_new_position(const Update<Position>& pos) | 36 | void location::cmds::Monitor::PrintingDelegate::on_new_position(const Update<Position>& pos) |
41 | 36 | { | 37 | { |
43 | 37 | out << pos << std::endl; | 38 | last_position_update = pos; |
44 | 39 | print_row(); | ||
45 | 38 | } | 40 | } |
46 | 39 | 41 | ||
47 | 40 | void location::cmds::Monitor::PrintingDelegate::on_new_heading(const Update<units::Degrees>& heading) | 42 | void location::cmds::Monitor::PrintingDelegate::on_new_heading(const Update<units::Degrees>& heading) |
48 | 41 | { | 43 | { |
50 | 42 | out << heading << std::endl; | 44 | last_heading_update = heading; |
51 | 45 | print_row(); | ||
52 | 43 | } | 46 | } |
53 | 44 | 47 | ||
54 | 45 | void location::cmds::Monitor::PrintingDelegate::on_new_velocity(const Update<units::MetersPerSecond>& velocity) | 48 | void location::cmds::Monitor::PrintingDelegate::on_new_velocity(const Update<units::MetersPerSecond>& velocity) |
55 | 46 | { | 49 | { |
57 | 47 | out << velocity << std::endl; | 50 | last_velocity_update = velocity; |
58 | 51 | print_row(); | ||
59 | 52 | } | ||
60 | 53 | |||
61 | 54 | void location::cmds::Monitor::PrintingDelegate::print_header() | ||
62 | 55 | { | ||
63 | 56 | out << std::left << std::setw(15) << std::setfill(' ') << "lat.[deg]" | ||
64 | 57 | << std::left << std::setw(15) << std::setfill(' ') << "lon.[deg]" | ||
65 | 58 | << std::left << std::setw(15) << std::setfill(' ') << "hor.acc.[m]" | ||
66 | 59 | << std::left << std::setw(15) << std::setfill(' ') << "alt.[m]" | ||
67 | 60 | << std::left << std::setw(15) << std::setfill(' ') << "ver.acc.[m]" | ||
68 | 61 | << std::left << std::setw(15) << std::setfill(' ') << "heading[deg]" | ||
69 | 62 | << std::left << std::setw(15) << std::setfill(' ') << "vel.[m/s]" << std::endl; | ||
70 | 63 | } | ||
71 | 64 | |||
72 | 65 | void location::cmds::Monitor::PrintingDelegate::print_row() | ||
73 | 66 | { | ||
74 | 67 | if (last_position_update) | ||
75 | 68 | { | ||
76 | 69 | out << std::left << std::setw(15) << std::setfill(' ') << std::fixed << std::setprecision(5) << last_position_update->value.latitude().value(); | ||
77 | 70 | out << std::left << std::setw(15) << std::setfill(' ') << std::fixed << std::setprecision(5) << last_position_update->value.longitude().value(); | ||
78 | 71 | |||
79 | 72 | if (last_position_update->value.accuracy().horizontal()) | ||
80 | 73 | out << std::left << std::setw(15) << std::setfill(' ') << std::fixed << std::setprecision(2) << last_position_update->value.accuracy().horizontal()->value() ; | ||
81 | 74 | else | ||
82 | 75 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a" ; | ||
83 | 76 | |||
84 | 77 | if (last_position_update->value.altitude()) | ||
85 | 78 | out << std::left << std::setw(15) << std::setfill(' ') << std::fixed << std::setprecision(2) << last_position_update->value.altitude()->value() ; | ||
86 | 79 | else | ||
87 | 80 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a" ; | ||
88 | 81 | |||
89 | 82 | if (last_position_update->value.accuracy().vertical()) | ||
90 | 83 | out << std::left << std::setw(15) << std::setfill(' ') << std::fixed << std::setprecision(2) << last_position_update->value.accuracy().vertical()->value() ; | ||
91 | 84 | else | ||
92 | 85 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a" ; | ||
93 | 86 | } | ||
94 | 87 | else | ||
95 | 88 | { | ||
96 | 89 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a" // latitude | ||
97 | 90 | << std::left << std::setw(15) << std::setfill(' ') << "n/a" // longitude | ||
98 | 91 | << std::left << std::setw(15) << std::setfill(' ') << "n/a" // horizontal accuracy | ||
99 | 92 | << std::left << std::setw(15) << std::setfill(' ') << "n/a" // altitude | ||
100 | 93 | << std::left << std::setw(15) << std::setfill(' ') << "n/a" ; // vertical accuracy | ||
101 | 94 | } | ||
102 | 95 | |||
103 | 96 | if (last_heading_update) | ||
104 | 97 | { | ||
105 | 98 | out << std::left << std::setw(15) << std::setfill(' ') << last_heading_update->value.value() ; | ||
106 | 99 | } | ||
107 | 100 | else | ||
108 | 101 | { | ||
109 | 102 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a" ; | ||
110 | 103 | } | ||
111 | 104 | |||
112 | 105 | if (last_velocity_update) | ||
113 | 106 | { | ||
114 | 107 | out << std::left << std::setw(15) << std::setfill(' ') << last_velocity_update->value.value(); | ||
115 | 108 | } | ||
116 | 109 | else | ||
117 | 110 | { | ||
118 | 111 | out << std::left << std::setw(15) << std::setfill(' ') << "n/a"; | ||
119 | 112 | } | ||
120 | 113 | |||
121 | 114 | out << std::endl; | ||
122 | 115 | |||
123 | 48 | } | 116 | } |
124 | 49 | 117 | ||
125 | 50 | location::cmds::Monitor::Monitor(const std::shared_ptr<Delegate>& delegate) | 118 | location::cmds::Monitor::Monitor(const std::shared_ptr<Delegate>& delegate) |
126 | @@ -96,7 +164,7 @@ | |||
127 | 96 | session->updates().heading_status = location::Service::Session::Updates::Status::enabled; | 164 | session->updates().heading_status = location::Service::Session::Updates::Status::enabled; |
128 | 97 | session->updates().velocity_status = location::Service::Session::Updates::Status::enabled; | 165 | session->updates().velocity_status = location::Service::Session::Updates::Status::enabled; |
129 | 98 | 166 | ||
131 | 99 | ctxt.cout << "Enabled position/heading/velocity updates..." << std::endl; | 167 | LOG(INFO) << "Enabled position/heading/velocity updates..." << std::endl; |
132 | 100 | }); | 168 | }); |
133 | 101 | }); | 169 | }); |
134 | 102 | 170 | ||
135 | 103 | 171 | ||
136 | === modified file 'src/location/cmds/monitor.h' | |||
137 | --- src/location/cmds/monitor.h 2017-03-07 10:01:34 +0000 | |||
138 | +++ src/location/cmds/monitor.h 2017-05-05 09:37:41 +0000 | |||
139 | @@ -61,8 +61,15 @@ | |||
140 | 61 | void on_new_position(const Update<Position>& pos) override; | 61 | void on_new_position(const Update<Position>& pos) override; |
141 | 62 | void on_new_heading(const Update<units::Degrees>& heading) override; | 62 | void on_new_heading(const Update<units::Degrees>& heading) override; |
142 | 63 | void on_new_velocity(const Update<units::MetersPerSecond>& velocity) override; | 63 | void on_new_velocity(const Update<units::MetersPerSecond>& velocity) override; |
143 | 64 | |||
144 | 64 | private: | 65 | private: |
145 | 66 | void print_header(); | ||
146 | 67 | void print_row(); | ||
147 | 68 | |||
148 | 65 | std::ostream& out; | 69 | std::ostream& out; |
149 | 70 | Optional<Update<Position>> last_position_update; | ||
150 | 71 | Optional<Update<units::Degrees>> last_heading_update; | ||
151 | 72 | Optional<Update<units::MetersPerSecond>> last_velocity_update; | ||
152 | 66 | }; | 73 | }; |
153 | 67 | 74 | ||
154 | 68 | // Monitor initializes a new instance. | 75 | // Monitor initializes a new instance. |
155 | 69 | 76 | ||
156 | === renamed directory 'src/location/providers/ubx/_8/nmea' => 'src/location/nmea' | |||
157 | === modified file 'src/location/nmea/cardinal_direction.h' | |||
158 | --- src/location/providers/ubx/_8/nmea/cardinal_direction.h 2016-10-10 09:15:40 +0000 | |||
159 | +++ src/location/nmea/cardinal_direction.h 2017-05-05 09:37:41 +0000 | |||
160 | @@ -12,17 +12,11 @@ | |||
161 | 12 | // | 12 | // |
162 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
163 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
166 | 15 | #ifndef UBX_8_NMEA_CARDINAL_DIRECTION_H_ | 15 | #ifndef LOCATION_NMEA_CARDINAL_DIRECTION_H_ |
167 | 16 | #define UBX_8_NMEA_CARDINAL_DIRECTION_H_ | 16 | #define LOCATION_NMEA_CARDINAL_DIRECTION_H_ |
168 | 17 | 17 | ||
169 | 18 | namespace location | 18 | namespace location |
170 | 19 | { | 19 | { |
171 | 20 | namespace providers | ||
172 | 21 | { | ||
173 | 22 | namespace ubx | ||
174 | 23 | { | ||
175 | 24 | namespace _8 | ||
176 | 25 | { | ||
177 | 26 | namespace nmea | 20 | namespace nmea |
178 | 27 | { | 21 | { |
179 | 28 | /// @brief CardinalDirection enumerates the main cardinal direction | 22 | /// @brief CardinalDirection enumerates the main cardinal direction |
180 | @@ -36,8 +30,5 @@ | |||
181 | 36 | }; | 30 | }; |
182 | 37 | } | 31 | } |
183 | 38 | } | 32 | } |
184 | 39 | } | ||
185 | 40 | } | ||
186 | 41 | } | ||
187 | 42 | 33 | ||
189 | 43 | #endif // UBX_8_NMEA_CARDINAL_DIRECTION_H_ | 34 | #endif // LOCATION_NMEA_CARDINAL_DIRECTION_H_ |
190 | 44 | 35 | ||
191 | === modified file 'src/location/nmea/date.h' | |||
192 | --- src/location/providers/ubx/_8/nmea/date.h 2016-10-10 09:15:40 +0000 | |||
193 | +++ src/location/nmea/date.h 2017-05-05 09:37:41 +0000 | |||
194 | @@ -12,19 +12,13 @@ | |||
195 | 12 | // | 12 | // |
196 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
197 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
200 | 15 | #ifndef UBX_8_NMEA_DATE_H_ | 15 | #ifndef LOCATION_NMEA_DATE_H_ |
201 | 16 | #define UBX_8_NMEA_DATE_H_ | 16 | #define LOCATION_NMEA_DATE_H_ |
202 | 17 | 17 | ||
203 | 18 | #include <cstdint> | 18 | #include <cstdint> |
204 | 19 | 19 | ||
205 | 20 | namespace location | 20 | namespace location |
206 | 21 | { | 21 | { |
207 | 22 | namespace providers | ||
208 | 23 | { | ||
209 | 24 | namespace ubx | ||
210 | 25 | { | ||
211 | 26 | namespace _8 | ||
212 | 27 | { | ||
213 | 28 | namespace nmea | 22 | namespace nmea |
214 | 29 | { | 23 | { |
215 | 30 | /// @brief Date models a specific calendar day (Gregorian calendar). | 24 | /// @brief Date models a specific calendar day (Gregorian calendar). |
216 | @@ -36,8 +30,5 @@ | |||
217 | 36 | }; | 30 | }; |
218 | 37 | } | 31 | } |
219 | 38 | } | 32 | } |
220 | 39 | } | ||
221 | 40 | } | ||
222 | 41 | } | ||
223 | 42 | 33 | ||
225 | 43 | #endif // UBX_8_NMEA_DATE_H_ | 34 | #endif // LOCATION_NMEA_DATE_H_ |
226 | 44 | 35 | ||
227 | === modified file 'src/location/nmea/fusion_adapt.h' | |||
228 | --- src/location/providers/ubx/_8/nmea/fusion_adapt.h 2016-10-10 09:15:40 +0000 | |||
229 | +++ src/location/nmea/fusion_adapt.h 2017-05-05 09:37:41 +0000 | |||
230 | @@ -12,123 +12,123 @@ | |||
231 | 12 | // | 12 | // |
232 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
233 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
236 | 15 | #ifndef UBX_8_NMEA_FUSION_ADAPT_H_ | 15 | #ifndef LOCATION_NMEA_FUSION_ADAPT_H_ |
237 | 16 | #define UBX_8_NMEA_FUSION_ADAPT_H_ | 16 | #define LOCATION_NMEA_FUSION_ADAPT_H_ |
238 | 17 | 17 | ||
239 | 18 | #define BOOST_SPIRIT_DEBUG | 18 | #define BOOST_SPIRIT_DEBUG |
240 | 19 | #define FUSION_MAX_VECTOR_SIZE 15 | 19 | #define FUSION_MAX_VECTOR_SIZE 15 |
241 | 20 | 20 | ||
243 | 21 | #include <location/providers/ubx/_8/nmea/sentence.h> | 21 | #include <location/nmea/sentence.h> |
244 | 22 | 22 | ||
245 | 23 | #include <boost/fusion/adapted/struct.hpp> | 23 | #include <boost/fusion/adapted/struct.hpp> |
246 | 24 | 24 | ||
247 | 25 | // clang-format off | 25 | // clang-format off |
248 | 26 | BOOST_FUSION_ADAPT_STRUCT( | 26 | BOOST_FUSION_ADAPT_STRUCT( |
260 | 27 | location::providers::ubx::_8::nmea::Latitude, | 27 | location::nmea::Latitude, |
261 | 28 | (uint32_t, degrees) | 28 | (uint32_t, degrees) |
262 | 29 | (double, minutes)) | 29 | (double, minutes)) |
263 | 30 | 30 | ||
264 | 31 | BOOST_FUSION_ADAPT_STRUCT( | 31 | BOOST_FUSION_ADAPT_STRUCT( |
265 | 32 | location::providers::ubx::_8::nmea::Longitude, | 32 | location::nmea::Longitude, |
266 | 33 | (uint32_t, degrees) | 33 | (uint32_t, degrees) |
267 | 34 | (double, minutes)) | 34 | (double, minutes)) |
268 | 35 | 35 | ||
269 | 36 | BOOST_FUSION_ADAPT_STRUCT( | 36 | BOOST_FUSION_ADAPT_STRUCT( |
270 | 37 | location::providers::ubx::_8::nmea::Date, | 37 | location::nmea::Date, |
271 | 38 | (std::uint8_t, day) | 38 | (std::uint8_t, day) |
272 | 39 | (std::uint8_t, month) | 39 | (std::uint8_t, month) |
273 | 40 | (std::uint8_t, year)) | 40 | (std::uint8_t, year)) |
274 | 41 | 41 | ||
275 | 42 | BOOST_FUSION_ADAPT_STRUCT( | 42 | BOOST_FUSION_ADAPT_STRUCT( |
277 | 43 | location::providers::ubx::_8::nmea::Utc, | 43 | location::nmea::Utc, |
278 | 44 | (std::uint8_t, hours) | 44 | (std::uint8_t, hours) |
279 | 45 | (std::uint8_t, minutes) | 45 | (std::uint8_t, minutes) |
280 | 46 | (double, seconds)) | 46 | (double, seconds)) |
281 | 47 | 47 | ||
282 | 48 | BOOST_FUSION_ADAPT_STRUCT( | 48 | BOOST_FUSION_ADAPT_STRUCT( |
287 | 49 | location::providers::ubx::_8::nmea::Gsa, | 49 | location::nmea::Gsa, |
288 | 50 | (location::providers::ubx::_8::nmea::Talker, talker) | 50 | (location::nmea::Talker, talker) |
289 | 51 | (boost::optional<location::providers::ubx::_8::nmea::Gsa::OperationMode>, operation_mode) | 51 | (boost::optional<location::nmea::Gsa::OperationMode>, operation_mode) |
290 | 52 | (boost::optional<location::providers::ubx::_8::nmea::Gsa::FixMode>, fix_mode) | 52 | (boost::optional<location::nmea::Gsa::FixMode>, fix_mode) |
291 | 53 | (std::vector<boost::optional<std::uint8_t>>, satellite_ids) | 53 | (std::vector<boost::optional<std::uint8_t>>, satellite_ids) |
295 | 54 | (boost::optional<location::providers::ubx::Dop<location::providers::ubx::tag::Positional>>, pdop) | 54 | (boost::optional<float>, pdop) |
296 | 55 | (boost::optional<location::providers::ubx::Dop<location::providers::ubx::tag::Horizontal>>, hdop) | 55 | (boost::optional<float>, hdop) |
297 | 56 | (boost::optional<location::providers::ubx::Dop<location::providers::ubx::tag::Vertical>>, vdop)) | 56 | (boost::optional<float>, vdop)) |
298 | 57 | 57 | ||
299 | 58 | BOOST_FUSION_ADAPT_STRUCT( | 58 | BOOST_FUSION_ADAPT_STRUCT( |
308 | 59 | location::providers::ubx::_8::nmea::Gga, | 59 | location::nmea::Gga, |
309 | 60 | (location::providers::ubx::_8::nmea::Talker, talker) | 60 | (location::nmea::Talker, talker) |
310 | 61 | (boost::optional<location::providers::ubx::_8::nmea::Utc>, utc) | 61 | (boost::optional<location::nmea::Utc>, utc) |
311 | 62 | (boost::optional<location::providers::ubx::_8::nmea::Latitude>, latitude) | 62 | (boost::optional<location::nmea::Latitude>, latitude) |
312 | 63 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, latitude_direction) | 63 | (boost::optional<location::nmea::CardinalDirection>, latitude_direction) |
313 | 64 | (boost::optional<location::providers::ubx::_8::nmea::Longitude>, longitude) | 64 | (boost::optional<location::nmea::Longitude>, longitude) |
314 | 65 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, longitude_direction) | 65 | (boost::optional<location::nmea::CardinalDirection>, longitude_direction) |
315 | 66 | (boost::optional<location::providers::ubx::_8::nmea::gps::FixMode>, fix_mode) | 66 | (boost::optional<location::nmea::gps::FixMode>, fix_mode) |
316 | 67 | (boost::optional<std::uint8_t>, satellites_in_use) | 67 | (boost::optional<std::uint8_t>, satellites_in_use) |
318 | 68 | (boost::optional<location::providers::ubx::Dop<location::providers::ubx::tag::Horizontal>>, hdop) | 68 | (boost::optional<float>, hdop) |
319 | 69 | (boost::optional<float>, altitude) | 69 | (boost::optional<float>, altitude) |
320 | 70 | (boost::optional<float>, geoidal_separation) | 70 | (boost::optional<float>, geoidal_separation) |
321 | 71 | (boost::optional<float>, age) | 71 | (boost::optional<float>, age) |
322 | 72 | (boost::optional<std::uint16_t>, differential_reference_station)) | 72 | (boost::optional<std::uint16_t>, differential_reference_station)) |
323 | 73 | 73 | ||
324 | 74 | BOOST_FUSION_ADAPT_STRUCT( | 74 | BOOST_FUSION_ADAPT_STRUCT( |
334 | 75 | location::providers::ubx::_8::nmea::Gll, | 75 | location::nmea::Gll, |
335 | 76 | (location::providers::ubx::_8::nmea::Talker, talker) | 76 | (location::nmea::Talker, talker) |
336 | 77 | (boost::optional<location::providers::ubx::_8::nmea::Latitude>, latitude) | 77 | (boost::optional<location::nmea::Latitude>, latitude) |
337 | 78 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, latitude_direction) | 78 | (boost::optional<location::nmea::CardinalDirection>, latitude_direction) |
338 | 79 | (boost::optional<location::providers::ubx::_8::nmea::Longitude>, longitude) | 79 | (boost::optional<location::nmea::Longitude>, longitude) |
339 | 80 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, longitude_direction) | 80 | (boost::optional<location::nmea::CardinalDirection>, longitude_direction) |
340 | 81 | (boost::optional<location::providers::ubx::_8::nmea::Utc>, utc) | 81 | (boost::optional<location::nmea::Utc>, utc) |
341 | 82 | (boost::optional<location::providers::ubx::_8::nmea::Status>, status) | 82 | (boost::optional<location::nmea::Status>, status) |
342 | 83 | (boost::optional<location::providers::ubx::_8::nmea::Mode>, mode)) | 83 | (boost::optional<location::nmea::Mode>, mode)) |
343 | 84 | 84 | ||
344 | 85 | BOOST_FUSION_ADAPT_STRUCT( | 85 | BOOST_FUSION_ADAPT_STRUCT( |
346 | 86 | location::providers::ubx::_8::nmea::Gsv::Info, | 86 | location::nmea::Gsv::Info, |
347 | 87 | (boost::optional<std::uint8_t>, satellite_id) | 87 | (boost::optional<std::uint8_t>, satellite_id) |
348 | 88 | (boost::optional<std::uint8_t>, elevation) | 88 | (boost::optional<std::uint8_t>, elevation) |
349 | 89 | (boost::optional<std::uint16_t>, azimuth) | 89 | (boost::optional<std::uint16_t>, azimuth) |
350 | 90 | (boost::optional<std::uint8_t>, snr)) | 90 | (boost::optional<std::uint8_t>, snr)) |
351 | 91 | 91 | ||
352 | 92 | BOOST_FUSION_ADAPT_STRUCT( | 92 | BOOST_FUSION_ADAPT_STRUCT( |
355 | 93 | location::providers::ubx::_8::nmea::Gsv, | 93 | location::nmea::Gsv, |
356 | 94 | (location::providers::ubx::_8::nmea::Talker, talker) | 94 | (location::nmea::Talker, talker) |
357 | 95 | (boost::optional<std::uint8_t>, sentence_count) | 95 | (boost::optional<std::uint8_t>, sentence_count) |
358 | 96 | (boost::optional<std::uint8_t>, sentence_number) | 96 | (boost::optional<std::uint8_t>, sentence_number) |
359 | 97 | (boost::optional<std::uint8_t>, satellites_count) | 97 | (boost::optional<std::uint8_t>, satellites_count) |
361 | 98 | (std::vector<location::providers::ubx::_8::nmea::Gsv::Info>, satellites_info)) | 98 | (std::vector<location::nmea::Gsv::Info>, satellites_info)) |
362 | 99 | 99 | ||
363 | 100 | BOOST_FUSION_ADAPT_STRUCT( | 100 | BOOST_FUSION_ADAPT_STRUCT( |
372 | 101 | location::providers::ubx::_8::nmea::Rmc, | 101 | location::nmea::Rmc, |
373 | 102 | (location::providers::ubx::_8::nmea::Talker, talker) | 102 | (location::nmea::Talker, talker) |
374 | 103 | (boost::optional<location::providers::ubx::_8::nmea::Utc>, utc) | 103 | (boost::optional<location::nmea::Utc>, utc) |
375 | 104 | (boost::optional<location::providers::ubx::_8::nmea::Status>, status) | 104 | (boost::optional<location::nmea::Status>, status) |
376 | 105 | (boost::optional<location::providers::ubx::_8::nmea::Latitude>, latitude) | 105 | (boost::optional<location::nmea::Latitude>, latitude) |
377 | 106 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, latitude_direction) | 106 | (boost::optional<location::nmea::CardinalDirection>, latitude_direction) |
378 | 107 | (boost::optional<location::providers::ubx::_8::nmea::Longitude>, longitude) | 107 | (boost::optional<location::nmea::Longitude>, longitude) |
379 | 108 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, longitude_direction) | 108 | (boost::optional<location::nmea::CardinalDirection>, longitude_direction) |
380 | 109 | (boost::optional<float>, speed_over_ground)(boost::optional<float>, course_over_ground) | 109 | (boost::optional<float>, speed_over_ground)(boost::optional<float>, course_over_ground) |
382 | 110 | (boost::optional<location::providers::ubx::_8::nmea::Date>, date) | 110 | (boost::optional<location::nmea::Date>, date) |
383 | 111 | (boost::optional<float>, magnetic_variation) | 111 | (boost::optional<float>, magnetic_variation) |
386 | 112 | (boost::optional<location::providers::ubx::_8::nmea::CardinalDirection>, cardinal_direction) | 112 | (boost::optional<location::nmea::CardinalDirection>, cardinal_direction) |
387 | 113 | (boost::optional<location::providers::ubx::_8::nmea::Mode>, mode)) | 113 | (boost::optional<location::nmea::Mode>, mode)) |
388 | 114 | 114 | ||
389 | 115 | BOOST_FUSION_ADAPT_STRUCT( | 115 | BOOST_FUSION_ADAPT_STRUCT( |
392 | 116 | location::providers::ubx::_8::nmea::Txt, | 116 | location::nmea::Txt, |
393 | 117 | (location::providers::ubx::_8::nmea::Talker, talker) | 117 | (location::nmea::Talker, talker) |
394 | 118 | (boost::optional<std::uint8_t>, total_number_of_sentences) | 118 | (boost::optional<std::uint8_t>, total_number_of_sentences) |
395 | 119 | (boost::optional<std::uint8_t>, sentence_number) | 119 | (boost::optional<std::uint8_t>, sentence_number) |
396 | 120 | (boost::optional<std::uint8_t>, identifier) | 120 | (boost::optional<std::uint8_t>, identifier) |
397 | 121 | (boost::optional<std::string>, message)) | 121 | (boost::optional<std::string>, message)) |
398 | 122 | 122 | ||
399 | 123 | BOOST_FUSION_ADAPT_STRUCT( | 123 | BOOST_FUSION_ADAPT_STRUCT( |
402 | 124 | location::providers::ubx::_8::nmea::Vtg, | 124 | location::nmea::Vtg, |
403 | 125 | (location::providers::ubx::_8::nmea::Talker, talker) | 125 | (location::nmea::Talker, talker) |
404 | 126 | (boost::optional<float>, cog_true) | 126 | (boost::optional<float>, cog_true) |
405 | 127 | (boost::optional<float>, cog_magnetic) | 127 | (boost::optional<float>, cog_magnetic) |
406 | 128 | (boost::optional<float>, sog_knots) | 128 | (boost::optional<float>, sog_knots) |
407 | 129 | (boost::optional<float>, sog_kmh) | 129 | (boost::optional<float>, sog_kmh) |
409 | 130 | (boost::optional<location::providers::ubx::_8::nmea::Mode>, mode)) | 130 | (boost::optional<location::nmea::Mode>, mode)) |
410 | 131 | 131 | ||
411 | 132 | // clang-format on | 132 | // clang-format on |
412 | 133 | 133 | ||
414 | 134 | #endif // UBX_8_NMEA_FUSION_ADAPT_H_ | 134 | #endif // LOCATION_NMEA_FUSION_ADAPT_H_ |
415 | 135 | 135 | ||
416 | === modified file 'src/location/nmea/generator.h' | |||
417 | --- src/location/providers/ubx/_8/nmea/generator.h 2017-03-09 09:42:25 +0000 | |||
418 | +++ src/location/nmea/generator.h 2017-05-05 09:37:41 +0000 | |||
419 | @@ -12,15 +12,14 @@ | |||
420 | 12 | // | 12 | // |
421 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
422 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
425 | 15 | #ifndef UBX_8_NMEA_GENERATOR_H_ | 15 | #ifndef LOCATION_NMEA_GENERATOR_H_ |
426 | 16 | #define UBX_8_NMEA_GENERATOR_H_ | 16 | #define LOCATION_NMEA_GENERATOR_H_ |
427 | 17 | 17 | ||
428 | 18 | #define BOOST_SPIRIT_DEBUG | ||
429 | 19 | #define FUSION_MAX_VECTOR_SIZE 15 | 18 | #define FUSION_MAX_VECTOR_SIZE 15 |
430 | 20 | 19 | ||
432 | 21 | #include <location/providers/ubx/_8/nmea/sentence.h> | 20 | #include <location/nmea/sentence.h> |
433 | 22 | 21 | ||
435 | 23 | #include <location/providers/ubx/_8/nmea/fusion_adapt.h> | 22 | #include <location/nmea/fusion_adapt.h> |
436 | 24 | 23 | ||
437 | 25 | #include <boost/spirit/include/classic.hpp> | 24 | #include <boost/spirit/include/classic.hpp> |
438 | 26 | #include <boost/spirit/include/karma.hpp> | 25 | #include <boost/spirit/include/karma.hpp> |
439 | @@ -31,12 +30,6 @@ | |||
440 | 31 | 30 | ||
441 | 32 | namespace location | 31 | namespace location |
442 | 33 | { | 32 | { |
443 | 34 | namespace providers | ||
444 | 35 | { | ||
445 | 36 | namespace ubx | ||
446 | 37 | { | ||
447 | 38 | namespace _8 | ||
448 | 39 | { | ||
449 | 40 | namespace nmea | 33 | namespace nmea |
450 | 41 | { | 34 | { |
451 | 42 | 35 | ||
452 | @@ -209,9 +202,9 @@ | |||
453 | 209 | boost::spirit::karma::rule<Iterator, Longitude()> longitude; | 202 | boost::spirit::karma::rule<Iterator, Longitude()> longitude; |
454 | 210 | boost::spirit::karma::rule<Iterator, Date()> date; | 203 | boost::spirit::karma::rule<Iterator, Date()> date; |
455 | 211 | boost::spirit::karma::rule<Iterator, Utc()> utc; | 204 | boost::spirit::karma::rule<Iterator, Utc()> utc; |
459 | 212 | boost::spirit::karma::rule<Iterator, Dop<tag::Positional>()> pdop; | 205 | boost::spirit::karma::rule<Iterator, float()> pdop; |
460 | 213 | boost::spirit::karma::rule<Iterator, Dop<tag::Horizontal>()> hdop; | 206 | boost::spirit::karma::rule<Iterator, float()> hdop; |
461 | 214 | boost::spirit::karma::rule<Iterator, Dop<tag::Vertical>()> vdop; | 207 | boost::spirit::karma::rule<Iterator, float()> vdop; |
462 | 215 | 208 | ||
463 | 216 | boost::spirit::karma::rule<Iterator, Gsa()> gsa; | 209 | boost::spirit::karma::rule<Iterator, Gsa()> gsa; |
464 | 217 | boost::spirit::karma::rule<Iterator, Gga()> gga; | 210 | boost::spirit::karma::rule<Iterator, Gga()> gga; |
465 | @@ -246,10 +239,8 @@ | |||
466 | 246 | boost::spirit::karma::symbols<Gsa::FixMode, char> fix_mode; | 239 | boost::spirit::karma::symbols<Gsa::FixMode, char> fix_mode; |
467 | 247 | } for_gsa; | 240 | } for_gsa; |
468 | 248 | }; | 241 | }; |
476 | 249 | } | 242 | |
477 | 250 | } | 243 | } |
478 | 251 | } | 244 | } |
479 | 252 | } | 245 | |
480 | 253 | } | 246 | #endif // LOCATION_NMEA_GENERATOR_H_ |
474 | 254 | |||
475 | 255 | #endif // UBX_8_NMEA_GENERATOR_H_ | ||
481 | 256 | 247 | ||
482 | === modified file 'src/location/nmea/gga.h' | |||
483 | --- src/location/providers/ubx/_8/nmea/gga.h 2016-10-10 09:15:40 +0000 | |||
484 | +++ src/location/nmea/gga.h 2017-05-05 09:37:41 +0000 | |||
485 | @@ -12,18 +12,18 @@ | |||
486 | 12 | // | 12 | // |
487 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
488 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
491 | 15 | #ifndef UBX_8_NMEA_GGA_H_ | 15 | #ifndef LOCATION_NMEA_GGA_H_ |
492 | 16 | #define UBX_8_NMEA_GGA_H_ | 16 | #define LOCATION_NMEA_GGA_H_ |
493 | 17 | 17 | ||
494 | 18 | #include <location/providers/ubx/dop.h> | 18 | #include <location/providers/ubx/dop.h> |
495 | 19 | 19 | ||
501 | 20 | #include <location/providers/ubx/_8/nmea/cardinal_direction.h> | 20 | #include <location/nmea/cardinal_direction.h> |
502 | 21 | #include <location/providers/ubx/_8/nmea/latitude.h> | 21 | #include <location/nmea/latitude.h> |
503 | 22 | #include <location/providers/ubx/_8/nmea/longitude.h> | 22 | #include <location/nmea/longitude.h> |
504 | 23 | #include <location/providers/ubx/_8/nmea/talker.h> | 23 | #include <location/nmea/talker.h> |
505 | 24 | #include <location/providers/ubx/_8/nmea/utc.h> | 24 | #include <location/nmea/utc.h> |
506 | 25 | 25 | ||
508 | 26 | #include <location/providers/ubx/_8/nmea/gps/fix_mode.h> | 26 | #include <location/nmea/gps/fix_mode.h> |
509 | 27 | 27 | ||
510 | 28 | #include <boost/optional.hpp> | 28 | #include <boost/optional.hpp> |
511 | 29 | 29 | ||
512 | @@ -31,14 +31,9 @@ | |||
513 | 31 | 31 | ||
514 | 32 | namespace location | 32 | namespace location |
515 | 33 | { | 33 | { |
516 | 34 | namespace providers | ||
517 | 35 | { | ||
518 | 36 | namespace ubx | ||
519 | 37 | { | ||
520 | 38 | namespace _8 | ||
521 | 39 | { | ||
522 | 40 | namespace nmea | 34 | namespace nmea |
523 | 41 | { | 35 | { |
524 | 36 | |||
525 | 42 | /// @brief Global positioning system fix data. | 37 | /// @brief Global positioning system fix data. |
526 | 43 | /// | 38 | /// |
527 | 44 | /// Time and position, together with GPS fixing related data (number of | 39 | /// Time and position, together with GPS fixing related data (number of |
528 | @@ -54,16 +49,14 @@ | |||
529 | 54 | boost::optional<CardinalDirection> longitude_direction; | 49 | boost::optional<CardinalDirection> longitude_direction; |
530 | 55 | boost::optional<gps::FixMode> fix_mode; | 50 | boost::optional<gps::FixMode> fix_mode; |
531 | 56 | boost::optional<std::uint8_t> satellites_in_use; | 51 | boost::optional<std::uint8_t> satellites_in_use; |
533 | 57 | boost::optional<Dop<tag::Horizontal>> hdop; | 52 | boost::optional<float> hdop; |
534 | 58 | boost::optional<float> altitude; | 53 | boost::optional<float> altitude; |
535 | 59 | boost::optional<float> geoidal_separation; | 54 | boost::optional<float> geoidal_separation; |
536 | 60 | boost::optional<float> age; // [s] | 55 | boost::optional<float> age; // [s] |
537 | 61 | boost::optional<std::uint16_t> differential_reference_station; | 56 | boost::optional<std::uint16_t> differential_reference_station; |
538 | 62 | }; | 57 | }; |
546 | 63 | } | 58 | |
547 | 64 | } | 59 | } |
548 | 65 | } | 60 | } |
549 | 66 | } | 61 | |
550 | 67 | } | 62 | #endif // LOCATION_NMEA_GGA_H_ |
544 | 68 | |||
545 | 69 | #endif // UBX_8_NMEA_GGA_H_ | ||
551 | 70 | 63 | ||
552 | === modified file 'src/location/nmea/gll.h' | |||
553 | --- src/location/providers/ubx/_8/nmea/gll.h 2016-10-10 09:15:40 +0000 | |||
554 | +++ src/location/nmea/gll.h 2017-05-05 09:37:41 +0000 | |||
555 | @@ -12,29 +12,24 @@ | |||
556 | 12 | // | 12 | // |
557 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
558 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
561 | 15 | #ifndef UBX_8_NMEA_GLL_H_ | 15 | #ifndef LOCATION_NMEA_GLL_H_ |
562 | 16 | #define UBX_8_NMEA_GLL_H_ | 16 | #define LOCATION_NMEA_GLL_H_ |
563 | 17 | 17 | ||
571 | 18 | #include <location/providers/ubx/_8/nmea/cardinal_direction.h> | 18 | #include <location/nmea/cardinal_direction.h> |
572 | 19 | #include <location/providers/ubx/_8/nmea/latitude.h> | 19 | #include <location/nmea/latitude.h> |
573 | 20 | #include <location/providers/ubx/_8/nmea/longitude.h> | 20 | #include <location/nmea/longitude.h> |
574 | 21 | #include <location/providers/ubx/_8/nmea/mode.h> | 21 | #include <location/nmea/mode.h> |
575 | 22 | #include <location/providers/ubx/_8/nmea/status.h> | 22 | #include <location/nmea/status.h> |
576 | 23 | #include <location/providers/ubx/_8/nmea/talker.h> | 23 | #include <location/nmea/talker.h> |
577 | 24 | #include <location/providers/ubx/_8/nmea/utc.h> | 24 | #include <location/nmea/utc.h> |
578 | 25 | 25 | ||
579 | 26 | #include <boost/optional.hpp> | 26 | #include <boost/optional.hpp> |
580 | 27 | 27 | ||
581 | 28 | namespace location | 28 | namespace location |
582 | 29 | { | 29 | { |
583 | 30 | namespace providers | ||
584 | 31 | { | ||
585 | 32 | namespace ubx | ||
586 | 33 | { | ||
587 | 34 | namespace _8 | ||
588 | 35 | { | ||
589 | 36 | namespace nmea | 30 | namespace nmea |
590 | 37 | { | 31 | { |
591 | 32 | |||
592 | 38 | /// @brief Latitude and longitude, with time of position fix and status | 33 | /// @brief Latitude and longitude, with time of position fix and status |
593 | 39 | struct Gll | 34 | struct Gll |
594 | 40 | { | 35 | { |
595 | @@ -49,8 +44,5 @@ | |||
596 | 49 | }; | 44 | }; |
597 | 50 | } | 45 | } |
598 | 51 | } | 46 | } |
599 | 52 | } | ||
600 | 53 | } | ||
601 | 54 | } | ||
602 | 55 | 47 | ||
604 | 56 | #endif // UBX_8_NMEA_GLL_H_ | 48 | #endif // LOCATION_NMEA_GLL_H_ |
605 | 57 | 49 | ||
606 | === modified file 'src/location/nmea/gps/fix_mode.h' | |||
607 | --- src/location/providers/ubx/_8/nmea/gps/fix_mode.h 2016-10-10 09:15:40 +0000 | |||
608 | +++ src/location/nmea/gps/fix_mode.h 2017-05-05 09:37:41 +0000 | |||
609 | @@ -12,21 +12,16 @@ | |||
610 | 12 | // | 12 | // |
611 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
612 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
615 | 15 | #ifndef UBX_8_NMEA_GPS_FIX_MODE_H_ | 15 | #ifndef LOCATION_NMEA_GPS_FIX_MODE_H_ |
616 | 16 | #define UBX_8_NMEA_GPS_FIX_MODE_H_ | 16 | #define LOCATION_NMEA_GPS_FIX_MODE_H_ |
617 | 17 | 17 | ||
618 | 18 | namespace location | 18 | namespace location |
619 | 19 | { | 19 | { |
620 | 20 | namespace providers | ||
621 | 21 | { | ||
622 | 22 | namespace ubx | ||
623 | 23 | { | ||
624 | 24 | namespace _8 | ||
625 | 25 | { | ||
626 | 26 | namespace nmea | 20 | namespace nmea |
627 | 27 | { | 21 | { |
628 | 28 | namespace gps | 22 | namespace gps |
629 | 29 | { | 23 | { |
630 | 24 | |||
631 | 30 | /// @brief FixMode enumerates all known, gps-specific fix modes. | 25 | /// @brief FixMode enumerates all known, gps-specific fix modes. |
632 | 31 | enum class FixMode | 26 | enum class FixMode |
633 | 32 | { | 27 | { |
634 | @@ -40,11 +35,9 @@ | |||
635 | 40 | manual_input = 7, | 35 | manual_input = 7, |
636 | 41 | simulator = 8 | 36 | simulator = 8 |
637 | 42 | }; | 37 | }; |
646 | 43 | } | 38 | |
647 | 44 | } | 39 | } |
648 | 45 | } | 40 | } |
649 | 46 | } | 41 | } |
650 | 47 | } | 42 | |
651 | 48 | } | 43 | #endif // LOCATION_NMEA_GPS_FIX_MODE_H_ |
644 | 49 | |||
645 | 50 | #endif // UBX_8_NMEA_GPS_FIX_MODE_H_ | ||
652 | 51 | 44 | ||
653 | === modified file 'src/location/nmea/grammar.h' | |||
654 | --- src/location/providers/ubx/_8/nmea/grammar.h 2017-03-09 09:42:25 +0000 | |||
655 | +++ src/location/nmea/grammar.h 2017-05-05 09:37:41 +0000 | |||
656 | @@ -12,13 +12,12 @@ | |||
657 | 12 | // | 12 | // |
658 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
659 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
662 | 15 | #ifndef UBX_8_NMEA_GRAMMAR_H_ | 15 | #ifndef LOCATION_NMEA_GRAMMAR_H_ |
663 | 16 | #define UBX_8_NMEA_GRAMMAR_H_ | 16 | #define LOCATION_NMEA_GRAMMAR_H_ |
664 | 17 | 17 | ||
665 | 18 | #define BOOST_SPIRIT_DEBUG | ||
666 | 19 | #define FUSION_MAX_VECTOR_SIZE 15 | 18 | #define FUSION_MAX_VECTOR_SIZE 15 |
667 | 20 | 19 | ||
669 | 21 | #include <location/providers/ubx/_8/nmea/fusion_adapt.h> | 20 | #include <location/nmea/fusion_adapt.h> |
670 | 22 | 21 | ||
671 | 23 | #include <boost/spirit/include/classic.hpp> | 22 | #include <boost/spirit/include/classic.hpp> |
672 | 24 | #include <boost/spirit/include/qi.hpp> | 23 | #include <boost/spirit/include/qi.hpp> |
673 | @@ -29,12 +28,6 @@ | |||
674 | 29 | 28 | ||
675 | 30 | namespace location | 29 | namespace location |
676 | 31 | { | 30 | { |
677 | 32 | namespace providers | ||
678 | 33 | { | ||
679 | 34 | namespace ubx | ||
680 | 35 | { | ||
681 | 36 | namespace _8 | ||
682 | 37 | { | ||
683 | 38 | namespace nmea | 31 | namespace nmea |
684 | 39 | { | 32 | { |
685 | 40 | 33 | ||
686 | @@ -206,9 +199,9 @@ | |||
687 | 206 | boost::spirit::qi::rule<Iterator, Longitude()> longitude; | 199 | boost::spirit::qi::rule<Iterator, Longitude()> longitude; |
688 | 207 | boost::spirit::qi::rule<Iterator, Date()> date; | 200 | boost::spirit::qi::rule<Iterator, Date()> date; |
689 | 208 | boost::spirit::qi::rule<Iterator, Utc()> utc; | 201 | boost::spirit::qi::rule<Iterator, Utc()> utc; |
693 | 209 | boost::spirit::qi::rule<Iterator, Dop<tag::Positional>()> pdop; | 202 | boost::spirit::qi::rule<Iterator, float()> pdop; |
694 | 210 | boost::spirit::qi::rule<Iterator, Dop<tag::Horizontal>()> hdop; | 203 | boost::spirit::qi::rule<Iterator, float()> hdop; |
695 | 211 | boost::spirit::qi::rule<Iterator, Dop<tag::Vertical>()> vdop; | 204 | boost::spirit::qi::rule<Iterator, float()> vdop; |
696 | 212 | 205 | ||
697 | 213 | boost::spirit::qi::rule<Iterator, Gsa()> gsa; | 206 | boost::spirit::qi::rule<Iterator, Gsa()> gsa; |
698 | 214 | boost::spirit::qi::rule<Iterator, Gga()> gga; | 207 | boost::spirit::qi::rule<Iterator, Gga()> gga; |
699 | @@ -245,8 +238,5 @@ | |||
700 | 245 | }; | 238 | }; |
701 | 246 | } | 239 | } |
702 | 247 | } | 240 | } |
703 | 248 | } | ||
704 | 249 | } | ||
705 | 250 | } | ||
706 | 251 | 241 | ||
708 | 252 | #endif // UBX_8_NMEA_GRAMMAR_H_ | 242 | #endif // LOCATION_NMEA_GRAMMAR_H_ |
709 | 253 | 243 | ||
710 | === modified file 'src/location/nmea/gsa.h' | |||
711 | --- src/location/providers/ubx/_8/nmea/gsa.h 2016-10-10 09:15:40 +0000 | |||
712 | +++ src/location/nmea/gsa.h 2017-05-05 09:37:41 +0000 | |||
713 | @@ -12,16 +12,16 @@ | |||
714 | 12 | // | 12 | // |
715 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
716 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
719 | 15 | #ifndef UBX_8_NMEA_GSA_H_ | 15 | #ifndef LOCATION_NMEA_GSA_H_ |
720 | 16 | #define UBX_8_NMEA_GSA_H_ | 16 | #define LOCATION_NMEA_GSA_H_ |
721 | 17 | 17 | ||
722 | 18 | #include <location/providers/ubx/dop.h> | 18 | #include <location/providers/ubx/dop.h> |
723 | 19 | 19 | ||
727 | 20 | #include <location/providers/ubx/_8/nmea/latitude.h> | 20 | #include <location/nmea/latitude.h> |
728 | 21 | #include <location/providers/ubx/_8/nmea/longitude.h> | 21 | #include <location/nmea/longitude.h> |
729 | 22 | #include <location/providers/ubx/_8/nmea/talker.h> | 22 | #include <location/nmea/talker.h> |
730 | 23 | 23 | ||
732 | 24 | #include <location/providers/ubx/_8/nmea/gps/fix_mode.h> | 24 | #include <location/nmea/gps/fix_mode.h> |
733 | 25 | 25 | ||
734 | 26 | #include <boost/optional.hpp> | 26 | #include <boost/optional.hpp> |
735 | 27 | 27 | ||
736 | @@ -30,12 +30,6 @@ | |||
737 | 30 | 30 | ||
738 | 31 | namespace location | 31 | namespace location |
739 | 32 | { | 32 | { |
740 | 33 | namespace providers | ||
741 | 34 | { | ||
742 | 35 | namespace ubx | ||
743 | 36 | { | ||
744 | 37 | namespace _8 | ||
745 | 38 | { | ||
746 | 39 | namespace nmea | 33 | namespace nmea |
747 | 40 | { | 34 | { |
748 | 41 | /// @brief GNSS DOP and Active Satellites. | 35 | /// @brief GNSS DOP and Active Satellites. |
749 | @@ -71,14 +65,11 @@ | |||
750 | 71 | boost::optional<OperationMode> operation_mode; | 65 | boost::optional<OperationMode> operation_mode; |
751 | 72 | boost::optional<FixMode> fix_mode; | 66 | boost::optional<FixMode> fix_mode; |
752 | 73 | std::vector<boost::optional<std::uint8_t>> satellite_ids; | 67 | std::vector<boost::optional<std::uint8_t>> satellite_ids; |
756 | 74 | boost::optional<Dop<tag::Positional>> pdop; | 68 | boost::optional<float> pdop; |
757 | 75 | boost::optional<Dop<tag::Horizontal>> hdop; | 69 | boost::optional<float> hdop; |
758 | 76 | boost::optional<Dop<tag::Vertical>> vdop; | 70 | boost::optional<float> vdop; |
759 | 77 | }; | 71 | }; |
760 | 78 | } | 72 | } |
761 | 79 | } | 73 | } |
762 | 80 | } | ||
763 | 81 | } | ||
764 | 82 | } | ||
765 | 83 | 74 | ||
767 | 84 | #endif // UBX_8_NMEA_GSA_H_ | 75 | #endif // LOCATION_NMEA_GSA_H_ |
768 | 85 | 76 | ||
769 | === modified file 'src/location/nmea/gsv.h' | |||
770 | --- src/location/providers/ubx/_8/nmea/gsv.h 2016-10-10 09:15:40 +0000 | |||
771 | +++ src/location/nmea/gsv.h 2017-05-05 09:37:41 +0000 | |||
772 | @@ -12,10 +12,10 @@ | |||
773 | 12 | // | 12 | // |
774 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
775 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
778 | 15 | #ifndef UBX_8_NMEA_GSV_H_ | 15 | #ifndef LOCATION_NMEA_GSV_H_ |
779 | 16 | #define UBX_8_NMEA_GSV_H_ | 16 | #define LOCATION_NMEA_GSV_H_ |
780 | 17 | 17 | ||
782 | 18 | #include <location/providers/ubx/_8/nmea/talker.h> | 18 | #include <location/nmea/talker.h> |
783 | 19 | 19 | ||
784 | 20 | #include <boost/optional.hpp> | 20 | #include <boost/optional.hpp> |
785 | 21 | 21 | ||
786 | @@ -25,14 +25,9 @@ | |||
787 | 25 | 25 | ||
788 | 26 | namespace location | 26 | namespace location |
789 | 27 | { | 27 | { |
790 | 28 | namespace providers | ||
791 | 29 | { | ||
792 | 30 | namespace ubx | ||
793 | 31 | { | ||
794 | 32 | namespace _8 | ||
795 | 33 | { | ||
796 | 34 | namespace nmea | 28 | namespace nmea |
797 | 35 | { | 29 | { |
798 | 30 | |||
799 | 36 | /// @brief GNSS Satellites in View. | 31 | /// @brief GNSS Satellites in View. |
800 | 37 | /// | 32 | /// |
801 | 38 | /// The number of satellites in view, together with each SV ID, elevation | 33 | /// The number of satellites in view, together with each SV ID, elevation |
802 | @@ -57,10 +52,8 @@ | |||
803 | 57 | boost::optional<std::uint8_t> satellites_count; | 52 | boost::optional<std::uint8_t> satellites_count; |
804 | 58 | std::vector<Info> satellites_info; | 53 | std::vector<Info> satellites_info; |
805 | 59 | }; | 54 | }; |
813 | 60 | } | 55 | |
814 | 61 | } | 56 | } |
815 | 62 | } | 57 | } |
816 | 63 | } | 58 | |
817 | 64 | } | 59 | #endif // LOCATION_NMEA_GSV_H_ |
811 | 65 | |||
812 | 66 | #endif // UBX_8_NMEA_GSV_H_ | ||
818 | 67 | 60 | ||
819 | === modified file 'src/location/nmea/latitude.h' | |||
820 | --- src/location/providers/ubx/_8/nmea/latitude.h 2016-10-10 09:15:40 +0000 | |||
821 | +++ src/location/nmea/latitude.h 2017-05-05 09:37:41 +0000 | |||
822 | @@ -12,31 +12,24 @@ | |||
823 | 12 | // | 12 | // |
824 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
825 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
828 | 15 | #ifndef UBX_8_NMEA_LATITUDE_H_ | 15 | #ifndef LOCATION_NMEA_LATITUDE_H_ |
829 | 16 | #define UBX_8_NMEA_LATITUDE_H_ | 16 | #define LOCATION_NMEA_LATITUDE_H_ |
830 | 17 | 17 | ||
831 | 18 | #include <cstdint> | 18 | #include <cstdint> |
832 | 19 | 19 | ||
833 | 20 | namespace location | 20 | namespace location |
834 | 21 | { | 21 | { |
835 | 22 | namespace providers | ||
836 | 23 | { | ||
837 | 24 | namespace ubx | ||
838 | 25 | { | ||
839 | 26 | namespace _8 | ||
840 | 27 | { | ||
841 | 28 | namespace nmea | 22 | namespace nmea |
842 | 29 | { | 23 | { |
843 | 24 | |||
844 | 30 | /// @brief Latitude as defined in wgs84. | 25 | /// @brief Latitude as defined in wgs84. |
845 | 31 | struct Latitude | 26 | struct Latitude |
846 | 32 | { | 27 | { |
847 | 33 | std::uint32_t degrees; | 28 | std::uint32_t degrees; |
848 | 34 | double minutes; | 29 | double minutes; |
849 | 35 | }; | 30 | }; |
857 | 36 | } | 31 | |
858 | 37 | } | 32 | } |
859 | 38 | } | 33 | } |
860 | 39 | } | 34 | |
861 | 40 | } | 35 | #endif // LOCATION_NMEA_LATITUDE_H_ |
855 | 41 | |||
856 | 42 | #endif // UBX_8_NMEA_LATITUDE_H_ | ||
862 | 43 | 36 | ||
863 | === modified file 'src/location/nmea/longitude.h' | |||
864 | --- src/location/providers/ubx/_8/nmea/longitude.h 2016-10-10 09:15:40 +0000 | |||
865 | +++ src/location/nmea/longitude.h 2017-05-05 09:37:41 +0000 | |||
866 | @@ -12,31 +12,24 @@ | |||
867 | 12 | // | 12 | // |
868 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
869 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
872 | 15 | #ifndef UBX_8_NMEA_LONGITUDE_H_ | 15 | #ifndef LOCATION_NMEA_LONGITUDE_H_ |
873 | 16 | #define UBX_8_NMEA_LONGITUDE_H_ | 16 | #define LOCATION_NMEA_LONGITUDE_H_ |
874 | 17 | 17 | ||
875 | 18 | #include <cstdint> | 18 | #include <cstdint> |
876 | 19 | 19 | ||
877 | 20 | namespace location | 20 | namespace location |
878 | 21 | { | 21 | { |
879 | 22 | namespace providers | ||
880 | 23 | { | ||
881 | 24 | namespace ubx | ||
882 | 25 | { | ||
883 | 26 | namespace _8 | ||
884 | 27 | { | ||
885 | 28 | namespace nmea | 22 | namespace nmea |
886 | 29 | { | 23 | { |
887 | 24 | |||
888 | 30 | /// @brief Longitude as defined in wgs84. | 25 | /// @brief Longitude as defined in wgs84. |
889 | 31 | struct Longitude | 26 | struct Longitude |
890 | 32 | { | 27 | { |
891 | 33 | std::uint32_t degrees; | 28 | std::uint32_t degrees; |
892 | 34 | double minutes; | 29 | double minutes; |
893 | 35 | }; | 30 | }; |
901 | 36 | } | 31 | |
902 | 37 | } | 32 | } |
903 | 38 | } | 33 | } |
904 | 39 | } | 34 | |
905 | 40 | } | 35 | #endif // LOCATION_NMEA_LONGITUDE_H_ |
899 | 41 | |||
900 | 42 | #endif // UBX_8_NMEA_LONGITUDE_H_ | ||
906 | 43 | 36 | ||
907 | === modified file 'src/location/nmea/mode.h' | |||
908 | --- src/location/providers/ubx/_8/nmea/mode.h 2016-10-10 09:15:40 +0000 | |||
909 | +++ src/location/nmea/mode.h 2017-05-05 09:37:41 +0000 | |||
910 | @@ -12,19 +12,14 @@ | |||
911 | 12 | // | 12 | // |
912 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
913 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
916 | 15 | #ifndef UBX_8_NMEA_MODE_H_ | 15 | #ifndef LOCATION_NMEA_MODE_H_ |
917 | 16 | #define UBX_8_NMEA_MODE_H_ | 16 | #define LOCATION_NMEA_MODE_H_ |
918 | 17 | 17 | ||
919 | 18 | namespace location | 18 | namespace location |
920 | 19 | { | 19 | { |
921 | 20 | namespace providers | ||
922 | 21 | { | ||
923 | 22 | namespace ubx | ||
924 | 23 | { | ||
925 | 24 | namespace _8 | ||
926 | 25 | { | ||
927 | 26 | namespace nmea | 20 | namespace nmea |
928 | 27 | { | 21 | { |
929 | 22 | |||
930 | 28 | /// @brief Mode enumerates all known NMEA positioning modes. | 23 | /// @brief Mode enumerates all known NMEA positioning modes. |
931 | 29 | enum class Mode | 24 | enum class Mode |
932 | 30 | { | 25 | { |
933 | @@ -35,10 +30,8 @@ | |||
934 | 35 | simulator_mode = 'S', | 30 | simulator_mode = 'S', |
935 | 36 | data_not_valid = 'N' | 31 | data_not_valid = 'N' |
936 | 37 | }; | 32 | }; |
944 | 38 | } | 33 | |
945 | 39 | } | 34 | } |
946 | 40 | } | 35 | } |
947 | 41 | } | 36 | |
948 | 42 | } | 37 | #endif // LOCATION_NMEA_MODE_H_ |
942 | 43 | |||
943 | 44 | #endif // UBX_8_NMEA_MODE_H_ | ||
949 | 45 | 38 | ||
950 | === modified file 'src/location/nmea/rmc.h' | |||
951 | --- src/location/providers/ubx/_8/nmea/rmc.h 2016-10-10 09:15:40 +0000 | |||
952 | +++ src/location/nmea/rmc.h 2017-05-05 09:37:41 +0000 | |||
953 | @@ -12,17 +12,17 @@ | |||
954 | 12 | // | 12 | // |
955 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
956 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
959 | 15 | #ifndef UBX_8_NMEA_RMC_H_ | 15 | #ifndef LOCATION_NMEA_RMC_H_ |
960 | 16 | #define UBX_8_NMEA_RMC_H_ | 16 | #define LOCATION_NMEA_RMC_H_ |
961 | 17 | 17 | ||
970 | 18 | #include <location/providers/ubx/_8/nmea/cardinal_direction.h> | 18 | #include <location/nmea/cardinal_direction.h> |
971 | 19 | #include <location/providers/ubx/_8/nmea/date.h> | 19 | #include <location/nmea/date.h> |
972 | 20 | #include <location/providers/ubx/_8/nmea/latitude.h> | 20 | #include <location/nmea/latitude.h> |
973 | 21 | #include <location/providers/ubx/_8/nmea/longitude.h> | 21 | #include <location/nmea/longitude.h> |
974 | 22 | #include <location/providers/ubx/_8/nmea/mode.h> | 22 | #include <location/nmea/mode.h> |
975 | 23 | #include <location/providers/ubx/_8/nmea/status.h> | 23 | #include <location/nmea/status.h> |
976 | 24 | #include <location/providers/ubx/_8/nmea/talker.h> | 24 | #include <location/nmea/talker.h> |
977 | 25 | #include <location/providers/ubx/_8/nmea/utc.h> | 25 | #include <location/nmea/utc.h> |
978 | 26 | 26 | ||
979 | 27 | #include <boost/optional.hpp> | 27 | #include <boost/optional.hpp> |
980 | 28 | 28 | ||
981 | @@ -32,14 +32,9 @@ | |||
982 | 32 | 32 | ||
983 | 33 | namespace location | 33 | namespace location |
984 | 34 | { | 34 | { |
985 | 35 | namespace providers | ||
986 | 36 | { | ||
987 | 37 | namespace ubx | ||
988 | 38 | { | ||
989 | 39 | namespace _8 | ||
990 | 40 | { | ||
991 | 41 | namespace nmea | 35 | namespace nmea |
992 | 42 | { | 36 | { |
993 | 37 | |||
994 | 43 | /// @brief Recommended Minimum data. | 38 | /// @brief Recommended Minimum data. |
995 | 44 | /// | 39 | /// |
996 | 45 | /// The recommended minimum sentence defined by NMEA for GNSS system data. | 40 | /// The recommended minimum sentence defined by NMEA for GNSS system data. |
997 | @@ -59,10 +54,8 @@ | |||
998 | 59 | boost::optional<CardinalDirection> cardinal_direction; | 54 | boost::optional<CardinalDirection> cardinal_direction; |
999 | 60 | boost::optional<Mode> mode; | 55 | boost::optional<Mode> mode; |
1000 | 61 | }; | 56 | }; |
1008 | 62 | } | 57 | |
1009 | 63 | } | 58 | } |
1010 | 64 | } | 59 | } |
1011 | 65 | } | 60 | |
1012 | 66 | } | 61 | #endif // LOCATION_NMEA_RMC_H_ |
1006 | 67 | |||
1007 | 68 | #endif // UBX_8_NMEA_RMC_H_ | ||
1013 | 69 | 62 | ||
1014 | === modified file 'src/location/nmea/scanner.cpp' | |||
1015 | --- src/location/providers/ubx/_8/nmea/scanner.cpp 2017-03-23 12:32:38 +0000 | |||
1016 | +++ src/location/nmea/scanner.cpp 2017-05-05 09:37:41 +0000 | |||
1017 | @@ -13,11 +13,11 @@ | |||
1018 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1019 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1020 | 15 | 15 | ||
1022 | 16 | #include <location/providers/ubx/_8/nmea/scanner.h> | 16 | #include <location/nmea/scanner.h> |
1023 | 17 | 17 | ||
1024 | 18 | #include <stdexcept> | 18 | #include <stdexcept> |
1025 | 19 | 19 | ||
1027 | 20 | namespace nmea = location::providers::ubx::_8::nmea; | 20 | namespace nmea = location::nmea; |
1028 | 21 | 21 | ||
1029 | 22 | nmea::Scanner::Expect nmea::Scanner::update(char c) { | 22 | nmea::Scanner::Expect nmea::Scanner::update(char c) { |
1030 | 23 | switch (state) { | 23 | switch (state) { |
1031 | 24 | 24 | ||
1032 | === modified file 'src/location/nmea/scanner.h' | |||
1033 | --- src/location/providers/ubx/_8/nmea/scanner.h 2016-10-10 09:15:40 +0000 | |||
1034 | +++ src/location/nmea/scanner.h 2017-05-05 09:37:41 +0000 | |||
1035 | @@ -12,22 +12,17 @@ | |||
1036 | 12 | // | 12 | // |
1037 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1038 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1041 | 15 | #ifndef UBX_8_NMEA_SCANNER_H_ | 15 | #ifndef LOCATION_NMEA_SCANNER_H_ |
1042 | 16 | #define UBX_8_NMEA_SCANNER_H_ | 16 | #define LOCATION_NMEA_SCANNER_H_ |
1043 | 17 | 17 | ||
1044 | 18 | #include <sstream> | 18 | #include <sstream> |
1045 | 19 | #include <string> | 19 | #include <string> |
1046 | 20 | 20 | ||
1047 | 21 | namespace location | 21 | namespace location |
1048 | 22 | { | 22 | { |
1049 | 23 | namespace providers | ||
1050 | 24 | { | ||
1051 | 25 | namespace ubx | ||
1052 | 26 | { | ||
1053 | 27 | namespace _8 | ||
1054 | 28 | { | ||
1055 | 29 | namespace nmea | 23 | namespace nmea |
1056 | 30 | { | 24 | { |
1057 | 25 | |||
1058 | 31 | /// @brief Scanner inspects incoming characters and tries to identify beginning | 26 | /// @brief Scanner inspects incoming characters and tries to identify beginning |
1059 | 32 | /// and end of | 27 | /// and end of |
1060 | 33 | /// NMEA messages. | 28 | /// NMEA messages. |
1061 | @@ -58,10 +53,8 @@ | |||
1062 | 58 | Expect state{Expect::dollar}; ///< The state of the Scanner. | 53 | Expect state{Expect::dollar}; ///< The state of the Scanner. |
1063 | 59 | std::stringstream ss; ///< Buffer holding incomplete sentence data. | 54 | std::stringstream ss; ///< Buffer holding incomplete sentence data. |
1064 | 60 | }; | 55 | }; |
1072 | 61 | } | 56 | |
1073 | 62 | } | 57 | } |
1074 | 63 | } | 58 | } |
1075 | 64 | } | 59 | |
1076 | 65 | } | 60 | #endif // LOCATION_NMEA_SCANNER_H_ |
1070 | 66 | |||
1071 | 67 | #endif // UBX_8_NMEA_SCANNER_H_ | ||
1077 | 68 | 61 | ||
1078 | === modified file 'src/location/nmea/sentence.cpp' | |||
1079 | --- src/location/providers/ubx/_8/nmea/sentence.cpp 2016-10-10 09:15:40 +0000 | |||
1080 | +++ src/location/nmea/sentence.cpp 2017-05-05 09:37:41 +0000 | |||
1081 | @@ -13,12 +13,12 @@ | |||
1082 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1083 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1084 | 15 | 15 | ||
1087 | 16 | #include <location/providers/ubx/_8/nmea/generator.h> | 16 | #include <location/nmea/generator.h> |
1088 | 17 | #include <location/providers/ubx/_8/nmea/grammar.h> | 17 | #include <location/nmea/grammar.h> |
1089 | 18 | 18 | ||
1090 | 19 | #include <iterator> | 19 | #include <iterator> |
1091 | 20 | 20 | ||
1093 | 21 | namespace nmea = location::providers::ubx::_8::nmea; | 21 | namespace nmea = location::nmea; |
1094 | 22 | 22 | ||
1095 | 23 | namespace { | 23 | namespace { |
1096 | 24 | template <typename Iterator> | 24 | template <typename Iterator> |
1097 | 25 | 25 | ||
1098 | === modified file 'src/location/nmea/sentence.h' | |||
1099 | --- src/location/providers/ubx/_8/nmea/sentence.h 2016-10-10 09:15:40 +0000 | |||
1100 | +++ src/location/nmea/sentence.h 2017-05-05 09:37:41 +0000 | |||
1101 | @@ -12,16 +12,16 @@ | |||
1102 | 12 | // | 12 | // |
1103 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1104 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1107 | 15 | #ifndef UBX_8_NMEA_SENTENCE_H_ | 15 | #ifndef LOCATION_NMEA_SENTENCE_H_ |
1108 | 16 | #define UBX_8_NMEA_SENTENCE_H_ | 16 | #define LOCATION_NMEA_SENTENCE_H_ |
1109 | 17 | 17 | ||
1117 | 18 | #include <location/providers/ubx/_8/nmea/gga.h> | 18 | #include <location/nmea/gga.h> |
1118 | 19 | #include <location/providers/ubx/_8/nmea/gll.h> | 19 | #include <location/nmea/gll.h> |
1119 | 20 | #include <location/providers/ubx/_8/nmea/gsa.h> | 20 | #include <location/nmea/gsa.h> |
1120 | 21 | #include <location/providers/ubx/_8/nmea/gsv.h> | 21 | #include <location/nmea/gsv.h> |
1121 | 22 | #include <location/providers/ubx/_8/nmea/rmc.h> | 22 | #include <location/nmea/rmc.h> |
1122 | 23 | #include <location/providers/ubx/_8/nmea/txt.h> | 23 | #include <location/nmea/txt.h> |
1123 | 24 | #include <location/providers/ubx/_8/nmea/vtg.h> | 24 | #include <location/nmea/vtg.h> |
1124 | 25 | 25 | ||
1125 | 26 | #include <boost/variant.hpp> | 26 | #include <boost/variant.hpp> |
1126 | 27 | 27 | ||
1127 | @@ -29,12 +29,6 @@ | |||
1128 | 29 | 29 | ||
1129 | 30 | namespace location | 30 | namespace location |
1130 | 31 | { | 31 | { |
1131 | 32 | namespace providers | ||
1132 | 33 | { | ||
1133 | 34 | namespace ubx | ||
1134 | 35 | { | ||
1135 | 36 | namespace _8 | ||
1136 | 37 | { | ||
1137 | 38 | namespace nmea | 32 | namespace nmea |
1138 | 39 | { | 33 | { |
1139 | 40 | 34 | ||
1140 | @@ -47,10 +41,8 @@ | |||
1141 | 47 | std::string generate_sentence(const Sentence& sentence); | 41 | std::string generate_sentence(const Sentence& sentence); |
1142 | 48 | /// @brief operator<< inserts sentence into out. | 42 | /// @brief operator<< inserts sentence into out. |
1143 | 49 | std::ostream& operator<<(std::ostream& out, const Sentence& sentence); | 43 | std::ostream& operator<<(std::ostream& out, const Sentence& sentence); |
1151 | 50 | } | 44 | |
1152 | 51 | } | 45 | } |
1153 | 52 | } | 46 | } |
1154 | 53 | } | 47 | |
1155 | 54 | } | 48 | #endif // LOCATION_NMEA_SENTENCE_H_ |
1149 | 55 | |||
1150 | 56 | #endif // UBX_8_NMEA_SENTENCE_H_ | ||
1156 | 57 | 49 | ||
1157 | === modified file 'src/location/nmea/status.h' | |||
1158 | --- src/location/providers/ubx/_8/nmea/status.h 2016-10-10 09:15:40 +0000 | |||
1159 | +++ src/location/nmea/status.h 2017-05-05 09:37:41 +0000 | |||
1160 | @@ -12,29 +12,22 @@ | |||
1161 | 12 | // | 12 | // |
1162 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1163 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1166 | 15 | #ifndef UBX_8_NMEA_STATUS_H_ | 15 | #ifndef LOCATION_NMEA_STATUS_H_ |
1167 | 16 | #define UBX_8_NMEA_STATUS_H_ | 16 | #define LOCATION_NMEA_STATUS_H_ |
1168 | 17 | 17 | ||
1169 | 18 | namespace location | 18 | namespace location |
1170 | 19 | { | 19 | { |
1171 | 20 | namespace providers | ||
1172 | 21 | { | ||
1173 | 22 | namespace ubx | ||
1174 | 23 | { | ||
1175 | 24 | namespace _8 | ||
1176 | 25 | { | ||
1177 | 26 | namespace nmea | 20 | namespace nmea |
1178 | 27 | { | 21 | { |
1179 | 22 | |||
1180 | 28 | /// @brief Status enumerates all status codes known to NMEA messages. | 23 | /// @brief Status enumerates all status codes known to NMEA messages. |
1181 | 29 | enum class Status | 24 | enum class Status |
1182 | 30 | { | 25 | { |
1183 | 31 | valid = 'A', ///< The referenced data is valid. | 26 | valid = 'A', ///< The referenced data is valid. |
1184 | 32 | not_valid = 'V' ///< The reference data is missing and thus not valid. | 27 | not_valid = 'V' ///< The reference data is missing and thus not valid. |
1185 | 33 | }; | 28 | }; |
1193 | 34 | } | 29 | |
1194 | 35 | } | 30 | } |
1195 | 36 | } | 31 | } |
1196 | 37 | } | 32 | |
1197 | 38 | } | 33 | #endif // LOCATION_NMEA_STATUS_H_ |
1191 | 39 | |||
1192 | 40 | #endif // UBX_8_NMEA_STATUS_H_ | ||
1198 | 41 | 34 | ||
1199 | === modified file 'src/location/nmea/talker.h' | |||
1200 | --- src/location/providers/ubx/_8/nmea/talker.h 2017-03-09 09:42:25 +0000 | |||
1201 | +++ src/location/nmea/talker.h 2017-05-05 09:37:41 +0000 | |||
1202 | @@ -12,19 +12,14 @@ | |||
1203 | 12 | // | 12 | // |
1204 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1205 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1208 | 15 | #ifndef UBX_8_NMEA_TALKER_H_ | 15 | #ifndef LOCATION_NMEA_TALKER_H_ |
1209 | 16 | #define UBX_8_NMEA_TALKER_H_ | 16 | #define LOCATION_NMEA_TALKER_H_ |
1210 | 17 | 17 | ||
1211 | 18 | namespace location | 18 | namespace location |
1212 | 19 | { | 19 | { |
1213 | 20 | namespace providers | ||
1214 | 21 | { | ||
1215 | 22 | namespace ubx | ||
1216 | 23 | { | ||
1217 | 24 | namespace _8 | ||
1218 | 25 | { | ||
1219 | 26 | namespace nmea | 20 | namespace nmea |
1220 | 27 | { | 21 | { |
1221 | 22 | |||
1222 | 28 | /// @brief Talker enumerates well-known participants on an NMEA bus. | 23 | /// @brief Talker enumerates well-known participants on an NMEA bus. |
1223 | 29 | enum class Talker | 24 | enum class Talker |
1224 | 30 | { | 25 | { |
1225 | @@ -33,10 +28,8 @@ | |||
1226 | 33 | gn, ///< Global Navigation Satellite System (GNSS) | 28 | gn, ///< Global Navigation Satellite System (GNSS) |
1227 | 34 | gp ///< Global Positioning System (GPS) | 29 | gp ///< Global Positioning System (GPS) |
1228 | 35 | }; | 30 | }; |
1236 | 36 | } | 31 | |
1237 | 37 | } | 32 | } |
1238 | 38 | } | 33 | } |
1239 | 39 | } | 34 | |
1240 | 40 | } | 35 | #endif // LOCATION_NMEA_TALKER_H_ |
1234 | 41 | |||
1235 | 42 | #endif // UBX_8_NMEA_TALKER_H_ | ||
1241 | 43 | 36 | ||
1242 | === modified file 'src/location/nmea/txt.h' | |||
1243 | --- src/location/providers/ubx/_8/nmea/txt.h 2016-10-10 09:15:40 +0000 | |||
1244 | +++ src/location/nmea/txt.h 2017-05-05 09:37:41 +0000 | |||
1245 | @@ -12,10 +12,10 @@ | |||
1246 | 12 | // | 12 | // |
1247 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1248 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1251 | 15 | #ifndef UBX_8_NMEA_TXT_H_ | 15 | #ifndef LOCATION_NMEA_TXT_H_ |
1252 | 16 | #define UBX_8_NMEA_TXT_H_ | 16 | #define LOCATION_NMEA_TXT_H_ |
1253 | 17 | 17 | ||
1255 | 18 | #include <location/providers/ubx/_8/nmea/talker.h> | 18 | #include <location/nmea/talker.h> |
1256 | 19 | 19 | ||
1257 | 20 | #include <boost/optional.hpp> | 20 | #include <boost/optional.hpp> |
1258 | 21 | 21 | ||
1259 | @@ -25,14 +25,9 @@ | |||
1260 | 25 | 25 | ||
1261 | 26 | namespace location | 26 | namespace location |
1262 | 27 | { | 27 | { |
1263 | 28 | namespace providers | ||
1264 | 29 | { | ||
1265 | 30 | namespace ubx | ||
1266 | 31 | { | ||
1267 | 32 | namespace _8 | ||
1268 | 33 | { | ||
1269 | 34 | namespace nmea | 28 | namespace nmea |
1270 | 35 | { | 29 | { |
1271 | 30 | |||
1272 | 36 | /// @brief Text Transmission. | 31 | /// @brief Text Transmission. |
1273 | 37 | /// | 32 | /// |
1274 | 38 | /// This message outputs various information on the receiver, such as power-up | 33 | /// This message outputs various information on the receiver, such as power-up |
1275 | @@ -46,10 +41,8 @@ | |||
1276 | 46 | boost::optional<std::uint8_t> identifier; | 41 | boost::optional<std::uint8_t> identifier; |
1277 | 47 | boost::optional<std::string> message; | 42 | boost::optional<std::string> message; |
1278 | 48 | }; | 43 | }; |
1286 | 49 | } | 44 | |
1287 | 50 | } | 45 | } |
1288 | 51 | } | 46 | } |
1289 | 52 | } | 47 | |
1290 | 53 | } | 48 | #endif // LOCATION_NMEA_TXT_H_ |
1284 | 54 | |||
1285 | 55 | #endif // UBX_8_NMEA_TXT_H_ | ||
1291 | 56 | 49 | ||
1292 | === modified file 'src/location/nmea/utc.h' | |||
1293 | --- src/location/providers/ubx/_8/nmea/utc.h 2016-10-10 09:15:40 +0000 | |||
1294 | +++ src/location/nmea/utc.h 2017-05-05 09:37:41 +0000 | |||
1295 | @@ -12,21 +12,16 @@ | |||
1296 | 12 | // | 12 | // |
1297 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1298 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1301 | 15 | #ifndef UBX_8_NMEA_UTC_H_ | 15 | #ifndef LOCATION_NMEA_UTC_H_ |
1302 | 16 | #define UBX_8_NMEA_UTC_H_ | 16 | #define LOCATION_NMEA_UTC_H_ |
1303 | 17 | 17 | ||
1304 | 18 | #include <cstdint> | 18 | #include <cstdint> |
1305 | 19 | 19 | ||
1306 | 20 | namespace location | 20 | namespace location |
1307 | 21 | { | 21 | { |
1308 | 22 | namespace providers | ||
1309 | 23 | { | ||
1310 | 24 | namespace ubx | ||
1311 | 25 | { | ||
1312 | 26 | namespace _8 | ||
1313 | 27 | { | ||
1314 | 28 | namespace nmea | 22 | namespace nmea |
1315 | 29 | { | 23 | { |
1316 | 24 | |||
1317 | 30 | /// @brief Time in UTC. | 25 | /// @brief Time in UTC. |
1318 | 31 | struct Utc | 26 | struct Utc |
1319 | 32 | { | 27 | { |
1320 | @@ -34,10 +29,8 @@ | |||
1321 | 34 | std::uint8_t minutes; | 29 | std::uint8_t minutes; |
1322 | 35 | double seconds; | 30 | double seconds; |
1323 | 36 | }; | 31 | }; |
1331 | 37 | } | 32 | |
1332 | 38 | } | 33 | } |
1333 | 39 | } | 34 | } |
1334 | 40 | } | 35 | |
1335 | 41 | } | 36 | #endif // LOCATION_NMEA_UTC_H_ |
1329 | 42 | |||
1330 | 43 | #endif // UBX_8_NMEA_UTC_H_ | ||
1336 | 44 | 37 | ||
1337 | === modified file 'src/location/nmea/vtg.h' | |||
1338 | --- src/location/providers/ubx/_8/nmea/vtg.h 2016-10-10 09:15:40 +0000 | |||
1339 | +++ src/location/nmea/vtg.h 2017-05-05 09:37:41 +0000 | |||
1340 | @@ -12,11 +12,11 @@ | |||
1341 | 12 | // | 12 | // |
1342 | 13 | // You should have received a copy of the GNU Lesser General Public License | 13 | // You should have received a copy of the GNU Lesser General Public License |
1343 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
1346 | 15 | #ifndef UBX_8_NMEA_VTG_H_ | 15 | #ifndef LOCATION_NMEA_VTG_H_ |
1347 | 16 | #define UBX_8_NMEA_VTG_H_ | 16 | #define LOCATION_NMEA_VTG_H_ |
1348 | 17 | 17 | ||
1351 | 18 | #include <location/providers/ubx/_8/nmea/mode.h> | 18 | #include <location/nmea/mode.h> |
1352 | 19 | #include <location/providers/ubx/_8/nmea/talker.h> | 19 | #include <location/nmea/talker.h> |
1353 | 20 | 20 | ||
1354 | 21 | #include <boost/optional.hpp> | 21 | #include <boost/optional.hpp> |
1355 | 22 | 22 | ||
1356 | @@ -24,14 +24,9 @@ | |||
1357 | 24 | 24 | ||
1358 | 25 | namespace location | 25 | namespace location |
1359 | 26 | { | 26 | { |
1360 | 27 | namespace providers | ||
1361 | 28 | { | ||
1362 | 29 | namespace ubx | ||
1363 | 30 | { | ||
1364 | 31 | namespace _8 | ||
1365 | 32 | { | ||
1366 | 33 | namespace nmea | 27 | namespace nmea |
1367 | 34 | { | 28 | { |
1368 | 29 | |||
1369 | 35 | /// @brief Course over ground and Ground speed. | 30 | /// @brief Course over ground and Ground speed. |
1370 | 36 | /// | 31 | /// |
1371 | 37 | /// Velocity is given as Course over Ground (COG) and Speed over Ground (SOG). | 32 | /// Velocity is given as Course over Ground (COG) and Speed over Ground (SOG). |
1372 | @@ -44,10 +39,8 @@ | |||
1373 | 44 | boost::optional<float> sog_kmh; | 39 | boost::optional<float> sog_kmh; |
1374 | 45 | boost::optional<Mode> mode; | 40 | boost::optional<Mode> mode; |
1375 | 46 | }; | 41 | }; |
1383 | 47 | } | 42 | |
1384 | 48 | } | 43 | } |
1385 | 49 | } | 44 | } |
1386 | 50 | } | 45 | |
1387 | 51 | } | 46 | #endif // LOCATION_NMEA_VTG_H_ |
1381 | 52 | |||
1382 | 53 | #endif // UBX_8_NMEA_VTG_H_ | ||
1388 | 54 | 47 | ||
1389 | === modified file 'src/location/providers/CMakeLists.txt' | |||
1390 | --- src/location/providers/CMakeLists.txt 2017-03-04 21:43:23 +0000 | |||
1391 | +++ src/location/providers/CMakeLists.txt 2017-05-05 09:37:41 +0000 | |||
1392 | @@ -3,6 +3,7 @@ | |||
1393 | 3 | add_subdirectory(mls) | 3 | add_subdirectory(mls) |
1394 | 4 | # add_subdirectory(remote) | 4 | # add_subdirectory(remote) |
1395 | 5 | add_subdirectory(gps) | 5 | add_subdirectory(gps) |
1396 | 6 | add_subdirectory(sirf) | ||
1397 | 6 | add_subdirectory(ubx) | 7 | add_subdirectory(ubx) |
1398 | 7 | 8 | ||
1399 | 8 | set( | 9 | set( |
1400 | 9 | 10 | ||
1401 | === modified file 'src/location/providers/config.cpp' | |||
1402 | --- src/location/providers/config.cpp 2016-10-10 09:15:40 +0000 | |||
1403 | +++ src/location/providers/config.cpp 2017-05-05 09:37:41 +0000 | |||
1404 | @@ -20,6 +20,7 @@ | |||
1405 | 20 | 20 | ||
1406 | 21 | #include "dummy/provider.h" | 21 | #include "dummy/provider.h" |
1407 | 22 | #include "mls/provider.h" | 22 | #include "mls/provider.h" |
1408 | 23 | #include "sirf/provider.h" | ||
1409 | 23 | #include "ubx/provider.h" | 24 | #include "ubx/provider.h" |
1410 | 24 | 25 | ||
1411 | 25 | #include <map> | 26 | #include <map> |
1412 | @@ -47,6 +48,12 @@ | |||
1413 | 47 | location::providers::mls::Provider::create_instance | 48 | location::providers::mls::Provider::create_instance |
1414 | 48 | }; | 49 | }; |
1415 | 49 | 50 | ||
1416 | 51 | static FactoryInjector sirf_injector | ||
1417 | 52 | { | ||
1418 | 53 | "sirf::Provider", | ||
1419 | 54 | location::providers::sirf::Provider::create_instance | ||
1420 | 55 | }; | ||
1421 | 56 | |||
1422 | 50 | static FactoryInjector ubx_injector | 57 | static FactoryInjector ubx_injector |
1423 | 51 | { | 58 | { |
1424 | 52 | "ubx::Provider", | 59 | "ubx::Provider", |
1425 | 53 | 60 | ||
1426 | === added directory 'src/location/providers/sirf' | |||
1427 | === added file 'src/location/providers/sirf/CMakeLists.txt' | |||
1428 | --- src/location/providers/sirf/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
1429 | +++ src/location/providers/sirf/CMakeLists.txt 2017-05-05 09:37:41 +0000 | |||
1430 | @@ -0,0 +1,33 @@ | |||
1431 | 1 | file(GLOB_RECURSE SIRF_HEADERS*.h) | ||
1432 | 2 | |||
1433 | 3 | add_library( | ||
1434 | 4 | sirf | ||
1435 | 5 | |||
1436 | 6 | ${SIRF_HEADERS} | ||
1437 | 7 | |||
1438 | 8 | bits.h | ||
1439 | 9 | |||
1440 | 10 | checksum.h | ||
1441 | 11 | checksum.cpp | ||
1442 | 12 | reader.h | ||
1443 | 13 | reader.cpp | ||
1444 | 14 | receiver.h | ||
1445 | 15 | receiver.cpp | ||
1446 | 16 | scanner.h | ||
1447 | 17 | scanner.cpp | ||
1448 | 18 | serial_port_receiver.h | ||
1449 | 19 | serial_port_receiver.cpp | ||
1450 | 20 | writer.h | ||
1451 | 21 | writer.cpp | ||
1452 | 22 | |||
1453 | 23 | provider.h provider.cpp) | ||
1454 | 24 | |||
1455 | 25 | target_link_libraries( | ||
1456 | 26 | sirf | ||
1457 | 27 | |||
1458 | 28 | nmea) | ||
1459 | 29 | |||
1460 | 30 | set( | ||
1461 | 31 | ENABLED_PROVIDER_TARGETS | ||
1462 | 32 | ${ENABLED_PROVIDER_TARGETS} sirf | ||
1463 | 33 | PARENT_SCOPE) | ||
1464 | 0 | 34 | ||
1465 | === added file 'src/location/providers/sirf/bits.h' | |||
1466 | --- src/location/providers/sirf/bits.h 1970-01-01 00:00:00 +0000 | |||
1467 | +++ src/location/providers/sirf/bits.h 2017-05-05 09:37:41 +0000 | |||
1468 | @@ -0,0 +1,49 @@ | |||
1469 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
1470 | 2 | // | ||
1471 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1472 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1473 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1474 | 6 | // (at your option) any later version. | ||
1475 | 7 | // | ||
1476 | 8 | // This program is distributed in the hope that it will be useful, | ||
1477 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1478 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1479 | 11 | // GNU General Public License for more details. | ||
1480 | 12 | // | ||
1481 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1482 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1483 | 15 | |||
1484 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_BITS_H_ | ||
1485 | 17 | #define LOCATION_PROVIDERS_SIRF_BITS_H_ | ||
1486 | 18 | |||
1487 | 19 | #include <cstdint> | ||
1488 | 20 | |||
1489 | 21 | namespace location | ||
1490 | 22 | { | ||
1491 | 23 | namespace providers | ||
1492 | 24 | { | ||
1493 | 25 | namespace sirf | ||
1494 | 26 | { | ||
1495 | 27 | namespace bits | ||
1496 | 28 | { | ||
1497 | 29 | |||
1498 | 30 | template<std::size_t begin, std::size_t end, typename T, typename U> | ||
1499 | 31 | void set(T& bitfield, U value) | ||
1500 | 32 | { | ||
1501 | 33 | static_assert(begin < end, "begin >= end"); | ||
1502 | 34 | bitfield |= ((value & ((1 << (end - begin))-1)) << begin); | ||
1503 | 35 | } | ||
1504 | 36 | |||
1505 | 37 | template<std::size_t begin, std::size_t end, typename T, typename U = T> | ||
1506 | 38 | U get(const T& bitfield) | ||
1507 | 39 | { | ||
1508 | 40 | static_assert(begin < end, "begin >= end"); | ||
1509 | 41 | return (bitfield >> begin) & ((1 << (end - begin)) - 1); | ||
1510 | 42 | } | ||
1511 | 43 | |||
1512 | 44 | } // namespace bits | ||
1513 | 45 | } // namespace sirf | ||
1514 | 46 | } // namespace providers | ||
1515 | 47 | } // namespace location | ||
1516 | 48 | |||
1517 | 49 | #endif // LOCATION_PROVIDERS_SIRF_BITS_H_ | ||
1518 | 0 | 50 | ||
1519 | === added file 'src/location/providers/sirf/checksum.cpp' | |||
1520 | --- src/location/providers/sirf/checksum.cpp 1970-01-01 00:00:00 +0000 | |||
1521 | +++ src/location/providers/sirf/checksum.cpp 2017-05-05 09:37:41 +0000 | |||
1522 | @@ -0,0 +1,28 @@ | |||
1523 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
1524 | 2 | // | ||
1525 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1526 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1527 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1528 | 6 | // (at your option) any later version. | ||
1529 | 7 | // | ||
1530 | 8 | // This program is distributed in the hope that it will be useful, | ||
1531 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1532 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1533 | 11 | // GNU General Public License for more details. | ||
1534 | 12 | // | ||
1535 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1536 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1537 | 15 | |||
1538 | 16 | #include <location/providers/sirf/checksum.h> | ||
1539 | 17 | |||
1540 | 18 | namespace sirf = location::providers::sirf; | ||
1541 | 19 | |||
1542 | 20 | void sirf::Checksum::operator()(std::uint8_t byte) | ||
1543 | 21 | { | ||
1544 | 22 | checksum += byte; | ||
1545 | 23 | } | ||
1546 | 24 | |||
1547 | 25 | std::uint16_t sirf::Checksum::operator()() const | ||
1548 | 26 | { | ||
1549 | 27 | return checksum; | ||
1550 | 28 | } | ||
1551 | 0 | 29 | ||
1552 | === added file 'src/location/providers/sirf/checksum.h' | |||
1553 | --- src/location/providers/sirf/checksum.h 1970-01-01 00:00:00 +0000 | |||
1554 | +++ src/location/providers/sirf/checksum.h 2017-05-05 09:37:41 +0000 | |||
1555 | @@ -0,0 +1,42 @@ | |||
1556 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
1557 | 2 | // | ||
1558 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1559 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1560 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1561 | 6 | // (at your option) any later version. | ||
1562 | 7 | // | ||
1563 | 8 | // This program is distributed in the hope that it will be useful, | ||
1564 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1565 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1566 | 11 | // GNU General Public License for more details. | ||
1567 | 12 | // | ||
1568 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1569 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1570 | 15 | |||
1571 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_CHECKSUM_H_ | ||
1572 | 17 | #define LOCATION_PROVIDERS_SIRF_CHECKSUM_H_ | ||
1573 | 18 | |||
1574 | 19 | #include <cstdint> | ||
1575 | 20 | |||
1576 | 21 | namespace location | ||
1577 | 22 | { | ||
1578 | 23 | namespace providers | ||
1579 | 24 | { | ||
1580 | 25 | namespace sirf | ||
1581 | 26 | { | ||
1582 | 27 | |||
1583 | 28 | class Checksum | ||
1584 | 29 | { | ||
1585 | 30 | public: | ||
1586 | 31 | void operator()(std::uint8_t byte); | ||
1587 | 32 | std::uint16_t operator()() const; | ||
1588 | 33 | |||
1589 | 34 | private: | ||
1590 | 35 | std::uint16_t checksum{0}; | ||
1591 | 36 | }; | ||
1592 | 37 | |||
1593 | 38 | } // namespace sirf | ||
1594 | 39 | } // namespace providers | ||
1595 | 40 | } // namepsace location | ||
1596 | 41 | |||
1597 | 42 | #endif // LOCATION_PROVIDERS_SIRF_CHECKSUM_H_ | ||
1598 | 0 | 43 | ||
1599 | === added file 'src/location/providers/sirf/codec.h' | |||
1600 | --- src/location/providers/sirf/codec.h 1970-01-01 00:00:00 +0000 | |||
1601 | +++ src/location/providers/sirf/codec.h 2017-05-05 09:37:41 +0000 | |||
1602 | @@ -0,0 +1,81 @@ | |||
1603 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
1604 | 2 | // | ||
1605 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1606 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1607 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1608 | 6 | // (at your option) any later version. | ||
1609 | 7 | // | ||
1610 | 8 | // This program is distributed in the hope that it will be useful, | ||
1611 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1612 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1613 | 11 | // GNU General Public License for more details. | ||
1614 | 12 | // | ||
1615 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1616 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1617 | 15 | |||
1618 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_CODEC_H_ | ||
1619 | 17 | #define LOCATION_PROVIDERS_SIRF_CODEC_H_ | ||
1620 | 18 | |||
1621 | 19 | #include <location/providers/sirf/checksum.h> | ||
1622 | 20 | #include <location/providers/sirf/magic.h> | ||
1623 | 21 | #include <location/providers/sirf/reader.h> | ||
1624 | 22 | #include <location/providers/sirf/writer.h> | ||
1625 | 23 | |||
1626 | 24 | #include <algorithm> | ||
1627 | 25 | #include <cstdint> | ||
1628 | 26 | #include <iostream> | ||
1629 | 27 | #include <vector> | ||
1630 | 28 | |||
1631 | 29 | namespace location | ||
1632 | 30 | { | ||
1633 | 31 | namespace providers | ||
1634 | 32 | { | ||
1635 | 33 | namespace sirf | ||
1636 | 34 | { | ||
1637 | 35 | |||
1638 | 36 | template<typename T> | ||
1639 | 37 | inline T decode_message(const std::vector<std::uint8_t>& payload) | ||
1640 | 38 | { | ||
1641 | 39 | T result; | ||
1642 | 40 | Reader reader{payload.begin(), payload.end()}; | ||
1643 | 41 | result.read(reader); | ||
1644 | 42 | |||
1645 | 43 | return result; | ||
1646 | 44 | } | ||
1647 | 45 | |||
1648 | 46 | template<typename T> | ||
1649 | 47 | inline std::vector<std::uint8_t> encode_message(const T& message) | ||
1650 | 48 | { | ||
1651 | 49 | auto msg_size = message.size(); | ||
1652 | 50 | |||
1653 | 51 | std::uint16_t size = | ||
1654 | 52 | sizeof(std::uint8_t) + sizeof(std::uint8_t) + | ||
1655 | 53 | sizeof(std::uint16_t) + | ||
1656 | 54 | msg_size + | ||
1657 | 55 | sizeof(std::uint16_t) + | ||
1658 | 56 | sizeof(std::uint8_t) + sizeof(std::uint8_t); | ||
1659 | 57 | |||
1660 | 58 | std::vector<std::uint8_t> result(size, 0); | ||
1661 | 59 | |||
1662 | 60 | Writer writer{result.begin(), result.end()}; | ||
1663 | 61 | writer.write_unsigned_char(begin::sync_char_1); | ||
1664 | 62 | writer.write_unsigned_char(begin::sync_char_2); | ||
1665 | 63 | writer.write_unsigned_short(msg_size); | ||
1666 | 64 | |||
1667 | 65 | Writer payload = writer.slice(msg_size); | ||
1668 | 66 | message.write(payload); | ||
1669 | 67 | |||
1670 | 68 | auto checksum = std::for_each(result.begin() + 4, result.end() - 4, Checksum{}); | ||
1671 | 69 | |||
1672 | 70 | writer.write_unsigned_short(checksum()); | ||
1673 | 71 | writer.write_unsigned_char(end::sync_char_1); | ||
1674 | 72 | writer.write_unsigned_char(end::sync_char_2); | ||
1675 | 73 | |||
1676 | 74 | return result; | ||
1677 | 75 | } | ||
1678 | 76 | |||
1679 | 77 | } // namespace sirf | ||
1680 | 78 | } // namespace providers | ||
1681 | 79 | } // namespace location | ||
1682 | 80 | |||
1683 | 81 | #endif // LOCATION_PROVIDERS_SIRF_CODEC_H_ | ||
1684 | 0 | 82 | ||
1685 | === added file 'src/location/providers/sirf/dop.h' | |||
1686 | --- src/location/providers/sirf/dop.h 1970-01-01 00:00:00 +0000 | |||
1687 | +++ src/location/providers/sirf/dop.h 2017-05-05 09:37:41 +0000 | |||
1688 | @@ -0,0 +1,64 @@ | |||
1689 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
1690 | 2 | // | ||
1691 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1692 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1693 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1694 | 6 | // (at your option) any later version. | ||
1695 | 7 | // | ||
1696 | 8 | // This program is distributed in the hope that it will be useful, | ||
1697 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1698 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1699 | 11 | // GNU General Public License for more details. | ||
1700 | 12 | // | ||
1701 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1702 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1703 | 15 | #ifndef LOCATION_PROVIDERS_SIRF_DOP_H_ | ||
1704 | 16 | #define LOCATION_PROVIDERS_SIRF_DOP_H_ | ||
1705 | 17 | |||
1706 | 18 | namespace location | ||
1707 | 19 | { | ||
1708 | 20 | namespace providers | ||
1709 | 21 | { | ||
1710 | 22 | namespace sirf | ||
1711 | 23 | { | ||
1712 | 24 | namespace tag | ||
1713 | 25 | { | ||
1714 | 26 | |||
1715 | 27 | struct Horizontal | ||
1716 | 28 | { | ||
1717 | 29 | }; | ||
1718 | 30 | struct Positional | ||
1719 | 31 | { | ||
1720 | 32 | }; | ||
1721 | 33 | struct Vertical | ||
1722 | 34 | { | ||
1723 | 35 | }; | ||
1724 | 36 | |||
1725 | 37 | } // namespace tag | ||
1726 | 38 | |||
1727 | 39 | template <typename T> | ||
1728 | 40 | struct DillusionOfPrecision | ||
1729 | 41 | { | ||
1730 | 42 | explicit DillusionOfPrecision(float value = -1) : value{value} {} | ||
1731 | 43 | |||
1732 | 44 | DillusionOfPrecision(const DillusionOfPrecision<T>& rhs) : value{rhs.value} {} | ||
1733 | 45 | |||
1734 | 46 | DillusionOfPrecision& operator=(const DillusionOfPrecision<T>& rhs) | ||
1735 | 47 | { | ||
1736 | 48 | value = rhs.value; | ||
1737 | 49 | return *this; | ||
1738 | 50 | } | ||
1739 | 51 | |||
1740 | 52 | operator float() const { return value; } | ||
1741 | 53 | |||
1742 | 54 | float value; | ||
1743 | 55 | }; | ||
1744 | 56 | |||
1745 | 57 | template <typename T> | ||
1746 | 58 | using Dop = DillusionOfPrecision<T>; | ||
1747 | 59 | |||
1748 | 60 | } // namespace sirf | ||
1749 | 61 | } // namespace providers | ||
1750 | 62 | } // namespace location | ||
1751 | 63 | |||
1752 | 64 | #endif // LOCATION_PROVIDERS_SIRF_DOP_H_ | ||
1753 | 0 | 65 | ||
1754 | === added file 'src/location/providers/sirf/geodetic_navigation_data.h' | |||
1755 | --- src/location/providers/sirf/geodetic_navigation_data.h 1970-01-01 00:00:00 +0000 | |||
1756 | +++ src/location/providers/sirf/geodetic_navigation_data.h 2017-05-05 09:37:41 +0000 | |||
1757 | @@ -0,0 +1,213 @@ | |||
1758 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss@canonical.com> | ||
1759 | 2 | // | ||
1760 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1761 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1762 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1763 | 6 | // (at your option) any later version. | ||
1764 | 7 | // | ||
1765 | 8 | // This program is distributed in the hope that it will be useful, | ||
1766 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1767 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1768 | 11 | // GNU General Public License for more details. | ||
1769 | 12 | // | ||
1770 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1771 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1772 | 15 | |||
1773 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_GEODETIC_NAVIGATION_DATA_H_ | ||
1774 | 17 | #define LOCATION_PROVIDERS_SIRF_GEODETIC_NAVIGATION_DATA_H_ | ||
1775 | 18 | |||
1776 | 19 | #include <location/providers/sirf/reader.h> | ||
1777 | 20 | |||
1778 | 21 | #include <cstdint> | ||
1779 | 22 | #include <iostream> | ||
1780 | 23 | |||
1781 | 24 | namespace location | ||
1782 | 25 | { | ||
1783 | 26 | namespace providers | ||
1784 | 27 | { | ||
1785 | 28 | namespace sirf | ||
1786 | 29 | { | ||
1787 | 30 | |||
1788 | 31 | struct GeodeticNavigationData | ||
1789 | 32 | { | ||
1790 | 33 | enum NavValid | ||
1791 | 34 | { | ||
1792 | 35 | valid_navigation = 0, | ||
1793 | 36 | solution_not_overdetermined = 1 << 0, | ||
1794 | 37 | invalid_dr_sensor_data = 1 << 3, | ||
1795 | 38 | invalid_dr_calibration = 1 << 4, | ||
1796 | 39 | unavailable_dr_gps_calibration = 1 << 5, | ||
1797 | 40 | invalid_dr_position_fix = 1 << 6, | ||
1798 | 41 | invalid_heading = 1 << 7, | ||
1799 | 42 | no_tracker_data_available = 1 << 15 | ||
1800 | 43 | }; | ||
1801 | 44 | |||
1802 | 45 | enum NavType | ||
1803 | 46 | { | ||
1804 | 47 | no_navigation_fix = 0, | ||
1805 | 48 | one_sv_kf_solution = 1, | ||
1806 | 49 | two_sv_kf_solution = 2, | ||
1807 | 50 | three_sv_kf_solution = 3, | ||
1808 | 51 | four_sv_kf_solution = 4, | ||
1809 | 52 | two_dim_least_squares_solution = 5, | ||
1810 | 53 | three_dim_least_squares_solution = 6, | ||
1811 | 54 | dr_solution = 7, | ||
1812 | 55 | trickle_power_in_use = 1 << 3, | ||
1813 | 56 | altitude_hold_off = 0, | ||
1814 | 57 | altitude_hold_kf = 1, | ||
1815 | 58 | altitude_hold_user_input = 2, | ||
1816 | 59 | altitude_hold_user_input_always = 3, | ||
1817 | 60 | dop_limits_exceeded = 1 << 6, | ||
1818 | 61 | dgps_corrections_applied = 1 << 7, | ||
1819 | 62 | dr_solution_type_sensor = 1, | ||
1820 | 63 | dr_solution_type_velocity = 0, | ||
1821 | 64 | navigation_solution_overdetermined = 1 << 9, | ||
1822 | 65 | velocity_dr_timeout_exceeded = 1 << 10, | ||
1823 | 66 | fix_edited_by_mi_functions = 1 << 11, | ||
1824 | 67 | invalid_velocity = 1 << 12, | ||
1825 | 68 | altitude_hold_disabled = 1 << 13, | ||
1826 | 69 | |||
1827 | 70 | }; | ||
1828 | 71 | |||
1829 | 72 | static constexpr std::uint8_t id{0x29}; | ||
1830 | 73 | |||
1831 | 74 | std::size_t size() const | ||
1832 | 75 | { | ||
1833 | 76 | return 91; | ||
1834 | 77 | } | ||
1835 | 78 | |||
1836 | 79 | void read(Reader& reader) | ||
1837 | 80 | { | ||
1838 | 81 | nav_valid = reader.read_unsigned_short(); | ||
1839 | 82 | nav_type = reader.read_unsigned_short(); | ||
1840 | 83 | extended_week_number = reader.read_unsigned_short(); | ||
1841 | 84 | time_of_week = reader.read_unsigned_long(); | ||
1842 | 85 | utc.year = reader.read_unsigned_short(); | ||
1843 | 86 | utc.month = reader.read_unsigned_char(); | ||
1844 | 87 | utc.day = reader.read_unsigned_char(); | ||
1845 | 88 | utc.hour = reader.read_unsigned_char(); | ||
1846 | 89 | utc.minute = reader.read_unsigned_char(); | ||
1847 | 90 | utc.seconds = reader.read_unsigned_short(); | ||
1848 | 91 | satellite_id_list = reader.read_unsigned_long(); | ||
1849 | 92 | latitude = reader.read_signed_long() * 1e-7; | ||
1850 | 93 | longitude = reader.read_signed_long() * 1e-7; | ||
1851 | 94 | altitude.above_ellipsoid = reader.read_signed_long() * 1e-2; | ||
1852 | 95 | altitude.above_mean_sea_level = reader.read_signed_long() * 1e-2; | ||
1853 | 96 | map_datum = reader.read_signed_char(); | ||
1854 | 97 | over_ground.speed = reader.read_unsigned_short() * 1e-2; | ||
1855 | 98 | over_ground.course = reader.read_unsigned_short() * 1e-2; | ||
1856 | 99 | magnetic_variation = reader.read_signed_short(); | ||
1857 | 100 | climb_rate = reader.read_signed_short() * 1e-2; | ||
1858 | 101 | heading_rate = reader.read_signed_short() * 1e-2; | ||
1859 | 102 | error.horizontal_position = reader.read_unsigned_long() * 1e-2; | ||
1860 | 103 | error.vertical_position = reader.read_unsigned_long() * 1e-2; | ||
1861 | 104 | error.time = reader.read_unsigned_long() * 1e-2; | ||
1862 | 105 | error.horizontal_velocity = reader.read_unsigned_short() * 1e-2; | ||
1863 | 106 | clock.bias = reader.read_signed_long() * 1e-2; | ||
1864 | 107 | clock.bias_error = reader.read_unsigned_long() * 1e-2; | ||
1865 | 108 | clock.drift = reader.read_signed_long() * 1e-2; | ||
1866 | 109 | clock.drift_error = reader.read_unsigned_long() * 1e-2; | ||
1867 | 110 | distance_traveled = reader.read_unsigned_long(); | ||
1868 | 111 | distance_traveled_error = reader.read_unsigned_short(); | ||
1869 | 112 | error.heading = reader.read_unsigned_short() * 1e-2; | ||
1870 | 113 | svs_in_fix = reader.read_unsigned_char(); | ||
1871 | 114 | hdop = reader.read_unsigned_char() / 5.f; | ||
1872 | 115 | mode_info = reader.read_unsigned_char(); | ||
1873 | 116 | } | ||
1874 | 117 | |||
1875 | 118 | std::uint16_t nav_valid; | ||
1876 | 119 | std::uint16_t nav_type; | ||
1877 | 120 | std::uint16_t extended_week_number; | ||
1878 | 121 | std::uint32_t time_of_week; | ||
1879 | 122 | struct | ||
1880 | 123 | { | ||
1881 | 124 | std::uint16_t year; | ||
1882 | 125 | std::uint8_t month; | ||
1883 | 126 | std::uint8_t day; | ||
1884 | 127 | std::uint8_t hour; | ||
1885 | 128 | std::uint8_t minute; | ||
1886 | 129 | std::uint16_t seconds; | ||
1887 | 130 | } utc; | ||
1888 | 131 | std::uint32_t satellite_id_list; | ||
1889 | 132 | float latitude; | ||
1890 | 133 | float longitude; | ||
1891 | 134 | struct | ||
1892 | 135 | { | ||
1893 | 136 | float above_ellipsoid; | ||
1894 | 137 | float above_mean_sea_level; | ||
1895 | 138 | } altitude; | ||
1896 | 139 | std::int8_t map_datum; | ||
1897 | 140 | struct | ||
1898 | 141 | { | ||
1899 | 142 | std::uint16_t speed; | ||
1900 | 143 | std::uint16_t course; | ||
1901 | 144 | } over_ground; | ||
1902 | 145 | std::int16_t magnetic_variation; | ||
1903 | 146 | float climb_rate; | ||
1904 | 147 | float heading_rate; | ||
1905 | 148 | struct | ||
1906 | 149 | { | ||
1907 | 150 | float horizontal_position; | ||
1908 | 151 | float vertical_position; | ||
1909 | 152 | float time; | ||
1910 | 153 | float horizontal_velocity; | ||
1911 | 154 | float heading; | ||
1912 | 155 | } error; | ||
1913 | 156 | struct | ||
1914 | 157 | { | ||
1915 | 158 | float bias; | ||
1916 | 159 | float bias_error; | ||
1917 | 160 | float drift; | ||
1918 | 161 | float drift_error; | ||
1919 | 162 | } clock; | ||
1920 | 163 | std::uint32_t distance_traveled; | ||
1921 | 164 | std::uint32_t distance_traveled_error; | ||
1922 | 165 | std::uint8_t svs_in_fix; | ||
1923 | 166 | std::uint8_t hdop; | ||
1924 | 167 | std::uint8_t mode_info; | ||
1925 | 168 | }; | ||
1926 | 169 | |||
1927 | 170 | inline std::ostream& operator<<(std::ostream& out, const GeodeticNavigationData& gnd) | ||
1928 | 171 | { | ||
1929 | 172 | return out << "GeodeticNavigationData:" << std::endl | ||
1930 | 173 | << " nav-valid: " << gnd.nav_valid << std::endl | ||
1931 | 174 | << " nav-type: " << gnd.nav_type << std::endl | ||
1932 | 175 | << " extended-week-number: " << gnd.extended_week_number << std::endl | ||
1933 | 176 | << " time-of-week: " << gnd.time_of_week << std::endl | ||
1934 | 177 | << " utc.year: " << gnd.utc.year << std::endl | ||
1935 | 178 | << " utc.month: " << std::uint32_t(gnd.utc.month) << std::endl | ||
1936 | 179 | << " utc.day: " << std::uint32_t(gnd.utc.day) << std::endl | ||
1937 | 180 | << " utc.hour: " << std::uint32_t(gnd.utc.hour) << std::endl | ||
1938 | 181 | << " utc.minute: " << std::uint32_t(gnd.utc.minute) << std::endl | ||
1939 | 182 | << " utc.seconds: " << gnd.utc.seconds << std::endl | ||
1940 | 183 | << " satellite-id-list: " << gnd.satellite_id_list << std::endl | ||
1941 | 184 | << " latitude: " << gnd.latitude << std::endl | ||
1942 | 185 | << " longitude: " << gnd.longitude << std::endl | ||
1943 | 186 | << " altitude.above-ellipsoid: " << gnd.altitude.above_ellipsoid << std::endl | ||
1944 | 187 | << " altitude.above-msl: " << gnd.altitude.above_mean_sea_level << std::endl | ||
1945 | 188 | << " map-datum: " << std::int32_t(gnd.map_datum) << std::endl | ||
1946 | 189 | << " over-ground.speed: " << gnd.over_ground.speed << std::endl | ||
1947 | 190 | << " over-ground.course: " << gnd.over_ground.course << std::endl | ||
1948 | 191 | << " climb-rate: " << gnd.climb_rate << std::endl | ||
1949 | 192 | << " heading-rate: " << gnd.heading_rate << std::endl | ||
1950 | 193 | << " error.horizontal-position: " << gnd.error.horizontal_position << std::endl | ||
1951 | 194 | << " error.vertical-position: " << gnd.error.vertical_position << std::endl | ||
1952 | 195 | << " error.time: " << gnd.error.time << std::endl | ||
1953 | 196 | << " error.horizontal-velocity: " << gnd.error.horizontal_velocity << std::endl | ||
1954 | 197 | << " error.heading: " << gnd.error.heading << std::endl | ||
1955 | 198 | << " clock.bias: " << gnd.clock.bias << std::endl | ||
1956 | 199 | << " clock.bias-error: " << gnd.clock.bias_error << std::endl | ||
1957 | 200 | << " clock.drift: " << gnd.clock.drift << std::endl | ||
1958 | 201 | << " clock.drift-error: " << gnd.clock.drift_error << std::endl | ||
1959 | 202 | << " distance-traveled: " << gnd.distance_traveled << std::endl | ||
1960 | 203 | << " distance-traveled-error: " << gnd.distance_traveled_error << std::endl | ||
1961 | 204 | << " svs-in-fix: " << std::uint32_t(gnd.svs_in_fix) << std::endl | ||
1962 | 205 | << " hdop: " << std::uint32_t(gnd.hdop) << std::endl | ||
1963 | 206 | << " mode-info: " << std::uint32_t(gnd.mode_info); | ||
1964 | 207 | } | ||
1965 | 208 | |||
1966 | 209 | } // namespace sirf | ||
1967 | 210 | } // namespace providers | ||
1968 | 211 | } // namespace location | ||
1969 | 212 | |||
1970 | 213 | #endif // LOCATION_PROVIDERS_SIRF_GEODETIC_NAVIGATION_DATA_H_ | ||
1971 | 0 | 214 | ||
1972 | === added file 'src/location/providers/sirf/initialize_data_source.h' | |||
1973 | --- src/location/providers/sirf/initialize_data_source.h 1970-01-01 00:00:00 +0000 | |||
1974 | +++ src/location/providers/sirf/initialize_data_source.h 2017-05-05 09:37:41 +0000 | |||
1975 | @@ -0,0 +1,93 @@ | |||
1976 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss@canonical.com> | ||
1977 | 2 | // | ||
1978 | 3 | // This library is free software: you can redistribute it and/or modify | ||
1979 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
1980 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
1981 | 6 | // (at your option) any later version. | ||
1982 | 7 | // | ||
1983 | 8 | // This program is distributed in the hope that it will be useful, | ||
1984 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1985 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1986 | 11 | // GNU General Public License for more details. | ||
1987 | 12 | // | ||
1988 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
1989 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1990 | 15 | |||
1991 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_INITIALIZE_DATA_SOURCE_H_ | ||
1992 | 17 | #define LOCATION_PROVIDERS_SIRF_INITIALIZE_DATA_SOURCE_H_ | ||
1993 | 18 | |||
1994 | 19 | #include <location/providers/sirf/writer.h> | ||
1995 | 20 | |||
1996 | 21 | #include <cstdint> | ||
1997 | 22 | #include <iostream> | ||
1998 | 23 | |||
1999 | 24 | namespace location | ||
2000 | 25 | { | ||
2001 | 26 | namespace providers | ||
2002 | 27 | { | ||
2003 | 28 | namespace sirf | ||
2004 | 29 | { | ||
2005 | 30 | |||
2006 | 31 | struct InitializeDataSource | ||
2007 | 32 | { | ||
2008 | 33 | enum ResetConfiguration | ||
2009 | 34 | { | ||
2010 | 35 | data_valid = 1 << 0, | ||
2011 | 36 | clear_ephemeris_data = 1 << 1, | ||
2012 | 37 | clear_all_history = 1 << 2, | ||
2013 | 38 | factory_reset = 1 << 3, | ||
2014 | 39 | enable_nav_lib_data = 1 << 4, | ||
2015 | 40 | enable_debug_data = 1 << 5, | ||
2016 | 41 | rtc_is_not_precise = 1 << 6, | ||
2017 | 42 | reset = 1 << 7 | ||
2018 | 43 | }; | ||
2019 | 44 | |||
2020 | 45 | static constexpr std::uint8_t id{128}; | ||
2021 | 46 | static constexpr std::uint8_t max_number_channels{12}; | ||
2022 | 47 | |||
2023 | 48 | std::size_t size() const | ||
2024 | 49 | { | ||
2025 | 50 | return 25; | ||
2026 | 51 | } | ||
2027 | 52 | |||
2028 | 53 | void write(Writer& writer) const | ||
2029 | 54 | { | ||
2030 | 55 | writer.write_unsigned_char(id); | ||
2031 | 56 | writer.write_signed_long(ecef_x); | ||
2032 | 57 | writer.write_signed_long(ecef_y); | ||
2033 | 58 | writer.write_signed_long(ecef_z); | ||
2034 | 59 | writer.write_signed_long(clock_drift); | ||
2035 | 60 | writer.write_unsigned_long(ecef_x); | ||
2036 | 61 | writer.write_unsigned_short(week_number); | ||
2037 | 62 | writer.write_unsigned_char(channels); | ||
2038 | 63 | writer.write_unsigned_char(reset_configuration); | ||
2039 | 64 | } | ||
2040 | 65 | |||
2041 | 66 | std::int32_t ecef_x; | ||
2042 | 67 | std::int32_t ecef_y; | ||
2043 | 68 | std::int32_t ecef_z; | ||
2044 | 69 | std::int32_t clock_drift; | ||
2045 | 70 | std::uint32_t time_of_week; | ||
2046 | 71 | std::uint16_t week_number; | ||
2047 | 72 | std::uint8_t channels; | ||
2048 | 73 | std::uint8_t reset_configuration; | ||
2049 | 74 | }; | ||
2050 | 75 | |||
2051 | 76 | inline std::ostream& operator<<(std::ostream& out, const InitializeDataSource& ids) | ||
2052 | 77 | { | ||
2053 | 78 | return out << "InitializeDataSource:" << std::endl | ||
2054 | 79 | << " ecef-x: " << ids.ecef_x << std::endl | ||
2055 | 80 | << " ecef-y: " << ids.ecef_y << std::endl | ||
2056 | 81 | << " ecef-z: " << ids.ecef_z << std::endl | ||
2057 | 82 | << " clock-drift: " << ids.clock_drift << std::endl | ||
2058 | 83 | << " time-of-week: " << ids.time_of_week << std::endl | ||
2059 | 84 | << " week_number: " << ids.week_number << std::endl | ||
2060 | 85 | << " channels: " << std::uint32_t(ids.channels) << std::endl | ||
2061 | 86 | << " reset-config: " << std::uint32_t(ids.reset_configuration) << std::endl; | ||
2062 | 87 | } | ||
2063 | 88 | |||
2064 | 89 | } // namespace sirf | ||
2065 | 90 | } // namespace providers | ||
2066 | 91 | } // namespace location | ||
2067 | 92 | |||
2068 | 93 | #endif // LOCATION_PROVIDERS_SIRF_INITIALIZE_DATA_SOURCE_H_ | ||
2069 | 0 | 94 | ||
2070 | === added file 'src/location/providers/sirf/magic.h' | |||
2071 | --- src/location/providers/sirf/magic.h 1970-01-01 00:00:00 +0000 | |||
2072 | +++ src/location/providers/sirf/magic.h 2017-05-05 09:37:41 +0000 | |||
2073 | @@ -0,0 +1,43 @@ | |||
2074 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
2075 | 2 | // | ||
2076 | 3 | // This library is free software: you can redistribute it and/or modify | ||
2077 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
2078 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
2079 | 6 | // (at your option) any later version. | ||
2080 | 7 | // | ||
2081 | 8 | // This program is distributed in the hope that it will be useful, | ||
2082 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2083 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2084 | 11 | // GNU General Public License for more details. | ||
2085 | 12 | // | ||
2086 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
2087 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2088 | 15 | |||
2089 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_MAGIC_H_ | ||
2090 | 17 | #define LOCATION_PROVIDERS_SIRF_MAGIC_H_ | ||
2091 | 18 | |||
2092 | 19 | namespace location | ||
2093 | 20 | { | ||
2094 | 21 | namespace providers | ||
2095 | 22 | { | ||
2096 | 23 | namespace sirf | ||
2097 | 24 | { | ||
2098 | 25 | namespace begin | ||
2099 | 26 | { | ||
2100 | 27 | |||
2101 | 28 | constexpr const std::uint8_t sync_char_1{0xa0}; | ||
2102 | 29 | constexpr const std::uint8_t sync_char_2{0xa2}; | ||
2103 | 30 | |||
2104 | 31 | } // namespace begin | ||
2105 | 32 | namespace end | ||
2106 | 33 | { | ||
2107 | 34 | |||
2108 | 35 | constexpr const std::uint8_t sync_char_1{0xb0}; | ||
2109 | 36 | constexpr const std::uint8_t sync_char_2{0xb3}; | ||
2110 | 37 | |||
2111 | 38 | } // namespace end | ||
2112 | 39 | } // namespace sirf | ||
2113 | 40 | } // namespace providers | ||
2114 | 41 | } // namespace location | ||
2115 | 42 | |||
2116 | 43 | #endif // LOCATION_PROVIDERS_SIRF_MAGIC_H_ | ||
2117 | 0 | 44 | ||
2118 | === added file 'src/location/providers/sirf/message.h' | |||
2119 | --- src/location/providers/sirf/message.h 1970-01-01 00:00:00 +0000 | |||
2120 | +++ src/location/providers/sirf/message.h 2017-05-05 09:37:41 +0000 | |||
2121 | @@ -0,0 +1,53 @@ | |||
2122 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
2123 | 2 | // | ||
2124 | 3 | // This library is free software: you can redistribute it and/or modify | ||
2125 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
2126 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
2127 | 6 | // (at your option) any later version. | ||
2128 | 7 | // | ||
2129 | 8 | // This program is distributed in the hope that it will be useful, | ||
2130 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2131 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2132 | 11 | // GNU General Public License for more details. | ||
2133 | 12 | // | ||
2134 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
2135 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2136 | 15 | |||
2137 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_MESSAGE_H_ | ||
2138 | 17 | #define LOCATION_PROVIDERS_SIRF_MESSAGE_H_ | ||
2139 | 18 | |||
2140 | 19 | #include <location/providers/sirf/geodetic_navigation_data.h> | ||
2141 | 20 | #include <location/providers/sirf/initialize_data_source.h> | ||
2142 | 21 | #include <location/providers/sirf/set_protocol.h> | ||
2143 | 22 | |||
2144 | 23 | #include <boost/variant.hpp> | ||
2145 | 24 | |||
2146 | 25 | #include <iostream> | ||
2147 | 26 | |||
2148 | 27 | namespace location | ||
2149 | 28 | { | ||
2150 | 29 | namespace providers | ||
2151 | 30 | { | ||
2152 | 31 | namespace sirf | ||
2153 | 32 | { | ||
2154 | 33 | |||
2155 | 34 | struct Null {}; | ||
2156 | 35 | |||
2157 | 36 | using Message = boost::variant< | ||
2158 | 37 | Null, | ||
2159 | 38 | InitializeDataSource, | ||
2160 | 39 | GeodeticNavigationData, | ||
2161 | 40 | SetProtocol | ||
2162 | 41 | >; | ||
2163 | 42 | |||
2164 | 43 | inline std::ostream& operator<<(std::ostream& out, const Null&) | ||
2165 | 44 | { | ||
2166 | 45 | return out << "Uninterpreted sirf message"; | ||
2167 | 46 | } | ||
2168 | 47 | |||
2169 | 48 | |||
2170 | 49 | } // namespace sirf | ||
2171 | 50 | } // namespace providers | ||
2172 | 51 | } // namespace location | ||
2173 | 52 | |||
2174 | 53 | #endif // LOCATION_PROVIDERS_SIRF_MESSAGE_H_ | ||
2175 | 0 | 54 | ||
2176 | === added file 'src/location/providers/sirf/provider.cpp' | |||
2177 | --- src/location/providers/sirf/provider.cpp 1970-01-01 00:00:00 +0000 | |||
2178 | +++ src/location/providers/sirf/provider.cpp 2017-05-05 09:37:41 +0000 | |||
2179 | @@ -0,0 +1,353 @@ | |||
2180 | 1 | /* | ||
2181 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2182 | 3 | * | ||
2183 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2184 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
2185 | 6 | * as published by the Free Software Foundation. | ||
2186 | 7 | * | ||
2187 | 8 | * This program is distributed in the hope that it will be useful, | ||
2188 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2189 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2190 | 11 | * GNU Lesser General Public License for more details. | ||
2191 | 12 | * | ||
2192 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2193 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2194 | 15 | * | ||
2195 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | ||
2196 | 17 | */ | ||
2197 | 18 | |||
2198 | 19 | #include <location/providers/sirf/provider.h> | ||
2199 | 20 | |||
2200 | 21 | #include <location/logging.h> | ||
2201 | 22 | #include <location/runtime.h> | ||
2202 | 23 | #include <location/events/reference_position_updated.h> | ||
2203 | 24 | #include <location/glib/runtime.h> | ||
2204 | 25 | |||
2205 | 26 | #include <core/net/http/client.h> | ||
2206 | 27 | #include <core/posix/this_process.h> | ||
2207 | 28 | |||
2208 | 29 | #include <boost/lexical_cast.hpp> | ||
2209 | 30 | |||
2210 | 31 | #include <fstream> | ||
2211 | 32 | #include <iostream> | ||
2212 | 33 | #include <iterator> | ||
2213 | 34 | #include <thread> | ||
2214 | 35 | |||
2215 | 36 | namespace env = core::posix::this_process::env; | ||
2216 | 37 | namespace sirf = location::providers::sirf; | ||
2217 | 38 | |||
2218 | 39 | namespace | ||
2219 | 40 | { | ||
2220 | 41 | |||
2221 | 42 | struct SettingsHelper | ||
2222 | 43 | { | ||
2223 | 44 | template<typename T> | ||
2224 | 45 | static T get_value(std::string key, T&& default_value) | ||
2225 | 46 | { | ||
2226 | 47 | static const std::string snap_path = env::get("SNAP_DATA"); | ||
2227 | 48 | |||
2228 | 49 | boost::filesystem::path path{snap_path}; | ||
2229 | 50 | std::replace(key.begin(), key.end(), '.', '/'); | ||
2230 | 51 | path /= key; | ||
2231 | 52 | |||
2232 | 53 | LOG(INFO) << "Reading setting from " << path.string(); | ||
2233 | 54 | |||
2234 | 55 | std::ifstream in{path.string().c_str()}; | ||
2235 | 56 | T value{default_value}; in >> value; | ||
2236 | 57 | |||
2237 | 58 | return value; | ||
2238 | 59 | } | ||
2239 | 60 | }; | ||
2240 | 61 | |||
2241 | 62 | } | ||
2242 | 63 | |||
2243 | 64 | std::string sirf::Provider::class_name() | ||
2244 | 65 | { | ||
2245 | 66 | return "sirf::Provider"; | ||
2246 | 67 | } | ||
2247 | 68 | |||
2248 | 69 | void sirf::Provider::Monitor::on_new_sirf_message(const Message& message) | ||
2249 | 70 | { | ||
2250 | 71 | VLOG(1) << message; | ||
2251 | 72 | if (auto sp = provider.lock()) | ||
2252 | 73 | if (sp->configuration.protocol == Provider::Protocol::sirf) | ||
2253 | 74 | boost::apply_visitor(*this, message); | ||
2254 | 75 | } | ||
2255 | 76 | |||
2256 | 77 | |||
2257 | 78 | void sirf::Provider::Monitor::on_new_nmea_sentence(const nmea::Sentence& sentence) | ||
2258 | 79 | { | ||
2259 | 80 | VLOG(1) << sentence; | ||
2260 | 81 | if (auto sp = provider.lock()) | ||
2261 | 82 | if (sp->configuration.protocol == Provider::Protocol::nmea) | ||
2262 | 83 | boost::apply_visitor(*this, sentence); | ||
2263 | 84 | } | ||
2264 | 85 | |||
2265 | 86 | void sirf::Provider::Monitor::operator()(const sirf::GeodeticNavigationData& gnd) | ||
2266 | 87 | { | ||
2267 | 88 | auto thiz = shared_from_this(); | ||
2268 | 89 | std::weak_ptr<sirf::Provider::Monitor> wp{thiz}; | ||
2269 | 90 | |||
2270 | 91 | glib::Runtime::instance()->dispatch([gnd, wp]() | ||
2271 | 92 | { | ||
2272 | 93 | if (auto sp = wp.lock()) | ||
2273 | 94 | { | ||
2274 | 95 | if (auto spp = sp->provider.lock()) | ||
2275 | 96 | { | ||
2276 | 97 | if (gnd.nav_valid == GeodeticNavigationData::valid_navigation) | ||
2277 | 98 | { | ||
2278 | 99 | Position position | ||
2279 | 100 | { | ||
2280 | 101 | gnd.latitude * units::degrees, | ||
2281 | 102 | gnd.longitude * units::degrees | ||
2282 | 103 | }; | ||
2283 | 104 | position.accuracy().horizontal(gnd.error.horizontal_position * units::meters); | ||
2284 | 105 | |||
2285 | 106 | position.altitude(gnd.altitude.above_mean_sea_level * units::meters); | ||
2286 | 107 | position.accuracy().vertical(gnd.error.vertical_position * units::meters); | ||
2287 | 108 | |||
2288 | 109 | spp->updates.position(location::Update<location::Position>{position}); | ||
2289 | 110 | if (!(gnd.nav_type & GeodeticNavigationData::invalid_heading)) | ||
2290 | 111 | spp->updates.heading(location::Update<units::Degrees>{gnd.over_ground.course * units::degrees}); | ||
2291 | 112 | if (!(gnd.nav_type & GeodeticNavigationData::invalid_velocity)) | ||
2292 | 113 | spp->updates.velocity(location::Update<units::MetersPerSecond>{gnd.over_ground.speed * units::meters_per_second}); | ||
2293 | 114 | } | ||
2294 | 115 | } | ||
2295 | 116 | } | ||
2296 | 117 | }); | ||
2297 | 118 | } | ||
2298 | 119 | |||
2299 | 120 | void sirf::Provider::Monitor::operator()(const nmea::Gga& gga) | ||
2300 | 121 | { | ||
2301 | 122 | if (gga.latitude && gga.longitude) | ||
2302 | 123 | { | ||
2303 | 124 | auto lat = gga.latitude.get(); | ||
2304 | 125 | auto lon = gga.longitude.get(); | ||
2305 | 126 | |||
2306 | 127 | Position position | ||
2307 | 128 | { | ||
2308 | 129 | (lat.degrees + lat.minutes / 60.f) * units::degrees, | ||
2309 | 130 | (lon.degrees + lon.minutes / 60.f) * units::degrees | ||
2310 | 131 | }; | ||
2311 | 132 | |||
2312 | 133 | if (gga.altitude) | ||
2313 | 134 | position.altitude(units::Meters::from_value(*gga.altitude)); | ||
2314 | 135 | |||
2315 | 136 | // TODO(tvoss): Maximum accuracy should be reported by the receiver | ||
2316 | 137 | // implementation rather than hardcoding 3 [m] here. | ||
2317 | 138 | if (gga.hdop) | ||
2318 | 139 | position.accuracy().horizontal(gga.hdop.get() * 3. * units::meters); | ||
2319 | 140 | |||
2320 | 141 | auto thiz = shared_from_this(); | ||
2321 | 142 | std::weak_ptr<sirf::Provider::Monitor> wp{thiz}; | ||
2322 | 143 | |||
2323 | 144 | glib::Runtime::instance()->dispatch([position, wp]() | ||
2324 | 145 | { | ||
2325 | 146 | if (auto sp = wp.lock()) | ||
2326 | 147 | if (auto spp = sp->provider.lock()) | ||
2327 | 148 | spp->updates.position(location::Update<location::Position>{position}); | ||
2328 | 149 | }); | ||
2329 | 150 | } | ||
2330 | 151 | } | ||
2331 | 152 | |||
2332 | 153 | void sirf::Provider::Monitor::operator()(const nmea::Gsa&) | ||
2333 | 154 | { | ||
2334 | 155 | // Empty on purpose | ||
2335 | 156 | } | ||
2336 | 157 | |||
2337 | 158 | void sirf::Provider::Monitor::operator()(const nmea::Gll&) | ||
2338 | 159 | { | ||
2339 | 160 | // Empty on purpose | ||
2340 | 161 | } | ||
2341 | 162 | |||
2342 | 163 | void sirf::Provider::Monitor::operator()(const nmea::Gsv&) | ||
2343 | 164 | { | ||
2344 | 165 | // Empty on purpose | ||
2345 | 166 | } | ||
2346 | 167 | |||
2347 | 168 | void sirf::Provider::Monitor::operator()(const nmea::Rmc&) | ||
2348 | 169 | { | ||
2349 | 170 | // Empty on purpose | ||
2350 | 171 | } | ||
2351 | 172 | |||
2352 | 173 | void sirf::Provider::Monitor::operator()(const nmea::Txt&) | ||
2353 | 174 | { | ||
2354 | 175 | // Empty on purpose | ||
2355 | 176 | } | ||
2356 | 177 | |||
2357 | 178 | void sirf::Provider::Monitor::operator()(const nmea::Vtg& vtg) | ||
2358 | 179 | { | ||
2359 | 180 | auto thiz = shared_from_this(); | ||
2360 | 181 | std::weak_ptr<sirf::Provider::Monitor> wp{thiz}; | ||
2361 | 182 | |||
2362 | 183 | glib::Runtime::instance()->dispatch([vtg, wp]() | ||
2363 | 184 | { | ||
2364 | 185 | if (auto sp = wp.lock()) | ||
2365 | 186 | { | ||
2366 | 187 | if (vtg.cog_true) | ||
2367 | 188 | if (auto spp = sp->provider.lock()) | ||
2368 | 189 | spp->updates.heading( | ||
2369 | 190 | Update<units::Degrees>( | ||
2370 | 191 | vtg.cog_true.get() * units::degrees)); | ||
2371 | 192 | if (vtg.sog_kmh) | ||
2372 | 193 | if (auto spp = sp->provider.lock()) | ||
2373 | 194 | spp->updates.velocity( | ||
2374 | 195 | Update<units::MetersPerSecond>( | ||
2375 | 196 | vtg.sog_kmh.get() * 1000./3600. * units::meters_per_second)); | ||
2376 | 197 | } | ||
2377 | 198 | }); | ||
2378 | 199 | } | ||
2379 | 200 | |||
2380 | 201 | location::Provider::Ptr sirf::Provider::create_instance(const location::ProviderFactory::Configuration& config) | ||
2381 | 202 | { | ||
2382 | 203 | Configuration configuration | ||
2383 | 204 | { | ||
2384 | 205 | SettingsHelper::get_value<Protocol>( | ||
2385 | 206 | "sirf.provider.protocol", | ||
2386 | 207 | Protocol::sirf), | ||
2387 | 208 | config.get<std::string>( | ||
2388 | 209 | "device", SettingsHelper::get_value<std::string>( | ||
2389 | 210 | "sirf.provider.path", | ||
2390 | 211 | "/dev/ttyUSB1" | ||
2391 | 212 | ) | ||
2392 | 213 | ) | ||
2393 | 214 | }; | ||
2394 | 215 | |||
2395 | 216 | return sirf::Provider::create(configuration); | ||
2396 | 217 | } | ||
2397 | 218 | |||
2398 | 219 | // Create a new instance with configuration. | ||
2399 | 220 | std::shared_ptr<sirf::Provider> sirf::Provider::create(const Configuration& configuration) | ||
2400 | 221 | { | ||
2401 | 222 | auto sp = std::shared_ptr<Provider>{new Provider{configuration}}; | ||
2402 | 223 | return sp->finalize_construction(); | ||
2403 | 224 | } | ||
2404 | 225 | |||
2405 | 226 | |||
2406 | 227 | sirf::Provider::Provider(const Configuration& configuration) | ||
2407 | 228 | : configuration{configuration}, | ||
2408 | 229 | runtime{location::Runtime::create(1)}, | ||
2409 | 230 | monitor{std::make_shared<Monitor>()}, | ||
2410 | 231 | receiver{SerialPortReceiver::create(runtime->service(), configuration.device, monitor)} | ||
2411 | 232 | { | ||
2412 | 233 | runtime->start(); | ||
2413 | 234 | configure_protocol(); | ||
2414 | 235 | } | ||
2415 | 236 | |||
2416 | 237 | sirf::Provider::~Provider() noexcept | ||
2417 | 238 | { | ||
2418 | 239 | deactivate(); | ||
2419 | 240 | runtime->stop(); | ||
2420 | 241 | } | ||
2421 | 242 | |||
2422 | 243 | void sirf::Provider::reset() | ||
2423 | 244 | { | ||
2424 | 245 | InitializeDataSource ids; | ||
2425 | 246 | ids.channels = InitializeDataSource::max_number_channels; | ||
2426 | 247 | ids.reset_configuration = InitializeDataSource::clear_ephemeris_data | InitializeDataSource::clear_all_history; | ||
2427 | 248 | receiver->send_message(Message{ids}); | ||
2428 | 249 | } | ||
2429 | 250 | |||
2430 | 251 | void sirf::Provider::on_new_event(const Event&) | ||
2431 | 252 | { | ||
2432 | 253 | // TODO(tvoss): Use incoming reference position updates | ||
2433 | 254 | // to query assistance data. | ||
2434 | 255 | } | ||
2435 | 256 | |||
2436 | 257 | location::Provider::Requirements sirf::Provider::requirements() const | ||
2437 | 258 | { | ||
2438 | 259 | return Requirements::none; | ||
2439 | 260 | } | ||
2440 | 261 | |||
2441 | 262 | bool sirf::Provider::satisfies(const location::Criteria&) | ||
2442 | 263 | { | ||
2443 | 264 | return true; | ||
2444 | 265 | } | ||
2445 | 266 | |||
2446 | 267 | void sirf::Provider::enable() | ||
2447 | 268 | { | ||
2448 | 269 | } | ||
2449 | 270 | |||
2450 | 271 | void sirf::Provider::disable() | ||
2451 | 272 | { | ||
2452 | 273 | } | ||
2453 | 274 | |||
2454 | 275 | void sirf::Provider::activate() | ||
2455 | 276 | { | ||
2456 | 277 | receiver->start(); | ||
2457 | 278 | } | ||
2458 | 279 | |||
2459 | 280 | void sirf::Provider::deactivate() | ||
2460 | 281 | { | ||
2461 | 282 | receiver->stop(); | ||
2462 | 283 | } | ||
2463 | 284 | |||
2464 | 285 | const core::Signal<location::Update<location::Position>>& sirf::Provider::position_updates() const | ||
2465 | 286 | { | ||
2466 | 287 | return updates.position; | ||
2467 | 288 | } | ||
2468 | 289 | |||
2469 | 290 | const core::Signal<location::Update<location::units::Degrees>>& sirf::Provider::heading_updates() const | ||
2470 | 291 | { | ||
2471 | 292 | return updates.heading; | ||
2472 | 293 | } | ||
2473 | 294 | |||
2474 | 295 | const core::Signal<location::Update<location::units::MetersPerSecond>>& sirf::Provider::velocity_updates() const | ||
2475 | 296 | { | ||
2476 | 297 | return updates.velocity; | ||
2477 | 298 | } | ||
2478 | 299 | |||
2479 | 300 | std::shared_ptr<sirf::Provider> sirf::Provider::finalize_construction() | ||
2480 | 301 | { | ||
2481 | 302 | auto thiz = shared_from_this(); | ||
2482 | 303 | std::weak_ptr<sirf::Provider> wp{thiz}; | ||
2483 | 304 | |||
2484 | 305 | monitor->provider = wp; | ||
2485 | 306 | return thiz; | ||
2486 | 307 | } | ||
2487 | 308 | |||
2488 | 309 | void sirf::Provider::configure_protocol() | ||
2489 | 310 | { | ||
2490 | 311 | switch(configuration.protocol) | ||
2491 | 312 | { | ||
2492 | 313 | case Protocol::sirf: | ||
2493 | 314 | { | ||
2494 | 315 | static const std::string set_serial_port{"$PSRF100,0,4800,8,1,0*0F\r\n"}; | ||
2495 | 316 | receiver->send_encoded_message(std::vector<std::uint8_t>{set_serial_port.begin(), set_serial_port.end()}); | ||
2496 | 317 | break; | ||
2497 | 318 | } | ||
2498 | 319 | case Protocol::nmea: | ||
2499 | 320 | receiver->send_message(Message{SetProtocol{SetProtocol::nmea}}); | ||
2500 | 321 | break; | ||
2501 | 322 | default: | ||
2502 | 323 | break; | ||
2503 | 324 | } | ||
2504 | 325 | } | ||
2505 | 326 | |||
2506 | 327 | std::istream& sirf::operator>>(std::istream& in, Provider::Protocol& protocol) | ||
2507 | 328 | { | ||
2508 | 329 | std::string value; | ||
2509 | 330 | in >> value; | ||
2510 | 331 | |||
2511 | 332 | if (value == "sirf") | ||
2512 | 333 | protocol = Provider::Protocol::sirf; | ||
2513 | 334 | if (value == "nmea") | ||
2514 | 335 | protocol = Provider::Protocol::nmea; | ||
2515 | 336 | |||
2516 | 337 | return in; | ||
2517 | 338 | } | ||
2518 | 339 | |||
2519 | 340 | std::ostream& sirf::operator<<(std::ostream& out, Provider::Protocol protocol) | ||
2520 | 341 | { | ||
2521 | 342 | switch (protocol) | ||
2522 | 343 | { | ||
2523 | 344 | case Provider::Protocol::sirf: | ||
2524 | 345 | out << "sirf"; | ||
2525 | 346 | break; | ||
2526 | 347 | case Provider::Protocol::nmea: | ||
2527 | 348 | out << "nmea"; | ||
2528 | 349 | break; | ||
2529 | 350 | } | ||
2530 | 351 | |||
2531 | 352 | return out; | ||
2532 | 353 | } | ||
2533 | 0 | 354 | ||
2534 | === added file 'src/location/providers/sirf/provider.h' | |||
2535 | --- src/location/providers/sirf/provider.h 1970-01-01 00:00:00 +0000 | |||
2536 | +++ src/location/providers/sirf/provider.h 2017-05-05 09:37:41 +0000 | |||
2537 | @@ -0,0 +1,143 @@ | |||
2538 | 1 | /* | ||
2539 | 2 | * Copyright © 2016 Canonical Ltd. | ||
2540 | 3 | * | ||
2541 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
2542 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
2543 | 6 | * as published by the Free Software Foundation. | ||
2544 | 7 | * | ||
2545 | 8 | * This program is distributed in the hope that it will be useful, | ||
2546 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2547 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2548 | 11 | * GNU Lesser General Public License for more details. | ||
2549 | 12 | * | ||
2550 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
2551 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2552 | 15 | * | ||
2553 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | ||
2554 | 17 | */ | ||
2555 | 18 | #ifndef LOCATION_PROVIDERS_SIRF_PROVIDER_H_ | ||
2556 | 19 | #define LOCATION_PROVIDERS_SIRF_PROVIDER_H_ | ||
2557 | 20 | |||
2558 | 21 | #include <location/provider.h> | ||
2559 | 22 | #include <location/provider_factory.h> | ||
2560 | 23 | #include <location/runtime.h> | ||
2561 | 24 | #include <location/nmea/sentence.h> | ||
2562 | 25 | #include <location/providers/sirf/serial_port_receiver.h> | ||
2563 | 26 | |||
2564 | 27 | #include <boost/filesystem.hpp> | ||
2565 | 28 | |||
2566 | 29 | #include <iosfwd> | ||
2567 | 30 | #include <thread> | ||
2568 | 31 | |||
2569 | 32 | namespace location | ||
2570 | 33 | { | ||
2571 | 34 | namespace providers | ||
2572 | 35 | { | ||
2573 | 36 | namespace sirf | ||
2574 | 37 | { | ||
2575 | 38 | // sirf::Provider integrates GNSS receivers relying on | ||
2576 | 39 | // ublox chipsets with locationd. | ||
2577 | 40 | // | ||
2578 | 41 | // In this version, only receivers connected to a serial port | ||
2579 | 42 | // are supported. More to this, this version only reads NMEA sentences | ||
2580 | 43 | // and does not support the proprietary ublox protocol. | ||
2581 | 44 | // | ||
2582 | 45 | // Configuration parameters: | ||
2583 | 46 | // - device[=/dev/ttyUSB1] serial device connecting to the receiver. | ||
2584 | 47 | class Provider : public location::Provider, public std::enable_shared_from_this<Provider> | ||
2585 | 48 | { | ||
2586 | 49 | public: | ||
2587 | 50 | enum class Protocol | ||
2588 | 51 | { | ||
2589 | 52 | sirf, // Rely on sirf. | ||
2590 | 53 | nmea // Rely on nmea. | ||
2591 | 54 | }; | ||
2592 | 55 | |||
2593 | 56 | // Configuration bundles all construction time parameters. | ||
2594 | 57 | struct Configuration | ||
2595 | 58 | { | ||
2596 | 59 | Protocol protocol; // The protocol used for communicating with the receiver. | ||
2597 | 60 | boost::filesystem::path device; // Serial device used for communicating with the receiver. | ||
2598 | 61 | }; | ||
2599 | 62 | |||
2600 | 63 | // For integration with the Provider factory. | ||
2601 | 64 | static std::string class_name(); | ||
2602 | 65 | // Instantiates a new provider instance, populating the configuration object | ||
2603 | 66 | // from the provided property bundle. Please see dummy::Configuration::Keys | ||
2604 | 67 | // for the list of known options. | ||
2605 | 68 | static Provider::Ptr create_instance(const ProviderFactory::Configuration&); | ||
2606 | 69 | |||
2607 | 70 | // Create a new instance with configuration. | ||
2608 | 71 | static std::shared_ptr<Provider> create(const Configuration& configuration); | ||
2609 | 72 | |||
2610 | 73 | // Cleans up all resources and stops the updates. | ||
2611 | 74 | ~Provider() noexcept; | ||
2612 | 75 | |||
2613 | 76 | // Resets the chipset and drops all cached data. | ||
2614 | 77 | // The next positioning request will be a cold start. | ||
2615 | 78 | void reset(); | ||
2616 | 79 | |||
2617 | 80 | // From Provider | ||
2618 | 81 | void on_new_event(const Event& event) override; | ||
2619 | 82 | |||
2620 | 83 | void enable() override; | ||
2621 | 84 | void disable() override; | ||
2622 | 85 | void activate() override; | ||
2623 | 86 | void deactivate() override; | ||
2624 | 87 | |||
2625 | 88 | Requirements requirements() const override; | ||
2626 | 89 | bool satisfies(const Criteria& criteria) override; | ||
2627 | 90 | const core::Signal<Update<Position>>& position_updates() const override; | ||
2628 | 91 | const core::Signal<Update<units::Degrees>>& heading_updates() const override; | ||
2629 | 92 | const core::Signal<Update<units::MetersPerSecond>>& velocity_updates() const override; | ||
2630 | 93 | |||
2631 | 94 | private: | ||
2632 | 95 | // Relays incoming sentences to a provider instance. | ||
2633 | 96 | struct Monitor : public std::enable_shared_from_this<sirf::Provider::Monitor>, public sirf::Receiver::Monitor, public boost::static_visitor<> | ||
2634 | 97 | { | ||
2635 | 98 | // From Receiver::Monitor | ||
2636 | 99 | void on_new_sirf_message(const Message& message) override; | ||
2637 | 100 | void on_new_nmea_sentence(const nmea::Sentence& sentence) override; | ||
2638 | 101 | |||
2639 | 102 | template<typename T> | ||
2640 | 103 | void operator()(const T&) const {} | ||
2641 | 104 | |||
2642 | 105 | void operator()(const GeodeticNavigationData& gnd); | ||
2643 | 106 | |||
2644 | 107 | void operator()(const nmea::Gga& gga); | ||
2645 | 108 | void operator()(const nmea::Gsa& gsa); | ||
2646 | 109 | void operator()(const nmea::Gll& gll); | ||
2647 | 110 | void operator()(const nmea::Gsv& gsv); | ||
2648 | 111 | void operator()(const nmea::Rmc& rmc); | ||
2649 | 112 | void operator()(const nmea::Txt& txt); | ||
2650 | 113 | void operator()(const nmea::Vtg& vtg); | ||
2651 | 114 | |||
2652 | 115 | std::weak_ptr<Provider> provider; | ||
2653 | 116 | }; | ||
2654 | 117 | |||
2655 | 118 | // Creates a new provider instance talking via device to the ubx chipset. | ||
2656 | 119 | Provider(const Configuration& configuration); | ||
2657 | 120 | |||
2658 | 121 | std::shared_ptr<Provider> finalize_construction(); | ||
2659 | 122 | void configure_protocol(); | ||
2660 | 123 | |||
2661 | 124 | Configuration configuration; | ||
2662 | 125 | std::shared_ptr<location::Runtime> runtime; | ||
2663 | 126 | std::shared_ptr<Monitor> monitor; | ||
2664 | 127 | std::shared_ptr<SerialPortReceiver> receiver; | ||
2665 | 128 | struct | ||
2666 | 129 | { | ||
2667 | 130 | core::Signal<Update<Position>> position; | ||
2668 | 131 | core::Signal<Update<units::Degrees>> heading; | ||
2669 | 132 | core::Signal<Update<units::MetersPerSecond>> velocity; | ||
2670 | 133 | } updates; | ||
2671 | 134 | }; | ||
2672 | 135 | |||
2673 | 136 | std::istream& operator>>(std::istream&, Provider::Protocol&); | ||
2674 | 137 | std::ostream& operator<<(std::ostream&, Provider::Protocol); | ||
2675 | 138 | |||
2676 | 139 | } // namespace sirf | ||
2677 | 140 | } // namespace providers | ||
2678 | 141 | } // namespace location | ||
2679 | 142 | |||
2680 | 143 | #endif // LOCATION_PROVIDERS_SIRF_PROVIDER_H_ | ||
2681 | 0 | 144 | ||
2682 | === added file 'src/location/providers/sirf/reader.cpp' | |||
2683 | --- src/location/providers/sirf/reader.cpp 1970-01-01 00:00:00 +0000 | |||
2684 | +++ src/location/providers/sirf/reader.cpp 2017-05-05 09:37:41 +0000 | |||
2685 | @@ -0,0 +1,87 @@ | |||
2686 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
2687 | 2 | // | ||
2688 | 3 | // This library is free software: you can redistribute it and/or modify | ||
2689 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
2690 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
2691 | 6 | // (at your option) any later version. | ||
2692 | 7 | // | ||
2693 | 8 | // This program is distributed in the hope that it will be useful, | ||
2694 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2695 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2696 | 11 | // GNU General Public License for more details. | ||
2697 | 12 | // | ||
2698 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
2699 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2700 | 15 | |||
2701 | 16 | #include <location/providers/sirf/reader.h> | ||
2702 | 17 | |||
2703 | 18 | #include <arpa/inet.h> | ||
2704 | 19 | |||
2705 | 20 | #include <cstring> | ||
2706 | 21 | #include <stdexcept> | ||
2707 | 22 | |||
2708 | 23 | namespace sirf = location::providers::sirf; | ||
2709 | 24 | |||
2710 | 25 | sirf::Reader::Reader(std::vector<std::uint8_t>::const_iterator begin, | ||
2711 | 26 | std::vector<std::uint8_t>::const_iterator end) | ||
2712 | 27 | : begin{begin}, current{begin}, end{end} {} | ||
2713 | 28 | |||
2714 | 29 | std::uint8_t sirf::Reader::read_unsigned_char() | ||
2715 | 30 | { | ||
2716 | 31 | if (current + sizeof(std::uint8_t) > end) | ||
2717 | 32 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2718 | 33 | |||
2719 | 34 | auto result = *current; | ||
2720 | 35 | ++current; | ||
2721 | 36 | return result; | ||
2722 | 37 | } | ||
2723 | 38 | |||
2724 | 39 | std::int8_t sirf::Reader::read_signed_char() | ||
2725 | 40 | { | ||
2726 | 41 | if (current + sizeof(std::int8_t) > end) | ||
2727 | 42 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2728 | 43 | |||
2729 | 44 | auto result = reinterpret_cast<const std::int8_t*>(&(*current)); | ||
2730 | 45 | current += sizeof(std::int8_t); | ||
2731 | 46 | return *result; | ||
2732 | 47 | } | ||
2733 | 48 | |||
2734 | 49 | std::uint16_t sirf::Reader::read_unsigned_short() | ||
2735 | 50 | { | ||
2736 | 51 | if (current + sizeof(std::uint16_t) > end) | ||
2737 | 52 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2738 | 53 | |||
2739 | 54 | auto result = reinterpret_cast<const std::uint16_t*>(&(*current)); | ||
2740 | 55 | current += sizeof(std::uint16_t); | ||
2741 | 56 | return ::htons(*result); | ||
2742 | 57 | } | ||
2743 | 58 | |||
2744 | 59 | std::int16_t sirf::Reader::read_signed_short() | ||
2745 | 60 | { | ||
2746 | 61 | if (current + sizeof(std::int16_t) > end) | ||
2747 | 62 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2748 | 63 | |||
2749 | 64 | auto result = reinterpret_cast<const std::int16_t*>(&(*current)); | ||
2750 | 65 | current += sizeof(std::int16_t); | ||
2751 | 66 | return ::htons(*result); | ||
2752 | 67 | } | ||
2753 | 68 | |||
2754 | 69 | std::uint32_t sirf::Reader::read_unsigned_long() | ||
2755 | 70 | { | ||
2756 | 71 | if (current + sizeof(std::uint32_t) > end) | ||
2757 | 72 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2758 | 73 | |||
2759 | 74 | auto result = reinterpret_cast<const std::uint32_t*>(&(*current)); | ||
2760 | 75 | current += sizeof(std::uint32_t); | ||
2761 | 76 | return ::htonl(*result); | ||
2762 | 77 | } | ||
2763 | 78 | |||
2764 | 79 | std::int32_t sirf::Reader::read_signed_long() | ||
2765 | 80 | { | ||
2766 | 81 | if (current + sizeof(std::int32_t) > end) | ||
2767 | 82 | throw std::out_of_range{"Read buffer exhausted"}; | ||
2768 | 83 | |||
2769 | 84 | auto result = reinterpret_cast<const std::int32_t*>(&(*current)); | ||
2770 | 85 | current += sizeof(std::int32_t); | ||
2771 | 86 | return ::htonl(*result); | ||
2772 | 87 | } | ||
2773 | 0 | 88 | ||
2774 | === added file 'src/location/providers/sirf/reader.h' | |||
2775 | --- src/location/providers/sirf/reader.h 1970-01-01 00:00:00 +0000 | |||
2776 | +++ src/location/providers/sirf/reader.h 2017-05-05 09:37:41 +0000 | |||
2777 | @@ -0,0 +1,52 @@ | |||
2778 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
2779 | 2 | // | ||
2780 | 3 | // This library is free software: you can redistribute it and/or modify | ||
2781 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
2782 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
2783 | 6 | // (at your option) any later version. | ||
2784 | 7 | // | ||
2785 | 8 | // This program is distributed in the hope that it will be useful, | ||
2786 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2787 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2788 | 11 | // GNU General Public License for more details. | ||
2789 | 12 | // | ||
2790 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
2791 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2792 | 15 | |||
2793 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_READER_H_ | ||
2794 | 17 | #define LOCATION_PROVIDERS_SIRF_READER_H_ | ||
2795 | 18 | |||
2796 | 19 | #include <cstdint> | ||
2797 | 20 | #include <vector> | ||
2798 | 21 | |||
2799 | 22 | namespace location | ||
2800 | 23 | { | ||
2801 | 24 | namespace providers | ||
2802 | 25 | { | ||
2803 | 26 | namespace sirf | ||
2804 | 27 | { | ||
2805 | 28 | |||
2806 | 29 | class Reader | ||
2807 | 30 | { | ||
2808 | 31 | public: | ||
2809 | 32 | explicit Reader(std::vector<std::uint8_t>::const_iterator begin, | ||
2810 | 33 | std::vector<std::uint8_t>::const_iterator end); | ||
2811 | 34 | |||
2812 | 35 | std::uint8_t read_unsigned_char(); | ||
2813 | 36 | std::int8_t read_signed_char(); | ||
2814 | 37 | std::uint16_t read_unsigned_short(); | ||
2815 | 38 | std::int16_t read_signed_short(); | ||
2816 | 39 | std::uint32_t read_unsigned_long(); | ||
2817 | 40 | std::int32_t read_signed_long(); | ||
2818 | 41 | |||
2819 | 42 | private: | ||
2820 | 43 | std::vector<std::uint8_t>::const_iterator begin; | ||
2821 | 44 | std::vector<std::uint8_t>::const_iterator current; | ||
2822 | 45 | std::vector<std::uint8_t>::const_iterator end; | ||
2823 | 46 | }; | ||
2824 | 47 | |||
2825 | 48 | } // namespace sirf | ||
2826 | 49 | } // namespace providers | ||
2827 | 50 | } // namespace location | ||
2828 | 51 | |||
2829 | 52 | #endif // LOCATION_PROVIDERS_SIRF_READER_H_ | ||
2830 | 0 | 53 | ||
2831 | === added file 'src/location/providers/sirf/receiver.cpp' | |||
2832 | --- src/location/providers/sirf/receiver.cpp 1970-01-01 00:00:00 +0000 | |||
2833 | +++ src/location/providers/sirf/receiver.cpp 2017-05-05 09:37:41 +0000 | |||
2834 | @@ -0,0 +1,80 @@ | |||
2835 | 1 | #include <location/providers/sirf/receiver.h> | ||
2836 | 2 | |||
2837 | 3 | #include <location/nmea/sentence.h> | ||
2838 | 4 | #include <location/providers/sirf/message.h> | ||
2839 | 5 | |||
2840 | 6 | #include <iostream> | ||
2841 | 7 | |||
2842 | 8 | namespace sirf = location::providers::sirf; | ||
2843 | 9 | |||
2844 | 10 | namespace | ||
2845 | 11 | { | ||
2846 | 12 | |||
2847 | 13 | struct EncodingVisitor : public boost::static_visitor<std::vector<std::uint8_t>> | ||
2848 | 14 | { | ||
2849 | 15 | template<typename T> | ||
2850 | 16 | std::vector<std::uint8_t> operator()(const T&) const | ||
2851 | 17 | { | ||
2852 | 18 | throw std::logic_error{"Encoding not supported"}; | ||
2853 | 19 | } | ||
2854 | 20 | |||
2855 | 21 | std::vector<std::uint8_t> operator()(const sirf::InitializeDataSource& ids) const | ||
2856 | 22 | { | ||
2857 | 23 | return sirf::encode_message(ids); | ||
2858 | 24 | } | ||
2859 | 25 | |||
2860 | 26 | std::vector<std::uint8_t> operator()(const sirf::SetProtocol& sp) const | ||
2861 | 27 | { | ||
2862 | 28 | return sirf::encode_message(sp); | ||
2863 | 29 | } | ||
2864 | 30 | }; | ||
2865 | 31 | |||
2866 | 32 | } // namespace | ||
2867 | 33 | |||
2868 | 34 | sirf::Receiver::Receiver(const std::shared_ptr<Monitor>& monitor) : monitor{monitor} {} | ||
2869 | 35 | |||
2870 | 36 | void sirf::Receiver::send_message(const Message& message) | ||
2871 | 37 | { | ||
2872 | 38 | send_encoded_message(boost::apply_visitor(EncodingVisitor{}, message)); | ||
2873 | 39 | } | ||
2874 | 40 | |||
2875 | 41 | void sirf::Receiver::process_chunk(Buffer::iterator it, Buffer::iterator itE) | ||
2876 | 42 | { | ||
2877 | 43 | while (it != itE) | ||
2878 | 44 | { | ||
2879 | 45 | auto result = sirf_scanner.update(*it); | ||
2880 | 46 | |||
2881 | 47 | if (std::get<0>(result) == Scanner::Expect::nothing_more) | ||
2882 | 48 | { | ||
2883 | 49 | try | ||
2884 | 50 | { | ||
2885 | 51 | monitor->on_new_sirf_message(sirf_scanner.finalize()); | ||
2886 | 52 | } | ||
2887 | 53 | catch (...) | ||
2888 | 54 | { | ||
2889 | 55 | // Dropping the exception as there is hardly any reasonable measure | ||
2890 | 56 | // we can take. Both scanners are designed to recover from issues, and we | ||
2891 | 57 | // we just trap the exception here to guarantee that we keep on consuming the | ||
2892 | 58 | // entire buffer. | ||
2893 | 59 | } | ||
2894 | 60 | } | ||
2895 | 61 | else if (!std::get<1>(result)) | ||
2896 | 62 | { | ||
2897 | 63 | if (nmea::Scanner::Expect::nothing_more == nmea_scanner.update(*it)) | ||
2898 | 64 | { | ||
2899 | 65 | try | ||
2900 | 66 | { | ||
2901 | 67 | monitor->on_new_nmea_sentence(nmea::parse_sentence(nmea_scanner.finalize())); | ||
2902 | 68 | } | ||
2903 | 69 | catch (...) | ||
2904 | 70 | { | ||
2905 | 71 | // Dropping the exception as there is hardly any reasonable measure | ||
2906 | 72 | // we can take. Both scanners are designed to recover from issues, and we | ||
2907 | 73 | // we just trap the exception here to guarantee that we keep on consuming the | ||
2908 | 74 | // entire buffer. | ||
2909 | 75 | } | ||
2910 | 76 | } | ||
2911 | 77 | } | ||
2912 | 78 | ++it; | ||
2913 | 79 | } | ||
2914 | 80 | } | ||
2915 | 0 | 81 | ||
2916 | === added file 'src/location/providers/sirf/receiver.h' | |||
2917 | --- src/location/providers/sirf/receiver.h 1970-01-01 00:00:00 +0000 | |||
2918 | +++ src/location/providers/sirf/receiver.h 2017-05-05 09:37:41 +0000 | |||
2919 | @@ -0,0 +1,92 @@ | |||
2920 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
2921 | 2 | // | ||
2922 | 3 | // This library is free software: you can redistribute it and/or modify | ||
2923 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
2924 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
2925 | 6 | // (at your option) any later version. | ||
2926 | 7 | // | ||
2927 | 8 | // This program is distributed in the hope that it will be useful, | ||
2928 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2929 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2930 | 11 | // GNU General Public License for more details. | ||
2931 | 12 | // | ||
2932 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
2933 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
2934 | 15 | |||
2935 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_RECEIVER_H_ | ||
2936 | 17 | #define LOCATION_PROVIDERS_SIRF_RECEIVER_H_ | ||
2937 | 18 | |||
2938 | 19 | #include <location/providers/sirf/codec.h> | ||
2939 | 20 | #include <location/providers/sirf/message.h> | ||
2940 | 21 | #include <location/providers/sirf/scanner.h> | ||
2941 | 22 | |||
2942 | 23 | #include <location/nmea/scanner.h> | ||
2943 | 24 | #include <location/nmea/sentence.h> | ||
2944 | 25 | |||
2945 | 26 | #include <memory> | ||
2946 | 27 | |||
2947 | 28 | namespace location | ||
2948 | 29 | { | ||
2949 | 30 | namespace providers | ||
2950 | 31 | { | ||
2951 | 32 | namespace sirf | ||
2952 | 33 | { | ||
2953 | 34 | |||
2954 | 35 | /// @brief Receiver connects to a ublox 8 GNSS receiver. | ||
2955 | 36 | class Receiver | ||
2956 | 37 | { | ||
2957 | 38 | public: | ||
2958 | 39 | using Buffer = std::array<std::uint8_t, 4096>; | ||
2959 | 40 | |||
2960 | 41 | /// @brief Monitor provides calling code with means for monitoring | ||
2961 | 42 | /// receiver operation. | ||
2962 | 43 | class Monitor | ||
2963 | 44 | { | ||
2964 | 45 | public: | ||
2965 | 46 | /// @cond | ||
2966 | 47 | Monitor() = default; | ||
2967 | 48 | Monitor(const Monitor&) = delete; | ||
2968 | 49 | Monitor(Monitor&&) = delete; | ||
2969 | 50 | virtual ~Monitor() = default; | ||
2970 | 51 | Monitor& operator=(const Monitor&) = delete; | ||
2971 | 52 | Monitor& operator=(Monitor&&) = delete; | ||
2972 | 53 | /// @endcond | ||
2973 | 54 | |||
2974 | 55 | /// @brief on_new_ubx_message is invoked for every complete and parsed | ||
2975 | 56 | /// ubx message. | ||
2976 | 57 | virtual void on_new_sirf_message(const sirf::Message& message) = 0; | ||
2977 | 58 | |||
2978 | 59 | /// @brief on_new_nmea_sentence is invoked for every complete and parsed | ||
2979 | 60 | /// nmea sentence. | ||
2980 | 61 | virtual void on_new_nmea_sentence(const nmea::Sentence& sentence) = 0; | ||
2981 | 62 | }; | ||
2982 | 63 | |||
2983 | 64 | /// @brief send_message encodes and sends 'message' to the receiver. | ||
2984 | 65 | void send_message(const Message& message); | ||
2985 | 66 | |||
2986 | 67 | /// @brief send_encoded_message sends out data to the receiver. | ||
2987 | 68 | virtual void send_encoded_message(const std::vector<std::uint8_t> &data) = 0; | ||
2988 | 69 | |||
2989 | 70 | protected: | ||
2990 | 71 | /// @brief Receiver initializes a new instance with monitor | ||
2991 | 72 | /// | ||
2992 | 73 | /// Throws in case of issues. | ||
2993 | 74 | Receiver(const std::shared_ptr<Monitor>& monitor); | ||
2994 | 75 | |||
2995 | 76 | /// @brief process_chunk iterates over the given range, updating scanners and | ||
2996 | 77 | /// parsers. | ||
2997 | 78 | /// | ||
2998 | 79 | /// Calls out to a configured monitor instance for announcing results. | ||
2999 | 80 | void process_chunk(Buffer::iterator it, Buffer::iterator itE); | ||
3000 | 81 | |||
3001 | 82 | private: | ||
3002 | 83 | std::shared_ptr<Monitor> monitor; | ||
3003 | 84 | nmea::Scanner nmea_scanner; | ||
3004 | 85 | sirf::Scanner sirf_scanner; | ||
3005 | 86 | }; | ||
3006 | 87 | |||
3007 | 88 | } // namespace sirf | ||
3008 | 89 | } // namespace providers | ||
3009 | 90 | } // namespace location | ||
3010 | 91 | |||
3011 | 92 | #endif // LOCATION_PROVIDERS_SIRF_RECEIVER_H_ | ||
3012 | 0 | 93 | ||
3013 | === added file 'src/location/providers/sirf/scanner.cpp' | |||
3014 | --- src/location/providers/sirf/scanner.cpp 1970-01-01 00:00:00 +0000 | |||
3015 | +++ src/location/providers/sirf/scanner.cpp 2017-05-05 09:37:41 +0000 | |||
3016 | @@ -0,0 +1,161 @@ | |||
3017 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
3018 | 2 | // | ||
3019 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3020 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3021 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3022 | 6 | // (at your option) any later version. | ||
3023 | 7 | // | ||
3024 | 8 | // This program is distributed in the hope that it will be useful, | ||
3025 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3026 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3027 | 11 | // GNU General Public License for more details. | ||
3028 | 12 | // | ||
3029 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3030 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3031 | 15 | |||
3032 | 16 | #include <location/providers/sirf/scanner.h> | ||
3033 | 17 | |||
3034 | 18 | #include <location/providers/sirf/codec.h> | ||
3035 | 19 | #include <location/providers/sirf/magic.h> | ||
3036 | 20 | #include <location/providers/sirf/message.h> | ||
3037 | 21 | |||
3038 | 22 | #include <cstdint> | ||
3039 | 23 | #include <functional> | ||
3040 | 24 | #include <iomanip> | ||
3041 | 25 | #include <iostream> | ||
3042 | 26 | #include <map> | ||
3043 | 27 | #include <stdexcept> | ||
3044 | 28 | #include <tuple> | ||
3045 | 29 | #include <vector> | ||
3046 | 30 | |||
3047 | 31 | namespace sirf = location::providers::sirf; | ||
3048 | 32 | |||
3049 | 33 | sirf::Scanner::Scanner() | ||
3050 | 34 | : next{Expect::sync_char_begin_1}, | ||
3051 | 35 | expected_size{0}, | ||
3052 | 36 | message_id{0}, | ||
3053 | 37 | payload_iterator{payload.end()}, | ||
3054 | 38 | checksum_1{0}, | ||
3055 | 39 | checksum_2{0} | ||
3056 | 40 | { | ||
3057 | 41 | } | ||
3058 | 42 | |||
3059 | 43 | std::tuple<sirf::Scanner::Expect, bool> sirf::Scanner::update(std::uint8_t c) | ||
3060 | 44 | { | ||
3061 | 45 | bool consumed = false; | ||
3062 | 46 | |||
3063 | 47 | switch (next) | ||
3064 | 48 | { | ||
3065 | 49 | case Expect::sync_char_begin_1: | ||
3066 | 50 | if (c == begin::sync_char_1) | ||
3067 | 51 | { | ||
3068 | 52 | reset(); | ||
3069 | 53 | next = Expect::sync_char_begin_2; | ||
3070 | 54 | consumed = true; | ||
3071 | 55 | } | ||
3072 | 56 | break; | ||
3073 | 57 | case Expect::sync_char_begin_2: | ||
3074 | 58 | if (c == begin::sync_char_2) | ||
3075 | 59 | { | ||
3076 | 60 | next = Expect::length_1; | ||
3077 | 61 | consumed = true; | ||
3078 | 62 | } | ||
3079 | 63 | break; | ||
3080 | 64 | case Expect::length_1: | ||
3081 | 65 | expected_size |= (c << 8); | ||
3082 | 66 | next = Expect::length_2; | ||
3083 | 67 | consumed = true; | ||
3084 | 68 | break; | ||
3085 | 69 | case Expect::length_2: | ||
3086 | 70 | expected_size |= c; | ||
3087 | 71 | if (expected_size > 0) | ||
3088 | 72 | expected_size -= 1; | ||
3089 | 73 | payload.resize(expected_size); | ||
3090 | 74 | payload_iterator = payload.begin(); | ||
3091 | 75 | next = Expect::message_id; | ||
3092 | 76 | consumed = true; | ||
3093 | 77 | break; | ||
3094 | 78 | case Expect::message_id: | ||
3095 | 79 | checksum(c); | ||
3096 | 80 | message_id = c; | ||
3097 | 81 | next = expected_size > 0 ? Expect::payload : Expect::checksum_1; | ||
3098 | 82 | consumed = true; | ||
3099 | 83 | break; | ||
3100 | 84 | case Expect::payload: | ||
3101 | 85 | checksum(c); | ||
3102 | 86 | *payload_iterator = c; | ||
3103 | 87 | ++payload_iterator; | ||
3104 | 88 | next = payload_iterator == payload.end() | ||
3105 | 89 | ? Expect::checksum_1 | ||
3106 | 90 | : next; | ||
3107 | 91 | consumed = true; | ||
3108 | 92 | break; | ||
3109 | 93 | case Expect::checksum_1: | ||
3110 | 94 | checksum_1 = c; | ||
3111 | 95 | next = Expect::checksum_2; | ||
3112 | 96 | consumed = true; | ||
3113 | 97 | break; | ||
3114 | 98 | case Expect::checksum_2: | ||
3115 | 99 | checksum_2 = c; | ||
3116 | 100 | next = Expect::sync_char_end_1; | ||
3117 | 101 | consumed = true; | ||
3118 | 102 | break; | ||
3119 | 103 | case Expect::sync_char_end_1: | ||
3120 | 104 | if (c == end::sync_char_1) | ||
3121 | 105 | { | ||
3122 | 106 | next = Expect::sync_char_end_2; | ||
3123 | 107 | consumed = true; | ||
3124 | 108 | } | ||
3125 | 109 | break; | ||
3126 | 110 | case Expect::sync_char_end_2: | ||
3127 | 111 | if (c == end::sync_char_2) | ||
3128 | 112 | { | ||
3129 | 113 | next = Expect::nothing_more; | ||
3130 | 114 | consumed = true; | ||
3131 | 115 | } | ||
3132 | 116 | break; | ||
3133 | 117 | default: | ||
3134 | 118 | consumed = false; | ||
3135 | 119 | break; | ||
3136 | 120 | } | ||
3137 | 121 | |||
3138 | 122 | return std::make_tuple(next, consumed); | ||
3139 | 123 | } | ||
3140 | 124 | |||
3141 | 125 | sirf::Message sirf::Scanner::finalize() | ||
3142 | 126 | { | ||
3143 | 127 | if (next != Expect::nothing_more) | ||
3144 | 128 | throw std::logic_error{"Not ready for extraction."}; | ||
3145 | 129 | |||
3146 | 130 | struct Scope | ||
3147 | 131 | { | ||
3148 | 132 | Scope(Scanner& scanner) : scanner{scanner} {} | ||
3149 | 133 | ~Scope() { scanner.reset(); } | ||
3150 | 134 | |||
3151 | 135 | Scanner& scanner; | ||
3152 | 136 | } scope{*this}; | ||
3153 | 137 | |||
3154 | 138 | if (checksum() != ((checksum_1 << 8) | checksum_2)) | ||
3155 | 139 | throw std::runtime_error("Failed to verify sirf protocol message integrity."); | ||
3156 | 140 | |||
3157 | 141 | switch (message_id) | ||
3158 | 142 | { | ||
3159 | 143 | case GeodeticNavigationData::id: | ||
3160 | 144 | return decode_message<GeodeticNavigationData>(payload); | ||
3161 | 145 | default: | ||
3162 | 146 | break; | ||
3163 | 147 | } | ||
3164 | 148 | |||
3165 | 149 | return Message{Null{}}; | ||
3166 | 150 | } | ||
3167 | 151 | |||
3168 | 152 | void sirf::Scanner::reset() | ||
3169 | 153 | { | ||
3170 | 154 | checksum = Checksum{}; | ||
3171 | 155 | next = Expect::sync_char_begin_1; | ||
3172 | 156 | expected_size = 0; | ||
3173 | 157 | message_id = 0; | ||
3174 | 158 | payload.clear(); | ||
3175 | 159 | payload_iterator = payload.end(); | ||
3176 | 160 | checksum_1 = checksum_2 = 0; | ||
3177 | 161 | } | ||
3178 | 0 | 162 | ||
3179 | === added file 'src/location/providers/sirf/scanner.h' | |||
3180 | --- src/location/providers/sirf/scanner.h 1970-01-01 00:00:00 +0000 | |||
3181 | +++ src/location/providers/sirf/scanner.h 2017-05-05 09:37:41 +0000 | |||
3182 | @@ -0,0 +1,76 @@ | |||
3183 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
3184 | 2 | // | ||
3185 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3186 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3187 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3188 | 6 | // (at your option) any later version. | ||
3189 | 7 | // | ||
3190 | 8 | // This program is distributed in the hope that it will be useful, | ||
3191 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3192 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3193 | 11 | // GNU General Public License for more details. | ||
3194 | 12 | // | ||
3195 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3196 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3197 | 15 | |||
3198 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_SCANNER_H_ | ||
3199 | 17 | #define LOCATION_PROVIDERS_SIRF_SCANNER_H_ | ||
3200 | 18 | |||
3201 | 19 | #include <location/providers/sirf/checksum.h> | ||
3202 | 20 | #include <location/providers/sirf/message.h> | ||
3203 | 21 | |||
3204 | 22 | #include <cstdint> | ||
3205 | 23 | #include <tuple> | ||
3206 | 24 | #include <vector> | ||
3207 | 25 | |||
3208 | 26 | namespace location | ||
3209 | 27 | { | ||
3210 | 28 | namespace providers | ||
3211 | 29 | { | ||
3212 | 30 | namespace sirf | ||
3213 | 31 | { | ||
3214 | 32 | |||
3215 | 33 | class Scanner | ||
3216 | 34 | { | ||
3217 | 35 | public: | ||
3218 | 36 | /// @brief Expect enumerates the different states of the scanner/parser. | ||
3219 | 37 | enum class Expect | ||
3220 | 38 | { | ||
3221 | 39 | sync_char_begin_1, | ||
3222 | 40 | sync_char_begin_2, | ||
3223 | 41 | length_1, | ||
3224 | 42 | length_2, | ||
3225 | 43 | message_id, | ||
3226 | 44 | payload, | ||
3227 | 45 | checksum_1, | ||
3228 | 46 | checksum_2, | ||
3229 | 47 | sync_char_end_1, | ||
3230 | 48 | sync_char_end_2, | ||
3231 | 49 | nothing_more | ||
3232 | 50 | }; | ||
3233 | 51 | |||
3234 | 52 | Scanner(); | ||
3235 | 53 | |||
3236 | 54 | std::tuple<Expect, bool> update(std::uint8_t c); | ||
3237 | 55 | |||
3238 | 56 | Message finalize(); | ||
3239 | 57 | |||
3240 | 58 | private: | ||
3241 | 59 | |||
3242 | 60 | void reset(); | ||
3243 | 61 | |||
3244 | 62 | Expect next; | ||
3245 | 63 | Checksum checksum; | ||
3246 | 64 | std::uint16_t expected_size; | ||
3247 | 65 | std::uint8_t message_id; | ||
3248 | 66 | std::vector<uint8_t> payload; | ||
3249 | 67 | std::vector<uint8_t>::iterator payload_iterator; | ||
3250 | 68 | std::uint8_t checksum_1; | ||
3251 | 69 | std::uint8_t checksum_2; | ||
3252 | 70 | }; | ||
3253 | 71 | |||
3254 | 72 | } | ||
3255 | 73 | } | ||
3256 | 74 | } | ||
3257 | 75 | |||
3258 | 76 | #endif // LOCATION_PROVIDERS_SIRF_SCANNER_H_ | ||
3259 | 0 | 77 | ||
3260 | === added file 'src/location/providers/sirf/serial_port_receiver.cpp' | |||
3261 | --- src/location/providers/sirf/serial_port_receiver.cpp 1970-01-01 00:00:00 +0000 | |||
3262 | +++ src/location/providers/sirf/serial_port_receiver.cpp 2017-05-05 09:37:41 +0000 | |||
3263 | @@ -0,0 +1,80 @@ | |||
3264 | 1 | #include <location/providers/sirf/serial_port_receiver.h> | ||
3265 | 2 | |||
3266 | 3 | #include <location/logging.h> | ||
3267 | 4 | |||
3268 | 5 | #include <iostream> | ||
3269 | 6 | #include <system_error> | ||
3270 | 7 | |||
3271 | 8 | namespace sirf = location::providers::sirf; | ||
3272 | 9 | |||
3273 | 10 | std::shared_ptr<sirf::SerialPortReceiver> sirf::SerialPortReceiver::create( | ||
3274 | 11 | boost::asio::io_service& ios, const boost::filesystem::path& dev, const std::shared_ptr<Monitor>& monitor) | ||
3275 | 12 | { | ||
3276 | 13 | return std::shared_ptr<SerialPortReceiver>{new SerialPortReceiver{ios, dev, monitor}}; | ||
3277 | 14 | } | ||
3278 | 15 | |||
3279 | 16 | sirf::SerialPortReceiver::SerialPortReceiver(boost::asio::io_service& ios, const boost::filesystem::path& dev, | ||
3280 | 17 | const std::shared_ptr<Monitor>& monitor) | ||
3281 | 18 | : Receiver{monitor}, ios{ios}, serial_port{ios, dev.string().c_str()} | ||
3282 | 19 | { | ||
3283 | 20 | serial_port.set_option(boost::asio::serial_port::baud_rate(4800)); | ||
3284 | 21 | serial_port.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::one)); | ||
3285 | 22 | serial_port.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::none)); | ||
3286 | 23 | serial_port.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::none)); | ||
3287 | 24 | } | ||
3288 | 25 | |||
3289 | 26 | void sirf::SerialPortReceiver::send_encoded_message(const std::vector<std::uint8_t>& data) | ||
3290 | 27 | { | ||
3291 | 28 | auto thiz = shared_from_this(); | ||
3292 | 29 | std::weak_ptr<SerialPortReceiver> wp{thiz}; | ||
3293 | 30 | |||
3294 | 31 | ios.dispatch([this, wp, data]() | ||
3295 | 32 | { | ||
3296 | 33 | if (auto sp = wp.lock()) | ||
3297 | 34 | boost::asio::write(serial_port, boost::asio::buffer(data), boost::asio::transfer_all()); | ||
3298 | 35 | }); | ||
3299 | 36 | } | ||
3300 | 37 | |||
3301 | 38 | void sirf::SerialPortReceiver::start() | ||
3302 | 39 | { | ||
3303 | 40 | ::tcflush(serial_port.lowest_layer().native_handle(), TCIFLUSH); | ||
3304 | 41 | start_read(); | ||
3305 | 42 | } | ||
3306 | 43 | |||
3307 | 44 | void sirf::SerialPortReceiver::stop() | ||
3308 | 45 | { | ||
3309 | 46 | serial_port.cancel(); | ||
3310 | 47 | } | ||
3311 | 48 | |||
3312 | 49 | void sirf::SerialPortReceiver::start_read() | ||
3313 | 50 | { | ||
3314 | 51 | auto thiz = shared_from_this(); | ||
3315 | 52 | std::weak_ptr<SerialPortReceiver> wp{thiz}; | ||
3316 | 53 | |||
3317 | 54 | boost::asio::async_read(serial_port, boost::asio::buffer(&buffer.front(), buffer.size()), | ||
3318 | 55 | [this, wp](const boost::system::error_code& ec, std::size_t transferred) { | ||
3319 | 56 | if (ec == boost::asio::error::operation_aborted) | ||
3320 | 57 | return; | ||
3321 | 58 | |||
3322 | 59 | if (auto sp = wp.lock()) | ||
3323 | 60 | { | ||
3324 | 61 | if (not ec) | ||
3325 | 62 | { | ||
3326 | 63 | try | ||
3327 | 64 | { | ||
3328 | 65 | process_chunk(buffer.begin(), buffer.begin() + transferred); | ||
3329 | 66 | } | ||
3330 | 67 | catch(const std::exception& e) | ||
3331 | 68 | { | ||
3332 | 69 | LOG(WARNING) << "Error processing data chunk: " << e.what(); | ||
3333 | 70 | } | ||
3334 | 71 | catch(...) | ||
3335 | 72 | { | ||
3336 | 73 | LOG(WARNING) << "Error processing data chunk."; | ||
3337 | 74 | } | ||
3338 | 75 | |||
3339 | 76 | start_read(); | ||
3340 | 77 | } | ||
3341 | 78 | } | ||
3342 | 79 | }); | ||
3343 | 80 | } | ||
3344 | 0 | 81 | ||
3345 | === added file 'src/location/providers/sirf/serial_port_receiver.h' | |||
3346 | --- src/location/providers/sirf/serial_port_receiver.h 1970-01-01 00:00:00 +0000 | |||
3347 | +++ src/location/providers/sirf/serial_port_receiver.h 2017-05-05 09:37:41 +0000 | |||
3348 | @@ -0,0 +1,79 @@ | |||
3349 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
3350 | 2 | // | ||
3351 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3352 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3353 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3354 | 6 | // (at your option) any later version. | ||
3355 | 7 | // | ||
3356 | 8 | // This program is distributed in the hope that it will be useful, | ||
3357 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3358 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3359 | 11 | // GNU General Public License for more details. | ||
3360 | 12 | // | ||
3361 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3362 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3363 | 15 | #ifndef LOCATION_PROVIDERS_SIRF_SERIAL_PORT_RECEIVER_H_ | ||
3364 | 16 | #define LOCATION_PROVIDERS_SIRF_SERIAL_PORT_RECEIVER_H_ | ||
3365 | 17 | |||
3366 | 18 | #include <location/providers/sirf/receiver.h> | ||
3367 | 19 | |||
3368 | 20 | #include <boost/asio.hpp> | ||
3369 | 21 | #include <boost/filesystem.hpp> | ||
3370 | 22 | |||
3371 | 23 | #include <array> | ||
3372 | 24 | #include <atomic> | ||
3373 | 25 | |||
3374 | 26 | namespace location | ||
3375 | 27 | { | ||
3376 | 28 | namespace providers | ||
3377 | 29 | { | ||
3378 | 30 | namespace sirf | ||
3379 | 31 | { | ||
3380 | 32 | |||
3381 | 33 | /// @brief SerialPortReceiver connects to a ublox 8 GNSS receiver over a serial | ||
3382 | 34 | /// port. | ||
3383 | 35 | class SerialPortReceiver : public Receiver, public std::enable_shared_from_this<SerialPortReceiver> | ||
3384 | 36 | { | ||
3385 | 37 | public: | ||
3386 | 38 | /// @brief create returns a new Receiver instance connected to the | ||
3387 | 39 | /// serial port reachable under dev. | ||
3388 | 40 | static std::shared_ptr<SerialPortReceiver> create(boost::asio::io_service& ios, const boost::filesystem::path& dev, | ||
3389 | 41 | const std::shared_ptr<Receiver::Monitor>& monitor); | ||
3390 | 42 | |||
3391 | 43 | void start(); | ||
3392 | 44 | void stop(); | ||
3393 | 45 | |||
3394 | 46 | void send_encoded_message(const std::vector<std::uint8_t>& data) override; | ||
3395 | 47 | |||
3396 | 48 | private: | ||
3397 | 49 | enum class State | ||
3398 | 50 | { | ||
3399 | 51 | running, | ||
3400 | 52 | stopped | ||
3401 | 53 | }; | ||
3402 | 54 | |||
3403 | 55 | /// @brief Receiver initializes a new instance opening the serial port | ||
3404 | 56 | /// located at path. | ||
3405 | 57 | /// | ||
3406 | 58 | /// Throws in case of issues. | ||
3407 | 59 | SerialPortReceiver(boost::asio::io_service& ios, const boost::filesystem::path& dev, | ||
3408 | 60 | const std::shared_ptr<Receiver::Monitor>& monitor); | ||
3409 | 61 | |||
3410 | 62 | /// @brief finalize returns a finalized reader instance reading from | ||
3411 | 63 | /// the serial port. | ||
3412 | 64 | std::shared_ptr<SerialPortReceiver> finalize(); | ||
3413 | 65 | |||
3414 | 66 | /// @brief start_read starts an async read operation from the configured | ||
3415 | 67 | /// serial port. | ||
3416 | 68 | void start_read(); | ||
3417 | 69 | |||
3418 | 70 | Receiver::Buffer buffer; | ||
3419 | 71 | boost::asio::io_service& ios; | ||
3420 | 72 | boost::asio::serial_port serial_port; | ||
3421 | 73 | }; | ||
3422 | 74 | |||
3423 | 75 | } | ||
3424 | 76 | } | ||
3425 | 77 | } | ||
3426 | 78 | |||
3427 | 79 | #endif // LOCATION_PROVIDERS_SIRF_SERIAL_PORT_RECEIVER_H_ | ||
3428 | 0 | 80 | ||
3429 | === added file 'src/location/providers/sirf/set_protocol.h' | |||
3430 | --- src/location/providers/sirf/set_protocol.h 1970-01-01 00:00:00 +0000 | |||
3431 | +++ src/location/providers/sirf/set_protocol.h 2017-05-05 09:37:41 +0000 | |||
3432 | @@ -0,0 +1,73 @@ | |||
3433 | 1 | // Copyright (C) 2017 Thomas Voss <thomas.voss@canonical.com> | ||
3434 | 2 | // | ||
3435 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3436 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3437 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3438 | 6 | // (at your option) any later version. | ||
3439 | 7 | // | ||
3440 | 8 | // This program is distributed in the hope that it will be useful, | ||
3441 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3442 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3443 | 11 | // GNU General Public License for more details. | ||
3444 | 12 | // | ||
3445 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3446 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3447 | 15 | |||
3448 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_SET_PROTOCOL_H_ | ||
3449 | 17 | #define LOCATION_PROVIDERS_SIRF_SET_PROTOCOL_H_ | ||
3450 | 18 | |||
3451 | 19 | #include <location/providers/sirf/writer.h> | ||
3452 | 20 | |||
3453 | 21 | #include <cstdint> | ||
3454 | 22 | #include <iostream> | ||
3455 | 23 | |||
3456 | 24 | namespace location | ||
3457 | 25 | { | ||
3458 | 26 | namespace providers | ||
3459 | 27 | { | ||
3460 | 28 | namespace sirf | ||
3461 | 29 | { | ||
3462 | 30 | |||
3463 | 31 | // Switches the protocol to another protocol. For most software, | ||
3464 | 32 | // the default protocol is SiRF binary. | ||
3465 | 33 | struct SetProtocol | ||
3466 | 34 | { | ||
3467 | 35 | enum | ||
3468 | 36 | { | ||
3469 | 37 | null = 0, | ||
3470 | 38 | sirf_binary = 1, | ||
3471 | 39 | nmea = 2, | ||
3472 | 40 | ascii = 3, | ||
3473 | 41 | rtcm = 4, | ||
3474 | 42 | user1 = 5, | ||
3475 | 43 | sirf_loc = 6, | ||
3476 | 44 | statistic = 7 | ||
3477 | 45 | }; | ||
3478 | 46 | |||
3479 | 47 | static constexpr std::uint8_t id{0x87}; | ||
3480 | 48 | |||
3481 | 49 | std::size_t size() const | ||
3482 | 50 | { | ||
3483 | 51 | return sizeof(std::uint8_t) + sizeof(std::uint8_t); | ||
3484 | 52 | } | ||
3485 | 53 | |||
3486 | 54 | void write(Writer& writer) const | ||
3487 | 55 | { | ||
3488 | 56 | writer.write_unsigned_char(id); | ||
3489 | 57 | writer.write_unsigned_char(protocol); | ||
3490 | 58 | } | ||
3491 | 59 | |||
3492 | 60 | std::uint8_t protocol; | ||
3493 | 61 | }; | ||
3494 | 62 | |||
3495 | 63 | inline std::ostream& operator<<(std::ostream& out, const SetProtocol& sp) | ||
3496 | 64 | { | ||
3497 | 65 | return out << "SetProtocol:" << std::endl | ||
3498 | 66 | << " protocol: " << sp.protocol; | ||
3499 | 67 | } | ||
3500 | 68 | |||
3501 | 69 | } // namespace sirf | ||
3502 | 70 | } // namespace providers | ||
3503 | 71 | } // namespace location | ||
3504 | 72 | |||
3505 | 73 | #endif // LOCATION_PROVIDERS_SIRF_SET_PROTOCOL_H_ | ||
3506 | 0 | 74 | ||
3507 | === added file 'src/location/providers/sirf/writer.cpp' | |||
3508 | --- src/location/providers/sirf/writer.cpp 1970-01-01 00:00:00 +0000 | |||
3509 | +++ src/location/providers/sirf/writer.cpp 2017-05-05 09:37:41 +0000 | |||
3510 | @@ -0,0 +1,94 @@ | |||
3511 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
3512 | 2 | // | ||
3513 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3514 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3515 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3516 | 6 | // (at your option) any later version. | ||
3517 | 7 | // | ||
3518 | 8 | // This program is distributed in the hope that it will be useful, | ||
3519 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3520 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3521 | 11 | // GNU General Public License for more details. | ||
3522 | 12 | // | ||
3523 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3524 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3525 | 15 | |||
3526 | 16 | #include <location/providers/sirf/writer.h> | ||
3527 | 17 | |||
3528 | 18 | #include <arpa/inet.h> | ||
3529 | 19 | |||
3530 | 20 | #include <cstring> | ||
3531 | 21 | #include <stdexcept> | ||
3532 | 22 | |||
3533 | 23 | namespace sirf = location::providers::sirf; | ||
3534 | 24 | |||
3535 | 25 | sirf::Writer::Writer(std::vector<std::uint8_t>::iterator begin, | ||
3536 | 26 | std::vector<std::uint8_t>::iterator end) | ||
3537 | 27 | : begin{begin}, current{begin}, end{end} {} | ||
3538 | 28 | |||
3539 | 29 | void sirf::Writer::write_unsigned_char(std::uint8_t value) | ||
3540 | 30 | { | ||
3541 | 31 | if (current + sizeof(value) > end) | ||
3542 | 32 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3543 | 33 | |||
3544 | 34 | *reinterpret_cast<std::uint8_t*>(&(*current)) = value; | ||
3545 | 35 | current += sizeof(value); | ||
3546 | 36 | |||
3547 | 37 | } | ||
3548 | 38 | |||
3549 | 39 | void sirf::Writer::write_signed_char(std::int8_t value) | ||
3550 | 40 | { | ||
3551 | 41 | if (current + sizeof(value) > end) | ||
3552 | 42 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3553 | 43 | |||
3554 | 44 | *reinterpret_cast<std::int8_t*>(&(*current)) = value; | ||
3555 | 45 | current += sizeof(value); | ||
3556 | 46 | |||
3557 | 47 | } | ||
3558 | 48 | |||
3559 | 49 | void sirf::Writer::write_unsigned_short(std::uint16_t value) | ||
3560 | 50 | { | ||
3561 | 51 | if (current + sizeof(value) > end) | ||
3562 | 52 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3563 | 53 | |||
3564 | 54 | *reinterpret_cast<std::uint16_t*>(&(*current)) = ::ntohs(value); | ||
3565 | 55 | current += sizeof(value); | ||
3566 | 56 | } | ||
3567 | 57 | |||
3568 | 58 | void sirf::Writer::write_signed_short(std::int16_t value) | ||
3569 | 59 | { | ||
3570 | 60 | if (current + sizeof(value) > end) | ||
3571 | 61 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3572 | 62 | |||
3573 | 63 | *reinterpret_cast<std::int16_t*>(&(*current)) = ::ntohs(value); | ||
3574 | 64 | current += sizeof(value); | ||
3575 | 65 | } | ||
3576 | 66 | |||
3577 | 67 | void sirf::Writer::write_unsigned_long(std::uint32_t value) | ||
3578 | 68 | { | ||
3579 | 69 | if (current + sizeof(value) > end) | ||
3580 | 70 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3581 | 71 | |||
3582 | 72 | *reinterpret_cast<std::uint32_t*>(&(*current)) = ::ntohl(value); | ||
3583 | 73 | current += sizeof(value); | ||
3584 | 74 | } | ||
3585 | 75 | |||
3586 | 76 | void sirf::Writer::write_signed_long(std::int32_t value) | ||
3587 | 77 | { | ||
3588 | 78 | if (current + sizeof(value) > end) | ||
3589 | 79 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3590 | 80 | |||
3591 | 81 | *reinterpret_cast<std::int32_t*>(&(*current)) = ::ntohl(value); | ||
3592 | 82 | current += sizeof(value); | ||
3593 | 83 | } | ||
3594 | 84 | |||
3595 | 85 | sirf::Writer sirf::Writer::slice(std::size_t size) | ||
3596 | 86 | { | ||
3597 | 87 | if (current + size > end) | ||
3598 | 88 | throw std::out_of_range{"Write buffer exhausted"}; | ||
3599 | 89 | |||
3600 | 90 | Writer result{current, current + size}; | ||
3601 | 91 | current += size; | ||
3602 | 92 | |||
3603 | 93 | return result; | ||
3604 | 94 | } | ||
3605 | 0 | 95 | ||
3606 | === added file 'src/location/providers/sirf/writer.h' | |||
3607 | --- src/location/providers/sirf/writer.h 1970-01-01 00:00:00 +0000 | |||
3608 | +++ src/location/providers/sirf/writer.h 2017-05-05 09:37:41 +0000 | |||
3609 | @@ -0,0 +1,54 @@ | |||
3610 | 1 | // Copyright (C) 2016 Thomas Voss <thomas.voss.bochum@gmail.com> | ||
3611 | 2 | // | ||
3612 | 3 | // This library is free software: you can redistribute it and/or modify | ||
3613 | 4 | // it under the terms of the GNU Lesser General Public License as published | ||
3614 | 5 | // by the Free Software Foundation, either version 3 of the License, or | ||
3615 | 6 | // (at your option) any later version. | ||
3616 | 7 | // | ||
3617 | 8 | // This program is distributed in the hope that it will be useful, | ||
3618 | 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
3619 | 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
3620 | 11 | // GNU General Public License for more details. | ||
3621 | 12 | // | ||
3622 | 13 | // You should have received a copy of the GNU Lesser General Public License | ||
3623 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
3624 | 15 | |||
3625 | 16 | #ifndef LOCATION_PROVIDERS_SIRF_WRITER_H_ | ||
3626 | 17 | #define LOCATION_PROVIDERS_SIRF_WRITER_H_ | ||
3627 | 18 | |||
3628 | 19 | #include <cstdint> | ||
3629 | 20 | #include <vector> | ||
3630 | 21 | |||
3631 | 22 | namespace location | ||
3632 | 23 | { | ||
3633 | 24 | namespace providers | ||
3634 | 25 | { | ||
3635 | 26 | namespace sirf | ||
3636 | 27 | { | ||
3637 | 28 | |||
3638 | 29 | class Writer | ||
3639 | 30 | { | ||
3640 | 31 | public: | ||
3641 | 32 | explicit Writer(std::vector<std::uint8_t>::iterator begin, | ||
3642 | 33 | std::vector<std::uint8_t>::iterator end); | ||
3643 | 34 | |||
3644 | 35 | void write_unsigned_char(std::uint8_t value); | ||
3645 | 36 | void write_signed_char(std::int8_t value); | ||
3646 | 37 | void write_unsigned_short(std::uint16_t value); | ||
3647 | 38 | void write_signed_short(std::int16_t value); | ||
3648 | 39 | void write_unsigned_long(std::uint32_t value); | ||
3649 | 40 | void write_signed_long(std::int32_t value); | ||
3650 | 41 | |||
3651 | 42 | Writer slice(std::size_t size); | ||
3652 | 43 | |||
3653 | 44 | private: | ||
3654 | 45 | std::vector<std::uint8_t>::iterator begin; | ||
3655 | 46 | std::vector<std::uint8_t>::iterator current; | ||
3656 | 47 | std::vector<std::uint8_t>::iterator end; | ||
3657 | 48 | }; | ||
3658 | 49 | |||
3659 | 50 | } // namespace sirf | ||
3660 | 51 | } // namespace providers | ||
3661 | 52 | } // namespace location | ||
3662 | 53 | |||
3663 | 54 | #endif // LOCATION_PROVIDERS_SIRF_WRITER_H_ | ||
3664 | 0 | 55 | ||
3665 | === modified file 'src/location/providers/ubx/CMakeLists.txt' | |||
3666 | --- src/location/providers/ubx/CMakeLists.txt 2017-03-23 12:32:38 +0000 | |||
3667 | +++ src/location/providers/ubx/CMakeLists.txt 2017-05-05 09:37:41 +0000 | |||
3668 | @@ -37,11 +37,14 @@ | |||
3669 | 37 | _8/nav/pvt.cpp | 37 | _8/nav/pvt.cpp |
3670 | 38 | _8/nav/sat.h | 38 | _8/nav/sat.h |
3671 | 39 | _8/nav/sat.cpp | 39 | _8/nav/sat.cpp |
3672 | 40 | _8/nmea/scanner.cpp | ||
3673 | 41 | _8/nmea/sentence.cpp | ||
3674 | 42 | 40 | ||
3675 | 43 | provider.h provider.cpp) | 41 | provider.h provider.cpp) |
3676 | 44 | 42 | ||
3677 | 43 | target_link_libraries( | ||
3678 | 44 | ubx | ||
3679 | 45 | |||
3680 | 46 | nmea) | ||
3681 | 47 | |||
3682 | 45 | set( | 48 | set( |
3683 | 46 | ENABLED_PROVIDER_TARGETS | 49 | ENABLED_PROVIDER_TARGETS |
3684 | 47 | ${ENABLED_PROVIDER_TARGETS} ubx | 50 | ${ENABLED_PROVIDER_TARGETS} ubx |
3685 | 48 | 51 | ||
3686 | === modified file 'src/location/providers/ubx/_8/receiver.cpp' | |||
3687 | --- src/location/providers/ubx/_8/receiver.cpp 2017-03-23 15:47:38 +0000 | |||
3688 | +++ src/location/providers/ubx/_8/receiver.cpp 2017-05-05 09:37:41 +0000 | |||
3689 | @@ -1,6 +1,6 @@ | |||
3690 | 1 | #include <location/providers/ubx/_8/receiver.h> | 1 | #include <location/providers/ubx/_8/receiver.h> |
3691 | 2 | 2 | ||
3693 | 3 | #include <location/providers/ubx/_8/nmea/sentence.h> | 3 | #include <location/nmea/sentence.h> |
3694 | 4 | 4 | ||
3695 | 5 | #include <iostream> | 5 | #include <iostream> |
3696 | 6 | 6 | ||
3697 | 7 | 7 | ||
3698 | === modified file 'src/location/providers/ubx/_8/receiver.h' | |||
3699 | --- src/location/providers/ubx/_8/receiver.h 2017-03-24 21:13:53 +0000 | |||
3700 | +++ src/location/providers/ubx/_8/receiver.h 2017-05-05 09:37:41 +0000 | |||
3701 | @@ -20,8 +20,8 @@ | |||
3702 | 20 | #include <location/providers/ubx/_8/message.h> | 20 | #include <location/providers/ubx/_8/message.h> |
3703 | 21 | #include <location/providers/ubx/_8/scanner.h> | 21 | #include <location/providers/ubx/_8/scanner.h> |
3704 | 22 | 22 | ||
3707 | 23 | #include <location/providers/ubx/_8/nmea/scanner.h> | 23 | #include <location/nmea/scanner.h> |
3708 | 24 | #include <location/providers/ubx/_8/nmea/sentence.h> | 24 | #include <location/nmea/sentence.h> |
3709 | 25 | 25 | ||
3710 | 26 | #include <memory> | 26 | #include <memory> |
3711 | 27 | 27 | ||
3712 | @@ -60,7 +60,7 @@ | |||
3713 | 60 | 60 | ||
3714 | 61 | /// @brief on_new_nmea_sentence is invoked for every complete and parsed | 61 | /// @brief on_new_nmea_sentence is invoked for every complete and parsed |
3715 | 62 | /// nmea sentence. | 62 | /// nmea sentence. |
3717 | 63 | virtual void on_new_nmea_sentence(const ubx::_8::nmea::Sentence& sentence) = 0; | 63 | virtual void on_new_nmea_sentence(const nmea::Sentence& sentence) = 0; |
3718 | 64 | }; | 64 | }; |
3719 | 65 | 65 | ||
3720 | 66 | /// @brief send_message encodes and sends 'message' to the receiver. | 66 | /// @brief send_message encodes and sends 'message' to the receiver. |
3721 | @@ -83,7 +83,7 @@ | |||
3722 | 83 | 83 | ||
3723 | 84 | private: | 84 | private: |
3724 | 85 | std::shared_ptr<Monitor> monitor; | 85 | std::shared_ptr<Monitor> monitor; |
3726 | 86 | ubx::_8::nmea::Scanner nmea_scanner; | 86 | nmea::Scanner nmea_scanner; |
3727 | 87 | ubx::_8::Scanner ubx_scanner; | 87 | ubx::_8::Scanner ubx_scanner; |
3728 | 88 | }; | 88 | }; |
3729 | 89 | 89 | ||
3730 | 90 | 90 | ||
3731 | === modified file 'src/location/providers/ubx/_8/scanner.cpp' | |||
3732 | --- src/location/providers/ubx/_8/scanner.cpp 2017-03-23 12:32:38 +0000 | |||
3733 | +++ src/location/providers/ubx/_8/scanner.cpp 2017-05-05 09:37:41 +0000 | |||
3734 | @@ -105,7 +105,7 @@ | |||
3735 | 105 | expected_size |= (c << 8); | 105 | expected_size |= (c << 8); |
3736 | 106 | payload.resize(expected_size); | 106 | payload.resize(expected_size); |
3737 | 107 | payload_iterator = payload.begin(); | 107 | payload_iterator = payload.begin(); |
3739 | 108 | next = Expect::payload; | 108 | next = expected_size > 0 ? Expect::payload : Expect::ck_a; |
3740 | 109 | consumed = true; | 109 | consumed = true; |
3741 | 110 | break; | 110 | break; |
3742 | 111 | case Expect::payload: | 111 | case Expect::payload: |
3743 | 112 | 112 | ||
3744 | === modified file 'src/location/providers/ubx/provider.cpp' | |||
3745 | --- src/location/providers/ubx/provider.cpp 2017-04-21 07:16:45 +0000 | |||
3746 | +++ src/location/providers/ubx/provider.cpp 2017-05-05 09:37:41 +0000 | |||
3747 | @@ -80,7 +80,7 @@ | |||
3748 | 80 | } | 80 | } |
3749 | 81 | 81 | ||
3750 | 82 | 82 | ||
3752 | 83 | void ubx::Provider::Monitor::on_new_nmea_sentence(const _8::nmea::Sentence& sentence) | 83 | void ubx::Provider::Monitor::on_new_nmea_sentence(const nmea::Sentence& sentence) |
3753 | 84 | { | 84 | { |
3754 | 85 | VLOG(1) << sentence; | 85 | VLOG(1) << sentence; |
3755 | 86 | if (auto sp = provider.lock()) | 86 | if (auto sp = provider.lock()) |
3756 | @@ -88,7 +88,7 @@ | |||
3757 | 88 | boost::apply_visitor(*this, sentence); | 88 | boost::apply_visitor(*this, sentence); |
3758 | 89 | } | 89 | } |
3759 | 90 | 90 | ||
3761 | 91 | void ubx::Provider::Monitor::operator()(const _8::nmea::Gga& gga) | 91 | void ubx::Provider::Monitor::operator()(const nmea::Gga& gga) |
3762 | 92 | { | 92 | { |
3763 | 93 | if (gga.latitude && gga.longitude) | 93 | if (gga.latitude && gga.longitude) |
3764 | 94 | { | 94 | { |
3765 | @@ -159,32 +159,32 @@ | |||
3766 | 159 | }); | 159 | }); |
3767 | 160 | } | 160 | } |
3768 | 161 | 161 | ||
3795 | 162 | void ubx::Provider::Monitor::operator()(const _8::nmea::Gsa&) | 162 | void ubx::Provider::Monitor::operator()(const nmea::Gsa&) |
3796 | 163 | { | 163 | { |
3797 | 164 | // Empty on purpose | 164 | // Empty on purpose |
3798 | 165 | } | 165 | } |
3799 | 166 | 166 | ||
3800 | 167 | void ubx::Provider::Monitor::operator()(const _8::nmea::Gll&) | 167 | void ubx::Provider::Monitor::operator()(const nmea::Gll&) |
3801 | 168 | { | 168 | { |
3802 | 169 | // Empty on purpose | 169 | // Empty on purpose |
3803 | 170 | } | 170 | } |
3804 | 171 | 171 | ||
3805 | 172 | void ubx::Provider::Monitor::operator()(const _8::nmea::Gsv&) | 172 | void ubx::Provider::Monitor::operator()(const nmea::Gsv&) |
3806 | 173 | { | 173 | { |
3807 | 174 | // Empty on purpose | 174 | // Empty on purpose |
3808 | 175 | } | 175 | } |
3809 | 176 | 176 | ||
3810 | 177 | void ubx::Provider::Monitor::operator()(const _8::nmea::Rmc&) | 177 | void ubx::Provider::Monitor::operator()(const nmea::Rmc&) |
3811 | 178 | { | 178 | { |
3812 | 179 | // Empty on purpose | 179 | // Empty on purpose |
3813 | 180 | } | 180 | } |
3814 | 181 | 181 | ||
3815 | 182 | void ubx::Provider::Monitor::operator()(const _8::nmea::Txt&) | 182 | void ubx::Provider::Monitor::operator()(const nmea::Txt&) |
3816 | 183 | { | 183 | { |
3817 | 184 | // Empty on purpose | 184 | // Empty on purpose |
3818 | 185 | } | 185 | } |
3819 | 186 | 186 | ||
3820 | 187 | void ubx::Provider::Monitor::operator()(const _8::nmea::Vtg& vtg) | 187 | void ubx::Provider::Monitor::operator()(const nmea::Vtg& vtg) |
3821 | 188 | { | 188 | { |
3822 | 189 | auto thiz = shared_from_this(); | 189 | auto thiz = shared_from_this(); |
3823 | 190 | std::weak_ptr<ubx::Provider::Monitor> wp{thiz}; | 190 | std::weak_ptr<ubx::Provider::Monitor> wp{thiz}; |
3824 | 191 | 191 | ||
3825 | === modified file 'src/location/providers/ubx/provider.h' | |||
3826 | --- src/location/providers/ubx/provider.h 2017-04-21 07:16:45 +0000 | |||
3827 | +++ src/location/providers/ubx/provider.h 2017-05-05 09:37:41 +0000 | |||
3828 | @@ -21,7 +21,7 @@ | |||
3829 | 21 | #include <location/provider.h> | 21 | #include <location/provider.h> |
3830 | 22 | #include <location/provider_factory.h> | 22 | #include <location/provider_factory.h> |
3831 | 23 | #include <location/runtime.h> | 23 | #include <location/runtime.h> |
3833 | 24 | 24 | #include <location/nmea/sentence.h> | |
3834 | 25 | #include <location/providers/ubx/_8/assist_now_online_client.h> | 25 | #include <location/providers/ubx/_8/assist_now_online_client.h> |
3835 | 26 | #include <location/providers/ubx/_8/serial_port_receiver.h> | 26 | #include <location/providers/ubx/_8/serial_port_receiver.h> |
3836 | 27 | 27 | ||
3837 | @@ -104,20 +104,20 @@ | |||
3838 | 104 | { | 104 | { |
3839 | 105 | // From Receiver::Monitor | 105 | // From Receiver::Monitor |
3840 | 106 | void on_new_ubx_message(const _8::Message& message) override; | 106 | void on_new_ubx_message(const _8::Message& message) override; |
3842 | 107 | void on_new_nmea_sentence(const _8::nmea::Sentence& sentence) override; | 107 | void on_new_nmea_sentence(const nmea::Sentence& sentence) override; |
3843 | 108 | 108 | ||
3844 | 109 | template<typename T> | 109 | template<typename T> |
3845 | 110 | void operator()(const T&) const {} | 110 | void operator()(const T&) const {} |
3846 | 111 | 111 | ||
3847 | 112 | void operator()(const _8::nav::Pvt& pvt); | 112 | void operator()(const _8::nav::Pvt& pvt); |
3848 | 113 | 113 | ||
3856 | 114 | void operator()(const _8::nmea::Gga& gga); | 114 | void operator()(const nmea::Gga& gga); |
3857 | 115 | void operator()(const _8::nmea::Gsa& gsa); | 115 | void operator()(const nmea::Gsa& gsa); |
3858 | 116 | void operator()(const _8::nmea::Gll& gll); | 116 | void operator()(const nmea::Gll& gll); |
3859 | 117 | void operator()(const _8::nmea::Gsv& gsv); | 117 | void operator()(const nmea::Gsv& gsv); |
3860 | 118 | void operator()(const _8::nmea::Rmc& rmc); | 118 | void operator()(const nmea::Rmc& rmc); |
3861 | 119 | void operator()(const _8::nmea::Txt& txt); | 119 | void operator()(const nmea::Txt& txt); |
3862 | 120 | void operator()(const _8::nmea::Vtg& vtg); | 120 | void operator()(const nmea::Vtg& vtg); |
3863 | 121 | 121 | ||
3864 | 122 | std::weak_ptr<Provider> provider; | 122 | std::weak_ptr<Provider> provider; |
3865 | 123 | }; | 123 | }; |
3866 | 124 | 124 | ||
3867 | === modified file 'src/location/runtime_tests.cpp' | |||
3868 | --- src/location/runtime_tests.cpp 2017-04-03 07:32:40 +0000 | |||
3869 | +++ src/location/runtime_tests.cpp 2017-05-05 09:37:41 +0000 | |||
3870 | @@ -22,6 +22,7 @@ | |||
3871 | 22 | #include <location/clock.h> | 22 | #include <location/clock.h> |
3872 | 23 | #include <location/glib/runtime.h> | 23 | #include <location/glib/runtime.h> |
3873 | 24 | #include <location/providers/gps/hardware_abstraction_layer.h> | 24 | #include <location/providers/gps/hardware_abstraction_layer.h> |
3874 | 25 | #include <location/providers/sirf/provider.h> | ||
3875 | 25 | #include <location/providers/ubx/provider.h> | 26 | #include <location/providers/ubx/provider.h> |
3876 | 26 | #include <location/util/benchmark.h> | 27 | #include <location/util/benchmark.h> |
3877 | 27 | #include <location/util/cli.h> | 28 | #include <location/util/cli.h> |
3878 | @@ -251,12 +252,98 @@ | |||
3879 | 251 | return 0; | 252 | return 0; |
3880 | 252 | } | 253 | } |
3881 | 253 | 254 | ||
3882 | 255 | int sirf(std::ostream& cout, std::ostream&) | ||
3883 | 256 | { | ||
3884 | 257 | location::util::Benchmark benchmark{boost::lexical_cast<unsigned int>(env::get("SIRF_PROVIDER_TEST_TRIALS", "15")), "ttff in [µs]"}; | ||
3885 | 258 | |||
3886 | 259 | auto test_device = env::get_or_throw("SIRF_PROVIDER_TEST_DEVICE"); | ||
3887 | 260 | |||
3888 | 261 | location::providers::sirf::Provider::Configuration configuration | ||
3889 | 262 | { | ||
3890 | 263 | location::providers::sirf::Provider::Protocol::sirf, test_device | ||
3891 | 264 | }; | ||
3892 | 265 | |||
3893 | 266 | auto provider = location::providers::sirf::Provider::create(configuration); | ||
3894 | 267 | |||
3895 | 268 | struct State | ||
3896 | 269 | { | ||
3897 | 270 | State() : worker{[this]() { runtime.run(); }}, fix_received(false) | ||
3898 | 271 | { | ||
3899 | 272 | } | ||
3900 | 273 | |||
3901 | 274 | ~State() | ||
3902 | 275 | { | ||
3903 | 276 | runtime.stop(); | ||
3904 | 277 | if (worker.joinable()) | ||
3905 | 278 | worker.join(); | ||
3906 | 279 | } | ||
3907 | 280 | |||
3908 | 281 | bool wait_for_fix_for(const std::chrono::seconds& seconds) | ||
3909 | 282 | { | ||
3910 | 283 | std::unique_lock<std::mutex> ul(guard); | ||
3911 | 284 | return wait_condition.wait_for( | ||
3912 | 285 | ul, | ||
3913 | 286 | seconds, | ||
3914 | 287 | [this]() {return fix_received == true;}); | ||
3915 | 288 | } | ||
3916 | 289 | |||
3917 | 290 | void on_position_updated(const location::Position&) | ||
3918 | 291 | { | ||
3919 | 292 | fix_received = true; | ||
3920 | 293 | wait_condition.notify_all(); | ||
3921 | 294 | } | ||
3922 | 295 | |||
3923 | 296 | void reset() | ||
3924 | 297 | { | ||
3925 | 298 | fix_received = false; | ||
3926 | 299 | } | ||
3927 | 300 | |||
3928 | 301 | location::glib::Runtime runtime{location::glib::Runtime::WithOwnMainLoop{}}; | ||
3929 | 302 | std::thread worker; | ||
3930 | 303 | std::mutex guard; | ||
3931 | 304 | std::condition_variable wait_condition; | ||
3932 | 305 | bool fix_received; | ||
3933 | 306 | } state; | ||
3934 | 307 | |||
3935 | 308 | provider->position_updates().connect([&state](const location::Update<location::Position>& update) | ||
3936 | 309 | { | ||
3937 | 310 | state.on_position_updated(update.value); | ||
3938 | 311 | }); | ||
3939 | 312 | |||
3940 | 313 | { | ||
3941 | 314 | cli::ProgressBar pb(cout, "sirf runtime test: ", 30); | ||
3942 | 315 | |||
3943 | 316 | benchmark.run( | ||
3944 | 317 | [&](std::size_t) | ||
3945 | 318 | { | ||
3946 | 319 | provider->reset(); state.reset(); | ||
3947 | 320 | }, | ||
3948 | 321 | [&](std::size_t trial) | ||
3949 | 322 | { | ||
3950 | 323 | pb.update(trial / static_cast<double>(benchmark.trials())); | ||
3951 | 324 | |||
3952 | 325 | provider->activate(); | ||
3953 | 326 | // We expect a maximum cold start time of 15 minutes. The theoretical | ||
3954 | 327 | // limit is 12.5 minutes, and we add up some grace period to make the | ||
3955 | 328 | // test more robust (see http://en.wikipedia.org/wiki/Time_to_first_fix). | ||
3956 | 329 | expect<true, std::runtime_error>(state.wait_for_fix_for(std::chrono::seconds{15 * 60}), "Wait for fix timed out."); | ||
3957 | 330 | provider->deactivate(); | ||
3958 | 331 | }); | ||
3959 | 332 | } | ||
3960 | 333 | |||
3961 | 334 | cout << benchmark << std::endl; | ||
3962 | 335 | |||
3963 | 336 | return 0; | ||
3964 | 337 | } | ||
3965 | 338 | |||
3966 | 254 | } // namespace | 339 | } // namespace |
3967 | 255 | 340 | ||
3968 | 256 | int location::execute_runtime_tests(const std::string& test_suite, std::ostream& cout, std::ostream& cerr) | 341 | int location::execute_runtime_tests(const std::string& test_suite, std::ostream& cout, std::ostream& cerr) |
3969 | 257 | { | 342 | { |
3970 | 258 | if (test_suite == "android-gps") | 343 | if (test_suite == "android-gps") |
3971 | 259 | return snr_and_ttff(cout, cerr); | 344 | return snr_and_ttff(cout, cerr); |
3972 | 345 | else if (test_suite == "sirf") | ||
3973 | 346 | return sirf(cout, cerr); | ||
3974 | 260 | else if (test_suite == "ubx") | 347 | else if (test_suite == "ubx") |
3975 | 261 | return ubx(cout, cerr); | 348 | return ubx(cout, cerr); |
3976 | 262 | return 0; | 349 | return 0; |
LGTM