| | |
| | | TCP_BHZH_VERB_V2("TCP_BHZH_VERB_V2", "馿µ·æ§å¶ææºè½æçº¿çV2"), |
| | | TCP_BHZH_INOUT_V1("TCP_BHZH_INOUT_V1", "馿µ·æºè½åºå
¥åºæ§å¶å¨åè®®"), |
| | | TCP_BEIBO_GRAIN_V1("TCP_BEIBO_GRAIN_V1", "è´åç²®æ
åæºæå¡ç«¯åè®®"), |
| | | TCP_ES_DLT645_V1("TCP_ES_DLT645_V1", "DL/T 645å¤åè½çµè¡¨åè®®"), |
| | | FZZY_OPENAPI_HTTP("FZZY_OPENAPI_HTTP", "飿£è´è¿API-HTTPåè®®"), |
| | | TCP_MODBUS("TCP_MODBUS", "Modbus-TCPåè®®"); |
| | | |
| | |
| | | |
| | | Date end = (Date) param.get("end"); |
| | | if(null != end){ |
| | | start = DateUtil.getNextZero(end); |
| | | end = DateUtil.getNextZero(end); |
| | | hql += " and updateTime <:end "; |
| | | args.put("end", end); |
| | | } |
| | |
| | | <Property name="property">deviceName</Property> |
| | | <Property name="align">center</Property> |
| | | </DataColumn> |
| | | <DataColumn name="updateTime"> |
| | | <Property name="property">updateTime</Property> |
| | | <Property name="align">center</Property> |
| | | <Property name="width">130</Property> |
| | | </DataColumn> |
| | | <ColumnGroup> |
| | | <Property name="caption">ä¸ç¸çµå</Property> |
| | | <DataColumn name="ua"> |
| | |
| | | <Property name="caption">Cç¸</Property> |
| | | </DataColumn> |
| | | </ColumnGroup> |
| | | <DataColumn name="f"> |
| | | <Property name="property">f</Property> |
| | | <Property name="align">center</Property> |
| | | <Property name="width">60</Property> |
| | | </DataColumn> |
| | | <ColumnGroup> |
| | | <Property name="caption">çµè½ï¼çµè¡¨å¼ï¼</Property> |
| | | <DataColumn name="ep"> |
| | | <Property name="property">ep</Property> |
| | | <Property name="caption">æå</Property> |
| | | <Property name="align">center</Property> |
| | | </DataColumn> |
| | | <DataColumn name="eq"> |
| | | <Property name="property">eq</Property> |
| | | <Property name="caption">æ å</Property> |
| | | <Property name="align">center</Property> |
| | | </DataColumn> |
| | | <DataColumn name="es"> |
| | |
| | | <Property name="caption">æ»çµè½</Property> |
| | | </DataColumn> |
| | | </ColumnGroup> |
| | | <DataColumn name="esInc"> |
| | | <Property name="property">esInc</Property> |
| | | <DataColumn name="updateTime"> |
| | | <Property name="property">updateTime</Property> |
| | | <Property name="align">center</Property> |
| | | <Property name="caption">å°æ¶ç¨è½</Property> |
| | | <Property name="width">150</Property> |
| | | </DataColumn> |
| | | </DataGrid> |
| | | </Container> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <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-es</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> |
| | | |
| | | <!-- å¼å
¥è½èå
--> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-es</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.es.dlt645; |
| | | |
| | | import com.ld.igds.constant.RedisConst; |
| | | import com.ld.igds.io.RemoteEsService; |
| | | import com.ld.igds.io.constant.OrderRespEnum; |
| | | import com.ld.igds.io.constant.ProtocolEnum; |
| | | import com.ld.igds.io.request.BaseRequest; |
| | | import com.ld.igds.io.response.BaseResponse; |
| | | import com.ld.igds.io.response.GrainResponse; |
| | | import com.ld.igds.protocol.es.dlt645.builder.CommandBuild; |
| | | import com.ld.igds.protocol.es.dlt645.client.Dlt645ClientEngine; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.RedisUtil; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * å½ååè®®å®ç°ï¼è½èåè®® |
| | | * |
| | | * @author czt |
| | | */ |
| | | @Slf4j |
| | | @Component(RemoteEsServiceImpl.BEAN_ID) |
| | | public class RemoteEsServiceImpl implements RemoteEsService { |
| | | |
| | | public static final String BEAN_ID = "dlt645.remoteEsServiceImpl"; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Override |
| | | public String getProtocol() { |
| | | return ProtocolEnum.TCP_ES_DLT645_V1.getCode(); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResponse checkEs(BaseRequest request) { |
| | | |
| | | try { |
| | | log.info("DL/T645å¤åè½çµè¡¨åæºå¼å§æ£æµï¼åæº{}çIP={},端å£={}",request.getSerId(),request.getIp(),request.getPort()); |
| | | |
| | | Dlt645ClientEngine clientEngine = new Dlt645ClientEngine(request.getIp(), request.getPort()); |
| | | clientEngine.start(); |
| | | Thread.sleep(1000); |
| | | |
| | | //ééå½ä»¤åå
¥ç¼åï¼è§£ææ¶å辨æ¯åªä¸ªä»çè½èï¼æ¶æ5åé |
| | | String key = RedisConst.buildKey(request.getCompanyId(), "ES-DLT645", request.getSerId()); |
| | | redisUtil.set(key, request.getDepotId(), 60*5); |
| | | |
| | | //çæå½ä»¤-æ¥è¯¢æ»çµè½çå½ä»¤ |
| | | String hexStr = CommandBuild.getInstance().getMsgCheck(request.getSerId()); |
| | | |
| | | InvokeResult result = clientEngine.send(BytesUtil.hexStrToBytes(hexStr)); |
| | | |
| | | log.info("result=" +result.getMessage()); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (InvokeResult.SUCCESS == result) { |
| | | return new GrainResponse(OrderRespEnum.ORDER_SUCCESS.getCode(), |
| | | "è½èå½ä»¤åéæåï¼"); |
| | | } else { |
| | | log.error("å¹³å°------>>>>è½èåæºï¼è½èæ£æµ-失败{}", result.getMessage()); |
| | | return new GrainResponse(OrderRespEnum.ORDER_ERROR.getCode(), |
| | | "å½ä»¤åéå¼å¸¸ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("è½èæ£æµå¼å¸¸ï¼{}", e); |
| | | return new BaseResponse(OrderRespEnum.ORDER_ERROR.getCode(), "å端å¼å¸¸ï¼" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.es.dlt645.analysis; |
| | | |
| | | import com.ld.igds.common.CoreSerService; |
| | | import com.ld.igds.constant.RedisConst; |
| | | import com.ld.igds.es.dto.EsData; |
| | | import com.ld.igds.es.service.CoreEsService; |
| | | import com.ld.igds.models.DeviceSer; |
| | | import com.ld.igds.protocol.es.dlt645.util.Dlt645Utils; |
| | | import com.ld.igds.util.ContextUtil; |
| | | 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.Date; |
| | | |
| | | /** |
| | | * DLT645çµè¡¨å议解æ |
| | | * |
| | | * @author czt |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisService.BEAN_ID) |
| | | public class AnalysisService { |
| | | |
| | | |
| | | public static final String BEAN_ID = "dlt645.analysisService"; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private CoreSerService coreSerService; |
| | | @Autowired |
| | | private CoreEsService esService; |
| | | |
| | | /** |
| | | * |
| | | * @param result |
| | | */ |
| | | public void analysis(String result){ |
| | | log.info("è½èåæº------->>å¹³å°ï¼ä¿¡æ¯æ¥æ={}", result); |
| | | if(!result.startsWith(Dlt645Utils.MSG_START)){ |
| | | log.error("è½èåæº------->>å¹³å°ï¼è§£æè½èå¤±è´¥ï¼æ¥æèµ·å§ç¬¦é误ï¼ä¸è§£æ"); |
| | | return; |
| | | } |
| | | //å»é¤èµ·å§ç¬¦ |
| | | result = result.substring(8); |
| | | //è·åæ ¡éªä½ |
| | | String oldCheck = result.substring(result.length() - 4, result.length() - 2); |
| | | String check = Dlt645Utils.makeCheck(result.substring(0, result.length() - 4)); |
| | | |
| | | if(!check.equals(oldCheck)){ |
| | | log.error("è½èåæº------->>å¹³å°ï¼è§£æè½èå¤±è´¥ï¼æ ¡éªä½ä¸å¯¹ï¼ä¸è§£æ"); |
| | | return; |
| | | } |
| | | analysisGrain(result); |
| | | } |
| | | |
| | | |
| | | private void analysisGrain(String result) { |
| | | try { |
| | | |
| | | //è·åè½èåæºå°å |
| | | String serId = Dlt645Utils.addrToString(result.substring(2, 14)); |
| | | |
| | | //æ ¹æ®åæºå°åè·ååæºä¿¡æ¯ |
| | | DeviceSer ser = coreSerService.getCacheSer(ContextUtil.getDefaultCompanyId(), serId); |
| | | if (ser == null) { |
| | | log.error("è½èåæº-------->>å¹³å°ï¼è§£æè½èå¤±è´¥ï¼æªè·åå°ç³»ç»è½è主æºé
ç½®ï¼" + serId); |
| | | return; |
| | | } |
| | | |
| | | String key = RedisConst.buildKey(ser.getCompanyId(), "ES-DLT645", ser.getId()); |
| | | String depotId = (String) redisUtil.get(key); |
| | | if(null == depotId){ |
| | | log.error("è½èåæº-------->>å¹³å°ï¼è§£æè½èå¤±è´¥ï¼æªè·åå°ä»åºä¿¡æ¯ï¼" + depotId); |
| | | return; |
| | | } |
| | | |
| | | //è§£ææ»è½èæ°æ® |
| | | String dataStr = result.substring(28, 36); |
| | | |
| | | Double esNum = Dlt645Utils.parseData(dataStr); |
| | | EsData esData = new EsData(); |
| | | esData.setDeviceName("çµè¡¨"); |
| | | esData.setCompanyId(ser.getCompanyId()); |
| | | esData.setDepotId(depotId); |
| | | esData.setUpdateTime(new Date()); |
| | | |
| | | esData.setEp(esNum); |
| | | esData.setEs(esNum); |
| | | |
| | | log.info("DLT645çµè¡¨----->>>å¹³å°ï¼è½èæ°æ®è§£æå®æ-ä»åº={}", esData.getDepotId()); |
| | | esService.saveAndUpdateInc(esData); |
| | | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.es.dlt645.builder; |
| | | |
| | | import com.ld.igds.protocol.es.dlt645.util.Dlt645Utils; |
| | | |
| | | /** |
| | | * çµè¡¨å½ä»¤çæ |
| | | * |
| | | * @author czt |
| | | */ |
| | | public class CommandBuild { |
| | | |
| | | private final static CommandBuild instance = new CommandBuild(); |
| | | |
| | | private CommandBuild() { |
| | | } |
| | | |
| | | public static CommandBuild getInstance() { |
| | | return instance; |
| | | } |
| | | |
| | | /** |
| | | * è½èééå½ä»¤ |
| | | * |
| | | * @param esAddr çµè¡¨å°å |
| | | * @return |
| | | */ |
| | | public static String getMsgCheck(String esAddr) { |
| | | |
| | | //è·åå½ä»¤ |
| | | StringBuffer sb = new StringBuffer(); |
| | | |
| | | //帧起å§ç¬¦ |
| | | sb.append("68"); |
| | | //å°ååï¼ååæ¼æ¥ |
| | | sb.append(Dlt645Utils.addrToString(esAddr)); |
| | | //帧起å§ç¬¦ |
| | | sb.append("68"); |
| | | //æ§å¶ç å |
| | | sb.append("11"); |
| | | //æ°æ®åé¿åº¦ |
| | | sb.append("04"); |
| | | //æ°æ®å |
| | | sb.append("33333433"); |
| | | //æ ¡éªç |
| | | String checkNum = Dlt645Utils.makeCheck(sb.toString()); |
| | | sb.append(checkNum); |
| | | |
| | | StringBuffer sb0 = new StringBuffer(); |
| | | //èµ·å§ç¬¦ |
| | | sb0.append(Dlt645Utils.MSG_START); |
| | | sb0.append(sb); |
| | | //ç»å°¾ç¬¦ |
| | | sb0.append(Dlt645Utils.MSG_END); |
| | | |
| | | return sb0.toString(); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.es.dlt645.client; |
| | | |
| | | import com.ld.igds.protocol.es.dlt645.analysis.AnalysisService; |
| | | import com.ld.igds.util.BytesUtil; |
| | | import com.ld.igds.util.SpringUtil; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.channel.SimpleChannelInboundHandler; |
| | | import io.netty.util.internal.logging.InternalLogger; |
| | | import io.netty.util.internal.logging.InternalLoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | import java.net.InetSocketAddress; |
| | | |
| | | |
| | | /** |
| | | * Handles a client-side channel. |
| | | */ |
| | | public class ClientHandler extends SimpleChannelInboundHandler<Object> { |
| | | |
| | | |
| | | private AnalysisService analysisService; |
| | | |
| | | private final InternalLogger log = InternalLoggerFactory.getInstance(this.getClass()); |
| | | @Override |
| | | public void channelActive(ChannelHandlerContext ctx) { |
| | | InetSocketAddress insocket = (InetSocketAddress) ctx.channel() |
| | | .remoteAddress(); |
| | | log.info("çµè¡¨æå¡å¨æåè¿æ¥ï¼IP={},port={}", insocket.getAddress() |
| | | .getHostAddress(), insocket.getPort()); |
| | | } |
| | | |
| | | @Override |
| | | public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
| | | super.channelInactive(ctx); |
| | | |
| | | InetSocketAddress insocket = (InetSocketAddress) ctx.channel() |
| | | .remoteAddress(); |
| | | |
| | | log.info("çµè¡¨æå¡å¨æå¼è¿æ¥ï¼IP={},port={}", insocket.getAddress(),insocket.getPort()); |
| | | } |
| | | |
| | | @Override |
| | | public void channelRead0(ChannelHandlerContext ctx, Object msg) |
| | | throws Exception { |
| | | byte[] bytes = (byte[]) msg; |
| | | String result = BytesUtil.bytesToString(bytes); |
| | | log.info("çµè¡¨æå¡å¨åæºè¿åä¿¡æ¯=" + result); |
| | | |
| | | // InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | |
| | | //è§£æ |
| | | //è°ç¨è§£ææ¥å£å¼å§è§£æ |
| | | if (null == analysisService) { |
| | | analysisService = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); |
| | | } |
| | | analysisService.analysis(result); |
| | | } |
| | | |
| | | @Override |
| | | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { |
| | | ctx.close(); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.es.dlt645.client; |
| | | |
| | | import com.ld.io.api.InvokeResult; |
| | | import io.netty.bootstrap.Bootstrap; |
| | | import io.netty.buffer.Unpooled; |
| | | import io.netty.channel.*; |
| | | import io.netty.channel.oio.OioEventLoopGroup; |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.channel.socket.oio.OioSocketChannel; |
| | | import io.netty.handler.codec.bytes.ByteArrayDecoder; |
| | | import io.netty.handler.codec.bytes.ByteArrayEncoder; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * DL/T 645-2007å¤åè½çµè¡¨ |
| | | * |
| | | * @author czt |
| | | */ |
| | | @Slf4j |
| | | public class Dlt645ClientEngine implements Runnable { |
| | | |
| | | private String host; |
| | | private int port; |
| | | |
| | | public Channel channel; |
| | | |
| | | public Dlt645ClientEngine(String host, int port) { |
| | | this.host = host; |
| | | this.port = port; |
| | | } |
| | | public void start() { |
| | | Thread thread = new Thread(this); |
| | | thread.start(); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | startRun(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public void startRun() throws Exception { |
| | | EventLoopGroup group = new OioEventLoopGroup(); |
| | | Bootstrap b = new Bootstrap(); |
| | | // b.option(ChannelOption.SO_KEEPALIVE, true); |
| | | b.group(group).channel(OioSocketChannel.class) |
| | | .handler(new ChannelInitializer<SocketChannel>() { |
| | | @Override |
| | | protected void initChannel(SocketChannel ch) |
| | | throws Exception { |
| | | ChannelPipeline p = ch.pipeline(); |
| | | // å符串解ç å ç¼ç |
| | | p.addLast("decoder", new ByteArrayDecoder()); |
| | | p.addLast("encoder", new ByteArrayEncoder()); |
| | | // èªå·±çé»è¾Handler |
| | | p.addLast("handler", new ClientHandler()); |
| | | } |
| | | }); |
| | | |
| | | // åèµ·å¼æ¥è¿æ¥è¯·æ±ï¼ç»å®è¿æ¥ç«¯å£åhostä¿¡æ¯ |
| | | ChannelFuture channelFuture = b.connect(host, port); |
| | | this.channel = channelFuture.channel(); |
| | | // channelFuture.channel().closeFuture().sync(); |
| | | |
| | | channelFuture.addListener(new ChannelFutureListener() { |
| | | @Override |
| | | public void operationComplete(ChannelFuture arg0) throws Exception { |
| | | if (channelFuture.isSuccess()) { |
| | | log.info("-----è¿æ¥çµè¡¨æå¡å¨æåï¼IP={}ï¼PORT={}", host, port); |
| | | } else { |
| | | log.info("-----è¿æ¥çµè¡¨æå¡å¨å¤±è´¥ï¼IP={}ï¼PORT={}", host, port); |
| | | channelFuture.cause().printStackTrace(); |
| | | group.shutdownGracefully(); // å
³é线ç¨ç» |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public InvokeResult send(byte[] array) throws InterruptedException { |
| | | if (null == channel) { |
| | | return InvokeResult.SOCKET_NOT_CREATE; |
| | | } |
| | | if (!channel.isActive()) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | channel.writeAndFlush(Unpooled.copiedBuffer(array)).sync(); |
| | | |
| | | return InvokeResult.SUCCESS; |
| | | } |
| | | |
| | | public Channel getChannel() { |
| | | return channel; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | |
| | | |
| | | /** |
| | | * @Desc: DL/T 645å¤åè½çµè¡¨ |
| | | * @author: czt |
| | | */ |
| | | package com.ld.igds.protocol.bhzn; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ld.igds.protocol.es.dlt645.util; |
| | | |
| | | /** |
| | | * å·¥å
·ç±» |
| | | * |
| | | * @author czt |
| | | */ |
| | | public class Dlt645Utils { |
| | | |
| | | |
| | | public static String MSG_START = "FEFEFEFE"; //èµ·å§ç¬¦ |
| | | public static String MSG_END = "16"; //ç»å°¾ç¬¦ |
| | | |
| | | public static void main(String[] args) { |
| | | String s = makeCheck("6857141222000068110433333433"); |
| | | System.out.println(s); |
| | | } |
| | | |
| | | /** |
| | | * å°6个åèçå°ååï¼æ¯åè2ä½ BCDç ,转æ¢ä¸º12ä½10è¿å¶æ° |
| | | */ |
| | | public static String addrToString(String str) { |
| | | byte[] bytes = stringToBytes(str); |
| | | return String.format("%02x%02x%02x%02x%02x%02x", bytes[5], bytes[4], bytes[3], bytes[2], bytes[1], bytes[0]); |
| | | } |
| | | |
| | | /** |
| | | * DLT645æ ¡éªç |
| | | */ |
| | | public static String makeCheck(String data) { |
| | | |
| | | if (data == null || data.equals("")) { |
| | | return ""; |
| | | } |
| | | int total = 0; |
| | | int len = data.length(); |
| | | int num = 0; |
| | | while (num < len) { |
| | | String s = data.substring(num, num + 2); |
| | | total += Integer.parseInt(s, 16); |
| | | num = num + 2; |
| | | } |
| | | /** |
| | | * ç¨256æ±ä½æå¤§æ¯255ï¼å³16è¿å¶çFF |
| | | */ |
| | | int mod = total % 256; |
| | | String hex = Integer.toHexString(mod); |
| | | len = hex.length(); |
| | | // 妿ä¸å¤æ ¡éªä½çé¿åº¦ï¼è¡¥0,è¿éç¨çæ¯ä¸¤ä½æ ¡éª |
| | | if (len < 2) { |
| | | hex = "0" + hex; |
| | | } |
| | | return hex.toUpperCase(); |
| | | } |
| | | |
| | | /** |
| | | * å°Stringç±»åè½¬æ¢æbyteæ°ç» |
| | | */ |
| | | public static byte[] stringToBytes(String str) { |
| | | if (str == null || str.equals("")) { |
| | | return null; |
| | | } |
| | | byte[] bytes = new byte[str.length() / 2]; |
| | | for (int i = 0; i < bytes.length; i++) { |
| | | String subStr = str.substring(i * 2, i * 2 + 2); |
| | | bytes[i] = (byte) Integer.parseInt(subStr, 16); |
| | | } |
| | | return bytes; |
| | | } |
| | | |
| | | /** |
| | | * è§£æè¿åçå
·ä½æ°æ® |
| | | */ |
| | | public static Double parseData(String dataStr) { |
| | | byte[] data = stringToBytes(dataStr); |
| | | // æ¯ä¸ªåè-33Hå¤ç |
| | | for (int i = 0; i < data.length; i++) { |
| | | data[i] = (byte) (data[i] - 0x33); |
| | | } |
| | | StringBuilder str = new StringBuilder(); |
| | | // BCDç è½¬æ¢æ10è¿å¶ |
| | | for (byte b : data) { |
| | | str.insert(0, String.format("%02x", b)); |
| | | } |
| | | return Double.parseDouble(str.toString()) * 0.01; |
| | | } |
| | | |
| | | } |
| | |
| | | </exclusions> |
| | | </dependency>--> |
| | | |
| | | <!-- ç§æåè®®-DLT645çµè¡¨åè®®--> |
| | | <dependency> |
| | | <groupId>com.ld.igds</groupId> |
| | | <artifactId>igds-protocol-es</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> |
| | |
| | | <module>igds-protocol-zldz</module> |
| | | <!--è´åç²®æ
åè®®--> |
| | | <module>igds-protocol-beibo</module> |
| | | <!--çµè¡¨--> |
| | | <module>igds-protocol-es</module> |
| | | <!--ç©èç½æå±è®¾å¤å
--> |
| | | <module>igds-protocol-iot</module> |
| | | |
| | |
| | | <!--modbus-tcp--> |
| | | <module>igds-protocol-modbus</module> |
| | | |
| | | |
| | | <!-- ææºå
--> |
| | | <module>igds-api-phone</module> |
| | | <!-- æ¥å£å
ï¼å
æ¬ä¸ç»´æ¥å£ --> |