mac
2024-01-31 4cfd0dee1abf5db41b54fb2d4bdd666792b1da72
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -291,18 +291,10 @@
                    //设备取消驱动,固件下载升级文件
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: {
                        this.uniCancelDownloadingUpgradeFile(data, callback);
//                        HdlThreadLogic.runSubThread(new Runnable() {
//                            @Override
//                            public void run() {
//                                HdlLogLogic.print("当前线程名称取消下载====" + Thread.currentThread().getName());
//                                uniCancelDownloadingUpgradeFile(data, callback);
//                            }
//                        });
                    }
                    break;
                    //设备驱动,固件取消升级
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_CANCEL_UPGRADE: {
                        this.uniCancelUpgrade(data, callback);
                    }
                    break;
@@ -334,6 +326,11 @@
                    //获取位置信息
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_LOCATION_INFO: {
                        this.uniGetLocationInfo(data, callback);
                    }
                    //专门收集uni日志
                    case HDLUniMP.UNI_EVENT_REPLY_OTHER_UNI_LOG: {
                        String customizeContentFormat = getKeyValue("customizeContentFormat", getKeyValue("data", data));
                        HdlLogLogic.print("uni--->log--->" + customizeContentFormat, true);
                    }
                }
            }
@@ -395,7 +392,7 @@
        //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", "没有位置信息权限");
            jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.exception_no_location_information_permission));
            uniCallbackData(jsonObject.toString(), callback);
            return;
        }
@@ -403,7 +400,7 @@
        // 判断设备是否支持定位功能
        if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            jsonObject.addProperty("result", -1);//没开启定位功能
            jsonObject.addProperty("des", "没开启定位功能");
            jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.exception_the_location_function_is_not_enabled));
            //todo 提示用户打开定位功能或者引导用户去系统设置页面打开定位功能
            uniCallbackData(jsonObject.toString(), callback);
            return;
@@ -411,12 +408,12 @@
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        if (location == null) {
            jsonObject.addProperty("result", -3);//没有位置信息权限
            jsonObject.addProperty("des", "没开启定位功能");
            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", "成功");
        jsonObject.addProperty("des", HDLApp.getInstance().getString(R.string.succeed));
        jsonObject.addProperty("longitude", location.getLongitude());//经度
        jsonObject.addProperty("latitude", location.getLatitude());//纬度
        uniCallbackData(jsonObject.toString(), callback);
@@ -1206,6 +1203,8 @@
     * @param callback uni回调
     */
    private void uniSearchGateway(DCUniMPJSCallback callback) {
        HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() {
            @Override
            public void onSuccess(List<GatewayBean> gatewayBeanList) {
@@ -1216,6 +1215,7 @@
            public void onError(HDLLinkException e) {
                //发送失败
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
@@ -1288,22 +1288,24 @@
//            modBusBean.setOid("0101050217BBC400");
//        }
        if (modBusBean.getMac() == null || modBusBean.getData() == null) {
            HdlLogLogic.print("内容为空--->oid--->" + modBusBean.getMac() + " data--->" + Arrays.toString(modBusBean.getData()), false);
            HdlLogLogic.print("uni--->发送--->ModBus--->发送失败,(mac或者oid)为空." + Arrays.toString(modBusBean.getData()), true);
            return;
        }
        HdlLogLogic.print("uni--->发送--->ModBus--->" + Arrays.toString(modBusBean.getData()), true);
        //发送modbus协议
        HDLModBusConnect.getInstance().Send(modBusBean.getMac(), modBusBean.getData(), new ModbusCallBack() {
            @Override
            public void onSuccess(int[] data) {
                Log.d("data", Arrays.toString(data));
                uniCallbackData(data, callback);
                HdlLogLogic.print("uni--->接收--->ModBus--->" + Arrays.toString(data), true);
            }
            @Override
            public void onError(HDLLinkException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
                HdlLogLogic.print("uni--->异常--->ModBus--->" + e.getMsg() + "(" + e.getCode() + ")", true);
            }
        });
    }