```
feat(protocol): Observation坐标字段可选化及协议v2扩展 - 将Observation中longitude/latitude/altitude_m/heading_deg改为Option类型, 支持无位置信息的观测数据 - 新增DeviceTelemetry结构体承载设备遥测扩展字段(serial, mac, model, rssi, speed, vertical_speed, pressure_altitude, geometric_altitude, height_agl, pilot_position等) - 新增LegacyObservation兼容结构体及From转换,保持旧接收器协议输入兼容 - PROTOCOL_VERSION从1升至2 - 新增coordinates()辅助方法统一提取有效坐标 - validate()适配Option类型,允许坐标字段同时缺失 - Store新增position_generation机制追踪位置可用性变化,确保合并帧间的 位置丢失仍能正确断开轨迹 - geofence-map-adapter过滤无效坐标避免渲染异常 - 新增appearance.css外观主题系统,支持blue/graphite/white三套配色 ```
This commit is contained in:
@@ -133,8 +133,8 @@ pub struct Alert {
|
||||
pub target_id: String,
|
||||
pub fence_id: Option<String>,
|
||||
pub fence_name: Option<String>,
|
||||
pub longitude: f64,
|
||||
pub latitude: f64,
|
||||
pub longitude: Option<f64>,
|
||||
pub latitude: Option<f64>,
|
||||
pub list_kind: String,
|
||||
}
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -5,7 +5,7 @@ pub mod geofences;
|
||||
pub mod map_settings;
|
||||
pub mod target_lists;
|
||||
|
||||
pub const PROTOCOL_VERSION: u16 = 1;
|
||||
pub const PROTOCOL_VERSION: u16 = 2;
|
||||
pub const MAX_BATCH: usize = 4096;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
@@ -15,14 +15,20 @@ pub struct Observation {
|
||||
/// Monotonically increasing receiver boot/session number.
|
||||
pub source_epoch: u64,
|
||||
pub sequence: u64,
|
||||
pub longitude: f64,
|
||||
pub latitude: f64,
|
||||
pub longitude: Option<f64>,
|
||||
pub latitude: Option<f64>,
|
||||
/// WGS84 ellipsoid altitude in metres, not height above ground.
|
||||
pub altitude_m: f32,
|
||||
pub heading_deg: f32,
|
||||
pub altitude_m: Option<f32>,
|
||||
pub heading_deg: Option<f32>,
|
||||
#[serde(default)]
|
||||
pub telemetry: Option<DeviceTelemetry>,
|
||||
}
|
||||
|
||||
impl Observation {
|
||||
pub fn coordinates(&self) -> Option<[f64; 2]> {
|
||||
Some([self.longitude?, self.latitude?])
|
||||
}
|
||||
|
||||
pub fn validate(&self) -> bool {
|
||||
fn identity(s: &str) -> bool {
|
||||
!s.is_empty()
|
||||
@@ -32,14 +38,22 @@ impl Observation {
|
||||
}
|
||||
identity(&self.target_id)
|
||||
&& identity(&self.receiver_id)
|
||||
&& self.longitude.is_finite()
|
||||
&& (-180.0..=180.0).contains(&self.longitude)
|
||||
&& self.latitude.is_finite()
|
||||
&& (-90.0..=90.0).contains(&self.latitude)
|
||||
&& self.altitude_m.is_finite()
|
||||
&& (-1000.0..=100000.0).contains(&self.altitude_m)
|
||||
&& self.heading_deg.is_finite()
|
||||
&& (0.0..360.0).contains(&self.heading_deg)
|
||||
&& match (self.longitude, self.latitude) {
|
||||
(None, None) => true,
|
||||
(Some(lon), Some(lat)) => {
|
||||
lon.is_finite()
|
||||
&& (-180.0..=180.0).contains(&lon)
|
||||
&& lat.is_finite()
|
||||
&& (-90.0..=90.0).contains(&lat)
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
&& self
|
||||
.altitude_m
|
||||
.is_none_or(|v| v.is_finite() && (-1000.0..=100000.0).contains(&v))
|
||||
&& self
|
||||
.heading_deg
|
||||
.is_none_or(|v| v.is_finite() && (0.0..360.0).contains(&v))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +61,8 @@ impl Observation {
|
||||
pub struct Target {
|
||||
pub observation: Observation,
|
||||
pub received_at_ms: u64,
|
||||
/// Changes on every position availability transition, even between coalesced frames.
|
||||
pub position_generation: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
@@ -70,3 +86,51 @@ pub struct Metrics {
|
||||
pub capacity: usize,
|
||||
pub sequence: u64,
|
||||
}
|
||||
|
||||
/// Fields reported by the device; height reference systems are never interchanged.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
|
||||
pub struct DeviceTelemetry {
|
||||
pub serial: Option<String>,
|
||||
pub mac: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub name: Option<String>,
|
||||
pub ssid: Option<String>,
|
||||
pub ua_type: Option<u8>,
|
||||
pub rssi: Option<f64>,
|
||||
pub frequency_mhz: Option<f64>,
|
||||
pub speed_mps: Option<f64>,
|
||||
pub vertical_speed_mps: Option<f64>,
|
||||
pub pressure_altitude_m: Option<f64>,
|
||||
pub geometric_altitude_m: Option<f64>,
|
||||
pub height_agl_m: Option<f64>,
|
||||
pub pilot_position: Option<[f64; 2]>,
|
||||
pub utc_raw: Option<String>,
|
||||
}
|
||||
|
||||
/// Original receiver wire contract, retained for JSON and Postcard input compatibility.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct LegacyObservation {
|
||||
pub target_id: String,
|
||||
pub receiver_id: String,
|
||||
pub source_epoch: u64,
|
||||
pub sequence: u64,
|
||||
pub longitude: f64,
|
||||
pub latitude: f64,
|
||||
pub altitude_m: f32,
|
||||
pub heading_deg: f32,
|
||||
}
|
||||
impl From<LegacyObservation> for Observation {
|
||||
fn from(o: LegacyObservation) -> Self {
|
||||
Self {
|
||||
target_id: o.target_id,
|
||||
receiver_id: o.receiver_id,
|
||||
source_epoch: o.source_epoch,
|
||||
sequence: o.sequence,
|
||||
longitude: Some(o.longitude),
|
||||
latitude: Some(o.latitude),
|
||||
altitude_m: Some(o.altitude_m),
|
||||
heading_deg: Some(o.heading_deg),
|
||||
telemetry: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user