//package com.hdl.sdk.ttl_sdk.bean; // //import android.os.Bundle; //import android.view.View; //import android.widget.Button; //import android.widget.RelativeLayout; //import android.widget.TextView; // ////import com.google.gson.Gson; ////import com.google.gson.Gson; //import com.google.gson.Gson; //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.bean.ZigBeeCommand; //import com.hdl.sdk.ttl_sdk.bean.ZigBeeCtrl; //import com.hdl.sdk.ttl_sdk.bean.ZigBeeCtrl2; //import com.hdl.sdk.ttl_sdk.bean.ZigBeeDataBean; //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.ArrayList; //import java.util.List; //import java.util.Timer; //import java.util.TimerTask; // //public class ZigbeeActivity2 extends BaseActivity { // /** // * Topbar // */ // private RelativeLayout topBarBack; // private TextView topBarTitle; // private Button btn_PassThrough, btn_PassThrough_close; // private Button btn_open_light, btn_open_switch,btn_open_switch2; // // // private TextView tv_other_mes; // private Button btn_close; // private boolean bReceivingMode = false;//接收者模式 // // // // // // /** // * 复写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(); // startHDLThread(); // startSendHeartPacketTimer(); // } // // // // /** // * 初始化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_light = findViewById(R.id.btn_open_light); // btn_open_switch = findViewById(R.id.btn_open_switch); // // btn_open_switch2= findViewById(R.id.btn_open_switch2); // // } // // boolean dd = true; // /** // * initOnClick // */ // private void initOnClick() { // btn_PassThrough.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { //// //// SendCtrl222(); //// dd = !dd; //// if(dd){ //// SendGetDeviceList(); //// }else { //// SendCtrl222(); //// } //// SendCtrl(); // SendGetDeviceList(); //// SendCtrlLight(); //// SendCtrl(); //// SendCtrlLight(); // } // }); // // 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(); // } // }); // // btn_open_light.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // SendCtrlLight(); // } // }); // // btn_open_switch.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // SendCtrl(); // } // }); // // // btn_open_switch2.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // SendCtrl222(); // } // }); // // } // // /** // * 2019-8-9 // * 发送透传参数 // * 透传数据,不走bus协议,直接转发,不做数据格式处理 // * mcuSendTransparentData接口调用一次以后,默认所有接收数据走透传 // * 可以调用setHDLPassThroughOpen关闭透传数据 // */ // private void mcuSendTransparentData() { // startSendHeartPacketTimer(); // } // // /** // * 设置是否开启透传数据 // * 要想直接接收透传数据,直接调用这个接口打开就可以,不走bus协议处理 // * 不想透传的话,要记得设置回关闭状态 // */ // private void setHDLPassThroughOpen(Boolean bOpen){ // // HDLCommand.setHDLPassThroughOpen(bOpen); // // } // // //// private int HeartData = 0x2000; //// private byte[] HeartDataBytes = {(byte) (HeartData / 256),(byte) (HeartData % 256) }; // private String sendDataStr = ""; // // private static int sendCount = 0;//发送序列号 //// private boolean bFrist = true; // // private void SendHeartPacket(){ // if(sendCount<255){ // sendCount++; // }else { // sendCount = 0; // } // // byte[] sendBytes = ZigBeeCommand.GetHeartbeatBytes(sendCount); // HDLCommand.mcuSendTransparentData(sendBytes); // } // // private void SendGetDeviceList(){ //// if(bReceivingMode) return; // // // byte[] bytes = sendDataStr.getBytes(); // byte[] sendBytes = ZigBeeCommand.GetSendBytes(bytes, ZigBeeCommand.COMMAND_SEND_DATA, sendCount); // HDLCommand.mcuSendTransparentData(sendBytes); // //// bReceivingMode = true; // // } // // int lenght = 1280; // // private void SendCtrl222(){ // //// byte[] sendBytes = new byte[]{ //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11, //// }; // // lenght ++; // HDLLog.Log("KNNN:send" + lenght); // byte[] sendBytes = new byte[lenght]; // for(int i = 0;i STM32) // getJsonData(mZigBeeDataBean2); // break; // } // // // // // } // // private void getJsonData(ZigBeeDataBean mZigBeeDataBean){ //// String receiveString = HDLStringUtils.ByteArrToHex(mZigBeeDataBean.receiveBytes, 0, mZigBeeDataBean.receiveBytes.length); //// String receiveString =new Gson().toJson(mZigBeeDataBean.receiveBytes); // // String receiveString = HDLStringUtils.byte2String(mZigBeeDataBean.receiveBytes); // //// Log.d(TAG,new Gson().toJson(mZigBeeDataBean.receiveBytes)); // // setTextView("GET JSON: "+receiveString ); // //回复:透传JSON数据返回(魔镜->STM32) // } // // // /** // * 透传JSON数据返回(魔镜->STM32) // * 0XF8成功 0XF5失败 // * @param mID // */ // private void sendReceiveDataSuccess(int mID){ // byte[] sendBytes = ZigBeeCommand.GetReplyBytes(mID, true); // HDLCommand.mcuSendTransparentData(sendBytes); // } // // // // private void setTextView(final String mes){ // // // runOnUiThread(new Runnable() { // public void run() { // tv_other_mes.append(mes + "\n"); // } // }); // // HDLLog.Log("KNNN:" + mes); // } // // // // // // // // // // /** // * 启动线程 // */ // private void startHDLThread() { // mHDLRead485DatasThread = new HDLRead485DatasThread(); // mHDLRead485DatasThread.start(); // } // /** // * 启动线程 // */ // private void closeThread() { // if (mHDLRead485DatasThread != null) mHDLRead485DatasThread.interrupt(); // } // // private HDLRead485DatasThread mHDLRead485DatasThread; // private boolean bOpenSuccess= true; // private List mReceiveDatasList = new ArrayList();//485接收数据队列 // // /** // * // * @param receiveBytes // */ // private void AddReceiveDatasList(byte[] receiveBytes) { // for (int i = 0; i < receiveBytes.length; i++) { // mReceiveDatasList.add(receiveBytes[i]); // } // } // // /** // * 485数据接收线程 // * // * @author 2019年06月26日 // */ // private class HDLRead485DatasThread extends Thread { // // @Override // public void run() { // super.run(); // HDLLog.Log("ZigBee接收线程 开启"); // while (bOpenSuccess) { // int size = 0; // try { // Thread.sleep(10); // while (0 < mReceiveDatasList.size()) { //// HDLLog.I("485arraylist.size():" + mReceive485DatasList.size()); // if (mReceiveDatasList.size() < 3) break;//2019-07-02 // if (mReceiveDatasList.size() > 3000) { //数据缓存太多错误情况下 清空一次 // mReceiveDatasList.clear(); // break;//2019-07-24 // } // int len = -1; // int startIndex = 0; // for (startIndex = 0; startIndex < mReceiveDatasList.size(); startIndex++) { // if ((mReceiveDatasList.get(startIndex) & 0xFF) == 0xAA // && (mReceiveDatasList.get(startIndex + 1) & 0xFF) == 0xAA) { //// len = (mReceiveDatasList.get(startIndex + 2) & 0xFF) * 256 + (mReceiveDatasList.get(startIndex + 3) & 0xFF) + 5; // len = (mReceiveDatasList.get(startIndex + 2) & 0xFF) * 256 + (mReceiveDatasList.get(startIndex + 3) & 0xFF) + 2; // break; // } // } // if (len == -1 || mReceiveDatasList.size() < len) break; // //// HDLLog.Log("startIndex:" + startIndex + " LEN:" + len); // for (int i = 0; i < startIndex; i++) { // if (mReceiveDatasList.size() < 1) break;//2019-07-02 // mReceiveDatasList.remove(0); // } // byte[] tempBytes = new byte[len]; // for (int i = 0; i < tempBytes.length; i++) { // if (mReceiveDatasList.size() < 1) break;//2019-07-02 // // tempBytes[i] = mReceiveDatasList.get(0); // mReceiveDatasList.remove(0); // } // HandleMCUdata(tempBytes); // } // } catch (Exception e) { // e.printStackTrace(); // HDLLog.Log("error:" + e.getMessage()); // } // } // HDLLog.Log("485接收线程 关闭"); // } // } //}