Пример #1
0
 def _struct(cls):
     return construct.Struct(
         "type" / construct.Enum(construct.Byte, ParamType),
         "value" / construct.Switch(
             construct.this.type,
             {
                 "Int":
                 construct.Int32sl,
                 "Float":
                 construct.ExprAdapter(
                     construct.Bytes(10),
                     lambda obj, ctx: numpy.frombuffer(
                         obj.rjust(16, b"\x00"), dtype=numpy.longdouble),
                     lambda obj, ctx: numpy.longdouble(obj).tobytes()[-10:],
                 ),
                 "Flag":
                 construct.Byte,
                 "Str":
                 construct.PascalString(construct.Int32ul, "cp932"),
             },
             # else 'Var' variable name type
             construct.Select(
                 construct.PascalString(construct.Int32ul, "cp932"), ),
         ),
     )
Пример #2
0
 def __init__(self, const):
     self.const = const
     super().__init__(
         c.IfThenElse(
             c.this._building,
             c.Select(c.Bytes(len(self.const)), c.Pass),
             Optional(c.Const(const)),
         )
     )
Пример #3
0
class JBSQ(ct.TContainerMixin):
    magic: Optional[bytes] = ct.sfield(
        c.Select(c.Const(b"IJBQ"), c.Const(b"IJSQ"), c.Const(b"JBSQ")))
    num_events: int = ct.sfield(c.Int32ul)
    combo: int = ct.sfield(c.Int32ul)
    end_time: int = ct.sfield(c.Int32ul)
    _1: None = ct.sfield(c.Padding(2))
    starting_buttons: int = ct.sfield(c.Int16ul)
    start_time: int = ct.sfield(c.Int32ul)
    _2: None = ct.sfield(c.Padding(12))
    density_graph: List[int] = ct.sfield(c.Byte[60])
    events: List[Event] = ct.sfield(
        c.Array(c.this.num_events, ct.TStruct(Event)))
Пример #4
0
 def _struct(cls):
     return construct.Struct(
         'version' / _LsbVersionValidator(construct.Int32ul),
         'flags' / construct.Byte,
         'command_count' / construct.Int32ul,
         'param_stream_size' / construct.Int32ul,
         'command_params' / construct.Array(
             construct.this.command_count,
             _ParamStreamAdapter(
                 construct.Bytes(construct.this.param_stream_size)),
         ),
         'commands' / construct.PrefixedArray(
             construct.Int32ul, construct.Select(*_command_structs)),
     )
Пример #5
0
 def _struct(cls):
     return construct.Struct(
         "version" / LsbVersionValidator(construct.Int32ul),
         "flags" / construct.Byte,
         "command_count" / construct.Int32ul,
         "param_stream_size" / construct.Int32ul,
         "command_params" / construct.Array(
             construct.this.command_count,
             _ParamStreamAdapter(
                 construct.Bytes(construct.this.param_stream_size)),
         ),
         "commands" / construct.PrefixedArray(
             construct.Int32ul, construct.Select(*_command_structs)),
     )
Пример #6
0
 def _struct(cls):
     return construct.Struct(
         'type' / construct.Enum(construct.Byte, ParamType),
         'value' / construct.Switch(
             construct.this.type,
             {
                 'Int': construct.Int32ul,
                 'Float': construct.ExprAdapter(
                     construct.Bytes(10),
                     lambda obj, ctx: numpy.frombuffer(obj.rjust(16, b'\x00'),
                                                       dtype=numpy.longdouble),
                     lambda obj, ctx: numpy.longdouble(obj).tobytes()[-10:]
                 ),
                 'Flag': construct.Byte,
                 'Str': construct.PascalString(construct.Int32ul, 'cp932'),
             },
             # else 'Var' variable name type
             construct.Select(
                 construct.PascalString(construct.Int32ul, 'cp932'),
             ),
         ),
     )
