From a0626aeba664e001aed3b9a19dd400fd4b382778 Mon Sep 17 00:00:00 2001 From: MDP G14 RPI Date: Mon, 14 Oct 2019 05:32:39 +0000 Subject: [PATCH] Add additional test cases for communicator utils and fix bug in fpParser --- src/communicator/MultiProcess.py | 14 +++++++------- src/communicator/test.py | 28 ++++++++++++++++++++++++++++ src/communicator/utils.py | 5 ++--- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/communicator/MultiProcess.py b/src/communicator/MultiProcess.py index e18e1b4..52ae421 100644 --- a/src/communicator/MultiProcess.py +++ b/src/communicator/MultiProcess.py @@ -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() @@ -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() diff --git a/src/communicator/test.py b/src/communicator/test.py index 2166a92..beee24e 100644 --- a/src/communicator/test.py +++ b/src/communicator/test.py @@ -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!') diff --git a/src/communicator/utils.py b/src/communicator/utils.py index ba68af1..b554cfd 100644 --- a/src/communicator/utils.py +++ b/src/communicator/utils.py @@ -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'] ''' @@ -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'): @@ -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':