diff --git a/Cargo.lock b/Cargo.lock index 6647cf0..fcb922d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -574,9 +574,9 @@ checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "pdl-compiler" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d277c9e6a1869e95522f9bd532bc225f85c03434b48cd914524235910f9ccdbe" +checksum = "6853e3b47aa4a5be1287e9115d6fae9b3118971eba855f4d60323d19a66c07cf" dependencies = [ "argh", "codespan-reporting", @@ -593,9 +593,9 @@ dependencies = [ [[package]] name = "pdl-runtime" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce05e0a116b0250bb41732e2858eada706aebdf311d7f832898c9256bb442abe" +checksum = "a8684812e36689336c83de6033669573b33b6e59c831145ee496c38a71ed0d7c" dependencies = [ "bytes", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index faddcd2..03ed1c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ default = ["web"] web = ["hyper", "tokio/rt-multi-thread"] [build-dependencies] -pdl-compiler = "0.2.3" +pdl-compiler = "0.3.0" [dependencies] anyhow = "1.0.56" @@ -55,7 +55,7 @@ log = "0.4.20" env_logger = "0.11.1" num-derive = "0.3.3" num-traits = "0.2.17" -pdl-runtime = "0.2.2" +pdl-runtime = "0.3.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0.49" diff --git a/build.rs b/build.rs index 3535d03..c99bdd8 100644 --- a/build.rs +++ b/build.rs @@ -39,7 +39,7 @@ fn generate_module(in_file: &Path) { ) .expect("PDL parse failed"); let analyzed_file = pdl_compiler::analyzer::analyze(&parsed_file).expect("PDL analysis failed"); - let rust_source = pdl_compiler::backends::rust::generate(&sources, &analyzed_file); + let rust_source = pdl_compiler::backends::rust_legacy::generate(&sources, &analyzed_file); out_file .write_all(rust_source.as_bytes()) .expect("Could not write to output file"); diff --git a/src/device.rs b/src/device.rs index eec1c7f..62f3ffc 100644 --- a/src/device.rs +++ b/src/device.rs @@ -19,6 +19,7 @@ use crate::PicaCommand; use std::collections::HashMap; use std::time::Duration; +use pdl_runtime::Packet; use tokio::sync::mpsc; use tokio::time; @@ -142,8 +143,13 @@ impl Device { let tx = self.tx.clone(); tokio::spawn(async move { time::sleep(Duration::from_millis(5)).await; - tx.send(CoreDeviceStatusNtfBuilder { device_state }.build().into()) - .unwrap() + tx.send( + CoreDeviceStatusNtfBuilder { device_state } + .build() + .encode_to_vec() + .unwrap(), + ) + .unwrap() }); } @@ -194,8 +200,13 @@ impl Device { } // Send a response or notification to the Host. - fn send_control(&mut self, packet: impl Into>) { - let _ = self.tx.send(packet.into()); + fn send_raw_control(&mut self, packet: Vec) { + let _ = self.tx.send(packet); + } + + // Send a response or notification to the Host. + fn send_control(&mut self, packet: impl Packet) { + self.send_raw_control(packet.encode_to_vec().unwrap()); } // The fira norm specify to send a response, then reset, then @@ -753,7 +764,8 @@ impl Device { session_token: session_handle, } .build() - .into(), + .encode_to_vec() + .unwrap(), ) .unwrap() }); @@ -1050,7 +1062,7 @@ impl Device { 1, status.into(), ]; - self.send_control(response) + self.send_raw_control(response) } // Parsing success, ignore non command packets. diff --git a/src/lib.rs b/src/lib.rs index 8810bd6..f8260b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ // limitations under the License. use anyhow::Result; +use pdl_runtime::Packet; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::fmt::Display; @@ -477,7 +478,8 @@ impl Pica { status: uci::Status::Ok, } .build() - .into(), + .encode_to_vec() + .unwrap(), ) .unwrap(); } @@ -495,7 +497,8 @@ impl Pica { vendor_data: vec![], } .build() - .into(), + .encode_to_vec() + .unwrap(), ) .unwrap(); diff --git a/src/session.rs b/src/session.rs index f3ee408..54b98a2 100644 --- a/src/session.rs +++ b/src/session.rs @@ -19,6 +19,7 @@ use crate::packets::uci::{self, *}; use crate::{AppConfig, MacAddress}; use bytes::BytesMut; +use pdl_runtime::Packet; use std::time::Duration; use tokio::sync::mpsc; use tokio::task::JoinHandle; @@ -80,7 +81,8 @@ impl Session { reason_code: reason_code.into(), } .build() - .into(), + .encode_to_vec() + .unwrap(), ) .unwrap() });