|
...
|
...
|
@@ -34,6 +34,7 @@ import com.qnbar.smc.socketProtocol.toServer.Heartbeat; |
|
34
|
34
|
import com.qnbar.smc.socketProtocol.toServer.SocketSendMsg;
|
|
35
|
35
|
import com.qnbar.smc.utils.LightOperationUtils;
|
|
36
|
36
|
import com.telink.bluetooth.light.ConnectionStatus;
|
|
|
37
|
+import com.telink.bluetooth.light.DeviceInfo;
|
|
37
|
38
|
import com.xgimi.gimicinema.ICinemaControl;
|
|
38
|
39
|
import com.xgimi.gimicinema.activity.AdsPreVideoPlayerActivity;
|
|
39
|
40
|
import com.xgimi.gimicinema.activity.MainActivity;
|
|
...
|
...
|
@@ -136,7 +137,7 @@ public class SocketService1 extends BaseService { |
|
136
|
137
|
AtomicBoolean sendRegister = new AtomicBoolean(false);
|
|
137
|
138
|
AtomicInteger heartBeatErrorCount = new AtomicInteger(0);
|
|
138
|
139
|
|
|
139
|
|
- public ICinemaControl iPlayer=null;
|
|
|
140
|
+ public ICinemaControl iPlayer = null;
|
|
140
|
141
|
private ServiceConnection conn = new ServiceConnection() {
|
|
141
|
142
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
142
|
143
|
Log.d("yao", "ServiceConnection -> onServiceConnected");
|
|
...
|
...
|
@@ -144,7 +145,9 @@ public class SocketService1 extends BaseService { |
|
144
|
145
|
}
|
|
145
|
146
|
|
|
146
|
147
|
public void onServiceDisconnected(ComponentName className) {
|
|
147
|
|
- };
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ ;
|
|
148
|
151
|
};
|
|
149
|
152
|
|
|
150
|
153
|
public Runnable heartBeatRunnable = new Runnable() {
|
|
...
|
...
|
@@ -154,14 +157,11 @@ public class SocketService1 extends BaseService { |
|
154
|
157
|
mHandler.postDelayed(this, HEART_BEAT_RATE);
|
|
155
|
158
|
//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket
|
|
156
|
159
|
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
|
|
- {
|
|
|
160
|
+ if (heartbearNum > 10) {
|
|
|
161
|
+ heartbeat.setLightStatus(getLightStatus());
|
|
|
162
|
+ heartbeat.setPlayStatus(getPlayStatus());
|
|
|
163
|
+ heartbeat.setVolume(getAudioVolume() / 6 + 1);
|
|
|
164
|
+ } else {
|
|
165
|
165
|
heartbearNum++;
|
|
166
|
166
|
}
|
|
167
|
167
|
heartbeat.setRoom_sn(testRoomSn);
|
|
...
|
...
|
@@ -174,7 +174,7 @@ public class SocketService1 extends BaseService { |
|
174
|
174
|
boolean isSuccess = sendMsg(msg + END_SYMBOL);
|
|
175
|
175
|
if (!isSuccess) {
|
|
176
|
176
|
LogUtils.i(TAG, "send heart beat error restart");
|
|
177
|
|
- Log.d("heartbeat content",msg);
|
|
|
177
|
+ Log.d("heartbeat content", msg);
|
|
178
|
178
|
}
|
|
179
|
179
|
}
|
|
180
|
180
|
};
|
|
...
|
...
|
@@ -213,7 +213,7 @@ public class SocketService1 extends BaseService { |
|
213
|
213
|
super.onStartCommand(intent, flags, startId);
|
|
214
|
214
|
LogUtils.i(TAG, "onStartCommand");
|
|
215
|
215
|
int ftTest = Utils.getInt(this, "ft-test", 0);
|
|
216
|
|
- Log.d("Host", ""+ftTest);
|
|
|
216
|
+ Log.d("Host", "" + ftTest);
|
|
217
|
217
|
switch (ftTest) {
|
|
218
|
218
|
case 0:
|
|
219
|
219
|
serverHost = SERVER_HOST_ONLINE;
|
|
...
|
...
|
@@ -333,8 +333,7 @@ public class SocketService1 extends BaseService { |
|
333
|
333
|
int length = 0;
|
|
334
|
334
|
while (!socket.isClosed()
|
|
335
|
335
|
&& !socket.isInputShutdown()
|
|
336
|
|
- && ((length = is.read(buffer)) > 0)
|
|
337
|
|
- ) {
|
|
|
336
|
+ && ((length = is.read(buffer)) > 0)) {
|
|
338
|
337
|
String tmp = new String(Arrays.copyOf(buffer, length));
|
|
339
|
338
|
readingMsg.append(tmp);
|
|
340
|
339
|
int pos = readingMsg.indexOf(END_SYMBOL);
|
|
...
|
...
|
@@ -375,7 +374,6 @@ public class SocketService1 extends BaseService { |
|
375
|
374
|
e.printStackTrace();
|
|
376
|
375
|
LogUtils.e(TAG, "init socket thread error,restart again after " + HEART_BEAT_RATE / 1000 + " seconds");
|
|
377
|
376
|
}
|
|
378
|
|
-
|
|
379
|
377
|
try {
|
|
380
|
378
|
Thread.sleep(1000);
|
|
381
|
379
|
} catch (InterruptedException e1) {
|
|
...
|
...
|
@@ -463,7 +461,7 @@ public class SocketService1 extends BaseService { |
|
463
|
461
|
LogUtils.i(TAG, "RETURN_VERIFY_CODE");
|
|
464
|
462
|
if (!TextUtils.isEmpty(socketResponse.getData())) {
|
|
465
|
463
|
VerifyCode verifyResponse = gson.fromJson(socketResponse.getData(), VerifyCode.class);
|
|
466
|
|
- if(!TextUtils.isEmpty(verifyResponse.getVerify())){
|
|
|
464
|
+ if (!TextUtils.isEmpty(verifyResponse.getVerify())) {
|
|
467
|
465
|
String verifyMsg = AuthCode.getDecodeStr(verifyResponse.getVerify());
|
|
468
|
466
|
SocketSendMsg ssm = new SocketSendMsg().contractVerifyMsg(testRoomSn, verifyMsg);
|
|
469
|
467
|
String msg = gson.toJson(ssm) + END_SYMBOL;
|
|
...
|
...
|
@@ -505,11 +503,11 @@ public class SocketService1 extends BaseService { |
|
505
|
503
|
|
|
506
|
504
|
/**
|
|
507
|
505
|
* 处理服务器发送的命令
|
|
|
506
|
+ *
|
|
508
|
507
|
* @param socketResponse
|
|
509
|
508
|
*/
|
|
510
|
509
|
private void serverCommandDeal(MainResponse socketResponse) {
|
|
511
|
|
- switch (socketResponse.getCmd())
|
|
512
|
|
- {
|
|
|
510
|
+ switch (socketResponse.getCmd()) {
|
|
513
|
511
|
case OPEN_DOOR://开门
|
|
514
|
512
|
if (socketResponse.getData() != null) {
|
|
515
|
513
|
OpenDoor openDoorResponse = gson.fromJson(socketResponse.getData(), OpenDoor.class);
|
|
...
|
...
|
@@ -539,16 +537,15 @@ public class SocketService1 extends BaseService { |
|
539
|
537
|
break;
|
|
540
|
538
|
|
|
541
|
539
|
case REPORT_EQU_STATUS://获取声音,灯光,播放暂停状态
|
|
542
|
|
- long time1 = System.currentTimeMillis();
|
|
543
|
|
- Log.d("ReportInfo","收到上报命令");
|
|
|
540
|
+ Log.d("ReportInfo", "收到上报命令");
|
|
544
|
541
|
//获取serverId
|
|
545
|
542
|
ReportEquStatus rps = gson.fromJson(socketResponse.getData(), ReportEquStatus.class);
|
|
546
|
543
|
// String serverId = rps.getServerId();
|
|
547
|
|
- reportEquStatus(rps.getServerId(),0);
|
|
|
544
|
+ reportEquStatus(rps.getServerId(), 0);
|
|
548
|
545
|
break;
|
|
549
|
546
|
|
|
550
|
547
|
case SET_EQU_STATUS://设置声音,灯光,播放暂停
|
|
551
|
|
- Log.d("ReportInfo","收到控制命令:"+socketResponse.getData());
|
|
|
548
|
+ Log.d("ReportInfo", "收到控制命令:" + socketResponse.getData());
|
|
552
|
549
|
EquipmentControl equc = gson.fromJson(socketResponse.getData(), EquipmentControl.class);
|
|
553
|
550
|
setEquipmentStatus(equc);
|
|
554
|
551
|
break;
|
|
...
|
...
|
@@ -572,7 +569,7 @@ public class SocketService1 extends BaseService { |
|
572
|
569
|
} else {
|
|
573
|
570
|
sendMessage(USER_OPEN_DOOR, "user open the door");
|
|
574
|
571
|
}
|
|
575
|
|
- Log.d("op","开门");
|
|
|
572
|
+ Log.d("op", "开门");
|
|
576
|
573
|
break;
|
|
577
|
574
|
case 20:
|
|
578
|
575
|
LogUtils.i(TAG, "admin open the door,del the log");
|
|
...
|
...
|
@@ -593,43 +590,14 @@ public class SocketService1 extends BaseService { |
|
593
|
590
|
}
|
|
594
|
591
|
}
|
|
595
|
592
|
|
|
596
|
|
- private void reportEquStatus(String serverId,int lightSet) {
|
|
|
593
|
+ private void reportEquStatus(String serverId, int lightSet) {
|
|
597
|
594
|
//填充返回数据
|
|
598
|
|
- int volume = getAudioVolume()/6 + 1;
|
|
|
595
|
+ int volume = getAudioVolume() / 6 + 1;
|
|
599
|
596
|
int playStatus = getPlayStatus();
|
|
600
|
597
|
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
|
|
-// }
|
|
615
|
|
-
|
|
616
|
598
|
if (lightSet == 1 || lightSet == 2) {
|
|
617
|
599
|
lightStatus = lightSet;
|
|
618
|
600
|
} else {
|
|
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
|
601
|
lightStatus = getLightStatus();
|
|
634
|
602
|
}
|
|
635
|
603
|
|
|
...
|
...
|
@@ -645,31 +613,36 @@ public class SocketService1 extends BaseService { |
|
645
|
613
|
rep.setData(equStatus);
|
|
646
|
614
|
String msg = gson.toJson(rep) + END_SYMBOL;
|
|
647
|
615
|
sendMsg(msg);
|
|
648
|
|
- Log.d("ReportInfo",msg);
|
|
|
616
|
+ Log.d("ReportInfo", msg);
|
|
649
|
617
|
}
|
|
650
|
618
|
|
|
|
619
|
+ private static final int SERVER_CMD_OPEN_LIGHT = 1;
|
|
|
620
|
+ private static final int SERVER_CMD_CLOSE_LIGHT = 2;
|
|
|
621
|
+
|
|
651
|
622
|
private void setLight(int op) {
|
|
652
|
|
- if (op == 1){//打开灯光
|
|
653
|
|
- Log.d("setEqu","打开灯光");
|
|
|
623
|
+ if (op == SERVER_CMD_OPEN_LIGHT) {//打开灯光
|
|
|
624
|
+ Log.d("setEqu", "打开灯光");
|
|
654
|
625
|
LightOperationUtils.open();
|
|
655
|
626
|
LightOperationUtils.setLightValue(5);
|
|
656
|
|
-
|
|
657
|
627
|
//延时增亮
|
|
658
|
|
- Timer timer=new Timer();//实例化Timer类
|
|
659
|
|
- timer.schedule(new TimerTask(){
|
|
660
|
|
- public void run(){
|
|
|
628
|
+ Timer timer = new Timer();//实例化Timer类
|
|
|
629
|
+ timer.schedule(new TimerTask() {
|
|
|
630
|
+ public void run() {
|
|
661
|
631
|
LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50));
|
|
662
|
|
- this.cancel();}},2000);//毫秒
|
|
663
|
|
- } else if(op == 2) {//关闭灯光
|
|
664
|
|
- Log.d("setEqu","关闭灯光");
|
|
|
632
|
+ this.cancel();
|
|
|
633
|
+ }
|
|
|
634
|
+ }, 2000);//毫秒
|
|
|
635
|
+ } else if (op == SERVER_CMD_CLOSE_LIGHT) {//关闭灯光
|
|
|
636
|
+ Log.d("setEqu", "关闭灯光");
|
|
665
|
637
|
LightOperationUtils.setLightValue(5);
|
|
666
|
|
-
|
|
667
|
638
|
//延时关闭
|
|
668
|
|
- Timer timer=new Timer();//实例化Timer类
|
|
669
|
|
- timer.schedule(new TimerTask(){
|
|
670
|
|
- public void run(){
|
|
|
639
|
+ Timer timer = new Timer();//实例化Timer类
|
|
|
640
|
+ timer.schedule(new TimerTask() {
|
|
|
641
|
+ public void run() {
|
|
671
|
642
|
LightOperationUtils.close();
|
|
672
|
|
- this.cancel();}},2000);//毫秒
|
|
|
643
|
+ this.cancel();
|
|
|
644
|
+ }
|
|
|
645
|
+ }, 2000);//毫秒
|
|
673
|
646
|
}
|
|
674
|
647
|
}
|
|
675
|
648
|
|
|
...
|
...
|
@@ -681,14 +654,11 @@ public class SocketService1 extends BaseService { |
|
681
|
654
|
e.printStackTrace();
|
|
682
|
655
|
}
|
|
683
|
656
|
|
|
684
|
|
- if (op == 1 && status == 2)
|
|
685
|
|
- {
|
|
686
|
|
- Log.d("setEqu","开始播放");
|
|
|
657
|
+ if (op == 1 && status == 2) {
|
|
|
658
|
+ Log.d("setEqu", "开始播放");
|
|
687
|
659
|
ShellUtils.execCommand("input keyevent 23", false);
|
|
688
|
|
- }
|
|
689
|
|
- else if (op == 2 && status == 1)
|
|
690
|
|
- {
|
|
691
|
|
- Log.d("setEqu","暂停播放");
|
|
|
660
|
+ } else if (op == 2 && status == 1) {
|
|
|
661
|
+ Log.d("setEqu", "暂停播放");
|
|
692
|
662
|
ShellUtils.execCommand("input keyevent 23", false);
|
|
693
|
663
|
}
|
|
694
|
664
|
}
|
|
...
|
...
|
@@ -700,15 +670,14 @@ public class SocketService1 extends BaseService { |
|
700
|
670
|
|
|
701
|
671
|
setAudioVolume(equc.getAudioCtl());
|
|
702
|
672
|
|
|
703
|
|
- if (equc.getLightCtl() != 0){
|
|
|
673
|
+ if (equc.getLightCtl() != 0) {
|
|
704
|
674
|
try {
|
|
705
|
675
|
Thread.sleep(500);
|
|
706
|
676
|
} catch (InterruptedException e) {
|
|
707
|
677
|
e.printStackTrace();
|
|
708
|
678
|
}
|
|
709
|
679
|
}
|
|
710
|
|
-
|
|
711
|
|
- reportEquStatus(equc.getServerId(),equc.getLightCtl());
|
|
|
680
|
+ reportEquStatus(equc.getServerId(), equc.getLightCtl());
|
|
712
|
681
|
}
|
|
713
|
682
|
|
|
714
|
683
|
/*--命令处理-end-----------------------------------*/
|
|
...
|
...
|
@@ -716,54 +685,57 @@ public class SocketService1 extends BaseService { |
|
716
|
685
|
public int getAudioVolume() {
|
|
717
|
686
|
AudioManager mAudioManager;
|
|
718
|
687
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
719
|
|
- return mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );
|
|
|
688
|
+ return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
|
720
|
689
|
}
|
|
721
|
690
|
|
|
722
|
691
|
public int getPlayStatus() {
|
|
723
|
692
|
int playStatus = 0;
|
|
724
|
|
-
|
|
|
693
|
+ if (iPlayer == null) {
|
|
|
694
|
+ return playStatus;
|
|
|
695
|
+ }
|
|
725
|
696
|
try {
|
|
726
|
697
|
playStatus = iPlayer.getCurrentStatus();
|
|
727
|
|
- Log.d("ReportInfo","playStatus:"+playStatus);
|
|
|
698
|
+ Log.d("ReportInfo", "playStatus:" + playStatus);
|
|
728
|
699
|
} catch (RemoteException e) {
|
|
729
|
700
|
e.printStackTrace();
|
|
730
|
701
|
}
|
|
731
|
702
|
if (playStatus == 0) {
|
|
732
|
703
|
boolean bool = ActivityCollector.isActivityExist(AdsPreVideoPlayerActivity.class);
|
|
733
|
|
- Log.d("ReportInfo","广告状态:"+bool);
|
|
734
|
|
- if(bool) {
|
|
|
704
|
+ Log.d("ReportInfo", "广告状态:" + bool);
|
|
|
705
|
+ if (bool) {
|
|
735
|
706
|
playStatus = 3;
|
|
736
|
707
|
}
|
|
737
|
708
|
}
|
|
738
|
|
-
|
|
739
|
709
|
return playStatus;
|
|
740
|
710
|
}
|
|
741
|
711
|
|
|
742
|
712
|
public int getLightStatus() {
|
|
743
|
713
|
int lightStatus = 2;
|
|
744
|
|
-
|
|
745
|
714
|
try {
|
|
|
715
|
+ DeviceInfo connectDevice = ((FangTangApplication) getApplication()).
|
|
|
716
|
+ getConnectDevice();
|
|
|
717
|
+ if (connectDevice == null) {
|
|
|
718
|
+ return lightStatus;
|
|
|
719
|
+ }
|
|
746
|
720
|
ConnectionStatus stu = Lights.getInstance().
|
|
747
|
|
- getByMeshAddress(((FangTangApplication) getApplication()).
|
|
748
|
|
- getConnectDevice().meshAddress).status;
|
|
749
|
|
- if( stu == ConnectionStatus.ON ) {
|
|
750
|
|
- Log.d("ReportInfo","lightStatus==1");
|
|
|
721
|
+ getByMeshAddress(connectDevice.meshAddress).status;
|
|
|
722
|
+ if (stu == ConnectionStatus.ON) {
|
|
|
723
|
+ Log.d("ReportInfo", "lightStatus==1");
|
|
751
|
724
|
lightStatus = 1;
|
|
752
|
725
|
} else {
|
|
753
|
|
- Log.d("ReportInfo", "lightStatus:"+stu);
|
|
|
726
|
+ Log.d("ReportInfo", "lightStatus:" + stu);
|
|
754
|
727
|
}
|
|
755
|
728
|
} catch (Exception e) {
|
|
756
|
729
|
e.printStackTrace();
|
|
757
|
730
|
lightStatus = 0;//获取失败
|
|
758
|
731
|
}
|
|
759
|
|
-
|
|
760
|
732
|
return lightStatus;
|
|
761
|
733
|
}
|
|
762
|
734
|
|
|
763
|
735
|
private int setAudioVolume(int volume) {
|
|
764
|
736
|
AudioManager mAudioManager;
|
|
765
|
737
|
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
|
766
|
|
- int now = getAudioVolume()/6;
|
|
|
738
|
+ int now = getAudioVolume() / 6;
|
|
767
|
739
|
|
|
768
|
740
|
if (volume == 0) {
|
|
769
|
741
|
return now;
|
|
...
|
...
|
@@ -772,22 +744,22 @@ public class SocketService1 extends BaseService { |
|
772
|
744
|
}
|
|
773
|
745
|
|
|
774
|
746
|
if (volume > now) {//加音量
|
|
775
|
|
- Log.d("setEqu","加音量"+now+":"+volume);
|
|
776
|
|
- while(now < volume) {
|
|
|
747
|
+ Log.d("setEqu", "加音量" + now + ":" + volume);
|
|
|
748
|
+ while (now < volume) {
|
|
777
|
749
|
mAudioManager.adjustStreamVolume(
|
|
778
|
750
|
AudioManager.STREAM_MUSIC,
|
|
779
|
751
|
AudioManager.ADJUST_RAISE,
|
|
780
|
752
|
AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
|
|
781
|
|
- now ++;
|
|
|
753
|
+ now++;
|
|
782
|
754
|
}
|
|
783
|
|
- } else if(volume < now) {//减音量
|
|
784
|
|
- Log.d("setEqu","减音量"+now+":"+volume);
|
|
785
|
|
- while(now > volume) {
|
|
|
755
|
+ } else if (volume < now) {//减音量
|
|
|
756
|
+ Log.d("setEqu", "减音量" + now + ":" + volume);
|
|
|
757
|
+ while (now > volume) {
|
|
786
|
758
|
mAudioManager.adjustStreamVolume(
|
|
787
|
759
|
AudioManager.STREAM_MUSIC,
|
|
788
|
760
|
AudioManager.ADJUST_LOWER,
|
|
789
|
761
|
AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
|
|
790
|
|
- now --;
|
|
|
762
|
+ now--;
|
|
791
|
763
|
}
|
|
792
|
764
|
}
|
|
793
|
765
|
|
...
|
...
|
|