mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 10:30:14 +01:00
add warning for wrong endianness, clear pixel buffer
This commit is contained in:
parent
2fe6c3b6f1
commit
94868bbc73
|
@ -31,11 +31,9 @@ fn main() {
|
|||
env_logger::init();
|
||||
|
||||
let cli = Cli::parse();
|
||||
info!("running with args: {:?}", &cli);
|
||||
info!("starting with args: {:?}", &cli);
|
||||
|
||||
info!("display booting up");
|
||||
let (stop_udp_tx, stop_udp_rx) = mpsc::channel();
|
||||
|
||||
let thread = start_udp_thread(cli.bind, stop_udp_rx);
|
||||
|
||||
let event_loop = EventLoop::new().expect("could not create event loop");
|
||||
|
|
|
@ -82,13 +82,11 @@ enum DisplaySubcommand {
|
|||
*/
|
||||
|
||||
fn handle_package(received: &mut [u8]) {
|
||||
let header = read_hdr_window(&received[..10]);
|
||||
if let Err(err) = header {
|
||||
warn!("could not read header: {}", err);
|
||||
return;
|
||||
}
|
||||
let header = match read_hdr_window(&received[..10]){
|
||||
None => return,
|
||||
Some(value) => value
|
||||
};
|
||||
|
||||
let header = header.unwrap();
|
||||
let payload = &received[10..];
|
||||
|
||||
info!(
|
||||
|
@ -99,7 +97,10 @@ fn handle_package(received: &mut [u8]) {
|
|||
|
||||
match header.command {
|
||||
DisplayCommand::CmdClear => {
|
||||
info!("(imagine an empty screen now)")
|
||||
info!("clearing display");
|
||||
for v in unsafe { DISPLAY.iter_mut() } {
|
||||
*v = false;
|
||||
}
|
||||
}
|
||||
DisplayCommand::CmdHardReset => {
|
||||
warn!("display shutting down");
|
||||
|
@ -117,18 +118,29 @@ fn handle_package(received: &mut [u8]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_hdr_window(buffer: &[u8]) -> Result<HdrWindow, String> {
|
||||
fn read_hdr_window(buffer: &[u8]) -> Option<HdrWindow> {
|
||||
if buffer.len() < size_of::<HdrWindow>() {
|
||||
return Err("received a packet that is too small".into());
|
||||
error!("received a packet that is too small");
|
||||
return None;
|
||||
}
|
||||
|
||||
let command_u16 = read_beu16_from_buffer(&buffer[0..=1]);
|
||||
let maybe_command = num::FromPrimitive::from_u16(command_u16);
|
||||
if maybe_command.is_none() {
|
||||
return Err(format!("received invalid command {}", command_u16));
|
||||
error!("received invalid command {}", command_u16);
|
||||
|
||||
let maybe_command: Option<DisplayCommand> = num::FromPrimitive::from_u16(u16::swap_bytes(command_u16));
|
||||
if let Some(command) = maybe_command {
|
||||
error!(
|
||||
"The reversed byte order of {} matches command {:?}, you are probably sending the wrong endianness",
|
||||
command_u16, command
|
||||
);
|
||||
}
|
||||
|
||||
return Ok(HdrWindow {
|
||||
return None;
|
||||
}
|
||||
|
||||
return Some(HdrWindow {
|
||||
command: maybe_command.unwrap(),
|
||||
x: read_beu16_from_buffer(&buffer[2..=3]),
|
||||
y: read_beu16_from_buffer(&buffer[4..=5]),
|
||||
|
|
Loading…
Reference in a new issue