forked from M-Labs/nac3
runtime: modified protocols to use device endian
This commit is contained in:
parent
be01fbd943
commit
faa335461d
|
@ -50,6 +50,7 @@ struct Header {
|
|||
}
|
||||
|
||||
async fn write_header(stream: &mut TcpStream, header: &Header) -> Result<(), Error> {
|
||||
stream.send_slice("e".as_bytes()).await?;
|
||||
write_i32(stream, header.sent_bytes as i32).await?;
|
||||
write_i64(stream, header.total_byte_count as i64).await?;
|
||||
write_i8(stream, header.error_occurred as i8).await?;
|
||||
|
|
|
@ -317,6 +317,7 @@ async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Contr
|
|||
if !expect(stream, b"ARTIQ coredev\n").await? {
|
||||
return Err(Error::UnexpectedPattern);
|
||||
}
|
||||
stream.send_slice("e".as_bytes()).await?;
|
||||
loop {
|
||||
let request = read_request(stream, true).await?;
|
||||
if request.is_none() {
|
||||
|
|
|
@ -117,6 +117,7 @@ async fn handle_connection(
|
|||
if !expect(&stream, b"ARTIQ management\n").await? {
|
||||
return Err(Error::UnexpectedPattern);
|
||||
}
|
||||
stream.send_slice("e".as_bytes()).await?;
|
||||
|
||||
loop {
|
||||
let msg = read_i8(stream).await;
|
||||
|
|
|
@ -83,6 +83,7 @@ async fn handle_connection(stream: &TcpStream, timer: GlobalTimer) -> Result<()>
|
|||
if !expect(&stream, b"ARTIQ moninj\n").await? {
|
||||
return Err(Error::UnexpectedPattern);
|
||||
}
|
||||
stream.send_slice("e".as_bytes()).await?;
|
||||
|
||||
let mut probe_watch_list: BTreeMap<(i32, i8), Option<i32>> = BTreeMap::new();
|
||||
let mut inject_watch_list: BTreeMap<(i32, i8), Option<i8>> = BTreeMap::new();
|
||||
|
|
|
@ -54,13 +54,13 @@ pub async fn read_i8(stream: &TcpStream) -> Result<i8> {
|
|||
pub async fn read_i32(stream: &TcpStream) -> Result<i32> {
|
||||
let mut buffer: [u8; 4] = [0; 4];
|
||||
read_chunk(stream, &mut buffer).await?;
|
||||
Ok(i32::from_be_bytes(buffer))
|
||||
Ok(i32::from_le_bytes(buffer))
|
||||
}
|
||||
|
||||
pub async fn read_i64(stream: &TcpStream) -> Result<i64> {
|
||||
let mut buffer: [u8; 8] = [0; 8];
|
||||
read_chunk(stream, &mut buffer).await?;
|
||||
Ok(i64::from_be_bytes(buffer))
|
||||
Ok(i64::from_le_bytes(buffer))
|
||||
}
|
||||
|
||||
pub async fn read_chunk(stream: &TcpStream, destination: &mut [u8]) -> Result<()> {
|
||||
|
@ -90,12 +90,12 @@ pub async fn write_bool(stream: &TcpStream, value: bool) -> Result<()> {
|
|||
}
|
||||
|
||||
pub async fn write_i32(stream: &TcpStream, value: i32) -> Result<()> {
|
||||
stream.send_slice(&value.to_be_bytes()).await?;
|
||||
stream.send_slice(&value.to_le_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write_i64(stream: &TcpStream, value: i64) -> Result<()> {
|
||||
stream.send_slice(&value.to_be_bytes()).await?;
|
||||
stream.send_slice(&value.to_le_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use core::str::Utf8Error;
|
||||
use byteorder::{ByteOrder, NetworkEndian};
|
||||
use byteorder::{ByteOrder, NativeEndian};
|
||||
use alloc::vec;
|
||||
use alloc::string::String;
|
||||
|
||||
|
@ -28,21 +28,21 @@ pub trait ProtoRead {
|
|||
fn read_u16(&mut self) -> Result<u16, Self::ReadError> {
|
||||
let mut bytes = [0; 2];
|
||||
self.read_exact(&mut bytes)?;
|
||||
Ok(NetworkEndian::read_u16(&bytes))
|
||||
Ok(NativeEndian::read_u16(&bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_u32(&mut self) -> Result<u32, Self::ReadError> {
|
||||
let mut bytes = [0; 4];
|
||||
self.read_exact(&mut bytes)?;
|
||||
Ok(NetworkEndian::read_u32(&bytes))
|
||||
Ok(NativeEndian::read_u32(&bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_u64(&mut self) -> Result<u64, Self::ReadError> {
|
||||
let mut bytes = [0; 8];
|
||||
self.read_exact(&mut bytes)?;
|
||||
Ok(NetworkEndian::read_u64(&bytes))
|
||||
Ok(NativeEndian::read_u64(&bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -85,42 +85,42 @@ pub trait ProtoWrite {
|
|||
#[inline]
|
||||
fn write_u16(&mut self, value: u16) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 2];
|
||||
NetworkEndian::write_u16(&mut bytes, value);
|
||||
NativeEndian::write_u16(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_i16(&mut self, value: i16) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 2];
|
||||
NetworkEndian::write_i16(&mut bytes, value);
|
||||
NativeEndian::write_i16(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_u32(&mut self, value: u32) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 4];
|
||||
NetworkEndian::write_u32(&mut bytes, value);
|
||||
NativeEndian::write_u32(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_i32(&mut self, value: i32) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 4];
|
||||
NetworkEndian::write_i32(&mut bytes, value);
|
||||
NativeEndian::write_i32(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_u64(&mut self, value: u64) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 8];
|
||||
NetworkEndian::write_u64(&mut bytes, value);
|
||||
NativeEndian::write_u64(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn write_i64(&mut self, value: i64) -> Result<(), Self::WriteError> {
|
||||
let mut bytes = [0; 8];
|
||||
NetworkEndian::write_i64(&mut bytes, value);
|
||||
NativeEndian::write_i64(&mut bytes, value);
|
||||
self.write_all(&bytes)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use core::str;
|
|||
use core::future::Future;
|
||||
use cslice::{CSlice, CMutSlice};
|
||||
use log::trace;
|
||||
use byteorder::{NetworkEndian, ByteOrder};
|
||||
use byteorder::{NativeEndian, ByteOrder};
|
||||
|
||||
use core_io::{Write, Error};
|
||||
use libboard_zynq::smoltcp;
|
||||
|
@ -96,7 +96,7 @@ async unsafe fn recv_value<F>(stream: &TcpStream, tag: Tag<'async_recursion>, da
|
|||
proto_async::read_chunk(stream, dest).await?;
|
||||
drop(dest);
|
||||
let dest = core::slice::from_raw_parts_mut(ptr, length);
|
||||
NetworkEndian::from_slice_u32(dest);
|
||||
NativeEndian::from_slice_u32(dest);
|
||||
},
|
||||
Tag::Int64 | Tag::Float64 => {
|
||||
let ptr = align_ptr_mut::<u64>(data);
|
||||
|
@ -104,7 +104,7 @@ async unsafe fn recv_value<F>(stream: &TcpStream, tag: Tag<'async_recursion>, da
|
|||
proto_async::read_chunk(stream, dest).await?;
|
||||
drop(dest);
|
||||
let dest = core::slice::from_raw_parts_mut(ptr, length);
|
||||
NetworkEndian::from_slice_u64(dest);
|
||||
NativeEndian::from_slice_u64(dest);
|
||||
},
|
||||
_ => {
|
||||
for _ in 0..(*ptr).length as usize {
|
||||
|
@ -141,7 +141,7 @@ async unsafe fn recv_value<F>(stream: &TcpStream, tag: Tag<'async_recursion>, da
|
|||
proto_async::read_chunk(stream, dest).await?;
|
||||
drop(dest);
|
||||
let dest = core::slice::from_raw_parts_mut(ptr, length);
|
||||
NetworkEndian::from_slice_u32(dest);
|
||||
NativeEndian::from_slice_u32(dest);
|
||||
},
|
||||
Tag::Int64 | Tag::Float64 => {
|
||||
let ptr = align_ptr_mut::<u64>(data);
|
||||
|
@ -149,7 +149,7 @@ async unsafe fn recv_value<F>(stream: &TcpStream, tag: Tag<'async_recursion>, da
|
|||
proto_async::read_chunk(stream, dest).await?;
|
||||
drop(dest);
|
||||
let dest = core::slice::from_raw_parts_mut(ptr, length);
|
||||
NetworkEndian::from_slice_u64(dest);
|
||||
NativeEndian::from_slice_u64(dest);
|
||||
},
|
||||
_ => {
|
||||
for _ in 0..length {
|
||||
|
@ -244,25 +244,13 @@ unsafe fn send_value<W>(writer: &mut W, tag: Tag, data: &mut *const ())
|
|||
},
|
||||
Tag::Int32 => {
|
||||
let ptr1 = align_ptr::<i32>(data);
|
||||
let slice = core::slice::from_raw_parts(ptr1, length as usize);
|
||||
let mut v: alloc::vec::Vec<i32> = slice.to_vec();
|
||||
NetworkEndian::from_slice_i32(&mut v);
|
||||
let slice2 = core::slice::from_raw_parts(
|
||||
v.as_ptr() as usize as *const u8,
|
||||
length as usize * 4
|
||||
);
|
||||
writer.write_all(slice2)?;
|
||||
let slice = core::slice::from_raw_parts(ptr1 as *const u8, length as usize * 4);
|
||||
writer.write_all(slice)?;
|
||||
},
|
||||
Tag::Int64 | Tag::Float64 => {
|
||||
let ptr1 = align_ptr::<i64>(data);
|
||||
let slice = core::slice::from_raw_parts(ptr1, length as usize);
|
||||
let mut v: alloc::vec::Vec<i64> = slice.to_vec();
|
||||
NetworkEndian::from_slice_i64(&mut v);
|
||||
let slice2 = core::slice::from_raw_parts(
|
||||
v.as_ptr() as usize as *const u8,
|
||||
length as usize * 8
|
||||
);
|
||||
writer.write_all(slice2)?;
|
||||
let slice = core::slice::from_raw_parts(ptr1 as *const u8, length as usize * 8);
|
||||
writer.write_all(slice)?;
|
||||
},
|
||||
// non-primitive types, not sure if this would happen but we can handle it...
|
||||
_ => {
|
||||
|
@ -297,25 +285,13 @@ unsafe fn send_value<W>(writer: &mut W, tag: Tag, data: &mut *const ())
|
|||
},
|
||||
Tag::Int32 => {
|
||||
let ptr1 = align_ptr::<i32>(data);
|
||||
let slice = core::slice::from_raw_parts(ptr1, length as usize);
|
||||
let mut v: alloc::vec::Vec<i32> = slice.to_vec();
|
||||
NetworkEndian::from_slice_i32(&mut v);
|
||||
let slice2 = core::slice::from_raw_parts(
|
||||
v.as_ptr() as usize as *const u8,
|
||||
length as usize * 4
|
||||
);
|
||||
writer.write_all(slice2)?;
|
||||
let slice = core::slice::from_raw_parts(ptr1 as *const u8, length as usize * 4);
|
||||
writer.write_all(slice)?;
|
||||
},
|
||||
Tag::Int64 | Tag::Float64 => {
|
||||
let ptr1 = align_ptr::<i64>(data);
|
||||
let slice = core::slice::from_raw_parts(ptr1, length as usize);
|
||||
let mut v: alloc::vec::Vec<i64> = slice.to_vec();
|
||||
NetworkEndian::from_slice_i64(&mut v);
|
||||
let slice2 = core::slice::from_raw_parts(
|
||||
v.as_ptr() as usize as *const u8,
|
||||
length as usize * 8
|
||||
);
|
||||
writer.write_all(slice2)?;
|
||||
let slice = core::slice::from_raw_parts(ptr1 as *const u8, length as usize * 8);
|
||||
writer.write_all(slice)?;
|
||||
},
|
||||
// non-primitive types, not sure if this would happen but we can handle it...
|
||||
_ => {
|
||||
|
|
Loading…
Reference in New Issue