Skip to content

Commit 14166c4

Browse files
committed
Fix GPS not ready
1 parent a55b7c3 commit 14166c4

File tree

8 files changed

+2037
-2056
lines changed

8 files changed

+2037
-2056
lines changed

logs/libapp-demangle.S

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

logs/libapp-expanded.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,8 @@ mod gps_sensor {
548548
};
549549
let sensor_value = convert_gps_data(sensor_data, sensor_type);
550550
if let SensorValueType::None = sensor_value.val {
551-
if !false {
552-
{
553-
::core::panicking::panic(&("bad type",
554-
"rust/app/src/gps_sensor.rs",
555-
84u32, 55u32))
556-
}
557-
};
551+
console::print("GPS not ready\n");
552+
return MynewtError::SYS_EINVAL;
558553
}
559554
if let SensorValueType::Geolocation { latitude, longitude, altitude }
560555
= sensor_value.val {
@@ -575,7 +570,7 @@ mod gps_sensor {
575570
#[allow(non_snake_case, unused_variables)]
576571
fn convert_gps_data(sensor_data: sensor_data_ptr,
577572
sensor_type: sensor_type_t) -> SensorValue {
578-
console::print("GPS listener got geolocation\n");
573+
console::print("GPS listener converting geolocation\n");
579574
SensorValue{key: &GPS_SENSOR_KEY,
580575
val:
581576
match sensor_type {
@@ -621,31 +616,25 @@ mod gps_sensor {
621616
::core::fmt::Display::fmt)],
622617
}),
623618
&("rust/app/src/gps_sensor.rs",
624-
114u32,
619+
117u32,
625620
17u32))
626621
}
627622
}
628623
}
629624
}
630625
};
631-
if !(geolocation.sgd_latitude_is_valid != 0 &&
632-
geolocation.sgd_longitude_is_valid !=
633-
0 &&
634-
geolocation.sgd_altitude_is_valid !=
635-
0) {
636-
{
637-
::core::panicking::panic(&("bad geodata",
638-
"rust/app/src/gps_sensor.rs",
639-
116u32,
640-
17u32))
641-
}
642-
};
643-
SensorValueType::Geolocation{latitude:
644-
geolocation.sgd_latitude,
645-
longitude:
646-
geolocation.sgd_longitude,
647-
altitude:
648-
geolocation.sgd_altitude,}
626+
if geolocation.sgd_latitude_is_valid != 0 &&
627+
geolocation.sgd_longitude_is_valid != 0
628+
&&
629+
geolocation.sgd_altitude_is_valid != 0
630+
{
631+
SensorValueType::Geolocation{latitude:
632+
geolocation.sgd_latitude,
633+
longitude:
634+
geolocation.sgd_longitude,
635+
altitude:
636+
geolocation.sgd_altitude,}
637+
} else { SensorValueType::None }
649638
}
650639
},}
651640
}

logs/libapp.S

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

logs/libapp.elf

Lines changed: 1515 additions & 1532 deletions
Large diffs are not rendered by default.

logs/libapp.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

logs/rustlib-demangle.S

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

logs/rustlib.S

Lines changed: 122 additions & 121 deletions
Large diffs are not rendered by default.

rust/app/src/gps_sensor.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ extern fn handle_gps_data(sensor: sensor_ptr, _arg: sensor_arg,
8181

8282
// Convert the GPS geolocation for transmission.
8383
let sensor_value = convert_gps_data(sensor_data, sensor_type);
84-
if let SensorValueType::None = sensor_value.val { assert!(false, "bad type"); }
84+
if let SensorValueType::None = sensor_value.val {
85+
console::print("GPS not ready\n");
86+
return MynewtError::SYS_EINVAL; // Exit if GPS is not ready
87+
}
8588

8689
// Show the GPS geolocation.
8790
if let SensorValueType::Geolocation { latitude, longitude, altitude } = sensor_value.val {
@@ -102,7 +105,7 @@ extern fn handle_gps_data(sensor: sensor_ptr, _arg: sensor_arg,
102105
/// `sensor_type` indicates the type of data in `sensor_data`.
103106
#[allow(non_snake_case, unused_variables)]
104107
fn convert_gps_data(sensor_data: sensor_data_ptr, sensor_type: sensor_type_t) -> SensorValue {
105-
console::print("GPS listener got geolocation\n");
108+
console::print("GPS listener converting geolocation\n");
106109
// Construct and return a new `SensorValue` (without semicolon)
107110
SensorValue {
108111
key: &GPS_SENSOR_KEY, // Sensor data key is `geolocation`
@@ -113,17 +116,19 @@ fn convert_gps_data(sensor_data: sensor_data_ptr, sensor_type: sensor_type_t) ->
113116
let rc = unsafe { sensor::get_geolocation_data(sensor_data, &mut geolocation) };
114117
assert_eq!(rc, 0, "geodata fail");
115118
// Check that the geolocation data is valid.
116-
assert!(
117-
geolocation.sgd_latitude_is_valid != 0 &&
119+
if geolocation.sgd_latitude_is_valid != 0 &&
118120
geolocation.sgd_longitude_is_valid != 0 &&
119-
geolocation.sgd_altitude_is_valid != 0,
120-
"bad geodata");
121-
// Geolocation data is valid. Return it.
122-
SensorValueType::Geolocation {
123-
latitude: geolocation.sgd_latitude,
124-
longitude: geolocation.sgd_longitude,
125-
altitude: geolocation.sgd_altitude,
126-
}
121+
geolocation.sgd_altitude_is_valid != 0 {
122+
// Geolocation data is valid. Return it.
123+
SensorValueType::Geolocation {
124+
latitude: geolocation.sgd_latitude,
125+
longitude: geolocation.sgd_longitude,
126+
altitude: geolocation.sgd_altitude,
127+
}
128+
} else {
129+
// Geolocation data is invalid. Maybe GPS is not ready.
130+
SensorValueType::None
131+
}
127132
}
128133
// Unknown type of sensor value
129134
// _ => { assert!(false, "sensor type"); SensorValueType::Uint(0) }

0 commit comments

Comments
 (0)