|
...
|
...
|
@@ -30,6 +30,7 @@ import com.qnbar.smc.socketProtocol.fromServer.OpenDoor; |
|
30
|
30
|
import com.qnbar.smc.socketProtocol.fromServer.ReportEquStatus;
|
|
31
|
31
|
import com.qnbar.smc.socketProtocol.fromServer.VerifyCode;
|
|
32
|
32
|
import com.qnbar.smc.socketProtocol.toServer.EquipmentStatus;
|
|
|
33
|
+import com.qnbar.smc.socketProtocol.toServer.Heartbeat;
|
|
33
|
34
|
import com.qnbar.smc.socketProtocol.toServer.SocketSendMsg;
|
|
34
|
35
|
import com.qnbar.smc.utils.LightOperationUtils;
|
|
35
|
36
|
import com.telink.bluetooth.light.ConnectionStatus;
|
|
...
|
...
|
@@ -66,7 +67,7 @@ public class SocketService1 extends BaseService { |
|
66
|
67
|
|
|
67
|
68
|
// public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703;
|
|
68
|
69
|
/*
|
|
69
|
|
- * 10001 //服务器发送了命令(带命令的返回消息),这个一般是服务器主动发消息的时候code为这个值
|
|
|
70
|
+ 10001 //服务器发送了命令(带命令的返回消息),这个一般是服务器主动发消息的时候code为这个值
|
|
70
|
71
|
10002 //连接(认证)失败
|
|
71
|
72
|
10003 //还未注册连接就进行认证
|
|
72
|
73
|
10004 //终端编号未传
|
|
...
|
...
|
@@ -96,6 +97,7 @@ public class SocketService1 extends BaseService { |
|
96
|
97
|
private static final int REPORT_EQU_STATUS = 50003;//返回设备状态信息
|
|
97
|
98
|
private static final int SET_EQU_STATUS = 50004;//返回设备状态信息
|
|
98
|
99
|
|
|
|
100
|
+ private static final int HEART_BEAT = 20025;
|
|
99
|
101
|
private static final int CMD_REPORT_EQU_STATUS = 20030;//上报设备状态信息
|
|
100
|
102
|
private static final int ROOM_HAS_REGISTERED = 1001;
|
|
101
|
103
|
private static final int ROOM_NOT_EXIST_M = 1002;
|
|
...
|
...
|
@@ -115,6 +117,7 @@ public class SocketService1 extends BaseService { |
|
115
|
117
|
private String serverHost = SERVER_HOST;
|
|
116
|
118
|
private int serverPort = SERVER_PORT;
|
|
117
|
119
|
|
|
|
120
|
+ public int heartbearNum = 0;
|
|
118
|
121
|
|
|
119
|
122
|
public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容
|
|
120
|
123
|
// public String testRoomSn = "R170413034374";
|
|
...
|
...
|
@@ -133,18 +136,45 @@ public class SocketService1 extends BaseService { |
|
133
|
136
|
AtomicBoolean sendRegister = new AtomicBoolean(false);
|
|
134
|
137
|
AtomicInteger heartBeatErrorCount = new AtomicInteger(0);
|
|
135
|
138
|
|
|
136
|
|
- ICinemaControl iPlayer;
|
|
|
139
|
+ public ICinemaControl iPlayer=null;
|
|
|
140
|
+ private ServiceConnection conn = new ServiceConnection() {
|
|
|
141
|
+ public void onServiceConnected(ComponentName className, IBinder service) {
|
|
|
142
|
+ Log.d("yao", "ServiceConnection -> onServiceConnected");
|
|
|
143
|
+ iPlayer = ICinemaControl.Stub.asInterface(service);
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ public void onServiceDisconnected(ComponentName className) {
|
|
|
147
|
+ };
|
|
|
148
|
+ };
|
|
|
149
|
+
|
|
|
150
|
+ public Runnable heartBeatRunnable = new Runnable() {
|
|
137
|
151
|
|
|
138
|
|
- private Runnable heartBeatRunnable = new Runnable() {
|
|
139
|
152
|
@Override
|
|
140
|
153
|
public void run() {
|
|
141
|
154
|
mHandler.postDelayed(this, HEART_BEAT_RATE);
|
|
142
|
155
|
//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket
|
|
143
|
|
- final String s = new Gson().toJson(
|
|
144
|
|
- new SocketSendMsg().contractHeartBeatMsg(testRoomSn));
|
|
145
|
|
- boolean isSuccess = sendMsg(s + END_SYMBOL);
|
|
|
156
|
+ Heartbeat heartbeat = new Heartbeat();
|
|
|
157
|
+ if (heartbearNum > 10)
|
|
|
158
|
+ {
|
|
|
159
|
+ heartbeat.setLightStatus( getLightStatus() );
|
|
|
160
|
+ heartbeat.setPlayStatus( getPlayStatus() );
|
|
|
161
|
+ heartbeat.setVolume( getAudioVolume()/6 + 1 );
|
|
|
162
|
+ }
|
|
|
163
|
+ else
|
|
|
164
|
+ {
|
|
|
165
|
+ heartbearNum++;
|
|
|
166
|
+ }
|
|
|
167
|
+ heartbeat.setRoom_sn(testRoomSn);
|
|
|
168
|
+ MainRequest rep = new MainRequest();
|
|
|
169
|
+ rep.setCmd(HEART_BEAT);
|
|
|
170
|
+ rep.setData(heartbeat);
|
|
|
171
|
+ String msg = gson.toJson(rep);
|
|
|
172
|
+// final String msg = new Gson().toJson(
|
|
|
173
|
+// new SocketSendMsg().contractHeartBeatMsg(testRoomSn));
|
|
|
174
|
+ boolean isSuccess = sendMsg(msg + END_SYMBOL);
|
|
146
|
175
|
if (!isSuccess) {
|
|
147
|
176
|
LogUtils.i(TAG, "send heart beat error restart");
|
|
|
177
|
+ Log.d("heartbeat content",msg);
|
|
148
|
178
|
}
|
|
149
|
179
|
}
|
|
150
|
180
|
};
|
|
...
|
...
|
@@ -175,7 +205,7 @@ public class SocketService1 extends BaseService { |
|
175
|
205
|
super.onCreate();
|
|
176
|
206
|
LogUtils.i(TAG, "onCreate");
|
|
177
|
207
|
bindService(new Intent(SocketService1.this, CinemaControlService.class), conn, Context.BIND_AUTO_CREATE);
|
|
178
|
|
- startService(new Intent(SocketService1.this, CinemaControlService.class));
|
|
|
208
|
+// startService(new Intent(SocketService1.this, CinemaControlService.class));
|
|
179
|
209
|
}
|
|
180
|
210
|
|
|
181
|
211
|
@Override
|
|
...
|
...
|
@@ -188,8 +218,6 @@ public class SocketService1 extends BaseService { |
|
188
|
218
|
case 0:
|
|
189
|
219
|
serverHost = SERVER_HOST_ONLINE;
|
|
190
|
220
|
serverPort = SERVER_PORT_ONLINE;
|
|
191
|
|
-// serverHost = "192.168.200.217";
|
|
192
|
|
-// serverPort = 9501;
|
|
193
|
221
|
break;
|
|
194
|
222
|
case 1:
|
|
195
|
223
|
serverHost = SERVER_HOST_DEVELOP;
|
|
...
|
...
|
@@ -568,34 +596,41 @@ public class SocketService1 extends BaseService { |
|
568
|
596
|
private void reportEquStatus(String serverId,int lightSet) {
|
|
569
|
597
|
//填充返回数据
|
|
570
|
598
|
int volume = getAudioVolume()/6 + 1;
|
|
571
|
|
- int lightStatus = 2;
|
|
572
|
|
- int playStatus = 0;
|
|
573
|
|
-
|
|
574
|
|
- try {
|
|
575
|
|
- playStatus = iPlayer.getCurrentStatus();
|
|
576
|
|
- Log.d("ReportInfo","playStatus:"+playStatus);
|
|
577
|
|
- } catch (RemoteException e) {
|
|
578
|
|
- e.printStackTrace();
|
|
579
|
|
- }
|
|
580
|
|
- if (playStatus == 0) {
|
|
581
|
|
- boolean bool = ActivityCollector.isActivityExist(AdsPreVideoPlayerActivity.class);
|
|
582
|
|
- Log.d("ReportInfo","广告状态:"+bool);
|
|
583
|
|
- if(bool) {
|
|
584
|
|
- playStatus = 3;
|
|
585
|
|
- }
|
|
586
|
|
- }
|
|
|
599
|
+ int playStatus = getPlayStatus();
|
|
|
600
|
+ int lightStatus = 0;
|
|
|
601
|
+
|
|
|
602
|
+// try {
|
|
|
603
|
+// playStatus = iPlayer.getCurrentStatus();
|
|
|
604
|
+// Log.d("ReportInfo","playStatus:"+playStatus);
|
|
|
605
|
+// } catch (RemoteException e) {
|
|
|
606
|
+// e.printStackTrace();
|
|
|
607
|
+// }
|
|
|
608
|
+// if (playStatus == 0) {
|
|
|
609
|
+// boolean bool = ActivityCollector.isActivityExist(AdsPreVideoPlayerActivity.class);
|
|
|
610
|
+// Log.d("ReportInfo","广告状态:"+bool);
|
|
|
611
|
+// if(bool) {
|
|
|
612
|
+// playStatus = 3;
|
|
|
613
|
+// }
|
|
|
614
|
+// }
|
|
587
|
615
|
|
|
588
|
616
|
if (lightSet == 1 || lightSet == 2) {
|
|
589
|
617
|
lightStatus = lightSet;
|
|
590
|
618
|
} else {
|
|
591
|
|
- ConnectionStatus stu = Lights.getInstance().getByMeshAddress(((FangTangApplication) getApplication()).getConnectDevice().meshAddress).status;
|
|
592
|
|
- if( Lights.getInstance().getByMeshAddress(
|
|
593
|
|
- ((FangTangApplication) getApplication()).getConnectDevice().meshAddress).status == ConnectionStatus.ON ) {
|
|
594
|
|
- Log.d("ReportInfo","lightStatus==1");
|
|
595
|
|
- lightStatus = 1;
|
|
596
|
|
- } else {
|
|
597
|
|
- Log.d("ReportInfo", "lightStatus:"+stu);
|
|
598
|
|
- }
|
|
|
619
|
+// try {
|
|
|
620
|
+// ConnectionStatus stu = Lights.getInstance().
|
|
|
621
|
+// getByMeshAddress(((FangTangApplication) getApplication()).
|
|
|
622
|
+// getConnectDevice().meshAddress).status;
|
|
|
623
|
+// if( stu == ConnectionStatus.ON ) {
|
|
|
624
|
+// Log.d("ReportInfo","lightStatus==1");
|
|
|
625
|
+// lightStatus = 1;
|
|
|
626
|
+// } else {
|
|
|
627
|
+// Log.d("ReportInfo", "lightStatus:"+stu);
|
|
|
628
|
+// }
|
|
|
629
|
+// } catch (Exception e) {
|
|
|
630
|
+// e.printStackTrace();
|
|
|
631
|
+// lightStatus = 0;//获取失败
|
|
|
632
|
+// }
|
|
|
633
|
+ lightStatus = getLightStatus();
|
|
599
|
634
|
}
|
|
600
|
635
|
|
|
601
|
636
|
EquipmentStatus equStatus = new EquipmentStatus();
|
|
...
|
...
|
@@ -678,12 +713,53 @@ public class SocketService1 extends BaseService { |
|
678
|
713
|
|
|
679
|
714
|
/*--命令处理-end-----------------------------------*/
|
|
680
|
715
|
|
|
681
|
|
- private int getAudioVolume() {
|
|
|
716
|
+ public int getAudioVolume() {
|
|
682
|
717
|
AudioManager mAudioManager;
|
|
683
|
718
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
684
|
719
|
return mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
|
|
685
|
720
|
}
|
|
686
|
721
|
|
|
|
722
|
+ public int getPlayStatus() {
|
|
|
723
|
+ int playStatus = 0;
|
|
|
724
|
+
|
|
|
725
|
+ try {
|
|
|
726
|
+ playStatus = iPlayer.getCurrentStatus();
|
|
|
727
|
+ Log.d("ReportInfo","playStatus:"+playStatus);
|
|
|
728
|
+ } catch (RemoteException e) {
|
|
|
729
|
+ e.printStackTrace();
|
|
|
730
|
+ }
|
|
|
731
|
+ if (playStatus == 0) {
|
|
|
732
|
+ boolean bool = ActivityCollector.isActivityExist(AdsPreVideoPlayerActivity.class);
|
|
|
733
|
+ Log.d("ReportInfo","广告状态:"+bool);
|
|
|
734
|
+ if(bool) {
|
|
|
735
|
+ playStatus = 3;
|
|
|
736
|
+ }
|
|
|
737
|
+ }
|
|
|
738
|
+
|
|
|
739
|
+ return playStatus;
|
|
|
740
|
+ }
|
|
|
741
|
+
|
|
|
742
|
+ public int getLightStatus() {
|
|
|
743
|
+ int lightStatus = 2;
|
|
|
744
|
+
|
|
|
745
|
+ try {
|
|
|
746
|
+ ConnectionStatus stu = Lights.getInstance().
|
|
|
747
|
+ getByMeshAddress(((FangTangApplication) getApplication()).
|
|
|
748
|
+ getConnectDevice().meshAddress).status;
|
|
|
749
|
+ if( stu == ConnectionStatus.ON ) {
|
|
|
750
|
+ Log.d("ReportInfo","lightStatus==1");
|
|
|
751
|
+ lightStatus = 1;
|
|
|
752
|
+ } else {
|
|
|
753
|
+ Log.d("ReportInfo", "lightStatus:"+stu);
|
|
|
754
|
+ }
|
|
|
755
|
+ } catch (Exception e) {
|
|
|
756
|
+ e.printStackTrace();
|
|
|
757
|
+ lightStatus = 0;//获取失败
|
|
|
758
|
+ }
|
|
|
759
|
+
|
|
|
760
|
+ return lightStatus;
|
|
|
761
|
+ }
|
|
|
762
|
+
|
|
687
|
763
|
private int setAudioVolume(int volume) {
|
|
688
|
764
|
AudioManager mAudioManager;
|
|
689
|
765
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
...
|
...
|
@@ -718,14 +794,4 @@ public class SocketService1 extends BaseService { |
|
718
|
794
|
return now;
|
|
719
|
795
|
}
|
|
720
|
796
|
|
|
721
|
|
- private ServiceConnection conn = new ServiceConnection() {
|
|
722
|
|
- public void onServiceConnected(ComponentName className, IBinder service) {
|
|
723
|
|
- Log.d("yao", "ServiceConnection -> onServiceConnected");
|
|
724
|
|
- iPlayer = ICinemaControl.Stub.asInterface(service);
|
|
725
|
|
- }
|
|
726
|
|
-
|
|
727
|
|
- public void onServiceDisconnected(ComponentName className) {
|
|
728
|
|
- };
|
|
729
|
|
- };
|
|
730
|
|
-
|
|
731
|
797
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|