#
Junjie
3 天以前 5496a3a7b476135208d46dee279f506f9d69a234
#
8个文件已修改
234 ■■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/BasMapController.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/RedisKeyType.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/enums/WrkIoType.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/StationObjModel.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/plugin/NormalProcess.java 160 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -218,8 +218,20 @@
                        Integer isBarcodeStation = value.getInteger("isBarcodeStation");
                        if (isBarcodeStation != null && isBarcodeStation == 1) {
                            StationObjModel barcodeStationModel = new StationObjModel();
                            barcodeStationModel.setDeviceNo(deviceNo);
                            barcodeStationModel.setStationId(value.getInteger("stationId"));
                            if (value.getInteger("backStation") != null) {
                                StationObjModel backStation = new StationObjModel();
                                barcodeStationModel.setBackStation(backStation);
                                backStation.setDeviceNo(value.getInteger("backStationDeviceNo"));
                                backStation.setStationId(value.getInteger("backStation"));
                            }
                            List<StationObjModel> barcodeStationList = barcodeStationMap.getOrDefault(deviceNo, new ArrayList<>());
                            barcodeStationList.add(stationObjModel);
                            barcodeStationList.add(barcodeStationModel);
                            barcodeStationMap.put(deviceNo, barcodeStationList);
                        }
src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -39,6 +39,7 @@
    STATION_OUT_EXECUTE_COMPLETE_LIMIT("station_out_execute_complete_limit_"),
    CHECK_STATION_RUN_BLOCK_LIMIT_("check_station_run_block_limit_"),
    CHECK_SHALLOW_LOC_STATUS_LIMIT("check_shallow_loc_status_limit_"),
    GENERATE_ENABLE_IN_STATION_DATA_LIMIT("generate_enable_in_station_data_limit_"),
    DUAL_CRN_PICK_WAIT_NEXT_TASK("dual_crn_pick_wait_next_task_"),
    DUAL_CRN_OUT_TASK_STATION_INFO("dual_crn_out_task_station_info_"),
src/main/java/com/zy/core/enums/WrkIoType.java
@@ -7,8 +7,6 @@
    IN(1, "入库"),
    OUT(101, "出库"),
    LOC_MOVE(201, "移库任务"),
    PREVIEW_LIFT_MOVE(98, "提升机预调度移动任务"),
    MANUAL(99, "手动任务"),
    FAKE_TASK_NO(9999, "仿真随机工作号"),
    ;
src/main/java/com/zy/core/model/StationObjModel.java
@@ -19,4 +19,6 @@
    private StationObjModel barcodeStation;
    private StationObjModel backStation;
}
src/main/java/com/zy/core/network/real/ZyStationV3RealConnect.java
@@ -50,7 +50,7 @@
    @Override
    public boolean connect() {
        boolean connected = false;
        siemensNet = new SiemensS7Net(SiemensPLCS.S1200, deviceConfig.getIp());
        siemensNet = new SiemensS7Net(SiemensPLCS.S1500, deviceConfig.getIp());
        OperateResult connect = siemensNet.ConnectServer();
        if (connect.IsSuccess) {
            connected = true;
@@ -66,6 +66,7 @@
            News.error("输送站plc连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]",
                    deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort());
        }
//        siemensNet.ConnectClose();
        return connected;
    }
@@ -97,6 +98,10 @@
            if (barcodeStatusList != null) {
                barcodeStatusList.sort(Comparator.comparing(ZyStationStatusEntity::getStationId));
            }
        }
        if (siemensNet == null) {
            return statusList;
        }
        OperateResultExOne<byte[]> result = siemensNet.Read("DB100.0", (short) (statusList.size() * 8));
