Exemplo n.º 1
0
from Updater import settings
from Updater import rsa_signing


class MessageType(enum.IntEnum):
    VERSION_UPDATE = 1   # Announces a new version - Can be sent by official update server only!
    SERVER_UPDATE = 2    # Announces a new server information - Can be sent by official update server only!
    REQUEST_VERSION = 3  # Request specific version from a client / server
    REQUEST_UPDATE = 4   # Request the most updated version from a client / server


GENERIC_MESSAGE =           construct.FixedSized(settings.MESSAGE_SIZE,
                                construct.Struct(
                                    "type"      / construct.Enum(construct.Byte, MessageType),
                                    "signature" / construct.BytesInteger(settings.SIGNATURE_SIZE),
                                    "data"      / construct.Bytes(settings.MESSAGE_SIZE - settings.SIGNATURE_SIZE - construct.Byte.sizeof())
                                ))

VERSION_UPDATE_MESSAGE =    construct.FixedSized(settings.MESSAGE_SIZE,
                                construct.Struct(
                                    "type"              / construct.Const(MessageType.VERSION_UPDATE.value, construct.Byte),
                                    "header_signature"  / construct.BytesInteger(settings.SIGNATURE_SIZE),
                                    "major"             / construct.Int16ub,
                                    "minor"             / construct.Int16ub,
                                    "size"              / construct.Int32ub,
                                    "update_signature"  / construct.BytesInteger(settings.SIGNATURE_SIZE),
                                    "spread"            / construct.Flag
                                ))

