TMP: Add message generator
This commit is contained in:
parent
4d7bef58a1
commit
202d874dee
2 changed files with 95 additions and 0 deletions
|
|
@ -14,6 +14,12 @@ name = "test"
|
|||
path = "./src/test.rs"
|
||||
required-features = ["std", "cam"]
|
||||
|
||||
[[bin]]
|
||||
## run with cargo run --target host-tuple --bin test-proto --no-default-features -F std,uart
|
||||
name = "test-proto"
|
||||
path = "./src/test-proto.rs"
|
||||
required-features = ["std", "uart", "cam"]
|
||||
|
||||
[features]
|
||||
default = ["esp", "spat", "gnss", "screen"]
|
||||
|
||||
|
|
|
|||
89
src/test-proto.rs
Normal file
89
src/test-proto.rs
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#![cfg(not(target_arch = "riscv32"))]
|
||||
#![allow(unused)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod applogic;
|
||||
mod io;
|
||||
mod v2x_tx;
|
||||
|
||||
fn main() {
|
||||
use prost::Message as _;
|
||||
|
||||
// env_logger::init();
|
||||
|
||||
// generate some test UART messages as hex strings
|
||||
let raw_its = input_from_raw(io::msg::RawMsgTx {
|
||||
payload: [0xaa, 0xbb, 0xcc, 0xdd].to_vec(),
|
||||
message_type: 1,
|
||||
gn_transport: io::msg::GnTransport::Shb.into(),
|
||||
gn_area: io::msg::GnArea {
|
||||
area: None,
|
||||
position: None,
|
||||
dist_a: None,
|
||||
dist_b: None,
|
||||
angle: None,
|
||||
},
|
||||
hop_limit: 2,
|
||||
station_type: None,
|
||||
});
|
||||
println!("{}", serialize_serial_msg_hex(&raw_its));
|
||||
|
||||
let pos = input_from_position(io::msg::PositionState {
|
||||
timestamp_ms: 1785144196000,
|
||||
position: io::msg::Position {
|
||||
latitude_deg: 42.,
|
||||
longitude_deg: 23.,
|
||||
},
|
||||
heading: None,
|
||||
speed: None,
|
||||
});
|
||||
println!("{}", serialize_serial_msg_hex(&pos));
|
||||
}
|
||||
|
||||
fn input_from_raw(value: io::msg::RawMsgTx) -> io::msg::SerialInputMsg {
|
||||
use io::msg::serial_input_msg::Payload;
|
||||
|
||||
io::msg::SerialInputMsg {
|
||||
payload: Some(Payload::TxMsg(value)),
|
||||
}
|
||||
}
|
||||
fn input_from_position(value: io::msg::PositionState) -> io::msg::SerialInputMsg {
|
||||
use io::msg::serial_input_msg::Payload;
|
||||
|
||||
io::msg::SerialInputMsg {
|
||||
payload: Some(Payload::Position(value)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn serialize_serial_msg_hex(msg: &io::msg::SerialInputMsg) -> alloc::string::String {
|
||||
use prost::Message as _;
|
||||
|
||||
let mut msg_buf = msg.encode_to_vec();
|
||||
|
||||
let sof = [0x56u8, 0x32, 0x58, 0x2B];
|
||||
let eof = [0x0du8, 0x0a];
|
||||
let len: [u8; 2] = (msg_buf.len() as u16).to_be_bytes();
|
||||
|
||||
let mut out = sof.to_vec();
|
||||
out.extend_from_slice(&len);
|
||||
out.append(&mut msg_buf);
|
||||
out.extend_from_slice(&eof);
|
||||
|
||||
// convert to hex string
|
||||
let mut hex_str = alloc::string::String::default();
|
||||
for c in out {
|
||||
hex_str.push_str(format!("{c:02x}").as_str());
|
||||
}
|
||||
|
||||
hex_str
|
||||
}
|
||||
|
||||
// /// Initializes the env-logger to be used inside tests
|
||||
// fn init_test_env_logger() {
|
||||
// let _ = env_logger::builder()
|
||||
// .format_timestamp(None)
|
||||
// .filter_level(log::LevelFilter::Debug)
|
||||
// .is_test(true)
|
||||
// .try_init();
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue