opt:自动下发分配充电任务开发
This commit is contained in:
@@ -58,4 +58,8 @@ public interface AcsConfig {
|
||||
String MAXSENDTASKTIME = "maxSendTaskTime";
|
||||
//指令下发立库
|
||||
String INSTSENDLK = "instSendLk";
|
||||
|
||||
String ELECTRIC ="electric";
|
||||
|
||||
String IS_ATUO_ELECTRIC ="is_atuo_electric";
|
||||
}
|
||||
|
||||
@@ -40,4 +40,7 @@ public interface NDCAgvService {
|
||||
* @return
|
||||
*/
|
||||
public boolean createChargingTaskToNDC(String carno);
|
||||
|
||||
|
||||
public void charge(String carno);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.nl.acs.log.LokiLogType;
|
||||
import org.nl.acs.log.service.DeviceExecuteLogService;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.opc.DeviceAppServiceImpl;
|
||||
import org.nl.system.service.dict.ISysDictService;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.common.utils.CodeUtil;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
@@ -23,6 +25,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@@ -34,7 +37,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
private final DeviceAppService deviceAppService;
|
||||
private final ISysParamService paramService;
|
||||
private final AcsToWmsService acsToWmsService;
|
||||
|
||||
private final ISysDictService dictService;
|
||||
private final DeviceExecuteLogService logServer;
|
||||
|
||||
Map<String, AgvDto> AGVDeviceStatus = new HashMap();
|
||||
@@ -193,6 +196,73 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void charge(String carno) {
|
||||
//检查数据字典station为0的参数
|
||||
//分配车辆
|
||||
List<Dict> dictList= dictService.getDictByName("station");
|
||||
int satation=0;
|
||||
Dict temp=new Dict();
|
||||
for(Dict dict : dictList){
|
||||
if ("1".equals(dict.getValue())&&carno.equals(dict.getPara2())){
|
||||
log.info("当前车辆{}已分配充电桩{},退出后续判断",carno,dict.getPara1());
|
||||
return;
|
||||
}
|
||||
}
|
||||
for(Dict dict : dictList){
|
||||
if ("0".equals(dict.getValue())){
|
||||
satation = Integer.parseInt(dict.getPara1());
|
||||
temp=dict;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(satation!=0){
|
||||
String instcode =CodeUtil.getNewCode("INSTRUCT_NO");
|
||||
byte ikeyhigh = (byte) IntToHexHigh(Integer.parseInt(instcode));
|
||||
byte ikeylow = (byte) IntToHexLow(Integer.parseInt(instcode));
|
||||
byte carhigh = (byte) IntToHexHigh(Integer.parseInt(carno));
|
||||
byte carlow = (byte) IntToHexLow(Integer.parseInt(carno));
|
||||
byte satationhigh = (byte) IntToHexHigh(satation);
|
||||
byte satationlow = (byte) IntToHexLow(satation);
|
||||
String str = "十进制下发:";
|
||||
String str1 = "十六进制下发:";
|
||||
str += "ikey:" + (Integer.parseInt(instcode));
|
||||
str1 += "ikey:" + hexToString(ikeyhigh & 0xFF) + hexToString(ikeylow & 0xFF);
|
||||
str += "carno:" + (Integer.parseInt(carno));
|
||||
str1 += "carno:" + hexToString(carhigh & 0xFF) + hexToString(carlow & 0xFF);
|
||||
str += "/satation:" + (satation);
|
||||
str1 += "/satation:" + hexToString(satationhigh & 0xFF) + hexToString(satationlow & 0xFF);
|
||||
|
||||
byte[] b = new byte[]{(byte) 0X87, (byte) 0XCD,
|
||||
(byte) 0X00, (byte) 0X08,
|
||||
(byte) 0X00, (byte) 0X0E,
|
||||
(byte) 0X00, (byte) 0X01,
|
||||
(byte) 0X00, (byte) 0X71,
|
||||
(byte) 0X00, (byte) 0X0A,
|
||||
(byte) 0X64, (byte) 0X80,
|
||||
(byte) 0X00, (byte) 0X01,
|
||||
(byte) ikeyhigh, (byte) ikeylow,
|
||||
(byte) carhigh, (byte) carlow,
|
||||
(byte) satationhigh, (byte) satationlow
|
||||
|
||||
};
|
||||
log.info("下发AGV充电任务--{}", str1);
|
||||
|
||||
try{
|
||||
OneNDCSocketConnectionAutoRun.write(b);
|
||||
} catch (Exception e){
|
||||
log.error("下发充电任务失败{}{}",e,e.getMessage());
|
||||
}
|
||||
|
||||
temp.setValue("1");
|
||||
temp.setPara2(String.valueOf(carno));
|
||||
dictService.updateDetail(temp);
|
||||
|
||||
}else{
|
||||
log.error("目前暂无可使用充电桩充电桩,暂不分配{}充电任务",carno);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createChargingTaskToNDC(String carno) {
|
||||
byte carhigh = (byte) IntToHexHigh(Integer.parseInt(carno));
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.nl.acs.instruction.service.impl.InstructionServiceImpl;
|
||||
import org.nl.acs.log.service.DeviceExecuteLogService;
|
||||
import org.nl.acs.opc.DeviceAppService;
|
||||
import org.nl.acs.task.service.TaskService;
|
||||
import org.nl.system.service.dict.ISysDictService;
|
||||
import org.nl.system.service.dict.dao.Dict;
|
||||
import org.nl.system.service.lucene.LuceneExecuteLogService;
|
||||
import org.nl.system.service.param.ISysParamService;
|
||||
import org.nl.config.SpringContextHolder;
|
||||
@@ -59,6 +61,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
AutoRunService autoRunService;
|
||||
@Autowired
|
||||
LuceneExecuteLogService luceneExecuteLogService;
|
||||
@Autowired
|
||||
ISysDictService dictService;
|
||||
|
||||
|
||||
public OneNDCSocketConnectionAutoRun() {
|
||||
@@ -127,6 +131,9 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
int agvaddr = arr[18] * 256 + arr[19];
|
||||
//车号
|
||||
int carno = arr[20];
|
||||
//充电桩站点号
|
||||
int station=arr[25];
|
||||
|
||||
Instruction link_inst = null;
|
||||
Instruction inst = null;
|
||||
List<Instruction> insts = null;
|
||||
@@ -245,8 +252,36 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
}
|
||||
}
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
|
||||
//充电任务下发成功上报
|
||||
} else if (phase == 0x64){
|
||||
log.info("AGV车号{}反馈充电任务下发成功,锁定充电桩{}",agvaddr,station);
|
||||
List<Dict> dictList= dictService.getDictByName("station");
|
||||
for(Dict dict : dictList){
|
||||
if (Integer.parseInt(dict.getPara1())==station){
|
||||
dict.setValue("1");
|
||||
dict.setPara2(String.valueOf(agvaddr));
|
||||
dictService.updateDetail(dict);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//充电成功
|
||||
}else if (phase == 0x65){
|
||||
log.info("AGV车号{}反馈充电中,充电桩{}",agvaddr,station);
|
||||
//充电取消上报
|
||||
}else if (phase == 0x66){
|
||||
log.info("AGV车号{}反馈充电任务已取消,释放充电桩{}",agvaddr,station);
|
||||
List<Dict> dictList= dictService.getDictByName("station");
|
||||
for(Dict dict : dictList){
|
||||
if (Integer.parseInt(dict.getPara1())==station){
|
||||
dict.setValue("0");
|
||||
dict.setPara2("");
|
||||
dictService.updateDetail(dict);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
else {
|
||||
//上报异常信息
|
||||
//(不需要WCS反馈)
|
||||
if (phase == 0x67) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.AcsConfig;
|
||||
import org.nl.acs.agv.server.NDCAgvService;
|
||||
import org.nl.acs.auto.run.OneNDCSocketConnectionAutoRun;
|
||||
import org.nl.acs.device.domain.Device;
|
||||
@@ -75,6 +76,7 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
int last_electric_qty = 0;
|
||||
int last_status = 0;
|
||||
int last_error = 0;
|
||||
boolean isCharge = false;
|
||||
|
||||
@LokiLog(type = LokiLogType.ACS_TO_LMS)
|
||||
public synchronized void processSocket(int[] arr) throws Exception {
|
||||
@@ -322,7 +324,27 @@ public class AgvNdcOneDeviceDriver extends AbstractDeviceDriver implements Devic
|
||||
agvaddr_copy = agvaddr;
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0, 0, 0, 0, 0);
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
}else if (phase == 0x73) {
|
||||
//agv电量
|
||||
electric_qty = ikey;
|
||||
//是否开启自动充电
|
||||
String is_atuo_electric = paramService.findByCode(AcsConfig.IS_ATUO_ELECTRIC).getValue();
|
||||
if("1".equals(is_atuo_electric)){
|
||||
int electric = Integer.parseInt(paramService.findByCode(AcsConfig.ELECTRIC).getValue());
|
||||
if (electric_qty>0&&electric_qty < electric) {
|
||||
log.info("当前车辆{}电量为{}低于{},开始判断是否需要充电!", this.device_code, electric_qty,electric);
|
||||
NDCAgvService.charge(String.valueOf(this.agvaddr));
|
||||
isCharge =true;
|
||||
}
|
||||
}
|
||||
} else if (phase == 0x74) {
|
||||
//三色灯状态
|
||||
status = ikey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!ObjectUtil.isEmpty(data)) {
|
||||
logServer.deviceExecuteLog(this.device_code, "", "", "agvphase:" + phase + "反馈:" + data);
|
||||
OneNDCSocketConnectionAutoRun.write(data);
|
||||
|
||||
Reference in New Issue
Block a user