Aircraft callsign

    Args:
        msg (string): 28 bytes hexadecimal message string

    Returns:
        string: callsign
483100
def callsign(msg):
    

    if common.typecode(msg) < 1 or common.typecode(msg) > 4:
        raise RuntimeError("%s: Not a identification message" % msg)

    chars = '#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'
    msgbin = common.hex2bin(msg)
    csbin = msgbin[40:96]

    cs = ''
    cs += chars[common.bin2int(csbin[0:6])]
    cs += chars[common.bin2int(csbin[6:12])]
    cs += chars[common.bin2int(csbin[12:18])]
    cs += chars[common.bin2int(csbin[18:24])]
    cs += chars[common.bin2int(csbin[24:30])]
    cs += chars[common.bin2int(csbin[30:36])]
    cs += chars[common.bin2int(csbin[36:42])]
    cs += chars[common.bin2int(csbin[42:48])]

    # clean string, remove spaces and marks, if any.
    # cs = cs.replace('_', '')
    cs = cs.replace('#', '')
    return cs
1141174
def sign(self, message):
		
		return hmac.HMAC(self.key, message, digestmod=hashlib.md5).digest()
811159
def ParseMessage(descriptor, byte_str):
  
  result_class = MakeClass(descriptor)
  new_msg = result_class()
  new_msg.ParseFromString(byte_str)
  return new_msg
347134
def mach53(msg):
    
    d = hex2bin(data(msg))

    if d[23] == '0':
        return None

    mach = bin2int(d[24:33]) * 0.008
    return round(mach, 3)
99048
def raise_msg_to_str(msg):
    """"""
    if not is_string_like(msg):
        msg = '\n'.join(map(str, msg))
    return msg
