def _test_bad_params(self):
        empty_diddef = DynamicDidDefinition()
        valid_diddef = DynamicDidDefinition(source_did=0x1234,
                                            position=1,
                                            memorysize=1)

        with self.assertRaises(ValueError):
            self.udsclient.clear_dynamically_defined_did(-1)

        with self.assertRaises(ValueError):
            self.udsclient.clear_dynamically_defined_did(0x10000)

        with self.assertRaises(ValueError):
            self.udsclient.clear_dynamically_defined_did('aaa')

        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(-1, valid_diddef)

        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0x10000, valid_diddef)

        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0xF200, empty_diddef)

        with self.assertRaises(Exception):
            self.udsclient.dynamically_define_did(0xF200, 'aaa')

        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did('aaa', valid_diddef)
    def _test_define_by_did_composite_wrong_did_echo(self):
        diddef = DynamicDidDefinition(source_did=0x1234,
                                      position=1,
                                      memorysize=2)
        diddef.add(source_did=0x5678, position=1, memorysize=4)
        diddef.add(source_did=0x1234, position=5, memorysize=2)

        with self.assertRaises(UnexpectedResponseException):
            self.udsclient.dynamically_define_did(0xf204, diddef)
    def _test_define_by_did_composite_success(self):
        diddef = DynamicDidDefinition(source_did=0x1234,
                                      position=1,
                                      memorysize=2)
        diddef.add(source_did=0x5678, position=1, memorysize=4)
        diddef.add(source_did=0x1234, position=5, memorysize=2)

        response = self.udsclient.dynamically_define_did(0xf202, diddef)
        self.assertEqual(response.service_data.subfunction_echo, 1)
        self.assertEqual(response.service_data.did_echo, 0xf202)
 def _test_define_by_did_incomplete_response(self):
     with self.assertRaises(InvalidResponseException):
         self.udsclient.dynamically_define_did(
             0xf201,
             DynamicDidDefinition(source_did=0x1234,
                                  position=1,
                                  memorysize=2))
    def _test_define_by_memloc_composite_success_default_format(self):
        diddef = DynamicDidDefinition()
        diddef.add(MemoryLocation(address=0x1122, memorysize=2))
        diddef.add(MemoryLocation(address=0x3344, memorysize=4))
        diddef.add(MemoryLocation(address=0x5566, memorysize=8))

        self.udsclient.set_config('server_address_format', 32)
        self.udsclient.set_config('server_memorysize_format', 16)

        response = self.udsclient.dynamically_define_did(0xf302, diddef)
        self.assertEqual(response.service_data.subfunction_echo, 2)
        self.assertEqual(response.service_data.did_echo, 0xf302)
    def _test_define_by_memloc_composite_wrong_did_echo(self):
        diddef = DynamicDidDefinition()
        diddef.add(
            MemoryLocation(address=0x1122,
                           memorysize=2,
                           address_format=16,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x3344,
                           memorysize=4,
                           address_format=16,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x5566,
                           memorysize=8,
                           address_format=16,
                           memorysize_format=8))

        with self.assertRaises(UnexpectedResponseException):
            self.udsclient.dynamically_define_did(0xf302, diddef)
 def _test_define_by_did_success(self):
     response = self.udsclient.dynamically_define_did(
         0xf201,
         DynamicDidDefinition(source_did=0x1234, position=1, memorysize=2))
     self.assertEqual(response.service_data.subfunction_echo, 1)
     self.assertEqual(response.service_data.did_echo, 0xf201)
    def _test_inconsistent_composite_memloc(self):
        self.udsclient.set_config('server_address_format', 16)
        self.udsclient.set_config('server_memorysize_format', 8)

        diddef = DynamicDidDefinition()
        diddef.add(
            MemoryLocation(address=0x11,
                           memorysize=2,
                           address_format=8,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x3344,
                           memorysize=4,
                           address_format=16,
                           memorysize_format=8))
        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0xf300, diddef)

        diddef = DynamicDidDefinition()
        diddef.add(
            MemoryLocation(address=0x1122,
                           memorysize=2,
                           address_format=16,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x3344,
                           memorysize=4,
                           address_format=16,
                           memorysize_format=16))
        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0xf300, diddef)

        diddef = DynamicDidDefinition()
        diddef.add(MemoryLocation(address=0x1122, memorysize=2))
        diddef.add(
            MemoryLocation(address=0x3344,
                           memorysize=4,
                           address_format=32,
                           memorysize_format=8))
        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0xf300, diddef)

        diddef = DynamicDidDefinition()
        diddef.add(MemoryLocation(address=0x1122, memorysize=2))
        diddef.add(
            MemoryLocation(address=0x3344,
                           memorysize=4,
                           address_format=16,
                           memorysize_format=16))
        with self.assertRaises(ValueError):
            self.udsclient.dynamically_define_did(0xf300, diddef)
Esempio n. 9
0
    def test_get_alfid(self):
        diddef = DynamicDidDefinition()
        diddef.add(source_did=0x1234, position=1, memorysize=1)
        diddef.add(source_did=0x1234, position=2, memorysize=1)
        with self.assertRaises(ValueError):
            diddef.get_alfid()

        diddef = DynamicDidDefinition()
        diddef.add(
            MemoryLocation(address=0x1234,
                           memorysize=1,
                           address_format=16,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x1235,
                           memorysize=1,
                           address_format=16,
                           memorysize_format=8))
        alfid = diddef.get_alfid()
        self.assertEqual(alfid.get_byte_as_int(), 0x12)

        diddef = DynamicDidDefinition()
        diddef.add(
            MemoryLocation(address=0x1234,
                           memorysize=1,
                           address_format=16,
                           memorysize_format=8))
        diddef.add(
            MemoryLocation(address=0x1235,
                           memorysize=1,
                           address_format=16,
                           memorysize_format=16))
        with self.assertRaises(ValueError):
            alfid = diddef.get_alfid()
Esempio n. 10
0
    def test_type(self):
        diddef = DynamicDidDefinition()

        self.assertFalse(diddef.is_by_source_did())
        self.assertFalse(diddef.is_by_memory_address())
        diddef.add(source_did=0x1234, position=1, memorysize=1)
        diddef.add(source_did=0x1234, position=2, memorysize=1)

        self.assertTrue(diddef.is_by_source_did())
        self.assertFalse(diddef.is_by_memory_address())

        diddef = DynamicDidDefinition()
        diddef.add(MemoryLocation(address=0x1234, memorysize=1))
        diddef.add(MemoryLocation(address=0x1235, memorysize=1))

        self.assertFalse(diddef.is_by_source_did())
        self.assertTrue(diddef.is_by_memory_address())
Esempio n. 11
0
 def test_def_mismatch(self):
     diddef = DynamicDidDefinition()
     diddef.add(source_did=0x1234, position=1, memorysize=1)
     with self.assertRaises(ValueError):
         diddef.add(MemoryLocation(address=0x1234, memorysize=1))