//package com.hdl.sdk.ttl_sdk.activity; // //import android.support.v7.app.AppCompatActivity; //import android.os.Bundle; //import android.text.TextUtils; //import android.view.View; //import android.widget.Button; //import android.widget.RelativeLayout; //import android.widget.TextView; // //import com.hdl.sdk.ttl.Config.MCUConstants; //import com.hdl.sdk.ttl.HDLDeviceManger.Core.Crc; //import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand; //import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode; //import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent; //import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLStringUtils; //import com.hdl.sdk.ttl_sdk.R; //import com.hdl.sdk.ttl_sdk.base.BaseActivity; //import com.hdl.sdk.ttl_sdk.utlis.HDLLog; // //import org.greenrobot.eventbus.Subscribe; //import org.greenrobot.eventbus.ThreadMode; //import org.json.JSONException; //import org.json.JSONObject; // //import java.util.Timer; //import java.util.TimerTask; // //public class ZigbeeActivity extends BaseActivity { // /** // * Topbar // */ // private RelativeLayout topBarBack; // private TextView topBarTitle; // private Button btn_PassThrough, btn_PassThrough_close; // private TextView tv_other_mes; // private Button btn_close; // private Button btn_open_switch2; // // // /** // * 复写isRegisterEventBus() 要注册使用EventBus,这里要设置返回true // * // * @return true // */ // @Override // protected boolean isRegisterEventBus() { // return true; // } // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_zigbee); // initToolbar(); // initView(); // initOnClick(); // getJson(); // } // // // // /** // * 初始化Toolbar // */ // private void initToolbar() { // topBarBack = findViewById(R.id.ll_top_b_left); // setViewVisible(topBarBack); // topBarTitle = findViewById(R.id.tv_top_b_header_title); // topBarBack.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // finish(); // } // }); // topBarTitle.setText("Zigbee调试"); // } // // /** // * initView // */ // private void initView() { // btn_PassThrough = findViewById(R.id.btn_PassThrough); // btn_PassThrough_close = findViewById(R.id.btn_PassThrough_close); // tv_other_mes = findViewById(R.id.tv_other_mes); // // btn_close = findViewById(R.id.btn_close); // btn_open_switch2 = findViewById(R.id.btn_close); // } // // /** // * initOnClick // */ // private void initOnClick() { // btn_PassThrough.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // startSendHeartPacketTimer(); // // } // }); // // btn_PassThrough_close.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // setHDLPassThroughOpen(false); // tv_other_mes.setText("关闭透传"); // // } // }); // // btn_close.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // cancelTimer(); // } // }); // // } // // /** // * 2019-8-9 // * 发送透传参数 // * 透传数据,不走bus协议,直接转发,不做数据格式处理 // * mcuSendTransparentData接口调用一次以后,默认所有接收数据走透传 // * 可以调用setHDLPassThroughOpen关闭透传数据 // */ // private void mcuSendTransparentData() { // startSendHeartPacketTimer(); // } // // /** // * 设置是否开启透传数据 // * 要想直接接收透传数据,直接调用这个接口打开就可以,不走bus协议处理 // * 不想透传的话,要记得设置回关闭状态 // */ // private void setHDLPassThroughOpen(Boolean bOpen){ // // HDLCommand.setHDLPassThroughOpen(bOpen); // // } // // // private int DeviceType = 0x6666; // private int Command1002 = 0x1002; // private int CommandHeartbeat = 0x2000; // private int DeviceID = 0x01; // private int sendCount = 0;//发送序列号 // /** // * @return // */ // private byte[] GetHeartbeatBytes() { // sendCount++; // if(sendCount > 254){ // sendCount = 0; // } // byte[] crcBytes = new byte[13]; // byte[] sendBytes = new byte[2 + crcBytes.length]; // //Boot code // sendBytes[0] = (byte) 0xAA; // sendBytes[1] = (byte) 0xAA; // crcBytes[0] = (byte) (crcBytes.length / 256); // crcBytes[1] = (byte) (crcBytes.length % 256); // crcBytes[2] = (byte) 0x01; // crcBytes[3] = (byte) 0x01; // crcBytes[4] = (byte) (DeviceType / 256); // crcBytes[5] = (byte) (DeviceType % 256); // crcBytes[6] = (byte) (CommandHeartbeat / 256); // crcBytes[7] = (byte) (CommandHeartbeat % 256); // crcBytes[8] = (byte) 0x02; // crcBytes[9] = (byte) 0x02; // crcBytes[10] = (byte) sendCount; // // Crc.ConCRC(crcBytes, crcBytes.length - 2); // System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length); // return sendBytes; // } // // /** // * @return // */ // private byte[] GetSendBytes(byte[] addBytes, int mCommand) { // sendCount++; // if(sendCount > 254){ // sendCount = 0; // } // // byte[] crcBytes = new byte[15 + addBytes.length]; // byte[] sendBytes = new byte[2 + crcBytes.length]; // //Boot code // sendBytes[0] = (byte) 0xAA; // sendBytes[1] = (byte) 0xAA; // crcBytes[0] = (byte) (crcBytes.length / 256); // crcBytes[1] = (byte) (crcBytes.length % 256); // crcBytes[2] = (byte) 0x01; // crcBytes[3] = (byte) 0x01; // crcBytes[4] = (byte) (DeviceType / 256); // crcBytes[5] = (byte) (DeviceType % 256); // crcBytes[6] = (byte) (mCommand / 256); // crcBytes[7] = (byte) (mCommand % 256); // crcBytes[8] = (byte) 0x02; // crcBytes[9] = (byte) 0x02; // crcBytes[10] = (byte) sendCount; // crcBytes[11] = (byte) (addBytes.length / 256); // crcBytes[12] = (byte) (addBytes.length % 256); // System.arraycopy(addBytes, 0, crcBytes, 13, addBytes.length); // Crc.ConCRC(crcBytes, crcBytes.length - 2); // System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length); // return sendBytes; // } // // // // // private int HeartData = 0x2000; //// private byte[] HeartDataBytes = {(byte) (HeartData / 256),(byte) (HeartData % 256) }; // private String sendDataStr = ""; // // // private boolean bFrist = true; // private void SendHeartPacket(){ //// if(sendCount > 4){ //// cancelTimer(); //// return; //// } // // byte[] sendBytes = GetHeartbeatBytes(); // HDLCommand.mcuSendTransparentData(sendBytes); // if(bFrist){ // bFrist = false; // bBeginSendData = true; // } // } // // private void SendGetDeviceList(){ // byte[] bytes = sendDataStr.getBytes(); // byte[] sendBytes = GetSendBytes(bytes, Command1002 ); // HDLCommand.mcuSendTransparentData(sendBytes); // // } // // // private boolean bGetData = false; // private boolean bBeginSendData = false; // // 定时器 // private Timer mTimer = new Timer(); // // 定时任务 // private MyTimerTask mTask; // // class MyTimerTask extends TimerTask{ // @Override // public void run() { // // TODO Auto-generated method stub // // 要做的事情 // if(!bGetData) { // if(bBeginSendData){ // SendGetDeviceList(); // bBeginSendData = false; // // }else { // // SendHeartPacket(); // } // } // } // // } // // private void startSendHeartPacketTimer(){ // // if(mTimer == null){ // mTimer = new Timer(); // } // if(mTask != null){ // mTask.cancel(); // // } // mTask = new MyTimerTask(); // mTimer.schedule(mTask, 200, 500); // } // // private void cancelTimer() { // if (mTimer != null) { // mTask.cancel(); // mTimer.cancel(); // mTimer = null; // // } // } // // /** // * ***********************************************************处理MCU回复数据*********************************************************** // */ // /** // * MCU控制回调Event // * // * @param event // */ // @Subscribe(threadMode = ThreadMode.MAIN) // public void onMCUFeedBackEventMain(MCUFeedBackEvent event) { // if (event.getEventCode() == EventCode.FAILURE_TIMEOUT) { // if (TextUtils.isEmpty(event.getError())) { // showToast("MCU请求超时,请稍后再试"); // } else { // showToast(event.getError()); // } // return; // } // // switch (event.getMCUDataBean().command) { // case MCUConstants.MCU_COMMAND_SEND_BACK: // // //透传返回的数据 // handleMCUPassThroughDataBack(event); // break; // default: // break; // } // } // // // /** // * 处理MCU透传回调数据 // * 透传数据,不走bus协议,直接转发,不做数据格式处理 // * // * @param event // */ // private void handleMCUPassThroughDataBack(MCUFeedBackEvent event) { // if (event.getEventCode() != EventCode.SUCCESS) { // tv_other_mesSetText("MCU透传数据出错,返回数据异常"); // return; // } // String receiveString = HDLStringUtils.ByteArrToHex(event.getMCUDataBean().receiveBytes, 0, event.getMCUDataBean().receiveBytes.length); // // tv_other_mes.append("GET: "+receiveString + "\n"); //// tv_other_mes.setText("收到的透传数据:" + receiveString); // HDLLog.Log("收到的透传数据:" + receiveString); // } // // private void tv_other_mesSetText(String mes) { // tv_other_mes.setText(mes); // showToast(mes); // } // // // @Override // protected void onDestroy() { // super.onDestroy(); // cancelTimer(); // } // //// private class ZIGBEECommand{ //// private int Cluster_ID = 0; //// private int Command = 93; //// private ZIGBEECommand(int Cluster_ID, int Command){ //// this.Cluster_ID = Cluster_ID; //// this.Command = Command; //// } //// } // // private void getJson(){ // try { // JSONObject jsonObject = new JSONObject(); // jsonObject.put("Cluster_ID", 0); // jsonObject.put("Command", 93); // HDLLog.Log("getJson:" + jsonObject.toString()); // sendDataStr = jsonObject.toString(); // // } catch (JSONException e) { // e.printStackTrace(); // } // } // // //// /** //// * 处理HDL Data //// * //// * @param receiveBytes //// */ //// private void HandleMCUdata(byte[] receiveBytes) { //// if (receiveBytes.length < 5) { //// return; //// } //// //// } //}