Showing
2 changed files
with
48 additions
and
69 deletions
| ... | ... | @@ -53,8 +53,6 @@ import java.io.InterruptedIOException; |
| 53 | 53 | import java.io.OutputStream; |
| 54 | 54 | import java.net.Socket; |
| 55 | 55 | import java.util.Arrays; |
| 56 | -import java.util.Timer; | |
| 57 | -import java.util.TimerTask; | |
| 58 | 56 | import java.util.concurrent.atomic.AtomicBoolean; |
| 59 | 57 | import java.util.concurrent.atomic.AtomicInteger; |
| 60 | 58 | |
| ... | ... | @@ -100,9 +98,6 @@ public class SocketService1 extends BaseService { |
| 100 | 98 | |
| 101 | 99 | private static final int HEART_BEAT = 20025; |
| 102 | 100 | private static final int CMD_REPORT_EQU_STATUS = 20030;//上报设备状态信息 |
| 103 | - private static final int ROOM_HAS_REGISTERED = 1001; | |
| 104 | - private static final int ROOM_NOT_EXIST_M = 1002; | |
| 105 | - private static final int HEAT_BEAT_RTN = 1003; | |
| 106 | 101 | |
| 107 | 102 | // online |
| 108 | 103 | public static final String SERVER_HOST_ONLINE = "conn.ft.qnbar.com";// "192.168.1.21";// |
| ... | ... | @@ -118,7 +113,7 @@ public class SocketService1 extends BaseService { |
| 118 | 113 | private String serverHost = SERVER_HOST; |
| 119 | 114 | private int serverPort = SERVER_PORT; |
| 120 | 115 | |
| 121 | - public int heartbearNum = 0; | |
| 116 | + public int heartbeatNum = 0; | |
| 122 | 117 | |
| 123 | 118 | public static final String END_SYMBOL = "\\r\\n\\r\\n";//心跳包内容 |
| 124 | 119 | // public String testRoomSn = "R170413034374"; |
| ... | ... | @@ -155,12 +150,12 @@ public class SocketService1 extends BaseService { |
| 155 | 150 | mHandler.postDelayed(this, HEART_BEAT_RATE); |
| 156 | 151 | //就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket |
| 157 | 152 | Heartbeat heartbeat = new Heartbeat(); |
| 158 | - if (heartbearNum > 10) { | |
| 153 | + if (heartbeatNum > 10) { | |
| 159 | 154 | heartbeat.setLightStatus(getLightStatus()); |
| 160 | 155 | heartbeat.setPlayStatus(getPlayStatus()); |
| 161 | 156 | heartbeat.setVolume(getAudioVolume() / 6 + 1); |
| 162 | 157 | } else { |
| 163 | - heartbearNum++; | |
| 158 | + heartbeatNum++; | |
| 164 | 159 | } |
| 165 | 160 | heartbeat.setRoom_sn(testRoomSn); |
| 166 | 161 | MainRequest rep = new MainRequest(); |
| ... | ... | @@ -168,7 +163,7 @@ public class SocketService1 extends BaseService { |
| 168 | 163 | rep.setData(heartbeat); |
| 169 | 164 | String msg = gson.toJson(rep); |
| 170 | 165 | // final String msg = new Gson().toJson( |
| 171 | -// new SocketSendMsg().contractHeartBeatMsg(testRoomSn)); | |
| 166 | +// new SocketSendMsg().contractHeartBeatMsg(testRoomSn)); | |
| 172 | 167 | boolean isSuccess = sendMsg(msg + END_SYMBOL); |
| 173 | 168 | if (!isSuccess) { |
| 174 | 169 | LogUtils.i(TAG, "send heart beat error restart"); |
| ... | ... | @@ -203,7 +198,6 @@ public class SocketService1 extends BaseService { |
| 203 | 198 | super.onCreate(); |
| 204 | 199 | LogUtils.i(TAG, "onCreate"); |
| 205 | 200 | bindService(new Intent(SocketService1.this, CinemaControlService.class), conn, Context.BIND_AUTO_CREATE); |
| 206 | -// startService(new Intent(SocketService1.this, CinemaControlService.class)); | |
| 207 | 201 | } |
| 208 | 202 | |
| 209 | 203 | @Override |
| ... | ... | @@ -224,7 +218,6 @@ public class SocketService1 extends BaseService { |
| 224 | 218 | case 2: |
| 225 | 219 | serverHost = SERVER_HOST; |
| 226 | 220 | serverPort = SERVER_PORT; |
| 227 | -// serverHost = "192.168.200.217"; | |
| 228 | 221 | break; |
| 229 | 222 | } |
| 230 | 223 | |
| ... | ... | @@ -261,7 +254,7 @@ public class SocketService1 extends BaseService { |
| 261 | 254 | boolean availableByPing = NetStatusUtils.isAvailableByPing("www.baidu.com"); |
| 262 | 255 | boolean availableByPing1 = NetStatusUtils.isAvailableByPing(serverHost); |
| 263 | 256 | boolean availableByPing2 = NetStatusUtils.isAvailableByPing("192.168.200.241"); |
| 264 | - LogUtils.i(TAG, "initsocket serverHost:serverPort:" + serverHost + ":" + serverPort); | |
| 257 | + LogUtils.i(TAG, "init socket serverHost:serverPort:" + serverHost + ":" + serverPort); | |
| 265 | 258 | LogUtils.i(TAG, "networkConnected:" + networkConnected + ":baidu:" + availableByPing + ",serverHost:" + availableByPing1 + ",serverIp:" + availableByPing2); |
| 266 | 259 | mHandler.post(new Runnable() { |
| 267 | 260 | @Override |
| ... | ... | @@ -332,9 +325,7 @@ public class SocketService1 extends BaseService { |
| 332 | 325 | msg.setLength(0); |
| 333 | 326 | msg.append(readingMsg.substring(0, pos)); |
| 334 | 327 | readingMsg.delete(0, pos + END_SYMBOL.length()); |
| 335 | -// if (msg.length() > 55) { | |
| 336 | - LogUtils.d("recvMsg","from last:"+msg.length()+":"+msg); | |
| 337 | -// } | |
| 328 | + LogUtils.d("recvMsg", "from last:" + msg.length() + ":" + msg); | |
| 338 | 329 | return true; |
| 339 | 330 | } |
| 340 | 331 | } |
| ... | ... | @@ -346,21 +337,17 @@ public class SocketService1 extends BaseService { |
| 346 | 337 | && !socket.isInputShutdown() |
| 347 | 338 | && ((length = is.read(buffer)) > 0)) { |
| 348 | 339 | String tmp = new String(Arrays.copyOf(buffer, length)); |
| 349 | -// if (length > 55) { | |
| 350 | - LogUtils.d("recvMsg", msgId + ":" + length + ":" + tmp); | |
| 351 | -// } | |
| 340 | + LogUtils.d("recvMsg", msgId + ":" + length + ":" + tmp); | |
| 352 | 341 | readingMsg.append(tmp); |
| 353 | 342 | int pos = readingMsg.indexOf(END_SYMBOL); |
| 354 | 343 | if (pos != -1) { |
| 355 | 344 | msg.setLength(0); |
| 356 | 345 | msg.append(readingMsg.substring(0, pos)); |
| 357 | 346 | readingMsg.delete(0, pos + END_SYMBOL.length()); |
| 358 | -// if (length > 55) { | |
| 359 | - LogUtils.d("recvMsg", msgId + ":" + length + ":" + msg); | |
| 360 | -// } | |
| 347 | + LogUtils.d("recvMsg", msgId + ":" + length + ":" + msg); | |
| 361 | 348 | return true; |
| 362 | 349 | } |
| 363 | - msgId ++; | |
| 350 | + msgId++; | |
| 364 | 351 | } |
| 365 | 352 | } catch (InterruptedIOException e) { |
| 366 | 353 | return false; |
| ... | ... | @@ -430,9 +417,7 @@ public class SocketService1 extends BaseService { |
| 430 | 417 | sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME; |
| 431 | 418 | while (recvMsg(message)) { |
| 432 | 419 | sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME; |
| 433 | -// if (message.length() > 55) { | |
| 434 | - LogUtils.d("recvMsg", "logic:" + message); | |
| 435 | -// } | |
| 420 | + LogUtils.d("recvMsg", "logic:" + message); | |
| 436 | 421 | LogUtils.d(TAG, "recv msg:" + message); |
| 437 | 422 | MainResponse socketResponse; |
| 438 | 423 | try { |
| ... | ... | @@ -492,7 +477,6 @@ public class SocketService1 extends BaseService { |
| 492 | 477 | case CONTAIN_MESSAGE: |
| 493 | 478 | heartBeatErrorCount.set(0); |
| 494 | 479 | LogUtils.i(TAG, "CONTAIN_MESSAGE"); |
| 495 | -// Log.d("getctrl","收到有命令的返回"); | |
| 496 | 480 | serverCommandDeal(socketResponse); |
| 497 | 481 | break; |
| 498 | 482 | default: |
| ... | ... | @@ -534,7 +518,6 @@ public class SocketService1 extends BaseService { |
| 534 | 518 | OpenDoor openDoorResponse = gson.fromJson(socketResponse.getData(), OpenDoor.class); |
| 535 | 519 | openDoor(openDoorResponse); |
| 536 | 520 | } |
| 537 | -// Log.d("getctrl","开门"); | |
| 538 | 521 | break; |
| 539 | 522 | case CLEAN_OVER://清洁完成处理 |
| 540 | 523 | LogUtils.i("LightOperationUtils", "admin clean over close light"); |
| ... | ... | @@ -559,15 +542,12 @@ public class SocketService1 extends BaseService { |
| 559 | 542 | break; |
| 560 | 543 | |
| 561 | 544 | case REPORT_EQU_STATUS://获取声音,灯光,播放暂停状态 |
| 562 | -// Log.d("ReportInfo", "收到上报命令"); | |
| 563 | 545 | //获取serverId |
| 564 | 546 | ReportEquStatus rps = gson.fromJson(socketResponse.getData(), ReportEquStatus.class); |
| 565 | -// String serverId = rps.getServerId(); | |
| 566 | 547 | reportEquStatus(rps.getServerId(), 0); |
| 567 | 548 | break; |
| 568 | 549 | |
| 569 | 550 | case SET_EQU_STATUS://设置声音,灯光,播放暂停 |
| 570 | -// Log.d("getctrl","收到控制命令"); | |
| 571 | 551 | Log.d("ReportInfo", "收到控制命令:" + socketResponse.getData()); |
| 572 | 552 | EquipmentControl equc = gson.fromJson(socketResponse.getData(), EquipmentControl.class); |
| 573 | 553 | setEquipmentStatus(equc); |
| ... | ... | @@ -617,7 +597,7 @@ public class SocketService1 extends BaseService { |
| 617 | 597 | //填充返回数据 |
| 618 | 598 | int volume = getAudioVolume() / 6 + 1; |
| 619 | 599 | int playStatus = getPlayStatus(); |
| 620 | - int lightStatus = 0; | |
| 600 | + int lightStatus; | |
| 621 | 601 | if (lightSet == 1 || lightSet == 2) { |
| 622 | 602 | lightStatus = lightSet; |
| 623 | 603 | } else { |
| ... | ... | @@ -645,42 +625,32 @@ public class SocketService1 extends BaseService { |
| 645 | 625 | private void setLight(int op) { |
| 646 | 626 | if (op == SERVER_CMD_OPEN_LIGHT) {//打开灯光 |
| 647 | 627 | Log.d("setEqu", "打开灯光"); |
| 648 | - try { | |
| 649 | - iPlayer.openLight(); | |
| 650 | - } catch (RemoteException e) { | |
| 651 | - e.printStackTrace(); | |
| 628 | + if (iPlayer != null) { | |
| 629 | + try { | |
| 630 | + iPlayer.openLight(); | |
| 631 | + } catch (RemoteException e) { | |
| 632 | + e.printStackTrace(); | |
| 633 | + } | |
| 652 | 634 | } |
| 653 | -// LightOperationUtils.open(); | |
| 654 | -// LightOperationUtils.setLightValue(5); | |
| 655 | -// //延时增亮 | |
| 656 | -// Timer timer = new Timer();//实例化Timer类 | |
| 657 | -// timer.schedule(new TimerTask() { | |
| 658 | -// public void run() { | |
| 659 | -// LightOperationUtils.setLightValue(Utils.getInt(context, "brightness", 50)); | |
| 660 | -// this.cancel(); | |
| 661 | -// } | |
| 662 | -// }, 2000);//毫秒 | |
| 663 | 635 | } else if (op == SERVER_CMD_CLOSE_LIGHT) {//关闭灯光 |
| 664 | 636 | Log.d("setEqu", "关闭灯光"); |
| 665 | - try { | |
| 666 | - iPlayer.closeLight(); | |
| 667 | - } catch (RemoteException e) { | |
| 668 | - e.printStackTrace(); | |
| 637 | + if (iPlayer != null) { | |
| 638 | + try { | |
| 639 | + iPlayer.closeLight(); | |
| 640 | + } catch (RemoteException e) { | |
| 641 | + e.printStackTrace(); | |
| 642 | + } | |
| 669 | 643 | } |
| 670 | -// LightOperationUtils.setLightValue(20); | |
| 671 | -// //延时关闭 | |
| 672 | -// Timer timer = new Timer();//实例化Timer类 | |
| 673 | -// timer.schedule(new TimerTask() { | |
| 674 | -// public void run() { | |
| 675 | -// LightOperationUtils.close(); | |
| 676 | -// this.cancel(); | |
| 677 | -// } | |
| 678 | -// }, 2000);//毫秒 | |
| 679 | 644 | } |
| 680 | 645 | } |
| 681 | 646 | |
| 682 | 647 | private void playCtl(int op) { |
| 683 | 648 | int status = -1; |
| 649 | + | |
| 650 | + if (iPlayer == null) { | |
| 651 | + LogUtils.i("iPlayer is null"); | |
| 652 | + return; | |
| 653 | + } | |
| 684 | 654 | try { |
| 685 | 655 | status = iPlayer.getCurrentStatus(); |
| 686 | 656 | } catch (RemoteException e) { |
| ... | ... | @@ -698,18 +668,8 @@ public class SocketService1 extends BaseService { |
| 698 | 668 | |
| 699 | 669 | private void setEquipmentStatus(EquipmentControl equc) { |
| 700 | 670 | setLight(equc.getLightCtl()); |
| 701 | - | |
| 702 | 671 | playCtl(equc.getPlayCtl()); |
| 703 | - | |
| 704 | 672 | setAudioVolume(equc.getAudioCtl()); |
| 705 | - | |
| 706 | -// if (equc.getLightCtl() != 0) { | |
| 707 | -// try { | |
| 708 | -// Thread.sleep(500); | |
| 709 | -// } catch (InterruptedException e) { | |
| 710 | -// e.printStackTrace(); | |
| 711 | -// } | |
| 712 | -// } | |
| 713 | 673 | reportEquStatus(equc.getServerId(), equc.getLightCtl()); |
| 714 | 674 | } |
| 715 | 675 | |
| ... | ... | @@ -748,6 +708,7 @@ public class SocketService1 extends BaseService { |
| 748 | 708 | DeviceInfo connectDevice = ((FangTangApplication) getApplication()). |
| 749 | 709 | getConnectDevice(); |
| 750 | 710 | if (connectDevice == null) { |
| 711 | + LogUtils.i(TAG, "connectDevice is null"); | |
| 751 | 712 | return lightStatus; |
| 752 | 713 | } |
| 753 | 714 | ConnectionStatus stu = Lights.getInstance(). | ... | ... |
| ... | ... | @@ -130,8 +130,26 @@ public class QrCodeShowActivity extends Activity implements IUpdateQrCodeView { |
| 130 | 130 | @Override |
| 131 | 131 | public void getQrCodeSuccess(RoomQrCodeInfo info) { |
| 132 | 132 | try { |
| 133 | + if (info == null) { | |
| 134 | + LogUtils.i("info = null"); | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + if (info.getData() == null) { | |
| 138 | + LogUtils.i("info.getData() = null"); | |
| 139 | + return; | |
| 140 | + } | |
| 141 | + //TODO 连场修正 | |
| 142 | + if (!TextUtils.isEmpty(info.getData().getOrder_sn())) { | |
| 143 | + LogUtils.i("get qr code order sn not null, record msg:" + info.getData()); | |
| 144 | +// WrongMsg wrongMsg = new WrongMsg(); | |
| 145 | +// wrongMsg.setMsg("请联系服务员处理"); | |
| 146 | +// getQrCodeFailure(wrongMsg); | |
| 147 | + return; | |
| 148 | + } | |
| 133 | 149 | LogUtils.i("QrCodeShowActivity", info.getData().getCode()); |
| 134 | - iv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400)); | |
| 150 | + if (!TextUtils.isEmpty(info.getData().getCode())) { | |
| 151 | + iv.setImageBitmap(QRCodeUtils.createQRCode(info.getData().getCode(), 400)); | |
| 152 | + } | |
| 135 | 153 | } catch (WriterException e) { |
| 136 | 154 | e.printStackTrace(); |
| 137 | 155 | } | ... | ... |
Please
register
or
login
to post a comment