app/src/main/AndroidManifest.xml
@@ -38,6 +38,7 @@ <activity android:name=".activity.CtrlCommonSwitchActivity" /> <activity android:name=".activity.CtrlSecurityActivity" /> <activity android:name=".activity.SensorActivity" /> <activity android:name=".activity.CtrlAirHVACActivity" /> <receiver android:name=".activity.BootComplete"> <intent-filter> app/src/main/java/com/hdl/sdk/hdl_sdk/activity/AppliancesActivity.java
@@ -79,7 +79,14 @@ } } else if (appliancesInfos.get(position).getBigType() == Configuration.AIR_BIG_TYPE) { //空调模块 if(appliancesInfos.get(position).getDeviceType() == HDLApConfig.TYPE_AC_HVAC){ intent.setClass(AppliancesActivity.this, CtrlAirHVACActivity.class); }else { intent.setClass(AppliancesActivity.this, CtrlActivity.class); } } else { intent.setClass(AppliancesActivity.this, CtrlActivity.class); app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlAirHVACActivity.java
New file @@ -0,0 +1,437 @@ package com.hdl.sdk.hdl_sdk.activity; import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.RelativeLayout; import android.widget.TextView; import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirHVACBackInfo; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser; import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo; import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLCommand; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.AirHVACFeedBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DeviceStateEvent; import com.hdl.sdk.hdl_sdk.R; import com.hdl.sdk.hdl_sdk.base.BaseActivity; import com.hdl.sdk.hdl_sdk.utlis.HDLLog; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; /** * Created by JLChen on 2019/7/4 * 空调类模块控制页面 * HVAC 类型空调模块 * 16~30摄氏度(℃) */ public class CtrlAirHVACActivity extends BaseActivity { private Button airBtnSwitch, airBtnMode, airBtnTemp, airBtnSpeed; private TextView airText; private EditText airTempEd; private AppliancesInfo appliancesInfo; private int airSwitchState;//Demo仅以此作为演示,实际请根据需求开发设计 private int airModeState; private int airTempState; private int airSpeedState; // /** // * true为设置摄氏度 false为设置华氏度 // * 参数范围 16~30摄氏度(℃) // * ~86华氏度(℉) // */ // private boolean bCelsius = true; /** * 复写isRegisterEventBus() 要注册使用EventBus,这里要设置返回true * * @return true */ @Override protected boolean isRegisterEventBus() { return true; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ctrl_air_hvac); initToolbar(); initView(); initOnClick(); initcurState(); showStateView(); // if(appliancesInfo.getDeviceType() == HDLApConfig.TYPE_AC_HVAC) { // HDLCommand.getHVACDeviceStateFromNetwork(appliancesInfo); // } HDLCommand.getHVACDeviceStateFromNetwork(appliancesInfo); } /** * 初始化Toolbar */ private void initToolbar() { // topBarBack = findViewById(R.id.ll_top_b_left); // setViewVisible(topBarBack); // topBarTitle = findViewById(R.id.tv_top_b_header_title); // topBarBack.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // finish(); // } // }); } private void initcurState() { appliancesInfo = (AppliancesInfo) getIntent().getSerializableExtra("hdl"); String titleStr = appliancesInfo.getRemarks(); } private void initView() { airBtnSwitch = findViewById(R.id.airbtn_switch); airBtnMode = findViewById(R.id.airbtn_mode); airBtnSpeed = findViewById(R.id.airbtn_speed); airBtnTemp = findViewById(R.id.airbtn_tempBtn); airTempEd = findViewById(R.id.airet_tempet); airText = findViewById(R.id.airText); } private void initOnClick() { airBtnSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //演示当前状态为关,设置为开。开,设置为关。 if (airSwitchState == 0) { HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSwich, AirCtrlParser.airOn);//空调开 } else { HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSwich, AirCtrlParser.airOff);//空调关 } } }); airBtnMode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (airModeState) { case 0: //若当前空调模式为制冷,则点击按钮设置为制热 HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeHeatTem);//空调模式制热 break; case 1: //若当前空调模式为制热,则点击按钮设置为通风 HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeVen);//空调模式通风 break; case 2: //若当前空调模式为通风,则点击按钮设置为自动 HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeAuto);//空调模式自动 break; case 3: //若当前空调模式为自动,则点击按钮设置为抽湿 HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeDehum);//空调模式抽湿 break; case 4: //若当前空调模式为抽湿,则点击按钮设置为制冷 HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeRefTem);//空调模式制冷 break; default: HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airMode, AirCtrlParser.airModeRefTem);//空调模式制冷 break; } } }); airBtnSpeed.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { HDLCommand.airCtrl(appliancesInfo,AirCtrlParser.downTem,1);//上升温度 范围0-5 return; // switch (airSpeedState) { // case 0: // //若当前空调风速为自动,则点击按钮设置为高风 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSpeed, AirCtrlParser.airSpeedHigh);//风速高风 // break; // case 1: // //若当前空调风速为高风,则点击按钮设置为中风 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSpeed, AirCtrlParser.airSpeedMid);//风速中风 // break; // case 2: // //若当前空调风速为中风,则点击按钮设置为低风 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSpeed, AirCtrlParser.airSpeedLow);//风速低风 // break; // case 3: // //若当前空调风速为低风,则点击按钮设置为自动 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.airSpeed, AirCtrlParser.airSpeedAuto);//风速自动 // break; // // // } } }); airBtnTemp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { HDLCommand.airCtrl(appliancesInfo,AirCtrlParser.upTem,1);//上升温度 范围0-5 return; // String tempStr = airTempEd.getText().toString(); // if (TextUtils.isEmpty(tempStr)) { // showToast("设置的温度不能为空"); // return; // } // int tempInt = Integer.parseInt(tempStr); // // if (tempInt < 16 || tempInt > 30) { // showToast("温度设置范围为:16~30摄氏度(℃)"); // return; // } // // switch (airModeState) { // case 0: // //当前空调模式为制冷 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.refTem, tempInt);//制冷温度 // break; // case 1: // //当前空调模式为制热 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.heatTem, tempInt);//制热温度 // break; // case 2: // //当前空调模式为通风 // showToast("通风模式不能控制温度"); // break; // case 3: // //当前空调模式为自动 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.autoTem, tempInt);//自动温度 范围16-30 // break; // case 4: // //当前空调模式为抽湿 // HDLCommand.airCtrl(appliancesInfo, AirCtrlParser.dehumTem, tempInt);//抽湿温度 范围16-30 // break; // default: // break; // // } // HDLCommand.airCtrl(appliancesInfo,AirCtrlParser.upTem,1);//上升温度 范围0-5 // HDLCommand.airCtrl(appliancesInfo,AirCtrlParser.downTem,1);//下降温度 范围0-5 } }); } private void showStateView() { if (appliancesInfo.getArrCurState() != null) { AirHVACBackInfo mAirHVACBackInfo = new AirHVACBackInfo(appliancesInfo); String stringState = ""; if (mAirHVACBackInfo.getIsOn() == AirCtrlParser.airOff) { stringState = "HVAC空调模块:关闭"; } else if (mAirHVACBackInfo.getIsOn() == AirCtrlParser.airOn) { stringState = "HVAC空调模块:打开"; stringState += "\n" + getModeStateString(mAirHVACBackInfo.getAirMode());//模式 stringState += "\n" + getSpeedStateString(mAirHVACBackInfo.getAirSpeed());//风速 stringState += "\n室内温度:" + mAirHVACBackInfo.getIndoorTemp(); stringState += "\n制冷模式温度:" + mAirHVACBackInfo.getRefTemp(); stringState += "\n制热模式温度:" + mAirHVACBackInfo.getHeatTemp(); stringState += "\n自动模式温度:" + mAirHVACBackInfo.getAutoTemp(); stringState += "\n抽湿模式温度:" + mAirHVACBackInfo.getWettedTemp(); } else { stringState = "未知开关状态"; } airText.setText(stringState); } else { airText.setText("未获取到HVAC空调模块状态"); } } /** * getModeStateString * * @param mState * @return */ private String getModeStateString(int mState) { String mStrState = "未知"; airModeState = mState; //更新模式状态 switch (mState) { case AirCtrlParser.airModeRefTem: mStrState = "模式:制冷"; break; case AirCtrlParser.airModeHeatTem: mStrState = "模式:制热"; break; case AirCtrlParser.airModeVen: mStrState = "模式:通风"; break; case AirCtrlParser.airModeAuto: mStrState = "模式:自动"; break; case AirCtrlParser.airModeDehum: mStrState = "模式:抽湿"; break; default: mStrState = "未知模式状态"; break; } return mStrState; } /** * getSpeedStateString * * @param mState * @return */ private String getSpeedStateString(int mState) { String mStrState = "未知"; airSpeedState = mState; //更新当前风速状态 switch (mState) { case AirCtrlParser.airSpeedAuto: mStrState = "风速:自动"; break; case AirCtrlParser.airSpeedHigh: mStrState = "风速:高"; break; case AirCtrlParser.airSpeedMid: mStrState = "风速:中"; break; case AirCtrlParser.airSpeedLow: mStrState = "风速:低"; break; default: mStrState = "未知风速状态"; break; } return mStrState; } /** * getSwichStateString * * @param mState * @return */ private String getSwichStateString(int mState) { String mStrState = "未知"; airSwitchState = mState; //更新开关状态 switch (mState) { case AirCtrlParser.airOn: mStrState = "HVAC空调模块:打开"; break; case AirCtrlParser.airOff: mStrState = "HVAC空调模块:关闭"; break; default: mStrState = "未知状态"; break; } return mStrState; } private void showAirHVACBackInfo(AirHVACBackInfo mAirHVACBackInfo){ String message = ""; if(mAirHVACBackInfo.getIsOn() == AirCtrlParser.airOn) { message = getSwichStateString(mAirHVACBackInfo.getIsOn()); message += "\n" + getModeStateString(mAirHVACBackInfo.getAirMode());//模式 message += "\n" + getSpeedStateString(mAirHVACBackInfo.getAirSpeed());//风速 message += "\n室内温度:" + mAirHVACBackInfo.getIndoorTemp(); message += "\n制冷模式温度:" + mAirHVACBackInfo.getRefTemp(); message += "\n制热模式温度:" + mAirHVACBackInfo.getHeatTemp(); message += "\n自动模式温度:" + mAirHVACBackInfo.getAutoTemp(); message += "\n抽湿模式温度:" + mAirHVACBackInfo.getWettedTemp(); }else { message = getSwichStateString(mAirHVACBackInfo.getIsOn()); } airText.setText(message); showToast(message); HDLLog.I(message); } /** * 空调模块控制回调Event * * @param event */ @Subscribe(threadMode = ThreadMode.MAIN) public void onAirHVACFeedBackEventMain(AirHVACFeedBackEvent event) { if (event.getAirHVACBackInfo().getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID() && event.getAirHVACBackInfo().getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID() && event.getAirHVACBackInfo().getAppliancesInfo().getChannelNum() == appliancesInfo.getChannelNum() ) { // 先判断是否超时 if (!event.isSuccess()) { showToast("空调控制超时,请重新再试"); return; } AirHVACBackInfo mAirHVACBackInfo = event.getAirHVACBackInfo(); showAirHVACBackInfo(mAirHVACBackInfo); } } /** * 获取单一设备状态回调Event * * @param event */ @Subscribe(threadMode = ThreadMode.MAIN) public void onDeviceStateEventMain(DeviceStateEvent event) { if (event.getAppliancesInfo().getDeviceSubnetID() == appliancesInfo.getDeviceSubnetID() && event.getAppliancesInfo().getDeviceDeviceID() == appliancesInfo.getDeviceDeviceID() ) { //这个返回的信息是当前状态的 switch (event.getAppliancesInfo().getDeviceType()) { case HDLApConfig.TYPE_AC_HVAC: if (appliancesInfo.getChannelNum() == event.getAppliancesInfo().getChannelNum()) { if (!event.isSuccess()) { showToast("获取空调状态失败,请重新再试"); return; } AirHVACBackInfo mAirHVACBackInfo = new AirHVACBackInfo(event.getAppliancesInfo()); if (mAirHVACBackInfo == null) { showToast("获取空调状态失败,请重新再试"); return; } showAirHVACBackInfo(mAirHVACBackInfo); } break; default: //不处理 break; } } } } app/src/main/java/com/hdl/sdk/hdl_sdk/activity/GeothermalActivity.java
@@ -412,6 +412,7 @@ message = getSwichStateString(mGeothermalBackInfo.getIsOn()); message += "\n" + getModeStateString(mGeothermalBackInfo.getgMode()); message += "\n" + "室内温度:" + mGeothermalBackInfo.getgCurrentTemp(); message += "\n" + "普通模式温度:" + mGeothermalBackInfo.getgNormalTemp(); message += "\n" + "白天模式温度:" + mGeothermalBackInfo.getgDayTemp(); message += "\n" + "夜间模式温度:" + mGeothermalBackInfo.getgNightTemp(); app/src/main/res/layout/activity_ctrl_air_hvac.xml
New file @@ -0,0 +1,75 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_ctrl" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- <include--> <!-- android:id="@+id/hdl_top_bar_layout"--> <!-- layout="@layout/hdl_toolbar_top_view_b"/>--> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="40dp" android:text="HVAC空调功能类模块" android:gravity="center|left" android:textSize="@dimen/ts_24" /> <LinearLayout android:id="@+id/air" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/airText" android:textSize="@dimen/ts_20" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="这个按钮做空调面板的演示" /> <Button android:id="@+id/airbtn_switch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="空调开关" /> <Button android:id="@+id/airbtn_mode" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="空调模式" /> <Button android:id="@+id/airbtn_speed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="空调风速" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/airbtn_tempBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点击设置空调温度:" /> <EditText android:id="@+id/airet_tempet" android:layout_width="match_parent" android:layout_height="match_parent" android:inputType="number"/> </LinearLayout> </LinearLayout> </LinearLayout> </RelativeLayout> hdl_core/src/main/java/com/hdl/sdk/hdl_core/Config/Configuration.java
@@ -113,8 +113,8 @@ public static final int AIR_HVAC_CTRL_COMMAND = 0x193A; public static final int AIR_HVAC_CTRL_BACK_COMMAND = 0x193B; // public static final int AIR_HVAC_STATE_COMMAND = 0x1938; public static final int AIR_HVAC_STATE_BACK_COMMAND = 0x209A; public static final int AIR_HVAC_STATE_COMMAND = 0x1938; public static final int AIR_HVAC_STATE_BACK_COMMAND = 0x1939; //逻辑模块操作码、状态读取码 hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLAppliances/HDLAirCondition/AirHVACBackInfo.java
New file @@ -0,0 +1,149 @@ package com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition; import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo; import java.io.Serializable; /** * Created by JLChen on 2019/8/6 */ public class AirHVACBackInfo implements Serializable { private AppliancesInfo appliancesInfo; private String remarks; private int channelNum;//回路号 private int isOn;//0=关,1=开 private int indoorTemp;//室内温度点 0-84 private int refTemp;//制冷温度点 0-84 private int heatTemp;//制热温度点 0-84 private int autoTemp;//自动温度点 0-84 private int wettedTemp;//抽湿温度点 private int airSpeed;//风速 0 =自动, 1 = 高风, 1 = 中风, 3 = 低风 private int airMode;//空调模式0 = 制冷, 1 = 制热, 1 = 通风, 3 =自动, 4 = 抽湿 // private int upTemp;//上升温度 // private int downTemp;//下降温度 private byte[] curState ;//控制回馈信息 public AirHVACBackInfo(){ } public AirHVACBackInfo(AppliancesInfo mAppliancesInfo) { this.appliancesInfo = mAppliancesInfo; this.curState = mAppliancesInfo.getArrCurState(); this.remarks = mAppliancesInfo.getRemarks(); if (this.curState == null) return; if (this.curState.length >= 13) { this.channelNum = this.curState[0] & 0xFF; this.indoorTemp = this.curState[2] & 0xFF; this.refTemp = this.curState[3] & 0xFF;//制冷温度点 0-84 this.heatTemp = this.curState[4] & 0xFF;//制热温度点 0-84 this.autoTemp = this.curState[5] & 0xFF;//自动温度点 0-84 this.wettedTemp = this.curState[6] & 0xFF;//抽湿温度点 0-84 this.isOn = this.curState[8] & 0xFF;//只取低4位 this.airMode = this.curState[9] & 0xFF; this.airSpeed = this.curState[10] & 0xFF; } } public int getIndoorTemp() { return indoorTemp; } public void setIndoorTemp(int indoorTemp) { this.indoorTemp = indoorTemp; } public AppliancesInfo getAppliancesInfo() { return appliancesInfo; } public void setAppliancesInfo(AppliancesInfo appliancesInfo) { this.appliancesInfo = appliancesInfo; } public String getRemarks() { return remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } public int getChannelNum() { return channelNum; } public void setChannelNum(int channelNum) { this.channelNum = channelNum; } public int getIsOn() { return isOn; } public void setIsOn(int isOn) { this.isOn = isOn; } public int getRefTemp() { return refTemp; } public void setRefTemp(int refTemp) { this.refTemp = refTemp; } public int getHeatTemp() { return heatTemp; } public void setHeatTemp(int heatTemp) { this.heatTemp = heatTemp; } public int getAutoTemp() { return autoTemp; } public void setAutoTemp(int autoTemp) { this.autoTemp = autoTemp; } public int getWettedTemp() { return wettedTemp; } public void setWettedTemp(int wettedTemp) { this.wettedTemp = wettedTemp; } public int getAirSpeed() { return airSpeed; } public void setAirSpeed(int airSpeed) { this.airSpeed = airSpeed; } public int getAirMode() { return airMode; } public void setAirMode(int airMode) { this.airMode = airMode; } public byte[] getCurState() { return curState; } public void setCurState(byte[] curState) { this.curState = curState; } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLAppliances/HDLAirCondition/Parser/AirCtrlParser.java
@@ -121,22 +121,59 @@ } /** * 生成默认数据 * 状态数据异常的时候,生成默认空调数据 * @return */ public static byte[] getNewAcByte() { byte[] airBytes = new byte[13]; airBytes[0] = 0; airBytes[1] = 0; airBytes[2] = (byte) 28; airBytes[3] = (byte) 28; airBytes[4] = (byte) 28; airBytes[5] = (byte) 28; airBytes[6] = (byte) 28; airBytes[7] = 0; airBytes[8] = 1; airBytes[9] = 0; airBytes[10] = 0; airBytes[11] = (byte) 28; airBytes[12] = 0; return airBytes; } /** * 简易编程搜索 状态数据bytes格式,对比旧状态数据修改更新状态处理,不用简易编程搜索备注接收状态的话,该方法可以忽略 * 0 开关状态 * 1 模式 * 2 温度 * 3 风速 * 4 * 4 当前室温 * 5 是否摆风 * * @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; public static byte[] getNewAcByteWithE44B(byte[] bytes, byte[] oldBytes) { byte[] airBytes = getNewAcByte(); if(oldBytes != null && oldBytes.length >= 13){ airBytes = oldBytes; } if (bytes.length > 5) { // airBytes[0] = 0; // airBytes[1] = 0; airBytes[2] = bytes[4]; // airBytes[3] = bytes[2]; // airBytes[4] = bytes[2]; // airBytes[5] = bytes[2]; // airBytes[6] = bytes[2]; airBytes[7] = (byte) ((airBytes[2] & 0xff) * 16 + (airBytes[3] & 0xff)); airBytes[8] = bytes[0]; airBytes[9] = bytes[1]; airBytes[10] = bytes[3]; airBytes[11] = bytes[2]; airBytes[12] = bytes[5]; } return airBytes; } @@ -154,7 +191,7 @@ && 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) { if (newInfo.getArrCurState() == null || newInfo.getArrCurState().length != 13) { newInfo.setArrCurState(getNewAcByte()); } airBytes = newInfo.getArrCurState(); @@ -166,73 +203,27 @@ } byte[] addBytes = new byte[13]; if (airBytes != null && airBytes.length >= 6) { if (airBytes != null && airBytes.length >= 13) { //2020-05-28 如果温度为0自动修改为28 if((airBytes[2] & 0xff) == 0){ airBytes[2] = (byte)28; if ((airBytes[11] & 0xff) == 0) { airBytes[11] = (byte) 28; } 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]; addBytes[2] = airBytes[2]; addBytes[3] = airBytes[3]; addBytes[4] = airBytes[4]; addBytes[5] = airBytes[5]; addBytes[6] = airBytes[6]; addBytes[7] = (byte) ((airBytes[9] & 0xff) * 16 + (airBytes[10] & 0xff)); addBytes[8] = airBytes[8]; addBytes[9] = airBytes[9]; addBytes[10] = airBytes[10]; addBytes[11] = airBytes[11]; addBytes[12] = airBytes[12]; 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) ((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; @@ -247,53 +238,87 @@ 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; } } switch (type) { case airSwich: if (state == airOff) { addBytes[8] = 0; } else { addBytes[8] = 1; } break; case refTem: addBytes[8] = 1; addBytes[3] = (byte) state; addBytes[11] = (byte) state; break; case heatTem: addBytes[8] = 1; addBytes[4] = (byte) state; addBytes[11] = (byte) state; break; case autoTem: addBytes[8] = 1; addBytes[5] = (byte) state; addBytes[11] = (byte) state; break; case dehumTem: addBytes[8] = 1; addBytes[6] = (byte) state; addBytes[11] = (byte) state; break; case upTem: addBytes[8] = 1; byte tempByte = (byte) ((airBytes[11] & 0xff) + state); //判断当前模式 if(addBytes[9] == 0){//制冷 tempByte = (byte) ((airBytes[3] & 0xff) + state); addBytes[3] = tempByte; }else if(addBytes[9] == 1){//制热 tempByte = (byte) ((airBytes[4] & 0xff) + state); addBytes[4] = tempByte; }else if(addBytes[9] == 3){//自动 tempByte = (byte) ((airBytes[5] & 0xff) + state); addBytes[5] = tempByte; }else if(addBytes[9] == 4){//抽湿 tempByte = (byte) ((airBytes[6] & 0xff) + state); addBytes[6] = tempByte; } addBytes[11] = tempByte; break; case downTem: addBytes[8] = 1; byte tempByte2 = (byte) ((airBytes[11] & 0xff) - state); //判断当前模式 if(addBytes[9] == 0){//制冷 tempByte2 = (byte) ((airBytes[3] & 0xff) - state); addBytes[3] = tempByte2; }else if(addBytes[9] == 1){//制热 tempByte2 = (byte) ((airBytes[4] & 0xff) - state); addBytes[4] = tempByte2; }else if(addBytes[9] == 3){//自动 tempByte2 = (byte) ((airBytes[5] & 0xff) - state); addBytes[5] = tempByte2; }else if(addBytes[9] == 4){//抽湿 tempByte2 = (byte) ((airBytes[6] & 0xff) - state); addBytes[6] = tempByte2; } addBytes[11] = tempByte2; break; case airMode: addBytes[8] = 1; addBytes[7] = (byte) (state * 16 + (airBytes[10] & 0xff)); addBytes[9] = (byte) state; break; case airSpeed: addBytes[8] = 1; addBytes[7] = (byte) ((airBytes[9] & 0xff) * 16 + state); addBytes[10] = (byte) state; break; } return addBytes; } catch (Exception e) { e.printStackTrace(); @@ -301,185 +326,6 @@ } } } // public static byte[] getRcuAirAddByte(AppliancesInfo info,int type, int arg2){ // byte[] addBytes = new byte[9]; // addBytes[4] = 1; // byte[] curAirInfo = info.getArrCurState(); // switch (info.getChannelNum()){ // case 1: // curAirInfo = HDLDeviceManager.air1Info; // break; // case 2: // curAirInfo = HDLDeviceManager.air2Info; // break; // case 3: // curAirInfo = HDLDeviceManager.air3Info; // break; // case 4: // curAirInfo = HDLDeviceManager.air4Info; // break; // } // // byte airSwitch = curAirInfo[0]; // byte aircurMode = curAirInfo[1]; // byte airTem = curAirInfo[2]; // byte aircurSpeed = curAirInfo[3]; // byte aircurTem = curAirInfo[4]; // byte airBAIFENG = curAirInfo[5]; // // addBytes[0] = (byte) info.getChannelNum(); // addBytes[1] = airSwitch; // switch (aircurMode){ // case 0: // addBytes[2] = airTem; // break; // case 1: // addBytes[5] = airTem; // break; // case 2: // break; // case 3: // addBytes[6] = airTem; // break; // } // addBytes[3] = (byte) ((aircurMode << 4) | aircurSpeed); // addBytes[4] = 1; // addBytes[8] = airBAIFENG; // switch (type){ // case airSwich: // if(arg2 == airOff){ // addBytes[1] = 0; // }else if(arg2 == airOn){ // addBytes[1] = 1; // } // break; // case refTem: // addBytes[2] = (byte) arg2; // addBytes[5] = (byte) arg2; // addBytes[6] = (byte) arg2; // addBytes[7] = (byte) arg2; // break; // case airSpeed : // int modifyLow; // int height = ((addBytes[3] & 0xf0) >> 4);//获取高4位 // switch (arg2){ // case airSpeedAuto: // modifyLow = 0; // addBytes[3] = (byte)((height<<4)|modifyLow); // break; // case airSpeedHigh: // modifyLow = 1; // addBytes[3] = (byte)((height<<4)|modifyLow); // break; // case airSpeedMid: // modifyLow = 2; // addBytes[3] = (byte)((height<<4)|modifyLow); // break; // case airSpeedLow: // modifyLow = 3; // addBytes[3] = (byte)((height<<4)|modifyLow); // break; // default: // addBytes = new byte[]{fail}; // break; // } // break; // case airMode: // int modify; // int low = (addBytes[3] & 0x0f);//获取低4位 // switch (arg2){ // case airModeRefTem: // // modify = 0; // addBytes[3] = (byte)((modify<<4)|low); // break; // case airModeHeatTem: // modify = 1; // addBytes[3] = (byte)((modify<<4)|low); // break; // case airModeVen: // modify = 2; // addBytes[3] = (byte)((modify<<4)|low); // break; // case airModeAuto: // modify = 3; // addBytes[3] = (byte)((modify<<4)|low); // break; // case airModeDehum: // modify = 4; // addBytes[3] = (byte)((modify<<4)|low); // break; // default: // addBytes = new byte[]{fail}; // break; // } // break; // case heatTem: // addBytes[2] = (byte) arg2; // addBytes[5] = (byte) arg2; // addBytes[6] = (byte) arg2; // addBytes[7] = (byte) arg2; // break; // case autoTem: // addBytes[2] = (byte) arg2; // addBytes[5] = (byte) arg2; // addBytes[6] = (byte) arg2; // addBytes[7] = (byte) arg2; // break; // case dehumTem: // addBytes[2] = (byte) arg2; // addBytes[5] = (byte) arg2; // addBytes[6] = (byte) arg2; // addBytes[7] = (byte) arg2; // break; // case upTem: //// int height2 = ((addBytes[3] & 0xf0) >> 4);//获取高4位 //// switch (height2){ //// case 0: //// addBytes[2] = (byte) (arg2 + (airTem & 0xFF)); //// break; //// case 1: //// addBytes[5] = (byte) (arg2 + (airTem & 0xFF)); //// break; //// case 3: //// addBytes[6] = (byte) (arg2 + (airTem & 0xFF)); //// break; //// case 4: //// addBytes[7] = (byte) (arg2 + (airTem & 0xFF)); //// break; //// } // addBytes[2] = (byte) (arg2 + (airTem & 0xFF)); // addBytes[5] = (byte) (arg2 + (airTem & 0xFF)); // addBytes[6] = (byte) (arg2 + (airTem & 0xFF)); // addBytes[7] = (byte) (arg2 + (airTem & 0xFF)); // break; // case downTem: //// int height3= ((addBytes[3] & 0xf0) >> 4);//获取高4位 //// switch (height3){ //// case 0: //// addBytes[2] = (byte) ((airTem & 0xFF)-arg2 ); //// break; //// case 1: //// addBytes[5] = (byte) ((airTem & 0xFF)-arg2 ); //// break; //// case 3: //// addBytes[6] = (byte) ((airTem & 0xFF)-arg2 ); //// break; //// case 4: //// addBytes[7] = (byte) ((airTem & 0xFF)-arg2 ); //// break; //// } // addBytes[2] = (byte) ((airTem & 0xFF)-arg2 ); // addBytes[5] = (byte) ((airTem & 0xFF)-arg2 ); // addBytes[6] = (byte) ((airTem & 0xFF)-arg2 ); // addBytes[7] = (byte) ((airTem & 0xFF)-arg2 ); // break; // default: // addBytes = new byte[]{fail}; // break; // } // return addBytes; // } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLAppliances/HDLGeothermal/GeothermalBackInfo.java
@@ -49,8 +49,13 @@ this.gNightTemp = this.curState[6] & 0xFF; this.gLeaveTemp = this.curState[7] & 0xFF; this.gAutoTemp = this.curState[8] & 0xFF; this.gCurrentTemp = this.curState[9] & 0xFF; // this.gCurrentTemp = this.curState[9] & 0xFF; //当前温度(环境温度) bit7 0=正值 1=负值 if(((this.curState[9] & 0xFF) >> 7) > 0){ this.gCurrentTemp = -(this.curState[9] & 0x7F); }else{ this.gCurrentTemp = this.curState[9] & 0x7F; } } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java
@@ -1255,6 +1255,26 @@ // } /** * 获取HVAC空调设备状态 * @param info */ public static void getHVACDeviceStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_AC_HVAC: // case HDLApConfig.TYPE_AC_PANEL: //发送HVAC状态数据 addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); break; default: HDLLog.info("不是HVAC空调设备"); break; } } /** * 获取干接点传感器模块状态 hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java
@@ -10,6 +10,7 @@ import com.hdl.sdk.hdl_core.Config.Configuration; import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirCtrlBackInfo; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirHVACBackInfo; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAudio.HDLAudio; import com.hdl.sdk.hdl_core.HDLAppliances.HDLCommonSwitch.CommonSwitchBackInfo; @@ -32,6 +33,7 @@ import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.RcuLight; import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.UdpDataBean; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.AirFeedBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.AirHVACFeedBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.CommonSwitchCtrlBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.CommonSwitchStateBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.CurtainFeedBackEvent; @@ -52,6 +54,7 @@ import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil; import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils; import com.hdl.sdk.hdl_core.Util.TransformUtil.DataConverseUtil; import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis; import com.hdl.sdk.hdl_core.Util.TransformUtil.StringUtil; import org.greenrobot.eventbus.EventBus; @@ -189,9 +192,12 @@ case Configuration.CURTAIN_CTRL_BACK_COMMAND: case Configuration.AIR_CTRL_BACK_COMMAND: case Configuration.LOGIC_CTRL_BACK_COMMAND: case Configuration.AIR_HVAC_CTRL_BACK_COMMAND: // case Configuration.AIR_HVAC_CTRL_BACK_COMMAND: case Configuration.FRESH_AIR_CTRL_BACK_COMMAND: //20190709新增 handleCtrlData(getDatas); break; case Configuration.AIR_HVAC_CTRL_BACK_COMMAND: handleHVACCtrlData(getDatas); break; case Configuration.LIGHT_RGB_CTRL_BACK_COMMAND: //2020-10-19新增 handleRGBCCTCtrlData(getDatas); @@ -241,7 +247,7 @@ case Configuration.SENSOR_STATE_BACK_COMMAND: handleSensorAnalogStateData(getDatas, true); break; case Configuration.SENSOR_BROADCAST_COMMAND://传感器模拟量广播 case Configuration.SENSOR_BROADCAST_COMMAND://2021-08-10 传感器模拟量广播 handleSensorAnalogStateData(getDatas, false); break; //获取新风设备状态 20190709新增 @@ -254,7 +260,8 @@ break; case Configuration.AIR_HVAC_STATE_BACK_COMMAND: handleRcuAirCastData(getDatas); // handleRcuAirCastData(getDatas); handleHVACStateData(getDatas);//2019-06-27 break; case Configuration.RCU_ROOM_CAST_COMMAND: handleRcuLightCastData(getDatas); @@ -1405,182 +1412,182 @@ } } /** * 处理RCU空调广播消息 * * @param getDatas */ private static void handleRcuAirCastData(UdpDataBean getDatas) { int count = getDatas.addBytes.length / 11; for (int airIndex = 0; airIndex < count; airIndex++) { outter: for (int indexI = 0, len = devicesDataList.size(); indexI < len; indexI++) { if (devicesDataList.get(indexI).getSourceSubnetID() == getDatas.sourceSubnetID && devicesDataList.get(indexI).getSourceDeviceID() == getDatas.sourceDeviceID ) { List<AppliancesInfo> infos = devicesDataList.get(indexI).getAppliancesInfoList(); for (int indexJ = 0, len2 = infos.size(); indexJ < len2; indexJ++) { if (infos.get(indexJ).getBigType() == Configuration.AIR_BIG_TYPE && infos.get(indexJ).getDeviceType() != HDLApConfig.TYPE_AC_PANEL && infos.get(indexJ).getChannelNum() == (getDatas.addBytes[airIndex * 11] & 0xFF)) { AppliancesInfo appliancesInfo = devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ); if (appliancesInfo.getPort() != 0) { byte[] oldAirInfo = appliancesInfo.getArrCurState(); if (oldAirInfo == null || oldAirInfo.length == 0) { oldAirInfo = AirCtrlParser.getNewAcByte(); } handleAirCastData(getDatas, oldAirInfo, airIndex, appliancesInfo); oldAirInfo[0] = getDatas.addBytes[1 + 0 * 11]; oldAirInfo[1] = (byte) ((getDatas.addBytes[3 + 0 * 11] & 0xf0) >> 4); switch (oldAirInfo[0] & 0xff) { case 0: oldAirInfo[2] = getDatas.addBytes[2 + 0 * 11]; break; case 1: oldAirInfo[2] = getDatas.addBytes[6 + 0 * 11]; break; case 3: oldAirInfo[2] = getDatas.addBytes[8 + 0 * 11]; break; case 4: oldAirInfo[2] = getDatas.addBytes[9 + 0 * 11]; break; } oldAirInfo[3] = (byte) (getDatas.addBytes[3 + 0 * 11] & 0x0f); oldAirInfo[4] = getDatas.addBytes[5 + 0 * 11]; oldAirInfo[5] = getDatas.addBytes[10 + 0 * 11]; devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo); // switch (getDatas.addBytes[airIndex * 11] & 0xff) { // case 1: // handleAirCastData(getDatas, air1Info, airIndex, appliancesInfo); // air1Info[0] = getDatas.addBytes[1 + 0 * 11]; // /** // * 处理RCU空调广播消息 // * // * @param getDatas // */ // private static void handleRcuAirCastData(UdpDataBean getDatas) { // int count = getDatas.addBytes.length / 11; // // for (int airIndex = 0; airIndex < count; airIndex++) { // outter: // for (int indexI = 0, len = devicesDataList.size(); indexI < len; indexI++) { // if (devicesDataList.get(indexI).getSourceSubnetID() == getDatas.sourceSubnetID // && devicesDataList.get(indexI).getSourceDeviceID() == getDatas.sourceDeviceID // ) { // List<AppliancesInfo> infos = devicesDataList.get(indexI).getAppliancesInfoList(); // for (int indexJ = 0, len2 = infos.size(); indexJ < len2; indexJ++) { // if (infos.get(indexJ).getBigType() == Configuration.AIR_BIG_TYPE // && infos.get(indexJ).getDeviceType() != HDLApConfig.TYPE_AC_PANEL // && infos.get(indexJ).getChannelNum() == (getDatas.addBytes[airIndex * 11] & 0xFF)) { // AppliancesInfo appliancesInfo = devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ); // if (appliancesInfo.getPort() != 0) { // byte[] oldAirInfo = appliancesInfo.getArrCurState(); // // if (oldAirInfo == null || oldAirInfo.length == 0) { // oldAirInfo = AirCtrlParser.getNewAcByte(); // } // // // air1Info[1] = (byte) ((getDatas.addBytes[3 + 0 * 11] & 0xf0) >> 4); // handleAirCastData(getDatas, oldAirInfo, airIndex, appliancesInfo); // // oldAirInfo[0] = getDatas.addBytes[1 + 0 * 11]; // // oldAirInfo[1] = (byte) ((getDatas.addBytes[3 + 0 * 11] & 0xf0) >> 4); // // // switch (air1Info[0] & 0xff) { // case 0: // air1Info[2] = getDatas.addBytes[2 + 0 * 11]; // break; // case 1: // air1Info[2] = getDatas.addBytes[6 + 0 * 11]; // break; // case 3: // air1Info[2] = getDatas.addBytes[8 + 0 * 11]; // break; // case 4: // air1Info[2] = getDatas.addBytes[9 + 0 * 11]; // break; // // } // // air1Info[3] = (byte) (getDatas.addBytes[3 + 0 * 11] & 0x0f); // air1Info[4] = getDatas.addBytes[5 + 0 * 11]; // air1Info[5] = getDatas.addBytes[10 + 0 * 11]; //// HDLLog.info( "209a air1Info = " + air1Info[0] + " " + air1Info[1] + " " + air1Info[2] + " " + air1Info[3] + " " + air1Info[4] + " " + air1Info[5]); //// String arrString = "209a 附加数据:"; //// for (int i = 0; i < getDatas.addBytes.length; i++) { //// arrString += (getDatas.addBytes[i] & 0xff) + ","; //// } //// HDLLog.info( arrString); // devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air1Info); // switch (oldAirInfo[0] & 0xff) { // case 0: // oldAirInfo[2] = getDatas.addBytes[2 + 0 * 11]; // break; // case 2: // handleAirCastData(getDatas, air2Info, airIndex, appliancesInfo); // air2Info[0] = getDatas.addBytes[1 + 1 * 11]; // air2Info[1] = (byte) ((getDatas.addBytes[3 + 1 * 11] & 0xf0) >> 4); // switch (air2Info[0] & 0xff) { // case 0: // air2Info[2] = getDatas.addBytes[2 + 1 * 11]; // break; // case 1: // air2Info[2] = getDatas.addBytes[6 + 1 * 11]; // break; // case 3: // air2Info[2] = getDatas.addBytes[8 + 1 * 11]; // break; // case 4: // air2Info[2] = getDatas.addBytes[9 + 1 * 11]; // break; // // } // air2Info[3] = (byte) (getDatas.addBytes[3 + 1 * 11] & 0x0f); // air2Info[4] = getDatas.addBytes[5 + 1 * 11]; // air2Info[5] = getDatas.addBytes[10 + 1 * 11]; // devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air2Info); // case 1: // oldAirInfo[2] = getDatas.addBytes[6 + 0 * 11]; // break; // case 3: // handleAirCastData(getDatas, air3Info, airIndex, appliancesInfo); // air3Info[0] = getDatas.addBytes[1 + 2 * 11]; // air3Info[1] = (byte) ((getDatas.addBytes[3 + 2 * 11] & 0xf0) >> 4); // switch (air3Info[0] & 0xff) { // case 0: // air3Info[2] = getDatas.addBytes[2 + 2 * 11]; // break; // case 1: // air3Info[2] = getDatas.addBytes[6 + 2 * 11]; // break; // case 3: // air3Info[2] = getDatas.addBytes[8 + 2 * 11]; // break; // case 4: // air3Info[2] = getDatas.addBytes[9 + 2 * 11]; // break; // } // air3Info[3] = (byte) (getDatas.addBytes[3 + 2 * 11] & 0x0f); // air3Info[4] = getDatas.addBytes[5 + 2 * 11]; // air3Info[5] = getDatas.addBytes[10 + 2 * 11]; // devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air3Info); // oldAirInfo[2] = getDatas.addBytes[8 + 0 * 11]; // break; // case 4: // handleAirCastData(getDatas, air4Info, airIndex, appliancesInfo); // air4Info[0] = getDatas.addBytes[1 + 3 * 11]; // air4Info[1] = (byte) ((getDatas.addBytes[3 + 3 * 11] & 0xf0) >> 4); // switch (air4Info[0] & 0xff) { // case 0: // air4Info[2] = getDatas.addBytes[2 + 3 * 11]; // break; // case 1: // air4Info[2] = getDatas.addBytes[6 + 3 * 11]; // break; // case 3: // air4Info[2] = getDatas.addBytes[8 + 3 * 11]; // break; // case 4: // air4Info[2] = getDatas.addBytes[9 + 3 * 11]; // break; // } // air4Info[3] = (byte) (getDatas.addBytes[3 + 3 * 11] & 0x0f); // air4Info[4] = getDatas.addBytes[5 + 3 * 11]; // air4Info[5] = getDatas.addBytes[10 + 3 * 11]; // devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air4Info); // oldAirInfo[2] = getDatas.addBytes[9 + 0 * 11]; // break; // // } } } } } } } } // // oldAirInfo[3] = (byte) (getDatas.addBytes[3 + 0 * 11] & 0x0f); // oldAirInfo[4] = getDatas.addBytes[5 + 0 * 11]; // oldAirInfo[5] = getDatas.addBytes[10 + 0 * 11]; // devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo); // // //// switch (getDatas.addBytes[airIndex * 11] & 0xff) { //// case 1: //// handleAirCastData(getDatas, air1Info, airIndex, appliancesInfo); //// air1Info[0] = getDatas.addBytes[1 + 0 * 11]; //// //// //// air1Info[1] = (byte) ((getDatas.addBytes[3 + 0 * 11] & 0xf0) >> 4); //// //// //// switch (air1Info[0] & 0xff) { //// case 0: //// air1Info[2] = getDatas.addBytes[2 + 0 * 11]; //// break; //// case 1: //// air1Info[2] = getDatas.addBytes[6 + 0 * 11]; //// break; //// case 3: //// air1Info[2] = getDatas.addBytes[8 + 0 * 11]; //// break; //// case 4: //// air1Info[2] = getDatas.addBytes[9 + 0 * 11]; //// break; //// //// } //// //// air1Info[3] = (byte) (getDatas.addBytes[3 + 0 * 11] & 0x0f); //// air1Info[4] = getDatas.addBytes[5 + 0 * 11]; //// air1Info[5] = getDatas.addBytes[10 + 0 * 11]; ////// HDLLog.info( "209a air1Info = " + air1Info[0] + " " + air1Info[1] + " " + air1Info[2] + " " + air1Info[3] + " " + air1Info[4] + " " + air1Info[5]); ////// String arrString = "209a 附加数据:"; ////// for (int i = 0; i < getDatas.addBytes.length; i++) { ////// arrString += (getDatas.addBytes[i] & 0xff) + ","; ////// } ////// HDLLog.info( arrString); //// devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air1Info); //// break; //// case 2: //// handleAirCastData(getDatas, air2Info, airIndex, appliancesInfo); //// air2Info[0] = getDatas.addBytes[1 + 1 * 11]; //// air2Info[1] = (byte) ((getDatas.addBytes[3 + 1 * 11] & 0xf0) >> 4); //// switch (air2Info[0] & 0xff) { //// case 0: //// air2Info[2] = getDatas.addBytes[2 + 1 * 11]; //// break; //// case 1: //// air2Info[2] = getDatas.addBytes[6 + 1 * 11]; //// break; //// case 3: //// air2Info[2] = getDatas.addBytes[8 + 1 * 11]; //// break; //// case 4: //// air2Info[2] = getDatas.addBytes[9 + 1 * 11]; //// break; //// //// } //// air2Info[3] = (byte) (getDatas.addBytes[3 + 1 * 11] & 0x0f); //// air2Info[4] = getDatas.addBytes[5 + 1 * 11]; //// air2Info[5] = getDatas.addBytes[10 + 1 * 11]; //// devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air2Info); //// break; //// case 3: //// handleAirCastData(getDatas, air3Info, airIndex, appliancesInfo); //// air3Info[0] = getDatas.addBytes[1 + 2 * 11]; //// air3Info[1] = (byte) ((getDatas.addBytes[3 + 2 * 11] & 0xf0) >> 4); //// switch (air3Info[0] & 0xff) { //// case 0: //// air3Info[2] = getDatas.addBytes[2 + 2 * 11]; //// break; //// case 1: //// air3Info[2] = getDatas.addBytes[6 + 2 * 11]; //// break; //// case 3: //// air3Info[2] = getDatas.addBytes[8 + 2 * 11]; //// break; //// case 4: //// air3Info[2] = getDatas.addBytes[9 + 2 * 11]; //// break; //// } //// air3Info[3] = (byte) (getDatas.addBytes[3 + 2 * 11] & 0x0f); //// air3Info[4] = getDatas.addBytes[5 + 2 * 11]; //// air3Info[5] = getDatas.addBytes[10 + 2 * 11]; //// devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air3Info); //// break; //// case 4: //// handleAirCastData(getDatas, air4Info, airIndex, appliancesInfo); //// air4Info[0] = getDatas.addBytes[1 + 3 * 11]; //// air4Info[1] = (byte) ((getDatas.addBytes[3 + 3 * 11] & 0xf0) >> 4); //// switch (air4Info[0] & 0xff) { //// case 0: //// air4Info[2] = getDatas.addBytes[2 + 3 * 11]; //// break; //// case 1: //// air4Info[2] = getDatas.addBytes[6 + 3 * 11]; //// break; //// case 3: //// air4Info[2] = getDatas.addBytes[8 + 3 * 11]; //// break; //// case 4: //// air4Info[2] = getDatas.addBytes[9 + 3 * 11]; //// break; //// } //// air4Info[3] = (byte) (getDatas.addBytes[3 + 3 * 11] & 0x0f); //// air4Info[4] = getDatas.addBytes[5 + 3 * 11]; //// air4Info[5] = getDatas.addBytes[10 + 3 * 11]; //// devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(air4Info); //// break; //// //// } // } // } // } // } // } // // // } // // // } /** @@ -2036,14 +2043,24 @@ case Configuration.AIR_BIG_TYPE: switch (infos.get(appPos).getLittleType()) { case 0: byte[] hvacBytes = new byte[getDatas.addBytes.length - 23]; for (int i = 23; i < getDatas.addBytes.length; i++) { hvacBytes[i - 23] = getDatas.addBytes[i]; } HDLLog.info("获取备注Configuration.AIR_BIG_TYPE: " + StringUtil.ByteArrToHex(hvacBytes, 0, hvacBytes.length)); devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setArrCurState(hvacBytes); // hvacBytes * 简易编程搜索 状态数据bytes格式 // * 0 开关状态 // * 1 模式 // * 2 温度 // * 3 风速 // * 4 当前室温 // * 5 是否摆风 byte[] oldHvacBytes = devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).getArrCurState(); //为了不改变原来其他模式的温度数据,需要获取原来的状态修改处理 byte[] newHvacBytes = AirCtrlParser.getNewAcByteWithE44B(hvacBytes, oldHvacBytes); // HDLLog.info("获取备注Configuration.AIR_BIG_TYPE: " + StringUtil.ByteArrToHex(hvacBytes, 0, hvacBytes.length)); // HDLLog.info("获取备注Configuration.AIR_BIG_TYPEnewhvacBytes: " + StringUtil.ByteArrToHex(newHvacBytes, 0, newHvacBytes.length)); devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setArrCurState(newHvacBytes); // switch (devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).getChannelNum()) { // case 1: // if (air1Info == null) { @@ -2066,7 +2083,7 @@ // } // break; // // } // break; case 3: byte[] newBytes = new byte[getDatas.addBytes.length - 24 + 1]; @@ -2078,12 +2095,6 @@ } break; case Configuration.SENSOR_BIG_TYPE: // String aa = "传感器备注:"; // for (int i = 0; i < getDatas.addBytes.length; i++) { // aa += (getDatas.addBytes[i] & 0xff) + ","; // } // HDLLog.info( aa); //使用干节点指令的传感器 if (DeviceParser.getIfDryContactSensor(infos.get(appPos).getLittleType())) { //干节点传感器,要特殊处理修改回路号 @@ -2099,18 +2110,30 @@ devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(curState); devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState((int) curState); } else { //标准模拟量传感器 //标准模拟量传感器 2021-08-09 float curState; if (getDatas.addBytes.length >= 28) { curState = DataConverseUtil.byte2Float(Arrays.copyOfRange(getDatas.addBytes, 24, 27)); if (getDatas.addBytes.length >= 26) { curState = (float) ((getDatas.addBytes[24] & 0xff) * 256 + (getDatas.addBytes[25] & 0xff)); //TVOC 和温度传感器要特殊处理 if (infos.get(appPos).getLittleType() == 5) {//TVOC //TVOC固定:2(10 ug/m3)所以要乘以10 才是ug/m3 curState = curState * 10; HDLLog.info("curStatecurState TVOC:" + curState); } else if (infos.get(appPos).getLittleType() == 2) {//温度 //转为Float if (getDatas.addBytes.length >= 28) { curState = HDLUtlis.byteArrayToFloatWithSign((byte) 3, getDatas.addBytes[24], getDatas.addBytes[25], getDatas.addBytes[26], getDatas.addBytes[27]); HDLLog.info("curStatecurState temp:" + curState); } } } else { curState = (float) (getDatas.addBytes[getDatas.addBytes.length - 1] & 0xff); //格式不对,赋值状态为0 curState = 0; } devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(curState); devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState((int) curState); } break; case Configuration.FRESH_AIR_BIG_TYPE://20190711新增 @@ -2312,6 +2335,12 @@ /** * 处理各种传感器模拟量状态数据 * 2021-08-05 * 小类 * 2:温度 * 3:湿度 * 5:TVOC * 6:PM2.5 * 7:CO2 * * @param getDatas */ @@ -2332,10 +2361,15 @@ isGetDeviceStateSuccess = true; } AppliancesInfo sensorInfo = devicesDataList.get(i).getAppliancesInfoList().get(j); float value = DataConverseUtil.byte2Float(Arrays.copyOfRange(getDatas.addBytes, 5, 8)); // float value = HDLUtlis.byteArrayToFloat(Arrays.copyOfRange(getDatas.addBytes, 5, 8)); float value = HDLUtlis.byteArrayToFloatWithSign(getDatas.addBytes[3], getDatas.addBytes[5], getDatas.addBytes[6], getDatas.addBytes[7], getDatas.addBytes[8]); if (devicesDataList.get(i).getAppliancesInfoList().get(j).getLittleType() == 5) { //TVOC固定:2(0.01ug/m3)所以要除以100 才是微克/m3 value = value / 100; } devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(value); devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState((int) value); HDLLog.info("curStatecurState ug:" + value); sensorInfo.setCurState(value); String unite = ""; @@ -2362,7 +2396,7 @@ unite = "LUX"; break; case HDLApConfig.TYPE_SENSOR_VOC: unite = ""; unite = "ug/m3"; break; case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5: switch (getDatas.addBytes[4] & 0xff) { @@ -3093,4 +3127,77 @@ } /** * 处理HVAC 控制回调 * 2019-8-6 * * @param getDatas */ private static void handleHVACCtrlData(UdpDataBean getDatas) { switch (getDatas.command) { case Configuration.AIR_HVAC_CTRL_BACK_COMMAND: outter: for (int i = 0, len = devicesDataList.size(); i < len; i++) { if (devicesDataList.get(i).getSourceSubnetID() == getDatas.sourceSubnetID && devicesDataList.get(i).getSourceDeviceID() == getDatas.sourceDeviceID ) { List<AppliancesInfo> infos = devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (getDatas.addBytes.length > 0) { if (infos.get(j).getBigType() == Configuration.AIR_BIG_TYPE && infos.get(j).getDeviceType() == HDLApConfig.TYPE_AC_HVAC && infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) { devicesDataList.get(i).getAppliancesInfoList().get(j).setArrCurState(getDatas.addBytes); AppliancesInfo mHvacAirInfo = devicesDataList.get(i).getAppliancesInfoList().get(j); AirHVACBackInfo info = new AirHVACBackInfo(mHvacAirInfo); setDeviceCtrlSuccessStateWithInfo(infos.get(j), true); EventBus.getDefault().post(new AirHVACFeedBackEvent(info, true)); break outter; } // else { // HDLLog.E("控制HVAC状态反馈数据异常"); // } } } break outter; } } break; } } /** * 读取HVAC状态反馈 * * @param getDatas */ private static void handleHVACStateData(UdpDataBean getDatas) { outter: for (int i = 0, len = devicesDataList.size(); i < len; i++) { if (devicesDataList.get(i).getSourceSubnetID() == getDatas.sourceSubnetID && devicesDataList.get(i).getSourceDeviceID() == getDatas.sourceDeviceID ) { List<AppliancesInfo> infos = devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (infos.get(j).getBigType() == Configuration.AIR_BIG_TYPE && infos.get(j).getDeviceType() == HDLApConfig.TYPE_AC_HVAC && infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {//2019-8-6 isGetDeviceStateSuccess = true; devicesDataList.get(i).getAppliancesInfoList().get(j).setArrCurState(getDatas.addBytes); EventBus.getDefault().post(new DeviceStateEvent(devicesDataList.get(i).getAppliancesInfoList().get(j), true)); break outter; } else { HDLLog.info("handleHVACStateData 没有找到匹配类型"); } } break outter; } } } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/EventBusEvent/AirHVACFeedBackEvent.java
New file @@ -0,0 +1,25 @@ package com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent; import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirHVACBackInfo; /** * Created by JLChen on 2019/8/6 */ public class AirHVACFeedBackEvent { AirHVACBackInfo mAirHVACBackInfo; boolean isSuccess; public AirHVACFeedBackEvent(AirHVACBackInfo airHVACBackInfo, boolean isSuccess){ this.mAirHVACBackInfo = airHVACBackInfo; this.isSuccess = isSuccess; } public AirHVACBackInfo getAirHVACBackInfo() { return mAirHVACBackInfo; } public boolean isSuccess() { return isSuccess; } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java
@@ -429,7 +429,7 @@ if (littleType == 0) { appliancesInfo.setCtrlCommand(Configuration.AIR_HVAC_CTRL_COMMAND); appliancesInfo.setCtrlBackCommand(Configuration.AIR_HVAC_CTRL_BACK_COMMAND); // appliancesInfo.setStateCommand(Configuration.AIR_HVAC_STATE_COMMAND); appliancesInfo.setStateCommand(Configuration.AIR_HVAC_STATE_COMMAND); appliancesInfo.setStateBackCommand(Configuration.AIR_HVAC_STATE_BACK_COMMAND); } else { appliancesInfo.setCtrlCommand(Configuration.AIR_CTRL_COMMAND); @@ -659,11 +659,6 @@ appliancesInfo.setChannelNum(curChannelNum); appliancesInfo.setBigType(Configuration.SENSOR_BIG_TYPE); appliancesInfo.setLittleType(littleType); // appliancesInfo.setCtrlCommand(Configuration.LOGIC_CTRL_COMMAND); // appliancesInfo.setCtrlBackCommand(Configuration.LOGIC_CTRL_BACK_COMMAND); // appliancesInfo.setStateCommand(Configuration.SENSOR_STATE_COMMAND); // appliancesInfo.setStateBackCommand(Configuration.SENSOR_STATE_BACK_COMMAND); appliancesInfo.setDeviceSubnetID(devicesData.getSourceSubnetID()); appliancesInfo.setDeviceDeviceID(devicesData.getSourceDeviceID()); appliancesInfo.setParentRemarks(parentRemarks); hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/DataConverseUtil.java
@@ -15,4 +15,6 @@ float f2 = buf.getFloat(); return f2; } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java
@@ -55,17 +55,26 @@ * @return */ public static float byteToFloat(byte b1, byte b2, byte b3, byte b4) { byte[] mByte = new byte[4]; mByte[0] = b1; mByte[1] = b2; mByte[2] = b3; mByte[3] = b4; byte[] mByte = new byte[]{b4, b3, b2, b1}; return byteArrayToFloat(mByte); } public static double byteToDouble(byte b1, byte b2, byte b3, byte b4) { return b1 * 256 * 256 * 256 + b2 * 256 * 256 + b3 * 256 + b4; /** * 无符号4Byte整形 */ public static float byteToFloat_UnsignedInteger(byte b1, byte b2, byte b3, byte b4) { return (b1 & 0xFF) * 256 * 256 * 256 + (b2 & 0xFF) * 256 * 256 + (b3 & 0xFF) * 256 + (b4 & 0xFF); } /** * 有符号4Byte整形 */ public static float byteToFloat_SignedInteger(byte b1, byte b2, byte b3, byte b4) { float mfloat = (b1 & 0x7F) * 256 * 256 * 256 + (b2 & 0xFF) * 256 * 256 + (b3 & 0xFF) * 256 + (b4 & 0xFF); if(((b1 & 0xFF) >> 7) > 0){ return -mfloat; }else{ return mfloat; } } @@ -108,5 +117,30 @@ return getByteArray(intbits); } /** * byte[4]数组 转换为float类型 * @param sign 数据类型 0保留 1无符号4Byte整形 2有符号4Byte整形 3Float形(代±) 注:小数点的用浮点表示,整数不表示小数点 * @param b1~b5 sign == 3 的时候 数据值高位在前,低位在后 (数据从后往前装载,例如100的值,应该时0x00000064) * @return */ public static float byteArrayToFloatWithSign(byte sign, byte b1, byte b2, byte b3, byte b4) { try { if(sign == 1){//1无符号4Byte整形 return byteToFloat_UnsignedInteger(b1, b2, b3, b4); }else if(sign == 2){//2有符号4Byte整形 return byteToFloat_SignedInteger(b1, b2, b3, b4); }else if(sign == 3){//3Float形(代±) byte[] mByte = new byte[]{b4, b3, b2, b1}; return byteArrayToFloat(mByte); }else{ return byteToFloat_UnsignedInteger(b1, b2, b3, b4); } } catch (Exception e) { e.printStackTrace(); return 0; } } }