wip: dirty state for debugging etherdream
This commit is contained in:
parent
2c0d5cd13f
commit
650a3ed521
@ -22,10 +22,10 @@ redis_url = "redis://127.0.0.1:6379/"
|
|||||||
# [dac.etherdream]
|
# [dac.etherdream]
|
||||||
# ip = "192.168.1.68"
|
# ip = "192.168.1.68"
|
||||||
|
|
||||||
[[transformers]]
|
#[[transformers]]
|
||||||
[transformers.translate]
|
#[transformers.translate]
|
||||||
x = 2000
|
#x = 20
|
||||||
y = 2000
|
#y = 20
|
||||||
|
|
||||||
[[transformers]]
|
[[transformers]]
|
||||||
[transformers.replicate]
|
[transformers.replicate]
|
||||||
|
@ -23,7 +23,7 @@ fn main() {
|
|||||||
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
|
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
|
||||||
let frames_per_second = 60.0;
|
let frames_per_second = 60.0;
|
||||||
// Lets use the DAC at an eighth the maximum scan rate.
|
// Lets use the DAC at an eighth the maximum scan rate.
|
||||||
let points_per_second = stream.dac().max_point_rate / 32;
|
let points_per_second = 20_000;
|
||||||
// Determine the number of points per frame given our target frame and point rates.
|
// Determine the number of points per frame given our target frame and point rates.
|
||||||
let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
|
let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
|
||||||
|
|
||||||
@ -70,7 +70,6 @@ fn main() {
|
|||||||
err
|
err
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
eprintln!("Stream dac{:?}", stream.dac());
|
|
||||||
|
|
||||||
// Loop and continue to send points forever.
|
// Loop and continue to send points forever.
|
||||||
loop {
|
loop {
|
||||||
@ -129,7 +128,7 @@ impl Iterator for SineWave {
|
|||||||
_ => (std::u16::MAX, std::u16::MAX, std::u16::MAX),
|
_ => (std::u16::MAX, std::u16::MAX, std::u16::MAX),
|
||||||
};
|
};
|
||||||
let x_min = std::i16::MIN;
|
let x_min = std::i16::MIN;
|
||||||
let x_max = std::i8::MAX as i16;
|
let x_max = std::i16::MAX;
|
||||||
let x = (x_min as f32 + fract * (x_max as f32 - x_min as f32)) as i16;
|
let x = (x_min as f32 + fract * (x_max as f32 - x_min as f32)) as i16;
|
||||||
let y = (amp * x_max as f32) as i16;
|
let y = (amp * x_max as f32) as i16;
|
||||||
let control = 0;
|
let control = 0;
|
||||||
|
@ -78,7 +78,7 @@ impl Conf {
|
|||||||
TransformConf::Intensity(r) => Box::new(*r),
|
TransformConf::Intensity(r) => Box::new(*r),
|
||||||
TransformConf::Replicate(r) => Box::new(*r),
|
TransformConf::Replicate(r) => Box::new(*r),
|
||||||
TransformConf::Rotate(r) => Box::new(*r),
|
TransformConf::Rotate(r) => Box::new(*r),
|
||||||
TransformConf::Translate(t) => Box::new(*t),
|
TransformConf::Translate(r) => Box::new(*r),
|
||||||
};
|
};
|
||||||
v.push(t);
|
v.push(t);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[warn(unused_imports)]
|
#[warn(unused_imports)]
|
||||||
use log::{ debug, info, warn};
|
use log::{debug, info, warn};
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
@ -14,6 +14,7 @@ use crate::device::{Device, Status, PlaybackState};
|
|||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
use crate::point::{Color, Point};
|
use crate::point::{Color, Point};
|
||||||
use ether_dream::protocol::{DacBroadcast, DacResponse};
|
use ether_dream::protocol::{DacBroadcast, DacResponse};
|
||||||
|
use crate::device::PlaybackState::PLAYING;
|
||||||
|
|
||||||
|
|
||||||
#[warn(dead_code)]
|
#[warn(dead_code)]
|
||||||
@ -21,18 +22,6 @@ pub struct EtherdreamDevice {
|
|||||||
pub conf: EtherDreamConf,
|
pub conf: EtherDreamConf,
|
||||||
dac: DacBroadcast,
|
dac: DacBroadcast,
|
||||||
stream: Stream,
|
stream: Stream,
|
||||||
|
|
||||||
// "a": ACK "F": Full "I": invalid. 64 or 35 for no connection.
|
|
||||||
// /// The previous command was accepted.
|
|
||||||
// pub const ACK: u8 = 0x61;
|
|
||||||
// /// The write command could not be performed because there was not enough buffer space when it
|
|
||||||
// /// was received.
|
|
||||||
// pub const NAK_FULL: u8 = 0x46;
|
|
||||||
// /// The command contained an invalid `command` byte or parameters.
|
|
||||||
// pub const NAK_INVALID: u8 = 0x49;
|
|
||||||
// /// An emergency-stop condition still exists.
|
|
||||||
// pub const NAK_STOP_CONDITION: u8 = 0x21;
|
|
||||||
// }
|
|
||||||
dac_response: u8,
|
dac_response: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +41,7 @@ impl EtherdreamDevice {
|
|||||||
dac_broadcast.set_timeout(Some(time::Duration::new(10, 0)))?;
|
dac_broadcast.set_timeout(Some(time::Duration::new(10, 0)))?;
|
||||||
info!("Attempting to get DAC broadcast...");
|
info!("Attempting to get DAC broadcast...");
|
||||||
let broadcast = dac_broadcast
|
let broadcast = dac_broadcast
|
||||||
.take(3)
|
.take(5)
|
||||||
.filter_map(|result| {
|
.filter_map(|result| {
|
||||||
match result {
|
match result {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -85,6 +74,20 @@ impl EtherdreamDevice {
|
|||||||
|
|
||||||
fn get_tcp_stream(dac: &DacBroadcast, source_address: &SocketAddr) -> LJResult<Stream> {
|
fn get_tcp_stream(dac: &DacBroadcast, source_address: &SocketAddr) -> LJResult<Stream> {
|
||||||
let mut stream = connect(dac, source_address.ip())?;
|
let mut stream = connect(dac, source_address.ip())?;
|
||||||
|
debug!("Stream dac BEFORE PREPARE {:?}", stream.dac());
|
||||||
|
debug!("Playback State BEFORE PREPARE {:?}, {:?}", stream.dac().dac.status.playback, Playback::Playing );
|
||||||
|
if stream.dac().dac.status.playback == Playback::Playing {
|
||||||
|
warn!("DAC was in playback PLAYING, attempting to stop");
|
||||||
|
match stream
|
||||||
|
.queue_commands()
|
||||||
|
.stop()
|
||||||
|
.submit() {
|
||||||
|
Err(err) => warn!("err occurred when submitting STOP command: {}",err),
|
||||||
|
Ok(_) => info!("Prepared Stream.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if stream.dac().dac.status.playback != Playback::Prepared {
|
||||||
|
warn!("DAC was not in playback state PREPARED, attempting to prepare");
|
||||||
match stream
|
match stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.prepare_stream()
|
.prepare_stream()
|
||||||
@ -92,10 +95,13 @@ impl EtherdreamDevice {
|
|||||||
Err(err) => warn!("err occurred when submitting PREPARE_STREAM command and listening for response: {}",err),
|
Err(err) => warn!("err occurred when submitting PREPARE_STREAM command and listening for response: {}",err),
|
||||||
Ok(_) => info!("Prepared Stream.")
|
Ok(_) => info!("Prepared Stream.")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
|
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
|
||||||
let frames_per_second = 60.0;
|
let frames_per_second = 60.0;
|
||||||
// Lets use the DAC at an eighth the maximum scan rate.
|
// Lets use the DAC at an eighth the maximum scan rate.
|
||||||
let points_per_second = stream.dac().max_point_rate / 32;
|
let points_per_second = 20_000;
|
||||||
|
// let points_per_second = 30_000;
|
||||||
|
debug!("points per second {:?}", points_per_second);
|
||||||
// Determine the number of points per frame given our target frame and point rates.
|
// Determine the number of points per frame given our target frame and point rates.
|
||||||
let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
|
let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
|
||||||
|
|
||||||
@ -104,6 +110,7 @@ impl EtherdreamDevice {
|
|||||||
points_per_frame,
|
points_per_frame,
|
||||||
frames_per_second,
|
frames_per_second,
|
||||||
};
|
};
|
||||||
|
debug!("Stream dac BEFORE BEGIN {:?}", stream.dac());
|
||||||
|
|
||||||
match stream
|
match stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
@ -122,15 +129,15 @@ impl EtherdreamDevice {
|
|||||||
/***
|
/***
|
||||||
Determine the number of points needed to fill the DAC.
|
Determine the number of points needed to fill the DAC.
|
||||||
***/
|
***/
|
||||||
// Fixme thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
let cap = self.dac.buffer_capacity as usize;
|
||||||
let n_points = self.dac.buffer_capacity as usize - self.stream.dac().dac.status.buffer_fullness as usize - 1;
|
let fullness = self.stream.dac().dac.status.buffer_fullness as usize;
|
||||||
|
// Sometimes we had thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
||||||
|
let n_points = if cap > fullness { cap - fullness } else { 0 };
|
||||||
n_points
|
n_points
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ping(&mut self) -> LJResult<()> {
|
fn ping(&mut self) -> LJResult<()> {
|
||||||
|
|
||||||
Ok(self.stream.queue_commands().ping().submit()?)
|
Ok(self.stream.queue_commands().ping().submit()?)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +151,9 @@ impl Device for EtherdreamDevice {
|
|||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let now: DateTime<Utc> = now.into();
|
let now: DateTime<Utc> = now.into();
|
||||||
let now = now.to_rfc3339();
|
let now = now.to_rfc3339();
|
||||||
|
// debug!("Dac Status: {:?} ", status );
|
||||||
|
// debug!("Etherdream Dac {:?} ", self.dac );
|
||||||
|
debug!("Stream dac{:?}", self.stream.dac());
|
||||||
|
|
||||||
Status {
|
Status {
|
||||||
last_traced_at: now,
|
last_traced_at: now,
|
||||||
@ -152,9 +162,6 @@ impl Device for EtherdreamDevice {
|
|||||||
capacity: self.points_capacity(),
|
capacity: self.points_capacity(),
|
||||||
lack: self.dac_response.to_string(),
|
lack: self.dac_response.to_string(),
|
||||||
}
|
}
|
||||||
// debug!("Dac Status: {:?} ", status );
|
|
||||||
// debug!("Etherdream Dac {:?} ", self.dac );
|
|
||||||
// debug!("Stream dac{:?}", self.stream.dac());
|
|
||||||
// status
|
// status
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,22 +169,23 @@ impl Device for EtherdreamDevice {
|
|||||||
line: Vec<Point>,
|
line: Vec<Point>,
|
||||||
_speed: u32,
|
_speed: u32,
|
||||||
) -> LJResult<()> {
|
) -> LJResult<()> {
|
||||||
let chunk_size = 64;
|
let chunk_size = 111;
|
||||||
let points_iter = line.into_iter();
|
let points_iter = line.into_iter();
|
||||||
for chunk in points_iter.as_slice().chunks(chunk_size){
|
for chunk in points_iter.as_slice().chunks(chunk_size) {
|
||||||
debug!("New chunk length: {:?}", chunk.len());
|
debug!("New chunk length: {:?}", chunk.len());
|
||||||
loop {
|
loop {
|
||||||
let capacity = self.points_capacity();
|
let capacity = self.points_capacity();
|
||||||
|
debug!("capacity : {:?}", capacity);
|
||||||
if chunk.len() > capacity as usize {
|
if chunk.len() > capacity as usize {
|
||||||
debug!("Sleep, capacity : {:?}", capacity);
|
debug!("Sleep");
|
||||||
// Sleep for 1/100th of a sec
|
// Sleep for 1/100th of a sec
|
||||||
sleep(Duration::new( 0, 10000000));
|
sleep(Duration::new(0, 10_000_000));
|
||||||
self.ping();
|
self.ping();
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
debug!("drawing");
|
debug!("Drawing");
|
||||||
match self.stream
|
match self.stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.data(
|
.data(
|
||||||
@ -216,6 +224,7 @@ impl Device for EtherdreamDevice {
|
|||||||
|
|
||||||
fn stop(&mut self) -> LJResult<()> {
|
fn stop(&mut self) -> LJResult<()> {
|
||||||
info!("Stopping Etherdream device...");
|
info!("Stopping Etherdream device...");
|
||||||
|
info!("Stream dac{:?}", self.stream.dac());
|
||||||
match self.stream
|
match self.stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.stop()
|
.stop()
|
||||||
|
@ -76,7 +76,7 @@ fn run_all() -> LJResult<()> {
|
|||||||
// Dispatch based on redis requests
|
// Dispatch based on redis requests
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
rs.set_status(tracer.status())?;
|
rs.set_status(tracer.status())?;
|
||||||
let _ = framerate_handler.handle_time()?;
|
// let _ = framerate_handler.handle_time()?;
|
||||||
let order = rs.get_order(config.laser_id)?;
|
let order = rs.get_order(config.laser_id)?;
|
||||||
match order {
|
match order {
|
||||||
Order::Draw | Order::Black | Order::Grid => {
|
Order::Draw | Order::Black | Order::Grid => {
|
||||||
|
@ -15,6 +15,7 @@ pub struct Color {
|
|||||||
pub g: u8,
|
pub g: u8,
|
||||||
pub b: u8,
|
pub b: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mul<u8> for Color {
|
impl Mul<u8> for Color {
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
|
@ -7,16 +7,15 @@ use serde::{Serialize, Deserialize};
|
|||||||
/// Converts helios Geometry to Helios
|
/// Converts helios Geometry to Helios
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||||
pub struct HeliosToEtherdream {
|
pub struct HeliosToEtherdream {}
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for HeliosToEtherdream {
|
impl Transformers for HeliosToEtherdream {
|
||||||
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> {
|
||||||
// debug!("list helios {:?}", point_list);
|
// debug!("list helios {:?}", point_list);
|
||||||
let out = point_list.iter().map(|pt| {
|
let out = point_list.iter().map(|pt| {
|
||||||
Point {
|
Point {
|
||||||
x: 8.0 * (pt.x - 2047.0),
|
x: 50.0 * (320.0 - pt.x),
|
||||||
y: 8.0 * (pt.y - 2047.0),
|
y: 40.0 * (240.0 - pt.y),
|
||||||
..*pt
|
..*pt
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
|
@ -8,20 +8,18 @@ use serde::{Serialize, Deserialize};
|
|||||||
/// Converts helios Geometry to Helios
|
/// Converts helios Geometry to Helios
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||||
pub struct Intensity {
|
pub struct Intensity {}
|
||||||
}
|
|
||||||
|
|
||||||
impl Transformers for Intensity {
|
impl Transformers for Intensity {
|
||||||
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
|
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
|
||||||
// debug!("list helios {:?}", point_list);
|
// debug!("list helios {:?}", point_list);
|
||||||
let out = point_list.iter().map(|pt| {
|
let out = point_list.iter().map(|pt| {
|
||||||
Point {
|
Point {
|
||||||
x: pt.x,
|
color: pt.color * ws.intensity,
|
||||||
y: pt.y,
|
..*pt
|
||||||
color: pt.color * ws.intensity
|
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
debug!("list intensity {:?}", out);
|
// debug!("list intensity {:?}", out);
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user