| | |
| | | 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.HDLApp; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.bean.ModBusBean; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | 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); |
| | | HdlLogLogic.print("uni发来的数据--->大类--->" + topic + "\r\n" + data, true); |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni发来的数据--->" + e.getMessage(), 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", HDLApp.getInstance().getString(R.string.exception_no_location_information_permission)); |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | |
| | | // 判断设备是否支持定位功能 |
| | | if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { |
| | | jsonObject.addProperty("result", -1);//没开启定位功能 |
| | | jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | //todo 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能 |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); |
| | | if (location == null) { |
| | | jsonObject.addProperty("result", -3);//没有位置信息权限 |
| | | jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled)); |
| | | uniCallbackData(jsonObject.toString(), callback); |
| | | return; |
| | | } |
| | | jsonObject.addProperty("result", 0); |
| | | jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.succeed)); |
| | | 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; |
| | | String module = "FW#" + imageId;//模块信息(HW:硬件) |
| | | |
| | | //升级本地优先->云端升级 |
| | | HdlDeviceLogic.getInstance().isLocalConnect(deviceMac, new CloudCallBeak<Boolean>() { |
| | |
| | | } |
| | | String md5 = HDLMD5Utils.encodeMD5(data);//网关固件需要 |
| | | //升级固件文件地址 |
| | | String upgradeFileLocalPathUrl = "http://" + NetworkUtils.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://" + NetworkUtils.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); |
| | |
| | | public void onSuccess(Boolean obj) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); |
| | | if (gatewayBean == null) { |
| | | uniCallbackData(null, -100, "本地找不到网关", callback); |
| | | uniCallbackData(null, -100, HDLApp.getInstance().getString(R.string.The_gateway_cannot_be_found_locally), callback); |
| | | |
| | | return; |
| | | } |
| | |
| | | private void sendModBus(Object data, DCUniMPJSCallback callback) { |
| | | String tempData = getKeyValue("data", data); |
| | | if (TextUtils.isEmpty(tempData)) { |
| | | HdlLogLogic.print("data内容为空", false); |
| | | HdlLogLogic.print("data内容为空--->", false); |
| | | return; |
| | | } |
| | | ModBusBean modBusBean = new Gson().fromJson(tempData, ModBusBean.class); |
| | |
| | | // modBusBean.setOid("0101050217BBC400"); |
| | | // } |
| | | if (modBusBean.getMac() == null || modBusBean.getData() == null) { |
| | | HdlLogLogic.print("内容为空===oid=" + modBusBean.getMac() + " data=" + Arrays.toString(modBusBean.getData()), false); |
| | | HdlLogLogic.print("内容为空--->oid--->" + modBusBean.getMac() + " data--->" + Arrays.toString(modBusBean.getData()), false); |
| | | return; |
| | | } |
| | | |
| | |
| | | data = new JSONObject(); |
| | | } |
| | | if (isTokenAndRefreshToken) { |
| | | //小程序那里有自己的请求方法,需要这些数据 |
| | | data.put("token", UserConfigManage.getInstance().getToken()); |
| | | data.put("refreshToken", UserConfigManage.getInstance().getRefreshToken()); |
| | | data.put("serverAddress", AppConfigManage.getUserRegionUrl()); |
| | | data.put("appKey", AppConfigManage.getAppKey()); |
| | | data.put("appSecret", AppConfigManage.getAppSecret()); |
| | | } |
| | | uniCallBackBaseBean.setData(data); |
| | | return getJSONObject(uniCallBackBaseBean); |
| | |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | HdlLogLogic.print("uni===组装uni发送数据格式===" + e.getMessage(), false); |
| | | HdlLogLogic.print("uni--->组装uni发送数据格式--->" + e.getMessage(), false); |
| | | } |
| | | |
| | | |