Commit c97918265fd3e27616a3ef6e10a3035899bd516f

Authored by wugian
1 parent 76870886

switch receive message

... ... @@ -36,6 +36,6 @@ dependencies {
36 36 exclude group: 'com.android.support', module: 'support-annotations'
37 37 })
38 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 40 testCompile 'junit:junit:4.12'
41 41 }
... ...
... ... @@ -9,7 +9,7 @@ import android.util.Log;
9 9 public class GlobalVar {
10 10 public static final String CHARSET_UTF8 = "utf-8";
11 11 public static final byte MAX_BYTE = (byte) 0xFF;
12   - static GlobalVar globalVar;
  12 + static GlobalVar globalVar = new GlobalVar();
13 13
14 14
15 15 public static GlobalVar getLogUtils() {
... ...
... ... @@ -4,22 +4,24 @@ import android.content.Context;
4 4 import android.content.Intent;
5 5 import android.os.AsyncTask;
6 6 import android.support.v4.content.LocalBroadcastManager;
7   -
  7 +import android.text.TextUtils;
  8 +import android.util.Log;
8 9 import com.adroplat.fist_switch.SwitchApplication;
9 10 import com.adroplat.fist_switch.config.GlobalVar;
10 11 import com.adroplat.fist_switch.utils.ToastUtils;
11 12 import com.adroplat.fist_switch.utils.WifiUtils;
12 13 import com.adroplat.fist_switch.utils.protocol.one.FistProtocol;
13 14 import com.google.gson.Gson;
  15 +import io.realm.Realm;
14 16
15 17 import java.util.ArrayList;
16 18
17   -import io.realm.Realm;
18   -
19 19 /**
20 20 * Created by WLJ on 2016/1/14.
21 21 */
22 22 public class FistJni {
  23 + private static final String TAG = FistJni.class.getSimpleName();
  24 +
23 25 static {
24 26 System.loadLibrary("fist_ndk");
25 27 }
... ... @@ -119,16 +121,21 @@ public class FistJni {
119 121 LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
120 122 }
121 123
  124 + static String deviceJsonAA;
  125 +
122 126 public static void fistListener(String jsonDevice) {
123 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 130 Gson gson = getGson();
126 131 Device device = gson.fromJson(jsonDevice, Device.class);
127 132 char cmdTpye = (char) device.getCmdType();
128   -
  133 + if (TextUtils.isEmpty(deviceJsonAA)) {
  134 + deviceJsonAA = jsonDevice;
  135 + }
129 136 if (FistProtocol.CommondType.CMD_TYPE_SEARCH_RESPONSE == cmdTpye) {//查询响应
130 137 removeId(device);
131   - online(device, jsonDevice);
  138 +// online(device, jsonDevice);
132 139 sendJsonDevice(SEARCH_RESPONSE, device);
133 140
134 141 } else if (FistProtocol.CommondType.CMD_TYPE_CONFIG_DONE == cmdTpye) {//配置完成处理
... ... @@ -143,7 +150,7 @@ public class FistJni {
143 150 sendJsonDevice(ADD_DONE, device);
144 151 ArrayList<SubDevice> subDevices = device.getSubDevices();
145 152 if (!subDevices.isEmpty()) {//查询结果不为空
146   - Realm realm = Realm.getDefaultInstance();
  153 +// Realm realm = Realm.getDefaultInstance();
147 154 // long hostNum = device.getLongDeviceNum();
148 155 // RealmResults<Hub> hubs = realm.where(Hub.class)
149 156 // .equalTo(Hub.Companion.getDEVICE_NUM(), hostNum)
... ... @@ -175,7 +182,7 @@ public class FistJni {
175 182 // }
176 183 // }
177 184
178   - realm.close();
  185 +// realm.close();
179 186 }
180 187 // sendJsonDevice(LightingGroupAdapter.REFRESH, device);
181 188
... ... @@ -254,6 +261,7 @@ public class FistJni {
254 261 @Override
255 262 protected Void doInBackground(Void... params) {
256 263 start();
  264 + Log.d(TAG, "start sdk");
257 265 return null;
258 266 }
259 267 }.execute();
... ... @@ -298,6 +306,19 @@ public class FistJni {
298 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 491 @Override
471 492 protected Void doInBackground(Void... params) {
472 493 searchDevice();
  494 + Log.d(TAG, "search local device");
473 495 return null;
474 496 }
475 497 }.execute();
... ...
1 1 package com.qnbar.switchcontrol;
2 2
3 3 import android.os.Bundle;
4   -import android.os.Handler;
5   -import android.os.Message;
6 4 import android.support.v7.app.AppCompatActivity;
7   -import android.util.Log;
8 5 import android.view.View;
9   -
10 6 import com.adroplat.fist_switch.jni.FistJni;
11 7
12 8 public class MainActivity extends AppCompatActivity {
... ... @@ -16,29 +12,30 @@ public class MainActivity extends AppCompatActivity {
16 12 super.onCreate(savedInstanceState);
17 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 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 36 // new UdpHelper().run();
41 37 // new UdpHelper().run();
  38 +
42 39 }
43 40
44 41 public void startSdk(View view) {
... ... @@ -50,4 +47,10 @@ public class MainActivity extends AppCompatActivity {
50 47 FistJni fistJni = FistJni.getInstance();
51 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 33 message.length);
34 34 datagramSocket.receive(datagramPacket);
35 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 37 + ":" +strMsg );
39 38 }
40 39 } catch (IOException e) {//IOException
... ...
... ... @@ -22,6 +22,12 @@
22 22 <Button
23 23 android:layout_width="wrap_content"
24 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 31 android:onClick="searchLocalDevice"
26 32 android:text="searchLocalDevice"/>
27 33
... ...
Please register or login to post a comment