forked from M-Labs/thermostat
config: switch to postcard encoding
This commit is contained in:
parent
5d0d75d395
commit
d40a038c2f
51
Cargo.lock
generated
51
Cargo.lock
generated
@ -174,10 +174,26 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "half"
|
name = "hash32"
|
||||||
version = "1.6.0"
|
version = "0.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177"
|
checksum = "d4041af86e63ac4298ce40e5cca669066e75b6f1aa3390fe2561ffa5e1d9f4cc"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heapless"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "74911a68a1658cfcfb61bc0ccfbd536e3b6e906f8c2f7883ee50157e3e2184f1"
|
||||||
|
dependencies = [
|
||||||
|
"as-slice",
|
||||||
|
"generic-array 0.13.2",
|
||||||
|
"hash32",
|
||||||
|
"serde",
|
||||||
|
"stable_deref_trait",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
@ -257,6 +273,23 @@ dependencies = [
|
|||||||
"cortex-m-semihosting",
|
"cortex-m-semihosting",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "postcard"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b3e3f5c2e9a91383c6594ec68aa2dfdfe19a3c86f34b088ba7203f2483d2682f"
|
||||||
|
dependencies = [
|
||||||
|
"heapless",
|
||||||
|
"postcard-cobs",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "postcard-cobs"
|
||||||
|
version = "0.1.5-pre"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7c68cb38ed13fd7bc9dd5db8f165b7c8d9c1a315104083a2b10f11354c2af97f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
@ -320,16 +353,6 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_cbor"
|
|
||||||
version = "0.11.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622"
|
|
||||||
dependencies = [
|
|
||||||
"half",
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.116"
|
version = "1.0.116"
|
||||||
@ -440,8 +463,8 @@ dependencies = [
|
|||||||
"num-traits",
|
"num-traits",
|
||||||
"panic-abort",
|
"panic-abort",
|
||||||
"panic-semihosting",
|
"panic-semihosting",
|
||||||
|
"postcard",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_cbor",
|
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
"stm32-eth",
|
"stm32-eth",
|
||||||
"stm32f4xx-hal",
|
"stm32f4xx-hal",
|
||||||
|
@ -34,7 +34,7 @@ nb = "0.1"
|
|||||||
uom = { version = "0.29", default-features = false, features = ["autoconvert", "si", "f64", "use_serde"] }
|
uom = { version = "0.29", default-features = false, features = ["autoconvert", "si", "f64", "use_serde"] }
|
||||||
eeprom24x = "0.3"
|
eeprom24x = "0.3"
|
||||||
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
serde = { version = "1.0", default-features = false, features = ["derive"] }
|
||||||
serde_cbor = { version = "0.11.1", default-features = false }
|
postcard = "0.5.1"
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git" }
|
stm32f4xx-hal = { git = "https://github.com/stm32-rs/stm32f4xx-hal.git" }
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
use serde_cbor::Serializer;
|
use postcard::to_slice;
|
||||||
use serde_cbor::ser::SliceWrite;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
channel_state::ChannelState,
|
channel_state::ChannelState,
|
||||||
channels::{CHANNELS, Channels},
|
channels::{CHANNELS, Channels},
|
||||||
@ -25,13 +24,12 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode(&self, buffer: &mut [u8]) -> Result<usize, serde_cbor::Error> {
|
pub fn encode<'a>(&self, buffer: &'a mut [u8]) -> Result<&'a mut [u8], postcard::Error> {
|
||||||
let writer = SliceWrite::new(buffer);
|
to_slice(self, buffer)
|
||||||
let mut ser = Serializer::new(writer);
|
}
|
||||||
self.serialize(&mut ser)?;
|
|
||||||
let writer = ser.into_inner();
|
pub fn decode(buffer: &[u8]) -> Result<Self, postcard::Error> {
|
||||||
let size = writer.bytes_written();
|
from_bytes(buffer)
|
||||||
Ok(size)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,10 +432,10 @@ fn main() -> ! {
|
|||||||
Command::Load => {}
|
Command::Load => {}
|
||||||
Command::Save => {
|
Command::Save => {
|
||||||
let config = Config::new(&mut channels);
|
let config = Config::new(&mut channels);
|
||||||
let mut buf = [0; 0x200];
|
let mut buf = [0; 128];
|
||||||
match config.encode(&mut buf) {
|
match config.encode(&mut buf) {
|
||||||
Ok(len) => {
|
Ok(buf) => {
|
||||||
let _ = writeln!(socket, "Encoded: {:?}", &buf[..len]);
|
let _ = writeln!(socket, "Encoded {}: {:?}", buf.len(), buf);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = writeln!(socket, "Error encoding configuration: {}", e);
|
let _ = writeln!(socket, "Error encoding configuration: {}", e);
|
||||||
|
Loading…
Reference in New Issue
Block a user