wuhb 2 yıl önce
ebeveyn
işleme
f894c833bd

+ 16 - 7
app/src/main/java/com/qy/agv/activity/ControlActivity.java

@@ -320,6 +320,7 @@ public class ControlActivity extends BaseActivity {
     }
 
     protected void bindSocketService() {
+
         sc = new ServiceConnection() {
             @Override
             public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
@@ -331,7 +332,6 @@ public class ControlActivity extends BaseActivity {
             }
         };
         socketIntent = new Intent(getApplicationContext(), SocketService.class);
-        startService(socketIntent);
         bindService(socketIntent, sc, BIND_AUTO_CREATE);
     }
 
@@ -434,12 +434,22 @@ public class ControlActivity extends BaseActivity {
             case "cdw":
                 rs = socketService.sendData("Hcdw,"+id+","+args[0]+"T");
                 if(rs){
-                    socketService.checkID.put(id, new String[]{"重定位成功", "重定位失败"});
+                    Map<String, String> msg = new HashMap<>();
+                    msg.put("1T", "重定位成功");
+                    msg.put("2T", "重定位失败");
+                    socketService.checkID.put(id, msg);
                     checkCDW(id, 3);
                 }
                 break;
             case "cdwtx":
-                socketService.sendData("Hcdwtx,"+id+",T");
+                rs = socketService.sendData("Hcdwtx,"+id+",T");
+                break;
+            case "qrdw":
+                Map<String, String> msg = new HashMap<>();
+                msg.put("0T", "定位成功");
+                msg.put("1T", "定位失败");
+                socketService.checkID.put(id, msg);
+                rs = socketService.sendData("qrdw,"+id+",T");
                 break;
         }
         if(!rs){
@@ -473,7 +483,6 @@ public class ControlActivity extends BaseActivity {
                 try {
                     String value = params.get(position).get("value");
                     sendCommand("cdw",value);
-                    ToastUtils.showToast(context, "重定位发送成功");
                     popupWindow.dismiss();
                 }catch (Exception ex){
                     mylog.error("选择位置异常", ex);
@@ -522,11 +531,11 @@ public class ControlActivity extends BaseActivity {
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if(socketIntent != null) {
-            stopService(socketIntent);
-        }
         if(sc!=null) {
             unbindService(sc);
         }
+        if(socketIntent != null) {
+            stopService(socketIntent);
+        }
     }
 }

+ 8 - 13
app/src/main/java/com/qy/agv/receiver/SocketService.java

@@ -60,7 +60,7 @@ public class SocketService extends Service {
     private final Intent intent = new Intent(Constant.RECEIVER_MSG);
     private Long lastTime = 0L;
     private int bleSeq = 0;
-    public volatile Map<String, String[]> checkID = new HashMap<>();
+    public volatile Map<String, Map<String, String>> checkID = new HashMap<>();
 
 
     @Override
@@ -77,11 +77,6 @@ public class SocketService extends Service {
 
     @Override
     public void onCreate() {
-        super.onCreate();
-    }
-
-    @Override
-    public int onStartCommand(Intent intent, int flags, int startId) {
         /*初始化socket*/
         try {
             if(Constant.robotModel != null
@@ -91,6 +86,11 @@ public class SocketService extends Service {
         }catch (Exception e){
             e.printStackTrace();
         }
+        super.onCreate();
+    }
+
+    @Override
+    public int onStartCommand(Intent intent, int flags, int startId) {
         return super.onStartCommand(intent, flags, startId);
     }
 
@@ -158,15 +158,11 @@ public class SocketService extends Service {
         }
         String recID = rec.split(",")[1];
         if(checkID.containsKey(recID)){
-            String[] str = checkID.get(rec);
+            Map<String, String> str = checkID.get(rec);
             if(str == null){
                 return;
             }
-            if(rec.contains("1T")) {
-                toastMsg(str[0]);
-            }else{
-                toastMsg(str[1]);
-            }
+            toastMsg(str.get(rec));
             checkID.remove(rec);
         }else {
             intent.putExtra("json", rec);
@@ -316,7 +312,6 @@ public class SocketService extends Service {
         if (socket != null) {
             try {
                 socket.close();
-
             } catch (IOException e) {
             }
             socket = null;