Struct Transmission

Source
pub struct Transmission {
    pub sequence: String,
    pub pulse_length: u16,
    pub repeats: u8,
    pub protocol: ProtocolProperties,
}
Expand description

A transmission consists of a sequence of short and long radio pulses. The binary sequence is represented by a string of literal ‘0’ and ‘1’ characters. That way you can compose the signal simply by concatenating multiple strings.

The pulse length is the smallest time unit of the signal. It will be multiplied by the respective values specified in the ProtocolProperties struct. The pulse length is given in microseconds. Usually, a lot of fine tuning is required.

Usually, sending the signal once is not enough, so we need to specify the number of repeats.

Fields§

§sequence: String§pulse_length: u16§repeats: u8§protocol: ProtocolProperties

Implementations§

Source§

impl Transmission

Source

pub fn send_to(&self, gpio_dev: &str, gpio_pin: u8) -> Result<(), Error>

Output the signal on a gpio pin on the specified gpio device via the gpio character device ABI. Finding the right device can sometimes be a bit tricky. Further information might be found in the documentation of your SBC. On a Raspberry Pi 4B it is /dev/gpiochip0, but on a Raspberry Pi 5 the appropiate device is /dev/gpiochip4. gpio_pin is the number of the gpio pin the radio transmitter module, e.g. an FS1000A module, is connected to.

The sequence is transmitted by iterating over the characters of a string slice. If the character is ‘1’ a binary one will be transmitted, or a binary zero if the character is ‘0’, respectively. All other characters will result in a sync bit.

§Examples
use libsparkypi::*;

let my_signal = Transmission::builder()
    .sequence("s000000000000010101010001")
    .pulse_length(320)
    .repeats(10)
    .protocol(P1)
    .build();

// output on device /dev/gpiochip0, gpio pin 18
my_signal.send_to("/dev/gpiochip0", 18).unwrap();
Source

pub fn sequence(&mut self, seq: &str)

Modifies the binary sequence.

Source

pub fn new() -> Self

Creates a new instance with default values, e.g. all fields with numbers will be zero, and the string will be empty.

Source

pub fn builder() -> TransmissionBuilder

Invokes the builder.

Source

pub fn csv_as_bytes(&self) -> Vec<u8>

Creates a byte vector containing the data from the transmission in the form of literal characters in the following comma separated pattern:

SEQUENCE,PULSE_LENGTH,REPEATS,SHORT,LONG,SYNC_BIT,SYNC_GAP

You can send those bytes e.g. via UART to an appropriately programmed microcontroller, which subsequently can parse the values, and transmit the binary sequence accordingly via a radio module. You can for example connect an Arduino Nano via USB to a regular x86 PC and make use of the serialport crate.

Trait Implementations§

Source§

impl Clone for Transmission

Source§

fn clone(&self) -> Transmission

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Transmission

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Transmission

Source§

fn default() -> Transmission

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Transmission

Source§

fn eq(&self, other: &Transmission) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Transmission

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.