| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | |
| | | import android.Manifest; |
| | | import android.content.ComponentName; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.content.pm.PackageManager; |
| | | import android.location.Location; |
| | | import android.location.LocationListener; |
| | | import android.location.LocationManager; |
| | | import android.os.IBinder; |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.device.bean.DeviceOidInfoBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.CloudDeviceFirmwaresBean; |
| | |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.NetworkUtils123; |
| | | import com.hdl.photovoltaic.utils.NetworkUtils; |
| | | import com.hdl.photovoltaic.utils.WifiUtils; |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkCode; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | |
| | | uniCallbackData(UserConfigManage.getInstance().getCurrentAppLanguage(), callback); |
| | | } |
| | | break; |
| | | //获取位置信息 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTHER_LOCATION_INFO: { |
| | | this.uniGetLocationInfo(data, callback); |
| | | } |
| | | } |
| | | } |
| | | HdlLogLogic.print("uni发来的数据--->大类--->" + topic + "\r\n" + data, true); |
| | |
| | | //endregion |
| | | |
| | | //region ******uni接口方法****** |
| | | |
| | | /** |
| | | * 获取位置信息,包括经纬度 |
| | | */ |
| | | private void uniGetLocationInfo(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | // 初始化LocationManager对象 |
| | | LocationManager locationManager = (LocationManager) HDLApp.getInstance().getSystemService(Context.LOCATION_SERVICE); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | //INTERNET 允许使用网络 |
| | | //ACCESS_FINE_LOCATION 允许使用GPS定位 |
| | | //ACCESS_COARSE_LOCATION 允许使用WIFI热点或基站来获取粗略的定位 |
| | | if (ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(HDLApp.getInstance(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { |
| | | jsonObject.addProperty("result", -2);//没有位置信息权限 |
| | | jsonObject.addProperty("des", "没有位置信息权限"); |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | jsonObject.addProperty("result", -1);//没开启定位功能 |
| | | jsonObject.addProperty("des", "没开启定位功能"); |
| | | //todo 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | if (location == null) { |
| | | jsonObject.addProperty("result", -3);//没有位置信息权限 |
| | | jsonObject.addProperty("des", "没开启定位功能"); |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | jsonObject.addProperty("result", 0); |
| | | jsonObject.addProperty("des", "成功"); |
| | | jsonObject.addProperty("longitude", location.getLongitude());//经度 |
| | | jsonObject.addProperty("latitude", location.getLatitude());//纬度 |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | HdlLogLogic.print("经纬度--->经度:" + location.getLongitude() + "纬度:" + location.getLatitude(), true); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取逆变器oid列表 |
| | |
| | | */ |
| | | private void uniGetLocalFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | try { |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号 |
| | | // String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//系统镜像id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | // String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | // String oid = getKeyValue("oid", getKeyValue("data", data));//固件oid |
| | | List<DeviceFirmwareBean> list = new ArrayList<>(); |
| | | String driverFileList = HdlFileLogic.getInstance().getFirmwareRootPath(); |
| | |
| | | * 向云端发起【设备固件下载】指令 |
| | | */ |
| | | private void uniDeviceFirmwareDownload(Object data, DCUniMPJSCallback callback) { |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//云端上设备id |
| | | // String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//云端上设备id |
| | | String oid = getKeyValue("oid", getKeyValue("data", data));//该固件的oid |
| | | String imageId = getKeyValue("imageId", getKeyValue("data", data));//固件镜像id |
| | | String version = getKeyValue("version", getKeyValue("data", data));//固件版本 |
| | |
| | | String oid = getKeyValue("oid", getKeyValue("data", data));//升级固件的oid |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | String version = getKeyValue("version", getKeyValue("data", data));//固件版本 |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//云端上文件MD5 |
| | | // String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//云端上文件MD5 |
| | | String imageId = getKeyValue("imageId", getKeyValue("data", data));//固件镜像id |
| | | String module = "FW#" + imageId;//模块信息(HW:硬件) |
| | | |
| | |
| | | } |
| | | String md5 = HDLMD5Utils.encodeMD5(data);//网关固件需要 |
| | | //升级固件文件地址 |
| | | String upgradeFileLocalPathUrl = "http://" + NetworkUtils123.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName; |
| | | String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName; |
| | | //通知给网关升级固件文件地址等信息 |
| | | HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, oid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() { |
| | | @Override |
| | |
| | | private void uniGetLocalDrivers(Object data, DCUniMPJSCallback callback) { |
| | | try { |
| | | String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动类型id |
| | | // String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | // String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动类型id |
| | | List<GatewayDriverBean> list = new ArrayList<>(); |
| | | String driverFileList = HdlFileLogic.getInstance().getDriveRootPath(); |
| | | File file = new File(driverFileList); |
| | |
| | | */ |
| | | private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid |
| | | // String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid |
| | | String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//驱动编码 |
| | | String imageId = getKeyValue("imageId", getKeyValue("data", data));//驱动镜像id |
| | | // String imageId = getKeyValue("imageId", getKeyValue("data", data));//驱动镜像id |
| | | String version = getKeyValue("version", getKeyValue("data", data));//驱动版本 |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id |
| | | // String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id |
| | | String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//储存在本地驱动文件路径 |
| | | String url = getKeyValue("url", getKeyValue("data", data));//云端上文件地址 |
| | | String md5 = getKeyValue("md5", getKeyValue("data", data));//云端上文件MD5 |
| | |
| | | } |
| | | String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要 |
| | | //升级驱动文件地址 |
| | | String upgradeFileLocalPathUrl = "http://" + NetworkUtils123.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName; |
| | | String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName; |
| | | //通知给网关升级驱动文件地址等信息 |
| | | HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, deviceOid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() { |
| | | @Override |
| | |
| | | String mac = getKeyValue("mac", getKeyValue("data", data)); |
| | | String date = getKeyValue("date", getKeyValue("data", data)); |
| | | String time = getKeyValue("time", getKeyValue("data", data)); |
| | | HdlDeviceLogic.getInstance().editGatewayTime(mac, date, time, new LinkCallBack<Boolean>() { |
| | | String timezone = getKeyValue("timezone", getKeyValue("data", data)); |
| | | HdlDeviceLogic.getInstance().editGatewayTime(mac, date, time, timezone, new LinkCallBack<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(true, callback); |