Compare commits

..

No commits in common. "13bf8b6080722bd5a55f07f8a5a2217b0b913944" and "8dbf62167971a56b71d777f824be76afe689687b" have entirely different histories.

6 changed files with 15 additions and 124 deletions

View File

@ -17,9 +17,7 @@ smoltcp = { version = "0.6.0", default-features = false, features = [ "ethernet"
nb = "1.0.0" nb = "1.0.0"
scpi = { git = "https://github.com/occheung/scpi-rs", branch = "issue-4" } scpi = { git = "https://github.com/occheung/scpi-rs", branch = "issue-4" }
lexical-core = { version="0.7.1", features=["radix"], default-features=false } lexical-core = { version="0.7.1", features=["radix"], default-features=false }
libm = "0.2.0" libm = { version = "0.2.0" }
embedded-nal = "0.1.0"
minimq = "0.1.0"
# Logging and Panicking # Logging and Panicking
panic-itm = "0.4.1" panic-itm = "0.4.1"

View File

@ -58,9 +58,6 @@ use smoltcp::socket::SocketSet;
use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer}; use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer};
use smoltcp::time::{Duration, Instant}; use smoltcp::time::{Duration, Instant};
// Use embedded-nal to access smoltcp
use embedded_nal::TcpStack;
use firmware; use firmware;
use firmware::{ use firmware::{
attenuator::Attenuator, attenuator::Attenuator,
@ -304,6 +301,8 @@ fn main() -> ! {
}; };
let mut eth_up = false; let mut eth_up = false;
let mut receive_and_not_send = true;
let mut counter = 0;
// Record activeness of silent socket, init as false // Record activeness of silent socket, init as false
let mut silent_socket_active = false; let mut silent_socket_active = false;
@ -320,7 +319,7 @@ fn main() -> ! {
}, },
}; };
// Float rounding test socket (:6969) // Counting socket (:6969)
{ {
let mut socket = sockets.get::<TcpSocket>(tcp1_handle); let mut socket = sockets.get::<TcpSocket>(tcp1_handle);
if !socket.is_open() { if !socket.is_open() {
@ -328,7 +327,7 @@ fn main() -> ! {
socket.set_timeout(Some(Duration::from_millis(5000))); socket.set_timeout(Some(Duration::from_millis(5000)));
} }
if socket.can_recv() { if socket.can_recv() && receive_and_not_send {
let data = socket.recv(|buffer| { let data = socket.recv(|buffer| {
(buffer.len(), buffer) (buffer.len(), buffer)
}).unwrap(); }).unwrap();
@ -336,8 +335,16 @@ fn main() -> ! {
let result = lexical_core::parse_partial::<f64>(data).unwrap(); let result = lexical_core::parse_partial::<f64>(data).unwrap();
writeln!(socket, "{}", round(result.0 * 2.0)); writeln!(socket, "{}", round(result.0 * 2.0));
} }
else if socket.can_recv() {
// hprintln!("{:?}", socket.can_recv());
} }
// SCPI interaction socket (:7000)
if socket.can_send() && !receive_and_not_send {
writeln!(socket, "{}", counter);
receive_and_not_send = true;
}
}
// Silent socket (:7000)
{ {
let mut socket = sockets.get::<TcpSocket>(silent_handle); let mut socket = sockets.get::<TcpSocket>(silent_handle);
if !socket.is_open() { if !socket.is_open() {

View File

@ -357,7 +357,7 @@ where
// Test configuration register by getting SDIO_IN_ONLY and LSB_FIRST. // Test configuration register by getting SDIO_IN_ONLY and LSB_FIRST.
let mut error_count = 0; let mut error_count = 0;
let mut config_checks = [ let mut config_checks = [
(DDSCFRMask::SDIO_IN_ONLY, 1), (DDSCFRMask::SDIO_IN_ONLY, 0),
(DDSCFRMask::LSB_FIRST, 0) (DDSCFRMask::LSB_FIRST, 0)
]; ];
self.get_configurations(&mut config_checks)?; self.get_configurations(&mut config_checks)?;

View File

@ -1,5 +1,4 @@
#![no_std] #![no_std]
#![feature(generic_associated_types)]
extern crate embedded_hal; extern crate embedded_hal;
use embedded_hal::{ use embedded_hal::{
digital::v2::OutputPin, digital::v2::OutputPin,
@ -38,8 +37,6 @@ use crate::dds::DDS;
pub mod scpi; pub mod scpi;
pub mod nal_tcp_client;
/* /*
* Enum for structuring error * Enum for structuring error
*/ */

View File

@ -1,109 +0,0 @@
use embedded_nal::{TcpStack, Mode, SocketAddr};
use embedded_nal::SocketAddr::{V4, V6};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
use smoltcp::socket::SocketSet;
use smoltcp::socket::{SocketHandle, TcpSocket, TcpSocketBuffer};
use smoltcp::time::{Duration, Instant};
use smoltcp::Error;
use nb::Error as nbError;
use core::cell;
const BUFFER_SIZE: usize = 2048;
pub static mut TX_STORAGE: &'static mut [u8] = &mut [0; BUFFER_SIZE];
pub static mut RX_STORAGE: &'static mut [u8] = &mut [0; BUFFER_SIZE];
/*
* Struct for a TCP socket
* TODO: Consider handling all sockets in this struct
*/
pub struct NalTcpClient {}
// impl NalTcpClient {
// pub fn new(socket: &'a mut TcpSocket<'a>) -> Self {
// NalTcpClient {
// socket,
// }
// }
// }
impl<'a> TcpStack for &'a NalTcpClient{
// The type returned when we create a new TCP socket
type TcpSocket = smoltcp::socket::TcpSocket<'a>;
// The type returned when we have an error
type Error = Error;
// Open a new TCP socket. The socket starts in the unconnected state.
fn open(&self, mode: Mode) -> Result<Self::TcpSocket, Self::Error> {
let tx_buffer = unsafe { TcpSocketBuffer::new(&mut TX_STORAGE[..]) };
let rx_buffer = unsafe { TcpSocketBuffer::new(&mut RX_STORAGE[..]) };
let mut socket = TcpSocket::new(rx_buffer, tx_buffer);
if let Mode::Timeout(dur) = mode {
socket.set_timeout(Some(Duration::from_millis(dur.into())));
}
Ok(socket)
}
// Connect to the given remote host and port.
fn connect(
&self,
mut socket: Self::TcpSocket,
remote: SocketAddr,
) -> Result<Self::TcpSocket, Self::Error> {
let result = match remote {
V4(v4_addr) => {
let ip_addr = v4_addr.ip().octets();
socket.connect((IpAddress::v4(ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]), v4_addr.port()), 49500)
},
V6(v6_addr) => {
let ip_addr = v6_addr.ip().segments();
socket.connect((IpAddress::v6(ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3],
ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3]), v6_addr.port()), 49500)
}
};
match result {
Ok(_) => Ok(socket),
Err(_e) => Err(_e),
}
}
/// Check if this socket is connected
fn is_connected(&self, socket: &Self::TcpSocket) -> Result<bool, Self::Error> {
Ok(socket.is_active())
}
/// Write to the stream. Returns the number of bytes written is returned
/// (which may be less than `buffer.len()`), or an error.
fn write(&self, socket: &mut Self::TcpSocket, buffer: &[u8]) -> nb::Result<usize, Self::Error> {
if socket.can_send() {
socket.send_slice(buffer).map_err(nbError::Other)
} else {
Err(nbError::Other(Error::Illegal))
}
}
/// Read from the stream. Returns `Ok(n)`, which means `n` bytes of
/// data have been received and they have been placed in
/// `&buffer[0..n]`, or an error.
fn read(
&self,
socket: &mut Self::TcpSocket,
buffer: &mut [u8],
) -> nb::Result<usize, Self::Error> {
if socket.can_recv() {
socket.recv_slice(buffer).map_err(nbError::Other)
} else {
Err(nbError::Other(Error::Illegal))
}
}
/// Close an existing TCP socket.
fn close(&self, mut socket: Self::TcpSocket) -> Result<(), Self::Error> {
socket.close();
Ok(())
}
}

View File

@ -29,7 +29,6 @@ use scpi::{
}; };
use embedded_hal::blocking::spi::Transfer; use embedded_hal::blocking::spi::Transfer;
use cortex_m_semihosting::hprintln;
use crate::Urukul; use crate::Urukul;
@ -71,7 +70,6 @@ where
} }
fn tst(&mut self) -> Result<()> { fn tst(&mut self) -> Result<()> {
hprintln!("Testing Urukul...").unwrap();
match self.test() { match self.test() {
Ok(0) => Ok(()), Ok(0) => Ok(()),
Ok(_) => Err(Error::new( Ok(_) => Err(Error::new(