Browse Source

设备状态

master
sige 2 years ago
parent
commit
6789bf0325
  1. 81
      src/main/java/com/dreamworks/boditech/controller/DeviceController.java
  2. 16
      src/main/java/com/dreamworks/boditech/driver/task/Executor.java
  3. 41
      src/main/java/com/dreamworks/boditech/service/DeviceService.java

81
src/main/java/com/dreamworks/boditech/controller/DeviceController.java

@ -6,6 +6,7 @@ import com.dreamworks.boditech.driver.actuator.ActModuleIncubatorTemperature;
import com.dreamworks.boditech.driver.actuator.ActModuleTestCardBoxCaseTemperature;
import com.dreamworks.boditech.driver.actuator.ActuatorModule;
import com.dreamworks.boditech.driver.entity.*;
import com.dreamworks.boditech.driver.task.Executor;
import com.dreamworks.boditech.entity.MdbTestTubeRackTestTask;
import com.dreamworks.boditech.service.DeviceService;
import com.dreamworks.boditech.utils.I18n;
@ -133,54 +134,21 @@ public class DeviceController extends BaseController {
return this.success();
}
@ResponseBody
@PostMapping("/api/device/power-off")
public ApiResponse powerOff() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.powerOff();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
@PostMapping("/api/device/reboot")
public ApiResponse reboot() {
this.deviceService.reboot();
return this.success();
}
@ResponseBody
@PostMapping("/api/device/reboot")
public ApiResponse reboot() {
DeviceService theDeviceService = this.deviceService;
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
theDeviceService.reboot();
}
};
Timer timer = new Timer();
timer.schedule(timerTask, 1000);
@PostMapping("/api/device/power-off")
public ApiResponse powerOff() {
// 这里只是同步一下系统状态接口返回之后由前台提示可以拔电源了 ~~~~
this.deviceService.poweroff();
return this.success();
}
@ResponseBody
@PostMapping("/api/device/status-get")
public ApiResponse status() {
@ -195,42 +163,17 @@ public class DeviceController extends BaseController {
statusName = I18n.t("device.status.consumablesLoaded");
}
if ( this.deviceService.isExecutorRunning() ) {
// status = this.deviceService.getExecutorWorkingStatus();
status = "RUNNING";
statusName = "运行中";
Executor executor = this.deviceService.getTaskExecutor();
status = executor.getWorkingStatus();
statusName = I18n.t("device.status." + status);
}
return this.success(Map.of("status", status, "statusName", statusName));
}
@ResponseBody
@PostMapping("/api/device/restore")
public ApiResponse restore() {
// 忘了这个时干嘛的了 ~~~~ 先留着 确认后在处理
this.deviceService.reset();
return this.success();
}

16
src/main/java/com/dreamworks/boditech/driver/task/Executor.java

@ -211,6 +211,15 @@ public class Executor implements Runnable {
}
}
/**
* get executor status
* @return executor status
*/
public String getWorkingStatus() {
return this.workingStatus;
}
@ -247,13 +256,6 @@ public class Executor implements Runnable {
/**
* get executor status
* @return executor status
*/
public Integer getStatus() {
return this.status;
}
/**
* get device instance

41
src/main/java/com/dreamworks/boditech/service/DeviceService.java

@ -132,6 +132,29 @@ public class DeviceService {
this.taskExecutor.resume();
}
// reboot the device
public void reboot() {
if ( null != this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_BUSY);
}
try {
Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// power off the device
public void poweroff() {
if ( null != this.taskExecutor ) {
throw new AppRuntimeException(AppError.DEVICE_BUSY);
}
try {
Runtime.getRuntime().exec("sync");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@ -263,24 +286,6 @@ public class DeviceService {
this.tasks.notifyAll();
}
}
// power off the device
public void powerOff() {
try {
Runtime.getRuntime().exec("poweroff");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
// reboot the device
public void reboot() {
try {
Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Loading…
Cancel
Save