| | |
| | | package com.sandu.ximon.admin.utils; |
| | | |
| | | import com.sandu.ximon.admin.entity.AtmoHeartBeatDataPackage; |
| | | import com.sandu.ximon.admin.entity.DataTransportMainFrame; |
| | | import com.sandu.ximon.admin.entity.DataTransportMainResponse; |
| | | import com.sandu.ximon.admin.entity.DataTransportOrderType; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.AtmoCommonFrame; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.AtmoFunctionCode; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.response.AtmoQueryHeartBeatResponse; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.util.SupplementUtils; |
| | | import org.apache.logging.log4j.util.Base64Util; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component("AtmoAPIUtils") |
| | |
| | | |
| | | /** |
| | | * 查询大气数据心跳包 |
| | | * |
| | | * @param mac |
| | | */ |
| | | public AtmoHeartBeatDataPackage queryHeartBeat(String mac) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 查询大气数据心跳包间隔时间 |
| | | * @param mac |
| | | */ |
| | | public Integer queryHeartBeatTime(String mac) { |
| | | // 生成控制帧 |
| | | String frame = generateNoPayLoadFrame(AtmoFunctionCode.QueryHeartBeatTime, "FFFF"); |
| | | // 发送RRPC |
| | | String result = rrpc(mac, frame); |
| | | if(null != result) { |
| | | // 返回结果 |
| | | result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | AtmoQueryHeartBeatTimeResponse response = new AtmoQueryHeartBeatTimeResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | return response.getHeartBeatTimeInt(); |
| | | } |
| | | return -1; |
| | | } |
| | | // /** |
| | | // * 查询大气数据心跳包间隔时间 |
| | | // * @param mac |
| | | // */ |
| | | // public Integer queryHeartBeatTime(String mac) { |
| | | // // 生成控制帧 |
| | | // String frame = generateNoPayLoadFrame(AtmoFunctionCode.QueryHeartBeatTime, "FFFF"); |
| | | // // 发送RRPC |
| | | // String result = rrpc(mac, frame); |
| | | // if(null != result) { |
| | | // // 返回结果 |
| | | // result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | // DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | // AtmoQueryHeartBeatTimeResponse response = new AtmoQueryHeartBeatTimeResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | // return response.getHeartBeatTimeInt(); |
| | | // } |
| | | // return -1; |
| | | // } |
| | | // |
| | | // |
| | | // /** |
| | | // * 软重启 |
| | | // * @param mac |
| | | // * |
| | | // */ |
| | | // public String reboot(String mac) { |
| | | // // 生成控制帧 |
| | | // String frame = generateNoPayLoadFrame(AtmoFunctionCode.Reboot, "FFFF"); |
| | | // // 发送RRPC |
| | | // String result = rrpc(mac, frame); |
| | | // if(null != result) { |
| | | // // 返回结果 |
| | | // result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | // DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | // AtmoCommonResponse response = new AtmoCommonResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | // return response.getResponseStatus(); |
| | | // } |
| | | // return CommonResponse.No_Response.getCode(); |
| | | // } |
| | | |
| | | |
| | | /** |
| | | * 软重启 |
| | | * @param mac |
| | | * |
| | | */ |
| | | public String reboot(String mac) { |
| | | // 生成控制帧 |
| | | String frame = generateNoPayLoadFrame(AtmoFunctionCode.Reboot, "FFFF"); |
| | | // 发送RRPC |
| | | String result = rrpc(mac, frame); |
| | | if(null != result) { |
| | | // 返回结果 |
| | | result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | AtmoCommonResponse response = new AtmoCommonResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | return response.getResponseStatus(); |
| | | } |
| | | return CommonResponse.No_Response.getCode(); |
| | | } |
| | | |
| | | /** |
| | | * 设置心跳时间 |
| | | * @param mac |
| | | * @param heartBeatTime s |
| | | */ |
| | | public String settingHeartBeatTime(String mac, Integer heartBeatTime) { |
| | | String payload = "FFFF" + SupplementUtils.suppleZero(HexStrConvertUtil.tenToHex(heartBeatTime),4); |
| | | // 生成控制帧 |
| | | String frame = generateNoPayLoadFrame(AtmoFunctionCode.SettingHeartBeatTime, payload); |
| | | // 发送RRPC |
| | | String result = rrpc(mac, frame); |
| | | if(null != result) { |
| | | // 返回结果 |
| | | result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | AtmoCommonResponse response = new AtmoCommonResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | return response.getResponseStatus(); |
| | | } |
| | | return CommonResponse.No_Response.getCode(); |
| | | } |
| | | |
| | | // /** |
| | | // * 设置心跳时间 |
| | | // * @param mac |
| | | // * @param heartBeatTime s |
| | | // */ |
| | | // public String settingHeartBeatTime(String mac, Integer heartBeatTime) { |
| | | // String payload = "FFFF" + SupplementUtils.suppleZero(HexStrConvertUtil.tenToHex(heartBeatTime),4); |
| | | // // 生成控制帧 |
| | | // String frame = generateNoPayLoadFrame(AtmoFunctionCode.SettingHeartBeatTime, payload); |
| | | // // 发送RRPC |
| | | // String result = rrpc(mac, frame); |
| | | // if(null != result) { |
| | | // // 返回结果 |
| | | // result = HexStrConvertUtil.bytesToHexString(Base64Util.decode(result)); |
| | | // DataTransportMainResponse dataTransportMainResponse = new DataTransportMainResponse().convertInstance(result.substring(2)); |
| | | // AtmoCommonResponse response = new AtmoCommonResponse().convertInstance(dataTransportMainResponse.getPayload()); |
| | | // return response.getResponseStatus(); |
| | | // } |
| | | // return CommonResponse.No_Response.getCode(); |
| | | // } |
| | | // |
| | | private String generateNoPayLoadFrame(AtmoFunctionCode atmoFunctionCode, String payload){ |
| | | String frame = DataTransportMainFrame.generateInstance( |
| | | DataTransportOrderType.AtmosphereData, |