2023年11月20日18:24:36
备份一下代码
| | |
| | | implementation 'androidx.webkit:webkit:1.3.0'//3.6.15版本之后 必须集成,用来支持暗黑模式 |
| | | //********UniSDK必须添加的依赖 end******** |
| | | |
| | | //NanoHTTPD搭建服务器 |
| | | implementation 'org.nanohttpd:nanohttpd:2.3.1' |
| | | |
| | | |
| | | } |
| | |
| | | <uses-permission |
| | | android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" |
| | | tools:ignore="ProtectedPermissions" /> <!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> --> |
| | | <!-- <uses-permission android:name="android.permission.CAMERA" /> --> |
| | | <uses-permission android:name="android.permission.VIBRATE" /> <!-- <uses-permission android:name="android.permission.INTERNET" /> --> |
| | | <!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> --> |
| | | <!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> --> |
| | |
| | | <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> <!-- <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> --> |
| | | <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> <!-- wifi状态权限 --> |
| | | <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> |
| | | <uses-permission android:name="android.permission.INTERNET" /> <!-- 位置信息 --> |
| | | <uses-permission android:name="android.permission.INTERNET" /><!--开启网络权限--><!-- 位置信息 --> |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 如果是安卓10.0,需要后台获取连接的wifi名称则添加进程获取位置信息权限 --> |
| | | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- android 10.0使用wifi api新添加的权限 --> |
| | | <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> |
| | |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- bugly所需权限 start --> |
| | | <uses-permission android:name="android.permission.CAMERA" /> <!-- <uses-permission android:name="android.permission.INTERNET" /> --> |
| | | <!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> --> |
| | | <uses-permission android:name="android.permission.INTERNET" /> |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| | | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
| | | <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> |
| | |
| | | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- bugly所需权限 end --> |
| | | <!-- UNI SDK 基座删除的部分权限 start --> |
| | | <uses-permission android:name="android.permission.CAMERA" /> |
| | | <uses-permission android:name="android.permission.INTERNET" /> <!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> --> |
| | | <!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> --> |
| | | <!-- <uses-feature android:name="android.hardware.camera.autofocus" /> --> |
| | | <!-- <uses-permission android:name="android.permission.CAMERA" /> --> |
| | | <!-- <uses-permission android:name="android.permission.RECORD_AUDIO" /> --> |
| | | <!-- <uses-permission android:name="android.permission.READ_PHONE_STATE" /> --> |
| | | <!-- 访问闪光灯 --> |
| | | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
| | | <uses-permission android:name="android.permission.INTERNET" /> |
| | | <uses-permission android:name="android.permission.READ_PHONE_STATE" /> |
| | | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
| | | <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> |
| | |
| | | <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> |
| | | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
| | | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
| | | <uses-permission android:name="android.permission.INTERNET" /> |
| | | <uses-permission android:name="com.hdl.debugtreasure.permission.JPUSH_MESSAGE" /> |
| | | <uses-permission android:name="android.permission.CALL_PHONE" /> |
| | | <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> |
| | |
| | | </intent-filter> |
| | | </activity> |
| | | |
| | | <!--注册服务--> |
| | | <service android:name="com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService" /> |
| | | |
| | | <meta-data |
| | | android:name="design_height_in_dp" |
| | | android:value="812" /> |
New file |
| | |
| | | package com.hdl.photovoltaic.internet.HttpServer; |
| | | |
| | | import android.text.TextUtils; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import fi.iki.elonen.NanoHTTPD; |
| | | |
| | | /** |
| | | * 本地服务器 |
| | | */ |
| | | public class MyNanoHttpServer extends NanoHTTPD { |
| | | |
| | | //声明服务端 端口 |
| | | private static final Integer HTTP_PORT = 49152; |
| | | |
| | | public MyNanoHttpServer(String hostname, int port) { |
| | | super(hostname, port); |
| | | } |
| | | |
| | | private volatile static MyNanoHttpServer myNanoHttpServer; |
| | | |
| | | //TODO 单例模式,获取实例对象,并传入当前机器IP |
| | | public static MyNanoHttpServer getInstance(String ipAddress) { |
| | | if (myNanoHttpServer == null) { |
| | | synchronized (MyNanoHttpServer.class) { |
| | | if (myNanoHttpServer == null) { |
| | | myNanoHttpServer = new MyNanoHttpServer(ipAddress, HTTP_PORT); |
| | | } |
| | | } |
| | | } |
| | | return myNanoHttpServer; |
| | | } |
| | | |
| | | @Override |
| | | public Response serve(IHTTPSession session) { |
| | | //TODO 解决客户端请求参数携带中文,出现中文乱码问题 |
| | | ContentType ct = new ContentType(session.getHeaders().get("content-type")).tryUTF8(); |
| | | session.getHeaders().put("content-type", ct.getContentTypeHeader()); |
| | | return dealWith(session); |
| | | } |
| | | |
| | | private Response dealWith(IHTTPSession session) { |
| | | Date dateTime = new Date(); |
| | | if (Method.POST == session.getMethod()) { |
| | | //获取请求头数据 |
| | | Map<String, String> header = session.getHeaders(); |
| | | //获取传参参数 |
| | | Map<String, String> params = new HashMap<String, String>(); |
| | | try { |
| | | session.parseBody(params); |
| | | String paramStr = params.get("postData"); |
| | | if (TextUtils.isEmpty(paramStr)) { |
| | | return newFixedLengthResponse("success"); |
| | | } |
| | | paramStr = paramStr.replace("\r\n", " "); |
| | | |
| | | com.alibaba.fastjson.JSONObject jsonParam = JSON.parseObject(paramStr); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | //TODO 写你的业务逻辑..... |
| | | |
| | | String ss = HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getLogFilePath()); |
| | | //响应客户端 |
| | | return newFixedLengthResponse(ss); |
| | | // return newFixedLengthResponse("success"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } catch (ResponseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return newFixedLengthResponse("success"); |
| | | } else if (Method.GET == session.getMethod()) { |
| | | |
| | | Map<String, List<String>> parameters = session.getParameters(); |
| | | String ss = HdlFileLogic.getInstance().readFile(HdlFileLogic.getInstance().getLogFilePath()); |
| | | //响应客户端 |
| | | return newFixedLengthResponse(ss); |
| | | // return newFixedLengthResponse("success"); |
| | | } |
| | | |
| | | return newFixedLengthResponse("404"); |
| | | } |
| | | |
| | | public static Response newFixedLengthResponse(String msg) { |
| | | return newFixedLengthResponse(Response.Status.OK, NanoHTTPD.MIME_HTML, msg); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.hdl.photovoltaic.internet.HttpServer; |
| | | |
| | | import android.app.Service; |
| | | import android.content.Intent; |
| | | import android.os.IBinder; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | public class MyNanoHttpService extends Service { |
| | | private MyNanoHttpServer myNanoHttpServer = MyNanoHttpServer.getInstance(null); |
| | | |
| | | @Nullable |
| | | @Override |
| | | public IBinder onBind(Intent intent) { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | try { |
| | | myNanoHttpServer.start(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | startService(new Intent(this, MyNanoHttpService.class)); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int onStartCommand(Intent intent, int flags, int startId) { |
| | | return super.onStartCommand(intent, flags, startId); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onDestroy() { |
| | | super.onDestroy(); |
| | | myNanoHttpServer.stop(); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取逆变器列表 |
| | | * 获取逆变器列表(整合云端和本地列表) |
| | | * 注意:有外网以云端设备为准,本地存在,云端没有则删除;内网以本地为主,搜索多少个设备就显示多少个; |
| | | * |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //外网只有1情况(本地搜索逆变器列表失败了) |
| | | //外网只有1种情况(本地搜索逆变器列表失败了) |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); |
| | | } |
| | | |
| | | /** |
| | | * 判断是本地连接 |
| | | * |
| | | * @param deviceMac 设备mac |
| | | * @return true=本地连接 |
| | | */ |
| | | public boolean isLocalConnect(String deviceMac) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceMac); |
| | | return gatewayBean == null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取存放【驱动文件夹】根路径 |
| | | */ |
| | | public String getDriveRootPath() { |
| | | return getAPPInternalStoreFilesPath() + "/upgrade/drive"; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取存放【固件文件夹】根路径 |
| | | */ |
| | | public String getFirmwareRootPath() { |
| | | return getAPPInternalStoreFilesPath() + "/upgrade/firmware"; |
| | | } |
| | | |
| | | /** |
| | | * 获取【日志文件】全路径 |
| | | */ |
| | | public String getLogFilePath() { |
| | | return getCurrentHomeRootPath() + "/Log.txt"; |
| | | return getCurrentHomeRootPath() + "/log.txt"; |
| | | } |
| | | |
| | | /** |
| | | * 获取【用户文件】全路径 |
| | | */ |
| | | public String getUserFilePath() { |
| | | return getAPPInternalStoreFilesPath() + "/UserConfigManage.txt"; |
| | | return getAPPInternalStoreFilesPath() + "/userConfigManage.txt"; |
| | | } |
| | | |
| | | //endregion |
| | |
| | | public void createDirectory() { |
| | | //存放住宅信息 |
| | | this.createFileDir(this.getCurrentHomeRootPath()); |
| | | //驱动文件 |
| | | this.createFileDir(this.getDriveRootPath()); |
| | | //固件文件 |
| | | this.createFileDir(this.getFirmwareRootPath()); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static void writeLog(String strLog) { |
| | | synchronized (HdlLogLogic.class) { |
| | | strLog = TimeUtils.getTimeFromTimestamp(System.currentTimeMillis()) + "s%" + " " + strLog;//加打印时间(s%占位符,显示时间时设置不同字体颜色) |
| | | strLog = TimeUtils.getTimeFromTimestamp(System.currentTimeMillis()) + "s%" + " " + strLog;//加打印时间(s%占位符,设置显示时间不同字体颜色) |
| | | HdlFileLogic.getInstance().appendFile(HdlFileLogic.getInstance().getLogFilePath(), strLog); |
| | | } |
| | | } |
| | |
| | | * @param firmwareVersionId 固件版本Id |
| | | */ |
| | | public void getDeviceFirmwareDownloadUrl(String firmwareVersionId, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | // "protocolType":"bus", |
| | | // "deviceModel":"029B9988", |
| | | // "firmwareNameEn":"核心层", |
| | | // "firmwareNameCn":"核心层", |
| | | // "imageId":"12345678", |
| | | // "version":"V01.02.20" |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备固件】下载升级文件 |
| | | * |
| | | * @param downloadUrl 云端固件地址 |
| | | */ |
| | | public void getDeviceFirmwareDownloadFile(String downloadUrl, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | } |
| | | |
| | | //endregion |
| | |
| | | * |
| | | * @param driverVersionId 驱动版本Id |
| | | */ |
| | | public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<String> callBack) { |
| | | // "driverCode":"029B9988", |
| | | // "driverName":"核心层", |
| | | // "imageId":"12345678", |
| | | // "version":"V01.02.20" |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("driverVersionId", driverVersionId); |
| | |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new DownloadUrlBean()); |
| | | callBack.onSuccess("-2"); |
| | | } |
| | | return; |
| | | } |
| | |
| | | Type typeOfT = new TypeToken<DownloadUrlBean>() { |
| | | }.getType(); |
| | | DownloadUrlBean downloadUrlBean = gson.fromJson(json, typeOfT); |
| | | if (downloadUrlBean == null) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(downloadUrlBean); |
| | | callBack.onSuccess("-2"); |
| | | } |
| | | return; |
| | | } |
| | | getDeviceDriverDownloadFile(downloadUrlBean.getDownloadUrl(), new CloudCallBeak<DownloadUrlBean>() { |
| | | @Override |
| | | public void onSuccess(DownloadUrlBean obj) { |
| | | String full = HdlFileLogic.getInstance().getDriveRootPath() + "/" + driverVersionId; |
| | | HdlFileLogic.getInstance().writeFile(full, obj.toString()); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备驱动】下载升级文件 |
| | | * |
| | | * @param downloadUrl 云端固件地址 |
| | | */ |
| | | public void getDeviceDriverDownloadFile(String downloadUrl, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | |
| | | } |
| | | |
| | | |
| | | //endregion |
| | | } |
| | |
| | | import com.hdl.linkpm.sdk.ota.bean.CloudDeviceFirmwaresBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.CloudGatewayDriversBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.DeviceFirmwareBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.DownloadUrlBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.bean.ModBusBean; |
| | |
| | | this.uniGetNewDeviceFirmwares(data, callback); |
| | | } |
| | | break; |
| | | //设备本地固件列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_LOCAL: { |
| | | this.uniGetLocalFirmwares(data, callback); |
| | | } |
| | | break; |
| | | //设备固件下载 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_DOWNLOAD: { |
| | | this.uniDeviceFirmwareDownload(data, callback); |
| | | } |
| | | break; |
| | | //设备固件升级 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE: { |
| | | this.uniUpgradeDeviceFirmware(data, callback); |
| | |
| | | //设备新驱动列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_NEW: { |
| | | this.uniGetNewGatewayDrivers(data, callback); |
| | | } |
| | | break; |
| | | //设备本地驱动列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_LOCAL: { |
| | | this.uniGetLocalDrivers(data, callback); |
| | | } |
| | | break; |
| | | //设备驱动下载 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_DOWNLOAD: { |
| | | this.uniGatewayDriverDownload(data, callback); |
| | | } |
| | | break; |
| | | //设备驱动升级 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取【设备本地固件】列表 |
| | | */ |
| | | private void uniGetLocalFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//系统镜像id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//系统镜像id |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备固件】下载指令 |
| | | */ |
| | | private void uniDeviceFirmwareDownload(Object data, DCUniMPJSCallback callback) { |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//设备id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | HdlOtaLogic.getInstance().getDeviceFirmwareDownloadUrl(firmwareVersionId, new CloudCallBeak<DownloadUrlBean>() { |
| | | @Override |
| | | public void onSuccess(DownloadUrlBean obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备固件】升级OTA指令 |
| | | */ |
| | | private void uniUpgradeDeviceFirmware(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//网关设备mac(查找socket) |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//设备id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | |
| | | boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac); |
| | | if (isLocalConnect) { |
| | | //本地 |
| | | //1,建立本地服务; |
| | | // 2,告诉网关手机ip和端口; |
| | | |
| | | } else { |
| | | //云端 |
| | | HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备驱动】升级OTA指令 |
| | | * 获取【设备本地驱动】列表 |
| | | */ |
| | | private void uniUpgradeGatewayDriver(Object data, DCUniMPJSCallback callback) { |
| | | private void uniGetLocalDrivers(Object data, DCUniMPJSCallback callback) { |
| | | String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动类型id |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备驱动】下载指令 |
| | | */ |
| | | private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id |
| | | HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备驱动】升级OTA指令 |
| | | */ |
| | | private void uniUpgradeGatewayDriver(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//网关设备mac(查找socket) |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id |
| | | boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac); |
| | | if (isLocalConnect) { |
| | | //本地 |
| | | //1,建立本地服务; |
| | | // 2,告诉网关手机ip和端口; |
| | | |
| | | } else { |
| | | HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 逆变器清空住宅id |
| | | * |
| | | * @param data uni数据 |
| | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.ui.account.ChangePassword; |
| | | import com.hdl.photovoltaic.ui.account.RegisterAccountActivity; |
| | |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog1; |
| | | |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 登录的界面 |
| | |
| | | @Override |
| | | public Object getContentView() { |
| | | |
| | | |
| | | viewBinding = ActivityHomeLoginBinding.inflate(getLayoutInflater()); |
| | | return viewBinding.getRoot(); |
| | | } |
| | |
| | | import androidx.appcompat.content.res.AppCompatResources; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.os.Process; |
| | |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding; |
| | | import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer; |
| | | import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | initMqttClient(); |
| | | |
| | | |
| | | //实例化 获取ip 地址 |
| | | MyNanoHttpServer.getInstance(AppManagerUtils.getAppManager().getIPAddress(this)); |
| | | // MyNanoHttpServer.getInstance("127.0.0.1"); |
| | | Intent intent = new Intent(); |
| | | intent.setClass(this, MyNanoHttpService.class); |
| | | //启动服务监听 |
| | | startService(intent); |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlResidenceLogic; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId() + "&homeName=" + houseIdBean.getHomeName(); |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | HdlLogLogic.print("点击住宅详情===1", true); |
| | | HdlLogLogic.print("点击住宅详情===2", true); |
| | | HdlLogLogic.print("点击住宅详情===3", true); |
| | | |
| | | } |
| | | }); |
| | |
| | | /*********OTA模块*********/ |
| | | public final static String UNI_EVENT_REPLY_OTA_MODEL = "uni_ota_model";//升级模块(大类) |
| | | public final static String UNI_EVENT_REPLY_OTA_CLOUD_OID_LIST = "cloud_oid_list";//向云端获取oid列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LIST = "firmwares_list";//当前设备固件列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LIST = "firmwares_current_list";//当前设备固件列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST = "firmwares_new_list";//设备新固件列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LOCAL = "firmwares_local_list";//设备本地固件列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_DOWNLOAD = "firmwares_download";//设备固件下载 |
| | | public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE = "firmwares_upgrade";//设备固件升级 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_LIST = "driver_list";//当前设备驱动列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_NEW = "driver_new";//设备新驱动列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_LIST = "driver_current_list";//当前设备驱动列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_NEW = "driver_new_list";//设备新驱动列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_LOCAL = "driver_local_list";//设备本地驱动列表 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_DOWNLOAD = "driver_download";//设备驱动下载 |
| | | public final static String UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE = "driver_upgrade";//设备驱动升级 |
| | | |
| | | |
| | |
| | | import android.content.Context; |
| | | import android.content.pm.PackageInfo; |
| | | import android.content.pm.PackageManager; |
| | | import android.net.ConnectivityManager; |
| | | import android.net.NetworkInfo; |
| | | import android.net.wifi.WifiInfo; |
| | | import android.net.wifi.WifiManager; |
| | | |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | |
| | | import java.net.Inet4Address; |
| | | import java.net.InetAddress; |
| | | import java.net.NetworkInterface; |
| | | import java.net.SocketException; |
| | | import java.util.Enumeration; |
| | | import java.util.Iterator; |
| | | import java.util.Stack; |
| | | |
| | |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 获得IP地址,分为两种情况: |
| | | * 一:是wifi下; |
| | | * 二:是移动网络下; |
| | | */ |
| | | public String getIPAddress(Context context) { |
| | | NetworkInfo info = ((ConnectivityManager) context |
| | | .getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo(); |
| | | if (info != null && info.isConnected()) { |
| | | if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//当前使用2G/3G/4G网络 |
| | | try { |
| | | //Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces(); |
| | | for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { |
| | | NetworkInterface intf = en.nextElement(); |
| | | for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { |
| | | InetAddress inetAddress = enumIpAddr.nextElement(); |
| | | if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) { |
| | | return inetAddress.getHostAddress(); |
| | | } |
| | | } |
| | | } |
| | | } catch (SocketException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//当前使用无线网络 |
| | | WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); |
| | | WifiInfo wifiInfo = wifiManager.getConnectionInfo(); |
| | | //调用方法将int转换为地址字符串 |
| | | String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//得到IPV4地址 |
| | | return ipAddress; |
| | | } |
| | | } else { |
| | | //当前无网络连接,请在设置中打开网络 |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 将得到的int类型的IP转换为String类型 |
| | | * |
| | | * @param ip int类型 |
| | | * @return - |
| | | */ |
| | | public static String intIP2StringIP(int ip) { |
| | | return (ip & 0xFF) + "." + |
| | | ((ip >> 8) & 0xFF) + "." + |
| | | ((ip >> 16) & 0xFF) + "." + |
| | | (ip >> 24 & 0xFF); |
| | | } |
| | | |
| | | |
| | | } |