ccsds_packet

Struct Command

source
#[repr(C)]
pub struct Command<T: Copy> { pub payload: T, /* private fields */ }
Expand description

A cFS-flavor CCSDS command packet, as a Rust structure.

Fields§

§payload: T

The message’s payload. As messages are copied willy-nilly, T needs to be Copy.

Implementations§

source§

impl<T: Copy> Command<T>

source

pub fn new(msg_id: u32, function_code: u16, payload: T) -> Result<Self, ()>

If msg_id and function_code are a permissible message ID and a permissible command code (respectively), returns a new Command with the payload initialized to payload; otherwise returns an error.

source

pub fn new_default(msg_id: u32, function_code: u16) -> Result<Self, ()>
where T: Default,

Self::new, but using Default::default() as the payload.

source

pub fn as_bytes(&self) -> &[u8]

Returns a view of the Command as a sequence of bytes, ready for transmission.

source

pub unsafe fn from_bytes(bytes: &[u8]) -> Result<Self, ()>

Turns a sequence of bytes representing a message into a Command, assuming bytes is the correct length and the header bytes have sane values.

§Safety

Using this function is only safe if the part of bytes at bytes 8..(8 + std::mem::size_of::<T>()) is byte-for-byte equal to a valid item of type T.

source

pub fn msg_id(&self) -> u32

Returns the message’s message ID.

source

pub fn function_code(&self) -> u16

Returns the message’s command code.

source

pub fn set_msg_id(&mut self, msg_id: u32) -> Result<(), ()>

If msg_id is a valid message ID, sets the message’s message ID to msg_id.

source

pub fn set_function_code(&mut self, function_code: u16) -> Result<(), ()>

If function_code is a valid command code, sets the message’s function code to function_code.

Trait Implementations§

source§

impl<T: Clone + Copy> Clone for Command<T>

source§

fn clone(&self) -> Command<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Command<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Command<T>
where T: RefUnwindSafe,

§

impl<T> Send for Command<T>
where T: Send,

§

impl<T> Sync for Command<T>
where T: Sync,

§

impl<T> Unpin for Command<T>
where T: Unpin,

§

impl<T> UnwindSafe for Command<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.