mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 11:42:53 -05:00
Ran cargo fmt
This commit is contained in:
parent
0b59de7109
commit
3980cfa189
3 changed files with 89 additions and 70 deletions
|
@ -15,12 +15,14 @@ fn main() {
|
|||
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.address(),
|
||||
device_desc.vendor_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_controller = NetMDInterface::new(player);
|
||||
|
|
|
@ -16,7 +16,8 @@ const BULK_READ_ENDPOINT: u8 = 0x01;
|
|||
pub const CHUNKSIZE: u32 = 0x10000;
|
||||
|
||||
// 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(|| {
|
||||
nofmt::pls! {
|
||||
Vec::from([
|
||||
DeviceId {vendor_id: 0x04dd, product_id: 0x7202, name: Some(String::from("Sharp IM-MT899H"))},
|
||||
DeviceId {vendor_id: 0x04dd, product_id: 0x9013, name: Some(String::from("Sharp IM-DR400"))},
|
||||
|
@ -65,6 +66,7 @@ pub static DEVICE_IDS: Lazy<Vec<DeviceId>> = Lazy::new(|| nofmt::pls!{
|
|||
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 {
|
||||
|
@ -259,7 +261,11 @@ impl NetMD {
|
|||
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 mut done = 0;
|
||||
|
||||
|
@ -270,20 +276,17 @@ impl NetMD {
|
|||
done += self.device_connection.read_bulk(
|
||||
BULK_READ_ENDPOINT,
|
||||
&mut buffer,
|
||||
DEFAULT_TIMEOUT
|
||||
DEFAULT_TIMEOUT,
|
||||
)? as u32;
|
||||
|
||||
}
|
||||
|
||||
Ok(final_result)
|
||||
}
|
||||
|
||||
pub fn write_bulk(&self, data: &mut Vec<u8>) -> Result<usize, Box<dyn Error>> {
|
||||
let written = self.device_connection.read_bulk(
|
||||
BULK_WRITE_ENDPOINT,
|
||||
data,
|
||||
DEFAULT_TIMEOUT
|
||||
)?;
|
||||
let written =
|
||||
self.device_connection
|
||||
.read_bulk(BULK_WRITE_ENDPOINT, data, DEFAULT_TIMEOUT)?;
|
||||
|
||||
Ok(written)
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ impl std::convert::TryFrom<u8> for NetMDLevel {
|
|||
0x20 => Ok(NetMDLevel::Level1),
|
||||
0x50 => Ok(NetMDLevel::Level2),
|
||||
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,
|
||||
media_type_attributes: u8,
|
||||
md_audio_version: u8,
|
||||
supports_md_clip: u8
|
||||
supports_md_clip: u8,
|
||||
}
|
||||
|
||||
pub struct NetMDInterface {
|
||||
|
@ -212,7 +212,11 @@ impl NetMDInterface {
|
|||
let mut buffer_offset: usize = 0;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -246,7 +250,7 @@ impl NetMDInterface {
|
|||
implementation_profile_id,
|
||||
media_type_attributes,
|
||||
md_audio_version,
|
||||
supports_md_clip
|
||||
supports_md_clip,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -262,7 +266,7 @@ impl NetMDInterface {
|
|||
continue;
|
||||
}
|
||||
|
||||
return NetMDLevel::try_from(media.implementation_profile_id)
|
||||
return NetMDLevel::try_from(media.implementation_profile_id);
|
||||
}
|
||||
Err("No supported media types found".into())
|
||||
}
|
||||
|
@ -333,7 +337,8 @@ impl NetMDInterface {
|
|||
Status::NotImplemented => return Err("Not implemented".into()),
|
||||
Status::Rejected => return Err("Rejected".into()),
|
||||
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);
|
||||
std::thread::sleep(sleep_dur); // Sleep to wait before retrying
|
||||
current_attempt += 1;
|
||||
|
@ -393,7 +398,10 @@ impl NetMDInterface {
|
|||
|
||||
fn status(&self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
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 res = response[22..].to_vec();
|
||||
|
@ -413,7 +421,10 @@ impl NetMDInterface {
|
|||
|
||||
fn full_operating_status(&self) -> Result<(u8, u16), Box<dyn Error>> {
|
||||
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 operating_status = response[27..].to_vec();
|
||||
|
@ -422,7 +433,7 @@ impl NetMDInterface {
|
|||
self.change_descriptor_state(Descriptor::OperatingStatusBlock, DescriptorAction::Close);
|
||||
|
||||
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]];
|
||||
|
@ -440,7 +451,10 @@ impl NetMDInterface {
|
|||
|
||||
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);
|
||||
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[7] = p1[1];
|
||||
|
|
Loading…
Reference in a new issue