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目前支持的大类:小类 * 灯光类:调光回路、开关回路、混合调光类、混合开关类 * 窗帘类:开合帘电机、卷帘电机、窗帘模块 * 空调功能:HVAC 模块、通用空调面板 * 背景音乐功能:背景音乐模块 2018新背景音乐模块小类3 * 传感器:干结点0 到 功率24 * 逻辑功能:逻辑模块 * 全局场景: * 地热功能:地热模块 * 新风:新风系统 * 灯光类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 格式的设备列表数据 * * 上层做本地保存或者云端备份,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 parentRemarksList = new ArrayList(); private EditText et_subnetID, et_deviceID, et_bitType, et_littleType, et_remarks, et_remarks_mk, et_mChannelNum,et_scene,et_mPort; 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); 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(littleTypeStr)) { 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 mAreaNum //场景 区域号 * @param mAreaSceneNum //场景 当前区域场景号 * @param mChannelRemark 读取场景的备注名称 例如: 入住、起床模式、阅读模式 * @param parentRemarks 当前回路模块的备注 例如: 酒店RCU模块 * @param bSaveAndCallBack 是否马上保存本地并且推送DevicesInfoEvent 事件 * @return */ private void AddScenesDevices(int mSubnetID, int mDeviceID, int mAreaNum, int mAreaSceneNum, String mChannelRemark, String parentRemarks, boolean bSaveAndCallBack) { //添加场景 DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 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 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_sceneString = et_scene.getText().toString(); if (TextUtils.isEmpty(et_sceneString)) { showToast("场景ID不能为空"); 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 sceneID = Integer.parseInt(et_sceneString); DevicesData mScenesData = DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, sceneID, 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); //添加一个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); //添加一个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); //添加一个场景 最后一个bSaveAndCallBack 设置为true DeviceParser.addScenesDevicesListWithoutSearching(port, mSubnetID, mDeviceID, 5, 5, "会客模式", parentRemarks,true); } private void showToast(String text) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } }