| | |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | |
| | | |
| | | import com.chad.library.adapter.base.BaseQuickAdapter; |
| | | import com.chad.library.adapter.base.listener.OnItemClickListener; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlsdk.device.DevicesListActivity; |
| | | import com.hdl.sdk.common.config.TopicConstant; |
| | | import com.hdl.sdk.common.event.EventListener; |
| | | import com.hdl.sdk.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.common.utils.IdUtils; |
| | | import com.hdl.sdk.common.utils.IpUtils; |
| | | import com.hdl.sdk.common.utils.gson.GsonConvert; |
| | | import com.hdl.sdk.connect.HDLLink; |
| | | import com.hdl.sdk.connect.bean.LinkRequest; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | | import com.hdl.sdk.connect.bean.request.AuthenticateRequest; |
| | | import com.hdl.sdk.connect.bean.request.PropertyReadRequest; |
| | |
| | | import com.hdl.sdk.connect.bean.response.GatewaySearchBean; |
| | | import com.hdl.sdk.connect.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; |
| | | import com.hdl.sdk.connect.config.HDLLinkConfig; |
| | | import com.hdl.sdk.connect.socket.HDLAuthSocket; |
| | | import com.hdl.sdk.connect.socket.HDLSocket; |
| | | import com.hdl.sdk.connect.bean.request.DeviceControlRequest; |
| | |
| | | beans.add(new DemoBean("读取状态")); |
| | | beans.add(new DemoBean("获取场景列表")); |
| | | beans.add(new DemoBean("场景控制")); |
| | | beans.add(new DemoBean("设备功能列表")); |
| | | beans.add(new DemoBean("UDP发送")); |
| | | beans.add(new DemoBean("TCP发送")); |
| | | demoAdapter = new DemoAdapter(beans); |
| | | rv.setAdapter(demoAdapter); |
| | | |
| | | |
| | | // final SocketOptions options = new SocketOptions(); |
| | | // |
| | | MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // options.setHandleMessage(pipeLine); |
| | | // options.setEnabledHeartbeat(false); |
| | | |
| | |
| | | //获取场景列表 |
| | | controlScene(); |
| | | break; |
| | | case 8: |
| | | //功能列表 |
| | | startDevicesListActivity(); |
| | | break; |
| | | case 9: |
| | | //UDP发送 |
| | | udpSend(); |
| | | break; |
| | | case 10: |
| | | //TCP发送 |
| | | tcpSend(); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | public void showToast(String text) { |
| | | Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); |
| | | } |
| | |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LinkResponse response = (LinkResponse)msg; |
| | | if(response != null){ |
| | | Log.i(TAG, "AllTopicsListener" |
| | | + "\nTopic: " + response.getTopic() |
| | | +"\n Data: " + response.getData()); |
| | | handleLinkResponse(response); |
| | | } |
| | | |
| | | } |
| | | }; |
| | | HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); |
| | |
| | | }.getType()); |
| | | searchBean = response.getObjects(); |
| | | } |
| | | |
| | | } |
| | | return searchBean; |
| | | } |
| | |
| | | tv.setText("开始入网认证..."); |
| | | //认证提交参数准备 |
| | | |
| | | //测试服务 |
| | | String spkStr = "ir.module";//产品spk |
| | | String macStr = "AA000000000000BB";//设备唯一MAC地址 |
| | | String secret = "87ae414b7a853f65";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | //正式服务器 |
| | | // String spkStr = "screen.mirror";//产品spk |
| | | // String macStr = "AA000000000000AC";//设备唯一MAC地址 |
| | | // String secret = "ee62124c151b737c";//通过spk和mac提交云端认证后分配的secret |
| | | |
| | | String mac_key = stringToMD5(stringToMD5(macStr + secret)); |
| | | String versionString = "HDL_V1.0.1";// |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | |
| | | //1.设置认证信息 |
| | | AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean(); |
| | | requestBean.setMAC(macStr); |
| | | requestBean.setSupplier("HDL"); |
| | | requestBean.setSupplier("raysgem"); |
| | | requestBean.setFirmwareVersion(versionString); |
| | | requestBean.setHardwareModel("1956F"); |
| | | AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean(); |
| | |
| | | infoBean.setDeviceName("红外宝");//设备名字 |
| | | infoBean.setDeviceModel("HDL");// |
| | | infoBean.setAccessMode("WIFI"); |
| | | infoBean.setIPGateway("192.168.12.1"); |
| | | infoBean.setIPGateway("192.168.88.1"); |
| | | infoBean.setIPAddress(IpUtils.getIP(this)); |
| | | |
| | | infoBean.setOID("010105000000FE08"); |
| | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | tv.setText("网关不在线"); |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | @Override |
| | | public void onSuccess(GatewaySearchBean gatewaySearchBean) { |
| | |
| | | } |
| | | |
| | | |
| | | void startDevicesListActivity(){ |
| | | Intent intent = new Intent(this, DevicesListActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | /** |
| | | * TCP发送 只发一次,不监听回复,不重发 |
| | | */ |
| | | private void tcpSend() { |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); |
| | | } |
| | | |
| | | /** |
| | | * 只发一次,不监听回复,不重发 |
| | | */ |
| | | private void udpSend() { |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr); |
| | | } |
| | | |
| | | private String getPropertyDownBodyStr(){ |
| | | isOn = !isOn; |
| | | List<DeviceControlRequest> requestList = new ArrayList<>(); |
| | | DeviceControlRequest request = new DeviceControlRequest(); |
| | | request.setSid(testLightSid); |
| | | List<DeviceControlRequest.StatusBean> statusBeanList= new ArrayList<>(); |
| | | DeviceControlRequest.StatusBean bean = new DeviceControlRequest.StatusBean(); |
| | | bean.setKey("on_off"); |
| | | bean.setValue(isOn ? "on" : "off"); |
| | | statusBeanList.add(bean); |
| | | request.setStatus(statusBeanList); |
| | | requestList.add(request); |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | |
| | | final BaseLocalResponse<List<DeviceControlRequest>> data = new BaseLocalResponse<>(); |
| | | data.setId(IdUtils.getUUId()); |
| | | data.setTime_stamp(time); |
| | | data.setObjects(requestList); |
| | | |
| | | return GsonConvert.getGson().toJson(data); |
| | | } |
| | | } |