Пример #7
0
 con.Select(
     # New format starting from firmware v0.2 - added a new field 'torque' and one reserved four bytes long field
     con.Struct(
         'stall_count' / U32,
         'demand_factor' / F32,
         # Mechanical parameters
         'electrical_angular_velocity' / F32,
         'mechanical_angular_velocity' / F32,
         'torque' / F32,
         # Rotating system parameters
         'u_dq' / con.Array(2, F32),
         'i_dq' / con.Array(2, F32),
         # Control mode
         'mode' / ControlModeFormat,
         # State flags
         'spinup_in_progress' / con.Flag,
         'rotation_reversed' / con.Flag,
         'controller_saturated' / con.Flag,
     ),
     # An older format used in the firmware v0.1 - this one is shorter, hence it must be at the end of Select()
     con.Struct(
         'stall_count' / U32,
         'demand_factor' / F32,
         'electrical_angular_velocity' / F32,
         'mechanical_angular_velocity' / F32,
         'u_dq' / con.Array(2, F32),
         'i_dq' / con.Array(2, F32),
         'mode' / ControlModeFormat,
         'spinup_in_progress' / con.Flag,
         'rotation_reversed' / con.Flag,
         'controller_saturated' / con.Flag,
     ),
 ),
Пример #8
0
        construct.macros.BitField('gct_size', 3),
    ),
    construct.ULInt8('bg_col_index'),
    construct.ULInt8('pixel_aspect'),
)

_gct = construct.Array(
    lambda ctx: pow(2, ctx.logical_screen_descriptor.gct_size + 1),
    construct.Array(3, construct.ULInt8('gct')),
)

gif = construct.Struct(
    'GIF',
    construct.Select(
        'magic',
        construct.Magic('GIF89a'),
        construct.Magic('GIF87a'),
    ),
    _logical_screen_descriptor,
    construct.If(lambda ctx: ctx.logical_screen_descriptor.gct_flag, _gct),
    construct.RepeatUntil(
        lambda obj, ctx: obj.block_start == 0x3B,
        construct.Struct(
            'body',
            construct.ULInt8('block_start'),
            construct.Embedded(
                construct.Switch(
                    'block',
                    lambda ctx: ctx.block_start,
                    {
                        0x3B:
Пример #9
0
 con.Select(
     # New format starting from firmware v0.2 - added a new field 'torque' and one reserved four bytes long field
     con.Struct(
         "stall_count" / U32,
         "demand_factor" / F32,
         # Mechanical parameters
         "electrical_angular_velocity" / F32,
         "mechanical_angular_velocity" / F32,
         "torque" / F32,
         # Rotating system parameters
         "u_dq" / con.Array(2, F32),
         "i_dq" / con.Array(2, F32),
         # Control mode
         "mode" / ControlModeFormat,
         # State flags
         "spinup_in_progress" / con.Flag,
         "rotation_reversed" / con.Flag,
         "controller_saturated" / con.Flag,
     ),
     # An older format used in the firmware v0.1 - this one is shorter, hence it must be at the end of Select()
     con.Struct(
         "stall_count" / U32,
         "demand_factor" / F32,
         "electrical_angular_velocity" / F32,
         "mechanical_angular_velocity" / F32,
         "u_dq" / con.Array(2, F32),
         "i_dq" / con.Array(2, F32),
         "mode" / ControlModeFormat,
         "spinup_in_progress" / con.Flag,
         "rotation_reversed" / con.Flag,
         "controller_saturated" / con.Flag,
     ),
 ),
Пример #10
0
def Optional(subcon):
    """Custom version of Optional which fixes construct issue #760"""
    select = c.Select(subcon, c.Pass)
    select.flagbuildnone = True
    return select
Пример #11
0
TRANSPORT_DATA_PARAMETER = construct.Select(
    # BYTE
    construct.Struct(
        "data_type" / construct.Const(bytes([TransportDataType.BYTE])),
        construct.Const(bytes([0x00, 0x01])),
        "data" / construct.Byte,
    ),
    # BYTE_ARRAY
    construct.Struct(
        "data_type" / construct.Const(bytes([TransportDataType.BYTE_ARRAY])),
        "data" / construct.Prefixed(construct.Int16ub, construct.GreedyBytes),
    ),
    # SHORT
    construct.Struct(
        "data_type" / construct.Const(bytes([TransportDataType.SHORT])),
        construct.Const(bytes([0x00, 0x02])),
        "data" / construct.Int16ub,
    ),
    # STRING
    construct.Struct(
        "data_type" / construct.Const(bytes([TransportDataType.STRING])),
        "data" /
        construct.Prefixed(construct.Int16ub, construct.GreedyString("ascii")),
    ),
    # LONG_ARRAY
    construct.Struct(
        "data_type" / construct.Const(bytes([TransportDataType.LONG_ARRAY])),
        construct.Const(bytes([0x00, 0x02])),
        "data" / construct.Prefixed(construct.Int16ub,
                                    construct.GreedyRange(construct.Int32ub)),
    ),
)