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: UdpSocketImplementations§
Source§impl<E: 'static> UdpTcServer<E>
impl<E: 'static> UdpTcServer<E>
pub fn new<A: ToSocketAddrs>( addr: A, max_recv_size: usize, tc_receiver: Box<dyn ReceivesTc<Error = E>>, ) -> Result<Self, Error>
pub fn try_recv_tc(&mut self) -> Result<(usize, SocketAddr), ReceiveResult<E>>
pub fn last_sender(&self) -> Option<SocketAddr>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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> ReceivesTc for Twhere
T: ReceivesTcCore + Send + 'static,
impl<T> ReceivesTc for Twhere
T: ReceivesTcCore + Send + 'static,
Source§fn upcast(&self) -> &dyn ReceivesTcCore<Error = <T as ReceivesTcCore>::Error>
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>
fn upcast_mut( &mut self, ) -> &mut dyn ReceivesTcCore<Error = <T as ReceivesTcCore>::Error>
Available on crate feature
alloc only.