How to use the udsoncan.Baudrate function in udsoncan

To help you get started, we’ve selected a few udsoncan examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pylessard / python-udsoncan / test / client / test_link_control.py View on Github external
def _test_linkcontrol_verify_fixed(self):
        baudrate = Baudrate(250000, baudtype=Baudrate.Type.Fixed)
        response = self.udsclient.link_control(control_type=1, baudrate=baudrate)
        self.assertTrue(response.valid)
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.control_type_echo, 1)
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_create_fixed(self):
        br = Baudrate(115200, baudtype=Baudrate.Type.Fixed)
        self.assertEqual(br.get_bytes(), b'\x05')

        with self.assertRaises(ValueError):
            br = Baudrate(123456, baudtype=Baudrate.Type.Fixed)
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_oob_values(self):
        with self.assertRaises(ValueError):
            br = Baudrate(-1)

        with self.assertRaises(ValueError):
            br = Baudrate(1, baudtype=-1)

        with self.assertRaises(ValueError):
            br = Baudrate(1, baudtype=0xFF)
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_oob_values(self):
        with self.assertRaises(ValueError):
            br = Baudrate(-1)

        with self.assertRaises(ValueError):
            br = Baudrate(1, baudtype=-1)

        with self.assertRaises(ValueError):
            br = Baudrate(1, baudtype=0xFF)
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_create_id(self):
        for i in range (0xFF):
            br = Baudrate(i, baudtype=Baudrate.Type.Identifier)
            self.assertEqual(br.get_bytes(), struct.pack('B', i))

        with self.assertRaises(ValueError):
            br = Baudrate(0x100, baudtype=Baudrate.Type.Identifier)
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_change_type(self):
        br = Baudrate(115200, baudtype=Baudrate.Type.Fixed)
        br2 = br.make_new_type(Baudrate.Type.Specific)
        self.assertEqual(br2.get_bytes(), b'\x01\xC2\x00')

        br = Baudrate(115200, baudtype=Baudrate.Type.Specific)
        br2 = br.make_new_type(Baudrate.Type.Fixed)
        self.assertEqual(br2.get_bytes(), b'\x05')
github pylessard / python-udsoncan / test / test_helper_class.py View on Github external
def test_effective_baudrate(self):
        br = Baudrate(0x12, Baudrate.Type.Identifier) # 500kbits
        self.assertEqual(br.effective_baudrate(), 500000)
github pylessard / python-udsoncan / test / client / test_link_control.py View on Github external
def _test_linkcontrol_verify_specific(self):
        baudrate = Baudrate(0x123456, baudtype=Baudrate.Type.Specific)
        response = self.udsclient.link_control(control_type=2, baudrate=baudrate)
        self.assertTrue(response.valid)
        self.assertTrue(response.positive)
        self.assertEqual(response.service_data.control_type_echo, 2)
github pylessard / python-udsoncan / udsoncan / services.py View on Github external
def __init__(self, control_type, baudrate=None):
		from udsoncan import Baudrate
		if not isinstance(control_type, int):
			raise ValueError('control_type must be an integer')

		if control_type < 0 or control_type > 0x7F:
			raise ValueError('control_type must be an integer between 0 and 0x7F')

		if control_type in [self.ControlType.verifyBaudrateTransitionWithSpecificBaudrate, self.ControlType.verifyBaudrateTransitionWithFixedBaudrate]:
			if baudrate is None:
				raise ValueError('A Baudrate must be provided with control type : "verifyBaudrateTransitionWithSpecificBaudrate" (0x%02x) or "verifyBaudrateTransitionWithFixedBaudrate" (0x%02x)' % (self.ControlType.verifyBaudrateTransitionWithSpecificBaudrate, self.ControlType.verifyBaudrateTransitionWithFixedBaudrate))

			if not isinstance(baudrate, Baudrate):
				raise ValueError('Given baudrate must be an instance of the Baudrate class')
		else:
			if baudrate is not None:
				raise ValueError('The baudrate parameter is only needed when control type is "verifyBaudrateTransitionWithSpecificBaudrate" (0x%02x) or "verifyBaudrateTransitionWithFixedBaudrate" (0x%02x)' % (self.ControlType.verifyBaudrateTransitionWithSpecificBaudrate, self.ControlType.verifyBaudrateTransitionWithFixedBaudrate))

		self.baudrate = baudrate
		self.control_type = control_type
		
		if control_type == self.ControlType.verifyBaudrateTransitionWithSpecificBaudrate:
			self.baudrate = self.baudrate.make_new_type(Baudrate.Type.Specific)

		if control_type == self.ControlType.verifyBaudrateTransitionWithFixedBaudrate and baudrate.baudtype == Baudrate.Type.Specific:
			self.baudrate = self.baudrate.make_new_type(Baudrate.Type.Fixed)