|
...
|
...
|
@@ -57,29 +57,12 @@ import java.util.concurrent.atomic.AtomicBoolean; |
|
57
|
57
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
58
|
58
|
|
|
59
|
59
|
public class SocketService1 extends BaseService {
|
|
60
|
|
- private static final String TAG = "BackService1";
|
|
|
60
|
+ private static final String TAG = "BackService";
|
|
61
|
61
|
private static final long HEART_BEAT_RATE = 2 * 1000;
|
|
62
|
62
|
private final long READ_THREAD_DEFAULT_SLEEP_MTIME = 100;
|
|
63
|
63
|
public static final int JUST_OPEN_DOOR = 1701;
|
|
64
|
64
|
public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703;
|
|
65
|
65
|
public static final int USER_OPEN_DOOR = 1704;
|
|
66
|
|
-
|
|
67
|
|
- // public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703;
|
|
68
|
|
- /*
|
|
69
|
|
- 10001 //服务器发送了命令(带命令的返回消息),这个一般是服务器主动发消息的时候code为这个值
|
|
70
|
|
- 10002 //连接(认证)失败
|
|
71
|
|
- 10003 //还未注册连接就进行认证
|
|
72
|
|
- 10004 //终端编号未传
|
|
73
|
|
- 10005 //心跳异常,没有找到房间连接信息
|
|
74
|
|
- 10006 //心跳异常,连接标识符不一致
|
|
75
|
|
- 10007 //收到未知命令
|
|
76
|
|
- 10008 //收到无法解析的消息
|
|
77
|
|
- 10009 //已经认证过了,不允许再认证
|
|
78
|
|
- 10010 //room_sn 已连接,不能再连接
|
|
79
|
|
- 9997 //心跳成功
|
|
80
|
|
- 9998 //请求认证被服务器接受了,服务器返回了认证码
|
|
81
|
|
- 9999 //认证成功,可以开始心跳了
|
|
82
|
|
- */
|
|
83
|
66
|
private static final int HEART_BEAT_SUCCESS = 9997;
|
|
84
|
67
|
private static final int RETURN_VERIFY_CODE = 9998;
|
|
85
|
68
|
private static final int VERIFY_SUCCESS = 9999;
|
|
...
|
...
|
@@ -116,13 +99,9 @@ public class SocketService1 extends BaseService { |
|
116
|
99
|
public int heartbeatNum = 0;
|
|
117
|
100
|
|
|
118
|
101
|
public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容
|
|
119
|
|
- // public String testRoomSn = "R170413034374";
|
|
120
|
102
|
public String testRoomSn = "c";
|
|
121
|
103
|
|
|
122
|
|
- // private ReadThread mReadThread;
|
|
123
|
104
|
private Gson gson = new Gson();
|
|
124
|
|
-
|
|
125
|
|
- // private WeakReference<Socket> mSocket;
|
|
126
|
105
|
private Socket socket = null;
|
|
127
|
106
|
StringBuilder readingMsg = new StringBuilder();
|
|
128
|
107
|
|
|
...
|
...
|
@@ -135,11 +114,12 @@ public class SocketService1 extends BaseService { |
|
135
|
114
|
public ICinemaControl iPlayer = null;
|
|
136
|
115
|
private ServiceConnection conn = new ServiceConnection() {
|
|
137
|
116
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
138
|
|
- Log.d("yao", "ServiceConnection -> onServiceConnected");
|
|
|
117
|
+ LogUtils.i("bind cinema control service success");
|
|
139
|
118
|
iPlayer = ICinemaControl.Stub.asInterface(service);
|
|
140
|
119
|
}
|
|
141
|
120
|
|
|
142
|
121
|
public void onServiceDisconnected(ComponentName className) {
|
|
|
122
|
+ LogUtils.i("cinema control service error");
|
|
143
|
123
|
}
|
|
144
|
124
|
};
|
|
145
|
125
|
|
|
...
|
...
|
@@ -162,12 +142,9 @@ public class SocketService1 extends BaseService { |
|
162
|
142
|
rep.setCmd(HEART_BEAT);
|
|
163
|
143
|
rep.setData(heartbeat);
|
|
164
|
144
|
String msg = gson.toJson(rep);
|
|
165
|
|
-// final String msg = new Gson().toJson(
|
|
166
|
|
-// new SocketSendMsg().contractHeartBeatMsg(testRoomSn));
|
|
167
|
145
|
boolean isSuccess = sendMsg(msg + END_SYMBOL);
|
|
168
|
146
|
if (!isSuccess) {
|
|
169
|
147
|
LogUtils.i(TAG, "send heart beat error restart");
|
|
170
|
|
- Log.d("heartbeat content", msg);
|
|
171
|
148
|
}
|
|
172
|
149
|
}
|
|
173
|
150
|
};
|
|
...
|
...
|
@@ -205,7 +182,6 @@ public class SocketService1 extends BaseService { |
|
205
|
182
|
super.onStartCommand(intent, flags, startId);
|
|
206
|
183
|
LogUtils.i(TAG, "onStartCommand");
|
|
207
|
184
|
int ftTest = Utils.getInt(this, "ft-test", 0);
|
|
208
|
|
- Log.d("Host", "" + ftTest);
|
|
209
|
185
|
switch (ftTest) {
|
|
210
|
186
|
case 0:
|
|
211
|
187
|
serverHost = SERVER_HOST_ONLINE;
|
|
...
|
...
|
@@ -229,7 +205,7 @@ public class SocketService1 extends BaseService { |
|
229
|
205
|
}
|
|
230
|
206
|
|
|
231
|
207
|
LogUtils.i("room-info", "room info not null");
|
|
232
|
|
- RoomInfo roomInfo = null;
|
|
|
208
|
+ RoomInfo roomInfo;
|
|
233
|
209
|
try {
|
|
234
|
210
|
roomInfo = gson.fromJson(roomInfoStr, RoomInfo.class);
|
|
235
|
211
|
LogUtils.i("room-info", "room info room_sn update");
|
|
...
|
...
|
@@ -337,14 +313,12 @@ public class SocketService1 extends BaseService { |
|
337
|
313
|
&& !socket.isInputShutdown()
|
|
338
|
314
|
&& ((length = is.read(buffer)) > 0)) {
|
|
339
|
315
|
String tmp = new String(Arrays.copyOf(buffer, length));
|
|
340
|
|
- LogUtils.d("recvMsg", msgId + ":" + length + ":" + tmp);
|
|
341
|
316
|
readingMsg.append(tmp);
|
|
342
|
317
|
int pos = readingMsg.indexOf(END_SYMBOL);
|
|
343
|
318
|
if (pos != -1) {
|
|
344
|
319
|
msg.setLength(0);
|
|
345
|
320
|
msg.append(readingMsg.substring(0, pos));
|
|
346
|
321
|
readingMsg.delete(0, pos + END_SYMBOL.length());
|
|
347
|
|
- LogUtils.d("recvMsg", msgId + ":" + length + ":" + msg);
|
|
348
|
322
|
return true;
|
|
349
|
323
|
}
|
|
350
|
324
|
msgId++;
|
|
...
|
...
|
@@ -412,12 +386,9 @@ public class SocketService1 extends BaseService { |
|
412
|
386
|
sendRegister.set(true);
|
|
413
|
387
|
}
|
|
414
|
388
|
|
|
415
|
|
- LogUtils.d(TAG, "begin to recv msg");
|
|
416
|
|
-
|
|
417
|
389
|
sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME;
|
|
418
|
390
|
while (recvMsg(message)) {
|
|
419
|
391
|
sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME;
|
|
420
|
|
- LogUtils.d("recvMsg", "logic:" + message);
|
|
421
|
392
|
LogUtils.d(TAG, "recv msg:" + message);
|
|
422
|
393
|
MainResponse socketResponse;
|
|
423
|
394
|
try {
|
|
...
|
...
|
@@ -540,23 +511,20 @@ public class SocketService1 extends BaseService { |
|
540
|
511
|
e.printStackTrace();
|
|
541
|
512
|
}
|
|
542
|
513
|
break;
|
|
543
|
|
-
|
|
544
|
|
- case REPORT_EQU_STATUS://获取声音,灯光,播放暂停状态
|
|
|
514
|
+ case REPORT_EQU_STATUS:
|
|
|
515
|
+ //获取声音,灯光,播放暂停状态并上报
|
|
545
|
516
|
//获取serverId
|
|
546
|
517
|
ReportEquStatus rps = gson.fromJson(socketResponse.getData(), ReportEquStatus.class);
|
|
547
|
518
|
reportEquStatus(rps.getServerId(), 0);
|
|
548
|
519
|
break;
|
|
549
|
|
-
|
|
550
|
520
|
case SET_EQU_STATUS://设置声音,灯光,播放暂停
|
|
551
|
|
- Log.d("ReportInfo", "收到控制命令:" + socketResponse.getData());
|
|
|
521
|
+ LogUtils.i("ReportInfo", "收到控制命令:" + socketResponse.getData());
|
|
552
|
522
|
EquipmentControl equc = gson.fromJson(socketResponse.getData(), EquipmentControl.class);
|
|
553
|
523
|
setEquipmentStatus(equc);
|
|
554
|
524
|
break;
|
|
555
|
525
|
}
|
|
556
|
526
|
}
|
|
557
|
527
|
|
|
558
|
|
- /*--命令处理-start-----------------------------------*/
|
|
559
|
|
-
|
|
560
|
528
|
private void openDoor(OpenDoor openDoorResponse) {
|
|
561
|
529
|
switch (openDoorResponse.getUser()) {
|
|
562
|
530
|
//10用户,20管理员,默认值为0
|
|
...
|
...
|
@@ -572,7 +540,6 @@ public class SocketService1 extends BaseService { |
|
572
|
540
|
} else {
|
|
573
|
541
|
sendMessage(USER_OPEN_DOOR, "user open the door");
|
|
574
|
542
|
}
|
|
575
|
|
- Log.d("op", "开门");
|
|
576
|
543
|
break;
|
|
577
|
544
|
case 20:
|
|
578
|
545
|
LogUtils.i(TAG, "admin open the door,del the log");
|
|
...
|
...
|
@@ -673,8 +640,6 @@ public class SocketService1 extends BaseService { |
|
673
|
640
|
reportEquStatus(equc.getServerId(), equc.getLightCtl());
|
|
674
|
641
|
}
|
|
675
|
642
|
|
|
676
|
|
-/*--命令处理-end-----------------------------------*/
|
|
677
|
|
-
|
|
678
|
643
|
public int getAudioVolume() {
|
|
679
|
644
|
AudioManager mAudioManager;
|
|
680
|
645
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
...
|
...
|
|