Sfoglia il codice sorgente

started to use curio

digital 8 anni fa
parent
commit
2b571fea0d
3 ha cambiato i file con 23 aggiunte e 18 eliminazioni
  1. 6 6
      gui.py
  2. 6 5
      lib/beewatch/pinapi/__init__.py
  3. 11 7
      lib/beewatch/server/__init__.py

+ 6 - 6
gui.py

@@ -87,17 +87,17 @@ group_af_family.add_argument(
 )
 args = parser.parse_args()
 if args.debug:
-    with open("bee_logging.yaml") as f:
+    with open("config/logging.yaml") as f:
         data = f.read()
     config = yaml.safe_load(data)
     logging.config.dictConfig(config)
 #
-if args.af_family == "AF_INET":
-    port = args.port
-elif args.af_family == "AF_UNIX":
-    port = None
 print(args)
-win = beewatch.gui.BeeWindow(host=args.host,port=port)
+win = beewatch.gui.BeeWindow(
+    host=args.host,
+    port=args.port,
+    af_family=args.af_family
+)
 win.start()
 
 

+ 6 - 5
lib/beewatch/pinapi/__init__.py

@@ -19,7 +19,7 @@
 # Python Libraries
 import curio
 import logging
-import threaing
+import threading
 import time
 # My Libraries
 import digilib.pin
@@ -54,9 +54,10 @@ class PinAPIBee(digilib.pin.PinAPIBase):
             return False
     def make_engine(self,*args):
         return digilib.pin.PCEngine(*args)
-    def turn(self,direction,respond_method):
+    async def turn(self,direction,*args,respond_method):
+        lpin.debug(args)
         lpin.debug(threading.current_thread())
-        with self ad
+        # with self ad
         lpin.info("turning {}".format(direction))
         right_state = self.engine_right.is_on
         right_speed = self.engine_right.speed
@@ -70,8 +71,8 @@ class PinAPIBee(digilib.pin.PinAPIBase):
             self.engine_right.set_state(True)
             self.engine_right.set_speed(1)
             self.engine_left.set_state(False)
-        # curio.sleep(2)
-        time.sleep(2)
+        await curio.sleep(2)
+        # time.sleep(2)
         self.engine_right.set_state(right_state)
         self.engine_right.set_speed(right_speed)
         self.engine_left.set_state(left_state)

+ 11 - 7
lib/beewatch/server/__init__.py

@@ -16,6 +16,7 @@
 # You should have received a copy of the GNU General Public License
 # along with BeeWatch.  If not, see <http://www.gnu.org/licenses/>.
 
+import curio
 import logging
 import logging.handlers
 import digilib.network
@@ -107,22 +108,25 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
         data_decoded=data_decoded.strip()
         lchat.info("Client:"+data_decoded)
         if data_decoded.find(" ") != -1:
-            cmd=data_decoded.split()[0]
-            args=data_decoded.split()[1:]
+            cmd = data_decoded.split()[0]
+            args = data_decoded.split()[1:]
         else:
             cmd=data_decoded
-            args=()
-            kwargs={}
+            args = ()
+        kwargs = {}
         # if cmd in self.command_to_function.keys():
         if cmd in self.bee_api.text_to_func.keys():
             try:
                 # self.respond(str(args))
-                self.bee_api.text_to_func[cmd](
+                task = curio.run(
+                    self.bee_api.text_to_func[cmd],
                     self.bee_api,
                     *args,
-                    respond_method=self.respond,
-                    **kwargs,
+                    self.respond
+                    # respond_method=self.respond,
+                    # **kwargs,
                 )
+                task.join()
             except:
                 tb = traceback.format_exc()
                 print(tb)