From d54a73244ad7ad8056433ec1494c467d531c9b19 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 27 Dec 2024 16:10:07 +0100 Subject: [PATCH] update micodus_server --- .gitattributes | 1 + Cargo.lock | 40 +++++++++++++++++++ Cargo.toml | 1 + ...Data Protocol for MV55G MV66--20230612.pdf | 3 ++ src/parser/body.rs | 21 +++++++++- src/parser/mod.rs | 8 ++++ 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 doc/MiCODUS OBD Data Protocol for MV55G MV66--20230612.pdf diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b634d85 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.pdf filter=lfs diff=lfs merge=lfs -text diff --git a/Cargo.lock b/Cargo.lock index c5ac929..a73a93e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,6 +53,18 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -80,6 +92,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "getrandom" version = "0.2.15" @@ -124,6 +142,7 @@ name = "micodus_server" version = "0.1.0" dependencies = [ "bcd-convert", + "bitvec", "encoding_rs", "rand", "tokio", @@ -214,6 +233,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -301,6 +326,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "thiserror" version = "1.0.69" @@ -435,6 +466,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 9c3d74e..5d4b52b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] bcd-convert = { version = "0.1" } +bitvec = { version = "1.0.1" } encoding_rs = { version = "0.8" } rand = { version = "0.8" } tokio = { version = "1.42", features = ["full", "sync"] } diff --git a/doc/MiCODUS OBD Data Protocol for MV55G MV66--20230612.pdf b/doc/MiCODUS OBD Data Protocol for MV55G MV66--20230612.pdf new file mode 100644 index 0000000..fc84e99 --- /dev/null +++ b/doc/MiCODUS OBD Data Protocol for MV55G MV66--20230612.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d245f6e4be5a881736bd83217a9e56be337804687f329b393559092981d62d5d +size 238868 diff --git a/src/parser/body.rs b/src/parser/body.rs index b4453a3..a71a0ff 100644 --- a/src/parser/body.rs +++ b/src/parser/body.rs @@ -144,6 +144,7 @@ impl TerminalRegistration { res.answer_serial_no = serial; res.result = TerminalRegistrationResult::Success as u8; //res.authentication_code = String::from_utf8(terminal_id).unwrap(); + println!("{:?}", terminal_id); res.authentication_code = vec![0x36, 0x31, 0x33, 0x32, 0x31, 0x31, 0x38]; res } @@ -208,6 +209,14 @@ impl TerminalLogout { pub const ID: u16 = 0x0003; pub fn parse(&mut self, rawbody: &Vec) {} + + pub fn generate_reply(&self, answer_id: u16, serial: u16) -> PlatformUniversalResponse { + let mut res = PlatformUniversalResponse::default(); + res.answer_serial_no = serial; + res.answer_id = answer_id; + res.result = TerminalRegistrationResult::Success as u8; + res + } } impl std::fmt::Display for TerminalLogout { @@ -309,7 +318,7 @@ pub struct LocationInformationReport { pub height: u16, pub speed: u16, pub direction: u16, - pub time: u64, + pub time: String, } impl LocationInformationReport { @@ -377,7 +386,7 @@ impl LocationInformationReport { tmptime[i] = *bd.next().unwrap(); } let code = BcdNumber::try_from(&tmptime as &[u8]).unwrap(); - self.time = code.to_u64().unwrap(); + self.time = format!("{}", code.to_u64().unwrap()); } pub fn generate_reply(&self, answer_id: u16, serial: u16) -> PlatformUniversalResponse { @@ -405,6 +414,14 @@ impl EndOfTrip { pub fn parse(&mut self, rawbody: &Vec) {} } +struct BCDTime { + pub time: String, +} + +impl BCDTime { + pub fn parse() {} +} + generate_impl!( TerminalUniversalResponse, PlatformUniversalResponse, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f9cb529..d24b716 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -284,6 +284,14 @@ impl Message { reply.header.serial_number = rng.gen(); reply.content = MessageType::PlatformUniversalResponse(cnt); } + MessageType::TerminalLogout(t) => { + let cnt = t.generate_reply(TerminalHeartbeat::ID, inmsg.header.serial_number); + reply.header.id = PlatformUniversalResponse::ID; + reply.header.raw_terminal_id = inmsg.header.raw_terminal_id; + reply.header.properties = cnt.to_raw().len() as u16; + reply.header.serial_number = rng.gen(); + reply.content = MessageType::PlatformUniversalResponse(cnt); + } _ => { println!("no type"); return None;