Browse Source

Fix nits

pull/156/head
Jhynjhiruu 9 months ago
parent
commit
b9b8d6baf9
  1. 10
      ctru-rs/examples/local-networking.rs
  2. 22
      ctru-rs/src/services/uds.rs

10
ctru-rs/examples/local-networking.rs

@ -7,7 +7,7 @@ use ctru::services::uds::*;
fn handle_status_event(uds: &Uds, prev_node_mask: u16) -> ctru::Result<u16> { fn handle_status_event(uds: &Uds, prev_node_mask: u16) -> ctru::Result<u16> {
println!("Connection status event signalled"); println!("Connection status event signalled");
let status = uds.get_connection_status()?; let status = uds.connection_status()?;
println!("Status: {status:#02X?}"); println!("Status: {status:#02X?}");
let left = prev_node_mask & (status.node_bitmask() ^ prev_node_mask); let left = prev_node_mask & (status.node_bitmask() ^ prev_node_mask);
let joined = status.node_bitmask() & (status.node_bitmask() ^ prev_node_mask); let joined = status.node_bitmask() & (status.node_bitmask() ^ prev_node_mask);
@ -21,7 +21,7 @@ fn handle_status_event(uds: &Uds, prev_node_mask: u16) -> ctru::Result<u16> {
println!( println!(
"Node {} connected: {:?}", "Node {} connected: {:?}",
i + 1, i + 1,
uds.get_node_info(NodeID::Node(i + 1)) uds.node_info(NodeID::Node(i + 1))
); );
} }
} }
@ -153,7 +153,7 @@ fn main() -> Result<(), Error> {
} }
} }
State::Connect => { State::Connect => {
let appdata = uds.get_network_appdata(&networks[selected_network], None)?; let appdata = uds.network_appdata(&networks[selected_network], None)?;
println!("App data: {:02X?}", appdata); println!("App data: {:02X?}", appdata);
if let Err(e) = uds.connect_network( if let Err(e) = uds.connect_network(
@ -167,10 +167,10 @@ fn main() -> Result<(), Error> {
state = State::Initialised; state = State::Initialised;
println!("Press A to start scanning or B to create a new network"); println!("Press A to start scanning or B to create a new network");
} else { } else {
channel = uds.get_channel()?; channel = uds.channel()?;
println!("Connected using channel {}", channel); println!("Connected using channel {}", channel);
let appdata = uds.get_appdata(None)?; let appdata = uds.appdata(None)?;
println!("App data: {:02X?}", appdata); println!("App data: {:02X?}", appdata);
if uds.wait_status_event(false, false)? { if uds.wait_status_event(false, false)? {

22
ctru-rs/src/services/uds.rs

@ -569,13 +569,13 @@ impl Uds {
/// let mut uds = Uds::new(None)?; /// let mut uds = Uds::new(None)?;
/// ///
/// let networks = uds.scan(b"HBW\x10", None, None)?; /// let networks = uds.scan(b"HBW\x10", None, None)?;
/// let appdata = uds.get_network_appdata(&networks[0], None)?; /// let appdata = uds.network_appdata(&networks[0], None)?;
/// # /// #
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[doc(alias = "udsGetNetworkStructApplicationData")] #[doc(alias = "udsGetNetworkStructApplicationData")]
pub fn get_network_appdata( pub fn network_appdata(
&self, &self,
network: &NetworkScanInfo, network: &NetworkScanInfo,
max_size: Option<usize>, max_size: Option<usize>,
@ -625,13 +625,13 @@ impl Uds {
/// ///
/// let networks = uds.scan(b"HBW\x10", None, None)?; /// let networks = uds.scan(b"HBW\x10", None, None)?;
/// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?; /// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?;
/// let appdata = uds.get_appdata(None)?; /// let appdata = uds.appdata(None)?;
/// # /// #
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[doc(alias = "udsGetApplicationData")] #[doc(alias = "udsGetApplicationData")]
pub fn get_appdata(&self, max_size: Option<usize>) -> Result<Vec<u8>, Error> { pub fn appdata(&self, max_size: Option<usize>) -> Result<Vec<u8>, Error> {
if self.service_status() == ServiceStatus::Disconnected { if self.service_status() == ServiceStatus::Disconnected {
return Err(Error::NotConnected); return Err(Error::NotConnected);
} }
@ -807,13 +807,13 @@ impl Uds {
/// ///
/// let networks = uds.scan(b"HBW\x10", None, None)?; /// let networks = uds.scan(b"HBW\x10", None, None)?;
/// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?; /// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?;
/// let channel = uds.get_channel()?; /// let channel = uds.channel()?;
/// # /// #
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[doc(alias = "udsGetChannel")] #[doc(alias = "udsGetChannel")]
pub fn get_channel(&self) -> Result<u8, Error> { pub fn channel(&self) -> Result<u8, Error> {
if self.service_status() == ServiceStatus::Disconnected { if self.service_status() == ServiceStatus::Disconnected {
return Err(Error::NotConnected); return Err(Error::NotConnected);
} }
@ -870,8 +870,6 @@ impl Uds {
/// Returns the current [`ConnectionStatus`] struct. /// Returns the current [`ConnectionStatus`] struct.
/// ///
/// TODO: should this return an error if not connected?
///
/// # Example /// # Example
/// ///
/// ``` /// ```
@ -886,7 +884,7 @@ impl Uds {
/// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?; /// uds.connect_network(&networks[0], b"udsdemo passphrase c186093cd2652741\0", ConnectionType::Client, 1)?;
/// if uds.wait_status_event(false, false)? { /// if uds.wait_status_event(false, false)? {
/// println!("Connection status event signalled"); /// println!("Connection status event signalled");
/// let status = uds.get_connection_status()?; /// let status = uds.connection_status()?;
/// println!("Status: {status:#X?}"); /// println!("Status: {status:#X?}");
/// } /// }
/// # /// #
@ -894,7 +892,7 @@ impl Uds {
/// # } /// # }
/// ``` /// ```
#[doc(alias = "udsGetConnectionStatus")] #[doc(alias = "udsGetConnectionStatus")]
pub fn get_connection_status(&self) -> crate::Result<ConnectionStatus> { pub fn connection_status(&self) -> crate::Result<ConnectionStatus> {
let mut status = MaybeUninit::uninit(); let mut status = MaybeUninit::uninit();
ResultCode(unsafe { ctru_sys::udsGetConnectionStatus(status.as_mut_ptr()) })?; ResultCode(unsafe { ctru_sys::udsGetConnectionStatus(status.as_mut_ptr()) })?;
@ -1350,13 +1348,13 @@ impl Uds {
/// let mut uds = Uds::new(None)?; /// let mut uds = Uds::new(None)?;
/// ///
/// uds.create_network(b"HBW\x10", None, None, b"udsdemo passphrase c186093cd2652741\0", 1)?; /// uds.create_network(b"HBW\x10", None, None, b"udsdemo passphrase c186093cd2652741\0", 1)?;
/// let node_info = uds.get_node_info(NodeID::Node(2))?; /// let node_info = uds.node_info(NodeID::Node(2))?;
/// # /// #
/// # Ok(()) /// # Ok(())
/// # } /// # }
/// ``` /// ```
#[doc(alias = "udsGetNodeInformation")] #[doc(alias = "udsGetNodeInformation")]
pub fn get_node_info(&self, address: NodeID) -> Result<NodeInfo, Error> { pub fn node_info(&self, address: NodeID) -> Result<NodeInfo, Error> {
let NodeID::Node(node) = address else { let NodeID::Node(node) = address else {
return Err(Error::NotANode); return Err(Error::NotANode);
}; };

Loading…
Cancel
Save