SERVER_UPDATE_MESSAGE =     construct.FixedSized(settings.MESSAGE_SIZE,
Exemplo n.º 2
0
    def handle_msg(self, msg_pmt):
        msg = pmt.cdr(msg_pmt)
        if not pmt.is_u8vector(msg):
            print
            "[ERROR] Received invalid message type. Expected u8vector"
            return
        packet = pmt.u8vector_elements(msg)
        if self.input_manual_automatic == 1:
            self.now = datetime.utcnow()
            if self.length_of_submillisecond_cds >= 2:
                self.length_of_submillisecond_cds = 1
            if self.number_of_subsecond_ccs >= 4:
                self.length_of_susecond_ccs = 3
        else:
            self.now = datetime(self.year, self.month, self.day, self.hour,
                                self.minute, self.second, self.microsecond)

        finalHeader = []

        if self.time_format == 0:  #CUC
            basic_time = 1 + self.basic_time_num_octets_cuc
            fractional_time = self.fractional_time_num_octets_cuc

            if self.pfield == 1:  #If it exists

                finalHeader.extend(
                    array.array(
                        'B',
                        space_packet.PFieldCUC.build(
                            dict(pfield_extension=self.pfield_extension,
                                 time_code_identification=self.
                                 time_code_identification_cuc,
                                 number_of_basic_time_unit_octets=self.
                                 basic_time_num_octets_cuc,
                                 number_of_fractional_time_unit_octets=self.
                                 fractional_time_num_octets_cuc))).tolist())

                if self.pfield_extension == 1:  #If it is extended
                    basic_time += self.additional_octets_basic_time_cuc
                    fractional_time += self.additional_octets_fractional_time_cuc
                    finalHeader.extend(
                        array.array(
                            'B',
                            space_packet.PFieldCUCExtension.build(
                                dict(
                                    pfieldextension=self.
                                    pfield_extension_extended,
                                    number_of_additional_basic_time_unit_octets
                                    =self.additional_octets_basic_time_cuc,
                                    number_of_additional_fractional_time_unit_octets
                                    =self.
                                    additional_octets_fractional_time_cuc,
                                    reserved_for_mission_definition=self.
                                    rsvd_cuc))).tolist())
            temp_diff = self.now - self.epoch_cuc
            total_basic = int(temp_diff.total_seconds())
            total_frac = int((temp_diff.total_seconds() - total_basic) *
                             (256**fractional_time))
            finalHeader.extend(
                array.array(
                    'B',
                    construct.BytesInteger(basic_time).build(
                        total_basic)).tolist())
            finalHeader.extend(
                array.array(
                    'B',
                    construct.BytesInteger(fractional_time).build(
                        total_frac)).tolist())

        elif self.time_format == 1:  #CDS
            if self.pfield == 1:
                finalHeader.extend(
                    array.array(
                        'B',
                        space_packet.PFieldCDS.build(
                            dict(pfield_extension=self.pfield_extension,
                                 time_code_identification=self.
                                 time_code_identification_cds,
                                 epoch_identification=self.
                                 epoch_identification_cds,
                                 length_of_day_segment=self.length_of_day_cds,
                                 length_of_submillisecond_segment=self.
                                 length_of_submillisecond_cds))).tolist())
            days_len = 2 if self.length_of_day_cds == 0 else 3
            finalHeader.extend(
                array.array(
                    'B',
                    construct.BytesInteger(days_len).build(
                        (self.now - self.epoch_cds).days)).tolist())
            finalHeader.extend(
                array.array(
                    'B', construct.Int32ub.build(self.now.microsecond /
                                                 1000)).tolist())
            if self.length_of_submillisecond_cds == 1:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int16ub.build(self.now.microsecond %
                                                1000)).tolist())
            elif self.length_of_submillisecond_cds == 2:
                finalHeader.extend(
                    array.array('B', construct.Int32ub.build(
                        self.picosecond)).tolist())

        elif self.time_format == 2:  #CCS
            if self.pfield == 1:
                finalHeader.extend(
                    array.array(
                        'B',
                        space_packet.PFieldCCS.build(
                            dict(pfield_extension=self.pfield_extension,
                                 time_code_identification=self.
                                 time_code_identification_ccs,
                                 calendar_variation_flag=self.
                                 calendar_variation_ccs,
                                 resolution=self.number_of_subsecond_ccs))).
                    tolist())
            finalHeader.extend(
                array.array('B',
                            construct.Int16ub.build(self.now.year)).tolist())
            if self.calendar_variation_ccs == 0:
                finalHeader.extend(
                    array.array('B', construct.Int8ub.build(
                        self.now.month)).tolist())
                finalHeader.extend(
                    array.array('B',
                                construct.Int8ub.build(self.now.day)).tolist())
            else:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int16ub.build(
                            self.now.timetuple().tm_yday)).tolist())

            finalHeader.extend(
                array.array('B',
                            construct.Int8ub.build(self.now.hour)).tolist())
            finalHeader.extend(
                array.array('B',
                            construct.Int8ub.build(self.now.minute)).tolist())
            finalHeader.extend(
                array.array('B',
                            construct.Int8ub.build(self.now.second)).tolist())

            if self.number_of_subsecond_ccs >= 1:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int8ub.build(self.now.microsecond /
                                               10**4)).tolist())
            if self.number_of_subsecond_ccs >= 2:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int8ub.build(
                            (self.now.microsecond / 10**2) % 10**2)).tolist())
            if self.number_of_subsecond_ccs >= 3:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int8ub.build(self.now.microsecond %
                                               10**2)).tolist())
            if self.number_of_subsecond_ccs >= 4:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int8ub.build(
                            (self.picosecond % 10**6) / 10**4)).tolist())
            if self.number_of_subsecond_ccs >= 5:
                finalHeader.extend(
                    array.array(
                        'B',
                        construct.Int8ub.build(
                            (self.picosecond % 10**4) / 10**2)).tolist())
            if self.number_of_subsecond_ccs >= 6:
                finalHeader.extend(
                    array.array(
                        'B', construct.Int8ub.build(self.picosecond %
                                                    10**2)).tolist())

        elif self.time_format == 3 or self.time_format == 4:
            if (self.ascii_dec_num < 0 or self.ascii_dec_num > 6):
                print "Decimals of ASCII in Time Stamp Adder block should be between 0 and 6. The number was automatically set to 1."
                self.ascii_dec_num = 1

            if self.time_format == 3:  # ASCII A
                arr = self.now.isoformat()
            else:  #ASCII B
                arr = self.now.strftime("%Y-%jT%H:%M:%S.%f")

            arr = arr[:-(6 - self.ascii_dec_num)]

            if (self.add_z_terminator == 1):
                arr += 'Z'

            finalHeader = array.array('B', arr).tolist()

        else:
            print "Time Format Unknown"

        finalPacket = numpy.append(finalHeader, packet)
        finalPacket = array.array('B', finalPacket[:])
        finalPacket = pmt.cons(
            pmt.PMT_NIL, pmt.init_u8vector(len(finalPacket), finalPacket))
        self.message_port_pub(pmt.intern('out'), finalPacket)
