def prepare_4_match_parameters(self): self.prepare_3_parse_logger_definition() self._ecu_context = PMCUContext(self._ecu_packet, [1, 3]) self._ecu_parameters = self._ecu_context.match_parameters(self._parameters) self.assertIsNotNone(self._ecu_parameters) self.assertEqual(len(self._ecu_parameters), 125) self._ecu_switch_parameters = self._ecu_context.match_switch_parameters(self._parameters) self.assertIsNotNone(self._ecu_switch_parameters) self.assertEqual(len(self._ecu_switch_parameters), 36) self._ecu_calculated_parameters = self._ecu_context.match_calculated_parameters(self._parameters, self._ecu_parameters) self.assertIsNotNone(self._ecu_calculated_parameters) self.assertEqual(len(self._ecu_calculated_parameters), 4) self._tcu_context = PMCUContext(self._tcu_packet, [2]) self._tcu_parameters = self._tcu_context.match_parameters(self._parameters) self.assertIsNotNone(self._tcu_parameters) self.assertEqual(len(self._tcu_parameters), 11) self._tcu_switch_parameters = self._tcu_context.match_switch_parameters(self._parameters) self.assertIsNotNone(self._tcu_switch_parameters) self.assertEqual(len(self._tcu_switch_parameters), 13) self._tcu_calculated_parameters = self._tcu_context.match_calculated_parameters(self._parameters, self._tcu_parameters) self.assertIsNotNone(self._tcu_calculated_parameters) self.assertEqual(len(self._tcu_calculated_parameters), 0)
def is_supported(self, data): offset = PMCUContext.RESPONSE_MARK_OFFSET() + 1 + self._byte_index # <, not <= because last one is checksum if offset < len(data): cu_byte = data[offset] bit_mask = 1 << self._bit_index return cu_byte & bit_mask == bit_mask else: return False
output.close() if len(sys.argv) > 1 and sys.argv[1] == "demo": connection = PMDemoConnection() elif platform.system() == "Linux": connection = PMConnection() else: connection = PMDemoConnection() while True: try: connection.open() ecu_packet = connection.init(1) tcu_packet = connection.init(2) ecu_context = PMCUContext(ecu_packet, [1, 3]) ecu_parameters = ecu_context.match_parameters(defined_parameters) ecu_switch_parameters = ecu_context.match_switch_parameters( defined_parameters) ecu_calculated_parameters = ecu_context.match_calculated_parameters( defined_parameters, ecu_parameters) tcu_context = PMCUContext(tcu_packet, [2]) tcu_parameters = tcu_context.match_parameters(defined_parameters) tcu_switch_parameters = tcu_context.match_switch_parameters( defined_parameters) tcu_calculated_parameters = tcu_context.match_calculated_parameters( defined_parameters, tcu_parameters) PM.log("ECU ROM ID: " + ecu_context.get_rom_id()) PM.log("TCU ROM ID: " + tcu_context.get_rom_id())
pickle.dump(defined_parameters, output, -1) output.close() if len(sys.argv) > 1 and sys.argv[1] == "demo": connection = PMDemoConnection() elif platform.system() == "Linux": connection = PMConnection() else: connection = PMDemoConnection() while True: try: connection.open() ecu_packet = connection.init(1) ecu_context = PMCUContext(ecu_packet, [1, 3]) ecu_parameters = ecu_context.match_parameters(defined_parameters) ecu_switch_parameters = ecu_context.match_switch_parameters( defined_parameters) ecu_calculated_parameters = ecu_context.match_calculated_parameters( defined_parameters, ecu_parameters) supported_parameters = ecu_parameters + ecu_switch_parameters + ecu_calculated_parameters supported_parameters = sorted(supported_parameters, key=stringSplitByNumbers) # Build our screens & data sources # Clock first screen.add_window(PMClock())
output.close() if len(sys.argv) > 1 and sys.argv[1] == "demo": connection = PMDemoConnection() elif platform.system() == "Linux": connection = PMConnection() else: connection = PMDemoConnection() while True: try: connection.open() ecu_packet = connection.init(1) tcu_packet = connection.init(2) ecu_context = PMCUContext(ecu_packet, [1, 3]) ecu_parameters = ecu_context.match_parameters(defined_parameters) ecu_switch_parameters = ecu_context.match_switch_parameters(defined_parameters) ecu_calculated_parameters = ecu_context.match_calculated_parameters(defined_parameters, ecu_parameters) tcu_context = PMCUContext(tcu_packet, [2]) tcu_parameters = tcu_context.match_parameters(defined_parameters) tcu_switch_parameters = tcu_context.match_switch_parameters(defined_parameters) tcu_calculated_parameters = tcu_context.match_calculated_parameters(defined_parameters, tcu_parameters) PM.log("ECU ROM ID: " + ecu_context.get_rom_id()) PM.log("TCU ROM ID: " + tcu_context.get_rom_id()) supported_parameters = ecu_parameters + ecu_switch_parameters + ecu_calculated_parameters + tcu_parameters + tcu_switch_parameters + tcu_calculated_parameters supported_parameters = sorted(supported_parameters, key=stringSplitByNumbers)
class PMCUTestCase(unittest.TestCase): def setUp(self): self._ecu_packet = None self._tcu_packet = None self._connection = None self._parameters = None self._ecu_context = None self._tcu_context = None self._ecu_parameters = None self._ecu_switch_parameters = None self._ecu_calculated_parameters = None self._tcu_parameters = None self._tcu_calculated_parameters = None self._tcu_switch_parameters = None logger = PM() logger.set(self.log) def prepare_1_open_connection(self): self._connection = PMDemoConnection() result = self._connection.open() self.assertTrue(result) def prepare_2_init_connection(self): self.prepare_1_open_connection() self.assertIsNotNone(self._connection) self._ecu_packet = self._connection.init(1) self.assertIsNotNone(self._ecu_packet) self._tcu_packet = self._connection.init(2) self.assertIsNotNone(self._tcu_packet) def prepare_3_parse_logger_definition(self): self.prepare_2_init_connection() parser = PMXmlParser() self._parameters = parser.parse("logger_METRIC_EN_v263.xml") self._parameters = sorted(self._parameters, key=lambda x: x.get_id(), reverse=True) self.assertIsNotNone(self._parameters) self.assertEqual(len(self._parameters), 716) def prepare_4_match_parameters(self): self.prepare_3_parse_logger_definition() self._ecu_context = PMCUContext(self._ecu_packet, [1, 3]) self._ecu_parameters = self._ecu_context.match_parameters(self._parameters) self.assertIsNotNone(self._ecu_parameters) self.assertEqual(len(self._ecu_parameters), 125) self._ecu_switch_parameters = self._ecu_context.match_switch_parameters(self._parameters) self.assertIsNotNone(self._ecu_switch_parameters) self.assertEqual(len(self._ecu_switch_parameters), 36) self._ecu_calculated_parameters = self._ecu_context.match_calculated_parameters(self._parameters, self._ecu_parameters) self.assertIsNotNone(self._ecu_calculated_parameters) self.assertEqual(len(self._ecu_calculated_parameters), 4) self._tcu_context = PMCUContext(self._tcu_packet, [2]) self._tcu_parameters = self._tcu_context.match_parameters(self._parameters) self.assertIsNotNone(self._tcu_parameters) self.assertEqual(len(self._tcu_parameters), 11) self._tcu_switch_parameters = self._tcu_context.match_switch_parameters(self._parameters) self.assertIsNotNone(self._tcu_switch_parameters) self.assertEqual(len(self._tcu_switch_parameters), 13) self._tcu_calculated_parameters = self._tcu_context.match_calculated_parameters(self._parameters, self._tcu_parameters) self.assertIsNotNone(self._tcu_calculated_parameters) self.assertEqual(len(self._tcu_calculated_parameters), 0) #TODO: switches def test_5_read_parameters(self): self.prepare_4_match_parameters() print self._ecu_parameters[120].to_string() packet = self._connection.read_parameter(self._ecu_parameters[120]) value = self._ecu_parameters[120].get_value(packet) print 'value=' + value def log(self, message, mid): print message return mid