def testSendSpeedAndDetectAllBcm(self): NUMBER_OF_FRAMES_TO_SEND = 1000 # Seems to give problems for larger values self.simulated_can_process = subprocess.Popen(['candump', VIRTUAL_CAN_BUS_NAME, "-n", str(NUMBER_OF_FRAMES_TO_SEND)], shell=False, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) time.sleep(0.1) starttime = time.time() for i in range(NUMBER_OF_FRAMES_TO_SEND): signalvalues_to_send = {'testsignal1': 1, 'testsignal2': i, 'testsignal3': 256 * 4 + 5} self.canbus_bcm.send_signals(signalvalues_to_send) try: self.simulated_can_process.communicate(timeout=10) except subprocess.TimeoutExpired: raise exceptions.CanTimeoutException("At least one of the {} sent frames was not seen by candump.".format( NUMBER_OF_FRAMES_TO_SEND)) execution_time = time.time() - starttime time_per_loop_ms = 1000 * execution_time / NUMBER_OF_FRAMES_TO_SEND frames_per_seconds = NUMBER_OF_FRAMES_TO_SEND / execution_time output_string = "\n --> Sent {} frames in {:.1f} s ({:.2f} ms per frame, {:.1f} frames/s). ".format( NUMBER_OF_FRAMES_TO_SEND, execution_time, time_per_loop_ms, frames_per_seconds) print(output_string)
def testReceiveAllSentFramesBcm(self): self.canbus_bcm.init_reception() self.simulated_can_process = subprocess.Popen(["cangen", VIRTUAL_CAN_BUS_NAME, "-I", "{:3x}".format(FRAME_ID_RECEIVE), "-L", str(self.FRAME_NUMBER_OF_DATABYTES), "-D", "i", "-g", str(self.FRAME_SENDER_SPACING_MILLISECONDS), "-n", str(self.NUMBER_OF_LOOPS)], shell=False, stderr=subprocess.STDOUT) try: for i in range(self.NUMBER_OF_LOOPS): self.canbus_bcm.recv_next_signals() except exceptions.CanTimeoutException: raise exceptions.CanTimeoutException("Missed receiving at least one of the {} frames".format( self.NUMBER_OF_LOOPS))