173704
def process_raw(self, adsb_ts, adsb_msgs, commb_ts, commb_msgs, tnow=None):
        
        if tnow is None:
            tnow = time.time()

        self.t = tnow

        local_updated_acs_buffer = []
        output_buffer = []

        # process adsb message
        for t, msg in zip(adsb_ts, adsb_msgs):
            icao = pms.icao(msg)
            tc = pms.adsb.typecode(msg)

            if icao not in self.acs:
                self.acs[icao] = {
                    'live': None,
                    'call': None,
                    'lat': None,
                    'lon': None,
                    'alt': None,
                    'gs': None,
                    'trk': None,
                    'roc': None,
                    'tas': None,
                    'roll': None,
                    'rtrk': None,
                    'ias': None,
                    'mach': None,
                    'hdg': None,
                    'ver' : None,
                    'HPL' : None,
                    'RCu' : None,
                    'RCv' : None,
                    'HVE' : None,
                    'VVE' : None,
                    'Rc' : None,
                    'VPL' : None,
                    'EPU' : None,
                    'VEPU' : None,
                    'HFOMr' : None,
                    'VFOMr' : None,
                    'PE_RCu' : None,
                    'PE_VPL' : None,
                }

            self.acs[icao]['t'] = t
            self.acs[icao]['live'] = int(t)

            if 1 <= tc <= 4:
                cs = pms.adsb.callsign(msg)
                self.acs[icao]['call'] = cs
                output_buffer.append([t, icao, 'cs', cs])

            if (5 <= tc <= 8) or (tc == 19):
                vdata = pms.adsb.velocity(msg)
                if vdata is None:
                    continue

                spd, trk, roc, tag = vdata
                if tag != 'GS':
                    continue
                if (spd is None) or (trk is None):
                    continue

                self.acs[icao]['gs'] = spd
                self.acs[icao]['trk'] = trk
                self.acs[icao]['roc'] = roc
                self.acs[icao]['tv'] = t

                output_buffer.append([t, icao, 'gs', spd])
                output_buffer.append([t, icao, 'trk', trk])
                output_buffer.append([t, icao, 'roc', roc])


            if (5 <= tc <= 18):
                oe = pms.adsb.oe_flag(msg)
                self.acs[icao][oe] = msg
                self.acs[icao]['t'+str(oe)] = t

                if ('tpos' in self.acs[icao]) and (t - self.acs[icao]['tpos'] < 180):
                    # use single message decoding
                    rlat = self.acs[icao]['lat']
                    rlon = self.acs[icao]['lon']
                    latlon = pms.adsb.position_with_ref(msg, rlat, rlon)
                elif ('t0' in self.acs[icao]) and ('t1' in self.acs[icao]) and \
                     (abs(self.acs[icao]['t0'] - self.acs[icao]['t1']) < 10):
                    # use multi message decoding
                    try:
                        latlon = pms.adsb.position(
                            self.acs[icao][0],
                            self.acs[icao][1],
                            self.acs[icao]['t0'],
                            self.acs[icao]['t1'],
                            self.lat0, self.lon0
                            )
                    except:
                        # mix of surface and airborne position message
                        continue
                else:
                    latlon = None

                if latlon is not None:
                    self.acs[icao]['tpos'] = t
                    self.acs[icao]['lat'] = latlon[0]
                    self.acs[icao]['lon'] = latlon[1]

                    alt = pms.adsb.altitude(msg)
                    self.acs[icao]['alt'] = alt

                    output_buffer.append([t, icao, 'lat', latlon[0]])
                    output_buffer.append([t, icao, 'lon', latlon[1]])
                    output_buffer.append([t, icao, 'alt', alt])

                    local_updated_acs_buffer.append(icao)

            # Uncertainty & accuracy
            ac = self.acs[icao]

            if 9 <= tc <= 18:
                ac['nic_bc'] = pms.adsb.nic_b(msg)

            if (5 <= tc <= 8) or (9 <= tc <= 18) or (20 <= tc <= 22):
                ac['HPL'], ac['RCu'], ac['RCv'] = pms.adsb.nuc_p(msg)

                if (ac['ver'] == 1) and ('nic_s' in ac.keys()):
                    ac['Rc'], ac['VPL'] = pms.adsb.nic_v1(msg, ac['nic_s'])
                elif (ac['ver'] == 2) and ('nic_a' in ac.keys()) and ('nic_bc' in ac.keys()):
                    ac['Rc'] = pms.adsb.nic_v2(msg, ac['nic_a'], ac['nic_bc'])

            if tc == 19:
                ac['HVE'], ac['VVE'] = pms.adsb.nuc_v(msg)
                if ac['ver'] in [1, 2]:
                    ac['HFOMr'], ac['VFOMr'] = pms.adsb.nac_v(msg)

            if tc == 29:
                ac['PE_RCu'], ac['PE_VPL'], ac['base'] = pms.adsb.sil(msg, ac['ver'])
                ac['EPU'], ac['VEPU'] = pms.adsb.nac_p(msg)

            if tc == 31:
                ac['ver']  = pms.adsb.version(msg)
                ac['EPU'], ac['VEPU'] = pms.adsb.nac_p(msg)
                ac['PE_RCu'], ac['PE_VPL'], ac['sil_base'] = pms.adsb.sil(msg, ac['ver'])

                if ac['ver']  == 1:
                    ac['nic_s'] = pms.adsb.nic_s(msg)
                elif ac['ver']  == 2:
                    ac['nic_a'], ac['nic_bc'] = pms.adsb.nic_a_c(msg)


        # process commb message
        for t, msg in zip(commb_ts, commb_msgs):
            icao = pms.icao(msg)

            if icao not in self.acs:
                continue

            bds = pms.bds.infer(msg)

            if bds == 'BDS50':
                roll50 = pms.commb.roll50(msg)
                trk50 = pms.commb.trk50(msg)
                rtrk50 = pms.commb.rtrk50(msg)
                gs50 = pms.commb.gs50(msg)
                tas50 = pms.commb.tas50(msg)

                self.acs[icao]['t50'] = t
                if tas50:
                    self.acs[icao]['tas'] = tas50
                    output_buffer.append([t, icao, 'tas50', tas50])
                if roll50:
                    self.acs[icao]['roll'] = roll50
                    output_buffer.append([t, icao, 'roll50', roll50])
                if rtrk50:
                    self.acs[icao]['rtrk'] = rtrk50
                    output_buffer.append([t, icao, 'rtrk50', rtrk50])

                if trk50:
                    output_buffer.append([t, icao, 'trk50', trk50])
                if gs50:
                    output_buffer.append([t, icao, 'gs50', gs50])

            elif bds == 'BDS60':
                ias60 = pms.commb.ias60(msg)
                hdg60 = pms.commb.hdg60(msg)
                mach60 = pms.commb.mach60(msg)
                roc60baro = pms.commb.vr60baro(msg)
                roc60ins = pms.commb.vr60ins(msg)

                if ias60 or hdg60 or mach60:
                    self.acs[icao]['t60'] = t
                if ias60:
                    self.acs[icao]['ias'] = ias60
                if hdg60:
                    self.acs[icao]['hdg'] = hdg60
                if mach60:
                    self.acs[icao]['mach'] = mach60

                if roc60baro:
                    output_buffer.append([t, icao, 'roc60baro', roc60baro])
                if roc60ins:
                    output_buffer.append([t, icao, 'roc60ins', roc60ins])

        # clear up old data
        for icao in list(self.acs.keys()):
            if self.t - self.acs[icao]['live'] > self.cache_timeout:
                del self.acs[icao]
                continue

        if self.dumpto is not None:
            dh = str(datetime.datetime.now().strftime("%Y%m%d_%H"))
            fn = self.dumpto + '/pymodes_dump_%s.csv' % dh
            output_buffer.sort(key=lambda x: x[0])
            with open(fn, "a") as f:
                writer = csv.writer(f)
                writer.writerows(output_buffer)

        return
