Compare commits
3 Commits
6e0cf26d6a
...
026dd1ed9c
Author | SHA1 | Date |
---|---|---|
Astro | 026dd1ed9c | |
Astro | d4e7036fab | |
Astro | bfdb64ffd6 |
|
@ -6,15 +6,19 @@ from pytec.client import Client
|
||||||
|
|
||||||
TIME_WINDOW = 300.0
|
TIME_WINDOW = 300.0
|
||||||
|
|
||||||
|
tec = Client()
|
||||||
|
target_temperature = tec.get_pid()[0]['target']
|
||||||
|
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
|
||||||
|
|
||||||
class Series:
|
class Series:
|
||||||
def __init__(self, scale=1.0):
|
def __init__(self, conv=lambda x: x):
|
||||||
self.scale = scale
|
self.conv = conv
|
||||||
self.x_data = []
|
self.x_data = []
|
||||||
self.y_data = []
|
self.y_data = []
|
||||||
|
|
||||||
def append(self, x, y):
|
def append(self, x, y):
|
||||||
self.x_data.append(x)
|
self.x_data.append(x)
|
||||||
self.y_data.append(self.scale * y)
|
self.y_data.append(self.conv(y))
|
||||||
|
|
||||||
def clip(self, min_x):
|
def clip(self, min_x):
|
||||||
drop = 0
|
drop = 0
|
||||||
|
@ -25,8 +29,8 @@ class Series:
|
||||||
|
|
||||||
series = {
|
series = {
|
||||||
'adc': Series(),
|
'adc': Series(),
|
||||||
'sens': Series(0.0001),
|
'sens': Series(lambda x: x * 0.0001),
|
||||||
'temperature': Series(),
|
'temperature': Series(lambda t: t - target_temperature),
|
||||||
'i_set': Series(),
|
'i_set': Series(),
|
||||||
'pid_output': Series(),
|
'pid_output': Series(),
|
||||||
'vref': Series(),
|
'vref': Series(),
|
||||||
|
@ -55,7 +59,6 @@ def recv_data(tec):
|
||||||
if quit:
|
if quit:
|
||||||
break
|
break
|
||||||
|
|
||||||
tec = Client()
|
|
||||||
thread = Thread(target=recv_data, args=(tec,))
|
thread = Thread(target=recv_data, args=(tec,))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
CHANNELS = 2
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
def __init__(self, host="192.168.1.26", port=23, timeout=None):
|
def __init__(self, host="192.168.1.26", port=23, timeout=None):
|
||||||
self._socket = socket.create_connection((host, port), timeout)
|
self._socket = socket.create_connection((host, port), timeout)
|
||||||
|
@ -22,6 +24,27 @@ class Client:
|
||||||
self._lines = self._lines[1:]
|
self._lines = self._lines[1:]
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
def _get_conf(self, topic):
|
||||||
|
self._command(topic)
|
||||||
|
result = []
|
||||||
|
for channel in range(0, CHANNELS):
|
||||||
|
line = self._read_line()
|
||||||
|
conf = json.loads(line)
|
||||||
|
result.append(conf)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_pwm(self):
|
||||||
|
return self._get_conf("pwm")
|
||||||
|
|
||||||
|
def get_pid(self):
|
||||||
|
return self._get_conf("pid")
|
||||||
|
|
||||||
|
def get_steinhart_hart(self):
|
||||||
|
return self._get_conf("s-h")
|
||||||
|
|
||||||
|
def get_postfilter(self):
|
||||||
|
return self._get_conf("postfilter")
|
||||||
|
|
||||||
def report_mode(self):
|
def report_mode(self):
|
||||||
"""Start reporting measurement values
|
"""Start reporting measurement values
|
||||||
|
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -54,7 +54,7 @@ mod net;
|
||||||
mod server;
|
mod server;
|
||||||
use server::Server;
|
use server::Server;
|
||||||
mod session;
|
mod session;
|
||||||
use session::{Session, SessionOutput};
|
use session::{Session, SessionInput};
|
||||||
mod command_parser;
|
mod command_parser;
|
||||||
use command_parser::{Command, ShowCommand, PwmPin};
|
use command_parser::{Command, ShowCommand, PwmPin};
|
||||||
mod timer;
|
mod timer;
|
||||||
|
@ -194,10 +194,12 @@ fn main() -> ! {
|
||||||
if ! socket.is_active() {
|
if ! socket.is_active() {
|
||||||
let _ = socket.listen(TCP_PORT);
|
let _ = socket.listen(TCP_PORT);
|
||||||
session.reset();
|
session.reset();
|
||||||
} else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 1024 {
|
} else if socket.may_send() && !socket.may_recv() {
|
||||||
|
socket.close()
|
||||||
|
} else if socket.can_send() && socket.can_recv() {
|
||||||
match socket.recv(|buf| session.feed(buf)) {
|
match socket.recv(|buf| session.feed(buf)) {
|
||||||
Ok(SessionOutput::Nothing) => {}
|
Ok(SessionInput::Nothing) => {}
|
||||||
Ok(SessionOutput::Command(command)) => match command {
|
Ok(SessionInput::Command(command)) => match command {
|
||||||
Command::Quit =>
|
Command::Quit =>
|
||||||
socket.close(),
|
socket.close(),
|
||||||
Command::Reporting(reporting) => {
|
Command::Reporting(reporting) => {
|
||||||
|
@ -413,7 +415,7 @@ fn main() -> ! {
|
||||||
SCB::sys_reset();
|
SCB::sys_reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(SessionOutput::Error(e)) => {
|
Ok(SessionInput::Error(e)) => {
|
||||||
let _ = writeln!(socket, "Command error: {:?}", e);
|
let _ = writeln!(socket, "Command error: {:?}", e);
|
||||||
}
|
}
|
||||||
Err(_) =>
|
Err(_) =>
|
||||||
|
|
|
@ -38,16 +38,16 @@ impl LineReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum SessionOutput {
|
pub enum SessionInput {
|
||||||
Nothing,
|
Nothing,
|
||||||
Command(Command),
|
Command(Command),
|
||||||
Error(ParserError),
|
Error(ParserError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Result<Command, ParserError>> for SessionOutput {
|
impl From<Result<Command, ParserError>> for SessionInput {
|
||||||
fn from(input: Result<Command, ParserError>) -> Self {
|
fn from(input: Result<Command, ParserError>) -> Self {
|
||||||
input.map(SessionOutput::Command)
|
input.map(SessionInput::Command)
|
||||||
.unwrap_or_else(SessionOutput::Error)
|
.unwrap_or_else(SessionInput::Error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ impl Session {
|
||||||
self.report_pending[channel] = false;
|
self.report_pending[channel] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionOutput) {
|
pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionInput) {
|
||||||
let mut buf_bytes = 0;
|
let mut buf_bytes = 0;
|
||||||
for (i, b) in buf.iter().enumerate() {
|
for (i, b) in buf.iter().enumerate() {
|
||||||
buf_bytes = i + 1;
|
buf_bytes = i + 1;
|
||||||
|
@ -125,6 +125,6 @@ impl Session {
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(buf_bytes, SessionOutput::Nothing)
|
(buf_bytes, SessionInput::Nothing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue