mirror of
https://github.com/linux-msm/sk8brd.git
synced 2026-02-25 13:13:15 -08:00
main.rs: stubby handle all calls
Signed-off-by: Konrad Dybcio <konradybcio@kernel.org>
This commit is contained in:
committed by
Konrad Dybcio
parent
d9740766b0
commit
79972d496c
@@ -5,6 +5,7 @@ use std::mem::size_of;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum Sk8brdMsgs {
|
||||
MsgSelectBoard = 1,
|
||||
MsgConsole,
|
||||
@@ -139,7 +140,7 @@ pub fn send_vbus_ctrl(write_sink: &mut impl Write, en: bool) {
|
||||
}
|
||||
|
||||
#[allow(clippy::explicit_write)]
|
||||
pub fn list_device(buf: &[u8], len: u16) {
|
||||
pub fn print_string_msg(buf: &[u8], len: u16) {
|
||||
if len == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
25
src/main.rs
25
src/main.rs
@@ -1,7 +1,7 @@
|
||||
use clap::Parser;
|
||||
use colored::Colorize;
|
||||
use sk8brd::{
|
||||
console_print, list_device, parse_recv_msg, select_brd, send_ack, send_image, send_msg,
|
||||
console_print, parse_recv_msg, print_string_msg, select_brd, send_ack, send_image, send_msg,
|
||||
Sk8brdMsgs, MSG_HDR_SIZE,
|
||||
};
|
||||
use ssh2::Session;
|
||||
@@ -116,15 +116,16 @@ async fn main() {
|
||||
sess.set_blocking(true);
|
||||
let msg = parse_recv_msg(&hdr_buf);
|
||||
|
||||
// Now read the actual data
|
||||
// Now read the actual data...
|
||||
chan.read_exact(&mut buf[..msg.len as usize]).unwrap();
|
||||
|
||||
// And process it
|
||||
// ..and process it
|
||||
match msg.r#type.try_into() {
|
||||
Ok(Sk8brdMsgs::MsgSelectBoard) => {
|
||||
send_msg(&mut chan, Sk8brdMsgs::MsgPowerOn, 0, &[0])
|
||||
}
|
||||
Ok(Sk8brdMsgs::MsgConsole) => console_print(&buf, msg.len),
|
||||
Ok(Sk8brdMsgs::MsgHardReset) => todo!("MsgHardReset is unused"),
|
||||
Ok(Sk8brdMsgs::MsgPowerOn) => (),
|
||||
Ok(Sk8brdMsgs::MsgPowerOff) => (),
|
||||
Ok(Sk8brdMsgs::MsgFastbootPresent) => {
|
||||
@@ -132,11 +133,19 @@ async fn main() {
|
||||
send_image(&mut chan, &fastboot_image)
|
||||
}
|
||||
}
|
||||
Ok(Sk8brdMsgs::MsgListDevices) => list_device(&buf, msg.len),
|
||||
Ok(m) => writeln!(stdout(), "unknown message type {m:?}").unwrap(),
|
||||
Err(e) => {
|
||||
writeln!(stdout(), "got error '{e}' while processing msg: {msg:?}").unwrap()
|
||||
}
|
||||
Ok(Sk8brdMsgs::MsgFastbootDownload) => (),
|
||||
Ok(Sk8brdMsgs::MsgFastbootBoot) => todo!("MsgFastbootBoot is unused"),
|
||||
Ok(Sk8brdMsgs::MsgStatusUpdate) => todo!("MsgStatusUpdate: implement me!"),
|
||||
Ok(Sk8brdMsgs::MsgVbusOn) => todo!("Unexpected MsgVbusOn"),
|
||||
Ok(Sk8brdMsgs::MsgVbusOff) => todo!("Unexpected MsgVbusOff"),
|
||||
Ok(Sk8brdMsgs::MsgFastbootReboot) => todo!("MsgFastbootReboot is unused"),
|
||||
Ok(Sk8brdMsgs::MsgSendBreak) => todo!("MsgSendBreak: implement me!"),
|
||||
Ok(Sk8brdMsgs::MsgListDevices) => print_string_msg(&buf, msg.len),
|
||||
Ok(Sk8brdMsgs::MsgBoardInfo) => print_string_msg(&buf, msg.len),
|
||||
Ok(Sk8brdMsgs::MsgFastbootContinue) => (),
|
||||
|
||||
Ok(m) => todo!("{m:?} is unimplemented, skipping.."),
|
||||
Err(e) => todo!("Received unknown/invalid message: `{e}`"),
|
||||
};
|
||||
sess.set_blocking(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user