Ran cargo fmt

This commit is contained in:
G2-Games 2023-09-23 11:59:01 -05:00
parent 0b59de7109
commit 3980cfa189
3 changed files with 89 additions and 70 deletions

View file

@ -15,12 +15,14 @@ fn main() {
Err(_) => continue, Err(_) => continue,
}; };
println!("Connected to Bus {:03} Device {:03} VID: {:04x}, PID: {:04x}, {:?}", println!(
"Connected to Bus {:03} Device {:03} VID: {:04x}, PID: {:04x}, {:?}",
device.bus_number(), device.bus_number(),
device.address(), device.address(),
device_desc.vendor_id(), device_desc.vendor_id(),
device_desc.product_id(), device_desc.product_id(),
new_device.read_product_string_ascii(&device_desc)); new_device.read_product_string_ascii(&device_desc)
);
let player = NetMD::new(new_device, device_desc).unwrap(); let player = NetMD::new(new_device, device_desc).unwrap();
let player_controller = NetMDInterface::new(player); let player_controller = NetMDInterface::new(player);

View file

@ -16,55 +16,57 @@ const BULK_READ_ENDPOINT: u8 = 0x01;
pub const CHUNKSIZE: u32 = 0x10000; pub const CHUNKSIZE: u32 = 0x10000;
// TODO: I think this sucks, figure out a better way // TODO: I think this sucks, figure out a better way
pub static DEVICE_IDS: Lazy<Vec<DeviceId>> = Lazy::new(|| nofmt::pls!{ pub static DEVICE_IDS: Lazy<Vec<DeviceId>> = Lazy::new(|| {
Vec::from([ nofmt::pls! {
DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))}, Vec::from([
DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))},
DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0034, name: Some(String::from("Sony PCLK-XX"))}, DeviceId {vendor_id: 0x04dd, product_id: 0x9014, name: Some(String::from("Sharp IM-DR80"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0036, name: Some(String::from("Sony"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0034, name: Some(String::from("Sony PCLK-XX"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0075, name: Some(String::from("Sony MZ-N1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0036, name: Some(String::from("Sony"))},
DeviceId {vendor_id: 0x054c, product_id: 0x007c, name: Some(String::from("Sony"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0075, name: Some(String::from("Sony MZ-N1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0080, name: Some(String::from("Sony LAM-1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x007c, name: Some(String::from("Sony"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0081, name: Some(String::from("Sony MDS-JB980/MDS-NT1/MDS-JE780"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0080, name: Some(String::from("Sony LAM-1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0084, name: Some(String::from("Sony MZ-N505"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0081, name: Some(String::from("Sony MDS-JB980/MDS-NT1/MDS-JE780"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0085, name: Some(String::from("Sony MZ-S1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0084, name: Some(String::from("Sony MZ-N505"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0086, name: Some(String::from("Sony MZ-N707"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0085, name: Some(String::from("Sony MZ-S1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x008e, name: Some(String::from("Sony CMT-C7NT"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0086, name: Some(String::from("Sony MZ-N707"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0097, name: Some(String::from("Sony PCGA-MDN1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x008e, name: Some(String::from("Sony CMT-C7NT"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00ad, name: Some(String::from("Sony CMT-L7HD"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0097, name: Some(String::from("Sony PCGA-MDN1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00c6, name: Some(String::from("Sony MZ-N10"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00ad, name: Some(String::from("Sony CMT-L7HD"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00c7, name: Some(String::from("Sony MZ-N910"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00c6, name: Some(String::from("Sony MZ-N10"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00c8, name: Some(String::from("Sony MZ-N710/NF810"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00c7, name: Some(String::from("Sony MZ-N910"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00c9, name: Some(String::from("Sony MZ-N510/N610"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00c8, name: Some(String::from("Sony MZ-N710/NF810"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00ca, name: Some(String::from("Sony MZ-NE410/NF520D"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00c9, name: Some(String::from("Sony MZ-N510/N610"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00e7, name: Some(String::from("Sony CMT-M333NT/M373NT"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00ca, name: Some(String::from("Sony MZ-NE410/NF520D"))},
DeviceId {vendor_id: 0x054c, product_id: 0x00eb, name: Some(String::from("Sony MZ-NE810/NE910"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00e7, name: Some(String::from("Sony CMT-M333NT/M373NT"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0101, name: Some(String::from("Sony LAM"))}, DeviceId {vendor_id: 0x054c, product_id: 0x00eb, name: Some(String::from("Sony MZ-NE810/NE910"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0113, name: Some(String::from("Aiwa AM-NX1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0101, name: Some(String::from("Sony LAM"))},
DeviceId {vendor_id: 0x054c, product_id: 0x013f, name: Some(String::from("Sony MDS-S500"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0113, name: Some(String::from("Aiwa AM-NX1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x014c, name: Some(String::from("Aiwa AM-NX9"))}, DeviceId {vendor_id: 0x054c, product_id: 0x013f, name: Some(String::from("Sony MDS-S500"))},
DeviceId {vendor_id: 0x054c, product_id: 0x017e, name: Some(String::from("Sony MZ-NH1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x014c, name: Some(String::from("Aiwa AM-NX9"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0180, name: Some(String::from("Sony MZ-NH3D"))}, DeviceId {vendor_id: 0x054c, product_id: 0x017e, name: Some(String::from("Sony MZ-NH1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0182, name: Some(String::from("Sony MZ-NH900"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0180, name: Some(String::from("Sony MZ-NH3D"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0184, name: Some(String::from("Sony MZ-NH700/NH800"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0182, name: Some(String::from("Sony MZ-NH900"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0186, name: Some(String::from("Sony MZ-NH600"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0184, name: Some(String::from("Sony MZ-NH700/NH800"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0187, name: Some(String::from("Sony MZ-NH600D"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0186, name: Some(String::from("Sony MZ-NH600"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0188, name: Some(String::from("Sony MZ-N920"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0187, name: Some(String::from("Sony MZ-NH600D"))},
DeviceId {vendor_id: 0x054c, product_id: 0x018a, name: Some(String::from("Sony LAM-3"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0188, name: Some(String::from("Sony MZ-N920"))},
DeviceId {vendor_id: 0x054c, product_id: 0x01e9, name: Some(String::from("Sony MZ-DH10P"))}, DeviceId {vendor_id: 0x054c, product_id: 0x018a, name: Some(String::from("Sony LAM-3"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0219, name: Some(String::from("Sony MZ-RH10"))}, DeviceId {vendor_id: 0x054c, product_id: 0x01e9, name: Some(String::from("Sony MZ-DH10P"))},
DeviceId {vendor_id: 0x054c, product_id: 0x021b, name: Some(String::from("Sony MZ-RH710/MZ-RH910"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0219, name: Some(String::from("Sony MZ-RH10"))},
DeviceId {vendor_id: 0x054c, product_id: 0x021d, name: Some(String::from("Sony CMT-AH10"))}, DeviceId {vendor_id: 0x054c, product_id: 0x021b, name: Some(String::from("Sony MZ-RH710/MZ-RH910"))},
DeviceId {vendor_id: 0x054c, product_id: 0x022c, name: Some(String::from("Sony CMT-AH10"))}, DeviceId {vendor_id: 0x054c, product_id: 0x021d, name: Some(String::from("Sony CMT-AH10"))},
DeviceId {vendor_id: 0x054c, product_id: 0x023c, name: Some(String::from("Sony DS-HMD1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x022c, name: Some(String::from("Sony CMT-AH10"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0286, name: Some(String::from("Sony MZ-RH1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x023c, name: Some(String::from("Sony DS-HMD1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x011a, name: Some(String::from("Sony CMT-SE7"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0286, name: Some(String::from("Sony MZ-RH1"))},
DeviceId {vendor_id: 0x054c, product_id: 0x0148, name: Some(String::from("Sony MDS-A1"))}, DeviceId {vendor_id: 0x054c, product_id: 0x011a, name: Some(String::from("Sony CMT-SE7"))},
DeviceId {vendor_id: 0x0b28, product_id: 0x1004, name: Some(String::from("Kenwood MDX-J9"))}, DeviceId {vendor_id: 0x054c, product_id: 0x0148, name: Some(String::from("Sony MDS-A1"))},
DeviceId {vendor_id: 0x04da, product_id: 0x23b3, name: Some(String::from("Panasonic SJ-MR250"))}, DeviceId {vendor_id: 0x0b28, product_id: 0x1004, name: Some(String::from("Kenwood MDX-J9"))},
DeviceId {vendor_id: 0x04da, product_id: 0x23b6, name: Some(String::from("Panasonic SJ-MR270"))}, DeviceId {vendor_id: 0x04da, product_id: 0x23b3, name: Some(String::from("Panasonic SJ-MR250"))},
]) DeviceId {vendor_id: 0x04da, product_id: 0x23b6, name: Some(String::from("Panasonic SJ-MR270"))},
])
}
}); });
pub enum Status { pub enum Status {
@ -259,7 +261,11 @@ impl NetMD {
Ok(result.to_vec()) Ok(result.to_vec())
} }
pub fn read_bulk_to_array(&self, length: u32, chunksize: u32) -> Result<Vec<u8>, Box<dyn Error>> { pub fn read_bulk_to_array(
&self,
length: u32,
chunksize: u32,
) -> Result<Vec<u8>, Box<dyn Error>> {
let final_result: Vec<u8> = Vec::new(); let final_result: Vec<u8> = Vec::new();
let mut done = 0; let mut done = 0;
@ -270,20 +276,17 @@ impl NetMD {
done += self.device_connection.read_bulk( done += self.device_connection.read_bulk(
BULK_READ_ENDPOINT, BULK_READ_ENDPOINT,
&mut buffer, &mut buffer,
DEFAULT_TIMEOUT DEFAULT_TIMEOUT,
)? as u32; )? as u32;
} }
Ok(final_result) Ok(final_result)
} }
pub fn write_bulk(&self, data: &mut Vec<u8>) -> Result<usize, Box<dyn Error>> { pub fn write_bulk(&self, data: &mut Vec<u8>) -> Result<usize, Box<dyn Error>> {
let written = self.device_connection.read_bulk( let written =
BULK_WRITE_ENDPOINT, self.device_connection
data, .read_bulk(BULK_WRITE_ENDPOINT, data, DEFAULT_TIMEOUT)?;
DEFAULT_TIMEOUT
)?;
Ok(written) Ok(written)
} }

View file

@ -81,7 +81,7 @@ impl std::convert::TryFrom<u8> for NetMDLevel {
0x20 => Ok(NetMDLevel::Level1), 0x20 => Ok(NetMDLevel::Level1),
0x50 => Ok(NetMDLevel::Level2), 0x50 => Ok(NetMDLevel::Level2),
0x70 => Ok(NetMDLevel::Level3), 0x70 => Ok(NetMDLevel::Level3),
_ => Err("Value not valid NetMD Level".into()) _ => Err("Value not valid NetMD Level".into()),
} }
} }
} }
@ -164,7 +164,7 @@ struct MediaInfo {
implementation_profile_id: u8, implementation_profile_id: u8,
media_type_attributes: u8, media_type_attributes: u8,
md_audio_version: u8, md_audio_version: u8,
supports_md_clip: u8 supports_md_clip: u8,
} }
pub struct NetMDInterface { pub struct NetMDInterface {
@ -179,7 +179,7 @@ impl NetMDInterface {
NetMDInterface { net_md_device } NetMDInterface { net_md_device }
} }
fn construct_multibyte(&self, buffer: &Vec<u8>, n: u8, offset: &mut usize) -> u32{ fn construct_multibyte(&self, buffer: &Vec<u8>, n: u8, offset: &mut usize) -> u32 {
let mut bytes = [0u8; 4]; let mut bytes = [0u8; 4];
for i in 0..n as usize { for i in 0..n as usize {
bytes[i] = buffer[*offset]; bytes[i] = buffer[*offset];
@ -212,7 +212,11 @@ impl NetMDInterface {
let mut buffer_offset: usize = 0; let mut buffer_offset: usize = 0;
for _ in 0..amt_of_root_object_lists { for _ in 0..amt_of_root_object_lists {
root_objects.push(self.construct_multibyte(&buffer, size_of_list_id, &mut buffer_offset)); root_objects.push(self.construct_multibyte(
&buffer,
size_of_list_id,
&mut buffer_offset,
));
} }
println!("{:?}", root_objects); println!("{:?}", root_objects);
@ -246,7 +250,7 @@ impl NetMDInterface {
implementation_profile_id, implementation_profile_id,
media_type_attributes, media_type_attributes,
md_audio_version, md_audio_version,
supports_md_clip supports_md_clip,
}) })
} }
@ -262,7 +266,7 @@ impl NetMDInterface {
continue; continue;
} }
return NetMDLevel::try_from(media.implementation_profile_id) return NetMDLevel::try_from(media.implementation_profile_id);
} }
Err("No supported media types found".into()) Err("No supported media types found".into())
} }
@ -333,7 +337,8 @@ impl NetMDInterface {
Status::NotImplemented => return Err("Not implemented".into()), Status::NotImplemented => return Err("Not implemented".into()),
Status::Rejected => return Err("Rejected".into()), Status::Rejected => return Err("Rejected".into()),
Status::Interim if !accept_interim => { Status::Interim if !accept_interim => {
let sleep_time = Self::INTERIM_RESPONSE_RETRY_INTERVAL as u64 * (u64::pow(2, current_attempt as u32) - 1); let sleep_time = Self::INTERIM_RESPONSE_RETRY_INTERVAL as u64
* (u64::pow(2, current_attempt as u32) - 1);
let sleep_dur = std::time::Duration::from_millis(sleep_time); let sleep_dur = std::time::Duration::from_millis(sleep_time);
std::thread::sleep(sleep_dur); // Sleep to wait before retrying std::thread::sleep(sleep_dur); // Sleep to wait before retrying
current_attempt += 1; current_attempt += 1;
@ -393,7 +398,10 @@ impl NetMDInterface {
fn status(&self) -> Result<Vec<u8>, Box<dyn Error>> { fn status(&self) -> Result<Vec<u8>, Box<dyn Error>> {
self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead); self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead);
let mut query = vec![0x18, 0x09, 0x80, 0x01, 0x02, 0x30, 0x88, 0x00, 0x00, 0x30, 0x88, 0x04, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00]; let mut query = vec![
0x18, 0x09, 0x80, 0x01, 0x02, 0x30, 0x88, 0x00, 0x00, 0x30, 0x88, 0x04, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00,
];
let response = self.send_query(&mut query, false, false)?; let response = self.send_query(&mut query, false, false)?;
let res = response[22..].to_vec(); let res = response[22..].to_vec();
@ -413,7 +421,10 @@ impl NetMDInterface {
fn full_operating_status(&self) -> Result<(u8, u16), Box<dyn Error>> { fn full_operating_status(&self) -> Result<(u8, u16), Box<dyn Error>> {
self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead); self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead);
let mut query = vec![0x18, 0x09, 0x80, 0x01, 0x03, 0x30, 0x88, 0x02, 0x00, 0x30, 0x88, 0x05, 0x00, 0x30, 0x88, 0x06, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00]; let mut query = vec![
0x18, 0x09, 0x80, 0x01, 0x03, 0x30, 0x88, 0x02, 0x00, 0x30, 0x88, 0x05, 0x00, 0x30,
0x88, 0x06, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let response = self.send_query(&mut query, false, false)?; let response = self.send_query(&mut query, false, false)?;
let operating_status = response[27..].to_vec(); let operating_status = response[27..].to_vec();
@ -422,7 +433,7 @@ impl NetMDInterface {
self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::Close); self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::Close);
if operating_status.len() < 2 { if operating_status.len() < 2 {
return Err("Unparsable operating system".into()) return Err("Unparsable operating system".into());
} }
let status_bytes = [operating_status[0], operating_status[1]]; let status_bytes = [operating_status[0], operating_status[1]];
@ -440,7 +451,10 @@ impl NetMDInterface {
fn playback_status_query(&self, p1: [u8; 2], p2: [u8; 2]) -> Result<Vec<u8>, Box<dyn Error>> { fn playback_status_query(&self, p1: [u8; 2], p2: [u8; 2]) -> Result<Vec<u8>, Box<dyn Error>> {
self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead); self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::OpenRead);
let mut query = vec![0x18, 0x09, 0x80, 0x01, 0x03, 0x30, 0x00, 0x00, 0x00, 0x30, 0x88, 0x05, 0x00, 0x30, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00]; let mut query = vec![
0x18, 0x09, 0x80, 0x01, 0x03, 0x30, 0x00, 0x00, 0x00, 0x30, 0x88, 0x05, 0x00, 0x30,
0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
];
query[6] = p1[0]; query[6] = p1[0];
query[7] = p1[1]; query[7] = p1[1];