Example #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)
Example #2
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)
Example #3
0
class BoxedGreedy(Structure):
    sof = Magic(b'\xAA')
    a = LengthField(UBInt8())
    b = UBInt8()
    payload = Payload()
    c = UBInt16()
    d = VariableRawPayload(a)
    eof = Magic(b'\xbb')
Example #4
0
class MyBasicDispatchMessage(Structure):
    type = DispatchField(UBInt8())
    length = LengthField(UBInt16())
    body = DispatchTarget(
        length, type, {
            0x00: MyTargetMessage,
            0x01: MyOtherTargetMessage,
            None: MyDefaultTargetMessage
        })
Example #5
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)
Example #6
0
class DNSMessage(Structure):
    identification = UBInt16()
    fields = BitField(
        16,
        is_reply=BitBool(),  # QR
        opcode=BitNum(4),
        truncated=BitBool(),
        recursion_desired=BitBool(),
        ra=BitBool(),
        z=BitBool(),
        non_authenticated_data_acceptable=BitBool(),
        cd=BitBool(),
        rcode=BitNum(4),
    )
    total_questions = UBInt16()
    total_answers_rrs = UBInt16()
    total_authority_rrs = UBInt16()
    total_additional_rrs = UBInt16()
    data = Payload()  # greedy
class EthernetFrame(Structure):
    preamble_sof = Magic('\xAA' * 8)  # 8 bytes of 10101010
    mac_dest = UBInt8Sequence(6)
    mac_source = UBInt8Sequence(6)
    ethertype = DispatchField(UBInt16())
    payload = DispatchTarget(None, ethertype, {
        0x0800: IPV4Frame,
        #         0x85DD: IPV6Message,
        #         0x0806: ARPMessage,
    })

    checksum = UBInt32()
class TCPFrameHeader(Structure):
    source_address = UBInt16()
    destination_address = UBInt16()
    sequence_number = UBInt32()
    acknowledgement_number = UBInt32()
    options = BitField(16,
                       data_offset=BitNum(4),
                       reserved=BitNum(3),
                       NS=BitBool(),
                       CWR=BitBool(),
                       ECE=BitBool(),
                       URG=BitBool(),
                       ACK=BitBool(),
                       PSH=BitBool(),
                       RST=BitBool(),
                       SYN=BitBool(),
                       FIN=BitBool()
                       )
    window_size = UBInt16()
    checksum = UBInt16()
    urgent_pointer = UBInt16()
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()
Example #10
0
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'~')
Example #11
0
 class MyLengthyMessage(Structure):
     length = LengthField(UBInt16())
     payload = VariableRawPayload(length)
Example #12
0
class Structure16(Structure):
    value = UBInt16()
Example #13
0
class PascalString16(Structure):
    length = LengthField(UBInt16())
    value = Payload(length)
Example #14
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
class UDPFrame(Structure):
    source_port = UBInt16()
    destination_port = UBInt16()
    length = LengthField(UBInt16())
    checksum = UBInt16()
    data = VariableRawPayload(length)
Example #16
0
class One(Structure):
    first = UBInt8()
    second = UBInt16()
Example #17
0
class EchoProtocolFrame(Structure):
    frame_type = UBInt8()
    payload_length = LengthField(UBInt16())
    payload = Payload(payload_length)
Example #18
0
class Message(Structure):
    tag = DispatchField(UBInt16())
    length = LengthField(UBInt16())
    message = DispatchTarget(length, tag, MESSAGE_DISPATCH_MAPPING)