Browse Source

Update AppVersion to version A80.CN.01.00.07; refactor WebSocket endpoint and state management for emergency key handling

master
zhaohe 6 days ago
parent
commit
bb8fc76cec
  1. 2
      src/main/java/a8k/app/constant/AppVersion.java
  2. 87
      src/main/java/a8k/app/controler/api/v1/app/ws/AppWebSocketEndpointMgr.java
  3. 11
      src/main/java/a8k/app/dao/type/db/AppUser.java
  4. 6
      src/main/java/a8k/app/service/statemgr/GStateMgrService.java
  5. 13
      src/main/java/a8k/app/type/GState.java
  6. 7
      src/main/java/a8k/extui/page/extapp/UsrOperationSimulationPage.java
  7. 21
      src/test/java/a8k/app/factory/BiLisDoubleTrackFrameFactoryTest.java

2
src/main/java/a8k/app/constant/AppVersion.java

@ -1,5 +1,5 @@
package a8k.app.constant;
public class AppVersion {
public static final String APP_VERSION = "1.0.5";
public static final String APP_VERSION = "A80.CN.01.00.07";
}

87
src/main/java/a8k/app/controler/api/v1/app/ws/AppWebSocketEndpointMgr.java

@ -1,6 +1,5 @@
package a8k.app.controler.api.v1.app.ws;
import a8k.SpringBootBeanUtil;
import a8k.app.service.engineer.state.EngineerModeStateMgrService;
import a8k.app.type.AppGetStateFn;
import a8k.app.type.DeviceRunMode;
@ -47,13 +46,6 @@ public class AppWebSocketEndpointMgr {
}
}
static public class DeviceContext {
public DeviceRunMode runMode = DeviceRunMode.RealMode;
public Boolean loginFlag = false;
public AppUser loginUser = null;
public Boolean deviceInitedFlag = false;
public Boolean fatalErrorFlag = false;
}
private final AppUserMgrService appUserMgrService;
private final AppDeviceInitCtrlService appDeviceInitCtrlService;
@ -72,9 +64,9 @@ public class AppWebSocketEndpointMgr {
final private AppEventBusService eventBus;
List<Session> stateWebsocketSessions = new ArrayList<>();
List<Session> eventWebsocketSessions = new ArrayList<>();
Map<String, Integer> stateVersionCache = new HashMap<>();
List<Session> stateWebsocketSessions = new ArrayList<>();
List<Session> eventWebsocketSessions = new ArrayList<>();
Map<String, Object> stateVersionCache = new HashMap<>();
final Object sessionLock = new Object();
AtomicInteger forceUpdateCnt = new AtomicInteger(0);
@ -125,12 +117,16 @@ public class AppWebSocketEndpointMgr {
broadcastState(message);
}
synchronized public void reportState(String type, Integer version, boolean force, AppGetStateFn getStateFn) {
synchronized public void reportState(String type, Object version, boolean force, AppGetStateFn getStateFn) {
reportState(type, type, version, force, getStateFn);
}
synchronized public void reportState(String typeKey, String reportName, Integer version, boolean force, AppGetStateFn getStateFn) {
Integer lastVersion = stateVersionCache.get(typeKey);
synchronized public void reportState(String type, boolean force, AppGetStateFn getStateFn) {
reportState(type, type, getStateFn.getState(), force, getStateFn);
}
synchronized public void reportState(String typeKey, String reportName, Object version, boolean force, AppGetStateFn getStateFn) {
Object lastVersion = stateVersionCache.get(typeKey);
if (force || lastVersion == null || !lastVersion.equals(version)) {
stateVersionCache.put(typeKey, version);
reportState(reportName, getStateFn.getState());
@ -170,17 +166,8 @@ public class AppWebSocketEndpointMgr {
@Scheduled(fixedDelay = 900)
public void reportDeviceState() {
reportState("GDeviceState", gStateMgrService.getGState());
reportState("IncubationPlateState", incubationPlateStateMgr.get());
reportState("SensorState", gStateMgrService.getSensorState());
DeviceContext deviceContext = new DeviceContext();
deviceContext.runMode = gStateMgrService.getDeviceRunMode();
deviceContext.loginFlag = appUserMgrService.getLoginUsr() != null;
deviceContext.loginUser = appUserMgrService.getLoginUsr();
deviceContext.deviceInitedFlag = appDeviceInitCtrlService.getState().deviceInited;
deviceContext.fatalErrorFlag = deviceWorkStateMgrService.getDeviceWorkState().fatalErrorFlag;
reportState("DeviceContext", deviceContext);
}
@Scheduled(fixedDelay = 50)
@ -189,6 +176,10 @@ public class AppWebSocketEndpointMgr {
}
public void quickReportStateSchedule(boolean force) {
reportState("EmergencyKeyState", force, this::getEmergencyKeyState);
reportState("DeviceContext", force, this::getDeviceContext);
reportState("ConsumablesState", consumablesMgrService.getStateVersion(), force, consumablesMgrService::getState);
reportState("EngineerModeState", engineerModeStateMgrService.getVersion(), force, engineerModeStateMgrService::getState);
reportState("DeviceWorkState", deviceWorkStateMgrService.getVersion(), force, deviceWorkStateMgrService::getDeviceWorkState);
@ -235,6 +226,56 @@ public class AppWebSocketEndpointMgr {
}
public static class EmergencyKeyState {
public Boolean emergencyKeyTrigger = false;
@Override public boolean equals(Object other) {
if (other instanceof EmergencyKeyState that) {
return emergencyKeyTrigger.equals(that.emergencyKeyTrigger);
} else {
return false;
}
}
}
private EmergencyKeyState getEmergencyKeyState() {
EmergencyKeyState state = new EmergencyKeyState();
state.emergencyKeyTrigger = gStateMgrService.getGState().getEmergencyKeyTriggered();
return state;
}
static public class DeviceContext {
public DeviceRunMode runMode = DeviceRunMode.RealMode;
public Boolean loginFlag = false;
public AppUser loginUser = null;
public Boolean deviceInitedFlag = false;
public Boolean fatalErrorFlag = false;
@Override public boolean equals(Object other) {
if (other instanceof DeviceContext that) {
return runMode.equals(that.runMode) &&
loginFlag.equals(that.loginFlag) &&
Objects.equals(loginUser, that.loginUser) &&
deviceInitedFlag.equals(that.deviceInitedFlag) &&
fatalErrorFlag.equals(that.fatalErrorFlag);
} else {
return false;
}
}
}
private DeviceContext getDeviceContext() {
DeviceContext deviceContext = new DeviceContext();
deviceContext.runMode = gStateMgrService.getDeviceRunMode();
deviceContext.loginFlag = appUserMgrService.getLoginUsr() != null;
deviceContext.loginUser = appUserMgrService.getLoginUsr();
deviceContext.deviceInitedFlag = appDeviceInitCtrlService.getState().deviceInited;
deviceContext.fatalErrorFlag = deviceWorkStateMgrService.getDeviceWorkState().fatalErrorFlag;
return deviceContext;
}
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<>();
}

11
src/main/java/a8k/app/dao/type/db/AppUser.java

@ -44,5 +44,16 @@ public class AppUser {
public AppUser() {
}
@Override
public boolean equals(Object obj) {
if ((obj instanceof AppUser other)) {
return this.account.equals(other.account) &&
this.password.equals(other.password) &&
this.usrRole.equals(other.usrRole)
;
} else {
return false;
}
}
}

6
src/main/java/a8k/app/service/statemgr/GStateMgrService.java

@ -58,6 +58,10 @@ public class GStateMgrService {
gState.sensorState.setWasteBinFullFlag(val);
}
public void updateEmergencyStopFlag(Boolean val) {
gState.emergencyKeyTriggered = val;
}
public synchronized void setSensorState(SensorState sensorState) {
this.gState.sensorState = sensorState;
@ -144,7 +148,7 @@ public class GStateMgrService {
}
public synchronized void checkIfIsInVirtualMode() throws AppException {
if (!this.gState.getDeviceRunMode().equals(DeviceRunMode.VirtualMode)) {
if (!isInMode(DeviceRunMode.VirtualMode)) {
throw AppException.of(A8kEcode.CODEERROR, "只有在虚拟模式下才能进行当前操作");
}
}

13
src/main/java/a8k/app/type/GState.java

@ -1,8 +1,6 @@
package a8k.app.type;
import a8k.app.constant.AppConstant;
import a8k.app.constant.AppVersion;
import a8k.app.i18n.Internationalization;
import a8k.app.type.a8k.state.SensorState;
import a8k.app.type.error.AppError;
import lombok.Data;
@ -34,14 +32,15 @@ public class GState {
//
public String localIP = "";//设备IP
public SensorState sensorState = new SensorState();
public SensorState sensorState = new SensorState();
//
public String deviceType = "A8000";
public String deviceType = "A8000";
//
public String deviceVersion = "1"; //设备版本号
public String deviceVersion = "1"; //设备版本号
//生产日期
public String manufactureDate = "20250101"; //生产日期
public String manufactureDate = "20250101"; //生产日期
//急停触发
public Boolean emergencyKeyTriggered = false; //设备锁定状态,用于工程师模式下的设备锁定
/**
* 该变量,由AppEnvInitializer初始化完成后设置为true

7
src/main/java/a8k/extui/page/extapp/UsrOperationSimulationPage.java

@ -97,6 +97,10 @@ public class UsrOperationSimulationPage {
}
public void setEmergencyKeyState(Boolean state) throws AppException {
gstate.updateEmergencyStopFlag(state);
}
@PostConstruct
public void init() {
var page = extApiPageMgr.newPage(this);
@ -111,6 +115,9 @@ public class UsrOperationSimulationPage {
page.newGroup("样本模拟操作");
page.addFunction("放入一个全血高试管架", this::putInVirtualBloodTubeHolder);
page.newGroup("急停");
page.addFunction("设置急停状态", this::setEmergencyKeyState);
extApiPageMgr.addPage(page);
}

21
src/test/java/a8k/app/factory/BiLisDoubleTrackFrameFactoryTest.java

@ -1,6 +1,7 @@
package a8k.app.factory;
import a8k.app.constant.AppConstant;
import a8k.app.type.exception.AppException;
import a8k.app.type.lisprotocol.BiLisDoubleTrackFrameBuildContext;
import a8k.app.utils.ByteArrayUtils;
import lombok.extern.slf4j.Slf4j;
@ -26,15 +27,21 @@ class BiLisDoubleTrackFrameFactoryTest {
@Test
void createQFrameBytes() {
BiLisDoubleTrackFrameBuildContext cxt = BiLisDoubleTrackFrameFactory.createQFrameBytes("A8000", "123456789");
log.info("frameBytes {}", ByteArrayUtils.toByteString(cxt.frameBytes));
log.info("frameContent {}",cxt.frameContentStr);
log.info("checksum {} {}", cxt.checksum[0], cxt.checksum[1]);
BiLisDoubleTrackFrameBuildContext cxt = null;
try {
cxt = BiLisDoubleTrackFrameFactory.createQFrameBytes("A8000", "123456789");
log.info("frameBytes {}", ByteArrayUtils.toByteString(cxt.frameBytes));
log.info("frameContent {}", cxt.frameContentStr);
log.info("checksum {} {}", cxt.checksum[0], cxt.checksum[1]);
assertNotNull(cxt);
assertTrue(cxt.buildSuccess);
assertEquals("Q|A8000|^123456789|\r", cxt.frameContentStr);
assertNotNull(cxt);
assertEquals("Q|A8000|^123456789|\r", cxt.frameContentStr);
} catch (AppException e) {
log.error("Error creating Q frame bytes", e);
fail("Exception should not be thrown");
}
}
@Test

Loading…
Cancel
Save