Compare commits

..

No commits in common. "026dd1ed9c058f38817a89d023490be77d578156" and "6e0cf26d6a88aa2078a6aa52331d8d9482a89089" have entirely different histories.

4 changed files with 18 additions and 46 deletions

View File

@ -6,19 +6,15 @@ from pytec.client import Client
TIME_WINDOW = 300.0
tec = Client()
target_temperature = tec.get_pid()[0]['target']
print("Channel 0 target temperature: {:.3f}".format(target_temperature))
class Series:
def __init__(self, conv=lambda x: x):
self.conv = conv
def __init__(self, scale=1.0):
self.scale = scale
self.x_data = []
self.y_data = []
def append(self, x, y):
self.x_data.append(x)
self.y_data.append(self.conv(y))
self.y_data.append(self.scale * y)
def clip(self, min_x):
drop = 0
@ -29,8 +25,8 @@ class Series:
series = {
'adc': Series(),
'sens': Series(lambda x: x * 0.0001),
'temperature': Series(lambda t: t - target_temperature),
'sens': Series(0.0001),
'temperature': Series(),
'i_set': Series(),
'pid_output': Series(),
'vref': Series(),
@ -59,6 +55,7 @@ def recv_data(tec):
if quit:
break
tec = Client()
thread = Thread(target=recv_data, args=(tec,))
thread.start()

View File

@ -1,8 +1,6 @@
import socket
import json
CHANNELS = 2
class Client:
def __init__(self, host="192.168.1.26", port=23, timeout=None):
self._socket = socket.create_connection((host, port), timeout)
@ -24,27 +22,6 @@ class Client:
self._lines = self._lines[1:]
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):
"""Start reporting measurement values

View File

@ -54,7 +54,7 @@ mod net;
mod server;
use server::Server;
mod session;
use session::{Session, SessionInput};
use session::{Session, SessionOutput};
mod command_parser;
use command_parser::{Command, ShowCommand, PwmPin};
mod timer;
@ -194,12 +194,10 @@ fn main() -> ! {
if ! socket.is_active() {
let _ = socket.listen(TCP_PORT);
session.reset();
} else if socket.may_send() && !socket.may_recv() {
socket.close()
} else if socket.can_send() && socket.can_recv() {
} else if socket.can_send() && socket.can_recv() && socket.send_capacity() - socket.send_queue() > 1024 {
match socket.recv(|buf| session.feed(buf)) {
Ok(SessionInput::Nothing) => {}
Ok(SessionInput::Command(command)) => match command {
Ok(SessionOutput::Nothing) => {}
Ok(SessionOutput::Command(command)) => match command {
Command::Quit =>
socket.close(),
Command::Reporting(reporting) => {
@ -415,7 +413,7 @@ fn main() -> ! {
SCB::sys_reset();
}
}
Ok(SessionInput::Error(e)) => {
Ok(SessionOutput::Error(e)) => {
let _ = writeln!(socket, "Command error: {:?}", e);
}
Err(_) =>

View File

@ -38,16 +38,16 @@ impl LineReader {
}
}
pub enum SessionInput {
pub enum SessionOutput {
Nothing,
Command(Command),
Error(ParserError),
}
impl From<Result<Command, ParserError>> for SessionInput {
impl From<Result<Command, ParserError>> for SessionOutput {
fn from(input: Result<Command, ParserError>) -> Self {
input.map(SessionInput::Command)
.unwrap_or_else(SessionInput::Error)
input.map(SessionOutput::Command)
.unwrap_or_else(SessionOutput::Error)
}
}
@ -106,7 +106,7 @@ impl Session {
self.report_pending[channel] = false;
}
pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionInput) {
pub fn feed(&mut self, buf: &[u8]) -> (usize, SessionOutput) {
let mut buf_bytes = 0;
for (i, b) in buf.iter().enumerate() {
buf_bytes = i + 1;
@ -125,6 +125,6 @@ impl Session {
None => {}
}
}
(buf_bytes, SessionInput::Nothing)
(buf_bytes, SessionOutput::Nothing)
}
}