JLChen
2019-09-30 4f841eac608f6f22a573b4f7ed713679e89c2e5b
hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLAppliances/HDLAirCondition/Parser/AirCtrlParser.java
@@ -120,114 +120,179 @@
        return addBytes;
    }
    /**
     * 生成默认数据
     *
     * @return
     */
    public static byte[] getNewAcByte() {
        byte[] airBytes = new byte[6];
        airBytes[0] = (byte) 0;
        airBytes[1] = (byte) 0;
        airBytes[2] = (byte) 28;
        airBytes[3] = (byte) 0;
        airBytes[4] = (byte) 28;
        airBytes[5] = (byte) 0;
        return airBytes;
    }
    public static byte[] getAcAddByte(AppliancesInfo appliancesInfo, int type, int state) {
        AppliancesInfo newInfo = null;
        byte[] airBytes = null;
        outter:
        for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
            if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
                    && appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()) {
                for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
                    if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.AIR_BIG_TYPE
                            && HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() != HDLApConfig.TYPE_AC_PANEL
                            && appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
                        newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
                        switch (newInfo.getChannelNum()) {
                            case 1:
                                airBytes = HDLDeviceManager.air1Info;
                                break;
                            case 2:
                                airBytes = HDLDeviceManager.air2Info;
                                break;
                            case 3:
                                airBytes = HDLDeviceManager.air3Info;
                                break;
                            case 4:
                                airBytes = HDLDeviceManager.air4Info;
                                break;
                            default:
                                airBytes = new byte[6];
                                break;
        try {
            AppliancesInfo newInfo = null;
            byte[] airBytes = null;
            outter:
            for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
                if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
                        && appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()) {
                    for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
                        if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.AIR_BIG_TYPE
                                && HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() != HDLApConfig.TYPE_AC_PANEL
                                && appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
                            newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
                            if (newInfo.getArrCurState() == null || newInfo.getArrCurState().length != 6) {
                                newInfo.setArrCurState(getNewAcByte());
                            }
                            airBytes = newInfo.getArrCurState();
                            break outter;
                        }
                        if (newInfo.getArrCurState() == null) {
                            newInfo.setArrCurState(new byte[6]);
                        }
                        break outter;
                    }
                }
            }
        }
        if (airBytes != null && airBytes.length >= 6) {
            byte[] addBytes = new byte[13];
            addBytes[0] = (byte) newInfo.getChannelNum();
            addBytes[1] = 0;
            addBytes[2] = airBytes[4];
            addBytes[3] = airBytes[2];
            addBytes[4] = airBytes[2];
            addBytes[5] = airBytes[2];
            addBytes[6] = airBytes[2];
            addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + (airBytes[3] & 0xff));
            addBytes[8] = airBytes[0];
            addBytes[9] = airBytes[1];
            addBytes[10] = airBytes[3];
            addBytes[11] = airBytes[2];
            addBytes[12] = airBytes[5];
            if (airBytes != null && airBytes.length >= 6) {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = 0;
                addBytes[2] = airBytes[4];
                addBytes[3] = airBytes[2];
                addBytes[4] = airBytes[2];
                addBytes[5] = airBytes[2];
                addBytes[6] = airBytes[2];
                addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + (airBytes[3] & 0xff));
                addBytes[8] = airBytes[0];
                addBytes[9] = airBytes[1];
                addBytes[10] = airBytes[3];
                addBytes[11] = airBytes[2];
                addBytes[12] = airBytes[5];
            switch (type) {
                case airSwich:
                    if (state == airOff) {
                        addBytes[8] = 0;
                    } else {
                switch (type) {
                    case airSwich:
                        if (state == airOff) {
                            addBytes[8] = 0;
                        } else {
                            addBytes[8] = 1;
                        }
                        break;
                    case refTem:
                    case heatTem:
                    case autoTem:
                    case dehumTem:
                        addBytes[8] = 1;
                    }
                    break;
                case refTem:
                case heatTem:
                case autoTem:
                case dehumTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) state;
                    addBytes[4] = (byte) state;
                    addBytes[5] = (byte) state;
                    addBytes[6] = (byte) state;
                    addBytes[11] = (byte) state;
                    break;
                case upTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[4] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[5] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[6] = (byte) ((airBytes[2] & 0xff) + state);
                    addBytes[11] = (byte) ((airBytes[2] & 0xff) + state);
                    break;
                case downTem:
                    addBytes[8] = 1;
                    addBytes[3] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[4] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[5] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[6] = (byte) ((airBytes[2] & 0xff) - state);
                    addBytes[11] = (byte) ((airBytes[2] & 0xff) - state);
                    break;
                case airMode:
                    addBytes[8] = 1;
                    addBytes[7] = (byte) (state * 16 + (airBytes[3] & 0xff));
                    addBytes[9] = (byte) state;
                    break;
                case airSpeed:
                    addBytes[8] = 1;
                    addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + state);
                    addBytes[10] = (byte) state;
                    break;
                        addBytes[3] = (byte) state;
                        addBytes[4] = (byte) state;
                        addBytes[5] = (byte) state;
                        addBytes[6] = (byte) state;
                        addBytes[11] = (byte) state;
                        break;
                    case upTem:
                        addBytes[8] = 1;
                        addBytes[3] = (byte) ((airBytes[2] & 0xff) + state);
                        addBytes[4] = (byte) ((airBytes[2] & 0xff) + state);
                        addBytes[5] = (byte) ((airBytes[2] & 0xff) + state);
                        addBytes[6] = (byte) ((airBytes[2] & 0xff) + state);
                        addBytes[11] = (byte) ((airBytes[2] & 0xff) + state);
                        break;
                    case downTem:
                        addBytes[8] = 1;
                        addBytes[3] = (byte) ((airBytes[2] & 0xff) - state);
                        addBytes[4] = (byte) ((airBytes[2] & 0xff) - state);
                        addBytes[5] = (byte) ((airBytes[2] & 0xff) - state);
                        addBytes[6] = (byte) ((airBytes[2] & 0xff) - state);
                        addBytes[11] = (byte) ((airBytes[2] & 0xff) - state);
                        break;
                    case airMode:
                        addBytes[8] = 1;
                        addBytes[7] = (byte) (state * 16 + (airBytes[3] & 0xff));
                        addBytes[9] = (byte) state;
                        break;
                    case airSpeed:
                        addBytes[8] = 1;
                        addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + state);
                        addBytes[10] = (byte) state;
                        break;
                }
                return addBytes;
            } else {
                addBytes[0] = (byte) newInfo.getChannelNum();
                addBytes[1] = 0;
                addBytes[2] = (byte) 28;
                addBytes[3] = (byte) 28;
                addBytes[4] = (byte) 28;
                addBytes[5] = (byte) 28;
                addBytes[6] = (byte) 28;
                addBytes[7] = 0;
                addBytes[8] = 1;
                addBytes[9] = 0;
                addBytes[10] = 0;
                addBytes[11] = (byte) 28;
                addBytes[12] = 0;
                switch (type) {
                    case airSwich://设置开关状态
                        if (state == airOff) {
                            addBytes[8] = 0;
                        } else {
                            addBytes[8] = 1;
                        }
                        break;
                    case refTem:
                    case heatTem:
                    case autoTem:
                    case dehumTem://设置温度
                        addBytes[8] = 1;
                        addBytes[3] = (byte) state;
                        addBytes[4] = (byte) state;
                        addBytes[5] = (byte) state;
                        addBytes[6] = (byte) state;
                        addBytes[11] = (byte) state;
                        break;
                    case upTem://升温
                        addBytes[8] = 1;
                        addBytes[3] = (byte) (28 + state);
                        addBytes[4] = (byte) (28 + state);
                        addBytes[5] = (byte) (28 + state);
                        addBytes[6] = (byte) (28 + state);
                        addBytes[11] = (byte) (28 + state);
                        break;
                    case downTem://降温
                        addBytes[8] = 1;
                        addBytes[3] = (byte) (28 - state);
                        addBytes[4] = (byte) (28 - state);
                        addBytes[5] = (byte) (28 - state);
                        addBytes[6] = (byte) (28 - state);
                        addBytes[11] = (byte) (28 - state);
                        break;
                    case airMode://设置空调模式
                        addBytes[8] = 1;
                        addBytes[7] = (byte) (state * 16);
                        addBytes[9] = (byte) state;
                        break;
                    case airSpeed://设置风速
                        addBytes[8] = 1;
                        addBytes[7] = (byte) (state);
                        addBytes[10] = (byte) state;
                        break;
                }
            }
            return addBytes;
        } else {
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return new byte[]{fail};
        }
    }
}
//    public static byte[] getRcuAirAddByte(AppliancesInfo info,int type, int arg2){
//        byte[] addBytes = new byte[9];