Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", optional = true }
toml = "0.8"

# ASTM F3411 Remote ID message encoding
remoteid = { version = "0.3.2", default-features = false }

# Async runtime
tokio = { version = "1", features = ["full"] }
async-trait = "0.1"
Expand Down
23 changes: 15 additions & 8 deletions src/security/remote_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ impl RemoteIdBroadcast {
}

/// Encode a 25-byte ASTM F3411 Basic ID message.
/// Format: [message_type(1)] [id_type(1)] [uas_id(20)] [reserved(3)]
/// Format: [type(4)|version(4)] [id_type(4)|ua_type(4)] [uas_id(20)] [reserved(3)]
pub fn encode_basic_id(&self) -> [u8; 25] {
let mut buf = [0u8; 25];
buf[0] = 0x00; // Message type: Basic ID
buf[1] = 0x01; // ID type: Serial Number
buf[2..22].copy_from_slice(&self.uas_id);
// bytes 22-24: reserved
buf
remoteid::BasicId {
protocol_version: remoteid::PROTOCOL_VERSION,
id_type: remoteid::IdType::SerialNumber,
ua_type: remoteid::UaType::HelicopterOrMultirotor,
uas_id: self.uas_id,
}
.encode()
.expect("fixed Basic ID fields are valid nibbles")
}
}

Expand All @@ -95,7 +97,12 @@ mod tests {
let rid = RemoteIdBroadcast::new([0x41u8; 20]);
let buf = rid.encode_basic_id();
assert_eq!(buf.len(), 25);
assert_eq!(buf[1], 0x01); // ID type: serial number
assert_eq!(buf[0], 0x02); // Basic ID, protocol version 2
assert_eq!(buf[1], 0x12); // ID type: serial number, UA type: multirotor
let decoded = remoteid::BasicId::decode(&buf).unwrap();
assert_eq!(decoded.id_type, remoteid::IdType::SerialNumber);
assert_eq!(decoded.ua_type, remoteid::UaType::HelicopterOrMultirotor);
assert_eq!(decoded.uas_id, [0x41u8; 20]);
}

#[test]
Expand Down