From 2e680a9f30b6c78a88739742148c19688c0ed206 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Fri, 27 Mar 2020 21:13:47 +0300 Subject: [PATCH 01/26] support msp version 2 --- Cargo.toml | 1 + src/lib.rs | 2 + src/packet.rs | 143 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 127 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c5b4022..d42902b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ packed_struct = "0.2" packed_struct_codegen = "0.2" serde = "1.0" serde_derive = "1.0" +crc-any = "2.3" [features] default = ["std"] diff --git a/src/lib.rs b/src/lib.rs index 1db7ec1..937e3f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,8 @@ extern crate alloc; extern crate packed_struct; +extern crate crc_any; + #[macro_use] extern crate packed_struct_codegen; diff --git a/src/packet.rs b/src/packet.rs index c9b5926..01a0931 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -1,4 +1,6 @@ use prelude::v1::*; +use crc_any::CRCu8; + /// Packet parsing error #[derive(Copy, Clone, Debug, PartialEq)] @@ -38,7 +40,7 @@ impl MspPacketDirection { #[derive(Debug, Clone, PartialEq)] /// A decoded MSP packet, with a command code, direction and payload pub struct MspPacket<'a> { - pub cmd: u8, + pub cmd: u16, pub direction: MspPacketDirection, pub data: Cow<'a, [u8]> } @@ -48,33 +50,47 @@ enum MspParserState { Header1, Header2, Direction, + FlagV2, DataLength, + DataLengthV2, Command, + CommandV2, Data, - Crc + DataV2, + Crc, +} + +#[derive(Copy, Clone, PartialEq, Debug)] +enum MSPVersion { + V1, + V2, } #[derive(Debug)] /// Parser that can find packets from a raw byte stream pub struct MspParser { state: MspParserState, + packet_version: MSPVersion, packet_direction: MspPacketDirection, - packet_cmd: u8, + packet_cmd: u16, packet_data_length_remaining: usize, packet_data: Vec, - packet_crc: u8 + packet_crc: u8, + packet_crc_v2: CRCu8, } impl MspParser { /// Create a new parser pub fn new() -> MspParser { - MspParser { + Self { state: MspParserState::Header1, + packet_version: MSPVersion::V1, packet_direction: MspPacketDirection::ToFlightController, packet_data_length_remaining: 0, packet_cmd: 0, packet_data: Vec::new(), - packet_crc: 0 + packet_crc: 0, + packet_crc_v2: CRCu8::crc8dvb_s2(), } } @@ -96,29 +112,84 @@ impl MspParser { }, MspParserState::Header2 => { - if input == ('M' as u8) { - self.state = MspParserState::Direction; - } else { - self.reset(); - } + self.packet_version = match input as char { + 'M' => MSPVersion::V1, + 'X' => MSPVersion::V2, + _=> { + self.reset(); + return Ok(None); + }, + }; + + self.state = MspParserState::Direction; }, MspParserState::Direction => { match input { - 60 => self.packet_direction = MspPacketDirection::ToFlightController, - 62 => self.packet_direction = MspPacketDirection::FromFlightController, - 33 => self.packet_direction = MspPacketDirection::Unsupported, + 60 => self.packet_direction = MspPacketDirection::ToFlightController, // '>' + 62 => self.packet_direction = MspPacketDirection::FromFlightController, // '<' + 33 => self.packet_direction = MspPacketDirection::Unsupported, // '!' error _ => { self.reset(); return Ok(None); } } - self.state = MspParserState::DataLength; + self.state = match self.packet_version { + MSPVersion::V1 => MspParserState::DataLength, + MSPVersion::V2 => MspParserState::FlagV2, + }; }, - MspParserState::DataLength => { + MspParserState::FlagV2 => { + // uint8, flag, usage to be defined (set to zero) + self.state = MspParserState::CommandV2; + self.packet_data = Vec::with_capacity(2); + self.packet_crc_v2.digest(&[input]); + }, + + MspParserState::CommandV2 => { + self.packet_data.push(input); + + if self.packet_data.len() == 2 { + let mut s = [0; 2]; + s.copy_from_slice(&self.packet_data); + self.packet_cmd = u16::from_le_bytes(s); + + self.packet_crc_v2.digest(&self.packet_data); + self.packet_data.clear(); + self.state = MspParserState::DataLengthV2; + } + }, + + MspParserState::DataLengthV2 => { + self.packet_data.push(input); + + if self.packet_data.len() == 2 { + let mut s = [0; 8]; + s[0..2].copy_from_slice(&self.packet_data); + self.packet_data_length_remaining = usize::from_le_bytes(s); + self.packet_crc_v2.digest(&self.packet_data); + self.packet_data = Vec::with_capacity(self.packet_data_length_remaining as usize); + + if self.packet_data_length_remaining == 0 { + self.state = MspParserState::Crc; + } else { + self.state = MspParserState::DataV2; + } + } + }, + + MspParserState::DataV2 => { + self.packet_data.push(input); + self.packet_data_length_remaining -= 1; + + if self.packet_data_length_remaining == 0 { + self.state = MspParserState::Crc; + } + }, + MspParserState::DataLength => { self.packet_data_length_remaining = input as usize; self.state = MspParserState::Command; self.packet_crc ^= input; @@ -127,7 +198,7 @@ impl MspParser { MspParserState::Command => { - self.packet_cmd = input; + self.packet_cmd = input as u16; if self.packet_data_length_remaining == 0 { self.state = MspParserState::Crc; @@ -153,6 +224,10 @@ impl MspParser { }, MspParserState::Crc => { + if self.packet_version == MSPVersion::V2 { + self.packet_crc_v2.digest(&self.packet_data); + self.packet_crc = self.packet_crc_v2.get_crc(); + } let packet_crc = self.packet_crc; if input != packet_crc { @@ -186,6 +261,7 @@ impl MspParser { self.packet_cmd = 0; self.packet_data.clear(); self.packet_crc = 0; + self.packet_crc_v2.reset(); } } @@ -195,6 +271,11 @@ impl<'a> MspPacket<'a> { 6 + self.data.len() } + /// Number of bytes that this packet requires to be packed + pub fn packet_size_bytes_v2(&self) -> usize { + 9 + self.data.len() + } + /// Serialize to network bytes pub fn serialize(&self, output: &mut [u8]) -> Result<(), MspPacketParseError> { let l = output.len(); @@ -207,7 +288,7 @@ impl<'a> MspPacket<'a> { output[1] = 'M' as u8; output[2] = self.direction.to_byte(); output[3] = self.data.len() as u8; - output[4] = self.cmd; + output[4] = self.cmd as u8; output[5..l - 1].copy_from_slice(&self.data); @@ -220,6 +301,30 @@ impl<'a> MspPacket<'a> { Ok(()) } + + /// Serialize to network bytes + pub fn serialize_v2(&self, output: &mut [u8]) -> Result<(), MspPacketParseError> { + let l = output.len(); + + if l != self.packet_size_bytes_v2() { + return Err(MspPacketParseError::OutputBufferSizeMismatch); + } + + output[0] = '$' as u8; + output[1] = 'X' as u8; + output[2] = self.direction.to_byte(); + output[3] = 0; + output[4..6].copy_from_slice(&self.cmd.to_le_bytes()); + output[6..8].copy_from_slice(&(self.data.len() as u16).to_le_bytes()); + + output[8..l - 1].copy_from_slice(&self.data); + + let mut crc = CRCu8::crc8dvb_s2(); + crc.digest(&output[3..l - 1]); + output[l - 1] = crc.get_crc(); + + Ok(()) + } } @@ -301,4 +406,4 @@ fn test_roundtrip() { }; roundtrip(&packet); } -} \ No newline at end of file +} From 797a2a644b4642165de4e826116a0d292f776146 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Fri, 27 Mar 2020 21:13:47 +0300 Subject: [PATCH 02/26] fix msp v2 packet parsing --- src/packet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packet.rs b/src/packet.rs index 01a0931..68353bb 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -167,7 +167,7 @@ impl MspParser { if self.packet_data.len() == 2 { let mut s = [0; 8]; - s[0..2].copy_from_slice(&self.packet_data); + s[5..7].copy_from_slice(&self.packet_data); self.packet_data_length_remaining = usize::from_le_bytes(s); self.packet_crc_v2.digest(&self.packet_data); self.packet_data = Vec::with_capacity(self.packet_data_length_remaining as usize); From 4f95d40accabcffd09cd7b2ce1c117142a738d17 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Fri, 1 May 2020 00:04:10 +0300 Subject: [PATCH 03/26] fork multiwii-serial-protocol --- Cargo.toml | 8 ++++---- README.md | 8 +++++--- src/structs.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d42902b..8248b34 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "multiwii_serial_protocol" +name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" -repository = "https://github.com/hashmismatch/multiwii_serial_protocol.rs" -version = "0.1.1" -authors = ["Rudi Benkovic "] +repository = "https://github.com/amfern/multiwii_serial_protocol.rs" +version = "0.1.3" +authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/README.md b/README.md index 7a179a4..5a4a63e 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ A Multiwii Serial Protocol (MSP) implementation for Rust ## Introduction -An incomplete implementation of the MSP protocol, with some Cleanflight and Betaflight extensions. Allows one to implement a flight controller that can connect to the Cleanflight or Baseflight configurator. +This is a fork of https://github.com/hashmismatch/multiwii_serial_protocol.rs! + +An incomplete implementation of the MSP2 protocol, with some Cleanflight, Betaflight and iNav extensions. Allows one to implement a flight controller that can connect to the Cleanflight or Baseflight configurator. # Installation @@ -15,13 +17,13 @@ MSP is available on crates.io and can be included in your Cargo enabled project ```toml [dependencies] -multiwii_serial_protocol = "0.1.0" +multiwii_serial_protocol_2 = "0.1.3" ``` Then include it in your code like this: ```rust -extern crate multiwii_serial_protocol; +extern crate multiwii_serial_protocol_2; ``` License: MIT OR Apache-2.0 diff --git a/src/structs.rs b/src/structs.rs index 562d4bb..707a08d 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -449,4 +449,4 @@ fn test_mixer() { assert_eq!(3, m.mixer_mode.to_primitive()); let p = m.pack(); assert_eq!(&[3], &p); -} \ No newline at end of file +} From cebb423a2ff27f2f783106d61c9afbae1eb2ee4d Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Mon, 30 Mar 2020 22:36:07 +0300 Subject: [PATCH 04/26] use rust vec instead of Cow, avoid lifetime static to the caller --- src/packet.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/packet.rs b/src/packet.rs index 68353bb..2bfb402 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -39,10 +39,10 @@ impl MspPacketDirection { #[derive(Debug, Clone, PartialEq)] /// A decoded MSP packet, with a command code, direction and payload -pub struct MspPacket<'a> { +pub struct MspPacket { pub cmd: u16, pub direction: MspPacketDirection, - pub data: Cow<'a, [u8]> + pub data: Vec } #[derive(Copy, Clone, PartialEq, Debug)] @@ -101,7 +101,7 @@ impl MspParser { /// Parse the next input byte. Returns a valid packet whenever a full packet is received, otherwise /// restarts the state of the parser. - pub fn parse<'b>(&mut self, input: u8) -> Result>, MspPacketParseError> { + pub fn parse(&mut self, input: u8) -> Result, MspPacketParseError> { match self.state { MspParserState::Header1 => { if input == ('$' as u8) { @@ -167,7 +167,7 @@ impl MspParser { if self.packet_data.len() == 2 { let mut s = [0; 8]; - s[5..7].copy_from_slice(&self.packet_data); + s[0..2].copy_from_slice(&self.packet_data); self.packet_data_length_remaining = usize::from_le_bytes(s); self.packet_crc_v2.digest(&self.packet_data); self.packet_data = Vec::with_capacity(self.packet_data_length_remaining as usize); @@ -241,7 +241,7 @@ impl MspParser { let packet = MspPacket { cmd: self.packet_cmd, direction: self.packet_direction, - data: Cow::Owned(n) + data: n }; self.reset(); @@ -254,7 +254,7 @@ impl MspParser { Ok(None) } - fn reset(&mut self) { + pub fn reset(&mut self) { self.state = MspParserState::Header1; self.packet_direction = MspPacketDirection::ToFlightController; self.packet_data_length_remaining = 0; @@ -265,7 +265,7 @@ impl MspParser { } } -impl<'a> MspPacket<'a> { +impl MspPacket { /// Number of bytes that this packet requires to be packed pub fn packet_size_bytes(&self) -> usize { 6 + self.data.len() From 8ccba3b8805097987451217333f3576a3f4afbe9 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Wed, 15 Apr 2020 19:03:00 +0300 Subject: [PATCH 05/26] add msp2 message ids --- src/commands.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index 7850433..8ec98d9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -57,6 +57,9 @@ pub enum MspCommandCode { MSP_TRANSPONDER_CONFIG = 82, MSP_SET_TRANSPONDER_CONFIG = 83, + MSP_OSD_CONFIG = 84, //out message Get osd settings - baseflight + MSP_SET_OSD_CONFIG = 85, //in message Set osd settings - baseflight + MSP_LED_STRIP_MODECOLOR = 127, MSP_SET_LED_STRIP_MODECOLOR = 221, @@ -157,5 +160,11 @@ pub enum MspCommandCode { MSP_SET_PID_ADVANCED = 95, MSP_SENSOR_CONFIG = 96, - MSP_SET_SENSOR_CONFIG = 97 + MSP_SET_SENSOR_CONFIG = 97, + + MSP2_MOTOR_MIXER = 0x1005, + MSP2_SET_MOTOR_MIXER = 0x1006, + + MSP2_SERIAL_CONFIG = 0x1009, + MSP2_SET_SERIAL_CONFIG = 0x100A, } From 937f81691b4fb29e5b05c606790074c9caa72f08 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 16 Apr 2020 20:19:18 +0300 Subject: [PATCH 06/26] upgrade packet_struct to latest --- Cargo.toml | 4 ++-- src/commands.rs | 2 +- src/structs.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8248b34..e45a054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,8 @@ license = "MIT OR Apache-2.0" readme = "README.md" [dependencies] -packed_struct = "0.2" -packed_struct_codegen = "0.2" +packed_struct = "0.3" +packed_struct_codegen = "0.3" serde = "1.0" serde_derive = "1.0" crc-any = "2.3" diff --git a/src/commands.rs b/src/commands.rs index 8ec98d9..e58eca9 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,4 @@ -#[derive(PrimitiveEnum_u8)] +#[derive(PrimitiveEnum)] #[derive(Debug, Copy, Clone, PartialEq)] #[allow(non_camel_case_types)] diff --git a/src/structs.rs b/src/structs.rs index 707a08d..b0d50c9 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -279,7 +279,7 @@ pub struct MspRcChannelValue { pub value: u16 } -#[derive(PrimitiveEnum_u8, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum MspRcChannel { /// Ailerons Roll = 0, @@ -424,7 +424,7 @@ pub struct MspMixerConfig { pub mixer_mode: MixerMode } -#[derive(PrimitiveEnum_u8, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum MixerMode { Tri = 1, QuadPlus = 2, From d8ac5b4f296d202fff28fb12e9df70947f6d545b Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 16 Apr 2020 21:31:51 +0300 Subject: [PATCH 07/26] add msp structs --- src/structs.rs | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/src/structs.rs b/src/structs.rs index b0d50c9..298e8e3 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -125,6 +125,20 @@ pub struct MspDataFlashSummaryReply { pub used_size_bytes: u32 } +#[derive(PackedStruct, Serialize, Deserialize, Debug, Copy, Clone)] +#[packed_struct(bytes="1", endian="lsb", bit_numbering="msb0")] +pub struct MspDataFlashReply { + pub read_address: u32, + // pub payload: Vec, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "6", endian = "lsb", bit_numbering = "msb0")] +pub struct MspDataFlashRead { + pub read_address: u32, + pub read_length: u16, +} + #[derive(PackedStruct, Serialize, Deserialize, Debug, Copy, Clone)] #[packed_struct(endian="lsb")] pub struct MspAccTrim { @@ -424,6 +438,24 @@ pub struct MspMixerConfig { pub mixer_mode: MixerMode } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "4", endian = "lsb", bit_numbering = "msb0")] +pub struct MspModeRange { + pub box_id: u8, + #[packed_field(size_bits="8", ty="enum")] + pub aux_channel_index: MspRcChannel, + pub start_step: u8, + pub end_step: u8, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "5", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetModeRange { + pub index: u8, + #[packed_field(size_bytes="4")] + pub mode_range: MspModeRange, +} + #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum MixerMode { Tri = 1, @@ -439,6 +471,96 @@ pub enum MixerMode { OctoX8 = 11 } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "8", endian = "lsb", bit_numbering = "msb0")] +pub struct MspMotorMixer { + pub throttle: u16, + pub roll: u16, + pub pitch: u16, + pub yaw: u16, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "9", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetMotorMixer { + pub index: u8, + #[packed_field(size_bytes="8")] + pub motor_mixer: MspMotorMixer, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "13", endian = "lsb", bit_numbering = "msb0")] +pub struct OsdConfig { + pub video_system: u8, + pub units: u8, + pub rssi_alarm: u8, + pub capacity_warning: u16, + pub time_alarm: u16, + pub alt_alarm: u16, + pub dist_alarm: u16, + pub neg_alt_alarm: u16, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetGetOsdConfig { + pub item_index: u8, + #[packed_field(size_bytes="13")] + pub config: OsdConfig, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "2", endian = "lsb", bit_numbering = "msb0")] +pub struct OsdItemPosition { + pub col: u8, + pub row: u8, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetOsdLayout { + pub item_index: u8, + #[packed_field(size_bytes="2")] + pub item: OsdItemPosition, +} + +#[derive(Debug)] +pub struct OsdSettings { + pub osd_support: u8, + pub config: OsdConfig, + pub item_positions: Vec, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(endian = "lsb", bit_numbering = "msb0")] +pub struct SerialSetting { + pub index: u8, + pub function_mask: u32, + pub msp_baudrate_index: u8, + pub gps_baudrate_index: u8, + pub telemetry_baudrate_index: u8, + pub peripheral_baudrate_index: u8, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(endian = "lsb", bit_numbering = "msb0")] +pub struct MspServoMixRule { + pub index: u8, + pub target_channel: u8, + pub input_source: u8, + pub rate: u8, + pub speed: u8, + pub min: u8, + pub max: u8, + pub box_id: u8, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(endian = "lsb", bit_numbering = "msb0")] +pub struct MspRxMap { + pub map: [u8; 4], // MAX_MAPPABLE_RX_INPUTS +} + #[test] fn test_mixer() { use packed_struct::prelude::*; From 8e5a79470b36ab2e98f8d44389ca869afdc29ed8 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 19 Apr 2020 16:31:47 +0300 Subject: [PATCH 08/26] add inav common settings msp --- src/commands.rs | 6 +++++ src/structs.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index e58eca9..04a59c6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -162,9 +162,15 @@ pub enum MspCommandCode { MSP_SENSOR_CONFIG = 96, MSP_SET_SENSOR_CONFIG = 97, + MSP2_COMMON_SETTING = 0x1003, //in/out message Returns the value for a setting + MSP2_COMMON_SET_SETTING = 0x1004, //in message Sets the value for a setting + MSP2_MOTOR_MIXER = 0x1005, MSP2_SET_MOTOR_MIXER = 0x1006, + MSP2_COMMON_SETTING_INFO = 0x1007, + MSP2_COMMON_PG_LIST = 0x1008, + MSP2_SERIAL_CONFIG = 0x1009, MSP2_SET_SERIAL_CONFIG = 0x100A, } diff --git a/src/structs.rs b/src/structs.rs index 298e8e3..b06225a 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -129,7 +129,7 @@ pub struct MspDataFlashSummaryReply { #[packed_struct(bytes="1", endian="lsb", bit_numbering="msb0")] pub struct MspDataFlashReply { pub read_address: u32, - // pub payload: Vec, + // pub payload: Vec, // TODO: packed_struct should support dynamic size too the end } #[derive(PackedStruct, Debug, Copy, Clone)] @@ -561,6 +561,72 @@ pub struct MspRxMap { pub map: [u8; 4], // MAX_MAPPABLE_RX_INPUTS } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(endian = "lsb", bit_numbering = "msb0")] +pub struct MspSettingGroup { + pub group_id: u16, + pub start_id: u16, + pub end_id: u16, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(endian = "lsb", bit_numbering = "msb0")] +pub struct MspSettingInfoRequest { + pub null: u8, + pub id: u16, +} + + + +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +pub enum SettingMode { + ModeDirect = 0, + ModeLookup = 0x40, +} + +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +pub enum SettingType { + VarUint8 = 0, + VarInt8 = 1, + VarUint16 = 2, + VarInt16 = 3, + VarUint32 = 4, + VarFloat = 5, + VarString = 6, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "15", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSettingInfo { + // pub name: [u8; ?], null terminated strings + + // Parameter Group ID + pub group_id: u16, + + // Type, section and mode + #[packed_field(size_bits="8", ty="enum")] + pub section_type: SettingType, + pub setting_section: u8, + #[packed_field(size_bits="8", ty="enum")] + pub setting_mode: SettingMode, + + pub min: u32, + pub max: u32, + + // Absolute setting index + pub absolute_index: u16, + + // If the setting is profile based, send the current one + // and the count, both as uint8_t. For MASTER_VALUE, we + // send two zeroes, so the MSP client can assume there + pub profile_id: u8, + pub profile_count: u8, + + // if setting uses enum values, it will be written here + // pub enum_names: [String; ?] // TODO: packed_struct should support null terminated string parsing + // pub value: [u8; ?] +} + #[test] fn test_mixer() { use packed_struct::prelude::*; From 7ee20901084bde5b5432af4a65de020a5b529493 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Tue, 21 Apr 2020 17:49:47 +0300 Subject: [PATCH 09/26] rename section_type to setting_type --- src/structs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structs.rs b/src/structs.rs index b06225a..43bf60f 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -605,7 +605,7 @@ pub struct MspSettingInfo { // Type, section and mode #[packed_field(size_bits="8", ty="enum")] - pub section_type: SettingType, + pub setting_type: SettingType, pub setting_section: u8, #[packed_field(size_bits="8", ty="enum")] pub setting_mode: SettingMode, From 708c077bc7b744a62e0f5f69f32250fe0aad4720 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sat, 25 Apr 2020 23:08:38 +0300 Subject: [PATCH 10/26] use enum for serial baurdrates --- src/structs.rs | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 43bf60f..99d3a1a 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -529,17 +529,42 @@ pub struct OsdSettings { pub osd_support: u8, pub config: OsdConfig, pub item_positions: Vec, +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +pub enum Baudrate { + BaudAuto = 0, + Baud1200 = 1, + Baud2400 = 2, + Baud4800 = 3, + Baud9600 = 4, + Baud19200 = 5, + Baud38400 = 6, + Baud57600 = 7, + Baud115200 = 8, + Baud230400 = 9, + Baud250000 = 10, + Baud460800 = 11, + Baud921600 = 12, + Baud1000000 = 13, + Baud1500000 = 14, + Baud2000000 = 15, + Baud2470000 = 16 +} } #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(endian = "lsb", bit_numbering = "msb0")] -pub struct SerialSetting { - pub index: u8, +pub struct MspSerialSetting { + // #[packed_field(size_bits="8", ty="enum")] + pub identifier: u8, pub function_mask: u32, - pub msp_baudrate_index: u8, - pub gps_baudrate_index: u8, - pub telemetry_baudrate_index: u8, - pub peripheral_baudrate_index: u8, + #[packed_field(size_bits="8", ty="enum")] + pub msp_baudrate_index: Baudrate, + #[packed_field(size_bits="8", ty="enum")] + pub gps_baudrate_index: Baudrate, + #[packed_field(size_bits="8", ty="enum")] + pub telemetry_baudrate_index: Baudrate, + #[packed_field(size_bits="8", ty="enum")] + pub peripheral_baudrate_index: Baudrate, } #[derive(PackedStruct, Debug, Copy, Clone)] From 57348aaad64d638b515eee21b6196f7afee50701 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 26 Apr 2020 16:42:21 +0300 Subject: [PATCH 11/26] prefix osd layout with msp --- src/structs.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 99d3a1a..3d3c41d 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -490,7 +490,7 @@ pub struct MspSetMotorMixer { #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(bytes = "13", endian = "lsb", bit_numbering = "msb0")] -pub struct OsdConfig { +pub struct MspOsdConfig { pub video_system: u8, pub units: u8, pub rssi_alarm: u8, @@ -506,12 +506,12 @@ pub struct OsdConfig { pub struct MspSetGetOsdConfig { pub item_index: u8, #[packed_field(size_bytes="13")] - pub config: OsdConfig, + pub config: MspOsdConfig, } #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(bytes = "2", endian = "lsb", bit_numbering = "msb0")] -pub struct OsdItemPosition { +pub struct MspOsdItemPosition { pub col: u8, pub row: u8, } @@ -521,14 +521,16 @@ pub struct OsdItemPosition { pub struct MspSetOsdLayout { pub item_index: u8, #[packed_field(size_bytes="2")] - pub item: OsdItemPosition, + pub item: MspOsdItemPosition, } #[derive(Debug)] -pub struct OsdSettings { +pub struct MspOsdSettings { pub osd_support: u8, - pub config: OsdConfig, - pub item_positions: Vec, + pub config: MspOsdConfig, + pub item_positions: Vec, +} + #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum Baudrate { BaudAuto = 0, @@ -549,7 +551,6 @@ pub enum Baudrate { Baud2000000 = 15, Baud2470000 = 16 } -} #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(endian = "lsb", bit_numbering = "msb0")] From e11cbb5c1a796b8d5eb816132e135496605c3c5f Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 26 Apr 2020 17:38:37 +0300 Subject: [PATCH 12/26] redefine serial identifier with enum --- src/structs.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 3d3c41d..893c1fc 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -531,6 +531,22 @@ pub struct MspOsdSettings { pub item_positions: Vec, } +#[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] +pub enum SerialIdentifier { + None = 255, + USART1 = 0, + USART2 = 1, + USART3 = 2, + USART4 = 3, + USART5 = 4, + USART6 = 5, + USART7 = 6, + USART8 = 7, + UsbVcp = 20, + SoftSerial1 = 30, + SoftSerial2 = 31, +} + #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum Baudrate { BaudAuto = 0, @@ -555,8 +571,8 @@ pub enum Baudrate { #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(endian = "lsb", bit_numbering = "msb0")] pub struct MspSerialSetting { - // #[packed_field(size_bits="8", ty="enum")] - pub identifier: u8, + #[packed_field(size_bits="8", ty="enum")] + pub identifier: SerialIdentifier, pub function_mask: u32, #[packed_field(size_bits="8", ty="enum")] pub msp_baudrate_index: Baudrate, From 17cec50f594f550c41b6e2a993be75c2f9c983f6 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 26 Apr 2020 23:29:37 +0300 Subject: [PATCH 13/26] refactor msp servo mix rule packet --- src/structs.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 893c1fc..82f959f 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -585,12 +585,19 @@ pub struct MspSerialSetting { } #[derive(PackedStruct, Debug, Copy, Clone)] -#[packed_struct(endian = "lsb", bit_numbering = "msb0")] -pub struct MspServoMixRule { +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetServoMixRule { pub index: u8, + #[packed_field(size_bytes="8")] + pub servo_rule: MspServoMixRule, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "8", endian = "lsb", bit_numbering = "msb0")] +pub struct MspServoMixRule { pub target_channel: u8, pub input_source: u8, - pub rate: u8, + pub rate: u16, pub speed: u8, pub min: u8, pub max: u8, From ef9e45b85434759ed041fd3227e5028c2e6113b8 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 18 Jun 2020 16:13:21 +0300 Subject: [PATCH 14/26] upgrade version to 0.1.5 version 0.1.4 was released from different branch and no longer considred canon --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e45a054..bddd5c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.3" +version = "0.1.5" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" From 5fece2b39545c4648f66c62832a282e1901865a2 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 18 Jun 2020 16:17:41 +0300 Subject: [PATCH 15/26] add MspServoConfig packet --- src/structs.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/structs.rs b/src/structs.rs index 82f959f..c8ad35e 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -431,6 +431,28 @@ pub struct MspServos { pub servos: [u16; 8] } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "14", endian = "lsb", bit_numbering = "msb0")] +pub struct MspServoConfig { + pub min: u16, + pub max: u16, + pub middle: u16, + pub rate: u8, + pub unused1: u8, + pub unused2: u8, + pub forward_from_channel: u8, // Depracted, set to 255 for backward compatibility + pub reverse_input: u32, // Depracted, Input reversing is not required since it can be done on mixer level +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetServoConfig { + pub index: u8, + #[packed_field(size_bytes="14")] + pub servo_config: MspServoConfig, +} + + #[derive(PackedStruct, Serialize, Deserialize, Debug, Copy, Clone)] #[packed_struct(endian="lsb")] pub struct MspMixerConfig { From 01bde578fe637a04055eab70357edd5980c7f0c6 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 21 Jun 2020 20:34:29 +0300 Subject: [PATCH 16/26] implement inav osd layout --- src/commands.rs | 8 ++++++++ src/structs.rs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index 04a59c6..ce09fda 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -162,6 +162,7 @@ pub enum MspCommandCode { MSP_SENSOR_CONFIG = 96, MSP_SET_SENSOR_CONFIG = 97, + // Inav MSP2_COMMON_SETTING = 0x1003, //in/out message Returns the value for a setting MSP2_COMMON_SET_SETTING = 0x1004, //in message Sets the value for a setting @@ -173,4 +174,11 @@ pub enum MspCommandCode { MSP2_SERIAL_CONFIG = 0x1009, MSP2_SET_SERIAL_CONFIG = 0x100A, + + MSP2_INAV_OSD_LAYOUTS = 0x2012, + MSP2_INAV_OSD_SET_LAYOUT_ITEM = 0x2013, + MSP2_INAV_OSD_ALARMS = 0x2014, + MSP2_INAV_OSD_SET_ALARMS = 0x2015, + MSP2_INAV_OSD_PREFERENCES = 0x2016, + MSP2_INAV_OSD_SET_PREFERENCES = 0x2017, } diff --git a/src/structs.rs b/src/structs.rs index c8ad35e..9d2628a 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -546,6 +546,15 @@ pub struct MspSetOsdLayout { pub item: MspOsdItemPosition, } +// inav msp layout item +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetOsdLayoutItem { + pub layout_index: u8, + #[packed_field(size_bytes="3")] + pub item: MspSetOsdLayout, +} + #[derive(Debug)] pub struct MspOsdSettings { pub osd_support: u8, @@ -553,6 +562,13 @@ pub struct MspOsdSettings { pub item_positions: Vec, } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "2", endian = "lsb", bit_numbering = "msb0")] +pub struct MspOsdLayouts { + pub layout_count: u8, + pub item_count: u8, +} + #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum SerialIdentifier { None = 255, From 6bdc90668b8caa572ec25c736a889bb884e4588b Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Mon, 22 Jun 2020 12:41:20 +0300 Subject: [PATCH 17/26] bump version 0.1.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bddd5c5..8f00243 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.5" +version = "0.1.6" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" From 56d61c11a41114494205ebd62fb027d13c2bb1b5 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Mon, 22 Jun 2020 17:47:53 +0300 Subject: [PATCH 18/26] implement convert trait for baudate and serialidentifier --- src/prelude/std.rs | 3 +- src/structs.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/prelude/std.rs b/src/prelude/std.rs index a2a037a..f48a347 100644 --- a/src/prelude/std.rs +++ b/src/prelude/std.rs @@ -20,4 +20,5 @@ pub use std::io; pub use std::io::Write; pub use std::sync::Arc; pub use std::str::from_utf8; -pub use std::ops::Deref; \ No newline at end of file +pub use std::ops::Deref; +pub use std::convert::TryFrom; diff --git a/src/structs.rs b/src/structs.rs index 9d2628a..76e4c7b 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -585,6 +585,30 @@ pub enum SerialIdentifier { SoftSerial2 = 31, } +impl TryFrom for SerialIdentifier { + type Error = &'static str; + + fn try_from(value: u8) -> Result { + let serial = match value { + 255 => SerialIdentifier::None, + 0 => SerialIdentifier::USART1, + 1 => SerialIdentifier::USART2, + 2 => SerialIdentifier::USART3, + 3 => SerialIdentifier::USART4, + 4 => SerialIdentifier::USART5, + 5 => SerialIdentifier::USART6, + 6 => SerialIdentifier::USART7, + 7 => SerialIdentifier::USART8, + 20 => SerialIdentifier::UsbVcp, + 30 => SerialIdentifier::SoftSerial1, + 31 => SerialIdentifier::SoftSerial2, + _ => return Err("Serial identifier not found"), + }; + + Ok(serial) + } +} + #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum Baudrate { BaudAuto = 0, @@ -606,6 +630,59 @@ pub enum Baudrate { Baud2470000 = 16 } +impl TryFrom<&str> for Baudrate { + type Error = &'static str; + + fn try_from(value: &str) -> Result { + let baudrate = match value { + "0" => Baudrate::BaudAuto, + "1200" => Baudrate::Baud1200, + "2400" => Baudrate::Baud2400, + "4800" => Baudrate::Baud4800, + "9600" => Baudrate::Baud9600, + "19200" => Baudrate::Baud19200, + "38400" => Baudrate::Baud38400, + "57600" => Baudrate::Baud57600, + "115200" => Baudrate::Baud115200, + "230400" => Baudrate::Baud230400, + "250000" => Baudrate::Baud250000, + "460800" => Baudrate::Baud460800, + "921600" => Baudrate::Baud921600, + "1000000" => Baudrate::Baud1000000, + "1500000" => Baudrate::Baud1500000, + "2000000" => Baudrate::Baud2000000, + "2470000" => Baudrate::Baud2470000, + _ => return Err("Baudrate identifier not found"), + }; + + return Ok(baudrate); + } +} + +impl From for String { + fn from(value: Baudrate) -> Self { + match value { + Baudrate::BaudAuto => "0", + Baudrate::Baud1200 => "1200", + Baudrate::Baud2400 => "2400", + Baudrate::Baud4800 => "4800", + Baudrate::Baud9600 => "9600", + Baudrate::Baud19200 => "19200", + Baudrate::Baud38400 => "38400", + Baudrate::Baud57600 => "57600", + Baudrate::Baud115200 => "115200", + Baudrate::Baud230400 => "230400", + Baudrate::Baud250000 => "250000", + Baudrate::Baud460800 => "460800", + Baudrate::Baud921600 => "921600", + Baudrate::Baud1000000 => "1000000", + Baudrate::Baud1500000 => "1500000", + Baudrate::Baud2000000 => "2000000", + Baudrate::Baud2470000 => "2470000", + }.to_owned() + } +} + #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(endian = "lsb", bit_numbering = "msb0")] pub struct MspSerialSetting { From 0d8745bf244b70698885970e2fcb29783e22490e Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Mon, 22 Jun 2020 19:36:45 +0300 Subject: [PATCH 19/26] bump version 0.1.7 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8f00243..ba369e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.6" +version = "0.1.7" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" From 4396767dbf2c0885ff03daa57d324c4fe7ad3ab7 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Wed, 24 Jun 2020 11:48:32 +0300 Subject: [PATCH 20/26] add OSD_CHAR msp commands --- src/commands.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index ce09fda..5e50a91 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -60,6 +60,9 @@ pub enum MspCommandCode { MSP_OSD_CONFIG = 84, //out message Get osd settings - baseflight MSP_SET_OSD_CONFIG = 85, //in message Set osd settings - baseflight + MSP_OSD_CHAR_READ = 86, //out message Get osd settings - betaflight + MSP_OSD_CHAR_WRITE = 87, //in message Set osd settings - betaflight + MSP_LED_STRIP_MODECOLOR = 127, MSP_SET_LED_STRIP_MODECOLOR = 221, From 954a89ed18e1f489a92a52203989c3b8e861181f Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Wed, 24 Jun 2020 16:52:44 +0300 Subject: [PATCH 21/26] bump version 0.1.8 --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ba369e8..8a68b86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.7" +version = "0.1.8" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/README.md b/README.md index 5a4a63e..ee94566 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ MSP is available on crates.io and can be included in your Cargo enabled project ```toml [dependencies] -multiwii_serial_protocol_2 = "0.1.3" +multiwii_serial_protocol_2 = "0.1.8" ``` Then include it in your code like this: From 3863ad0286758cdac4e387fd52a056554048e12d Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 25 Jun 2020 15:45:15 +0300 Subject: [PATCH 22/26] support inav flavor of smix --- src/commands.rs | 3 +++ src/structs.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/commands.rs b/src/commands.rs index 5e50a91..e4d77ed 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -184,4 +184,7 @@ pub enum MspCommandCode { MSP2_INAV_OSD_SET_ALARMS = 0x2015, MSP2_INAV_OSD_PREFERENCES = 0x2016, MSP2_INAV_OSD_SET_PREFERENCES = 0x2017, + + MSP2_INAV_SERVO_MIXER = 0x2020, + MSP2_INAV_SET_SERVO_MIXER = 0x2021, } diff --git a/src/structs.rs b/src/structs.rs index 76e4c7b..c3da417 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -719,6 +719,24 @@ pub struct MspServoMixRule { pub box_id: u8, } +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "1", endian = "lsb", bit_numbering = "msb0")] +pub struct MspSetServoMixer { + pub index: u8, + #[packed_field(size_bytes="6")] + pub servo_rule: MspServoMixer, +} + +#[derive(PackedStruct, Debug, Copy, Clone)] +#[packed_struct(bytes = "6", endian = "lsb", bit_numbering = "msb0")] +pub struct MspServoMixer { + pub target_channel: u8, + pub input_source: u8, + pub rate: u16, + pub speed: u8, + pub condition_id: u8, +} + #[derive(PackedStruct, Debug, Copy, Clone)] #[packed_struct(endian = "lsb", bit_numbering = "msb0")] pub struct MspRxMap { From ba4d57508e6b17134f5f8a891f64d05a07b8dac9 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 25 Jun 2020 13:26:55 +0300 Subject: [PATCH 23/26] optional support common setting int32 feature --- Cargo.toml | 3 ++- src/structs.rs | 14 ++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a68b86..d790855 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,5 @@ crc-any = "2.3" [features] default = ["std"] std = [] -no_std = [] \ No newline at end of file +no_std = [] +suppport_int32_setting_type = [] \ No newline at end of file diff --git a/src/structs.rs b/src/structs.rs index c3da417..61eebaf 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -769,12 +769,14 @@ pub enum SettingMode { #[derive(PrimitiveEnum, Serialize, Deserialize, Debug, Copy, Clone, PartialEq)] pub enum SettingType { VarUint8 = 0, - VarInt8 = 1, - VarUint16 = 2, - VarInt16 = 3, - VarUint32 = 4, - VarFloat = 5, - VarString = 6, + VarInt8, + VarUint16, + VarInt16, + VarUint32, + #[cfg(feature = "suppport_int32_setting_type")] + VarInt32, + VarFloat, + VarString, } #[derive(PackedStruct, Debug, Copy, Clone)] From 38d4f48fd5a8995c186322c745180b90e1e8904c Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Thu, 25 Jun 2020 19:59:05 +0300 Subject: [PATCH 24/26] bump version 0.1.9 --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d790855..cf063d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.8" +version = "0.1.9" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/README.md b/README.md index ee94566..8c95550 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ MSP is available on crates.io and can be included in your Cargo enabled project ```toml [dependencies] -multiwii_serial_protocol_2 = "0.1.8" +multiwii_serial_protocol_2 = "0.1.9" ``` Then include it in your code like this: From 673d6195ce9e5be5a7b34fb9d6e36cf4287fd4d4 Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 28 Jun 2020 12:35:25 +0300 Subject: [PATCH 25/26] fix servo struct to use int setting --- src/structs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/structs.rs b/src/structs.rs index 61eebaf..89e011c 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -437,7 +437,7 @@ pub struct MspServoConfig { pub min: u16, pub max: u16, pub middle: u16, - pub rate: u8, + pub rate: i8, pub unused1: u8, pub unused2: u8, pub forward_from_channel: u8, // Depracted, set to 255 for backward compatibility @@ -732,9 +732,9 @@ pub struct MspSetServoMixer { pub struct MspServoMixer { pub target_channel: u8, pub input_source: u8, - pub rate: u16, + pub rate: i16, pub speed: u8, - pub condition_id: u8, + pub condition_id: i8, } #[derive(PackedStruct, Debug, Copy, Clone)] From 522de6426ec3f4089fef6a01328c9bab62eac88e Mon Sep 17 00:00:00 2001 From: Ilya Guterman Date: Sun, 28 Jun 2020 15:13:12 +0300 Subject: [PATCH 26/26] bump version 0.1.11 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cf063d8..20b990e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "multiwii_serial_protocol_v2" description = "A Multiwii Serial Protocol (MSP) implementation for Rust" repository = "https://github.com/amfern/multiwii_serial_protocol.rs" -version = "0.1.9" +version = "0.1.11" authors = ["Rudi Benkovic ", "Ilya Guterman "] license = "MIT OR Apache-2.0" readme = "README.md"