| | |
| | | public static final String POST_OTA_GET_DeviceFirmwares = "/home-wisdom/program/device/ota/getDeviceFirmwares"; |
| | | //设备固件云端的驱动分页列表获取 |
| | | public static final String POST_OTA_GET_CloudDeviceFirmwares = "/smart-footstone/firmware/firmwareVersion/getLastOne"; |
| | | //Link设备固件升级OTA命令下发 |
| | | //设备固件升级OTA命令 |
| | | public static final String POST_OTA_DeviceFirmwareUpgrade = "/home-wisdom/program/device/ota/deviceFirmwareUpgrade"; |
| | | //LINK设备获取固件升级包下载地址 |
| | | //设备获取固件升级包下载地址 |
| | | public static final String POST_OTA_GET_LinkDeviceFirmwareDownloadUrl = "/smart-footstone/mgmt/device/ota/getLinkDeviceFirmwareDownloadUrl"; |
| | | |
| | | //获取IARCC三方固件分页 |
| | |
| | | dirs 'libs' |
| | | } |
| | | } |
| | | /** |
| | | * 打包自动命名 |
| | | */ |
| | | android.applicationVariants.configureEach { variant -> |
| | | variant.outputs.configureEach { |
| | | outputFileName = "photovoltaic_${name}_v${versionName}_${generateTime()}.apk" |
| | | } |
| | | } |
| | | |
| | | buildTypes { |
| | | release { |
| | |
| | | targetCompatibility JavaVersion.VERSION_1_8 |
| | | } |
| | | } |
| | | //构建时间 |
| | | static def generateTime() { |
| | | return new Date().format("yyyyMMddHHmm") |
| | | } |
| | | |
| | | dependencies { |
| | | |
| | |
| | | package com.hdl.photovoltaic; |
| | | |
| | | import android.app.Application; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.content.res.Resources; |
| | | import android.util.DisplayMetrics; |
| | | |
| | | |
| | | import com.hdl.hdlhttp.HxHttpConfig; |
| | |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | import com.hdl.photovoltaic.utils.SharedPreUtils; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.core.connect.HDLUdpConnect; |
| | | import com.hdl.sdk.link.core.utils.QueueUtils; |
| | | import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; |
| | | |
| | | import java.util.HashMap;import java.util.Locale; |
| | | import java.util.HashMap; |
| | | import java.util.Locale; |
| | | import java.util.Objects; |
| | | |
| | | import io.dcloud.common.util.RuningAcitvityUtil; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // /** |
| | | // * 初始化uni app mqtt |
| | | // */ |
| | |
| | | // } |
| | | // } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | import com.hdl.photovoltaic.listener.BaseView; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | import com.hdl.photovoltaic.widget.LoadingDialog; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | |
| | |
| | | @Override |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | |
| | | LocalManageUtil.changeAppLanguage("en", this); |
| | | _mActivity = this; |
| | | Object content = getContentView(); |
| | | //添加Activity到堆栈 |
| | |
| | | package com.hdl.photovoltaic.base; |
| | | |
| | | |
| | | import android.content.Context; |
| | | import android.os.Bundle; |
| | | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.utils.LocalManageUtil; |
| | | |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 自定义方法,用于实现个性化 |
| | |
| | | @Override |
| | | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | setNotificationBarBackgroundColor(0); |
| | | setNotificationBarBackgroundColor(CustomColor.blue); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param color 颜色值(0=蓝色;1=白色;) |
| | | */ |
| | | public void setNotificationBarBackgroundColor(int color) { |
| | | |
| | | if (color == 0) { |
| | | color = R.color.text_245EC3; |
| | | } else if (color == 1) { |
| | | if (color == 1) { |
| | | color = R.color.text_FFFFFFFF; |
| | | public void setNotificationBarBackgroundColor(CustomColor color) { |
| | | switch (color) { |
| | | case blue: { |
| | | getWindow().setStatusBarColor(getColor(R.color.text_245EC3)); |
| | | break; |
| | | } |
| | | case white: { |
| | | getWindow().setStatusBarColor(getColor(R.color.text_FFFFFFFF)); |
| | | break; |
| | | } |
| | | } |
| | | getWindow().setStatusBarColor(getColor(color)); |
| | | |
| | | } |
| | | |
| | | public enum CustomColor { |
| | | blue,//蓝色 |
| | | white,//白色 |
| | | |
| | | |
| | | } |
| | | } |
| | |
| | | package com.hdl.photovoltaic.internet; |
| | | |
| | | |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | | import com.hdl.log.utils.PointUtil; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.core.callback.ModbusCallBack; |
| | | import com.hdl.sdk.link.core.connect.HDLModBusConnect; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * 客户端操作逻辑 |
| | |
| | | HDLLinkLocalGateway.getInstance().sendDataToLinkGateway(mac, topic, jObject, sendPath, callBack); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 发送ModBus数据到网关 |
| | | * 下发主题底层默认 |
| | | * |
| | | * @param mac 网关mac |
| | | * @param oidAddresses oid里面Addresses地址 |
| | | * @param functionCode 功能码【3=(读取多个寄存器)),6=(写入单个寄存器),16=(写入多个寄存器)】 |
| | | * @param registerAddress 寄存器地址 |
| | | * @param contentData 内容数据(不含寄存器地址)【注意:功能码=3时,填数值;实际读多少byte就填多少,例如填"20"】 |
| | | */ |
| | | public void SendModBusDataToLinkGateway(String mac, String oidAddresses, int functionCode, int registerAddress, String contentData, ModbusCallBack modbusCallBack) { |
| | | String s = ""; |
| | | switch (functionCode) { |
| | | case 3: { |
| | | s = getReadModbusPassData(oidAddresses, registerAddress, functionCode, contentData); |
| | | } |
| | | break; |
| | | case 6: { |
| | | s = getWriteSingleModbusPassData(oidAddresses, registerAddress, functionCode, contentData); |
| | | } |
| | | break; |
| | | case 16: { |
| | | s = getWriteMultipleModbusPassData(oidAddresses, registerAddress, functionCode, contentData); |
| | | } |
| | | break; |
| | | } |
| | | HDLModBusConnect.getInstance().Send(mac, s.getBytes(), modbusCallBack); |
| | | } |
| | | |
| | | /** |
| | | * 获取读取【modbus协议】拼接透传数据的字符串 |
| | | * 下发主题:/user/${gw_id}/custom/native/${driver}/down; |
| | | * 逆变器回复主题:/user/${gw_id}/custom/native/${driver}/down_reply; |
| | | * Modbus ECU协议:事件ID(2个byte)->协议[固定:0,0](2个byte)->长度(2byte)->标识符[oid的addresses值](4个byte)->功能码(1个byte)->负载数据(N个byte); |
| | | * 长度(2个byte)=标识符(4个byte)+功能码(1个byte)+负载数据(N个byte); |
| | | * 负载数据=寄存器地址(2个byte)+寄存器长度(2个byte)+内容长度(1个byte)+内容数据(N个byte)【注意:单个写入寄存器-->去掉<寄存器长度>和<内容长度>】; |
| | | * 寄存器长度=(内容数据/2); |
| | | * 例子:new byte[]{00,01,00,00,00,0x09,00,00,00,01,03,00,00,00,01}; |
| | | * |
| | | * @param oidAddresses oid里面Addresses的值 |
| | | * @param functionCode 功能码【3=(读取多个寄存器)),6=(写入单个寄存器),16=(写入多个寄存器)】 |
| | | * @param registerAddress 寄存器地址 |
| | | * @param contentData 内容数据(不含寄存器地址) |
| | | */ |
| | | public String getReadModbusPassData(String oidAddresses, int functionCode, int registerAddress, String contentData) { |
| | | String data = ""; |
| | | try { |
| | | String eventID = to2ByteHexString(registerAddress);//事件ID(2byte) |
| | | String agreement = "0000";//协议(2byte) |
| | | String dataByteLength = "";//长度(N byte) |
| | | String oidAddresses_1 = oidAddresses;//标识符(4byte) |
| | | String functionCode_1 = to1ByteHexString(functionCode);//功能码(=1byte) |
| | | String registerAddress_1 = to2ByteHexString(registerAddress);//寄存器地址(2byte) |
| | | String registerLength_1 = to2ByteHexString(Integer.getInteger(contentData) / 2);//寄存器长度(2byte) |
| | | byte[] bytes = (oidAddresses_1 + functionCode_1 + registerAddress_1 + registerLength_1).getBytes(); |
| | | dataByteLength = to1ByteHexString(bytes.length / 2); |
| | | data = eventID + agreement + dataByteLength + oidAddresses_1 + functionCode_1 + registerAddress_1 + registerLength_1; |
| | | return data; |
| | | } catch (Exception ignored) { |
| | | return data; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取写入单个【modbus协议】拼接透传数据的字符串 |
| | | * 下发主题:/user/${gw_id}/custom/native/${driver}/down; |
| | | * 逆变器回复主题:/user/${gw_id}/custom/native/${driver}/down_reply; |
| | | * Modbus ECU协议:事件ID(2个byte)->协议[固定:0,0](2个byte)->长度(2byte)->标识符[oid的addresses值](4个byte)->功能码(1个byte)->负载数据(N个byte); |
| | | * 长度(2个byte)=标识符(4个byte)+功能码(1个byte)+负载数据(N个byte); |
| | | * 负载数据=寄存器地址(2个byte)+寄存器长度(2个byte)+内容长度(1个byte)+内容数据(N个byte)【注意:单个写入寄存器-->去掉<寄存器长度>和<内容长度>】; |
| | | * 寄存器长度=(内容数据/2); |
| | | * 例子:new byte[]{[0, 11, 0, 0, 0, 30, 0, 0, 0, 26, 6, 0, 11, 49, 50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]}; |
| | | * |
| | | * @param oidAddresses oid里面Addresses的值 |
| | | * @param functionCode 功能码【3=(读取多个寄存器)),6=(写入单个寄存器),16=(写入多个寄存器)】 |
| | | * @param registerAddress 寄存器地址 |
| | | * @param contentData 内容数据(不含寄存器地址) |
| | | */ |
| | | public String getWriteSingleModbusPassData(String oidAddresses, int functionCode, int registerAddress, String contentData) { |
| | | String data = ""; |
| | | try { |
| | | String eventID = to2ByteHexString(registerAddress);//事件ID(2byte) |
| | | String agreement = "0000";//协议(2byte) |
| | | String dataByteLength = "";//长度(N byte) |
| | | String oidAddresses_1 = oidAddresses;//标识符(4byte) |
| | | String functionCode_1 = to1ByteHexString(functionCode);//功能码(=1byte) |
| | | String registerAddress_1 = to2ByteHexString(registerAddress);//寄存器地址(2byte) |
| | | String contentData_1 = contentData;//内容数据(N byte) |
| | | byte[] bytes = (oidAddresses_1 + functionCode_1 + registerAddress_1 + contentData_1).getBytes(); |
| | | dataByteLength = to1ByteHexString(bytes.length / 2); |
| | | data = eventID + agreement + dataByteLength + oidAddresses_1 + functionCode_1 + registerAddress_1 + contentData_1; |
| | | return data; |
| | | } catch (Exception ignored) { |
| | | return data; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取写入多个【modbus协议】拼接透传数据的字符串 |
| | | * 下发主题:/user/${gw_id}/custom/native/${driver}/down; |
| | | * 逆变器回复主题:/user/${gw_id}/custom/native/${driver}/down_reply; |
| | | * Modbus ECU协议:事件ID(2个byte)->协议[固定:0,0](2个byte)->长度(2byte)->标识符[oid的addresses值](4个byte)->功能码(1个byte)->负载数据(N个byte); |
| | | * 长度(2个byte)=标识符(4个byte)+功能码(1个byte)+负载数据(N个byte); |
| | | * 负载数据=寄存器地址(2个byte)+寄存器长度(2个byte)+内容长度(1个byte)+内容数据(N个byte)【注意:单个写入寄存器-->去掉<寄存器长度>和<内容长度>】; |
| | | * 寄存器长度=(内容数据/2); |
| | | * 例子:new byte[]{[0, 11, 0, 0, 0, 30, 0, 0, 0, 26, 16, 0, 11, 0, 10, 20, 49, 50, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]}; |
| | | * |
| | | * @param oidAddresses oid里面Addresses的值 |
| | | * @param functionCode 功能码【3=(读取多个寄存器)),6=(写入单个寄存器),16=(写入多个寄存器)】 |
| | | * @param registerAddress 寄存器地址 |
| | | * @param contentData 内容数据(不含寄存器地址) |
| | | */ |
| | | public String getWriteMultipleModbusPassData(String oidAddresses, int functionCode, int registerAddress, String contentData) { |
| | | |
| | | String data = ""; |
| | | try { |
| | | String eventID = to2ByteHexString(registerAddress);//事件ID(2byte) |
| | | String agreement = "0000";//协议(2byte) |
| | | String dataByteLength = "";//长度(N byte) |
| | | String oidAddresses_1 = oidAddresses;//标识符(4byte) |
| | | String functionCode_1 = to1ByteHexString(functionCode);//功能码(=1byte) |
| | | String registerAddress_1 = to2ByteHexString(registerAddress);//寄存器地址(2byte) |
| | | String registerLength_1 = to2ByteHexString(contentData.length() / 2);//寄存器长度(2byte) |
| | | String contentLength_1 = to1ByteHexString(contentData.length());//内容长度(1byte) |
| | | String contentData_1 = contentData;//内容数据(N byte) |
| | | byte[] bytes = (oidAddresses_1 + functionCode_1 + registerAddress_1 + registerLength_1 + contentLength_1 + contentData_1).getBytes(); |
| | | dataByteLength = to1ByteHexString(bytes.length / 2); |
| | | data = eventID + agreement + dataByteLength + oidAddresses_1 + functionCode_1 + registerAddress_1 + registerLength_1 + contentLength_1 + contentData_1; |
| | | return data; |
| | | } catch (Exception ignored) { |
| | | return data; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取十六进制字符串(不够两位前面补0) |
| | | * |
| | | * @param value 寄存器地址(十进制) |
| | | * @return (2byte)十六进制字符串 |
| | | */ |
| | | public String to2ByteHexString(int value) { |
| | | String high = ""; |
| | | String low = ""; |
| | | if (value > 255) { |
| | | high = to1ByteHexString(value / 256); |
| | | |
| | | low = to1ByteHexString(value % 256); |
| | | } else { |
| | | high = "00"; |
| | | low = to1ByteHexString(value); |
| | | } |
| | | return high + low; |
| | | } |
| | | |
| | | /** |
| | | * 获取十六进制字符串(不够两位前面补0) |
| | | * |
| | | * @param value 十进制 |
| | | * @return (1byte)十六进制字符串 |
| | | */ |
| | | public String to1ByteHexString(int value) { |
| | | try { |
| | | String hexString = Integer.toHexString(value); |
| | | if (hexString.length() == 1) { |
| | | return "0" + hexString; |
| | | } |
| | | return hexString; |
| | | } catch (Exception e) { |
| | | return "00"; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取十六进制字符串(不够两位前面补0) |
| | | * |
| | | * @param dataBytes 数组 |
| | | * @return -(n byte)十六进制字符串 |
| | | */ |
| | | public String toNByteHexString(byte[] dataBytes) { |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (byte dataByte : dataBytes) { |
| | | String dataB = Integer.toHexString(dataByte & 0xFF); |
| | | if (dataB.length() == 1) { |
| | | dataB = "0" + dataB; |
| | | } |
| | | stringBuilder.append(dataB); |
| | | } |
| | | return stringBuilder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 获取十六进制字符串(不够两位前面补0) |
| | | * |
| | | * @param value 寄存器地址(十进制) |
| | | * @return (2byte)十六进制字符串 |
| | | */ |
| | | private String getByteHexString(int value) { |
| | | String high = ""; |
| | | String low = ""; |
| | | if (value > 255) { |
| | | high = to1ByteHexString(value / 256); |
| | | |
| | | low = to1ByteHexString(value % 256); |
| | | } else { |
| | | high = "00"; |
| | | low = to1ByteHexString(value); |
| | | } |
| | | return high + low; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | 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"; |
| | | //设备基本信息列表(oid)获取 |
| | | public static final String POST_DEVICE_OID_LIST_GET = "/home-wisdom/program/device/oid/list"; |
| | | //设备固件列表获取 |
| | | public static final String POST_OTA_GET_DeviceFirmwares = "/home-wisdom/program/device/ota/getDeviceFirmwares"; |
| | | //设备固件云端的驱动分页列表获取 |
| | | public static final String POST_OTA_GET_CloudDeviceFirmwares = "/smart-footstone/firmware/firmwareVersion/getLastOne"; |
| | | //设备固件升级OTA命令 |
| | | public static final String POST_OTA_DeviceFirmwareUpgrade = "/home-wisdom/program/device/ota/deviceFirmwareUpgrade"; |
| | | //设备获取固件升级包下载地址 |
| | | public static final String POST_OTA_GET_LinkDeviceFirmwareDownloadUrl = "/smart-footstone/mgmt/device/ota/getLinkDeviceFirmwareDownloadUrl"; |
| | | //当前网关驱动列表获取 |
| | | public static final String POST_OTA_GET_GatewayDrivers = "/home-wisdom/program/device/ota/getGatewayDrivers"; |
| | | //网关云端的驱动分页列表获取 |
| | | public static final String POST_OTA_GET_CloudGatewayDrivers = "/smart-footstone/driver/buspro/download"; |
| | | //网关驱动升级OTA命令下发 |
| | | public static final String POST_OTA_GatewayDriverUpgrade = "/home-wisdom/program/device/ota/gatewayDriverUpgrade"; |
| | | //LINK设备获取驱动升级包下载地址 |
| | | public static final String POST_OTA_GET_LinkDeviceDriverDownloadUrl = "/smart-footstone/mgmt/device/ota/getLinkDeviceDriverDownloadUrl"; |
| | | |
| | | //endregion |
| | | //endregion |
| | | |
| | |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlhttp.HxHttp; |
| | | import com.hdl.linkpm.sdk.core.api.HDLCloudHomeApi; |
| | | import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack; |
| | | import com.hdl.linkpm.sdk.core.callback.IResponseCallBack; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.core.response.HDLResponse; |
| | | import com.hdl.linkpm.sdk.device.bean.DeviceOidInfoBean; |
| | | import com.hdl.linkpm.sdk.device.bean.GatewayCloudBean; |
| | | import com.hdl.linkpm.sdk.ota.HDLLinkPMOta; |
| | | 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.linkpm.sdk.project.HDLLinkPMProject; |
| | | import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | import com.hdl.sdk.link.gateway.type.GatewayMasterType; |
| | | |
| | | import org.json.JSONException; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import io.dcloud.feature.unimp.DCUniMPJSCallback; |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 逆变器上传数据到云端(包括:sid,oid) |
| | |
| | | * @param deviceRemoteInfo 设备远程通讯信息 |
| | | * @param cloudInverterDeviceBean 逆变器 |
| | | */ |
| | | private static void refreshGatewayCacheData(boolean isLocal, CloudInverterDeviceBean cloudInverterDeviceBean, DeviceRemoteInfo deviceRemoteInfo) { |
| | | private void refreshGatewayCacheData(boolean isLocal, CloudInverterDeviceBean cloudInverterDeviceBean, DeviceRemoteInfo deviceRemoteInfo) { |
| | | //本地查找逆变器 |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(cloudInverterDeviceBean.getOsn()); |
| | | if (gatewayBean == null) { |
| | |
| | | private static volatile HdlFileLogic sHdlFileLogic; |
| | | |
| | | /** |
| | | * 表示1m数据 |
| | | * 表示1m大小数据 |
| | | */ |
| | | private final int m = 1; |
| | | |
| | |
| | | * 获取手机内部存储文件路径 |
| | | */ |
| | | public String getAPPInternalStoreFilesPath() { |
| | | return HDLApp.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getPath(); |
| | | return Objects.requireNonNull(HDLApp.getInstance().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS)).getPath(); |
| | | } |
| | | |
| | | /** |
| | | * 获取存放【用户】文件夹根路径 |
| | | * 获取存放【用户文件夹】根路径 |
| | | */ |
| | | public String getCurrentUserRootPath() { |
| | | return getAPPInternalStoreFilesPath() + "/" + getUserId(); |
| | | } |
| | | |
| | | /** |
| | | * 获取存放【住宅】文件夹根路径 |
| | | * 获取存放【住宅文件夹】根路径 |
| | | */ |
| | | public String getCurrentHomeRootPath() { |
| | | return getCurrentUserRootPath() + "/" + "home_" + getHomeId(); |
| | | } |
| | | |
| | | /** |
| | | * 获取【日志】文件全路径 |
| | | * 获取【日志文件】全路径 |
| | | */ |
| | | public String getLogFilePath() { |
| | | return getCurrentHomeRootPath() + "/Log.txt"; |
| | | } |
| | | |
| | | /** |
| | | * 获取【用户】文件全路径 |
| | | * 获取【用户文件】全路径 |
| | | */ |
| | | public String getUserFilePath() { |
| | | return getAPPInternalStoreFilesPath() + "/UserConfigManage.txt"; |
New file |
| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | import android.text.TextUtils; |
| | | |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | 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.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.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | | import com.hdl.photovoltaic.internet.api.HttpApi; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * ota升级逻辑 |
| | | */ |
| | | public class HdlOtaLogic { |
| | | private static volatile HdlOtaLogic sHdlOtaLogic; |
| | | |
| | | /** |
| | | * 获取当前对象 |
| | | * |
| | | * @return HdlDeviceLogic |
| | | */ |
| | | public static synchronized HdlOtaLogic getInstance() { |
| | | if (sHdlOtaLogic == null) { |
| | | synchronized (HdlOtaLogic.class) { |
| | | if (sHdlOtaLogic == null) { |
| | | sHdlOtaLogic = new HdlOtaLogic(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | return sHdlOtaLogic; |
| | | } |
| | | |
| | | //region -----固件升级--------- |
| | | |
| | | /** |
| | | * 向云端获取逆变器oid列表 |
| | | * 前提条件:要上传逆变器oid列表给云端 |
| | | * |
| | | * @param callBack - |
| | | */ |
| | | public void getCloudOidList(CloudCallBeak<List<DeviceOidInfoBean>> callBack) { |
| | | String requestUrl = HttpApi.POST_DEVICE_OID_LIST_GET; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<List<DeviceOidInfoBean>>() { |
| | | }.getType(); |
| | | List<DeviceOidInfoBean> list = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【当前设备固件】列表 |
| | | * 前提条件:设备自动上报oid信息给云端 |
| | | * |
| | | * @param deviceOidId oid云端id |
| | | * @param callBack - |
| | | */ |
| | | public void getCurrentDeviceFirmwares(String deviceOidId, CloudCallBeak<List<DeviceFirmwareBean>> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_DeviceFirmwares; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("deviceOidId", deviceOidId); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<List<DeviceFirmwareBean>>() { |
| | | }.getType(); |
| | | List<DeviceFirmwareBean> list = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 向云端获取【设备新固件】列表 |
| | | * 前提条件:要通过平台软件上传新固件 |
| | | * |
| | | * @param hardwareModel 硬件型号 |
| | | * @param osImageId 系统镜像id |
| | | * @param callBack - |
| | | */ |
| | | public void getNewDeviceFirmwares(String hardwareModel, String osImageId, CloudCallBeak<List<CloudDeviceFirmwaresBean>> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_CloudDeviceFirmwares; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("hardwareModel", hardwareModel); |
| | | json.addProperty("osImageId", osImageId); |
| | | json.addProperty("protocolType", "ZIGBEE");//协议类型,可用值:BUSPRO,KNX,ZIGBEE,OTHER |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<List<CloudDeviceFirmwaresBean>>() { |
| | | }.getType(); |
| | | List<CloudDeviceFirmwaresBean> list = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 向云端发起【设备固件】升级OTA指令 |
| | | * |
| | | * @param deviceOidId 设备id |
| | | * @param firmwareVersionId 固件版本id |
| | | * @param callBack- |
| | | */ |
| | | public void upgradeDeviceFirmware(String deviceOidId, String firmwareVersionId, CloudCallBeak<Boolean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_DeviceFirmwareUpgrade; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("deviceOidId", deviceOidId); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(true); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备固件】升级包下载地址 |
| | | * |
| | | * @param firmwareVersionId 固件版本Id |
| | | */ |
| | | public void getDeviceFirmwareDownloadUrl(String firmwareVersionId, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new DownloadUrlBean()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<DownloadUrlBean>() { |
| | | }.getType(); |
| | | DownloadUrlBean downloadUrlBean = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(downloadUrlBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | //endregion |
| | | |
| | | //region -----驱动升级--------- |
| | | |
| | | /** |
| | | * 向云端获取【当前设备驱动】列表 |
| | | * 前提条件:设备自动上报oid信息给云端 |
| | | * |
| | | * @param oid 网关设备oid |
| | | * @param callBack - |
| | | */ |
| | | public void getCurrentGatewayDrivers(String oid, CloudCallBeak<List<GatewayDriverBean>> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_GatewayDrivers; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("oid", oid); |
| | | |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<List<GatewayDriverBean>>() { |
| | | }.getType(); |
| | | List<GatewayDriverBean> list = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备新驱动】列表 |
| | | * 前提条件:要通过平台软件上传新驱动 |
| | | * |
| | | * @param driveCode 驱动编号或驱动名称 |
| | | * @param osImageId 驱动类型id |
| | | * @param callBack - |
| | | */ |
| | | public void getNewGatewayDrivers(String driveCode, String osImageId, CloudCallBeak<CloudGatewayDriversBean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_CloudGatewayDrivers; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("driveCode", driveCode); |
| | | json.addProperty("osImageId", osImageId); |
| | | |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new CloudGatewayDriversBean()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<CloudGatewayDriversBean>() { |
| | | }.getType(); |
| | | CloudGatewayDriversBean cloudGatewayDriversBean = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(cloudGatewayDriversBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 云端发起【设备驱动】升级OTA指令 |
| | | * |
| | | * @param oid 网关设备oid |
| | | * @param driverVersionId 驱动版本id |
| | | * @param callBack - |
| | | */ |
| | | public void upgradeGatewayDriver(String oid, String driverVersionId, CloudCallBeak<Boolean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GatewayDriverUpgrade; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("oid", oid); |
| | | json.addProperty("driverVersionId", driverVersionId); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(true); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备驱动】升级包下载地址 |
| | | * |
| | | * @param driverVersionId 驱动版本Id |
| | | */ |
| | | public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<DownloadUrlBean> callBack) { |
| | | String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("driverVersionId", driverVersionId); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(new DownloadUrlBean()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<DownloadUrlBean>() { |
| | | }.getType(); |
| | | DownloadUrlBean downloadUrlBean = gson.fromJson(json, typeOfT); |
| | | if (callBack != null) { |
| | | callBack.onSuccess(downloadUrlBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | //endregion |
| | | } |
| | |
| | | |
| | | import com.google.gson.Gson; |
| | | 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.linkpm.sdk.ota.bean.CloudGatewayDriversBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.DeviceFirmwareBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean; |
| | | import com.hdl.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.bean.ModBusBean; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | |
| | | break; |
| | | |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL.equals(event)) { |
| | | //OTA升级模块 |
| | | switch (type) { |
| | | //向云端获取oid列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_CLOUD_OID_LIST: { |
| | | this.uniGetCloudOidList(data, callback); |
| | | } |
| | | break; |
| | | //当前设备固件列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_LIST: { |
| | | this.uniGetCurrentDeviceFirmwares(data, callback); |
| | | } |
| | | break; |
| | | //设备新固件列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST: { |
| | | this.uniGetNewDeviceFirmwares(data, callback); |
| | | } |
| | | break; |
| | | //设备固件升级 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE: { |
| | | this.uniUpgradeDeviceFirmware(data, callback); |
| | | } |
| | | break; |
| | | //当前设备驱动列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_LIST: { |
| | | this.uniGetCurrentGatewayDrivers(data, callback); |
| | | } |
| | | break; |
| | | //设备新驱动列表 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_NEW: { |
| | | this.uniGetNewGatewayDrivers(data, callback); |
| | | } |
| | | break; |
| | | //设备驱动升级 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE: { |
| | | this.uniUpgradeGatewayDriver(data, callback); |
| | | } |
| | | break; |
| | | |
| | | } |
| | | } |
| | | HdlLogLogic.print("uni===原生接收uni发来的数据===" + event + "\r\n" + data, false); |
| | | } catch (Exception e) { |
| | |
| | | * @param jsonObject 附件数据(没有数据填null) |
| | | */ |
| | | public void openUniMP(String path, JSONObject jsonObject) { |
| | | |
| | | JSONObject json = this.createdJsonDate(jsonObject, true); |
| | | HdlLogLogic.print("uni===组装uni发送数据格式===" + json, false); |
| | | JSONObject json = this.createdJSONObject(jsonObject, true); |
| | | HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this); |
| | | HdlLogLogic.print("uni===组装uni发送数据格式===" + json, false); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | //endregion |
| | | |
| | | //region ******uni逻辑方法****** |
| | | //region ******uni接口方法****** |
| | | |
| | | /** |
| | | * 向云端获取逆变器oid列表 |
| | | * 前提条件:要上传逆变器oid列表给云端 |
| | | * |
| | | * @param callback - |
| | | */ |
| | | private void uniGetCloudOidList(Object data, DCUniMPJSCallback callback) { |
| | | HdlOtaLogic.getInstance().getCloudOidList(new CloudCallBeak<List<DeviceOidInfoBean>>() { |
| | | @Override |
| | | public void onSuccess(List<DeviceOidInfoBean> obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【当前设备固件】列表 |
| | | * 前提条件:设备自动上报oid信息给云端 |
| | | */ |
| | | private void uniGetCurrentDeviceFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data)); |
| | | HdlOtaLogic.getInstance().getCurrentDeviceFirmwares(deviceOidId, new CloudCallBeak<List<DeviceFirmwareBean>>() { |
| | | @Override |
| | | public void onSuccess(List<DeviceFirmwareBean> obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备新固件】列表 |
| | | * 前提条件:要通过平台软件上传新固件 |
| | | */ |
| | | private void uniGetNewDeviceFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//系统镜像id |
| | | HdlOtaLogic.getInstance().getNewDeviceFirmwares(hardwareModel, osImageId, new CloudCallBeak<List<CloudDeviceFirmwaresBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudDeviceFirmwaresBean> 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 deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//设备id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, 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); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【当前设备驱动】列表 |
| | | * 前提条件:设备自动上报oid信息给云端 |
| | | */ |
| | | private void uniGetCurrentGatewayDrivers(Object data, DCUniMPJSCallback callback) { |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data)); |
| | | HdlOtaLogic.getInstance().getCurrentGatewayDrivers(deviceOid, new CloudCallBeak<List<GatewayDriverBean>>() { |
| | | @Override |
| | | public void onSuccess(List<GatewayDriverBean> obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端获取【设备新驱动】列表 |
| | | * 前提条件:要通过平台软件上传新驱动 |
| | | */ |
| | | private void uniGetNewGatewayDrivers(Object data, DCUniMPJSCallback callback) { |
| | | String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | HdlOtaLogic.getInstance().getNewGatewayDrivers(driveCode, osImageId, new CloudCallBeak<CloudGatewayDriversBean>() { |
| | | @Override |
| | | public void onSuccess(CloudGatewayDriversBean obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备驱动】升级OTA指令 |
| | | */ |
| | | private void uniUpgradeGatewayDriver(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>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(obj, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 逆变器清空住宅id |
| | |
| | | uniCallbackData(null, -100, "本地找不到网关", callback); |
| | | return; |
| | | } |
| | | HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac, |
| | | gatewayBean.getGatewayType(), |
| | | gatewayBean.getSid(), |
| | | gatewayBean.getOid(), |
| | | gatewayBean.getDevice_name(), |
| | | new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(null, callback); |
| | | } |
| | | HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac, gatewayBean.getGatewayType(), gatewayBean.getSid(), gatewayBean.getOid(), gatewayBean.getDevice_name(), new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(null, callback); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 发送modbus协议数据 |
| | | * 透传协议 |
| | | * 下发主题:/user/${gw_id}/custom/native/${driver}/down; |
| | | * 逆变器回复主题:/user/${gw_id}/custom/native/${driver}/down_reply; |
| | | * Modbus ECU协议:事件ID(2个byte)->协议[固定:0,0](2个byte)->长度(2byte)->标识符[oid的addresses值](4个byte)->功能码(1个byte)->负载数据(N个byte); |
| | | * 长度(2个byte)=标识符(4个byte)+功能码(1个byte)+负载数据(N个byte); |
| | | * 负载数据=寄存器地址(2个byte)+寄存器长度(2个byte)+内容长度(1个byte)+内容数据(N个byte)【注意:单个写入寄存器-->去掉<寄存器长度>和<内容长度>】; |
| | | * 寄存器长度=(内容数据/2); |
| | | * 例子:new byte[]{00,01,00,00,00,0x09,00,00,00,01,03,00,00,00,01}; |
| | | * |
| | | * @param data modbus数据 |
| | | * @param callback 回调 |
| | | */ |
| | | void sendModBus(Object data, DCUniMPJSCallback callback) { |
| | | private void sendModBus(Object data, DCUniMPJSCallback callback) { |
| | | String tempData = getKeyValue("data", data); |
| | | if (TextUtils.isEmpty(tempData)) { |
| | | HdlLogLogic.print("data内容为空", false); |
| | |
| | | /** |
| | | * 组装uni发送数据格式 |
| | | * |
| | | * @param data -附件数据(没有数据填null) |
| | | * @param data 附加数据(没有数据填null) |
| | | * @param isTokenAndRefreshToken (true=底层默认添加token和refreshToken;false=不加) |
| | | * @return JSONObject |
| | | * @return JSONObject uni方法名里面参数需要的JSONObject对象 |
| | | */ |
| | | private JSONObject createdJsonDate(JSONObject data, boolean isTokenAndRefreshToken) { |
| | | private JSONObject createdJSONObject(JSONObject data, boolean isTokenAndRefreshToken) { |
| | | HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean(); |
| | | try { |
| | | if (data == null) { |
| | |
| | | } catch (Exception e) { |
| | | return ""; |
| | | } |
| | | |
| | | } |
| | | //endregion |
| | | |
| | |
| | | public final static String UNI_EVENT_REPLY_DEVICE_UPLOADING_DATA = "uploading_data";//设备上传数据 |
| | | public final static String UNI_EVENT_REPLY_DEVICE_MODBUS_SEND = "modbus_send";//modbus协议 |
| | | |
| | | /*********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_NEW_LIST = "firmwares_new_list";//设备新固件列表 |
| | | 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_UPGRADE = "driver_upgrade";//设备驱动升级 |
| | | |
| | | |
| | | /*********Wifi模块*********/ //卫锦定义 |
| | | public final static String UNI_EVENT_REPLY_WIFI_MODEL = "uni_wifi_model";//wifi模块(大类) |
| | | public final static String UNI_EVENT_REPLY_WIFI_LIST = "list";//获取wifi列表 |
| | |
| | | package com.hdl.photovoltaic.utils; |
| | | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | | import android.content.res.Resources; |
| | | import android.os.Build; |
| | | import android.os.LocaleList; |
| | | import android.text.TextUtils; |
| | | import android.util.DisplayMetrics; |
| | | |
| | | |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * Created by hxb on 2022/6/7. |
| | | * desc : 多语言适配方案,适配各种版本,核心未替换上下文Context中的Local |
| | | * 多语言适配 |
| | | */ |
| | | public class LocalManageUtil { |
| | | |
| | | // private static final String TAG = "LanguageUtil"; |
| | | // |
| | | // /** |
| | | // * 默认支持的语言,英语、法语、阿拉伯语 |
| | | // */ |
| | | // private static HashMap<String, Locale> supportLanguage = new HashMap<String, Locale>(4) {{ |
| | | // put(Language.ENGLISH, Locale.ENGLISH); |
| | | // }}; |
| | | // |
| | | // /** |
| | | // * 应用多语言切换,重写BaseActivity中的attachBaseContext即可 |
| | | // * 采用本地SP存储的语言 |
| | | // * |
| | | // * @param context 上下文 |
| | | // * @return context |
| | | // */ |
| | | // public static Context attachBaseContext(Context context) { |
| | | // String language = LanguageSp.getLanguage(context); |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { |
| | | // return createConfigurationContext(context, language); |
| | | // } else { |
| | | // return updateConfiguration(context, language); |
| | | // } |
| | | // } |
| | | // |
| | | // /** |
| | | // * 应用多语言切换,重写BaseActivity中的attachBaseContext即可 |
| | | // * |
| | | // * @param context 上下文 |
| | | // * @param language 语言 |
| | | // * @return context |
| | | // */ |
| | | // public static Context attachBaseContext(Context context, String language) { |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { |
| | | // return createConfigurationContext(context, language); |
| | | // } else { |
| | | // return updateConfiguration(context, language); |
| | | // } |
| | | // } |
| | | // |
| | | // /** |
| | | // * 获取Local,根据language |
| | | // * |
| | | // * @param language 语言 |
| | | // * @return Locale |
| | | // */ |
| | | // private static Locale getLanguageLocale(String language) { |
| | | // if (supportLanguage.containsKey(language)) { |
| | | // return supportLanguage.get(language); |
| | | // } else { |
| | | // Locale systemLocal = getSystemLocal(); |
| | | // for (String languageKey : supportLanguage.keySet()) { |
| | | // if (TextUtils.equals(supportLanguage.get(languageKey).getLanguage(), systemLocal.getLanguage())) { |
| | | // return systemLocal; |
| | | // } |
| | | // } |
| | | // } |
| | | // return Locale.ENGLISH; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 获取当前的Local,默认英语 |
| | | // * |
| | | // * @param context context |
| | | // * @return Locale |
| | | // */ |
| | | // public static Locale getCurrentLocale(Context context) { |
| | | // String language = LanguageSp.getLanguage(context); |
| | | // if (supportLanguage.containsKey(language)) { |
| | | // return supportLanguage.get(language); |
| | | // } else { |
| | | // Locale systemLocal = getSystemLocal(); |
| | | // for (String languageKey : supportLanguage.keySet()) { |
| | | // if (TextUtils.equals(supportLanguage.get(languageKey).getLanguage(), systemLocal.getLanguage())) { |
| | | // return systemLocal; |
| | | // } |
| | | // } |
| | | // } |
| | | // return Locale.ENGLISH; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 获取系统的Local |
| | | // * |
| | | // * @return Locale |
| | | // */ |
| | | // private static Locale getSystemLocal() { |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | // return Resources.getSystem().getConfiguration().getLocales().get(0); |
| | | // } else { |
| | | // return Locale.getDefault(); |
| | | // } |
| | | // } |
| | | // |
| | | // /** |
| | | // * Android 7.1 以下通过 updateConfiguration |
| | | // * |
| | | // * @param context context |
| | | // * @param language 语言 |
| | | // * @return Context |
| | | // */ |
| | | // private static Context updateConfiguration(Context context, String language) { |
| | | // Resources resources = context.getResources(); |
| | | // Configuration configuration = resources.getConfiguration(); |
| | | // Locale locale = getLanguageLocale(language); |
| | | // Log.e(TAG, "updateLocalApiLow==== " + locale.getLanguage()); |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | // // apply locale |
| | | // configuration.setLocales(new LocaleList(locale)); |
| | | // } else { |
| | | // // updateConfiguration |
| | | // configuration.locale = locale; |
| | | // DisplayMetrics dm = resources.getDisplayMetrics(); |
| | | // resources.updateConfiguration(configuration, dm); |
| | | // } |
| | | // return context; |
| | | // } |
| | | // |
| | | // /** |
| | | // * Android 7.1以上通过createConfigurationContext |
| | | // * N增加了通过config.setLocales去修改多语言 |
| | | // * |
| | | // * @param context 上下文 |
| | | // * @param language 语言 |
| | | // * @return context |
| | | // */ |
| | | // @RequiresApi(api = Build.VERSION_CODES.N_MR1) |
| | | // private static Context createConfigurationContext(Context context, String language) { |
| | | // Resources resources = context.getResources(); |
| | | // Configuration configuration = resources.getConfiguration(); |
| | | // Locale locale = getLanguageLocale(language); |
| | | // Log.d(TAG, "current Language locale = " + locale); |
| | | // LocaleList localeList = new LocaleList(locale); |
| | | // configuration.setLocales(localeList); |
| | | // return context.createConfigurationContext(configuration); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 切换语言 |
| | | // * |
| | | // * @param language 语言 |
| | | // * @param activity 当前界面 |
| | | // * @param cls 跳转的界面 |
| | | // */ |
| | | // public static void switchLanguage(String language, Activity activity, Class<?> cls) { |
| | | // LanguageSp.setLanguage(activity, language); |
| | | // Intent intent = new Intent(activity, cls); |
| | | // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| | | // activity.startActivity(intent); |
| | | // activity.finish(); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 切换语言,携带传递数据 |
| | | // * |
| | | // * @param language 语言 |
| | | // * @param activity 当前界面 |
| | | // * @param cls 跳转的界面 |
| | | // */ |
| | | // public static void switchLanguage(String language, Activity activity, Class<?> cls, Bundle bundle) { |
| | | // LanguageSp.setLanguage(activity, language); |
| | | // Intent intent = new Intent(activity, cls); |
| | | // if (bundle != null) { |
| | | // intent.putExtras(bundle); |
| | | // } |
| | | // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| | | // activity.startActivity(intent); |
| | | // activity.finish(); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 获取新语言的 Context,修复了androidx.appCompact 1.2.0的问题 |
| | | // * |
| | | // * @param newBase newBase |
| | | // * @return Context |
| | | // */ |
| | | // public static Context getNewLocalContext(Context newBase) { |
| | | // try { |
| | | // // 多语言适配 |
| | | // Context context = LanguageUtil.attachBaseContext(newBase); |
| | | // // 兼容appcompat 1.2.0后切换语言失效问题 |
| | | // final Configuration configuration = context.getResources().getConfiguration(); |
| | | // return new ContextThemeWrapper(context, R.style.Theme_AppCompat_Empty) { |
| | | // @Override |
| | | // public void applyOverrideConfiguration(Configuration overrideConfiguration) { |
| | | // if (overrideConfiguration != null) { |
| | | // overrideConfiguration.setTo(configuration); |
| | | // } |
| | | // super.applyOverrideConfiguration(overrideConfiguration); |
| | | // } |
| | | // }; |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // return newBase; |
| | | // } |
| | | // |
| | | // /** |
| | | // * 更新Application的Resource local,应用不重启的情况才调用,因为部分会用到application中的context |
| | | // * 切记不能走新api createConfigurationContext,亲测 |
| | | // * |
| | | // * @param context context |
| | | // * @param newLanguage newLanguage |
| | | // */ |
| | | // public static void updateApplicationLocale(Context context, String newLanguage) { |
| | | // Resources resources = context.getResources(); |
| | | // Configuration configuration = resources.getConfiguration(); |
| | | // Locale locale = getLanguageLocale(newLanguage); |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | // // apply locale |
| | | // configuration.setLocales(new LocaleList(locale)); |
| | | // } else { |
| | | // configuration.setLocale(locale); |
| | | // } |
| | | // DisplayMetrics dm = resources.getDisplayMetrics(); |
| | | // resources.updateConfiguration(configuration, dm); |
| | | // } |
| | | |
| | | private static Locale locale; |
| | | |
| | | // private static Locale mLocale; |
| | | |
| | | /** |
| | | * 获取系统的locale |
| | |
| | | } |
| | | return locale; |
| | | } |
| | | // |
| | | // public static Context setLocal(Context context) { |
| | | // return updateResources(context, mLocale); |
| | | // } |
| | | // |
| | | // public static Context updateResources(Context context, Locale locale) { |
| | | // if (locale == null) { |
| | | // return context; |
| | | // } |
| | | // LocalManageUtil.mLocale = locale; |
| | | // Locale.setDefault(locale); |
| | | // |
| | | // Resources res = context.getResources(); |
| | | // Configuration config = new Configuration(res.getConfiguration()); |
| | | // config.setLocale(locale); |
| | | // context = context.createConfigurationContext(config); |
| | | // return context; |
| | | // } |
| | | |
| | | public static Context setLocal(Context context) { |
| | | return updateResources(context, locale); |
| | | |
| | | /** |
| | | * 应用内切换语言 |
| | | * |
| | | * @param language language (zh:汉语;en:英语) |
| | | * @param context 上下文 |
| | | */ |
| | | public static void changeAppLanguage(String language, Context context) { |
| | | Locale locale = getLocale(language); |
| | | updateResources(locale, context); |
| | | } |
| | | |
| | | public static Context updateResources(Context context, Locale locale) { |
| | | if (locale == null) { |
| | | return context; |
| | | } |
| | | LocalManageUtil.locale = locale; |
| | | Locale.setDefault(locale); |
| | | |
| | | Resources res = context.getResources(); |
| | | Configuration config = new Configuration(res.getConfiguration()); |
| | | if (Build.VERSION.SDK_INT >= 17) { |
| | | config.setLocale(locale); |
| | | context = context.createConfigurationContext(config); |
| | | /** |
| | | * 获取系统当前语言 |
| | | * |
| | | * @return _ |
| | | */ |
| | | public static Locale getDefaultLocale() { |
| | | return Resources.getSystem().getConfiguration().locale; |
| | | } |
| | | |
| | | /** |
| | | * 获取Locale |
| | | * |
| | | * @param language (zh:汉语;en:英语) |
| | | * @return Locale |
| | | */ |
| | | public static Locale getLocale(String language) { |
| | | try { |
| | | if (TextUtils.isEmpty(language)) { |
| | | return getDefaultLocale(); |
| | | } |
| | | return new Locale(language); |
| | | } catch (Exception e) { |
| | | return getDefaultLocale(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 更新资源数据 |
| | | * |
| | | * @param locale 语言实体类 |
| | | * @param context 上下文 |
| | | * @return - |
| | | */ |
| | | private static void updateResources(Locale locale, Context context) { |
| | | |
| | | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
| | | //7.0以下系统 |
| | | DisplayMetrics metrics = context.getResources().getDisplayMetrics(); |
| | | Configuration configuration = context.getResources().getConfiguration(); |
| | | configuration.setLocale(locale); |
| | | context.getResources().updateConfiguration(configuration, metrics); |
| | | // Locale.setDefault(locale); |
| | | } else { |
| | | config.locale = locale; |
| | | res.updateConfiguration(config, res.getDisplayMetrics()); |
| | | //7.0及以上系统 |
| | | Configuration configuration = context.getResources().getConfiguration(); |
| | | configuration.setLocale(locale); |
| | | configuration.setLocales(new LocaleList(locale)); |
| | | context.createConfigurationContext(configuration); |
| | | } |
| | | return context; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 设置当前APP的语言模式 |
| | | * |
| | | * @param context 上下文 |
| | | */ |
| | | private static void setCurrLanguageMode(Context context) { |
| | | String language = SharedPreUtils.getSharedPreferencesKey("languege", context); |
| | | Locale local = getLocale(language); |
| | | Resources res = context.getResources(); |
| | | DisplayMetrics dm = res.getDisplayMetrics(); |
| | | Configuration conf = res.getConfiguration(); |
| | | conf.locale = local; |
| | | res.updateConfiguration(conf, dm); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | <string name="home_login_input_phone">请输入手机号</string> |
| | | <string name="home_login_email_address">邮箱号</string> |
| | | <string name="home_login_input_psw">请输入密码</string> |
| | | <string name="home_login_register">注册</string> |
| | | <string name="home_login_register">register</string> |
| | | <string name="home_login_forget_password">忘记密码</string> |
| | | <string name="home_login_change_password">修改密码</string> |
| | | <string name="home_login_logoin">登录</string> |
| | | <string name="home_login_logoin">log in</string> |
| | | <string name="home_login_be_logging_in">登录中…</string> |
| | | <string name="home_login_power_station">体验电站</string> |
| | | <string name="home_login_consent_service_agreement">同意《服务协议》和《用户信息保护规定》</string> |
| | |
| | | |
| | | <!--我的电站--> |
| | | <string name="power_station">电站</string> |
| | | <string name="power_station_me">我的</string> |
| | | <string name="power_station_me">my</string> |
| | | <string name="my_power_station">我的电站</string> |
| | | <string name="power_station_generated_power">发电功率:</string> |
| | | <string name="power_station_Power_generation_today">今日发电</string> |