app/src/main/java/com/hdl/photovoltaic/HDLApp.java
@@ -108,4 +108,17 @@ HDLUdpConnect.getInstance().initUdp(); } // /** // * 初始化uni app mqtt // */ // private void initUniMqtt() { // try { // Through.getInstance().setUni(false); // //IP 地址要根据实际的更改 // UniAppMqtt.getInstance().initMqtt(this, "tcp://192.168.3.124:1883", "Android_" + android.os.Build.BRAND + "_" + this.hashCode(), new String[]{"PCToAndroid/#"}); // } catch (Exception e) { // LogUtils.e("测试Mqtt连接服务端失败"); // } // } } app/src/main/java/com/hdl/photovoltaic/config/UserConfigManage.java
@@ -47,6 +47,8 @@ private String homeId; //是否登录状态 private boolean isLogin; //本地通讯秘钥 private String localSecret; //是否是B端账号登录 private boolean isB_account; @@ -156,6 +158,14 @@ isB_account = b; } public String getLocalSecret() { return localSecret == null ? "" : localSecret; } public void setLocalSecret(String localSecret) { this.localSecret = localSecret; } /** * 当前住宅 */ app/src/main/java/com/hdl/photovoltaic/internet/api/HttpApi.java
@@ -1,9 +1,7 @@ package com.hdl.photovoltaic.internet.api; public class HttpApi { /** * -----用户管理--------- */ //region -----用户管理--------- //获取账号区域信息 public static final String POST_RegionByUserAccount = "/smart-footstone/region/regionByUserAccount"; //登录接口 @@ -28,10 +26,8 @@ public static final String POST_GET_IMAGE_URL = "/home-wisdom/app/images/get_image_url"; //退出登录 public static final String POST_GET_IMAGE_LOGOUT = "basis-footstone/mgmt/user/oauth/logout"; /** * ------电站管理(住宅)-------- */ //endregion //region -----电站管理(住宅)--------- //电站列表 public static final String POST_PowerStation_List = "/home-wisdom/app/powerStation/page"; //电站创建 @@ -42,10 +38,9 @@ public static final String POST_PowerStation_Info = "/home-wisdom/app/powerStation/info"; //电站编辑 public static final String POST_PowerStation_Edit = "/home-wisdom/app/powerStation/edit"; //endregion /** * ------设备管理-------- */ //region -----设备管理--------- //添加逆变器 public static final String POST_Device_Add = "/home-wisdom/app/device/independentRegister"; //获取逆变器列表 @@ -56,6 +51,9 @@ public static final String POST_Device_ChildDevices_List = "/home-wisdom/app/powerStation/childDevices"; //全量更新OID public static final String POST_Device_Oid = "/home-wisdom/program/device/oid/add"; //获取逆变器(获取设备远程通讯信息) public static final String POST_Device_remoteInfo = "/home-wisdom/program/device/remoteInfo"; //endregion } app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -4,6 +4,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.hdlhttp.HxHttp; import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.internet.HttpClient; @@ -24,6 +25,8 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; import io.reactivex.rxjava3.disposables.Disposable; /** * 设备逻辑的界面 @@ -85,13 +88,13 @@ /** * 获取逆变器列表 * * @param inverterDeviceBean 逆变器对象 * @param cloudCallBeak 回调 * @param homeId 住宅id * @param cloudCallBeak 回调 */ public void getInverterDeviceList(InverterDeviceBean inverterDeviceBean, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { public void getInverterDeviceList(String homeId, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { String requestUrl = HttpApi.POST_Device_List; JsonObject json = new JsonObject(); json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); json.addProperty("homeId", homeId); // json.addProperty("zoneType", "password");//区域 HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { app/src/main/java/com/hdl/photovoltaic/other/HdlMqttLogic.java
New file @@ -0,0 +1,79 @@ package com.hdl.photovoltaic.other; import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; import com.hdl.hdlhttp.HxHttp; import com.hdl.photovoltaic.bean.HttpResponsePack; import com.hdl.photovoltaic.internet.HttpClient; import com.hdl.photovoltaic.internet.api.HttpApi; import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean; import java.lang.reflect.Type; import java.util.List; import io.reactivex.rxjava3.disposables.Disposable; /** * mqtt的逻辑 */ public class HdlMqttLogic { private static volatile HdlMqttLogic sHdlMqttLogic; /** * 获取当前对象 * * @return HdlAccountLogic */ public static synchronized HdlMqttLogic getInstance() { if (sHdlMqttLogic == null) { synchronized (HdlMqttLogic.class) { if (sHdlMqttLogic == null) { sHdlMqttLogic = new HdlMqttLogic(); } } } return sHdlMqttLogic; } /** * 获取逆变器(获取设备远程通讯信息) * * @param homeId 住宅Id * @param spk spk * @param mac 设备mac * @param cloudCallBeak 回调 */ public void getDeviceRemoteInfo(String homeId, String spk, String mac, CloudCallBeak<String> cloudCallBeak) { String requestUrl = HttpApi.POST_Device_remoteInfo; JsonObject json = new JsonObject(); json.addProperty("homeId", homeId); json.addProperty("spk", spk); json.addProperty("mac", mac); HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @Override public void onSuccess(HttpResponsePack httpResponsePack) { // if (httpResponsePack != null && httpResponsePack.getData() != null) { // Gson gson = new Gson(); // String json = gson.toJson(httpResponsePack.getData()); // Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() { // }.getType(); // if (cloudCallBeak != null) { // cloudCallBeak.onSuccess("list"); // } // } } @Override public void onFailure(Exception exception) { if (cloudCallBeak != null) { cloudCallBeak.onFailure(exception); } } }); } } app/src/main/java/com/hdl/photovoltaic/other/HdlResidenceLogic.java
@@ -12,6 +12,10 @@ import com.hdl.photovoltaic.listener.CloudCallBeak; import com.hdl.photovoltaic.ui.bean.HouseInfoBean; import com.hdl.photovoltaic.ui.bean.HouseIdBean; import com.hdl.sdk.link.common.exception.HDLLinkException; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.config.HDLLinkConfig; import java.util.ArrayList; import java.util.List; @@ -502,21 +506,44 @@ /** * 切换住宅 * * @param homeId 住宅id * @param houseIdBean 住宅Id对象 */ public Boolean switchHouse(String homeId) { public void switchHouse(HouseIdBean houseIdBean) { String oidHomeId = UserConfigManage.getInstance().getHomeId(); if (houseIdBean.getHomeId().equals(oidHomeId)) { return; } //删除旧的住宅文件夹 HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); UserConfigManage.getInstance().setHomeId(homeId); //重新设置住宅id UserConfigManage.getInstance().setHomeId(houseIdBean.getHomeId()); //重新设置本地通讯秘钥 UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); //重新创建住宅文件夹 HdlFileLogic.getInstance().createDirectory(); HdlThreadLogic.runThread(new Runnable() { //配置本地通信的信息 initLocalLinkSdk(); HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { @Override public void run() { //搜索一下住宅设备 public void onSuccess(List<GatewayBean> gatewayBeanList) { } }, null, null); return true; @Override public void onError(HDLLinkException e) { } }); } /** * 配置本地通信的信息(tcp通信用到) */ private void initLocalLinkSdk() { HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); } app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -113,6 +113,7 @@ } break; case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: { //发送modbus协议 // HDLModBusConnect.getInstance().Send(uniToAndroidBean.getGatewayOid(), null, ); } app/src/main/java/com/hdl/photovoltaic/ui/bean/HouseIdBean.java
@@ -10,6 +10,7 @@ private String power;//发电功率 private String todayElectricity;//今天发电量 private int powerStationStatus;//电站状态(电站状态 1:正常(运行),2:离线,3:连接中,4:故障) private String localSecret;//本地通讯秘钥 public String getHomeId() { return homeId == null ? "" : homeId; @@ -66,5 +67,12 @@ public void setPowerStationStatus(int powerStationStatus) { this.powerStationStatus = powerStationStatus; } public String getLocalSecret() { return localSecret == null ? "" : localSecret; } public void setLocalSecret(String localSecret) { this.localSecret = localSecret; } } app/src/main/java/com/hdl/photovoltaic/ui/powerstation/HouseListFragment.java
@@ -104,7 +104,7 @@ public void onClick(int position, HouseIdBean houseIdBean) { //点击住宅详情 HdlLogLogic.print("====点击住宅详情" + position); HdlResidenceLogic.getInstance().switchHouse(houseIdBean.getHomeId()); HdlResidenceLogic.getInstance().switchHouse(houseIdBean); String path = HDLUniMP.UNI_EVENT_OPEN_HOME_DETAILS + "?homeId=" + houseIdBean.getHomeId(); HdlUniLogic.getInstance().openUniMP(path, null); } app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
@@ -69,8 +69,6 @@ */ public static class UniCallBackBaseBean implements Serializable { private String path;//打开小程序路径(暂时用不上) private String code;//状态码 private String mes;//信息描述 private String type;//功能类型 @@ -118,14 +116,6 @@ public void setType(String type) { this.type = type; } public String getPath() { return path == null ? "" : path; } public void setPath(String path) { this.path = path; } app/src/main/java/com/hdl/photovoltaic/utils/ThroughUtils.java
New file @@ -0,0 +1,117 @@ //package com.hdl.photovoltaic.utils; // //import com.alibaba.fastjson.JSONObject; //import com.hdl.photovoltaic.other.HdlUniLogic; //import com.hdl.photovoltaic.uni.HDLUniMP; //import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; //import com.hdl.sdk.link.common.event.EventListener; //import com.hdl.sdk.link.core.bean.ZigbeeResponse; //import com.hdl.sdk.link.core.connect.HDLZigbeeConnect; // ///** // * Created by hxb on 2022/1/18. // * 原生透传到uni app // */ //public class ThroughUtils { // // final String tag = ThroughUtils.class.getName(); // // /** // * 是否uni方式,否则mqtt方式 // */ // private boolean isUni=true; // // // /** // * instance // */ // private volatile static ThroughUtils instance; // // /** // * getInstance // * // * @return Through // */ // public static synchronized ThroughUtils getInstance() { // if (instance == null) { // synchronized (ThroughUtils.class) { // if (instance == null) { // instance = new ThroughUtils(); // } // } // } // return instance; // } // // EventListener throughEventListener; // // /** // * 注册新设备入网监听 // */ // public void registerThroughListener() { // //注册监听事件 // if (throughEventListener == null) { // throughEventListener = new EventListener() { // @Override // public void onMessage(Object msg) { // if (msg instanceof ZigbeeResponse) { // ZigbeeResponse zigbeeResponse = (ZigbeeResponse) msg; // try { // HDLUniMP.UniCallBackBaseBean callBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); // callBackBaseBean.setTopic(zigbeeResponse.getTopic()); // callBackBaseBean.setData(zigbeeResponse.getData()); // if (zigbeeResponse.getTopic().startsWith("ZbDataPassthrough")) { // //如果不是使用mqtt方式,就使用uni app推送方式 // if (isUni()) { // HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, callBackBaseBean); // HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.UNI_EVENT_ZigBeePassthrough, JSONObject.toJSON(callBackBaseBean)); // } else {//使用mqtt方式 // //AndroidToPC/唯一标识/uni_event" // UniAppMqtt.getInstance().publish(String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.UNI_EVENT_ZigBeePassthrough), JSONObject.toJSON(callBackBaseBean).toString()); // } // } // else if(zigbeeResponse.getTopic().contains("DeviceStatusReport/")){ // //如果不是使用mqtt方式,就使用uni app推送方式 // if (isUni()) { // HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, HDLUniMP.EVENT_DeviceStatusReportPassthrough, JSONObject.toJSON(callBackBaseBean)); // } else {//使用mqtt方式 // //AndroidToPC/唯一标识/uni_event" // UniAppMqtt.getInstance().publish(String.format("AndroidToPC/%s/%s", System.currentTimeMillis(), HDLUniMP.EVENT_DeviceStatusReportPassthrough), JSONObject.toJSON(callBackBaseBean).toString()); // } // } // // } catch (Exception e) { // // } // } // } // }; // HDLZigbeeConnect.getInstance().registerListener(throughEventListener); // } // } // // /** // * 移除全局监听 // */ // public void removeThroughListener() // { // HDLZigbeeConnect.getInstance().removeListener(throughEventListener); // throughEventListener=null; // } // // /** // * 是否uni方式,否则mqtt方式 // * @return // */ // public boolean isUni() { // return isUni; // } // // /** // * 是否uni方式,否则mqtt方式 // * @param uni // */ // public void setUni(boolean uni) { // isUni = uni; // } //} local.properties
@@ -5,4 +5,4 @@ # For customization when using a Version Control System, please read the # header note. #Wed Jun 28 17:38:10 CST 2023 sdk.dir=/Users/wenjucheng/Library/Android/sdk sdk.dir=/Users/hdl/Library/Developer/Xamarin/android-sdk-macosx/platform-tools