Convert ImprovPackets back to bytes
This commit is contained in:
22
src/main.rs
22
src/main.rs
@@ -117,28 +117,22 @@ async fn main() -> Result<()>{
|
||||
.fold(String::new(), |a, b| a + &b + &String::from("\n")));
|
||||
},
|
||||
Commands::Device {path, baud_rate, device_command} => {
|
||||
let mut rpc_command_request_current_state: Vec<u8> = Vec::new();
|
||||
rpc_command_request_current_state.extend(IMPROV_HEADER);
|
||||
rpc_command_request_current_state.push(IMPROV_VERSION);
|
||||
rpc_command_request_current_state.push(PacketType::RPCCommand as u8);
|
||||
|
||||
let mut data: Vec<u8> = Vec::new();
|
||||
data.push(RPCCommand::RequestCurrentState as u8); // command
|
||||
data.push(0x00); // command data length
|
||||
|
||||
rpc_command_request_current_state.push(data.len().try_into().unwrap()); // length
|
||||
rpc_command_request_current_state.extend(data.clone()); // data
|
||||
let request_current_state_packet = ImprovPacket {
|
||||
version: IMPROV_VERSION,
|
||||
r#type: PacketType::RPCCommand,
|
||||
data: data,
|
||||
};
|
||||
|
||||
let checksum: u8 = calculate_checksum(&rpc_command_request_current_state);
|
||||
println!("{}", hex::encode([checksum.clone()]));
|
||||
rpc_command_request_current_state.push(checksum);
|
||||
|
||||
println!("{}", hex::encode(&rpc_command_request_current_state));
|
||||
println!("{}", to_ascii_debug(&rpc_command_request_current_state));
|
||||
println!("{}", hex::encode(&request_current_state_packet.to_bytes()));
|
||||
println!("{}", to_ascii_debug(&request_current_state_packet.to_bytes()));
|
||||
|
||||
let mut serial_interface = tokio_serial::new(path, *baud_rate).open().unwrap();
|
||||
|
||||
serial_interface.write(&rpc_command_request_current_state).unwrap();
|
||||
serial_interface.write(&request_current_state_packet.to_bytes()).unwrap();
|
||||
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
serial_interface.read_to_end(&mut buffer);
|
||||
|
Reference in New Issue
Block a user