How to use the uavcan.transport.cast function in uavcan

To help you get started, we’ve selected a few uavcan 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 UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_unsigned_saturated_1bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            1,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(1, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(2, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(5, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(-10, dtype)
        self.assertEqual(value, 0)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_unsigned_saturated_1bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            1,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(1, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(2, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(5, dtype)
        self.assertEqual(value, 1)
        value = transport.cast(-10, dtype)
        self.assertEqual(value, 0)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_unsigned_saturated_33bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            33,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(8589934591, dtype)
        self.assertEqual(value, 8589934591)
        value = transport.cast(8589934592, dtype)
        self.assertEqual(value, 8589934591)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 0)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_signed_saturated_64bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_SIGNED_INT,
            64,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(18446744073709551615, dtype)
        self.assertEqual(value, 9223372036854775808)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, -1)
        value = transport.cast(-18446744073709551617, dtype)
        self.assertEqual(value, -9223372036854775809)
        value = transport.cast(-9223372036854775808, dtype)
        self.assertEqual(value, -9223372036854775808)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_unsigned_saturated_4bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            4,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(15, dtype)
        self.assertEqual(value, 15)
        value = transport.cast(16, dtype)
        self.assertEqual(value, 15)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(30, dtype)
        self.assertEqual(value, 15)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_signed_saturated_64bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_SIGNED_INT,
            64,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(18446744073709551615, dtype)
        self.assertEqual(value, 9223372036854775808)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, -1)
        value = transport.cast(-18446744073709551617, dtype)
        self.assertEqual(value, -9223372036854775809)
        value = transport.cast(-9223372036854775808, dtype)
        self.assertEqual(value, -9223372036854775808)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_truncated_33bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            33,
            parser.PrimitiveType.CAST_MODE_TRUNCATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(8589934591, dtype)
        self.assertEqual(value, 8589934591)
        value = transport.cast(8589934592, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 8589934591)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_unsigned_saturated_33bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            33,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(8589934591, dtype)
        self.assertEqual(value, 8589934591)
        value = transport.cast(8589934592, dtype)
        self.assertEqual(value, 8589934591)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 0)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_truncated_4bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_UNSIGNED_INT,
            4,
            parser.PrimitiveType.CAST_MODE_TRUNCATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(15, dtype)
        self.assertEqual(value, 15)
        value = transport.cast(16, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, 15)
        value = transport.cast(30, dtype)
        self.assertEqual(value, 14)
github UAVCAN / pyuavcan / test / test_transport.py View on Github external
def test_signed_saturated_4bit(self):
        dtype = parser.PrimitiveType(
            parser.PrimitiveType.KIND_SIGNED_INT,
            4,
            parser.PrimitiveType.CAST_MODE_SATURATED)
        value = transport.cast(0, dtype)
        self.assertEqual(value, 0)
        value = transport.cast(15, dtype)
        self.assertEqual(value, 7)
        value = transport.cast(16, dtype)
        self.assertEqual(value, 7)
        value = transport.cast(-1, dtype)
        self.assertEqual(value, -1)
        value = transport.cast(-30, dtype)
        self.assertEqual(value, -8)