Commit c97918265fd3e27616a3ef6e10a3035899bd516f

Authored by wugian
1 parent 76870886

switch receive message

@@ -36,6 +36,6 @@ dependencies { @@ -36,6 +36,6 @@ dependencies {
36 exclude group: 'com.android.support', module: 'support-annotations' 36 exclude group: 'com.android.support', module: 'support-annotations'
37 }) 37 })
38 compile 'com.android.support:appcompat-v7:25.2.0' 38 compile 'com.android.support:appcompat-v7:25.2.0'
39 - compile group: 'com.google.code.gson', name: 'gson', version: '2.4' 39 + compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
40 testCompile 'junit:junit:4.12' 40 testCompile 'junit:junit:4.12'
41 } 41 }
@@ -9,7 +9,7 @@ import android.util.Log; @@ -9,7 +9,7 @@ import android.util.Log;
9 public class GlobalVar { 9 public class GlobalVar {
10 public static final String CHARSET_UTF8 = "utf-8"; 10 public static final String CHARSET_UTF8 = "utf-8";
11 public static final byte MAX_BYTE = (byte) 0xFF; 11 public static final byte MAX_BYTE = (byte) 0xFF;
12 - static GlobalVar globalVar; 12 + static GlobalVar globalVar = new GlobalVar();
13 13
14 14
15 public static GlobalVar getLogUtils() { 15 public static GlobalVar getLogUtils() {
@@ -4,22 +4,24 @@ import android.content.Context; @@ -4,22 +4,24 @@ import android.content.Context;
4 import android.content.Intent; 4 import android.content.Intent;
5 import android.os.AsyncTask; 5 import android.os.AsyncTask;
6 import android.support.v4.content.LocalBroadcastManager; 6 import android.support.v4.content.LocalBroadcastManager;
7 - 7 +import android.text.TextUtils;
  8 +import android.util.Log;
8 import com.adroplat.fist_switch.SwitchApplication; 9 import com.adroplat.fist_switch.SwitchApplication;
9 import com.adroplat.fist_switch.config.GlobalVar; 10 import com.adroplat.fist_switch.config.GlobalVar;
10 import com.adroplat.fist_switch.utils.ToastUtils; 11 import com.adroplat.fist_switch.utils.ToastUtils;
11 import com.adroplat.fist_switch.utils.WifiUtils; 12 import com.adroplat.fist_switch.utils.WifiUtils;
12 import com.adroplat.fist_switch.utils.protocol.one.FistProtocol; 13 import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
13 import com.google.gson.Gson; 14 import com.google.gson.Gson;
  15 +import io.realm.Realm;
14 16
15 import java.util.ArrayList; 17 import java.util.ArrayList;
16 18
17 -import io.realm.Realm;  
18 -  
19 /** 19 /**
20 * Created by WLJ on 2016/1/14. 20 * Created by WLJ on 2016/1/14.
21 */ 21 */
22 public class FistJni { 22 public class FistJni {
  23 + private static final String TAG = FistJni.class.getSimpleName();
  24 +
23 static { 25 static {
24 System.loadLibrary("fist_ndk"); 26 System.loadLibrary("fist_ndk");
25 } 27 }
@@ -119,16 +121,21 @@ public class FistJni { @@ -119,16 +121,21 @@ public class FistJni {
119 LocalBroadcastManager.getInstance(context).sendBroadcast(intent); 121 LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
120 } 122 }
121 123
  124 + static String deviceJsonAA;
  125 +
122 public static void fistListener(String jsonDevice) { 126 public static void fistListener(String jsonDevice) {
123 if (null == jsonDevice || jsonDevice.isEmpty()) return; 127 if (null == jsonDevice || jsonDevice.isEmpty()) return;
124 - GlobalVar.getLogUtils().i("fistListener jsonDevice =" + jsonDevice); 128 +// GlobalVar.getLogUtils().i("fistListener jsonDevice =" + jsonDevice);
  129 + Log.d(TAG, jsonDevice);
125 Gson gson = getGson(); 130 Gson gson = getGson();
126 Device device = gson.fromJson(jsonDevice, Device.class); 131 Device device = gson.fromJson(jsonDevice, Device.class);
127 char cmdTpye = (char) device.getCmdType(); 132 char cmdTpye = (char) device.getCmdType();
128 - 133 + if (TextUtils.isEmpty(deviceJsonAA)) {
  134 + deviceJsonAA = jsonDevice;
  135 + }
129 if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应 136 if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
130 removeId(device); 137 removeId(device);
131 - online(device, jsonDevice); 138 +// online(device, jsonDevice);
132 sendJsonDevice(SEARCH_RESPONSE, device); 139 sendJsonDevice(SEARCH_RESPONSE, device);
133 140
134 } else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理 141 } else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
@@ -143,7 +150,7 @@ public class FistJni { @@ -143,7 +150,7 @@ public class FistJni {
143 sendJsonDevice(ADD_DONE, device); 150 sendJsonDevice(ADD_DONE, device);
144 ArrayList<SubDevice> subDevices = device.getSubDevices(); 151 ArrayList<SubDevice> subDevices = device.getSubDevices();
145 if (!subDevices.isEmpty()) {//查询结果不为空 152 if (!subDevices.isEmpty()) {//查询结果不为空
146 - Realm realm = Realm.getDefaultInstance(); 153 +// Realm realm = Realm.getDefaultInstance();
147 // long hostNum = device.getLongDeviceNum(); 154 // long hostNum = device.getLongDeviceNum();
148 // RealmResults<Hub> hubs = realm.where(Hub.class) 155 // RealmResults<Hub> hubs = realm.where(Hub.class)
149 // .equalTo(Hub.Companion.getDEVICE_NUM(), hostNum) 156 // .equalTo(Hub.Companion.getDEVICE_NUM(), hostNum)
@@ -175,7 +182,7 @@ public class FistJni { @@ -175,7 +182,7 @@ public class FistJni {
175 // } 182 // }
176 // } 183 // }
177 184
178 - realm.close(); 185 +// realm.close();
179 } 186 }
180 // sendJsonDevice(LightingGroupAdapter.REFRESH, device); 187 // sendJsonDevice(LightingGroupAdapter.REFRESH, device);
181 188
@@ -254,6 +261,7 @@ public class FistJni { @@ -254,6 +261,7 @@ public class FistJni {
254 @Override 261 @Override
255 protected Void doInBackground(Void... params) { 262 protected Void doInBackground(Void... params) {
256 start(); 263 start();
  264 + Log.d(TAG, "start sdk");
257 return null; 265 return null;
258 } 266 }
259 }.execute(); 267 }.execute();
@@ -298,6 +306,19 @@ public class FistJni { @@ -298,6 +306,19 @@ public class FistJni {
298 }.execute(); 306 }.execute();
299 } 307 }
300 308
  309 + public void query( ) {
  310 +// if (!HeService.isConn()) {
  311 +// return;
  312 +// }
  313 + new AsyncTask<Void, Void, Void>() {
  314 + @Override
  315 + protected Void doInBackground(Void... params) {
  316 + querySubDevice(deviceJsonAA);
  317 + return null;
  318 + }
  319 + }.execute();
  320 + }
  321 +
301 /** 322 /**
302 * 开始添加子设备 323 * 开始添加子设备
303 */ 324 */
@@ -470,6 +491,7 @@ public class FistJni { @@ -470,6 +491,7 @@ public class FistJni {
470 @Override 491 @Override
471 protected Void doInBackground(Void... params) { 492 protected Void doInBackground(Void... params) {
472 searchDevice(); 493 searchDevice();
  494 + Log.d(TAG, "search local device");
473 return null; 495 return null;
474 } 496 }
475 }.execute(); 497 }.execute();
1 package com.qnbar.switchcontrol; 1 package com.qnbar.switchcontrol;
2 2
3 import android.os.Bundle; 3 import android.os.Bundle;
4 -import android.os.Handler;  
5 -import android.os.Message;  
6 import android.support.v7.app.AppCompatActivity; 4 import android.support.v7.app.AppCompatActivity;
7 -import android.util.Log;  
8 import android.view.View; 5 import android.view.View;
9 -  
10 import com.adroplat.fist_switch.jni.FistJni; 6 import com.adroplat.fist_switch.jni.FistJni;
11 7
12 public class MainActivity extends AppCompatActivity { 8 public class MainActivity extends AppCompatActivity {
@@ -16,29 +12,30 @@ public class MainActivity extends AppCompatActivity { @@ -16,29 +12,30 @@ public class MainActivity extends AppCompatActivity {
16 super.onCreate(savedInstanceState); 12 super.onCreate(savedInstanceState);
17 setContentView(R.layout.activity_main); 13 setContentView(R.layout.activity_main);
18 14
19 - Handler handler = new Handler() {  
20 - @Override  
21 - public void dispatchMessage(Message msg) {  
22 - super.dispatchMessage(msg);  
23 - switch (msg.what) {  
24 - case UdpPostSender.MSG_What:  
25 - Log.d("lovely_switch", "msg what:" + msg.toString());  
26 - break;  
27 - default:  
28 - Log.d("lovely_switch", msg.toString());  
29 - }  
30 - }  
31 - }; 15 +// Handler handler = new Handler() {
  16 +// @Override
  17 +// public void dispatchMessage(Message msg) {
  18 +// super.dispatchMessage(msg);
  19 +// switch (msg.what) {
  20 +// case UdpPostSender.MSG_What:
  21 +// Log.d("lovely_switch", "msg what:" + msg.toString());
  22 +// break;
  23 +// default:
  24 +// Log.d("lovely_switch", msg.toString());
  25 +// }
  26 +// }
  27 +// };
32 // new UdpPostSender("", 9000, 9000, handler).start(); 28 // new UdpPostSender("", 9000, 9000, handler).start();
33 - new Thread(){  
34 - @Override  
35 - public void run() {  
36 - super.run();  
37 - new UdpHelper().StartListen();  
38 - }  
39 - }.start(); 29 +// new Thread(){
  30 +// @Override
  31 +// public void run() {
  32 +// super.run();
  33 +// new UdpHelper().StartListen();
  34 +// }
  35 +// }.start();
40 // new UdpHelper().run(); 36 // new UdpHelper().run();
41 // new UdpHelper().run(); 37 // new UdpHelper().run();
  38 +
42 } 39 }
43 40
44 public void startSdk(View view) { 41 public void startSdk(View view) {
@@ -50,4 +47,10 @@ public class MainActivity extends AppCompatActivity { @@ -50,4 +47,10 @@ public class MainActivity extends AppCompatActivity {
50 FistJni fistJni = FistJni.getInstance(); 47 FistJni fistJni = FistJni.getInstance();
51 fistJni.searchLocalDevice(); 48 fistJni.searchLocalDevice();
52 } 49 }
  50 +
  51 + public void startFist(View view) {
  52 +
  53 + FistJni fistJni = FistJni.getInstance();
  54 + fistJni.query();
  55 + }
53 } 56 }
@@ -33,8 +33,7 @@ public class UdpHelper{ @@ -33,8 +33,7 @@ public class UdpHelper{
33 message.length); 33 message.length);
34 datagramSocket.receive(datagramPacket); 34 datagramSocket.receive(datagramPacket);
35 String strMsg=new String(datagramPacket.getData()).trim(); 35 String strMsg=new String(datagramPacket.getData()).trim();
36 - Log.d("UDP_Demo", datagramPacket.getAddress()  
37 - .getHostAddress().toString() 36 + Log.d("UDP_Demo", datagramPacket.getAddress().getHostAddress()
38 + ":" +strMsg ); 37 + ":" +strMsg );
39 } 38 }
40 } catch (IOException e) {//IOException 39 } catch (IOException e) {//IOException
@@ -22,6 +22,12 @@ @@ -22,6 +22,12 @@
22 <Button 22 <Button
23 android:layout_width="wrap_content" 23 android:layout_width="wrap_content"
24 android:layout_height="wrap_content" 24 android:layout_height="wrap_content"
  25 + android:onClick="startFist"
  26 + android:text="FindSubDevice"/>
  27 +
  28 + <Button
  29 + android:layout_width="wrap_content"
  30 + android:layout_height="wrap_content"
25 android:onClick="searchLocalDevice" 31 android:onClick="searchLocalDevice"
26 android:text="searchLocalDevice"/> 32 android:text="searchLocalDevice"/>
27 33
Please register or login to post a comment