Added gridlocator calculation
This commit is contained in:
parent
f005c5c178
commit
77b732824b
|
@ -18,6 +18,8 @@ stm32f1xx-hal = { version = "~0.6.1", features = ["stm32f103", "rt"] }
|
|||
embedded-hal = {version = "~0.2.3"}
|
||||
nb = "~1.0.0"
|
||||
nmea0183 = "~0.2.3"
|
||||
arrayvec = {version = "~0.7.0", default-features = false}
|
||||
|
||||
|
||||
[features]
|
||||
# set logging levels here
|
||||
|
|
|
@ -5,6 +5,7 @@ use panic_probe as _;
|
|||
use stm32f1xx_hal as _;
|
||||
|
||||
pub mod application;
|
||||
pub mod loc;
|
||||
pub mod time;
|
||||
|
||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
use arrayvec::ArrayString;
|
||||
|
||||
const FIELD_SYMBOLS: &str = "ABCDEFGHIJKLMNOPQR";
|
||||
const SUBSQUARE_SYMBOLS: &str = "abcdefghijklmnopqrstuvwx";
|
||||
|
||||
pub fn locator_from_coordinates(lat: f32, long: f32) -> ArrayString<6> {
|
||||
let mut target_buf = ArrayString::<6>::new();
|
||||
|
||||
let false_east = if long < 180.0 {
|
||||
long + 180.0
|
||||
} else {
|
||||
long - 180.0
|
||||
};
|
||||
|
||||
let false_north = if lat < 90.0 { lat + 90.0 } else { lat - 90.0 };
|
||||
|
||||
let long_field = ((false_east / 20.0) as usize);
|
||||
let mut long_rest = false_east % 20.0;
|
||||
target_buf.push(FIELD_SYMBOLS.chars().nth(long_field).unwrap());
|
||||
|
||||
let lat_field = ((false_north / 10.0) as usize);
|
||||
let mut lat_rest = false_north % 10.0;
|
||||
target_buf.push(FIELD_SYMBOLS.chars().nth(lat_field).unwrap());
|
||||
|
||||
let long_square = (long_rest / 2.0) as u32;
|
||||
long_rest = long_rest % 2.0;
|
||||
target_buf.push(char::from_digit(long_square, 10).unwrap());
|
||||
|
||||
let lat_square = (lat_rest / 1.0) as u32;
|
||||
lat_rest = lat_rest % 1.0;
|
||||
target_buf.push(char::from_digit(lat_square, 10).unwrap());
|
||||
|
||||
let long_subsquare = (long_rest / 2.0 * 24.0) as usize;
|
||||
target_buf.push(SUBSQUARE_SYMBOLS.chars().nth(long_subsquare).unwrap());
|
||||
|
||||
let lat_subsquare = (lat_rest / 1.0 * 24.0) as usize;
|
||||
target_buf.push(SUBSQUARE_SYMBOLS.chars().nth(lat_subsquare).unwrap());
|
||||
|
||||
return target_buf;
|
||||
}
|
|
@ -7,7 +7,7 @@ edition = "2018"
|
|||
version = "0.1.0"
|
||||
|
||||
[[test]]
|
||||
name = "test"
|
||||
name = "loc"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
|
@ -18,6 +18,7 @@ defmt = "0.2.0"
|
|||
defmt-rtt = "0.2.0"
|
||||
defmt-test = "0.2.0"
|
||||
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||
arrayvec = {version = "~0.7.0", default-features = false}
|
||||
|
||||
[features]
|
||||
# set logging levels here
|
||||
|
|
|
@ -7,15 +7,14 @@ use wspr_beacon as _; // memory layout + panic handler
|
|||
// feature)
|
||||
#[defmt_test::tests]
|
||||
mod tests {
|
||||
use arrayvec::ArrayString;
|
||||
use defmt::{assert, assert_eq};
|
||||
use wspr_beacon::loc;
|
||||
|
||||
#[test]
|
||||
fn assert_true() {
|
||||
assert!(true)
|
||||
}
|
||||
let res = loc::locator_from_coordinates(49.4395, 7.7635);
|
||||
|
||||
#[test]
|
||||
fn assert_eq() {
|
||||
assert_eq!(24, 42, "TODO: write actual tests")
|
||||
assert_eq!(res.as_str(), "JN39vk")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue