From d6d95564b016c281bfa2e8c2454db8d71083e858 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期二, 26 十一月 2019 17:48:09 +0800 Subject: [PATCH] 2019-11-26 1.控制命令改为广播模式。 --- hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HandleSearch.java | 113 +++++-- app/src/main/res/layout/activity_add_devices_manually.xml | 113 ++++++++ hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java | 92 ++++++ app/src/main/res/values/strings.xml | 2 app/src/main/AndroidManifest.xml | 4 hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Bean/AppliancesInfo.java | 15 hdl_core/build.gradle | 2 hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java | 12 app/src/main/java/com/hdl/sdk/hdl_sdk/activity/AddDevicesManuallyActivity.java | 130 +++++++++ hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java | 8 README.md | 27 + hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java | 89 ++++++ app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java | 79 +++++ app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlActivity.java | 80 ++-- hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java | 32 + hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java | 2 app/src/main/res/layout/activity_main.xml | 10 hdl_core/libs/gson-2.8.5.jar | 0 18 files changed, 718 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 2ec9626..2022202 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,33 @@ HDL XW Android SDK Copyright (c) 2019 HDL Inc. +SDK 鐗堟湰锛歨dl_lib_v1.6.8.20191016_beta +1.鎺у埗閮芥敼鎴愬箍鎾舰寮忎簡锛屼笉璁板綍涓�绔彛鐨処P銆� + + +SDK 鐗堟湰锛歨dl_lib_v1.6.4.20191015_beta +1.澧炲姞鎼滅储瀹岃澶囨垨鑰呭娉ㄥ埛鏂板畬锛岃嚜鍔ㄤ繚瀛樹竴娆℃暟鎹埌鏈湴銆� +2.澧炲姞璇诲彇鏈湴鏁版嵁鎺ュ彛锛� +3.澧炲姞鍒锋柊鎵�鏈夎澶囩殑澶囨敞鍜岀姸鎬佹帴鍙o紱 + +鎺ュ彛璇存槑锛� + /** + * 璇诲彇鍜屽姞杞芥湰鍦版暟鎹� + */ + private void getLocalDevicesDataList() { + devicesDatas = HDLDeviceManager.getLocalDevicesDataList(); + if (devicesDatas.size() > 0) { + updateDeviceListView(); + HandleSearch.refreshAllDevicesStateAndRemarks();//濡傛灉鏈湴鏈夋暟鎹紝鍙互璋冪敤璇ユ柟娉曪紝閬嶅巻鍙戦�佹寚浠わ紝鍒锋柊鎵�鏈夎澶囩殑澶囨敞鍜岀姸鎬� + } else { + //showToast("鏈湴鏁版嵁涓虹┖"); + } + } + +/**淇濆瓨鏁版嵁鍒版湰鍦版帴鍙o紝闄DK鑷姩淇濆瓨鍚庯紝涓婂眰鍙互閫夋嫨鎵嬪姩璋冪敤淇濆瓨*/ +HDLDeviceManager.saveDevicesDataList(); + + 鎻愪緵澹板繀鍙疭DK椤圭洰 ##Version 1.0.2 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e4e3ec7..808a4de 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,7 +18,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + <activity android:name=".activity.AddDevicesManuallyActivity"></activity> <activity android:name=".activity.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -30,7 +30,7 @@ <activity android:name=".activity.CtrlActivity" /> <activity android:name=".activity.AudioActivity" /> <activity android:name=".activity.FreshAirActivity" /> - <activity android:name=".activity.GeothermalActivity"></activity> + <activity android:name=".activity.GeothermalActivity" /> <receiver android:name=".activity.BootComplete"> <intent-filter> diff --git a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/AddDevicesManuallyActivity.java b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/AddDevicesManuallyActivity.java new file mode 100644 index 0000000..a9e41ae --- /dev/null +++ b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/AddDevicesManuallyActivity.java @@ -0,0 +1,130 @@ +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.HDLDeviceManger.Parser.DeviceParser; +import com.hdl.sdk.hdl_sdk.R; + +import java.util.ArrayList; + +public class AddDevicesManuallyActivity extends Activity { + + private int bigType; + private int littleType; + private int mSubnetID; + private int mDeviceID; + private int port; + private String parentRemarks; + private ArrayList<String> parentRemarksList = new ArrayList(); + + private EditText et_subnetID,et_deviceID, et_bitType, et_littleType, et_remarks, et_port,et_remarks_mk; + private Button btn_add; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_devices_manually); + + 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); + btn_add = findViewById(R.id.btn_add); + + btn_add.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + addDevicesManuallyWithoutSearchingAll(); + + } + }); + + + } + + + + + 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 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); + parentRemarks = remarksMkString; + port = Integer.parseInt(et_portString); + + String[] arr = remarksString.split("-"); + if(arr.length >0){ + for(int i = 0; i< arr.length; i++){ + parentRemarksList.add(arr[i]); + } + }else { + parentRemarksList.add(remarksString); + } + + + DeviceParser.addDevicesManuallyWithoutSearchingAll( bigType, littleType, mSubnetID, mDeviceID, port, parentRemarks, parentRemarksList); + } + + + private void showToast(String text) { + Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); + } +} diff --git a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlActivity.java b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlActivity.java index 25d2d99..543a8af 100644 --- a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlActivity.java +++ b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/CtrlActivity.java @@ -23,6 +23,7 @@ import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DeviceStateEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightFeedBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent; +import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -126,8 +127,9 @@ sensorText.setVisibility(View.GONE); - if (appliancesInfo.getCurState() != null) { - int curLightState = (int) appliancesInfo.getCurState(); + if (appliancesInfo.getCurStateObject() != null) { + + int curLightState = HDLUtlis.getIntegerByObject(appliancesInfo.getCurStateObject()); lightText.setText("褰撳墠鐏厜浜害锛�" + curLightState); lightBtn.setText("褰撳墠鐏厜浜害锛�" + curLightState); @@ -163,9 +165,9 @@ curtainBtn4.setVisibility(View.GONE); curtainBtn5.setVisibility(View.GONE); - if (appliancesInfo.getCurState() != null) { + if (appliancesInfo.getCurStateObject() != null) { String stringCurtainState = ""; - int curCurtainState = (int) appliancesInfo.getCurState(); + int curCurtainState = HDLUtlis.getIntegerByObject(appliancesInfo.getCurStateObject()); Log.i("djl", "curCurtainState = " + curCurtainState); switch (curCurtainState) { case CurtainCtrlParser.TYPE_STATE_PAUSE: @@ -197,8 +199,8 @@ curText1.setVisibility(View.GONE); curtainBtn.setVisibility(View.GONE); - if (appliancesInfo.getCurState() != null) { - curText2.setText("褰撳墠绐楀笜鐘舵�侊細" + appliancesInfo.getCurState()); + if (appliancesInfo.getCurStateObject() != null) { + curText2.setText("褰撳墠绐楀笜鐘舵�侊細" + HDLUtlis.getIntegerByObject(appliancesInfo.getCurStateObject())); } else { curText2.setText("鏈幏鍙栧埌绐楀笜妯″潡鐘舵��"); } @@ -410,8 +412,8 @@ lightText.setVisibility(View.GONE); logicBtn.setVisibility(View.GONE); logicText.setVisibility(View.GONE); - if (appliancesInfo.getCurState() != null) { - float value = (float) appliancesInfo.getCurState(); + if (appliancesInfo.getCurStateObject() != null) { + float value = (float) appliancesInfo.getCurStateObject(); sensorBtn.setText("浼犳劅鍣ㄦ暟鍊硷細" + value); } break; @@ -636,10 +638,10 @@ } int tempInt = Integer.parseInt(tempStr); - if (tempInt < 16 || tempInt > 30) { - showToast("娓╁害璁剧疆鑼冨洿涓猴細16~30鎽勬皬搴�(鈩�)"); - return; - } +// if (tempInt < 16 || tempInt > 30) { +// showToast("娓╁害璁剧疆鑼冨洿涓猴細16~30鎽勬皬搴�(鈩�)"); +// return; +// } switch (airModeState) { case 0: @@ -948,7 +950,7 @@ showToast("鑾峰彇鐏厜鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - lightBtn.setText("浜害 = " + event.getAppliancesInfo().getCurState()); + lightBtn.setText("浜害 = " + HDLUtlis.getIntegerByObject(event.getAppliancesInfo().getCurStateObject())); } break; case HDLApConfig.TYPE_CURTAIN_GLYSTRO: @@ -961,7 +963,7 @@ } //绐楀笜妯″潡锛歝urState:0=鍋滄,1=鎵撳紑,2=鍏抽棴銆� //寮�鍚堝笜鐢垫満锛屽嵎甯樼數鏈猴細curState:1-100寮�鍚堝害銆� - int curState = (int) event.getAppliancesInfo().getCurState(); + int curState = HDLUtlis.getIntegerByObject(event.getAppliancesInfo().getCurStateObject()); if (event.getAppliancesInfo().getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) {//鍒ゆ柇鏄惁涓虹獥甯樻ā鍧�,鍚﹀垯涓哄紑鍚堝笜鎴栧嵎甯樼數鏈� switch (curState) { case CurtainCtrlParser.curtainOff: @@ -1123,7 +1125,7 @@ showToast("鑾峰彇浼犳劅鍣�---骞叉帴鐐圭姸鎬佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float dryContactValue = (float) event.getAppliancesInfo().getCurState(); + float dryContactValue = (float) event.getAppliancesInfo().getCurStateObject(); String dryContactUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---骞叉帴鐐圭姸鎬侊細" + dryContactValue + dryContactUnit); Log.i("djl", "浼犳劅鍣�---骞叉帴鐐圭姸鎬侊細" + dryContactValue + dryContactUnit); @@ -1134,7 +1136,7 @@ showToast("鑾峰彇浼犳劅鍣�---绉诲姩鎺㈡祴鐏垫晱搴︾姸鎬佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float mdValue = (float) event.getAppliancesInfo().getCurState(); + float mdValue = (float) event.getAppliancesInfo().getCurStateObject(); String mdValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---绉诲姩鎺㈡祴鐏垫晱搴︼細" + mdValue + mdValueUnit); Log.i("djl", "浼犳劅鍣�---绉诲姩鎺㈡祴鐏垫晱搴︼細" + mdValue + mdValueUnit); @@ -1145,7 +1147,7 @@ showToast("鑾峰彇浼犳劅鍣�---娓╁害鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float tempValue = (float) event.getAppliancesInfo().getCurState(); + float tempValue = (float) event.getAppliancesInfo().getCurStateObject(); String tempValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---娓╁害锛�" + tempValue + tempValueUnit); Log.i("djl", "浼犳劅鍣�---娓╁害锛�" + tempValue + tempValueUnit); @@ -1156,7 +1158,7 @@ showToast("鑾峰彇浼犳劅鍣�---婀垮害鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float humidityValue = (float) event.getAppliancesInfo().getCurState(); + float humidityValue = (float) event.getAppliancesInfo().getCurStateObject(); String humidityValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---婀垮害锛�" + humidityValue + humidityValueUnit); Log.i("djl", "浼犳劅鍣�---婀垮害锛�" + humidityValue + humidityValueUnit); @@ -1167,7 +1169,7 @@ showToast("鑾峰彇浼犳劅鍣�---鐓у害鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float illuminaceValue = (float) event.getAppliancesInfo().getCurState(); + float illuminaceValue = (float) event.getAppliancesInfo().getCurStateObject(); String illuminaceValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---鐓у害锛�" + illuminaceValue + illuminaceValueUnit); Log.i("djl", "浼犳劅鍣�---鐓у害锛�" + illuminaceValue + illuminaceValueUnit); @@ -1178,7 +1180,7 @@ showToast("鑾峰彇浼犳劅鍣�---褰撳墠绌烘皵璐ㄩ噺绛夌骇鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float vocValue = (float) event.getAppliancesInfo().getCurState(); + float vocValue = (float) event.getAppliancesInfo().getCurStateObject(); String vocValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---褰撳墠绌烘皵璐ㄩ噺绛夌骇锛�" + vocValue + vocValueUnit); Log.i("djl", "浼犳劅鍣�---褰撳墠绌烘皵璐ㄩ噺绛夌骇锛�" + vocValue + vocValueUnit); @@ -1189,7 +1191,7 @@ showToast("鑾峰彇浼犳劅鍣�---pm2.5鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float pm2_5Value = (float) event.getAppliancesInfo().getCurState(); + float pm2_5Value = (float) event.getAppliancesInfo().getCurStateObject(); String pm2_5ValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---pm2.5锛�" + pm2_5Value + pm2_5ValueUnit); Log.i("djl", "浼犳劅鍣�---pm2.5锛�" + pm2_5Value + pm2_5ValueUnit); @@ -1200,7 +1202,7 @@ showToast("鑾峰彇浼犳劅鍣�---浜屾哀鍖栫⒊鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float co2Value = (float) event.getAppliancesInfo().getCurState(); + float co2Value = (float) event.getAppliancesInfo().getCurStateObject(); String co2ValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---浜屾哀鍖栫⒊锛�" + co2Value + co2ValueUnit); Log.i("djl", "浼犳劅鍣�---浜屾哀鍖栫⒊锛�" + co2Value + co2ValueUnit); @@ -1211,7 +1213,7 @@ showToast("鑾峰彇浼犳劅鍣�---娑插寲鐭虫补姘旂姸鎬佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float lpgValue = (float) event.getAppliancesInfo().getCurState(); + float lpgValue = (float) event.getAppliancesInfo().getCurStateObject(); String lpgValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---娑插寲鐭虫补姘旓細" + lpgValue + lpgValueUnit); Log.i("djl", "浼犳劅鍣�---娑插寲鐭虫补姘旓細" + lpgValue + lpgValueUnit); @@ -1222,7 +1224,7 @@ showToast("鑾峰彇浼犳劅鍣�---浜哄伐鐓ゆ皵鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float coh2Value = (float) event.getAppliancesInfo().getCurState(); + float coh2Value = (float) event.getAppliancesInfo().getCurStateObject(); String coh2ValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---浜哄伐鐓ゆ皵锛�" + coh2Value + coh2ValueUnit); Log.i("djl", "浼犳劅鍣�---浜哄伐鐓ゆ皵锛�" + coh2Value + coh2ValueUnit); @@ -1233,7 +1235,7 @@ showToast("鑾峰彇浼犳劅鍣�---澶╃劧姘旂姸鎬佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float ch4Value = (float) event.getAppliancesInfo().getCurState(); + float ch4Value = (float) event.getAppliancesInfo().getCurStateObject(); String ch4ValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---澶╃劧姘旓細" + ch4Value + ch4ValueUnit); Log.i("djl", "浼犳劅鍣�---澶╃劧姘旓細" + ch4Value + ch4ValueUnit); @@ -1244,7 +1246,7 @@ showToast("鑾峰彇浼犳劅鍣�---鐑熼浘鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float smogValue = (float) event.getAppliancesInfo().getCurState(); + float smogValue = (float) event.getAppliancesInfo().getCurStateObject(); String smogValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---鐑熼浘锛�" + smogValue + smogValueUnit); Log.i("djl", "浼犳劅鍣�---鐑熼浘锛�" + smogValue + smogValueUnit); @@ -1255,7 +1257,7 @@ showToast("鑾峰彇浼犳劅鍣�---椋庨�熺姸鎬佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float windSpeedValue = (float) event.getAppliancesInfo().getCurState(); + float windSpeedValue = (float) event.getAppliancesInfo().getCurStateObject(); String windSpeedValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---椋庨�燂細" + windSpeedValue + windSpeedValueUnit); Log.i("djl", "浼犳劅鍣�---椋庨�燂細" + windSpeedValue + windSpeedValueUnit); @@ -1266,7 +1268,7 @@ showToast("鑾峰彇浼犳劅鍣�---椋庡帇鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float windPressureValue = (float) event.getAppliancesInfo().getCurState(); + float windPressureValue = (float) event.getAppliancesInfo().getCurStateObject(); String windPressureValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---椋庡帇锛�" + windPressureValue + windPressureValueUnit); Log.i("djl", "浼犳劅鍣�---椋庡帇锛�" + windPressureValue + windPressureValueUnit); @@ -1277,7 +1279,7 @@ showToast("鑾峰彇浼犳劅鍣�---娑蹭綋娴侀噺鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float liquidFlowValue = (float) event.getAppliancesInfo().getCurState(); + float liquidFlowValue = (float) event.getAppliancesInfo().getCurStateObject(); String liquidFlowValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---娑蹭綋娴侀噺锛�" + liquidFlowValue + liquidFlowValueUnit); Log.i("djl", "浼犳劅鍣�---娑蹭綋娴侀噺锛�" + liquidFlowValue + liquidFlowValueUnit); @@ -1288,7 +1290,7 @@ showToast("鑾峰彇浼犳劅鍣�---娑蹭綋鍘嬪姏鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float liquidPressureValue = (float) event.getAppliancesInfo().getCurState(); + float liquidPressureValue = (float) event.getAppliancesInfo().getCurStateObject(); String liquidPressureValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---娑蹭綋鍘嬪姏锛�" + liquidPressureValue + liquidPressureValueUnit); Log.i("djl", "浼犳劅鍣�---娑蹭綋鍘嬪姏锛�" + liquidPressureValue + liquidPressureValueUnit); @@ -1299,7 +1301,7 @@ showToast("鑾峰彇浼犳劅鍣�---娑蹭綋娣卞害鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float liquidDepthValue = (float) event.getAppliancesInfo().getCurState(); + float liquidDepthValue = (float) event.getAppliancesInfo().getCurStateObject(); String liquidDepthValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---娑蹭綋娣卞害锛�" + liquidDepthValue + liquidDepthValueUnit); Log.i("djl", "浼犳劅鍣�---娑蹭綋娣卞害锛�" + liquidDepthValue + liquidDepthValueUnit); @@ -1310,7 +1312,7 @@ showToast("鑾峰彇浼犳劅鍣�---闆ㄩ噺鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float rainFallValue = (float) event.getAppliancesInfo().getCurState(); + float rainFallValue = (float) event.getAppliancesInfo().getCurStateObject(); String rainFallValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---闆ㄩ噺锛�" + rainFallValue + rainFallValueUnit); Log.i("djl", "浼犳劅鍣�---闆ㄩ噺锛�" + rainFallValue + rainFallValueUnit); @@ -1321,7 +1323,7 @@ showToast("鑾峰彇浼犳劅鍣�---閲嶉噺鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float weightValue = (float) event.getAppliancesInfo().getCurState(); + float weightValue = (float) event.getAppliancesInfo().getCurStateObject(); String weightValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---閲嶉噺锛�" + weightValue + weightValueUnit); Log.i("djl", "浼犳劅鍣�---閲嶉噺锛�" + weightValue + weightValueUnit); @@ -1332,7 +1334,7 @@ showToast("鑾峰彇浼犳劅鍣�---閲嶉噺鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float height_lengthValue = (float) event.getAppliancesInfo().getCurState(); + float height_lengthValue = (float) event.getAppliancesInfo().getCurStateObject(); String height_lengthValueUnit = ((SensorStateBackInfo) event).getUnite(); showToast("浼犳劅鍣�---閲嶉噺锛�" + height_lengthValue + height_lengthValueUnit); Log.i("djl", "浼犳劅鍣�---閲嶉噺锛�" + height_lengthValue + height_lengthValueUnit); @@ -1343,7 +1345,7 @@ showToast("鑾峰彇浼犳劅鍣�---鐗╀綋閫熷害鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float objectSpeedValue = (float) event.getAppliancesInfo().getCurState(); + float objectSpeedValue = (float) event.getAppliancesInfo().getCurStateObject(); String objectSpeedUnite = ((SensorStateBackInfo) event).getUnite();//鏁板�煎崟浣� showToast("浼犳劅鍣�---鐗╀綋閫熷害锛�" + objectSpeedValue + objectSpeedUnite); Log.i("djl", "浼犳劅鍣�---鐗╀綋閫熷害锛�" + objectSpeedValue + objectSpeedUnite); @@ -1354,7 +1356,7 @@ showToast("鑾峰彇浼犳劅鍣�---闇囧姩鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float shakeValue = (float) event.getAppliancesInfo().getCurState(); + float shakeValue = (float) event.getAppliancesInfo().getCurStateObject(); String shakeValueUnite = ((SensorStateBackInfo) event).getUnite();//鏁板�煎崟浣� showToast("浼犳劅鍣�---闇囧姩锛�" + shakeValue + shakeValueUnite); Log.i("djl", "浼犳劅鍣�---闇囧姩锛�" + shakeValue + shakeValueUnite); @@ -1365,7 +1367,7 @@ showToast("鑾峰彇浼犳劅鍣�---鐢靛帇鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float voltageValue = (float) event.getAppliancesInfo().getCurState(); + float voltageValue = (float) event.getAppliancesInfo().getCurStateObject(); String voltageValueUnite = ((SensorStateBackInfo) event).getUnite();//鏁板�煎崟浣� showToast("浼犳劅鍣�---鐢靛帇锛�" + voltageValue + voltageValueUnite); Log.i("djl", "浼犳劅鍣�---鐢靛帇锛�" + voltageValue + voltageValueUnite); @@ -1376,7 +1378,7 @@ showToast("鑾峰彇浼犳劅鍣�---鐢垫祦鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float electricityValue = (float) event.getAppliancesInfo().getCurState(); + float electricityValue = (float) event.getAppliancesInfo().getCurStateObject(); String electricityValueUnite = ((SensorStateBackInfo) event).getUnite();//鏁板�煎崟浣� showToast("浼犳劅鍣�---鐢垫祦锛�" + electricityValue + electricityValueUnite); Log.i("djl", "浼犳劅鍣�---鐢垫祦锛�" + electricityValue + electricityValueUnite); @@ -1387,7 +1389,7 @@ showToast("鑾峰彇浼犳劅鍣�---鍔熺巼鐘舵�佸け璐ワ紝璇烽噸鏂板啀璇�"); return; } - float powerValue = (float) event.getAppliancesInfo().getCurState(); + float powerValue = (float) event.getAppliancesInfo().getCurStateObject(); String powerValueUnite = ((SensorStateBackInfo) event).getUnite();//鏁板�煎崟浣� showToast("浼犳劅鍣�---鍔熺巼锛�" + powerValue + powerValueUnite); Log.i("djl", "浼犳劅鍣�---鍔熺巼锛�" + powerValue + powerValueUnite); diff --git a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java index 6c3e53b..5b09f1c 100644 --- a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java +++ b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java @@ -19,11 +19,14 @@ 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.Core.HDLCommand; +import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLDeviceManager; +import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HandleSearch; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.BgmInfoEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DevicesInfoEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.ThirdPartyBgmInfoEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.WarningInfoEvent; import com.hdl.sdk.hdl_sdk.R; +import com.hdl.sdk.hdl_sdk.utlis.HDLLog; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; @@ -37,7 +40,7 @@ public class MainActivity extends AppCompatActivity { private Button btn, btn2; - private Button btn_get_all,btn_on_all, btn_off_all; + private Button btn_get_all,btn_on_all, btn_off_all,btn_getlocal,btn_getlocal_add; private TextView tv; private EditText editText; private List<DevicesData> devicesDatas; @@ -72,7 +75,10 @@ btn_get_all = findViewById(R.id.btn_get_all); btn_on_all = findViewById(R.id.btn_on_all); btn_off_all = findViewById(R.id.btn_off_all); - + btn_getlocal = findViewById(R.id.btn_getlocal); + + btn_getlocal_add = findViewById(R.id.btn_getlocal_add); + tv = findViewById(R.id.tv); editText = findViewById(R.id.edt); editText.setText("172.168.188.100"); @@ -142,8 +148,77 @@ sendAll(false); } }); + + + btn_getlocal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + clearListView(); + getLocalDevicesDataList(); + } + }); + + + + + btn_getlocal_add.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(AddDevicesManuallyActivity.class); + + } + }); } + public void startActivity(Class<?> clazz) { + Intent intent = new Intent(this, clazz); + startActivity(intent); + } + /** + * 璇诲彇鍜屽姞杞芥湰鍦版暟鎹� + */ + private void getLocalDevicesDataList() { + devicesDatas = HDLDeviceManager.getLocalDevicesDataList(); + if (devicesDatas.size() > 0) { + updateDeviceListView(); + HandleSearch.refreshAllDevicesStateAndRemarks();//濡傛灉鏈湴鏈夋暟鎹紝鍙互璋冪敤璇ユ柟娉曪紝閬嶅巻鍙戦�佹寚浠わ紝鍒锋柊鎵�鏈夎澶囩殑澶囨敞鍜岀姸鎬� + } else { + showToast("鏈湴鏁版嵁涓虹┖"); + } + } + + /** + * 鍒锋柊璁惧鍒楄〃鏁版嵁 + */ + private void updateDeviceListView() { + int countAll = 0; + for (DevicesData devicesData : devicesDatas) { + countAll += devicesData.getAppliancesInfoList().size(); + } + tv.setText("鎬诲叡妯″潡鏁帮細" + devicesDatas.size() + " 鎬诲叡鍥炶矾鏁帮細" + countAll); + HDLLog.I("鑾峰彇鏁版嵁鎴愬姛锛氭�诲叡妯″潡鏁帮細" + devicesDatas.size() + " 鎬诲叡鍥炶矾鏁帮細" + countAll); + + for (int i = 0; i < devicesDatas.size(); i++) { + if (TextUtils.isEmpty(devicesDatas.get(i).getRemark())) { + listString.add("鏆傛棤澶囨敞"); + } else { + listString.add(devicesDatas.get(i).getRemark()); + } + } + adapter.notifyDataSetChanged(); + } + + + /** + * 娓呯┖鏁版嵁骞跺埛鏂板垪琛� + */ + private void clearListView() { + if (devicesDatas != null) devicesDatas.clear(); + if (listString != null) listString.clear(); + + adapter.notifyDataSetChanged(); + } @Override protected void onDestroy() { diff --git a/app/src/main/res/layout/activity_add_devices_manually.xml b/app/src/main/res/layout/activity_add_devices_manually.xml new file mode 100644 index 0000000..9033f3d --- /dev/null +++ b/app/src/main/res/layout/activity_add_devices_manually.xml @@ -0,0 +1,113 @@ +<?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:id="@+id/activity_main" + android:layout_width="match_parent" + android:layout_height="match_parent" +> + + + + <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"> + + <TextView + android:layout_width="match_parent" + android:layout_height="50dp" + android:text="鎵嬪姩娣诲姞" + android:gravity="center|left" + android:textSize="24sp" + android:textColor="@android:color/black" + /> + + + + <TextView + android:layout_width="100dp" + android:layout_height="match_parent" + android:gravity="center|left" + android:textSize="18sp" + android:textColor="@android:color/black" + android:text="璁惧鍙傛暟" /> + + <EditText + android:id="@+id/et_subnetID" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:inputType="number" + android:maxLength="3" + android:hint="瀛愮綉鍙凤紙鑼冨洿0 - 254锛�" + /> + + <EditText + android:id="@+id/et_deviceID" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:inputType="number" + android:maxLength="3" + android:hint="璁惧鍙凤紙鑼冨洿0 - 254锛�" + /> + <EditText + android:id="@+id/et_bitType" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:inputType="number" + android:maxLength="3" + android:hint="澶х被" + /> + + <EditText + android:id="@+id/et_littleType" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:inputType="number" + android:maxLength="3" + android:hint="灏忕被" + /> + + <EditText + android:id="@+id/et_remarks_mk" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:hint="璇疯緭鍏ユā鍧楀娉�" + /> + + <EditText + android:id="@+id/et_remarks" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:hint="璇疯緭鍏ュ娉紝澶氫釜鍥炶矾澶囨敞鈥�-鈥濆垎鍓�" + /> + + <EditText + android:id="@+id/et_port" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:inputType="number" + android:maxLength="4" + android:text="6000" + android:hint="绔彛" + /> + + <Button + android:id="@+id/btn_add" + android:layout_width="match_parent" + android:layout_height="50dp" + android:layout_marginTop="10dp" + android:text="娣诲姞"/> + + </LinearLayout> + +</RelativeLayout> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 5879771..18c4b53 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -25,6 +25,16 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="鎼滅储瀹跺眳璁惧" /> + <Button + android:id="@+id/btn_getlocal" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="鍔犺浇鏈湴璁惧" /> + <Button + android:id="@+id/btn_getlocal_add" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="娣诲姞鏁版嵁" /> <Button android:id="@+id/btn_get_all" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0767ba..3d676c0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ <resources> <string name="app_name">HDL_SDK</string> - <string name="app_version">hdl_lib_v1.6.2.20191008_beta</string> + <string name="app_version">hdl_lib_v1.6.4.20191015_beta</string> </resources> diff --git a/hdl_core/build.gradle b/hdl_core/build.gradle index 20a763d..6ac4331 100644 --- a/hdl_core/build.gradle +++ b/hdl_core/build.gradle @@ -7,7 +7,7 @@ minSdkVersion 17 targetSdkVersion 28 versionCode 1 - versionName "1.0.4" + versionName "1.0.5" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/hdl_core/libs/gson-2.8.5.jar b/hdl_core/libs/gson-2.8.5.jar new file mode 100644 index 0000000..0d5baf3 --- /dev/null +++ b/hdl_core/libs/gson-2.8.5.jar Binary files differ diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Bean/AppliancesInfo.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Bean/AppliancesInfo.java index 079c91d..4fa306b 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Bean/AppliancesInfo.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Bean/AppliancesInfo.java @@ -49,7 +49,7 @@ this.port = port; } - public String getIpAddress() { + public String getIpAddressDevice() { return ipAddress; } @@ -89,9 +89,20 @@ this.parentRemarks = parentRemarks; } - public Object getCurState() { +// public Object getCurState() { +// return curState; +// } + + public Object getCurStateObject() { return curState; } +// public int getCurStateToInt() { +// return HDLUtlis.getIntegerByObject(curState); +// } +// +// public float getCurStateToFloat() { +// return HDLUtlis.getFloatByObject(curState); +// } public void setCurState(Object curState) { this.curState = curState; diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java index 2a44bd2..4dc6b19 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java @@ -27,6 +27,7 @@ import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightFeedBackEvent; import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent; 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.HDLUtlis; @@ -63,6 +64,21 @@ HDLDeviceManager.init(context); } +// /** +// * 鑾峰彇鏈湴骞挎挱IP +// * @return +// */ +// public static String getLocalBroadCastIp(){ +// return NetWorkUtil.getLocalBroadCast(); +// } + + /** + * 鑾峰彇鏈湴骞挎挱IP + * @return + */ + public static String getLocalBroadCastIp(){ + return NetWorkUtil.getLocalBroadCast(); + } /** * 鏄惁寮�鍚疭DK鏃ュ織鎵撳嵃 @@ -617,7 +633,7 @@ } } //鏇存柊鎵�鏈夎澶囩姸鎬� - HandleSearch.refreshAllDevicesState(); +// HandleSearch.refreshAllDevicesState(30); if (!deviceStateBeanList.isEmpty()) { return deviceStateBeanList; } else { @@ -649,7 +665,7 @@ ) { // curState = (int) infos.get(j).getCurState();//鏃� //20190712瑙e喅寮哄埗杞崲int绫诲瀷闂�� - curState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState()); + curState = HDLUtlis.getIntegerByObject(infos.get(j).getCurStateObject()); break outter; } @@ -680,7 +696,7 @@ ) { //杩欓噷搴旇鏄淇鐨勶紝鏆傛椂鏈壘鍒般�� //20190712瑙e喅寮哄埗杞崲int绫诲瀷闂�� - int state = HDLUtlis.getIntegerByObject(infos.get(j).getCurState()); + int state = HDLUtlis.getIntegerByObject(infos.get(j).getCurStateObject()); switch (state) { case -1: curState = 0; @@ -815,7 +831,7 @@ // HDLLog.info("鍙戝嚭鏁版嵁锛�"+sendData+"瀛愮綉id:"+info.getDeviceSubnetID()+" 璁惧id锛�"+info.getDeviceDeviceID()); cusSendCommand(command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes, - info.getPort(), info.getIpAddress()); + info.getPort(), getLocalBroadCastIp()); } } @@ -857,7 +873,7 @@ // HDLLog.info("鍙戝嚭鏁版嵁锛�"+sendData+"瀛愮綉id:"+info.getDeviceSubnetID()+" 璁惧id锛�"+info.getDeviceDeviceID()); cusSendCommand(command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes, - info.getPort(), info.getIpAddress()); + info.getPort(), getLocalBroadCastIp()); } } @@ -891,7 +907,7 @@ // HDLLog.info("鍙戝嚭鏁版嵁锛�"+sendData+"瀛愮綉id:"+info.getDeviceSubnetID()+" 璁惧id锛�"+info.getDeviceDeviceID()); cusSendCommand(command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes, - info.getPort(), info.getIpAddress()); + info.getPort(), getLocalBroadCastIp()); } } @@ -920,7 +936,7 @@ */ private static void addSendData(final AppliancesInfo info, byte[] addBytes, final int type) { - final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes, info.getPort(), info.getIpAddress()); + final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes, info.getPort(), getLocalBroadCastIp()); sendDatas.count = 0; @@ -966,7 +982,7 @@ // } } if (!sendDatas.isCtrlSuccess) { - cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes, info.getPort(), info.getIpAddress()); + cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes, info.getPort(), getLocalBroadCastIp()); } else { // HDLLog.info("鎺у埗宸叉垚鍔燂紝鍋滄"); sendCycleTimer.cancel(); diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java index 7e97d83..ddd3bda 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java @@ -4,6 +4,9 @@ import android.content.Intent; import android.text.TextUtils; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; +import com.google.gson.reflect.TypeToken; 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; @@ -95,12 +98,16 @@ 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(); } + /** @@ -213,7 +220,7 @@ SPUtils.setParam(viewContext, SPUtils.KEY_HDL_RCU_IP, getDatas.ipAddress); } handleSearchData(getDatas); - HandleSearch.deviceListCallBack();//鎵嬪姩娣诲姞璁惧鎴愬姛绔嬪埢杩斿洖 + HandleSearch.OnDeviceListGetSuccessCallBack();//鎵嬪姩娣诲姞璁惧鎴愬姛绔嬪埢杩斿洖 HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_DEVICE_BACK_COMMAND, Crc.localSubnetID, Crc.localDeviceID, @@ -230,7 +237,7 @@ break; case Configuration.MANUAL_ADD_REMARK_COMMAND: handleRemarkCurStateData(getDatas); - HandleSearch.deviceListCallBack();//鎵嬪姩娣诲姞澶囨敞鎴愬姛绔嬪埢杩斿洖 + HandleSearch.OnDeviceListGetSuccessCallBack();//鎵嬪姩娣诲姞澶囨敞鎴愬姛绔嬪埢杩斿洖 HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_REMARK_BACK_COMMAND, Crc.localSubnetID, Crc.localDeviceID, @@ -839,7 +846,7 @@ setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true); for (int oldAirInedx = 0; oldAirInedx < oldAirInfo.length; oldAirInedx++) { if (oldAirInedx == 0) { -// if (oldAirInfo[0] != newAirInfo[8]) {//2019 鍘绘帀鐩稿悓寮�鍏崇姸鎬佸垽鏂�,瑙e喅寮�鐘舵�佷笅,璋冪敤寮�鍛戒护鐘舵�佷笅,涓嶅仠閲嶅彂闂 + if (oldAirInfo[0] != newAirInfo[8]) {//2019 鍘绘帀鐩稿悓寮�鍏崇姸鎬佸垽鏂�,瑙e喅寮�鐘舵�佷笅,璋冪敤寮�鍛戒护鐘舵�佷笅,涓嶅仠閲嶅彂闂 oldAirInfo[0] = newAirInfo[8]; curAirInfo = new byte[]{AirCtrlParser.airSwich, newAirInfo[8]}; if (curAirInfo.length > 1) { @@ -853,7 +860,7 @@ EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true)); } -// } + } } else if (oldAirInedx == 1) { // int mode = ((newAirInfo[4] & 0xf0) >> 4); int mode = newAirInfo[9] & 0xff; @@ -2413,4 +2420,78 @@ if(success == null) success = false; return success; } + + /** + * 淇濆瓨璁惧鏁版嵁鍒楄〃 + * 鏍规嵁闇�瑕侊紝瀹炴椂淇濆瓨褰撳墠鏁版嵁 + * 2019-10-14 + * @return boolean + */ + public static boolean saveDevicesDataList() { + try { + Gson gson = new Gson(); + String jsonStr = gson.toJson(devicesDataList); //灏哃ist杞崲鎴怞son +// HDLLog.info("saveDevicesDataList: \n" + jsonStr); + SPUtils.setParam(viewContext, SPUtils.KEY_DEVICE_DATA_LIST, jsonStr); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } + + /** + * 鍔犺浇鏈湴璁惧鏁版嵁鍒楄〃 + * + * @return devicesDataList + */ + public static List<DevicesData> getLocalDevicesDataList() { + try { + String getJsonStr = SPUtils.getParam(viewContext, SPUtils.KEY_DEVICE_DATA_LIST, "").toString(); +// HDLLog.I("getJsonStr: \n" + getJsonStr); + if (!TextUtils.isEmpty(getJsonStr)) //闃茬┖鍒ゆ柇 + { + Gson gson = new Gson(); + devicesDataList = gson.fromJson(getJsonStr, new TypeToken<List<DevicesData>>() { + }.getType()); //灏唈son瀛楃涓茶浆鎹㈡垚List闆嗗悎 + + } + } catch (JsonSyntaxException e) { + e.printStackTrace(); + } + if (devicesDataList == null) devicesDataList = new ArrayList<>(); + List<DevicesData> devicesDataList2 = devicesDataList; + + setRemarkList();//鍔犺浇澶囨敞list + + if (!TextUtils.isEmpty(HandleSearch.rcuIp)) {//鍒ゆ柇涔嬪墠鏄惁涓篟UC妯″紡 + HandleSearch.curSearchMode = HandleSearch.GET_RCU_DEVICES; + HDLUdpCore.closeSocket6000(); + HDLUdpCore.init6008(); + }else { + HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES; + HDLUdpCore.closeSocket6008(); + HDLUdpCore.init6000(); + } + + return devicesDataList2; + } + + + + private static void setRemarkList(){ + listRemarks.clear(); + for (int j = 0; j < devicesDataList.size(); j++) { + if (devicesDataList.get(j).getAppliancesInfoList().get(0).getBigType() != Configuration.AUDIO_BIG_TYPE) { + for (int i = 0, len = devicesDataList.get(j).getAppliancesInfoList().size(); i < len; i++) { + ListRemarks listRemarksTemp = new ListRemarks(); + listRemarksTemp.setCallBack(false); + listRemarksTemp.setAppliancesInfo(devicesDataList.get(j).getAppliancesInfoList().get(i)); + listRemarks.add(listRemarksTemp); + } + } + } + } + + } diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HandleSearch.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HandleSearch.java index 042d813..ba65550 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HandleSearch.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HandleSearch.java @@ -20,7 +20,7 @@ public class HandleSearch { - public static boolean isSearching = true; + public static boolean isSearching = false; public static int curSearchMode = 0; public static String rcuIp = "";//涓诲姩浼犲叆鐨剅cu ip鍦板潃 // private static Timer getRcuIpTimer = null;//鑾峰彇Rcuip Timer @@ -389,38 +389,87 @@ } } - /** * 杩斿洖璁惧鍒楄〃 + * 2019-10-14 */ - public static void deviceListCallBack() { - byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2]; - debugBytes[0] = 1; - debugBytes[1] = 1; - debugBytes[2] = 1; - debugBytes[3] = 1; - debugBytes[4] = 1; - debugBytes[5] = 1; + public static void OnDeviceListGetSuccessCallBack() { +// byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2]; +// debugBytes[0] = 1; +// debugBytes[1] = 1; +// debugBytes[2] = 1; +// debugBytes[3] = 1; +// debugBytes[4] = 1; +// debugBytes[5] = 1; +// +// for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) { +// +// debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID(); +// debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID(); +// String device = "绗� " + (i + 1) + " 涓ā鍧楋細妯″潡澶囨敞鍚嶇О锛�" + HDLDeviceManager.devicesDataList.get(i).getRemark() +// + ",瀛愮綉鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() +// + ",璁惧鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() +// + ",鍥炶矾鏁帮細" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n"; +// HDLLog.info(device); +// } - for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) { - - debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID(); - debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID(); - String device = "绗� " + (i + 1) + " 涓ā鍧楋細妯″潡澶囨敞鍚嶇О锛�" + HDLDeviceManager.devicesDataList.get(i).getRemark() - + ",瀛愮綉鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() - + ",璁惧鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() - + ",鍥炶矾鏁帮細" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n"; - HDLLog.info(device); - } - -// HDLUdpCore.sendTestCMD(debugBytes, HDLTest.SEND_TEST_PORT); EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true)); - - + /**鎼滅储璁惧鎴愬姛锛屾墽琛屼竴娆′繚瀛樺埌鏈湴*/ + HDLDeviceManager.saveDevicesDataList(); } - public static void refreshAllDevicesState() { +// /** +// * 杩斿洖璁惧鍒楄〃 +// */ +// public static void deviceListCallBack() { +// byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2]; +// debugBytes[0] = 1; +// debugBytes[1] = 1; +// debugBytes[2] = 1; +// debugBytes[3] = 1; +// debugBytes[4] = 1; +// debugBytes[5] = 1; +// +// for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) { +// +// debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID(); +// debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID(); +// String device = "绗� " + (i + 1) + " 涓ā鍧楋細妯″潡澶囨敞鍚嶇О锛�" + HDLDeviceManager.devicesDataList.get(i).getRemark() +// + ",瀛愮綉鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() +// + ",璁惧鍙凤細" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() +// + ",鍥炶矾鏁帮細" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n"; +// HDLLog.info(device); +// } +// +//// HDLUdpCore.sendTestCMD(debugBytes, HDLTest.SEND_TEST_PORT); +// EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true)); +// +// +// } + + /** + * 鍒锋柊鎵�鏈夎澶囩姸鎬佸拰澶囨敞 + * 2019-10-15 + */ + public static void refreshAllDevicesStateAndRemarks() { + + if (isSearching) { + isRefreshAllDevicesState = false; + return; + } + isRefreshAllDevicesState = true; + for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) { + HDLDeviceManager.listRemarks.get(i).setCallBack(false); + } + getDevRemarks(); + } + + /** + * 1S + * @param delayTime 鍗曚綅绉� + */ + public static void refreshAllDevicesState(int delayTime) { if (refreshTimer != null) { refreshTimer.cancel(); refreshTimer.purge(); @@ -441,7 +490,7 @@ } getDevRemarks(); } - }, 1000 * 30); + }, 1000 * delayTime); } @@ -475,13 +524,15 @@ //鍒ゆ柇鏄惁鑾峰彇璁惧澶囨敞瀹屽叏锛岃嫢瀹屽叏鍒欒繑鍥炴墍鏈夎澶囧垪琛ㄣ�� if (HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() != 0 && pos == -1) { if (!isRefreshAllDevicesState) { - HandleSearch.deviceListCallBack(); - + HandleSearch.OnDeviceListGetSuccessCallBack(); } else { //鍒锋柊瀹屾瘯 - // TODO: 2018/12/29 鍒锋柊瀹屾瘯鍙兘瑕佸仛鏌愪簺浜嬫儏 + // TODO: 鍒锋柊瀹屾瘯鍙兘瑕佸仛鏌愪簺浜嬫儏 HDLLog.info("鍒锋柊璁惧鐘舵�佸畬姣�"); isRefreshAllDevicesState = false; + HandleSearch.OnDeviceListGetSuccessCallBack(); +// /**鍒锋柊璁惧鐘舵�佸畬姣曪紝鎵ц涓�娆′繚瀛樺埌鏈湴*/ +// HDLDeviceManager.saveDevicesDataList(); } return; @@ -508,8 +559,8 @@ port = Configuration.RCU_SEND_PORT; break; case HandleSearch.GET_BUS_DEVICES: -// ipAddress = NetWorkUtil.getLocalBroadCast(); - ipAddress = HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getIpAddress(); + ipAddress = HDLCommand.getLocalBroadCastIp();//2019-10-16 +// ipAddress = HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getIpAddress(); port = Configuration.PORT; break; } diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java index 42d672f..c8c5f41 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Parser/DeviceParser.java @@ -4,6 +4,8 @@ import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig; 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.Core.HDLDeviceManager; +import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HandleSearch; import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog; import java.util.ArrayList; @@ -690,4 +692,94 @@ } } + + /** + * + * @param bigType + * @param littleType + * @param mSubnetID + * @param mDeviceID + * @param parentRemarks + * @return + */ + public static DevicesData addDevicesManuallyWithoutSearchingAll(int bigType, int littleType, int mSubnetID, int mDeviceID, int port, String parentRemarks, ArrayList<String> parentRemarksList) { + boolean bWantData = false; + DevicesData devicesData = new DevicesData(); + devicesData.setSourceSubnetID(mSubnetID); + devicesData.setSourceDeviceID(mDeviceID); + devicesData.setRemark(parentRemarks); + + List<AppliancesInfo> appliancesInfoList = new ArrayList<>(); + if (isWantData(bigType, littleType)) { + for(int i = 0; i<parentRemarksList.size();i++){ + appliancesInfoList.add( getDevicesInfo(devicesData, bigType, littleType,i+1, port, parentRemarks, parentRemarksList.get(i))); + } + bWantData = true; + +// HDLLog.I( "鍚戞ā鍧楁坊鍔犲洖璺細"+"澶х被锛�" + mBigType + " 灏忕被锛�" + mLittleType +" 妯″潡澶囨敞" + mRemarks ); + } else { +// HDLLog.I( "涓嶆槸瑕佹坊鍔犵殑璁惧锛氬ぇ绫伙細" + mBigType + " 灏忕被锛�" + mLittleType +" 妯″潡澶囨敞" + mRemarks ); + } + + if (bWantData) { + devicesData.setAppliancesInfoList(appliancesInfoList); + HDLDeviceManager.devicesDataList.add(devicesData); + + HandleSearch.OnDeviceListGetSuccessCallBack(); + }else { + devicesData = null; + } + + return devicesData; + } + + private static AppliancesInfo getDevicesInfo(DevicesData devicesData, int bigType, int littleType, int curChannelNum, int port, String parentRemarks, String mRemarks){ + AppliancesInfo appliancesInfo = new AppliancesInfo(); + /**鏍规嵁绫诲埆锛岃祴鍊兼搷浣滅爜绛変竴浜涢噸瑕佷俊鎭�*/ + switch (bigType) { + case Configuration.LIGTH_BIG_TYPE: + parseLightData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.CURTAIN_BIG_TYPE: + parseCurtainData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.AIR_BIG_TYPE: + parseAirData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.AUDIO_BIG_TYPE: + parseAudioData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.LOGIC_BIG_TYPE: + parseLogicData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.GLOBAL_LOGIC_BIG_TYPE: + parseGlobalLogicData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.SENSOR_BIG_TYPE: + parseSensorData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + //2019-07-08 鏂板鍦扮儹鍜屾柊椋庣被 + case Configuration.GEOTHERMAL_BIG_TYPE://鍦扮儹 + parseGeothermalData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + case Configuration.FRESH_AIR_BIG_TYPE: + parseFreshAirData(littleType, appliancesInfo, devicesData, parentRemarks, curChannelNum, port, ""); + break; + default: +// appliancesInfo.setDeviceName(Configuration.UNKNOW_TYPE); + break; + } + + + String key = "K" + appliancesInfo.getBigType() + + "-" + appliancesInfo.getLittleType() + + "-" + appliancesInfo.getDeviceSubnetID() + + "-" + appliancesInfo.getDeviceDeviceID() + + "-" + appliancesInfo.getChannelNum(); + appliancesInfo.setRemarks(mRemarks); + appliancesInfo.setDeviceKey(key);//2019-8-2 娣诲姞鍞竴鏍囪瘑key + return appliancesInfo; + + } + } diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java index 3aee825..b030684 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/NetUtil/NetWorkUtil.java @@ -7,6 +7,8 @@ import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; +import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog; + import java.net.InetAddress; import java.net.InterfaceAddress; import java.net.NetworkInterface; @@ -128,13 +130,17 @@ //鍙湁 IPv4 缃戠粶鍏锋湁骞挎挱鍦板潃锛屽洜姝ゅ浜� IPv6 缃戠粶灏嗚繑鍥� null銆� if (interfaceAddress.getBroadcast() != null) { broadCastIp = interfaceAddress.getBroadcast().getHostAddress(); - } } } } } catch (Exception e) { e.printStackTrace(); + + } + + if(broadCastIp == null){ + HDLLog.E("getLocalBroadCast error ip null"); } return broadCastIp; } diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java index 3341889..3037054 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/SPUtil/SPUtils.java @@ -35,7 +35,7 @@ public static final String KEY_SUB_ID_ = "subid"; public static final String KEY_DEVICE_ID = "deviceid"; - + public static final String KEY_DEVICE_DATA_LIST = "hdldevicedatalist"; /** * 淇濆瓨鏁版嵁鐨勬柟娉曪紝鎴戜滑闇�瑕佹嬁鍒颁繚瀛樻暟鎹殑鍏蜂綋绫诲瀷锛岀劧鍚庢牴鎹被鍨嬭皟鐢ㄤ笉鍚岀殑淇濆瓨鏂规硶 * diff --git a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java index ed18c79..4f23557 100644 --- a/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java +++ b/hdl_core/src/main/java/com/hdl/sdk/hdl_core/Util/TransformUtil/HDLUtlis.java @@ -33,6 +33,18 @@ return in; } + public static float getFloatByObject(Object object) { + float f = 0f; + try { + f = (float)object; + } catch (Exception e) { + e.printStackTrace(); + } + return f; + + } + + /** * 4 byte 杞崲涓篺loat绫诲瀷 * -- Gitblit v1.8.0