mirror of
https://github.com/G2-Games/minidisc-cli.git
synced 2025-04-19 19:52:53 -05:00
Merge branch 'async'
This commit is contained in:
commit
1dadbd697d
8 changed files with 539 additions and 511 deletions
|
@ -9,8 +9,10 @@ authors = ["G2 <g2@g2games.dev>"]
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
futures = "0.3.30"
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
nusb = "0.1.4"
|
nusb = "0.1.4"
|
||||||
|
tokio = { version = "1.35.1", features = ["full"] }
|
||||||
translit = "0.5.0"
|
translit = "0.5.0"
|
||||||
|
|
||||||
[dependencies.minidisc-rs]
|
[dependencies.minidisc-rs]
|
||||||
|
|
|
@ -4,13 +4,10 @@ use std::error::Error;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// USB stuff
|
// USB stuff
|
||||||
use nusb::transfer::{Control, ControlType, Recipient, RequestBuffer};
|
use nusb::transfer::{Control, ControlIn, ControlOut, ControlType, Recipient, RequestBuffer};
|
||||||
use nusb::{Device, DeviceInfo, Interface};
|
use nusb::{Device, DeviceInfo, Interface};
|
||||||
|
|
||||||
use futures_lite::future::block_on;
|
|
||||||
|
|
||||||
const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0);
|
const DEFAULT_TIMEOUT: Duration = Duration::new(10000, 0);
|
||||||
|
|
||||||
const BULK_WRITE_ENDPOINT: u8 = 0x02;
|
const BULK_WRITE_ENDPOINT: u8 = 0x02;
|
||||||
const BULK_READ_ENDPOINT: u8 = 0x81;
|
const BULK_READ_ENDPOINT: u8 = 0x81;
|
||||||
|
|
||||||
|
@ -98,7 +95,7 @@ impl NetMD {
|
||||||
const READ_REPLY_RETRY_INTERVAL: u32 = 10;
|
const READ_REPLY_RETRY_INTERVAL: u32 = 10;
|
||||||
|
|
||||||
/// Creates a new interface to a NetMD device
|
/// Creates a new interface to a NetMD device
|
||||||
pub fn new(device_info: &DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
pub async fn new(device_info: &DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
||||||
let mut model = DeviceId {
|
let mut model = DeviceId {
|
||||||
vendor_id: device_info.vendor_id(),
|
vendor_id: device_info.vendor_id(),
|
||||||
product_id: device_info.product_id(),
|
product_id: device_info.product_id(),
|
||||||
|
@ -131,61 +128,67 @@ impl NetMD {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the device name, this is limited to the devices in the list
|
/// Gets the device name, this is limited to the devices in the list
|
||||||
pub fn device_name(&self) -> &Option<String> {
|
pub async fn device_name(&self) -> &Option<String> {
|
||||||
&self.model.name
|
&self.model.name
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the vendor id
|
/// Gets the vendor id
|
||||||
pub fn vendor_id(&self) -> &u16 {
|
pub async fn vendor_id(&self) -> &u16 {
|
||||||
&self.model.vendor_id
|
&self.model.vendor_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the product id
|
/// Gets the product id
|
||||||
pub fn product_id(&self) -> &u16 {
|
pub async fn product_id(&self) -> &u16 {
|
||||||
&self.model.product_id
|
&self.model.product_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Poll the device to get either the result
|
/// Poll the device to get either the result
|
||||||
/// of the previous command, or the status
|
/// of the previous command, or the status
|
||||||
pub fn poll(&mut self) -> Result<(u16, [u8; 4]), Box<dyn Error>> {
|
pub async fn poll(&mut self) -> Result<(u16, [u8; 4]), Box<dyn Error>> {
|
||||||
// Create an array to store the result of the poll
|
// Create an array to store the result of the poll
|
||||||
let mut poll_result = [0u8; 4];
|
let poll_result = match self
|
||||||
|
.usb_interface
|
||||||
let _status = match self.usb_interface.control_in_blocking(
|
.control_in(ControlIn {
|
||||||
Control {
|
|
||||||
control_type: ControlType::Vendor,
|
control_type: ControlType::Vendor,
|
||||||
recipient: Recipient::Interface,
|
recipient: Recipient::Interface,
|
||||||
request: 0x01,
|
request: 0x01,
|
||||||
value: 0,
|
value: 0,
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
length: 4,
|
||||||
&mut poll_result,
|
})
|
||||||
DEFAULT_TIMEOUT,
|
.await
|
||||||
) {
|
.into_result()
|
||||||
|
{
|
||||||
Ok(size) => size,
|
Ok(size) => size,
|
||||||
Err(error) => return Err(error.into()),
|
Err(error) => return Err(error.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let length_bytes = [poll_result[2], poll_result[3]];
|
let length_bytes = u16::from_le_bytes([poll_result[2], poll_result[3]]);
|
||||||
Ok((u16::from_le_bytes(length_bytes), poll_result))
|
|
||||||
|
let poll_result: [u8; 4] = match poll_result.try_into() {
|
||||||
|
Ok(val) => val,
|
||||||
|
Err(_) => return Err("could not convert result".into()),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((length_bytes, poll_result))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_command(&mut self, command: Vec<u8>) -> Result<(), Box<dyn Error>> {
|
pub async fn send_command(&mut self, command: Vec<u8>) -> Result<(), Box<dyn Error>> {
|
||||||
self._send_command(command, false)
|
self._send_command(command, false).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_factory_command(&mut self, command: Vec<u8>) -> Result<(), Box<dyn Error>> {
|
pub async fn send_factory_command(&mut self, command: Vec<u8>) -> Result<(), Box<dyn Error>> {
|
||||||
self._send_command(command, true)
|
self._send_command(command, true).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a control message to the device
|
/// Send a control message to the device
|
||||||
fn _send_command(
|
async fn _send_command(
|
||||||
&mut self,
|
&mut self,
|
||||||
command: Vec<u8>,
|
command: Vec<u8>,
|
||||||
use_factory_command: bool,
|
use_factory_command: bool,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
// First poll to ensure the device is ready
|
// First poll to ensure the device is ready
|
||||||
match self.poll() {
|
match self.poll().await {
|
||||||
Ok(buffer) => match buffer.1[2] {
|
Ok(buffer) => match buffer.1[2] {
|
||||||
0 => 0,
|
0 => 0,
|
||||||
_ => return Err("Device not ready!".into()),
|
_ => return Err("Device not ready!".into()),
|
||||||
|
@ -198,49 +201,54 @@ impl NetMD {
|
||||||
true => 0xff,
|
true => 0xff,
|
||||||
};
|
};
|
||||||
|
|
||||||
match self.usb_interface.control_out_blocking(
|
match self
|
||||||
Control {
|
.usb_interface
|
||||||
|
.control_out(ControlOut {
|
||||||
control_type: ControlType::Vendor,
|
control_type: ControlType::Vendor,
|
||||||
recipient: Recipient::Interface,
|
recipient: Recipient::Interface,
|
||||||
request,
|
request,
|
||||||
value: 0,
|
value: 0,
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
data: &command,
|
||||||
&command,
|
})
|
||||||
DEFAULT_TIMEOUT,
|
.await
|
||||||
) {
|
.into_result()
|
||||||
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(error) => Err(error.into()),
|
Err(error) => Err(error.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_reply(&mut self, override_length: Option<i32>) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn read_reply(
|
||||||
self._read_reply(false, override_length)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_factory_reply(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
override_length: Option<i32>,
|
override_length: Option<i32>,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self._read_reply(true, override_length)
|
self._read_reply(false, override_length).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Poll to see if a message is ready,
|
pub async fn read_factory_reply(
|
||||||
/// and if so, recieve it
|
&mut self,
|
||||||
fn _read_reply(
|
override_length: Option<i32>,
|
||||||
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
|
self._read_reply(true, override_length).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Poll to see if a message is ready, and once it is, retrieve it
|
||||||
|
async fn _read_reply(
|
||||||
&mut self,
|
&mut self,
|
||||||
use_factory_command: bool,
|
use_factory_command: bool,
|
||||||
override_length: Option<i32>,
|
override_length: Option<i32>,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let mut length = self.poll()?.0;
|
let mut length = self.poll().await?.0;
|
||||||
|
|
||||||
let mut current_attempt = 0;
|
let mut current_attempt = 0;
|
||||||
while length == 0 {
|
while length == 0 {
|
||||||
|
// Back off while trying again
|
||||||
let sleep_time = Self::READ_REPLY_RETRY_INTERVAL as u64
|
let sleep_time = Self::READ_REPLY_RETRY_INTERVAL as u64
|
||||||
* (u64::pow(2, current_attempt as u32 / 10) - 1);
|
* (u64::pow(2, current_attempt as u32 / 10) - 1);
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::from_millis(sleep_time));
|
std::thread::sleep(std::time::Duration::from_millis(sleep_time));
|
||||||
length = self.poll()?.0;
|
length = self.poll().await?.0;
|
||||||
current_attempt += 1;
|
current_attempt += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,38 +262,35 @@ impl NetMD {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a buffer to fill with the result
|
// Create a buffer to fill with the result
|
||||||
let mut buf: Vec<u8> = vec![0; length as usize];
|
let reply = self
|
||||||
|
.usb_interface
|
||||||
// Create a buffer to fill with the result
|
.control_in(ControlIn {
|
||||||
match self.usb_interface.control_in_blocking(
|
|
||||||
Control {
|
|
||||||
control_type: ControlType::Vendor,
|
control_type: ControlType::Vendor,
|
||||||
recipient: Recipient::Interface,
|
recipient: Recipient::Interface,
|
||||||
request,
|
request,
|
||||||
value: 0,
|
value: 0,
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
length,
|
||||||
&mut buf,
|
})
|
||||||
DEFAULT_TIMEOUT,
|
.await
|
||||||
) {
|
.into_result()?;
|
||||||
Ok(_) => Ok(buf),
|
|
||||||
Err(error) => Err(error.into()),
|
Ok(reply)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default chunksize should be 0x10000
|
// Default chunksize should be 0x10000
|
||||||
// TODO: Make these Async eventually
|
// TODO: Make these Async eventually
|
||||||
pub fn read_bulk(
|
pub async fn read_bulk(
|
||||||
&mut self,
|
&mut self,
|
||||||
length: usize,
|
length: usize,
|
||||||
chunksize: usize,
|
chunksize: usize,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let result = self.read_bulk_to_array(length, chunksize)?;
|
let result = self.read_bulk_to_array(length, chunksize).await?;
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_bulk_to_array(
|
pub async fn read_bulk_to_array(
|
||||||
&mut self,
|
&mut self,
|
||||||
length: usize,
|
length: usize,
|
||||||
chunksize: usize,
|
chunksize: usize,
|
||||||
|
@ -298,7 +303,10 @@ impl NetMD {
|
||||||
done -= to_read;
|
done -= to_read;
|
||||||
let buffer = RequestBuffer::new(to_read);
|
let buffer = RequestBuffer::new(to_read);
|
||||||
|
|
||||||
let res = match block_on(self.usb_interface.bulk_in(BULK_READ_ENDPOINT, buffer))
|
let res = match self
|
||||||
|
.usb_interface
|
||||||
|
.bulk_in(BULK_READ_ENDPOINT, buffer)
|
||||||
|
.await
|
||||||
.into_result()
|
.into_result()
|
||||||
{
|
{
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
|
@ -311,11 +319,12 @@ impl NetMD {
|
||||||
Ok(final_result)
|
Ok(final_result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_bulk(&mut self, data: Vec<u8>) -> Result<usize, Box<dyn Error>> {
|
pub async fn write_bulk(&mut self, data: Vec<u8>) -> Result<usize, Box<dyn Error>> {
|
||||||
Ok(
|
Ok(self
|
||||||
block_on(self.usb_interface.bulk_out(BULK_WRITE_ENDPOINT, data))
|
.usb_interface
|
||||||
.into_result()?
|
.bulk_out(BULK_WRITE_ENDPOINT, data)
|
||||||
.actual_length(),
|
.await
|
||||||
)
|
.into_result()?
|
||||||
|
.actual_length())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,8 +203,8 @@ impl NetMDInterface {
|
||||||
const MAX_INTERIM_READ_ATTEMPTS: u8 = 4;
|
const MAX_INTERIM_READ_ATTEMPTS: u8 = 4;
|
||||||
const INTERIM_RESPONSE_RETRY_INTERVAL: u32 = 100;
|
const INTERIM_RESPONSE_RETRY_INTERVAL: u32 = 100;
|
||||||
|
|
||||||
pub fn new(device: &nusb::DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
pub async fn new(device: &nusb::DeviceInfo) -> Result<Self, Box<dyn Error>> {
|
||||||
let net_md_device = base::NetMD::new(device)?;
|
let net_md_device = base::NetMD::new(device).await?;
|
||||||
Ok(NetMDInterface { net_md_device })
|
Ok(NetMDInterface { net_md_device })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Finish proper implementation
|
// TODO: Finish proper implementation
|
||||||
fn disc_subunit_identifier(&mut self) -> Result<NetMDLevel, Box<dyn Error>> {
|
async fn disc_subunit_identifier(&mut self) -> Result<NetMDLevel, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::DiscSubunitIdentifier,
|
&Descriptor::DiscSubunitIdentifier,
|
||||||
&DescriptorAction::OpenRead,
|
&DescriptorAction::OpenRead,
|
||||||
|
@ -227,7 +227,7 @@ impl NetMDInterface {
|
||||||
|
|
||||||
let mut query = format_query("1809 00 ff00 0000 0000".to_string(), vec![])?;
|
let mut query = format_query("1809 00 ff00 0000 0000".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -315,8 +315,8 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn net_md_level(&mut self) -> Result<NetMDLevel, Box<dyn Error>> {
|
async fn net_md_level(&mut self) -> Result<NetMDLevel, Box<dyn Error>> {
|
||||||
let result = self.disc_subunit_identifier()?;
|
let result = self.disc_subunit_identifier().await?;
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
@ -334,20 +334,24 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a query to the NetMD player
|
/// Send a query to the NetMD player
|
||||||
fn send_query(
|
async fn send_query(
|
||||||
&mut self,
|
&mut self,
|
||||||
query: &mut Vec<u8>,
|
query: &mut Vec<u8>,
|
||||||
test: bool,
|
test: bool,
|
||||||
accept_interim: bool,
|
accept_interim: bool,
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.send_command(query, test)?;
|
self.send_command(query, test).await?;
|
||||||
|
|
||||||
let result = self.read_reply(accept_interim)?;
|
let result = self.read_reply(accept_interim).await?;
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_command(&mut self, query: &mut Vec<u8>, test: bool) -> Result<(), Box<dyn Error>> {
|
async fn send_command(
|
||||||
|
&mut self,
|
||||||
|
query: &mut Vec<u8>,
|
||||||
|
test: bool,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let status_byte = match test {
|
let status_byte = match test {
|
||||||
true => Status::GeneralInquiry,
|
true => Status::GeneralInquiry,
|
||||||
false => Status::Control,
|
false => Status::Control,
|
||||||
|
@ -358,17 +362,17 @@ impl NetMDInterface {
|
||||||
new_query.push(status_byte as u8);
|
new_query.push(status_byte as u8);
|
||||||
new_query.append(query);
|
new_query.append(query);
|
||||||
|
|
||||||
self.net_md_device.send_command(new_query)?;
|
self.net_md_device.send_command(new_query).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_reply(&mut self, accept_interim: bool) -> Result<Vec<u8>, Box<dyn Error>> {
|
async fn read_reply(&mut self, accept_interim: bool) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let mut current_attempt = 0;
|
let mut current_attempt = 0;
|
||||||
let mut data;
|
let mut data;
|
||||||
|
|
||||||
while current_attempt < Self::MAX_INTERIM_READ_ATTEMPTS {
|
while current_attempt < Self::MAX_INTERIM_READ_ATTEMPTS {
|
||||||
data = match self.net_md_device.read_reply(None) {
|
data = match self.net_md_device.read_reply(None).await {
|
||||||
Ok(reply) => reply,
|
Ok(reply) => reply,
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
};
|
};
|
||||||
|
@ -403,66 +407,66 @@ impl NetMDInterface {
|
||||||
Err("The max retries is set to 0".into())
|
Err("The max retries is set to 0".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn playback_control(&mut self, action: Action) -> Result<(), Box<dyn Error>> {
|
async fn playback_control(&mut self, action: Action) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"18c3 00 %b 000000".to_string(),
|
"18c3 00 %b 000000".to_string(),
|
||||||
vec![QueryValue::Number(action as i64)],
|
vec![QueryValue::Number(action as i64)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "18c3 00 %b 000000".to_string())?;
|
scan_query(reply, "18c3 00 %b 000000".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn play(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self.playback_control(Action::Play)
|
self.playback_control(Action::Play).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fast_forward(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn fast_forward(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self.playback_control(Action::FastForward)
|
self.playback_control(Action::FastForward).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rewind(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn rewind(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self.playback_control(Action::Rewind)
|
self.playback_control(Action::Rewind).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn pause(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self.playback_control(Action::Pause)
|
self.playback_control(Action::Pause).await
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Implement fix for LAM-1
|
//TODO: Implement fix for LAM-1
|
||||||
pub fn stop(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn stop(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("18c5 ff 00000000".to_string(), vec![])?;
|
let mut query = format_query("18c5 ff 00000000".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "18c5 00 00000000".to_string())?;
|
scan_query(reply, "18c5 00 00000000".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn acquire(&mut self) -> Result<(), Box<dyn Error>> {
|
async fn acquire(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("ff 010c ffff ffff ffff ffff ffff ffff".to_string(), vec![])?;
|
let mut query = format_query("ff 010c ffff ffff ffff ffff ffff ffff".to_string(), vec![])?;
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "ff 010c ffff ffff ffff ffff ffff ffff".to_string())?;
|
scan_query(reply, "ff 010c ffff ffff ffff ffff ffff ffff".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn release(&mut self) -> Result<(), Box<dyn Error>> {
|
async fn release(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("ff 0100 ffff ffff ffff ffff ffff ffff".to_string(), vec![])?;
|
let mut query = format_query("ff 0100 ffff ffff ffff ffff ffff ffff".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "ff 0100 ffff ffff ffff ffff ffff ffff".to_string())?;
|
scan_query(reply, "ff 0100 ffff ffff ffff ffff ffff ffff".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn status(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn status(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::OperatingStatusBlock,
|
&Descriptor::OperatingStatusBlock,
|
||||||
&DescriptorAction::OpenRead,
|
&DescriptorAction::OpenRead,
|
||||||
|
@ -473,7 +477,7 @@ impl NetMDInterface {
|
||||||
vec![],
|
vec![],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -487,15 +491,15 @@ impl NetMDInterface {
|
||||||
Ok(final_array)
|
Ok(final_array)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disc_present(&mut self) -> Result<bool, Box<dyn Error>> {
|
pub async fn disc_present(&mut self) -> Result<bool, Box<dyn Error>> {
|
||||||
let status = self.status()?;
|
let status = self.status().await?;
|
||||||
|
|
||||||
println!("{:X?}", status);
|
println!("{:X?}", status);
|
||||||
|
|
||||||
Ok(status[4] == 0x40)
|
Ok(status[4] == 0x40)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn full_operating_status(&mut self) -> Result<(u8, u16), Box<dyn Error>> {
|
async fn full_operating_status(&mut self) -> Result<(u8, u16), Box<dyn Error>> {
|
||||||
// WARNING: Does not work for all devices. See https://github.com/cybercase/webminidisc/issues/21
|
// WARNING: Does not work for all devices. See https://github.com/cybercase/webminidisc/issues/21
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::OperatingStatusBlock,
|
&Descriptor::OperatingStatusBlock,
|
||||||
|
@ -506,7 +510,7 @@ impl NetMDInterface {
|
||||||
vec![],
|
vec![],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let result = scan_query(
|
let result = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -528,13 +532,13 @@ impl NetMDInterface {
|
||||||
Ok((status_mode, operating_status_number))
|
Ok((status_mode, operating_status_number))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn operating_status(&mut self) -> Result<u16, Box<dyn Error>> {
|
pub async fn operating_status(&mut self) -> Result<u16, Box<dyn Error>> {
|
||||||
let status = self.full_operating_status()?.1;
|
let status = self.full_operating_status().await?.1;
|
||||||
|
|
||||||
Ok(status)
|
Ok(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn playback_status_query(&mut self, p1: u32, p2: u32) -> Result<Vec<u8>, Box<dyn Error>> {
|
async fn playback_status_query(&mut self, p1: u32, p2: u32) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::OperatingStatusBlock,
|
&Descriptor::OperatingStatusBlock,
|
||||||
&DescriptorAction::OpenRead,
|
&DescriptorAction::OpenRead,
|
||||||
|
@ -545,7 +549,7 @@ impl NetMDInterface {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -557,15 +561,15 @@ impl NetMDInterface {
|
||||||
Ok(res.unwrap()[0].to_vec().unwrap())
|
Ok(res.unwrap()[0].to_vec().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn playback_status1(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn playback_status1(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.playback_status_query(0x8801, 0x8807)
|
self.playback_status_query(0x8801, 0x8807).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn playback_status2(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn playback_status2(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.playback_status_query(0x8802, 0x8806)
|
self.playback_status_query(0x8802, 0x8806).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn position(&mut self) -> Result<[u16; 5], Box<dyn Error>> {
|
pub async fn position(&mut self) -> Result<[u16; 5], Box<dyn Error>> {
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::OperatingStatusBlock,
|
&Descriptor::OperatingStatusBlock,
|
||||||
&DescriptorAction::OpenRead,
|
&DescriptorAction::OpenRead,
|
||||||
|
@ -577,7 +581,7 @@ impl NetMDInterface {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = match self.send_query(&mut query, false, false) {
|
let reply = match self.send_query(&mut query, false, false).await {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
Err(e) if e.to_string() == "Rejected" => Vec::new(),
|
Err(e) if e.to_string() == "Rejected" => Vec::new(),
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
|
@ -598,31 +602,31 @@ impl NetMDInterface {
|
||||||
Ok(final_result)
|
Ok(final_result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eject_disc(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn eject_disc(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("18c1 ff 6000".to_string(), vec![]).unwrap();
|
let mut query = format_query("18c1 ff 6000".to_string(), vec![]).unwrap();
|
||||||
|
|
||||||
let _reply = self.send_query(&mut query, false, false)?;
|
let _reply = self.send_query(&mut query, false, false).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn can_eject_disc(&mut self) -> Result<bool, Box<dyn Error>> {
|
pub async fn can_eject_disc(&mut self) -> Result<bool, Box<dyn Error>> {
|
||||||
let mut query = format_query("18c1 ff 6000".to_string(), vec![]).unwrap();
|
let mut query = format_query("18c1 ff 6000".to_string(), vec![]).unwrap();
|
||||||
|
|
||||||
match self.send_query(&mut query, true, false) {
|
match self.send_query(&mut query, true, false).await {
|
||||||
Ok(_) => Ok(true),
|
Ok(_) => Ok(true),
|
||||||
Err(error) => Err(error),
|
Err(error) => Err(error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Track control */
|
/* Track control */
|
||||||
pub fn go_to_track(&mut self, track_number: u16) -> Result<u16, Box<dyn Error>> {
|
pub async fn go_to_track(&mut self, track_number: u16) -> Result<u16, Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1850 ff010000 0000 %w".to_string(),
|
"1850 ff010000 0000 %w".to_string(),
|
||||||
vec![QueryValue::Number(track_number as i64)],
|
vec![QueryValue::Number(track_number as i64)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1850 00010000 0000 %w".to_string())?;
|
let res = scan_query(reply, "1850 00010000 0000 %w".to_string())?;
|
||||||
|
|
||||||
|
@ -631,7 +635,7 @@ impl NetMDInterface {
|
||||||
Ok(value as u16)
|
Ok(value as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go_to_time(
|
pub async fn go_to_time(
|
||||||
&mut self,
|
&mut self,
|
||||||
track_number: u16,
|
track_number: u16,
|
||||||
hour: u8,
|
hour: u8,
|
||||||
|
@ -651,7 +655,7 @@ impl NetMDInterface {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1850 00000000 %?%? %w %B%B%B%B".to_string())?;
|
let res = scan_query(reply, "1850 00000000 %?%? %w %B%B%B%B".to_string())?;
|
||||||
|
|
||||||
|
@ -660,14 +664,14 @@ impl NetMDInterface {
|
||||||
Ok(value as u16)
|
Ok(value as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _track_change(&mut self, direction: Track) -> Result<(), Box<dyn Error>> {
|
async fn track_change(&mut self, direction: Track) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1850 ff10 00000000 %w".to_string(),
|
"1850 ff10 00000000 %w".to_string(),
|
||||||
vec![QueryValue::Number(direction as i64)],
|
vec![QueryValue::Number(direction as i64)],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "1850 0010 00000000 %?%?".to_string())?;
|
scan_query(reply, "1850 0010 00000000 %?%?".to_string())?;
|
||||||
|
|
||||||
|
@ -675,35 +679,35 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change to the next track (skip forward)
|
/// Change to the next track (skip forward)
|
||||||
pub fn next_track(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn next_track(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self._track_change(Track::Next)
|
self.track_change(Track::Next).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change to the next track (skip back)
|
/// Change to the next track (skip back)
|
||||||
pub fn previous_track(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn previous_track(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self._track_change(Track::Next)
|
self.track_change(Track::Next).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change to the next track (skip to beginning of track)
|
/// Change to the next track (skip to beginning of track)
|
||||||
pub fn restart_track(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn restart_track(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
self._track_change(Track::Next)
|
self.track_change(Track::Next).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Content access and control */
|
/* Content access and control */
|
||||||
pub fn erase_disc(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn erase_disc(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("1840 ff 0000".to_string(), vec![]).unwrap();
|
let mut query = format_query("1840 ff 0000".to_string(), vec![]).unwrap();
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
scan_query(reply, "1840 00 0000".to_string())?;
|
scan_query(reply, "1840 00 0000".to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ensure this is returning the correct value, it
|
// TODO: Ensure this is returning the correct value, it
|
||||||
// looks like it actually might be a 16 bit integer
|
// looks like it actually might be a 16 bit integer
|
||||||
pub fn disc_flags(&mut self) -> Result<u8, Box<dyn Error>> {
|
pub async fn disc_flags(&mut self) -> Result<u8, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::RootTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::RootTD, &DescriptorAction::OpenRead);
|
||||||
let mut query = format_query("1806 01101000 ff00 0001000b".to_string(), vec![]).unwrap();
|
let mut query = format_query("1806 01101000 ff00 0001000b".to_string(), vec![]).unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1806 01101000 1000 0001000b %b".to_string()).unwrap();
|
let res = scan_query(reply, "1806 01101000 1000 0001000b %b".to_string()).unwrap();
|
||||||
|
|
||||||
|
@ -713,13 +717,13 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The number of tracks on the disc
|
/// The number of tracks on the disc
|
||||||
pub fn track_count(&mut self) -> Result<u16, Box<dyn Error>> {
|
pub async fn track_count(&mut self) -> Result<u16, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||||
|
|
||||||
let mut query =
|
let mut query =
|
||||||
format_query("1806 02101001 3000 1000 ff00 00000000".to_string(), vec![]).unwrap();
|
format_query("1806 02101001 3000 1000 ff00 00000000".to_string(), vec![]).unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -732,7 +736,7 @@ impl NetMDInterface {
|
||||||
Ok(res[0].to_i64().unwrap() as u16)
|
Ok(res[0].to_i64().unwrap() as u16)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _disc_title(&mut self, wchar: bool) -> Result<String, Box<dyn Error>> {
|
async fn raw_disc_title(&mut self, wchar: bool) -> Result<String, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||||
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::OpenRead);
|
||||||
|
|
||||||
|
@ -759,7 +763,7 @@ impl NetMDInterface {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
if remaining == 0 {
|
if remaining == 0 {
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
|
@ -795,8 +799,8 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the disc title
|
/// Gets the disc title
|
||||||
pub fn disc_title(&mut self, wchar: bool) -> Result<String, Box<dyn Error>> {
|
pub async fn disc_title(&mut self, wchar: bool) -> Result<String, Box<dyn Error>> {
|
||||||
let mut title = self._disc_title(wchar)?;
|
let mut title = self.raw_disc_title(wchar).await?;
|
||||||
|
|
||||||
let delim = match wchar {
|
let delim = match wchar {
|
||||||
true => "//",
|
true => "//",
|
||||||
|
@ -821,16 +825,16 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all groups on the disc
|
/// Gets all groups on the disc
|
||||||
pub fn track_group_list(
|
pub async fn track_group_list(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<Vec<(Option<String>, Option<String>, Vec<u16>)>, Box<dyn Error>> {
|
) -> Result<Vec<(Option<String>, Option<String>, Vec<u16>)>, Box<dyn Error>> {
|
||||||
let raw_title = self._disc_title(false)?;
|
let raw_title = self.raw_disc_title(false).await?;
|
||||||
let group_list = raw_title.split("//");
|
let group_list = raw_title.split("//");
|
||||||
let mut track_dict: HashMap<u16, (String, u16)> = HashMap::new();
|
let mut track_dict: HashMap<u16, (String, u16)> = HashMap::new();
|
||||||
let track_count = self.track_count()?;
|
let track_count = self.track_count().await?;
|
||||||
let mut result: Vec<(Option<String>, Option<String>, Vec<u16>)> = Vec::new();
|
let mut result: Vec<(Option<String>, Option<String>, Vec<u16>)> = Vec::new();
|
||||||
|
|
||||||
let raw_full_title = self._disc_title(true)?;
|
let raw_full_title = self.raw_disc_title(true).await?;
|
||||||
|
|
||||||
let mut full_width_group_list = raw_full_title.split("//");
|
let mut full_width_group_list = raw_full_title.split("//");
|
||||||
|
|
||||||
|
@ -907,7 +911,7 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a list of track titles from a set
|
/// Gets a list of track titles from a set
|
||||||
pub fn track_titles(
|
pub async fn track_titles(
|
||||||
&mut self,
|
&mut self,
|
||||||
tracks: Vec<u16>,
|
tracks: Vec<u16>,
|
||||||
wchar: bool,
|
wchar: bool,
|
||||||
|
@ -935,7 +939,7 @@ impl NetMDInterface {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -956,9 +960,9 @@ impl NetMDInterface {
|
||||||
Ok(track_titles)
|
Ok(track_titles)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the title of a track at an index
|
/// Gets the title of a single track at an index
|
||||||
pub fn track_title(&mut self, track: u16, wchar: bool) -> Result<String, Box<dyn Error>> {
|
pub async fn track_title(&mut self, track: u16, wchar: bool) -> Result<String, Box<dyn Error>> {
|
||||||
let title = match self.track_titles([track].into(), wchar) {
|
let title = match self.track_titles([track].into(), wchar).await {
|
||||||
Ok(titles) => titles[0].clone(),
|
Ok(titles) => titles[0].clone(),
|
||||||
Err(error) if error.to_string() == "Rejected" => String::new(),
|
Err(error) if error.to_string() == "Rejected" => String::new(),
|
||||||
Err(error) => return Err(error),
|
Err(error) => return Err(error),
|
||||||
|
@ -967,10 +971,14 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets the title of the disc
|
// Sets the title of the disc
|
||||||
pub fn set_disc_title(&mut self, title: String, wchar: bool) -> Result<(), Box<dyn Error>> {
|
pub async fn set_disc_title(
|
||||||
let current_title = self._disc_title(wchar)?;
|
&mut self,
|
||||||
|
title: String,
|
||||||
|
wchar: bool,
|
||||||
|
) -> Result<(), Box<dyn Error>> {
|
||||||
|
let current_title = self.raw_disc_title(wchar).await?;
|
||||||
if current_title == title {
|
if current_title == title {
|
||||||
return Ok(());
|
return Err("Title is already the same".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_title: Vec<u8>;
|
let new_title: Vec<u8>;
|
||||||
|
@ -989,7 +997,7 @@ impl NetMDInterface {
|
||||||
|
|
||||||
let new_len = new_title.len();
|
let new_len = new_title.len();
|
||||||
|
|
||||||
if self.net_md_device.vendor_id() == &0x04dd {
|
if self.net_md_device.vendor_id().await == &0x04dd {
|
||||||
self.change_descriptor_state(&Descriptor::AudioUTOC1TD, &DescriptorAction::OpenWrite)
|
self.change_descriptor_state(&Descriptor::AudioUTOC1TD, &DescriptorAction::OpenWrite)
|
||||||
} else {
|
} else {
|
||||||
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::Close);
|
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::Close);
|
||||||
|
@ -1008,7 +1016,7 @@ impl NetMDInterface {
|
||||||
|
|
||||||
let _ = self.send_query(&mut query, false, false);
|
let _ = self.send_query(&mut query, false, false);
|
||||||
|
|
||||||
if self.net_md_device.vendor_id() == &0x04dd {
|
if self.net_md_device.vendor_id().await == &0x04dd {
|
||||||
self.change_descriptor_state(&Descriptor::AudioUTOC1TD, &DescriptorAction::Close)
|
self.change_descriptor_state(&Descriptor::AudioUTOC1TD, &DescriptorAction::Close)
|
||||||
} else {
|
} else {
|
||||||
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::Close);
|
self.change_descriptor_state(&Descriptor::DiscTitleTD, &DescriptorAction::Close);
|
||||||
|
@ -1020,7 +1028,7 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the title of a track
|
/// Sets the title of a track
|
||||||
pub fn set_track_title(
|
pub async fn set_track_title(
|
||||||
&mut self,
|
&mut self,
|
||||||
track: u16,
|
track: u16,
|
||||||
title: String,
|
title: String,
|
||||||
|
@ -1040,7 +1048,7 @@ impl NetMDInterface {
|
||||||
|
|
||||||
let new_len = new_title.len();
|
let new_len = new_title.len();
|
||||||
|
|
||||||
let old_len: u16 = match self.track_title(track, wchar) {
|
let old_len: u16 = match self.track_title(track, wchar).await {
|
||||||
Ok(current_title) => {
|
Ok(current_title) => {
|
||||||
if title == current_title {
|
if title == current_title {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -1062,7 +1070,7 @@ impl NetMDInterface {
|
||||||
QueryValue::Array(new_title),
|
QueryValue::Array(new_title),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let _ = scan_query(
|
let _ = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -1074,19 +1082,19 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes a track from the UTOC
|
/// Removes a track from the UTOC
|
||||||
pub fn erase_track(&mut self, track: u16) -> Result<(), Box<dyn Error>> {
|
pub async fn erase_track(&mut self, track: u16) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1840 ff01 00 201001 %w".to_string(),
|
"1840 ff01 00 201001 %w".to_string(),
|
||||||
vec![QueryValue::Number(track as i64)],
|
vec![QueryValue::Number(track as i64)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let _ = self.send_query(&mut query, false, false);
|
let _result = self.send_query(&mut query, false, false).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves a track to another position on the disc
|
/// Moves a track to another position on the disc
|
||||||
pub fn move_track(&mut self, source: u16, dest: u16) -> Result<(), Box<dyn Error>> {
|
pub async fn move_track(&mut self, source: u16, dest: u16) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1843 ff00 00 201001 %w 201001 %w".to_string(),
|
"1843 ff00 00 201001 %w 201001 %w".to_string(),
|
||||||
vec![
|
vec![
|
||||||
|
@ -1095,12 +1103,17 @@ impl NetMDInterface {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let _ = self.send_query(&mut query, false, false);
|
let _result = self.send_query(&mut query, false, false).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _track_info(&mut self, track: u16, p1: i32, p2: i32) -> Result<Vec<u8>, Box<dyn Error>> {
|
async fn raw_track_info(
|
||||||
|
&mut self,
|
||||||
|
track: u16,
|
||||||
|
p1: i32,
|
||||||
|
p2: i32,
|
||||||
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||||
|
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
|
@ -1112,7 +1125,7 @@ impl NetMDInterface {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
"1806 02201001 %?%? %?%? %?%? 1000 00%?0000 %x".to_string(),
|
"1806 02201001 %?%? %?%? %?%? 1000 00%?0000 %x".to_string(),
|
||||||
|
@ -1124,7 +1137,7 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the length of tracks as a `std::time::Duration` from a set
|
/// Gets the length of tracks as a `std::time::Duration` from a set
|
||||||
pub fn track_lengths(
|
pub async fn track_lengths(
|
||||||
&mut self,
|
&mut self,
|
||||||
tracks: Vec<u16>,
|
tracks: Vec<u16>,
|
||||||
) -> Result<Vec<std::time::Duration>, Box<dyn Error>> {
|
) -> Result<Vec<std::time::Duration>, Box<dyn Error>> {
|
||||||
|
@ -1141,7 +1154,7 @@ impl NetMDInterface {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -1168,13 +1181,16 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the length of a track as a `std::time::Duration`
|
/// Gets the length of a track as a `std::time::Duration`
|
||||||
pub fn track_length(&mut self, track: u16) -> Result<std::time::Duration, Box<dyn Error>> {
|
pub async fn track_length(
|
||||||
Ok(self.track_lengths([track].into())?[0])
|
&mut self,
|
||||||
|
track: u16,
|
||||||
|
) -> Result<std::time::Duration, Box<dyn Error>> {
|
||||||
|
Ok(self.track_lengths([track].into()).await?[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the encoding of a track (SP, LP2, LP4)
|
/// Gets the encoding of a track (SP, LP2, LP4)
|
||||||
pub fn track_encoding(&mut self, track_number: u16) -> Result<Encoding, Box<dyn Error>> {
|
pub async fn track_encoding(&mut self, track_number: u16) -> Result<Encoding, Box<dyn Error>> {
|
||||||
let raw_value = self._track_info(track_number, 0x3080, 0x0700)?;
|
let raw_value = self.raw_track_info(track_number, 0x3080, 0x0700).await?;
|
||||||
let result = scan_query(raw_value, "07 0004 0110 %b %b".to_string())?;
|
let result = scan_query(raw_value, "07 0004 0110 %b %b".to_string())?;
|
||||||
|
|
||||||
let final_encoding = match result[0].to_i64() {
|
let final_encoding = match result[0].to_i64() {
|
||||||
|
@ -1189,13 +1205,13 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a track's flags
|
/// Gets a track's flags
|
||||||
pub fn track_flags(&mut self, track: u16) -> Result<u8, Box<dyn Error>> {
|
pub async fn track_flags(&mut self, track: u16) -> Result<u8, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::AudioContentsTD, &DescriptorAction::OpenRead);
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1806 01201001 %w ff00 00010008".to_string(),
|
"1806 01201001 %w ff00 00010008".to_string(),
|
||||||
vec![QueryValue::Number(track as i64)],
|
vec![QueryValue::Number(track as i64)],
|
||||||
)?;
|
)?;
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1806 01201001 %?%? 10 00 00010008 %b".to_string())?;
|
let res = scan_query(reply, "1806 01201001 %?%? 10 00 00010008 %b".to_string())?;
|
||||||
|
|
||||||
|
@ -1205,10 +1221,10 @@ impl NetMDInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the disc capacity as a `std::time::Duration`
|
/// Gets the disc capacity as a `std::time::Duration`
|
||||||
pub fn disc_capacity(&mut self) -> Result<[std::time::Duration; 3], Box<dyn Error>> {
|
pub async fn disc_capacity(&mut self) -> Result<[std::time::Duration; 3], Box<dyn Error>> {
|
||||||
self.change_descriptor_state(&Descriptor::RootTD, &DescriptorAction::OpenRead);
|
self.change_descriptor_state(&Descriptor::RootTD, &DescriptorAction::OpenRead);
|
||||||
let mut query = format_query("1806 02101000 3080 0300 ff00 00000000".to_string(), vec![])?;
|
let mut query = format_query("1806 02101000 3080 0300 ff00 00000000".to_string(), vec![])?;
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
let mut result: [std::time::Duration; 3] = [std::time::Duration::from_secs(0); 3];
|
let mut result: [std::time::Duration; 3] = [std::time::Duration::from_secs(0); 3];
|
||||||
|
|
||||||
// 8003 changed to %?03 - Panasonic returns 0803 instead. This byte's meaning is unknown
|
// 8003 changed to %?03 - Panasonic returns 0803 instead. This byte's meaning is unknown
|
||||||
|
@ -1234,7 +1250,7 @@ impl NetMDInterface {
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recording_parameters(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn recording_parameters(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
self.change_descriptor_state(
|
self.change_descriptor_state(
|
||||||
&Descriptor::OperatingStatusBlock,
|
&Descriptor::OperatingStatusBlock,
|
||||||
&DescriptorAction::OpenRead,
|
&DescriptorAction::OpenRead,
|
||||||
|
@ -1244,7 +1260,7 @@ impl NetMDInterface {
|
||||||
vec![],
|
vec![],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1809 8001 0330 8801 0030 8805 0030 8807 00 1000 000e0000 000c 8805 0008 80e0 0110 %b %b 4000".to_string())?;
|
let res = scan_query(reply, "1809 8001 0330 8801 0030 8805 0030 8807 00 1000 000e0000 000c 8805 0008 80e0 0110 %b %b 4000".to_string())?;
|
||||||
|
|
||||||
|
@ -1256,7 +1272,7 @@ impl NetMDInterface {
|
||||||
/// Gets the bytes of a track
|
/// Gets the bytes of a track
|
||||||
///
|
///
|
||||||
/// This can only be executed on an MZ-RH1 / M200
|
/// This can only be executed on an MZ-RH1 / M200
|
||||||
pub fn save_track_to_array(
|
pub async fn save_track_to_array(
|
||||||
&mut self,
|
&mut self,
|
||||||
track: u16,
|
track: u16,
|
||||||
) -> Result<(DiscFormat, u16, Vec<u8>), Box<dyn Error>> {
|
) -> Result<(DiscFormat, u16, Vec<u8>), Box<dyn Error>> {
|
||||||
|
@ -1265,7 +1281,7 @@ impl NetMDInterface {
|
||||||
vec![QueryValue::Number((track + 1) as i64)],
|
vec![QueryValue::Number((track + 1) as i64)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, true)?;
|
let reply = self.send_query(&mut query, false, true).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -1276,10 +1292,10 @@ impl NetMDInterface {
|
||||||
let codec = res[1].to_i64().unwrap() as u8;
|
let codec = res[1].to_i64().unwrap() as u8;
|
||||||
let length = res[2].to_i64().unwrap() as usize;
|
let length = res[2].to_i64().unwrap() as usize;
|
||||||
|
|
||||||
let result = self.net_md_device.read_bulk(length, 0x10000)?;
|
let result = self.net_md_device.read_bulk(length, 0x10000).await?;
|
||||||
|
|
||||||
scan_query(
|
scan_query(
|
||||||
self.read_reply(false)?,
|
self.read_reply(false).await?,
|
||||||
"1800 080046 f003010330 0000 1001 %?%? %?%?".to_string(),
|
"1800 080046 f003010330 0000 1001 %?%? %?%?".to_string(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -1296,50 +1312,51 @@ impl NetMDInterface {
|
||||||
Ok((format, frames, result))
|
Ok((format, frames, result))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_new_track_protection(&mut self, val: u16) -> Result<(), Box<dyn Error>> {
|
pub async fn disable_new_track_protection(&mut self, val: u16) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1800 080046 f0030103 2b ff %w".to_string(),
|
"1800 080046 f0030103 2b ff %w".to_string(),
|
||||||
vec![QueryValue::Number(val as i64)],
|
vec![QueryValue::Number(val as i64)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
scan_query(reply, "1800 080046 f0030103 2b 00 %?%?".to_string())?;
|
scan_query(reply, "1800 080046 f0030103 2b 00 %?%?".to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enter_secure_session(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn enter_secure_session(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("1800 080046 f0030103 80 ff".to_string(), vec![])?;
|
let mut query = format_query("1800 080046 f0030103 80 ff".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
scan_query(reply, "1800 080046 f0030103 80 00".to_string())?;
|
scan_query(reply, "1800 080046 f0030103 80 00".to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn leave_secure_session(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn leave_secure_session(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("1800 080046 f0030103 81 ff".to_string(), vec![])?;
|
let mut query = format_query("1800 080046 f0030103 81 ff".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
scan_query(reply, "1800 080046 f0030103 81 00".to_string())?;
|
scan_query(reply, "1800 080046 f0030103 81 00".to_string())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Read the leaf ID of the present NetMD device. The leaf ID tells
|
* Read the leaf ID of the present NetMD device. The leaf ID tells
|
||||||
which keys the device posesses, which is needed to find out which
|
* which keys the device posesses, which is needed to find out which
|
||||||
parts of the EKB needs to be sent to the device for it to decrypt
|
* parts of the EKB needs to be sent to the device for it to decrypt
|
||||||
the root key.
|
* the root key.
|
||||||
The leaf ID is a 8-byte constant
|
*
|
||||||
**/
|
* The leaf ID is a 8-byte constant
|
||||||
pub fn leaf_id(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
**/
|
||||||
|
pub async fn leaf_id(&mut self) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
let mut query = format_query("1800 080046 f0030103 11 ff".to_string(), vec![])?;
|
let mut query = format_query("1800 080046 f0030103 11 ff".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
let res = scan_query(reply, "1800 080046 f0030103 11 00 %*".to_string())?;
|
let res = scan_query(reply, "1800 080046 f0030103 11 00 %*".to_string())?;
|
||||||
|
|
||||||
Ok(res[0].to_vec().unwrap())
|
Ok(res[0].to_vec().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_key_data(
|
pub async fn send_key_data(
|
||||||
&mut self,
|
&mut self,
|
||||||
ekbid: i32,
|
ekbid: i32,
|
||||||
keychain: [[u8; 16]; 2],
|
keychain: [[u8; 16]; 2],
|
||||||
|
@ -1371,7 +1388,7 @@ impl NetMDInterface {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
|
@ -1381,7 +1398,10 @@ impl NetMDInterface {
|
||||||
Ok(res[0].to_vec().unwrap())
|
Ok(res[0].to_vec().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn session_key_exchange(&mut self, hostnonce: Vec<u8>) -> Result<Vec<u8>, Box<dyn Error>> {
|
pub async fn session_key_exchange(
|
||||||
|
&mut self,
|
||||||
|
hostnonce: Vec<u8>,
|
||||||
|
) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
if hostnonce.len() != 8 {
|
if hostnonce.len() != 8 {
|
||||||
return Err("Supplied host nonce length wrong".into());
|
return Err("Supplied host nonce length wrong".into());
|
||||||
}
|
}
|
||||||
|
@ -1390,23 +1410,23 @@ impl NetMDInterface {
|
||||||
vec![QueryValue::Array(hostnonce)],
|
vec![QueryValue::Array(hostnonce)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1800 080046 f0030103 20 %? 000000 %#".to_string())?;
|
let res = scan_query(reply, "1800 080046 f0030103 20 %? 000000 %#".to_string())?;
|
||||||
|
|
||||||
Ok(res[0].to_vec().unwrap())
|
Ok(res[0].to_vec().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn session_key_forget(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn session_key_forget(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("1800 080046 f0030103 21 ff 000000".to_string(), vec![])?;
|
let mut query = format_query("1800 080046 f0030103 21 ff 000000".to_string(), vec![])?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
let _ = scan_query(reply, "1800 080046 f0030103 21 00 000000".to_string())?;
|
let _ = scan_query(reply, "1800 080046 f0030103 21 00 000000".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_download(
|
pub async fn setup_download(
|
||||||
&mut self,
|
&mut self,
|
||||||
contentid: Vec<u8>,
|
contentid: Vec<u8>,
|
||||||
keyenckey: Vec<u8>,
|
keyenckey: Vec<u8>,
|
||||||
|
@ -1433,14 +1453,14 @@ impl NetMDInterface {
|
||||||
vec![QueryValue::Array(encryptedarg)],
|
vec![QueryValue::Array(encryptedarg)],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "1800 080046 f0030103 22 00 0000".to_string())?;
|
scan_query(reply, "1800 080046 f0030103 22 00 0000".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn commit_track(
|
pub async fn commit_track(
|
||||||
&mut self,
|
&mut self,
|
||||||
track_number: u16,
|
track_number: u16,
|
||||||
hex_session_key: String,
|
hex_session_key: String,
|
||||||
|
@ -1460,14 +1480,14 @@ impl NetMDInterface {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
scan_query(reply, "1800 080046 f0030103 22 00 0000".to_string())?;
|
scan_query(reply, "1800 080046 f0030103 22 00 0000".to_string())?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_track(
|
pub async fn send_track(
|
||||||
&mut self,
|
&mut self,
|
||||||
wireformat: u8,
|
wireformat: u8,
|
||||||
discformat: u8,
|
discformat: u8,
|
||||||
|
@ -1495,7 +1515,7 @@ impl NetMDInterface {
|
||||||
QueryValue::Number(total_bytes as i64),
|
QueryValue::Number(total_bytes as i64),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
let mut reply = self.send_query(&mut query, false, true)?;
|
let mut reply = self.send_query(&mut query, false, true).await?;
|
||||||
scan_query(
|
scan_query(
|
||||||
reply,
|
reply,
|
||||||
"1800 080046 f0030103 28 00 000100 1001 %?%? 00 %*".to_string(),
|
"1800 080046 f0030103 28 00 000100 1001 %?%? 00 %*".to_string(),
|
||||||
|
@ -1512,12 +1532,12 @@ impl NetMDInterface {
|
||||||
} else {
|
} else {
|
||||||
data.clone()
|
data.clone()
|
||||||
};
|
};
|
||||||
self.net_md_device.write_bulk(binpack)?;
|
self.net_md_device.write_bulk(binpack).await?;
|
||||||
_written_bytes += data.len();
|
_written_bytes += data.len();
|
||||||
}
|
}
|
||||||
|
|
||||||
reply = self.read_reply(false)?;
|
reply = self.read_reply(false).await?;
|
||||||
self.net_md_device.poll()?;
|
self.net_md_device.poll().await?;
|
||||||
let res = scan_query(
|
let res = scan_query(
|
||||||
reply,
|
reply,
|
||||||
"1800 080046 f0030103 28 00 000100 1001 %w 00 %?%? %?%?%?%? %?%?%?%? %*".to_string(),
|
"1800 080046 f0030103 28 00 000100 1001 %w 00 %?%? %?%?%?%? %?%?%?%? %*".to_string(),
|
||||||
|
@ -1536,21 +1556,21 @@ impl NetMDInterface {
|
||||||
Ok((res[0].to_i64().unwrap(), part1, part2))
|
Ok((res[0].to_i64().unwrap(), part1, part2))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn track_uuid(&mut self, track: u16) -> Result<String, Box<dyn Error>> {
|
pub async fn track_uuid(&mut self, track: u16) -> Result<String, Box<dyn Error>> {
|
||||||
let mut query = format_query(
|
let mut query = format_query(
|
||||||
"1800 080046 f0030103 23 ff 1001 %w".to_string(),
|
"1800 080046 f0030103 23 ff 1001 %w".to_string(),
|
||||||
vec![QueryValue::Number(track as i64)],
|
vec![QueryValue::Number(track as i64)],
|
||||||
)?;
|
)?;
|
||||||
let reply = self.send_query(&mut query, false, false)?;
|
let reply = self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
let res = scan_query(reply, "1800 080046 f0030103 23 00 1001 %?%? %*".to_string())?;
|
let res = scan_query(reply, "1800 080046 f0030103 23 00 1001 %?%? %*".to_string())?;
|
||||||
|
|
||||||
Ok(String::from_utf8_lossy(&res[0].to_vec().unwrap()).to_string())
|
Ok(String::from_utf8_lossy(&res[0].to_vec().unwrap()).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn terminate(&mut self) -> Result<(), Box<dyn Error>> {
|
pub async fn terminate(&mut self) -> Result<(), Box<dyn Error>> {
|
||||||
let mut query = format_query("1800 080046 f0030103 2a ff00".to_string(), vec![])?;
|
let mut query = format_query("1800 080046 f0030103 2a ff00".to_string(), vec![])?;
|
||||||
self.send_query(&mut query, false, false)?;
|
self.send_query(&mut query, false, false).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,7 +193,6 @@ lazy_static! {
|
||||||
("。".to_string(), "。".to_string()),
|
("。".to_string(), "。".to_string()),
|
||||||
("、".to_string(), "、".to_string())
|
("、".to_string(), "、".to_string())
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pub static ref MAPPINGS_RU: HashMap<String, String> = HashMap::from([
|
pub static ref MAPPINGS_RU: HashMap<String, String> = HashMap::from([
|
||||||
("а".to_string(), "a".to_string()),
|
("а".to_string(), "a".to_string()),
|
||||||
("б".to_string(), "b".to_string()),
|
("б".to_string(), "b".to_string()),
|
||||||
|
@ -262,7 +261,6 @@ lazy_static! {
|
||||||
("Ю".to_string(), "Iu".to_string()),
|
("Ю".to_string(), "Iu".to_string()),
|
||||||
("Я".to_string(), "Ia".to_string())
|
("Я".to_string(), "Ia".to_string())
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pub static ref MAPPINGS_DE: HashMap<String, String> = HashMap::from([
|
pub static ref MAPPINGS_DE: HashMap<String, String> = HashMap::from([
|
||||||
("Ä".to_string(), "Ae".to_string()),
|
("Ä".to_string(), "Ae".to_string()),
|
||||||
("ä".to_string(), "ae".to_string()),
|
("ä".to_string(), "ae".to_string()),
|
||||||
|
@ -272,287 +270,285 @@ lazy_static! {
|
||||||
("ü".to_string(), "ue".to_string()),
|
("ü".to_string(), "ue".to_string()),
|
||||||
("ß".to_string(), "ss".to_string())
|
("ß".to_string(), "ss".to_string())
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pub static ref MAPPINGS_HW: HashMap<String, String> = HashMap::from([
|
pub static ref MAPPINGS_HW: HashMap<String, String> = HashMap::from([
|
||||||
("-".to_string(),"-".to_string()),
|
("-".to_string(), "-".to_string()),
|
||||||
("ー".to_string(),"-".to_string()),
|
("ー".to_string(), "-".to_string()),
|
||||||
("ァ".to_string(),"ァ".to_string()),
|
("ァ".to_string(), "ァ".to_string()),
|
||||||
("ア".to_string(),"ア".to_string()),
|
("ア".to_string(), "ア".to_string()),
|
||||||
("ィ".to_string(),"ィ".to_string()),
|
("ィ".to_string(), "ィ".to_string()),
|
||||||
("イ".to_string(),"イ".to_string()),
|
("イ".to_string(), "イ".to_string()),
|
||||||
("ゥ".to_string(),"ゥ".to_string()),
|
("ゥ".to_string(), "ゥ".to_string()),
|
||||||
("ウ".to_string(),"ウ".to_string()),
|
("ウ".to_string(), "ウ".to_string()),
|
||||||
("ェ".to_string(),"ェ".to_string()),
|
("ェ".to_string(), "ェ".to_string()),
|
||||||
("エ".to_string(),"エ".to_string()),
|
("エ".to_string(), "エ".to_string()),
|
||||||
("ォ".to_string(),"ォ".to_string()),
|
("ォ".to_string(), "ォ".to_string()),
|
||||||
("オ".to_string(),"オ".to_string()),
|
("オ".to_string(), "オ".to_string()),
|
||||||
("カ".to_string(),"カ".to_string()),
|
("カ".to_string(), "カ".to_string()),
|
||||||
("ガ".to_string(),"ガ".to_string()),
|
("ガ".to_string(), "ガ".to_string()),
|
||||||
("キ".to_string(),"キ".to_string()),
|
("キ".to_string(), "キ".to_string()),
|
||||||
("ギ".to_string(),"ギ".to_string()),
|
("ギ".to_string(), "ギ".to_string()),
|
||||||
("ク".to_string(),"ク".to_string()),
|
("ク".to_string(), "ク".to_string()),
|
||||||
("グ".to_string(),"グ".to_string()),
|
("グ".to_string(), "グ".to_string()),
|
||||||
("ケ".to_string(),"ケ".to_string()),
|
("ケ".to_string(), "ケ".to_string()),
|
||||||
("ゲ".to_string(),"ゲ".to_string()),
|
("ゲ".to_string(), "ゲ".to_string()),
|
||||||
("コ".to_string(),"コ".to_string()),
|
("コ".to_string(), "コ".to_string()),
|
||||||
("ゴ".to_string(),"ゴ".to_string()),
|
("ゴ".to_string(), "ゴ".to_string()),
|
||||||
("サ".to_string(),"サ".to_string()),
|
("サ".to_string(), "サ".to_string()),
|
||||||
("ザ".to_string(),"ザ".to_string()),
|
("ザ".to_string(), "ザ".to_string()),
|
||||||
("シ".to_string(),"シ".to_string()),
|
("シ".to_string(), "シ".to_string()),
|
||||||
("ジ".to_string(),"ジ".to_string()),
|
("ジ".to_string(), "ジ".to_string()),
|
||||||
("ス".to_string(),"ス".to_string()),
|
("ス".to_string(), "ス".to_string()),
|
||||||
("ズ".to_string(),"ズ".to_string()),
|
("ズ".to_string(), "ズ".to_string()),
|
||||||
("セ".to_string(),"セ".to_string()),
|
("セ".to_string(), "セ".to_string()),
|
||||||
("ゼ".to_string(),"ゼ".to_string()),
|
("ゼ".to_string(), "ゼ".to_string()),
|
||||||
("ソ".to_string(),"ソ".to_string()),
|
("ソ".to_string(), "ソ".to_string()),
|
||||||
("ゾ".to_string(),"ゾ".to_string()),
|
("ゾ".to_string(), "ゾ".to_string()),
|
||||||
("タ".to_string(),"タ".to_string()),
|
("タ".to_string(), "タ".to_string()),
|
||||||
("ダ".to_string(),"ダ".to_string()),
|
("ダ".to_string(), "ダ".to_string()),
|
||||||
("チ".to_string(),"チ".to_string()),
|
("チ".to_string(), "チ".to_string()),
|
||||||
("ヂ".to_string(),"ヂ".to_string()),
|
("ヂ".to_string(), "ヂ".to_string()),
|
||||||
("ッ".to_string(),"ッ".to_string()),
|
("ッ".to_string(), "ッ".to_string()),
|
||||||
("ツ".to_string(),"ツ".to_string()),
|
("ツ".to_string(), "ツ".to_string()),
|
||||||
("ヅ".to_string(),"ヅ".to_string()),
|
("ヅ".to_string(), "ヅ".to_string()),
|
||||||
("テ".to_string(),"テ".to_string()),
|
("テ".to_string(), "テ".to_string()),
|
||||||
("デ".to_string(),"デ".to_string()),
|
("デ".to_string(), "デ".to_string()),
|
||||||
("ト".to_string(),"ト".to_string()),
|
("ト".to_string(), "ト".to_string()),
|
||||||
("ド".to_string(),"ド".to_string()),
|
("ド".to_string(), "ド".to_string()),
|
||||||
("ナ".to_string(),"ナ".to_string()),
|
("ナ".to_string(), "ナ".to_string()),
|
||||||
("ニ".to_string(),"ニ".to_string()),
|
("ニ".to_string(), "ニ".to_string()),
|
||||||
("ヌ".to_string(),"ヌ".to_string()),
|
("ヌ".to_string(), "ヌ".to_string()),
|
||||||
("ネ".to_string(),"ネ".to_string()),
|
("ネ".to_string(), "ネ".to_string()),
|
||||||
("ノ".to_string(),"ノ".to_string()),
|
("ノ".to_string(), "ノ".to_string()),
|
||||||
("ハ".to_string(),"ハ".to_string()),
|
("ハ".to_string(), "ハ".to_string()),
|
||||||
("バ".to_string(),"バ".to_string()),
|
("バ".to_string(), "バ".to_string()),
|
||||||
("パ".to_string(),"パ".to_string()),
|
("パ".to_string(), "パ".to_string()),
|
||||||
("ヒ".to_string(),"ヒ".to_string()),
|
("ヒ".to_string(), "ヒ".to_string()),
|
||||||
("ビ".to_string(),"ビ".to_string()),
|
("ビ".to_string(), "ビ".to_string()),
|
||||||
("ピ".to_string(),"ピ".to_string()),
|
("ピ".to_string(), "ピ".to_string()),
|
||||||
("フ".to_string(),"フ".to_string()),
|
("フ".to_string(), "フ".to_string()),
|
||||||
("ブ".to_string(),"ブ".to_string()),
|
("ブ".to_string(), "ブ".to_string()),
|
||||||
("プ".to_string(),"プ".to_string()),
|
("プ".to_string(), "プ".to_string()),
|
||||||
("ヘ".to_string(),"ヘ".to_string()),
|
("ヘ".to_string(), "ヘ".to_string()),
|
||||||
("ベ".to_string(),"ベ".to_string()),
|
("ベ".to_string(), "ベ".to_string()),
|
||||||
("ペ".to_string(),"ペ".to_string()),
|
("ペ".to_string(), "ペ".to_string()),
|
||||||
("ホ".to_string(),"ホ".to_string()),
|
("ホ".to_string(), "ホ".to_string()),
|
||||||
("ボ".to_string(),"ボ".to_string()),
|
("ボ".to_string(), "ボ".to_string()),
|
||||||
("ポ".to_string(),"ポ".to_string()),
|
("ポ".to_string(), "ポ".to_string()),
|
||||||
("マ".to_string(),"マ".to_string()),
|
("マ".to_string(), "マ".to_string()),
|
||||||
("ミ".to_string(),"ミ".to_string()),
|
("ミ".to_string(), "ミ".to_string()),
|
||||||
("ム".to_string(),"ム".to_string()),
|
("ム".to_string(), "ム".to_string()),
|
||||||
("メ".to_string(),"メ".to_string()),
|
("メ".to_string(), "メ".to_string()),
|
||||||
("モ".to_string(),"モ".to_string()),
|
("モ".to_string(), "モ".to_string()),
|
||||||
("ャ".to_string(),"ャ".to_string()),
|
("ャ".to_string(), "ャ".to_string()),
|
||||||
("ヤ".to_string(),"ヤ".to_string()),
|
("ヤ".to_string(), "ヤ".to_string()),
|
||||||
("ュ".to_string(),"ュ".to_string()),
|
("ュ".to_string(), "ュ".to_string()),
|
||||||
("ユ".to_string(),"ユ".to_string()),
|
("ユ".to_string(), "ユ".to_string()),
|
||||||
("ョ".to_string(),"ョ".to_string()),
|
("ョ".to_string(), "ョ".to_string()),
|
||||||
("ヨ".to_string(),"ヨ".to_string()),
|
("ヨ".to_string(), "ヨ".to_string()),
|
||||||
("ラ".to_string(),"ラ".to_string()),
|
("ラ".to_string(), "ラ".to_string()),
|
||||||
("リ".to_string(),"リ".to_string()),
|
("リ".to_string(), "リ".to_string()),
|
||||||
("ル".to_string(),"ル".to_string()),
|
("ル".to_string(), "ル".to_string()),
|
||||||
("レ".to_string(),"レ".to_string()),
|
("レ".to_string(), "レ".to_string()),
|
||||||
("ロ".to_string(),"ロ".to_string()),
|
("ロ".to_string(), "ロ".to_string()),
|
||||||
("ワ".to_string(),"ワ".to_string()),
|
("ワ".to_string(), "ワ".to_string()),
|
||||||
("ヲ".to_string(),"ヲ".to_string()),
|
("ヲ".to_string(), "ヲ".to_string()),
|
||||||
("ン".to_string(),"ン".to_string()),
|
("ン".to_string(), "ン".to_string()),
|
||||||
("ー".to_string(),"-".to_string()),
|
("ー".to_string(), "-".to_string()),
|
||||||
("ヮ".to_string(),"ヮ".to_string()),
|
("ヮ".to_string(), "ヮ".to_string()),
|
||||||
("ヰ".to_string(),"ヰ".to_string()),
|
("ヰ".to_string(), "ヰ".to_string()),
|
||||||
("ヱ".to_string(),"ヱ".to_string()),
|
("ヱ".to_string(), "ヱ".to_string()),
|
||||||
("ヵ".to_string(),"ヵ".to_string()),
|
("ヵ".to_string(), "ヵ".to_string()),
|
||||||
("ヶ".to_string(),"ヶ".to_string()),
|
("ヶ".to_string(), "ヶ".to_string()),
|
||||||
("ヴ".to_string(),"ヴ".to_string()),
|
("ヴ".to_string(), "ヴ".to_string()),
|
||||||
("ヽ".to_string(),"ヽ".to_string()),
|
("ヽ".to_string(), "ヽ".to_string()),
|
||||||
("ヾ".to_string(),"ヾ".to_string()),
|
("ヾ".to_string(), "ヾ".to_string()),
|
||||||
("・".to_string(),"・".to_string()),
|
("・".to_string(), "・".to_string()),
|
||||||
("「".to_string(),"「".to_string()),
|
("「".to_string(), "「".to_string()),
|
||||||
("」".to_string(),"」".to_string()),
|
("」".to_string(), "」".to_string()),
|
||||||
("。".to_string(),"。".to_string()),
|
("。".to_string(), "。".to_string()),
|
||||||
("、".to_string(),"、".to_string()),
|
("、".to_string(), "、".to_string()),
|
||||||
("!".to_string(),"!".to_string()),
|
("!".to_string(), "!".to_string()),
|
||||||
(""".to_string(),"\"".to_string()),
|
(""".to_string(), "\"".to_string()),
|
||||||
("#".to_string(),"#".to_string()),
|
("#".to_string(), "#".to_string()),
|
||||||
("$".to_string(),"$".to_string()),
|
("$".to_string(), "$".to_string()),
|
||||||
("%".to_string(),"%".to_string()),
|
("%".to_string(), "%".to_string()),
|
||||||
("&".to_string(),"&".to_string()),
|
("&".to_string(), "&".to_string()),
|
||||||
("'".to_string(),"'".to_string()),
|
("'".to_string(), "'".to_string()),
|
||||||
("(".to_string(),"(".to_string()),
|
("(".to_string(), "(".to_string()),
|
||||||
(")".to_string(),")".to_string()),
|
(")".to_string(), ")".to_string()),
|
||||||
("*".to_string(),"*".to_string()),
|
("*".to_string(), "*".to_string()),
|
||||||
("+".to_string(),"+".to_string()),
|
("+".to_string(), "+".to_string()),
|
||||||
(",".to_string(),",".to_string()),
|
(",".to_string(), ",".to_string()),
|
||||||
(".".to_string(),".".to_string()),
|
(".".to_string(), ".".to_string()),
|
||||||
("/".to_string(),"/".to_string()),
|
("/".to_string(), "/".to_string()),
|
||||||
(":".to_string(),":".to_string()),
|
(":".to_string(), ":".to_string()),
|
||||||
(";".to_string(),";".to_string()),
|
(";".to_string(), ";".to_string()),
|
||||||
("<".to_string(),"<".to_string()),
|
("<".to_string(), "<".to_string()),
|
||||||
("=".to_string(),"=".to_string()),
|
("=".to_string(), "=".to_string()),
|
||||||
(">".to_string(),">".to_string()),
|
(">".to_string(), ">".to_string()),
|
||||||
("?".to_string(),"?".to_string()),
|
("?".to_string(), "?".to_string()),
|
||||||
("@".to_string(),"@".to_string()),
|
("@".to_string(), "@".to_string()),
|
||||||
("A".to_string(),"A".to_string()),
|
("A".to_string(), "A".to_string()),
|
||||||
("B".to_string(),"B".to_string()),
|
("B".to_string(), "B".to_string()),
|
||||||
("C".to_string(),"C".to_string()),
|
("C".to_string(), "C".to_string()),
|
||||||
("D".to_string(),"D".to_string()),
|
("D".to_string(), "D".to_string()),
|
||||||
("E".to_string(),"E".to_string()),
|
("E".to_string(), "E".to_string()),
|
||||||
("F".to_string(),"F".to_string()),
|
("F".to_string(), "F".to_string()),
|
||||||
("G".to_string(),"G".to_string()),
|
("G".to_string(), "G".to_string()),
|
||||||
("H".to_string(),"H".to_string()),
|
("H".to_string(), "H".to_string()),
|
||||||
("I".to_string(),"I".to_string()),
|
("I".to_string(), "I".to_string()),
|
||||||
("J".to_string(),"J".to_string()),
|
("J".to_string(), "J".to_string()),
|
||||||
("K".to_string(),"K".to_string()),
|
("K".to_string(), "K".to_string()),
|
||||||
("L".to_string(),"L".to_string()),
|
("L".to_string(), "L".to_string()),
|
||||||
("M".to_string(),"M".to_string()),
|
("M".to_string(), "M".to_string()),
|
||||||
("N".to_string(),"N".to_string()),
|
("N".to_string(), "N".to_string()),
|
||||||
("O".to_string(),"O".to_string()),
|
("O".to_string(), "O".to_string()),
|
||||||
("P".to_string(),"P".to_string()),
|
("P".to_string(), "P".to_string()),
|
||||||
("Q".to_string(),"Q".to_string()),
|
("Q".to_string(), "Q".to_string()),
|
||||||
("R".to_string(),"R".to_string()),
|
("R".to_string(), "R".to_string()),
|
||||||
("S".to_string(),"S".to_string()),
|
("S".to_string(), "S".to_string()),
|
||||||
("T".to_string(),"T".to_string()),
|
("T".to_string(), "T".to_string()),
|
||||||
("U".to_string(),"U".to_string()),
|
("U".to_string(), "U".to_string()),
|
||||||
("V".to_string(),"V".to_string()),
|
("V".to_string(), "V".to_string()),
|
||||||
("W".to_string(),"W".to_string()),
|
("W".to_string(), "W".to_string()),
|
||||||
("X".to_string(),"X".to_string()),
|
("X".to_string(), "X".to_string()),
|
||||||
("Y".to_string(),"Y".to_string()),
|
("Y".to_string(), "Y".to_string()),
|
||||||
("Z".to_string(),"Z".to_string()),
|
("Z".to_string(), "Z".to_string()),
|
||||||
("[".to_string(),"[".to_string()),
|
("[".to_string(), "[".to_string()),
|
||||||
("\".to_string(),"\\".to_string()),
|
("\".to_string(), "\\".to_string()),
|
||||||
("]".to_string(),"]".to_string()),
|
("]".to_string(), "]".to_string()),
|
||||||
("^".to_string(),"^".to_string()),
|
("^".to_string(), "^".to_string()),
|
||||||
("_".to_string(),"_".to_string()),
|
("_".to_string(), "_".to_string()),
|
||||||
("`".to_string(),"`".to_string()),
|
("`".to_string(), "`".to_string()),
|
||||||
("a".to_string(),"a".to_string()),
|
("a".to_string(), "a".to_string()),
|
||||||
("b".to_string(),"b".to_string()),
|
("b".to_string(), "b".to_string()),
|
||||||
("c".to_string(),"c".to_string()),
|
("c".to_string(), "c".to_string()),
|
||||||
("d".to_string(),"d".to_string()),
|
("d".to_string(), "d".to_string()),
|
||||||
("e".to_string(),"e".to_string()),
|
("e".to_string(), "e".to_string()),
|
||||||
("f".to_string(),"f".to_string()),
|
("f".to_string(), "f".to_string()),
|
||||||
("g".to_string(),"g".to_string()),
|
("g".to_string(), "g".to_string()),
|
||||||
("h".to_string(),"h".to_string()),
|
("h".to_string(), "h".to_string()),
|
||||||
("i".to_string(),"i".to_string()),
|
("i".to_string(), "i".to_string()),
|
||||||
("j".to_string(),"j".to_string()),
|
("j".to_string(), "j".to_string()),
|
||||||
("k".to_string(),"k".to_string()),
|
("k".to_string(), "k".to_string()),
|
||||||
("l".to_string(),"l".to_string()),
|
("l".to_string(), "l".to_string()),
|
||||||
("m".to_string(),"m".to_string()),
|
("m".to_string(), "m".to_string()),
|
||||||
("n".to_string(),"n".to_string()),
|
("n".to_string(), "n".to_string()),
|
||||||
("o".to_string(),"o".to_string()),
|
("o".to_string(), "o".to_string()),
|
||||||
("p".to_string(),"p".to_string()),
|
("p".to_string(), "p".to_string()),
|
||||||
("q".to_string(),"q".to_string()),
|
("q".to_string(), "q".to_string()),
|
||||||
("r".to_string(),"r".to_string()),
|
("r".to_string(), "r".to_string()),
|
||||||
("s".to_string(),"s".to_string()),
|
("s".to_string(), "s".to_string()),
|
||||||
("t".to_string(),"t".to_string()),
|
("t".to_string(), "t".to_string()),
|
||||||
("u".to_string(),"u".to_string()),
|
("u".to_string(), "u".to_string()),
|
||||||
("v".to_string(),"v".to_string()),
|
("v".to_string(), "v".to_string()),
|
||||||
("w".to_string(),"w".to_string()),
|
("w".to_string(), "w".to_string()),
|
||||||
("x".to_string(),"x".to_string()),
|
("x".to_string(), "x".to_string()),
|
||||||
("y".to_string(),"y".to_string()),
|
("y".to_string(), "y".to_string()),
|
||||||
("z".to_string(),"z".to_string()),
|
("z".to_string(), "z".to_string()),
|
||||||
("{".to_string(),"{".to_string()),
|
("{".to_string(), "{".to_string()),
|
||||||
("|".to_string(),"|".to_string()),
|
("|".to_string(), "|".to_string()),
|
||||||
("}".to_string(),"}".to_string()),
|
("}".to_string(), "}".to_string()),
|
||||||
("~".to_string(),"~".to_string()),
|
("~".to_string(), "~".to_string()),
|
||||||
(" ".to_string()," ".to_string()),
|
(" ".to_string(), " ".to_string()),
|
||||||
("0".to_string(),"0".to_string()),
|
("0".to_string(), "0".to_string()),
|
||||||
("1".to_string(),"1".to_string()),
|
("1".to_string(), "1".to_string()),
|
||||||
("2".to_string(),"2".to_string()),
|
("2".to_string(), "2".to_string()),
|
||||||
("3".to_string(),"3".to_string()),
|
("3".to_string(), "3".to_string()),
|
||||||
("4".to_string(),"4".to_string()),
|
("4".to_string(), "4".to_string()),
|
||||||
("5".to_string(),"5".to_string()),
|
("5".to_string(), "5".to_string()),
|
||||||
("6".to_string(),"6".to_string()),
|
("6".to_string(), "6".to_string()),
|
||||||
("7".to_string(),"7".to_string()),
|
("7".to_string(), "7".to_string()),
|
||||||
("8".to_string(),"8".to_string()),
|
("8".to_string(), "8".to_string()),
|
||||||
("9".to_string(),"9".to_string()),
|
("9".to_string(), "9".to_string()),
|
||||||
("ぁ".to_string(),"ァ".to_string()),
|
("ぁ".to_string(), "ァ".to_string()),
|
||||||
("あ".to_string(),"ア".to_string()),
|
("あ".to_string(), "ア".to_string()),
|
||||||
("ぃ".to_string(),"ィ".to_string()),
|
("ぃ".to_string(), "ィ".to_string()),
|
||||||
("い".to_string(),"イ".to_string()),
|
("い".to_string(), "イ".to_string()),
|
||||||
("ぅ".to_string(),"ゥ".to_string()),
|
("ぅ".to_string(), "ゥ".to_string()),
|
||||||
("う".to_string(),"ウ".to_string()),
|
("う".to_string(), "ウ".to_string()),
|
||||||
("ぇ".to_string(),"ェ".to_string()),
|
("ぇ".to_string(), "ェ".to_string()),
|
||||||
("え".to_string(),"エ".to_string()),
|
("え".to_string(), "エ".to_string()),
|
||||||
("ぉ".to_string(),"ォ".to_string()),
|
("ぉ".to_string(), "ォ".to_string()),
|
||||||
("お".to_string(),"オ".to_string()),
|
("お".to_string(), "オ".to_string()),
|
||||||
("か".to_string(),"カ".to_string()),
|
("か".to_string(), "カ".to_string()),
|
||||||
("が".to_string(),"ガ".to_string()),
|
("が".to_string(), "ガ".to_string()),
|
||||||
("き".to_string(),"キ".to_string()),
|
("き".to_string(), "キ".to_string()),
|
||||||
("ぎ".to_string(),"ギ".to_string()),
|
("ぎ".to_string(), "ギ".to_string()),
|
||||||
("く".to_string(),"ク".to_string()),
|
("く".to_string(), "ク".to_string()),
|
||||||
("ぐ".to_string(),"グ".to_string()),
|
("ぐ".to_string(), "グ".to_string()),
|
||||||
("け".to_string(),"ケ".to_string()),
|
("け".to_string(), "ケ".to_string()),
|
||||||
("げ".to_string(),"ゲ".to_string()),
|
("げ".to_string(), "ゲ".to_string()),
|
||||||
("こ".to_string(),"コ".to_string()),
|
("こ".to_string(), "コ".to_string()),
|
||||||
("ご".to_string(),"ゴ".to_string()),
|
("ご".to_string(), "ゴ".to_string()),
|
||||||
("さ".to_string(),"サ".to_string()),
|
("さ".to_string(), "サ".to_string()),
|
||||||
("ざ".to_string(),"ザ".to_string()),
|
("ざ".to_string(), "ザ".to_string()),
|
||||||
("し".to_string(),"シ".to_string()),
|
("し".to_string(), "シ".to_string()),
|
||||||
("じ".to_string(),"ジ".to_string()),
|
("じ".to_string(), "ジ".to_string()),
|
||||||
("す".to_string(),"ス".to_string()),
|
("す".to_string(), "ス".to_string()),
|
||||||
("ず".to_string(),"ズ".to_string()),
|
("ず".to_string(), "ズ".to_string()),
|
||||||
("せ".to_string(),"セ".to_string()),
|
("せ".to_string(), "セ".to_string()),
|
||||||
("ぜ".to_string(),"ゼ".to_string()),
|
("ぜ".to_string(), "ゼ".to_string()),
|
||||||
("そ".to_string(),"ソ".to_string()),
|
("そ".to_string(), "ソ".to_string()),
|
||||||
("ぞ".to_string(),"ゾ".to_string()),
|
("ぞ".to_string(), "ゾ".to_string()),
|
||||||
("た".to_string(),"タ".to_string()),
|
("た".to_string(), "タ".to_string()),
|
||||||
("だ".to_string(),"ダ".to_string()),
|
("だ".to_string(), "ダ".to_string()),
|
||||||
("ち".to_string(),"チ".to_string()),
|
("ち".to_string(), "チ".to_string()),
|
||||||
("ぢ".to_string(),"ヂ".to_string()),
|
("ぢ".to_string(), "ヂ".to_string()),
|
||||||
("っ".to_string(),"ッ".to_string()),
|
("っ".to_string(), "ッ".to_string()),
|
||||||
("つ".to_string(),"ツ".to_string()),
|
("つ".to_string(), "ツ".to_string()),
|
||||||
("づ".to_string(),"ヅ".to_string()),
|
("づ".to_string(), "ヅ".to_string()),
|
||||||
("て".to_string(),"テ".to_string()),
|
("て".to_string(), "テ".to_string()),
|
||||||
("で".to_string(),"デ".to_string()),
|
("で".to_string(), "デ".to_string()),
|
||||||
("と".to_string(),"ト".to_string()),
|
("と".to_string(), "ト".to_string()),
|
||||||
("ど".to_string(),"ド".to_string()),
|
("ど".to_string(), "ド".to_string()),
|
||||||
("な".to_string(),"ナ".to_string()),
|
("な".to_string(), "ナ".to_string()),
|
||||||
("に".to_string(),"ニ".to_string()),
|
("に".to_string(), "ニ".to_string()),
|
||||||
("ぬ".to_string(),"ヌ".to_string()),
|
("ぬ".to_string(), "ヌ".to_string()),
|
||||||
("ね".to_string(),"ネ".to_string()),
|
("ね".to_string(), "ネ".to_string()),
|
||||||
("の".to_string(),"ノ".to_string()),
|
("の".to_string(), "ノ".to_string()),
|
||||||
("は".to_string(),"ハ".to_string()),
|
("は".to_string(), "ハ".to_string()),
|
||||||
("ば".to_string(),"バ".to_string()),
|
("ば".to_string(), "バ".to_string()),
|
||||||
("ぱ".to_string(),"パ".to_string()),
|
("ぱ".to_string(), "パ".to_string()),
|
||||||
("ひ".to_string(),"ヒ".to_string()),
|
("ひ".to_string(), "ヒ".to_string()),
|
||||||
("び".to_string(),"ビ".to_string()),
|
("び".to_string(), "ビ".to_string()),
|
||||||
("ぴ".to_string(),"ピ".to_string()),
|
("ぴ".to_string(), "ピ".to_string()),
|
||||||
("ふ".to_string(),"フ".to_string()),
|
("ふ".to_string(), "フ".to_string()),
|
||||||
("ぶ".to_string(),"ブ".to_string()),
|
("ぶ".to_string(), "ブ".to_string()),
|
||||||
("ぷ".to_string(),"プ".to_string()),
|
("ぷ".to_string(), "プ".to_string()),
|
||||||
("へ".to_string(),"ヘ".to_string()),
|
("へ".to_string(), "ヘ".to_string()),
|
||||||
("べ".to_string(),"ベ".to_string()),
|
("べ".to_string(), "ベ".to_string()),
|
||||||
("ぺ".to_string(),"ペ".to_string()),
|
("ぺ".to_string(), "ペ".to_string()),
|
||||||
("ほ".to_string(),"ホ".to_string()),
|
("ほ".to_string(), "ホ".to_string()),
|
||||||
("ぼ".to_string(),"ボ".to_string()),
|
("ぼ".to_string(), "ボ".to_string()),
|
||||||
("ぽ".to_string(),"ポ".to_string()),
|
("ぽ".to_string(), "ポ".to_string()),
|
||||||
("ま".to_string(),"マ".to_string()),
|
("ま".to_string(), "マ".to_string()),
|
||||||
("み".to_string(),"ミ".to_string()),
|
("み".to_string(), "ミ".to_string()),
|
||||||
("む".to_string(),"ム".to_string()),
|
("む".to_string(), "ム".to_string()),
|
||||||
("め".to_string(),"メ".to_string()),
|
("め".to_string(), "メ".to_string()),
|
||||||
("も".to_string(),"モ".to_string()),
|
("も".to_string(), "モ".to_string()),
|
||||||
("ゃ".to_string(),"ャ".to_string()),
|
("ゃ".to_string(), "ャ".to_string()),
|
||||||
("や".to_string(),"ヤ".to_string()),
|
("や".to_string(), "ヤ".to_string()),
|
||||||
("ゅ".to_string(),"ュ".to_string()),
|
("ゅ".to_string(), "ュ".to_string()),
|
||||||
("ゆ".to_string(),"ユ".to_string()),
|
("ゆ".to_string(), "ユ".to_string()),
|
||||||
("ょ".to_string(),"ョ".to_string()),
|
("ょ".to_string(), "ョ".to_string()),
|
||||||
("よ".to_string(),"ヨ".to_string()),
|
("よ".to_string(), "ヨ".to_string()),
|
||||||
("ら".to_string(),"ラ".to_string()),
|
("ら".to_string(), "ラ".to_string()),
|
||||||
("り".to_string(),"リ".to_string()),
|
("り".to_string(), "リ".to_string()),
|
||||||
("る".to_string(),"ル".to_string()),
|
("る".to_string(), "ル".to_string()),
|
||||||
("れ".to_string(),"レ".to_string()),
|
("れ".to_string(), "レ".to_string()),
|
||||||
("ろ".to_string(),"ロ".to_string()),
|
("ろ".to_string(), "ロ".to_string()),
|
||||||
("わ".to_string(),"ワ".to_string()),
|
("わ".to_string(), "ワ".to_string()),
|
||||||
("を".to_string(),"ヲ".to_string()),
|
("を".to_string(), "ヲ".to_string()),
|
||||||
("ん".to_string(),"ン".to_string()),
|
("ん".to_string(), "ン".to_string()),
|
||||||
("ゎ".to_string(),"ヮ".to_string()),
|
("ゎ".to_string(), "ヮ".to_string()),
|
||||||
("ゐ".to_string(),"ヰ".to_string()),
|
("ゐ".to_string(), "ヰ".to_string()),
|
||||||
("ゑ".to_string(),"ヱ".to_string()),
|
("ゑ".to_string(), "ヱ".to_string()),
|
||||||
("ゕ".to_string(),"ヵ".to_string()),
|
("ゕ".to_string(), "ヵ".to_string()),
|
||||||
("ゖ".to_string(),"ヶ".to_string()),
|
("ゖ".to_string(), "ヶ".to_string()),
|
||||||
("ゔ".to_string(),"ヴ".to_string()),
|
("ゔ".to_string(), "ヴ".to_string()),
|
||||||
("ゝ".to_string(),"ヽ".to_string()),
|
("ゝ".to_string(), "ヽ".to_string()),
|
||||||
("ゞ".to_string(),"ヾ".to_string()),
|
("ゞ".to_string(), "ヾ".to_string()),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
pub static ref ALLOWED_HW_KANA: Vec<String> = MAPPINGS_HW.values().cloned().collect();
|
pub static ref ALLOWED_HW_KANA: Vec<String> = MAPPINGS_HW.values().cloned().collect();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
mod base;
|
mod base;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
|
mod mappings;
|
||||||
mod query_utils;
|
mod query_utils;
|
||||||
mod utils;
|
mod utils;
|
||||||
mod mappings;
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use lazy_static::lazy_static;
|
||||||
use std::collections::hash_map::HashMap;
|
use std::collections::hash_map::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
lazy_static!{
|
lazy_static! {
|
||||||
/// %b, w, d, q - explained above (can have endiannes overriden by '>' and '<' operators, f. ex. %>d %<q)
|
/// %b, w, d, q - explained above (can have endiannes overriden by '>' and '<' operators, f. ex. %>d %<q)
|
||||||
/// %s - Uint8Array preceded by 2 bytes of length
|
/// %s - Uint8Array preceded by 2 bytes of length
|
||||||
/// %x - Uint8Array preceded by 2 bytes of length
|
/// %x - Uint8Array preceded by 2 bytes of length
|
||||||
|
@ -44,10 +44,7 @@ impl QueryValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formats a query using a standard input to send to the player
|
/// Formats a query using a standard input to send to the player
|
||||||
pub fn format_query(
|
pub fn format_query(format: String, args: Vec<QueryValue>) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||||
format: String,
|
|
||||||
args: Vec<QueryValue>,
|
|
||||||
) -> Result<Vec<u8>, Box<dyn Error>> {
|
|
||||||
if DEBUG {
|
if DEBUG {
|
||||||
println!("SENT>>> F: {}", format);
|
println!("SENT>>> F: {}", format);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,9 +59,7 @@ pub fn half_width_to_full_width_range(range: &str) -> String {
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_bytes<const S: usize>(
|
pub fn get_bytes<const S: usize>(iterator: &mut IntoIter<u8>) -> Result<[u8; S], Box<dyn Error>> {
|
||||||
iterator: &mut IntoIter<u8>,
|
|
||||||
) -> Result<[u8; S], Box<dyn Error>> {
|
|
||||||
let byte_vec: Vec<u8> = iterator.take(S).collect();
|
let byte_vec: Vec<u8> = iterator.take(S).collect();
|
||||||
let bytes: [u8; S] = byte_vec.try_into().unwrap();
|
let bytes: [u8; S] = byte_vec.try_into().unwrap();
|
||||||
|
|
||||||
|
@ -170,5 +168,7 @@ pub fn agressive_sanitize_title(title: &str) -> String {
|
||||||
|
|
||||||
pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration {
|
pub fn time_to_duration(time: &Vec<u64>) -> std::time::Duration {
|
||||||
assert_eq!(time.len(), 4);
|
assert_eq!(time.len(), 4);
|
||||||
std::time::Duration::from_micros((time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600))
|
std::time::Duration::from_micros(
|
||||||
|
(time[0] * 3600000000) + (time[1] * 60000000) + (time[2] * 1000000) + (time[3] * 11600),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -1,14 +1,15 @@
|
||||||
use minidisc_rs::netmd::interface;
|
use minidisc_rs::netmd::interface;
|
||||||
use nusb;
|
use nusb;
|
||||||
|
|
||||||
fn main() {
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
let devices = nusb::list_devices().unwrap();
|
let devices = nusb::list_devices().unwrap();
|
||||||
|
|
||||||
for device in devices {
|
for device in devices {
|
||||||
// Ensure the player is a minidisc player and not some other random device
|
// Ensure the player is a minidisc player and not some other random device
|
||||||
let mut player_controller = match interface::NetMDInterface::new(&device) {
|
let mut player_controller = match interface::NetMDInterface::new(&device).await {
|
||||||
Ok(player) => player,
|
Ok(player) => player,
|
||||||
Err(_) => continue,
|
Err(err) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
@ -22,22 +23,25 @@ fn main() {
|
||||||
player_controller
|
player_controller
|
||||||
.net_md_device
|
.net_md_device
|
||||||
.device_name()
|
.device_name()
|
||||||
|
.await
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
let now = std::time::Instant::now();
|
let now = std::time::Instant::now();
|
||||||
|
let half_title = player_controller.disc_title(false).await.unwrap_or("".to_string());
|
||||||
|
let full_title = player_controller.disc_title(true).await.unwrap_or("".to_string());
|
||||||
println!(
|
println!(
|
||||||
"Disc Title: {} | {}",
|
"Disc Title: {} | {}",
|
||||||
player_controller
|
half_title,
|
||||||
.disc_title(false)
|
full_title
|
||||||
.unwrap_or("".to_string()),
|
|
||||||
player_controller.disc_title(true).unwrap_or("".to_string())
|
|
||||||
);
|
);
|
||||||
let track_count = player_controller.track_count().unwrap();
|
|
||||||
let track_titles = player_controller.track_titles((0..track_count).collect(), false).unwrap();
|
let track_count = player_controller.track_count().await.unwrap();
|
||||||
let track_titlesw = player_controller.track_titles((0..track_count).collect(), true).unwrap();
|
println!("{}", track_count);
|
||||||
let track_lengths = player_controller.track_lengths((0..track_count).collect()).unwrap();
|
let track_titles = player_controller.track_titles((0..track_count).collect(), false).await.unwrap();
|
||||||
|
let track_titlesw = player_controller.track_titles((0..track_count).collect(), true).await.unwrap();
|
||||||
|
let track_lengths = player_controller.track_lengths((0..track_count).collect()).await.unwrap();
|
||||||
for (i, track) in track_titles.iter().enumerate() {
|
for (i, track) in track_titles.iter().enumerate() {
|
||||||
println!(
|
println!(
|
||||||
"Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
|
"Track {i} Info:\n Title: {track} | {}\n Length: {:?}",
|
||||||
|
|
Loading…
Reference in a new issue