已重命名1个文件
已删除1个文件
已修改13个文件
已添加24个文件
| | |
| | | |
| | | private Integer port; |
| | | |
| | | private String orgId; |
| | | |
| | | //ç¶ææ¯å¦å¨çº¿ |
| | | private String status = Constant.YN_Y; |
| | | |
| | |
| | | |
| | | TCP_FZZY_V3("TCP_FZZY_V3", "ç²®æ
-飿£è´è¿æ§å¶æåè®®V3"), |
| | | GRAIN_FZZY_IGDS_V40("GRAIN_FZZY_IGDS_V40", "ç²®æ
-飿£è´è¿ç³»ç»V40"), |
| | | GRAIN_FZZY_BHZN_WEB("GRAIN_FZZY_BHZN_WEB", "ç²®æ
-飿£è´è¿é¦æµ·ç½å£åè®®"), |
| | | GRAIN_FZZY_BHZN_WEB("GRAIN_FZZY_BHZN_WEB", "ç²®æ
-FZZY-馿µ·æºè½ç½å£åè®®"), |
| | | GRAIN_FZZY_ZLDZ_WEB("GRAIN_FZZY_ZLDZ_WEB", "ç²®æ
-FZZY-æ£æ¥çµåç½å£åè®®"), |
| | | DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "å°ç£
-HTTPåè®®"), |
| | | DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "å°ç£
-èåTCPåè®®"), |
| | | DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "身份è¯-HTTPåè®®"), |
| | |
| | | list.add(new ApiTrigger(TCP_FZZY_V3.getCode(), TCP_FZZY_V3.getName())); |
| | | list.add(new ApiTrigger(GRAIN_FZZY_IGDS_V40.getCode(), GRAIN_FZZY_IGDS_V40.getName())); |
| | | list.add(new ApiTrigger(GRAIN_FZZY_BHZN_WEB.getCode(), GRAIN_FZZY_BHZN_WEB.getName())); |
| | | list.add(new ApiTrigger(GRAIN_FZZY_ZLDZ_WEB.getCode(), GRAIN_FZZY_ZLDZ_WEB.getName())); |
| | | list.add(new ApiTrigger(DEVICE_WEIGHT_HTTP.getCode(), DEVICE_WEIGHT_HTTP.getName())); |
| | | list.add(new ApiTrigger(DEVICE_WEIGHT_TCP_YH.getCode(), DEVICE_WEIGHT_TCP_YH.getName())); |
| | | list.add(new ApiTrigger(DEVICE_IDCARD_HTTP.getCode(), DEVICE_IDCARD_HTTP.getName())); |
| | |
| | | } |
| | | return biannary2Decimal(two) + 1; |
| | | } |
| | | |
| | | public static String byteToHex(byte b) { |
| | | String hex = Integer.toHexString(b & 0xFF); |
| | | if (hex.length() < 2) { |
| | | hex = "0" + hex; |
| | | } |
| | | return hex; |
| | | } |
| | | } |
| | |
| | | import com.fzzy.api.Constant; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateUtils; |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | public static String buildDeviceStatusKey(String companyId, String serId, int passCode) { |
| | | return companyId + "_" + serId + "_STATUS_" + passCode; |
| | | } |
| | | |
| | | |
| | | public static String getDefaultBatchId() { |
| | | return DateFormatUtils.format(new Date(), "yyyyMMddHHmm"); |
| | | } |
| | | } |
| | |
| | | @PropertyDef(label = "ä½ç½®") |
| | | private String position; |
| | | |
| | | @Column(name = "REMARK_", length = 200) |
| | | @PropertyDef(label = "夿³¨", description = "夿³¨ä¿¡æ¯") |
| | | private String remark; |
| | | |
| | | |
| | | @Column(name = "CABLE_RULE_", length = 20) |
| | | @PropertyDef(label = "å¸çº¿è§å", description = "å¹³æ¹ä»è¡¨ç¤ºå±è¡åï¼çä»è¡¨ç¤ºæ¯åçåæ°") |
| | |
| | | @PropertyDef(label = "å¨çº¿ç¶æ") |
| | | private String status = Constant.YN_Y; |
| | | |
| | | @Column(name = "CABLE_START_") |
| | | @PropertyDef(label = "çµç¼å¼å§") |
| | | private int cableStart; |
| | | |
| | | @Column(name = "CABLE_END_") |
| | | @PropertyDef(label = "çµç¼æªè³") |
| | | private int cableEnd; |
| | | |
| | | @Column(name = "TH_ADDR_") |
| | | @PropertyDef(label = "温湿度å°å") |
| | | private String thAddr; |
| | | |
| | | @Column(name = "CABLE_FORMAT", length = 4) |
| | | @PropertyDef(label = "çµç¼å¶å¼") |
| | | private String cableFormat; |
| | | |
| | | @Column(name = "CABLE_TYPE", length = 4) |
| | | @PropertyDef(label = "çµç¼ç±»å") |
| | | private String cableType; |
| | | |
| | | @Transient |
| | | @PropertyDef(label = "设å¤ä¸çº¿æ¶é´") |
| | | private Date onlineTime; |
| | | |
| | | @Column(name = "REMARK_", length = 200) |
| | | @PropertyDef(label = "夿³¨", description = "夿³¨ä¿¡æ¯") |
| | | private String remark; |
| | | |
| | | } |
| | |
| | | flushCache(); |
| | | } |
| | | |
| | | public void updateData(GatewayDevice device) { |
| | | device.setStatus(Constant.YN_Y); |
| | | |
| | | gatewayDeviceRep.save(device); |
| | | |
| | | flushCacheOne(device); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * gatewayDeviceService#delData |
| | | * |
| | |
| | | for (GatewayDevice device : list) { |
| | | GatewayUtils.add2Cache(device); |
| | | } |
| | | } |
| | | |
| | | private void flushCacheOne(GatewayDevice device) { |
| | | GatewayUtils.add2Cache(device); |
| | | } |
| | | |
| | | |
| | |
| | | GatewayUtils.add2Cache(device); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol; |
| | | |
| | | |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.protocol.data.THDto; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * å议解æå
¨å±å¸¸é |
| | | */ |
| | | public class ProtocolUtils { |
| | | |
| | | /** |
| | | * 请æ±ç¼å key = deviceId,value = requData |
| | | */ |
| | | private static Map<String, BaseReqData> contextSyncReqMap = new HashMap<>(); |
| | | |
| | | /** |
| | | * 请æ±ç¼å key = deviceId,value = thDto |
| | | */ |
| | | private static Map<String, THDto> contextThMap = new HashMap<>(); |
| | | |
| | | |
| | | //-粮温å¤ç¨ç¹ |
| | | public static final double ERROR_TEMP = -100; |
| | | //-粮温æ
éç¹ |
| | | public static final double FAULT_TEMP = -101; |
| | | //-粮温补å¿ç¹-é对é¥å½¢ä»è¡¥ç¹ä½¿ç¨ |
| | | public static final double ADD_TEMP = -102; |
| | | |
| | | |
| | | /** |
| | | * å°æ§è¡å½ä»¤ä¿¡æ¯åæ¾å¨ç¼å |
| | | * |
| | | * @param depotId ä»åºç¼ç |
| | | * @param reqData 请æ±åæ°ä¿¡æ¯ |
| | | */ |
| | | public static void addSyncReq2Map(String depotId, BaseReqData reqData) { |
| | | contextSyncReqMap.put(depotId, reqData); |
| | | } |
| | | |
| | | public static BaseReqData getSyncReq(String depotId) { |
| | | return contextSyncReqMap.get(depotId); |
| | | } |
| | | |
| | | public static void addTh2Map(String deviceId, THDto thDto) { |
| | | contextThMap.put(deviceId, thDto); |
| | | } |
| | | |
| | | public static THDto getCacheTh(String deviceId) { |
| | | return contextThMap.get(deviceId); |
| | | } |
| | | } |
| | |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.protocol.ConstantProtocol; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.bhzn.cmd.CommandBuild; |
| | | import com.fzzy.protocol.bhzn.cmd.ReMessageBuilder; |
| | | import com.fzzy.protocol.bhzn.data.IoMessage; |
| | | import com.fzzy.protocol.bhzn.data.THDto; |
| | | import com.fzzy.protocol.data.THDto; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; |
| | | import com.fzzy.protocol.fzzy.server.ServerUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | } |
| | | |
| | | //è·å请æ±ä¿¡æ¯ |
| | | BaseReqData reqData = BhznGrainV2ServerUtils.getSyncReq(gatewayDevice.getDepotIdSys()); |
| | | BaseReqData reqData = ProtocolUtils.getSyncReq(gatewayDevice.getDepotIdSys()); |
| | | if (null == reqData) { |
| | | replayGrain(message); |
| | | log.error("主æº-------->>å¹³å°ï¼è§£æç²®æ
å¤±è´¥ï¼æªè·åå°ç²®æ
请æ±ä¿¡æ¯ï¼" + message.getAddr()); |
| | |
| | | temp = "0000"; |
| | | } |
| | | if (ReMessageBuilder.ERROR_TAG.equals(temp)) { |
| | | tempValue = ConstantProtocol.ERROR_TEMP; |
| | | tempValue = ProtocolUtils.ERROR_TEMP; |
| | | } else { |
| | | tempValue = BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) / 10.0; |
| | | } |
| | | // æ
éå¼å¤ç |
| | | if (tempValue >= ReMessageBuilder.FAULT_CHECK_TAG) { |
| | | tempValue = ConstantProtocol.FAULT_TEMP; |
| | | tempValue = ProtocolUtils.FAULT_TEMP; |
| | | } |
| | | temps.add(tempValue); |
| | | } |
| | |
| | | @Service |
| | | public class BhznGrainV2ServerEngine { |
| | | |
| | | public static final Integer PORT = 19309; |
| | | public static final Integer PORT = 19301; |
| | | |
| | | public static NettyServer ioServer = null; |
| | | |
| | |
| | | */ |
| | | public static Map<String, Long> contextMapHeart = new HashMap<>(); |
| | | |
| | | /** |
| | | * 请æ±ç¼å key = deviceId,value = requData |
| | | */ |
| | | private static Map<String, BaseReqData> contextSyncReqMap = new HashMap<>(); |
| | | |
| | | |
| | | |
| | |
| | | public static String FUNCTION_ID_83 = "83"; |
| | | public static String FUNCTION_ID_93 = "93"; |
| | | public static String FUNCTION_ID_92 = "92"; |
| | | |
| | | |
| | | /** |
| | | * å°æ§è¡å½ä»¤ä¿¡æ¯åæ¾å¨ç¼å |
| | | * |
| | | * @param depotId ä»åºç¼ç |
| | | * @param reqData 请æ±åæ°ä¿¡æ¯ |
| | | */ |
| | | public static void addSyncReq2Map(String depotId, BaseReqData reqData) { |
| | | contextSyncReqMap.put(depotId, reqData); |
| | | } |
| | | |
| | | public static BaseReqData getSyncReq(String depotId) { |
| | | return contextSyncReqMap.get(depotId); |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.bhzn.cmd.CommandBuild; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 飿£è´è¿æ§å¶æåè®® |
| | | * 馿µ·æºè½ç²®æ
åè®®-ç½å£è®¾å¤ |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | |
| | | |
| | | try { |
| | | //Step 请æ±ä¿¡æ¯æ¾å
¥å
å |
| | | BhznGrainV2ServerUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); |
| | | ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); |
| | | |
| | | // çæç²®æ
ä¿¡æ¯ |
| | | String hexStr = CommandBuild.getInstance().getMsgCheck(device.getDeviceSn(), device.getDepotIdSys()); |
ÎļþÃû´Ó src/main/java/com/fzzy/protocol/bhzn/data/THDto.java ÐÞ¸Ä |
| | |
| | | package com.fzzy.protocol.bhzn.data; |
| | | package com.fzzy.protocol.data; |
| | | |
| | | import com.bstek.dorado.annotation.PropertyDef; |
| | | import lombok.Data; |
| | |
| | | |
| | | private String serId;//æå±åæº |
| | | |
| | | private String thConf = "1";//æå±éé |
| | | private String thAddr = "1";//æå±éé |
| | | |
| | | @PropertyDef(label = "æå±ä»åº", description = "ä»åºç¼å·") |
| | | private String depotId; |
| | |
| | | @PropertyDef(label = "ä»å
湿度", description = "åä½%RH") |
| | | private Double humidityIn; |
| | | |
| | | @PropertyDef(label = "æ¥æ¶æ¶é´", description = "") |
| | | @PropertyDef(label = "æ¥æ¶æ¶é´") |
| | | private Date receiveDate = new Date(); |
| | | |
| | | private String remark; |
| | |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.fzzy.builder.SimpleCommandBuilder; |
| | | import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; |
| | | import com.fzzy.protocol.fzzy.data.ReMessage; |
| | |
| | | private void buildBizInfo1(Response2102 response) { |
| | | |
| | | //è·å请æ±ä¿¡æ¯ |
| | | BaseReqData reqData = ServerUtils.getSyncReq(response.getHouseId()); |
| | | BaseReqData reqData = ProtocolUtils.getSyncReq(response.getHouseId()); |
| | | |
| | | if (null == reqData) { |
| | | log.error("--ç²®æ
å°è£
è§£æï¼æªè·åå°è¯·æ±ç¸å
³åæ°----"); |
| | |
| | | |
| | | private static Map<String, Integer> contextOrder = new HashMap<>(); |
| | | |
| | | /** |
| | | * 请æ±ç¼å key = deviceId,value = requData |
| | | */ |
| | | private static Map<String, BaseReqData> contextSyncReqMap = new HashMap<>(); |
| | | |
| | | /** |
| | | * å°æ§è¡å½ä»¤ä¿¡æ¯åæ¾å¨ç¼å |
| | | * |
| | | * @param depotId ä»åºç¼ç |
| | | * @param reqData 请æ±åæ°ä¿¡æ¯ |
| | | */ |
| | | public static void addSyncReq2Map(String depotId, BaseReqData reqData) { |
| | | contextSyncReqMap.put(depotId, reqData); |
| | | } |
| | | |
| | | public static BaseReqData getSyncReq(String depotId) { |
| | | return contextSyncReqMap.get(depotId); |
| | | } |
| | | |
| | | |
| | | public static final String MSG_BEGIN = "<FZZY>"; |
| | | public static final String MSG_END = "<END>"; |
| | |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.fzzy.builder.GrainCommandBuilder; |
| | | import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl; |
| | | import com.fzzy.protocol.fzzy.data.SendMessage; |
| | |
| | | try { |
| | | |
| | | //Step 请æ±ä¿¡æ¯æ¾å
¥å
å |
| | | ServerUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); |
| | | ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); |
| | | |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | SendMessage message = GrainCommandBuilder.getInstance().buildMessage(device,apiCommonDevice); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.analysis; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.service.GatewayDeviceService; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * @author vince |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisConf.BEAN_ID) |
| | | public class AnalysisConf { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisConf"; |
| | | |
| | | @Resource |
| | | private GatewayDeviceService gatewayDeviceService; |
| | | |
| | | /** |
| | | * è§£æåæºé
ç½®ä¿¡æ¯ |
| | | * |
| | | * @param message |
| | | * @param ser |
| | | */ |
| | | public void analysis8816(ReMessage message, GatewayDevice ser) { |
| | | |
| | | log.debug("åæº---->>>å¹³å°ï¼æ¶æ¯ç±»å=8816-----{}", ser.getDeviceName()); |
| | | |
| | | 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); |
| | | |
| | | // 屿° |
| | | String cable = ""; |
| | | start = 6; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | cable += BytesUtil.hexToInt(temp); |
| | | |
| | | // è¡æ° |
| | | start = 7; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | cable += "-" + BytesUtil.hexToInt(temp); |
| | | |
| | | // åæ° |
| | | start = 8; |
| | | len = 1; |
| | | temp = content.substring(start * 2, start * 2 + len * 2); |
| | | cable += "-" + BytesUtil.hexToInt(temp); |
| | | |
| | | //å± - è¡ - å é
ç½® |
| | | ser.setCableRule(cable); |
| | | |
| | | // çµç¼å¶å¼ |
| | | 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.getDeviceName() + " è¿ç¨è·åé
ç½®æåï¼è¯·å·æ°æ°æ®æ¥çï¼"; |
| | | |
| | | // ç»ç»ç¼ç |
| | | start = 12; |
| | | temp = content.substring(start * 2); |
| | | if (readTag == 1) {// 表示åçæåè¿å |
| | | ser.setOrgId(ser.getOrgId()); |
| | | msg = ser.getDeviceName() + " è¿ç¨åå
¥æåï¼è¯·å·æ°æ°æ®æ¥çï¼"; |
| | | } else { |
| | | ser.setOrgId(BytesUtil.hexToInt(BytesUtil.tran_LH(temp)) + ""); |
| | | } |
| | | |
| | | if (null == ser.getDeviceSn()) { |
| | | ser.setDeviceSn(ser.getId()); |
| | | } |
| | | ser.setIp(message.getIp()); |
| | | ser.setPort(message.getPort()); |
| | | |
| | | // å¼å§åé»è®¤=1 |
| | | if (ser.getCableStart() == 0) { |
| | | ser.setCableStart(1); |
| | | } |
| | | |
| | | log.info("åæº---->>>å¹³å°ï¼åæºé
置解æå®æ---{}ï¼æ´æ°å°ææå¡å¨", |
| | | ser.getDeviceName()); |
| | | |
| | | //æ´æ°è®¾å¤ä¿¡æ¯ |
| | | gatewayDeviceService.updateData(ser); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼åå§åæå |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8822(ReMessage reMessage, GatewayDevice ser) { |
| | | log.info("--------çµç¼åå§åæå------------{}", ser.getDeviceName()); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼ä¿®æ¹è¿åï¼ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8826(ReMessage reMessage, GatewayDevice ser) { |
| | | log.info("--------ä¿®æ¹çµç¼ä¿¡æ¯è¿å------------{}", ser.getDeviceName()); |
| | | } |
| | | |
| | | /** |
| | | * ééçµç¼è·åè¿åï¼åæºè¿åæ¶å°å½ä»¤ä¿¡æ¯ï¼å®é
è¿åå¼å¨8829ä¸è¯´æ |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8825(ReMessage reMessage, GatewayDevice ser) { |
| | | log.info("--------ééçµç¼è·åè¿å------------{}", ser.getDeviceName()); |
| | | } |
| | | |
| | | /** |
| | | * ç»ç«¯åéééçµç¼æ°æ®ç»åå°ï¼åæºä¸»å¨æ¨é |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | @SuppressWarnings("unchecked") |
| | | public void analysis1129(ReMessage reMessage, GatewayDevice ser) { |
| | | log.info("--------ç»ç«¯åéééçµç¼æ°æ®ç»åå°------------{}", ser.getDeviceName()); |
| | | } |
| | | |
| | | /** |
| | | * çµç¼æ±æ»åºç |
| | | * |
| | | * @param reMessage |
| | | * @param ser |
| | | */ |
| | | public void analysis8823(ReMessage reMessage, GatewayDevice ser) { |
| | | // å¼å§è§£æ |
| | | String content = reMessage.getBody().getContent(); |
| | | |
| | | //DO NOTHING |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.analysis; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import com.fzzy.protocol.zldz.service.ZldzGatewayGrainService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | 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"; |
| | | |
| | | @Resource |
| | | private ZldzGatewayGrainService zldzGatewayGrainService; |
| | | |
| | | 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 device |
| | | */ |
| | | public void analysis8815(ReMessage reMessage, GatewayDevice device) { |
| | | BaseRequest request = new BaseRequest(); |
| | | request.setSerId(device.getId()); |
| | | request.setCompanyId(device.getOrgId()); |
| | | request.setIp(reMessage.getIp()); |
| | | request.setPort(reMessage.getPort()); |
| | | request.setSerName(device.getDeviceName()); |
| | | |
| | | zldzGatewayGrainService.reply8815(request); |
| | | } |
| | | |
| | | /** |
| | | * æ¥æ¶å°ç²®æ
çåå¤ |
| | | * |
| | | * @param reMessage |
| | | * @param device |
| | | */ |
| | | public void reply8817(ReMessage reMessage, GatewayDevice device) { |
| | | String bodyMsg = reMessage.getBody().getContent(); |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼æ¶å°çç²®æ
ä¿¡æ¯-{}-{}", |
| | | device.getDeviceName(), 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(device.getDeviceSn()); |
| | | request.setCompanyId(device.getOrgId()); |
| | | request.setIp(reMessage.getIp()); |
| | | request.setPort(reMessage.getPort()); |
| | | request.setSerName(device.getDeviceName()); |
| | | |
| | | zldzGatewayGrainService.reply8817(request, hexCurPacket); |
| | | } |
| | | |
| | | |
| | | public void analysis8817(ReMessage msg, GatewayDevice device) { |
| | | // æ¥å°ä¿¡æ¯åå¤--ä¸»æº |
| | | reply8817(msg, device); |
| | | |
| | | |
| | | BaseReqData reqData = ProtocolUtils.getSyncReq(device.getDepotIdSys()); |
| | | |
| | | if (null == reqData) { |
| | | log.warn("---------没æè·åå°å½åä»åºç请æ±ï¼ä¸æ§è¡è§£æ-----{}", device.getDeviceName()); |
| | | return; |
| | | } |
| | | |
| | | analysisStep(msg, device, reqData); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * å¼å§è§£æ |
| | | * |
| | | * @param device |
| | | * @param msg |
| | | * @throws Exception |
| | | */ |
| | | private void analysisStep(ReMessage msg, GatewayDevice device, BaseReqData reqData) { |
| | | // ç²®æ
çæ¹æ¬¡å·éæ°æ ¹æ®é¢çè°æ´ |
| | | msg.setBatchId(ContextUtil.getDefaultBatchId()); |
| | | |
| | | String bodyMsg = msg.getBody().getContent(); |
| | | |
| | | log.debug("{}=æ¶å°çç²®æ
ä¿¡æ¯={}", device.getDeviceName(), |
| | | 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("åæº={},å
æ»æ°={},å½åå
={}", device.getDeviceName(), sumPacket, curPacket); |
| | | |
| | | // ç²®é£æ¸©åº¦ä¿¡æ¯ |
| | | String grainStr = bodyMsg.substring(3 * 2); |
| | | |
| | | String contextKey = this.buildContextKey(msg, device.getDepotIdSys()); |
| | | 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(msg, device, reqData, contextKey, sumPacket); |
| | | log.info("åæº------>>>å¹³å°ï¼å½ä»¤ç±»å=8817--ç²®æ
å
¨é¨æ¶å°ï¼å¼å§è§£æ-{}", |
| | | device.getDeviceName()); |
| | | } |
| | | } |
| | | |
| | | private void analysisStep0(ReMessage msg, GatewayDevice device, BaseReqData reqData, String contextKey, int sumPacket) { |
| | | |
| | | Map<String, String> curMap = contextMap.get(contextKey); |
| | | |
| | | if (StringUtils.isEmpty(device.getCableCir())) { |
| | | analysisStep1(msg, device, reqData, curMap, sumPacket); |
| | | } else { |
| | | analysisStep2(msg, device, reqData, curMap, sumPacket); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * åçä»çç²®æ
è§£æ |
| | | * |
| | | * @param packetMap |
| | | * @param sumPackets |
| | | */ |
| | | private void analysisStep2(ReMessage msg, |
| | | GatewayDevice device, BaseReqData reqData, |
| | | Map<String, String> packetMap, int sumPackets) { |
| | | |
| | | |
| | | String[] cableRuleAtt = device.getCableRule().split("-"); |
| | | String[] cableCirAtt = device.getCableCir().split("-"); |
| | | |
| | | if (cableRuleAtt.length != cableCirAtt.length) { |
| | | log.error("åæº------>>>å¹³å°ï¼å½åä»åºï¼{}ï¼å¸çº¿è§å䏿£ç¡®ï¼æ æ³è§£æç²®æ
ä¿¡æ¯â¦â¦", device.getDeviceName()); |
| | | return; |
| | | } |
| | | |
| | | // è·åæå¤§çå±é
ç½®--é»è®¤æ¯ä¸åé½ä¸æ · |
| | | 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 = 0; |
| | | int len = 4 * cableZ * sumNum; |
| | | |
| | | strPoints = strPoints.substring(start, start + len); |
| | | log.info("åæº------>>>å¹³å°ï¼è¿åç²®æ
宿´ä¿¡æ¯ï¼åæº={}", device.getDeviceName()); |
| | | |
| | | // å°ç²®æ
è§£æææ°ç» |
| | | 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 = ProtocolUtils.ERROR_TEMP; |
| | | } |
| | | |
| | | // æ
éå¼å¤ç |
| | | if (tempValue >= FAULT_CHECK_TAG) { |
| | | tempValue = ProtocolUtils.FAULT_TEMP; |
| | | } |
| | | |
| | | // å¤ç¨å¼ |
| | | if (tempValue == ERROR_CHECK_TAG) { |
| | | tempValue = ProtocolUtils.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 = ProtocolUtils.ADD_TEMP; |
| | | } else { |
| | | temps.add(tempValue); |
| | | } |
| | | |
| | | } else { |
| | | temps.add(tempValue); |
| | | } |
| | | } |
| | | |
| | | // å°éåè§£ææåæ æ°æ® |
| | | addPoint2(temps, msg, device, reqData); |
| | | } |
| | | |
| | | /** |
| | | * è·åå½åè·æå¨å |
| | | * |
| | | * @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(ReMessage msg, |
| | | GatewayDevice device, BaseReqData reqData, |
| | | Map<String, String> packetMap, int sumPackets) { |
| | | // è·å宿´çç²®æ
å
ä¿¡æ¯ |
| | | String strPoints = ""; |
| | | for (int i = 1; i <= sumPackets; i++) { |
| | | strPoints += packetMap.get(buildCurKey(msg, i)); |
| | | } |
| | | |
| | | String[] attCable = device.getCableRule().split("-"); |
| | | int cableZ = Integer.valueOf(attCable[0]); |
| | | int cableY = Integer.valueOf(attCable[1]); |
| | | int cableX = Integer.valueOf(attCable[2]); |
| | | |
| | | // æ ¹æ®å±è¡åè·åæå®é¿åº¦ |
| | | int start = 4 * (device.getCableStart() - 1) * cableZ * cableY; |
| | | int len = 4 * cableZ * cableY * cableX; |
| | | |
| | | log.info("åæº------>>>å¹³å°ï¼è¿åç²®æ
宿´ä¿¡æ¯ï¼åæº={}", device.getDeviceName()); |
| | | |
| | | 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 = ProtocolUtils.ERROR_TEMP; |
| | | } |
| | | // æ
éå¼å¤ç |
| | | if (tempValue >= FAULT_CHECK_TAG) { |
| | | tempValue = ProtocolUtils.FAULT_TEMP; |
| | | } |
| | | temps.add(tempValue); |
| | | } |
| | | |
| | | |
| | | // å°éåè§£ææåæ æ°æ® |
| | | addPoint1(temps, msg, device, reqData); |
| | | } |
| | | |
| | | 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, |
| | | GatewayDevice device, BaseReqData reqData) { |
| | | //TODO |
| | | } |
| | | |
| | | /** |
| | | * åçä»è§£ææ¥éª¤ |
| | | * |
| | | * @param temps |
| | | * @param msg |
| | | */ |
| | | private void addPoint2(List<Double> temps, ReMessage msg, |
| | | GatewayDevice device, BaseReqData reqData) { |
| | | |
| | | //TODO |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.analysis; |
| | | |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.protocol.zldz.cmd.ReMessageBuilder; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | import com.fzzy.protocol.zldz.util.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | |
| | | /** |
| | | * å议解æå
¥å£ |
| | | * |
| | | * @author jiazx |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisService.BEAN_ID) |
| | | public class AnalysisService { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisService"; |
| | | |
| | | |
| | | @Resource |
| | | private AnalysisGrain analysisGrain; |
| | | |
| | | @Resource |
| | | private AnalysisTH analysisTH; |
| | | |
| | | @Resource |
| | | private AnalysisConf analysisConf; |
| | | |
| | | |
| | | public void analysis(String ip, Integer port, String strMsg) { |
| | | |
| | | ApiCommonDevice commonDevice = Constant.getCommonDeviceCacheByIp(ip); |
| | | |
| | | ReMessage reMessage = ReMessageBuilder.getInstance().buildMessage(null, commonDevice, strMsg); |
| | | |
| | | if (null == reMessage) { |
| | | log.error("åæº----->>>å¹³å°ï¼è¿åä¿¡æ¯æ²¡æè·åç»ç»ç¼ç ä¿¡æ¯ï¼æ æ³ç»§ç»è§£æ----{}", commonDevice.getIp()); |
| | | return; |
| | | } |
| | | |
| | | //è·å设å¤ä¿¡æ¯ |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceSn(commonDevice.getSn()); |
| | | if (null == device) { |
| | | log.error("åæº----->>>å¹³å°ï¼ä¸ºè·åå°è®¾å¤é
置信æ¯ï¼æ æ³ç»§ç»è§£æ----{}", commonDevice.getIp()); |
| | | return; |
| | | } |
| | | |
| | | String checkMsg = this.checkMsg(reMessage, device); |
| | | |
| | | if (null != checkMsg) { |
| | | log.error("åæº----->>>å¹³å°ï¼å½ä»¤éªè¯å¼å¸¸ï¼å¼å¸¸ä¿¡æ¯-{}ï¼æ¥æä¿¡æ¯-{}", checkMsg, reMessage.getStrMsg()); |
| | | return; |
| | | } |
| | | |
| | | switch (reMessage.getMessageType()) { |
| | | case ZldzServerUtil.MSG_TYPE_8828:// 温湿度解æ |
| | | analysisTH.analysis8828(reMessage, device); |
| | | break; |
| | | |
| | | case ZldzServerUtil.MSG_TYPE_8815:// ç»ç«¯åºçç²®æ
è¯·æ± |
| | | analysisGrain.analysis8815(reMessage, device); |
| | | break; |
| | | |
| | | case ZldzServerUtil.MSG_TYPE_1117:// ç²®æ
æ°æ®ä¿¡æ¯ |
| | | analysisGrain.analysis8817(reMessage, device); |
| | | break; |
| | | case ZldzServerUtil.MSG_TYPE_1129:// ç»ç«¯åéééçµç¼æ°æ®ç»åå° |
| | | analysisConf.analysis1129(reMessage, device); |
| | | break; |
| | | case ZldzServerUtil.MSG_TYPE_8816:// è§£æé
ç½® |
| | | analysisConf.analysis8816(reMessage, device); |
| | | break; |
| | | case ZldzServerUtil.MSG_TYPE_8822:// çµç¼åå§åæå |
| | | analysisConf.analysis8822(reMessage, device); |
| | | break; |
| | | case ZldzServerUtil.MSG_TYPE_8823:// çµç¼æ±æ»åºç |
| | | analysisConf.analysis8823(reMessage, device); |
| | | break; |
| | | |
| | | case ZldzServerUtil.MSG_TYPE_8825:// 读åééçµç¼é
ç½® |
| | | analysisConf.analysis8825(reMessage, device); |
| | | break; |
| | | |
| | | case ZldzServerUtil.MSG_TYPE_8826:// ä¿®æ¹çµç¼çè¿å |
| | | analysisConf.analysis8826(reMessage, device); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªï¼æ£å¸¸è¿åNULLï¼å¼å¸¸è¿åå¼å¸¸åå ï¼æ£å¸¸å¼å¸¸åå è¿åä¸è¸¢æéæ°è¿æ¥ |
| | | * |
| | | * @param message |
| | | * @param device |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | private String checkMsg(ReMessage message, GatewayDevice device) { |
| | | String result; |
| | | if (message.getResult() == 1) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼æ¥æ¶çåºçæ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 2) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼åéçæ°æ®æ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 3) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼æéä¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 4) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼åéè¶
æ¶é误"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 9) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼Io模åä¸å¨çº¿"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 10) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼åéä¸"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 11) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼æ 线模åæ
é"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 12) { |
| | | result = "åæº=" + device.getDeviceName() |
| | | + " å议解æå¤±è´¥ï¼åå ï¼ä¸»è¦æ¯åé¦åæ ç¹äº¤æ¢å½ä»¤æè
æ¯çµç¼ä¿®æ¹å½ä»¤çéè¯¯ï¼æè
ç²®æ
ééçåæ°ä¸å¯¹"; |
| | | return result; |
| | | } |
| | | if (message.getResult() == 13) { |
| | | result = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼ç½å
³æªæ³¨å"; |
| | | 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 = "åæº=" + device.getDeviceName() + " å议解æå¤±è´¥ï¼åå ï¼CRC16æ ¡éªå¼å¸¸"; |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.analysis; |
| | | |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.data.THDto; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * è§£ææ¸©æ¹¿åº¦ä¿¡æ¯ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | @Slf4j |
| | | @Component(AnalysisTH.BEAN_ID) |
| | | public class AnalysisTH { |
| | | |
| | | public static final String BEAN_ID = "zldz.analysisTH"; |
| | | |
| | | |
| | | public static int ERROR_TH_TAG = -50; |
| | | |
| | | /** |
| | | * è§£æä»åºæ¸©æ¹¿åº¦ä¿¡æ¯ï¼å°ä¿¡æ¯æ¾å¨ç¼åä¸ï¼ä»¥ä¾¿ç²®æ
ä½¿ç¨ |
| | | * |
| | | * @param msg |
| | | * @param ser |
| | | */ |
| | | public void analysis8828(ReMessage msg, GatewayDevice ser) { |
| | | |
| | | log.debug("-----------analysis8828------------{}.{}", ser.getIp(), ser.getPort()); |
| | | |
| | | String content = msg.getBody().getContent(); |
| | | |
| | | //温湿度å°å,æªå4ä½ |
| | | String temp = content.substring(0, 0 + 2 * 2); |
| | | //é«ä½ä½è½¬æ¢ |
| | | temp = BytesUtil.tran_LH(temp); |
| | | int thAddr = BytesUtil.hexToInt(temp); |
| | | |
| | | int t, h; |
| | | |
| | | THDto th = new THDto(); |
| | | th.setTempIn(ProtocolUtils.ERROR_TEMP); |
| | | th.setHumidityIn(ProtocolUtils.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.getDeviceName()); |
| | | th.setRemark(ser.getDeviceName() + "温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨"); |
| | | } 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.getDeviceName()); |
| | | th.setRemark(ser.getDeviceName() + "温湿度解æå¼å¸¸ï¼åå ï¼æ²¡ææ£æµå°ä¼ æå¨"); |
| | | } else { |
| | | th.setHumidityIn(Double.valueOf(h)); |
| | | } |
| | | |
| | | th.setSerId(ser.getId()); |
| | | th.setThAddr(thAddr + ""); |
| | | |
| | | //åæ¾ç¼å |
| | | ProtocolUtils.addTh2Map(ser.getDeviceId(), th); |
| | | |
| | | log.info("仿¸©ä»æ¹¿è§£æå®æ={}", th); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.cmd; |
| | | |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.fzzy.protocol.zldz.data.MessageBody; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | import com.fzzy.protocol.zldz.util.*; |
| | | |
| | | /** |
| | | * å½ä»¤çæå¨ |
| | | * |
| | | * @author Andy |
| | | */ |
| | | public abstract class CommandBuilder { |
| | | |
| | | /* |
| | | * å½ä»¤å建 |
| | | * |
| | | * @param order |
| | | */ |
| | | public Message buildMessage(BaseRequest request) { |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ZldzServerUtil.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, request); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, request); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ZldzServerUtil.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(ZldzServerUtil.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.fzzy.protocol.zldz.cmd; |
| | | |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.fzzy.protocol.zldz.data.MessageBody; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @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(BaseReqData reqData, ApiCommonDevice commonDevice) { |
| | | |
| | | //request.setCompanyId("1"); |
| | | |
| | | Message message = new Message(); |
| | | |
| | | message.setBegin(ZldzServerUtil.MSG_START); |
| | | |
| | | // è°æ´Message头é¨ä¿¡æ¯ |
| | | buildHeader(message, reqData, commonDevice); |
| | | |
| | | //å
å¤´æ ¡éª |
| | | buildCrc8(message); |
| | | |
| | | // åå»ºæ¶æ¯ä½ |
| | | buildBody(message, reqData, commonDevice); |
| | | |
| | | // æ·»å æ ¡éª |
| | | buildCrc16(message); |
| | | |
| | | message.setEnd(ZldzServerUtil.MSG_END); |
| | | |
| | | // çææ´ä½å½ä»¤ä¿¡æ¯åBYteä¿¡æ¯ |
| | | build(message); |
| | | |
| | | return message; |
| | | } |
| | | |
| | | public void buildHeader(Message message, BaseReqData reqData, ApiCommonDevice commonDevice) { |
| | | |
| | | GatewayDevice device = reqData.getDevice(); |
| | | String hexCompanyId = BytesUtil.getTargetId(commonDevice.getOrgId(), true); |
| | | hexCompanyId = BytesUtil.tran_LH(hexCompanyId); |
| | | |
| | | message.setSourceId(hexCompanyId); |
| | | message.setSendId(hexCompanyId); |
| | | message.setCompanyId(hexCompanyId); |
| | | |
| | | message.setTargetId(BytesUtil.tran_LH(BytesUtil.getTargetId(device.getDeviceSn(), true))); |
| | | message.setMessageType(BytesUtil.tran_LH(ZldzServerUtil.MSG_TYPE_1115)); |
| | | } |
| | | |
| | | |
| | | public void buildBody(Message message, BaseReqData reqData, ApiCommonDevice commonDevice) { |
| | | |
| | | GatewayDevice device = reqData.getDevice(); |
| | | |
| | | MessageBody body = new MessageBody(); |
| | | body.setLength(2); |
| | | int start = device.getCableStart(); |
| | | int end = device.getCableEnd(); |
| | | body.setContent(BytesUtil.toHexString(start) + BytesUtil.toHexString(end)); |
| | | message.setBody(body); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.cmd; |
| | | |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @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(ZldzServerUtil.MSG_TYPE_8815)); |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.cmd; |
| | | |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.fzzy.protocol.zldz.data.MessageBody; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | |
| | | /** |
| | | * ç²®æ
ä¿¡æ¯å½ä»¤ |
| | | * |
| | | * @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(ZldzServerUtil.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.fzzy.protocol.zldz.cmd; |
| | | |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.protocol.zldz.data.ReMessage; |
| | | import com.fzzy.protocol.zldz.data.ReMessageBody; |
| | | |
| | | 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 device |
| | | * @param strMsg |
| | | * @return |
| | | */ |
| | | public ReMessage buildMessage(byte[] bytes, ApiCommonDevice device, String strMsg) { |
| | | |
| | | ReMessage message = new ReMessage(); |
| | | message.setIp(device.getIp()); |
| | | message.setPort(device.getPort()); |
| | | 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 = device.getOrgId(); |
| | | |
| | | // ç®æ 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.fzzy.protocol.zldz.data; |
| | | |
| | | 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.fzzy.protocol.zldz.data; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class MessageBody { |
| | | |
| | | //é»è®¤10è¿å¶é¿åº¦ |
| | | private int length = 0; |
| | | |
| | | //æ¶æ¯ä½å
容 |
| | | private String content = ""; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.data; |
| | | |
| | | 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.fzzy.protocol.zldz.data; |
| | | |
| | | |
| | | 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.fzzy.protocol.zldz.data; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * æ¶æ¯-æ¶æ¯ä½ |
| | | * |
| | | * @author Andy |
| | | * |
| | | */ |
| | | @Data |
| | | public class ReMessageBody { |
| | | |
| | | private int length; |
| | | |
| | | private String content; |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * æ£æ¥çµå-ç²®æ
å议解æ |
| | | */ |
| | | package com.fzzy.protocol.zldz; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.server; |
| | | |
| | | import com.ld.io.api.HeartbeatProvider; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | |
| | | /** |
| | | * å¿è·³ç»´æï¼éªè¯å½åè¿æ¥ä¸çIP卿å¡å¨ä¸é
ç½®çææ²¡æï¼å¦ææå表示æ£å¸¸è¿æ¥ï¼å¦ææ²¡æå踢é¤è¿æ¥ã |
| | | * <p> |
| | | * å¦æææ£å¸¸å¿è·³ï¼åå鿣叏å¿è·³å½ä»¤ï¼å¦ææ²¡æååé设å¤ç¶ææ¥è¯¢ï¼ |
| | | */ |
| | | @Slf4j |
| | | public class HeartbeatProviderImpl implements HeartbeatProvider { |
| | | |
| | | |
| | | @Override |
| | | public byte[] provide(IoSession session) { |
| | | |
| | | log.debug("========ç³»ç»å¼å§æ§è¡å¿è·³=========={}---{}", session.getCompanyId(), session.getBusinessKey()); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.server; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.SpringUtil; |
| | | import com.fzzy.protocol.bhzn.cmd.ReMessageBuilder; |
| | | import com.fzzy.protocol.bhzn.data.IoMessage; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; |
| | | import com.fzzy.protocol.zldz.analysis.AnalysisService; |
| | | import com.ld.io.api.IoMsgConsumer; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * æ¥æ¶ç»ç«¯è¿å忥çä¿¡æ¯ã |
| | | * |
| | | * @author Andy |
| | | */ |
| | | @Slf4j |
| | | public class MsgConsumer implements IoMsgConsumer { |
| | | |
| | | |
| | | private AnalysisService analysis; |
| | | |
| | | @Override |
| | | public void consume(IoSession session, byte[] bytes) { |
| | | |
| | | try { |
| | | String hexStr = BytesUtil.bytesToString(bytes); |
| | | |
| | | log.debug("ã" + session.getAddress() + "ã主æº------->>å¹³å°ï¼æ¥æï¼" + hexStr); |
| | | // hexStr = hexStr.substring(ZldzServerUtil.MSG_START.length()); |
| | | |
| | | if (null == analysis) { |
| | | analysis = (AnalysisService) SpringUtil.getBean(AnalysisService.BEAN_ID); |
| | | } |
| | | |
| | | analysis.analysis(session.getAddress(),session.getPort(), hexStr); |
| | | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.server; |
| | | |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.SpringUtil; |
| | | import com.fzzy.gateway.service.GatewayDeviceService; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | @Slf4j |
| | | public class SessionListener implements IoSessionListener { |
| | | |
| | | |
| | | private GatewayDeviceService gatewayDeviceService; |
| | | |
| | | /** |
| | | * 设å¤å建å¨çº¿ï¼éè¦æ³¨æå½å使ç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºä¸çº¿é»è®¤ææç¸åSNé
ç½®çåæºå
¨é¨ä¸çº¿ |
| | | * |
| | | * @param session |
| | | */ |
| | | @Override |
| | | public void onCreate(IoSession session) { |
| | | |
| | | log.info("++++æ°å»ºè¿æ¥++++-IP={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | // æ·»å èªå®ä¹ä¸å¡ID |
| | | session.setBusinessKey(BhznGrainV2ServerUtils.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | //æ§è¡åæºä¸çº¿ |
| | | ApiCommonDevice commonDevice = Constant.updateCacheOnline(session.getAddress(), session.getPort()); |
| | | if (null == commonDevice.getSn()) { |
| | | log.error("------设å¤ä¸çº¿ï¼ç³»ç»ä¸æªåç°å½åé
ç½®-------"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 注æï¼å½åéç¨ä¸»æºæ¨¡å¼ï¼ä¸»æºç¦»çº¿ææç¸åSNé
ç½®çåæºå
¨é¨ç¦»çº¿ |
| | | * |
| | | * @param session |
| | | */ |
| | | @Override |
| | | public void onDestroy(IoSession session) { |
| | | log.info("----è¿æ¥æå¼-----IP={}ï¼PORT={}", session.getAddress(), session.getPort()); |
| | | |
| | | //è®¾ç½®åæºæçº¿ |
| | | ApiCommonDevice commonDevice = Constant.updateCacheOffline(session.getAddress(), session.getPort()); |
| | | |
| | | if (null == commonDevice) return; |
| | | |
| | | if (null == gatewayDeviceService) { |
| | | gatewayDeviceService = SpringUtil.getBean(GatewayDeviceService.class); |
| | | |
| | | gatewayDeviceService.OfflineByCommonDevice(commonDevice); |
| | | } |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.server; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.protocol.fzzy.server.ServerUtils; |
| | | import com.ld.io.api.*; |
| | | import com.ld.io.netty.NettyServer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * é
置主æå¡ä¿¡æ¯ |
| | | * |
| | | */ |
| | | @Slf4j |
| | | public class ZldzServerEngine { |
| | | |
| | | public static final int PORT = 19302; |
| | | |
| | | 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(ZldzServerUtil.MSG_END)); |
| | | |
| | | // é
ç½®å¿è·³æ§è¡æ¶é´ |
| | | ioServerOption.setReaderIdleTime(60 * 60); |
| | | |
| | | ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener, heartbeatProvider); |
| | | |
| | | ioServer.startup(); |
| | | |
| | | log.info("* ========================"); |
| | | log.info("* "); |
| | | log.info("* FZZY-ZLDZ纯粮æ
åè®®ï¼ç«¯å£å·={}", port); |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | |
| | | |
| | | System.out.println("* ========================"); |
| | | System.out.println("* "); |
| | | System.out.println("* FZZY-ZLDZ纯粮æ
åè®®ï¼ç«¯å£å·=" + port); |
| | | System.out.println("* "); |
| | | System.out.println("* ========================"); |
| | | } |
| | | |
| | | /** |
| | | * åéä¿¡æ¯ |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @param msg |
| | | * @return |
| | | */ |
| | | public static InvokeResult push(String ip, int port, byte[] msg) { |
| | | IoSessionQuery sessionFactory = ioServer.getSessionQuery(); |
| | | List<IoSession> sessions = sessionFactory.getAllSession(); |
| | | IoSession session = null; |
| | | for (IoSession ioSession : sessions) { |
| | | if (ServerUtils.getServerKey(ip, port).equals(ioSession.getBusinessKey())) { |
| | | session = ioSession; |
| | | break; |
| | | } |
| | | } |
| | | if (null == session) { |
| | | return InvokeResult.CHANNEL_CLOSED; |
| | | } |
| | | return session.invoke(msg); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.server; |
| | | |
| | | public class ZldzServerUtil { |
| | | |
| | | |
| | | 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; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.service; |
| | | |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.gateway.api.GatewaySyncGranService; |
| | | import com.fzzy.gateway.data.BaseReqData; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.io.request.BaseRequest; |
| | | import com.fzzy.protocol.ProtocolUtils; |
| | | import com.fzzy.protocol.bhzn.cmd.CommandBuild; |
| | | import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerEngine; |
| | | import com.fzzy.protocol.zldz.cmd.CommandBuilder1115; |
| | | import com.fzzy.protocol.zldz.cmd.CommandBuilder8815; |
| | | import com.fzzy.protocol.zldz.cmd.CommandBuilder8817; |
| | | import com.fzzy.protocol.zldz.data.Message; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerEngine; |
| | | import com.fzzy.protocol.zldz.server.ZldzServerUtil; |
| | | import com.ld.io.api.InvokeResult; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | /** |
| | | * æ£æ¥çµåç²®æ
åè®®å®ç° |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class ZldzGatewayGrainService implements GatewaySyncGranService { |
| | | |
| | | @Override |
| | | public String getGrainProtocol() { |
| | | return GatewayDeviceProtocol.GRAIN_FZZY_ZLDZ_WEB.getCode(); |
| | | } |
| | | |
| | | @Override |
| | | public BaseResp syncGrain(BaseReqData reqData) { |
| | | |
| | | BaseResp resp = new BaseResp(); |
| | | |
| | | GatewayDevice device = reqData.getDevice(); |
| | | |
| | | //è·åè¿æ¥ä¸ç设å¤ä¿¡æ¯ |
| | | ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCache(device.getDeviceSn()); |
| | | |
| | | if (null == apiCommonDevice) { |
| | | resp.setCode(500); |
| | | resp.setMsg("ç³»ç»æªè·åå°ä¸è¡è¿æ¥è®¾å¤ä¿¡æ¯ï¼æ æ³æ§è¡"); |
| | | log.error("----------------ç³»ç»æªè·åå°ä¸è¡è¿æ¥è®¾å¤ä¿¡æ¯,æ æ³æ§è¡---------"); |
| | | return resp; |
| | | } |
| | | |
| | | if (Constant.YN_N.equals(apiCommonDevice.getStatus())) { |
| | | resp.setCode(500); |
| | | resp.setMsg("ä¸è¡è®¾å¤ä¸å¨çº¿---æ æ³æ§è¡----" + device.getDeviceName()); |
| | | log.error("ä¸è¡è®¾å¤ä¸å¨çº¿---æ æ³æ§è¡----" + device.getDeviceName()); |
| | | return resp; |
| | | } |
| | | |
| | | device.setIp(apiCommonDevice.getIp()); |
| | | device.setPort(apiCommonDevice.getPort()); |
| | | |
| | | reqData.setDevice(device); |
| | | |
| | | try { |
| | | //Step 请æ±ä¿¡æ¯æ¾å
¥å
å |
| | | ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData); |
| | | |
| | | // çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder1115.getInstance().buildMessage(reqData, apiCommonDevice); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = ZldzServerEngine.push(apiCommonDevice.getIp(), apiCommonDevice.getPort(), message.getByteMsg()); |
| | | |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-{}", message); |
| | | |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败{}", result.getMessage()); |
| | | resp.setCode(500); |
| | | resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("ç²®æ
æ£æµå¼å¸¸ï¼{}", e); |
| | | resp.setCode(500); |
| | | resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤ï¼" + e.getMessage()); |
| | | return resp; |
| | | } |
| | | return resp; |
| | | } |
| | | |
| | | /** |
| | | * æå¡å¨åå¤ç»ç«¯çæ¶å°è¯·æ± |
| | | * |
| | | * @param request |
| | | */ |
| | | public BaseResp reply8815(BaseRequest request) { |
| | | BaseResp resp = new BaseResp(); |
| | | // Step1 çæç²®æ
ä¿¡æ¯ |
| | | Message message = CommandBuilder8815.getInstance().buildMessage( |
| | | request); |
| | | |
| | | log.debug("å¹³å°------>>>åæºï¼" +request.getSerName() + "-ç²®æ
æå¡ç«¯åå¤å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = ZldzServerEngine.push(request.getIp(), request.getPort(), message.getByteMsg()); |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败{}", result.getMessage()); |
| | | resp.setCode(500); |
| | | resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | return resp; |
| | | } |
| | | |
| | | /** |
| | | * åå¤å½ä»¤ |
| | | * |
| | | * @param request |
| | | * @param hexCurPacket å½åå
çhex |
| | | */ |
| | | public BaseResp reply8817(BaseRequest request, String hexCurPacket) { |
| | | BaseResp resp = new BaseResp(); |
| | | // Step1 çæç²®æ
ä¿¡æ¯ï¼æä¿¡æ¯æ¾å¨request |
| | | request.setBizType(hexCurPacket); |
| | | |
| | | Message message = CommandBuilder8817.getInstance().buildMessage(request); |
| | | |
| | | log.debug("å¹³å°------>>>åæºï¼" +request.getSerName() + "-ç²®æ
æå¡ç«¯å夿¶å°ç²®æ
å
å½ä»¤=" + message.toString()); |
| | | |
| | | // åéå½ä»¤ |
| | | InvokeResult result = ZldzServerEngine.push(request.getIp(), request.getPort(), |
| | | message.getByteMsg()); |
| | | // å°è£
è¿åä¿¡æ¯ |
| | | if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) { |
| | | log.error("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败{}", result.getMessage()); |
| | | resp.setCode(500); |
| | | resp.setMsg("å¹³å°------>>>>æ§å¶æï¼åéç²®æ
æ£æµå½ä»¤-失败ï¼" + result.getMessage()); |
| | | } |
| | | |
| | | return resp; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.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; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.zldz.util; |
| | | |
| | | /** |
| | | *计ç®CRC8æ ¡éªå¼ |
| | | */ |
| | | public class CRC8 { |
| | | |
| | | 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; |
| | | } |
| | | } |