| | |
| | | */
|
| | | if (code == null || code.intValue() == 200 || code.intValue() == 0) {
|
| | | notifySucceed(msg);
|
| | | }else {
|
| | | } else {
|
| | | notifyFailure(ErrorUtils.getByCode(code));
|
| | | }
|
| | | }
|
| | | else if (msg instanceof ZigbeeResponse) {
|
| | | } else if (msg instanceof ZigbeeResponse) {
|
| | | ZigbeeResponse linkResponse = (ZigbeeResponse) msg;
|
| | | //TODO 如果配置从网关的信息,通过主网关转达,这里oid要判断下
|
| | | if (replyTopic.equals(linkResponse.getTopic())) {
|
| | | notifySucceed(linkResponse.getData());
|
| | | }
|
| | | else{
|
| | | } else {
|
| | | notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT);
|
| | | }
|
| | | }else if(msg instanceof ModbusResponse){
|
| | | } else if (msg instanceof ModbusResponse) {
|
| | | ModbusResponse response = (ModbusResponse) msg;
|
| | | if (replyTopic.equals(response.getTopic())) {
|
| | | notifySucceed(response.getData());
|
| | | }
|
| | | else{
|
| | | } else {
|
| | | notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT);
|
| | | }
|
| | | }
|
| | | else{
|
| | | } else {
|
| | | notifyFailure(new HDLLinkCode(HDLLinkCode.HDL_OBJECT_NOT_SUPPORT.getCode(), "Object Name:" + msg));
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
| | | * @param mac 设备mac
|
| | | */
|
| | | public HDLConnectHelper(Long sendAwaitTime, int maxRetry, String ipAddress, int port,
|
| | | LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp,String mac) {
|
| | | this(sendAwaitTime,maxRetry,ipAddress,port,linkRequest,listener,isTcp);
|
| | | LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, String mac) {
|
| | | this(sendAwaitTime, maxRetry, ipAddress, port, linkRequest, listener, isTcp);
|
| | | this.mac = mac;
|
| | | }
|
| | |
|
| | |
| | | * @param mac 设备mac
|
| | | */
|
| | | public HDLConnectHelper(String ipAddress,
|
| | | LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp,String mac) {
|
| | | this(DEF_SEND_TIMEOUT, DEF_MAX_RETRY, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, listener, isTcp,mac);
|
| | | LinkRequest linkRequest, HdlSocketListener listener, boolean isTcp, String mac) {
|
| | | this(DEF_SEND_TIMEOUT, DEF_MAX_RETRY, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, listener, isTcp, mac);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | /**
|
| | |
| | | * @param linkRequest 发送对象
|
| | | * @param isTcp 是否TCP
|
| | | */
|
| | | public HDLConnectHelper(Long timeout,String ipAddress, LinkRequest linkRequest, boolean isTcp) {
|
| | | public HDLConnectHelper(Long timeout, String ipAddress, LinkRequest linkRequest, boolean isTcp) {
|
| | | this(timeout, DEF_SEND_ONE, ipAddress, isTcp ? TCP_PORT : UDP_PORT, linkRequest, null, isTcp);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | /**
|
| | |
| | | byte[] encryBytes = null;
|
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
|
| | | if (gatewayBean != null && getGatewayTypeList().contains(gatewayBean.getGatewayType())) {
|
| | | //毫米波远程mqtt秘钥不一样
|
| | | //逆变器远程mqtt秘钥不一样
|
| | | encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), gatewayBean.getAesKey());
|
| | | } else {
|
| | | encryBytes = EncryptUtil.encryBytes(linkRequest.getCloudSendBytes(), HDLLinkConfig.getInstance().getAesKey());
|
| | |
| | | connOpts.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1_1);
|
| | | sampleClient.setCallback(new MqttCallbackExtended() {
|
| | | public void connectComplete(boolean reconnect, String serverURI) {
|
| | | LogUtils.d(TAG, "connect success");
|
| | | LogUtils.d(TAG, "mqtt连接成功");
|
| | | checkAndsubscribeAllTopics("");
|
| | | }
|
| | |
|
| | | public void connectionLost(Throwable throwable) {
|
| | | LogUtils.d(TAG, "连接断开");
|
| | | LogUtils.d(TAG, "mqtt连接断开");
|
| | | lastTopicFilters.clear();
|
| | | }
|
| | |
|
| | |
| | | if (cloudsGatewayId.equals(HDLLinkConfig.getInstance().getHomeId())) {
|
| | | aes = getHomeAES();
|
| | | } else if (gatewayBean != null && HDLConnectHelper.getGatewayTypeList().contains(gatewayBean.getGatewayType())) {
|
| | | //毫米波mqtt专用秘钥
|
| | | //逆变器mqtt专用秘钥
|
| | | aes = gatewayBean.getAesKey();
|
| | | } else {
|
| | | aes = HDLLinkConfig.getInstance().getAesKey();
|
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 收到EventBUs通知 |
| | | * |
| | | * @param eventBus 数据 |
| | | */ |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | |
New file |
| | |
| | | package com.hdl.photovoltaic.bean; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | public class MqttInfo implements Serializable { |
| | | //客户端id |
| | | private String clientId; |
| | | //密码 |
| | | private String passWord; |
| | | //地址 |
| | | private String url; |
| | | //用户名 |
| | | private String userName; |
| | | |
| | | public String getClientId() { |
| | | return clientId == null ? "" : clientId; |
| | | } |
| | | |
| | | public void setClientId(String clientId) { |
| | | this.clientId = clientId; |
| | | } |
| | | |
| | | public String getPassWord() { |
| | | return passWord == null ? "" : passWord; |
| | | } |
| | | |
| | | public void setPassWord(String passWord) { |
| | | this.passWord = passWord; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url == null ? "" : url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | |
| | | public String getUserName() { |
| | | return userName == null ? "" : userName; |
| | | } |
| | | |
| | | public void setUserName(String userName) { |
| | | this.userName = userName; |
| | | } |
| | | } |
| | |
| | | public static final String SAVE_HOME_HOME_ID = "homeId"; |
| | | |
| | | /******EventBus发布事件的常量*********/ |
| | | public static final String EVENTBUS_POST_HOME_CREATED = "home_created";//住宅创建发布 |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | public class MqttClient { |
| | | |
| | | |
| | | } |
| | |
| | | package com.hdl.photovoltaic.internet.api; |
| | | |
| | | public class HttpApi { |
| | | //region -----用户管理--------- |
| | | /** |
| | | * B端接口 |
| | | */ |
| | | //获取账号区域信息 |
| | | public static final String POST_RegionByUserAccount = "/smart-footstone/region/regionByUserAccount"; |
| | | //登录接口 |
| | | public static final String POST_Login = "/smart-footstone/user/oauth/login"; |
| | | //用户找回密码 忘记密码,通过邮箱和手机号找回 |
| | | public static final String B_POST_FORGET_PROGRAM_PWD = "/smart-footstone/user/oauth/forgetProgramPwd"; |
| | | //发送消息验证码 |
| | | public static final String POST_SEND_VERIFICATION = "/smart-footstone/verification/message/send"; |
| | | //更改个人密码 |
| | | public static final String POST_UPDATE_PROGRAM_PASSWORD = "/smart-footstone/user/userInfo/updateProgramPassword"; |
| | | //获取员工列表 |
| | | public static final String POST_GET_USER_LIST = "/smart-footstone/user/userInfo/getUserList"; |
| | | //获取用户个人信息 C端 |
| | | public static final String POST_GET_MEMBER_INFO = "/smart-footstone/member/memberInfo/getMemberInfo"; |
| | | //更新个人信息 C端 |
| | | public static final String POST_UPDATE_MEMBER_INFO = "/smart-footstone/member/memberInfo/updateMemberInfo"; |
| | | //上传图片 |
| | | public static final String POST_UPLOAD_IMAGE = "/home-wisdom/app/images/upload_image"; |
| | | //上传图片(新) |
| | | public static final String POST_UPLOAD_IMAGE_NEW = "/basis-cosmos/file/upload"; |
| | | //查询图片路径 |
| | | 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"; |
| | | /** |
| | | * C端接口 |
| | | */ |
| | | //退出登录 |
| | | public static final String C_POST_GET_OAUTH_REGISTER = "/smart-footstone/member/oauth/register"; |
| | | //用户找回密码 忘记密码,通过邮箱和手机号找回 |
| | | public static final String C_POST_FORGET_PROGRAM_PWD = "/smart-footstone/member/oauth/forgetPwd"; |
| | | |
| | | //region **********【B端】和【C端】共用接口********** |
| | | //mqtt连接需要(语雀接口地址:https://hdl-gz.yuque.com/wnkbmh/cdrglh/totdnt#40b28997) |
| | | public static final String POST_Mqtt_GetRemoteInfo = "/home-wisdom/app/mqtt/getRemoteInfo"; |
| | | |
| | | //endregion |
| | | //region -----电站管理(住宅)--------- |
| | | //电站列表 |
| | | public static final String POST_PowerStation_List = "/home-wisdom/app/powerStation/page"; |
| | |
| | | //全量更新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"; |
| | | public static final String POST_Device_RemoteInfo = "/home-wisdom/program/device/remoteInfo"; |
| | | //endregion |
| | | //endregion |
| | | |
| | | //region **********【B端接口】********** |
| | | |
| | | //region -----用户管理--------- |
| | | //获取账号区域信息 |
| | | public static final String POST_RegionByUserAccount = "/smart-footstone/region/regionByUserAccount"; |
| | | //登录接口 |
| | | public static final String POST_Login = "/smart-footstone/user/oauth/login"; |
| | | //用户找回密码 忘记密码,通过邮箱和手机号找回 |
| | | public static final String B_POST_FORGET_PROGRAM_PWD = "/smart-footstone/user/oauth/forgetProgramPwd"; |
| | | //发送消息验证码 |
| | | public static final String POST_SEND_VERIFICATION = "/smart-footstone/verification/message/send"; |
| | | //更改个人密码 |
| | | public static final String POST_UPDATE_PROGRAM_PASSWORD = "/smart-footstone/user/userInfo/updateProgramPassword"; |
| | | //获取员工列表 |
| | | public static final String POST_GET_USER_LIST = "/smart-footstone/user/userInfo/getUserList"; |
| | | //获取用户个人信息 C端 |
| | | public static final String POST_GET_MEMBER_INFO = "/smart-footstone/member/memberInfo/getMemberInfo"; |
| | | //更新个人信息 C端 |
| | | public static final String POST_UPDATE_MEMBER_INFO = "/smart-footstone/member/memberInfo/updateMemberInfo"; |
| | | //上传图片 |
| | | public static final String POST_UPLOAD_IMAGE = "/home-wisdom/app/images/upload_image"; |
| | | //上传图片(新) |
| | | public static final String POST_UPLOAD_IMAGE_NEW = "/basis-cosmos/file/upload"; |
| | | //查询图片路径 |
| | | 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 |
| | | //endregion |
| | | |
| | | |
| | | //region **********【C端接口】********** |
| | | //region -----用户管理--------- |
| | | |
| | | |
| | | //退出登录 |
| | | public static final String C_POST_GET_OAUTH_REGISTER = "/smart-footstone/member/oauth/register"; |
| | | //用户找回密码 忘记密码,通过邮箱和手机号找回 |
| | | public static final String C_POST_FORGET_PROGRAM_PWD = "/smart-footstone/member/oauth/forgetPwd"; |
| | | //endregion |
| | | //endregion |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | import com.hdl.sdk.link.gateway.type.GatewayMasterType; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | |
| | | */ |
| | | public class HdlDeviceLogic { |
| | | private static volatile HdlDeviceLogic sHdlDeviceLogic; |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表 |
| | | */ |
| | | public List<GatewayBean> getGatewayList() { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals("true") |
| | | && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前对象 |
| | |
| | | } |
| | | return sHdlDeviceLogic; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表 |
| | | */ |
| | | public List<GatewayBean> getCurrentHomeGatewayList() { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) |
| | | && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加逆变器到云端上 |
| | |
| | | public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_EDIT; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("master", "true"); |
| | | json.addProperty("master", GatewayMasterType.MasterTrue); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取本地逆变器列表 |
| | | * 获取逆变器列表 |
| | | * 注意:有外网以云端设备为准,本地存在,云端没有则删除;内网以本地为主,搜索多少个设备就显示多少个; |
| | | * |
| | | * @param cloudCallBeak - |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | */ |
| | | public void getLocalGatewayList(CloudCallBeak<Boolean> cloudCallBeak) { |
| | | public void getCurrentHomeLocalAndCloudGatewayList(CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //局域网情况 |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | |
| | | // //云端没有绑定逆变器,以本地为主; |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | return; |
| | | } |
| | |
| | | removeInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | } |
| | |
| | | removeInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //外网情况 |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | //清楚本地网关列表 |
| | | //云端没有,清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | |
| | | if (list == null || list.size() == 0) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | return; |
| | | } |
| | |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | } |
| | |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | * @return - |
| | | */ |
| | | public void getDeviceRemoteInfo(String homeId, String spk, String mac, CloudCallBeak<DeviceRemoteInfo> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_remoteInfo; |
| | | String requestUrl = HttpApi.POST_Device_RemoteInfo; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("spk", spk); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 搜索网关列表 |
| | | * 搜索逆变器列表 |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | |
| | | if (deviceRemoteInfo != null) { |
| | | gatewayBean.setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥 |
| | | gatewayBean.setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | //用之前的库,底层mqtt订阅,加解密会用到该参数; |
| | | HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥库 |
| | | HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | |
| | | } |
| | | gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());//住宅id |
| | | gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//设置网关状态 |
| | |
| | | gatewayBean.setDevice_name(cloudInverterDeviceBean.getName());//设备名称 |
| | | gatewayBean.setGatewayType(cloudInverterDeviceBean.getSpk());//设置spk |
| | | gatewayBean.setLocalEncrypt(true); |
| | | gatewayBean.setMaster("true"); |
| | | gatewayBean.setMaster(GatewayMasterType.MasterTrue); |
| | | gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态 |
| | | gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号 |
| | | gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//设备类型(产品二级分类名称 |
| | |
| | | |
| | | import android.util.Log; |
| | | |
| | | import com.google.gson.Gson; |
| | | |
| | | /** |
| | | * 日志逻辑 |
| | | */ |
| | |
| | | * android打印 |
| | | * |
| | | * @param tag 标签 |
| | | * @param mgs 输出信息 |
| | | * @param mgs 错误信息 |
| | | */ |
| | | public static void print(String tag, String mgs) { |
| | | if (isDebug) { |
| | |
| | | System.out.println(mgs); |
| | | } |
| | | |
| | | /** |
| | | * java打印 |
| | | * |
| | | * @param tag 标题 |
| | | * @param mgs 错误信息 |
| | | * @param code 错误码 |
| | | */ |
| | | public static void print(String tag, String mgs, int code) { |
| | | if (isDebug) { |
| | | return; |
| | | } |
| | | System.out.println(title + tag + "======" + mgs + "(" + code + ")"); |
| | | } |
| | | |
| | | /** |
| | | * java打印 |
| | | * |
| | | * @param tag 标题 |
| | | * @param mgs 错误信息 |
| | | * @param code 错误码 |
| | | */ |
| | | public static void print(String tag, String mgs, String code) { |
| | | if (isDebug) { |
| | | return; |
| | | } |
| | | System.out.println(title + tag + "======" + mgs + "(" + code + ")"); |
| | | } |
| | | |
| | | /** |
| | | * java打印 |
| | | * |
| | | * @param tag 标题 |
| | | * @param o 错误信息 |
| | | */ |
| | | public static void print(String tag, Object o) { |
| | | |
| | | if (isDebug) { |
| | | return; |
| | | } |
| | | if (o == null) { |
| | | System.out.println(title + tag); |
| | | } else { |
| | | try { |
| | | System.out.println(title + tag + "======" + new Gson().toJson(o)); |
| | | } catch (Exception e) { |
| | | System.out.println(title + tag + "======" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private static final String title = "自定义输出打印信息:"; |
| | | |
| | | } |
| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlhttp.HxHttp; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.bean.HttpResponsePack; |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | | 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 com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取逆变器(获取设备远程通讯信息) |
| | | * 获取mqtt远程连接数据 |
| | | * |
| | | * @param homeId 住宅Id |
| | | * @param spk spk |
| | | * @param mac 设备mac |
| | | * @param homeType 住宅类型 (1.ZIGBEE 2.BUSPRO 3.A 4.ALL) |
| | | * @param cloudCallBeak 回调 |
| | | */ |
| | | public void getDeviceRemoteInfo(String homeId, String spk, String mac, CloudCallBeak<String> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_remoteInfo; |
| | | public void getMqttRemoteInfo(String homeType, CloudCallBeak<MqttInfo> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Mqtt_GetRemoteInfo; |
| | | int randomNumberClientId = new Random().nextInt(1000000000); |
| | | String deviceUuid = Settings.System.getString(HDLApp.getInstance().getContentResolver(), Settings.System.ANDROID_ID); |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("spk", spk); |
| | | json.addProperty("mac", mac); |
| | | json.addProperty("attachClientId", randomNumberClientId); |
| | | json.addProperty("homeType", homeType); |
| | | json.addProperty("deviceUuid", deviceUuid); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | // 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"); |
| | | // } |
| | | // } |
| | | Type type = new TypeToken<MqttInfo>() { |
| | | }.getType(); |
| | | MqttInfo mqttInfo = new Gson().fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(mqttInfo); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public void switchHouse(HouseIdBean houseIdBean) { |
| | | String oidHomeId = UserConfigManage.getInstance().getHomeId(); |
| | | // if (houseIdBean.getHomeId().equals(oidHomeId)) { |
| | | // return; |
| | | // } |
| | | |
| | | if (houseIdBean.getHomeId().equals(oidHomeId)) { |
| | | HdlLogLogic.print("点击同一个住宅"); |
| | | return; |
| | | } |
| | | //删除旧的住宅文件夹 |
| | | HdlFileLogic.getInstance().deleteDirectory(HdlFileLogic.getInstance().getCurrentHomeRootPath()); |
| | | //重新设置住宅id |
| | | UserConfigManage.getInstance().setHomeId(houseIdBean.getHomeId()); |
| | | //重新设置本地通讯秘钥 |
| | | UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); |
| | | //重新创建住宅文件夹 |
| | | HdlFileLogic.getInstance().createDirectory(); |
| | | //配置本地通信的信息 |
| | | initLocalLinkSdk(); |
| | | |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 配置本地通信的信息(tcp通信用到) |
| | | */ |
| | | private void initLocalLinkSdk() { |
| | | HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); |
| | | HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); |
| | | |
| | | |
| | | //重新创建住宅文件夹 |
| | | HdlFileLogic.getInstance().createDirectory(); |
| | | //进去住宅详情搜索一下逆变器列表,目的是建立通讯通道; |
| | | HdlDeviceLogic.getInstance().searchGateway(null); |
| | | } |
| | | |
| | | |
| | | static class HouseBeanClass { |
| | | |
| | |
| | | import android.util.Log; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.bean.BaseEventBus; |
| | |
| | | import com.hdl.sdk.link.core.callback.GatewayCallBack; |
| | | import com.hdl.sdk.link.core.callback.ModbusCallBack; |
| | | import com.hdl.sdk.link.core.connect.HDLModBusConnect; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | |
| | | //EventBus事件分发 |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | | baseEventBus.setType(ConstantManage.EVENTBUS_POST_HOME_CREATED); |
| | | baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION); |
| | | baseEventBus.setData(getKeyValue("data", data)); |
| | | EventBus.getDefault().post(baseEventBus); |
| | | } |
| | | break; |
| | | //读取详情 |
| | | case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: { |
| | | //详情 |
| | | |
| | | } |
| | | break; |
| | | //关闭详情页 |
| | | case HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE: { |
| | | //关闭详情页 |
| | | //EventBus事件分发 |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | | baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE); |
| | | baseEventBus.setData(getKeyValue("data", data)); |
| | | EventBus.getDefault().post(baseEventBus); |
| | | } |
| | | break; |
| | | |
| | |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) { |
| | | //设备模块 |
| | | switch (type) { |
| | | //添加逆变器到云端 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: { |
| | | //添加设备到云端 |
| | | String mac = getKeyValue("mac", getKeyValue("data", data)); |
| | | HdlDeviceLogic.getInstance().setGatewayRemoteParam(mac, new LinkCallBack<Boolean>() { |
| | | @Override |
| | |
| | | |
| | | } |
| | | break; |
| | | //局域网搜索逆变器列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_NET_LIST: { |
| | | //网关搜索 |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | |
| | | break; |
| | | //获取逆变器列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: { |
| | | |
| | | HdlDeviceLogic.getInstance().getLocalGatewayList(new CloudCallBeak<Boolean>() { |
| | | HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(new CloudCallBeak<List<GatewayBean>>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | public void onSuccess(List<GatewayBean> list) { |
| | | if (callback != null) { |
| | | uniCallbackData(HdlDeviceLogic.getInstance().getGatewayList(), callback); |
| | | uniCallbackData(list, callback); |
| | | //EventBus事件分发 |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | | baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST); |
| | | baseEventBus.setData(list); |
| | | EventBus.getDefault().post(baseEventBus); |
| | | } |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | break; |
| | | //设备时间读取 |
| | | //逆变器时间读取 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME: { |
| | | //添加设备到云端 |
| | | String mac = getKeyValue("mac", getKeyValue("data", data)); |
| | | //获取oid列表 |
| | | HdlDeviceLogic.getInstance().getGatewayTime(mac, new LinkCallBack<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | |
| | | }); |
| | | } |
| | | break; |
| | | //设备时间编辑 |
| | | //逆变器时间编辑 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME_EDIT: { |
| | | String mac = getKeyValue("mac", getKeyValue("data", data)); |
| | | HdlDeviceLogic.getInstance().getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(List<OidBean> obj) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | |
| | | } |
| | | }); |
| | | HdlDeviceLogic.getInstance().editGatewayTime(mac, new JsonObject(), null); |
| | | } |
| | | break; |
| | | |
| | |
| | | import android.Manifest; |
| | | import android.content.pm.PackageManager; |
| | | import android.os.Bundle; |
| | | import android.provider.Settings; |
| | | import android.view.View; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.linkpm.sdk.core.callback.IResponseCallBack; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.home.type.HomeType; |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.bean.MqttInfo; |
| | | import com.hdl.photovoltaic.databinding.ActivityMyPowerStationBinding; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlMqttLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.event.EventListener; |
| | | import com.hdl.sdk.link.core.bean.ModbusResponse; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * 我的电站界面 |
| | |
| | | initEvent(); |
| | | //注册监听 |
| | | registerAllTopicsListener(); |
| | | //初始化mqtt客户端 |
| | | initMqttClient(); |
| | | |
| | | |
| | | } |
| | | |
| | | private void initEvent() { |
| | |
| | | HDLLinkLocalSdk.getInstance().registerAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | /** |
| | | * 初始化mqtt客户端 |
| | | */ |
| | | public void initMqttClient() { |
| | | HdlMqttLogic.getInstance().getMqttRemoteInfo(HomeType.A, new CloudCallBeak<MqttInfo>() { |
| | | @Override |
| | | public void onSuccess(MqttInfo info) { |
| | | if (info != null) { |
| | | MqttRecvClient.init(_mActivity, info.getUrl(), info.getClientId(), info.getUserName(), info.getPassWord()); |
| | | HdlLogLogic.print("mqtt初始化成功!", info); |
| | | } else { |
| | | HdlLogLogic.print("mqtt初始化失败!", null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("mqtt初始化失败", e.getMessage(), e.getCode()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import android.widget.LinearLayout; |
| | | import android.widget.RelativeLayout; |
| | | |
| | | import com.hdl.linkpm.sdk.user.HDLLinkPMUser; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.databinding.ActivitySetBinding; |
| | |
| | | /** |
| | | * 设置界面 |
| | | */ |
| | | public class SetActivity extends CustomBaseActivity { |
| | | public class SetActivity extends CustomBaseActivity implements View.OnClickListener { |
| | | |
| | | private ActivitySetBinding viewBinding; |
| | | |
| | |
| | | } |
| | | |
| | | private void initEvent() { |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | finish(); |
| | | } |
| | | }); |
| | | viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.setOnClickListener(this); |
| | | viewBinding.outTv.setOnClickListener(this); |
| | | } |
| | | |
| | | private void initView() { |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (v.getId() == viewBinding.toolbarTopFragmentHouseListRl.topBackBtn.getId()) { |
| | | finish(); |
| | | } else if (v.getId() == viewBinding.outTv.getId()) { |
| | | logoutRequest(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 退出登录请求的方法 |
| | | */ |
| | | private void logoutRequest() { |
| | | HDLLinkPMUser.getInstance().logout(0); |
| | | } |
| | | } |
| | |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.bean.BaseEventBus; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.databinding.FragmentHouseListBinding; |
| | | import com.hdl.photovoltaic.base.CustomBaseFragment; |
| | | import com.hdl.photovoltaic.enums.ShowErrorMode; |
| | |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | import com.hdl.photovoltaic.ui.adapter.HouseInfoAdapter; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.HouseIdBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.PermissionUtils; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | manager = (CameraManager) _mActivity.getSystemService(Context.CAMERA_SERVICE); |
| | | |
| | | initData(); |
| | | //初始化 |
| | | initView(); |
| | |
| | | this.houseListBeanIDList.addAll(HdlResidenceLogic.getInstance().getHouseIdList()); |
| | | } |
| | | |
| | | /** |
| | | * 收到EventBUs通知 |
| | | * |
| | | * @param eventBus 数据 |
| | | */ |
| | | @Override |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | super.onEventMessage(eventBus); |
| | | //收到EventBUs通知 |
| | | if (ConstantManage.EVENTBUS_POST_HOME_CREATED.equals(eventBus.getType())) { |
| | | if (HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION.equals(eventBus.getType())) { |
| | | //uin创建电站成功后通知 |
| | | updateUIData(false); |
| | | if (eventBus.getData() != null) { |
| | | Gson gson = new Gson(); |
| | |
| | | HouseIdBean houseIdBean = gson.fromJson(json, HouseIdBean.class); |
| | | HdlResidenceLogic.getInstance().switchHouse(houseIdBean); |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE.equals(eventBus.getType())) { |
| | | //uin关闭住宅详情界面通知 |
| | | if (MqttRecvClient.getInstance() != null) { |
| | | MqttRecvClient.getInstance().removeAllTopic(); |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST.equals(eventBus.getType())) { |
| | | //进去住宅详情读取逆变器列表成功后通知 |
| | | for (int i = 0; i < HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().size(); i++) { |
| | | //String gatewayId = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList().get(i).getGatewayId(); |
| | | //字符串是自己按规则拼接的,里面注册主题时会解析字符串,只拿getGatewayId()值; |
| | | //String topic = "/user/" + gatewayId+"/1"; |
| | | //进去住宅详情开始订阅主题 |
| | | MqttRecvClient.getInstance().checkAndsubscribeAllTopics(""); |
| | | } |
| | | } |
| | | } |
| | | |