| | |
| | | package publicway; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import chuankou.SerialPortService; |
| | | import chushihua.SlotManager; |
| | | public class ProtocolParser01 { |
| | | |
| | |
| | | String receivedCRC = hexData.substring(hexData.length() - 6); |
| | | byte[] cmdBytes = HexUtil.hexStringToBytes(hexData.replace(receivedCRC,"")); |
| | | String crc = HexUtil.calculate(cmdBytes)+"00"; |
| | | System.out.println("收到的完整数据是:"+hexData); |
| | | System.out.println("收到数据校验码是:"+receivedCRC); |
| | | System.out.println("校验码是:"+crc); |
| | | //System.out.println("收到的完整数据是:"+hexData); |
| | | //System.out.println("收到数据校验码是:"+receivedCRC); |
| | | //System.out.println("校验码是:"+crc); |
| | | return receivedCRC.equalsIgnoreCase(crc); |
| | | } catch (Exception e) { |
| | | System.err.println("CRC校验异常: " + e.getMessage()); |
| | |
| | | sb.append("9. 电压: ").append(String.format("%.2f", voltage)); |
| | | sb.append("10. 电流: ").append(String.format("%.2f", current)); |
| | | sb.append("数据长度: ").append(dataLength).append(" 字节"); |
| | | // System.out.println(sb.toString()); |
| | | // //System.out.println(sb.toString()); |
| | | return sb.toString(); |
| | | } |
| | | |
| | |
| | | String.format("%.2f", voltage), // 电压 |
| | | String.format("%.2f", current), // 电流 |
| | | getFaultsString() // 故障1插卡错误;2过流;3,门控故障;4过压;5欠压; |
| | | ); |
| | | ); |
| | | |
| | | |
| | | |
| | | } |
| | | } |