Exemplo n.º 3
0
 def __init__(self):
     construct.Adapter.__init__(self, construct.BytesInteger(8,
                                                             swapped=True))
Exemplo n.º 4
0
PUBLICKEYSTRUC = construct.Struct(
    "type" / construct.Byte,
    "version" / construct.Byte,
    "reserved" / construct.Int16ul,
    "algid" / windows_enums.AlgorithmID(construct.Int32ul),
)

PUBLICKEYBLOB = construct.Struct(
    "publickeystruc" / PUBLICKEYSTRUC,
    construct.Check(this.publickeystruc.algid == "CALG_RSA_KEYX"),
    construct.Const("RSA1"),
    "bitlen" / construct.Int32ul,
    construct.Check((this.bitlen % 8) == 0),
    "pubexponent" / construct.Int32ul,
    "modulus" / construct.BytesInteger(this.bitlen / 8, swapped=True)
)

PRIVATEKEYBLOB = construct.Struct(
    "publickeystruc" / PUBLICKEYSTRUC,
    construct.Check(this.publickeystruc.algid == "CALG_RSA_KEYX"),
    construct.Const("RSA2"),
    "bitlen" / construct.Int32ul,
    construct.Check((this.bitlen % 8) == 0),
    "pubexponent" / construct.Int32ul,
    "modulus" / construct.BytesInteger(this.bitlen / 8, swapped=True),
    "P" / construct.BytesInteger(this.bitlen / 16, swapped=True),
    "Q" / construct.BytesInteger(this.bitlen / 16, swapped=True),
    # d % (p - 1)
    "Dp" / construct.BytesInteger(this.bitlen / 16, swapped=True),
    # d % (q - 1)
Exemplo n.º 5
0
 def __init__(self, size: int = 8):
     construct.Adapter.__init__(self,
                                construct.BytesInteger(size, swapped=True))
Exemplo n.º 6
0
    "srm_vault" / PublicKeyAdapter(), "admin" / PublicKeyAdapter(),
    "borrow_limits" / construct.Array(NUM_TOKENS, DecimalAdapter()),
    "mint_decimals" / construct.Array(NUM_TOKENS, DecimalAdapter(1)),
    "oracle_decimals" / construct.Array(NUM_MARKETS, DecimalAdapter(1)),
    "padding" / construct.Array(GROUP_PADDING, construct.Padding(1)))

MARGIN_ACCOUNT = construct.Struct(
    "account_flags" / MANGO_ACCOUNT_FLAGS, "mango_group" / PublicKeyAdapter(),
    "owner" / PublicKeyAdapter(),
    "deposits" / construct.Array(NUM_TOKENS, FloatAdapter()),
    "borrows" / construct.Array(NUM_TOKENS, FloatAdapter()),
    "open_orders" / construct.Array(NUM_MARKETS, PublicKeyAdapter()),
    "padding" / construct.Padding(8))

MANGO_INSTRUCTION_VARIANT_FINDER = construct.Struct(
    "variant" / construct.BytesInteger(4, swapped=True))

INIT_MANGO_GROUP = construct.Struct(
    "variant" / construct.Const(0x0, construct.BytesInteger(4, swapped=True)),
    "signer_nonce" / DecimalAdapter(),
    "maint_coll_ratio" / FloatAdapter(),
    "init_coll_ratio" / FloatAdapter(),
    #  "borrow_limits" / construct.Array(NUM_TOKENS, DecimalAdapter())  # This is inconsistently available
)

