Struct CommandQueue

Source
pub struct CommandQueue<'a> { /* private fields */ }
Expand description

A queue of commands that are to be submitted at once before listening for their responses.

Implementations§

Source§

impl<'a> CommandQueue<'a>

Source

pub fn prepare_stream(self) -> Self

This command causes the playback system to enter the Prepared state. The DAC resets its buffer to be empty and sets “point_count” to 0.

This command may only be sent if the light engine is Ready and the playback system is Idle. If so, the DAC replies with ACK. Otherwise, it replies with NAK - Invalid.

Examples found in repository?
examples/dac_stream.rs (line 38)
5fn main() {
6    println!("Listening for an Ether Dream DAC...");
7
8    let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
9        .expect("failed to bind to UDP socket")
10        .filter_map(Result::ok)
11        .next()
12        .unwrap();
13    let mac_address = dac::MacAddress(dac_broadcast.mac_address);
14
15    println!(
16        "Discovered DAC \"{}\" at \"{}\"! Connecting...",
17        mac_address, source_addr
18    );
19
20    // Establish the TCP connection.
21    let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
22
23    // If we want to create an animation (in our case a moving sine wave) we need a frame rate.
24    let frames_per_second = 60.0;
25    // Lets use the DAC at an eighth the maximum scan rate.
26    let points_per_second = stream.dac().max_point_rate / 32;
27    // Determine the number of points per frame given our target frame and point rates.
28    let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
29
30    println!(
31        "Preparing for playback:\n\tframe_hz: {}\n\tpoint_hz: {}\n\tpoints_per_frame: {}\n",
32        frames_per_second, points_per_second, points_per_frame
33    );
34
35    // Prepare the DAC's playback engine and await the repsonse.
36    stream
37        .queue_commands()
38        .prepare_stream()
39        .submit()
40        .err()
41        .map(|err| {
42            eprintln!(
43                "err occurred when submitting PREPARE_STREAM \
44                      command and listening for response: {}",
45                err
46            );
47        });
48
49    println!("Beginning playback!");
50
51    // The sine wave used to generate points.
52    let mut sine_wave = SineWave {
53        point: 0,
54        points_per_frame,
55        frames_per_second,
56    };
57
58    // Queue the initial frame and tell the DAC to begin producing output.
59    let n_points = points_to_generate(stream.dac());
60    stream
61        .queue_commands()
62        .data(sine_wave.by_ref().take(n_points))
63        .begin(0, points_per_second)
64        .submit()
65        .err()
66        .map(|err| {
67            eprintln!(
68                "err occurred when submitting initial DATA and BEGIN \
69                      commands and listening for response: {}",
70                err
71            );
72        });
73
74    // Loop and continue to send points forever.
75    loop {
76        // Determine how many points the DAC can currently receive.
77        let n_points = points_to_generate(stream.dac());
78        if let Err(err) = stream
79            .queue_commands()
80            .data(sine_wave.by_ref().take(n_points))
81            .submit()
82        {
83            eprintln!(
84                "err occurred when submitting DATA command and listening \
85                      for response: {}",
86                err
87            );
88            break;
89        }
90    }
91
92    // Tell the DAC to stop producing output and return to idle. Wait for the response.
93    //
94    // Note that the DAC is commanded to stop on `Drop` if this is not called and any errors
95    // produced are ignored.
96    stream
97        .queue_commands()
98        .stop()
99        .submit()
100        .expect("err occurred when submitting STOP command and listening for response");
101}
Source

pub fn begin(self, low_water_mark: u16, point_rate: u32) -> Self

Causes the DAC to begin producing output.

§low_water_mark

Currently unused.

§point_rate

The number of points per second to be read from the buffer. If the playback system was Prepared and there was data in the buffer, then the DAC will reply with ACK. Otherwise, it replies with NAK - Invalid.

Examples found in repository?
examples/dac_stream.rs (line 63)
5fn main() {
6    println!("Listening for an Ether Dream DAC...");
7
8    let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
9        .expect("failed to bind to UDP socket")
10        .filter_map(Result::ok)
11        .next()
12        .unwrap();
13    let mac_address = dac::MacAddress(dac_broadcast.mac_address);
14
15    println!(
16        "Discovered DAC \"{}\" at \"{}\"! Connecting...",
17        mac_address, source_addr
18    );
19
20    // Establish the TCP connection.
21    let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
22
23    // If we want to create an animation (in our case a moving sine wave) we need a frame rate.
24    let frames_per_second = 60.0;
25    // Lets use the DAC at an eighth the maximum scan rate.
26    let points_per_second = stream.dac().max_point_rate / 32;
27    // Determine the number of points per frame given our target frame and point rates.
28    let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
29
30    println!(
31        "Preparing for playback:\n\tframe_hz: {}\n\tpoint_hz: {}\n\tpoints_per_frame: {}\n",
32        frames_per_second, points_per_second, points_per_frame
33    );
34
35    // Prepare the DAC's playback engine and await the repsonse.
36    stream
37        .queue_commands()
38        .prepare_stream()
39        .submit()
40        .err()
41        .map(|err| {
42            eprintln!(
43                "err occurred when submitting PREPARE_STREAM \
44                      command and listening for response: {}",
45                err
46            );
47        });
48
49    println!("Beginning playback!");
50
51    // The sine wave used to generate points.
52    let mut sine_wave = SineWave {
53        point: 0,
54        points_per_frame,
55        frames_per_second,
56    };
57
58    // Queue the initial frame and tell the DAC to begin producing output.
59    let n_points = points_to_generate(stream.dac());
60    stream
61        .queue_commands()
62        .data(sine_wave.by_ref().take(n_points))
63        .begin(0, points_per_second)
64        .submit()
65        .err()
66        .map(|err| {
67            eprintln!(
68                "err occurred when submitting initial DATA and BEGIN \
69                      commands and listening for response: {}",
70                err
71            );
72        });
73
74    // Loop and continue to send points forever.
75    loop {
76        // Determine how many points the DAC can currently receive.
77        let n_points = points_to_generate(stream.dac());
78        if let Err(err) = stream
79            .queue_commands()
80            .data(sine_wave.by_ref().take(n_points))
81            .submit()
82        {
83            eprintln!(
84                "err occurred when submitting DATA command and listening \
85                      for response: {}",
86                err
87            );
88            break;
89        }
90    }
91
92    // Tell the DAC to stop producing output and return to idle. Wait for the response.
93    //
94    // Note that the DAC is commanded to stop on `Drop` if this is not called and any errors
95    // produced are ignored.
96    stream
97        .queue_commands()
98        .stop()
99        .submit()
100        .expect("err occurred when submitting STOP command and listening for response");
101}
Source

pub fn point_rate(self, point_rate: u32) -> Self

Adds a new point rate to the point rate buffer.

Point rate changes are read out of the buffer when a point with an appropriate flag is played (see the WriteData command).

If the DAC’s playback state is not Prepared or Playing, it replies with NAK - Invalid.

If the point rate buffer is full, it replies with NAK - Full.

Otherwise, it replies with ACK.

Source

pub fn data<I>(self, points: I) -> Self
where I: IntoIterator<Item = DacPoint>,

Indicates to the DAC to add the following point data into its buffer.

Examples found in repository?
examples/dac_stream.rs (line 62)
5fn main() {
6    println!("Listening for an Ether Dream DAC...");
7
8    let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
9        .expect("failed to bind to UDP socket")
10        .filter_map(Result::ok)
11        .next()
12        .unwrap();
13    let mac_address = dac::MacAddress(dac_broadcast.mac_address);
14
15    println!(
16        "Discovered DAC \"{}\" at \"{}\"! Connecting...",
17        mac_address, source_addr
18    );
19
20    // Establish the TCP connection.
21    let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
22
23    // If we want to create an animation (in our case a moving sine wave) we need a frame rate.
24    let frames_per_second = 60.0;
25    // Lets use the DAC at an eighth the maximum scan rate.
26    let points_per_second = stream.dac().max_point_rate / 32;
27    // Determine the number of points per frame given our target frame and point rates.
28    let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
29
30    println!(
31        "Preparing for playback:\n\tframe_hz: {}\n\tpoint_hz: {}\n\tpoints_per_frame: {}\n",
32        frames_per_second, points_per_second, points_per_frame
33    );
34
35    // Prepare the DAC's playback engine and await the repsonse.
36    stream
37        .queue_commands()
38        .prepare_stream()
39        .submit()
40        .err()
41        .map(|err| {
42            eprintln!(
43                "err occurred when submitting PREPARE_STREAM \
44                      command and listening for response: {}",
45                err
46            );
47        });
48
49    println!("Beginning playback!");
50
51    // The sine wave used to generate points.
52    let mut sine_wave = SineWave {
53        point: 0,
54        points_per_frame,
55        frames_per_second,
56    };
57
58    // Queue the initial frame and tell the DAC to begin producing output.
59    let n_points = points_to_generate(stream.dac());
60    stream
61        .queue_commands()
62        .data(sine_wave.by_ref().take(n_points))
63        .begin(0, points_per_second)
64        .submit()
65        .err()
66        .map(|err| {
67            eprintln!(
68                "err occurred when submitting initial DATA and BEGIN \
69                      commands and listening for response: {}",
70                err
71            );
72        });
73
74    // Loop and continue to send points forever.
75    loop {
76        // Determine how many points the DAC can currently receive.
77        let n_points = points_to_generate(stream.dac());
78        if let Err(err) = stream
79            .queue_commands()
80            .data(sine_wave.by_ref().take(n_points))
81            .submit()
82        {
83            eprintln!(
84                "err occurred when submitting DATA command and listening \
85                      for response: {}",
86                err
87            );
88            break;
89        }
90    }
91
92    // Tell the DAC to stop producing output and return to idle. Wait for the response.
93    //
94    // Note that the DAC is commanded to stop on `Drop` if this is not called and any errors
95    // produced are ignored.
96    stream
97        .queue_commands()
98        .stop()
99        .submit()
100        .expect("err occurred when submitting STOP command and listening for response");
101}
Source

pub fn stop(self) -> Self

Causes the DAC to immediately stop playing and return to the Idle playback state.

It is ACKed if the DAC was in the Playing or Prepared playback states.

Otherwise it is replied to with NAK - Invalid.

Examples found in repository?
examples/dac_stream.rs (line 98)
5fn main() {
6    println!("Listening for an Ether Dream DAC...");
7
8    let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
9        .expect("failed to bind to UDP socket")
10        .filter_map(Result::ok)
11        .next()
12        .unwrap();
13    let mac_address = dac::MacAddress(dac_broadcast.mac_address);
14
15    println!(
16        "Discovered DAC \"{}\" at \"{}\"! Connecting...",
17        mac_address, source_addr
18    );
19
20    // Establish the TCP connection.
21    let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
22
23    // If we want to create an animation (in our case a moving sine wave) we need a frame rate.
24    let frames_per_second = 60.0;
25    // Lets use the DAC at an eighth the maximum scan rate.
26    let points_per_second = stream.dac().max_point_rate / 32;
27    // Determine the number of points per frame given our target frame and point rates.
28    let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
29
30    println!(
31        "Preparing for playback:\n\tframe_hz: {}\n\tpoint_hz: {}\n\tpoints_per_frame: {}\n",
32        frames_per_second, points_per_second, points_per_frame
33    );
34
35    // Prepare the DAC's playback engine and await the repsonse.
36    stream
37        .queue_commands()
38        .prepare_stream()
39        .submit()
40        .err()
41        .map(|err| {
42            eprintln!(
43                "err occurred when submitting PREPARE_STREAM \
44                      command and listening for response: {}",
45                err
46            );
47        });
48
49    println!("Beginning playback!");
50
51    // The sine wave used to generate points.
52    let mut sine_wave = SineWave {
53        point: 0,
54        points_per_frame,
55        frames_per_second,
56    };
57
58    // Queue the initial frame and tell the DAC to begin producing output.
59    let n_points = points_to_generate(stream.dac());
60    stream
61        .queue_commands()
62        .data(sine_wave.by_ref().take(n_points))
63        .begin(0, points_per_second)
64        .submit()
65        .err()
66        .map(|err| {
67            eprintln!(
68                "err occurred when submitting initial DATA and BEGIN \
69                      commands and listening for response: {}",
70                err
71            );
72        });
73
74    // Loop and continue to send points forever.
75    loop {
76        // Determine how many points the DAC can currently receive.
77        let n_points = points_to_generate(stream.dac());
78        if let Err(err) = stream
79            .queue_commands()
80            .data(sine_wave.by_ref().take(n_points))
81            .submit()
82        {
83            eprintln!(
84                "err occurred when submitting DATA command and listening \
85                      for response: {}",
86                err
87            );
88            break;
89        }
90    }
91
92    // Tell the DAC to stop producing output and return to idle. Wait for the response.
93    //
94    // Note that the DAC is commanded to stop on `Drop` if this is not called and any errors
95    // produced are ignored.
96    stream
97        .queue_commands()
98        .stop()
99        .submit()
100        .expect("err occurred when submitting STOP command and listening for response");
101}
Source

pub fn emergency_stop(self) -> Self

Causes the light engine to enter the E-Stop state, regardless of its previous state.

This command is always ACKed.

Source

pub fn clear_emergency_stop(self) -> Self

If the light engine was in E-Stop state due to an emergency stop command (either from a local stop condition or over the network), this command resets it to Ready.

It is ACKed if the DAC was previously in E-Stop.

Otherwise it is replied to with a NAK - Invalid.

If the condition that caused the emergency stop is still active (e.g. E-Stop input still asserted, temperature still out of bounds, etc) a NAK - Stop Condition is sent.

Source

pub fn ping(self) -> Self

The DAC will reply to this with an ACK packet.

This serves as a keep-alive for the connection when the DAC is not actively streaming.

Source

pub fn submit(self) -> Result<(), CommunicationError>

Finish queueing commands and send them to the DAC.

First all commands are written to the TCP stream, then we block waiting for a response to each from the DAC.

Examples found in repository?
examples/dac_stream.rs (line 39)
5fn main() {
6    println!("Listening for an Ether Dream DAC...");
7
8    let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
9        .expect("failed to bind to UDP socket")
10        .filter_map(Result::ok)
11        .next()
12        .unwrap();
13    let mac_address = dac::MacAddress(dac_broadcast.mac_address);
14
15    println!(
16        "Discovered DAC \"{}\" at \"{}\"! Connecting...",
17        mac_address, source_addr
18    );
19
20    // Establish the TCP connection.
21    let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
22
23    // If we want to create an animation (in our case a moving sine wave) we need a frame rate.
24    let frames_per_second = 60.0;
25    // Lets use the DAC at an eighth the maximum scan rate.
26    let points_per_second = stream.dac().max_point_rate / 32;
27    // Determine the number of points per frame given our target frame and point rates.
28    let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
29
30    println!(
31        "Preparing for playback:\n\tframe_hz: {}\n\tpoint_hz: {}\n\tpoints_per_frame: {}\n",
32        frames_per_second, points_per_second, points_per_frame
33    );
34
35    // Prepare the DAC's playback engine and await the repsonse.
36    stream
37        .queue_commands()
38        .prepare_stream()
39        .submit()
40        .err()
41        .map(|err| {
42            eprintln!(
43                "err occurred when submitting PREPARE_STREAM \
44                      command and listening for response: {}",
45                err
46            );
47        });
48
49    println!("Beginning playback!");
50
51    // The sine wave used to generate points.
52    let mut sine_wave = SineWave {
53        point: 0,
54        points_per_frame,
55        frames_per_second,
56    };
57
58    // Queue the initial frame and tell the DAC to begin producing output.
59    let n_points = points_to_generate(stream.dac());
60    stream
61        .queue_commands()
62        .data(sine_wave.by_ref().take(n_points))
63        .begin(0, points_per_second)
64        .submit()
65        .err()
66        .map(|err| {
67            eprintln!(
68                "err occurred when submitting initial DATA and BEGIN \
69                      commands and listening for response: {}",
70                err
71            );
72        });
73
74    // Loop and continue to send points forever.
75    loop {
76        // Determine how many points the DAC can currently receive.
77        let n_points = points_to_generate(stream.dac());
78        if let Err(err) = stream
79            .queue_commands()
80            .data(sine_wave.by_ref().take(n_points))
81            .submit()
82        {
83            eprintln!(
84                "err occurred when submitting DATA command and listening \
85                      for response: {}",
86                err
87            );
88            break;
89        }
90    }
91
92    // Tell the DAC to stop producing output and return to idle. Wait for the response.
93    //
94    // Note that the DAC is commanded to stop on `Drop` if this is not called and any errors
95    // produced are ignored.
96    stream
97        .queue_commands()
98        .stop()
99        .submit()
100        .expect("err occurred when submitting STOP command and listening for response");
101}

Auto Trait Implementations§

§

impl<'a> Freeze for CommandQueue<'a>

§

impl<'a> RefUnwindSafe for CommandQueue<'a>

§

impl<'a> Send for CommandQueue<'a>

§

impl<'a> Sync for CommandQueue<'a>

§

impl<'a> Unpin for CommandQueue<'a>

§

impl<'a> !UnwindSafe for CommandQueue<'a>

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> 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, 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.