UdpTcServer

Struct UdpTcServer 

Source
pub struct UdpTcServer<E> {
    pub socket: UdpSocket,
    /* private fields */
}
Available on crate feature std only.
Expand description

This UDP server can be used to receive CCSDS space packet telecommands or any other telecommand format.

It caches all received telecomands into a vector. The maximum expected telecommand size should be declared upfront. This avoids dynamic allocation during run-time. The user can specify a TC receiver in form of a special trait object which implements ReceivesTc. Please note that the receiver should copy out the received data if it the data is required past the ReceivesTcCore::pass_tc call.

§Examples

use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use spacepackets::ecss::WritablePusPacket;
use satrs_core::hal::std::udp_server::UdpTcServer;
use satrs_core::tmtc::{ReceivesTc, ReceivesTcCore};
use spacepackets::SpHeader;
use spacepackets::ecss::tc::PusTcCreator;

#[derive (Default)]
struct PingReceiver {}
impl ReceivesTcCore for PingReceiver {
   type Error = ();
   fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error> {
        assert_eq!(tc_raw.len(), 13);
        Ok(())
    }
}

let mut buf = [0; 32];
let dest_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7777);
let ping_receiver = PingReceiver::default();
let mut udp_tc_server = UdpTcServer::new(dest_addr, 2048, Box::new(ping_receiver))
      .expect("Creating UDP TMTC server failed");
let mut sph = SpHeader::tc_unseg(0x02, 0, 0).unwrap();
let pus_tc = PusTcCreator::new_simple(&mut sph, 17, 1, None, true);
let len = pus_tc
    .write_to_bytes(&mut buf)
    .expect("Error writing PUS TC packet");
assert_eq!(len, 13);
let client = UdpSocket::bind("127.0.0.1:7778").expect("Connecting to UDP server failed");
client
    .send_to(&buf[0..len], dest_addr)
    .expect("Error sending PUS TC via UDP");

The satrs-example crate server code also includes example code on how to use this TC server. It uses the server to receive PUS telecommands on a specific port and then forwards them to a generic CCSDS packet receiver.

Fields§

§socket: UdpSocket

Implementations§

Source§

impl<E: 'static> UdpTcServer<E>

Source

pub fn new<A: ToSocketAddrs>( addr: A, max_recv_size: usize, tc_receiver: Box<dyn ReceivesTc<Error = E>>, ) -> Result<Self, Error>

Source

pub fn try_recv_tc(&mut self) -> Result<(usize, SocketAddr), ReceiveResult<E>>

Source

pub fn last_sender(&self) -> Option<SocketAddr>

Trait Implementations§

Source§

impl<E: 'static> ReceivesTcCore for UdpTcServer<E>

Source§

type Error = E

Source§

fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>

Auto Trait Implementations§

§

impl<E> Freeze for UdpTcServer<E>

§

impl<E> !RefUnwindSafe for UdpTcServer<E>

§

impl<E> Send for UdpTcServer<E>

§

impl<E> !Sync for UdpTcServer<E>

§

impl<E> Unpin for UdpTcServer<E>

§

impl<E> !UnwindSafe for UdpTcServer<E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReceivesTc for T
where T: ReceivesTcCore + Send + 'static,

Source§

fn upcast(&self) -> &dyn ReceivesTcCore<Error = <T as ReceivesTcCore>::Error>

Available on crate feature alloc only.
Source§

fn upcast_mut( &mut self, ) -> &mut dyn ReceivesTcCore<Error = <T as ReceivesTcCore>::Error>

Available on crate feature alloc only.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.