@@ -146,10 +151,12 @@
            return commandResponse;
        }
        int maxTryCount = 999;
        int tryCount = 0;
        if (command.getCommandType().equals(StationCommandType.MOVE)) {
            int enableCommandIdx = -1;
            while (true) {
                enableCommandIdx = getEnableCommandIdx();
                enableCommandIdx = getEnableCommandIdx(command.getTaskNo());
                if(enableCommandIdx == -1) {
                    try {
                        Thread.sleep(300);
@@ -157,11 +164,16 @@
                }else {
                    break;
                }
                tryCount++;
                if (tryCount > maxTryCount) {
                    commandResponse.setMessage("命令下发超时,无法找到可用下发区域");
                    return commandResponse;
                }
            }
            List<Integer> pathList = command.getNavigatePath();
            short[] data = new short[22];
            short[] data = new short[21];
            data[0] = command.getTargetStaNo().shortValue();
            int dataIdx = 1;
@@ -169,9 +181,18 @@
                data[dataIdx++] = path.shortValue();
            }
            OperateResult writeTask = siemensNet.Write("DB23." + enableCommandIdx * taskAddressLength, command.getTaskNo());
            OperateResult writeData = siemensNet.Write("DB23." + enableCommandIdx * taskAddressLength + 4, data);
            if(writeTask.IsSuccess &&  writeData.IsSuccess) {
            OperateResult writeTask = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength), command.getTaskNo());
            try {
                Thread.sleep(50);
            }catch (Exception e) {}
            OperateResult writeData = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 4), data);
            try {
                Thread.sleep(200);
            }catch (Exception e) {}
            OperateResult writeConfirm = siemensNet.Write("DB23." + (enableCommandIdx * taskAddressLength + 46), (short) 1);
            if(writeTask.IsSuccess &&  writeData.IsSuccess &&  writeConfirm.IsSuccess) {
                log.error("写入输送线命令成功。任务号={},站点数据={}", command.getTaskNo(), JSON.toJSON(command));
                commandResponse.setResult(true);
            }else {
@@ -219,11 +240,21 @@
        return null;
    }
    private int getEnableCommandIdx() {
    private int getEnableCommandIdx(int taskNo) {
        int useIdx = -1;
        for (int i = 0; i < taskAddressLimit; i++) {
            OperateResultExOne<byte[]> result = siemensNet.Read("DB23." + i * taskAddressLength, (short) taskAddressLength);
            int taskStatus = siemensNet.getByteTransform().TransInt16(result.Content, i * taskAddressLength + 46);
            OperateResultExOne<byte[]> resultTask = siemensNet.Read("DB23." + (i * taskAddressLength + 0), (short) 2);
            OperateResultExOne<byte[]> resultStatus = siemensNet.Read("DB23." + (i * taskAddressLength + 46), (short) 2);
            if(resultTask.IsSuccess && resultStatus.IsSuccess) {
                continue;
            }
            int commandAreaTaskNo = siemensNet.getByteTransform().TransInt32(resultTask.Content, 0);
            if(commandAreaTaskNo == taskNo) {
                return -1;
            }
            int taskStatus = siemensNet.getByteTransform().TransInt16(resultStatus.Content, 0);
            if (taskStatus == 1) {
                continue;
            }
src/main/java/com/zy/core/plugin/NormalProcess.java
@@ -1,11 +1,39 @@
package com.zy.core.plugin;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.zy.asrs.domain.param.CreateInTaskParam;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.StationCommandType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.Task;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.plugin.api.MainProcessPluginApi;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.CrnOperateProcessUtils;
import com.zy.core.utils.StationOperateProcessUtils;
import com.zy.core.utils.WmsOperateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Slf4j
@Component
@@ -15,9 +43,24 @@
    private CrnOperateProcessUtils crnOperateUtils;
    @Autowired
    private StationOperateProcessUtils stationOperateProcessUtils;
    @Autowired
    private CommonService commonService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private WmsOperateUtils wmsOperateUtils;
    @Override
    public void run() {
        //请求生成入库任务
        generateStoreWrkFile();
        //检测入库站是否有任务生成,并启动入库
        checkInStationHasTask();
        //执行堆垛机任务
        crnOperateUtils.crnIoExecute();
        //堆垛机任务执行完成-具备仿真能力
@@ -30,4 +73,121 @@
        stationOperateProcessUtils.stationOutExecuteFinish();
    }
    /**
     * 请求生成入库任务
     * 入库站,根据条码扫描生成入库工作档
     */
    public synchronized void generateStoreWrkFile() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            List<StationObjModel> list = basDevp.getBarcodeStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
                //满足自动、有物、有工作号,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() > 0
                ) {
                    if (Cools.isEmpty(stationProtocol.getBarcode())) {
                        continue;
                    }
                    //检测任务是否生成
                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    if (!wrkMasts.isEmpty()) {
                        continue;
                    }
                    Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
                    if (lock != null) {
                        continue;
                    }
                    redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
                    String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight());
                    if (response == null) {
                        News.error("请求WMS入库接口失败,接口未响应!!!response:{}", response);
                        continue;
                    }
                    JSONObject jsonObject = JSON.parseObject(response);
                    if (jsonObject.getInteger("code").equals(200)) {
                        StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                        CreateInTaskParam taskParam = new CreateInTaskParam();
                        taskParam.setTaskNo(dto.getTaskNo());
                        taskParam.setLocNo(dto.getLocNo());
                        taskParam.setTaskPri(dto.getTaskPri());
                        taskParam.setBarcode(stationProtocol.getBarcode());
                        WrkMast wrkMast = commonService.createInTask(taskParam);
                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
                        if(command == null){
                            News.taskInfo(wrkMast.getWrkNo(), "获取输送线命令失败");
                            continue;
                        }
                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    }
                }
            }
        }
    }
    //检测入库站是否有任务生成,并启动入库
    private synchronized void checkInStationHasTask() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
            List<StationObjModel> list = basDevp.getInStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
                Object lock = redisUtil.get(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId);
                if(lock != null){
                    continue;
                }
                //满足自动、无物、工作号0,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                        && stationProtocol.isEnableIn()
                ) {
                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
                    MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 10);
                }
            }
        }
    }
}
src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -217,7 +217,8 @@
        CommandResponse commandResponse = null;
        try {
            commandResponse = zyStationConnectDriver.sendCommand(command);
            return commandResponse;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
            List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
@@ -249,6 +250,7 @@
                optService.insert(basStationOpt);
            }
        }
        return commandResponse;
    }
    @Override
src/main/resources/application.yml
@@ -78,7 +78,7 @@
  expireDays: 7
llm:
  platform: python
  platform: java
  pythonPlatformUrl: http://127.0.0.1:9000/ai/diagnose/askStream
#  base-url: https://api.siliconflow.cn/v1
#  api-key: sk-sxdtebtquwrugzrmaqqqkzdzmrgzhzmplwwuowysdasccent