Bläddra i källkod

修改到站离站部分

oldwine 2 månader sedan
förälder
incheckning
e136e8633b
1 ändrade filer med 34 tillägg och 7 borttagningar
  1. 34 7
      models/parking.py

+ 34 - 7
models/parking.py

@@ -18,6 +18,8 @@ class Parking:
         self.car_time = [0, 0, 0, 0]
 
         self.car_be = []
+        self.car_be_send_state = [False] * 4
+        self.car_be_lock = [threading.Lock() for i in range(4)]
 
         self.plate_set = {'厂内00664', '厂内00415', '厂内00687', '厂内00701', '厂内00700', '厂内00901', '厂内00699', '厂内00695', '厂内00694', '厂内00693', '厂内00692', '厂内00902', '厂内00690', '厂内00689', '陕E08582D', '陕E08515D', '陕E08000D', '陕E00298D'}
 
@@ -44,6 +46,7 @@ class Parking:
         else:
             valuedata = self.value_a[i]
 
+        time.sleep(2)
         send_flag = False
         with self.lock:
             if self.current_car[i] != valuedata.data:
@@ -56,12 +59,36 @@ class Parking:
             self.sender.plate_update(self.ccmNo_list[i], str(i+1), self.current_car[i])
 
     def car_in(self, i):
-        plate = ''
-        time.sleep(10)
-        if time.time() - self.car_time[i] <= 10:
-            plate = self.current_car[i]
-
-        self.sender.car_add(self.ccmNo_list[i], str(i+1), plate)
+        with self.car_be_lock[i]:
+            if self.car_be_send_state[i]:
+                return None
+            start_time = time.time()
+            now = time.time()
+            while self.car_be[i].state and now - start_time < 10:
+                time.sleep(0.5)
+                now = time.time()
+            
+            if now - start_time < 10:
+                return None
+            else:
+                plate = ''
+                if time.time() - self.car_time[i] <= 10:
+                    plate = self.current_car[i]
+                self.sender.car_add(self.ccmNo_list[i], str(i+1), plate)
+                self.car_be_send_state[i] = True
 
     def car_out(self, i):
-        self.sender.car_go(self.ccmNo_list[i], str(i+1))
+        with self.car_be_lock[i]:
+            if not self.car_be_send_state[i]:
+                return None
+            start_time = time.time()
+            now = time.time()
+            while not self.car_be[i].state and now - start_time < 10:
+                time.sleep(0.5)
+                now = time.time()
+            
+            if now - start_time < 10:
+                return None
+            else:
+                self.sender.car_go(self.ccmNo_list[i], str(i+1))
+                self.car_be_send_state[i] = False