称重优化

This commit is contained in:
zc
2026-04-09 11:05:57 +08:00
parent 95242f772e
commit 90eb4a1af8
12 changed files with 124 additions and 43 deletions

View File

@@ -38,7 +38,7 @@ public class LightController {
if (connected) {
return R.ok();
} else {
return R.fail("500","灯光连接失败");
return R.fail("500", "灯光连接失败");
}
}
@@ -79,12 +79,13 @@ public class LightController {
if (success) {
return R.ok();
} else {
return R.fail("500","设置灯光亮度失败,请检查连接状态");
return R.fail("500", "设置灯光亮度失败,请检查连接状态");
}
}
/**
* 读取通道亮度
*
* @param channel 通道号 (1-2)
*/
@GetMapping("/brightness")
@@ -96,6 +97,7 @@ public class LightController {
/**
* 打开指定通道
*
* @param channel 通道号 (1-2)
*/
@PostMapping("/turn-on")
@@ -107,6 +109,7 @@ public class LightController {
/**
* 关闭指定通道
*
* @param channel 通道号 (1-2)
*/
@PostMapping("/turn-off")
@@ -118,6 +121,7 @@ public class LightController {
/**
* 设置所有通道亮度
*
* @param brightness 亮度等级 (0-255)
*/
@PostMapping("/all-brightness")

View File

@@ -1,15 +1,22 @@
package top.wms.admin.controller.vm;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.validation.CheckUtils;
import top.wms.admin.controller.tcp.config.SimpleRequestMatcher;
import top.wms.admin.controller.tcp.manager.ChannelManager;
import top.wms.admin.controller.tcp.service.SaveBmpTaskService;
import top.wms.admin.material.mapper.MaterialInfoMapper;
import top.wms.admin.material.model.entity.MaterialInfoDO;
import top.wms.admin.material.model.resp.MaterialInfoResp;
import top.wms.admin.material.service.MaterialInfoService;
@Slf4j
@RestController
@@ -25,11 +32,16 @@ public class VmCommandController {
@Autowired
private SaveBmpTaskService saveBmpTaskService;
@Autowired
private MaterialInfoMapper materialInfoMapper;
@PostMapping("/send")
public String sendAndWait(@RequestBody JSONObject js) {
String materialProcess = js.getString("materialProcess");
log.info("开始比对: {}", materialProcess);
CheckUtils.throwIf(StrUtil.isBlank(materialProcess), "物料流程编码不能为空");
String materialCode = js.getString("materialCode");
log.info("开始比对: {}", materialCode);
MaterialInfoDO materialInfoDO = materialInfoMapper.selectOne(new QueryWrapper<MaterialInfoDO>().eq("encoding", materialCode));
CheckUtils.throwIf(ObjectUtil.isEmpty(materialInfoDO), "物料数据异常");
CheckUtils.throwIf(StrUtil.isBlank(materialInfoDO.getMaterialProcess()), "物料流程编码不能为空");
// 1. 检查连接
Channel channel = channelManager.getFirstChannel();
@@ -38,16 +50,42 @@ public class VmCommandController {
}
// 2. 清空之前的响应队列,避免影响当前请求
requestMatcher.clear();
channel.writeAndFlush(materialProcess);
channel.writeAndFlush(materialInfoDO.getMaterialProcess());
// 3. 等待响应
String response = requestMatcher.waitForResponse(20);
log.info("sendAndWait-收到响应: {}", response);
CheckUtils.throwIf("TIMEOUT".equals(response), "响应超时,请重试");
CheckUtils.throwIf("ERROR".equals(response), "设备连接异常!");
//如果是圆管,数据格式为yg_yellow_139.092或者yg_yellow
if (response.contains("yg_")) {
CheckUtils.throwIf(null == materialInfoDO.getMaterialSpec(), "物料直径不能为空");
String[] split = response.split("_");
if (split.length != 3) {
throw new BusinessException("位置摆放不标准,未检查出直径");
}
if (!StrUtil.equals(split[1], materialInfoDO.getColor())) {
throw new BusinessException("颜色不匹配");
}
try {
double measuredDiameter = Double.parseDouble(split[2]);
double difference = Math.abs(measuredDiameter - materialInfoDO.getMaterialSpec());
if (difference > 5) {
throw new BusinessException("直径不匹配");
}
} catch (NumberFormatException e) {
throw new BusinessException("相机识别异常");
}
} else if (StrUtil.equals(response, materialCode)) {
response = "success";
} else {
response = "failed";
}
return response;
}
@PostMapping("/start")
public boolean startTask() {
return saveBmpTaskService.startTask();
@@ -57,4 +95,4 @@ public class VmCommandController {
public boolean stopTask() {
return saveBmpTaskService.stopTask();
}
}
}