Skip to content

Commit e5e4815

Browse files
committed
Use zerocopy for service messages
1 parent 6615aed commit e5e4815

File tree

8 files changed

+305
-242
lines changed

8 files changed

+305
-242
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/rt633/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/std/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/std/src/bin/thermal.rs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use static_cell::StaticCell;
1212
use std::sync::atomic::AtomicUsize;
1313
use std::sync::atomic::Ordering;
1414
use thermal_service as ts;
15-
use thermal_service_messages::ThermalRequest;
15+
use thermal_service_messages::{
16+
ThermalGetTmpRequest, ThermalGetVarRequest, ThermalRequest, ThermalSetThrsRequest, ThermalSetVarRequest,
17+
};
1618
use ts::mptf;
1719

1820
// Mock host service
@@ -21,7 +23,7 @@ mod host {
2123
use embedded_services::comms::{self, Endpoint, EndpointID, External, MailboxDelegate};
2224
use log::{info, warn};
2325
use thermal_service as ts;
24-
use thermal_service_messages::{ThermalResponse, ThermalResult};
26+
use thermal_service_messages::{ThermalGetTmpResponse, ThermalGetVarResponse, ThermalResponse, ThermalResult};
2527
use ts::mptf;
2628

2729
pub struct Host {
@@ -39,10 +41,10 @@ mod host {
3941

4042
fn handle_response(&self, response: ThermalResponse) {
4143
match response {
42-
ThermalResponse::ThermalGetTmpResponse { temperature } => {
44+
ThermalResponse::ThermalGetTmpResponse(ThermalGetTmpResponse { temperature }) => {
4345
info!("Host received temperature: {} °C", ts::utils::dk_to_c(temperature))
4446
}
45-
ThermalResponse::ThermalGetVarResponse { val } => {
47+
ThermalResponse::ThermalGetVarResponse(ThermalGetVarResponse { val }) => {
4648
info!("Host received fan RPM: {val}")
4749
}
4850
_ => info!("Received MPTF response: {response:?}"),
@@ -219,12 +221,12 @@ async fn host() {
219221
host.tp
220222
.send(
221223
thermal_id,
222-
&ThermalRequest::ThermalSetThrsRequest {
224+
&ThermalRequest::ThermalSetThrsRequest(ThermalSetThrsRequest {
223225
instance_id: 0,
224-
timeout: 0,
225-
low: 0,
226-
high: 3131,
227-
},
226+
timeout: 0.into(),
227+
low: 0.into(),
228+
high: 3131.into(),
229+
}),
228230
)
229231
.await
230232
.unwrap();
@@ -234,12 +236,12 @@ async fn host() {
234236
host.tp
235237
.send(
236238
thermal_id,
237-
&ThermalRequest::ThermalSetVarRequest {
239+
&ThermalRequest::ThermalSetVarRequest(ThermalSetVarRequest {
238240
instance_id: 0,
239-
len: 4,
241+
len: 4.into(),
240242
var_uuid: mptf::uuid_standard::FAN_ON_TEMP,
241-
set_var: 3131,
242-
},
243+
set_var: 3131.into(),
244+
}),
243245
)
244246
.await
245247
.unwrap();
@@ -249,12 +251,12 @@ async fn host() {
249251
host.tp
250252
.send(
251253
thermal_id,
252-
&ThermalRequest::ThermalSetVarRequest {
254+
&ThermalRequest::ThermalSetVarRequest(ThermalSetVarRequest {
253255
instance_id: 0,
254-
len: 4,
256+
len: 4.into(),
255257
var_uuid: mptf::uuid_standard::FAN_RAMP_TEMP,
256-
set_var: 3231,
257-
},
258+
set_var: 3231.into(),
259+
}),
258260
)
259261
.await
260262
.unwrap();
@@ -264,12 +266,12 @@ async fn host() {
264266
host.tp
265267
.send(
266268
thermal_id,
267-
&ThermalRequest::ThermalSetVarRequest {
269+
&ThermalRequest::ThermalSetVarRequest(ThermalSetVarRequest {
268270
instance_id: 0,
269-
len: 4,
271+
len: 4.into(),
270272
var_uuid: mptf::uuid_standard::FAN_MAX_TEMP,
271-
set_var: 3531,
272-
},
273+
set_var: 3531.into(),
274+
}),
273275
)
274276
.await
275277
.unwrap();
@@ -281,7 +283,10 @@ async fn host() {
281283

282284
info!("Host requesting temperature in response to threshold alert");
283285
host.tp
284-
.send(thermal_id, &ThermalRequest::ThermalGetTmpRequest { instance_id: 0 })
286+
.send(
287+
thermal_id,
288+
&ThermalRequest::ThermalGetTmpRequest(ThermalGetTmpRequest { instance_id: 0 }),
289+
)
285290
.await
286291
.unwrap();
287292

@@ -292,11 +297,11 @@ async fn host() {
292297
host.tp
293298
.send(
294299
thermal_id,
295-
&ThermalRequest::ThermalGetVarRequest {
300+
&ThermalRequest::ThermalGetVarRequest(ThermalGetVarRequest {
296301
instance_id: 0,
297-
len: 4,
302+
len: 4.into(),
298303
var_uuid: mptf::uuid_standard::FAN_CURRENT_RPM,
299-
},
304+
}),
300305
)
301306
.await
302307
.unwrap();

thermal-service-messages/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ defmt = { workspace = true, optional = true }
1010
embedded-services.workspace = true
1111
num_enum.workspace = true
1212
uuid.workspace = true
13+
zerocopy.workspace = true
1314

1415
[lints]
1516
workspace = true

0 commit comments

Comments
 (0)