Exemplo n.º 1
0
    def setUp(self):
        self.custom_type = parser.CompoundType(
            "CustomType",
            parser.CompoundType.KIND_MESSAGE,
            "source.uavcan",
            0,
            ""
        )
        self.custom_type.fields = [
            parser.Field(
                parser.PrimitiveType(
                    parser.PrimitiveType.KIND_FLOAT,
                    16,
                    parser.PrimitiveType.CAST_MODE_SATURATED
                ),
                "a"
            ),
            parser.Field(parser.VoidType(3), None),
            parser.Field(
                parser.PrimitiveType(
                    parser.PrimitiveType.KIND_UNSIGNED_INT,
                    1,
                    parser.PrimitiveType.CAST_MODE_SATURATED
                ),
                "b"
            )
        ]

        def custom_type_factory(*args, **kwargs):
            return transport.CompoundValue(self.custom_type, _tao=True, *args,
                                           **kwargs)
        self.custom_type._instantiate = custom_type_factory
Exemplo n.º 2
0
    def setUp(self):
        self.custom_type = parser.CompoundType(
            "CustomType", parser.CompoundType.KIND_MESSAGE, "source.uavcan", 0,
            "")
        self.custom_type.union = True
        self.custom_type.fields = [
            parser.Field(
                parser.PrimitiveType(parser.PrimitiveType.KIND_FLOAT, 16,
                                     parser.PrimitiveType.CAST_MODE_SATURATED),
                "a"),
            parser.Field(
                parser.ArrayType(
                    parser.PrimitiveType(
                        parser.PrimitiveType.KIND_UNSIGNED_INT, 8,
                        parser.PrimitiveType.CAST_MODE_SATURATED),
                    parser.ArrayType.MODE_STATIC, 2), "b")
        ]

        def custom_type_factory(*args, **kwargs):
            return transport.CompoundValue(self.custom_type,
                                           tao=True,
                                           *args,
                                           **kwargs)

        self.custom_type.__call__ = custom_type_factory
Exemplo n.º 3
0
 def test_signed_saturated_33bit(self):
     dtype = parser.PrimitiveType(parser.PrimitiveType.KIND_SIGNED_INT, 33,
                                  parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(8589934591, dtype)
     self.assertEqual(value, 4294967295)
     value = transport.cast(-8589934592, dtype)
     self.assertEqual(value, -4294967296)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, -1)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
0
 def test_unsigned_saturated_64bit(self):
     dtype = parser.PrimitiveType(parser.PrimitiveType.KIND_UNSIGNED_INT,
                                  64,
                                  parser.PrimitiveType.CAST_MODE_SATURATED)
     value = transport.cast(0, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(18446744073709551615, dtype)
     self.assertEqual(value, 18446744073709551615)
     value = transport.cast(-1, dtype)
     self.assertEqual(value, 0)
     value = transport.cast(18446744073709551617, dtype)
     self.assertEqual(value, 18446744073709551615)
     value = transport.cast(-18446744073709551615, dtype)
     self.assertEqual(value, 0)
Exemplo n.º 9
0
    def setUp(self):
        custom_type = parser.CompoundType("CustomType",
                                          parser.CompoundType.KIND_MESSAGE,
                                          "source.uavcan", 0, "")
        custom_type.fields = [
            parser.Field(
                parser.PrimitiveType(parser.PrimitiveType.KIND_SIGNED_INT, 8,
                                     parser.PrimitiveType.CAST_MODE_TRUNCATED),
                "a"),
            parser.Field(
                parser.PrimitiveType(parser.PrimitiveType.KIND_FLOAT, 16,
                                     parser.PrimitiveType.CAST_MODE_SATURATED),
                "b"),
            parser.Field(
                parser.ArrayType(
                    parser.PrimitiveType(
                        parser.PrimitiveType.KIND_UNSIGNED_INT, 1,
                        parser.PrimitiveType.CAST_MODE_SATURATED),
                    parser.ArrayType.MODE_DYNAMIC, 5), "c")
        ]

        def custom_type_factory(*args, **kwargs):
            return transport.CompoundValue(custom_type, *args, **kwargs)

        custom_type._instantiate = custom_type_factory

        self.a1_type = parser.ArrayType(
            parser.PrimitiveType(parser.PrimitiveType.KIND_SIGNED_INT, 8,
                                 parser.PrimitiveType.CAST_MODE_TRUNCATED),
            parser.ArrayType.MODE_STATIC, 4)
        self.a2_type = parser.ArrayType(
            parser.PrimitiveType(parser.PrimitiveType.KIND_FLOAT, 16,
                                 parser.PrimitiveType.CAST_MODE_SATURATED),
            parser.ArrayType.MODE_STATIC, 2)
        self.a3_type = parser.ArrayType(custom_type,
                                        parser.ArrayType.MODE_STATIC, 2)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 def make_float(bitlen):
     return parser.PrimitiveType(
         parser.PrimitiveType.KIND_FLOAT, bitlen,
         parser.PrimitiveType.CAST_MODE_TRUNCATED)