forked from M-Labs/artiq
firmware: migrate moninj_proto to new libio.
This commit is contained in:
parent
e292c8ab65
commit
e9c88e32e6
@ -45,7 +45,7 @@ pub enum Packet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Packet {
|
impl Packet {
|
||||||
pub fn read_from<T: Read>(reader: &mut T) -> Result<Packet, T::ReadError> {
|
pub fn read_from<T: Read>(reader: &mut T) -> Result<Self, T::ReadError> {
|
||||||
Ok(match reader.read_u8()? {
|
Ok(match reader.read_u8()? {
|
||||||
0x00 => Packet::EchoRequest,
|
0x00 => Packet::EchoRequest,
|
||||||
0x01 => Packet::EchoReply,
|
0x01 => Packet::EchoReply,
|
||||||
|
@ -41,7 +41,7 @@ pub enum Reply<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
pub fn read_from<T: Read>(reader: &mut T) -> Result<Request, T::ReadError> {
|
pub fn read_from<T: Read>(reader: &mut T) -> Result<Self, T::ReadError> {
|
||||||
#[cfg(feature = "log")]
|
#[cfg(feature = "log")]
|
||||||
fn read_log_level_filter<T: Read>(reader: &mut T) ->
|
fn read_log_level_filter<T: Read>(reader: &mut T) ->
|
||||||
Result<log::LevelFilter, T::ReadError> {
|
Result<log::LevelFilter, T::ReadError> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::io::{self, Read, Write};
|
use io::{Read, Write, Error, Result};
|
||||||
use {ReadExt, WriteExt};
|
use io::proto::{ProtoRead, ProtoWrite};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum HostMessage {
|
pub enum HostMessage {
|
||||||
@ -15,7 +15,7 @@ pub enum DeviceMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HostMessage {
|
impl HostMessage {
|
||||||
pub fn read_from(reader: &mut Read) -> io::Result<HostMessage> {
|
pub fn read_from<T: Read>(reader: &mut T) -> Result<Self, T::ReadError> {
|
||||||
Ok(match reader.read_u8()? {
|
Ok(match reader.read_u8()? {
|
||||||
0 => HostMessage::Monitor {
|
0 => HostMessage::Monitor {
|
||||||
enable: if reader.read_u8()? == 0 { false } else { true },
|
enable: if reader.read_u8()? == 0 { false } else { true },
|
||||||
@ -31,13 +31,13 @@ impl HostMessage {
|
|||||||
channel: reader.read_u32()?,
|
channel: reader.read_u32()?,
|
||||||
overrd: reader.read_u8()?
|
overrd: reader.read_u8()?
|
||||||
},
|
},
|
||||||
_ => return Err(io::Error::new(io::ErrorKind::InvalidData, "unknown packet type"))
|
_ => return Err(Error::Unrecognized)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeviceMessage {
|
impl DeviceMessage {
|
||||||
pub fn write_to(&self, writer: &mut Write) -> io::Result<()> {
|
pub fn write_to<T: Write>(&self, writer: &mut T) -> Result<(), T::WriteError> {
|
||||||
match *self {
|
match *self {
|
||||||
DeviceMessage::MonitorStatus { channel, probe, value } => {
|
DeviceMessage::MonitorStatus { channel, probe, value } => {
|
||||||
writer.write_u8(0)?;
|
writer.write_u8(0)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user