コード例 #1
0
    def test_init(self):
        # make sure it returns the correct type
        n = nmea.NMEA(
            '$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47'
        )
        self.assertIsInstance(n, nmea.NMEA)

        # make sure it won't try to parse something that isn't a string
        self.assertRaises(TypeError, lambda: nmea.NMEA(12))
コード例 #2
0
    def test_GLL(self):
        # make sure a valid sentence gets parsed correctly
        n = nmea.NMEA('$GPGLL,4916.45,N,12311.12,W,225444,A,*1D')
        self.assertEqual(n.utc.hour, 22)
        self.assertEqual(n.utc.minute, 54)
        self.assertEqual(n.utc.second, 44)
        self.assertTrue(n.status)
        self.assertAlmostEqual(n.latitude, 49.27417, 5)
        self.assertAlmostEqual(n.longitude, -123.1853, 4)

        # make sure an invalid sentence has False status
        n = nmea.NMEA('$GPGLL,4916.45,N,12311.12,W,225444,V,*1D')
        self.assertFalse(n.status)
コード例 #3
0
    def readGPS(self):
        # use the NMEA parser
        self.gps_serial_port.open()
        self.gps_serial_port.reset_input_buffer()
        for _ in range(5):
            try:
                line = self.gps_serial_port.readline().decode('utf-8')
            except:
                line = ''
            nmea_data = nmea.NMEA(line)
            if nmea_data.status:
                self.fix = True
                self.latitude = nmea_data.latitude
                self.longitude = nmea_data.longitude
                print("got lat {}, long {}".format(self.latitude, self.longitude))
                new_position = coord.Vector(self.coordinate_system,
                                            self.latitude, self.longitude)
                cur_time = time.time()

                if self.prev_time is None:
                    self.position = new_position
                    self.prev_time = cur_time
                else:
                    self.velocity = new_position.vectorSubtract(self.position)
                    self.velocity.scale(1.0 / (cur_time - self.prev_time))
                    self.position = new_position
                    self.prev_time = cur_time
        self.gps_serial_port.close()
コード例 #4
0
    def test_GGA(self):
        # make sure a valid sentence gets parsed correctly
        n = nmea.NMEA(
            '$GPGGA,123519,4807.038,S,01131.000,W,1,08,0.9,545.4,M,46.9,M,,*47'
        )
        self.assertEqual(n.utc.hour, 12)
        self.assertEqual(n.utc.minute, 35)
        self.assertEqual(n.utc.second, 19)
        self.assertTrue(n.status)
        self.assertAlmostEqual(n.latitude, -48.1173, 4)
        self.assertAlmostEqual(n.longitude, -11.51667, 5)

        # make sure an invalid sentence has False status
        n = nmea.NMEA(
            '$GPGGA,123519,4807.038,S,01131.000,W,0,08,0.9,545.4,M,46.9,M,,*47'
        )
        self.assertFalse(n.status)
コード例 #5
0
    def test_RMC(self):
        # make sure a valid sentence gets parsed correctly
        n = nmea.NMEA(
            '$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A'
        )
        self.assertEqual(n.utc.hour, 12)
        self.assertEqual(n.utc.minute, 35)
        self.assertEqual(n.utc.second, 19)
        self.assertTrue(n.status)
        self.assertAlmostEqual(n.latitude, 48.1173, 4)
        self.assertAlmostEqual(n.longitude, 11.51667, 5)

        # make sure an invalid sentence has False status
        n = nmea.NMEA(
            '$GPRMC,123519,V,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A'
        )
        self.assertFalse(n.status)
コード例 #6
0
 def test_GSV(self):
     # make sure status is false
     n = nmea.NMEA(
         '$GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75'
     )
     self.assertFalse(n.status)
コード例 #7
0
 def test_GSA(self):
     # make sure status is false
     n = nmea.NMEA('$GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39')
     self.assertFalse(n.status)
コード例 #8
0
 def test_VTG(self):
     # make sure status is false
     n = nmea.NMEA('$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48')
     self.assertFalse(n.status)