¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * <p>Description: </p> |
| | | * <p>Copyright: Copyright (c) 2020</p> |
| | | * <p>Company: www.31gps.net</p> |
| | | * @author chencq |
| | | * @version 1.0 |
| | | */ |
| | | package com.ruoyi.sy.gps31; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.gps31.push.netty.PushClient; |
| | | import com.gps31.push.netty.PushMsg; |
| | | import com.gps31.push.netty.client.TcpClient; |
| | | import com.gps31.push.util.MapUtil; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.sy.domain.ArdSyCarLock; |
| | | import com.ruoyi.sy.domain.ArdSyCarRtu; |
| | | import com.ruoyi.sy.service.ArdSyCarLockService; |
| | | import com.ruoyi.sy.service.ArdSyCarRtuService; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarDayServiceImpl; |
| | | import com.ruoyi.sy.service.impl.ArdSyCarServiceImpl; |
| | | import com.ruoyi.sy.service.impl.ArdTankAbnormalParkAlarmServiceImpl; |
| | | import com.ruoyi.utils.qymqtt.newM.EmqClient; |
| | | import com.ruoyi.utils.qymqtt.newM.QosEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | | /** |
| | | * <p>Description: </p> |
| | | * <p>Copyright: Copyright (c) 2020</p> |
| | | * <p>Company: www.31gps.net</p> |
| | | * @author chencq |
| | | * @version 1.0 |
| | | */ |
| | | @Slf4j(topic = "mqttCar") |
| | | public class PushClientImplSerialPort extends PushClient implements Runnable { |
| | | |
| | | // private static final Log log = LogFactory.getLog(PushClientImplPosition.class); |
| | | |
| | | private String ip; |
| | | |
| | | private String userId; |
| | | |
| | | private String password; |
| | | |
| | | public PushClientImplSerialPort(String ip, String userId, String password) { |
| | | this.ip = ip; |
| | | this.userId = userId; |
| | | this.password = password; |
| | | } |
| | | |
| | | public PushClientImplSerialPort() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void messageReceived(TcpClient tcpClient, PushMsg pushMsg) |
| | | throws Exception { |
| | | if("8001".equals(pushMsg.getCmd())) {//ç»å½åºç |
| | | String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1"); |
| | | if("0".equals(rspResult)) {//ç»å½æåï¼å®é
å¨ææ¶æ¯ |
| | | Map<String,Object> map = new HashMap<String,Object>(); |
| | | map.put("seq", "1"); |
| | | map.put("action", "add"); |
| | | map.put("msgIds", JSON.toJSONString(getSubCmdSet())); |
| | | PushMsg subMsg = getInstance("0003",map); |
| | | sendMsg(subMsg); |
| | | } |
| | | }else if("8002".equals(pushMsg.getCmd())){//å¿è·³åºç |
| | | |
| | | }else if("8003".equals(pushMsg.getCmd())){//订é
å¨ææ¶æ¯åºç |
| | | String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1"); |
| | | //log.error(String.format(" 订é
åºç:%s", "0".equals(rspResult)?"æå":"失败")); |
| | | }else if("0200".equals(pushMsg.getCmd())) {//å®ä½ä¿¡æ¯ |
| | | Map<String,Object> gpsMap = pushMsg.getJsonMap(); |
| | | log.debug(String.format(" ---->----æ¶å°å®ä½æ°æ®å¦ä¸:%s",JSON.toJSONString(gpsMap))); |
| | | /** |
| | | * |
| | | * 请å å
¥ä¸æ¹éææ¹çä¸å¡é»è¾ |
| | | * |
| | | */ |
| | | }else if("0300".equals(pushMsg.getCmd())) {//æ¥è¦æ¶æ¯ |
| | | Map<String,Object> alarmMap = pushMsg.getJsonMap(); |
| | | String carName = MapUtil.getStrVal(alarmMap, "carName","");//è·å车çå· |
| | | //log.error(String.format(" ---->æ¶å°æ¥è¦æ°æ®:%s",JSON.toJSONString(alarmMap))); |
| | | /** |
| | | * |
| | | * 请å å
¥ä¸æ¹éææ¹çä¸å¡é»è¾ |
| | | * |
| | | */ |
| | | }else if("0401".equals(pushMsg.getCmd())) {//éä¼ æ¶æ¯ |
| | | Map<String,Object> dataMap = pushMsg.getJsonMap(); |
| | | String carName = MapUtil.getStrVal(dataMap, "carName","");//è·å车çå· |
| | | //log.error(String.format(" ---->æ¶å°éä¼ æ°æ®:%s",JSON.toJSONString(dataMap))); |
| | | /** |
| | | * |
| | | * 请å å
¥ä¸æ¹éææ¹çä¸å¡é»è¾ |
| | | * |
| | | */ |
| | | } |
| | | } |
| | | |
| | | public void sendMassage() { |
| | | try { |
| | | PushClientImplSerialPort client = new PushClientImplSerialPort(); |
| | | client.setLog(false);//æ¯å¦æå°ææ |
| | | client.setHost(this.ip);//æå¡å¨IP |
| | | client.setPort(10100);//æå¡å¨ç«¯å£ |
| | | client.setUserName(this.userId);//ç³»ç»ç¨æ·å |
| | | client.setPwd(this.password);//ç³»ç»ç¨æ·å¯ç |
| | | client.setSubMsgIds("0401");//订é
çå¨ææ¶æ¯ï¼å¤ä¸ªå¨ææ¶æ¯ä½¿ç¨|è¾åï¼å½åç¤ºä¾æ¯è®¢é
å®ä½æ¶æ¯(0x0200)åæ¥è¦æ¶æ¯(0x0300) |
| | | client.setDesc("æµè¯å®¢æ·ç«¯");//客æ·ç«¯çæè¿°ï¼ |
| | | client.start(); |
| | | while(true) { |
| | | Thread.sleep(1000); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | sendMassage(); |
| | | } |
| | | |
| | | private void feng(String carId,String type,ArdSyCarRtuService carRtuService,ArdSyCarLockService lockService) throws MqttException { |
| | | //æ¥è¯¢è£
æ²¹ç¹æ¢å®Rtuç¶æ |
| | | ArdSyCarRtu ardSyCarRtu = carRtuService.one(carId); |
| | | if(ardSyCarRtu!=null){ |
| | | //æ¥è¯¢éä¿¡æ¯ |
| | | List<ArdSyCarLock> ardSyCarLocks = lockService.carLock(ardSyCarRtu.getId()); |
| | | if(ardSyCarLocks.size()>0){ |
| | | Integer fengType = null; |
| | | if("è£
æ²¹ç¹".equals(type)){ |
| | | fengType = ardSyCarRtu.getInstallType(); |
| | | }else if("叿²¹ç¹".equals(type)){ |
| | | fengType = ardSyCarRtu.getUnloadType(); |
| | | }else if("æ½å°".equals(type)){ |
| | | fengType = 0; |
| | | } |
| | | //1è§£å° |
| | | if(fengType==1){ |
| | | //妿䏿¯è§£å°å°ç¶æï¼ååéæ½å°å½ä»¤ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==0 || ardSyCarLocks.get(0).getRelayInfo()==null){ |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("A01", 110000);//导é第ä¸è·¯ç»§çµå¨ |
| | | // map.put("A02", 110000);//导é第äºè·¯ç»§çµå¨ |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | String mapString = "{\"A01\":110000,\"A02\":110000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | log.debug("èªå¨è§£å°ï¼"+mapString); |
| | | EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient.connect(); |
| | | emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false); |
| | | log.debug("车è¾"+carId+"è§£å°å½ä»¤åéæåï¼"); |
| | | // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"è§£å°"); |
| | | } |
| | | } |
| | | |
| | | //0æ½å° |
| | | if(fengType==0){ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==1 || ardSyCarLocks.get(0).getRelayInfo()==null){ |
| | | //éå¼å
³ç¶æ |
| | | int lockCloseNum = 0; |
| | | String mapString1 = "{\"A01\":100000,\"A02\":100000,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | System.out.println("èªå¨æ½å°ï¼"+mapString1); |
| | | EmqClient emqClient1 = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient1.connect(); |
| | | emqClient1.publish(ardSyCarRtu.getTopicPublish(),mapString1, QosEnum.QoS2,false); |
| | | //妿䏿¯æ½å°ç¶æï¼ååéæ½å°å½ä»¤ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()!=null){ |
| | | if(ardSyCarLocks.get(0).getRelayInfo()==1){ |
| | | for (int j = 0; j < ardSyCarLocks.size(); j++) { |
| | | ArdSyCarLock ardSyCarLock = ardSyCarLocks.get(j); |
| | | String currents = ardSyCarLock.getCurrents(); |
| | | Double currentInfo = ardSyCarLock.getCurrentInfo(); |
| | | //çµæµå¼ä¸º4.0æ¯å
³éç¶æ |
| | | if(currentInfo.equals(4.00) || currentInfo.equals(4)){ |
| | | lockCloseNum += 1; |
| | | }else { |
| | | String key = ""; |
| | | if(currents.equals("C01")){ |
| | | key = "D03"; |
| | | }else if(currents.equals("C02")){ |
| | | key = "D04"; |
| | | } |
| | | // Map<String,Object> map = new HashMap(); |
| | | // map.put(key, 0.01); |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | String mapString = "{\""+key+"\":0.01,\"res\":\""+String.valueOf(System.currentTimeMillis())+"\"}"; |
| | | log.debug("èªå¨å
³éï¼"+mapString); |
| | | EmqClient emqClient = new EmqClient(carId+"mqttPublish"+UUID.randomUUID()); |
| | | emqClient.connect(); |
| | | emqClient.publish(ardSyCarRtu.getTopicPublish(),mapString, QosEnum.QoS2,false); |
| | | // mqttOnce.publishCar("carId",ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"å¼éï¼"+currents); |
| | | while(true){ |
| | | ArdSyCarLock ardSyCarLock1 = lockService.getCurrentInfo(ardSyCarRtu.getId(),currents); |
| | | Double currentInfo1 = ardSyCarLock1.getCurrentInfo(); |
| | | if(currentInfo1.equals(4.00) || currentInfo1.equals(4)){ |
| | | lockCloseNum +=1; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(lockCloseNum == 2){ |
| | | // Map<String,Object> map = new HashMap<>(); |
| | | // map.put("A01", 100000);//æå¼ç¬¬ä¸è·¯ç»§çµå¨ |
| | | // map.put("A02", 100000);//æå¼ç¬¬äºè·¯ç»§çµå¨ |
| | | // map.put("res", String.valueOf(System.currentTimeMillis())); |
| | | // String mapString = com.alibaba.fastjson.JSON.toJSONString(map); |
| | | log.debug("车è¾"+carId+"æ½å°å½ä»¤åéæåï¼"); |
| | | // mqttOnce.publishCar(carId,ardSyCarRtu.getTopicPublish(),String.valueOf(new JSONObject(map)),"æ½å°"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public Double[] azimuth_offset(double origin_lon, double origin_lat, Integer direction,double distance){ |
| | | Double[] lonlat = new Double[2]; |
| | | if(direction != null && distance > 0){ |
| | | lonlat[0] = origin_lon + distance * Math.sin(direction* Math.PI / 180) * 180 / ( Math.PI * 6371229 * Math.cos(origin_lat * Math.PI / 180)); |
| | | lonlat[1] = origin_lat + distance * Math.cos(direction* Math.PI / 180) / ( Math.PI * 6371229 / 180); |
| | | }else{ |
| | | lonlat[0] = origin_lon; |
| | | lonlat[1] = origin_lat; |
| | | } |
| | | return lonlat; |
| | | } |
| | | |
| | | public Double getDistance(Double velocity ,Double acceleration ,String time){ |
| | | Double distance = velocity*Double.parseDouble(time) + 0.5*acceleration*Double.parseDouble(time)*Double.parseDouble(time); |
| | | return distance; |
| | | } |
| | | |
| | | /*public Double getVelocity(Double velocity ,Double acceleration ,String time){ |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | Long t = (long) 0; |
| | | try { |
| | | t = (new Date().getTime() - simpleDateFormat.parse(time).getTime())/1000; |
| | | } catch (Exception e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | Double velocityt = velocity + acceleration*t; |
| | | return velocityt; |
| | | }*/ |
| | | |
| | | } |