chore: fix import ordering and formatting in core and client
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use pipeview_core::frame::{
|
use pipeview_core::frame::{
|
||||||
Endian, Framer,
|
Endian, Framer,
|
||||||
cobs::CobsFramer,
|
cobs::CobsFramer,
|
||||||
@@ -15,6 +14,7 @@ use pipeview_core::protocol::{
|
|||||||
text::{TextDecoder, TextEncoding},
|
text::{TextDecoder, TextEncoding},
|
||||||
};
|
};
|
||||||
use pipeview_core::transport::TransportConfig;
|
use pipeview_core::transport::TransportConfig;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Result;
|
use crate::error::Result;
|
||||||
use crate::lua::codec::{LuaDecoder, LuaFramer};
|
use crate::lua::codec::{LuaDecoder, LuaFramer};
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ use std::fs;
|
|||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use mlua::{Function, Lua, RegistryKey, Table, Value};
|
use mlua::{Function, Lua, RegistryKey, Table, Value};
|
||||||
use tracing::warn;
|
|
||||||
use pipeview_core::frame::Framer;
|
use pipeview_core::frame::Framer;
|
||||||
use pipeview_core::protocol::plot::{PlotFormat, PlotFrame, SampleType};
|
use pipeview_core::protocol::plot::{PlotFormat, PlotFrame, SampleType};
|
||||||
use pipeview_core::protocol::{DecodedData, ProtocolDecoder};
|
use pipeview_core::protocol::{DecodedData, ProtocolDecoder};
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ use std::sync::{
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use mlua::{Function, Lua, LuaSerdeExt, RegistryKey, UserData, UserDataMethods, Value, Variadic};
|
use mlua::{Function, Lua, LuaSerdeExt, RegistryKey, UserData, UserDataMethods, Value, Variadic};
|
||||||
|
use pipeview_core::protocol::DecodedData;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use pipeview_core::protocol::DecodedData;
|
|
||||||
|
|
||||||
use crate::config::SessionConfig;
|
use crate::config::SessionConfig;
|
||||||
use crate::lua::LuaRuntime;
|
use crate::lua::LuaRuntime;
|
||||||
|
|||||||
@@ -173,22 +173,18 @@ impl Connection {
|
|||||||
pub fn set_dtr(&mut self, state: bool) -> Result<()> {
|
pub fn set_dtr(&mut self, state: bool) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Connection::Serial(t) => t.set_dtr(state),
|
Connection::Serial(t) => t.set_dtr(state),
|
||||||
Connection::Tcp(_) | Connection::Udp(_) => {
|
Connection::Tcp(_) | Connection::Udp(_) => Err(crate::error::Error::ConnectionFailed(
|
||||||
Err(crate::error::Error::ConnectionFailed(
|
"DTR only supported on Serial connections".into(),
|
||||||
"DTR only supported on Serial connections".into(),
|
)),
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_rts(&mut self, state: bool) -> Result<()> {
|
pub fn set_rts(&mut self, state: bool) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Connection::Serial(t) => t.set_rts(state),
|
Connection::Serial(t) => t.set_rts(state),
|
||||||
Connection::Tcp(_) | Connection::Udp(_) => {
|
Connection::Tcp(_) | Connection::Udp(_) => Err(crate::error::Error::ConnectionFailed(
|
||||||
Err(crate::error::Error::ConnectionFailed(
|
"RTS only supported on Serial connections".into(),
|
||||||
"RTS only supported on Serial connections".into(),
|
)),
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use serialport::SerialPort;
|
||||||
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
|
||||||
use tokio_serial::{DataBits, FlowControl, Parity, SerialPortBuilderExt, SerialStream, StopBits};
|
use tokio_serial::{DataBits, FlowControl, Parity, SerialPortBuilderExt, SerialStream, StopBits};
|
||||||
use serialport::SerialPort;
|
|
||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
use super::{Transport, TransportType};
|
use super::{Transport, TransportType};
|
||||||
@@ -277,10 +277,16 @@ impl Transport for SerialTransport {
|
|||||||
// HC-15, HC-05, Bluetooth/UART bridges) need DTR asserted to stay in
|
// HC-15, HC-05, Bluetooth/UART bridges) need DTR asserted to stay in
|
||||||
// transparent data mode and not fall into AT-command / reset state.
|
// transparent data mode and not fall into AT-command / reset state.
|
||||||
if let Err(e) = port.write_data_terminal_ready(self.dtr) {
|
if let Err(e) = port.write_data_terminal_ready(self.dtr) {
|
||||||
warn!("Failed to set DTR({}) on {}: {}", self.dtr, self.port_name, e);
|
warn!(
|
||||||
|
"Failed to set DTR({}) on {}: {}",
|
||||||
|
self.dtr, self.port_name, e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if let Err(e) = port.write_request_to_send(self.rts) {
|
if let Err(e) = port.write_request_to_send(self.rts) {
|
||||||
warn!("Failed to set RTS({}) on {}: {}", self.rts, self.port_name, e);
|
warn!(
|
||||||
|
"Failed to set RTS({}) on {}: {}",
|
||||||
|
self.rts, self.port_name, e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Serial port {} opened successfully", self.port_name);
|
debug!("Serial port {} opened successfully", self.port_name);
|
||||||
@@ -331,8 +337,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.port_name(), "COM1");
|
assert_eq!(transport.port_name(), "COM1");
|
||||||
assert_eq!(transport.baud_rate(), 115200);
|
assert_eq!(transport.baud_rate(), 115200);
|
||||||
@@ -347,8 +353,8 @@ mod tests {
|
|||||||
SerialParity::Even,
|
SerialParity::Even,
|
||||||
SerialStopBits::Two,
|
SerialStopBits::Two,
|
||||||
SerialFlowControl::Hardware,
|
SerialFlowControl::Hardware,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.port_name(), "COM3");
|
assert_eq!(transport.port_name(), "COM3");
|
||||||
assert_eq!(transport.baud_rate(), 9600);
|
assert_eq!(transport.baud_rate(), 9600);
|
||||||
@@ -367,8 +373,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.name(), "COM1");
|
assert_eq!(transport.name(), "COM1");
|
||||||
}
|
}
|
||||||
@@ -382,8 +388,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.transport_type(), TransportType::Serial);
|
assert_eq!(transport.transport_type(), TransportType::Serial);
|
||||||
}
|
}
|
||||||
@@ -397,8 +403,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert!(!transport.is_connected());
|
assert!(!transport.is_connected());
|
||||||
}
|
}
|
||||||
@@ -427,8 +433,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let pinned = Pin::new(&mut transport);
|
let pinned = Pin::new(&mut transport);
|
||||||
let mut buf_data = [0u8; 16];
|
let mut buf_data = [0u8; 16];
|
||||||
@@ -452,8 +458,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let pinned = Pin::new(&mut transport);
|
let pinned = Pin::new(&mut transport);
|
||||||
let data = b"hello";
|
let data = b"hello";
|
||||||
@@ -474,8 +480,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let pinned = Pin::new(&mut transport);
|
let pinned = Pin::new(&mut transport);
|
||||||
let waker = noop_waker();
|
let waker = noop_waker();
|
||||||
@@ -495,8 +501,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
let pinned = Pin::new(&mut transport);
|
let pinned = Pin::new(&mut transport);
|
||||||
let waker = noop_waker();
|
let waker = noop_waker();
|
||||||
@@ -518,8 +524,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.name(), "COM1");
|
assert_eq!(transport.name(), "COM1");
|
||||||
}
|
}
|
||||||
@@ -533,8 +539,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert_eq!(transport.transport_type(), TransportType::Serial);
|
assert_eq!(transport.transport_type(), TransportType::Serial);
|
||||||
}
|
}
|
||||||
@@ -548,8 +554,8 @@ mod tests {
|
|||||||
SerialParity::None,
|
SerialParity::None,
|
||||||
SerialStopBits::One,
|
SerialStopBits::One,
|
||||||
SerialFlowControl::None,
|
SerialFlowControl::None,
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
assert!(!transport.is_connected());
|
assert!(!transport.is_connected());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -688,8 +688,8 @@ async fn connection_transport_type_dispatch() {
|
|||||||
parity: SerialParity::None,
|
parity: SerialParity::None,
|
||||||
stop_bits: SerialStopBits::One,
|
stop_bits: SerialStopBits::One,
|
||||||
flow_control: SerialFlowControl::None,
|
flow_control: SerialFlowControl::None,
|
||||||
dtr: false,
|
dtr: false,
|
||||||
rts: false,
|
rts: false,
|
||||||
});
|
});
|
||||||
let tcp = Connection::new(TransportConfig::Tcp {
|
let tcp = Connection::new(TransportConfig::Tcp {
|
||||||
addr: "127.0.0.1:8080".into(),
|
addr: "127.0.0.1:8080".into(),
|
||||||
|
|||||||
Reference in New Issue
Block a user