Skip to content
Snippets Groups Projects
Commit f4675923 authored by jtkenny's avatar jtkenny
Browse files

implementing queueing

parent c2cc2da5
No related branches found
No related tags found
5 merge requests!106Adding Pycrocart 2.1,!104adding cflib to this branch,!103Updating develop to current state of master branch,!98Pycrocart 2.1 will,!94Merge cflib adapter into main
File added
File added
from queue import Queue
import socket import socket
import os import os
import collections import collections
...@@ -8,7 +9,7 @@ socket_path = './cflib_groundstation.socket' ...@@ -8,7 +9,7 @@ socket_path = './cflib_groundstation.socket'
class GroundstationSocket(): class GroundstationSocket():
metadata = collections.namedtuple("metadata", ["msg_type", "msg_id", "data_len"]) metadata = collections.namedtuple("metadata", ["msg_type", "msg_id", "data_len"])
def groundstation_connect(self): def groundstation_connect(self, inputQueue: Queue):
# remove the socket file if it already exists # remove the socket file if it already exists
try: try:
os.unlink(socket_path) os.unlink(socket_path)
...@@ -45,8 +46,9 @@ class GroundstationSocket(): ...@@ -45,8 +46,9 @@ class GroundstationSocket():
print("There was an error decoding the packet") print("There was an error decoding the packet")
break break
#TODO: Add the message to the main function queue, which will #Add the message to the main function queue, which will
#which will send the appropriate command to the quad. #which will send the appropriate command to the quad.
inputQueue.put(message)
finally: finally:
# close the connection # close the connection
self.connection.close() self.connection.close()
...@@ -149,7 +151,6 @@ class MessageTypeID(Enum): ...@@ -149,7 +151,6 @@ class MessageTypeID(Enum):
SEND_RT_ID = 20 SEND_RT_ID = 20
MAX_TYPE_ID = 21 MAX_TYPE_ID = 21
if __name__ == '__main__':
GroundstationSocket().groundstation_connect()
from email import message
from queue import Queue
from threading import Thread
from groundstation_socket import GroundstationSocket
from crazyflie_connection import CrazyflieConnection
class main(): class main():
print("main") def __init__(self) -> None:
\ No newline at end of file self.inputQueue = Queue()
self.outputQueue = Queue()
def processCommands(self):
gs = GroundstationSocket()
self.inThread = Thread(target = gs.groundstation_connect, args = (self.inputQueue,))
self.inThread.start()
while True:
if self.inputQueue.not_empty:
command = self.inputQueue.get()
print(command)
msg_type = command["msg_type"]
print(msg_type)
if __name__ == '__main__':
main().processCommands()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment