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>
impl<'a> CommandQueue<'a>
Sourcepub fn prepare_stream(self) -> Self
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?
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}Sourcepub fn begin(self, low_water_mark: u16, point_rate: u32) -> Self
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?
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}Sourcepub fn point_rate(self, point_rate: u32) -> Self
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.
Sourcepub fn data<I>(self, points: I) -> Selfwhere
I: IntoIterator<Item = DacPoint>,
pub fn data<I>(self, points: I) -> Selfwhere
I: IntoIterator<Item = DacPoint>,
Indicates to the DAC to add the following point data into its buffer.
Examples found in repository?
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}Sourcepub fn stop(self) -> Self
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?
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}Sourcepub fn emergency_stop(self) -> Self
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.
Sourcepub fn clear_emergency_stop(self) -> Self
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.
Sourcepub fn ping(self) -> Self
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.
Sourcepub fn submit(self) -> Result<(), CommunicationError>
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?
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}