.idea/codeStyles/Project.xml
New file @@ -0,0 +1,116 @@ <component name="ProjectCodeStyleConfiguration"> <code_scheme name="Project" version="173"> <codeStyleSettings language="XML"> <indentOptions> <option name="CONTINUATION_INDENT_SIZE" value="4" /> </indentOptions> <arrangement> <rules> <section> <rule> <match> <AND> <NAME>xmlns:android</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>^$</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>xmlns:.*</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>^$</XML_NAMESPACE> </AND> </match> <order>BY_NAME</order> </rule> </section> <section> <rule> <match> <AND> <NAME>.*:id</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>.*:name</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>name</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>^$</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>style</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>^$</XML_NAMESPACE> </AND> </match> </rule> </section> <section> <rule> <match> <AND> <NAME>.*</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>^$</XML_NAMESPACE> </AND> </match> <order>BY_NAME</order> </rule> </section> <section> <rule> <match> <AND> <NAME>.*</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> </AND> </match> <order>ANDROID_ATTRIBUTE_ORDER</order> </rule> </section> <section> <rule> <match> <AND> <NAME>.*</NAME> <XML_ATTRIBUTE /> <XML_NAMESPACE>.*</XML_NAMESPACE> </AND> </match> <order>BY_NAME</order> </rule> </section> </rules> </arrangement> </codeStyleSettings> </code_scheme> </component> app/src/main/AndroidManifest.xml
@@ -18,7 +18,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".activity.AddDevicesManuallyActivity"></activity> <activity android:name=".activity.SettingActivity"></activity> <activity android:name=".activity.AddDevicesManuallyActivity" /> <activity android:name=".activity.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
@@ -42,6 +42,7 @@ private Button btn, btn2; private Button btn_get_all,btn_on_all, btn_off_all,btn_getlocal,btn_getlocal_add; private Button btn_setting; private TextView tv; private EditText editText; private List<DevicesData> devicesDatas; @@ -81,6 +82,7 @@ btn_getlocal_add = findViewById(R.id.btn_getlocal_add); btn_setting = findViewById(R.id.btn_setting); tv = findViewById(R.id.tv); editText = findViewById(R.id.edt); editText.setText("172.168.188.100"); @@ -171,6 +173,13 @@ } }); btn_setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(SettingActivity.class); } }); } public void startActivity(Class<?> clazz) { app/src/main/java/com/hdl/sdk/hdl_sdk/activity/SettingActivity.java
New file @@ -0,0 +1,138 @@ 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.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLCommand; import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLDeviceManager; import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils; import com.hdl.sdk.hdl_sdk.R; /** * Created by JLChen on 2020-03-02 * 当前APP设备子网号和设备号配置,根据需要配置 */ public class SettingActivity extends Activity { /**Topbar*/ private RelativeLayout topBarBack; private TextView topBarTitle; //当前APP设备子网号和设备号配置 private EditText subnetIDEditText; private EditText deviceIDEditText; private Button saveButton; //当前APP设备设备号 private String strSubnetID = "254"; private String strDeviceID = "80"; private EditText bigIDEditText; private EditText smallIDEditText; private EditText remarkIDEditText; private Button btn_save_allow; private Button btn_save_close; private String strBigClassID = "9"; private String strSmallClassID = "1";//第三方背景音乐模块 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setting); initView(); setOnClick(); initData(); } private void initView() { subnetIDEditText = findViewById(R.id.et_subnetID); deviceIDEditText = findViewById(R.id.et_deviceID); saveButton = findViewById(R.id.btn_save); bigIDEditText = findViewById(R.id.et_bigclass); smallIDEditText = findViewById(R.id.et_smallclass); remarkIDEditText = findViewById(R.id.et_remark); btn_save_allow = findViewById(R.id.btn_save_allow); btn_save_close = findViewById(R.id.btn_save_close); } private void setOnClick() { saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveSubnetAndDeviceID(); } }); btn_save_allow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveSEasyProgrammingSearchInfo(); } }); btn_save_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { HDLDeviceManager.setIsAllowEasyProgrammingSearch(false); } }); } private void initData() { strSubnetID = SPUtils.getParam(this, SPUtils.KEY_SUB_ID_, SPUtils.DEFAULT_SUB_ID).toString(); strDeviceID = SPUtils.getParam(this, SPUtils.KEY_DEVICE_ID, SPUtils.DEFAULT_DEVICE_ID).toString(); subnetIDEditText.setText(strSubnetID); deviceIDEditText.setText(strDeviceID); //配置简易编程搜索的参数 HDLDeviceManager.setEasyProgrammingSearchLocalData(9, 90); } //本地子网号、设备号 范围0 - 254 private void saveSubnetAndDeviceID() { strSubnetID = subnetIDEditText.getText().toString(); strDeviceID = deviceIDEditText.getText().toString(); if (TextUtils.isEmpty(strSubnetID) || TextUtils.isEmpty(strDeviceID)) { showToast("ID不能为空"); } else { int mSubnetID = Integer.parseInt(strSubnetID); int mDeviceID = Integer.parseInt(strDeviceID); HDLCommand.setLocalId(this, mSubnetID, mDeviceID); } } private void saveSEasyProgrammingSearchInfo(){ strBigClassID = bigIDEditText.getText().toString(); strSmallClassID = smallIDEditText.getText().toString(); String remarkStr = remarkIDEditText.getText().toString(); if (TextUtils.isEmpty(strSmallClassID) || TextUtils.isEmpty(strBigClassID)) { showToast("大类或者小类ID不能为空"); } else { int mBigID = Integer.parseInt(strBigClassID); int mSmallID = Integer.parseInt(strSmallClassID); HDLDeviceManager.setEasyProgrammingSearchLocalData(mBigID, mSmallID, remarkStr); } } public void showToast(String text) { Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); } } app/src/main/res/layout/activity_main.xml
@@ -59,6 +59,21 @@ </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/btn_setting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" app/src/main/res/layout/activity_setting.xml
New file @@ -0,0 +1,162 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".activity.SettingActivity"> <LinearLayout android:id="@+id/mLinearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="20dp"> <TextView android:layout_width="match_parent" android:layout_height="30dp" android:text="修改本地的子网号和设备号" android:gravity="center|left" android:textSize="20dp" android:textColor="#000000"/> <EditText android:id="@+id/et_subnetID" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="10dp" android:inputType="number" android:maxLength="3" android:hint="@string/et_subnetid_hint" /> <EditText android:id="@+id/et_deviceID" android:layout_width="match_parent" android:layout_height="40dp" android:layout_marginTop="10dp" android:inputType="number" android:maxLength="3" android:hint="@string/et_deviceid_hint" /> <Button android:id="@+id/btn_save" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="10dp" android:text="@string/btn_save"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="20dp" android:layout_below="@+id/mLinearLayout1"> <TextView android:layout_width="match_parent" android:layout_height="30dp" android:text="修改是否允许简易编程搜索" android:gravity="center|left" android:textSize="20dp" android:textColor="#000000"/> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="60dp" android:layout_height="match_parent" android:text="大类:" android:gravity="center" android:textSize="16dp" ></TextView> <EditText android:id="@+id/et_bigclass" android:layout_width="120dp" android:layout_height="match_parent" android:layout_marginTop="10dp" android:gravity="center|left" android:hint="大类ID类型" android:inputType="number" android:maxLength="3" android:text="9" android:textSize="16dp" /> <TextView android:layout_width="60dp" android:layout_height="match_parent" android:text="小类:" android:gravity="center" android:textSize="16dp" android:layout_marginLeft="20dp" ></TextView> <EditText android:id="@+id/et_smallclass" android:layout_width="120dp" android:layout_height="match_parent" android:layout_marginTop="10dp" android:gravity="center|left" android:inputType="number" android:maxLength="3" android:textSize="16dp" android:text="1" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="60dp" android:layout_height="match_parent" android:text="备注:" android:gravity="center" android:textSize="16dp" ></TextView> <EditText android:id="@+id/et_remark" android:layout_width="200dp" android:layout_height="match_parent" android:layout_marginTop="10dp" android:gravity="center|left" android:inputType="number" android:hint="SDK备注" android:textSize="16dp" android:text="SDK特殊设备" /> <Button android:id="@+id/btn_save_allow" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="允许"/> </LinearLayout> <Button android:id="@+id/btn_save_close" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginTop="10dp" android:text="禁止"/> </LinearLayout> </RelativeLayout> app/src/main/res/values/strings.xml
@@ -1,4 +1,7 @@ <resources> <string name="app_name">HDL_SDK</string> <string name="app_version">hdl_lib_v1.6.5.20200117_beta</string> <string name="app_version">hdl_lib_v1.6.6.20200305_beta</string> <string name="btn_save">保存</string> <string name="et_subnetid_hint">子网号(范围0 - 254)</string> <string name="et_deviceid_hint">设备号号(范围0 - 254)</string> </resources> hdl_core/build.gradle
@@ -7,7 +7,7 @@ minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName "1.0.6" versionName "1.0.7" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java
@@ -64,6 +64,8 @@ HDLDeviceManager.init(context); } // /** // * 获取本地广播IP // * @return @@ -1030,4 +1032,6 @@ } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java
@@ -66,30 +66,19 @@ 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; //判断地热模块是否控制成功 //是否允许被简易编程搜索部分 private static boolean isAllowEasyProgrammingSearch = false;//是否允许被简易编程搜索 private static int SDKLocalBigClass = 9; //SDK 当前配置模拟设备的大类,默认为音乐、背景音乐功能 private static int SDKLocalSmallClass = 1; //SDK 当前配置模拟设备的小类,第三方背景音乐模块 private static String SDKLocalRemark = "特殊设备"; //SDK 当前配置模拟设备备注 /** @@ -100,12 +89,10 @@ 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); SDKLocalRemark = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK); // HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES; // HDLUdpCore.initMulticastSocket6000(); } @@ -122,6 +109,32 @@ HDLUdpCore.closeSocket6000(); } /** * 配置简易编程搜索返回的默认参数 * @param mSDKLocalBigClass * @param mSDKLocalSmallClass * @param mSDKLocalRemark */ public static void setEasyProgrammingSearchLocalData(int mSDKLocalBigClass, int mSDKLocalSmallClass, String mSDKLocalRemark){ SDKLocalBigClass = mSDKLocalBigClass; SDKLocalSmallClass = mSDKLocalSmallClass; if(mSDKLocalRemark != null){ SDKLocalRemark = mSDKLocalRemark; } isAllowEasyProgrammingSearch = true; } public static void setEasyProgrammingSearchLocalData(int mSDKLocalBigClass, int mSDKLocalSmallClass){ setEasyProgrammingSearchLocalData(mSDKLocalBigClass, mSDKLocalSmallClass,null); } /** * 设置是否允许被简易编程搜索 * @param isAllow */ public static void setIsAllowEasyProgrammingSearch(boolean isAllow){ isAllowEasyProgrammingSearch = isAllow; } /** * 处理CommandData并返回搜索或控制的有用信息 @@ -147,6 +160,10 @@ handleSearchData(getDatas); } } break; //简易编程设备搜索操作码、设备读取操作码 回复 case Configuration.DEVICES_SEARCH_COMMAND: handleDeviceSearchBackData(getDatas); break; // 控制设备 case Configuration.LIGHT_CTRL_BACK_COMMAND: @@ -279,6 +296,64 @@ /** * 回复简易编程搜索非网络设备,返回当前SDK信息 * * @param getDatas */ private static void sendDeviceSearchBackInfo(UdpDataBean getDatas) { byte[] remarkByte = StringUtil.stringtoBytes(SDKLocalRemark); byte[] addBytes = new byte[25]; addBytes[0] = getDatas.addBytes[0]; addBytes[1] = getDatas.addBytes[1]; System.arraycopy(remarkByte, 0, addBytes, 2, remarkByte.length > 20 ? 20 : remarkByte.length); addBytes[22] = (byte) SDKLocalBigClass; addBytes[23] = (byte) SDKLocalSmallClass; addBytes[24] = (byte) 1; HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_BACK_COMMAND, getDatas.sourceSubnetID, getDatas.sourceDeviceID, addBytes, getDatas.port, getDatas.ipAddress); // HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_BACK_COMMAND, // getDatas.sourceSubnetID, // getDatas.sourceDeviceID, // addBytes, // getDatas.port, NetWorkUtil.getLocalBroadCast()); } /** * 收到简易编程搜索非网络设备 * @param getDatas */ public static void handleDeviceSearchBackData(UdpDataBean getDatas){ //判断是否允许被简易编程搜索和回复 if(!isAllowEasyProgrammingSearch) return; if (getDatas.addBytes.length == 2) { sendDeviceSearchBackInfo(getDatas); } else { 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) == Crc.localDeviceID ) { sendDeviceSearchBackInfo(getDatas); break; } } } } } /** * 处理RCU搜索数据 * * @param getDatas @@ -342,9 +417,9 @@ } byte[] remarkByte; String remarkString = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK); // String remarkString = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK); remarkByte = StringUtil.stringtoBytes(remarkString); remarkByte = StringUtil.stringtoBytes(SDKLocalRemark); byte[] addBytes = new byte[53]; addBytes[0] = getDatas.addBytes[0]; @@ -2540,4 +2615,6 @@ } } hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLUdpCore.java
@@ -423,7 +423,7 @@ } break; case Configuration.DEVICES_SEARCH_COMMAND: //简易编程设备搜索操作码、设备读取操作码 回复 case Configuration.LIGHT_CTRL_BACK_COMMAND: case Configuration.CURTAIN_CTRL_BACK_COMMAND: case Configuration.AIR_CTRL_BACK_COMMAND: hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java
@@ -36,6 +36,12 @@ public static final String KEY_DEVICE_ID = "deviceid"; public static final String KEY_DEVICE_DATA_LIST = "hdldevicedatalist"; public static final String KEY_LOCAL_BIG_CLASS_ = "local_big_class"; public static final String KEY_LOCAL_Small_CLASS_ = "local_Small_class"; public static final int DEFAULT_SUB_ID = 254; public static final int DEFAULT_DEVICE_ID = 80; /** * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 *