| | |
| | | import com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorMetricState; |
| | | import com.ruoyi.device.simulator.DevelopmentCollectorSimulation.CollectorHistoryPage; |
| | | import com.ruoyi.device.simulator.DevelopmentCollectorSimulation.CollectorRealtimeSnapshot; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator.PlaybackSnapshot; |
| | | |
| | | /** 本机临时 BTS 模拟器控制 API。 */ |
| | | @Anonymous |
| | |
| | | } |
| | | } |
| | | |
| | | /** 返回检测柜通道播放、record、step 和 cycle 的当前快照。 */ |
| | | @GetMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback") |
| | | public PlaybackSnapshot btsPlayback(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @GetMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/records") |
| | | public List<com.ruoyi.device.simulator.BtsSimulatorStateStore.BtsHistoryRecord> btsRecords( |
| | | @PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { return simulator.btsRecords(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @GetMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/steps") |
| | | public List<BtsDevelopmentSimulator.BtsStepRecord> btsSteps( |
| | | @PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { return simulator.btsSteps(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @GetMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/cycles") |
| | | public List<BtsDevelopmentSimulator.BtsCycleRecord> btsCycles( |
| | | @PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { return simulator.btsCycles(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | /** 设置检测柜通道演示倍速。 */ |
| | | @PutMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback") |
| | | public PlaybackSnapshot configureBtsPlayback(@PathVariable int deviceId, @PathVariable int channelId, |
| | | @RequestBody PlaybackCommand command) |
| | | { |
| | | try |
| | | { |
| | | if (command.speedMultiplier() != null) simulator.setBtsSpeed(deviceId, channelId, command.speedMultiplier()); |
| | | if (command.playing() != null) |
| | | { |
| | | if (command.playing()) simulator.playBts(deviceId, channelId); |
| | | else simulator.pauseBts(deviceId, channelId); |
| | | } |
| | | return simulator.btsPlayback(deviceId, channelId); |
| | | } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/play") |
| | | public PlaybackSnapshot playBts(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.playBts(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/pause") |
| | | public PlaybackSnapshot pauseBts(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.pauseBts(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/resume") |
| | | public PlaybackSnapshot resumeBts(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.resumeBts(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/next-step") |
| | | public PlaybackSnapshot nextBtsStep(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.nextBtsStep(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/next-cycle") |
| | | public PlaybackSnapshot nextBtsCycle(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.nextBtsCycle(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | @PostMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}/playback/reset") |
| | | public PlaybackSnapshot resetBts(@PathVariable int deviceId, @PathVariable int channelId) |
| | | { |
| | | try { simulator.resetBts(deviceId, channelId); return simulator.btsPlayback(deviceId, channelId); } |
| | | catch (IllegalArgumentException exception) { throw badRequest(exception); } |
| | | } |
| | | |
| | | private ResponseStatusException badRequest(IllegalArgumentException exception) |
| | | { |
| | | return new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); |
| | |
| | | public record CollectorChannelCommand(List<CollectorMetricCommand> metrics) { } |
| | | |
| | | public record CollectorMetricCommand(String metricCode, BigDecimal value, String unit) { } |
| | | |
| | | public record PlaybackCommand(Integer speedMultiplier, Boolean playing) { } |
| | | } |