| | |
| | | package com.hdl.sdk.hdl_core.HDLDeviceManger.Core;
|
| | |
|
| | | import android.util.Log;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.hdl.sdk.hdl_core.Config.ZigbeeDeviceID;
|
| | | import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ZigbeeBean.CommonErrorBean;
|
| | |
| | | private static boolean isFinished = false;//标记回调和场景设备数据
|
| | | public static Timer timer = null;//设置设备和场景回调
|
| | | private static String ipAddr;//设定控制时的ip地址
|
| | | private static boolean is1 = false,is2 = false;//标记获取的温度和风扇强度
|
| | | private static boolean is1 = false, is2 = false;//标记获取的温度和风扇强度
|
| | | private static int airTag = 0;//标记传进来控制空调的是什么方式(开关、模式、风速、设定温度)
|
| | | private static int airMode = 1;//标注更改温度时,控制的模式
|
| | | private static int scenesId = 0;//发场景时传入,方便收场景
|
| | |
| | | this.ipAddr = ipAddr;
|
| | | }
|
| | |
|
| | | public static void initData(){
|
| | | public static void initData() {
|
| | | zigbeeDeviceListBeans = new ArrayList<>();//搜索或控制时候需初始化
|
| | | }
|
| | |
|
| | | public interface DataCallBack{
|
| | | void onSuccess( List<ZigbeeDeviceListBean> zigbeeDeviceListBeans,ZigbeeSceneListBean zigbeeSceneListBeans);
|
| | | public interface DataCallBack {
|
| | | void onSuccess(List<ZigbeeDeviceListBean> zigbeeDeviceListBeans, ZigbeeSceneListBean zigbeeSceneListBeans);
|
| | | }
|
| | |
|
| | | //处理接收的数据
|
| | |
| | | //所有信息获取完处理
|
| | | //选择网关的话要在判断中加)
|
| | |
|
| | | if (topic.contains("Scene/GetInfo_Respon")){
|
| | | if (topic.contains("Scene/GetInfo_Respon")) {
|
| | | //处理搜索到的场景
|
| | | handleSceneList(message);
|
| | | }
|
| | |
|
| | | if (topic.contains("DeviceInfoRespon")){
|
| | | if (topic.contains("DeviceInfoRespon")) {
|
| | | //处理获取到的设备
|
| | | handleDeviceList(message);
|
| | | }
|
| | |
|
| | | if (topic.contains("Scene/Open_Respon")){
|
| | | if (topic.contains("Scene/Open_Respon")) {
|
| | | //返回场景被执行
|
| | | reportSceneStatus(message);
|
| | | return;
|
| | | }
|
| | |
|
| | | if (topic.contains("DeviceInfoResponEnd")&&
|
| | | zigbeeDeviceListBeans.get(0).getData().getGwId().equals(gatewayId)){
|
| | | if (topic.contains("DeviceInfoResponEnd") &&
|
| | | zigbeeDeviceListBeans.get(0).getData().getGwId().equals(gatewayId)) {
|
| | | Log.d("11113", "程序接受完进来处理: ");
|
| | | isFinished = true;
|
| | | }
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | ZigbeeReportBean zigbeeReportBean =JsonUtil.parseJsonWithGson(message, ZigbeeReportBean.class);
|
| | | ZigbeeReportBean zigbeeReportBean = JsonUtil.parseJsonWithGson(message, ZigbeeReportBean.class);
|
| | | int cluterId = zigbeeReportBean.getData().getCluterID();
|
| | | if (!(cluterId == 6 || cluterId==8 || cluterId == 258 || cluterId == 513 || cluterId == 514)) {
|
| | | if (!(cluterId == 6 || cluterId == 8 || cluterId == 258 || cluterId == 513 || cluterId == 514)) {
|
| | | HDLLog.info("不处理的cluterId:" + cluterId);
|
| | | return;
|
| | | }
|
| | | int deviceID = zigbeeReportBean.getDevice_ID();
|
| | | switch (deviceID){
|
| | | switch (deviceID) {
|
| | | case ZigbeeDeviceID.OnOffOutput:
|
| | | //灯光设备
|
| | | StatusReadBackBean lightReadBackBean = new StatusReadBackBean();
|
| | |
| | | }
|
| | | break;
|
| | | case ZigbeeDeviceID.WindowCoveringDevice:
|
| | | //窗帘设备
|
| | | StatusReadBackBean curtainReadBackBean = new StatusReadBackBean();
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData()
|
| | | .getAttriBute()){
|
| | | if (attriButeBean.getAttriButeId() == 8){
|
| | | curtainReadBackBean.setValue(attriButeBean.getAttriButeData());
|
| | | }
|
| | | }
|
| | | String curtainReadBackJson = JsonUtil.toJson(curtainReadBackBean);
|
| | | if (stateListener != null) {
|
| | | StateEvent event = new StateEvent(curtainReadBackJson);
|
| | | stateListener.onData(event);
|
| | | }
|
| | | //窗帘设备
|
| | | StatusReadBackBean curtainReadBackBean = new StatusReadBackBean();
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData()
|
| | | .getAttriBute()) {
|
| | | if (attriButeBean.getAttriButeId() == 8) {
|
| | | curtainReadBackBean.setValue(attriButeBean.getAttriButeData());
|
| | | }
|
| | | }
|
| | | String curtainReadBackJson = JsonUtil.toJson(curtainReadBackBean);
|
| | | if (stateListener != null) {
|
| | | StateEvent event = new StateEvent(curtainReadBackJson);
|
| | | stateListener.onData(event);
|
| | | }
|
| | | break;
|
| | | case ZigbeeDeviceID.DimmableLight:
|
| | | //调光器设备
|
| | | StatusReadBackBean dimmableLightReadBackBean = new StatusReadBackBean();
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData()
|
| | | .getAttriBute()) {
|
| | | if (attriButeBean.getAttriButeId() == 0 && cluterId==8 ) {
|
| | | Log.d("2222", "调光器数据: "+attriButeBean.getAttriButeData());
|
| | | dimmableLightReadBackBean.setValue((int) (attriButeBean.getAttriButeData()/2.55));
|
| | | if (attriButeBean.getAttriButeId() == 0 && cluterId == 8) {
|
| | | Log.d("2222", "调光器数据: " + attriButeBean.getAttriButeData());
|
| | | dimmableLightReadBackBean.setValue((int) (attriButeBean.getAttriButeData() / 2.55));
|
| | | }
|
| | | }
|
| | | String dimmableLightReadBackJson = JsonUtil.toJson(dimmableLightReadBackBean);
|
| | |
| | | break;
|
| | | case ZigbeeDeviceID.Thermostat:
|
| | | //空调设备
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean:zigbeeReportBean.getData().getAttriBute()){
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData().getAttriBute()) {
|
| | |
|
| | | if (attriButeBean.getAttriButeId() == 28 && attriButeBean.getAttriButeDataType() == 48){
|
| | | if (attriButeBean.getAttriButeId() == 28 && attriButeBean.getAttriButeDataType() == 48) {
|
| | | //当前的空调模式
|
| | | int thermostatmode = attriButeBean.getAttriButeData();
|
| | | thermostatReadBackBean.setThermostatmode(thermostatmode);
|
| | | is1 = true;
|
| | | }
|
| | |
|
| | | if (attriButeBean.getAttriButeId() == 0 && attriButeBean.getAttriButeDataType() == 0x30){
|
| | | if (attriButeBean.getAttriButeId() == 0 && attriButeBean.getAttriButeDataType() == 0x30) {
|
| | | //当前的新风模式
|
| | | int fanmode = attriButeBean.getAttriButeData();
|
| | | thermostatReadBackBean.setFanmode(fanmode);
|
| | | is2 = true;
|
| | | }
|
| | | if (attriButeBean.getAttriButeId() == 17 && attriButeBean.getAttriButeDataType() == 41){
|
| | | if (attriButeBean.getAttriButeId() == 17 && attriButeBean.getAttriButeDataType() == 41) {
|
| | | //制冷温度
|
| | | int coolingSetpoint = attriButeBean.getAttriButeData()/100;
|
| | | int coolingSetpoint = attriButeBean.getAttriButeData() / 100;
|
| | | thermostatReadBackBean.setCoolingSetpoint(coolingSetpoint);
|
| | | //Log.d("11113", "制冷温度为: "+coolingSetpoint);
|
| | |
|
| | | }
|
| | | if (attriButeBean.getAttriButeId() == 18 && attriButeBean.getAttriButeDataType() == 41){
|
| | | if (attriButeBean.getAttriButeId() == 18 && attriButeBean.getAttriButeDataType() == 41) {
|
| | | //制热温度
|
| | | int heatingSetpoint = attriButeBean.getAttriButeData()/100;
|
| | | int heatingSetpoint = attriButeBean.getAttriButeData() / 100;
|
| | | thermostatReadBackBean.setHeatingSetpoint(heatingSetpoint);
|
| | | //Log.d("11113", "制热温度为: "+heatingSetpoint);
|
| | |
|
| | | }
|
| | | }
|
| | | if (is1 && is2 ){ //代表获取恒温器和风扇的状态后的回调
|
| | | is1 = false;is2 = false;
|
| | | if (is1 && is2) { //代表获取恒温器和风扇的状态后的回调
|
| | | is1 = false;
|
| | | is2 = false;
|
| | | thermostatReadBackBean.setTag(airTag);
|
| | | String thermostatReadJson = JsonUtil.toJson(thermostatReadBackBean);
|
| | | //Log.d("11113", "数据数据数据"+thermostatReadJson);
|
| | | if (stateListener != null ){
|
| | | if (stateListener != null) {
|
| | | StateEvent event = new StateEvent(thermostatReadJson);
|
| | | stateListener.onData(event);
|
| | | }
|
| | |
| | | case ZigbeeDeviceID.AirPanel:
|
| | | //新风设备
|
| | | StatusReadBackBean airPanelReadBackBean = new StatusReadBackBean();
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData().getAttriBute()){
|
| | | if (attriButeBean.getAttriButeId() == 0 && attriButeBean.getAttriButeDataType() == 0x30){
|
| | | for (ZigbeeReportBean.DataBean.AttriButeBean attriButeBean : zigbeeReportBean.getData().getAttriBute()) {
|
| | | if (attriButeBean.getAttriButeId() == 0 && attriButeBean.getAttriButeDataType() == 0x30) {
|
| | | //当前的新风模式
|
| | | int fanmode = attriButeBean.getAttriButeData();
|
| | | airPanelReadBackBean.setValue(fanmode);
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public static void sendThirdPartyJson(final ZigbeeDeviceSaveBean zigbeeJson, String statusJson, int type){
|
| | | public static void sendThirdPartyJson(final ZigbeeDeviceSaveBean zigbeeJson, String statusJson, int type) {
|
| | | HDLZigbeeMqtt.connect1(ipAddr);
|
| | | // 判断是write 还是 read,控制时判断传递参数
|
| | | switch (type){
|
| | | switch (type) {
|
| | | case ZigbeeDeviceID.OnOffOutput:
|
| | | //继电器
|
| | | GatewayCommondBean gatewayCommondBean = JsonUtil.parseJsonWithGson(statusJson, GatewayCommondBean.class);
|
| | |
| | | reportError("cmd parameter error, please check it out");
|
| | | return;
|
| | | }
|
| | | switch (gatewayCommondBean.getCmd()){
|
| | | switch (gatewayCommondBean.getCmd()) {
|
| | | case "write":
|
| | | // 灯光控制,0关 1开
|
| | | if (!(gatewayCommondBean.getValue()==1||gatewayCommondBean.getValue()==0)){
|
| | | if (!(gatewayCommondBean.getValue() == 1 || gatewayCommondBean.getValue() == 0)) {
|
| | | reportError("Wrong lighting control parameters");
|
| | | return;
|
| | | }
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | HDLZigbeeMqtt.sendMqttData1( "DeviceControl", ctrlLightjson);
|
| | | HDLZigbeeMqtt.sendMqttData1("DeviceControl", ctrlLightjson);
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | return;
|
| | | }
|
| | | //窗帘控制
|
| | | switch (gatewayCurtainBean.getCmd()){
|
| | | switch (gatewayCurtainBean.getCmd()) {
|
| | | case "write":
|
| | | ZigbeeCtrlBean curtainCtrl = new ZigbeeCtrlBean();
|
| | | curtainCtrl.setCluster_ID(258);
|
| | | int curtainCmd;
|
| | | switch (gatewayCurtainBean.getTag()){
|
| | | switch (gatewayCurtainBean.getTag()) {
|
| | | case 0:
|
| | | switch (gatewayCurtainBean.getValue()){
|
| | | switch (gatewayCurtainBean.getValue()) {
|
| | | case 0:
|
| | | curtainCmd = 0;
|
| | | break;
|
| | |
| | | curtainBean.setAttriBute(curtainAttriButeBeanList);
|
| | | curtainReadBean.setData(curtainBean);
|
| | | String curtainReadJson = JsonUtil.toJson(curtainReadBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("GetDeviceStatus",curtainReadJson);
|
| | | HDLZigbeeMqtt.sendMqttData1("GetDeviceStatus", curtainReadJson);
|
| | | break;
|
| | | }
|
| | | break;
|
| | | case ZigbeeDeviceID.DimmableLight:
|
| | | //调光灯
|
| | | GatewayCommondBean dimmableLightBean = JsonUtil.parseJsonWithGson(statusJson, GatewayCommondBean.class);
|
| | | if (dimmableLightBean.getCmd() == null) {
|
| | | reportError("cmd parameter error, please check it out");
|
| | | return;
|
| | | }
|
| | | switch (dimmableLightBean.getCmd()){
|
| | | case "write":
|
| | | // 调光控制
|
| | | ZigbeeDimmableCtrlBean light = new ZigbeeDimmableCtrlBean();
|
| | | ZigbeeDimmableCtrlBean.Data data = new ZigbeeDimmableCtrlBean.Data();
|
| | | light.setCluster_ID(8);
|
| | | light.setSendMode(2);
|
| | | light.setCommand(4);
|
| | | light.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | light.setEpoint(zigbeeJson.getEpoint());
|
| | | data.setLevel(dimmableLightBean.getValue());
|
| | | data.setTransitionTime(2);
|
| | | light.setData(data);
|
| | | String ctrlLightjson = JsonUtil.toJson(light);
|
| | | HDLZigbeeMqtt.sendMqttData1( "DeviceControl", ctrlLightjson);
|
| | | break;
|
| | | case "read":
|
| | | ZigbeeReadBean lightReadBean = new ZigbeeReadBean();
|
| | | lightReadBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | lightReadBean.setEpoint(zigbeeJson.getEpoint());
|
| | | lightReadBean.setCluster_ID(8);
|
| | | lightReadBean.setCommand(108);
|
| | | lightReadBean.setSendMode(2);
|
| | | case ZigbeeDeviceID.DimmableLight:
|
| | | //调光灯
|
| | | GatewayCommondBean dimmableLightBean = JsonUtil.parseJsonWithGson(statusJson, GatewayCommondBean.class);
|
| | | if (dimmableLightBean.getCmd() == null) {
|
| | | reportError("cmd parameter error, please check it out");
|
| | | return;
|
| | | }
|
| | | switch (dimmableLightBean.getCmd()) {
|
| | | case "write":
|
| | | // 调光控制
|
| | | ZigbeeDimmableCtrlBean light = new ZigbeeDimmableCtrlBean();
|
| | | ZigbeeDimmableCtrlBean.Data data = new ZigbeeDimmableCtrlBean.Data();
|
| | | light.setCluster_ID(8);
|
| | | light.setSendMode(2);
|
| | | light.setCommand(4);
|
| | | light.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | light.setEpoint(zigbeeJson.getEpoint());
|
| | | data.setLevel(dimmableLightBean.getValue());
|
| | | data.setTransitionTime(2);
|
| | | light.setData(data);
|
| | | String ctrlLightjson = JsonUtil.toJson(light);
|
| | | HDLZigbeeMqtt.sendMqttData1("DeviceControl", ctrlLightjson);
|
| | | break;
|
| | | case "read":
|
| | | ZigbeeReadBean lightReadBean = new ZigbeeReadBean();
|
| | | lightReadBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | lightReadBean.setEpoint(zigbeeJson.getEpoint());
|
| | | lightReadBean.setCluster_ID(8);
|
| | | lightReadBean.setCommand(108);
|
| | | lightReadBean.setSendMode(2);
|
| | |
|
| | | ZigbeeReadBean.DataBean lightBean = new ZigbeeReadBean.DataBean();
|
| | | List<ZigbeeReadBean.DataBean.AttriButeBean> lightAttriButeBeanList = new ArrayList<>();
|
| | | ZigbeeReadBean.DataBean.AttriButeBean lightAttriButeBean = new ZigbeeReadBean.DataBean.AttriButeBean();
|
| | | lightAttriButeBean.setAttriButeId(0);
|
| | | lightAttriButeBeanList.add(lightAttriButeBean);
|
| | | lightBean.setAttriBute(lightAttriButeBeanList);
|
| | | lightReadBean.setData(lightBean);
|
| | | String lightReadJson = JsonUtil.toJson(lightReadBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("GetDeviceStatus", lightReadJson);
|
| | | break;
|
| | | }
|
| | | break;
|
| | | ZigbeeReadBean.DataBean lightBean = new ZigbeeReadBean.DataBean();
|
| | | List<ZigbeeReadBean.DataBean.AttriButeBean> lightAttriButeBeanList = new ArrayList<>();
|
| | | ZigbeeReadBean.DataBean.AttriButeBean lightAttriButeBean = new ZigbeeReadBean.DataBean.AttriButeBean();
|
| | | lightAttriButeBean.setAttriButeId(0);
|
| | | lightAttriButeBeanList.add(lightAttriButeBean);
|
| | | lightBean.setAttriBute(lightAttriButeBeanList);
|
| | | lightReadBean.setData(lightBean);
|
| | | String lightReadJson = JsonUtil.toJson(lightReadBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("GetDeviceStatus", lightReadJson);
|
| | | break;
|
| | | }
|
| | | break;
|
| | | case ZigbeeDeviceID.Thermostat:
|
| | | //空调
|
| | | final GatewayCommondBean thermostatBean = JsonUtil.parseJsonWithGson(statusJson, GatewayCommondBean.class);
|
| | |
| | | reportError("cmd parameter error, please check it out");
|
| | | return;
|
| | | }
|
| | | switch (thermostatBean.getCmd()){
|
| | | case "write":
|
| | | switch (airTag){
|
| | | switch (thermostatBean.getCmd()) {
|
| | | case "write":
|
| | | switch (airTag) {
|
| | | case 0://开关,开关传入开关01
|
| | | switch (thermostatBean.getValue()){
|
| | | switch (thermostatBean.getValue()) {
|
| | | case 0://空调关
|
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | sendFan(zigbeeJson,0);//发送风扇控制
|
| | | sendThermostat(zigbeeJson,0);//发送恒温器
|
| | | sendFan(zigbeeJson, 0);//发送风扇控制
|
| | | sendThermostat(zigbeeJson, 0);//发送恒温器
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | sendThermostat(zigbeeJson,1);
|
| | | sendFan(zigbeeJson,4);
|
| | | sendThermostat(zigbeeJson, 1);
|
| | | sendFan(zigbeeJson, 4);
|
| | | }
|
| | | }).start();
|
| | |
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | sendThermostat(zigbeeJson,thermostatBean.getValue());
|
| | | sendThermostat(zigbeeJson, thermostatBean.getValue());
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | sendFan(zigbeeJson,thermostatBean.getValue());
|
| | | sendFan(zigbeeJson, thermostatBean.getValue());
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | | case 3://控制温度
|
| | | switch (airMode){
|
| | | switch (airMode) {
|
| | | case 0://制热
|
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | contrlThermostat(zigbeeJson,thermostatBean.getValue(),0);
|
| | | contrlThermostat(zigbeeJson, thermostatBean.getValue(), 0);
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | contrlThermostat(zigbeeJson,thermostatBean.getValue(),1);
|
| | | contrlThermostat(zigbeeJson, thermostatBean.getValue(), 1);
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | contrlThermostat(zigbeeJson,thermostatBean.getValue(),2);
|
| | | contrlThermostat(zigbeeJson, thermostatBean.getValue(), 2);
|
| | | }
|
| | | }).start();
|
| | | break;
|
| | |
| | | reportError("cmd parameter error, please check it out");
|
| | | return;
|
| | | }
|
| | | switch (airpanelBean.getCmd()){
|
| | | case "write":
|
| | | sendNewFan(zigbeeJson,airpanelBean.getValue());
|
| | | switch (airpanelBean.getCmd()) {
|
| | | case "write":
|
| | | sendNewFan(zigbeeJson, airpanelBean.getValue());
|
| | | break;
|
| | | case "read":
|
| | | readFan(zigbeeJson);
|
| | |
| | | }
|
| | |
|
| | | //初始化状态信息
|
| | | public static void initStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type){
|
| | | public static void initStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type) {
|
| | | initData();
|
| | | airTag = 0;
|
| | | new Thread(new Runnable() {
|
| | | @Override
|
| | | public void run() {
|
| | | String sendStatus = HDLCommandText.setSendStatus("read",0);//读不需要知道状态,随便填一个
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice,sendStatus, type);
|
| | | String sendStatus = HDLCommandText.setSendStatus("read", 0);//读不需要知道状态,随便填一个
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice, sendStatus, type);
|
| | | }
|
| | | }).start();
|
| | | }
|
| | |
|
| | | //更新空调状态
|
| | | public static void initAirStatus(final ZigbeeDeviceSaveBean zigbeeDevice,final int type ,int tag){
|
| | | public static void initAirStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type, int tag) {
|
| | | airTag = tag;
|
| | | String sendStatus = HDLCommandText.setSendStatus("read",0);//读不需要知道状态,随便填一个
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice,sendStatus, type);
|
| | | String sendStatus = HDLCommandText.setSendStatus("read", 0);//读不需要知道状态,随便填一个
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice, sendStatus, type);
|
| | | }
|
| | |
|
| | |
|
| | | //发送空调控制
|
| | | public static void sendAirStatus(final ZigbeeDeviceSaveBean zigbeeDevice,final int type ,final int value,
|
| | | int tag,int mode){
|
| | | airTag = tag; airMode = mode;
|
| | | String sendStatus = HDLCommandText.setSendStatus("write",value);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice,sendStatus,type);
|
| | | public static void sendAirStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type, final int value,
|
| | | int tag, int mode) {
|
| | | airTag = tag;
|
| | | airMode = mode;
|
| | | String sendStatus = HDLCommandText.setSendStatus("write", value);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice, sendStatus, type);
|
| | | }
|
| | |
|
| | | //发送开关控制控制
|
| | | public static void sendStatus(final ZigbeeDeviceSaveBean zigbeeDevice,final int type,final int value){
|
| | | String sendStatus = HDLCommandText.setSendStatus("write",value);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice,sendStatus,type);
|
| | | public static void sendStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type, final int value) {
|
| | | String sendStatus = HDLCommandText.setSendStatus("write", value);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice, sendStatus, type);
|
| | | }
|
| | |
|
| | | //初始化窗帘控制
|
| | | public static void sendCurtainStatus(final ZigbeeDeviceSaveBean zigbeeDevice,final int type,
|
| | | final int value,final int tag){
|
| | | String sendStatus = HDLCommandText.setSendCurtainStatus("write",value,tag);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice,sendStatus,type);
|
| | | public static void sendCurtainStatus(final ZigbeeDeviceSaveBean zigbeeDevice, final int type,
|
| | | final int value, final int tag) {
|
| | | String sendStatus = HDLCommandText.setSendCurtainStatus("write", value, tag);
|
| | | HDLCommandText.sendThirdPartyJson(zigbeeDevice, sendStatus, type);
|
| | | }
|
| | |
|
| | | //设置继电器的状态
|
| | | private static String setSendStatus(String status,int value){
|
| | | private static String setSendStatus(String status, int value) {
|
| | | GatewayCommondBean gatewayCommondBean = new GatewayCommondBean();
|
| | | gatewayCommondBean.setCmd(status);
|
| | | gatewayCommondBean.setValue(value);
|
| | |
| | | }
|
| | |
|
| | | //设置窗帘的状态
|
| | | private static String setSendCurtainStatus(String status,int value,int tag){
|
| | | private static String setSendCurtainStatus(String status, int value, int tag) {
|
| | | GatewayCurtainBean gatewayCurtainBean = new GatewayCurtainBean();
|
| | | gatewayCurtainBean.setCmd(status);
|
| | | gatewayCurtainBean.setValue(value);
|
| | |
| | | }
|
| | |
|
| | | //发送恒温器模式
|
| | | private static void sendThermostat(ZigbeeDeviceSaveBean zigbeeJson,int value){
|
| | | private static void sendThermostat(ZigbeeDeviceSaveBean zigbeeJson, int value) {
|
| | | ZigbeeWriteCtrlBean zigbeeOffBean = new ZigbeeWriteCtrlBean();
|
| | | zigbeeOffBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | zigbeeOffBean.setEpoint(zigbeeJson.getEpoint());
|
| | |
| | | zigbeeOffDataBean.setAttributeData(value);
|
| | | zigbeeOffBean.setData(zigbeeOffDataBean);
|
| | | String zigbeeoffJson = JsonUtil.toJson(zigbeeOffBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue",zigbeeoffJson);
|
| | | initAirStatus(zigbeeJson,ZigbeeDeviceID.Thermostat,airTag);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue", zigbeeoffJson);
|
| | | initAirStatus(zigbeeJson, ZigbeeDeviceID.Thermostat, airTag);
|
| | | }
|
| | |
|
| | | //发送风模式
|
| | | private static void sendFan(final ZigbeeDeviceSaveBean zigbeeJson, int value){
|
| | | private static void sendFan(final ZigbeeDeviceSaveBean zigbeeJson, int value) {
|
| | | ZigbeeWriteCtrlBean zigbeeOffBean = new ZigbeeWriteCtrlBean();
|
| | | zigbeeOffBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | zigbeeOffBean.setEpoint(zigbeeJson.getEpoint());
|
| | |
| | | zigbeeOffDataBean.setAttributeData(value);
|
| | | zigbeeOffBean.setData(zigbeeOffDataBean);
|
| | | String zigbeeoffJson = JsonUtil.toJson(zigbeeOffBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue",zigbeeoffJson);
|
| | | initAirStatus(zigbeeJson,ZigbeeDeviceID.Thermostat,airTag);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue", zigbeeoffJson);
|
| | | initAirStatus(zigbeeJson, ZigbeeDeviceID.Thermostat, airTag);
|
| | | }
|
| | |
|
| | | //新风状态下发送新风模式
|
| | | private static void sendNewFan(final ZigbeeDeviceSaveBean zigbeeJson, int value){
|
| | | private static void sendNewFan(final ZigbeeDeviceSaveBean zigbeeJson, int value) {
|
| | | ZigbeeWriteCtrlBean zigbeeOffBean = new ZigbeeWriteCtrlBean();
|
| | | zigbeeOffBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | zigbeeOffBean.setEpoint(zigbeeJson.getEpoint());
|
| | |
| | | zigbeeOffDataBean.setAttributeData(value);
|
| | | zigbeeOffBean.setData(zigbeeOffDataBean);
|
| | | String zigbeeoffJson = JsonUtil.toJson(zigbeeOffBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue",zigbeeoffJson);
|
| | | initStatus(zigbeeJson,ZigbeeDeviceID.AirPanel);
|
| | | HDLZigbeeMqtt.sendMqttData1("SetWritableValue", zigbeeoffJson);
|
| | | initStatus(zigbeeJson, ZigbeeDeviceID.AirPanel);
|
| | | }
|
| | |
|
| | | //温度控制
|
| | | private static void contrlThermostat(ZigbeeDeviceSaveBean zigbeeJson,int value, int mode){
|
| | | private static void contrlThermostat(ZigbeeDeviceSaveBean zigbeeJson, int value, int mode) {
|
| | | ZigbeeThermostatCtrlBean zigbeeThermostatCtrlBean = new ZigbeeThermostatCtrlBean();
|
| | | zigbeeThermostatCtrlBean.setDeviceAddr(zigbeeJson.getDeviceAddr());
|
| | | zigbeeThermostatCtrlBean.setEpoint(zigbeeJson.getEpoint());
|
| | |
| | | zigbeeData.setAmount(value);
|
| | | zigbeeThermostatCtrlBean.setData(zigbeeData);
|
| | | String zigbeeCtrlJson = JsonUtil.toJson(zigbeeThermostatCtrlBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("DeviceControl",zigbeeCtrlJson);
|
| | | initAirStatus(zigbeeJson,ZigbeeDeviceID.Thermostat,airTag);
|
| | | HDLZigbeeMqtt.sendMqttData1("DeviceControl", zigbeeCtrlJson);
|
| | | initAirStatus(zigbeeJson, ZigbeeDeviceID.Thermostat, airTag);
|
| | | }
|
| | |
|
| | | //查看风速
|
| | | private static void readFan(ZigbeeDeviceSaveBean zigbeeJson){
|
| | | private static void readFan(ZigbeeDeviceSaveBean zigbeeJson) {
|
| | |
|
| | | //获取当前通风信息
|
| | | ZigbeeReadBean fanBean = new ZigbeeReadBean();
|
| | |
| | | }
|
| | |
|
| | | //发送场景数据
|
| | | public static void sendSceneStatus(int ScenesId,int DelayTime){
|
| | | public static void sendSceneStatus(int ScenesId, int DelayTime) {
|
| | | scenesId = ScenesId;
|
| | | ZigbeeSceneCtrlBean zigbeeSceneCtrlBean = new ZigbeeSceneCtrlBean();
|
| | | zigbeeSceneCtrlBean.setCluster_ID(0);
|
| | |
| | | dataBean.setDelayTime(DelayTime);
|
| | | zigbeeSceneCtrlBean.setData(dataBean);
|
| | | String json = JsonUtil.toJson(zigbeeSceneCtrlBean);
|
| | | HDLZigbeeMqtt.sendMqttData1("Scene/Open",json);
|
| | | HDLZigbeeMqtt.sendMqttData1("Scene/Open", json);
|
| | | }
|
| | |
|
| | | //处理设备信息
|
| | | private static void handleDeviceList(String message) {
|
| | | ZigbeeDeviceListBean zigbeeDeviceListBean = JsonUtil.parseJsonWithGson(message,ZigbeeDeviceListBean.class);
|
| | | ZigbeeDeviceListBean zigbeeDeviceListBean = JsonUtil.parseJsonWithGson(message, ZigbeeDeviceListBean.class);
|
| | | zigbeeDeviceListBeans.add(zigbeeDeviceListBean);
|
| | | }
|
| | |
|
| | | //处理场景信息
|
| | | private static void handleSceneList(String message) {
|
| | | Gson gson = new Gson();
|
| | | zigbeeSceneListBean = gson.fromJson(message,ZigbeeSceneListBean.class);
|
| | | zigbeeSceneListBean = gson.fromJson(message, ZigbeeSceneListBean.class);
|
| | | }
|
| | |
|
| | | //处理场景的数据
|
| | |
| | | return;
|
| | | }
|
| | | StatusReadBackBean statusReadBackBean = new StatusReadBackBean();
|
| | | if (sceneCtrlBackBean.getData().getScenesId() == scenesId){
|
| | | if (sceneCtrlBackBean.getData().getScenesId() == scenesId) {
|
| | | statusReadBackBean.setValue(sceneCtrlBackBean.getData().getResult());
|
| | | }
|
| | | String Json = JsonUtil.toJson(statusReadBackBean);
|
| | | Log.d("11114", "处理数据回调: "+Json);
|
| | | Log.d("11114", "处理数据回调: " + Json);
|
| | | if (stateListener != null) {
|
| | | StateEvent event = new StateEvent(Json);
|
| | | stateListener.onData(event);
|
| | |
| | | }
|
| | |
|
| | | //回调获取到的设备信息
|
| | | public static void handleDeviceData(final DataCallBack dataCallBack){
|
| | | public static void handleDeviceData(final DataCallBack dataCallBack) {
|
| | | timer = new Timer();
|
| | | timer.schedule(new TimerTask() {
|
| | | @Override
|
| | | public void run() {
|
| | | if (!isFinished){
|
| | | if (!isFinished) {
|
| | | Log.d("11112", "run: 程序执行中");
|
| | | }else {
|
| | | } else {
|
| | | timer.cancel();
|
| | | timer.purge();
|
| | | timer = null;
|
| | | isFinished = false;
|
| | | dataCallBack.onSuccess(zigbeeDeviceListBeans,zigbeeSceneListBean);
|
| | | dataCallBack.onSuccess(zigbeeDeviceListBeans, zigbeeSceneListBean);
|
| | | }
|
| | | }
|
| | | },1,500);
|
| | | }, 1, 500);
|
| | | }
|
| | | public static void reSearch(){
|
| | | if (timer != null){
|
| | |
|
| | | public static void reSearch() {
|
| | | if (timer != null) {
|
| | | timer.cancel();
|
| | | timer.purge();
|
| | | timer = null;
|
| | |
| | | CommonErrorBean errorBean = new CommonErrorBean();
|
| | | errorBean.setCmd("error");
|
| | | errorBean.setReason(reason);
|
| | | String errorJson =JsonUtil.toJson(errorBean);
|
| | | String errorJson = JsonUtil.toJson(errorBean);
|
| | | StateEvent event = new StateEvent(errorJson);
|
| | | stateListener.onData(event);
|
| | | }
|