mirror of
https://github.com/PotentiaRobotics/control-system.git
synced 2025-04-17 18:00:17 -04:00
Complete Rewrite
This commit is contained in:
parent
59be8fee6b
commit
1652134788
|
@ -43,22 +43,22 @@ class Receiver:
|
||||||
# Commands must be in form "PRIORITY|{COMMAND}|TIMESTAMP|CHECKSUM"
|
# Commands must be in form "PRIORITY|{COMMAND}|TIMESTAMP|CHECKSUM"
|
||||||
# awaiting for message
|
# awaiting for message
|
||||||
while True:
|
while True:
|
||||||
instruction = self.conn.recv(1024)
|
action = self.conn.recv(1024).decode('UTF-8')
|
||||||
action = instruction.decode('UTF-8')
|
if len(action) > 0:
|
||||||
print("Action received:", action)
|
heapq.heappush(self.commands,action)
|
||||||
heapq.heappush(self.commands,action)
|
heapq.heappush(self.transmit,"Received|"+action)
|
||||||
heapq.heappush(self.transmit,"Received|"+action)
|
|
||||||
|
|
||||||
|
"""Method checks commands from queue and adds to execution queue"""
|
||||||
def checkCommand(self):
|
def checkCommand(self):
|
||||||
while True:
|
while True:
|
||||||
if len(self.commands) > 0:
|
if len(self.commands) > 0:
|
||||||
#checking if the checksum of the command
|
#checking if the checksum of the command
|
||||||
#equals the sum of all ascii values of every character
|
#equals the sum of all ascii values of every character
|
||||||
#in command statement
|
#in command statement
|
||||||
pattern = "^[0-5]\|.*\|[0-9]{2}:[0-9]{2}\|"
|
pattern = "^[0-5]\|.*\|[0-9]{2}:[0-9]{2}\|" #everything but the checksum value
|
||||||
checksum = "\w+$"
|
checksum = "\w+$" #checksum value
|
||||||
popped = commands.heappop()
|
popped = heapq.heapop(self.commands) #gets smallest value command
|
||||||
com = re.findall(pattern, popped)
|
com = re.findall(pattern, popped)
|
||||||
numval = re.findall(checksum, popped)
|
numval = re.findall(checksum, popped)
|
||||||
numval = int(numval,16) #converts hex to int
|
numval = int(numval,16) #converts hex to int
|
||||||
if numval == sum([ord(i) for i in com[0]]):
|
if numval == sum([ord(i) for i in com[0]]):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user