use chrono::prelude::*;
use crate::{
ubx_checksum, MemWriter, MemWriterError, PositionLLA, UbxPacketCreator, UbxPacketMeta,
};
use ublox_derive::ubx_packet_send;
#[ubx_packet_send]
#[ubx(
class = 0x0B,
id = 0x01,
fixed_payload_len = 48,
flags = "default_for_builder"
)]
struct AidIni {
ecef_x_or_lat: i32,
ecef_y_or_lon: i32,
ecef_z_or_alt: i32,
pos_accuracy: u32,
time_cfg: u16,
week_or_ym: u16,
tow_or_hms: u32,
tow_ns: i32,
tm_accuracy_ms: u32,
tm_accuracy_ns: u32,
clk_drift_or_freq: i32,
clk_drift_or_freq_accuracy: u32,
flags: u32,
}
impl AidIniBuilder {
pub fn set_position(mut self, pos: PositionLLA) -> Self {
self.ecef_x_or_lat = (pos.lat * 10_000_000.0) as i32;
self.ecef_y_or_lon = (pos.lon * 10_000_000.0) as i32;
self.ecef_z_or_alt = (pos.alt * 100.0) as i32; self.flags |= (1 << 0) | (1 << 5);
self
}
pub fn set_time(mut self, tm: DateTime<Utc>) -> Self {
self.week_or_ym = (match tm.year_ce() {
(true, yr) => yr - 2000,
(false, _) => {
panic!("AID-INI packet only supports years after 2000");
},
} * 100
+ tm.month0()) as u16;
self.tow_or_hms = tm.hour() * 10000 + tm.minute() * 100 + tm.second();
self.tow_ns = tm.nanosecond() as i32;
self.flags |= (1 << 1) | (1 << 10);
self
}
}