Skip to content

Commit

Permalink
minor bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9849 committed Dec 15, 2024
1 parent c998e30 commit d810eab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public double getConvertRuntimeToMl(int runtime) {
}

public void shutdownDriver() {
if(this.isCanPump() && this.getMotorDriver() != null) {
if(this.motorDriver != null) {
this.motorDriver.shutdown();
this.motorDriver = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setAcceleration(Integer acceleration) {
}

public void shutdownDriver() {
if(this.isCanPump() && this.getMotorDriver() != null) {
if(this.stepperDriver != null) {
this.stepperDriver.shutdown();
this.stepperDriver = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ValveDriver getMotorDriver() {

@Override
public void shutdownDriver() {
if(this.isCanPump() && this.getMotorDriver() != null) {
if(this.motorDriver != null) {
this.motorDriver.shutdown();
this.motorDriver = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

@Service
@Transactional
Expand Down Expand Up @@ -58,7 +59,7 @@ public class PumpMaintenanceService {
private Map<Long, PumpJobState> lastState = new HashMap<>();
private Direction direction = Direction.FORWARD;
private IOutputPin directionPin;
private boolean loadCellOccupied = false;
private AtomicInteger loadCellOccupied = new AtomicInteger(0);

public synchronized void postConstruct() {
configureReversePumpSettings(true);
Expand Down Expand Up @@ -88,7 +89,7 @@ public synchronized void stopAllPumps() {
for (Pump pump : pumps) {
cancelByPumpId(pump.getId());
if (pump.isCanPump()) {
pump.shutdownDriver();
pump.getMotorDriver().shutdown();
}
}
}
Expand Down Expand Up @@ -175,7 +176,8 @@ public synchronized long dispatchPumpJob(Pump pump, PumpAdvice advice, Runnable
|| advice.getType() == PumpAdvice.Type.PUMP_DOWN;

if (pump instanceof DcPump dcPump) {
if(loadCellOccupied) {
if(loadCellOccupied.get() > 0) {
callback.run();
throw new IllegalArgumentException("Load cell occupied! A valve is running that requires genuine load cell data!");
}
long timeToRun = 0;
Expand Down Expand Up @@ -210,7 +212,8 @@ public synchronized long dispatchPumpJob(Pump pump, PumpAdvice advice, Runnable


} else if (pump instanceof StepperPump stepperPump) {
if(loadCellOccupied) {
if(loadCellOccupied.get() > 0) {
callback.run();
throw new IllegalArgumentException("Load cell occupied! A valve is running that requires genuine load cell data!");
}
long stepsToRun = 0;
Expand Down Expand Up @@ -241,36 +244,47 @@ public synchronized long dispatchPumpJob(Pump pump, PumpAdvice advice, Runnable

} else if (pump instanceof Valve valve) {
long mlToPump;
boolean requireLoadCell = false;
switch (advice.getType()) {
case PUMP_ML:
mlToPump = advice.getAmount();
if(anyPumpsRunning()) {
callback.run();
throw new IllegalArgumentException("Load cell occupied! Other pumps are running currently.");
}
requireLoadCell = true;
mlToPump = advice.getAmount();
break;
case PUMP_UP:
if(anyPumpsRunning()) {
callback.run();
throw new IllegalArgumentException("Load cell occupied! Other pumps are running currently.");
}
requireLoadCell = true;
mlToPump = Math.round(valve.getTubeCapacityInMl());
break;
case RUN:
if(loadCellOccupied) {
if(loadCellOccupied.get() > 0) {
callback.run();
throw new IllegalArgumentException("Load cell occupied! A valve is running that requires genuine load cell data!");
}
mlToPump = Long.MAX_VALUE;
break;
default:
callback.run();
throw new IllegalArgumentException("Valve can't run perform advice: " + advice.getType());
}

Runnable finalCallback = callback;
boolean finalRequireLoadCell = requireLoadCell;
Runnable valveTaskCallback = () -> {
loadCellOccupied = false;
if(finalRequireLoadCell) {
loadCellOccupied.decrementAndGet();
}
finalCallback.run();
};

loadCellOccupied = true;
if(requireLoadCell) {
loadCellOccupied.incrementAndGet();
}
pumpTask = new ValveTask(valve, mlToPump, prevJobId, valve, isPumpUpDown, valveTaskCallback);
jobFuture = liveTasksExecutor.submit(pumpTask);

Expand Down

0 comments on commit d810eab

Please sign in to comment.