Skip to content

Commit

Permalink
Add additional test cases for communicator utils and fix bug in fpParser
Browse files Browse the repository at this point in the history
  • Loading branch information
MDP G14 RPI committed Oct 14, 2019
1 parent ef0a69e commit a0626ae
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/communicator/MultiProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
class MultiProcess:
def __init__(self):
log.info('Initializing Multithread Communication')
# self.android = Android()
self.android = Android()
self.arduino = Arduino()
self.pc = PC()
self.detector = SymbolDetector()

# self.android.connect()
self.android.connect()
self.arduino.connect()
self.pc.connect()

Expand All @@ -40,11 +40,11 @@ def __init__(self):

def start(self):
# self.detector.start()

# r_android = Process(target=self.read_android, args=(self.pc_queue,))
# r_android.start()
# w_android = Process(target=self.write_android, args=(self.android_queue,))
# w_android.start()
r_android = Process(target=self.read_android, args=(self.pc_queue,))
r_android.start()
w_android = Process(target=self.write_android, args=(self.android_queue,))
w_android.start()

r_arduino = Process(target=self.read_arduino, args=(self.pc_queue,))
r_arduino.start()
Expand Down
28 changes: 28 additions & 0 deletions src/communicator/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ def runTests(verbose):
all_passed = False
log.error('pcMsgParser: FP - Failed!')

try:
msg_read = "FP|(1,1,E);(1,5,E);(2,5,N);(4,5,N);(4,6,E);(4,9,E);(5,9,N);(8,9,N);(8,10,E);(8,13,E);(9,13,N);(10,13,N);(10,12,W)"
pc_msg = pcMsgParser(msg_read)
assert pc_msg['target'] == 'both'
assert pc_msg['payload']['arduino'] == 'w4aw3dw4aw4dw4aw2aw1'
if verbose:
log.info('Msg to parse: ' + msg_read)
log.info('Parsed Android: ' + pc_msg['payload']['android'])
log.info('Parsed Arduino: ' + pc_msg['payload']['arduino'])
log.info('pcMsgParser: FP2 - Passed!')
except AssertionError as e:
all_passed = False
log.error('pcMsgParser: FP2 - Failed!')

try:
msg_read = "FP|(1,1,E);(1,5,E);(2,5,N);(2,4,W)"
pc_msg = pcMsgParser(msg_read)
assert pc_msg['target'] == 'both'
assert pc_msg['payload']['arduino'] == 'w4aw1aw1'
if verbose:
log.info('Msg to parse: ' + msg_read)
log.info('Parsed Android: ' + pc_msg['payload']['android'])
log.info('Parsed Arduino: ' + pc_msg['payload']['arduino'])
log.info('pcMsgParser: FP3 - Passed!')
except AssertionError as e:
all_passed = False
log.error('pcMsgParser: FP3 - Failed!')

if all_passed:
log.info('All Tests Passed!')

Expand Down
5 changes: 2 additions & 3 deletions src/communicator/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from src.Logger import Logger
log = Logger()

arduino_commands = ['H', 'F', 'S']
arduino_commands = ['H', 'F', 'S', 'Z']
arduino_out = ['SD', 'MC', 'CC', 'EC']

'''
Expand Down Expand Up @@ -114,7 +114,7 @@ def fpParser(system, path_data):
or (dir_1 == 'E' and dir_2 == 'S')\
or (dir_1 == 'W' and dir_2 == 'N'):
step_seq.append('d')
elif (dir == 'N' and dir_2 =='W')\
elif (dir_1 == 'N' and dir_2 =='W')\
or (dir_1 == 'S' and dir_2 == 'E')\
or (dir_1 == 'E' and dir_2 == 'N')\
or (dir_1 == 'W' and dir_2 == 'S'):
Expand All @@ -126,7 +126,6 @@ def fpParser(system, path_data):
step_count = abs(int(x_1) - int(x_2))
else:
print('Error: ' + str(dir_1) + ', ' + str(dir_2))

step_seq = step_seq + [ 'w' for x in range(step_count) ]

if system == 'android':
Expand Down

0 comments on commit a0626ae

Please sign in to comment.