Beispiel #1
0
def test_msg_20():
    print "Message type 20:"
    data = bytearray([
        0x14, 0x00, 0xab, 0x45, 0x49, 0x1f, 0xef, 0x15, 0xa8, 0x89, 0x78, 0x0f,
        0x09, 0xa9, 0x07, 0xb0, 0x01, 0x20, 0x01, 0x4e, 0x38, 0x32, 0x35, 0x56,
        0x20, 0x20, 0x20, 0x00
    ])
    msg = messages.messageToObject(data)
    print msg
    print
Beispiel #2
0
def test_msg_0():
    print "Message type 0:"
    data = bytearray([0x00, 0x81, 0x00, 0xf0, 0xba, 0x01, 00])
    msg = messages.messageToObject(data)
    print msg
    print
Beispiel #3
0
    def _decodeMessage(self, escapedMessage):
        """decode one GDL90 message without the start/end markers"""

        rawMsg = self._unescape(escapedMessage)
        if len(rawMsg) < 5:
            return False
        msg = rawMsg[:-2]
        crc = rawMsg[-2:]
        crcValid = crcCheck(msg, crc)
        """
        self.stats['msgCount'] += 1
        if (self.stats['msgCount'] % self.reportFrequency) == 0:
            print "Statistics: total msgs = %d, resyncs = %d" % (self.stats['msgCount'], self.stats['resync'])
            msgTypes = self.stats['msgs'].keys()
            msgTypes.sort()
            for mt in msgTypes:
                (g, b) = self.stats['msgs'][mt]
                print "  Messge #%d: %d good, %d bad" % (mt, g, b)
        """

        # Create a new entry for this message type if it doesn't exist
        if not msg[0] in self.stats['msgs'].keys():
            self.stats['msgs'][msg[0]] = [0, 0]

        if not crcValid:
            self.stats['msgs'][msg[0]][1] += 1
            #print "****BAD CRC****"
            return False
        self.stats['msgs'][msg[0]][0] += 1
        """
        #if msg[0] in [0, 10, 11]:
        if msg[0] in [101]:
            print "msg%d: " % (msg[0])
            for m in [msg]:
                hexstr = ""
                for n in range(len(msg)):
                    if (n % 4) == 0:  hexstr += " "
                    hexstr += "%02x" % (msg[n])
                print " " + hexstr
        """

        m = messages.messageToObject(msg)
        if not m:
            return False

        if m.MsgType == 'Heartbeat':
            self.currtime += self.heartbeatInterval
            if self.format == 'normal':
                print 'MSG00: s1=%02x, s2=%02x, ts=%02x' % (
                    m.StatusByte1, m.StatusByte2, m.TimeStamp)
            elif self.format == 'plotflight':
                self.altitudeAge += 1

        elif m.MsgType == 'OwnershipReport':
            if m.Latitude == 0.00 and m.Longitude == 0.00:
                if m.NavIntegrityCat == 0 or m.NavIntegrityCat == 1:  # unknown or <20nm, consider it invalid
                    pass
            elif self.format == 'normal':
                print 'MSG10: %0.7f %0.7f %d %d %d' % (m.Latitude, m.Longitude,
                                                       m.HVelocity, m.Altitude,
                                                       m.TrackHeading)
            elif self.format == 'plotflight':
                if self.altitudeAge < self.altitudeMaxAge:
                    altitude = self.altitude
                else:
                    # revert to 25' resolution altitude from ownership report
                    altitude = m.Altitude

                # Must have the GPS time from a message 101 before outputting anything
                if not self.gpsTimeReceived:
                    return True
                print '%02d:%02d:%02d %0.7f %0.7f %d %d %d' % (
                    self.currtime.hour, self.currtime.minute,
                    self.currtime.second, m.Latitude, m.Longitude, m.HVelocity,
                    altitude, m.TrackHeading)

        elif m.MsgType == 'OwnershipGeometricAltitude':
            if self.format == 'normal':
                print 'MSG11: %d %04xh' % (m.Altitude, m.VerticalMetrics)
            elif self.format == 'plotflight':
                self.altitude = m.Altitude
                self.altitudeAge = 0

        elif m.MsgType == 'TrafficReport':
            if m.Latitude == 0.00 and m.Longitude == 0.00 and m.NavIntegrityCat == 0:  # no valid position
                pass
            elif self.format == 'normal':
                print 'MSG20: %0.7f %0.7f %d %d %d %d %s' % (
                    m.Latitude, m.Longitude, m.HVelocity, m.VVelocity,
                    m.Altitude, m.TrackHeading, m.CallSign)

        elif m.MsgType == 'GpsTime':
            if not self.gpsTimeReceived:
                self.gpsTimeReceived = True
                utcTime = datetime.time(m.Hour, m.Minute, 0)
                self.currtime = datetime.datetime.combine(
                    self.dayStart, utcTime)
            else:
                # correct time slips and move clock forward if necessary
                if self.currtime.hour < m.Hour or self.currtime.minute < m.Minute:
                    utcTime = datetime.time(m.Hour, m.Minute, 0)
                    self.currtime = datetime.datetime.combine(
                        self.currtime, utcTime)

            if self.format == 'normal':
                print 'MSG101: %02d:%02d UTC (waas = %s)' % (m.Hour, m.Minute,
                                                             m.Waas)

        elif m.MsgType == 'UplinkData' and self.uatOutput == True:
            messageUatToObject(m)

        return True
