2021-03-25 15:39:35 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2021-03-26 04:33:30 +00:00
|
|
|
use core::fmt::Write;
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
fn print_log_messages(log_message: &str, prefix: &str) {
|
2021-03-26 04:16:26 +00:00
|
|
|
log::info!(
|
|
|
|
|
"Got a message hook! Message: [{}], prefix: [{}]",
|
|
|
|
|
log_message,
|
|
|
|
|
prefix
|
|
|
|
|
);
|
2021-03-25 15:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-02 08:40:17 +00:00
|
|
|
fn handle_battstats(bs: com::BattStats) {
|
|
|
|
|
log::info!("battstats: {:?}", bs);
|
2021-04-02 09:58:03 +00:00
|
|
|
// note: at this point to repatriate data into the core main loop, you have two options:
|
|
|
|
|
// 1. send a new message to the server, using your own private API. This feels "wasteful"
|
|
|
|
|
// as you're bouncing a message twice but it keeps the API spaces strictly on crate boundaries
|
|
|
|
|
// 2. use an Atomic type to transfer primitive data types from the handler thread to the main thread
|
2021-04-02 08:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn rkyv_test_client() -> ! {
|
|
|
|
|
log_server::init_wait().unwrap();
|
|
|
|
|
log::info!(
|
|
|
|
|
"Hello, world! This is the client, PID {}",
|
|
|
|
|
xous::current_pid().unwrap().get()
|
|
|
|
|
);
|
2021-03-28 10:14:41 +00:00
|
|
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("couldn't create ticktimer object");
|
2021-03-25 15:39:35 +00:00
|
|
|
|
|
|
|
|
rkyv_test_server::hook_log_messages(print_log_messages);
|
|
|
|
|
|
|
|
|
|
let mut idx = 0;
|
2021-03-26 04:40:47 +00:00
|
|
|
|
|
|
|
|
// This is just some number. It should change width, ensuring our padding
|
|
|
|
|
// is working and we're not overwriting the buffer weirdly.
|
|
|
|
|
let mut some_number = 98653i32;
|
|
|
|
|
let mut double_src = xous::String::<256>::new();
|
2021-03-26 04:33:30 +00:00
|
|
|
|
|
|
|
|
let mut message_string = xous::String::<64>::new();
|
2021-04-02 08:40:17 +00:00
|
|
|
|
|
|
|
|
let xns = xous_names::XousNames::new().unwrap();
|
|
|
|
|
let mut com = com::Com::new(xns).unwrap();
|
|
|
|
|
com.hook_batt_stats(handle_battstats);
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
loop {
|
|
|
|
|
log::info!("2 + {} = {}", idx, rkyv_test_server::add(2, idx).unwrap());
|
2021-03-28 10:14:41 +00:00
|
|
|
ticktimer.sleep_ms(500).ok();
|
2021-03-26 04:33:30 +00:00
|
|
|
|
|
|
|
|
message_string.clear();
|
2021-03-26 04:40:47 +00:00
|
|
|
write!(message_string, "I'm at loop # {:^4} (some numer: {})", idx, some_number).unwrap();
|
|
|
|
|
some_number = some_number.wrapping_mul(53);
|
2021-03-26 04:33:30 +00:00
|
|
|
rkyv_test_server::log_message("prefix", message_string);
|
2021-03-26 04:40:47 +00:00
|
|
|
|
|
|
|
|
double_src.clear();
|
|
|
|
|
write!(double_src, "12345678 Loop {} 🎉 你好", idx).unwrap();
|
2021-03-26 04:16:26 +00:00
|
|
|
log::info!("Doubling string {}", double_src);
|
|
|
|
|
log::info!("Doubled string: {}", rkyv_test_server::double_string(&double_src));
|
2021-03-26 09:17:03 +00:00
|
|
|
|
|
|
|
|
let sent_str = xous::String::<32>::from_str("This got moved");
|
|
|
|
|
log::info!("Sending a string \"{}\"", sent_str);
|
|
|
|
|
rkyv_test_server::log_message("prefix", sent_str);
|
|
|
|
|
|
2021-04-02 08:40:17 +00:00
|
|
|
com.req_batt_stats();
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
idx += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-26 04:40:47 +00:00
|
|
|
|