package com.dy.pipirrComCreator.p206V1; 
 | 
  
 | 
import com.dy.common.mw.protocol.p206V1.parse.global.GlCreate; 
 | 
import com.dy.common.util.ByteUtil; 
 | 
import com.dy.common.util.ByteUtilUnsigned; 
 | 
import com.dy.common.util.IPUtils; 
 | 
import com.dy.common.util.NumUtil; 
 | 
  
 | 
/** 
 | 
 * @Author: liurunyu 
 | 
 * @Date: 2025/5/7 11:25 
 | 
 * @Description 
 | 
 */ 
 | 
public class P206V1Cd97 extends P206V1Cd { 
 | 
  
 | 
    public static final String ComCode = "97" ; 
 | 
  
 | 
    public String checkParams(String ...params){ 
 | 
        if(params.length != 3){ 
 | 
            return "只有虚拟IC卡编号、剩余金额、水价三个参数" ; 
 | 
        } 
 | 
        //62090200300400001 
 | 
        if(!NumUtil.isPlusIntNumber(params[0])){ 
 | 
            return "虚拟IC卡编号必须是正整数" ; 
 | 
        } 
 | 
        if(params[0].length() != 17){ 
 | 
            return "虚拟IC卡编号必须是17位数字" ; 
 | 
        } 
 | 
        //2.10 
 | 
        if(!NumUtil.isPlusDoubleNumber(params[1])){ 
 | 
            return "剩余金额必须是正数" ; 
 | 
        } 
 | 
        Integer temp = (Double.valueOf(Double.parseDouble(params[1]) * 100.0D)).intValue() ; 
 | 
        if(temp <= 0){ 
 | 
            return "剩余金额必须是大于0的正数" ; 
 | 
        } 
 | 
        if(temp >= 99999999){ 
 | 
            return "剩余金额必须是小于999999.99的正数" ; 
 | 
        } 
 | 
        //1.23 
 | 
        if(!NumUtil.isPlusDoubleNumber(params[2])){ 
 | 
            return "水价必须是正数" ; 
 | 
        } 
 | 
        temp = (Double.valueOf(Double.parseDouble(params[2]) * 100.0D)).intValue() ; 
 | 
        if(temp <= 0){ 
 | 
            return "水价必须是大于0的正数" ; 
 | 
        } 
 | 
        if(temp >= 9999){ 
 | 
            return "水价必须是小于99.99的正数" ; 
 | 
        } 
 | 
        return null ; 
 | 
    } 
 | 
    public String helpInfo() { 
 | 
        return ComCode + " *...*(虚拟IC卡编号) *...*(剩余金额) *...*(水价)[Enter](APP远程开阀)" ; 
 | 
    } 
 | 
    /** 
 | 
     * 构造命令数据(十六进制) 
 | 
     * @return 字符串 
 | 
     * @throws Exception 异常 
 | 
     */ 
 | 
    public String hex(String rtuAddr, String ...params) throws Exception { 
 | 
        byte[] bytes = bs(rtuAddr, params) ; 
 | 
        return ByteUtil.bytes2Hex(bytes, false) ; 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 构造命令数据(字节数组) 
 | 
     * @return 字节数组 
 | 
     * @throws Exception 异常 
 | 
     */ 
 | 
    public byte[] bs(String rtuAddr, String ...params) throws Exception { 
 | 
        byte[] bytes = createHead(rtuAddr, ComCode, P206V1Cd.CTRL); 
 | 
  
 | 
        byte[] bs = new byte[14] ; 
 | 
        byte n = 0 ; 
 | 
        GlCreate.createIcCardNo(params[0], bs, n); 
 | 
  
 | 
        n += 8 ; 
 | 
        Integer money = Double.valueOf(Double.parseDouble(params[1]) * 100.0D).intValue() ; 
 | 
        byte[] bTemp = ByteUtil.int2BCD_LE(money) ; 
 | 
        int bTempLen = bTemp.length ; 
 | 
        int count = 0 ; 
 | 
        for(int i = 0 ; i < bTempLen; i++){ 
 | 
            bs[n++] = bTemp[i] ; 
 | 
            count ++ ; 
 | 
            if(count >= 4){ 
 | 
                break ; 
 | 
            } 
 | 
        } 
 | 
        for(; count < 4; count++){ 
 | 
            bs[n++] = 0 ; 
 | 
        } 
 | 
  
 | 
        Integer price = Double.valueOf(Double.parseDouble(params[2]) * 100.0D).intValue() ; 
 | 
        bTemp = ByteUtil.int2BCD_LE(price) ; 
 | 
        bTempLen = bTemp.length ; 
 | 
        count = 0 ; 
 | 
        for(int i = 0 ; i < bTempLen; i++){ 
 | 
            bs[n++] = bTemp[i] ; 
 | 
            count ++ ; 
 | 
            if(count >= 2){ 
 | 
                break ; 
 | 
            } 
 | 
        } 
 | 
        for(; count < 2; count++){ 
 | 
            bs[n++] = 0 ; 
 | 
        } 
 | 
  
 | 
        bytes = ByteUtil.bytesMerge(bytes, bs); 
 | 
  
 | 
        GlCreate.createLen(bytes);//长度放字节数组中 
 | 
  
 | 
        byte[] bsTail = GlCreate.createCrcTail4P206(bytes) ;//CRC和尾叠加字节数组中 
 | 
  
 | 
        bytes = ByteUtil.bytesMerge(bytes, bsTail) ; 
 | 
  
 | 
        return bytes ; 
 | 
    } 
 | 
  
 | 
} 
 |