create VmcExtRvc

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-30 11:03:37 -05:00
parent fb62a02b04
commit 166feab2a2

View File

@ -717,6 +717,15 @@ impl MessageBehavior for DeviceTranform {
if msg.args.len() != 8 { if msg.args.len() != 8 {
return Err(String::from("arg count invalid")); 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 serial: String;
let mut origin = Vector3::new(0.0, 0.0, 0.0); let mut origin = Vector3::new(0.0, 0.0, 0.0);
let mut quat = Quaternion::new(0.0, 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<String>,
}
impl MessageBehavior for VmcExtRvc {
fn to_sendable_osc_message(&self) -> OscMessage {
let mut args: Vec<OscType>;
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<Self, String> {
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<String> = 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,
});
}
}