Compare commits
8 Commits
766c37ab96
...
d7462e6791
Author | SHA1 | Date |
---|---|---|
atse | d7462e6791 | |
atse | 6cd6a6a2c2 | |
atse | b93e2fbb7b | |
atse | 76b95f66e0 | |
atse | 8008870bc1 | |
atse | 7646ff9037 | |
atse | 6f81a63d12 | |
atse | 78012f6fdd |
|
@ -327,10 +327,10 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "panic-abort"
|
name = "panic-halt"
|
||||||
version = "0.3.2"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4e20e6499bbbc412f280b04a42346b356c6fa0753d5fd22b7bd752ff34c778ee"
|
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "panic-semihosting"
|
name = "panic-semihosting"
|
||||||
|
@ -563,7 +563,7 @@ dependencies = [
|
||||||
"nb 1.0.0",
|
"nb 1.0.0",
|
||||||
"nom",
|
"nom",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"panic-abort",
|
"panic-halt",
|
||||||
"panic-semihosting",
|
"panic-semihosting",
|
||||||
"serde",
|
"serde",
|
||||||
"serde-json-core",
|
"serde-json-core",
|
||||||
|
|
|
@ -7,14 +7,14 @@ authors = ["Astro <astro@spaceboyz.net>"]
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
keywords = ["thermostat", "laser", "physics"]
|
keywords = ["thermostat", "laser", "physics"]
|
||||||
repository = "https://git.m-labs.hk/M-Labs/thermostat"
|
repository = "https://git.m-labs.hk/M-Labs/thermostat"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = []
|
features = []
|
||||||
default-target = "thumbv7em-none-eabihf"
|
default-target = "thumbv7em-none-eabihf"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
panic-abort = "0.3"
|
panic-halt = "0.2"
|
||||||
panic-semihosting = { version = "0.5", optional = true }
|
panic-semihosting = { version = "0.5", optional = true }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
bare-metal = "1"
|
bare-metal = "1"
|
||||||
|
|
|
@ -29,7 +29,7 @@ Alternatively, you can install the Rust toolchain without Nix using rustup; see
|
||||||
|
|
||||||
Connect SWDIO/SWCLK/RST/GND to a programmer such as ST-Link v2.1. Run OpenOCD:
|
Connect SWDIO/SWCLK/RST/GND to a programmer such as ST-Link v2.1. Run OpenOCD:
|
||||||
```shell
|
```shell
|
||||||
openocd -f interface/stlink-v2-1.cfg -f target/stm32f4x.cfg
|
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
|
||||||
```
|
```
|
||||||
|
|
||||||
You may need to power up the programmer before powering the device.
|
You may need to power up the programmer before powering the device.
|
||||||
|
@ -64,7 +64,7 @@ On a Windows machine install [st.com](https://st.com) DfuSe USB device firmware
|
||||||
|
|
||||||
### OpenOCD
|
### OpenOCD
|
||||||
```shell
|
```shell
|
||||||
openocd -f interface/stlink-v2-1.cfg -f target/stm32f4x.cfg -c "program target/thumbv7em-none-eabihf/release/thermostat verify reset;exit"
|
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg -c "program target/thumbv7em-none-eabihf/release/thermostat verify reset;exit"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Network
|
## Network
|
||||||
|
@ -115,7 +115,7 @@ formatted as line-delimited JSON.
|
||||||
| `pid <0/1> output_min <amp>` | Set mininum output |
|
| `pid <0/1> output_min <amp>` | Set mininum output |
|
||||||
| `pid <0/1> output_max <amp>` | Set maximum output |
|
| `pid <0/1> output_max <amp>` | Set maximum output |
|
||||||
| `b-p` | Show B-Parameter equation parameters |
|
| `b-p` | Show B-Parameter equation parameters |
|
||||||
| `b-p <0/1> <t0/b/r0> <value>` | Set B-Parameter parameter for a channel |
|
| `b-p <0/1> <t0/b/r0> <value>` | Set B-Parameter for a channel |
|
||||||
| `postfilter` | Show postfilter settings |
|
| `postfilter` | Show postfilter settings |
|
||||||
| `postfilter <0/1> off` | Disable postfilter |
|
| `postfilter <0/1> off` | Disable postfilter |
|
||||||
| `postfilter <0/1> rate <rate>` | Set postfilter output data rate |
|
| `postfilter <0/1> rate <rate>` | Set postfilter output data rate |
|
||||||
|
|
11
flake.nix
11
flake.nix
|
@ -8,8 +8,8 @@
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
|
pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ (import mozilla-overlay) ]; };
|
||||||
rustManifest = pkgs.fetchurl {
|
rustManifest = pkgs.fetchurl {
|
||||||
url = "https://static.rust-lang.org/dist/2021-10-26/channel-rust-nightly.toml";
|
url = "https://static.rust-lang.org/dist/2022-12-15/channel-rust-stable.toml";
|
||||||
sha256 = "sha256-1hLbypXA+nuH7o3AHCokzSBZAvQxvef4x9+XxO3aBao=";
|
hash = "sha256-S7epLlflwt0d1GZP44u5Xosgf6dRrmr8xxC+Ml2Pq7c=";
|
||||||
};
|
};
|
||||||
|
|
||||||
targets = [
|
targets = [
|
||||||
|
@ -22,12 +22,12 @@
|
||||||
inherit targets;
|
inherit targets;
|
||||||
extensions = ["rust-src"];
|
extensions = ["rust-src"];
|
||||||
};
|
};
|
||||||
rust = rustChannelOfTargets "nightly" null targets;
|
rust = rustChannelOfTargets "stable" null targets;
|
||||||
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
|
rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
|
||||||
rustc = rust;
|
rustc = rust;
|
||||||
cargo = rust;
|
cargo = rust;
|
||||||
});
|
});
|
||||||
thermostat = rustPlatform.buildRustPackage rec {
|
thermostat = rustPlatform.buildRustPackage {
|
||||||
name = "thermostat";
|
name = "thermostat";
|
||||||
version = "0.0.0";
|
version = "0.0.0";
|
||||||
|
|
||||||
|
@ -67,8 +67,7 @@
|
||||||
devShell.x86_64-linux = pkgs.mkShell {
|
devShell.x86_64-linux = pkgs.mkShell {
|
||||||
name = "thermostat-dev-shell";
|
name = "thermostat-dev-shell";
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
rustc cargo
|
rust openocd dfu-util
|
||||||
openocd dfu-util
|
|
||||||
] ++ (with python3Packages; [
|
] ++ (with python3Packages; [
|
||||||
numpy matplotlib
|
numpy matplotlib
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Client:
|
||||||
return self._get_conf("pid")
|
return self._get_conf("pid")
|
||||||
|
|
||||||
def get_b_parameter(self):
|
def get_b_parameter(self):
|
||||||
"""Retrieve B-Parameter parameters for resistance to temperature conversion
|
"""Retrieve B-Parameter equation parameters for resistance to temperature conversion
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
[{'params': {'b': 3800.0, 'r0': 10000.0, 't0': 298.15}, 'channel': 0},
|
[{'params': {'b': 3800.0, 'r0': 10000.0, 't0': 298.15}, 'channel': 0},
|
||||||
|
|
|
@ -15,10 +15,10 @@ use serde::{Deserialize, Serialize};
|
||||||
pub struct Parameters {
|
pub struct Parameters {
|
||||||
/// Base temperature
|
/// Base temperature
|
||||||
pub t0: ThermodynamicTemperature,
|
pub t0: ThermodynamicTemperature,
|
||||||
/// Base resistance
|
/// Thermistor resistance at base temperature
|
||||||
pub r0: ElectricalResistance,
|
pub r0: ElectricalResistance,
|
||||||
/// Beta
|
/// B, the average slope of the function ln R vs. 1/T
|
||||||
pub b: f64,
|
pub b: ThermodynamicTemperature,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parameters {
|
impl Parameters {
|
||||||
|
|
|
@ -13,7 +13,6 @@ use super::{
|
||||||
PwmPin,
|
PwmPin,
|
||||||
BpParameter
|
BpParameter
|
||||||
},
|
},
|
||||||
leds::Leds,
|
|
||||||
ad7172,
|
ad7172,
|
||||||
CHANNEL_CONFIG_KEY,
|
CHANNEL_CONFIG_KEY,
|
||||||
channels::{
|
channels::{
|
||||||
|
@ -176,13 +175,13 @@ impl Handler {
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn engage_pid (socket: &mut TcpSocket, channels: &mut Channels, leds: &mut Leds, channel: usize) -> Result<Handler, Error> {
|
fn engage_pid (socket: &mut TcpSocket, channels: &mut Channels, channel: usize) -> Result<Handler, Error> {
|
||||||
channels.channel_state(channel).pid_engaged = true;
|
channels.channel_state(channel).pid_engaged = true;
|
||||||
send_line(socket, b"{}");
|
send_line(socket, b"{}");
|
||||||
Ok(Handler::Handled)
|
Ok(Handler::Handled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_pwm (socket: &mut TcpSocket, channels: &mut Channels, leds: &mut Leds, channel: usize, pin: PwmPin, value: f64) -> Result<Handler, Error> {
|
fn set_pwm (socket: &mut TcpSocket, channels: &mut Channels, channel: usize, pin: PwmPin, value: f64) -> Result<Handler, Error> {
|
||||||
match pin {
|
match pin {
|
||||||
PwmPin::ISet => {
|
PwmPin::ISet => {
|
||||||
channels.channel_state(channel).pid_engaged = false;
|
channels.channel_state(channel).pid_engaged = false;
|
||||||
|
@ -413,7 +412,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_command(command: Command, socket: &mut TcpSocket, channels: &mut Channels, session: &Session, leds: &mut Leds, store: &mut FlashStore, ipv4_config: &mut Ipv4Config, fan_ctrl: &mut FanCtrl, hwrev: HWRev) -> Result<Self, Error> {
|
pub fn handle_command(command: Command, socket: &mut TcpSocket, channels: &mut Channels, session: &Session, store: &mut FlashStore, ipv4_config: &mut Ipv4Config, fan_ctrl: &mut FanCtrl, hwrev: HWRev) -> Result<Self, Error> {
|
||||||
match command {
|
match command {
|
||||||
Command::Quit => Ok(Handler::CloseSocket),
|
Command::Quit => Ok(Handler::CloseSocket),
|
||||||
Command::Reporting(_reporting) => Handler::reporting(socket),
|
Command::Reporting(_reporting) => Handler::reporting(socket),
|
||||||
|
@ -424,8 +423,8 @@ impl Handler {
|
||||||
Command::Show(ShowCommand::BParameter) => Handler::show_b_parameter(socket, channels),
|
Command::Show(ShowCommand::BParameter) => Handler::show_b_parameter(socket, channels),
|
||||||
Command::Show(ShowCommand::PostFilter) => Handler::show_post_filter(socket, channels),
|
Command::Show(ShowCommand::PostFilter) => Handler::show_post_filter(socket, channels),
|
||||||
Command::Show(ShowCommand::Ipv4) => Handler::show_ipv4(socket, ipv4_config),
|
Command::Show(ShowCommand::Ipv4) => Handler::show_ipv4(socket, ipv4_config),
|
||||||
Command::PwmPid { channel } => Handler::engage_pid(socket, channels, leds, channel),
|
Command::PwmPid { channel } => Handler::engage_pid(socket, channels, channel),
|
||||||
Command::Pwm { channel, pin, value } => Handler::set_pwm(socket, channels, leds, channel, pin, value),
|
Command::Pwm { channel, pin, value } => Handler::set_pwm(socket, channels, channel, pin, value),
|
||||||
Command::CenterPoint { channel, center } => Handler::set_center_point(socket, channels, channel, center),
|
Command::CenterPoint { channel, center } => Handler::set_center_point(socket, channels, channel, center),
|
||||||
Command::Pid { channel, parameter, value } => Handler::set_pid(socket, channels, channel, parameter, value),
|
Command::Pid { channel, parameter, value } => Handler::set_pid(socket, channels, channel, parameter, value),
|
||||||
Command::BParameter { channel, parameter, value } => Handler::set_b_parameter(socket, channels, channel, parameter, value),
|
Command::BParameter { channel, parameter, value } => Handler::set_b_parameter(socket, channels, channel, parameter, value),
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use core::arch::asm;
|
||||||
use cortex_m_rt::pre_init;
|
use cortex_m_rt::pre_init;
|
||||||
use stm32f4xx_hal::stm32::{RCC, SYSCFG};
|
use stm32f4xx_hal::stm32::{RCC, SYSCFG};
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
#![cfg_attr(not(test), no_std)]
|
#![cfg_attr(not(test), no_std)]
|
||||||
#![cfg_attr(not(test), no_main)]
|
#![cfg_attr(not(test), no_main)]
|
||||||
#![feature(maybe_uninit_extra, asm)]
|
|
||||||
#![cfg_attr(test, allow(unused))]
|
#![cfg_attr(test, allow(unused))]
|
||||||
// TODO: #![deny(warnings, unused)]
|
// TODO: #![deny(warnings, unused)]
|
||||||
|
|
||||||
#[cfg(not(any(feature = "semihosting", test)))]
|
#[cfg(not(any(feature = "semihosting", test)))]
|
||||||
use panic_abort as _;
|
use panic_halt as _;
|
||||||
#[cfg(all(feature = "semihosting", not(test)))]
|
#[cfg(all(feature = "semihosting", not(test)))]
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
|
||||||
|
@ -217,7 +216,7 @@ fn main() -> ! {
|
||||||
// Do nothing and feed more data to the line reader in the next loop cycle.
|
// Do nothing and feed more data to the line reader in the next loop cycle.
|
||||||
Ok(SessionInput::Nothing) => {}
|
Ok(SessionInput::Nothing) => {}
|
||||||
Ok(SessionInput::Command(command)) => {
|
Ok(SessionInput::Command(command)) => {
|
||||||
match Handler::handle_command(command, &mut socket, &mut channels, session, &mut leds, &mut store, &mut ipv4_config, &mut fan_ctrl, hwrev) {
|
match Handler::handle_command(command, &mut socket, &mut channels, session, &mut store, &mut ipv4_config, &mut fan_ctrl, hwrev) {
|
||||||
Ok(Handler::NewIPV4(ip)) => new_ipv4_config = Some(ip),
|
Ok(Handler::NewIPV4(ip)) => new_ipv4_config = Some(ip),
|
||||||
Ok(Handler::Handled) => {},
|
Ok(Handler::Handled) => {},
|
||||||
Ok(Handler::CloseSocket) => socket.close(),
|
Ok(Handler::CloseSocket) => socket.close(),
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use core::mem::MaybeUninit;
|
|
||||||
use smoltcp::{
|
use smoltcp::{
|
||||||
iface::EthernetInterface,
|
iface::EthernetInterface,
|
||||||
socket::{SocketSet, SocketHandle, TcpSocket, TcpSocketBuffer, SocketRef},
|
socket::{SocketSet, SocketHandle, TcpSocket, TcpSocketBuffer, SocketRef},
|
||||||
|
@ -13,6 +12,18 @@ pub struct SocketState<S> {
|
||||||
state: S,
|
state: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, S: Default> SocketState<S>{
|
||||||
|
fn new(sockets: &mut SocketSet<'a>, tcp_rx_storage: &'a mut [u8; TCP_RX_BUFFER_SIZE], tcp_tx_storage: &'a mut [u8; TCP_TX_BUFFER_SIZE]) -> SocketState<S> {
|
||||||
|
let tcp_rx_buffer = TcpSocketBuffer::new(&mut tcp_rx_storage[..]);
|
||||||
|
let tcp_tx_buffer = TcpSocketBuffer::new(&mut tcp_tx_storage[..]);
|
||||||
|
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
|
||||||
|
SocketState::<S> {
|
||||||
|
handle: sockets.add(tcp_socket),
|
||||||
|
state: S::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Number of server sockets and therefore concurrent client
|
/// Number of server sockets and therefore concurrent client
|
||||||
/// sessions. Many data structures in `Server::run()` correspond to
|
/// sessions. Many data structures in `Server::run()` correspond to
|
||||||
/// this const.
|
/// this const.
|
||||||
|
@ -35,28 +46,27 @@ impl<'a, 'b, S: Default> Server<'a, 'b, S> {
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Server<'a, '_, S>),
|
F: FnOnce(&mut Server<'a, '_, S>),
|
||||||
{
|
{
|
||||||
let mut sockets_storage: [_; SOCKET_COUNT] = Default::default();
|
macro_rules! create_rtx_storage {
|
||||||
let mut sockets = SocketSet::new(&mut sockets_storage[..]);
|
($rx_storage:ident, $tx_storage:ident) => {
|
||||||
let mut states: [SocketState<S>; SOCKET_COUNT] = unsafe { MaybeUninit::uninit().assume_init() };
|
|
||||||
|
|
||||||
macro_rules! create_socket {
|
|
||||||
($set:ident, $rx_storage:ident, $tx_storage:ident, $target:expr) => {
|
|
||||||
let mut $rx_storage = [0; TCP_RX_BUFFER_SIZE];
|
let mut $rx_storage = [0; TCP_RX_BUFFER_SIZE];
|
||||||
let mut $tx_storage = [0; TCP_TX_BUFFER_SIZE];
|
let mut $tx_storage = [0; TCP_TX_BUFFER_SIZE];
|
||||||
let tcp_rx_buffer = TcpSocketBuffer::new(&mut $rx_storage[..]);
|
|
||||||
let tcp_tx_buffer = TcpSocketBuffer::new(&mut $tx_storage[..]);
|
|
||||||
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
|
|
||||||
$target = $set.add(tcp_socket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
create_socket!(sockets, tcp_rx_storage0, tcp_tx_storage0, states[0].handle);
|
|
||||||
create_socket!(sockets, tcp_rx_storage1, tcp_tx_storage1, states[1].handle);
|
|
||||||
create_socket!(sockets, tcp_rx_storage2, tcp_tx_storage2, states[2].handle);
|
|
||||||
create_socket!(sockets, tcp_rx_storage3, tcp_tx_storage3, states[3].handle);
|
|
||||||
|
|
||||||
for state in &mut states {
|
create_rtx_storage!(tcp_rx_storage0, tcp_tx_storage0);
|
||||||
state.state = S::default();
|
create_rtx_storage!(tcp_rx_storage1, tcp_tx_storage1);
|
||||||
}
|
create_rtx_storage!(tcp_rx_storage2, tcp_tx_storage2);
|
||||||
|
create_rtx_storage!(tcp_rx_storage3, tcp_tx_storage3);
|
||||||
|
|
||||||
|
let mut sockets_storage: [_; SOCKET_COUNT] = Default::default();
|
||||||
|
let mut sockets = SocketSet::new(&mut sockets_storage[..]);
|
||||||
|
|
||||||
|
let states: [SocketState<S>; SOCKET_COUNT] = [
|
||||||
|
SocketState::<S>::new(&mut sockets, &mut tcp_rx_storage0, &mut tcp_tx_storage0),
|
||||||
|
SocketState::<S>::new(&mut sockets, &mut tcp_rx_storage1, &mut tcp_tx_storage1),
|
||||||
|
SocketState::<S>::new(&mut sockets, &mut tcp_rx_storage2, &mut tcp_tx_storage2),
|
||||||
|
SocketState::<S>::new(&mut sockets, &mut tcp_rx_storage3, &mut tcp_tx_storage3),
|
||||||
|
];
|
||||||
|
|
||||||
let mut server = Server {
|
let mut server = Server {
|
||||||
states,
|
states,
|
||||||
|
|
Loading…
Reference in New Issue