Merge pull request #1464 from matthiasbeyer/libimagentrygps/32-bit-gps-values
libimagentrygps: 32 bit gps values
This commit is contained in:
commit
0976cab014
2 changed files with 30 additions and 24 deletions
|
@ -94,21 +94,35 @@ fn add(rt: &Runtime) {
|
||||||
.map_err_trace_exit_unwrap(1);
|
.map_err_trace_exit_unwrap(1);
|
||||||
|
|
||||||
let c = {
|
let c = {
|
||||||
let parse = |value: &str| -> Vec<i8> {
|
let parse = |value: &str| -> (i64, i64, i64) {
|
||||||
value.split(".")
|
debug!("Parsing '{}' into degree, minute and second", value);
|
||||||
|
let ary = value.split(".")
|
||||||
|
.map(|v| {debug!("Parsing = {}", v); v})
|
||||||
.map(FromStr::from_str)
|
.map(FromStr::from_str)
|
||||||
.map(|elem| {
|
.map(|elem| {
|
||||||
elem.or_else(|_| Err(GE::from(GEK::NumberConversionError)))
|
elem.or_else(|_| Err(GE::from(GEK::NumberConversionError)))
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
})
|
})
|
||||||
.collect::<Vec<i8>>()
|
.collect::<Vec<i64>>();
|
||||||
|
|
||||||
|
let degree = ary.get(0).unwrap_or_else(|| {
|
||||||
|
error!("Degree missing. This value is required.");
|
||||||
|
exit(1)
|
||||||
|
});
|
||||||
|
let minute = ary.get(1).unwrap_or_else(|| {
|
||||||
|
error!("Degree missing. This value is required.");
|
||||||
|
exit(1)
|
||||||
|
});
|
||||||
|
let second = ary.get(2).unwrap_or(&0);
|
||||||
|
|
||||||
|
(*degree, *minute, *second)
|
||||||
};
|
};
|
||||||
|
|
||||||
let long = parse(scmd.value_of("longitude").unwrap()); // unwrap safed by clap
|
let long = parse(scmd.value_of("longitude").unwrap()); // unwrap safed by clap
|
||||||
let lati = parse(scmd.value_of("latitude").unwrap()); // unwrap safed by clap
|
let lati = parse(scmd.value_of("latitude").unwrap()); // unwrap safed by clap
|
||||||
|
|
||||||
let long = GPSValue::new(long[0], long[1], long[2]);
|
let long = GPSValue::new(long.0, long.1, long.2);
|
||||||
let lati = GPSValue::new(lati[0], lati[1], lati[2]);
|
let lati = GPSValue::new(lati.0, lati.1, lati.2);
|
||||||
|
|
||||||
Coordinates::new(long, lati)
|
Coordinates::new(long, lati)
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,14 +34,14 @@ pub trait FromValue : Sized {
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct GPSValue {
|
pub struct GPSValue {
|
||||||
pub degree: i8,
|
pub degree: i64,
|
||||||
pub minutes: i8,
|
pub minutes: i64,
|
||||||
pub seconds: i8
|
pub seconds: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GPSValue {
|
impl GPSValue {
|
||||||
|
|
||||||
pub fn new(d: i8, m: i8, s: i8) -> GPSValue {
|
pub fn new(d: i64, m: i64, s: i64) -> GPSValue {
|
||||||
GPSValue {
|
GPSValue {
|
||||||
degree: d,
|
degree: d,
|
||||||
minutes: m,
|
minutes: m,
|
||||||
|
@ -49,15 +49,15 @@ impl GPSValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn degree(&self) -> i8 {
|
pub fn degree(&self) -> i64 {
|
||||||
self.degree
|
self.degree
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn minutes(&self) -> i8 {
|
pub fn minutes(&self) -> i64 {
|
||||||
self.minutes
|
self.minutes
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seconds(&self) -> i8 {
|
pub fn seconds(&self) -> i64 {
|
||||||
self.seconds
|
self.seconds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +68,9 @@ impl Into<Value> for GPSValue {
|
||||||
|
|
||||||
fn into(self) -> Value {
|
fn into(self) -> Value {
|
||||||
let mut map = BTreeMap::new();
|
let mut map = BTreeMap::new();
|
||||||
let _ = map.insert("degree".to_owned(), Value::Integer(self.degree as i64));
|
let _ = map.insert("degree".to_owned(), Value::Integer(self.degree));
|
||||||
let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes as i64));
|
let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes));
|
||||||
let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds as i64));
|
let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds));
|
||||||
Value::Table(map)
|
Value::Table(map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ impl FromValue for GPSValue {
|
||||||
fn from_value(v: &Value) -> Result<Self> {
|
fn from_value(v: &Value) -> Result<Self> {
|
||||||
let int_to_appropriate_width = |v: &Value| {
|
let int_to_appropriate_width = |v: &Value| {
|
||||||
v.as_integer()
|
v.as_integer()
|
||||||
.ok_or(GPSE::from_kind(GPSEK::HeaderTypeError)).and_then(i64_to_i8)
|
.ok_or(GPSE::from_kind(GPSEK::HeaderTypeError))
|
||||||
};
|
};
|
||||||
|
|
||||||
match *v {
|
match *v {
|
||||||
|
@ -172,12 +172,4 @@ impl Display for Coordinates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper to convert a i64 to i8 or return an error if this doesn't work.
|
|
||||||
fn i64_to_i8(i: i64) -> Result<i8> {
|
|
||||||
if i > (<i8>::max_value() as i64) {
|
|
||||||
Err(GPSE::from_kind(GPSEK::NumberConversionError))
|
|
||||||
} else {
|
|
||||||
Ok(i as i8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue