mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 11:42:53 -05:00
Updated crate name for minidisc-rs
This commit is contained in:
parent
01e1c46d32
commit
4a7f95d081
7 changed files with 63 additions and 62 deletions
|
@ -11,6 +11,6 @@ license = "AGPL-3.0"
|
|||
[dependencies]
|
||||
rusb = "0.9.3"
|
||||
|
||||
[dependencies.minidisc]
|
||||
[dependencies.minidisc-rs]
|
||||
path = "minidisc-rs"
|
||||
version = "0.0.1"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "minidisc"
|
||||
name = "minidisc-rs"
|
||||
version = "0.0.1"
|
||||
homepage = "https://github.com/G2-Games/minidisc-cli/"
|
||||
repository = "https://github.com/G2-Games/minidisc-cli/minidisc-rs/"
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
/// This is a test
|
||||
pub mod netmd;
|
||||
|
||||
use netmd::interface;
|
||||
use netmd::interface::NetMDInterface;
|
||||
|
|
|
@ -127,18 +127,18 @@ impl NetMD {
|
|||
}
|
||||
|
||||
/// Gets the device name from the struct
|
||||
pub fn device_name(&self) -> Option<String> {
|
||||
self.model.name.clone()
|
||||
pub fn device_name(&self) -> &Option<String> {
|
||||
&self.model.name
|
||||
}
|
||||
|
||||
/// Gets the vendor id from the struct
|
||||
pub fn vendor_id(&self) -> u16 {
|
||||
self.model.vendor_id.clone()
|
||||
pub fn vendor_id(&self) -> &u16 {
|
||||
&self.model.vendor_id
|
||||
}
|
||||
|
||||
/// Gets the product id from the struct
|
||||
pub fn product_id(&self) -> u16 {
|
||||
self.model.product_id.clone()
|
||||
pub fn product_id(&self) -> &u16 {
|
||||
&self.model.product_id
|
||||
}
|
||||
|
||||
/// Poll the device to get either the result
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::netmd::query_utils::{format_query, scan_query};
|
||||
use crate::netmd::utils;
|
||||
use crate::netmd::utils::{length_after_encoding_to_jis, half_width_to_full_width_range};
|
||||
use crate::netmd::base;
|
||||
use encoding_rs::*;
|
||||
use std::collections::HashMap;
|
||||
|
@ -189,7 +189,7 @@ impl NetMDInterface {
|
|||
|
||||
fn construct_multibyte(&self, buffer: &Vec<u8>, n: u8, offset: &mut usize) -> u32 {
|
||||
let mut output: u32 = 0;
|
||||
for i in 0..n as usize {
|
||||
for _ in 0..n as usize {
|
||||
output <<= 8;
|
||||
output |= buffer[*offset] as u32;
|
||||
*offset += 1;
|
||||
|
@ -736,12 +736,12 @@ impl NetMDInterface {
|
|||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::OpenRead);
|
||||
|
||||
let mut done: u16 = 0;
|
||||
let mut remaining: u16 = 0;
|
||||
let mut done: i32 = 0;
|
||||
let mut remaining: i32 = 0;
|
||||
let mut total = 1;
|
||||
let mut result: Vec<String> = Vec::new();
|
||||
let mut chunksize = 0;
|
||||
let mut chunk = String::new();
|
||||
let mut chunksize;
|
||||
let mut chunk;
|
||||
|
||||
while done < total {
|
||||
let wchar_value = match wchar {
|
||||
|
@ -763,15 +763,17 @@ impl NetMDInterface {
|
|||
let reply = self.send_query(&mut query, false, false)?;
|
||||
|
||||
if remaining == 0 {
|
||||
let res = chunksize = u16::from_le_bytes([reply[13], reply[14]]);
|
||||
total = u16::from_le_bytes([reply[22], reply[23]]);
|
||||
let res = scan_query(reply, "1806 02201801 00%? 3000 0a00 1000 %w0000 %?%?000a %w %*".to_string())?;
|
||||
|
||||
chunk = SHIFT_JIS.decode(&reply[25..]).0.into();
|
||||
chunksize = res[0].to_i64().unwrap() as i32;
|
||||
total = res[1].to_i64().unwrap() as i32;
|
||||
chunk = SHIFT_JIS.decode(&res[2].to_vec().unwrap()).0.into();
|
||||
|
||||
chunksize -= 6;
|
||||
} else {
|
||||
chunksize = u16::from_le_bytes([reply[13], reply[14]]);
|
||||
chunk = SHIFT_JIS.decode(&reply[18..]).0.into();
|
||||
let res = scan_query(reply, "1806 02201801 00%? 3000 0a00 1000 %w%?%? %*".to_string())?;
|
||||
chunksize = res[0].to_i64().unwrap() as i32;
|
||||
chunk = SHIFT_JIS.decode(&res[1].to_vec().unwrap()).0.into();
|
||||
}
|
||||
|
||||
result.push(chunk);
|
||||
|
@ -779,12 +781,12 @@ impl NetMDInterface {
|
|||
remaining = total - done;
|
||||
}
|
||||
|
||||
let final_result = result.join("");
|
||||
let res = result.join("");
|
||||
|
||||
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::Close);
|
||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::Close);
|
||||
|
||||
Ok(final_result)
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub fn disc_title(&self, wchar: bool) -> Result<String, Box<dyn Error>> {
|
||||
|
@ -844,7 +846,7 @@ impl NetMDInterface {
|
|||
|
||||
let group_name = &group[track_range.len() + 1..];
|
||||
|
||||
let full_width_range = utils::half_width_to_full_width_range(&track_range);
|
||||
let full_width_range = half_width_to_full_width_range(&track_range);
|
||||
|
||||
let full_width_group_name = full_width_group_list
|
||||
.find(|n| n.starts_with(&full_width_range))
|
||||
|
@ -936,4 +938,25 @@ impl NetMDInterface {
|
|||
.0
|
||||
.into())
|
||||
}
|
||||
|
||||
pub fn set_disc_title(&self, title: String, wchar: bool) -> Result<(), Box<dyn Error>> {
|
||||
let current_title = self._disc_title(wchar)?;
|
||||
if current_title == title {
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
let old_len = length_after_encoding_to_jis(current_title);
|
||||
let new_len = length_after_encoding_to_jis(title);
|
||||
|
||||
let wchar_value = match wchar {
|
||||
true => {
|
||||
|
||||
},
|
||||
false => {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use std::collections::hash_map::HashMap;
|
||||
use encoding_rs::SHIFT_JIS;
|
||||
use std::error::Error;
|
||||
|
||||
pub fn bcd_to_int(bcd: i32) -> i32 {
|
||||
let mut original = bcd;
|
||||
pub fn bcd_to_int(mut bcd: i32) -> i32 {
|
||||
let mut value = 0;
|
||||
let mut nibble = 0;
|
||||
while original != 0 {
|
||||
let nibble_value = original & 0xf;
|
||||
original = original >> 4;
|
||||
|
||||
while bcd != 0 {
|
||||
let nibble_value = bcd & 0xf;
|
||||
bcd = bcd >> 4;
|
||||
value += nibble_value * i32::pow(10, nibble);
|
||||
nibble += 1;
|
||||
}
|
||||
|
@ -29,33 +30,6 @@ pub fn int_to_bcd(mut value: i32) -> i32 {
|
|||
bcd
|
||||
}
|
||||
|
||||
pub fn int_from_bcd(byte: u8) -> Result<u8, Box<dyn Error>> {
|
||||
let upper = (byte & 0xF0) >> 4;
|
||||
let lower = byte & 0x0F;
|
||||
|
||||
if upper >= 10 {
|
||||
return Err("Upper nybble out of range [0..9]".into());
|
||||
}
|
||||
|
||||
if lower >= 10 {
|
||||
return Err("Lower nybble out of range [0..9]".into());
|
||||
}
|
||||
|
||||
Ok(upper * 10 + lower)
|
||||
}
|
||||
|
||||
pub fn bcd_from_int(byte: u8) -> Result<u8, Box<dyn Error>> {
|
||||
let mut new_byte: u8 = 0;
|
||||
|
||||
let upper = (byte / 10) << 4;
|
||||
let lower = byte % 10;
|
||||
|
||||
new_byte |= upper;
|
||||
new_byte |= lower;
|
||||
|
||||
Ok(new_byte)
|
||||
}
|
||||
|
||||
pub fn half_width_to_full_width_range(range: &String) -> String {
|
||||
let mappings: HashMap<char, char> = HashMap::from([
|
||||
('0', '0'),
|
||||
|
@ -93,3 +67,9 @@ pub fn get_bytes<const S: usize>(
|
|||
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
pub fn length_after_encoding_to_jis(string: String) -> usize {
|
||||
let new_string = SHIFT_JIS.encode(&string);
|
||||
|
||||
new_string.0.len()
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,4 +1,4 @@
|
|||
use minidisc::netmd;
|
||||
use minidisc_rs::netmd::interface;
|
||||
use rusb;
|
||||
|
||||
fn main() {
|
||||
|
@ -19,19 +19,17 @@ fn main() {
|
|||
new_device.read_product_string_ascii(&device_desc)
|
||||
);
|
||||
|
||||
let player_controller = match netmd::interface::NetMDInterface::new(new_device, device_desc) {
|
||||
let player_controller = match interface::NetMDInterface::new(new_device, device_desc) {
|
||||
Ok(player) => player,
|
||||
Err(_) => continue
|
||||
};
|
||||
|
||||
println!(
|
||||
"Player Model: {}",
|
||||
player_controller.net_md_device.device_name().unwrap()
|
||||
player_controller.net_md_device.device_name().clone().unwrap()
|
||||
);
|
||||
|
||||
println!("Disc Flags? {:?}", player_controller.disc_flags());
|
||||
println!("Track Count: {:?}", player_controller.track_count());
|
||||
println!("Disc Title: {:?}", player_controller.disc_title(false));
|
||||
println!("Track Count: {:?}", player_controller.track_count().unwrap());
|
||||
println!("Disc Title: {} | {}", player_controller.disc_title(false).unwrap(), player_controller.disc_title(true).unwrap());
|
||||
|
||||
//println!("TEST CASE: {:?}", player_controller.disc_subunit_identifier());
|
||||
|
||||
|
|
Loading…
Reference in a new issue