package com.hdl.sdk.hdl_sdk.activity;
|
|
import android.app.Activity;
|
import android.os.Bundle;
|
import android.text.TextUtils;
|
import android.view.View;
|
import android.widget.Button;
|
import android.widget.EditText;
|
import android.widget.Toast;
|
|
|
import com.hdl.sdk.hdl_core.Config.Configuration;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Parser.DeviceParser;
|
import com.hdl.sdk.hdl_sdk.R;
|
|
import java.util.ArrayList;
|
|
|
/** SDK目前支持手动添加的大类:小类
|
* 灯光类(大类1):调光回路(0)、开关回路(1)、混合调光类(9)、混合开关类(10)
|
* 窗帘类(大类2):开合帘电机(0)、卷帘电机(1)、窗帘模块(2)
|
* 空调功能(大类7):HVAC 模块(0)、通用空调面板(3)
|
* 背景音乐功能(大类9):背景音乐模块 2018新背景音乐模块小类3
|
* 传感器(大类5):干结点0 到 功率24
|
* 逻辑功能(大类12):逻辑模块(0)
|
* 全局场景(大类17):全局场景(0)
|
* 地热功能:地热模块(0)
|
* 新风(大类19):新风系统(0)
|
* 通用开关(大类100):通用开关(0)
|
|
* 格式 支持的模块名字 大类ID:小类ID
|
*
|
* 灯光类 1:0 ,1,9,10
|
* 窗帘类 2:0,1,2
|
* 传感器 5:0~24
|
* 空调类 7:0,3
|
* 地热模块 8:0
|
* 背景音乐功能 9:0
|
* 逻辑功能 12:0
|
* 全局场景 17:0
|
* 新风模块 19:0
|
* 通用开关 100:0
|
*
|
* 该方法应用于提供项目交付前的提取批量数据生成好数据。
|
* 模拟生成设备回路数据,在项目不支持简易编程搜索情况下,可以通过该方法,先快捷生成目标数据 得到 List<DevicesData> 格式的设备列表数据
|
*
|
* 上层做本地保存或者云端备份,App启动时读取恢复
|
* 每次启动时先加载生成好的设备列表数据,然后在 SDK 初始化后,赋值给 HDLDeviceManager.devicesDataList
|
*/
|
public class AddDevicesActivity extends Activity {
|
|
private int bigType;
|
private int littleType;
|
private int mSubnetID;
|
private int mDeviceID;
|
private int mChannelNum;
|
private int port = 6000;
|
private String parentRemarks;
|
private ArrayList<String> parentRemarksList = new ArrayList();
|
|
private EditText et_subnetID, et_deviceID, et_bitType, et_littleType, et_remarks, et_remarks_mk, et_mChannelNum,et_scene,et_mPort,et_scene2;
|
private Button btn_add,btn_scene,btn_addAll;
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_add_devices);
|
|
et_subnetID = findViewById(R.id.et_subnetID);
|
et_deviceID = findViewById(R.id.et_deviceID);
|
et_bitType = findViewById(R.id.et_bitType);
|
et_littleType = findViewById(R.id.et_littleType);
|
et_remarks = findViewById(R.id.et_remarks);
|
// et_port = findViewById(R.id.et_port);
|
et_remarks_mk = findViewById(R.id.et_remarks_mk);
|
et_mChannelNum = findViewById(R.id.et_mChannelNum);
|
et_mPort = findViewById(R.id.et_mPort);
|
|
et_scene = findViewById(R.id.et_scene);
|
et_scene2 = findViewById(R.id.et_scene2);
|
|
btn_add = findViewById(R.id.btn_add);
|
btn_scene = findViewById(R.id.btn_scene);
|
btn_addAll= findViewById(R.id.btn_addAll);
|
|
|
btn_add.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
addDevicesManuallyWithoutSearchingAll();
|
|
}
|
});
|
|
btn_scene.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
addScene();
|
|
}
|
});
|
|
btn_addAll.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
addMultipleDevices();
|
|
}
|
});
|
}
|
|
|
private void addDevicesManuallyWithoutSearchingAll() {
|
// parentRemarksList.clear();
|
|
|
String subnetIDStr = et_subnetID.getText().toString();
|
if (TextUtils.isEmpty(subnetIDStr)) {
|
showToast("子网号不能为空");
|
return;
|
}
|
|
String deviceIDStr = et_deviceID.getText().toString();
|
if (TextUtils.isEmpty(deviceIDStr)) {
|
showToast("设备号不能为空");
|
return;
|
}
|
|
String bitTypeStr = et_bitType.getText().toString();
|
if (TextUtils.isEmpty(bitTypeStr)) {
|
showToast("大类不能为空");
|
return;
|
}
|
|
String littleTypeStr = et_littleType.getText().toString();
|
if (TextUtils.isEmpty(littleTypeStr)) {
|
showToast("小类不能为空");
|
return;
|
}
|
String mChannelNumStr = et_mChannelNum.getText().toString();
|
if (TextUtils.isEmpty(mChannelNumStr)) {
|
showToast("回路号不能为空");
|
return;
|
}
|
|
String mPortStr = et_mPort.getText().toString();
|
if (TextUtils.isEmpty(mPortStr)) {
|
showToast("端口号不能为空");
|
return;
|
}
|
|
|
|
|
String remarksMkString = et_remarks_mk.getText().toString();
|
if (TextUtils.isEmpty(remarksMkString)) {
|
showToast("模块备注不能为空");
|
return;
|
}
|
|
|
String remarksString = et_remarks.getText().toString();
|
if (TextUtils.isEmpty(remarksString)) {
|
showToast("备注不能为空");
|
return;
|
}
|
|
// String et_portString = et_port.getText().toString();
|
// if (TextUtils.isEmpty(et_portString)) {
|
// showToast("端口不能为空");
|
// return;
|
// }
|
|
|
mSubnetID = Integer.parseInt(subnetIDStr);
|
mDeviceID = Integer.parseInt(deviceIDStr);
|
|
bigType = Integer.parseInt(bitTypeStr);
|
littleType = Integer.parseInt(littleTypeStr);
|
mChannelNum = Integer.parseInt(mChannelNumStr);
|
parentRemarks = remarksMkString;
|
port = Integer.parseInt(mPortStr);
|
|
|
/**
|
* 添加设备回路
|
* 如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
|
* @param bigType 回路大类
|
* @param littleType 回路小类
|
* @param mSubnetID 回路子网ID
|
* @param mDeviceID 回路设备ID
|
* @param mChannelNum 回路号
|
* @param mChannelRemark 回路备注 例如:窗帘、吊灯、厕所灯、电视
|
* @param parentRemarks 当前回路模块的备注 例如: 酒店RCU模块
|
* @return
|
*/
|
//如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
|
DevicesData mDevicesData = DeviceParser.addDevicesListWithoutSearching(port, bigType, littleType, mSubnetID, mDeviceID, mChannelNum, remarksString, parentRemarks,true);
|
if (mDevicesData != null) {
|
showToast("添加成功");
|
} else {
|
showToast("添加失败");
|
}
|
|
|
}
|
|
/**
|
* 添加场景设备回路 需指定 场景区号 和 场景号
|
* 如果存在相同子网号 设备号,则当成混合模块添加到该回路下,不存在则新添加模块
|
*
|
* @param mSubnetID
|
* @param mDeviceID
|
* @param mChannelNum 回路号 这里的回路号需要注意,相同子网号和设备号下的场景需要累加不重复,逻辑模块为例:1区有3个表,2区有2个表 总共5个场景,所以(2区表1 回路号为4、2区表2 回路号为5)
|
* @param mAreaNum //场景 区域号
|
* @param mAreaSceneNum //场景 当前区域场景号
|
* @param mChannelRemark 读取场景的备注名称 例如: 入住、起床模式、阅读模式
|
* @param parentRemarks 当前回路模块的备注 例如: 酒店RCU模块
|
* @param bSaveAndCallBack 是否马上保存本地并且推送DevicesInfoEvent 事件
|
* @return
|
*/
|
private void AddScenesDevices(int mSubnetID, int mDeviceID, int mChannelNum, int mAreaNum, int mAreaSceneNum, String mChannelRemark, String parentRemarks, boolean bSaveAndCallBack) {
|
//添加场景
|
DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, mChannelNum, mAreaNum, mAreaSceneNum, mChannelRemark, parentRemarks,true);
|
}
|
|
|
/**
|
* 添加场景回路
|
*/
|
private void addScene(){
|
|
String subnetIDStr = et_subnetID.getText().toString();
|
if (TextUtils.isEmpty(subnetIDStr)) {
|
showToast("子网号不能为空");
|
return;
|
}
|
|
String deviceIDStr = et_deviceID.getText().toString();
|
if (TextUtils.isEmpty(deviceIDStr)) {
|
showToast("设备号不能为空");
|
return;
|
}
|
|
|
String mPortStr = et_mPort.getText().toString();
|
if (TextUtils.isEmpty(mPortStr)) {
|
showToast("端口号不能为空");
|
return;
|
}
|
|
String mChannelNumStr = et_mChannelNum.getText().toString();
|
if (TextUtils.isEmpty(mChannelNumStr)) {
|
showToast("回路号不能为空");
|
return;
|
}
|
|
|
// String bitTypeStr = et_bitType.getText().toString();
|
// if (TextUtils.isEmpty(bitTypeStr)) {
|
// showToast("大类不能为空");
|
// return;
|
// }
|
//
|
// String littleTypeStr = et_littleType.getText().toString();
|
// if (TextUtils.isEmpty(littleTypeStr)) {
|
// showToast("小类不能为空");
|
// return;
|
// }
|
// String mChannelNumStr = et_mChannelNum.getText().toString();
|
// if (TextUtils.isEmpty(littleTypeStr)) {
|
// showToast("回路号不能为空");
|
// return;
|
// }
|
|
|
String remarksMkString = et_remarks_mk.getText().toString();
|
if (TextUtils.isEmpty(remarksMkString)) {
|
showToast("模块备注不能为空");
|
return;
|
}
|
|
|
String remarksString = et_remarks.getText().toString();
|
if (TextUtils.isEmpty(remarksString)) {
|
showToast("备注不能为空");
|
return;
|
}
|
|
String et_AreaNumString = et_scene.getText().toString();
|
if (TextUtils.isEmpty(et_AreaNumString)) {
|
showToast("场景:区号不能为空");
|
return;
|
}
|
|
String et_scene2String = et_scene2.getText().toString();
|
if (TextUtils.isEmpty(et_scene2String)) {
|
showToast("场景:场景号不能为空");
|
return;
|
}
|
|
|
|
|
mSubnetID = Integer.parseInt(subnetIDStr);
|
mDeviceID = Integer.parseInt(deviceIDStr);
|
port = Integer.parseInt(mPortStr);
|
// bigType = Integer.parseInt(bitTypeStr);
|
// littleType = Integer.parseInt(littleTypeStr);
|
mChannelNum = Integer.parseInt(mChannelNumStr);
|
parentRemarks = remarksMkString;
|
int areaID = Integer.parseInt(et_AreaNumString);
|
int sceneID = Integer.parseInt(et_scene2String);
|
|
DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, mChannelNum, areaID, sceneID, remarksString, parentRemarks,true);
|
if (mScenesData != null) {
|
showToast("添加成功");
|
} else {
|
showToast("添加失败");
|
}
|
|
}
|
|
/**
|
* 批量添加
|
* 仅做演示用
|
*/
|
private void addMultipleDevices(){
|
|
String subnetIDStr = et_subnetID.getText().toString();
|
if (TextUtils.isEmpty(subnetIDStr)) {
|
showToast("子网号不能为空");
|
return;
|
}
|
|
String deviceIDStr = et_deviceID.getText().toString();
|
if (TextUtils.isEmpty(deviceIDStr)) {
|
showToast("设备号不能为空");
|
return;
|
}
|
|
|
|
String remarksMkString = et_remarks_mk.getText().toString();
|
if (TextUtils.isEmpty(remarksMkString)) {
|
showToast("模块备注不能为空");
|
return;
|
}
|
|
|
|
|
mSubnetID = Integer.parseInt(subnetIDStr);
|
mDeviceID = Integer.parseInt(deviceIDStr);
|
parentRemarks = remarksMkString;
|
|
// //添加一个灯
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 1, "吧台灯", parentRemarks,false);
|
// //添加一个灯
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 2, "休闲灯", parentRemarks,false);
|
// //添加一个灯
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 3, "电视灯", parentRemarks,false);
|
// //添加一个灯
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, mSubnetID, mDeviceID, 6, "廊灯", parentRemarks,false);
|
//
|
// //添加一个窗帘
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, mSubnetID, mDeviceID, 1, "窗帘", parentRemarks,false);
|
// //添加一个窗帘
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, mSubnetID, mDeviceID, 2, "纱窗", parentRemarks,false);
|
//
|
// //添加一个空调
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.AIR_BIG_TYPE, 0, mSubnetID, mDeviceID, 1, "房间空调", parentRemarks,false);
|
//
|
//// //添加通用开关 清理
|
//// DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 15, "清理", parentRemarks,false);
|
//// //添加通用开关 入住
|
//// DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 16, "入住", parentRemarks,false);
|
//// //添加通用开关 稍后
|
//// DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 13, "稍后", parentRemarks,false);
|
//// //添加通用开关 勿扰
|
//// DeviceParser.addDevicesListWithoutSearching(port, Configuration.COMMON_SWITCH_BIG_TYPE, 0, mSubnetID, mDeviceID, 14, "勿扰", parentRemarks,false);
|
//// //添加一个安防模块
|
//// DeviceParser.addDevicesListWithoutSearching(port, Configuration.SECURITY_BIG_TYPE, 0, 12, 1, 1, "安防模块", "安防模块",false);
|
//
|
// //添加一个场景 这里场景号和区号 默认一样
|
// DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 2, 2, "空置无卡", parentRemarks,false);
|
// //添加一个场景
|
// DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 3, 3, "插卡场景", parentRemarks,false);
|
// //添加一个场景
|
// DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 4, 4, "房灯", parentRemarks,false);
|
// //添加一个场景 最后一个bSaveAndCallBack 设置为true
|
// DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 5, 5, "会客模式", parentRemarks,true);
|
|
|
// //添加一个4路继电器
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 1, "吧台灯", "4路继电器",false);
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 2, "休闲灯", "4路继电器",false);
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 3, "电视灯", "4路继电器",false);
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.LIGTH_BIG_TYPE, 0, 111, 3, 4, "廊灯", "4路继电器",false);
|
//
|
// //添加一个干节点传感器
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.SENSOR_BIG_TYPE, 0, 111, 99, 1, "干节点", "干节点",false);
|
//
|
//
|
// //添加一个2路窗帘
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, 111, 8, 1, "窗帘", "2路窗帘",false);
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 2, 111, 8, 2, "纱窗", "2路窗帘",false);
|
// //添加一个开合帘
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.CURTAIN_BIG_TYPE, 1, 111, 92, 1, "开合帘", "开合帘",false);
|
//
|
// //添加一个空调
|
// DeviceParser.addDevicesListWithoutSearching(port, Configuration.AIR_BIG_TYPE, 0, 111, 9, 1, "房间空调", "HVAC空调模块",false);
|
|
/**
|
* 场景这里的回路号需要注意: 相同子网号和设备号下的场景需要累加不重复,逻辑模块为例:1区有3个表,2区有2个表 总共5个场景,所以(2区表1 回路号为4、2区表2 回路号为5)
|
* 不然如果回路号不对简易编程搜索备注的话会出错
|
*/
|
//添加一个场景
|
DeviceParser.addLogicScenesDevicesListWithoutSearching(port, 1, 16, 4, 2, 1, "卧室开灯", "逻辑模块",false);
|
|
//添加一个场景 最后一个bSaveAndCallBack 设置为true
|
DeviceParser.addLogicScenesDevicesListWithoutSearching(port, 1, 16, 5,2, 2, "卧室关灯", "逻辑模块",true);
|
|
|
|
}
|
|
|
|
|
private void showToast(String text) {
|
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
|
}
|
|
|
}
|