Commit 5a9cdccd1e512d4e30731186ad634239f572efc5

Authored by jinyan.yi
1 parent 74ea5da4

心跳上报设备状态

@@ -19,6 +19,7 @@ public class RoomQrCodeInfo extends BaseModel { @@ -19,6 +19,7 @@ public class RoomQrCodeInfo extends BaseModel {
19 19
20 private String code; 20 private String code;
21 private String room_sn; 21 private String room_sn;
  22 + private String order_sn;
22 23
23 public String getCode() { 24 public String getCode() {
24 return code; 25 return code;
@@ -36,6 +37,14 @@ public class RoomQrCodeInfo extends BaseModel { @@ -36,6 +37,14 @@ public class RoomQrCodeInfo extends BaseModel {
36 this.room_sn = room_sn; 37 this.room_sn = room_sn;
37 } 38 }
38 39
  40 + public String getOrder_sn() {
  41 + return order_sn;
  42 + }
  43 +
  44 + public void setOrder_sn(String order_sn) {
  45 + this.order_sn = order_sn;
  46 + }
  47 +
39 @Override 48 @Override
40 public String toString() { 49 public String toString() {
41 return "DataEntity{" + 50 return "DataEntity{" +
@@ -659,7 +659,7 @@ public class SmartControlService extends BaseService implements EventListener<St @@ -659,7 +659,7 @@ public class SmartControlService extends BaseService implements EventListener<St
659 LogUtils.i(TAG, "order_sn not null:" + qrCodeInfo.toString()); 659 LogUtils.i(TAG, "order_sn not null:" + qrCodeInfo.toString());
660 String showMsg = ResUtils.getResResult(mContext, R.string.ads_promote, R.string.play_next_fill_name); 660 String showMsg = ResUtils.getResResult(mContext, R.string.ads_promote, R.string.play_next_fill_name);
661 CToast.makeText(mContext, showMsg, 30 * 1000).show(); 661 CToast.makeText(mContext, showMsg, 30 * 1000).show();
662 - presenter.getNextOrderInfo(SmartControlService.this, info.getData().getRoom_sn()); 662 + presenter.getNextOrderInfo(SmartControlService.this, info.getData().getOrder_sn());
663 } 663 }
664 } 664 }
665 665
@@ -30,6 +30,7 @@ import com.qnbar.smc.socketProtocol.fromServer.OpenDoor; @@ -30,6 +30,7 @@ import com.qnbar.smc.socketProtocol.fromServer.OpenDoor;
30 import com.qnbar.smc.socketProtocol.fromServer.ReportEquStatus; 30 import com.qnbar.smc.socketProtocol.fromServer.ReportEquStatus;
31 import com.qnbar.smc.socketProtocol.fromServer.VerifyCode; 31 import com.qnbar.smc.socketProtocol.fromServer.VerifyCode;
32 import com.qnbar.smc.socketProtocol.toServer.EquipmentStatus; 32 import com.qnbar.smc.socketProtocol.toServer.EquipmentStatus;
  33 +import com.qnbar.smc.socketProtocol.toServer.Heartbeat;
33 import com.qnbar.smc.socketProtocol.toServer.SocketSendMsg; 34 import com.qnbar.smc.socketProtocol.toServer.SocketSendMsg;
34 import com.qnbar.smc.utils.LightOperationUtils; 35 import com.qnbar.smc.utils.LightOperationUtils;
35 import com.telink.bluetooth.light.ConnectionStatus; 36 import com.telink.bluetooth.light.ConnectionStatus;
@@ -66,7 +67,7 @@ public class SocketService1 extends BaseService { @@ -66,7 +67,7 @@ public class SocketService1 extends BaseService {
66 67
67 // public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703; 68 // public static final int USER_OPEN_DOOR_AND_GET_MOVIE = 1703;
68 /* 69 /*
69 - * 10001 //服务器发送了命令(带命令的返回消息),这个一般是服务器主动发消息的时候code为这个值 70 + 10001 //服务器发送了命令(带命令的返回消息),这个一般是服务器主动发消息的时候code为这个值
70 10002 //连接(认证)失败 71 10002 //连接(认证)失败
71 10003 //还未注册连接就进行认证 72 10003 //还未注册连接就进行认证
72 10004 //终端编号未传 73 10004 //终端编号未传
@@ -96,6 +97,7 @@ public class SocketService1 extends BaseService { @@ -96,6 +97,7 @@ public class SocketService1 extends BaseService {
96 private static final int REPORT_EQU_STATUS = 50003;//返回设备状态信息 97 private static final int REPORT_EQU_STATUS = 50003;//返回设备状态信息
97 private static final int SET_EQU_STATUS = 50004;//返回设备状态信息 98 private static final int SET_EQU_STATUS = 50004;//返回设备状态信息
98 99
  100 + private static final int HEART_BEAT = 20025;
99 private static final int CMD_REPORT_EQU_STATUS = 20030;//上报设备状态信息 101 private static final int CMD_REPORT_EQU_STATUS = 20030;//上报设备状态信息
100 private static final int ROOM_HAS_REGISTERED = 1001; 102 private static final int ROOM_HAS_REGISTERED = 1001;
101 private static final int ROOM_NOT_EXIST_M = 1002; 103 private static final int ROOM_NOT_EXIST_M = 1002;
@@ -115,6 +117,7 @@ public class SocketService1 extends BaseService { @@ -115,6 +117,7 @@ public class SocketService1 extends BaseService {
115 private String serverHost = SERVER_HOST; 117 private String serverHost = SERVER_HOST;
116 private int serverPort = SERVER_PORT; 118 private int serverPort = SERVER_PORT;
117 119
  120 + public int heartbearNum = 0;
118 121
119 public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容 122 public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容
120 // public String testRoomSn = "R170413034374"; 123 // public String testRoomSn = "R170413034374";
@@ -133,18 +136,45 @@ public class SocketService1 extends BaseService { @@ -133,18 +136,45 @@ public class SocketService1 extends BaseService {
133 AtomicBoolean sendRegister = new AtomicBoolean(false); 136 AtomicBoolean sendRegister = new AtomicBoolean(false);
134 AtomicInteger heartBeatErrorCount = new AtomicInteger(0); 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 @Override 152 @Override
140 public void run() { 153 public void run() {
141 mHandler.postDelayed(this, HEART_BEAT_RATE); 154 mHandler.postDelayed(this, HEART_BEAT_RATE);
142 //就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket 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 if (!isSuccess) { 175 if (!isSuccess) {
147 LogUtils.i(TAG, "send heart beat error restart"); 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,7 +205,7 @@ public class SocketService1 extends BaseService {
175 super.onCreate(); 205 super.onCreate();
176 LogUtils.i(TAG, "onCreate"); 206 LogUtils.i(TAG, "onCreate");
177 bindService(new Intent(SocketService1.this, CinemaControlService.class), conn, Context.BIND_AUTO_CREATE); 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 @Override 211 @Override
@@ -188,8 +218,6 @@ public class SocketService1 extends BaseService { @@ -188,8 +218,6 @@ public class SocketService1 extends BaseService {
188 case 0: 218 case 0:
189 serverHost = SERVER_HOST_ONLINE; 219 serverHost = SERVER_HOST_ONLINE;
190 serverPort = SERVER_PORT_ONLINE; 220 serverPort = SERVER_PORT_ONLINE;
191 -// serverHost = "192.168.200.217";  
192 -// serverPort = 9501;  
193 break; 221 break;
194 case 1: 222 case 1:
195 serverHost = SERVER_HOST_DEVELOP; 223 serverHost = SERVER_HOST_DEVELOP;
@@ -568,34 +596,41 @@ public class SocketService1 extends BaseService { @@ -568,34 +596,41 @@ public class SocketService1 extends BaseService {
568 private void reportEquStatus(String serverId,int lightSet) { 596 private void reportEquStatus(String serverId,int lightSet) {
569 //填充返回数据 597 //填充返回数据
570 int volume = getAudioVolume()/6 + 1; 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 if (lightSet == 1 || lightSet == 2) { 616 if (lightSet == 1 || lightSet == 2) {
589 lightStatus = lightSet; 617 lightStatus = lightSet;
590 } else { 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 EquipmentStatus equStatus = new EquipmentStatus(); 636 EquipmentStatus equStatus = new EquipmentStatus();
@@ -678,12 +713,53 @@ public class SocketService1 extends BaseService { @@ -678,12 +713,53 @@ public class SocketService1 extends BaseService {
678 713
679 /*--命令处理-end-----------------------------------*/ 714 /*--命令处理-end-----------------------------------*/
680 715
681 - private int getAudioVolume() { 716 + public int getAudioVolume() {
682 AudioManager mAudioManager; 717 AudioManager mAudioManager;
683 mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 718 mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
684 return mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC ); 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 private int setAudioVolume(int volume) { 763 private int setAudioVolume(int volume) {
688 AudioManager mAudioManager; 764 AudioManager mAudioManager;
689 mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 765 mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
@@ -718,14 +794,4 @@ public class SocketService1 extends BaseService { @@ -718,14 +794,4 @@ public class SocketService1 extends BaseService {
718 return now; 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 }
1 package com.qnbar.smc.socketProtocol; 1 package com.qnbar.smc.socketProtocol;
2 2
  3 +import com.qnbar.smc.socketProtocol.toServer.Heartbeat;
  4 +
3 /** 5 /**
4 * Created by jinyan.yi on 2017/5/23. 6 * Created by jinyan.yi on 2017/5/23.
5 */ 7 */
@@ -31,4 +33,5 @@ public class MainRequest { @@ -31,4 +33,5 @@ public class MainRequest {
31 ", data=" + data + 33 ", data=" + data +
32 '}'; 34 '}';
33 } 35 }
  36 +
34 } 37 }
  1 +package com.qnbar.smc.socketProtocol.toServer;
  2 +
  3 +import com.qnbar.smc.socketProtocol.DataInfo;
  4 +
  5 +/**
  6 + * Created by jinyan.yi on 2017/6/14.
  7 + */
  8 +
  9 +public class Heartbeat extends DataInfo {
  10 + private int lightStatus;
  11 + private int volume;
  12 + private int playStatus;
  13 + private String room_sn;
  14 +
  15 + public int getLightStatus() {
  16 + return lightStatus;
  17 + }
  18 +
  19 + public void setLightStatus(int lightStatus) {
  20 + this.lightStatus = lightStatus;
  21 + }
  22 +
  23 + public int getVolume() {
  24 + return volume;
  25 + }
  26 +
  27 + public void setVolume(int volume) {
  28 + this.volume = volume;
  29 + }
  30 +
  31 + public int getPlayStatus() {
  32 + return playStatus;
  33 + }
  34 +
  35 + public void setPlayStatus(int playStatus) {
  36 + this.playStatus = playStatus;
  37 + }
  38 +
  39 + public String getRoom_sn() {
  40 + return room_sn;
  41 + }
  42 +
  43 + public void setRoom_sn(String room_sn) {
  44 + this.room_sn = room_sn;
  45 + }
  46 +
  47 + @Override
  48 + public String toString() {
  49 + return "Heartbeat{" +
  50 + "lightStatus=" + lightStatus +
  51 + ", volume=" + volume +
  52 + ", playStatus=" + playStatus +
  53 + ", room_sn='" + room_sn + '\'' +
  54 + '}';
  55 + }
  56 +}
1 -package com.qnbar.smc.soketProtocol;  
2 -  
3 -/**  
4 - * Created by jinyan.yi on 2017/5/23.  
5 - */  
6 -  
7 -public abstract class DataInfo {}  
Please register or login to post a comment