forked from M-Labs/kirdy
cmd: Add active report mode cmd
This commit is contained in:
parent
0642640da7
commit
5f83b73011
|
@ -6,6 +6,7 @@ use crate::laser_diode::ld_pwr_exc_protector::{LdPwrExcProtector, self};
|
||||||
use crate::laser_diode::pd_responsitivity;
|
use crate::laser_diode::pd_responsitivity;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use crate::device::sys_timer::sleep;
|
use crate::device::sys_timer::sleep;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use uom::si::{
|
use uom::si::{
|
||||||
electric_current::milliampere,
|
electric_current::milliampere,
|
||||||
|
@ -67,6 +68,16 @@ impl Default for Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
||||||
|
pub struct StatusReport {
|
||||||
|
pwr_engaged: bool,
|
||||||
|
pwr_excursion: bool,
|
||||||
|
ld_i_set: ElectricCurrent,
|
||||||
|
pd_i: ElectricCurrent,
|
||||||
|
pd_pwr: Power,
|
||||||
|
term_status: Impedance,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct LdDrive{
|
pub struct LdDrive{
|
||||||
ctrl: LdCtrl,
|
ctrl: LdCtrl,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
|
@ -120,6 +131,10 @@ impl LdDrive{
|
||||||
LdPwrExcProtector::get_status().v * Settings::PD_MON_TRANSCONDUCTANCE
|
LdPwrExcProtector::get_status().v * Settings::PD_MON_TRANSCONDUCTANCE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_pd_pwr(&mut self) -> Power {
|
||||||
|
self.settings.pd_responsitivity.get_ld_pwr_from_ld_i(LdPwrExcProtector::get_status().v * Settings::PD_MON_TRANSCONDUCTANCE)
|
||||||
|
}
|
||||||
|
|
||||||
// Ramping up or down laser diode current according to preset current step size and time step.
|
// Ramping up or down laser diode current according to preset current step size and time step.
|
||||||
pub fn ld_set_i(&mut self, i: ElectricCurrent) -> ElectricCurrent {
|
pub fn ld_set_i(&mut self, i: ElectricCurrent) -> ElectricCurrent {
|
||||||
let mut prev_i_set = self.settings.ld_drive_current;
|
let mut prev_i_set = self.settings.ld_drive_current;
|
||||||
|
@ -178,4 +193,15 @@ impl LdDrive{
|
||||||
pub fn get_term_status(&mut self) -> Impedance {
|
pub fn get_term_status(&mut self) -> Impedance {
|
||||||
self.ctrl.get_lf_mod_in_impedance()
|
self.ctrl.get_lf_mod_in_impedance()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_status_report(&mut self) -> StatusReport {
|
||||||
|
StatusReport {
|
||||||
|
pwr_engaged: LdPwrExcProtector::get_status().pwr_engaged,
|
||||||
|
pwr_excursion: LdPwrExcProtector::get_status().pwr_excursion,
|
||||||
|
ld_i_set: self.settings.ld_drive_current,
|
||||||
|
pd_i: self.get_pd_i(),
|
||||||
|
pd_pwr: self.get_pd_pwr(),
|
||||||
|
term_status: self.get_term_status(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Input, Output, PushPull},
|
gpio::{gpioa::*, gpiob::*, gpiod::*, Alternate, Input, Output, PushPull},
|
||||||
hal::{blocking::spi::Transfer, digital::{v2::OutputPin, v2::InputPin}},
|
hal::{blocking::spi::Transfer, digital::{v2::OutputPin, v2::InputPin}},
|
||||||
|
@ -13,7 +14,7 @@ use uom::si::{
|
||||||
use crate::laser_diode::max5719::{self, Dac};
|
use crate::laser_diode::max5719::{self, Dac};
|
||||||
use crate::laser_diode::laser_diode::TransimpedanceUnit;
|
use crate::laser_diode::laser_diode::TransimpedanceUnit;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
|
||||||
pub enum Impedance {
|
pub enum Impedance {
|
||||||
Is50Ohm,
|
Is50Ohm,
|
||||||
Not50Ohm,
|
Not50Ohm,
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -34,6 +34,10 @@ use panic_halt as _;
|
||||||
|
|
||||||
static mut ETH_DATA_BUFFER: [u8; 1024] = [0; 1024];
|
static mut ETH_DATA_BUFFER: [u8; 1024] = [0; 1024];
|
||||||
|
|
||||||
|
pub struct DeviceSettings{
|
||||||
|
report_readings: bool,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
@ -80,6 +84,10 @@ fn main() -> ! {
|
||||||
|
|
||||||
let mut should_reset = false;
|
let mut should_reset = false;
|
||||||
|
|
||||||
|
let mut device_settings = DeviceSettings {
|
||||||
|
report_readings: false,
|
||||||
|
};
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
wd.feed();
|
wd.feed();
|
||||||
|
|
||||||
|
@ -98,6 +106,15 @@ fn main() -> ! {
|
||||||
info!("power_excursion: {:?}", laser.pd_mon_status().pwr_excursion);
|
info!("power_excursion: {:?}", laser.pd_mon_status().pwr_excursion);
|
||||||
|
|
||||||
info!("Termination Status: {:?}", laser.get_term_status());
|
info!("Termination Status: {:?}", laser.get_term_status());
|
||||||
|
|
||||||
|
if net::net::eth_is_socket_active() {
|
||||||
|
if device_settings.report_readings {
|
||||||
|
unsafe {
|
||||||
|
net::cmd_handler::send_ld_readings(&mut ETH_DATA_BUFFER, &mut laser);
|
||||||
|
net::cmd_handler::send_tec_readings(&mut ETH_DATA_BUFFER, &mut thermostat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if net::net::eth_is_socket_active() {
|
if net::net::eth_is_socket_active() {
|
||||||
|
@ -114,10 +131,13 @@ fn main() -> ! {
|
||||||
});
|
});
|
||||||
let bytes = net::net::eth_recv(&mut ETH_DATA_BUFFER);
|
let bytes = net::net::eth_recv(&mut ETH_DATA_BUFFER);
|
||||||
debug!("Number of bytes recv: {:?}", bytes);
|
debug!("Number of bytes recv: {:?}", bytes);
|
||||||
(laser, thermostat, should_reset) = net::cmd_handler::execute_cmd(&mut ETH_DATA_BUFFER, bytes, laser, thermostat);
|
(laser, thermostat, should_reset, device_settings) = net::cmd_handler::execute_cmd(&mut ETH_DATA_BUFFER, bytes, laser, thermostat, device_settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
device_settings.report_readings = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Should reset, close all TCP sockets.
|
// Should reset, close all TCP sockets.
|
||||||
let mut any_socket_alive = false;
|
let mut any_socket_alive = false;
|
||||||
|
|
|
@ -7,17 +7,24 @@ use uom::si::{
|
||||||
electrical_resistance::{ElectricalResistance, ohm},
|
electrical_resistance::{ElectricalResistance, ohm},
|
||||||
f64::ThermodynamicTemperature, thermodynamic_temperature::degree_celsius
|
f64::ThermodynamicTemperature, thermodynamic_temperature::degree_celsius
|
||||||
};
|
};
|
||||||
use crate::{laser_diode::laser_diode::LdDrive, net::net, thermostat::thermostat::StatusReport};
|
use crate::{laser_diode::laser_diode::{
|
||||||
|
LdDrive, StatusReport as LdStatusReport
|
||||||
|
},
|
||||||
|
net::net,
|
||||||
|
thermostat::thermostat::StatusReport as TecStatusReport
|
||||||
|
};
|
||||||
use crate::thermostat::thermostat::Thermostat;
|
use crate::thermostat::thermostat::Thermostat;
|
||||||
use crate::thermostat::pid_state::PidSettings::*;
|
use crate::thermostat::pid_state::PidSettings::*;
|
||||||
use crate::device::dfu;
|
use crate::device::dfu;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
use crate::DeviceSettings;
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
||||||
enum DeviceCmd {
|
enum DeviceCmd {
|
||||||
#[default]
|
#[default]
|
||||||
Reserved,
|
Reserved,
|
||||||
Dfu
|
ReportStatus,
|
||||||
|
Dfu,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Default, Debug)]
|
||||||
|
@ -79,6 +86,7 @@ pub struct CmdJsonObj{
|
||||||
laser_diode_cmd: Option<LdCmdEnum>,
|
laser_diode_cmd: Option<LdCmdEnum>,
|
||||||
thermostat_cmd: Option<ThermostatCmdEnum>,
|
thermostat_cmd: Option<ThermostatCmdEnum>,
|
||||||
device_cmd: Option<DeviceCmd>,
|
device_cmd: Option<DeviceCmd>,
|
||||||
|
data_bool: Option<bool>,
|
||||||
data_f32: Option<f32>,
|
data_f32: Option<f32>,
|
||||||
data_f64: Option<f64>,
|
data_f64: Option<f64>,
|
||||||
}
|
}
|
||||||
|
@ -87,12 +95,33 @@ pub struct Cmd {
|
||||||
json: CmdJsonObj
|
json: CmdJsonObj
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
||||||
pub struct StatusReportStruct {
|
pub struct TecStatusReportStruct {
|
||||||
json: StatusReport
|
json: TecStatusReport
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mut tec: Thermostat)->(LdDrive, Thermostat, bool){
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
||||||
|
pub struct LaserStatusReportStruct {
|
||||||
|
json: LdStatusReport
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_ld_readings(buffer: &mut [u8], laser: &mut LdDrive){
|
||||||
|
let status_report = LaserStatusReportStruct {
|
||||||
|
json: laser.get_status_report()
|
||||||
|
};
|
||||||
|
let num_bytes = status_report.get_json("/json", buffer).unwrap();
|
||||||
|
net::eth_send(buffer, num_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_tec_readings(buffer: &mut [u8], tec: &mut Thermostat){
|
||||||
|
let status_report = TecStatusReportStruct {
|
||||||
|
json: tec.get_status_report()
|
||||||
|
};
|
||||||
|
let num_bytes = status_report.get_json("/json", buffer).unwrap();
|
||||||
|
net::eth_send(buffer, num_bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mut tec: Thermostat, mut device_settings: DeviceSettings)->(LdDrive, Thermostat, bool, DeviceSettings){
|
||||||
let mut should_reset = false;
|
let mut should_reset = false;
|
||||||
|
|
||||||
let mut cmd = Cmd {
|
let mut cmd = Cmd {
|
||||||
|
@ -111,6 +140,16 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
|
||||||
}
|
}
|
||||||
should_reset = true;
|
should_reset = true;
|
||||||
}
|
}
|
||||||
|
Some(DeviceCmd::ReportStatus) => {
|
||||||
|
match cmd.json.data_bool{
|
||||||
|
Some(val) => {
|
||||||
|
device_settings.report_readings = val;
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
info!("Wrong Data type is received")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
None => { /* Do Nothing */}
|
None => { /* Do Nothing */}
|
||||||
_ => {
|
_ => {
|
||||||
info!("Unimplemented Command")
|
info!("Unimplemented Command")
|
||||||
|
@ -176,7 +215,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
}
|
}
|
||||||
Some(LdCmdEnum::GetLdStatus) => {
|
Some(LdCmdEnum::GetLdStatus) => {
|
||||||
info!("Not supported Yet")
|
send_ld_readings(buffer, &mut laser);
|
||||||
}
|
}
|
||||||
Some(LdCmdEnum::GetAlramStatus) => {
|
Some(LdCmdEnum::GetAlramStatus) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
|
@ -334,11 +373,7 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(ThermostatCmdEnum::GetTecStatus) => {
|
Some(ThermostatCmdEnum::GetTecStatus) => {
|
||||||
let status_report = StatusReportStruct {
|
send_tec_readings(buffer, &mut tec);
|
||||||
json: tec.get_status_report()
|
|
||||||
};
|
|
||||||
let num_bytes = status_report.get_json("/json", buffer).unwrap();
|
|
||||||
net::eth_send(buffer, num_bytes);
|
|
||||||
}
|
}
|
||||||
Some(ThermostatCmdEnum::GetPidStatus) => {
|
Some(ThermostatCmdEnum::GetPidStatus) => {
|
||||||
info!("Not supported Yet")
|
info!("Not supported Yet")
|
||||||
|
@ -356,5 +391,5 @@ pub fn execute_cmd(buffer: &mut [u8], buffer_size: usize, mut laser: LdDrive, mu
|
||||||
info!("Invalid Command: {:?}", err);
|
info!("Invalid Command: {:?}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(laser, tec, should_reset)
|
(laser, tec, should_reset, device_settings)
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,7 +338,7 @@ impl Thermostat{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Default, Tree)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Tree)]
|
||||||
pub struct StatusReport {
|
pub struct StatusReport {
|
||||||
ts: u32,
|
ts: u32,
|
||||||
pid_engaged: bool,
|
pid_engaged: bool,
|
||||||
|
|
Loading…
Reference in New Issue