Beispiel #1
0
class Robot2DriverStationPacket(Structure):
    control_byte = BitField(8,
                            reset=BitBool(),
                            not_estop=BitBool(),
                            enabled=BitBool(),
                            autonmous=BitBool(),
                            fms_attacted=BitBool(),
                            resync=BitBool(),
                            test=BitBool(),
                            fpga_checksum=BitBool())
    battery_voltage = UBInt16()
    ds_digital_in = UBInt8()
    unknown_1 = UBInt32()
    team_number = UBInt16()
    crio_mac_address = UBInt48()
    version = UBInt64()
    unknown_2b = UBInt40()
    reported_state = UBInt8()
    packet_index = UBInt16()
    unknown_4 = Payload(988)
    crc_checksum = CRCField(UBInt32(), crc32, 0, 1024)

    def reported_state_str(self):
        if self.reported_state == 0:
            return c.NO_CODE
        elif self.reported_state == 1:
            return c.DISABLED
        elif self.reported_state == 4:
            return c.TELEOP
        else:
            return "Unknown: " + str(self.reported_state)
class BoxedGreedy(Structure):
    sof = Magic(b'\xAA')
    a = LengthField(UBInt8())
    b = UBInt8()
    payload = Payload()
    c = UBInt16()
    d = VariableRawPayload(a)
    eof = Magic(b'\xbb')
Beispiel #3
0
class ConditionalDispatch(Structure):
    f1 = DispatchField(UBInt8())
    f2 = UBInt8()  # separate from f1
    length = LengthField(UBInt8())
    f3 = ConditionalField(DispatchTarget(length, f1, {
        0: EmptyStructure,
        1: BasicMessage
    }),
                          condition=lambda m: m.f2 == 255)
Beispiel #4
0
class BGAPIFrame(Structure):
    head = LengthField(BitField(16,
                                is_event=BitBool(),
                                technology_type=BitNum(4),
                                length=BitNum(11)),
                       get_length=lambda f: f.length,
                       set_length=lambda f, l: setattr(f, 'length', l))
    class_id = UBInt8()
    command_id = UBInt8()
    payload = Payload(head)
Beispiel #5
0
class UserInfo(Structure):
    """Player data.

    This structure has the following format:

    +---------+---------------------------------------+
    | Byte    | Description                           |
    +=========+=======================================+
    | 0-7     | Version. Same for all players.        |
    +---------+---------------------------------------+
    | 8-15    | xuid. Some sort of unique ID.         |
    +---------+---------------------------------------+
    | 15-142  | Player name.                          |
    +---------+---------------------------------------+
    | 143-146 | Local server user ID.                 |
    +---------+---------------------------------------+
    | 147-179 | GUID                                  |
    +---------+---------------------------------------+
    | 180-183 | Friend's ID.                          |
    +---------+---------------------------------------+
    | 184-312 | Friend's Name.                        |
    +---------+---------------------------------------+
    | 313     | Is player a bot?                      |
    +---------+---------------------------------------+
    | 314     | Is player an HLTV proxy?              |
    +---------+---------------------------------------+
    | 314-329 | Custom files CRC.                     |
    +---------+---------------------------------------+
    | 330     | Numbre of files downloaded by server. |
    +---------+---------------------------------------+
    | 331-335 | Entity index.                         |
    +---------+---------------------------------------+
    | 336-340 | No idea.                              |
    +---------+---------------------------------------+
    """
    version = UBInt64()
    xuid = UBInt64()
    name = FixedLengthString(consts.MAX_PLAYER_NAME_LENGTH)
    user_id = UBInt32()
    guid = FixedLengthString(consts.SIGNED_GUID_LEN)
    friends_id = UBInt32()
    friends_name = FixedLengthString(consts.MAX_PLAYER_NAME_LENGTH)
    fake_player = UBInt8()
    is_hltv = UBInt8()
    custom_files = UBInt32Sequence(consts.MAX_CUSTOM_FILES)
    files_downloaded = UBInt8()
    entity_id = UBInt32()
    tbd = UBInt32()
Beispiel #6
0
class MyDynamicLengthDispatchMessage(Structure):
    type = DispatchField(UBInt8())
    body = DispatchTarget(None, type, {
        0x1F: MySimpleFixedPayload,
        0xCC: MyPayloadMessage,
    })
    eof = Magic(b'EOF')
class IPV4Frame(Structure):
    options = BitField(64,
                       version=BitNum(4),
                       internet_header_length=BitNum(4),
                       differentiated_services_code_point=BitNum(6),
                       explicit_congestion_notification=BitNum(2),
                       total_length=BitNum(16),
                       identification=BitNum(16),
                       flags=BitNum(3),
                       fragment_offset=BitNum(13),
                       )
    time_to_live = UBInt8()
    protocol = DispatchField(UBInt8())
    header_checksum = UBInt16()
    source_ip_address = UBInt32()
    destination_ip_address = UBInt32()
Beispiel #8
0
class ConditionalArrayElement(Structure):
    options = BitField(8,
                       cond8_present=BitBool(),
                       cond16_present=BitBool(),
                       unused=BitNum(6))
    cond8 = ConditionalField(UBInt8(), lambda m: m.options.cond8_present)
    cond16 = ConditionalField(UBInt16(), lambda m: m.options.cond16_present)
Beispiel #9
0
class PortTrafficStatistics(Structure):
    port = UBInt8()
    bytes_received = UBInt64()
    bytes_sent = UBInt64()
    unknown_0 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00')
    unknown_1 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00')
    unknown_2 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00')
    crc_error_packets = UBInt64()
class MyBasicDispatchMessage(Structure):
    type = DispatchField(UBInt8())
    length = LengthField(UBInt16())
    body = DispatchTarget(
        length, type, {
            0x00: MyTargetMessage,
            0x01: MyOtherTargetMessage,
            None: MyDefaultTargetMessage
        })
Beispiel #11
0
class Frame(Structure):
    version = UBInt8()
    operation = UBInt8()
    result = UBInt16()
    reserved_0 = Magic('\x00\x00\x00\x00')
    _host_mac = UBInt8Sequence(6)
    host_mac = FieldProperty(_host_mac,
                             onget=lambda v: unpack_mac(''.join(map(chr, v))),
                             onset=lambda v: tuple(map(ord, pack_mac(v))))
    _device_mac = UBInt8Sequence(6)
    device_mac = FieldProperty(
        _device_mac,
        onget=lambda v: unpack_mac(''.join(map(chr, v))),
        onset=lambda v: tuple(map(ord, pack_mac(v))))
    reserved_1 = Magic('\x00\x00')
    sequence = UBInt16()
    signature = Magic('NSDP')
    reserved_2 = Magic('\x00\x00\x00\x00')
    messages = FieldArray(Message)
class SuperMessage(Structure):
    magic = Magic(b'\xAA\xAA')

    # bitfield
    options = BitField(8, b1=BitBool(), b2=BitBool(), rest=BitNum(6))

    # unsigned big endian
    ubint8 = UBInt8()
    ubint16 = UBInt16()
    ubint24 = UBInt24()
    ubint32 = UBInt32()
    ubint64 = UBInt64()

    # signed big endian
    sbint8 = SBInt8()
    sbint16 = SBInt16()
    sbint32 = SBInt32()
    sbint64 = SBInt64()

    # unsigned little endian
    ulint8 = ULInt8()
    ulint16 = ULInt16()
    ulint32 = ULInt32()
    ulint64 = ULInt64()

    # signed little endian
    slint8 = SLInt8()
    slint16 = SLInt16()
    slint32 = SLInt32()
    slint64 = SLInt64()

    # optional
    optional_one = ConditionalField(UBInt8(), lambda m: m.options.b1)
    optional_two = ConditionalField(UBInt8(), lambda m: m.options.b2)

    # sequences with variable lengths
    ubseql = LengthField(UBInt8())
    ubseq = UBInt8Sequence(ubseql)

    sbseql = LengthField(UBInt8())
    sbseq = SBInt8Sequence(sbseql)

    # sequences with fixed lengths
    ubseqf = UBInt8Sequence(5)
    sbseqf = SBInt8Sequence(5)

    # don't change anything... for test coverage
    ulint16_value = FieldProperty(ulint16)
    ulint16_byte_string = FieldProperty(
        ulint16,
        onget=lambda v: str(v),
        onset=lambda v: struct.unpack(">H", v)[0])

    message_type = DispatchField(UBInt8())
    submessage_length = LengthField(UBInt16())
    submessage = DispatchTarget(submessage_length, message_type,
                                {0xEF: SuperChild})

    # checksum starts after beginning magic, ends before
    # the checksum
    crc = CRCField(UBInt16(), crc16_ccitt, 2, -3)
    eof = Magic(b'~')
class BasicGreedy(Structure):
    a = UBInt8()
    b = UBInt8()
    payload = Payload()
 class MyVarSeqMessage(Structure):
     type = UBInt8()
     length = LengthField(UBInt8())
     seq = UBInt8Sequence(length)
Beispiel #15
0
class ErrorCaseSchema(Structure):
    type = DispatchField(UBInt8())
    length = LengthField(UBInt8())
    body = DispatchTarget(length, type, {
        0x00: MagicSchema
    })
 class MyMuiltipliedLengthMessage(Structure):
     length = LengthField(UBInt8(), multiplier=8)
     payload = VariableRawPayload(length)
 class MySeqMessage(Structure):
     type = UBInt8()
     byte_values = UBInt8Sequence(16)
Beispiel #18
0
class TypeFieldWrongSize(Structure):
    type = TypeField(UBInt8(), size_mapping)
    greedy = Payload(type)
class BasicMessage(Structure):
    b1 = UBInt8()
    b2 = UBInt8()
Beispiel #20
0
class TypedArrayElement(Structure):
    type = TypeField(UBInt8(), size_mapping)
    value = DispatchTarget(type, type, dispatch_mapping)
Beispiel #21
0
class TypeFieldNoLengthProvider(Structure):
    type = TypeField(UBInt8(), size_mapping)
Beispiel #22
0
class DriverStation2RobotPacket(Structure):
    packet_index = UBInt16()
    control_byte = BitField(8,
                            reset=BitBool(),
                            not_estop=BitBool(),
                            enabled=BitBool(),
                            autonmous=BitBool(),
                            fms_attached=BitBool(),
                            resync=BitBool(),
                            test=BitBool(),
                            fpga_checksum=BitBool())
    digital_input = BitField(
        8,
        input_8=BitBool(),
        input_7=BitBool(),
        input_6=BitBool(),
        input_5=BitBool(),
        input_4=BitBool(),
        input_3=BitBool(),
        input_2=BitBool(),
        input_1=BitBool(),
    )
    team_number = UBInt16()
    alliance = UBInt8()  #ASCII of B or R
    position = UBInt8()  #ASCII of 1,2,3

    joystick_1_axis_1 = SBInt8()
    joystick_1_axis_2 = SBInt8()
    joystick_1_axis_3 = SBInt8()
    joystick_1_axis_4 = SBInt8()
    joystick_1_axis_5 = SBInt8()
    joystick_1_axis_6 = SBInt8()
    joystick_1_buttons = BitField(16,
                                  button_1=BitBool(),
                                  button_2=BitBool(),
                                  button_3=BitBool(),
                                  button_4=BitBool(),
                                  button_5=BitBool(),
                                  button_6=BitBool(),
                                  button_7=BitBool(),
                                  button_8=BitBool(),
                                  button_9=BitBool(),
                                  button_10=BitBool(),
                                  button_11=BitBool(),
                                  button_12=BitBool(),
                                  button_13=BitBool(),
                                  button_14=BitBool(),
                                  button_15=BitBool(),
                                  button_16=BitBool())
    joystick_2_axis_1 = SBInt8()
    joystick_2_axis_2 = SBInt8()
    joystick_2_axis_3 = SBInt8()
    joystick_2_axis_4 = SBInt8()
    joystick_2_axis_5 = SBInt8()
    joystick_2_axis_6 = SBInt8()
    joystick_2_buttons = BitField(16,
                                  button_1=BitBool(),
                                  button_2=BitBool(),
                                  button_3=BitBool(),
                                  button_4=BitBool(),
                                  button_5=BitBool(),
                                  button_6=BitBool(),
                                  button_7=BitBool(),
                                  button_8=BitBool(),
                                  button_9=BitBool(),
                                  button_10=BitBool(),
                                  button_11=BitBool(),
                                  button_12=BitBool(),
                                  button_13=BitBool(),
                                  button_14=BitBool(),
                                  button_15=BitBool(),
                                  button_16=BitBool())
    joystick_3_axis_1 = SBInt8()
    joystick_3_axis_2 = SBInt8()
    joystick_3_axis_3 = SBInt8()
    joystick_3_axis_4 = SBInt8()
    joystick_3_axis_5 = SBInt8()
    joystick_3_axis_6 = SBInt8()
    joystick_3_buttons = BitField(16,
                                  button_1=BitBool(),
                                  button_2=BitBool(),
                                  button_3=BitBool(),
                                  button_4=BitBool(),
                                  button_5=BitBool(),
                                  button_6=BitBool(),
                                  button_7=BitBool(),
                                  button_8=BitBool(),
                                  button_9=BitBool(),
                                  button_10=BitBool(),
                                  button_11=BitBool(),
                                  button_12=BitBool(),
                                  button_13=BitBool(),
                                  button_14=BitBool(),
                                  button_15=BitBool(),
                                  button_16=BitBool())
    joystick_4_axis_1 = SBInt8()
    joystick_4_axis_2 = SBInt8()
    joystick_4_axis_3 = SBInt8()
    joystick_4_axis_4 = SBInt8()
    joystick_4_axis_5 = SBInt8()
    joystick_4_axis_6 = SBInt8()
    joystick_4_buttons = BitField(16,
                                  button_1=BitBool(),
                                  button_2=BitBool(),
                                  button_3=BitBool(),
                                  button_4=BitBool(),
                                  button_5=BitBool(),
                                  button_6=BitBool(),
                                  button_7=BitBool(),
                                  button_8=BitBool(),
                                  button_9=BitBool(),
                                  button_10=BitBool(),
                                  button_11=BitBool(),
                                  button_12=BitBool(),
                                  button_13=BitBool(),
                                  button_14=BitBool(),
                                  button_15=BitBool(),
                                  button_16=BitBool())
    analog_value_1 = UBInt16()
    analog_value_2 = UBInt16()
    analog_value_3 = UBInt16()
    analog_value_4 = UBInt16()
    crio_checksum = UBInt64()
    fpga_checksum_1 = UBInt32()
    fpga_checksum_2 = UBInt32()
    fpga_checksum_3 = UBInt32()
    fpga_checksum_4 = UBInt32()
    driver_station_version = UBInt64()  #ASCII string such as '02121300'

    unknown = Payload(939)

    crc_checksum = CRCField(UBInt32(), crc32, 0, 1024)

    @staticmethod
    def make_packet(index, team_number):
        """
        I Don't like this
        """
        ret = DriverStation2RobotPacket()
        ret.packet_index = index
        ret.control_byte.reset = False
        ret.control_byte.not_estop = True
        ret.control_byte.enabled = False
        ret.control_byte.autonmous = False
        ret.control_byte.fms_attached = False
        ret.control_byte.resync = False
        ret.control_byte.fpga_checksum = False
        ret.digital_input.input_8 = False
        ret.digital_input.input_7 = False
        ret.digital_input.input_6 = False
        ret.digital_input.input_5 = False
        ret.digital_input.input_4 = False
        ret.digital_input.input_3 = False
        ret.digital_input.input_2 = False
        ret.digital_input.input_1 = False
        ret.team_number = team_number
        ret.alliance = ord('R')
        ret.position = ord('1')
        ret.joystick_1_axis_1 = 0
        ret.joystick_1_axis_2 = 0
        ret.joystick_1_axis_3 = 0
        ret.joystick_1_axis_4 = 0
        ret.joystick_1_axis_5 = 0
        ret.joystick_1_axis_6 = 0
        ret.joystick_1_buttons.button_1 = False
        ret.joystick_1_buttons.button_2 = False
        ret.joystick_1_buttons.button_3 = False
        ret.joystick_1_buttons.button_4 = False
        ret.joystick_1_buttons.button_5 = False
        ret.joystick_1_buttons.button_6 = False
        ret.joystick_1_buttons.button_7 = False
        ret.joystick_1_buttons.button_8 = False
        ret.joystick_1_buttons.button_9 = False
        ret.joystick_1_buttons.button_10 = False
        ret.joystick_1_buttons.button_11 = False
        ret.joystick_1_buttons.button_12 = False
        ret.joystick_1_buttons.button_13 = False
        ret.joystick_1_buttons.button_14 = False
        ret.joystick_1_buttons.button_15 = False
        ret.joystick_1_buttons.button_16 = False

        ret.joystick_2_axis_1 = 0
        ret.joystick_2_axis_2 = 0
        ret.joystick_2_axis_3 = 0
        ret.joystick_2_axis_4 = 0
        ret.joystick_2_axis_5 = 0
        ret.joystick_2_axis_6 = 0
        ret.joystick_2_buttons.button_1 = False
        ret.joystick_2_buttons.button_2 = False
        ret.joystick_2_buttons.button_3 = False
        ret.joystick_2_buttons.button_4 = False
        ret.joystick_2_buttons.button_5 = False
        ret.joystick_2_buttons.button_6 = False
        ret.joystick_2_buttons.button_7 = False
        ret.joystick_2_buttons.button_8 = False
        ret.joystick_2_buttons.button_9 = False
        ret.joystick_2_buttons.button_10 = False
        ret.joystick_2_buttons.button_11 = False
        ret.joystick_2_buttons.button_12 = False
        ret.joystick_2_buttons.button_13 = False
        ret.joystick_2_buttons.button_14 = False
        ret.joystick_2_buttons.button_15 = False
        ret.joystick_2_buttons.button_16 = False

        ret.joystick_3_axis_1 = 0
        ret.joystick_3_axis_2 = 0
        ret.joystick_3_axis_3 = 0
        ret.joystick_3_axis_4 = 0
        ret.joystick_3_axis_5 = 0
        ret.joystick_3_axis_6 = 0
        ret.joystick_3_buttons.button_1 = False
        ret.joystick_3_buttons.button_2 = False
        ret.joystick_3_buttons.button_3 = False
        ret.joystick_3_buttons.button_4 = False
        ret.joystick_3_buttons.button_5 = False
        ret.joystick_3_buttons.button_6 = False
        ret.joystick_3_buttons.button_7 = False
        ret.joystick_3_buttons.button_8 = False
        ret.joystick_3_buttons.button_9 = False
        ret.joystick_3_buttons.button_10 = False
        ret.joystick_3_buttons.button_11 = False
        ret.joystick_3_buttons.button_12 = False
        ret.joystick_3_buttons.button_13 = False
        ret.joystick_3_buttons.button_14 = False
        ret.joystick_3_buttons.button_15 = False
        ret.joystick_3_buttons.button_16 = False

        ret.joystick_4_axis_1 = 0
        ret.joystick_4_axis_2 = 0
        ret.joystick_4_axis_3 = 0
        ret.joystick_4_axis_4 = 0
        ret.joystick_4_axis_5 = 0
        ret.joystick_4_axis_6 = 0
        ret.joystick_4_buttons.button_1 = False
        ret.joystick_4_buttons.button_2 = False
        ret.joystick_4_buttons.button_3 = False
        ret.joystick_4_buttons.button_4 = False
        ret.joystick_4_buttons.button_5 = False
        ret.joystick_4_buttons.button_6 = False
        ret.joystick_4_buttons.button_7 = False
        ret.joystick_4_buttons.button_8 = False
        ret.joystick_4_buttons.button_9 = False
        ret.joystick_4_buttons.button_10 = False
        ret.joystick_4_buttons.button_11 = False
        ret.joystick_4_buttons.button_12 = False
        ret.joystick_4_buttons.button_13 = False
        ret.joystick_4_buttons.button_14 = False
        ret.joystick_4_buttons.button_15 = False
        ret.joystick_4_buttons.button_16 = False

        ret.analog_value_1 = 0
        ret.analog_value_2 = 0
        ret.analog_value_3 = 0
        ret.analog_value_4 = 0
        ret.crio_checksum = 0
        ret.fpga_checksum_1 = 0
        ret.fpga_checksum_2 = 0
        ret.fpga_checksum_3 = 0
        ret.fpga_checksum_4 = 0

        # This was reported by the FRC 2016 DS in 2014 mode
        ret.driver_station_version = 3546356223709687856

        payload = ""
        for i in xrange(0, 940):
            payload += "\x00"
        ret.unknown = payload
        return ret
Beispiel #23
0
class BasicMessageArrayAfter(Structure):
    count = LengthField(UBInt8(), multiplier=2)
    array = FieldArray(BasicMessage, count)
    after = UBInt8()
Beispiel #24
0
class BasicMessageArrayNumElements(Structure):
    count = LengthField(UBInt8())
    array = FieldArray(BasicMessage, num_elements_provider=count)
Beispiel #25
0
class ConditionalSubstructures(Structure):
    f1 = UBInt8()
    f2 = ConditionalField(SubstructureField(BasicMessage),
                          condition=lambda m: m.f1 < 10)
    f3 = ConditionalField(SubstructureField(BasicMessage),
                          condition=lambda m: m.f1 < 20)
Beispiel #26
0
class ConditionalLength(Structure):
    f1 = UBInt8()
    f2 = ConditionalField(LengthField(UBInt8()), lambda m: m.f1 == 255)
    f3 = ConditionalField(Payload(length_provider=f2), lambda m: m.f1 == 255)
class Conditional(Structure):
    f1 = UBInt8()
    f2 = ConditionalField(UBInt8(), lambda m: m.f1 == 255)
Beispiel #28
0
class ConditionalArrayGreedyAfter(Structure):
    length = LengthField(UBInt8())
    array = FieldArray(ConditionalArrayElement, length)
    greedy = Payload()
Beispiel #29
0
class EchoProtocolFrame(Structure):
    frame_type = UBInt8()
    payload_length = LengthField(UBInt16())
    payload = Payload(payload_length)
Beispiel #30
0
class Structure8(Structure):
    value = UBInt8()