package com.hdl.sdk.hdl_core.HDLDeviceManger.Core;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.text.TextUtils;
|
|
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.Parser.AirCtrlParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLAudio.HDLAudio;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLCurtain.CurtainCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLCurtain.Parser.CurtainCtrlParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLFreshAir.FreshAirBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.GeothermalBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLight.LightCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLogic.LogicCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLogic.LogicMode;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLSensor.SensorStateBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLWarning.WarningType;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ListRemarks;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.RcuCurtain;
|
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.CurtainFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DeviceStateEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.EventCode;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.FreshAirFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.WarningInfoEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Parser.DeviceParser;
|
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
|
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.StringUtil;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Timer;
|
import java.util.TimerTask;
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import static com.hdl.sdk.hdl_core.Util.TransformUtil.StringUtil.byte2String;
|
|
|
/**
|
* Created by djl on 2017/3/27.
|
* 设备管理类
|
* 此类事设备所有信息的管理类,作为一个中控,
|
* 包括搜索,读取,控制等所有操作的管理
|
*/
|
|
public class HDLDeviceManager {
|
public static List<String> rcuIpList = new ArrayList<>();//统计Rcu ip地址列表
|
public static List<DevicesData> devicesDataList = new ArrayList<>();//统计搜索列表
|
public static List<DevicesData> realDevicesDataList = new ArrayList<>();//统计搜索列表
|
private static Context viewContext;
|
public static List<ListRemarks> listRemarks = new ArrayList<>();
|
public static List<RcuLight> rcuLightList = new ArrayList<>();
|
public static List<RcuCurtain> rcuCurtainList = new ArrayList<>();
|
public static boolean isLogicCtrl = false;
|
public static ConcurrentHashMap<String, Boolean> ctrlSuccessStateHashMap = new ConcurrentHashMap<>();//2019-8-2
|
|
// public static byte[] air1Info = null;
|
// public static byte[] air2Info = null;
|
// public static byte[] air3Info = null;
|
// public static byte[] air4Info = null;
|
// air4Info[开关状态,模式,设置温度,风速,当前温度,是否摆风 ];
|
|
public static boolean isGetRcuIpSuccess = false;
|
public static boolean isGetDeviceStateSuccess = false; //判断获取设备状态是否控制成功
|
|
// public static boolean isLightCtrlSuccess = false; //判断灯光是否控制成功
|
// public static boolean isCurtainCtrlSuccess = false; //判断窗帘是否控制成功
|
// public static boolean isACCtrlSuccess = false; //判断空调是否控制成功
|
// public static boolean isSceneCtrlSuccess = false; //判断场景是否控制成功
|
// public static boolean isFreshAirCtrlSuccess = false; //判断新风系统是否控制成功
|
// public static boolean isGeothermalCtrlSuccess = false; //判断地热模块是否控制成功
|
|
|
/**
|
* 初始化SDK
|
*
|
* @param context 上下文
|
*/
|
public static void init(Context context) {
|
viewContext = context;
|
// HDLUdpCore.initMulticastSocket();
|
HandleSearch.rcuIp = (String) SPUtils.getParam(context, SPUtils.KEY_RCU_IP_, "");
|
Crc.localSubnetID = (int) SPUtils.getParam(context, SPUtils.KEY_SUB_ID_, 254);
|
Crc.localDeviceID = (int) SPUtils.getParam(context, SPUtils.KEY_DEVICE_ID, 80);
|
// HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES;
|
// HDLUdpCore.initMulticastSocket6000();
|
}
|
|
|
/**
|
* 释放Socket
|
*/
|
public static void release() {
|
HDLUdpCore.closeSocket6008();
|
HDLUdpCore.closeSocket6000();
|
}
|
|
|
/**
|
* 处理CommandData并返回搜索或控制的有用信息
|
*
|
* @param getDatas
|
* @param commandType 命令类型
|
*/
|
public static void handle(UdpDataBean getDatas, int commandType) {
|
switch (commandType) {
|
case Configuration.DEVICES_SEARCH_BACK_COMMAND:
|
if (HandleSearch.isGetRcuIp) {
|
handleRcuIp(getDatas);
|
} else {
|
boolean isExit = false;
|
for (DevicesData value : realDevicesDataList) {
|
if (value.getSourceDeviceID() == getDatas.sourceDeviceID
|
&& value.getSourceSubnetID() == getDatas.sourceSubnetID) {
|
isExit = true;
|
break;
|
}
|
}
|
if (!isExit) {
|
handleSearchData(getDatas);
|
}
|
}
|
break;
|
// 控制设备
|
case Configuration.LIGHT_CTRL_BACK_COMMAND:
|
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.FRESH_AIR_CTRL_BACK_COMMAND: //20190709新增
|
handleCtrlData(getDatas);
|
break;
|
case Configuration.GEOTHERMAL_MODULE_CTRL_BACK_COMMAND://20190709新增
|
handleGeothermalCtrlData(getDatas);
|
break;
|
|
// 获取设备备注
|
case Configuration.DEVICES_READ_BACK_COMMAND:
|
|
if (isLogicCtrl) {
|
isLogicCtrl = false;
|
handleLogicAir(getDatas);
|
} else {
|
handleRemarkCurStateData(getDatas);
|
}
|
break;
|
|
// 获取设备状态
|
case Configuration.LIGHT_STATE_BACK_COMMAND:
|
case Configuration.CURTAIN_STATE_BACK_COMMAND:
|
case Configuration.AIR_STATE_BACK_COMMAND:
|
case Configuration.SENSOR_STATE_BACK_COMMAND:
|
handleStateData(getDatas);
|
break;
|
//获取新风设备状态 20190709新增
|
case Configuration.FRESH_AIR_STATE_BACK_COMMAND:
|
handleFreshAirStateData(getDatas);
|
break;
|
//获取地热设备状态
|
case Configuration.GEOTHERMAL_MODULE_STATE_BACK_COMMAND:
|
handleGeothermalStateData(getDatas);
|
break;
|
|
case Configuration.AIR_HVAC_STATE_BACK_COMMAND:
|
handleRcuAirCastData(getDatas);
|
break;
|
case Configuration.RCU_ROOM_CAST_COMMAND:
|
handleRcuLightCastData(getDatas);
|
break;
|
case Configuration.RCU_CURTAIN_CAST_COMMAND:
|
handleRcuCurtainCastData(getDatas);
|
break;
|
case Configuration.WARNING_COMMAND:
|
handleWarningData(getDatas);
|
break;
|
case Configuration.AUDIO_CTRL_READ_BACK_COMMAND:
|
case Configuration.AUDIO_MenuPlay_INSTRUCTION_BACK_COMMAND:
|
handleAudioData(getDatas);
|
break;
|
case Configuration.RCU_SEARCH_COMMAND:
|
handleRcuSearchData(getDatas);
|
break;
|
case Configuration.RCU_READ_SDK_INFO_COMMAND:
|
handleRcuReadInfo(getDatas);
|
break;
|
case Configuration.MANUAL_ADD_DEVICE_COMMAND:
|
boolean isExit = false;
|
for (DevicesData value : realDevicesDataList) {
|
if (value.getSourceDeviceID() == getDatas.sourceDeviceID
|
&& value.getSourceSubnetID() == getDatas.sourceSubnetID) {
|
isExit = true;
|
break;
|
}
|
}
|
if (!isExit) {
|
if (getDatas.port == Configuration.RCU_SEND_PORT) {
|
SPUtils.setParam(viewContext, SPUtils.KEY_HDL_RCU_IP, getDatas.ipAddress);
|
}
|
handleSearchData(getDatas);
|
HandleSearch.deviceListCallBack();//手动添加设备成功立刻返回
|
HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_DEVICE_BACK_COMMAND,
|
Crc.localSubnetID,
|
Crc.localDeviceID,
|
new byte[]{1},
|
getDatas.port, getDatas.ipAddress);
|
} else {
|
//添加失败,已经存在了相同的子网id、设备id
|
HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_DEVICE_BACK_COMMAND,
|
Crc.localSubnetID,
|
Crc.localDeviceID,
|
new byte[]{0},
|
getDatas.port, getDatas.ipAddress);
|
}
|
break;
|
case Configuration.MANUAL_ADD_REMARK_COMMAND:
|
handleRemarkCurStateData(getDatas);
|
HandleSearch.deviceListCallBack();//手动添加备注成功立刻返回
|
HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_REMARK_BACK_COMMAND,
|
Crc.localSubnetID,
|
Crc.localDeviceID,
|
new byte[]{1},
|
getDatas.port, getDatas.ipAddress);
|
break;
|
|
// 控制和尔泰设备
|
// case Configuration.HET_DEVICES:
|
// Log.d("djlHet", "Configuration.HET_DEVICES send");
|
// EventBus.getDefault().post(new HetDevicesCtrlEvent(getDatas.addBytes));
|
// break;
|
// 控制美的设备
|
// case Configuration.Midea_DEVICES:
|
// Log.d("djlMidea", "Configuration.Midea_DEVICES send");
|
// EventBus.getDefault().post(new MideaDevicesCtrlEvent(getDatas.addBytes));
|
// break;
|
// 控制Jav设备
|
// case Configuration.JAV_DEVICES:
|
// Log.d("djlJav", "Configuration.Jav_DEVICES send");
|
// Intent javIntent = new Intent();
|
// javIntent.setAction("com.hdl.jav.hdljavlib.action");
|
// javIntent.putExtra("HdlJav", getDatas.addBytes);
|
// viewContext.sendBroadcast(javIntent);
|
// break;
|
// case Configuration.GET_LOGIC_INFO:
|
// 处理逻辑模块信息
|
// handleLogicData(getDatas);
|
// break;
|
|
default:
|
break;
|
}
|
}
|
|
|
/**
|
* 处理RCU搜索数据
|
*
|
* @param getDatas
|
*/
|
private static void handleRcuSearchData(UdpDataBean getDatas) {
|
if (getDatas.addBytes.length == 2) {
|
sendRCULocalInfo(getDatas);
|
} else {
|
//RCU默认普通网络设备的设备id为0
|
for (int i = 2, len = getDatas.addBytes.length; i < len; i++) {
|
if (i % 2 == 0) {
|
if ((getDatas.addBytes[i] & 0xFF) == Crc.localSubnetID
|
&& (getDatas.addBytes[i + 1] & 0xFF) == 0
|
) {
|
sendRCULocalInfo(getDatas);
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 返回给RCU的本地SDK信息
|
*
|
* @param getDatas
|
*/
|
private static void sendRCULocalInfo(UdpDataBean getDatas) {
|
boolean isGetIp;
|
byte[] localIp = null;
|
try {
|
localIp = NetWorkUtil.getLocalHostLANAddress().getAddress();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (localIp == null) {
|
isGetIp = false;
|
localIp = new byte[]{(byte) 0, (byte) 0, 0, 0};
|
} else {
|
isGetIp = true;
|
}
|
|
byte[] routeIp = NetWorkUtil.getWifiInfoByte(viewContext, NetWorkUtil.GET_GATEWAY);
|
if (routeIp == null) {
|
routeIp = new byte[]{0, 0, 0, 0};
|
}
|
|
byte[] ipMac = NetWorkUtil.getWifiInfoByte(viewContext, NetWorkUtil.GET_MAC_ADDRESS);
|
if (ipMac == null) {
|
ipMac = new byte[]{0, 0, 0, 0, 0, 0};
|
}
|
|
byte[] netMask = NetWorkUtil.getWifiInfoByte(viewContext, NetWorkUtil.GET_NETMASK);
|
if (netMask == null) {
|
netMask = new byte[]{0, 0, 0, 0};
|
}
|
|
byte dchp = 0;
|
if (isGetIp) {
|
dchp = 1;
|
}
|
|
byte[] remarkByte;
|
String remarkString = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK);
|
|
remarkByte = StringUtil.stringtoBytes(remarkString);
|
|
byte[] addBytes = new byte[53];
|
addBytes[0] = getDatas.addBytes[0];
|
addBytes[1] = getDatas.addBytes[1];
|
addBytes[2] = (byte) 254;
|
addBytes[3] = 3;
|
addBytes[4] = 1;
|
addBytes[addBytes.length - 1] = (byte) Crc.localSubnetID;
|
addBytes[addBytes.length - 2] = dchp;
|
System.arraycopy(remarkByte, 0, addBytes, 13, remarkByte.length);
|
System.arraycopy(localIp, 0, addBytes, 33, 4);
|
System.arraycopy(routeIp, 0, addBytes, 37, 4);
|
System.arraycopy(ipMac, 0, addBytes, 41, 6);
|
System.arraycopy(netMask, 0, addBytes, 47, 4);
|
|
HDLCommand.cusSendCommand(Configuration.RCU_SEARCH_BACK_COMMAND,
|
getDatas.sourceSubnetID,
|
getDatas.sourceDeviceID,
|
addBytes,
|
getDatas.port, getDatas.ipAddress);
|
}
|
|
/**
|
* 处理RCU读本地SDK信息
|
*
|
* @param getDatas
|
*/
|
private static void handleRcuReadInfo(UdpDataBean getDatas) {
|
byte[] addByte = new byte[6];
|
addByte[0] = 1;
|
|
String localRcuIp = (String) SPUtils.getParam(viewContext, SPUtils.KEY_HDL_RCU_IP, "0.0.0.0");
|
if (localRcuIp.equals("0.0.0.0")) {
|
addByte[1] = 1;
|
} else {
|
addByte[1] = 2;
|
}
|
String[] ip = localRcuIp.split("\\.");
|
|
addByte[2] = (byte) Integer.parseInt(ip[0]);
|
addByte[3] = (byte) Integer.parseInt(ip[1]);
|
addByte[4] = (byte) Integer.parseInt(ip[2]);
|
addByte[5] = (byte) Integer.parseInt(ip[3]);
|
|
|
HDLCommand.cusSendCommand(Configuration.RCU_READ_SDK_INFO_BACK_COMMAND,
|
getDatas.sourceSubnetID,
|
getDatas.sourceDeviceID,
|
addByte,
|
getDatas.port, getDatas.ipAddress);
|
}
|
|
/**
|
* 处理RCU读本地SDK的ip地址
|
*
|
* @param getDatas
|
*/
|
private static void handleRcuIp(UdpDataBean getDatas) {
|
isGetRcuIpSuccess = true;
|
if (rcuIpList.size() == 0 || !rcuIpList.contains(getDatas.ipAddress)) {
|
HDLLog.info("rcuIp = " + getDatas.ipAddress);
|
rcuIpList.add(getDatas.ipAddress);
|
}
|
}
|
|
/**
|
* 处理搜索设备数据
|
*
|
* @param getDatas
|
*/
|
private static void handleSearchData(UdpDataBean getDatas) {
|
|
DevicesData devicesData = new DevicesData();
|
devicesData.setSourceSubnetID(getDatas.sourceSubnetID);
|
devicesData.setSourceDeviceID(getDatas.sourceDeviceID);
|
devicesData.setAddByte(getDatas.addBytes);
|
byte[] remarkByte;
|
if (getDatas.addBytes.length >= 22) {
|
remarkByte = new byte[20];
|
System.arraycopy(getDatas.addBytes, 2, remarkByte, 0, remarkByte.length);
|
} else {
|
remarkByte = new byte[getDatas.addBytes.length - 2];
|
System.arraycopy(getDatas.addBytes, 2, remarkByte, 0, getDatas.addBytes.length - 2);
|
}
|
|
String remarkStr = byte2String(remarkByte);
|
devicesData.setRemark(remarkStr);
|
boolean isExitData = DeviceParser.parse(getDatas.addBytes, getDatas.port, getDatas.ipAddress, devicesData, remarkStr);
|
String addData = "";
|
for (int i = 22, len = getDatas.addBytes.length; i < len; i++) {
|
addData += " arr" + i + " = " + (getDatas.addBytes[i] & 0xFF) + ",";
|
}
|
realDevicesDataList.add(devicesData);//记录所有的接收到设备,包括SDK不支持的设备种类。作用:作为发送第二次搜索命令时用到
|
HDLLog.info("所有设备列表 第 " + realDevicesDataList.size() + " 个模块 "
|
+ " \n源子网号 = " + (getDatas.sourceSubnetID)
|
+ " \n源设备号 = " + (getDatas.sourceDeviceID)
|
+ " \n模块备注 = " + devicesData.getRemark()
|
+ " \n附加数据 = " + addData
|
|
);
|
|
// 判断是否已经存在在设备列表,若存在则过滤
|
if (isExitData) {
|
devicesDataList.add(devicesData);//记录所有的接收到设备,不包括SDK不支持的设备种类
|
// 过滤掉背景音乐,背景音乐没有备注返回
|
if (devicesDataList.get(devicesDataList.size() - 1).getAppliancesInfoList().get(0).getBigType() != Configuration.AUDIO_BIG_TYPE
|
) {
|
for (int i = 0, len = devicesDataList.get(devicesDataList.size() - 1).getAppliancesInfoList().size(); i < len; i++) {
|
ListRemarks listRemarksTemp = new ListRemarks();
|
listRemarksTemp.setCallBack(false);
|
listRemarksTemp.setAppliancesInfo(devicesDataList.get(devicesDataList.size() - 1).getAppliancesInfoList().get(i));
|
|
listRemarks.add(listRemarksTemp);
|
}
|
}
|
|
// HDLCommand.HDLgetDevRemarks(devicesDataList.get(devicesDataList.size()-1).getAppliancesInfoList());
|
//打印设备
|
// String addData = "";
|
// for(int i = 0,len = getDatas.AddBytes.length;i<len;i++){
|
// addData += " arr"+i+" = "+(getDatas.AddBytes[i] & 0xFF)+",";
|
// }
|
String deviceName = "";
|
for (int i = 0, len = devicesData.getAppliancesInfoList().size(); i < len; i++) {
|
deviceName += " " + devicesData.getAppliancesInfoList().get(i).getDeviceName() + " ";
|
}
|
|
|
HDLLog.info("\n --------> HDL SDK支持的设备列表 第 " + devicesDataList.size() + " 个模块 "
|
+ " \n源子网号 = " + (getDatas.sourceSubnetID)
|
+ " \n源设备号 = " + (getDatas.sourceDeviceID)
|
+ " \n目标子网号 = " + (getDatas.desSubnetID)
|
+ " \n目标设备号 = " + (getDatas.desDeviceID)
|
+ " \n源模块各回路类型 = " + deviceName
|
+ " \n模块备注 = " + devicesData.getRemark()
|
|
);
|
}
|
}
|
|
/**
|
* 处理设备控制数据
|
*
|
* @param getDatas
|
*/
|
private static void handleCtrlData(UdpDataBean getDatas) {
|
switch (getDatas.command) {
|
case Configuration.LIGHT_CTRL_BACK_COMMAND:
|
if (TextUtils.isEmpty(HandleSearch.rcuIp)) {
|
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).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {
|
AppliancesInfo lightInfo = infos.get(j);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[2] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[2] & 0xFF);
|
LightCtrlBackInfo info = new LightCtrlBackInfo();
|
info.setParentRemarks(lightInfo.getParentRemarks());
|
info.setAppliancesInfo(lightInfo);
|
info.setRemarks(lightInfo.getRemarks());
|
info.setChannelNum(getDatas.addBytes[0] & 0xFF);
|
// info.setIsSuccess(getDatas.AddBytes[1] & 0xFF);
|
info.setBrightness(getDatas.addBytes[2] & 0xFF);
|
// info.setChannelCount(getDatas.AddBytes[3] & 0xFF);
|
// info.setDeviceChannelCount(getDatas.AddBytes[4] & 0xFF);
|
// isLightCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
EventBus.getDefault().post(new LightFeedBackEvent(info, true));
|
break outter;
|
}
|
|
}
|
}
|
}
|
|
|
} else {
|
if (getDatas.addBytes.length != 0) {
|
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).getPhysicsChannelNum() == (getDatas.addBytes[0] & 0xFF)
|
) {
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[2] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[2] & 0xFF);
|
for (int k = 0; k < rcuLightList.size(); k++) {
|
if (devicesDataList.get(i).getAppliancesInfoList().get(j).getPhysicsChannelNum() == rcuLightList.get(k).getPhysicsChanelNum()
|
) {
|
rcuLightList.get(k).setCurState(getDatas.addBytes[2] & 0xFF);
|
break;
|
}
|
}
|
AppliancesInfo lightInfo1 = infos.get(j);
|
lightInfo1.setCurState(getDatas.addBytes[2] & 0xFF);
|
LightCtrlBackInfo info1 = new LightCtrlBackInfo();
|
info1.setParentRemarks(lightInfo1.getParentRemarks());
|
info1.setAppliancesInfo(lightInfo1);
|
info1.setRemarks(lightInfo1.getRemarks());
|
info1.setChannelNum(lightInfo1.getChannelNum());
|
// info1.setIsSuccess(getDatas.AddBytes[1] & 0xFF);
|
info1.setBrightness(getDatas.addBytes[2] & 0xFF);
|
info1.setChannelCount(getDatas.addBytes[3] & 0xFF);
|
info1.setDeviceChannelCount(getDatas.addBytes[4] & 0xFF);
|
// isLightCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
EventBus.getDefault().post(new LightFeedBackEvent(info1, true));
|
break outter;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
break;
|
case Configuration.CURTAIN_CTRL_BACK_COMMAND:
|
// if (TextUtils.isEmpty(HandleSearch.rcuIp)){
|
//
|
// }else{
|
// AppliancesInfo curtainInfo = new AppliancesInfo();
|
// 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.CURTAIN_BIG_TYPE
|
// && infos.get(j).getChannelNum() == (getDatas.addBytes[1] & 0xFF)) {
|
// for (int k = 0; k < rcuCurtainList.size(); k++) {
|
// if (devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum() == rcuCurtainList.get(k).getChanelNum()
|
// && devicesDataList.get(i).getAppliancesInfoList().get(j).getLittleType() == rcuCurtainList.get(k).getLittleType()
|
// ) {
|
// int state;
|
// switch (getDatas.addBytes[2] & 0xFF) {
|
// case 0:
|
// state = CurtainCtrlParser.curtainPause;
|
// break;
|
// case 1:
|
// state = CurtainCtrlParser.curtainOn;
|
// break;
|
// case 2:
|
// state = CurtainCtrlParser.curtainOff;
|
// break;
|
// default:
|
// state = 0;
|
// break;
|
// }
|
// rcuCurtainList.get(k).setCurState(state);
|
// devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[2] & 0xFF);
|
//// HDLLog.info("控制 rcuCurtainList回路号:"+rcuCurtainList.get(k).getChanelNum()
|
//// + " state = "+rcuCurtainList.get(k).getCurState()
|
//// );
|
// }
|
// }
|
//
|
// curtainInfo = infos.get(j);
|
// }
|
//
|
// }
|
// }
|
// }
|
// CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo();
|
// curtainCtrlBackInfo.setRemarks(curtainInfo.getRemarks());
|
// curtainCtrlBackInfo.setParentRemarks(curtainInfo.getParentRemarks());
|
// curtainCtrlBackInfo.setAppliancesInfo(curtainInfo);
|
// curtainCtrlBackInfo.setNum(getDatas.addBytes[1] & 0xFF);
|
// curtainCtrlBackInfo.setState(getDatas.addBytes[2] & 0xFF);
|
// isCurtainCtrlSuccess = true;
|
// EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, true));
|
// }
|
|
|
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();
|
inner:
|
for (int j = 0, len2 = infos.size(); j < len2; j++) {
|
AppliancesInfo curtainInfo;
|
if ((getDatas.addBytes[0] & 0xFF) >= 17) {
|
if (((getDatas.addBytes[0] & 0xFF) - 16) == infos.get(j).getChannelNum()) {
|
curtainInfo = infos.get(j);
|
} else {
|
continue inner;
|
}
|
} else {
|
if ((getDatas.addBytes[0] & 0xFF) == infos.get(j).getChannelNum()) {
|
curtainInfo = infos.get(j);
|
} else {
|
continue inner;
|
}
|
}
|
|
CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo();
|
curtainCtrlBackInfo.setRemarks(curtainInfo.getRemarks());
|
curtainCtrlBackInfo.setParentRemarks(curtainInfo.getParentRemarks());
|
curtainCtrlBackInfo.setAppliancesInfo(curtainInfo);
|
// isCurtainCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
|
if (curtainInfo.getDeviceType() == HDLApConfig.TYPE_CURTAIN_GLYSTRO
|
|| curtainInfo.getDeviceType() == HDLApConfig.TYPE_CURTAIN_ROLLER) {
|
if ((getDatas.addBytes[0] & 0xFF) >= 17) {
|
int curState = getDatas.addBytes[1] & 0xFF;
|
if (curState == 1) {
|
//这个判断很傻,窗帘关到百分比为0,会跳到1返回回来,只能强制改为0
|
curState = 0;
|
}
|
if (curState == 99) {
|
curState = 100;
|
}
|
curtainCtrlBackInfo.setState(curState);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(curState);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(curState);
|
curtainCtrlBackInfo.setNum((getDatas.addBytes[0] & 0xFF) - 16);
|
EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, true));
|
}
|
}
|
if (curtainInfo.getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) {
|
if ((getDatas.addBytes[0] & 0xFF) < 17) {
|
curtainCtrlBackInfo.setState(getDatas.addBytes[1] & 0xFF);
|
curtainCtrlBackInfo.setNum(getDatas.addBytes[0] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[1] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[1] & 0xFF);
|
EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, true));
|
}
|
}
|
|
|
break outter;
|
|
|
}
|
}
|
}
|
|
break;
|
case Configuration.AIR_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 (infos.get(j).getDeviceType() == HDLApConfig.TYPE_AC_PANEL) {
|
// airInfo = infos.get(j);//一般只有一个面板
|
// 如果有多个空调面板,这将会出错
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(infos.get(j));
|
// isACCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
if ((getDatas.addBytes[0] & 0xFF) == AirCtrlParser.airMode) {
|
airCtrlBackInfo.setCurState(new byte[]{getDatas.addBytes[0], getDatas.addBytes[1]});
|
byte[] airCurState = devicesDataList.get(i).getAppliancesInfoList().get(j).getArrCurState();
|
switch (getDatas.addBytes[0] & 0xff) {
|
case 3:
|
//开关
|
airCurState[0] = getDatas.addBytes[1];
|
break;
|
case 4:
|
//制冷温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 5:
|
//风速
|
airCurState[3] = getDatas.addBytes[1];
|
break;
|
case 6:
|
//模式
|
airCurState[1] = getDatas.addBytes[1];
|
break;
|
case 7:
|
//制热温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 8:
|
//自动温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 9:
|
//上升温度
|
airCurState[2] = (byte) ((airCurState[2] & 0xff) + (getDatas.addBytes[1] & 0xff));
|
break;
|
case 10:
|
//下降温度
|
airCurState[2] = (byte) ((airCurState[2] & 0xff) - (getDatas.addBytes[1] & 0xff));
|
break;
|
default:
|
break;
|
}
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setArrCurState(airCurState);
|
} else {
|
airCtrlBackInfo.setCurState(getDatas.addBytes);
|
byte[] airCurState = devicesDataList.get(i).getAppliancesInfoList().get(j).getArrCurState();
|
switch (getDatas.addBytes[0] & 0xff) {
|
case 3:
|
//开关
|
airCurState[0] = getDatas.addBytes[1];
|
break;
|
case 4:
|
//制冷温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 5:
|
//风速
|
airCurState[3] = getDatas.addBytes[1];
|
break;
|
case 6:
|
//模式
|
airCurState[1] = getDatas.addBytes[1];
|
break;
|
case 7:
|
//制热温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 8:
|
//自动温度
|
airCurState[2] = getDatas.addBytes[1];
|
break;
|
case 9:
|
//上升温度
|
airCurState[2] = (byte) ((airCurState[2] & 0xff) + (getDatas.addBytes[1] & 0xff));
|
break;
|
case 10:
|
//下降温度
|
airCurState[2] = (byte) ((airCurState[2] & 0xff) - (getDatas.addBytes[1] & 0xff));
|
break;
|
default:
|
break;
|
}
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setArrCurState(airCurState);
|
}
|
//上升温度、下降温度不返回。
|
if ((airCtrlBackInfo.getCurState()[0] & 0xff) != 9 && (airCtrlBackInfo.getCurState()[0] & 0xff) != 10) {
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
}
|
|
break outter;
|
}
|
}
|
}
|
}
|
|
|
break;
|
case Configuration.AIR_HVAC_CTRL_BACK_COMMAND:
|
outter:
|
for (int devIndex = 0, len = devicesDataList.size(); devIndex < len; devIndex++) {
|
if (devicesDataList.get(devIndex).getSourceSubnetID() == getDatas.sourceSubnetID
|
&& devicesDataList.get(devIndex).getSourceDeviceID() == getDatas.sourceDeviceID
|
) {
|
List<AppliancesInfo> infos = devicesDataList.get(devIndex).getAppliancesInfoList();
|
for (int appIndex = 0, len2 = infos.size(); appIndex < len2; appIndex++) {
|
if ((infos.get(appIndex).getDeviceType() == HDLApConfig.TYPE_AC_HVAC
|
|| infos.get(appIndex).getDeviceType() == HDLApConfig.TYPE_AC_COOLMASTER
|
|| infos.get(appIndex).getDeviceType() == HDLApConfig.TYPE_AC_INFRARED)
|
&& infos.get(appIndex).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {
|
// String airbytes = "193b 附加数据:";
|
// for (int i = 0; i < getDatas.addBytes.length; i++) {
|
// airbytes += (getDatas.addBytes[i] & 0xff) + ",";
|
// }
|
// HDLLog.info( airbytes);
|
AppliancesInfo airInfo = infos.get(appIndex);
|
int indexI = devIndex;
|
int indexJ = appIndex;
|
|
byte[] oldAirInfo = airInfo.getArrCurState();
|
// switch (getDatas.addBytes[0] & 0xFF) {
|
// case 1:
|
// oldAirInfo = air1Info;
|
// break;
|
// case 2:
|
// oldAirInfo = air2Info;
|
// break;
|
// case 3:
|
// oldAirInfo = air3Info;
|
// break;
|
// case 4:
|
// oldAirInfo = air4Info;
|
// break;
|
// default:
|
// oldAirInfo = new byte[1];
|
// break;
|
// }
|
byte[] newAirInfo = getDatas.addBytes;
|
byte[] curAirInfo = new byte[]{0};
|
boolean isModeChange = false;
|
if (oldAirInfo == null || oldAirInfo.length == 0) {
|
oldAirInfo = AirCtrlParser.getNewAcByte();
|
|
}
|
setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
for (int oldAirInedx = 0; oldAirInedx < oldAirInfo.length; oldAirInedx++) {
|
if (oldAirInedx == 0) {
|
// if (oldAirInfo[0] != newAirInfo[8]) {//2019 去掉相同开关状态判断,解决开状态下,调用开命令状态下,不停重发问题
|
oldAirInfo[0] = newAirInfo[8];
|
curAirInfo = new byte[]{AirCtrlParser.airSwich, newAirInfo[8]};
|
if (curAirInfo.length > 1) {
|
devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo);
|
airInfo.setArrCurState(oldAirInfo);
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(airInfo);
|
airCtrlBackInfo.setCurState(curAirInfo);
|
// isACCtrlSuccess = true;
|
// setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
|
}
|
// }
|
} else if (oldAirInedx == 1) {
|
// int mode = ((newAirInfo[4] & 0xf0) >> 4);
|
int mode = newAirInfo[9] & 0xff;
|
if (oldAirInfo[1] != (byte) mode) {
|
isModeChange = true;
|
oldAirInfo[1] = (byte) mode;
|
curAirInfo = new byte[]{AirCtrlParser.airMode, (byte) mode};
|
if (curAirInfo.length > 1) {
|
devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo);
|
airInfo.setArrCurState(oldAirInfo);
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(airInfo);
|
airCtrlBackInfo.setCurState(curAirInfo);
|
// isACCtrlSuccess = true;
|
// setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
|
}
|
}
|
} else if (oldAirInedx == 2) {
|
int mode = newAirInfo[9] & 0xff;
|
byte newAirTem = newAirInfo[11];
|
|
|
if (oldAirInfo[2] != newAirTem) {
|
oldAirInfo[2] = newAirTem;
|
switch (mode) {
|
case 0:
|
curAirInfo = new byte[]{AirCtrlParser.refTem, newAirTem};
|
break;
|
case 1:
|
curAirInfo = new byte[]{AirCtrlParser.heatTem, newAirTem};
|
break;
|
case 3:
|
curAirInfo = new byte[]{AirCtrlParser.autoTem, newAirTem};
|
break;
|
case 4:
|
curAirInfo = new byte[]{AirCtrlParser.dehumTem, newAirTem};
|
break;
|
}
|
if (curAirInfo.length > 1) {
|
devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo);
|
airInfo.setArrCurState(oldAirInfo);
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(airInfo);
|
airCtrlBackInfo.setCurState(curAirInfo);
|
// isACCtrlSuccess = true;
|
// setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
|
}
|
}
|
} else if (oldAirInedx == 3) {
|
// int speed = (newAirInfo[4] & 0x0f);//获取低4位
|
int speed = newAirInfo[10];
|
if (oldAirInfo[3] != (byte) speed) {
|
oldAirInfo[3] = (byte) speed;
|
curAirInfo = new byte[]{AirCtrlParser.airSpeed, (byte) speed};
|
if (curAirInfo.length > 1) {
|
devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo);
|
airInfo.setArrCurState(oldAirInfo);
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(airInfo);
|
airCtrlBackInfo.setCurState(curAirInfo);
|
// isACCtrlSuccess = true;
|
// setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
|
}
|
}
|
}
|
}
|
|
|
// if (curAirInfo.length > 1) {
|
// devicesDataList.get(indexI).getAppliancesInfoList().get(indexJ).setArrCurState(oldAirInfo);
|
// airInfo.setArrCurState(oldAirInfo);
|
// AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
// airCtrlBackInfo.setAppliancesInfo(airInfo);
|
// airCtrlBackInfo.setCurState(curAirInfo);
|
//// isACCtrlSuccess = true;
|
// setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
|
// EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
|
//
|
// }
|
|
|
break outter;
|
}
|
}
|
}
|
}
|
|
|
break;
|
case Configuration.LOGIC_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 ((infos.get(j).getBigType() == Configuration.LOGIC_BIG_TYPE
|
|| infos.get(j).getBigType() == Configuration.GLOBAL_LOGIC_BIG_TYPE)
|
&& infos.get(j).getLogicMode().getAreaNum() == (getDatas.addBytes[0] & 0xFF)
|
&& infos.get(j).getLogicMode().getAreaSceneNum() == (getDatas.addBytes[1] & 0xFF)
|
) {
|
AppliancesInfo sceneInfo = infos.get(j);
|
LogicMode logicMode = new LogicMode();
|
logicMode.setAreaNum(getDatas.addBytes[0] & 0xFF);
|
logicMode.setAreaSceneNum(getDatas.addBytes[1] & 0xFF);
|
sceneInfo.setLogicMode(logicMode);
|
|
LogicCtrlBackInfo logicCtrlBackInfo = new LogicCtrlBackInfo();
|
logicCtrlBackInfo.setAppliancesInfo(sceneInfo);
|
logicCtrlBackInfo.setAreaNum(getDatas.addBytes[0] & 0xFF);
|
logicCtrlBackInfo.setSceneNum(getDatas.addBytes[1] & 0xFF);
|
// isSceneCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
EventBus.getDefault().post(new LogicFeedBackEvent(logicCtrlBackInfo, true));
|
break outter;
|
}
|
}
|
}
|
}
|
|
//2019-07-09 新增新风系统控制回调
|
case Configuration.FRESH_AIR_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 (infos.get(j).getBigType() == Configuration.FRESH_AIR_BIG_TYPE
|
&& infos.get(j).getDeviceType() == HDLApConfig.TYPE_FRESH_AIR
|
&& infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {
|
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setFeedbackState(getDatas.addBytes);
|
AppliancesInfo mFreshAirInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
FreshAirBackInfo info = new FreshAirBackInfo(mFreshAirInfo);
|
// isFreshAirCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
EventBus.getDefault().post(new FreshAirFeedBackEvent(info, true));
|
break outter;
|
}
|
|
}
|
}
|
}
|
|
break;
|
}
|
}
|
|
/**
|
* 处理地热设备控制数据
|
* 20190710
|
*
|
* @param getDatas
|
*/
|
private static void handleGeothermalCtrlData(UdpDataBean getDatas) {
|
switch (getDatas.command) {
|
//2019-07-09 地热模块
|
case Configuration.GEOTHERMAL_MODULE_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.GEOTHERMAL_BIG_TYPE
|
&& infos.get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_MODULE
|
&& infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {
|
if (getDatas.addBytes.length >= 8) {
|
byte[] getBytes = devicesDataList.get(i).getAppliancesInfoList().get(j).getFeedbackState();
|
if (getBytes == null || getBytes.length < 10) {
|
getBytes = new byte[10];
|
}
|
System.arraycopy(getDatas.addBytes, 0, getBytes, 0, 8);//控制地热状态反馈,只取前8位数据
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setFeedbackState(getBytes);
|
AppliancesInfo mInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
|
GeothermalBackInfo info = new GeothermalBackInfo(mInfo, true);
|
// isGeothermalCtrlSuccess = true;
|
setDeviceCtrlSuccessStateWithInfo(infos.get(j), true);
|
EventBus.getDefault().post(new GeothermalFeedBackEvent(info, EventCode.SUCCESS));
|
} else {
|
|
// AppliancesInfo mInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
// GeothermalBackInfo info = new GeothermalBackInfo(mInfo, true);
|
// isGeothermalCtrlSuccess = true;
|
// EventBus.getDefault().post(new GeothermalFeedBackEvent(info, EventCode.DATAEMPTY));
|
|
HDLLog.E("控制地热状态反馈数据异常");
|
}
|
break outter;
|
}
|
}
|
}
|
}
|
}
|
|
break;
|
}
|
}
|
|
/**
|
* 处理RCU灯光广播消息
|
*
|
* @param getDatas
|
*/
|
private static void handleRcuLightCastData(UdpDataBean getDatas) {
|
for (int i = 0; i < devicesDataList.size(); i++) {
|
if (devicesDataList.get(i).getSourceSubnetID() == getDatas.sourceSubnetID
|
&& devicesDataList.get(i).getSourceDeviceID() == getDatas.sourceDeviceID
|
) {
|
for (int j = 0; j < devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
switch (getDatas.command) {
|
case Configuration.RCU_ROOM_CAST_COMMAND:
|
if (devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.LIGTH_BIG_TYPE
|
) {
|
for (int m = 13; m < getDatas.addBytes.length; m++) {
|
for (int n = 0; n < rcuLightList.size(); n++) {
|
if (rcuLightList.get(n).getPhysicsChanelNum() == (m - 12)
|
&& rcuLightList.get(n).getCurState() != getDatas.addBytes[m]
|
&& rcuLightList.get(n).getPhysicsChanelNum() == devicesDataList.get(i).getAppliancesInfoList().get(j).getPhysicsChannelNum()
|
) {
|
rcuLightList.get(n).setCurState(getDatas.addBytes[m]);
|
// HDLLog.info( "灯光物理回路:" + rcuLightList.get(n).getPhysicsChanelNum() + " 状态:" + rcuLightList.get(n).getCurState());
|
AppliancesInfo info = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
info.setCurState(getDatas.addBytes[m]);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[m]);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[m] & 0xff);
|
EventBus.getDefault().post(new DeviceStateEvent(info, true));
|
}
|
}
|
}
|
}
|
break;
|
// case Configuration.RCU_CURTAIN_CAST_COMMAND:
|
// if (devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.CURTAIN_BIG_TYPE
|
// ) {
|
// for (int l = 6; l < getDatas.addBytes.length; l++) {
|
// for (int k = 0; k < rcuCurtainList.size(); k++) {
|
// if (rcuCurtainList.get(k).getLittleType() == devicesDataList.get(i).getAppliancesInfoList().get(j).getLittleType()
|
// && rcuCurtainList.get(k).getChanelNum() == devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()
|
// && rcuCurtainList.get(k).getChanelNum() == (l - 5)
|
// ) {
|
// int state = 0;
|
// switch (getDatas.addBytes[l]) {
|
// case 0:
|
// state = CurtainCtrlParser.curtainPause;
|
// break;
|
// case 1:
|
// state = CurtainCtrlParser.curtainOn;
|
// break;
|
// case 2:
|
// state = CurtainCtrlParser.curtainOff;
|
// break;
|
// }
|
// if (rcuCurtainList.get(k).getCurState() != state && state != CurtainCtrlParser.curtainPause) {
|
// rcuCurtainList.get(k).setCurState(state);
|
// HDLLog.info( "广播 rcuCurtainList回路号:" + rcuCurtainList.get(k).getChanelNum()
|
// + " state = " + rcuCurtainList.get(k).getCurState());
|
// AppliancesInfo info = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
// info.setCurState(state);
|
// EventBus.getDefault().post(new DeviceStateEvent(info, true));
|
// }
|
// }
|
// }
|
// }
|
//
|
//
|
// }
|
// break;
|
|
default:
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 处理RCU窗帘广播消息
|
*
|
* @param getDatas
|
*/
|
private static void handleRcuCurtainCastData(UdpDataBean getDatas) {
|
outter:
|
for (int i = 0; i < devicesDataList.size(); i++) {
|
if (devicesDataList.get(i).getSourceSubnetID() == getDatas.sourceSubnetID
|
&& devicesDataList.get(i).getSourceDeviceID() == getDatas.sourceDeviceID
|
) {
|
for (int j = 0; j < devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
|
if (devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.CURTAIN_BIG_TYPE) {
|
for (int k = 0; k < 6; k++) {
|
if (devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum() == (k + 1)) {
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[k] & 0xff);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[k] & 0xff);
|
AppliancesInfo info = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
int state = 0;
|
switch (getDatas.addBytes[k]) {
|
case 0:
|
state = CurtainCtrlParser.curtainPause;
|
break;
|
case 1:
|
state = CurtainCtrlParser.curtainOn;
|
break;
|
case 2:
|
state = CurtainCtrlParser.curtainOff;
|
break;
|
}
|
info.setCurState(state);
|
// HDLLog.info( "2099 附加数据:" + Arrays.toString(getDatas.addBytes));
|
EventBus.getDefault().post(new DeviceStateEvent(info, true));
|
}
|
}
|
}
|
}
|
break outter;
|
}
|
}
|
}
|
|
/**
|
* 处理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];
|
//
|
//
|
// 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;
|
//
|
// }
|
}
|
}
|
}
|
}
|
}
|
|
|
}
|
|
|
}
|
|
|
/**
|
* 处理家居空调广播消息
|
*
|
* @param getDatas
|
* @param airInfo
|
* @param airIndex
|
* @param oldInfo
|
*/
|
private static void handleAirCastData(UdpDataBean getDatas, final byte[] airInfo, int airIndex, final AppliancesInfo oldInfo) {
|
if (airInfo[0] != getDatas.addBytes[1 + airIndex * 11]) {
|
|
// EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSwich, airInfo[0]});
|
// HDLLog.info( "0x209A in 空调开关改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 500);
|
}
|
|
// HDLLog.info( "airIndex = " + airIndex + " 209a 模式值 = " + ((getDatas.addBytes[3 + airIndex * 11] & 0xf0) >> 4) + " 或 = " + ((getDatas.addBytes[7 + airIndex * 11] & 0xf0) >> 4));
|
if (airInfo[1] != (byte) ((getDatas.addBytes[3 + airIndex * 11] & 0xf0) >> 4)) {
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airMode, airInfo[1]});
|
// HDLLog.info( "0x209A in 空调模式改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1000);
|
}
|
|
|
switch (airInfo[1] & 0xff) {
|
case 0:
|
if (airInfo[2] != getDatas.addBytes[2 + airIndex * 11]) {
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.refTem, airInfo[2]});
|
// HDLLog.info( "0x209A in 空调温度改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1500);
|
}
|
|
break;
|
case 1:
|
if (airInfo[2] != getDatas.addBytes[6 + airIndex * 11]) {
|
// airInfo[2] = getDatas.addBytes[6 + airIndex * 11];
|
|
// EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.heatTem, airInfo[2]});
|
// HDLLog.info( "0x209A in 空调温度改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1500);
|
}
|
|
break;
|
case 3:
|
if (airInfo[2] != getDatas.addBytes[8 + airIndex * 11]) {
|
// airInfo[2] = getDatas.addBytes[8 + airIndex * 11];
|
|
// EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.autoTem, airInfo[2]});
|
// HDLLog.info( "0x209A in 空调温度改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1500);
|
}
|
|
break;
|
case 4:
|
if (airInfo[2] != getDatas.addBytes[9 + airIndex * 11]) {
|
// airInfo[2] = getDatas.addBytes[9 + airIndex * 11];
|
|
// EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.dehumTem, airInfo[2]});
|
// HDLLog.info( "0x209A in 空调温度改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1500);
|
}
|
|
break;
|
}
|
|
// HDLLog.info( "airInfo[3] = " + (airInfo[3] & 0xff) + " 第3位 低4位风速 = "+(getDatas.addBytes[3 + airIndex * 11] & 0x0f));
|
// HDLLog.info( "airInfo[3] = " + (airInfo[3] & 0xff) + " 第7位 低4位风速 = "+(getDatas.addBytes[7 + airIndex * 11] & 0x0f));
|
if (airInfo[3] != (byte) (getDatas.addBytes[3 + airIndex * 11] & 0x0f)) {
|
// airInfo[3] = (byte) (getDatas.addBytes[3 + airIndex * 11] & 0x0f);
|
|
// EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
|
final AppliancesInfo newInfo = oldInfo;
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, airInfo[3]});
|
// HDLLog.info( "空调风速改变" + " appliancesInfo subid = " + newInfo.getDeviceSubnetID()
|
// + " devID = " + newInfo.getDeviceDeviceID() + " 回路号:" + newInfo.getChannelNum() + " devType" + newInfo.getDeviceType());
|
// HDLLog.info( "发送空调改变风速data = " + Arrays.toString(newInfo.getArrCurState()));
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 2000);
|
}
|
|
//室温、摆风没有返回。下个版本需要考虑
|
if (airInfo[4] != getDatas.addBytes[5 + airIndex * 11]) {
|
// airInfo[4] = getDatas.addBytes[5 + airIndex * 11];
|
}
|
|
if (airInfo[5] != getDatas.addBytes[10 + airIndex * 11]) {
|
// airInfo[5] = getDatas.addBytes[10 + airIndex * 11];
|
}
|
}
|
|
// private static void getAirInfo(final AppliancesInfo hvacInfo) {
|
//
|
// isLogicCtrl = true;
|
// timerAir = new Timer();
|
// timerAir.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// if (isLogicCtrl) {
|
// HDLCommand.HDLgetAirInfo(hvacInfo);
|
// } else {
|
// timerAir.cancel();
|
// }
|
//
|
// }
|
// }, 100, 500);
|
// }
|
|
|
/**
|
* 处理逻辑空调数据
|
*
|
* @param getDatas
|
*/
|
private static void handleLogicAir(UdpDataBean getDatas) {
|
AppliancesInfo newInfo1 = null;
|
for (int devPos = 0, len = devicesDataList.size(); devPos < len; devPos++) {
|
if (devicesDataList.get(devPos).getSourceSubnetID() == getDatas.sourceSubnetID
|
&& devicesDataList.get(devPos).getSourceDeviceID() == getDatas.sourceDeviceID
|
) {
|
List<AppliancesInfo> infos = devicesDataList.get(devPos).getAppliancesInfoList();
|
for (int appPos = 0, len2 = infos.size(); appPos < len2; appPos++) {
|
switch (infos.get(appPos).getBigType()) {
|
case Configuration.AIR_BIG_TYPE:
|
switch (infos.get(appPos).getLittleType()) {
|
case 0:
|
byte[] airInfo = new byte[6];
|
System.arraycopy(getDatas.addBytes, 23, airInfo, 0, airInfo.length);
|
// switch (getDatas.addBytes[2] & 0xFF) {
|
// case 1:
|
// air1Info = airInfo;
|
// break;
|
// case 2:
|
// air2Info = airInfo;
|
// break;
|
// case 3:
|
// air3Info = airInfo;
|
// break;
|
// case 4:
|
// air4Info = airInfo;
|
// break;
|
//
|
// }
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setArrCurState(airInfo);
|
newInfo1 = devicesDataList.get(devPos).getAppliancesInfoList().get(appPos);
|
break;
|
}
|
break;
|
}
|
}
|
}
|
}
|
|
// getAppInfo(newInfo);
|
final AppliancesInfo newInfo = newInfo1;
|
if (newInfo == null) {
|
return;
|
}
|
final byte[] airCurInfo = newInfo1.getArrCurState();
|
// switch (newInfo.getChannelNum()) {
|
// case 1:
|
// airCurInfo = air1Info;
|
// break;
|
// case 2:
|
// airCurInfo = air2Info;
|
// break;
|
// case 3:
|
// airCurInfo = air3Info;
|
// break;
|
// case 4:
|
// airCurInfo = air4Info;
|
// break;
|
// default:
|
// airCurInfo = new byte[]{0, 0};
|
// break;
|
// }
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSwich, airCurInfo[0]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 1000);
|
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airMode, airCurInfo[1]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 2000);
|
|
|
switch (airCurInfo[1] & 0xFF) {
|
case 0:
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.refTem, airCurInfo[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 3000);
|
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, airCurInfo[3]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 4000);
|
|
break;
|
case 1:
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.heatTem, airCurInfo[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 3000);
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, airCurInfo[3]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 4000);
|
|
break;
|
case 2:
|
// 通风模式无温度
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, airCurInfo[3]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 3000);
|
|
break;
|
case 3:
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.autoTem, airCurInfo[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 3000);
|
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, airCurInfo[3]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 4000);
|
|
|
break;
|
case 4:
|
//抽湿模式无风速
|
new Timer().schedule(new TimerTask() {
|
@Override
|
public void run() {
|
newInfo.setArrCurState(new byte[]{AirCtrlParser.dehumTem, airCurInfo[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(newInfo, true));
|
}
|
}, 3000);
|
|
break;
|
}
|
}
|
|
/**
|
* 处理所有备注数据、设置当前设备状态
|
*
|
* @param getDatas
|
*/
|
private static void handleRemarkCurStateData(UdpDataBean getDatas) {
|
outter:
|
for (int devPos = 0, len = devicesDataList.size(); devPos < len; devPos++) {
|
if (devicesDataList.get(devPos).getSourceSubnetID() == getDatas.sourceSubnetID
|
&& devicesDataList.get(devPos).getSourceDeviceID() == getDatas.sourceDeviceID
|
) {
|
List<AppliancesInfo> infos = devicesDataList.get(devPos).getAppliancesInfoList();
|
for (int appPos = 0, len2 = infos.size(); appPos < len2; appPos++) {
|
if ((infos.get(appPos).getBigType()) == (getDatas.addBytes[0] & 0xFF)
|
&& ((infos.get(appPos).getLittleType()) == (getDatas.addBytes[1] & 0xFF))
|
&& ((infos.get(appPos).getChannelNum()) == (getDatas.addBytes[2] & 0xFF))
|
) {
|
byte[] remark = new byte[20];
|
//硬件的字节流协议提供有误,收到某硬件提供备注不足20长度,解决这问题的权宜之计
|
int length;
|
if (getDatas.addBytes.length < 20) {
|
length = getDatas.addBytes.length;
|
} else {
|
length = remark.length;
|
}
|
System.arraycopy(getDatas.addBytes, 3, remark, 0, length);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setRemarks(byte2String(remark));
|
|
switch (infos.get(appPos).getBigType()) {
|
case Configuration.LOGIC_BIG_TYPE:
|
case Configuration.GLOBAL_LOGIC_BIG_TYPE:
|
LogicMode logicMode = new LogicMode();
|
logicMode.setAreaNum(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
logicMode.setAreaSceneNum(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setLogicMode(logicMode);
|
|
break;
|
case Configuration.LIGTH_BIG_TYPE:
|
switch (infos.get(appPos).getLittleType()) {
|
case 0:
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
break;
|
case 1:
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
break;
|
case 9:
|
RcuLight rcuLight = new RcuLight();
|
rcuLight.setPhysicsChanelNum(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
rcuLight.setCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
rcuLight.setLittleType(9);
|
rcuLightList.add(rcuLight);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setPhysicsChannelNum(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
break;
|
case 10:
|
RcuLight rcu2Light = new RcuLight();
|
rcu2Light.setPhysicsChanelNum(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
rcu2Light.setCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
rcu2Light.setLittleType(10);
|
rcuLightList.add(rcu2Light);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setPhysicsChannelNum(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(getDatas.addBytes[getDatas.addBytes.length - 2] & 0xFF);
|
break;
|
|
}
|
break;
|
case Configuration.CURTAIN_BIG_TYPE:
|
int curtainState;
|
switch (infos.get(appPos).getLittleType()) {
|
case 0:
|
curtainState = getDatas.addBytes[25] & 0xFF;
|
if (curtainState == 1) {
|
curtainState = 0;
|
} else if (curtainState == 99) {
|
curtainState = 100;
|
}
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(curtainState);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(curtainState);
|
break;
|
case 1:
|
curtainState = getDatas.addBytes[23] & 0xFF;
|
if (curtainState == 1) {
|
curtainState = 0;
|
} else if (curtainState == 99) {
|
curtainState = 100;
|
}
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(curtainState);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(curtainState);
|
break;
|
case 2:
|
if (!TextUtils.isEmpty(HandleSearch.rcuIp)) {
|
RcuCurtain rcuCurtain = new RcuCurtain();
|
rcuCurtain.setChanelNum(getDatas.addBytes[2] & 0xFF);
|
rcuCurtain.setLittleType(2);
|
int state = -1;
|
switch (getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF) {
|
case 0:
|
state = CurtainCtrlParser.curtainPause;
|
break;
|
case 1:
|
state = CurtainCtrlParser.curtainOn;
|
break;
|
case 2:
|
state = CurtainCtrlParser.curtainOff;
|
break;
|
}
|
rcuCurtain.setCurState(state);
|
rcuCurtainList.add(rcuCurtain);
|
}
|
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setIntCurState(getDatas.addBytes[getDatas.addBytes.length - 1] & 0xFF);
|
break;
|
|
}
|
break;
|
|
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);
|
// switch (devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).getChannelNum()) {
|
// case 1:
|
// if (air1Info == null) {
|
// air1Info = hvacBytes;
|
// }
|
// break;
|
// case 2:
|
// if (air2Info == null) {
|
// air2Info = hvacBytes;
|
// }
|
// break;
|
// case 3:
|
// if (air3Info == null) {
|
// air3Info = hvacBytes;
|
// }
|
// break;
|
// case 4:
|
// if (air4Info == null) {
|
// air4Info = hvacBytes;
|
// }
|
// break;
|
//
|
// }
|
break;
|
case 3:
|
byte[] newBytes = new byte[getDatas.addBytes.length - 24 + 1];
|
for (int i = 24; i < getDatas.addBytes.length; i++) {
|
newBytes[i - 24] = getDatas.addBytes[i];
|
}
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setArrCurState(newBytes);
|
break;
|
}
|
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);
|
float curState;
|
if (getDatas.addBytes.length >= 28) {
|
curState = DataConverseUtil.byte2Float(Arrays.copyOfRange(getDatas.addBytes, 24, 27));
|
|
} else {
|
curState = (float) (getDatas.addBytes[getDatas.addBytes.length - 1] & 0xff);
|
}
|
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新增
|
switch (infos.get(appPos).getLittleType()) {
|
case Configuration.FRESH_AIR_LITTLE_TYPE_0:
|
byte[] hvacBytes = new byte[getDatas.addBytes.length - 23];
|
for (int i = 23; i < getDatas.addBytes.length; i++) {
|
hvacBytes[i - 23] = getDatas.addBytes[i];
|
}
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setFeedbackState(hvacBytes);
|
break;
|
}
|
break;
|
case Configuration.GEOTHERMAL_BIG_TYPE://20190711新增
|
switch (infos.get(appPos).getLittleType()) {
|
case Configuration.GEOTHERMAL_LITTLE_TYPE_0:
|
byte[] hvacBytes = new byte[getDatas.addBytes.length - 23];
|
for (int i = 23; i < getDatas.addBytes.length; i++) {
|
hvacBytes[i - 23] = getDatas.addBytes[i];
|
}
|
devicesDataList.get(devPos).getAppliancesInfoList().get(appPos).setFeedbackState(hvacBytes);
|
break;
|
}
|
break;
|
default:
|
HDLLog.info("未找到此类型设备:" + infos.get(appPos).getBigType());
|
break;
|
}
|
listRemarksOutter:
|
for (int lRPos = 0, len3 = listRemarks.size(); lRPos < len3; lRPos++) {
|
|
//找到E44B对应的设备回路,判断是否已经拿到了数据。
|
if (listRemarks.get(lRPos).getAppliancesInfo().getDeviceSubnetID() == getDatas.sourceSubnetID
|
&& listRemarks.get(lRPos).getAppliancesInfo().getDeviceDeviceID() == getDatas.sourceDeviceID
|
&& listRemarks.get(lRPos).getAppliancesInfo().getBigType() == (getDatas.addBytes[0] & 0xFF)
|
&& listRemarks.get(lRPos).getAppliancesInfo().getLittleType() == (getDatas.addBytes[1] & 0xFF)
|
&& listRemarks.get(lRPos).getAppliancesInfo().getChannelNum() == (getDatas.addBytes[2] & 0xFF)
|
) {
|
|
|
//若没拿到数据,则拿数据;若已经拿到数据,需要判断listRemarks全部条目是否拿到备注。
|
if (listRemarks.get(lRPos).isCallBack()) {
|
for (int lR2Pos = 0, len4 = listRemarks.size(); lR2Pos < len4; lR2Pos++) {
|
if (listRemarks.get(lR2Pos).isCallBack()) {
|
if (lR2Pos == (len4 - 1)) {
|
HDLLog.info("收到备注命令,已存在此设备备注,过滤");
|
break listRemarksOutter;
|
}
|
} else {
|
HDLLog.info("不存在的设备备注,再次搜索备注。设备:子网号:" + listRemarks.get(lRPos).getAppliancesInfo().getDeviceSubnetID()
|
+ "设备号:" + listRemarks.get(lRPos).getAppliancesInfo().getDeviceDeviceID()
|
+ "回路号" + listRemarks.get(lRPos).getAppliancesInfo().getChannelNum()
|
+ "备注:" + listRemarks.get(lRPos).getAppliancesInfo().getRemarks());
|
HandleSearch.getDevRemarks();
|
break listRemarksOutter;
|
}
|
}
|
} else {
|
HDLLog.info("返回备注设备:子网号:" + listRemarks.get(lRPos).getAppliancesInfo().getDeviceSubnetID()
|
+ ",设备号:" + listRemarks.get(lRPos).getAppliancesInfo().getDeviceDeviceID()
|
+ ",回路号" + listRemarks.get(lRPos).getAppliancesInfo().getChannelNum()
|
+ ",备注:" + listRemarks.get(lRPos).getAppliancesInfo().getRemarks());
|
listRemarks.get(lRPos).setCallBack(true);
|
HandleSearch.getDevRemarks();
|
break listRemarksOutter;
|
|
}
|
|
}
|
}
|
|
break outter;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 处理设备状态数据
|
*
|
* @param getDatas
|
*/
|
private static void handleStateData(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++) {
|
// HDLLog.info("HDL big::" + devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType());
|
switch (devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType()) {
|
case Configuration.LIGTH_BIG_TYPE:
|
isGetDeviceStateSuccess = true;
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[j + 1] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[j + 1] & 0xFF);
|
EventBus.getDefault().post(new DeviceStateEvent(devicesDataList.get(i).getAppliancesInfoList().get(j), true));
|
// HDLLog.info("djllightState",devicesDataList.get(i).getAppliancesInfoList().get(j).toString());
|
break;
|
case Configuration.CURTAIN_BIG_TYPE:
|
|
int state;
|
if (devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) {
|
if ((getDatas.addBytes[0] & 0xFF) == infos.get(j).getChannelNum()) {
|
switch (getDatas.addBytes[1] & 0xFF) {//这里也应该改成0,1,2
|
case 0:
|
state = CurtainCtrlParser.curtainPause;
|
break;
|
case 1:
|
state = CurtainCtrlParser.curtainOn;
|
break;
|
case 2:
|
state = CurtainCtrlParser.curtainOff;
|
break;
|
default:
|
state = 0;
|
break;
|
}
|
isGetDeviceStateSuccess = true;
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[1] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[1] & 0xFF);
|
AppliancesInfo curtainInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
curtainInfo.setCurState(state);
|
EventBus.getDefault().post(new DeviceStateEvent(curtainInfo, true));
|
}
|
} else {
|
if ((getDatas.addBytes[0] & 0xFF) >= 17
|
&& ((getDatas.addBytes[0] & 0xFF) - 16) == infos.get(j).getChannelNum()) {//窗帘号大于等于17 减 16 = 当前窗帘回路号
|
state = getDatas.addBytes[1] & 0xFF;
|
if (state == 1) {
|
state = 0;//这个判断是将百分比为1,强制改为0.
|
}
|
if (state == 99) {
|
state = 100;//这个判断是将百分比为99,强制改为100.
|
}
|
isGetDeviceStateSuccess = true;
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(getDatas.addBytes[1] & 0xFF);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState(getDatas.addBytes[1] & 0xFF);
|
AppliancesInfo curtainInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
curtainInfo.setCurState(state);
|
EventBus.getDefault().post(new DeviceStateEvent(curtainInfo, true));
|
}
|
}
|
|
|
// HDLLog.info("djlcurtainState",devicesDataList.get(i).getAppliancesInfoList().get(j).toString());
|
break;
|
case Configuration.AIR_BIG_TYPE:
|
isGetDeviceStateSuccess = true;
|
AppliancesInfo appliancesInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
appliancesInfo.setArrCurState(getDatas.addBytes);
|
byte[] airBytes = appliancesInfo.getArrCurState();
|
switch (getDatas.addBytes[0] & 0xff) {
|
case AirCtrlParser.airSwich:
|
airBytes[0] = getDatas.addBytes[1];
|
break;
|
case AirCtrlParser.airMode:
|
airBytes[1] = getDatas.addBytes[1];
|
break;
|
case AirCtrlParser.refTem:
|
case AirCtrlParser.heatTem:
|
case AirCtrlParser.autoTem:
|
case AirCtrlParser.dehumTem:
|
airBytes[2] = getDatas.addBytes[1];
|
break;
|
case AirCtrlParser.airSpeed:
|
airBytes[3] = getDatas.addBytes[1];
|
break;
|
default:
|
break;
|
}
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setArrCurState(airBytes);
|
|
//上升、下降温度不返回
|
if ((getDatas.addBytes[0] & 0xff) != 9 && (getDatas.addBytes[0] & 0xff) != 10) {
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
}
|
|
break;
|
case Configuration.SENSOR_BIG_TYPE:
|
isGetDeviceStateSuccess = true;
|
AppliancesInfo sensorInfo = devicesDataList.get(i).getAppliancesInfoList().get(j);
|
float value = DataConverseUtil.byte2Float(Arrays.copyOfRange(getDatas.addBytes, 5, 8));
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setCurState(value);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setIntCurState((int) value);
|
|
sensorInfo.setCurState(value);
|
|
|
String unite = "";
|
switch (sensorInfo.getDeviceType()) {
|
case HDLApConfig.TYPE_SENSOR_DRY_CONTACT:
|
unite = "";
|
break;
|
case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR:
|
unite = "";
|
break;
|
case HDLApConfig.TYPE_SENSOR_TEMP:
|
if ((getDatas.addBytes[4] & 0xff) == 0) {
|
unite = "°C";
|
} else {
|
unite = "°F";
|
}
|
|
break;
|
case HDLApConfig.TYPE_SENSOR_HUMIDITY:
|
unite = "%";
|
break;
|
case HDLApConfig.TYPE_SENSOR_ILLUMINACE:
|
unite = "LUX";
|
break;
|
case HDLApConfig.TYPE_SENSOR_VOC:
|
unite = "";
|
break;
|
case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5:
|
switch (getDatas.addBytes[4] & 0xff) {
|
case 0:
|
unite = "mg/m3";
|
break;
|
case 1:
|
unite = "ppm";
|
break;
|
case 2:
|
unite = "μm";
|
break;
|
default:
|
unite = "";
|
break;
|
}
|
|
break;
|
case HDLApConfig.TYPE_SENSOR_C02:
|
switch (getDatas.addBytes[4] & 0xff) {
|
case 0:
|
unite = "mg/m3";
|
break;
|
case 1:
|
unite = "ppm";
|
break;
|
default:
|
unite = "";
|
break;
|
}
|
break;
|
case HDLApConfig.TYPE_SENSOR_LPG:
|
unite = "ppm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_CO_H2:
|
unite = "ppm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_CH4:
|
unite = "ppm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_SMOG:
|
unite = "";
|
break;
|
case HDLApConfig.TYPE_SENSOR_WIND_SPEED:
|
unite = "m/s";
|
break;
|
case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE:
|
unite = "Pa";
|
break;
|
case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW:
|
unite = "";
|
break;
|
case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE:
|
unite = "Pa";
|
break;
|
case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH:
|
unite = "mm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_RAIN_FALL:
|
switch (getDatas.addBytes[4] & 0xff) {
|
case 0:
|
unite = "无雨";
|
break;
|
case 1:
|
unite = "小雨";
|
break;
|
case 2:
|
unite = "大雨";
|
break;
|
default:
|
unite = "";
|
break;
|
}
|
break;
|
case HDLApConfig.TYPE_SENSOR_WEIGHT:
|
unite = "KG";
|
break;
|
case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH:
|
unite = "mm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED:
|
unite = "m/s";
|
break;
|
case HDLApConfig.TYPE_SENSOR_SHAKE:
|
unite = "mm";
|
break;
|
case HDLApConfig.TYPE_SENSOR_VOLTAGE:
|
switch (getDatas.addBytes[4] & 0xff) {
|
case 0:
|
unite = "V";
|
break;
|
case 1:
|
unite = "μV";
|
break;
|
default:
|
unite = "";
|
break;
|
}
|
break;
|
case HDLApConfig.TYPE_SENSOR_ELECTRICITY:
|
switch (getDatas.addBytes[4] & 0xff) {
|
case 0:
|
unite = "A";
|
break;
|
case 1:
|
unite = "μA";
|
break;
|
default:
|
unite = "";
|
break;
|
}
|
break;
|
case HDLApConfig.TYPE_SENSOR_POWER:
|
unite = "W";
|
break;
|
default:
|
unite = "未知单位";
|
break;
|
}
|
|
|
// EventBus.getDefault().post(new DeviceStateEvent(sensorInfo, true));
|
HDLLog.info("发送传感器通知更新");
|
EventBus.getDefault().post(new SensorStateBackInfo(sensorInfo, true, unite));
|
break;
|
default:
|
HDLLog.info("handle state 没有找到匹配类型");
|
break;
|
}
|
|
}
|
break outter;
|
}
|
}
|
}
|
|
/**
|
* 处理新风设备状态数据
|
* 20190710新增
|
*
|
* @param getDatas
|
*/
|
private static void handleFreshAirStateData(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.FRESH_AIR_BIG_TYPE
|
&& infos.get(j).getDeviceType() == HDLApConfig.TYPE_FRESH_AIR
|
&& infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {//2019-07-17
|
|
isGetDeviceStateSuccess = true;
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setFeedbackState(getDatas.addBytes);
|
EventBus.getDefault().post(new DeviceStateEvent(devicesDataList.get(i).getAppliancesInfoList().get(j), true));
|
break outter;
|
}else {
|
HDLLog.info("handleFreshAirStateData 没有找到匹配类型");
|
}
|
}
|
break outter;
|
}
|
}
|
}
|
|
|
/**
|
* 处理地热设备状态数据
|
* 20190710新增
|
*
|
* @param getDatas
|
*/
|
private static void handleGeothermalStateData(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.GEOTHERMAL_BIG_TYPE
|
&& infos.get(j).getDeviceType() == HDLApConfig.TYPE_GEOTHERMAL_MODULE
|
&& infos.get(j).getChannelNum() == (getDatas.addBytes[0] & 0xFF)) {//2019-07-17
|
if (getDatas.addBytes.length >= 10) {
|
byte[] getBytes = devicesDataList.get(i).getAppliancesInfoList().get(j).getFeedbackState();
|
if (getBytes == null || getBytes.length < 10) {
|
getBytes = new byte[10];
|
}
|
System.arraycopy(getDatas.addBytes, 0, getBytes, 0, 10);//20190710查询地热状态反馈,只取前10位数据
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setFeedbackState(getBytes);
|
isGetDeviceStateSuccess = true;
|
EventBus.getDefault().post(new DeviceStateEvent(devicesDataList.get(i).getAppliancesInfoList().get(j), true));
|
} else {
|
HDLLog.E("地热状态反馈数据异常");
|
}
|
|
break outter;
|
}else {
|
HDLLog.info("handleFreshAirStateData 没有找到匹配类型");
|
}
|
}
|
break outter;
|
}
|
}
|
}
|
|
|
|
/**
|
* 此方法基本没用到,逻辑模块的控制信息已经在handleCtrlData中处理过了
|
* <p>
|
* 处理逻辑模块数据
|
*
|
* @param getDatas
|
*/
|
private static void handleLogicData(UdpDataBean getDatas) {
|
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 (devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum() == ((byte) (getDatas.addBytes[2] & 0xFF) & 0xFF)) {
|
LogicMode logicMode = new LogicMode();
|
logicMode.setAreaNum((byte) (getDatas.addBytes[23] & 0xFF) & 0xFF);
|
logicMode.setAreaSceneNum((byte) (getDatas.addBytes[24] & 0xFF) & 0xFF);
|
byte[] remark = new byte[20];
|
System.arraycopy(getDatas.addBytes, 3, remark, 0, remark.length);
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setRemarks(byte2String(remark));
|
devicesDataList.get(i).getAppliancesInfoList().get(j).setLogicMode(logicMode);
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 处理警报数据
|
*
|
* @param getDatas
|
*/
|
private static void handleWarningData(UdpDataBean getDatas) {
|
if (getDatas.addBytes.length == 4) {
|
EventBus.getDefault().post(
|
new WarningInfoEvent(
|
WarningType.getWarningType(
|
(getDatas.addBytes[2] & 0xFF) * 256 + (getDatas.addBytes[3] & 0xFF))
|
));
|
Intent warningIntent = new Intent();
|
warningIntent.setAction("com.hdl.action.WARNING");
|
warningIntent.putExtra("HdlWarning",
|
WarningType.getWarningType((getDatas.addBytes[2] & 0xFF) * 256 + (getDatas.addBytes[3] & 0xFF)));
|
viewContext.sendBroadcast(warningIntent);
|
} else {
|
EventBus.getDefault().post(
|
new WarningInfoEvent(
|
WarningType.getWarningType(getDatas.addBytes[2] & 0xFF)));
|
Intent warningIntent = new Intent();
|
warningIntent.setAction("com.hdl.action.WARNING");
|
warningIntent.putExtra("HdlWarning",
|
WarningType.getWarningType(getDatas.addBytes[3] & 0xFF));
|
viewContext.sendBroadcast(warningIntent);
|
}
|
|
|
Intent warningIntent = new Intent();
|
warningIntent.setAction("com.hdl.devices.warning");
|
warningIntent.putExtra("HdlWarning",
|
WarningType.getWarningType((getDatas.addBytes[2] & 0xFF) * 256 + (getDatas.addBytes[3] & 0xFF)));
|
viewContext.sendBroadcast(warningIntent);
|
}
|
|
/**
|
* 处理HDL音乐协议
|
*
|
* @param getDatas
|
*/
|
private static void handleAudioData(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.AUDIO_BIG_TYPE) {
|
//暂时只支持旧版背景音乐
|
if (infos.get(j).getDeviceType() == HDLApConfig.TYPE_MUSIC_MODULE) {
|
HDLAudio.parseAudioData(getDatas, infos.get(j));
|
}
|
break outter;
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 设置控制是否成功状态
|
* @param info
|
* @param success
|
*/
|
public static void setDeviceCtrlSuccessStateWithInfo(AppliancesInfo info, Boolean success){
|
ctrlSuccessStateHashMap.put(info.getDeviceKey(), success);
|
}
|
|
/**
|
* 获取是否控制成功
|
* @param info
|
* @return 结果
|
*/
|
public static Boolean getDeviceCtrlSuccessStateWithInfo(AppliancesInfo info){
|
Boolean success = ctrlSuccessStateHashMap.get(info.getDeviceKey());
|
if(success == null) success = false;
|
return success;
|
}
|
}
|