summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-04-29 00:35:21 +0200
committerGitHub <noreply@github.com>2018-04-29 00:35:21 +0200
commit0976cab0144b45abd9d3806f8222f3dfdba3ea99 (patch)
treeba770d35cfe6d1ad200a13f7e47157a9403d4f6b
parent1dd5cb55658ffc536c5b55a0a72776b760bae2cb (diff)
parentdbb39475d982e8126fdbdb3e075f538a04ed460b (diff)
downloadimag-0976cab0144b45abd9d3806f8222f3dfdba3ea99.zip
imag-0976cab0144b45abd9d3806f8222f3dfdba3ea99.tar.gz
Merge pull request #1464 from matthiasbeyer/libimagentrygps/32-bit-gps-values
libimagentrygps: 32 bit gps values
-rw-r--r--bin/core/imag-gps/src/main.rs24
-rw-r--r--lib/entry/libimagentrygps/src/types.rs30
2 files changed, 30 insertions, 24 deletions
diff --git a/bin/core/imag-gps/src/main.rs b/bin/core/imag-gps/src/main.rs
index 502497a..a441559 100644
--- a/bin/core/imag-gps/src/main.rs
+++ b/bin/core/imag-gps/src/main.rs
@@ -94,21 +94,35 @@ fn add(rt: &Runtime) {
.map_err_trace_exit_unwrap(1);
let c = {
- let parse = |value: &str| -> Vec<i8> {
- value.split(".")
+ let parse = |value: &str| -> (i64, i64, i64) {
+ debug!("Parsing '{}' into degree, minute and second", value);
+ let ary = value.split(".")
+ .map(|v| {debug!("Parsing = {}", v); v})
.map(FromStr::from_str)
.map(|elem| {
elem.or_else(|_| Err(GE::from(GEK::NumberConversionError)))
.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 lati = parse(scmd.value_of("latitude").unwrap()); // unwrap safed by clap
- let long = GPSValue::new(long[0], long[1], long[2]);
- let lati = GPSValue::new(lati[0], lati[1], lati[2]);
+ let long = GPSValue::new(long.0, long.1, long.2);
+ let lati = GPSValue::new(lati.0, lati.1, lati.2);
Coordinates::new(long, lati)
};
diff --git a/lib/entry/libimagentrygps/src/types.rs b/lib/entry/libimagentrygps/src/types.rs
index 54ce6e6..265539e 100644
--- a/lib/entry/libimagentrygps/src/types.rs
+++ b/lib/entry/libimagentrygps/src/types.rs
@@ -34,14 +34,14 @@ pub trait FromValue : Sized {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct GPSValue {
- pub degree: i8,
- pub minutes: i8,
- pub seconds: i8
+ pub degree: i64,
+ pub minutes: i64,
+ pub seconds: i64,
}
impl GPSValue {
- pub fn new(d: i8, m: i8, s: i8) -> GPSValue {
+ pub fn new(d: i64, m: i64, s: i64) -> GPSValue {
GPSValue {
degree: d,
minutes: m,
@@ -49,15 +49,15 @@ impl GPSValue {
}
}
- pub fn degree(&self) -> i8 {
+ pub fn degree(&self) -> i64 {
self.degree
}
- pub fn minutes(&self) -> i8 {
+ pub fn minutes(&self) -> i64 {
self.minutes
}
- pub fn seconds(&self) -> i8 {
+ pub fn seconds(&self) -> i64 {
self.seconds
}
@@ -68,9 +68,9 @@ impl Into<Value> for GPSValue {
fn into(self) -> Value {
let mut map = BTreeMap::new();
- let _ = map.insert("degree".to_owned(), Value::Integer(self.degree as i64));
- let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes as i64));
- let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds as i64));
+ let _ = map.insert("degree".to_owned(), Value::Integer(self.degree));
+ let _ = map.insert("minutes".to_owned(), Value::Integer(self.minutes));
+ let _ = map.insert("seconds".to_owned(), Value::Integer(self.seconds));
Value::Table(map)
}
@@ -80,7 +80,7 @@ impl FromValue for GPSValue {
fn from_value(v: &Value) -> Result<Self> {
let int_to_appropriate_width = |v: &Value| {
v.as_integer()
- .ok_or(GPSE::from_kind(GPSEK::HeaderTypeError)).and_then(i64_to_i8)
+ .ok_or(GPSE::from_kind(GPSEK::HeaderTypeError))
};
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)
- }
-}