From 97ec252a8dbc4be7fa896291e4ffee65df2c22ef Mon Sep 17 00:00:00 2001 From: snacj <0xsnacj@proton.me> Date: Wed, 15 Oct 2025 15:17:45 +0200 Subject: [PATCH] rebase and merge issue fixes --- control-core/src/machines/connection.rs | 2 +- server/src/machines/buffer1/mod.rs | 59 +++++++++---------------- server/src/machines/buffer1/new.rs | 5 ++- server/src/machines/winder2/api.rs | 9 +--- server/src/machines/winder2/mod.rs | 9 ++++ 5 files changed, 36 insertions(+), 48 deletions(-) diff --git a/control-core/src/machines/connection.rs b/control-core/src/machines/connection.rs index 94b2e366..ea585056 100644 --- a/control-core/src/machines/connection.rs +++ b/control-core/src/machines/connection.rs @@ -92,7 +92,7 @@ pub struct MachineCrossConnection< > { machine_manager: Weak>, machine_identification_unique: MachineIdentificationUnique, - connected_machine: Weak>>, + pub connected_machine: Weak>>, _make_compiler_happy: std::marker::PhantomData, // This marks tells the typechecker, that we // need F in our type arguemnts. We are ok with // it being used only in a fake field. Without diff --git a/server/src/machines/buffer1/mod.rs b/server/src/machines/buffer1/mod.rs index 7d2651de..7d11ee9f 100644 --- a/server/src/machines/buffer1/mod.rs +++ b/server/src/machines/buffer1/mod.rs @@ -9,6 +9,7 @@ use buffer_lift_controller::BufferLiftController; use control_core::{ converters::linear_step_converter::LinearStepConverter, machines::{ + connection::{CrossConnectableMachine, MachineConnection, MachineCrossConnection}, identification::{MachineIdentification, MachineIdentificationUnique}, manager::MachineManager, }, @@ -19,14 +20,10 @@ use control_core_derive::Machine; use ethercat_hal::io::{ digital_input::DigitalInput, stepper_velocity_el70x1::StepperVelocityEL70x1, }; -use futures::executor::block_on; use puller_speed_controller::PullerRegulationMode; use serde::{Deserialize, Serialize}; -use smol::lock::{Mutex, RwLock}; -use std::{ - sync::{Arc, Weak}, - time::Instant, -}; +use smol::lock::RwLock; +use std::{sync::Weak, time::Instant}; use uom::si::{ f64::{Length, Velocity}, length::millimeter, @@ -35,7 +32,7 @@ use uom::si::{ use crate::machines::{ MACHINE_BUFFER_V1, VENDOR_QITECH, buffer1::{ - api::{ConnectedMachineState, CurrentInputSpeedState, LiftState, PullerState}, + api::{CurrentInputSpeedState, LiftState, PullerState}, puller_speed_controller::PullerSpeedController, }, winder2::{BufferState, Winder2, Winder2Mode}, @@ -228,19 +225,29 @@ impl BufferV1 { } fn update_winder2_mode(&mut self, mode: Winder2Mode) { - self.get_winder(|winder2| { - if winder2.mode != mode { - winder2.mode = mode; + if let Some(slot) = self.get_cross_connection().connected_machine.upgrade() { + let slot = slot.lock_blocking(); + + if let MachineConnection::Connected(machine) = &slot.machine_connection { + let mut winder = machine.lock_blocking(); + if winder.mode != mode { + winder.mode = mode; + } } - }); + } } fn update_winder2_buffer_state(&mut self, state: BufferState) { - self.get_winder(|winder2| { - if winder2.buffer_state != state { - winder2.set_buffer_state(state); + if let Some(slot) = self.get_cross_connection().connected_machine.upgrade() { + let slot = slot.lock_blocking(); + + if let MachineConnection::Connected(machine) = &slot.machine_connection { + let mut winder = machine.lock_blocking(); + if winder.buffer_state != state { + winder.set_buffer_state(state); + } } - }); + } } // Turn off motor and do nothing @@ -433,28 +440,6 @@ impl BufferV1 { self.connected_winder.disconnect(); self.emit_state(); } - - /// This helper function provides an easy way - /// to get the machine out of the Weak Reference - /// - /// Usage: - /// - /// self.get_winder(|winder2| { - /// winder2.do_something // Use the Winder here as usual - /// }); - fn get_winder(&self, func: F) -> Option - where - F: FnOnce(&mut Winder2) -> R, - { - self.connected_winder - .as_ref()? - .machine - .upgrade() - .map(|winder_arc| { - let mut winder = block_on(winder_arc.lock()); - func(&mut winder) - }) - } } #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] diff --git a/server/src/machines/buffer1/new.rs b/server/src/machines/buffer1/new.rs index 637b5270..22a265b3 100644 --- a/server/src/machines/buffer1/new.rs +++ b/server/src/machines/buffer1/new.rs @@ -127,7 +127,6 @@ impl MachineNewTrait for BufferV1 { } // Controller - let buffer_lift_controller = BufferLiftController::new( let buffer_lift_controller = BufferLiftController::new( StepperVelocityEL70x1::new(el7041.clone(), EL7041_0052Port::STM1), Length::new::(135.0), @@ -151,7 +150,9 @@ impl MachineNewTrait for BufferV1 { 200, Length::new::(32.22), ), - namespace: Buffer1Namespace::new(params.socket_queue_tx.clone()), + namespace: Buffer1Namespace { + namespace: params.namespace.clone(), + }, last_measurement_emit: Instant::now(), mode: BufferV1Mode::Standby, buffer_lift_controller, diff --git a/server/src/machines/winder2/api.rs b/server/src/machines/winder2/api.rs index 90df4fd1..72e51cad 100644 --- a/server/src/machines/winder2/api.rs +++ b/server/src/machines/winder2/api.rs @@ -293,14 +293,7 @@ impl MachineApi for Winder2 { Mutation::GotoTraverseLimitInner => self.traverse_goto_limit_inner(), Mutation::GotoTraverseHome => self.traverse_goto_home(), Mutation::SetPullerRegulationMode(regulation) => self.puller_set_regulation(regulation), - Mutation::SetPullerTargetSpeed(value) => { - self.puller_set_target_speed(value); - if self.connected_buffer.is_some() { - self.get_buffer(|buffer| { - buffer.buffer_lift_controller.set_current_input_speed(value); - }); - } - } + Mutation::SetPullerTargetSpeed(value) => self.puller_set_target_speed(value), Mutation::SetPullerTargetDiameter(_) => todo!(), Mutation::SetPullerForward(value) => self.puller_set_forward(value), Mutation::SetSpoolRegulationMode(mode) => self.spool_set_regulation_mode(mode), diff --git a/server/src/machines/winder2/mod.rs b/server/src/machines/winder2/mod.rs index 2d381836..0291dfba 100644 --- a/server/src/machines/winder2/mod.rs +++ b/server/src/machines/winder2/mod.rs @@ -306,6 +306,15 @@ impl Winder2 { .angular_velocity_to_steps(angular_velocity); let _ = self.puller.set_speed(steps_per_second); } + + /// Implement Buffer + pub fn sync_buffer_speed(&mut self) { + todo!(); + } + + pub fn set_buffer_state(&mut self, state: BufferState) { + self.buffer_state = state; + } } #[derive(Debug, Clone, PartialEq, Eq)]