Skip to content

Commit

Permalink
Change GPS_COORDS type Option<gps::Coordinates>.
Browse files Browse the repository at this point in the history
This this makes it possible to set to None when no coordinates are
available.
  • Loading branch information
brocaar committed Sep 10, 2020
1 parent eea5738 commit 4599035
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 57 deletions.
2 changes: 1 addition & 1 deletion chirpstack-concentratord-sx1301/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chirpstack-concentratord-sx1301"
version = "3.0.1"
version = "3.0.2"
authors = ["Orne Brocaar <[email protected]>"]
edition = "2018"
publish = false
Expand Down
11 changes: 4 additions & 7 deletions chirpstack-concentratord-sx1301/src/handler/gps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use libloragw_sx1301::{gps, hal};

lazy_static! {
static ref GPS_TIME_REF: Mutex<gps::TimeReference> = Mutex::new(Default::default());
static ref GPS_COORDS: Mutex<gps::Coordinates> = Mutex::new(gps::Coordinates {
latitude: 0.0,
longitude: 0.0,
altitude: 0
});
static ref GPS_COORDS: Mutex<Option<gps::Coordinates>> = Mutex::new(None);
static ref GPS_COORDS_ERROR: Mutex<gps::Coordinates> = Mutex::new(gps::Coordinates {
latitude: 0.0,
longitude: 0.0,
Expand Down Expand Up @@ -232,7 +228,7 @@ pub fn epoch2cnt(gps_epoch: &Duration) -> Result<u32, String> {
gps::epoch2cnt(&gps_time_ref, gps_epoch)
}

pub fn get_coords() -> Result<gps::Coordinates, String> {
pub fn get_coords() -> Result<Option<gps::Coordinates>, String> {
let gps_ref_valid = GPS_TIME_REF_VALID.lock().unwrap();
if *gps_ref_valid == false {
return Err("gps_ref_valid = false".to_string());
Expand Down Expand Up @@ -307,11 +303,12 @@ fn gps_process_coords() {
Ok(v) => v,
Err(err) => {
debug!("get gps coordinates failed, error: {}", err);
*coords = None;
return;
}
};

*coords = c;
*coords = Some(c);
*coords_error = ce;

trace!(
Expand Down
25 changes: 14 additions & 11 deletions chirpstack-concentratord-sx1301/src/handler/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ pub fn stats_loop(

// fetch the current gps coordinates
let loc = match gps::get_coords() {
Ok(v) => Some({
let mut loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};

loc.set_source(chirpstack_api::common::LocationSource::Gps);
loc
}),
Ok(v) => match v {
Some(v) => Some({
let mut loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};

loc.set_source(chirpstack_api::common::LocationSource::Gps);
loc
}),
None => None,
},
Err(err) => {
debug!("Get gps coordinates error, error: {}", err);
None
Expand Down
23 changes: 13 additions & 10 deletions chirpstack-concentratord-sx1301/src/wrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,20 @@ pub fn uplink_to_proto(
}
}
match gps::get_coords() {
Ok(v) => {
let mut proto_loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};
proto_loc.set_source(chirpstack_api::common::LocationSource::Gps);
Ok(v) => match v {
Some(v) => {
let mut proto_loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};
proto_loc.set_source(chirpstack_api::common::LocationSource::Gps);

rx_info.location = Some(proto_loc);
}
rx_info.location = Some(proto_loc);
}
None => {}
},
Err(err) => {
debug!(
"Could not get GPS coordinates, uplink_id: {}, error: {}",
Expand Down
2 changes: 1 addition & 1 deletion chirpstack-concentratord-sx1302/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chirpstack-concentratord-sx1302"
version = "3.0.1"
version = "3.0.2"
authors = ["Orne Brocaar <[email protected]>"]
edition = "2018"
publish = false
Expand Down
11 changes: 4 additions & 7 deletions chirpstack-concentratord-sx1302/src/handler/gps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ use libloragw_sx1302::{gps, hal};

lazy_static! {
static ref GPS_TIME_REF: Mutex<gps::TimeReference> = Mutex::new(Default::default());
static ref GPS_COORDS: Mutex<gps::Coordinates> = Mutex::new(gps::Coordinates {
latitude: 0.0,
longitude: 0.0,
altitude: 0
});
static ref GPS_COORDS: Mutex<Option<gps::Coordinates>> = Mutex::new(None);
static ref GPS_COORDS_ERROR: Mutex<gps::Coordinates> = Mutex::new(gps::Coordinates {
latitude: 0.0,
longitude: 0.0,
Expand Down Expand Up @@ -232,7 +228,7 @@ pub fn epoch2cnt(gps_epoch: &Duration) -> Result<u32, String> {
gps::epoch2cnt(&gps_time_ref, gps_epoch)
}

pub fn get_coords() -> Result<gps::Coordinates, String> {
pub fn get_coords() -> Result<Option<gps::Coordinates>, String> {
let gps_ref_valid = GPS_TIME_REF_VALID.lock().unwrap();
if *gps_ref_valid == false {
return Err("gps_ref_valid = false".to_string());
Expand Down Expand Up @@ -291,11 +287,12 @@ fn gps_process_coords() {
Ok(v) => v,
Err(err) => {
debug!("get gps coordinates failed, error: {}", err);
*coords = None;
return;
}
};

*coords = c;
*coords = Some(c);
*coords_error = ce;

trace!(
Expand Down
23 changes: 13 additions & 10 deletions chirpstack-concentratord-sx1302/src/handler/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ pub fn stats_loop(

// fetch the current gps coordinates
let loc = match gps::get_coords() {
Ok(v) => Some({
let mut loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};
Ok(v) => match v {
Some(v) => Some({
let mut loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};

loc.set_source(chirpstack_api::common::LocationSource::Gps);
loc
}),
loc.set_source(chirpstack_api::common::LocationSource::Gps);
loc
}),
None => None,
},
Err(err) => {
debug!("Get gps coordinates error, error: {}", err);
None
Expand Down
23 changes: 13 additions & 10 deletions chirpstack-concentratord-sx1302/src/wrapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,20 @@ pub fn uplink_to_proto(
}
}
match gps::get_coords() {
Ok(v) => {
let mut proto_loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};
proto_loc.set_source(chirpstack_api::common::LocationSource::Gps);
Ok(v) => match v {
Some(v) => {
let mut proto_loc = chirpstack_api::common::Location {
latitude: v.latitude,
longitude: v.longitude,
altitude: v.altitude as f64,
..Default::default()
};
proto_loc.set_source(chirpstack_api::common::LocationSource::Gps);

rx_info.location = Some(proto_loc);
}
rx_info.location = Some(proto_loc);
}
None => {}
},
Err(err) => {
debug!(
"Could not get GPS coordinates, uplink_id: {}, error: {}",
Expand Down

0 comments on commit 4599035

Please sign in to comment.