Skip to content

Commit

Permalink
Update to pdl 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaEvo committed Jun 3, 2024
1 parent bb23e87 commit e84edf5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
24 changes: 18 additions & 6 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
});
}

Expand Down Expand Up @@ -194,8 +200,13 @@ impl Device {
}

// Send a response or notification to the Host.
fn send_control(&mut self, packet: impl Into<Vec<u8>>) {
let _ = self.tx.send(packet.into());
fn send_raw_control(&mut self, packet: Vec<u8>) {
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
Expand Down Expand Up @@ -753,7 +764,8 @@ impl Device {
session_token: session_handle,
}
.build()
.into(),
.encode_to_vec()
.unwrap(),
)
.unwrap()
});
Expand Down Expand Up @@ -1050,7 +1062,7 @@ impl Device {
1,
status.into(),
];
self.send_control(response)
self.send_raw_control(response)
}

// Parsing success, ignore non command packets.
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -477,7 +478,8 @@ impl Pica {
status: uci::Status::Ok,
}
.build()
.into(),
.encode_to_vec()
.unwrap(),
)
.unwrap();
}
Expand All @@ -495,7 +497,8 @@ impl Pica {
vendor_data: vec![],
}
.build()
.into(),
.encode_to_vec()
.unwrap(),
)
.unwrap();

Expand Down
4 changes: 3 additions & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +81,8 @@ impl Session {
reason_code: reason_code.into(),
}
.build()
.into(),
.encode_to_vec()
.unwrap(),
)
.unwrap()
});
Expand Down

0 comments on commit e84edf5

Please sign in to comment.