Showing
1 changed file
with
34 additions
and
11 deletions
| ... | ... | @@ -146,8 +146,6 @@ public class SocketService1 extends BaseService { |
| 146 | 146 | |
| 147 | 147 | public void onServiceDisconnected(ComponentName className) { |
| 148 | 148 | } |
| 149 | - | |
| 150 | - ; | |
| 151 | 149 | }; |
| 152 | 150 | |
| 153 | 151 | public Runnable heartBeatRunnable = new Runnable() { |
| ... | ... | @@ -328,21 +326,41 @@ public class SocketService1 extends BaseService { |
| 328 | 326 | return false; |
| 329 | 327 | } |
| 330 | 328 | try { |
| 329 | + if (readingMsg.length() > 0) { | |
| 330 | + int pos = readingMsg.indexOf(END_SYMBOL); | |
| 331 | + if (pos != -1) { | |
| 332 | + msg.setLength(0); | |
| 333 | + msg.append(readingMsg.substring(0, pos)); | |
| 334 | + readingMsg.delete(0, pos + END_SYMBOL.length()); | |
| 335 | +// if (msg.length() > 55) { | |
| 336 | + LogUtils.d("recvMsg","from last:"+msg.length()+":"+msg); | |
| 337 | +// } | |
| 338 | + return true; | |
| 339 | + } | |
| 340 | + } | |
| 331 | 341 | InputStream is = socket.getInputStream(); |
| 332 | 342 | byte[] buffer = new byte[1024]; |
| 333 | 343 | int length = 0; |
| 344 | + int msgId = 0; | |
| 334 | 345 | while (!socket.isClosed() |
| 335 | 346 | && !socket.isInputShutdown() |
| 336 | 347 | && ((length = is.read(buffer)) > 0)) { |
| 337 | 348 | String tmp = new String(Arrays.copyOf(buffer, length)); |
| 349 | +// if (length > 55) { | |
| 350 | + LogUtils.d("recvMsg", msgId + ":" + length + ":" + tmp); | |
| 351 | +// } | |
| 338 | 352 | readingMsg.append(tmp); |
| 339 | 353 | int pos = readingMsg.indexOf(END_SYMBOL); |
| 340 | 354 | if (pos != -1) { |
| 341 | 355 | msg.setLength(0); |
| 342 | 356 | msg.append(readingMsg.substring(0, pos)); |
| 343 | 357 | readingMsg.delete(0, pos + END_SYMBOL.length()); |
| 358 | +// if (length > 55) { | |
| 359 | + LogUtils.d("recvMsg", msgId + ":" + length + ":" + msg); | |
| 360 | +// } | |
| 344 | 361 | return true; |
| 345 | 362 | } |
| 363 | + msgId ++; | |
| 346 | 364 | } |
| 347 | 365 | } catch (InterruptedIOException e) { |
| 348 | 366 | return false; |
| ... | ... | @@ -412,7 +430,9 @@ public class SocketService1 extends BaseService { |
| 412 | 430 | sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME; |
| 413 | 431 | while (recvMsg(message)) { |
| 414 | 432 | sleepTime = READ_THREAD_DEFAULT_SLEEP_MTIME; |
| 415 | - | |
| 433 | +// if (message.length() > 55) { | |
| 434 | + LogUtils.d("recvMsg", "logic:" + message); | |
| 435 | +// } | |
| 416 | 436 | LogUtils.d(TAG, "recv msg:" + message); |
| 417 | 437 | MainResponse socketResponse; |
| 418 | 438 | try { |
| ... | ... | @@ -472,6 +492,7 @@ public class SocketService1 extends BaseService { |
| 472 | 492 | case CONTAIN_MESSAGE: |
| 473 | 493 | heartBeatErrorCount.set(0); |
| 474 | 494 | LogUtils.i(TAG, "CONTAIN_MESSAGE"); |
| 495 | +// Log.d("getctrl","收到有命令的返回"); | |
| 475 | 496 | serverCommandDeal(socketResponse); |
| 476 | 497 | break; |
| 477 | 498 | default: |
| ... | ... | @@ -513,6 +534,7 @@ public class SocketService1 extends BaseService { |
| 513 | 534 | OpenDoor openDoorResponse = gson.fromJson(socketResponse.getData(), OpenDoor.class); |
| 514 | 535 | openDoor(openDoorResponse); |
| 515 | 536 | } |
| 537 | +// Log.d("getctrl","开门"); | |
| 516 | 538 | break; |
| 517 | 539 | case CLEAN_OVER://清洁完成处理 |
| 518 | 540 | LogUtils.i("LightOperationUtils", "admin clean over close light"); |
| ... | ... | @@ -537,7 +559,7 @@ public class SocketService1 extends BaseService { |
| 537 | 559 | break; |
| 538 | 560 | |
| 539 | 561 | case REPORT_EQU_STATUS://获取声音,灯光,播放暂停状态 |
| 540 | - Log.d("ReportInfo", "收到上报命令"); | |
| 562 | +// Log.d("ReportInfo", "收到上报命令"); | |
| 541 | 563 | //获取serverId |
| 542 | 564 | ReportEquStatus rps = gson.fromJson(socketResponse.getData(), ReportEquStatus.class); |
| 543 | 565 | // String serverId = rps.getServerId(); |
| ... | ... | @@ -545,6 +567,7 @@ public class SocketService1 extends BaseService { |
| 545 | 567 | break; |
| 546 | 568 | |
| 547 | 569 | case SET_EQU_STATUS://设置声音,灯光,播放暂停 |
| 570 | +// Log.d("getctrl","收到控制命令"); | |
| 548 | 571 | Log.d("ReportInfo", "收到控制命令:" + socketResponse.getData()); |
| 549 | 572 | EquipmentControl equc = gson.fromJson(socketResponse.getData(), EquipmentControl.class); |
| 550 | 573 | setEquipmentStatus(equc); |
| ... | ... | @@ -680,13 +703,13 @@ public class SocketService1 extends BaseService { |
| 680 | 703 | |
| 681 | 704 | setAudioVolume(equc.getAudioCtl()); |
| 682 | 705 | |
| 683 | - if (equc.getLightCtl() != 0) { | |
| 684 | - try { | |
| 685 | - Thread.sleep(500); | |
| 686 | - } catch (InterruptedException e) { | |
| 687 | - e.printStackTrace(); | |
| 688 | - } | |
| 689 | - } | |
| 706 | +// if (equc.getLightCtl() != 0) { | |
| 707 | +// try { | |
| 708 | +// Thread.sleep(500); | |
| 709 | +// } catch (InterruptedException e) { | |
| 710 | +// e.printStackTrace(); | |
| 711 | +// } | |
| 712 | +// } | |
| 690 | 713 | reportEquStatus(equc.getServerId(), equc.getLightCtl()); |
| 691 | 714 | } |
| 692 | 715 | ... | ... |
Please
register
or
login
to post a comment