INIT_MARGIN_ACCOUNT = construct.Struct(
    "variant" /
    construct.Const(0x1, construct.BytesInteger(4, swapped=True)), )

DEPOSIT = construct.Struct(
    "variant" / construct.Const(0x2, construct.BytesInteger(4, swapped=True)),
Exemplo n.º 7
0
    def run(self):
        r = self.socket.recv(64)
        if r[0:8] != b"ENO/GET/":
            print("[*] Invalid Packet")
            p_dny = b"ENO/DNY/\x00\x10/" + b'\x00' * 32 + b'/' + b'\x00' * 17
            self.socket.send(p_dny)
            return

        if b"dbg=1" in r:
            info = b"""
=========================================================================
    MAGIC DRAGON MASTER AUTHORITY

    Cert Level 1: Strong Prime Number for Certificate self-signing
                  Authentication: None

    Cert Level 2: Privileged Certificate for Border Authorities
                  Authentication: Challenge Response Protocol
                  System Details: 64 Round 48-Bit 4-XOR Arbiter PUF
=========================================================================
"""
            self.socket.send(info)

        elif b"cert_level=1" in r:
            p = number.getPrime(64)
            print(p)
            self.socket.send(struct.pack(">Q", p))
            print("[*] CERT LVL 1 OK")
        elif b"cert_level=2" in r:
            try:
                with open('weights.txt', 'rb') as f:
                    weights = np.load(f)
            except:
                weights = LTFArray.normal_weights(n=48, k=4)
                with open('weights.txt', 'wb') as f:
                    np.save(f, weights, allow_pickle=False)
            # print(weights)

            instance = LTFArray(
                weight_array=weights,
                transform=LTFArray.transform_atf,
                combiner=LTFArray.combiner_xor,
            )

            challenges = []
            c_string = b""
            for n in range(0, 64):
                c = np.zeros(48, dtype=np.int8)
                for i in range(0, 48):
                    c[i] = random.choice([-1, 1])
                challenges.append(c)

                # prepare message
                c = np.copy(c)
                c[c == 1] = 0
                c[c == -1] = 1

                cm = b""
                for b in c:
                    cm += str(b).encode()
                c_string += cm + b'\n'

            print("[*] Challenges prepared")
            challenges = np.array(challenges)
            correct_response = instance.eval(challenges)

            self.socket.send(c_string)
            print("[*] Expect Response")
            r = self.socket.recv(64)
            if len(r) != 64:
                print("[*] Invalid Response")
            else:
                given_response = np.zeros(64, dtype=np.int8)
                for i in range(0, 64):
                    given_response[i] = np.int8(r[i])
                correct_response[correct_response == 1] = 0
                correct_response[correct_response == -1] = 1
                print(correct_response)

                if (given_response == correct_response).all():
                    print("[*] ACCEPT")
                    x = 12074235067132104677358030448740169086211171545373284647579234906840326968311237601092259613113724502049948022317426840853777753513486274652991559584610574
                    self.socket.send(construct.BytesInteger(64).build(x))
                else:
                    print("[*] REJECT")
                    cm = b""
                    for b in correct_response:
                        cm += str(b).encode()
                    self.socket.send(cm)
        self.socket.close()
Exemplo n.º 8
0
class Message:
    MSP_MSG_IDENT = 100
    MSP_MSG_STATUS = 101
    MSP_MSG_RAW_IMU = 102
    MSP_MSG_SERVO = 103
    MSP_MSG_MOTOR = 104
    MSP_MSG_RC = 105
    MSP_MSG_RAW_GPS = 106
    MSP_MSG_COMP_GPS = 107
    MSP_MSG_ATTITUDE = 108
    MSP_MSG_ALTITUDE = 109
    MSP_MSG_ANALOG = 110
    MSP_MSG_RC_TUNING = 111
    MSP_MSG_PID = 112
    MSP_MSG_BOX = 113
    MSP_MSG_MISC = 114
    MSP_MSG_MOTOR_PINS = 115
    MSP_MSG_BOXNAMES = 116
    MSP_MSG_PIDNAMES = 117
    MSP_MSG_WP = 118
    MSP_MSG_BOXIDS = 119
    MSP_MSG_SERVO_CONF = 120
    MSP_MSG_SET_RAW_RC = 200
    MSP_MSG_SET_RAW_GPS = 201
    MSP_MSG_SET_PID = 202
    MSP_MSG_SET_BOX = 203
    MSP_MSG_SET_RC_TUNING = 204
    MSP_MSG_ACC_CALIBRATION = 205
    MSP_MSG_MAG_CALIBRATION = 206
    MSP_MSG_SET_MISC = 207
    MSP_MSG_RESET_CONF = 208
    MSP_MSG_SET_WP = 209
    MSP_MSG_SELECT_SETTING = 210
    MSP_MSG_SET_HEAD = 211
    MSP_MSG_SET_SERVO_CONF = 212
    MSP_MSG_SET_MOTOR = 214
    MSP_MSG_BIND = 240
    MSP_MSG_EEPROM_WRITE = 250

    struct = construct.Struct(
        "0" / construct.Const(b"$"), "1" / construct.Const(b"X"),
        "direction" / construct.Const(b"<"), "flag" / construct.Const(b"\0"),
        "function" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payloadSize" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payload" / construct.Array(this.payloadSize, Int8ub),
        "checksum" / Int8ub)
    structRecv = construct.Struct(
        "0" / construct.Const(b"$"), "1" / construct.Const(b"X"),
        "direction" / construct.Const(b">"), "flag" / construct.Const(b"\0"),
        "function" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payloadSize" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payload" / construct.Array(this.payloadSize, Int8ub),
        "checksum" / Int8ub)

    checksumFormat = construct.Struct(
        "function" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payloadSize" / construct.ByteSwapped(construct.BytesInteger(2)),
        "payload" / construct.Array(this.payloadSize, Int8ub),
    )

    msp_servo = construct.Struct(
        "servo" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(2))))

    msp_motor = construct.Struct(
        "motor" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(2))))

    msp_set_motor = construct.Struct(
        "motor" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(2))))

    msp_rc = construct.Struct(
        "rc_data" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(2))))

    msp_set_raw_rc = construct.Struct(
        "rc_data" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(2))))

    msp_raw_gps = construct.Struct(
        "fix" / construct.ByteSwapped(construct.BytesInteger(1)),
        "num_sat" / construct.ByteSwapped(construct.BytesInteger(1)),
        "coord_lat" / construct.ByteSwapped(Int32sb),
        "coord_lon" / construct.ByteSwapped(Int32sb),
        "altitude" / construct.ByteSwapped(Int16sb),
        "speed" / construct.ByteSwapped(construct.BytesInteger(2)),
        "ground_course" / construct.ByteSwapped(construct.BytesInteger(2)),
    )

    msp_set_raw_gps = construct.Struct(
        "fix" / construct.ByteSwapped(construct.BytesInteger(1)),
        "num_sat" / construct.ByteSwapped(construct.BytesInteger(1)),
        "coord_lat" / construct.ByteSwapped(construct.BytesInteger(4)),
        "coord_lon" / construct.ByteSwapped(construct.BytesInteger(4)),
        "altitude" / construct.ByteSwapped(construct.BytesInteger(2)),
        "speed" / construct.ByteSwapped(construct.BytesInteger(2)))

    msp_comp_gps = construct.Struct(
        "distance_to_home" / construct.ByteSwapped(construct.BytesInteger(2)),
        "direction_to_home" / construct.ByteSwapped(construct.BytesInteger(2)),
        "update" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_attitude = construct.Struct(
        "angx" / construct.ByteSwapped(Int16sb),
        "angy" / construct.ByteSwapped(Int16sb),
        "heading" / construct.ByteSwapped(construct.BytesInteger(2)),
    )

    msp_altitude = construct.Struct(
        "alt" / construct.ByteSwapped(Int32sb),
        "vario" / construct.ByteSwapped(construct.BytesInteger(2)))

    msp_analog = construct.Struct(
        "vbat" / construct.ByteSwapped(construct.BytesInteger(1)),
        "power_meter_sum" / construct.ByteSwapped(construct.BytesInteger(2)),
        "rssi" / construct.ByteSwapped(construct.BytesInteger(2)),
        "amperage" / construct.ByteSwapped(construct.BytesInteger(2)))

    msp_rc_tuning = construct.Struct(
        "rc_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "rc_expo" / construct.ByteSwapped(construct.BytesInteger(1)),
        "roll_pitch_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "yaw_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "dyn_thr_pid" / construct.ByteSwapped(construct.BytesInteger(1)),
        "throttle_mid" / construct.ByteSwapped(construct.BytesInteger(1)),
        "throttle_expo" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_set_rc_tuning = construct.Struct(
        "rc_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "rc_expo" / construct.ByteSwapped(construct.BytesInteger(1)),
        "roll_pitch_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "yaw_rate" / construct.ByteSwapped(construct.BytesInteger(1)),
        "dyn_thr_pid" / construct.ByteSwapped(construct.BytesInteger(1)),
        "throttle_mid" / construct.ByteSwapped(construct.BytesInteger(1)),
        "throttle_expo" / construct.ByteSwapped(construct.BytesInteger(1)))

    _msp_pid_item = construct.Struct(
        "p" / construct.ByteSwapped(construct.BytesInteger(1)),
        "i" / construct.ByteSwapped(construct.BytesInteger(1)),
        "d" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_pid = construct.Struct(
        "roll" / _msp_pid_item,
        "pitch" / _msp_pid_item,
        "yaw" / _msp_pid_item,
        "alt" / _msp_pid_item,
        "pos" / _msp_pid_item,
        "posr" / _msp_pid_item,
        "navr" / _msp_pid_item,
        "level" / _msp_pid_item,
        "mag" / _msp_pid_item,
        "vel" / _msp_pid_item,
    )

    msp_set_pid = construct.Struct(
        "roll" / _msp_pid_item, "pitch" / _msp_pid_item, "yaw" / _msp_pid_item,
        "alt" / _msp_pid_item, "pos" / _msp_pid_item, "posr" / _msp_pid_item,
        "navr" / _msp_pid_item, "level" / _msp_pid_item, "mag" / _msp_pid_item,
        "vel" / _msp_pid_item)

    msp_box = construct.Struct(
        "boxitems[1]" / construct.ByteSwapped(construct.BytesInteger(2)))

    msp_set_box = construct.Struct(
        "boxitems[1]" / construct.ByteSwapped(construct.BytesInteger(2)))

    msp_misc = construct.Struct(
        "power_trigger" / construct.ByteSwapped(construct.BytesInteger(2)),
        "min_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "max_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "min_command" / construct.ByteSwapped(construct.BytesInteger(2)),
        "failsafe_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "arm_count" / construct.ByteSwapped(construct.BytesInteger(2)),
        "lifetime" / construct.ByteSwapped(construct.BytesInteger(4)),
        "mag_declination" / construct.ByteSwapped(construct.BytesInteger(2)),
        "vbat_scale" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_warn1" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_warn2" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_crit" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_set_misc = construct.Struct(
        "power_trigger" / construct.ByteSwapped(construct.BytesInteger(2)),
        "min_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "max_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "min_command" / construct.ByteSwapped(construct.BytesInteger(2)),
        "failsafe_throttle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "arm_count" / construct.ByteSwapped(construct.BytesInteger(2)),
        "lifetime" / construct.ByteSwapped(construct.BytesInteger(4)),
        "mag_declination" / construct.ByteSwapped(construct.BytesInteger(2)),
        "vbat_scale" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_warn1" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_warn2" / construct.ByteSwapped(construct.BytesInteger(1)),
        "vbat_crit" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_motor_pins = construct.Struct(
        "pwm_pin" /
        construct.Array(8, construct.ByteSwapped(construct.BytesInteger(1))))

    msp_wp = construct.Struct(
        "wp_no" / construct.ByteSwapped(construct.BytesInteger(1)),
        "action" / construct.ByteSwapped(construct.BytesInteger(1)),
        "lat" / construct.ByteSwapped(construct.BytesInteger(4)),
        "lon" / construct.ByteSwapped(construct.BytesInteger(4)),
        "alt_hold" / construct.ByteSwapped(construct.BytesInteger(4)),
        "p1" / construct.ByteSwapped(construct.BytesInteger(2)),
        "p2" / construct.ByteSwapped(construct.BytesInteger(2)),
        "p3" / construct.ByteSwapped(construct.BytesInteger(2)),
        "nav_flag" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_set_wp = construct.Struct(
        "wp_no" / construct.ByteSwapped(construct.BytesInteger(1)),
        "action" / construct.ByteSwapped(construct.BytesInteger(1)),
        "lat" / construct.ByteSwapped(Int32sb),
        "lon" / construct.ByteSwapped(Int32sb),
        "alt_hold" / construct.ByteSwapped(construct.BytesInteger(4)),
        "heading" / construct.ByteSwapped(construct.BytesInteger(2)),
        "p2" / construct.ByteSwapped(construct.BytesInteger(2)),
        "p3" / construct.ByteSwapped(construct.BytesInteger(2)),
        "nav_flag" / construct.ByteSwapped(construct.BytesInteger(1)),
    )

    msp_boxids = construct.Struct(
        "checkbox_items[0]" / construct.ByteSwapped(construct.BytesInteger(1)))

    _msp_servo_conf_item = construct.Struct(
        "min" / construct.ByteSwapped(construct.BytesInteger(2)),
        "max" / construct.ByteSwapped(construct.BytesInteger(2)),
        "middle" / construct.ByteSwapped(construct.BytesInteger(2)),
        "rate" / construct.ByteSwapped(construct.BytesInteger(1)),
    )

    msp_select_setting = construct.Struct(
        "current_set" / construct.ByteSwapped(construct.BytesInteger(1)))

    msp_set_head = construct.Struct(
        "mag_hold" / construct.ByteSwapped(construct.BytesInteger(2)))
Exemplo n.º 9
0
accelerometer_data = construct.Struct("accel_x" / construct.Int16sl,
                                      "accel_y" / construct.Int16sl,
                                      "accel_z" / construct.Int16sl)

gyroscope_data = construct.BitStruct("gyro_roll" / construct.BitsInteger(24),
                                     "gyro_yaw" / construct.BitsInteger(24),
                                     "gyro_pitch" / construct.BitsInteger(24))

magnet_data = construct.Struct(construct.Padding(6))

touchscreen_coords_data = construct.BitStruct(
    "touch_pad" / construct.Bit, "touch_extra" / construct.BitsInteger(3),
    "touch_value" / construct.BitsInteger(12))
touchscreen_points_data = construct.Struct(
    "coords" / construct.Array(2, touchscreen_coords_data))
touchscreen_data = construct.Struct(
    "points" / construct.Array(10, touchscreen_points_data))

input_data = construct.Struct(
    "sequence_id" / construct.Int16ub, "buttons" / construct.Int16ub,
    "power_status" / construct.Int8ub, "battery_charge" / construct.Int8ub,
    "left_stick_x" / construct.Int16ub, "left_stick_y" / construct.Int16ub,
    "right_stick_x" / construct.Int16ub, "right_stick_y" / construct.Int16ub,
    "audio_volume" / construct.Int8ub, construct.Embedded(accelerometer_data),
    construct.Embedded(gyroscope_data), construct.Embedded(magnet_data),
    construct.Embedded(touchscreen_data),
    "unkown_0" / construct.BytesInteger(4), "extra_buttons" / construct.Int8ub,
    "unknown_1" / construct.BytesInteger(46),
    "fw_version_neg" / construct.Int8ub)