Beispiel #4
0
    def _decodeMessage(self, escapedMessage):
        """
        decode one GDL90 message without the start/end markers
        returns None or othe message number that was processed
        """
        
        rawMsg = self._unescape(escapedMessage)
        if len(rawMsg) < 5:
            return None
        msg = rawMsg[:-2]
        crc = rawMsg[-2:]
        crcValid = crcCheck(msg, crc)
        
        m = messages.messageToObject(msg)
        if not m:
            return None
        
        if m.MsgType == 'Heartbeat':
            # MsgType StatusByte1 StatusByte2 TimeStamp MessageCounts
            logging.info('MSG00: s1=%02x, s2=%02x, ts=%02x' % (m.StatusByte1, m.StatusByte2, m.TimeStamp))

            # TimeStamp is the number of seconds since midnight, UTC
            self.seconds_since_midnight = int(m.TimeStamp)
            self.current_datetime = datetime.datetime.combine(
                datetime.date.today(),
                datetime.time(0, 0, 0),
            ) + datetime.timedelta(seconds=int(m.TimeStamp))

            self.gpsAge += 1

            logging.info('MGS00: Secs since 00Z is {}, current datetime: {}, gpsAge: {}'.format(
                self.seconds_since_midnight, self.current_datetime, self.gpsAge,
            ))
            return 0  # message 0 received
        
        elif m.MsgType == 'OwnershipReport':
            # MsgType Status Type Address Latitude Longitude Altitude Misc NavIntegrityCat NavAccuracyCat 
            # HVelocity VVelocity TrackHeading EmitterCat CallSign Code

            logging.info('MSG10: {},{}   {} kts, {} fpm, {} pAlt, {} hdg, {} NIC, {} nacP'.format(
                m.Latitude, m.Longitude, m.HVelocity, m.VVelocity, m.Altitude, 
                m.TrackHeading, m.NavIntegrityCat, m.NavAccuracyCat))

            self.latitude = m.Latitude
            self.longitude = m.Longitude
            self.course = int(m.TrackHeading)        
            self.vertical_speed = m.VVelocity   # fpm
            self.speed = m.HVelocity            # knots
            self.pressure_altitude = m.Altitude 
            self.nic = m.NavIntegrityCat        # >= 8 is probably great for us
            self.nac = m.NavAccuracyCat         # >= 8 is probably great for us

            return 10 # message number 10

        
        elif m.MsgType == 'OwnershipGeometricAltitude':
            # MsgType Altitude VerticalMetrics
            logging.info('MSG11: %d gpsAlt %04xh' % (m.Altitude, m.VerticalMetrics))
            self.altitude = m.Altitude
            self.gpsAge = 0

            return 11 # message number 11

        
        # This message does not seem to be sent by my NGT-9000 or stratux
        # Not sure what that's all about... would be super userful to have a 
        # real clock.
        """
        elif m.MsgType == 'GpsTime':

            if not self.gpsTimeReceived:
                self.gpsTimeReceived = True
                utcTime = datetime.time(m.Hour, m.Minute, 0)
                self.currtime = datetime.datetime.combine(self.dayStart, utcTime)
            else:
                # correct time slips and move clock forward if necessary
                if self.currtime.hour < m.Hour or self.currtime.minute < m.Minute:
                    utcTime = datetime.time(m.Hour, m.Minute, 0)
                    self.currtime = datetime.datetime.combine(self.currtime, utcTime)
            
            print 'MSG101: %02d:%02d UTC (waas = %s)' % (m.Hour, m.Minute, m.Waas)
        """

        # Traffic reporting code has been ripped out, we don't need it

        return None