487271
def ic45(msg):
    
    d = hex2bin(data(msg))
    if d[9] == '0':
        return None

    ic = bin2int(d[10:12])
    return ic
407602
def _add_msg(self, m):
        ''''''
        type = m.get_type()
        self.messages[type] = m

        if self.clock:
            self.clock.message_arrived(m)

        if type == 'MSG':
            if m.Message.find("Rover") != -1:
                self.mav_type = mavutil.mavlink.MAV_TYPE_GROUND_ROVER
            elif m.Message.find("Plane") != -1:
                self.mav_type = mavutil.mavlink.MAV_TYPE_FIXED_WING
            elif m.Message.find("Copter") != -1:
                self.mav_type = mavutil.mavlink.MAV_TYPE_QUADROTOR
            elif m.Message.startswith("Antenna"):
                self.mav_type = mavutil.mavlink.MAV_TYPE_ANTENNA_TRACKER
        if type == 'MODE':
            if isinstance(m.Mode, str):
                self.flightmode = m.Mode.upper()
            elif 'ModeNum' in m._fieldnames:
                mapping = mavutil.mode_mapping_bynumber(self.mav_type)
                if mapping is not None and m.ModeNum in mapping:
                    self.flightmode = mapping[m.ModeNum]
            else:
                self.flightmode = mavutil.mode_string_acm(m.Mode)
        if type == 'STAT' and 'MainState' in m._fieldnames:
            self.flightmode = mavutil.mode_string_px4(m.MainState)
        if type == 'PARM' and getattr(m, 'Name', None) is not None:
            self.params[m.Name] = m.Value
        self._set_time(m)
382557
async def sign_data(self, msg: bytes) -> bytes:
        

        def transform_cb(arr_ptr: POINTER(c_uint8), arr_len: c_uint32):
            return bytes(arr_ptr[:arr_len]),

        if not hasattr(Connection.sign_data, "cb"):
            self.logger.debug("vcx_connection_sign_data: Creating callback")
            Connection.sign_data.cb = create_cb(CFUNCTYPE(None, c_uint32, c_uint32, POINTER(c_uint8), c_uint32), transform_cb)

        c_connection_handle = c_uint32(self.handle)
        c_msg_len = c_uint32(len(msg))

        result = await do_call('vcx_connection_sign_data',
                               c_connection_handle,
                               msg,
                               c_msg_len,
                               Connection.sign_data.cb)

        self.logger.debug("vcx_connection_sign_data completed")
        return result
1285952
def turb45(msg):
    
    d = hex2bin(data(msg))
    if d[0] == '0':
        return None

    turb = bin2int(d[1:3])
    return turb
1274942
def ias60(msg):
    
    d = hex2bin(data(msg))

    if d[12] == '0':
        return None

    ias = bin2int(d[13:23])    # kts
    return ias
96394
def alt40fms(msg):
    
    d = hex2bin(data(msg))

    if d[13] == '0':
        return None

    alt = bin2int(d[14:26]) * 16    # ft
    return alt
755203
def cmd_msg(self, args):
        ''''''
        if len(args) == 0:
            print(self.usage())
        txt = ' '.join(args)
        self.master.mav.statustext_send(mavutil.mavlink.MAV_SEVERITY_NOTICE,
                                        txt)
1081452
def hash_for_signing(self, msg):
        
        magic = self.msg_magic_for_netcode()

        fd = io.BytesIO()
        stream_satoshi_string(fd, magic.encode('utf8'))
        stream_satoshi_string(fd, msg.encode('utf8'))

        # return as a number, since it's an input to signing algos like that anyway
        return from_bytes_32(double_sha256(fd.getvalue()))
824539
def msg_name(code):
    """"""
    ids = {v: k for k, v in COMMANDS.items()}
    return ids[code]
840376
def message(self):
        ''' '''
        name = self.__class__.__name__
        return "{0} {1}".format(humanize(name),
                                pp(*self.expectedArgs, **self.expectedKwArgs))
1089790
async def message(self, msg, msg_type=None, use_version=None):
        
        elem_type = msg_type if msg_type is not None else msg.__class__
        msg = elem_type() if msg is None else msg
        if hasattr(elem_type, "serialize_archive"):
            version = await self.version(elem_type, None, elem=msg) if use_version is None else use_version
            return await msg.serialize_archive(self, version=version)

        mtype = msg.__class__ if msg_type is None else msg_type
        fields = mtype.f_specs()
        if hasattr(mtype, "serialize_archive"):
            raise ValueError("Cannot directly load, has to use archive with %s" % mtype)

        await self.message_fields(msg, fields)
        return msg