| | |
| | | package com.hdl.photovoltaic.ui; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import android.Manifest; |
| | | import android.content.ComponentName; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.home.type.HomeType; |
| | | import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.CloudGatewayDriversBean; |
| | | import com.hdl.linkpm.sdk.utils.HDLMD5Utils; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.AesUtils; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.Md5Utils; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | |
| | | import okhttp3.ResponseBody; |
| | | |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.blue); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | //初始化mqtt客户端 |
| | | initMqttClient(); |
| | | |
| | | // dddd(); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onEventMessage(BaseEventBus event) { |
| | | //网关更新mqtt秘钥更新通知 |
| | | |
| | | if (event == null) { |
| | | return; |
| | | } |
| | | if (TextUtils.isEmpty(event.getTopic())) { |
| | | return; |
| | | } |
| | | String[] topics = event.getTopic().split("/"); |
| | | //主题不符合规则不处理 |
| | | if (topics.length < 3) { |
| | | return; |
| | | } |
| | | int index = -1; |
| | | List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean.getGatewayId().equals(topics[2])) { |
| | | index = i; |
| | | break; |
| | | //网关更新mqtt秘钥更新通知 |
| | | if (event.getTopic().contains("/custom/mqtt/secret/change")) { |
| | | String[] topics = event.getTopic().split("/"); |
| | | //主题不符合规则不处理 |
| | | if (topics.length < 3) { |
| | | return; |
| | | } |
| | | } |
| | | if (index > -1) { |
| | | GatewayBean gatewayBean = list.get(index); |
| | | HdlDeviceLogic.getInstance().getDeviceRemoteInfo(UserConfigManage.getInstance().getHomeId(), gatewayBean.getSpk(), gatewayBean.getDevice_mac(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | if (deviceRemoteInfo != null) { |
| | | //更新mqtt通讯的新秘钥 |
| | | gatewayBean.setAesKey(deviceRemoteInfo.getSecret()); |
| | | //用之前的库,底层mqtt订阅,加解密会用到该参数; |
| | | HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥库 |
| | | int index = -1; |
| | | List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean.getGatewayId().equals(topics[2])) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | if (index > -1) { |
| | | GatewayBean gatewayBean = list.get(index); |
| | | HdlDeviceLogic.getInstance().getDeviceRemoteInfo(UserConfigManage.getInstance().getHomeId(), gatewayBean.getSpk(), gatewayBean.getDevice_mac(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | if (deviceRemoteInfo != null) { |
| | | //更新mqtt通讯的新秘钥 |
| | | gatewayBean.setAesKey(deviceRemoteInfo.getSecret()); |
| | | //用之前的库,底层mqtt订阅,加解密会用到该参数; |
| | | HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥库 |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } else if (event.getTopic().contains(HdlOtaLogic.localDownloadProgress)) { |
| | | //下载云端驱动或者固件文件,自己计算进度条上报到uni那边 |
| | | HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | uniCallBackBaseBean.setType(event.getType()); |
| | | uniCallBackBaseBean.setData(event.getData()); |
| | | HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL, uniCallBackBaseBean); |
| | | HdlLogLogic.print("进度:" + ((HdlOtaLogic.Progress) event.getData()).step + "", false); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | |
| | | private void dddd() { |
| | | // String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02"); |
| | | // String data = HdlFileLogic.getInstance().readFile(drivePathFileName); |
| | | // String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要 |
| | | // Log.e("", md5); |
| | | // HdlOtaLogic.getInstance().getDeviceDriverDownloadFile("http://192.168.16.135:49152/storage/emulated/0/Android/data/com.hdl.photovoltaic/files/Documents/upgrade/drive/036F6C1B_V01.01.02.zip", new CloudCallBeak<ResponseBody>() { |
| | | // @Override |
| | | // public void onSuccess(ResponseBody responseBody) { |
| | | // |
| | | // HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5); |
| | | // |
| | | //// //本地升级驱动文件路径 |
| | | //// |
| | | //// String data = HdlFileLogic.getInstance().readFile(drivePathFileName); |
| | | //// String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要 |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(HDLException e) { |
| | | // |
| | | // } |
| | | // }); |
| | | |
| | | |
| | | // HdlOtaLogic.getInstance().getNewGatewayDrivers("036F6C1B", "A000", new CloudCallBeak<CloudGatewayDriversBean>() { |
| | | // @Override |
| | | // public void onSuccess(CloudGatewayDriversBean obj) { |
| | | // |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(HDLException e) { |
| | | // |
| | | // } |
| | | // }); |
| | | |
| | | |
| | | // dowlao(); |
| | | HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() { |
| | | @Override |
| | | public void onServiceConnected(ComponentName name, IBinder service) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onServiceDisconnected(ComponentName name) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | void dowlao() { |
| | | |
| | | HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile("http://hdl-hz-test.oss-cn-hangzhou.aliyuncs.com/20/2023/11/1834a1d0-d2a7-4b6f-9877-6f2722e9b7bc.hdlipk_sec", new CloudCallBeak<ResponseBody>() { |
| | | @Override |
| | | public void onSuccess(ResponseBody responseBody) { |
| | | String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02"); |
| | | HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, "84cd8e62d4311c90508313f0e5965dbb", HdlOtaLogic.driver_type); |
| | | |
| | | // HdlFileLogic.getInstance().writeFile(drivePathFileName, bytes);//写入新文件 |
| | | HdlLogLogic.print("写入新驱动文件到内存成功.", false); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("下载驱动文件到内存失败.", false); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |