diff --git a/src/lib.rs b/src/lib.rs index db5972f..d77e618 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -717,6 +717,15 @@ impl MessageBehavior for DeviceTranform { if msg.args.len() != 8 { return Err(String::from("arg count invalid")); } + match msg.addr.as_str() { + "/VMC/Ext/Hmd/Pos" + | "/VMC/Ext/Con/Pos" + | "/VMC/Ext/Tra/Pos" + | "/VMC/Ext/Hmd/Pos/Local" + | "/VMC/Ext/Con/Pos/Local" + | "/VMC/Ext/Tra/Pos/Local" => {} + _ => return Err(String::from("addr invalid")), + } let serial: String; let mut origin = Vector3::new(0.0, 0.0, 0.0); let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0); @@ -759,3 +768,69 @@ impl MessageBehavior for DeviceTranform { }); } } + +struct VmcExtRvc { + enable: bool, + port: u16, + ip_addr: Option, +} + +impl MessageBehavior for VmcExtRvc { + fn to_sendable_osc_message(&self) -> OscMessage { + let mut args: Vec; + if self.enable { + args = vec![OscType::from(1)]; + } else { + args = vec![OscType::from(0)]; + } + args.push(OscType::from(self.port as i32)); + if self.ip_addr.is_some() { + args.push(OscType::from(self.ip_addr.clone().unwrap())); + } + return OscMessage { + addr: String::from("/VMC/Ext/Rvc"), + args, + }; + } + fn parse_from_osc_message(msg: OscMessage) -> Result { + if msg.args.len() < 2 || msg.args.len() > 3 { + return Err(String::from("arg count invalid")); + } + let enable: bool; + let port: u16; + let mut ip_addr: Option = None; + match msg.args[0] { + OscType::Int(i) => { + if i == 0 { + enable = false; + } else if i == 1 { + enable = true; + } else { + return Err(String::from("arg value invalid")); + } + } + _ => return Err(String::from("arg type invalid")), + } + match msg.args[1] { + OscType::Int(i) => { + if i >= 0 && i <= 65535 { + port = i as u16; + } else { + return Err(String::from("arg value invalid")); + } + } + _ => return Err(String::from("arg type invalid")), + } + if msg.args.len() == 3 { + match &msg.args[2] { + OscType::String(s) => ip_addr = Some(s.to_owned()), + _ => return Err(String::from("arg type invalid")), + } + } + return Ok(VmcExtRvc { + enable, + port, + ip_addr, + }); + } +}