| | |
| | | package com.ld.igds.protocol.bhzn; |
| | | |
| | | import com.ld.igds.data.ConfigData; |
| | | import com.ld.igds.protocol.bhzn.grainv1.server.BhznGrainV1ServerEngine; |
| | | import com.ld.igds.protocol.bhzn.grainv2.server.BhznGrainV2ServerEngine; |
| | | import com.ld.igds.protocol.bhzn.verb.server.BhznVerbServerEngine; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private ConfigData configData; |
| | | @Autowired |
| | | private BhznGrainV2ServerEngine bhznGrainServerEngine; |
| | | private BhznGrainV2ServerEngine bhznGrainServerEngine2; |
| | | @Autowired |
| | | private BhznGrainV1ServerEngine bhznGrainServerEngine1; |
| | | @Autowired |
| | | private BhznVerbServerEngine bhznVerbServerEngine; |
| | | @Override |
| | | public void run(String... strings) throws Exception { |
| | | |
| | | if (configData.getActive().indexOf("pro") >= 0) { |
| | | bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT); |
| | | bhznVerbServerEngine.start(BhznVerbServerEngine.PORT); |
| | | bhznGrainServerEngine1.start(BhznGrainV1ServerEngine.PORT); |
| | | // bhznVerbServerEngine.start(BhznVerbServerEngine.PORT); |
| | | } |
| | | if (configData.getActive().indexOf("dev") >= 0) { |
| | | bhznGrainServerEngine.start(BhznGrainV2ServerEngine.PORT); |
| | | bhznVerbServerEngine.start(BhznVerbServerEngine.PORT); |
| | | bhznGrainServerEngine1.start(BhznGrainV1ServerEngine.PORT); |
| | | //bhznVerbServerEngine.start(BhznVerbServerEngine.PORT); |
| | | } |
| | | } |
| | | } |
| | |
| | | public GrainResponse checkGrain(CheckGrainRequest request) { |
| | | try { |
| | | // çæç²®æ
ä¿¡æ¯ |
| | | String hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), request.getDepotId()); |
| | | |
| | | String hexStr = ""; |
| | | if("5323".equals(request.getCompanyId())){ |
| | | if("0P01".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "1"); |
| | | }else if("0P02".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "1"); |
| | | }else if("0P03".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "2"); |
| | | }else if("0P04".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "2"); |
| | | }else if("0P05".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "3"); |
| | | }else if("0P06".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4"); |
| | | }else if("0P07".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4"); |
| | | }else if("0P08".equals(request.getDepotId())){ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), "4"); |
| | | } |
| | | }else{ |
| | | hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId(), request.getDepotId()); |
| | | } |
| | | |
| | | // //é讯使ç¨çæ¯ä¸»æºé讯 |
| | | // DeviceSer mainSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); |
| | |
| | | import com.ld.igds.common.dto.THDto; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.constant.DepotType; |
| | | import com.ld.igds.grain.GrainUtil; |
| | | import com.ld.igds.grain.dto.GrainItemInfo; |
| | | import com.ld.igds.io.notify.NotifyGrainInvoker; |
| | | import com.ld.igds.models.DepotConf; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.models.DicSysConf; |
| | | import com.ld.igds.models.Grain; |
| | | import com.ld.igds.models.*; |
| | | import com.ld.igds.order.ExeOrderService; |
| | | import com.ld.igds.order.data.ExeRequest; |
| | | import com.ld.igds.protocol.bhzn.grainv1.msg.builder.CommandBuild; |
| | |
| | | //DO NOTHING |
| | | |
| | | log.info("主æº------->>å¹³å°ï¼æ³¨åä¿¡æ¯æ¥æ={}", message); |
| | | DeviceSer ser = coreSerService.getCacheSerBySn(ContextUtil.getDefaultCompanyId(),message.getAddr()); |
| | | DeviceSer ser = coreSerService.getCacheSerBySn("5323",message.getAddr()); |
| | | if(ser!= null ){ |
| | | ser.setIp(message.getIp()); |
| | | ser.setPort(message.getPort()); |
| | |
| | | |
| | | //æ ¹æ®åæºå°åè·ååæºä¿¡æ¯ |
| | | |
| | | DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), message.getAddr()); |
| | | DeviceSer ser = coreSerService.getCacheSer("5323", message.getAddr()); |
| | | if (ser == null) { |
| | | replayGrain(message); |
| | | log.error("主æº-------->>å¹³å°ï¼è§£æç²®æ
å¤±è´¥ï¼æªè·åå°ç³»ç»ç²®æ
主æºé
ç½®ï¼" + message.getAddr()); |
| | |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | return; |
| | | } |
| | | |
| | | Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId()); |
| | | if (null == depot) { |
| | | String info = "ç²®æ
è§£æå¤±è´¥:åæº=" + ser.getName() + "没æè·åå°ç²®æ
åæ°é
ç½®ä»åºã"; |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | return; |
| | | } |
| | | // ç²®æ
çæ¹æ¬¡å·éæ°æ ¹æ®é¢çè°æ´ |
| | | String batchId = ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq()); |
| | | |
| | | // å¤ææ°æ®ææ²¡ææ¶å宿´ |
| | | String[] attCable = depotConf.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | int cableZ = 1; |
| | | int cableY = 1; |
| | | int cableX = 1; |
| | | |
| | | if(DepotType.TYPE_01.equals(depot.getDepotType())){ |
| | | cableZ = Integer.valueOf(attCable[0]); |
| | | cableY = Integer.valueOf(attCable[1]); |
| | | cableX = Integer.valueOf(attCable[2]); |
| | | }else{ |
| | | cableZ = Integer.valueOf(depotConf.getCableCir()); |
| | | cableY = Integer.valueOf(attCable[0]); |
| | | cableX = 1; |
| | | } |
| | | int sumPoint = cableZ * cableY * cableX; |
| | | |
| | | //è·åå½åç²®æ
æ¸©åº¦æ¥æ |
| | |
| | | |
| | | private void analysisGrain2(DeviceSer ser, IoMessage message, ExeRequest exeRequest, DepotConf depotConf, DicSysConf sysConf, String batchId, String grainStr) { |
| | | // è·å宿´çç²®æ
å
ä¿¡æ¯ |
| | | Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId()); |
| | | if (null == depot) { |
| | | String info = "ç²®æ
è§£æå¤±è´¥:åæº=" + ser.getName() + "没æè·åå°ç²®æ
åæ°é
ç½®ä»åºã"; |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | return; |
| | | } |
| | | String[] attCable = depotConf.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | int cableZ = 1; |
| | | int cableY = 1; |
| | | int cableX = 1; |
| | | |
| | | if(DepotType.TYPE_01.equals(depot.getDepotType())){ |
| | | cableZ = Integer.valueOf(attCable[0]); |
| | | cableY = Integer.valueOf(attCable[1]); |
| | | cableX = Integer.valueOf(attCable[2]); |
| | | }else{ |
| | | cableZ = Integer.valueOf(depotConf.getCableCir()); |
| | | cableY = Integer.valueOf(attCable[0]); |
| | | cableX = 1; |
| | | } |
| | | |
| | | // æ ¹æ®å±è¡åè·åæå®é¿åº¦ |
| | | int start = 4 * (depotConf.getCableStart() - ser.getCableStart()) |
| | |
| | | private void addPoint1(List<Double> temps, |
| | | DepotConf depotConf, DeviceSer ser, ExeRequest exeRequest, |
| | | THDto thDto, DicSysConf sysConf, String batchId) { |
| | | |
| | | Depot depot = commonService.getDepotById(depotConf.getCompanyId(),depotConf.getDepotId()); |
| | | if (null == depot) { |
| | | String info = "ç²®æ
è§£æå¤±è´¥:åæº=" + ser.getName() + "没æè·åå°ç²®æ
åæ°é
ç½®ä»åºã"; |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | return; |
| | | } |
| | | //æ ¹æ®çµç¼èµ·å§æ¹ä½åå¸çº¿æ¹åï¼å¯¹ç²®æ
æ°æ®è¿è¡è°æ´ |
| | | if (null != depotConf.getStartOrientation()) { |
| | | temps = reversalGrainPoint(temps, depotConf); |
| | |
| | | } |
| | | |
| | | String[] attCable = depotConf.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | int cableZ = 1; |
| | | int cableY = 1; |
| | | int cableX = 1; |
| | | |
| | | if(DepotType.TYPE_01.equals(depot.getDepotType())){ |
| | | cableZ = Integer.valueOf(attCable[0]); |
| | | cableY = Integer.valueOf(attCable[1]); |
| | | cableX = Integer.valueOf(attCable[2]); |
| | | }else{ |
| | | cableZ = Integer.valueOf(depotConf.getCableCir()); |
| | | cableY = Integer.valueOf(attCable[0]); |
| | | cableX = 1; |
| | | } |
| | | |
| | | |
| | | Grain grain = new Grain(); |
| | | grain.setDepotId(depotConf.getDepotId()); |
| | | grain.setCompanyId(depotConf.getCompanyId()); |
| | | grain.setCable(depotConf.getCableRule()); |
| | | grain.setCableCir(depotConf.getCableCir()); |
| | | grain.setBatchId(batchId); |
| | | grain.setTempIn(Constant.ERROR_TEMP); |
| | | grain.setHumidityIn(Constant.ERROR_TEMP); |
| | |
| | | private void analysisTh(IoMessage message) { |
| | | try { |
| | | THDto th = new THDto(); |
| | | th.setCompanyId(ContextUtil.getDefaultCompanyId()); |
| | | th.setCompanyId("5323"); |
| | | String data = message.getContent(); |
| | | String houseNo = data.substring(0, 2); |
| | | String t = data.substring(4, 8); |
| | |
| | | package com.ld.igds.protocol.bhzn.grainv1.server; |
| | | |
| | | import com.ld.igds.common.CoreCommonService; |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.view.service.DeviceSerService; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Autowired |
| | | private CoreSerService coreSerService; |
| | | |
| | | /** |
| | | * 设å¤å建å¨çº¿ï¼éè¦æ³¨æå½å使ç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºä¸çº¿é»è®¤ææç¸åSNé
ç½®çåæºå
¨é¨ä¸çº¿ |
| | | * |
| | |
| | | session.setBusinessKey(BhznGrainV1ServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | //项ç®éç¨æ çº¿ä¸»æºæ¨¡å¼ï¼ç´æ¥è·åé»è®¤è®¾å¤ |
| | | DeviceSer deviceSer = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), BhznGrainV1ServerUtils.DEFAULT_MAC_ID); |
| | | |
| | | DeviceSer deviceSer = coreSerService.getCacheSerBySn("5323", BhznGrainV1ServerUtils.DEFAULT_MAC_ID); |
| | | if (null == deviceSer) return; |
| | | |
| | | coreSerService.onlineBySn(session.getAddress(), session.getPort(), deviceSer.getSn(), Constant.YN_Y); |
| | | //æ´æ°ç¼å |
| | | coreSerService.refreshCache(deviceSer.getCompanyId()); |
| | |
| | | try{ |
| | | log.info("BHZNæ§å¶LEDå¼å§"); |
| | | BHZNClientEngine test = new BHZNClientEngine( |
| | | "12.10.0.187", 58258); |
| | | "192.168.0.210", 58258); |
| | | test.start(); |
| | | Thread.sleep(3000L); |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| | | xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| | | <modelVersion>4.0.0</modelVersion> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-zldz</artifactId> |
| | | <version>4.0.0-RELEASE</version> |
| | | <packaging>jar</packaging> |
| | | |
| | | <properties> |
| | | <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| | | <java.version>1.8</java.version> |
| | | <igds.version>4.0.0-RELEASE</igds.version> |
| | | </properties> |
| | | |
| | | <dependencies> |
| | | |
| | | <!-- å¼å
¥ä¹å¡æ ¸å¿å
--> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-core</artifactId> |
| | | <version>${igds.version}</version> |
| | | </dependency> |
| | | |
| | | <!-- å¼å
¥IOå
--> |
| | | <dependency> |
| | | <groupId>com.ld.base.io</groupId> |
| | | <artifactId>base-io-netty</artifactId> |
| | | <version>1.0.0-SNAPSHOT</version> |
| | | </dependency> |
| | | |
| | | </dependencies> |
| | | |
| | | <build> |
| | | <plugins> |
| | | <plugin> |
| | | <groupId>org.apache.maven.plugins</groupId> |
| | | <artifactId>maven-compiler-plugin</artifactId> |
| | | <configuration> |
| | | <source>1.8</source> |
| | | <target>1.8</target> |
| | | <compilerArguments> |
| | | <extdirs>src\main\webapp\WEB-INF\lib</extdirs> |
| | | </compilerArguments> |
| | | </configuration> |
| | | </plugin> |
| | | </plugins> |
| | | </build> |
| | | |
| | | </project> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz; |
| | | |
| | | import com.ld.igds.data.ConfigData; |
| | | import com.ld.igds.protocol.zldz.server.ZldzServerEngine; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å¯ä»¥æ ¹æ®é
ç½®æä»¶çµæ´»è°æ´ |
| | | * é
ç½®éç³»ç»èªå¨å¯å¨æå¡ -- æ§è¡é¡ºåº20-29 |
| | | */ |
| | | @Component(ServerRunner.BEAN_ID) |
| | | @Order(value = 22) |
| | | public class ServerRunner implements CommandLineRunner { |
| | | |
| | | public static final String BEAN_ID = "zldz.serverRunner"; |
| | | |
| | | @Autowired |
| | | private ConfigData configData; |
| | | |
| | | @Override |
| | | public void run(String... strings) throws Exception { |
| | | // |
| | | if ("fzzy".equals(configData.getActive())) { |
| | | ZldzServerEngine.start(9201); |
| | | return; |
| | | } |
| | | |
| | | //飿£è´è¿é»è®¤é¨ç½²æå¡å½ååºç¨ä½¿ç¨9000ç«¯å£ |
| | | if (configData.getActive().equals("dev")) { |
| | | ZldzServerEngine.start(9201); |
| | | return; |
| | | } |
| | | |
| | | //飿£è´è¿é»è®¤é¨ç½²æå¡å½ååºç¨ä½¿ç¨9000ç«¯å£ |
| | | if (configData.getActive().indexOf("pro") >= 0) { |
| | | //FZZYå¹³å° |
| | | ZldzServerEngine.start(9201); |
| | | //å
¶ä»å¹³å° |
| | | // ZldzServerEngine.start(ZldzServerEngine.PORT); |
| | | return; |
| | | } |
| | | |
| | | //请注æï¼æ£æ¥çµåæ¬äºæå¡å¨é¨ç½²ç¨çç«¯å£æ¯ï¼8000 |
| | | if (configData.getActive().equals("zldz")) { |
| | | ZldzServerEngine.start(ZldzServerEngine.PORT); |
| | | return; |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.constant.RedisConst; |
| | | import com.ld.igds.grain.dto.GrainSerCableData; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessage; |
| | | import com.ld.igds.protocol.zldz.command.BaseRemoteImpl; |
| | | import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8829; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.task.CommandReSendService; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.RedisUtil; |
| | | import com.ld.igds.view.manager.TempManager; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author vince |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisConf.BEAN_ID) |
| | | public class AnalysisConf extends BaseRemoteImpl { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisConf"; |
| | | |
| | | @Autowired |
| | | private NotifyWebInvoker notifyWebInvoker; |
| | | |
| | | @Autowired |
| | | private CoreSerService serService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private TempManager thManager; |
| | | |
| | | @Autowired |
| | | private CommandReSendService commandReSendService; |
| | | |
| | | /** |
| | | * è§£æåæºé
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param message |
| | | * @param ser |
| | | */ |
| | | public void analysis8816(ReMessage message, DeviceSer ser) { |
| | | |
| | | log.debug("åæº---->>>å¹³å°ï¼æ¶æ¯ç±»å=8816----{}-{}.{}", ser.getCompanyId(), |
| | | ser.getIp(), ser.getPort()); |
| | | |
| | | // æ¸
é¤ç¼å |
| | | commandReSendService.cleanKey(message.getCompanyId(), message.getIp(), |
| | | message.getPort(), ServerUtils.MSG_TYPE_8816); |
| | | |
| | | // æ¸
æ¥åå§åç»éçè§£æ |
| | | commandReSendService.cleanKey(ServerUtils.DEFAULT_COMPANY, |
| | | message.getIp(), message.getPort(), ServerUtils.MSG_TYPE_8816); |
| | | |
| | | ser.setStatus(Constant.YN_Y); |
| | | |
| | | String content = message.getBody().getContent(); |
| | | |
| | | // è¯»åæ å¿ |
| | | int start = 0, len = 1; |
| | | String temp = content.substring(start * 2, start * 2 + len * 2); |
| | | int readTag = BytesUtil.hexToInt(temp); |
| | | |
| | | // 设å¤IDï¼å
¨å±å¯ä¸ |
| | | start = 1; |
| | | len = 2; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | |
| | | // ç½ç»ID |
| | | start = 3; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | |
| | | // ä¿¡é |
| | | start = 4; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | |
| | | // éç |
| | | start = 5; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | |
| | | // 屿° |
| | | start = 6; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setCableZ(BytesUtil.hexToInt(temp)); |
| | | |
| | | // è¡æ° |
| | | start = 7; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setCableY(BytesUtil.hexToInt(temp)); |
| | | |
| | | // åæ° |
| | | start = 8; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setCableX(BytesUtil.hexToInt(temp)); |
| | | |
| | | // çµç¼å¶å¼ |
| | | start = 9; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setCableFormat("0" + BytesUtil.hexToInt(temp)); |
| | | |
| | | // çµç¼ç±»å |
| | | start = 10; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setCableType("0" + BytesUtil.hexToInt(temp)); |
| | | |
| | | // ä¾çµæ¨¡å¼ |
| | | start = 11; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | ser.setPowerModel("0" + BytesUtil.hexToInt(temp)); |
| | | |
| | | String msg = ser.getName() + " è¿ç¨è·åé
ç½®æåï¼è¯·å·æ°æ°æ®æ¥çï¼"; |
| | | |
| | | // ç»ç»ç¼ç |
| | | start = 12; |
| | | temp = content.substring(start * 2); |
| | | if (readTag == 1) {// 表示åçæåè¿å |
| | | ser.setOrgId(ser.getCompanyId()); |
| | | msg = ser.getName() + " è¿ç¨åå
¥æåï¼è¯·å·æ°æ°æ®æ¥çï¼"; |
| | | } else { |
| | | ser.setOrgId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | } |
| | | |
| | | if (null == ser.getSn()) { |
| | | ser.setSn(ser.getId()); |
| | | } |
| | | ser.setIp(message.getIp()); |
| | | ser.setPort(message.getPort()); |
| | | |
| | | // å¼å§åé»è®¤=1 |
| | | if (ser.getCableStart() == 0) { |
| | | ser.setCableStart(1); |
| | | } |
| | | |
| | | log.info("åæº---->>>å¹³å°ï¼åæºé
置解æå®æ----{}-{}-{}-{}ï¼æ´æ°å°ææå¡å¨", |
| | | ser.getCompanyId(), ser.getIp(), ser.getPort(), ser.getName()); |
| | | serService.updateSerById(ser); |
| | | |
| | | // æ´æ°ä¼è¯ä¿¡æ¯ |
| | | super.updateSession(ser.getIp(), ser.getPort(), ser.getCompanyId()); |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg); |
| | | |
| | | //åæºä¸çº¿è¿è¡ä¸æ¬¡æ¸©æ¹¿åº¦éé |
| | | thManager.checkThBySer(ser.getCompanyId(), ser.getId()); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼åå§åæå |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8822(ReMessage reMessage, DeviceSer ser) { |
| | | log.debug("-----------analysis8822------------{}-{}.{}", |
| | | ser.getCompanyId(), ser.getIp(), ser.getPort()); |
| | | |
| | | // æ¸
é¤ç¼å |
| | | commandReSendService.cleanKey(reMessage.getCompanyId(), |
| | | reMessage.getIp(), reMessage.getPort(), |
| | | ServerUtils.MSG_TYPE_8822); |
| | | |
| | | String msg = ser.getName() + " åå§åçµç¼å®æï¼ï¼"; |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼ä¿®æ¹è¿åï¼ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8826(ReMessage reMessage, DeviceSer ser) { |
| | | log.debug("-----------analysis8826------------{}-{}.{}", |
| | | ser.getCompanyId(), ser.getIp(), ser.getPort()); |
| | | |
| | | // æ¸
é¤ç¼å |
| | | commandReSendService.cleanKey(reMessage.getCompanyId(), |
| | | reMessage.getIp(), reMessage.getPort(), |
| | | ServerUtils.MSG_TYPE_8826); |
| | | |
| | | String msg = ser.getName() + " çµç¼ä¿®æ¹æä½å®æ"; |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg); |
| | | } |
| | | |
| | | /** |
| | | * ééçµç¼è·åè¿åï¼åæºè¿åæ¶å°å½ä»¤ä¿¡æ¯ï¼å®é
è¿åå¼å¨8829ä¸è¯´æ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8825(ReMessage reMessage, DeviceSer ser) { |
| | | |
| | | log.debug("-----------analysis8825------------{}-{}.{}", |
| | | ser.getCompanyId(), ser.getIp(), ser.getPort()); |
| | | |
| | | // æ¸
é¤ç¼å |
| | | commandReSendService.cleanKey(reMessage.getCompanyId(), |
| | | reMessage.getIp(), reMessage.getPort(), |
| | | ServerUtils.MSG_TYPE_8825); |
| | | |
| | | String msg = ser.getName() + " 读åééçµç¼å¼å§è¿å"; |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, msg); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * ç»ç«¯åéééçµç¼æ°æ®ç»åå°ï¼åæºä¸»å¨æ¨é |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public void analysis1129(ReMessage reMessage, DeviceSer ser) { |
| | | |
| | | // å¼å§è§£æ |
| | | String content = reMessage.getBody().getContent(); |
| | | |
| | | // ééå· |
| | | int start = 0, len = 1; |
| | | String temp = content.substring(start * 2, start * 2 + len * 2); |
| | | int passCode = BytesUtil.hexToInt(temp); |
| | | |
| | | // ç¹åºå·ï¼æç
§è¿å顺åºå¡«åä»1å¼å§ |
| | | start = 1; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | int iotNum = BytesUtil.hexToInt(temp); |
| | | |
| | | // æ»å
æ° |
| | | start = 2; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | int sumPacket = BytesUtil.hexToInt(temp); |
| | | |
| | | // å½åå
|
| | | start = 3; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | int curPacket = BytesUtil.hexToInt(temp); |
| | | |
| | | // -----------å端éç¥ç»ç«¯æ¶å°ä¿¡æ¯----------------------// |
| | | GrainSerConfRequest request = new GrainSerConfRequest(); |
| | | request.setSerId(ser.getId()); |
| | | request.setBizType(BizType.SYS.getCode()); |
| | | request.setIp(ser.getIp()); |
| | | request.setPort(ser.getPort()); |
| | | request.setCompanyId(ser.getCompanyId()); |
| | | request.setValue1(curPacket); |
| | | |
| | | Message message = CommandBuilder8829.getInstance() |
| | | .buildMessage(request); |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "åå°æ¶å°çµç¼æ°æ®åºç=" |
| | | + message.toString()); |
| | | // åéå½ä»¤ |
| | | send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // -----------å端éç¥ç»ç«¯æ¶å°ä¿¡æ¯ EDN----------------------// |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼è¿åçµç¼ä¿¡æ¯ï¼åæº={}ï¼å½åå
ï¼{}ï¼ä¿¡æ¯={}", ser.getName(), |
| | | curPacket, content); |
| | | |
| | | // 详ç»ä¿¡æ¯ï¼æ¯é¿åº¦5为ä¸ç»æ°æ® |
| | | start = 4; |
| | | temp = content.substring(start * 2); |
| | | |
| | | String redisKey = RedisConst.buildKey(ser.getCompanyId(), |
| | | RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId() + "_" |
| | | + passCode); |
| | | |
| | | List<GrainSerCableData> dataList = null; |
| | | if (curPacket != 1) { |
| | | dataList = (List<GrainSerCableData>) redisUtil.get(redisKey); |
| | | } |
| | | if (null == dataList) |
| | | dataList = new ArrayList<>(); |
| | | |
| | | GrainSerCableData data; |
| | | |
| | | String str1 = temp.substring(0, 160);// æ¸©åº¦ç¹ 40个 |
| | | String str2 = temp.substring(160, 400);// 1ä¸ªæ ¹å·ï¼1个ç¹å·ï¼1个é
ç½®ï¼åè½40ç» |
| | | String temp1, temp2; |
| | | for (int i = 0; i < 40; i++) { |
| | | data = new GrainSerCableData(); |
| | | data.setPassCode(passCode); |
| | | data.setIotNum(i + 1); |
| | | data.setReceiveDate(new Date()); |
| | | //data.setPointIndex(dataList.size() + i + 1); |
| | | |
| | | // 温度 |
| | | temp1 = str1.substring(i * 4, i * 4 + 4); |
| | | data.setTemp(BytesUtil.hexToInt(BytesUtil.tran_LH(temp1)) / 10.0); |
| | | |
| | | //æ ¹å· |
| | | temp2 = str2.substring(i * 6, i * 6 + 6); |
| | | data.setRootIndex(BytesUtil.hexToInt(temp2.substring(0, 2))); |
| | | |
| | | //ç¹å· |
| | | data.setPointIndex(BytesUtil.hexToInt(temp2.substring(2, 4))); |
| | | |
| | | //é
ç½® |
| | | data.setConf(temp2.substring(4, 6)); |
| | | |
| | | dataList.add(data); |
| | | } |
| | | |
| | | // åæ¾ç·©å |
| | | redisUtil.set(redisKey, dataList, 5 * 60); |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, "ç³»ç»æ¶å°çµç¼é
置信æ¯ï¼è¯·æå¨å·æ°ï¼åæº=" |
| | | + ser.getName() + ",éé=" + passCode + ",æ»å
=" |
| | | + sumPacket + ",å½åå
=" + curPacket); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼æ±æ»åºç |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8823(ReMessage reMessage, DeviceSer ser) { |
| | | // å¼å§è§£æ |
| | | String content = reMessage.getBody().getContent(); |
| | | |
| | | // å¨ææ¼æ¥å¯¹è±¡ |
| | | List<GrainSerCableData> dataList = new ArrayList<GrainSerCableData>(); |
| | | String tempStr; |
| | | GrainSerCableData cableData; |
| | | for (int i = 0; i < content.length() / 4; i++) { |
| | | tempStr = content.substring(i * 4, i * 4 + 4); |
| | | cableData = new GrainSerCableData(); |
| | | cableData.setPassCode(i + 1); |
| | | cableData.setReceiveDate(new Date()); |
| | | cableData.setIotNum(BytesUtil.hexToInt(tempStr.substring(0, 2))); |
| | | cableData.setIotErrNum(BytesUtil.hexToInt(tempStr.substring(2, 4))); |
| | | |
| | | dataList.add(cableData); |
| | | } |
| | | |
| | | String redisKey = RedisConst.buildKey(ser.getCompanyId(), |
| | | RedisConst.KEY_TEMP_PREFIX, "CABLE_DATA_" + ser.getId()); |
| | | |
| | | // åæ¾ç·©å |
| | | redisUtil.set(redisKey, dataList, 5 * 60); |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_SUCCESS, BizType.SYS, |
| | | "ç³»ç»æ¶å°çµç¼æ±æ»ä¿¡æ¯ï¼è¯·æå¨æ´æ°æ¥çï¼è¿åä¿¡æ¯ï¼åæº=" + ser.getName()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis; |
| | | |
| | | import com.ld.igds.common.CoreCommonService; |
| | | import com.ld.igds.common.dto.THDto; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.constant.DepotType; |
| | | import com.ld.igds.grain.GrainUtil; |
| | | import com.ld.igds.grain.dto.GrainItemInfo; |
| | | import com.ld.igds.io.notify.NotifyGrainInvoker; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.models.DepotConf; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.models.DicSysConf; |
| | | import com.ld.igds.models.Grain; |
| | | import com.ld.igds.order.ExeOrderService; |
| | | import com.ld.igds.order.data.ExeRequest; |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessage; |
| | | import com.ld.igds.protocol.zldz.command.RemoteGrainServiceImpl; |
| | | import com.ld.igds.protocol.zldz.task.CommandReSendService; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.th.CoreThService; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | import com.ld.igds.warn.WarnUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * ç²®æ
è§£æ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisGrain.BEAN_ID) |
| | | public class AnalysisGrain { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisGrain"; |
| | | |
| | | @Autowired |
| | | private CoreCommonService commonService; |
| | | @Autowired |
| | | private CoreThService thService; |
| | | @Autowired |
| | | private ExeOrderService exeOrderService; |
| | | @Autowired |
| | | private GrainUtil grainUtil; |
| | | @Autowired |
| | | private NotifyGrainInvoker notifyGrainInvoker; |
| | | @Autowired |
| | | private RemoteGrainServiceImpl remoteGrainService; |
| | | @Autowired |
| | | private CommandReSendService commandReSendService; |
| | | @Autowired |
| | | private WarnUtils warnUtils; |
| | | |
| | | public static Map<String, Map<String, String>> contextMap = new HashMap<>(); |
| | | |
| | | public static double ERROR_CHECK_TAG = -100.0; |
| | | |
| | | public static double FAULT_CHECK_TAG = 85.0; |
| | | |
| | | public static double ERROR_CHECK_TAG2 = 50; |
| | | |
| | | public static double MAX_TEMP = -50.0; |
| | | public static double MIN_TEMP = 50.0; |
| | | |
| | | /** |
| | | * åå°åé请æ±åï¼ç»ç«¯çååº |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8815(ReMessage reMessage, DeviceSer ser) { |
| | | BaseRequest request = new BaseRequest(); |
| | | request.setSerId(ser.getId()); |
| | | request.setCompanyId(ser.getCompanyId()); |
| | | request.setIp(reMessage.getIp()); |
| | | request.setPort(reMessage.getPort()); |
| | | request.setSerName(ser.getName()); |
| | | |
| | | remoteGrainService.reply8815(request); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¶å°ç²®æ
çåå¤ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void reply8817(ReMessage reMessage, DeviceSer ser) { |
| | | String bodyMsg = reMessage.getBody().getContent(); |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼æ¶å°çç²®æ
ä¿¡æ¯-{}-{}-{}", ser.getCompanyId(), |
| | | ser.getName(), reMessage.getStrMsg()); |
| | | // Step1æ ¹æ®éè¦ç®åéè¦çä¿¡æ¯ |
| | | String ua = bodyMsg.substring(0 * 2, 1 * 2); |
| | | log.debug("è·åå°ççµåä¿¡æ¯ï¼ç³»ç»ä¸ä¿ç={}", ua); |
| | | |
| | | // æ»å
æ° |
| | | // int sumPacket = BytesUtil.hexToInt(bodyMsg.substring(1 * 2, 1 * 2 + 1 |
| | | // * 2)); |
| | | // å½åå
|
| | | String hexCurPacket = bodyMsg.substring(2 * 2, 2 * 2 + 1 * 2); |
| | | // int curPacket = BytesUtil.hexToInt(hexCurPacket); |
| | | |
| | | BaseRequest request = new BaseRequest(); |
| | | request.setSerId(ser.getId()); |
| | | request.setCompanyId(ser.getCompanyId()); |
| | | request.setIp(reMessage.getIp()); |
| | | request.setPort(reMessage.getPort()); |
| | | request.setSerName(ser.getName()); |
| | | |
| | | remoteGrainService.reply8817(request, hexCurPacket); |
| | | } |
| | | |
| | | @Transactional |
| | | public void analysis8817(ReMessage msg, DeviceSer ser) { |
| | | // æ¥å°ä¿¡æ¯åå¤--ä¸»æº |
| | | reply8817(msg, ser); |
| | | |
| | | // é¦å
è·åå°ç³»ç»åæ°ï¼å¤ææ¯å¦éè¦æ¹æ¬¡èªå¨ä¼å |
| | | DicSysConf sysConf = commonService.getCacheSysConf(ser.getCompanyId()); |
| | | |
| | | List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId()); |
| | | |
| | | if (null == list || list.isEmpty()) { |
| | | String info = "ç²®æ
è§£æå¤±è´¥:åæº=" + ser.getName() + "没æè·åå°æå±ä»åºä¿¡æ¯ã"; |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | ExeRequest exeRequest = list.get(0); |
| | | log.info("è·åç²®æ
å½ä»¤ä¿¡æ¯={}", exeRequest); |
| | | DepotConf depotConf = commonService.getCacheDepotConf( |
| | | exeRequest.getCompanyId(), exeRequest.getDepotId()); |
| | | if (null == depotConf) { |
| | | String info = "ç²®æ
è§£æå¤±è´¥:åæº=" + ser.getName() + "没æè·åå°ç²®æ
åæ°é
置信æ¯ã"; |
| | | log.error("åæº------>>>å¹³å°ï¼" + info); |
| | | notifyGrainInvoker.notifyWeb(ser.getCompanyId(), |
| | | OrderRespEnum.MSG_ERROR, BizType.GRAIN, info); |
| | | return; |
| | | } |
| | | |
| | | analysisStep(depotConf, msg, ser, exeRequest, sysConf); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¼å§è§£æ |
| | | * |
| | | * @param ser |
| | | * @param msg |
| | | * @throws Exception |
| | | */ |
| | | private void analysisStep(DepotConf depotConf, ReMessage msg, |
| | | DeviceSer ser, ExeRequest exeRequest, DicSysConf sysConf) { |
| | | // ç²®æ
çæ¹æ¬¡å·éæ°æ ¹æ®é¢çè°æ´ |
| | | msg.setBatchId(ContextUtil.getBatchIdByFireq(depotConf.getGrainFreq())); |
| | | |
| | | String bodyMsg = msg.getBody().getContent(); |
| | | |
| | | log.debug("{}-{}=æ¶å°çç²®æ
ä¿¡æ¯={}", ser.getCompanyId(), ser.getName(), |
| | | msg.getStrMsg()); |
| | | |
| | | // Step1æ ¹æ®éè¦ç®åéè¦çä¿¡æ¯ |
| | | String ua = bodyMsg.substring(0 * 2, 1 * 2); |
| | | log.debug("è·åå°ççµåä¿¡æ¯ï¼ç³»ç»ä¸ä¿ç={}", ua); |
| | | |
| | | // æ»å
æ° |
| | | int sumPacket = BytesUtil.hexToInt(bodyMsg.substring(1 * 2, |
| | | 1 * 2 + 1 * 2)); |
| | | // å½åå
|
| | | String hexCurPacket = bodyMsg.substring(2 * 2, 2 * 2 + 1 * 2); |
| | | int curPacket = BytesUtil.hexToInt(hexCurPacket); |
| | | |
| | | log.debug("åæº={},å
æ»æ°={},å½åå
={}", ser.getName(), sumPacket, curPacket); |
| | | |
| | | // ç²®é£æ¸©åº¦ä¿¡æ¯ |
| | | String grainStr = bodyMsg.substring(3 * 2); |
| | | |
| | | String contextKey = this.buildContextKey(msg, depotConf.getDepotId()); |
| | | String curKey = this.buildCurKey(msg, curPacket); |
| | | |
| | | Map<String, String> curMap = contextMap.get(contextKey); |
| | | if (null == curMap) { |
| | | curMap = new HashMap<>(); |
| | | contextMap.put(contextKey, curMap); |
| | | } |
| | | contextMap.get(contextKey).put(curKey, grainStr); |
| | | |
| | | // æ°æ®åå¤å¥½ï¼å¼å§æ§è¡è§£æ |
| | | if (curPacket == sumPacket) { |
| | | analysisStep0(depotConf, msg, ser, exeRequest, contextKey, |
| | | sumPacket, sysConf); |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼å½ä»¤ç±»å=8817--ç²®æ
å
¨é¨æ¶å°ï¼å¼å§è§£æ-{}-{}", |
| | | ser.getCompanyId(), ser.getName()); |
| | | // æ¸
é¤å½ä»¤ |
| | | commandReSendService.cleanKey(msg.getCompanyId(), msg.getIp(), |
| | | msg.getPort(), ServerUtils.MSG_TYPE_8817); |
| | | } |
| | | } |
| | | |
| | | private void analysisStep0(DepotConf depotConf, ReMessage msg, |
| | | DeviceSer ser, ExeRequest exeRequest, String contextKey, |
| | | int sumPacket, DicSysConf sysConf) { |
| | | |
| | | Map<String, String> curMap = contextMap.get(contextKey); |
| | | |
| | | List<DepotConf> depotConfs = null; |
| | | |
| | | // ä¸åæºå¤ä»ï¼æèµ·å§åæ¾å°æå¤§è¿è¡éé |
| | | if (Constant.YN_Y.equals(sysConf.getGrainMoreTag())) { |
| | | depotConfs = commonService.getCacheDepotConfBySerId2( |
| | | depotConf.getCompanyId(), ser.getId()); |
| | | } |
| | | |
| | | if (null == depotConfs) {// ä¸ä¸ªåæº1ä¸ªä» |
| | | if (DepotType.TYPE_02.getCode().equals(depotConf.getDepotType())) { |
| | | analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) { |
| | | analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else { |
| | | analysisStep1(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | |
| | | // ä¸åå å¤ä»æ
åµï¼èèåä»ééåå¤ä»éé |
| | | // åä»ééæ¶åæ°æ®ä»0è¿å |
| | | if (StringUtils.isEmpty(exeRequest.getDepotIds())) { |
| | | |
| | | depotConf.setCableEnd(depotConf.getCableEnd() - depotConf.getCableStart() + 1); |
| | | depotConf.setCableStart(ser.getCableStart()); |
| | | |
| | | if (DepotType.TYPE_02.getCode().equals(depotConf.getDepotType())) { |
| | | analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else if (DepotType.TYPE_04.getCode().equals(depotConf.getDepotType())) { |
| | | analysisStep2(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else { |
| | | analysisStep1(depotConf, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } |
| | | |
| | | return; |
| | | |
| | | } |
| | | |
| | | // æ¹éééææå
³èä¸èµ·ééï¼éåæ§è¡ |
| | | for (DepotConf depotConfTemp : depotConfs) { |
| | | if (DepotType.TYPE_02.getCode().equals(depotConfTemp.getDepotType())) { |
| | | analysisStep2(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else if (DepotType.TYPE_04.getCode().equals(depotConfTemp.getDepotType())) { |
| | | analysisStep2(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } else { |
| | | analysisStep1(depotConfTemp, msg, ser, exeRequest, curMap, sumPacket, sysConf); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åçä»çç²®æ
è§£æ |
| | | * |
| | | * @param depotConf |
| | | * @param msg |
| | | * @param ser |
| | | * @param exeRequest |
| | | * @param packetMap |
| | | * @param sumPackets |
| | | */ |
| | | private void analysisStep2(DepotConf depotConf, ReMessage msg, |
| | | DeviceSer ser, ExeRequest exeRequest, |
| | | Map<String, String> packetMap, int sumPackets, DicSysConf sysConf) { |
| | | if (StringUtils.isEmpty(depotConf.getCableRule()) |
| | | || StringUtils.isEmpty(depotConf.getCableCir())) { |
| | | log.error("åæº------>>>å¹³å°ï¼å½åä»åºï¼{}-{}ï¼æ²¡ææ²¡æé
ç½®å¸çº¿è§åï¼æ æ³è§£æç²®æ
ä¿¡æ¯â¦â¦", |
| | | ser.getCompanyId(), depotConf.getDepotName()); |
| | | return; |
| | | } |
| | | |
| | | String[] cableRuleAtt = depotConf.getCableRule().split("-"); |
| | | String[] cableCirAtt = depotConf.getCableCir().split("-"); |
| | | |
| | | if (cableRuleAtt.length != cableCirAtt.length) { |
| | | log.error("åæº------>>>å¹³å°ï¼å½åä»åºï¼{}-{}ï¼å¸çº¿è§å䏿£ç¡®ï¼æ æ³è§£æç²®æ
ä¿¡æ¯â¦â¦", ser.getCompanyId(), depotConf.getDepotName()); |
| | | return; |
| | | } |
| | | |
| | | |
| | | //é¿å
空æé |
| | | if (null == depotConf.getCableCone()) depotConf.setCableCone(Constant.CABLE_CONE_0); |
| | | |
| | | // è·åæå¤§çå±é
ç½®--é»è®¤æ¯ä¸åé½ä¸æ · |
| | | int layMax = Integer.valueOf(cableCirAtt[0]); |
| | | for (int i = 0; i < cableCirAtt.length; i++) { |
| | | if (Integer.valueOf(cableCirAtt[i]) >= layMax) layMax = Integer.valueOf(cableCirAtt[i]); |
| | | } |
| | | |
| | | // è·å宿´çç²®æ
å
ä¿¡æ¯ |
| | | String strPoints = ""; |
| | | for (int i = 1; i <= sumPackets; i++) { |
| | | strPoints += packetMap.get(buildCurKey(msg, i)); |
| | | } |
| | | |
| | | log.info("------çä»å®æ´çç²®æ
æ¥æ={}------", strPoints); |
| | | |
| | | int sumNum = 0, cableZ = 1;// sumNum å
±å¤å°æ ¹çµç¼ï¼cableZ å±çæå¤§å¼ï¼é¥å½¢ä»è¡¥é½æå¤§å± |
| | | for (int i = 0; i < cableCirAtt.length; i++) { |
| | | if (Integer.valueOf(cableCirAtt[i]) > cableZ) { |
| | | cableZ = Integer.valueOf(cableCirAtt[i]); |
| | | } |
| | | sumNum += Integer.valueOf(cableRuleAtt[i]); |
| | | } |
| | | |
| | | // æ ¹æ®å±è¡åè·åæå®é¿åº¦ |
| | | int start = 4 * (depotConf.getCableStart() - ser.getCableStart()) * cableZ; |
| | | int len = 4 * cableZ * sumNum; |
| | | |
| | | strPoints = strPoints.substring(start, start + len); |
| | | log.info("åæº------>>>å¹³å°ï¼è¿åç²®æ
宿´ä¿¡æ¯ï¼æå±ç»ç»={}ï¼åæº={}", ser.getCompanyId(), ser.getName()); |
| | | |
| | | // å°ç²®æ
è§£æææ°ç» |
| | | List<Double> temps = new ArrayList<>(); |
| | | double tempValue; |
| | | String temp; |
| | | int curLay = 1;//æå¨å±ä»1å¼å§ |
| | | int curRoot = 1;//æå¨æ ¹ |
| | | int curCir = 1;//æå¨å |
| | | int cirLay = 1;//å½ååçå± |
| | | for (int i = 0; i < strPoints.length() / 4; i++) { |
| | | temp = strPoints.substring(i * 4, i * 4 + 4); |
| | | if (temp == null) { |
| | | temp = "0000"; |
| | | } |
| | | tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0; |
| | | |
| | | //éæ£å¸¸å¼ |
| | | if (tempValue > ERROR_CHECK_TAG2) { |
| | | tempValue = Constant.ERROR_TEMP; |
| | | } |
| | | |
| | | // æ
éå¼å¤ç |
| | | if (tempValue >= FAULT_CHECK_TAG) { |
| | | tempValue = Constant.FAULT_TEMP; |
| | | } |
| | | |
| | | // å¤ç¨å¼ |
| | | if (tempValue == ERROR_CHECK_TAG) { |
| | | tempValue = Constant.ERROR_TEMP; |
| | | |
| | | |
| | | //éªè¯æ¯ä¸æ¯é¥å½¢ä»è¡¥å¿å¼ |
| | | curLay = (i % layMax) + 1; |
| | | curRoot = (i / layMax) + 1; |
| | | curCir = getCurCir(curRoot, cableRuleAtt); |
| | | |
| | | cirLay = Integer.valueOf(cableCirAtt[curCir - 1]); |
| | | |
| | | //æ¯å¦é
ç½®äº5å±ä½æ¯å½åæ¯6å±ï¼è¯´æå½åç¹ä¸ºè¡¥å¿ç¹ |
| | | if (curLay > cirLay) { |
| | | tempValue = Constant.ADD_TEMP; |
| | | |
| | | //夿æ¯ä¸æ¯ä¸é¥å½¢ï¼å°è¡¥ç¹è½¬ç§»å°ä¸æ¹ |
| | | if (Constant.CABLE_CONE_1.equals(depotConf.getCableCone())) { |
| | | int index = i - curLay - 1; |
| | | temps.add(index, tempValue); |
| | | }else { |
| | | temps.add(tempValue); |
| | | } |
| | | |
| | | } else { |
| | | temps.add(tempValue); |
| | | } |
| | | |
| | | } else { |
| | | temps.add(tempValue); |
| | | } |
| | | } |
| | | |
| | | log.debug("-------CheckGrainRequest--={}", exeRequest.toString()); |
| | | THDto thDto = thService.getCacheTH(exeRequest.getCompanyId(), exeRequest.getTempSerId(), exeRequest.getThConf()); |
| | | if (null != thDto) { |
| | | log.debug("-------THDto--={}", thDto.toString()); |
| | | } |
| | | |
| | | // å°éåè§£ææåæ æ°æ® |
| | | addPoint2(temps, msg, depotConf, exeRequest, thDto, sysConf); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åè·æå¨å |
| | | * |
| | | * @param curRoot |
| | | * @param cableRuleAtt |
| | | * @return |
| | | */ |
| | | private int getCurCir(int curRoot, String[] cableRuleAtt) { |
| | | |
| | | int sum = 0; |
| | | for (int i = 0; i < cableRuleAtt.length; i++) { |
| | | sum += Integer.valueOf(cableRuleAtt[i]); |
| | | if (curRoot <= sum) return i + 1; |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * å¹³æ¹ä»çè§£æï¼è§£æéè¦èèå½åæ¯å¦å¯ç¨çä¸åæºå¤ä» |
| | | * |
| | | * @param depotConf |
| | | * @param msg |
| | | * @param ser |
| | | * @param exeRequest |
| | | * @param packetMap |
| | | * @param sumPackets |
| | | */ |
| | | private void analysisStep1(DepotConf depotConf, ReMessage msg, |
| | | DeviceSer ser, ExeRequest exeRequest, |
| | | Map<String, String> packetMap, int sumPackets, DicSysConf sysConf) { |
| | | // è·å宿´çç²®æ
å
ä¿¡æ¯ |
| | | String strPoints = ""; |
| | | for (int i = 1; i <= sumPackets; i++) { |
| | | strPoints += packetMap.get(buildCurKey(msg, i)); |
| | | } |
| | | String[] attCable = depotConf.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | |
| | | // æ ¹æ®å±è¡åè·åæå®é¿åº¦ |
| | | int start = 4 * (depotConf.getCableStart() - ser.getCableStart()) |
| | | * cableZ * cableY; |
| | | int len = 4 * cableZ * cableY * cableX; |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼è¿åç²®æ
宿´ä¿¡æ¯ï¼æå±ç»ç»={}ï¼åæº={}", ser.getCompanyId(), ser.getName()); |
| | | |
| | | strPoints = strPoints.substring(start, start + len); |
| | | |
| | | // å°ç²®æ
è§£æææ°ç» |
| | | List<Double> temps = new ArrayList<>(); |
| | | double tempValue; |
| | | String temp; |
| | | for (int i = 0; i < strPoints.length() / 4; i++) { |
| | | temp = strPoints.substring(i * 4, i * 4 + 4); |
| | | if (temp == null) { |
| | | temp = "0000"; |
| | | } |
| | | tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0; |
| | | // 说æè§£æçæ°æ®æé®é¢ |
| | | if (tempValue == ERROR_CHECK_TAG || tempValue == ERROR_CHECK_TAG2) { |
| | | tempValue = Constant.ERROR_TEMP; |
| | | } |
| | | // æ
éå¼å¤ç |
| | | if (tempValue >= FAULT_CHECK_TAG) { |
| | | tempValue = Constant.FAULT_TEMP; |
| | | } |
| | | temps.add(tempValue); |
| | | } |
| | | |
| | | log.debug("-------CheckGrainRequest--={}", exeRequest.toString()); |
| | | THDto thDto = thService.getCacheTH(exeRequest.getCompanyId(), |
| | | exeRequest.getTempSerId(), exeRequest.getThConf()); |
| | | if (null != thDto) { |
| | | log.debug("-------THDto--={}", thDto.toString()); |
| | | } |
| | | // å°éåè§£ææåæ æ°æ® |
| | | addPoint1(temps, msg, depotConf, ser, exeRequest, thDto, sysConf); |
| | | } |
| | | |
| | | private String buildCurKey(ReMessage msg, int curPacket) { |
| | | return msg.getSourceId() + "_" + curPacket; |
| | | } |
| | | |
| | | private String buildContextKey(ReMessage msg, String depotId) { |
| | | return msg.getCompanyId() + "_" + msg.getSourceId() + "_" + depotId; |
| | | } |
| | | |
| | | /** |
| | | * å¹³æ¿ä»ï¼è§£æç¬¬äºæ¥ï¼è§£æå°åæ æ°æ® |
| | | * |
| | | * @param temps |
| | | * @throws Exception |
| | | */ |
| | | private void addPoint1(List<Double> temps, ReMessage msg, |
| | | DepotConf depotConf, DeviceSer ser, ExeRequest exeRequest, |
| | | THDto thDto, DicSysConf sysConf) { |
| | | |
| | | //æ ¹æ®çµç¼èµ·å§æ¹ä½åå¸çº¿æ¹åï¼å¯¹ç²®æ
æ°æ®è¿è¡è°æ´ |
| | | if (null != depotConf.getStartOrientation()) { |
| | | temps = reversalGrainPoint(temps, depotConf); |
| | | } |
| | | |
| | | //è¥èµ·ç¹ç¹ä½ä¸ºåºé¨ï¼åå°ç²®æ
æ°æ®è¿è¡ç¿»è½¬ |
| | | if (null != depotConf.getStartPoint() |
| | | && Constant.GRAIN_START_POINT_BELOW.equals(depotConf.getStartPoint())) { |
| | | temps = grainUtil.reversalUpAndDown(temps, depotConf.getCableRule()); |
| | | } |
| | | |
| | | String[] attCable = depotConf.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | |
| | | Grain grain = new Grain(); |
| | | grain.setDepotId(depotConf.getDepotId()); |
| | | grain.setCompanyId(depotConf.getCompanyId()); |
| | | grain.setCable(depotConf.getCableRule()); |
| | | grain.setBatchId(msg.getBatchId()); |
| | | grain.setTempIn(Constant.ERROR_TEMP); |
| | | grain.setHumidityIn(Constant.ERROR_TEMP); |
| | | |
| | | if (null != thDto) { |
| | | log.debug("ç²®æ
è§£æä¸è·åå°ç温湿度信æ¯={}", thDto.toString()); |
| | | grain.setHumidityIn(thDto.getHumidityIn()); |
| | | grain.setTempIn(thDto.getTempIn()); |
| | | } |
| | | grain.setReceiveDate(msg.getReceiveDate()); |
| | | grain.setRemark("粮温æ£å¸¸"); |
| | | |
| | | // è·åç¼åä¸çå½ä»¤ä¿¡æ¯ |
| | | grain.setCheckUser(exeRequest.getExeUser()); |
| | | |
| | | double max = MAX_TEMP, min = MIN_TEMP, sumT = 0.0, sumNum = cableX |
| | | * cableY * cableZ; |
| | | |
| | | // æ ¡éªåå®ç°ç»è®¡ï¼çæééç¹ä¿¡æ¯ |
| | | List<GrainItemInfo> listGrainItems = new ArrayList<>(); |
| | | int i = 1; |
| | | for (Double temp : temps) { |
| | | if (temp == Constant.ERROR_TEMP || temp == Constant.FAULT_TEMP || temp == Constant.ADD_TEMP) { |
| | | sumNum--; |
| | | } else { |
| | | sumT += temp; |
| | | if (temp > max) { |
| | | max = temp; |
| | | } |
| | | if (temp < min) { |
| | | min = temp; |
| | | } |
| | | } |
| | | listGrainItems.add(new GrainItemInfo(i, temp)); |
| | | i++; |
| | | } |
| | | |
| | | if (sumNum == 0) { |
| | | sumNum = 1; |
| | | grain.setRemark("å½åç²®æ
ééå¼å¸¸"); |
| | | } |
| | | //è¿æ»¤æ¯è¾ç¨çæå¤§æå°å¼ |
| | | if(max == MAX_TEMP){ |
| | | max = 0.0; |
| | | } |
| | | if(min == MIN_TEMP){ |
| | | min = 0.0; |
| | | } |
| | | if (null != depotConf.getTempMax() && max > depotConf.getTempMax()) { |
| | | grain.setRemark("ä»åºé
ç½®é«æ¸©è¦åå¼ï¼" + depotConf.getTempMax() + "ï¼å½åæ£æµé«æ¸©å¼ï¼" |
| | | + max); |
| | | warnUtils.addGrainWarn(depotConf, grain); |
| | | } |
| | | |
| | | grain.setTempAve(sumT / sumNum); |
| | | grain.setTempMax(max); |
| | | grain.setTempMin(min); |
| | | grain.setPoints(StringUtils.join(temps, ",")); |
| | | |
| | | String depotIds = exeRequest.getDepotIds(); |
| | | |
| | | boolean notifyWeb = true; |
| | | if (null != depotIds && depotIds.indexOf(depotConf.getDepotId()) == -1) { |
| | | notifyWeb = false; |
| | | } |
| | | // ç¨æ·å°è£
å¥½æ°æ®å³å¯ |
| | | notifyGrainInvoker.analysisSuccess(grain, listGrainItems, depotConf, |
| | | sysConf, notifyWeb, exeRequest); |
| | | } |
| | | |
| | | /** |
| | | * åçä»è§£ææ¥éª¤ |
| | | * |
| | | * @param temps |
| | | * @param msg |
| | | * @param depotConf |
| | | * @param exeRequest |
| | | * @param thDto |
| | | */ |
| | | private void addPoint2(List<Double> temps, ReMessage msg, |
| | | DepotConf depotConf, ExeRequest exeRequest, THDto thDto, |
| | | DicSysConf sysConf) { |
| | | |
| | | Grain grain = new Grain(); |
| | | grain.setDepotId(depotConf.getDepotId()); |
| | | grain.setCompanyId(depotConf.getCompanyId()); |
| | | grain.setCable(depotConf.getCableRule()); |
| | | grain.setCableCir(depotConf.getCableCir()); |
| | | grain.setBatchId(msg.getBatchId()); |
| | | grain.setTempIn(Constant.ERROR_TEMP); |
| | | grain.setHumidityIn(Constant.ERROR_TEMP); |
| | | if (null != thDto) { |
| | | log.debug("ç²®æ
è§£æä¸è·åå°ç温湿度信æ¯={}", thDto.toString()); |
| | | grain.setHumidityIn(thDto.getHumidityIn()); |
| | | grain.setTempIn(thDto.getTempIn()); |
| | | } |
| | | grain.setReceiveDate(msg.getReceiveDate()); |
| | | grain.setRemark("粮温æ£å¸¸"); |
| | | grain.setCheckUser(exeRequest.getExeUser()); |
| | | |
| | | double max = MAX_TEMP, min = MIN_TEMP, sumT = 0.0; |
| | | |
| | | int sumNum = temps.size(); |
| | | List<GrainItemInfo> listGrainItems = new ArrayList<>(); |
| | | int i = 1; |
| | | for (Double temp : temps) { |
| | | if (temp == Constant.ERROR_TEMP || temp == Constant.FAULT_TEMP || temp == Constant.ADD_TEMP) { |
| | | sumNum--; |
| | | } else { |
| | | sumT += temp; |
| | | if (temp > max) { |
| | | max = temp; |
| | | } |
| | | if (temp < min) { |
| | | min = temp; |
| | | } |
| | | } |
| | | listGrainItems.add(new GrainItemInfo(i, temp)); |
| | | i++; |
| | | } |
| | | |
| | | if (sumNum == 0) { |
| | | sumNum = 1; |
| | | grain.setRemark("å½åç²®æ
ééå¼å¸¸"); |
| | | } |
| | | //è¿æ»¤æ¯è¾ç¨çæå¤§æå°å¼ |
| | | if(max == MAX_TEMP){ |
| | | max = 0.0; |
| | | } |
| | | if(min == MIN_TEMP){ |
| | | min = 0.0; |
| | | } |
| | | if (null != depotConf.getTempMax() && max > depotConf.getTempMax()) { |
| | | grain.setRemark("ä»åºé
ç½®é«æ¸©è¦åå¼ï¼" + depotConf.getTempMax() + "ï¼å½åæ£æµé«æ¸©å¼ï¼" |
| | | + max); |
| | | warnUtils.addGrainWarn(depotConf, grain); |
| | | } |
| | | |
| | | grain.setTempAve(sumT / sumNum); |
| | | grain.setTempMax(max); |
| | | grain.setTempMin(min); |
| | | grain.setPoints(StringUtils.join(temps, ",")); |
| | | |
| | | String depotIds = exeRequest.getDepotIds(); |
| | | boolean notifyWeb = true; |
| | | if (null != depotIds && depotIds.indexOf(depotConf.getDepotId()) == -1) { |
| | | notifyWeb = false; |
| | | } |
| | | |
| | | // ç¨æ·å°è£
å¥½æ°æ®å³å¯ |
| | | notifyGrainInvoker.analysisSuccess(grain, listGrainItems, depotConf, |
| | | sysConf, notifyWeb, exeRequest); |
| | | } |
| | | |
| | | private List<Double> reversalGrainPoint(List<Double> temps, DepotConf conf) { |
| | | if (StringUtils.isEmpty(conf.getStartOrientation())) { |
| | | //è¥èµ·å§æ¹ä½ä¸ºç©ºï¼åé»è®¤èµ·å§æ¹ä½åæ¹åï¼ç´æ¥è¿å |
| | | return temps; |
| | | } |
| | | //èµ·å§æ¹ä½ä¸ºå³è¾¹æ¶ |
| | | if (Constant.GRAIN_START_ORIENTATION_RIGHT.equals(conf.getStartOrientation())) { |
| | | if (StringUtils.isEmpty(conf.getStartDirection())) { |
| | | //å³è¾¹èµ·å§ï¼é»è®¤çºµåå¸çº¿ï¼ç´æ¥è¿å |
| | | return temps; |
| | | } |
| | | if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) { |
| | | //å³è¾¹èµ·å§ï¼æ¨ªåå¸çº¿ |
| | | return grainUtil.reversalRight1(temps, conf.getCableRule()); |
| | | } |
| | | //å³è¾¹èµ·å§ï¼é»è®¤çºµåå¸çº¿ï¼ç´æ¥è¿å |
| | | return temps; |
| | | } |
| | | //èµ·å§æ¹ä½ä¸ºå³ä¸æ¶ |
| | | if (Constant.GRAIN_START_ORIENTATION_RIGHT_UP.equals(conf.getStartOrientation())) { |
| | | if (StringUtils.isEmpty(conf.getStartDirection())) { |
| | | //å³ä¸èµ·å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalRightUp2(temps, conf.getCableRule()); |
| | | } |
| | | if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) { |
| | | //å³ä¸èµ·å§ï¼æ¨ªåå¸çº¿ |
| | | return grainUtil.reversalRightUp1(temps, conf.getCableRule()); |
| | | } |
| | | //å³ä¸èµ·å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalRightUp2(temps, conf.getCableRule()); |
| | | } |
| | | //èµ·å§æ¹ä½ä¸ºå·¦è¾¹æ¶ |
| | | if (Constant.GRAIN_START_ORIENTATION_LEFT.equals(conf.getStartOrientation())) { |
| | | if (StringUtils.isEmpty(conf.getStartDirection())) { |
| | | //左边起å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalLeft2(temps, conf.getCableRule()); |
| | | } |
| | | if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) { |
| | | //左边起å§ï¼æ¨ªåå¸çº¿ |
| | | return grainUtil.reversalLeft1(temps, conf.getCableRule()); |
| | | } |
| | | //左边起å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalLeft2(temps, conf.getCableRule()); |
| | | } |
| | | //èµ·å§æ¹ä½ä¸ºå·¦ä¸æ¶ |
| | | if (Constant.GRAIN_START_ORIENTATION_LEFT_UP.equals(conf.getStartOrientation())) { |
| | | if (StringUtils.isEmpty(conf.getStartDirection())) { |
| | | //å·¦ä¸èµ·å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalLeftUp2(temps, conf.getCableRule()); |
| | | } |
| | | if (Constant.GRAIN_START_DIRECTION_TRANSVERSE.equals(conf.getStartDirection())) { |
| | | //å·¦ä¸èµ·å§ï¼æ¨ªåå¸çº¿ |
| | | return grainUtil.reversalLeftUp1(temps, conf.getCableRule()); |
| | | } |
| | | //å·¦ä¸èµ·å§ï¼é»è®¤çºµåå¸çº¿ |
| | | return grainUtil.reversalLeftUp2(temps, conf.getCableRule()); |
| | | } |
| | | |
| | | return temps; |
| | | } |
| | | |
| | | /** |
| | | * å转å ç°å®ä¸ä»å·¦è¾¹å¼å§ï¼å¼ºè¡å°å³è¾¹è§£æä¸ºç¬¬ä¸å |
| | | * |
| | | * @return |
| | | */ |
| | | private List<Double> reversalCable(List<Double> temps, String cable) { |
| | | String[] attCable = cable.split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | List<Double> t = new ArrayList<>(); |
| | | for (int i = 1; i <= temps.size(); i++) { |
| | | t.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ)))); |
| | | if (i % (cableY * cableZ) == 0) { |
| | | cableX = cableX - 1; |
| | | } |
| | | } |
| | | return t; |
| | | } |
| | | |
| | | /** |
| | | * çµç¼ä»ä¸é¢å¼å§æ¶ï¼å°ç²®æ
çµç¼ä¸ä¸ç¿»è½¬ |
| | | * |
| | | * @param pointsData ç²®æ
æ°æ® |
| | | * @param cable å±è¡åé
ç½®ï¼å¦ï¼4-7-11 |
| | | * @return |
| | | */ |
| | | private String reversalUpAndDown(String pointsData, String cable) { |
| | | String str = ""; |
| | | if (StringUtils.isEmpty(cable)) { |
| | | str = pointsData; |
| | | } |
| | | String[] attCable = cable.split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); //å± |
| | | |
| | | String[] points = pointsData.split(","); |
| | | for (int i = 0; i <= points.length - cableZ; i += cableZ) { |
| | | for (int j = cableZ - 1; j >= 0; j--) { |
| | | str += points[i + j]; |
| | | str += ","; |
| | | } |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * å转åå·éªè¯ |
| | | * 2022å¹´5æ30æ¥ 12:11:18 |
| | | * vince |
| | | * |
| | | * @param args |
| | | */ |
| | | public static void main(String[] args) { |
| | | List<Double> temps = new ArrayList<>(); |
| | | int cableZ = 3; |
| | | int cableY = 4; |
| | | int cableX = 6; |
| | | for (int i = 1; i < (cableX * cableY * cableZ + 1); i++) { |
| | | temps.add(i + 0.0); |
| | | } |
| | | |
| | | List<Double> t = new ArrayList<>(); |
| | | for (int i = 1; i <= temps.size(); i++) { |
| | | t.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ)))); |
| | | if (i % (cableY * cableZ) == 0) { |
| | | cableX = cableX - 1; |
| | | } |
| | | } |
| | | for (Double x : t) { |
| | | System.out.print(x); |
| | | System.out.print(","); |
| | | } |
| | | |
| | | |
| | | System.out.println("--------------------------"); |
| | | int i = 15; |
| | | int layMax = 10; |
| | | |
| | | System.out.println(i % layMax); |
| | | |
| | | |
| | | System.out.println(i / layMax); |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.order.ExeOrderService; |
| | | import com.ld.igds.order.data.ExeRequest; |
| | | import com.ld.igds.protocol.zldz.analysis.builder.ReMessageBuilder; |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessage; |
| | | import com.ld.igds.protocol.zldz.task.CommandReSendService; |
| | | import com.ld.igds.protocol.zldz.util.CRC8; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * å议解æå
¥å£ |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisService.BEAN_ID) |
| | | public class AnalysisService { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisService"; |
| | | |
| | | @Autowired |
| | | private CoreSerService coreSerService; |
| | | @Autowired |
| | | private AnalysisTH analysisTH; |
| | | @Autowired |
| | | private AnalysisGrain analysisGrain; |
| | | @Autowired |
| | | private AnalysisConf analysisConf; |
| | | @Autowired |
| | | private NotifyWebInvoker notifyWebInvoker; |
| | | @Autowired |
| | | private ExeOrderService exeOrderService; |
| | | @Autowired |
| | | private CommandReSendService commandReSendService; |
| | | |
| | | |
| | | /** |
| | | * @param sessionKey ip:port |
| | | * @param strMsg |
| | | */ |
| | | public void analysis2(String sessionKey, String strMsg) { |
| | | String[] attr = sessionKey.split(":"); |
| | | String ip = attr[0]; |
| | | Integer port = Integer.valueOf(attr[1]); |
| | | |
| | | ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(null, ip, port, strMsg); |
| | | |
| | | if (null == reMessage || null == reMessage.getCompanyId()) { |
| | | log.error("åæº----->>>å¹³å°ï¼è¿åä¿¡æ¯æ²¡æè·åç»ç»ç¼ç ä¿¡æ¯ï¼æ æ³ç»§ç»è§£æ----{}", sessionKey); |
| | | return; |
| | | } |
| | | |
| | | DeviceSer ser = coreSerService.getCacheSer(reMessage.getCompanyId(), reMessage.getSourceId()); |
| | | |
| | | if (null == ser) { |
| | | String info = "åæº=" + reMessage.getSourceId() + "è¿åä¿¡æ¯æ²¡æå¹é
å°åæºï¼ç³»ç»è¸¢åºç¦»çº¿ã"; |
| | | log.error("åæº----->>>å¹³å°ï¼" + info); |
| | | notifyWebInvoker.notifyWeb(reMessage.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, info); |
| | | |
| | | // æ¸
é¤ç¼å并鿝龿¥ |
| | | commandReSendService.destoryAndDelCache(reMessage.getCompanyId(), ip, port, reMessage.getMessageType()); |
| | | return; |
| | | } |
| | | |
| | | log.debug("åæº----->>>å¹³å°ï¼æå±ç»ç»-{}ï¼åæº-{} è¿åçå½ä»¤ä¿¡æ¯={}", ser.getCompanyId(), ser.getName(), reMessage.toString()); |
| | | |
| | | String checkMsg = this.checkMsg(reMessage, ser); |
| | | if (null != checkMsg) { |
| | | // ç³»ç»æ¦æªå°äºå¼å¸¸åå ï¼ä¸è¸¢åºè¿æ¥ |
| | | if (ServerUtils.MSG_TYPE_8815.equals(reMessage.getMessageType()) || ServerUtils.MSG_TYPE_8817.equals(reMessage.getMessageType())) { |
| | | commandReSendService.cleanKey(ser.getCompanyId(), ser.getIp(), ser.getPort(), ServerUtils.MSG_TYPE_8817); |
| | | |
| | | List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.GRAIN.getCode(), ser.getId()); |
| | | |
| | | if (null != list && list.size() > 0) { |
| | | exeOrderService.progressError(ser.getCompanyId(), BizType.GRAIN.getCode(), list.get(0).getDepotId(), checkMsg); |
| | | } else { |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, checkMsg); |
| | | } |
| | | } else { |
| | | commandReSendService.cleanKey(ser.getCompanyId(), ser.getIp(), ser.getPort(), reMessage.getMessageType()); |
| | | |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_ERROR, BizType.SYS, checkMsg); |
| | | } |
| | | |
| | | log.error("åæº----->>>å¹³å°ï¼å½ä»¤éªè¯å¼å¸¸ï¼æå±ç»ç»-{}ï¼å¼å¸¸ä¿¡æ¯-{}ï¼æ¥æä¿¡æ¯-{}", ser.getCompanyId(), checkMsg, reMessage.getStrMsg()); |
| | | return; |
| | | } |
| | | |
| | | switch (reMessage.getMessageType()) { |
| | | case ServerUtils.MSG_TYPE_8828:// 温湿度解æ |
| | | analysisTH.analysis8828(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8815:// ç»ç«¯åºçç²®æ
è¯·æ± |
| | | analysisGrain.analysis8815(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_1117:// ç²®æ
æ°æ®ä¿¡æ¯ |
| | | analysisGrain.analysis8817(reMessage, ser); |
| | | break; |
| | | |
| | | |
| | | case ServerUtils.MSG_TYPE_1129:// ç»ç«¯åéééçµç¼æ°æ®ç»åå° |
| | | analysisConf.analysis1129(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8816:// è§£æé
ç½® |
| | | analysisConf.analysis8816(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8822:// çµç¼åå§åæå |
| | | analysisConf.analysis8822(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8823:// çµç¼æ±æ»åºç |
| | | analysisConf.analysis8823(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8825:// 读åééçµç¼é
ç½® |
| | | analysisConf.analysis8825(reMessage, ser); |
| | | break; |
| | | |
| | | case ServerUtils.MSG_TYPE_8826:// ä¿®æ¹çµç¼çè¿å |
| | | analysisConf.analysis8826(reMessage, ser); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªï¼æ£å¸¸è¿åNULLï¼å¼å¸¸è¿åå¼å¸¸åå ï¼æ£å¸¸å¼å¸¸åå è¿åä¸è¸¢æéæ°è¿æ¥ |
| | | * |
| | | * @param message |
| | | * @param ser |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String checkMsg(ReMessage message, DeviceSer ser) { |
| | | String result; |
| | | if (message.getResult() == 1) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼æ¥æ¶çåºçæ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 2) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼åéçæ°æ®æ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 3) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼æéä¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 4) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼åéè¶
æ¶é误"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 9) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼Io模åä¸å¨çº¿"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 10) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼åéä¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 11) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼æ 线模åæ
é"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 12) { |
| | | result = "åæº=" + ser.getName() |
| | | + " å议解æå¤±è´¥ï¼åå ï¼ä¸»è¦æ¯åé¦åæ ç¹äº¤æ¢å½ä»¤æè
æ¯çµç¼ä¿®æ¹å½ä»¤çéè¯¯ï¼æè
ç²®æ
ééçåæ°ä¸å¯¹"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 13) { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼ç½å
³æªæ³¨å"; |
| | | return result; |
| | | } |
| | | |
| | | // è·åæ ¡éªçæ¥æä¿¡æ¯ |
| | | int end = 4 + 18 * 2 + message.getBody().getLength() * 2; |
| | | String checkStr = message.getStrMsg().substring(4, end); |
| | | |
| | | byte[] byteCrc16 = BytesUtil.hexStrToBytes(checkStr); |
| | | short crc16Hex2 = CRC8.calculateCrc16(byteCrc16, (short) 0, |
| | | (short) (byteCrc16.length)); |
| | | byte[] crc16Hex2Bytes = BytesUtil.shortToByte(crc16Hex2); |
| | | int crc16 = BytesUtil.bytesToInt(crc16Hex2Bytes); |
| | | String hexCrc16 = BytesUtil.intToHexStr(crc16); |
| | | |
| | | if (message.getHexCrc16().equals(hexCrc16)) { |
| | | return null; |
| | | } else { |
| | | result = "åæº=" + ser.getName() + " å议解æå¤±è´¥ï¼åå ï¼CRC16æ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis; |
| | | |
| | | import com.ld.igds.common.dto.THDto; |
| | | import com.ld.igds.constant.BizType; |
| | | import com.ld.igds.constant.Constant; |
| | | import com.ld.igds.io.notify.NotifyWebInvoker; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.order.ExeOrderService; |
| | | import com.ld.igds.order.data.ExeRequest; |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessage; |
| | | import com.ld.igds.th.CoreThService; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * è§£ææ¸©æ¹¿åº¦ä¿¡æ¯ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisTH.BEAN_ID) |
| | | public class AnalysisTH { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisTH"; |
| | | |
| | | @Autowired |
| | | private CoreThService thService; |
| | | |
| | | @Autowired |
| | | private NotifyWebInvoker notifyWebInvoker; |
| | | |
| | | @Autowired |
| | | private ExeOrderService exeOrderService; |
| | | |
| | | public static int ERROR_TH_TAG = -50; |
| | | |
| | | /** |
| | | * è§£æä»åºæ¸©æ¹¿åº¦ä¿¡æ¯ï¼å°ä¿¡æ¯æ¾å¨ç¼åä¸ï¼ä»¥ä¾¿ç²®æ
ä½¿ç¨ |
| | | * |
| | | * @param msg |
| | | * @param ser |
| | | */ |
| | | public void analysis8828(ReMessage msg, DeviceSer ser) { |
| | | |
| | | log.debug("-----------analysis8828------------{}-{}.{}", ser.getCompanyId(), ser.getIp(), ser.getPort()); |
| | | |
| | | String content = msg.getBody().getContent(); |
| | | |
| | | //温湿度å°å,æªå4ä½ |
| | | String temp = content.substring(0, 0 + 2 * 2); |
| | | //é«ä½ä½è½¬æ¢ |
| | | temp = BytesUtil.tran_LH(temp); |
| | | int thConf = BytesUtil.hexToInt(temp); |
| | | |
| | | List<ExeRequest> list = exeOrderService.getInProgressOrderBySerId(BizType.SYS.getCode(), ser.getId() + "_" + thConf); |
| | | ExeRequest exeRequest = list.get(0); |
| | | |
| | | int t, h; |
| | | |
| | | THDto th = new THDto(); |
| | | th.setCompanyId(ser.getCompanyId()); |
| | | th.setTempIn(Constant.ERROR_TEMP); |
| | | th.setHumidityIn(Constant.ERROR_TEMP); |
| | | |
| | | //温度 |
| | | int start = 2, len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | t = BytesUtil.hexToInt(temp); |
| | | if (t > 127) {//è¯´ææ¯è´æ° |
| | | t = BytesUtil.hexToInt("FF" + temp); |
| | | } |
| | | if (t == ERROR_TH_TAG) { |
| | | log.error("{}温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨", ser.getName()); |
| | | th.setRemark(ser.getName() + "温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨"); |
| | | } else { |
| | | th.setTempIn(Double.valueOf(t)); |
| | | } |
| | | |
| | | //湿度 |
| | | start = 3; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | h = BytesUtil.hexToInt(temp); |
| | | if (h > 127) {//è¯´ææ¯è´æ° |
| | | h = BytesUtil.hexToInt("FF" + temp); |
| | | } |
| | | if (h == ERROR_TH_TAG) { |
| | | log.error("{}温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨", ser.getName()); |
| | | th.setRemark(ser.getName() + "温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨"); |
| | | } else { |
| | | th.setHumidityIn(Double.valueOf(h)); |
| | | } |
| | | |
| | | th.setSerId(ser.getId()); |
| | | if (null != exeRequest) { |
| | | th.setThConf(exeRequest.getThConf()); |
| | | } else { |
| | | th.setThConf(thConf + ""); |
| | | } |
| | | |
| | | log.info("仿¸©ä»æ¹¿è§£æå®æ={}", th.toString()); |
| | | |
| | | //æç
§åæºééæ¥ç¡®å® |
| | | thService.setCacheTH(th); |
| | | |
| | | String info = ser.getName() + " 温湿度è·å宿"; |
| | | if (null != exeRequest) { |
| | | //宿 |
| | | exeRequest.setMsg(info); |
| | | exeOrderService.completeCache(exeRequest, false); |
| | | } |
| | | notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, info); |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis.builder; |
| | | |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessage; |
| | | import com.ld.igds.protocol.zldz.analysis.message.ReMessageBody; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.ContextUtil; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * æ ¹æ®æ¥æ¶å°çä¿¡æ¯è¿è¡å°è£
|
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class ReMessageBuilder { |
| | | |
| | | private final static ReMessageBuilder instance = new ReMessageBuilder(); |
| | | |
| | | private ReMessageBuilder() { |
| | | } |
| | | |
| | | public static ReMessageBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | /** |
| | | * 使ç¨ä¸åç°CRC16å¯è½ä»¥EEç»å°¾ï¼NETTY误以为æ¯ç»å°¾å¯¼è´æªåå°äºä¸ä¸ªEEï¼å½åæ¹æ³å¿
é¡»ä»å¤´ååæªåï¼ä¿è¯CRC16çä½ç½®åç¡® |
| | | * |
| | | * @param bytes |
| | | * @param ip |
| | | * @param port |
| | | * @param strMsg |
| | | * @return |
| | | */ |
| | | public ReMessage buildMessage(byte[] bytes, String ip, int port, String strMsg) { |
| | | |
| | | ReMessage message = new ReMessage(); |
| | | message.setIp(ip); |
| | | message.setPort(port); |
| | | message.setStrMsg(strMsg); |
| | | message.setByteMsg(bytes); |
| | | |
| | | // æºIDï¼åæºå¯ä¸ID |
| | | int start = 2, len = 2; |
| | | String temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setSourceId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | |
| | | //åæºæå±ç»ç»ç¼ç |
| | | String companyId = ContextUtil.getCompanyIdBySn(message.getSourceId()); |
| | | |
| | | // ç®æ ID |
| | | start = 4; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setTargetId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | |
| | | // åéID |
| | | start = 6; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setSendId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | |
| | | // è·¯ç±ä¿¡æ¯ï¼ä¸è§£æ |
| | | |
| | | // æ¶æ¯ç±»å |
| | | start = 12; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setMessageType(BytesUtil.tran_LH(temp)); |
| | | |
| | | // å¤çç»æ |
| | | start = 14; |
| | | len = 1; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setResult(BytesUtil.hexToInt(temp)); |
| | | |
| | | // ç»ç»ç¼ç |
| | | start = 15; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | if(null == companyId){ |
| | | message.setCompanyId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | }else{ |
| | | message.setCompanyId(companyId); |
| | | } |
| | | |
| | | //å
å¤´æ ¡éª |
| | | start = 17; |
| | | len = 1; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setHexCrc8(temp); |
| | | |
| | | // å½ä»¤ä½-é¿åº¦ |
| | | message.setBody(buildBody()); |
| | | start = 18; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | int bodyLen = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)); |
| | | message.getBody().setLength(bodyLen); |
| | | |
| | | //å½ä»¤ä½-å
容 |
| | | start = 20; |
| | | len = bodyLen; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.getBody().setContent(temp); |
| | | |
| | | // crc16éªè¯ |
| | | start = 20 + bodyLen; |
| | | len = 2; |
| | | temp = strMsg.substring(start * 2, start * 2 + len * 2); |
| | | message.setHexCrc16(temp); |
| | | |
| | | message.setReceiveDate(new Date()); |
| | | message.setBatchId(ContextUtil.getDefaultBatchId()); |
| | | return message; |
| | | } |
| | | |
| | | /** |
| | | * å建BODY对象 |
| | | * |
| | | * @param |
| | | * @return |
| | | */ |
| | | public ReMessageBody buildBody() { |
| | | ReMessageBody body = new ReMessageBody(); |
| | | body.setLength(0); |
| | | body.setContent(""); |
| | | return body; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis.message; |
| | | |
| | | import java.lang.annotation.Retention; |
| | | import java.lang.annotation.RetentionPolicy; |
| | | import java.lang.annotation.Target; |
| | | |
| | | import static java.lang.annotation.ElementType.FIELD; |
| | | |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Target(FIELD) |
| | | public @interface Metadata { |
| | | |
| | | String label() default ""; |
| | | |
| | | int bytes() default 0; |
| | | |
| | | int startIndex() default 0; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis.message; |
| | | |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * æ¶æ¯å¤´å¯¹è±¡ |
| | | * |
| | | * @author Andy |
| | | * |
| | | */ |
| | | @Data |
| | | public class ReMessage { |
| | | |
| | | private String ip; |
| | | |
| | | private int port; |
| | | |
| | | private String begin; |
| | | |
| | | private String sourceId;// æº ID |
| | | |
| | | private String targetId;// ç®æ ID |
| | | |
| | | private String sendId;//åéè
ID |
| | | |
| | | private String gateway1;//è·¯ç±1 |
| | | |
| | | private String gateway2;//è·¯ç±2 |
| | | |
| | | private String messageType;// æ¶æ¯ç±»å |
| | | |
| | | private int result;// å¤çç»æ |
| | | |
| | | private String companyId;// ç»ç»ç¼ç |
| | | |
| | | private String hexCrc8;//crc8å
å¤´æ ¡éª |
| | | |
| | | private ReMessageBody body; |
| | | |
| | | private String hexCrc16;//crc16æ ¡éª |
| | | |
| | | private String end; |
| | | |
| | | private byte[] byteMsg;// å½åå½ä»¤çåèä¿¡æ¯ |
| | | |
| | | private String strMsg;// å½åå½ä»¤è½¬æ¢ä¸ºå符串çä¿¡æ¯ |
| | | |
| | | private String batchId; |
| | | |
| | | private Date receiveDate; |
| | | |
| | | // å¼å¸¸ä¿¡æ¯ |
| | | private String error; |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "ReMessage{" + |
| | | "ip='" + ip + '\'' + |
| | | ", port=" + port + |
| | | ", sourceId='" + sourceId + '\'' + |
| | | ", targetId='" + targetId + '\'' + |
| | | ", sendId='" + sendId + '\'' + |
| | | ", messageType='" + messageType + '\'' + |
| | | ", result=" + result + |
| | | ", companyId='" + companyId + '\'' + |
| | | ", hexCrc8='" + hexCrc8 + '\'' + |
| | | ", hexCrc16='" + hexCrc16 + '\'' + |
| | | ", strMsg='" + strMsg + '\'' + |
| | | '}'; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.analysis.message; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * æ¶æ¯-æ¶æ¯ä½ |
| | | * |
| | | * @author Andy |
| | | * |
| | | */ |
| | | @Data |
| | | public class ReMessageBody { |
| | | |
| | | private int length; |
| | | |
| | | private String content; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command; |
| | | |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import com.ld.igds.protocol.zldz.server.ZldzServerEngine; |
| | | import com.ld.io.api.InvokeResult; |
| | | import com.ld.io.api.IoSession; |
| | | |
| | | public class BaseRemoteImpl { |
| | | |
| | | public String getProtocol() { |
| | | return ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode(); |
| | | } |
| | | |
| | | /** |
| | | * åéå½ä»¤ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public InvokeResult send(String ip, int port, byte[] msg) { |
| | | IoSession session = ZldzServerEngine.getSession(ip,port); |
| | | if (null == session) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | return session.invoke(msg); |
| | | } |
| | | |
| | | public static void updateSession(String ip, int port, String companyId) { |
| | | IoSession ioSession = ZldzServerEngine.getSession(ip,port); |
| | | if(null != ioSession){ |
| | | ioSession.setCompanyId(companyId); |
| | | } |
| | | } |
| | | |
| | | public static InvokeResult destory(String ip, int port) { |
| | | IoSession session = ZldzServerEngine.getSession(ip,port); |
| | | if (null == session) { |
| | | return InvokeResult.SUCCESS; |
| | | } |
| | | // æ§è¡è¿æ¥éæ¯ |
| | | session.destroy(); |
| | | return InvokeResult.SUCCESS; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command; |
| | | |
| | | import com.ld.igds.io.RemoteCommonService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.*; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import com.ld.igds.protocol.zldz.command.builder.*; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.task.CommandReSendService; |
| | | import com.ld.igds.protocol.zldz.task.CommandTask; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å½ååè®®å®ç°ï¼ç²®æ
模åå½ä»¤æ¥å£ |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteCommonImpl.BEAN_ID) |
| | | public class RemoteCommonImpl extends BaseRemoteImpl implements RemoteCommonService { |
| | | |
| | | public static final String BEAN_ID = "zldz.remoteCommonService"; |
| | | |
| | | @Autowired |
| | | private CommandReSendService commandReSendService; |
| | | |
| | | @Override |
| | | public BaseResponse heartBeat(BaseRequest request) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullDevice(BaseRequest request) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullDepot(BaseRequest request) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullAccess(AccessRequest request) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse pullDepotStatus(DepotStatusRequest request) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åè®®ä¸æ¯æ"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BaseResponse checkTh(CheckThRequest request) { |
| | | try { |
| | | Message message = CommandBuilder1128.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "-温湿度å½ä»¤ä¿¡æ¯=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "å鿏©æ¹¿åº¦å½ä»¤æå"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "å鿏©æ¹¿åº¦å½ä»¤å¤±è´¥ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åæº=" + request.getSerName() + "温湿度å½ä»¤å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse writeConf(GrainSerConfRequest request) { |
| | | try { |
| | | // Step1 çæå½ä»¤ |
| | | Message message = CommandBuilder1116_1.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "-åå
¥é
ç½®å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | |
| | | CommandTask commandData = new CommandTask(); |
| | | commandData.setCompanyId(request.getCompanyId()); |
| | | commandData.setIp(request.getIp()); |
| | | commandData.setPort(request.getPort()); |
| | | commandData.setByteCommand(message.getByteMsg()); |
| | | commandData.setCommand(message.getStrMsg()); |
| | | commandData.setResultType(ServerUtils.MSG_TYPE_8816); |
| | | commandReSendService.reSendTask(commandData); |
| | | |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "åå
¥é
ç½®å½ä»¤åéæå"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "åå
¥é
ç½®å½ä»¤åéå¼å¸¸ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åæº=" + request.getSerName() + "åå
¥é
ç½®å½ä»¤åéå¼å¸¸ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse readConf(GrainSerConfRequest request) { |
| | | try { |
| | | // Step1 çæå½ä»¤ |
| | | Message message = CommandBuilder1116_0.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "-读åé
ç½®å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | CommandTask commandData = new CommandTask(); |
| | | commandData.setCompanyId(request.getCompanyId()); |
| | | commandData.setIp(request.getIp()); |
| | | commandData.setPort(request.getPort()); |
| | | commandData.setByteCommand(message.getByteMsg()); |
| | | commandData.setCommand(message.getStrMsg()); |
| | | commandData.setResultType(ServerUtils.MSG_TYPE_8816); |
| | | commandReSendService.reSendTask(commandData); |
| | | |
| | | return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "读åé
ç½®å½ä»¤åéæå"); |
| | | } else { |
| | | |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "读åé
ç½®å½ä»¤åéå¼å¸¸ï¼" + result.getMessage()); |
| | | } |
| | | } catch (Exception e) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åæº=" + request.getSerName() + "读åé
ç½®å½ä»¤åéå¼å¸¸ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse initCable(BaseRequest request) { |
| | | try { |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder1122.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "-åå§åçµç¼å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | CommandTask commandData = new CommandTask(); |
| | | commandData.setCompanyId(request.getCompanyId()); |
| | | commandData.setIp(request.getIp()); |
| | | commandData.setPort(request.getPort()); |
| | | commandData.setByteCommand(message.getByteMsg()); |
| | | commandData.setCommand(message.getStrMsg()); |
| | | commandData.setResultType(ServerUtils.MSG_TYPE_8822); |
| | | commandReSendService.reSendTask(commandData); |
| | | |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "åå§åçµç¼åéæå"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "åå§åçµç¼å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } catch (Exception e) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åæº=" + request.getSerName() + "åå§åçµç¼å½ä»¤æ§è¡å¤±è´¥ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse updateGrainSerCable(GrainSerConfRequest request) { |
| | | if (null == request.getEditTag()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "å½åæä½æ²¡æå¶å®ä¿®æ¹æ è¯ï¼æ æ³æ§è¡ï¼"); |
| | | } |
| | | |
| | | //æ ¹æ®ä¿®æ¹æ è¯å¤çä¸åçé»è¾ -- 2ç¹å·ä¿®æ¹ 3åå·ä¿®æ¹ï¼4æ ¹å·ä¿®æ¹ï¼5忥çµç¼ï¼6æ ¹å·æ¿æ¢ |
| | | if (2 == request.getEditTag()) { |
| | | return updateGrainSerCable2(request); |
| | | } |
| | | if (3 == request.getEditTag()) { |
| | | return updateGrainSerCable3(request); |
| | | } |
| | | if (4 == request.getEditTag()) { |
| | | return updateGrainSerCable4(request); |
| | | } |
| | | if (5 == request.getEditTag()) { |
| | | return updateGrainSerCable5(request); |
| | | } |
| | | if (6 == request.getEditTag()) { |
| | | return updateGrainSerCable6(request); |
| | | } |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "没æå¹é
å°å½åéè¦æä½çæ è¯ï¼æ è¯=" + request.getEditTag()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹å·æ¿æ¢ |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | private BaseResponse updateGrainSerCable6(GrainSerConfRequest request) { |
| | | if (null == request.getValue1() || null == request.getValue2()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "æ¿æ¢æä½ä¸ï¼æ²¡æè·åå°æ°æ§åæ°é
ç½®ï¼"); |
| | | } |
| | | |
| | | // Step1 |
| | | Message message = CommandBuilder1126.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "çµç¼-æ ¹å·æ¿æ¢å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·æ¿æ¢åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·æ¿æ¢åé失败ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @param request |
| | | * @return |
| | | */ |
| | | private BaseResponse updateGrainSerCable5(GrainSerConfRequest request) { |
| | | if (null == request.getValue1() || null == request.getValue2()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "忥çµç¼å¤±è´¥ï¼åæ¥çµç¼åæ°ä¸å®æ´"); |
| | | } |
| | | |
| | | |
| | | // Step1 |
| | | Message message = CommandBuilder1126.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "忥çµç¼-å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·æ¿æ¢åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·æ¿æ¢åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private BaseResponse updateGrainSerCable4(GrainSerConfRequest request) { |
| | | if (null == request.getValue1() || null == request.getValue2()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "æ¿æ¢æä½ä¸ï¼æ²¡æè·åå°æ°æ§åæ°é
ç½®ï¼"); |
| | | } |
| | | |
| | | //è¾å
¥å¼éè¦-1 |
| | | request.setValue1(request.getValue1() - 1); |
| | | request.setValue2(request.getValue2() - 1); |
| | | |
| | | // Step1 |
| | | Message message = CommandBuilder1126.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "-çµç¼-æ ¹å·ä¿®æ¹å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·ä¿®æ¹å½ä»¤åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-æ ¹å·ä¿®æ¹å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private BaseResponse updateGrainSerCable3(GrainSerConfRequest request) { |
| | | |
| | | if (null == request.getEditCol()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "æ¿æ¢æä½ä¸ï¼æ²¡æè·åååæ°ï¼"); |
| | | } |
| | | |
| | | // Step1 |
| | | Message message = CommandBuilder1126.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "çµç¼-åå·ä¿®æ¹å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-åå·ä¿®æ¹å½ä»¤åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-åå·ä¿®æ¹å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private BaseResponse updateGrainSerCable2(GrainSerConfRequest request) { |
| | | |
| | | if (null == request.getValue1() || null == request.getValue2()) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "æ¿æ¢æä½ä¸ï¼æ²¡æè·åå°æ°æ§åæ°é
ç½®ï¼"); |
| | | } |
| | | |
| | | //è¾å
¥å¼éè¦-1 |
| | | request.setValue1(request.getValue1() - 1); |
| | | request.setValue2(request.getValue2() == null ? 0 : request.getValue2()); |
| | | |
| | | // Step1 çæå½ä»¤ |
| | | Message message = CommandBuilder1126.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "çµç¼-ç¹å·ä¿®æ¹å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-ç¹å·ä¿®æ¹å½ä»¤åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼-ç¹å·ä¿®æ¹å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * è·åééçµç¼ |
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BaseResponse checkGrainSerCable(GrainSerConfRequest request) { |
| | | |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder1125.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "è·åééçµç¼å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "è·åééçµç¼å½ä»¤åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "è·åééçµç¼å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BaseResponse destroyCon(BaseRequest request) { |
| | | InvokeResult result = destory(request.getIp(), request.getPort()); |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "æå¼è¿æ¥æ§è¡æå"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "åæº=" + request.getSerName() + "æå¼è¿æ¥å¤±è´¥ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse updateSysDepotConf(BaseRequest request) { |
| | | return new BaseResponse(OrderRespEnum.NO_FUNCTION); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse sumGrainSerCable(GrainSerConfRequest request) { |
| | | // Step1 |
| | | Message message = CommandBuilder1123.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" + request.getSerName() + "çµç¼æ±æ»å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼æ±æ»å½ä»¤åéæåï¼"); |
| | | } else { |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº=" + request.getSerName() + "çµç¼æ±æ»å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command; |
| | | |
| | | import com.ld.igds.io.RemoteGrainService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.io.request.CheckGrainRequest; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import com.ld.igds.protocol.zldz.command.builder.CommandBuilder1115; |
| | | import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8815; |
| | | import com.ld.igds.protocol.zldz.command.builder.CommandBuilder8817; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.task.CommandReSendService; |
| | | import com.ld.igds.protocol.zldz.task.CommandTask; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * ç²®æ
åè®®ï¼ç´æ¥è·åç²®æ
ï¼æ¸©æ¹¿åº¦ä¿¡æ¯éè¿å¿è·³å®æ¶è·åã |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteGrainServiceImpl.BEAN_ID) |
| | | public class RemoteGrainServiceImpl extends BaseRemoteImpl implements |
| | | RemoteGrainService { |
| | | |
| | | public static final String BEAN_ID = "zldz.remoteGrainService"; |
| | | |
| | | @Autowired |
| | | private CommandReSendService commandReSendService; |
| | | |
| | | /** |
| | | * ç²®æ
æ£æµï¼é¦å
éè¦æ§è¡æ¸©æ¹¿åº¦æ£æµï¼æ¸©æ¹¿åº¦æ£æµå®æåï¼åè¿ç²®æ
æ£æµã |
| | | * 温湿度çä¿¡æ¯æ ¹æ®åæºå温湿度å°ååå¨ç¼å30åéï¼30åéå
ä¸éå¤ééï¼ç³»ç»å¤æä¸å½åæ¶é´å·®è·ç¦»å½åæ¶é´æ¯å¦è¶
è¿25åé |
| | | * ï¼è¶
è¿éæ°è·åï¼æ²¡æè¶
è¿ç´æ¥ééç²®æ
|
| | | * |
| | | * @param request |
| | | * @return |
| | | */ |
| | | @Override |
| | | public GrainResponse checkGrain(CheckGrainRequest request) { |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder1115.getInstance().buildMessage(request); |
| | | |
| | | log.info("å¹³å°------>>>åæºï¼" +request.getSerName() + "-ç²®æ
ééå½ä»¤=" + message.toString()); |
| | | |
| | | InvokeResult result = send(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | CommandTask commandData = new CommandTask(); |
| | | commandData.setCompanyId(request.getCompanyId()); |
| | | commandData.setIp(request.getIp()); |
| | | commandData.setPort(request.getPort()); |
| | | commandData.setByteCommand(message.getByteMsg()); |
| | | commandData.setCommand(message.getStrMsg()); |
| | | commandData.setResultType(ServerUtils.MSG_TYPE_8817); |
| | | commandData.setCableRule(request.getCableRule()); |
| | | commandData.setSerName(request.getSerName()); |
| | | commandData.setDepotId(request.getDepotId()); |
| | | commandReSendService.reSendGrainTask(commandData); |
| | | return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "ç²®æ
ééå½ä»¤åéæå"); |
| | | } else { |
| | | log.info("åæº" + request.getSerName() + "ç²®æ
ééå½ä»¤åé失败ï¼" + result.getMessage()); |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æå¡å¨åå¤ç»ç«¯çæ¶å°è¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public BaseResponse reply8815(BaseRequest request) { |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder8815.getInstance().buildMessage( |
| | | request); |
| | | |
| | | log.debug("å¹³å°------>>>åæºï¼" +request.getSerName() + "-ç²®æ
æå¡ç«¯åå¤å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯åå¤å½ä»¤åéæå"); |
| | | } else { |
| | | log.error("åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯åå¤å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯åå¤å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åå¤å½ä»¤ |
| | | * |
| | | * @param request |
| | | * @param hexCurPacket å½åå
çhex |
| | | */ |
| | | public BaseResponse reply8817(BaseRequest request, String hexCurPacket) { |
| | | // Step1 çæç²®æ
ä¿¡æ¯ï¼æä¿¡æ¯æ¾å¨request |
| | | request.setBizType(hexCurPacket); |
| | | |
| | | Message message = CommandBuilder8817.getInstance().buildMessage(request); |
| | | |
| | | log.debug("å¹³å°------>>>åæºï¼" +request.getSerName() + "-ç²®æ
æå¡ç«¯å夿¶å°ç²®æ
å
å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = send(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new BaseResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯å夿¶å°ç²®æ
å
å½ä»¤åéæå"); |
| | | } else { |
| | | log.info("åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯å夿¶å°ç²®æ
å
å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "åæº" + request.getSerName() + "ç²®æ
æå¡ç«¯å夿¶å°ç²®æ
å
å½ä»¤åé失败ï¼" + result.getMessage()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.CRC8; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * å½ä»¤çæå¨ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public abstract class CommandBuilder { |
| | | |
| | | /* |
| | | * å½ä»¤å建 |
| | | * |
| | | * @param order |
| | | */ |
| | | public Message buildMessage(BaseRequest request) { |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | |
| | | public void buildHeader(Message message, BaseRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setSourceId(BytesUtil.getTargetId(request.getSerId(), true)); |
| | | |
| | | message.setMessageType(ServerUtils.MSG_TYPE_1116); |
| | | } |
| | | |
| | | public void buildBody(Message message, BaseRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setContent(""); |
| | | body.setLength(0); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | public void buildCrc8(Message message) { |
| | | StringBuffer hexSbCrc8 = new StringBuffer(); |
| | | hexSbCrc8.append(message.getSourceId()); |
| | | hexSbCrc8.append(message.getTargetId()); |
| | | hexSbCrc8.append(message.getSendId()); |
| | | hexSbCrc8.append(message.getGateway1()); |
| | | hexSbCrc8.append(message.getGateway2()); |
| | | hexSbCrc8.append(message.getMessageType()); |
| | | hexSbCrc8.append(message.getResult()); |
| | | hexSbCrc8.append(message.getCompanyId()); |
| | | |
| | | byte[] bytes = BytesUtil.hexStrToBytes(hexSbCrc8.toString()); |
| | | byte crc8 = CRC8.calcCrc8(bytes, (short) 0, (short) (bytes.length), |
| | | (byte) 0); |
| | | |
| | | message.setHexCrc8(BytesUtil.byteToHex(crc8)); |
| | | } |
| | | |
| | | |
| | | public void buildCrc16(Message message) { |
| | | StringBuffer hexSbCrc16 = new StringBuffer(); |
| | | hexSbCrc16.append(message.getSourceId()); |
| | | hexSbCrc16.append(message.getTargetId()); |
| | | hexSbCrc16.append(message.getSendId()); |
| | | hexSbCrc16.append(message.getGateway1()); |
| | | hexSbCrc16.append(message.getGateway2()); |
| | | hexSbCrc16.append(message.getMessageType()); |
| | | hexSbCrc16.append(message.getResult()); |
| | | hexSbCrc16.append(message.getCompanyId()); |
| | | |
| | | hexSbCrc16.append(message.getHexCrc8()); |
| | | |
| | | hexSbCrc16.append(BytesUtil.tran_LH(BytesUtil |
| | | .getHex2LenStr(message.getBody().getLength()))); |
| | | |
| | | hexSbCrc16.append(message.getBody().getContent()); |
| | | |
| | | byte[] byteCrc16 = BytesUtil.hexStrToBytes(hexSbCrc16.toString()); |
| | | short crc16Hex2 = CRC8.calculateCrc16(byteCrc16, (short) 0, (short) (byteCrc16.length)); |
| | | byte[] crc16Hex2Bytes = BytesUtil.shortToByte(crc16Hex2); |
| | | int crc16 = BytesUtil.bytesToInt(crc16Hex2Bytes); |
| | | |
| | | |
| | | message.setHexCrc16(BytesUtil.intToHexStr(crc16)); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®çæçå½ä»¤ï¼è¿è¡è°æ´ |
| | | * |
| | | * @param message |
| | | */ |
| | | public void build(Message message) { |
| | | StringBuffer hexSb = new StringBuffer(); |
| | | |
| | | hexSb.append(message.getBegin()); |
| | | hexSb.append(message.getSourceId()); |
| | | hexSb.append(message.getTargetId()); |
| | | hexSb.append(message.getSendId()); |
| | | hexSb.append(message.getGateway1()); |
| | | hexSb.append(message.getGateway2()); |
| | | hexSb.append(message.getMessageType()); |
| | | hexSb.append(message.getResult()); |
| | | hexSb.append(message.getCompanyId()); |
| | | hexSb.append(message.getHexCrc8()); |
| | | |
| | | hexSb.append(BytesUtil.tran_LH(BytesUtil |
| | | .getHex2LenStr(message.getBody().getLength()))); |
| | | |
| | | hexSb.append(message.getBody().getContent()); |
| | | hexSb.append(message.getHexCrc16()); |
| | | hexSb.append(message.getEnd()); |
| | | |
| | | message.setStrMsg(hexSb.toString()); |
| | | message.setByteMsg(BytesUtil.hexStrToBytes(message.getStrMsg())); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.io.request.CheckGrainRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1115 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder1115 instance = new CommandBuilder1115(); |
| | | |
| | | private CommandBuilder1115() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1115 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(CheckGrainRequest request) { |
| | | |
| | | //request.setCompanyId("1"); |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, BaseRequest order) { |
| | | String hexCompanyId = BytesUtil.getTargetId(order.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(order.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1115)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, CheckGrainRequest order) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(2); |
| | | int start = order.getCableStart(); |
| | | int end = order.getCableEnd(); |
| | | body.setContent(BytesUtil.toHexString(start) + BytesUtil.toHexString(end)); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1116_0 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder1116_0 instance = new CommandBuilder1116_0(); |
| | | |
| | | private CommandBuilder1116_0() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1116_0 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | |
| | | // String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | // |
| | | // hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | // message.setSourceId(hexCompanyId); |
| | | // message.setSendId(hexCompanyId); |
| | | // |
| | | // //åéçå¿
é¡»æ¯åæ¥çç»ç»ç¼ç |
| | | // String orgId = BytesUtil.tran_LH(BytesUtil.getTargetId(request.getOrgId(),true)); |
| | | // message.setCompanyId(orgId); |
| | | // |
| | | // message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | |
| | | message.setSourceId("0000"); |
| | | message.setSendId("0000"); |
| | | message.setCompanyId("0000"); |
| | | message.setTargetId("FFFF"); |
| | | |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, GrainSerConfRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setContent("0000000000000000000000000000"); |
| | | body.setLength(14); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1116_1 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder1116_1 instance = new CommandBuilder1116_1(); |
| | | |
| | | private CommandBuilder1116_1() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1116_1 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | |
| | | //åéçå¿
é¡»æ¯åæ¥çç»ç»ç¼ç |
| | | String orgId = BytesUtil.tran_LH(BytesUtil.getTargetId(request.getOrgId(),true)); |
| | | message.setCompanyId(orgId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, GrainSerConfRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | StringBuffer content = new StringBuffer(); |
| | | content.append("01");//åæ è®° |
| | | content.append(message.getTargetId()); |
| | | content.append(BytesUtil.getTargetId("01",false));//ç½ç»ID |
| | | content.append("0A");//é»è®¤10 ä¿¡é |
| | | content.append(BytesUtil.getTargetId("03",false));//éç |
| | | content.append(BytesUtil.toHexString(request.getCableZ())); |
| | | content.append(BytesUtil.toHexString(request.getCableY())); |
| | | content.append(BytesUtil.toHexString(request.getCableX())); |
| | | content.append(BytesUtil.getTargetId(request.getCableFormat(),false)); |
| | | content.append(BytesUtil.getTargetId(request.getCableType(),false)); |
| | | |
| | | if(StringUtils.isEmpty(request.getPowerModel())){ |
| | | request.setPowerModel("02"); |
| | | } |
| | | content.append(BytesUtil.getTargetId(request.getPowerModel(),false)); |
| | | |
| | | content.append(message.getSourceId()); |
| | | |
| | | body.setContent(content.toString()); |
| | | body.setLength(14); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * åå§åçµç¼çµç¼ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1122 extends CommandBuilder { |
| | | |
| | | private final static CommandBuilder1122 instance = new CommandBuilder1122(); |
| | | |
| | | private CommandBuilder1122() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1122 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public void buildHeader(Message message, BaseRequest request) { |
| | | |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1122)); |
| | | } |
| | | |
| | | public void buildBody(Message message, BaseRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setContent("01"); |
| | | body.setLength(1); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * ç²®æ
åæº-çµç¼æ±æ» |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1123 extends CommandBuilder { |
| | | |
| | | private final static CommandBuilder1123 instance = new CommandBuilder1123(); |
| | | |
| | | private CommandBuilder1123() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1123 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | // å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), |
| | | true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId( |
| | | request.getSerId(), true))); |
| | | |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1123)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * ç²®æ
åæº-çµç¼æ£æµ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1125 extends CommandBuilder { |
| | | |
| | | private final static CommandBuilder1125 instance = new CommandBuilder1125(); |
| | | |
| | | private CommandBuilder1125() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1125 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | // å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), |
| | | true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId( |
| | | request.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1125)); |
| | | } |
| | | |
| | | public void buildBody(Message message, GrainSerConfRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(1); |
| | | body.setContent(BytesUtil.toHexString(request.getPassCode())); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * ç²®æ
åæº-ä¿®æ¹ééçµç¼ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1126 extends CommandBuilder { |
| | | |
| | | private final static CommandBuilder1126 instance = new CommandBuilder1126(); |
| | | |
| | | private CommandBuilder1126() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1126 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | // å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), |
| | | true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId( |
| | | request.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1126)); |
| | | } |
| | | |
| | | public void buildBody(Message message, GrainSerConfRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(5); |
| | | StringBuilder bodyStr = new StringBuilder(); |
| | | // ä¿®æ¹æ è¯ |
| | | bodyStr.append(BytesUtil.toHexString(request.getEditTag())); |
| | | // ééå· |
| | | bodyStr.append(BytesUtil.toHexString(request.getPassCode())); |
| | | // åå· |
| | | bodyStr.append(BytesUtil.toHexString(request.getEditCol())); |
| | | |
| | | // ç¹åºå·/åæ ¹å·/èµ·å§æ ¹å·/æ ¹åºå· |
| | | // æ°ç¹å·/æ°æ ¹å·/çµç¼å±æ°/æ°æ ¹å· |
| | | if (6 == request.getEditTag()) { |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue1())); |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue2())); |
| | | } else if (5 == request.getEditTag()) { |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue1())); |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue2())); |
| | | } else if (4 == request.getEditTag()) { |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue1())); |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue2())); |
| | | } else if (2 == request.getEditTag()) { |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue1())); |
| | | bodyStr.append(BytesUtil.toHexString(request.getValue2())); |
| | | } else { |
| | | bodyStr.append("00"); |
| | | bodyStr.append("00"); |
| | | } |
| | | |
| | | body.setContent(bodyStr.toString()); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.CheckThRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * 仿¸©ä»æ¹¿å½ä»¤ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder1128 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder1128 instance = new CommandBuilder1128(); |
| | | |
| | | private CommandBuilder1128() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder1128 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(CheckThRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, CheckThRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1128)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, CheckThRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(2); |
| | | body.setContent(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getThConf(), true))); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder8815 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder8815 instance = new CommandBuilder8815(); |
| | | |
| | | private CommandBuilder8815() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder8815 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | |
| | | public void buildHeader(Message message, BaseRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8815)); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder8817 extends CommandBuilder { |
| | | |
| | | |
| | | private final static CommandBuilder8817 instance = new CommandBuilder8817(); |
| | | |
| | | private CommandBuilder8817() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder8817 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | |
| | | public void buildHeader(Message message, BaseRequest request) { |
| | | |
| | | //request.setCompanyId("1"); |
| | | |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(),true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(request.getSerId(), true))); |
| | | |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8817)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, BaseRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setContent(request.getBizType()); |
| | | body.setLength(1); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.GrainSerConfRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * ç²®æ
åæº-çµç¼æ±æ» |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class CommandBuilder8829 extends CommandBuilder { |
| | | |
| | | private final static CommandBuilder8829 instance = new CommandBuilder8829(); |
| | | |
| | | private CommandBuilder8829() { |
| | | |
| | | } |
| | | |
| | | public static CommandBuilder8829 getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public Message buildMessage(GrainSerConfRequest request) { |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ServerUtils.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | // å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ServerUtils.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, GrainSerConfRequest request) { |
| | | String hexCompanyId = BytesUtil.getTargetId(request.getCompanyId(), |
| | | true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId( |
| | | request.getSerId(), true))); |
| | | |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_8829)); |
| | | } |
| | | |
| | | public void buildBody(Message message, GrainSerConfRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(1); |
| | | body.setContent(BytesUtil.toHexString(request.getValue1())); |
| | | message.setBody(body); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.builder; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.command.message.MessageBody; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | |
| | | /** |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class OnLineCommandBuilder extends CommandBuilder { |
| | | |
| | | private final static OnLineCommandBuilder instance = new OnLineCommandBuilder(); |
| | | |
| | | private OnLineCommandBuilder() { |
| | | |
| | | } |
| | | |
| | | public static OnLineCommandBuilder getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | public void buildHeader(Message message, BaseRequest request) { |
| | | message.setSourceId("0000"); |
| | | message.setSendId("0000"); |
| | | message.setCompanyId("0000"); |
| | | message.setTargetId("FFFF"); |
| | | message.setMessageType(BytesUtil.tran_LH(ServerUtils.MSG_TYPE_1116)); |
| | | } |
| | | |
| | | public void buildBody(Message message, BaseRequest request) { |
| | | MessageBody body = new MessageBody(); |
| | | body.setContent("0000000000000000000000000000"); |
| | | body.setLength(14); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.message; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * å符串å¼åéç¨åå
è¿å¶ï¼æ¹ä¾¿æ ¡éªåå¼å |
| | | */ |
| | | @Data |
| | | public class Message { |
| | | |
| | | private String begin; |
| | | |
| | | private String sourceId;// æº ID |
| | | |
| | | private String targetId="FFFF";// ç®æ ID |
| | | |
| | | private String sendId;//åéè
ID |
| | | |
| | | private String gateway1 = "0100";//è·¯ç±1 |
| | | |
| | | private String gateway2 = "0000";//è·¯ç±2 |
| | | |
| | | private String messageType;// æ¶æ¯ç±»å |
| | | |
| | | private String result ="00";// å¤çç»æ |
| | | |
| | | private String companyId;// ç»ç»ç¼ç |
| | | |
| | | private String hexCrc8;//crc8å
å¤´æ ¡éª |
| | | |
| | | private MessageBody body; |
| | | |
| | | private String hexCrc16;//crc16æ ¡éª |
| | | |
| | | private String end; |
| | | |
| | | private byte[] byteMsg;// å½åå½ä»¤çåèä¿¡æ¯ |
| | | |
| | | private String strMsg;// å½åå½ä»¤è½¬æ¢ä¸ºå符串çä¿¡æ¯ |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "Message [sourceId=" + sourceId |
| | | + ", targetId=" + targetId |
| | | + ", messageType=" + messageType |
| | | + ", result=" + result + ", companyId=" + companyId |
| | | + ", hexCrc8=" + hexCrc8 + ", body=" + body + ", hexCrc16=" |
| | | + hexCrc16 + ", strMsg=" + strMsg + "]"; |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.command.message; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MessageBody { |
| | | |
| | | //é»è®¤10è¿å¶é¿åº¦ |
| | | private int length = 0; |
| | | |
| | | //æ¶æ¯ä½å
容 |
| | | private String content = ""; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.mq; |
| | | |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æ§å¶ç»ç«¯ä½ä¸ºåå¸è
åå¸ä¿¡æ¯ï¼æå¡ç«¯ä½ä¸ºè®¢é
è
订é
ï¼ééå®ä¹ä¸ºå½ååè®®ç¼ç |
| | | */ |
| | | @Slf4j |
| | | @Component(PublisherControl.BEAN_ID) |
| | | public class PublisherControl { |
| | | |
| | | public static final String BEAN_ID = "zldz.redisPublisher"; |
| | | |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | |
| | | /** |
| | | * æ£å¸¸è¿åä¿¡æ¯è·å |
| | | * |
| | | * @param reMessage |
| | | */ |
| | | public void publishMessage(String reMessage) { |
| | | redisTemplate.convertAndSend(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode(), reMessage); |
| | | log.debug("-----------æ¥æä¿¡æ¯åå
¥éå------{}", reMessage); |
| | | } |
| | | |
| | | /** |
| | | * ç»å½ä¿¡æ¯è·å |
| | | * |
| | | * @param sessionKey |
| | | */ |
| | | public void publishLoginMessage(String sessionKey) { |
| | | redisTemplate.convertAndSend(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode() + "_LOGIN", sessionKey); |
| | | log.debug("-----------ç»å½ä¿¡æ¯åå
¥éå------{}", sessionKey); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.mq; |
| | | |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.protocol.zldz.analysis.AnalysisService; |
| | | import com.ld.igds.protocol.zldz.command.builder.OnLineCommandBuilder; |
| | | import com.ld.igds.protocol.zldz.command.message.Message; |
| | | import com.ld.igds.protocol.zldz.server.ZldzServerEngine; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.io.api.InvokeResult; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.RandomUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.util.concurrent.CountDownLatch; |
| | | |
| | | /** |
| | | * æ¥ææ¥åå°åå¤ç |
| | | */ |
| | | @Slf4j |
| | | public class ReceiverServer { |
| | | |
| | | private CountDownLatch latch; |
| | | |
| | | @Autowired |
| | | public ReceiverServer(CountDownLatch latch) { |
| | | this.latch = latch; |
| | | } |
| | | |
| | | @Autowired |
| | | private AnalysisService analysisService; |
| | | |
| | | |
| | | |
| | | |
| | | public void onMessage(String message) { |
| | | message = message.replaceAll("\"", ""); |
| | | log.info("-------è·åéåä¿¡æ¯---" + message); |
| | | try { |
| | | String[] attr = message.split("_"); |
| | | String sessionKey = attr[0]; |
| | | String msg = attr[1]; |
| | | analysisService.analysis2(sessionKey, msg); |
| | | } catch (Exception e) { |
| | | latch.countDown(); |
| | | log.error("[æ£æ¥çµå--æ¶æ¯éåæ°æ®å¤±è´¥ï¼å¤±è´¥ä¿¡æ¯:{}]", e.getMessage(),e); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | | |
| | | |
| | | public void onLoginMessage(String sessionKey) { |
| | | log.info("-------è·åç»å½éåä¿¡æ¯---{}", sessionKey); |
| | | try { |
| | | sessionKey = sessionKey.replaceAll("\"", ""); |
| | | String[] attr = sessionKey.split(":"); |
| | | IoSession session = ZldzServerEngine.getSession(attr[0],Integer.valueOf(attr[1])); |
| | | |
| | | if (null == session) { |
| | | log.warn("---------------没æè·åå°ä¼è¯ä¿¡æ¯-------------{}", sessionKey); |
| | | latch.countDown(); |
| | | return; |
| | | } |
| | | |
| | | long l = RandomUtils.nextInt(1000, 9999); |
| | | Thread.sleep(l); |
| | | |
| | | BaseRequest request = new BaseRequest(); |
| | | request.setIp(session.getAddress()); |
| | | request.setPort(session.getPort()); |
| | | request.setCompanyId(ServerUtils.DEFAULT_COMPANY); |
| | | |
| | | // Step1 çæå¨çº¿æµè¯å½ä»¤ |
| | | Message message = OnLineCommandBuilder.getInstance().buildMessage(request); |
| | | // åéå½ä»¤ |
| | | InvokeResult result = session.invoke(message.getByteMsg()); |
| | | |
| | | //妿å½ä»¤åé失败ï¼ç´æ¥è¸¢æè¿æ¥ |
| | | if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { |
| | | session.destroy(); |
| | | } |
| | | } catch (Exception e) { |
| | | latch.countDown(); |
| | | log.error("[æ£æ¥çµå--ç»å½æ¶æ¯éåæ°æ®å¤±è´¥ï¼å¤±è´¥ä¿¡æ¯:{}]", e.getMessage()); |
| | | } |
| | | latch.countDown(); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.mq; |
| | | |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.listener.PatternTopic; |
| | | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| | | import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; |
| | | |
| | | import java.util.concurrent.CountDownLatch; |
| | | |
| | | /** |
| | | * æ¶æ¯è®¢é
é
ç½® |
| | | */ |
| | | @Configuration |
| | | public class RedisSubConfig { |
| | | |
| | | /** |
| | | * åå»ºè¿æ¥å·¥å |
| | | * |
| | | * @param connectionFactory |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, |
| | | MessageListenerAdapter adapter1, |
| | | MessageListenerAdapter adapter2) { |
| | | RedisMessageListenerContainer container = new RedisMessageListenerContainer(); |
| | | container.setConnectionFactory(connectionFactory); |
| | | |
| | | //çå¬å¯¹åºçchannel |
| | | container.addMessageListener(adapter1, new PatternTopic(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode())); |
| | | |
| | | //çå¬å¯¹åºçchannel |
| | | container.addMessageListener(adapter2, new PatternTopic(ProtocolEnum.TCP_ZLDZ_GRAIN_V1.getCode() + "_LOGIN")); |
| | | |
| | | return container; |
| | | } |
| | | |
| | | /** |
| | | * ç»å®æ¶æ¯çå¬è
忥æ¶çå¬çæ¹æ³ |
| | | * |
| | | * @param receiver |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public MessageListenerAdapter adapter1(ReceiverServer receiver) { |
| | | return new MessageListenerAdapter(receiver, "onMessage"); |
| | | } |
| | | |
| | | /** |
| | | * ç»å®æ¶æ¯çå¬è
忥æ¶çå¬çæ¹æ³ |
| | | * |
| | | * @param receiver |
| | | * @return |
| | | */ |
| | | @Bean |
| | | public MessageListenerAdapter adapter2(ReceiverServer receiver) { |
| | | return new MessageListenerAdapter(receiver, "onLoginMessage"); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | ReceiverServer receiver(CountDownLatch latch) { |
| | | return new ReceiverServer(latch); |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | public CountDownLatch latch() { |
| | | return new CountDownLatch(1);//æå®äºè®¡æ°çæ¬¡æ° 1 |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | /** |
| | | * æ£æ¥çµå-ç²®æ
åè®®V1 |
| | | * |
| | | */ |
| | | package com.ld.igds.protocol.zldz; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.server; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.util.SpringUtil; |
| | | import com.ld.io.api.HeartbeatProvider; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | |
| | | /** |
| | | * å¿è·³ç»´æï¼éªè¯å½åè¿æ¥ä¸çIP卿å¡å¨ä¸é
ç½®çææ²¡æï¼å¦ææå表示æ£å¸¸è¿æ¥ï¼å¦ææ²¡æå踢é¤è¿æ¥ã |
| | | * <p> |
| | | * å¦æææ£å¸¸å¿è·³ï¼åå鿣叏å¿è·³å½ä»¤ï¼å¦ææ²¡æååé设å¤ç¶ææ¥è¯¢ï¼ |
| | | */ |
| | | @Slf4j |
| | | public class HeartbeatProviderImpl implements HeartbeatProvider { |
| | | |
| | | private CoreSerService serService; |
| | | |
| | | @Override |
| | | public byte[] provide(IoSession session) { |
| | | |
| | | log.debug("========ç³»ç»å¼å§æ§è¡å¿è·³=========={}---{}", session.getCompanyId(), session.getBusinessKey()); |
| | | |
| | | if (null == serService) { |
| | | serService = SpringUtil.getBean(CoreSerService.class); |
| | | } |
| | | |
| | | DeviceSer ser = null; |
| | | String companyId = session.getCompanyId(); |
| | | if (StringUtils.isNotEmpty(companyId)) { |
| | | ser = serService.getCacheSerByIp(companyId, session.getAddress(), session.getPort()); |
| | | } |
| | | |
| | | if (null == ser) { |
| | | log.error("========å¿è·³æ§è¡æ²¡æè·åå°åæºä¿¡æ¯======IP={}-{}ï¼åæ¶è¸¢åºï¼åªåæ¥å¿æéã", session.getAddress(), session.getPort()); |
| | | session.destroy(); |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.server; |
| | | |
| | | import com.ld.igds.protocol.zldz.mq.PublisherControl; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.SpringUtil; |
| | | import com.ld.io.api.IoMsgConsumer; |
| | | import com.ld.io.api.IoSession; |
| | | |
| | | /** |
| | | * æ¥æ¶ç»ç«¯è¿å忥çä¿¡æ¯ã |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class MsgConsumer implements IoMsgConsumer { |
| | | |
| | | // private AnalysisService analysisService; |
| | | |
| | | private PublisherControl publisherControl; |
| | | |
| | | @Override |
| | | public void consume(IoSession session, byte[] bytes) { |
| | | |
| | | // è°ç¨è§£ææ¥å£å¼å§è§£æ |
| | | // if(null == analysisService){ |
| | | // analysisService = (AnalysisService) |
| | | // SpringUtil.getBean(AnalysisService.BEAN_ID); |
| | | // } |
| | | // analysisService.analysis(session.getAddress(),session.getPort(),bytes); |
| | | |
| | | // 2021å¹´6æ9æ¥ è°æ´ä¸ºæ¶æ¯éåå¤ç |
| | | if (null == publisherControl) { |
| | | publisherControl = SpringUtil.getBean(PublisherControl.class); |
| | | } |
| | | |
| | | String strMsg = BytesUtil.bytesToString(bytes) + ServerUtils.MSG_END; |
| | | |
| | | // äºæ¬¡è°æ´æ¥æ |
| | | if (!strMsg.startsWith(ServerUtils.MSG_START)) { |
| | | strMsg = strMsg.substring(strMsg.indexOf(ServerUtils.MSG_START)); |
| | | } |
| | | |
| | | publisherControl.publishMessage(session.getBusinessKey() + "_" + strMsg); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.server; |
| | | |
| | | import com.ld.igds.io.notify.ServerNotifyInvoker; |
| | | import com.ld.igds.protocol.zldz.command.BaseRemoteImpl; |
| | | import com.ld.igds.protocol.zldz.mq.PublisherControl; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.SpringUtil; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | |
| | | public class SessionListener extends BaseRemoteImpl implements IoSessionListener { |
| | | |
| | | public static final String BEAN_ID = "zldz.sessionListener"; |
| | | |
| | | private ServerNotifyInvoker serverNotifyInvoker; |
| | | |
| | | private PublisherControl publisherControl; |
| | | |
| | | @Override |
| | | public void onCreate(IoSession session) { |
| | | |
| | | // æ·»å èªå®ä¹ä¸å¡ID |
| | | session.setBusinessKey(ServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | //2021å¹´6æ9æ¥ è°æ´ä½¿ç¨ä¸ºéå |
| | | if (null == publisherControl) { |
| | | publisherControl = SpringUtil.getBean(PublisherControl.class); |
| | | } |
| | | publisherControl.publishLoginMessage(session.getBusinessKey()); |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy(IoSession session) { |
| | | if (null == serverNotifyInvoker) { |
| | | serverNotifyInvoker = SpringUtil.getBean(ServerNotifyInvoker.class); |
| | | } |
| | | serverNotifyInvoker.connectDestory(session.getBusinessKey(), |
| | | session.getAddress(), session.getPort()); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.server; |
| | | |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.io.api.*; |
| | | import com.ld.io.netty.NettyServer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * é
置主æå¡ä¿¡æ¯ |
| | | * |
| | | * @author Andy 2019å¹´10æ4æ¥ æ°å¢ |
| | | */ |
| | | @Slf4j |
| | | public class ZldzServerEngine { |
| | | |
| | | public static final int PORT = 8000; |
| | | |
| | | public static NettyServer ioServer = null; |
| | | // é
ç½®æ¶æ¯æ¥æ¶ç±» |
| | | private static MsgConsumer messageConsume = new MsgConsumer(); |
| | | // çå¬ä¼è¯çå建ä¸éæ¯ |
| | | private static SessionListener ioSessionListener = new SessionListener(); |
| | | |
| | | // å¿è·³æä¾ ï¼è¯¥æå¡ä¸éè¦å¿è·³ç»´æ |
| | | private static HeartbeatProvider heartbeatProvider = new HeartbeatProviderImpl(); |
| | | |
| | | |
| | | public static void start() { |
| | | start(PORT); |
| | | } |
| | | |
| | | public static void start(int port) { |
| | | // é
ç½®Serverçé
ç½® |
| | | IoServerOption ioServerOption = new IoServerOption(port); |
| | | |
| | | ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); |
| | | ioServerOption.setDelimiter(BytesUtil.hexStrToBytes(ServerUtils.MSG_END)); |
| | | |
| | | // é
ç½®å¿è·³æ§è¡æ¶é´ |
| | | ioServerOption.setReaderIdleTime(60 * 60); |
| | | |
| | | ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener, heartbeatProvider); |
| | | |
| | | ioServer.startup(); |
| | | |
| | | log.info("* ========================"); |
| | | log.info("* "); |
| | | log.info("* 纯粮æ
åè®®ï¼ç«¯å£å·={}", port); |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | |
| | | |
| | | System.out.println("* ========================"); |
| | | System.out.println("* "); |
| | | System.out.println("* 纯粮æ
åè®®ï¼ç«¯å£å·=" + port); |
| | | System.out.println("* "); |
| | | System.out.println("* ========================"); |
| | | } |
| | | |
| | | /** |
| | | * åéä¿¡æ¯ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public static InvokeResult push(String ip, int port, byte[] msg) { |
| | | IoSession session = getSession(ip, port); |
| | | if (null == session) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | return session.invoke(msg); |
| | | } |
| | | |
| | | /** |
| | | * 主å¨éæ¯å½åè¿æ¥ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @return |
| | | */ |
| | | public static InvokeResult destory(String ip, int port) { |
| | | IoSession session = getSession(ip, port); |
| | | |
| | | if (null == session) { |
| | | return InvokeResult.SUCCESS; |
| | | } |
| | | // æ§è¡è¿æ¥éæ¯ |
| | | session.destroy(); |
| | | return InvokeResult.SUCCESS; |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®SessionKeyè·åSessionä¿¡æ¯ |
| | | * |
| | | * @param ip |
| | | * @return |
| | | */ |
| | | public static IoSession getSession(String ip, int port) { |
| | | IoSessionQuery sessionFactory = ioServer.getSessionQuery(); |
| | | List<IoSession> sessions = sessionFactory.getAllSession(); |
| | | for (IoSession ioSession : sessions) { |
| | | if (ip.equals(ioSession.getAddress()) && port == ioSession.getPort()) { |
| | | return ioSession; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.task; |
| | | |
| | | import com.ld.igds.io.request.CheckGrainRequest; |
| | | import com.ld.igds.io.request.CheckThRequest; |
| | | import com.ld.igds.protocol.zldz.command.BaseRemoteImpl; |
| | | import com.ld.igds.protocol.zldz.util.ServerUtils; |
| | | import com.ld.igds.util.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutorService; |
| | | import java.util.concurrent.Executors; |
| | | import java.util.concurrent.FutureTask; |
| | | |
| | | /** |
| | | * å½ä»¤éå |
| | | */ |
| | | @Slf4j |
| | | @Component(CommandReSendService.BEAN_ID) |
| | | public class CommandReSendService extends BaseRemoteImpl { |
| | | |
| | | public static final String BEAN_ID = "zldz.commandReSendService"; |
| | | |
| | | public static final String REDIS_KEY_RESEND_COMMAND = "REDIS_KEY_RESEND_COMMAND"; |
| | | |
| | | public static final String REDIS_KEY_TH_QUEEN = "REDIS_KEY_TH_QUEEN"; |
| | | |
| | | public static final int REDIS_KEY_TIME = 4 * 60; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | public String buildKey(CommandTask data) { |
| | | return buildKey(data.getCompanyId(), data.getIp(), data.getPort(), |
| | | data.getResultType()); |
| | | } |
| | | |
| | | public String buildKey(String companyId, String ip, int port, |
| | | String resultType) { |
| | | String key = ip + "." + port + ":" + resultType; |
| | | return companyId + ":" + REDIS_KEY_RESEND_COMMAND + ":" + key; |
| | | } |
| | | |
| | | public void reSendTask(CommandTask data) { |
| | | // ç¼å |
| | | redisUtil.set(buildKey(data), data, REDIS_KEY_TIME); |
| | | |
| | | // å建åä»»å¡ |
| | | FutureTask<String> futureTask = new FutureTask<>(new ReSendCommonTask(data, redisUtil, buildKey(data))); |
| | | ExecutorService executorService = Executors.newCachedThreadPool(); |
| | | executorService.submit(futureTask); |
| | | executorService.shutdown(); |
| | | } |
| | | |
| | | // 温湿度å½ä»¤ä¸ä½¿ç¨åä»»å¡ |
| | | public void reSendThTask(CommandTask data) { |
| | | // ç¼å |
| | | redisUtil.set(buildKey(data), data, REDIS_KEY_TIME); |
| | | } |
| | | |
| | | public void reSendGrainTask(CommandTask data) { |
| | | // ç¼å |
| | | redisUtil.set(buildKey(data), data, REDIS_KEY_TIME); |
| | | |
| | | // å建åä»»å¡ |
| | | FutureTask<String> futureTask = new FutureTask<>(new ReSendGrainTask( |
| | | data, redisUtil, buildKey(data))); |
| | | ExecutorService executorService = Executors.newCachedThreadPool(); |
| | | executorService.submit(futureTask); |
| | | executorService.shutdown(); |
| | | } |
| | | |
| | | public void cleanKey(String companyId, String ip, int port, |
| | | String resultType) { |
| | | |
| | | String key = buildKey(companyId, ip, port, resultType); |
| | | redisUtil.del(key); |
| | | } |
| | | |
| | | public void destoryAndDelCache(String companyId, String ip, Integer port, |
| | | String messageType) { |
| | | try { |
| | | // ç²®æ
ç´æ¥ä½¿ç¨ææ»çç¶æè¿å |
| | | if (messageType.equals(ServerUtils.MSG_TYPE_1115)) { |
| | | messageType = ServerUtils.MSG_TYPE_8817; |
| | | } |
| | | this.cleanKey(companyId, ip, port, messageType); |
| | | |
| | | //é´é5S踢åºï¼é¿å
å¿«éç´æ¥è¿æ¥ |
| | | Thread.sleep(5 * 1000); |
| | | |
| | | super.destory(ip, port); |
| | | |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void reSend(String companyId, String ip, int port, String resultType) { |
| | | String key = buildKey(companyId, ip, port, resultType); |
| | | CommandTask commandData = (CommandTask) redisUtil.get(key); |
| | | if (null != commandData) { |
| | | super.send(ip, port, commandData.getByteCommand()); |
| | | } else { |
| | | log.error("å½ä»¤éå失败ï¼{}-{}-{}没æè·åå°å½ä»¤ã", ip, port, resultType); |
| | | } |
| | | } |
| | | |
| | | public CommandTask getRedisCommand(String companyId, String ip, |
| | | Integer port, String resultType) { |
| | | String key = this.buildKey(companyId, ip, port, resultType); |
| | | return (CommandTask) redisUtil.get(key); |
| | | } |
| | | |
| | | /** |
| | | * å½ååæºç¸åç²®æ
åæºççå¾
éå |
| | | * |
| | | * @param thRequest |
| | | * @param request |
| | | */ |
| | | public void addToThQueen(CheckThRequest thRequest, CheckGrainRequest request) { |
| | | String key = thRequest.getCompanyId() + ":" + REDIS_KEY_TH_QUEEN + ":" |
| | | + thRequest.getSerId(); |
| | | |
| | | List<CheckGrainRequest> list = this.getThQueen( |
| | | thRequest.getCompanyId(), thRequest.getSerId()); |
| | | if (null == list) { |
| | | list = new ArrayList<>(); |
| | | } |
| | | |
| | | list.add(request); |
| | | |
| | | redisUtil.set(key, list, 60); |
| | | } |
| | | |
| | | @SuppressWarnings("unchecked") |
| | | public List<CheckGrainRequest> getThQueen(String companyId, String serId) { |
| | | String key = companyId + ":" + REDIS_KEY_TH_QUEEN + ":" + serId; |
| | | return (List<CheckGrainRequest>) redisUtil.get(key); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.task; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * ç¨äºåæ¾åéçå½ä»¤ä¿¡æ¯ï¼åæ¾å°ç¼åä¸ |
| | | */ |
| | | @Data |
| | | public class CommandTask { |
| | | |
| | | private String companyId; |
| | | |
| | | private String depotId;//æ§è¡ä»åº |
| | | |
| | | private String serName; |
| | | |
| | | private String ip = ""; |
| | | |
| | | private int port = 0; |
| | | |
| | | private String command; //åéçå½ä»¤ |
| | | |
| | | private byte[] byteCommand; //åéçå½ä»¤ |
| | | |
| | | private String resultType;//çå¾
è¿åçå½ä»¤ç±»å |
| | | |
| | | private int sendNum = 1;//å鿬¡æ° |
| | | |
| | | private String cableRule; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.task; |
| | | |
| | | import com.ld.igds.protocol.zldz.command.BaseRemoteImpl; |
| | | import com.ld.igds.util.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.concurrent.Callable; |
| | | |
| | | /** |
| | | * åä»»å¡ï¼ç¨äºå¤æéååå¼å¸¸å¤çï¼å½ä»¤åéåå°å½ä»¤ä¿¡æ¯åæ¾ç¼åï¼å½å |
| | | * |
| | | * @author andy.jia |
| | | */ |
| | | @Slf4j |
| | | public class ReSendCommonTask extends BaseRemoteImpl implements Callable<String> { |
| | | |
| | | private CommandTask commandData; |
| | | |
| | | private RedisUtil redisUtil; |
| | | |
| | | private String redisKey; |
| | | |
| | | public RedisUtil getRedisUtil() { |
| | | return redisUtil; |
| | | } |
| | | |
| | | public void setRedisUtil(RedisUtil redisUtil) { |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | public String getRedisKey() { |
| | | return redisKey; |
| | | } |
| | | |
| | | public void setRedisKey(String redisKey) { |
| | | this.redisKey = redisKey; |
| | | } |
| | | |
| | | public void setCommandData(CommandTask commandData) { |
| | | this.commandData = commandData; |
| | | } |
| | | |
| | | public CommandTask getCommandData() { |
| | | return commandData; |
| | | } |
| | | |
| | | public ReSendCommonTask() { |
| | | super(); |
| | | } |
| | | |
| | | public ReSendCommonTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) { |
| | | super(); |
| | | this.commandData = commandData; |
| | | this.redisUtil = redisUtil; |
| | | this.redisKey = redisKey; |
| | | } |
| | | |
| | | @Override |
| | | public String call() throws Exception { |
| | | |
| | | //1,è·åç¼åä¸ä¿¡æ¯ |
| | | Thread.sleep(15 * 1000); |
| | | |
| | | CommandTask redisData = (CommandTask) redisUtil.get(redisKey); |
| | | if (null == redisData) { |
| | | return "å½ä»¤ç¬¬1次çå¾
ï¼ç»ç«¯å·²ç»æ£å¸¸è¿å"; |
| | | } else { |
| | | log.info("{}-第1次å½ä»¤è¡¥åå½ä»¤={}", commandData.getIp(), commandData.getCommand()); |
| | | super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand()); |
| | | } |
| | | |
| | | //2ï¼çå¾
20S |
| | | Thread.sleep(15 * 1000); |
| | | redisData = (CommandTask) redisUtil.get(redisKey); |
| | | if (null == redisData) { |
| | | return "å½ä»¤ç¬¬2次ççï¼ç»ç«¯å·²ç»æ£å¸¸è¿å"; |
| | | } else { |
| | | log.info("{}-第2次å½ä»¤è¡¥å½ä»¤={}", commandData.getIp(), commandData.getCommand()); |
| | | super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand()); |
| | | } |
| | | |
| | | //2ï¼çå¾
20S |
| | | Thread.sleep(15 * 1000); |
| | | redisData = (CommandTask) redisUtil.get(redisKey); |
| | | if (null == redisData) { |
| | | return "å½ä»¤ç¬¬3次ççï¼ç»ç«¯å·²ç»æ£å¸¸è¿å"; |
| | | } else { |
| | | log.info("{}-第3次å½ä»¤è¡¥ååï¼ä»ç¶æ²¡æè¿åï¼åæ¶çå¾
ã", commandData.getIp()); |
| | | //super.destory(commandData.getIp(), commandData.getPort()); |
| | | } |
| | | |
| | | return "å任塿§è¡å®æ"; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.task; |
| | | |
| | | import com.ld.igds.protocol.zldz.command.BaseRemoteImpl; |
| | | import com.ld.igds.util.RedisUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.concurrent.Callable; |
| | | |
| | | /** |
| | | * ç²®æ
åä»»å¡ï¼ç²®æ
åä»»å¡ï¼å¿½ç¥8815çåå¤å8817çåå¤ï¼ç´æ¥çç»æå
çå°è¾¾ï¼å¦æç»æå
没æå°è¾¾ï¼å°±éå¤åéç²®æ
è¯·æ± |
| | | * |
| | | * @author andy.jia |
| | | */ |
| | | @Slf4j |
| | | public class ReSendGrainTask extends BaseRemoteImpl implements Callable<String> { |
| | | |
| | | private CommandTask commandData; |
| | | |
| | | private RedisUtil redisUtil; |
| | | |
| | | private String redisKey; |
| | | |
| | | public RedisUtil getRedisUtil() { |
| | | return redisUtil; |
| | | } |
| | | |
| | | public void setRedisUtil(RedisUtil redisUtil) { |
| | | this.redisUtil = redisUtil; |
| | | } |
| | | |
| | | public String getRedisKey() { |
| | | return redisKey; |
| | | } |
| | | |
| | | public void setRedisKey(String redisKey) { |
| | | this.redisKey = redisKey; |
| | | } |
| | | |
| | | public void setCommandData(CommandTask commandData) { |
| | | this.commandData = commandData; |
| | | } |
| | | |
| | | public CommandTask getCommandData() { |
| | | return commandData; |
| | | } |
| | | |
| | | public ReSendGrainTask() { |
| | | super(); |
| | | } |
| | | |
| | | public ReSendGrainTask(CommandTask commandData, RedisUtil redisUtil, String redisKey) { |
| | | super(); |
| | | this.commandData = commandData; |
| | | this.redisUtil = redisUtil; |
| | | this.redisKey = redisKey; |
| | | } |
| | | |
| | | @Override |
| | | public String call() throws Exception { |
| | | |
| | | String[] attCable = commandData.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | |
| | | int point = cableX * cableY * cableZ; |
| | | long time = point * 100 + (point / 100) * 500; |
| | | |
| | | //1,ç²®æ
第1次çå¾
æ¶é´ä¸ºééç¹ä¸ªæ°* 0.1 ç§ + 20ç§ï¼å¦ææ²¡ææ£å¸¸è¿åååéç¬¬äºæ¬¡å½ä»¤ã |
| | | Thread.sleep(time); |
| | | CommandTask redisData = (CommandTask) redisUtil.get(redisKey); |
| | | if (null == redisData) { |
| | | return "å½ä»¤ç¬¬1次çå¾
ï¼ç»ç«¯å·²ç»æ£å¸¸è¿å"; |
| | | } else { |
| | | String msg = commandData.getSerName() + " 第1次补åå½ä»¤=" + commandData.getCommand(); |
| | | log.info(msg); |
| | | |
| | | super.send(commandData.getIp(), commandData.getPort(), commandData.getByteCommand()); |
| | | } |
| | | |
| | | //2 |
| | | Thread.sleep(time); |
| | | redisData = (CommandTask) redisUtil.get(redisKey); |
| | | if (null == redisData) { |
| | | return "å½ä»¤ç¬¬2次ççï¼ç»ç«¯å·²ç»æ£å¸¸è¿å"; |
| | | } else { |
| | | String msg = commandData.getSerName() + " 第2次补åç²®æ
å½ä»¤ï¼æ²¡æè¿åï¼ç³»ç»æå¼å½åè¿æ¥ã"; |
| | | log.info(msg); |
| | | |
| | | // ExeOrderService orderService = SpringUtil.getBean(ExeOrderService.class); |
| | | // orderService.progressError(commandData.getCompanyId(), BizType.GRAIN, commandData.getDepotId(), msg); |
| | | |
| | | //2021å¹´6æ5æ¥ 07:30:22 åæ¶è¶
æ¶è¸¢åºè¿æ¥ |
| | | // super.destory(commandData.getIp(), commandData.getPort()); |
| | | } |
| | | return "å任塿§è¡å®æ"; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.util; |
| | | |
| | | /*** |
| | | * |
| | | * @author Andy |
| | | * |
| | | */ |
| | | public class CRC16 { |
| | | |
| | | static byte[] crc16_tab_h = { (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, |
| | | (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, |
| | | (byte) 0x81, (byte) 0x40 }; |
| | | |
| | | static byte[] crc16_tab_l = { (byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03, |
| | | (byte) 0x02, (byte) 0xC2, (byte) 0xC6, (byte) 0x06, (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5, |
| | | (byte) 0xC4, (byte) 0x04, (byte) 0xCC, (byte) 0x0C, (byte) 0x0D, (byte) 0xCD, (byte) 0x0F, (byte) 0xCF, |
| | | (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, (byte) 0xC9, (byte) 0x09, |
| | | (byte) 0x08, (byte) 0xC8, (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB, |
| | | (byte) 0xDA, (byte) 0x1A, (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D, |
| | | (byte) 0x1C, (byte) 0xDC, (byte) 0x14, (byte) 0xD4, (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17, |
| | | (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, (byte) 0x13, (byte) 0xD3, (byte) 0x11, (byte) 0xD1, |
| | | (byte) 0xD0, (byte) 0x10, (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, (byte) 0x33, (byte) 0xF3, |
| | | (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35, |
| | | (byte) 0x34, (byte) 0xF4, (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F, |
| | | (byte) 0x3E, (byte) 0xFE, (byte) 0xFA, (byte) 0x3A, (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9, |
| | | (byte) 0xF8, (byte) 0x38, (byte) 0x28, (byte) 0xE8, (byte) 0xE9, (byte) 0x29, (byte) 0xEB, (byte) 0x2B, |
| | | (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, (byte) 0x2D, (byte) 0xED, |
| | | (byte) 0xEC, (byte) 0x2C, (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7, |
| | | (byte) 0xE6, (byte) 0x26, (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21, |
| | | (byte) 0x20, (byte) 0xE0, (byte) 0xA0, (byte) 0x60, (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3, |
| | | (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, (byte) 0xA7, (byte) 0x67, (byte) 0xA5, (byte) 0x65, |
| | | (byte) 0x64, (byte) 0xA4, (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, (byte) 0xAF, (byte) 0x6F, |
| | | (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9, |
| | | (byte) 0xA8, (byte) 0x68, (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B, |
| | | (byte) 0x7A, (byte) 0xBA, (byte) 0xBE, (byte) 0x7E, (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD, |
| | | (byte) 0xBC, (byte) 0x7C, (byte) 0xB4, (byte) 0x74, (byte) 0x75, (byte) 0xB5, (byte) 0x77, (byte) 0xB7, |
| | | (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, (byte) 0xB1, (byte) 0x71, |
| | | (byte) 0x70, (byte) 0xB0, (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, |
| | | (byte) 0x52, (byte) 0x92, (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, |
| | | (byte) 0x94, (byte) 0x54, (byte) 0x9C, (byte) 0x5C, (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F, |
| | | (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, (byte) 0x9B, (byte) 0x5B, (byte) 0x99, (byte) 0x59, |
| | | (byte) 0x58, (byte) 0x98, (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4B, (byte) 0x8B, |
| | | (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D, |
| | | (byte) 0x4C, (byte) 0x8C, (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, |
| | | (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, |
| | | (byte) 0x80, (byte) 0x40 }; |
| | | |
| | | /** |
| | | * 计ç®CRC16æ ¡éª |
| | | * |
| | | * @param data |
| | | * éè¦è®¡ç®çæ°ç» |
| | | * @return CRC16æ ¡éªå¼ |
| | | */ |
| | | public static int calcCrc16(byte[] data) { |
| | | return calcCrc16(data, 0, data.length); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®CRC16æ ¡éª |
| | | * |
| | | * @param data |
| | | * éè¦è®¡ç®çæ°ç» |
| | | * @param offset |
| | | * èµ·å§ä½ç½® |
| | | * @param len |
| | | * é¿åº¦ |
| | | * @return CRC16æ ¡éªå¼ |
| | | */ |
| | | public static int calcCrc16(byte[] data, int offset, int len) { |
| | | return calcCrc16(data, offset, len, 0xffff); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®CRC16æ ¡éª |
| | | * |
| | | * @param data |
| | | * éè¦è®¡ç®çæ°ç» |
| | | * @param offset |
| | | * èµ·å§ä½ç½® |
| | | * @param len |
| | | * é¿åº¦ |
| | | * @param preval |
| | | * ä¹åçæ ¡éªå¼ |
| | | * @return CRC16æ ¡éªå¼ |
| | | */ |
| | | public static int calcCrc16(byte[] data, int offset, int len, int preval) { |
| | | int ucCRCHi = (preval & 0xff00) >> 8; |
| | | int ucCRCLo = preval & 0x00ff; |
| | | int iIndex; |
| | | for (int i = 0; i < len; ++i) { |
| | | iIndex = (ucCRCLo ^ data[offset + i]) & 0x00ff; |
| | | ucCRCLo = ucCRCHi ^ crc16_tab_h[iIndex]; |
| | | ucCRCHi = crc16_tab_l[iIndex]; |
| | | } |
| | | return ((ucCRCHi & 0x00ff) << 8) | (ucCRCLo & 0x00ff) & 0xffff; |
| | | } |
| | | |
| | | // æµè¯ |
| | | public static void main(String[] args) { |
| | | // 0x02 05 00 03 FF 00 , crc16=7C 09 |
| | | int crc = CRC16.calcCrc16(new byte[] { 0x02, 0x05, 0x00, 0x03, (byte) 0xff, 0x00 }); |
| | | System.out.println(String.format("0x%04x", crc)); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.util; |
| | | |
| | | /** |
| | | *计ç®CRC8æ ¡éªå¼ |
| | | */ |
| | | public class CRC8 { |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | } |
| | | |
| | | static short[] gCrc16Table = { (short) 0x0000, (short) 0x1021, (short) 0x2042, (short) 0x3063, (short) 0x4084, |
| | | (short) 0x50a5, (short) 0x60c6, (short) 0x70e7, (short) 0xd94c, (short) 0xc96d, (short) 0xf90e, |
| | | (short) 0xe92f, (short) 0x99c8, (short) 0x89e9, (short) 0xb98a, (short) 0xa9ab, (short) 0x5844, |
| | | (short) 0x4865, (short) 0x7806, (short) 0x6827, (short) 0x18c0, (short) 0x08e1, (short) 0x3882, |
| | | (short) 0x28a3, (short) 0xcb7d, (short) 0xdb5c, (short) 0xeb3f, (short) 0xfb1e, (short) 0x8bf9, |
| | | (short) 0x9bd8, (short) 0xabbb, (short) 0xbb9a, (short) 0x4a75, (short) 0x5a54, (short) 0x6a37, |
| | | (short) 0x7a16, (short) 0x0af1, (short) 0x1ad0, (short) 0x2ab3, (short) 0x3a92, (short) 0xfd2e, |
| | | (short) 0xed0f, (short) 0xdd6c, (short) 0xcd4d, (short) 0xbdaa, (short) 0xad8b, (short) 0x9de8, |
| | | (short) 0x8dc9, (short) 0xc9cc, (short) 0xd9ed, (short) 0xe98e, (short) 0xf9af, (short) 0x8948, |
| | | (short) 0x9969, (short) 0xa90a, (short) 0xb92b, (short) 0x5af5, (short) 0x4ad4, (short) 0x7ab7, |
| | | (short) 0x6a96, (short) 0x1a71, (short) 0x0a50, (short) 0x3a33, (short) 0x2a12, (short) 0xdbfd, |
| | | (short) 0xcbdc, (short) 0xfbbf, (short) 0xeb9e, (short) 0x9b79, (short) 0x8b58, (short) 0xbb3b, |
| | | (short) 0xab1a, (short) 0x6ca6, (short) 0x7c87, (short) 0x4ce4, (short) 0x5cc5, (short) 0x2c22, |
| | | (short) 0x3c03, (short) 0x0c60, (short) 0x1c41, (short) 0x8108, (short) 0x9129, (short) 0xa14a, |
| | | (short) 0xb16b, (short) 0xc18c, (short) 0xd1ad, (short) 0xe1ce, (short) 0xf1ef, (short) 0x1231, |
| | | (short) 0x0210, (short) 0x3273, (short) 0x2252, (short) 0x52b5, (short) 0x4294, (short) 0x72f7, |
| | | (short) 0x62d6, (short) 0x9339, (short) 0x8318, (short) 0xb37b, (short) 0xa35a, (short) 0xd3bd, |
| | | (short) 0xc39c, (short) 0xf3ff, (short) 0xe3de, (short) 0x2462, (short) 0x3443, (short) 0x0420, |
| | | (short) 0x1401, (short) 0x64e6, (short) 0x74c7, (short) 0x44a4, (short) 0x5485, (short) 0xa56a, |
| | | (short) 0xb54b, (short) 0x8528, (short) 0x9509, (short) 0xe5ee, (short) 0xf5cf, (short) 0xc5ac, |
| | | (short) 0xd58d, (short) 0x3653, (short) 0x2672, (short) 0x1611, (short) 0x0630, (short) 0x76d7, |
| | | (short) 0x66f6, (short) 0x5695, (short) 0x46b4, (short) 0xb75b, (short) 0xa77a, (short) 0x9719, |
| | | (short) 0x8738, (short) 0xf7df, (short) 0xe7fe, (short) 0xd79d, (short) 0xc7bc, (short) 0x48c4, |
| | | (short) 0x58e5, (short) 0x6886, (short) 0x78a7, (short) 0x0840, (short) 0x1861, (short) 0x2802, |
| | | (short) 0x3823, (short) 0x83b9, (short) 0x9398, (short) 0xa3fb, (short) 0xb3da, (short) 0xc33d, |
| | | (short) 0xd31c, (short) 0xe37f, (short) 0xf35e, (short) 0x02b1, (short) 0x1290, (short) 0x22f3, |
| | | (short) 0x32d2, (short) 0x4235, (short) 0x5214, (short) 0x6277, (short) 0x7256, (short) 0xb5ea, |
| | | (short) 0xa5cb, (short) 0x95a8, (short) 0x8589, (short) 0xf56e, (short) 0xe54f, (short) 0xd52c, |
| | | (short) 0xc50d, (short) 0x34e2, (short) 0x24c3, (short) 0x14a0, (short) 0x0481, (short) 0x7466, |
| | | (short) 0x6447, (short) 0x5424, (short) 0x4405, (short) 0xa7db, (short) 0xb7fa, (short) 0x8799, |
| | | (short) 0x97b8, (short) 0xe75f, (short) 0xf77e, (short) 0xc71d, (short) 0xd73c, (short) 0x26d3, |
| | | (short) 0x36f2, (short) 0x0691, (short) 0x16b0, (short) 0x6657, (short) 0x7676, (short) 0x4615, |
| | | (short) 0x5634, (short) 0xedae, (short) 0xfd8f, (short) 0xcdec, (short) 0xddcd, (short) 0xad2a, |
| | | (short) 0xbd0b, (short) 0x8d68, (short) 0x9d49, (short) 0x7e97, (short) 0x6eb6, (short) 0x5ed5, |
| | | (short) 0x4ef4, (short) 0x3e13, (short) 0x2e32, (short) 0x1e51, (short) 0x0e70, (short) 0xff9f, |
| | | (short) 0xefbe, (short) 0xdfdd, (short) 0xcffc, (short) 0xbf1b, (short) 0xaf3a, (short) 0x9f59, |
| | | (short) 0x8f78, (short) 0x9188, (short) 0x81a9, (short) 0xb1ca, (short) 0xa1eb, (short) 0xd10c, |
| | | (short) 0xc12d, (short) 0xf14e, (short) 0xe16f, (short) 0x1080, (short) 0x00a1, (short) 0x30c2, |
| | | (short) 0x20e3, (short) 0x5004, (short) 0x4025, (short) 0x7046, (short) 0x6067, (short) 0x7c26, |
| | | (short) 0x6c07, (short) 0x5c64, (short) 0x4c45, (short) 0x3ca2, (short) 0x2c83, (short) 0x1ce0, |
| | | (short) 0x0cc1, (short) 0xef1f, (short) 0xff3e, (short) 0xcf5d, (short) 0xdf7c, (short) 0xaf9b, |
| | | (short) 0xbfba, (short) 0x8fd9, (short) 0x9ff8, (short) 0x6e17, (short) 0x7e36, (short) 0x4e55, |
| | | (short) 0x5e74, (short) 0x2e93, (short) 0x3eb2, (short) 0x0ed1, (short) 0x1ef0 }; |
| | | |
| | | static short[] crc8_tab = { (short) 0x00, (short) 0x07, (short) 0x0E, (short) 0x09, (short) 0x1C, (short) 0x1B, |
| | | (short) 0x12, (short) 0x15, (short) 0x38, (short) 0x3F, (short) 0x36, (short) 0x31, (short) 0x24, |
| | | (short) 0x23, (short) 0x2A, (short) 0x2D, (short) 0x70, (short) 0x77, (short) 0x7E, (short) 0x79, |
| | | (short) 0x6C, (short) 0x6B, (short) 0x62, (short) 0x65, (short) 0x48, (short) 0x4F, (short) 0x46, |
| | | (short) 0x41, (short) 0x54, (short) 0x53, (short) 0x5A, (short) 0x5D, (short) 0xE0, (short) 0xE7, |
| | | (short) 0xEE, (short) 0xE9, (short) 0xFC, (short) 0xFB, (short) 0xF2, (short) 0xF5, (short) 0xD8, |
| | | (short) 0xDF, (short) 0xD6, (short) 0xD1, (short) 0xC4, (short) 0xC3, (short) 0xCA, (short) 0xCD, |
| | | (short) 0x90, (short) 0x97, (short) 0x9E, (short) 0x99, (short) 0x8C, (short) 0x8B, (short) 0x82, |
| | | (short) 0x85, (short) 0xA8, (short) 0xAF, (short) 0xA6, (short) 0xA1, (short) 0xB4, (short) 0xB3, |
| | | (short) 0xBA, (short) 0xBD, (short) 0xC7, (short) 0xC0, (short) 0xC9, (short) 0xCE, (short) 0xDB, |
| | | (short) 0xDC, (short) 0xD5, (short) 0xD2, (short) 0xFF, (short) 0xF8, (short) 0xF1, (short) 0xF6, |
| | | (short) 0xE3, (short) 0xE4, (short) 0xED, (short) 0xEA, (short) 0xB7, (short) 0xB0, (short) 0xB9, |
| | | (short) 0xBE, (short) 0xAB, (short) 0xAC, (short) 0xA5, (short) 0xA2, (short) 0x8F, (short) 0x88, |
| | | (short) 0x81, (short) 0x86, (short) 0x93, (short) 0x94, (short) 0x9D, (short) 0x9A, (short) 0x27, |
| | | (short) 0x20, (short) 0x29, (short) 0x2E, (short) 0x3B, (short) 0x3C, (short) 0x35, (short) 0x32, |
| | | (short) 0x1F, (short) 0x18, (short) 0x11, (short) 0x16, (short) 0x03, (short) 0x04, (short) 0x0D, |
| | | (short) 0x0A, (short) 0x57, (short) 0x50, (short) 0x59, (short) 0x5E, (short) 0x4B, (short) 0x4C, |
| | | (short) 0x45, (short) 0x42, (short) 0x6F, (short) 0x68, (short) 0x61, (short) 0x66, (short) 0x73, |
| | | (short) 0x74, (short) 0x7D, (short) 0x7A, (short) 0x89, (short) 0x8E, (short) 0x87, (short) 0x80, |
| | | (short) 0x95, (short) 0x92, (short) 0x9B, (short) 0x9C, (short) 0xB1, (short) 0xB6, (short) 0xBF, |
| | | (short) 0xB8, (short) 0xAD, (short) 0xAA, (short) 0xA3, (short) 0xA4, (short) 0xF9, (short) 0xFE, |
| | | (short) 0xF7, (short) 0xF0, (short) 0xE5, (short) 0xE2, (short) 0xEB, (short) 0xEC, (short) 0xC1, |
| | | (short) 0xC6, (short) 0xCF, (short) 0xC8, (short) 0xDD, (short) 0xDA, (short) 0xD3, (short) 0xD4, |
| | | (short) 0x69, (short) 0x6E, (short) 0x67, (short) 0x60, (short) 0x75, (short) 0x72, (short) 0x7B, |
| | | (short) 0x7C, (short) 0x51, (short) 0x56, (short) 0x5F, (short) 0x58, (short) 0x4D, (short) 0x4A, |
| | | (short) 0x43, (short) 0x44, (short) 0x19, (short) 0x1E, (short) 0x17, (short) 0x10, (short) 0x05, |
| | | (short) 0x02, (short) 0x0B, (short) 0x0C, (short) 0x21, (short) 0x26, (short) 0x2F, (short) 0x28, |
| | | (short) 0x3D, (short) 0x3A, (short) 0x33, (short) 0x34, (short) 0x4E, (short) 0x49, (short) 0x40, |
| | | (short) 0x47, (short) 0x52, (short) 0x55, (short) 0x5C, (short) 0x5B, (short) 0x76, (short) 0x71, |
| | | (short) 0x78, (short) 0x7F, (short) 0x6A, (short) 0x6D, (short) 0x64, (short) 0x63, (short) 0x3E, |
| | | (short) 0x39, (short) 0x30, (short) 0x37, (short) 0x22, (short) 0x25, (short) 0x2C, (short) 0x2B, |
| | | (short) 0x06, (short) 0x01, (short) 0x08, (short) 0x0F, (short) 0x1A, (short) 0x1D, (short) 0x14, |
| | | (short) 0x13, (short) 0xAE, (short) 0xA9, (short) 0xA0, (short) 0xA7, (short) 0xB2, (short) 0xB5, |
| | | (short) 0xBC, (short) 0xBB, (short) 0x96, (short) 0x91, (short) 0x98, (short) 0x9F, (short) 0x8A, |
| | | (short) 0x8D, (short) 0x84, (short) 0x83, (short) 0xDE, (short) 0xD9, (short) 0xD0, (short) 0xD7, |
| | | (short) 0xC2, (short) 0xC5, (short) 0xCC, (short) 0xCB, (short) 0xE6, (short) 0xE1, (short) 0xE8, |
| | | (short) 0xEF, (short) 0xFA, (short) 0xFD, (short) 0xF4, (short) 0xF3 }; |
| | | |
| | | static byte[] crc8_tab2 = { (byte) 0x00, (byte) 0x07, (byte) 0x0E, (byte) 0x09, (byte) 0x1C, (byte) 0x1B, |
| | | (byte) 0x12, (byte) 0x15, (byte) 0x38, (byte) 0x3F, (byte) 0x36, (byte) 0x31, (byte) 0x24, (byte) 0x23, |
| | | (byte) 0x2A, (byte) 0x2D, (byte) 0x70, (byte) 0x77, (byte) 0x7E, (byte) 0x79, (byte) 0x6C, (byte) 0x6B, |
| | | (byte) 0x62, (byte) 0x65, (byte) 0x48, (byte) 0x4F, (byte) 0x46, (byte) 0x41, (byte) 0x54, (byte) 0x53, |
| | | (byte) 0x5A, (byte) 0x5D, (byte) 0xE0, (byte) 0xE7, (byte) 0xEE, (byte) 0xE9, (byte) 0xFC, (byte) 0xFB, |
| | | (byte) 0xF2, (byte) 0xF5, (byte) 0xD8, (byte) 0xDF, (byte) 0xD6, (byte) 0xD1, (byte) 0xC4, (byte) 0xC3, |
| | | (byte) 0xCA, (byte) 0xCD, (byte) 0x90, (byte) 0x97, (byte) 0x9E, (byte) 0x99, (byte) 0x8C, (byte) 0x8B, |
| | | (byte) 0x82, (byte) 0x85, (byte) 0xA8, (byte) 0xAF, (byte) 0xA6, (byte) 0xA1, (byte) 0xB4, (byte) 0xB3, |
| | | (byte) 0xBA, (byte) 0xBD, (byte) 0xC7, (byte) 0xC0, (byte) 0xC9, (byte) 0xCE, (byte) 0xDB, (byte) 0xDC, |
| | | (byte) 0xD5, (byte) 0xD2, (byte) 0xFF, (byte) 0xF8, (byte) 0xF1, (byte) 0xF6, (byte) 0xE3, (byte) 0xE4, |
| | | (byte) 0xED, (byte) 0xEA, (byte) 0xB7, (byte) 0xB0, (byte) 0xB9, (byte) 0xBE, (byte) 0xAB, (byte) 0xAC, |
| | | (byte) 0xA5, (byte) 0xA2, (byte) 0x8F, (byte) 0x88, (byte) 0x81, (byte) 0x86, (byte) 0x93, (byte) 0x94, |
| | | (byte) 0x9D, (byte) 0x9A, (byte) 0x27, (byte) 0x20, (byte) 0x29, (byte) 0x2E, (byte) 0x3B, (byte) 0x3C, |
| | | (byte) 0x35, (byte) 0x32, (byte) 0x1F, (byte) 0x18, (byte) 0x11, (byte) 0x16, (byte) 0x03, (byte) 0x04, |
| | | (byte) 0x0D, (byte) 0x0A, (byte) 0x57, (byte) 0x50, (byte) 0x59, (byte) 0x5E, (byte) 0x4B, (byte) 0x4C, |
| | | (byte) 0x45, (byte) 0x42, (byte) 0x6F, (byte) 0x68, (byte) 0x61, (byte) 0x66, (byte) 0x73, (byte) 0x74, |
| | | (byte) 0x7D, (byte) 0x7A, (byte) 0x89, (byte) 0x8E, (byte) 0x87, (byte) 0x80, (byte) 0x95, (byte) 0x92, |
| | | (byte) 0x9B, (byte) 0x9C, (byte) 0xB1, (byte) 0xB6, (byte) 0xBF, (byte) 0xB8, (byte) 0xAD, (byte) 0xAA, |
| | | (byte) 0xA3, (byte) 0xA4, (byte) 0xF9, (byte) 0xFE, (byte) 0xF7, (byte) 0xF0, (byte) 0xE5, (byte) 0xE2, |
| | | (byte) 0xEB, (byte) 0xEC, (byte) 0xC1, (byte) 0xC6, (byte) 0xCF, (byte) 0xC8, (byte) 0xDD, (byte) 0xDA, |
| | | (byte) 0xD3, (byte) 0xD4, (byte) 0x69, (byte) 0x6E, (byte) 0x67, (byte) 0x60, (byte) 0x75, (byte) 0x72, |
| | | (byte) 0x7B, (byte) 0x7C, (byte) 0x51, (byte) 0x56, (byte) 0x5F, (byte) 0x58, (byte) 0x4D, (byte) 0x4A, |
| | | (byte) 0x43, (byte) 0x44, (byte) 0x19, (byte) 0x1E, (byte) 0x17, (byte) 0x10, (byte) 0x05, (byte) 0x02, |
| | | (byte) 0x0B, (byte) 0x0C, (byte) 0x21, (byte) 0x26, (byte) 0x2F, (byte) 0x28, (byte) 0x3D, (byte) 0x3A, |
| | | (byte) 0x33, (byte) 0x34, (byte) 0x4E, (byte) 0x49, (byte) 0x40, (byte) 0x47, (byte) 0x52, (byte) 0x55, |
| | | (byte) 0x5C, (byte) 0x5B, (byte) 0x76, (byte) 0x71, (byte) 0x78, (byte) 0x7F, (byte) 0x6A, (byte) 0x6D, |
| | | (byte) 0x64, (byte) 0x63, (byte) 0x3E, (byte) 0x39, (byte) 0x30, (byte) 0x37, (byte) 0x22, (byte) 0x25, |
| | | (byte) 0x2C, (byte) 0x2B, (byte) 0x06, (byte) 0x01, (byte) 0x08, (byte) 0x0F, (byte) 0x1A, (byte) 0x1D, |
| | | (byte) 0x14, (byte) 0x13, (byte) 0xAE, (byte) 0xA9, (byte) 0xA0, (byte) 0xA7, (byte) 0xB2, (byte) 0xB5, |
| | | (byte) 0xBC, (byte) 0xBB, (byte) 0x96, (byte) 0x91, (byte) 0x98, (byte) 0x9F, (byte) 0x8A, (byte) 0x8D, |
| | | (byte) 0x84, (byte) 0x83, (byte) 0xDE, (byte) 0xD9, (byte) 0xD0, (byte) 0xD7, (byte) 0xC2, (byte) 0xC5, |
| | | (byte) 0xCC, (byte) 0xCB, (byte) 0xE6, (byte) 0xE1, (byte) 0xE8, (byte) 0xEF, (byte) 0xFA, (byte) 0xFD, |
| | | (byte) 0xF4, (byte) 0xF3 }; |
| | | |
| | | /** |
| | | * è®¡ç®æ°ç»çCRC8æ ¡éªå¼ |
| | | * |
| | | * @param data |
| | | * éè¦è®¡ç®çæ°ç» |
| | | * @return CRC8æ ¡éªå¼ |
| | | */ |
| | | public static byte calcCrc8(byte[] data) { |
| | | return calcCrc8(data, (short) 2, (short) (data.length - 2), (byte) 0); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®CRC8æ ¡éªå¼ |
| | | * |
| | | * @param data |
| | | * æ°æ® |
| | | * @param offset |
| | | * èµ·å§ä½ç½® |
| | | * @param len |
| | | * é¿åº¦ |
| | | * @return æ ¡éªå¼ |
| | | */ |
| | | public static byte calcCrc8(byte[] data, short offset, short len) { |
| | | return calcCrc8(data, offset, len, (byte) 0); |
| | | } |
| | | |
| | | public static byte calcCrc8(byte[] ucPtr, short offset, short ucLen, byte preval) { |
| | | short ucIndex; // CRC8æ ¡éªè¡¨æ ¼ç´¢å¼ |
| | | short ucCRC8 = 0; // CRC8åèåå§å |
| | | short i = 0; |
| | | // è¿è¡CRC8使 ¡éª |
| | | while ((ucLen--) > 0) { |
| | | short indexI = (short) (i + offset); |
| | | short data = ucPtr[indexI]; |
| | | if (data < 0) { |
| | | int sd = Byte.toUnsignedInt(ucPtr[indexI]); |
| | | data = (short) sd; |
| | | } |
| | | ucIndex = (short) (ucCRC8 ^ data); |
| | | ucCRC8 = crc8_tab[(short) ucIndex]; |
| | | i++; |
| | | } |
| | | // è¿åCRC8æ ¡éªæ°æ® |
| | | return (byte) (~ucCRC8); |
| | | } |
| | | |
| | | public static short crc16Byte(short crc, byte data) { |
| | | return (short) ((crc << 8) ^ gCrc16Table[((crc >> 8) ^ data) & 0xff]); |
| | | } |
| | | |
| | | public static short calculateCrc16(byte[] buf, short offset, short length) { |
| | | short crc = 0; |
| | | short i = 0; |
| | | while ((length--) > 0) { |
| | | crc = crc16Byte(crc, buf[offset + (i++)]); |
| | | } |
| | | return crc; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.zldz.util; |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * å·¥å
·ç±» |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public class ServerUtils { |
| | | |
| | | public static final Map<String, String> contextMap = new HashMap<>(); |
| | | |
| | | public static final String MSG_START = "AAAA"; |
| | | public static final String MSG_END = "EEEE"; |
| | | |
| | | //é»è®¤ç»ç»ç¼å· |
| | | public static final String DEFAULT_COMPANY = "0000"; |
| | | |
| | | |
| | | public static final String MSG_TYPE_1115 = "1115";// åå°è·åç²®æ
æ°æ®è¯·æ± |
| | | |
| | | public static final String MSG_TYPE_8815 = "8815";// ç»ç«¯åºçç²®æ
æ°æ®è¯·æ± |
| | | |
| | | public static final String MSG_TYPE_1116 = "1116";// é
置读ååæºåæ° |
| | | |
| | | public static final String MSG_TYPE_8816 = "8816";// é
置读ååæºåæ°åºç |
| | | |
| | | public static final String MSG_TYPE_1117 = "1117";// ç»ç«¯åéç²®æ
æ°æ®ç»åå° |
| | | |
| | | public static final String MSG_TYPE_8817 = "8817";// åå°æ¶å°ç²®æ
æ°æ®åºç |
| | | |
| | | public static final String MSG_TYPE_1122 = "1122";// åå§åçµç¼çµç¼ |
| | | |
| | | public static final String MSG_TYPE_1123 = "1123";// çµç¼æ±æ» |
| | | |
| | | public static final String MSG_TYPE_1125 = "1125";// 读åééçµç¼ |
| | | |
| | | public static final String MSG_TYPE_8825 = "8825";//读åééçµç¼åºç |
| | | |
| | | public static final String MSG_TYPE_1126 = "1126";// ä¿®æ¹ééçµç¼ |
| | | |
| | | public static final String MSG_TYPE_8826 = "8826";// ä¿®æ¹ééçµç¼åºç |
| | | |
| | | |
| | | public static final String MSG_TYPE_1128 = "1128";// 读åæçº¿æ¸©æ¹¿åº¦ |
| | | |
| | | public static final String MSG_TYPE_8822 = "8822";// åºçåå§åçµç¼çµç¼ |
| | | |
| | | public static final String MSG_TYPE_8823 = "8823";// åºççµç¼æ±æ»ç»æ |
| | | |
| | | public static final String MSG_TYPE_8828 = "8828";// 读åæçº¿æ¸©æ¹¿åº¦åºç |
| | | |
| | | public static final String MSG_TYPE_1129 = "1129";// ç»ç«¯åéééçµç¼æ°æ®ç»åå° |
| | | |
| | | public static final String MSG_TYPE_8829 = "8829";// åå°æ¶å°çµç¼æ°æ®åºç |
| | | |
| | | public static final String MSG_TYPE_112B = "112B";// éå¯åæº |
| | | |
| | | public static final String MSG_TYPE_882B = "882B";// éå¯åæºåºç |
| | | |
| | | |
| | | public static String getServerKey(String ip, int port) { |
| | | return ip + ":" + port; |
| | | } |
| | | } |
| | |
| | | </dependency> |
| | | |
| | | <!-- MODBUS-TCP --> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-modbus</artifactId> |
| | | <version>${igds.version}</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <artifactId>slf4j-log4j12</artifactId> |
| | | <groupId>org.slf4j</groupId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <artifactId>log4j</artifactId> |
| | | <groupId>log4j</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | <!-- <dependency>--> |
| | | <!-- <groupId>com.ld.igds</groupId>--> |
| | | <!-- <artifactId>igds-protocol-modbus</artifactId>--> |
| | | <!-- <version>${igds.version}</version>--> |
| | | <!-- <exclusions>--> |
| | | <!-- <exclusion>--> |
| | | <!-- <artifactId>slf4j-log4j12</artifactId>--> |
| | | <!-- <groupId>org.slf4j</groupId>--> |
| | | <!-- </exclusion>--> |
| | | <!-- <exclusion>--> |
| | | <!-- <artifactId>log4j</artifactId>--> |
| | | <!-- <groupId>log4j</groupId>--> |
| | | <!-- </exclusion>--> |
| | | <!-- </exclusions>--> |
| | | <!-- </dependency>--> |
| | | |
| | | |
| | | <!-- ç§æåè®®-飿£è´è¿IOTãå¶æ°®æº--> |
| | |
| | | </exclusions> |
| | | </dependency> |
| | | |
| | | <!-- ç§æåè®®-è´åç²®æ
|
| | | <!-- ç§æåè®®-è´åç²®æ
--> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-beibo</artifactId> |
| | |
| | | <groupId>log4j</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency>--> |
| | | </dependency> |
| | | |
| | | <!-- ç§æåè®®-馿µ·æºè½ |
| | | <!-- ç§æåè®®-馿µ·æºè½--> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-bhzn</artifactId> |
| | |
| | | <groupId>log4j</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency>--> |
| | | |
| | | <!-- 海康车çè¯å«-SDK |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-zldz</artifactId> |
| | | <version>${igds.version}</version> |
| | | <exclusions> |
| | | <exclusion> |
| | | <artifactId>slf4j-log4j12</artifactId> |
| | | <groupId>org.slf4j</groupId> |
| | | </exclusion> |
| | | <exclusion> |
| | | <artifactId>log4j</artifactId> |
| | | <groupId>log4j</groupId> |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | <!-- 海康车çè¯å«-SDK --> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-sdk</artifactId> |
| | |
| | | </exclusion> |
| | | </exclusions> |
| | | </dependency> |
| | | --> |
| | | |
| | | </dependencies> |
| | | |
| | | |
| | | <dependencyManagement> |
| | | <dependencies> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | ########################## 飿£è´è¿-ç²®æ
æå¡å¨ ########################## |
| | | server: |
| | | port: 8201 |
| | | context-path: / |
| | | connection-timeout: 5000 |
| | | tomcat: |
| | | uri-encoding: UTF-8 |
| | | |
| | | ########################## datasourcec ########################## |
| | | spring: |
| | | datasource: |
| | | db-base: |
| | | name: db-base |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | url: jdbc:mysql://127.0.0.1:3306/igds_master_v35?useUnicode=true&characterEncoding=utf-8 |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | | username: root |
| | | password: ukJp12Qf+elyBvGHkJ5MQMa95pfVm0oFBHefdEgDFKoFSjbgYa9PYfv5vlem5nvoXjQsP9tIIo53DvSbsl160Q== |
| | | public-key: |
| | | config-decrypt: true |
| | | initial-size: 5 |
| | | min-idle: 5 |
| | | max-active: 50 |
| | | max-wait: 60000 |
| | | time-between-eviction-runs-millis: 60000 |
| | | min-evictable-idle-time-millis: 300000 |
| | | validation-query: select 1 from dual |
| | | test-whileIdle: true |
| | | test-on-borrow: false |
| | | test-on-return: false |
| | | pool-prepared-statements: true |
| | | max-pool-prepared-statement-per-connection-size: 20 |
| | | filters: stat |
| | | connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
| | | use-global-data-source-stat: true |
| | | remove-abandoned: true |
| | | remove-abandoned-timeout: 1800 |
| | | log-abandoned: true |
| | | db-sqlite: |
| | | name: db-sqlite |
| | | url: jdbc:sqlite:D:/app/igds/db/iot_cfg.db |
| | | driver-class-name: org.sqlite.JDBC |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | username: |
| | | password: |
| | | |
| | | # Redisç¸å
³é
ç½® |
| | | redis: |
| | | database: 0 |
| | | host: 127.0.0.1 |
| | | port: 6379 |
| | | password: Abc123.. |
| | | # è¿æ¥æ± æå¤§è¿æ¥æ°ï¼ä½¿ç¨è´å¼è¡¨ç¤ºæ²¡æéå¶ï¼ |
| | | pool: |
| | | max-active: 200 |
| | | max-wait: -1 |
| | | max-idle: 10 |
| | | min-idle: 0 |
| | | timeout: 6000 |
| | | |
| | | license: |
| | | subject: ld_license |
| | | publicAlias: publicCert |
| | | storePass: PUBLICFZZYXXJSGFYXGS888888 |
| | | licensePath: C:/license/license.lic |
| | | publicKeysStorePath: C:/license/publicCerts.keystore |
| | | |
| | | ########################## IGDS ########################## |
| | | ## ç³»ç»æ¥å£è·¯ç±é
ç½® æ³¨ææ°å妿以0å¼å¤´çè¯ï¼åå°ä¼åºç°è½¬ä¹ï¼è¯·æ·»å "" |
| | | igds: |
| | | default: |
| | | companyId: 1000 |
| | | sys-name: æºæ
§ç²®åºç®¡çç³»ç» |
| | | logo: logo-default.png |
| | | logo-title: logo-title-default.png |
| | | support: æºæ
§ç²®æ
ç²®æ
äºç®¡çå¹³å° |
| | | grian-add-point: N |
| | | media-ip: 124.71.162.207 |
| | | media-port: 18000 |
| | | file-path: C:/IGDS-PLATFORM/ |
¶Ô±ÈÐÂÎļþ |
| | |
| | | ########################## 广ä¸å¾é»é¡¹ç® ########################## |
| | | server: |
| | | port: 8888 |
| | | context-path: / |
| | | connection-timeout: 5000 |
| | | tomcat: |
| | | uri-encoding: UTF-8 |
| | | |
| | | ########################## datasourcec ########################## |
| | | spring: |
| | | datasource: |
| | | db-base: |
| | | name: db-base |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | url: jdbc:mysql://127.0.0.1:3306/igds_master?useUnicode=true&characterEncoding=utf-8 |
| | | driver-class-name: com.mysql.jdbc.Driver |
| | | username: root |
| | | password: ukJp12Qf+elyBvGHkJ5MQMa95pfVm0oFBHefdEgDFKoFSjbgYa9PYfv5vlem5nvoXjQsP9tIIo53DvSbsl160Q== |
| | | public-key: |
| | | config-decrypt: true |
| | | initial-size: 5 |
| | | min-idle: 5 |
| | | max-active: 50 |
| | | max-wait: 60000 |
| | | time-between-eviction-runs-millis: 60000 |
| | | min-evictable-idle-time-millis: 300000 |
| | | validation-query: select 1 from dual |
| | | test-whileIdle: true |
| | | test-on-borrow: false |
| | | test-on-return: false |
| | | pool-prepared-statements: true |
| | | max-pool-prepared-statement-per-connection-size: 20 |
| | | filters: stat |
| | | connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 |
| | | use-global-data-source-stat: true |
| | | removeAbandoned: true |
| | | removeAbandonedTimeout: 90 |
| | | logAbandoned: true |
| | | poolPreparedStatements: true |
| | | maxPoolPreparedStatementPerConnectionSize: 20 |
| | | db-sqlite: |
| | | name: db-sqlite |
| | | url: jdbc:sqlite:D:/app/igds/db/iot_cfg.db |
| | | driver-class-name: org.sqlite.JDBC |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | username: |
| | | password: |
| | | |
| | | # Redisç¸å
³é
ç½® |
| | | redis: |
| | | database: 0 |
| | | host: 127.0.0.1 |
| | | port: 6379 |
| | | password: Abc123.. |
| | | # è¿æ¥æ± æå¤§è¿æ¥æ°ï¼ä½¿ç¨è´å¼è¡¨ç¤ºæ²¡æéå¶ï¼ |
| | | pool: |
| | | max-active: 200 |
| | | max-wait: -1 |
| | | max-idle: 10 |
| | | min-idle: 0 |
| | | timeout: 6000 |
| | | |
| | | license: |
| | | subject: ld_license |
| | | publicAlias: publicCert |
| | | storePass: PUBLICFZZYXXJSGFYXGS888888 |
| | | licensePath: D:/IGDS/license/license.lic |
| | | publicKeysStorePath: D:/IGDS/license/publicCerts.keystore |
| | | |
| | | ########################## IGDS ########################## |
| | | ## ç³»ç»æ¥å£è·¯ç±é
ç½® æ³¨ææ°å妿以0å¼å¤´çè¯ï¼åå°ä¼åºç°è½¬ä¹ï¼è¯·æ·»å "" |
| | | igds: |
| | | default: |
| | | companyId: 5322 |
| | | sys-name: æºæ
§ç²®åºç®¡çç³»ç» |
| | | logo: logo-default.png |
| | | logo-title: logo-title-default.png |
| | | support: æºæ
§ç²®åºç»¼å管çå¹³å° |
| | | grian-add-point: N |
| | | file-path: D:/IGDS/FILE/ |
| | |
| | | <module>igds-protocol-fzzy3</module> |
| | | <!--馿µ·æºè½--> |
| | | <module>igds-protocol-bhzn</module> |
| | | <!--馿µ·æºè½--> |
| | | <module>igds-protocol-zldz</module> |
| | | <!--è´åç²®æ
åè®®--> |
| | | <module>igds-protocol-beibo</module> |
| | | <!--ç©èç½æå±è®¾å¤å
--> |
| | |
| | | <module>igds-api-phone</module> |
| | | <!-- æ¥å£å
ï¼å
æ¬ä¸ç»´æ¥å£ --> |
| | | <module>igds-api-inte</module> |
| | | |
| | | <!-- <module>igds-api-three</module>--> |
| | | |
| | | <!-- å¯è§å--> |
| | | <module>igds-databoard</module> |