| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.common.mw.protocol.p206V2.parse.global; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.upVos.DataAlarmVo; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.p206V2.upVos.DataStateVo; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  | import com.dy.common.util.ByteUtilUnsigned; | 
|---|
|  |  |  | import org.apache.logging.log4j.LogManager; | 
|---|
|  |  |  | import org.apache.logging.log4j.Logger; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public class GlParse { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final Logger log = LogManager.getLogger(GlParse.class); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static DataAlarmVo parseAlarm(byte[] bs, short index){ | 
|---|
|  |  |  | /* | 
|---|
|  |  |  | 11011111 (DF)  +  11111001 (F9) | 
|---|
|  |  |  | 报警: | 
|---|
|  |  |  | 蓄电池电压:报警 | 
|---|
|  |  |  | 漏损:报警 | 
|---|
|  |  |  | 仪表:报警 | 
|---|
|  |  |  | 阀门:报警 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | DataAlarmVo avo = new DataAlarmVo() ; | 
|---|
|  |  |  | byte b = bs[index] ; | 
|---|
|  |  |  | avo.batteryVolt = (byte)((b & 0x2) >> 1) ; | 
|---|
|  |  |  | avo.meter = (byte)((b & 0x20) >> 5) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | b = bs[index + 1] ; | 
|---|
|  |  |  | avo.loss = (byte)((b & 0x2) >> 1) ; | 
|---|
|  |  |  | avo.valve = (byte)((b & 0x4) >> 2) ; | 
|---|
|  |  |  | return avo ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static DataStateVo parseState(byte[] bs, short index){ | 
|---|
|  |  |  | DataStateVo avo = new DataStateVo() ; | 
|---|
|  |  |  | byte b = bs[index] ; | 
|---|
|  |  |  | avo.icCard = (byte)((b & 0x4) >> 2) ; | 
|---|
|  |  |  | avo.valveState = (byte)((b & 0x10) >> 4) ; | 
|---|
|  |  |  | avo.powerType = (byte)((b & 0x40) >> 6) ; | 
|---|
|  |  |  | return avo ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分析IC卡编号 | 
|---|
|  |  |  | * @param bs 上行字节数组 | 
|---|
|  |  |  | * @param index 启始位 | 
|---|
|  |  |  | * @return 控制器地址 | 
|---|
|  |  |  | * @throws Exception 异常 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public static String parseIcCardNo(byte[] bs, int index)throws Exception{ | 
|---|
|  |  |  | String icNoStr = "" + ByteUtilUnsigned.bytes2Short_LE(bs, index) ; | 
|---|
|  |  |  | String icNoBCD = "" + ByteUtil.BCD2Long_LE(bs, index + 2, index + 7) ; | 
|---|
|  |  |  | while(icNoStr.length() < 5){ | 
|---|
|  |  |  | icNoStr = "0" + icNoStr ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return icNoBCD + icNoStr ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static String parseTp(byte[] bs, short index){ | 
|---|
|  |  |  | String dt = "" ; | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | dt = dt + ByteUtil.BCD2String_BE(bs, index, index) ;//秒 | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//分 | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | dt = ByteUtil.BCD2String_BE(bs, index, index) + ":" + dt ;//时 | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | dt = ByteUtil.BCD2String_BE(bs, index, index) + " " + dt ;//日 | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | //bs[index] = (byte)(bs[index] & 0x10); | 
|---|
|  |  |  | dt = ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//月 | 
|---|
|  |  |  | index++ ; | 
|---|
|  |  |  | dt = "20" + ByteUtil.BCD2String_BE(bs, index, index) + "-" + dt ;//年 | 
|---|
|  |  |  | }catch (Exception e){ | 
|---|
|  |  |  | log.error("解析控制器时钟时异常:" + e.getMessage(), e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return dt ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|