-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathbuild.rs
111 lines (92 loc) · 3.33 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use std::env;
use std::io::Write;
use std::path::Path;
fn build_nav_database() {
let outdir = env::var("OUT_DIR").unwrap();
let nav_path = Path::new(&outdir).join("nav_orbits.rs");
let mut nav_file = std::fs::File::create(nav_path).unwrap();
// read helper descriptor
let nav_descriptor = std::fs::read_to_string("db/NAV/orbits.json").unwrap();
// parse
let json: serde_json::Value = serde_json::from_str(&nav_descriptor).unwrap();
let nav_frames = json.as_array().unwrap();
let nav_content = "use lazy_static::lazy_static;
use crate::{
prelude::{Version, Constellation},
navigation::NavMessageType,
};
#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[derive(Eq, Ord)]
pub struct NavHelper<'a> {
pub constellation: Constellation,
pub version: Version,
pub msg: NavMessageType,
pub items: Vec<(&'a str, &'a str)>,
}
// NAV FRAMES description, from RINEX standards
";
nav_file.write_all(nav_content.as_bytes()).unwrap();
nav_file.write_all("lazy_static! {\n".as_bytes()).unwrap();
nav_file.write_all("#[derive(Debug)]\n".as_bytes()).unwrap();
nav_file
.write_all(" pub static ref NAV_ORBITS: Vec<NavHelper<'static>> = vec![ \n".as_bytes())
.unwrap();
for frame in nav_frames {
// grab all fields
let constellation = frame["constellation"].as_str().unwrap(); // mandatory
let major = frame["version"]["major"].as_u64().unwrap(); // major is mandatory
let minor = frame["version"]["minor"].as_u64().unwrap_or(0); // optionnal
let msg = frame["type"].as_str().unwrap_or("LNAV"); // default type
let items = frame["orbits"].as_object().unwrap(); // mandatory
// begin frame description
nav_file.write_all(" ( NavHelper {\n".as_bytes()).unwrap();
nav_file
.write_all(
format!(
" constellation: Constellation::from_str(\"{}\").unwrap(),\n",
constellation
)
.as_bytes(),
)
.unwrap();
nav_file
.write_all(" version: Version {\n".as_bytes())
.unwrap();
nav_file
.write_all(format!(" major: {},\n", major).as_bytes())
.unwrap();
nav_file
.write_all(format!(" minor: {},\n", minor).as_bytes())
.unwrap();
nav_file.write_all(" },\n".as_bytes()).unwrap();
nav_file
.write_all(
format!(
" msg: NavMessageType::from_str(\"{}\").unwrap(),\n",
msg
)
.as_bytes(),
)
.unwrap();
// frame body description
nav_file
.write_all(" items: vec![ \n".as_bytes())
.unwrap();
for key in items.keys() {
nav_file
.write_all(format!(" (\"{}\",{}),\n", key, items[key]).as_bytes())
.unwrap();
}
nav_file.write_all(" ],\n".as_bytes()).unwrap();
nav_file.write_all(" }),\n".as_bytes()).unwrap();
}
nav_file
.write_all(" ];\n".as_bytes()) // NAV_ORBITS vec![
.unwrap();
nav_file
.write_all("}\n".as_bytes()) // lazy_static!
.unwrap();
}
fn main() {
build_nav_database();
}