1use crate::{
15 byte_converter::*,
16 converting_callback_receiver::ConvertingCallbackReceiver,
17 converting_receiver::{BrickletRecvTimeoutError, ConvertingReceiver},
18 device::*,
19 ip_connection::GetRequestSender,
20 low_level_traits::*,
21};
22pub enum GpsV2BrickletFunction {
23 GetCoordinates,
24 GetStatus,
25 GetAltitude,
26 GetMotion,
27 GetDateTime,
28 Restart,
29 GetSatelliteSystemStatusLowLevel,
30 GetSatelliteStatus,
31 SetFixLedConfig,
32 GetFixLedConfig,
33 SetCoordinatesCallbackPeriod,
34 GetCoordinatesCallbackPeriod,
35 SetStatusCallbackPeriod,
36 GetStatusCallbackPeriod,
37 SetAltitudeCallbackPeriod,
38 GetAltitudeCallbackPeriod,
39 SetMotionCallbackPeriod,
40 GetMotionCallbackPeriod,
41 SetDateTimeCallbackPeriod,
42 GetDateTimeCallbackPeriod,
43 SetSbasConfig,
44 GetSbasConfig,
45 GetSpitfpErrorCount,
46 SetBootloaderMode,
47 GetBootloaderMode,
48 SetWriteFirmwarePointer,
49 WriteFirmware,
50 SetStatusLedConfig,
51 GetStatusLedConfig,
52 GetChipTemperature,
53 Reset,
54 WriteUid,
55 ReadUid,
56 GetIdentity,
57 CallbackPulsePerSecond,
58 CallbackCoordinates,
59 CallbackStatus,
60 CallbackAltitude,
61 CallbackMotion,
62 CallbackDateTime,
63}
64impl From<GpsV2BrickletFunction> for u8 {
65 fn from(fun: GpsV2BrickletFunction) -> Self {
66 match fun {
67 GpsV2BrickletFunction::GetCoordinates => 1,
68 GpsV2BrickletFunction::GetStatus => 2,
69 GpsV2BrickletFunction::GetAltitude => 3,
70 GpsV2BrickletFunction::GetMotion => 4,
71 GpsV2BrickletFunction::GetDateTime => 5,
72 GpsV2BrickletFunction::Restart => 6,
73 GpsV2BrickletFunction::GetSatelliteSystemStatusLowLevel => 7,
74 GpsV2BrickletFunction::GetSatelliteStatus => 8,
75 GpsV2BrickletFunction::SetFixLedConfig => 9,
76 GpsV2BrickletFunction::GetFixLedConfig => 10,
77 GpsV2BrickletFunction::SetCoordinatesCallbackPeriod => 11,
78 GpsV2BrickletFunction::GetCoordinatesCallbackPeriod => 12,
79 GpsV2BrickletFunction::SetStatusCallbackPeriod => 13,
80 GpsV2BrickletFunction::GetStatusCallbackPeriod => 14,
81 GpsV2BrickletFunction::SetAltitudeCallbackPeriod => 15,
82 GpsV2BrickletFunction::GetAltitudeCallbackPeriod => 16,
83 GpsV2BrickletFunction::SetMotionCallbackPeriod => 17,
84 GpsV2BrickletFunction::GetMotionCallbackPeriod => 18,
85 GpsV2BrickletFunction::SetDateTimeCallbackPeriod => 19,
86 GpsV2BrickletFunction::GetDateTimeCallbackPeriod => 20,
87 GpsV2BrickletFunction::SetSbasConfig => 27,
88 GpsV2BrickletFunction::GetSbasConfig => 28,
89 GpsV2BrickletFunction::GetSpitfpErrorCount => 234,
90 GpsV2BrickletFunction::SetBootloaderMode => 235,
91 GpsV2BrickletFunction::GetBootloaderMode => 236,
92 GpsV2BrickletFunction::SetWriteFirmwarePointer => 237,
93 GpsV2BrickletFunction::WriteFirmware => 238,
94 GpsV2BrickletFunction::SetStatusLedConfig => 239,
95 GpsV2BrickletFunction::GetStatusLedConfig => 240,
96 GpsV2BrickletFunction::GetChipTemperature => 242,
97 GpsV2BrickletFunction::Reset => 243,
98 GpsV2BrickletFunction::WriteUid => 248,
99 GpsV2BrickletFunction::ReadUid => 249,
100 GpsV2BrickletFunction::GetIdentity => 255,
101 GpsV2BrickletFunction::CallbackPulsePerSecond => 21,
102 GpsV2BrickletFunction::CallbackCoordinates => 22,
103 GpsV2BrickletFunction::CallbackStatus => 23,
104 GpsV2BrickletFunction::CallbackAltitude => 24,
105 GpsV2BrickletFunction::CallbackMotion => 25,
106 GpsV2BrickletFunction::CallbackDateTime => 26,
107 }
108 }
109}
110pub const GPS_V2_BRICKLET_RESTART_TYPE_HOT_START: u8 = 0;
111pub const GPS_V2_BRICKLET_RESTART_TYPE_WARM_START: u8 = 1;
112pub const GPS_V2_BRICKLET_RESTART_TYPE_COLD_START: u8 = 2;
113pub const GPS_V2_BRICKLET_RESTART_TYPE_FACTORY_RESET: u8 = 3;
114pub const GPS_V2_BRICKLET_SATELLITE_SYSTEM_GPS: u8 = 0;
115pub const GPS_V2_BRICKLET_SATELLITE_SYSTEM_GLONASS: u8 = 1;
116pub const GPS_V2_BRICKLET_SATELLITE_SYSTEM_GALILEO: u8 = 2;
117pub const GPS_V2_BRICKLET_FIX_NO_FIX: u8 = 1;
118pub const GPS_V2_BRICKLET_FIX_2D_FIX: u8 = 2;
119pub const GPS_V2_BRICKLET_FIX_3D_FIX: u8 = 3;
120pub const GPS_V2_BRICKLET_FIX_LED_CONFIG_OFF: u8 = 0;
121pub const GPS_V2_BRICKLET_FIX_LED_CONFIG_ON: u8 = 1;
122pub const GPS_V2_BRICKLET_FIX_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
123pub const GPS_V2_BRICKLET_FIX_LED_CONFIG_SHOW_FIX: u8 = 3;
124pub const GPS_V2_BRICKLET_FIX_LED_CONFIG_SHOW_PPS: u8 = 4;
125pub const GPS_V2_BRICKLET_SBAS_ENABLED: u8 = 0;
126pub const GPS_V2_BRICKLET_SBAS_DISABLED: u8 = 1;
127pub const GPS_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER: u8 = 0;
128pub const GPS_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE: u8 = 1;
129pub const GPS_V2_BRICKLET_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT: u8 = 2;
130pub const GPS_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT: u8 = 3;
131pub const GPS_V2_BRICKLET_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT: u8 = 4;
132pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_OK: u8 = 0;
133pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_INVALID_MODE: u8 = 1;
134pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_NO_CHANGE: u8 = 2;
135pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT: u8 = 3;
136pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT: u8 = 4;
137pub const GPS_V2_BRICKLET_BOOTLOADER_STATUS_CRC_MISMATCH: u8 = 5;
138pub const GPS_V2_BRICKLET_STATUS_LED_CONFIG_OFF: u8 = 0;
139pub const GPS_V2_BRICKLET_STATUS_LED_CONFIG_ON: u8 = 1;
140pub const GPS_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_HEARTBEAT: u8 = 2;
141pub const GPS_V2_BRICKLET_STATUS_LED_CONFIG_SHOW_STATUS: u8 = 3;
142
143#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
144pub struct Coordinates {
145 pub latitude: u32,
146 pub ns: char,
147 pub longitude: u32,
148 pub ew: char,
149}
150impl FromByteSlice for Coordinates {
151 fn bytes_expected() -> usize { 10 }
152 fn from_le_byte_slice(bytes: &[u8]) -> Coordinates {
153 Coordinates {
154 latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
155 ns: <char>::from_le_byte_slice(&bytes[4..5]),
156 longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
157 ew: <char>::from_le_byte_slice(&bytes[9..10]),
158 }
159 }
160}
161
162#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
163pub struct Status {
164 pub has_fix: bool,
165 pub satellites_view: u8,
166}
167impl FromByteSlice for Status {
168 fn bytes_expected() -> usize { 2 }
169 fn from_le_byte_slice(bytes: &[u8]) -> Status {
170 Status { has_fix: <bool>::from_le_byte_slice(&bytes[0..1]), satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]) }
171 }
172}
173
174#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
175pub struct Altitude {
176 pub altitude: i32,
177 pub geoidal_separation: i32,
178}
179impl FromByteSlice for Altitude {
180 fn bytes_expected() -> usize { 8 }
181 fn from_le_byte_slice(bytes: &[u8]) -> Altitude {
182 Altitude { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
183 }
184}
185
186#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
187pub struct Motion {
188 pub course: u32,
189 pub speed: u32,
190}
191impl FromByteSlice for Motion {
192 fn bytes_expected() -> usize { 8 }
193 fn from_le_byte_slice(bytes: &[u8]) -> Motion {
194 Motion { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
195 }
196}
197
198#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
199pub struct DateTime {
200 pub date: u32,
201 pub time: u32,
202}
203impl FromByteSlice for DateTime {
204 fn bytes_expected() -> usize { 8 }
205 fn from_le_byte_slice(bytes: &[u8]) -> DateTime {
206 DateTime { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
207 }
208}
209
210#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
211pub struct SatelliteSystemStatusLowLevel {
212 pub satellite_numbers_length: u8,
213 pub satellite_numbers_data: [u8; 12],
214 pub fix: u8,
215 pub pdop: u16,
216 pub hdop: u16,
217 pub vdop: u16,
218}
219impl FromByteSlice for SatelliteSystemStatusLowLevel {
220 fn bytes_expected() -> usize { 20 }
221 fn from_le_byte_slice(bytes: &[u8]) -> SatelliteSystemStatusLowLevel {
222 SatelliteSystemStatusLowLevel {
223 satellite_numbers_length: <u8>::from_le_byte_slice(&bytes[0..1]),
224 satellite_numbers_data: <[u8; 12]>::from_le_byte_slice(&bytes[1..13]),
225 fix: <u8>::from_le_byte_slice(&bytes[13..14]),
226 pdop: <u16>::from_le_byte_slice(&bytes[14..16]),
227 hdop: <u16>::from_le_byte_slice(&bytes[16..18]),
228 vdop: <u16>::from_le_byte_slice(&bytes[18..20]),
229 }
230 }
231}
232impl LowLevelRead<u8, SatelliteSystemStatusResult> for SatelliteSystemStatusLowLevel {
233 fn ll_message_length(&self) -> usize { self.satellite_numbers_length as usize }
234
235 fn ll_message_chunk_offset(&self) -> usize { 0 }
236
237 fn ll_message_chunk_data(&self) -> &[u8] { &self.satellite_numbers_data }
238
239 fn get_result(&self) -> SatelliteSystemStatusResult {
240 SatelliteSystemStatusResult { fix: self.fix, pdop: self.pdop, hdop: self.hdop, vdop: self.vdop }
241 }
242}
243
244#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
245pub struct SatelliteStatus {
246 pub elevation: i16,
247 pub azimuth: i16,
248 pub snr: i16,
249}
250impl FromByteSlice for SatelliteStatus {
251 fn bytes_expected() -> usize { 6 }
252 fn from_le_byte_slice(bytes: &[u8]) -> SatelliteStatus {
253 SatelliteStatus {
254 elevation: <i16>::from_le_byte_slice(&bytes[0..2]),
255 azimuth: <i16>::from_le_byte_slice(&bytes[2..4]),
256 snr: <i16>::from_le_byte_slice(&bytes[4..6]),
257 }
258 }
259}
260
261#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
262pub struct CoordinatesEvent {
263 pub latitude: u32,
264 pub ns: char,
265 pub longitude: u32,
266 pub ew: char,
267}
268impl FromByteSlice for CoordinatesEvent {
269 fn bytes_expected() -> usize { 10 }
270 fn from_le_byte_slice(bytes: &[u8]) -> CoordinatesEvent {
271 CoordinatesEvent {
272 latitude: <u32>::from_le_byte_slice(&bytes[0..4]),
273 ns: <char>::from_le_byte_slice(&bytes[4..5]),
274 longitude: <u32>::from_le_byte_slice(&bytes[5..9]),
275 ew: <char>::from_le_byte_slice(&bytes[9..10]),
276 }
277 }
278}
279
280#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
281pub struct StatusEvent {
282 pub has_fix: bool,
283 pub satellites_view: u8,
284}
285impl FromByteSlice for StatusEvent {
286 fn bytes_expected() -> usize { 2 }
287 fn from_le_byte_slice(bytes: &[u8]) -> StatusEvent {
288 StatusEvent { has_fix: <bool>::from_le_byte_slice(&bytes[0..1]), satellites_view: <u8>::from_le_byte_slice(&bytes[1..2]) }
289 }
290}
291
292#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
293pub struct AltitudeEvent {
294 pub altitude: i32,
295 pub geoidal_separation: i32,
296}
297impl FromByteSlice for AltitudeEvent {
298 fn bytes_expected() -> usize { 8 }
299 fn from_le_byte_slice(bytes: &[u8]) -> AltitudeEvent {
300 AltitudeEvent { altitude: <i32>::from_le_byte_slice(&bytes[0..4]), geoidal_separation: <i32>::from_le_byte_slice(&bytes[4..8]) }
301 }
302}
303
304#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
305pub struct MotionEvent {
306 pub course: u32,
307 pub speed: u32,
308}
309impl FromByteSlice for MotionEvent {
310 fn bytes_expected() -> usize { 8 }
311 fn from_le_byte_slice(bytes: &[u8]) -> MotionEvent {
312 MotionEvent { course: <u32>::from_le_byte_slice(&bytes[0..4]), speed: <u32>::from_le_byte_slice(&bytes[4..8]) }
313 }
314}
315
316#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
317pub struct DateTimeEvent {
318 pub date: u32,
319 pub time: u32,
320}
321impl FromByteSlice for DateTimeEvent {
322 fn bytes_expected() -> usize { 8 }
323 fn from_le_byte_slice(bytes: &[u8]) -> DateTimeEvent {
324 DateTimeEvent { date: <u32>::from_le_byte_slice(&bytes[0..4]), time: <u32>::from_le_byte_slice(&bytes[4..8]) }
325 }
326}
327
328#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
329pub struct SpitfpErrorCount {
330 pub error_count_ack_checksum: u32,
331 pub error_count_message_checksum: u32,
332 pub error_count_frame: u32,
333 pub error_count_overflow: u32,
334}
335impl FromByteSlice for SpitfpErrorCount {
336 fn bytes_expected() -> usize { 16 }
337 fn from_le_byte_slice(bytes: &[u8]) -> SpitfpErrorCount {
338 SpitfpErrorCount {
339 error_count_ack_checksum: <u32>::from_le_byte_slice(&bytes[0..4]),
340 error_count_message_checksum: <u32>::from_le_byte_slice(&bytes[4..8]),
341 error_count_frame: <u32>::from_le_byte_slice(&bytes[8..12]),
342 error_count_overflow: <u32>::from_le_byte_slice(&bytes[12..16]),
343 }
344 }
345}
346
347#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
348pub struct Identity {
349 pub uid: String,
350 pub connected_uid: String,
351 pub position: char,
352 pub hardware_version: [u8; 3],
353 pub firmware_version: [u8; 3],
354 pub device_identifier: u16,
355}
356impl FromByteSlice for Identity {
357 fn bytes_expected() -> usize { 25 }
358 fn from_le_byte_slice(bytes: &[u8]) -> Identity {
359 Identity {
360 uid: <String>::from_le_byte_slice(&bytes[0..8]),
361 connected_uid: <String>::from_le_byte_slice(&bytes[8..16]),
362 position: <char>::from_le_byte_slice(&bytes[16..17]),
363 hardware_version: <[u8; 3]>::from_le_byte_slice(&bytes[17..20]),
364 firmware_version: <[u8; 3]>::from_le_byte_slice(&bytes[20..23]),
365 device_identifier: <u16>::from_le_byte_slice(&bytes[23..25]),
366 }
367 }
368}
369
370#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
371pub struct SatelliteSystemStatusResult {
372 pub fix: u8,
373 pub pdop: u16,
374 pub hdop: u16,
375 pub vdop: u16,
376}
377
378#[derive(Clone)]
380pub struct GpsV2Bricklet {
381 device: Device,
382}
383impl GpsV2Bricklet {
384 pub const DEVICE_IDENTIFIER: u16 = 276;
385 pub const DEVICE_DISPLAY_NAME: &'static str = "GPS Bricklet 2.0";
386 pub fn new<T: GetRequestSender>(uid: &str, req_sender: T) -> GpsV2Bricklet {
388 let mut result = GpsV2Bricklet { device: Device::new([2, 0, 1], uid, req_sender, 1) };
389 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetCoordinates) as usize] = ResponseExpectedFlag::AlwaysTrue;
390 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
391 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetAltitude) as usize] = ResponseExpectedFlag::AlwaysTrue;
392 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetMotion) as usize] = ResponseExpectedFlag::AlwaysTrue;
393 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetDateTime) as usize] = ResponseExpectedFlag::AlwaysTrue;
394 result.device.response_expected[u8::from(GpsV2BrickletFunction::Restart) as usize] = ResponseExpectedFlag::False;
395 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetSatelliteSystemStatusLowLevel) as usize] =
396 ResponseExpectedFlag::AlwaysTrue;
397 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetSatelliteStatus) as usize] = ResponseExpectedFlag::AlwaysTrue;
398 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetFixLedConfig) as usize] = ResponseExpectedFlag::False;
399 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetFixLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
400 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetCoordinatesCallbackPeriod) as usize] =
401 ResponseExpectedFlag::True;
402 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetCoordinatesCallbackPeriod) as usize] =
403 ResponseExpectedFlag::AlwaysTrue;
404 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetStatusCallbackPeriod) as usize] = ResponseExpectedFlag::True;
405 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetStatusCallbackPeriod) as usize] =
406 ResponseExpectedFlag::AlwaysTrue;
407 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetAltitudeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
408 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetAltitudeCallbackPeriod) as usize] =
409 ResponseExpectedFlag::AlwaysTrue;
410 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetMotionCallbackPeriod) as usize] = ResponseExpectedFlag::True;
411 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetMotionCallbackPeriod) as usize] =
412 ResponseExpectedFlag::AlwaysTrue;
413 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetDateTimeCallbackPeriod) as usize] = ResponseExpectedFlag::True;
414 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetDateTimeCallbackPeriod) as usize] =
415 ResponseExpectedFlag::AlwaysTrue;
416 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetSbasConfig) as usize] = ResponseExpectedFlag::False;
417 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetSbasConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
418 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetSpitfpErrorCount) as usize] = ResponseExpectedFlag::AlwaysTrue;
419 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
420 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetBootloaderMode) as usize] = ResponseExpectedFlag::AlwaysTrue;
421 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetWriteFirmwarePointer) as usize] = ResponseExpectedFlag::False;
422 result.device.response_expected[u8::from(GpsV2BrickletFunction::WriteFirmware) as usize] = ResponseExpectedFlag::AlwaysTrue;
423 result.device.response_expected[u8::from(GpsV2BrickletFunction::SetStatusLedConfig) as usize] = ResponseExpectedFlag::False;
424 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetStatusLedConfig) as usize] = ResponseExpectedFlag::AlwaysTrue;
425 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetChipTemperature) as usize] = ResponseExpectedFlag::AlwaysTrue;
426 result.device.response_expected[u8::from(GpsV2BrickletFunction::Reset) as usize] = ResponseExpectedFlag::False;
427 result.device.response_expected[u8::from(GpsV2BrickletFunction::WriteUid) as usize] = ResponseExpectedFlag::False;
428 result.device.response_expected[u8::from(GpsV2BrickletFunction::ReadUid) as usize] = ResponseExpectedFlag::AlwaysTrue;
429 result.device.response_expected[u8::from(GpsV2BrickletFunction::GetIdentity) as usize] = ResponseExpectedFlag::AlwaysTrue;
430 result
431 }
432
433 pub fn get_response_expected(&mut self, fun: GpsV2BrickletFunction) -> Result<bool, GetResponseExpectedError> {
448 self.device.get_response_expected(u8::from(fun))
449 }
450
451 pub fn set_response_expected(&mut self, fun: GpsV2BrickletFunction, response_expected: bool) -> Result<(), SetResponseExpectedError> {
460 self.device.set_response_expected(u8::from(fun), response_expected)
461 }
462
463 pub fn set_response_expected_all(&mut self, response_expected: bool) { self.device.set_response_expected_all(response_expected) }
465
466 pub fn get_api_version(&self) -> [u8; 3] { self.device.api_version }
469
470 pub fn get_pulse_per_second_callback_receiver(&self) -> ConvertingCallbackReceiver<()> {
478 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackPulsePerSecond))
479 }
480
481 pub fn get_coordinates_callback_receiver(&self) -> ConvertingCallbackReceiver<CoordinatesEvent> {
489 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackCoordinates))
490 }
491
492 pub fn get_status_callback_receiver(&self) -> ConvertingCallbackReceiver<StatusEvent> {
499 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackStatus))
500 }
501
502 pub fn get_altitude_callback_receiver(&self) -> ConvertingCallbackReceiver<AltitudeEvent> {
510 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackAltitude))
511 }
512
513 pub fn get_motion_callback_receiver(&self) -> ConvertingCallbackReceiver<MotionEvent> {
521 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackMotion))
522 }
523
524 pub fn get_date_time_callback_receiver(&self) -> ConvertingCallbackReceiver<DateTimeEvent> {
531 self.device.get_callback_receiver(u8::from(GpsV2BrickletFunction::CallbackDateTime))
532 }
533
534 pub fn get_coordinates(&self) -> ConvertingReceiver<Coordinates> {
543 let payload = vec![0; 0];
544
545 self.device.get(u8::from(GpsV2BrickletFunction::GetCoordinates), payload)
546 }
547
548 pub fn get_status(&self) -> ConvertingReceiver<Status> {
554 let payload = vec![0; 0];
555
556 self.device.get(u8::from(GpsV2BrickletFunction::GetStatus), payload)
557 }
558
559 pub fn get_altitude(&self) -> ConvertingReceiver<Altitude> {
564 let payload = vec![0; 0];
565
566 self.device.get(u8::from(GpsV2BrickletFunction::GetAltitude), payload)
567 }
568
569 pub fn get_motion(&self) -> ConvertingReceiver<Motion> {
578 let payload = vec![0; 0];
579
580 self.device.get(u8::from(GpsV2BrickletFunction::GetMotion), payload)
581 }
582
583 pub fn get_date_time(&self) -> ConvertingReceiver<DateTime> {
588 let payload = vec![0; 0];
589
590 self.device.get(u8::from(GpsV2BrickletFunction::GetDateTime), payload)
591 }
592
593 pub fn restart(&self, restart_type: u8) -> ConvertingReceiver<()> {
608 let mut payload = vec![0; 1];
609 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(restart_type));
610
611 self.device.set(u8::from(GpsV2BrickletFunction::Restart), payload)
612 }
613
614 pub fn get_satellite_system_status_low_level(&self, satellite_system: u8) -> ConvertingReceiver<SatelliteSystemStatusLowLevel> {
637 let mut payload = vec![0; 1];
638 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(satellite_system));
639
640 self.device.get(u8::from(GpsV2BrickletFunction::GetSatelliteSystemStatusLowLevel), payload)
641 }
642
643 pub fn get_satellite_system_status(
658 &self,
659 satellite_system: u8,
660 ) -> Result<(Vec<u8>, SatelliteSystemStatusResult), BrickletRecvTimeoutError> {
661 let ll_result = self.device.get_high_level(0, &mut || self.get_satellite_system_status_low_level(satellite_system).recv())?;
662 Ok((ll_result.0, ll_result.1))
663 }
664
665 pub fn get_satellite_status(&self, satellite_system: u8, satellite_number: u8) -> ConvertingReceiver<SatelliteStatus> {
678 let mut payload = vec![0; 2];
679 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(satellite_system));
680 payload[1..2].copy_from_slice(&<u8>::to_le_byte_vec(satellite_number));
681
682 self.device.get(u8::from(GpsV2BrickletFunction::GetSatelliteStatus), payload)
683 }
684
685 pub fn set_fix_led_config(&self, config: u8) -> ConvertingReceiver<()> {
701 let mut payload = vec![0; 1];
702 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
703
704 self.device.set(u8::from(GpsV2BrickletFunction::SetFixLedConfig), payload)
705 }
706
707 pub fn get_fix_led_config(&self) -> ConvertingReceiver<u8> {
716 let payload = vec![0; 0];
717
718 self.device.get(u8::from(GpsV2BrickletFunction::GetFixLedConfig), payload)
719 }
720
721 pub fn set_coordinates_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
727 let mut payload = vec![0; 4];
728 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
729
730 self.device.set(u8::from(GpsV2BrickletFunction::SetCoordinatesCallbackPeriod), payload)
731 }
732
733 pub fn get_coordinates_callback_period(&self) -> ConvertingReceiver<u32> {
735 let payload = vec![0; 0];
736
737 self.device.get(u8::from(GpsV2BrickletFunction::GetCoordinatesCallbackPeriod), payload)
738 }
739
740 pub fn set_status_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
746 let mut payload = vec![0; 4];
747 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
748
749 self.device.set(u8::from(GpsV2BrickletFunction::SetStatusCallbackPeriod), payload)
750 }
751
752 pub fn get_status_callback_period(&self) -> ConvertingReceiver<u32> {
754 let payload = vec![0; 0];
755
756 self.device.get(u8::from(GpsV2BrickletFunction::GetStatusCallbackPeriod), payload)
757 }
758
759 pub fn set_altitude_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
765 let mut payload = vec![0; 4];
766 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
767
768 self.device.set(u8::from(GpsV2BrickletFunction::SetAltitudeCallbackPeriod), payload)
769 }
770
771 pub fn get_altitude_callback_period(&self) -> ConvertingReceiver<u32> {
773 let payload = vec![0; 0];
774
775 self.device.get(u8::from(GpsV2BrickletFunction::GetAltitudeCallbackPeriod), payload)
776 }
777
778 pub fn set_motion_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
784 let mut payload = vec![0; 4];
785 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
786
787 self.device.set(u8::from(GpsV2BrickletFunction::SetMotionCallbackPeriod), payload)
788 }
789
790 pub fn get_motion_callback_period(&self) -> ConvertingReceiver<u32> {
792 let payload = vec![0; 0];
793
794 self.device.get(u8::from(GpsV2BrickletFunction::GetMotionCallbackPeriod), payload)
795 }
796
797 pub fn set_date_time_callback_period(&self, period: u32) -> ConvertingReceiver<()> {
803 let mut payload = vec![0; 4];
804 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(period));
805
806 self.device.set(u8::from(GpsV2BrickletFunction::SetDateTimeCallbackPeriod), payload)
807 }
808
809 pub fn get_date_time_callback_period(&self) -> ConvertingReceiver<u32> {
811 let payload = vec![0; 0];
812
813 self.device.get(u8::from(GpsV2BrickletFunction::GetDateTimeCallbackPeriod), payload)
814 }
815
816 pub fn set_sbas_config(&self, sbas_config: u8) -> ConvertingReceiver<()> {
827 let mut payload = vec![0; 1];
828 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(sbas_config));
829
830 self.device.set(u8::from(GpsV2BrickletFunction::SetSbasConfig), payload)
831 }
832
833 pub fn get_sbas_config(&self) -> ConvertingReceiver<u8> {
842 let payload = vec![0; 0];
843
844 self.device.get(u8::from(GpsV2BrickletFunction::GetSbasConfig), payload)
845 }
846
847 pub fn get_spitfp_error_count(&self) -> ConvertingReceiver<SpitfpErrorCount> {
859 let payload = vec![0; 0];
860
861 self.device.get(u8::from(GpsV2BrickletFunction::GetSpitfpErrorCount), payload)
862 }
863
864 pub fn set_bootloader_mode(&self, mode: u8) -> ConvertingReceiver<u8> {
887 let mut payload = vec![0; 1];
888 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(mode));
889
890 self.device.get(u8::from(GpsV2BrickletFunction::SetBootloaderMode), payload)
891 }
892
893 pub fn get_bootloader_mode(&self) -> ConvertingReceiver<u8> {
902 let payload = vec![0; 0];
903
904 self.device.get(u8::from(GpsV2BrickletFunction::GetBootloaderMode), payload)
905 }
906
907 pub fn set_write_firmware_pointer(&self, pointer: u32) -> ConvertingReceiver<()> {
914 let mut payload = vec![0; 4];
915 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(pointer));
916
917 self.device.set(u8::from(GpsV2BrickletFunction::SetWriteFirmwarePointer), payload)
918 }
919
920 pub fn write_firmware(&self, data: [u8; 64]) -> ConvertingReceiver<u8> {
929 let mut payload = vec![0; 64];
930 payload[0..64].copy_from_slice(&<[u8; 64]>::to_le_byte_vec(data));
931
932 self.device.get(u8::from(GpsV2BrickletFunction::WriteFirmware), payload)
933 }
934
935 pub fn set_status_led_config(&self, config: u8) -> ConvertingReceiver<()> {
949 let mut payload = vec![0; 1];
950 payload[0..1].copy_from_slice(&<u8>::to_le_byte_vec(config));
951
952 self.device.set(u8::from(GpsV2BrickletFunction::SetStatusLedConfig), payload)
953 }
954
955 pub fn get_status_led_config(&self) -> ConvertingReceiver<u8> {
963 let payload = vec![0; 0];
964
965 self.device.get(u8::from(GpsV2BrickletFunction::GetStatusLedConfig), payload)
966 }
967
968 pub fn get_chip_temperature(&self) -> ConvertingReceiver<i16> {
975 let payload = vec![0; 0];
976
977 self.device.get(u8::from(GpsV2BrickletFunction::GetChipTemperature), payload)
978 }
979
980 pub fn reset(&self) -> ConvertingReceiver<()> {
987 let payload = vec![0; 0];
988
989 self.device.set(u8::from(GpsV2BrickletFunction::Reset), payload)
990 }
991
992 pub fn write_uid(&self, uid: u32) -> ConvertingReceiver<()> {
998 let mut payload = vec![0; 4];
999 payload[0..4].copy_from_slice(&<u32>::to_le_byte_vec(uid));
1000
1001 self.device.set(u8::from(GpsV2BrickletFunction::WriteUid), payload)
1002 }
1003
1004 pub fn read_uid(&self) -> ConvertingReceiver<u32> {
1007 let payload = vec![0; 0];
1008
1009 self.device.get(u8::from(GpsV2BrickletFunction::ReadUid), payload)
1010 }
1011
1012 pub fn get_identity(&self) -> ConvertingReceiver<Identity> {
1023 let payload = vec![0; 0];
1024
1025 self.device.get(u8::from(GpsV2BrickletFunction::GetIdentity), payload)
1026 }
1027}