| | |
| | | import com.hdl.sdk.link.common.utils.ThreadToolUtils;
|
| | | import com.hdl.sdk.link.core.bean.LinkRequest;
|
| | | import com.hdl.sdk.link.core.bean.LinkResponse;
|
| | | import com.hdl.sdk.link.core.bean.ModbusResponse;
|
| | | import com.hdl.sdk.link.core.bean.ZigbeeResponse;
|
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
|
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig;
|
| | |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | | import java.util.List;
|
| | | import java.util.concurrent.ScheduledExecutorService;
|
| | | import java.util.concurrent.TimeUnit;
|
| | |
| | | /**
|
| | | * 可能返回code属性可能没有 没有的话直接成功 有的话只有200才会成功
|
| | | */
|
| | | if (code == null || code.intValue() == 200 || code.intValue() == 0) {
|
| | | if (code == null || code == 200 || code == 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{
|
| | | } else if (msg instanceof ModbusResponse) {
|
| | | ModbusResponse response = (ModbusResponse) msg;
|
| | | if (replyTopic.equals(response.getTopic())) {
|
| | | notifySucceed(response.getData());
|
| | | } else {
|
| | | notifyFailure(HDLLinkCode.HDL_TOPIC_NOT_RIGHT);
|
| | | }
|
| | | } 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());
|
| | |
| | | if (MqttRecvClient.getInstance() != null) {
|
| | | MqttRecvClient.getInstance().send(requestTopic, encryBytes);
|
| | | }
|
| | | LogUtils.i("远程发送数据:" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes()));
|
| | | if (HDLConnectHelper.isInverterTopic(linkRequest.getCloudTopic())) {
|
| | | LogUtils.i("远程发送数据:" + linkRequest.getCloudTopic() + "\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getCloudSendBytes())));
|
| | | } else {
|
| | | LogUtils.i("远程发送数据:" + linkRequest.getCloudTopic() + "\r\n" + new String(linkRequest.getCloudSendBytes()));
|
| | | }
|
| | | }
|
| | | //本地TCP
|
| | | else {
|
| | | if (!linkRequest.getTopic().endsWith("heartbeat")) {//心跳主题数据过多,过滤下
|
| | | LogUtils.i("本地发送数据:\r\n" + new String(linkRequest.getSendBytes()));
|
| | | if (HDLConnectHelper.isInverterTopic(linkRequest.getTopic())) {
|
| | | LogUtils.i("本地发送数据:\r\n" + Arrays.toString(byteArrayConvertIntArray(linkRequest.getSendBytes())));
|
| | | } else {
|
| | | LogUtils.i("本地发送数据:\r\n" + new String(linkRequest.getSendBytes()));
|
| | | }
|
| | | }
|
| | | HDLTcpConnect.getTcpSocketBoot(ipAddress).sendMsg(EncryptUtil.getEncryBytes(linkRequest));
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 支持毫米类型
|
| | | *
|
| | |
| | | */
|
| | | public static List<String> getGatewayTypeList() {
|
| | | List<String> typeList = new ArrayList<>();
|
| | | typeList.add("sensor.mmv_sleep");//睡眠毫米波spk
|
| | | typeList.add("sensor.mmv_pose");//姿态毫米波spk
|
| | | // typeList.add("sensor.mmv_sleep");//睡眠毫米波spk
|
| | | // typeList.add("sensor.mmv_pose");//姿态毫米波spk
|
| | | typeList.add("energy.hdl_inverter");//逆变器spk
|
| | | return typeList;
|
| | | }
|
| | |
|
| | |
| | | listener = null;
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | public static boolean isInverterTopic(String topic) {
|
| | | if (TextUtils.isEmpty(topic)) {
|
| | | return false;
|
| | | }
|
| | | return topic.endsWith("custom/native/inverter/down_reply")
|
| | | || topic.endsWith("custom/native/inverter/down")
|
| | | || topic.endsWith("custom/native/inverter/up");
|
| | | }
|
| | |
|
| | | /**
|
| | | * byte数组转换成int数组(为了打印出无符号的btye数组数据)
|
| | | *
|
| | | * @param bytes 数组
|
| | | * @return
|
| | | */
|
| | | public static Integer[] byteArrayConvertIntArray(byte[] bytes) {
|
| | | if (bytes == null || bytes.length == 0) {
|
| | | return new Integer[]{};
|
| | | }
|
| | | Integer[] arr = new Integer[bytes.length];
|
| | | for (int i = 0; i < bytes.length; i++) {
|
| | | arr[i] = bytes[i] & 0xff;
|
| | | }
|
| | | return arr;
|
| | | }
|
| | | }
|