• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pynmea2.parse函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pynmea2.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_lat_lon_time_from_nmea

def get_lat_lon_time_from_nmea(nmea_file, local_time=True):
    '''
    Read location and time stamps from a track in a NMEA file.

    Returns a list of tuples (time, lat, lon).

    GPX stores time in UTC, by default we assume your camera used the local time
    and convert accordingly.
    '''
    with open(nmea_file, "r") as f:
        lines = f.readlines()
        lines = [l.rstrip("\n\r") for l in lines]

    points = []
    for l in lines:
        if "GPRMC" in l:
            data = pynmea2.parse(l)
            date = data.datetime.date()

        if "$GPGGA" in l:
            data = pynmea2.parse(l)
            timestamp = datetime.datetime.combine(date, data.timestamp)
            lat, lon, alt = data.latitude, data.longitude, data.altitude
            points.append((timestamp, lat, lon, alt))

    points.sort()
    return points
开发者ID:elopio,项目名称:mapillary_tools,代码行数:27,代码来源:gps_parser.py


示例2: test_proprietary_with_comma

def test_proprietary_with_comma():
    # class with no extra comma
    class TNLDG(pynmea2.tnl.TNL):
        fields = ()

    # raise Exception(TNL.sentence_types)
    # raise Exception(pynmea2.ProprietarySentence.sentence_types)

    data = "$PTNLDG,44.0,33.0,287.0,100,0,4,1,0,,,*3E"
    msg = pynmea2.parse(data)
    assert isinstance(msg, TNLDG)
    assert msg.data == ['DG', '44.0', '33.0', '287.0', '100', '0', '4', '1', '0', '', '', '']
    assert str(msg) == data


    # type with extra comma

    data = '$PTNL,PJT,NAD83(Conus),CaliforniaZone 4 0404*51'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.tnl.TNLPJT
    assert msg.manufacturer == 'TNL'
    assert msg.sentence_type == 'PJT'
    assert msg.coord_name == 'NAD83(Conus)'
    assert msg.project_name == 'CaliforniaZone 4 0404'
    assert str(msg) == data
开发者ID:jtornero,项目名称:pynmea2,代码行数:25,代码来源:test_proprietary.py


示例3: test_srf

def test_srf():
    # implemented sentence
    data = '$PSRF100,0,1200,8,1,1'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.srf.SRF100

    # unimplemented sentence
    data = '$PSRF999,0,1200,8,1,1'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.srf.SRF
开发者ID:jtornero,项目名称:pynmea2,代码行数:10,代码来源:test_proprietary.py


示例4: push_latlon_NMEA_data

    def push_latlon_NMEA_data(self,stream, deque):
        """
        """

        while True:
            time.sleep(0.1)
            while(len(deque) > 0):
                data = deque.pop()
                #print data                
                # Interprete the data
                try:
                    data_nmea = pynmea2.parse(data['nmea'])
                    data_time = data['time']
                    # Merge the date of the unix time sent and the
                    # HHMMSS of the GPGGA string together
                    ts = time.gmtime(data_time)
                    tstr = time.strftime("%Y%m%d",ts)
                    #
                    if(data_nmea.identifier().rfind('GPGGA')>=0):
                        #print('lat/lon!')
                        nmea_time = data_nmea.timestamp.strftime("%H%M%S")
                        tstr_unix = tstr + nmea_time
                        #print('unix time',tstr_unix)
                        tfloat_unix = calendar.timegm(time.strptime(tstr_unix,"%Y%m%d%H%M%S"))
                        lat = data_nmea.latitude
                        lon = data_nmea.longitude
                        #print(nmea_time)
                        #print(tfloat_unix,time.gmtime(tfloat_unix))
                        #print(data_nmea.latitude)
                        #print(data_nmea.longitude)
                        stream.pub_data([[nmea_time,tfloat_unix,lon,lat],])

                except Exception as e:
                    print(str(e) + ' Bad data ')
开发者ID:MarineDataTools,项目名称:pymqdatastream,代码行数:34,代码来源:pymqds_NMEA0183.py


示例5: test_proprietary_implemented

def test_proprietary_implemented():
    # Ensure a proprietary sentence that is explicitly implemented isn't
    # returned as a generic proprietary sentence.
    data = "$PGRME,15.0,M,45.0,M,25.0,M*1C"
    msg = pynmea2.parse(data)

    assert repr(msg) == "<RME(hpe='15.0', hpe_unit='M', vpe='45.0', vpe_unit='M', osepe='25.0', osepe_unit='M')>"
开发者ID:follower,项目名称:pynmea2,代码行数:7,代码来源:test_types.py


示例6: test_XDR

def test_XDR():
    data = "$YXXDR,A,-64.437,M,N,A,054.454,D,E,C,17.09,C,T-N1052*46"
    msg = pynmea2.parse(data)
    assert isinstance(msg, pynmea2.XDR)
    assert msg.talker == 'YX'
    assert msg.type == 'A'
    assert msg.value == '-64.437'
    assert msg.units == 'M'
    assert msg.id == 'N'

    assert msg.num_transducers == 3

    t0 = msg.get_transducer(0)
    assert t0.type == 'A'
    assert t0.value == '-64.437'
    assert t0.units == 'M'
    assert t0.id == 'N'

    t1 = msg.get_transducer(1)
    assert t1.type == 'A'
    assert t1.value == '054.454'
    assert t1.units == 'D'
    assert t1.id == 'E'

    t2 = msg.get_transducer(2)
    assert t2.type == 'C'
    assert t2.value == '17.09'
    assert t2.units == 'C'
    assert t2.id == 'T-N1052'
开发者ID:countkisg,项目名称:pynmea2,代码行数:29,代码来源:test_types.py


示例7: get_location

def get_location(gps):
    gps_data = ""
    print ("reading in location")
    gps.setblocking(True)
    while True:
        try:
            d = gps.recv(8096)
            gps.setblocking(False)
        except IOError:
            break
        gps_data += d
        print d
        if not d:
            break

    gps_data = "\n".join(gps_data.split("\n")[1:-1])  # :(

    nmea_stream_reader = pynmea2.NMEAStreamReader()
    gps_loc_msg = None

    for msg in gps_data.split("\n"):
        if len(str(msg)) > 50 and "GPGGA" in msg:
            gps_loc_msg = pynmea2.parse(msg[:-1])

    if gps_loc_msg == None:
        return (0, 0, 0)

    return (gps_loc_msg.latitude, gps_loc_msg.longitude, gps_loc_msg.horizontal_dil)
开发者ID:vbnbharath,项目名称:WSN,代码行数:28,代码来源:rssi_grabber.py


示例8: convert_nmea_to_json

def convert_nmea_to_json(nmea_str, filename, GMT_OFFSET=0):
    json_list = []
    filename = filename.strip('.LOG').strip('N')
    year = 2000 + int(filename[0:2])
    month = int(filename[2:4])
    day = int(filename[4:6])
    print(year, month, day)
    for line in nmea_str.split('\n'):
        line = line.strip()
        if '@' in line or 'GPRMC' in line or len(line) == 0:
            continue
        record = pynmea2.parse(line)
        dt = record.timestamp
        dt = datetime(year, month, day, dt.hour, dt.minute, dt.second)
        # Gather values
        posix = int(dt.strftime("%s"))
        posix += (60 * 60 * GMT_OFFSET)
        lat   = float(record.latitude)
        lon   = float(record.longitude)
        json_list.append({
            'time': posix,
            'lat':  lat,
            'lon':  lon,
        })
    return json.dumps({ "track": json_list })
开发者ID:Erotemic,项目名称:ibeis,代码行数:25,代码来源:appfuncs.py


示例9: test_GGA

def test_GGA():
    data = "$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D"
    msg = pynmea2.parse(data)
    assert msg.talker == 'GP'
    assert msg.type == 'GGA'

    # Timestamp
    assert msg.timestamp        == datetime.time(18, 43, 53)
    # Latitude
    assert msg.lat              == '1929.045'
    # Latitude Direction
    assert msg.lat_dir          == 'S'
    # Longitude
    assert msg.lon              == '02410.506'
    # Longitude Direction
    assert msg.lon_dir          == 'E'
    # GPS Quality Indicator
    assert msg.gps_qual         == '1'
    # Number of Satellites in use
    assert msg.num_sats         == '04'
    # Horizontal Dilution of Precision
    assert msg.horizontal_dil   == '2.6'
    # Antenna Alt above sea level (mean)
    assert msg.altitude         == 100.0
    # Units of altitude (meters)
    assert msg.altitude_units   == 'M'
    # Geoidal Separation
    assert msg.geo_sep          == '-33.9'
    # Units of Geoidal Separation (meters)
    assert msg.geo_sep_units    == 'M'
    # Age of Differential GPS Data (secs)
    assert msg.age_gps_data     == ''
    # Differential Reference Station ID
    assert msg.ref_station_id   == '0000'
开发者ID:ArenaSource,项目名称:pynmea2,代码行数:34,代码来源:test_types.py


示例10: run

 def run(self):
     while (self.connected):
         c = self.socket.recv(1)
         if (c=='$' or c=='!'): # beginning
             self.sentence = c
         else:
             self.sentence += c
         if c=='\n': # end of sentence
         # should check checksum...
             if (self.sentence[0]=='$'):
                 self.logger.debug("Received sentence: %s" % self.sentence)
                 sentence_header, comma, sentence_body = self.sentence.partition(',')
                 sentence_header = sentence_header.lstrip('$')
                 self.sentences[sentence_header] = self.sentence
                 try:
                     msg = pynmea2.parse(self.sentence)
                     self.logger.debug("Sentence type: %s" % msg.sentence_types)
                     if not NmeaDataSource.lock.acquire(False):
                         self.logger.error("Lock failed writing watchField")
                     else:
                         try:
                             for watchField in self.watch_fields:
                                 watchField.update_value_from_message(msg)
                         finally:
                             NmeaDataSource.lock.release()
                 except ValueError as e:
                     self.logger.debug("Unknown message type received")
                 except:
                     self.logger.error("Something shitty has happened. Offender is:")
                     self.logger.error(self.sentence)
                     raise
     self.socket.close()
开发者ID:CodeWithASmile,项目名称:boat_remote_server,代码行数:32,代码来源:nmea_data_source.py


示例11: parse_data

    def parse_data(self, datastring):
        self.log_gps(datastring)
        try:
            data = pynmea2.parse(datastring)
        except AttributeError as er:
            log(er.message)
            return
        except pynmea2.SentenceTypeError as er:
            log(er.message)
            return
        except pynmea2.ParseError as er:
            log(er.message)
            return
        except pynmea2.ChecksumError as er:
            log(er.message)
            return

        mappings = {"RMC": self.extract_rmc,
                    "GGA": self.extract_gga,
                    "GSV": self.extract_gsv,
                    "VTG": self.extract_vtg,
                    "GSA": self.extract_gsa}
        try:
            mappings[data.sentence_type](data)
            self.gpsStateChanged(self.info)
        except KeyError:
            return
        except AttributeError:
            return
开发者ID:skeenp,项目名称:Roam,代码行数:29,代码来源:gps.py


示例12: parse_sentence

    def parse_sentence(self):
        """ parse GPS nmea0183 sentences, one shot,
        currently only support RMC,"""
        sentence_type = ""
        while sentence_type is not "RMC":
            sentence = SC16IS750.read_sentence(self)
            try:
                parsed_sentence = pynmea2.parse(sentence)
            except:
                continue

            try:
                sentence_type = parsed_sentence.sentence_type
            except AttributeError: # "sentence not supported"
                # print "#attribute error"
                continue
            latitude = parsed_sentence.latitude
            longitude = parsed_sentence.longitude
            lat_dir = parsed_sentence.lat_dir
            lon_dir = parsed_sentence.lon_dir
            timestamp = parsed_sentence.timestamp
            datestamp = parsed_sentence.datestamp
            spd_over_grnd = parsed_sentence.spd_over_grnd
            true_course = parsed_sentence.true_course
            fix = parsed_sentence.is_valid
            # print fix
            return({"latitude": latitude,
                    "longitude": longitude,
                    "lat_dir": lat_dir,
                    "lon_dir": lon_dir,
                    "datetime": datestamp.strftime("%Y-%m-%d ") + timestamp.strftime("%H:%M:%S"),
                    "spd_over_grnd": spd_over_grnd,
                    "true_course": true_course,
                    "fix": fix})
开发者ID:ron1818,项目名称:AUV,代码行数:34,代码来源:SC16IS750_I2C.py


示例13: main

def main():
  time_string = datetime.utcnow().strftime('%Y%m%d%H%M%S%f')
  filename = '/media/sdcard/gps{0}.csv'.format(time_string)
  raw_filename = '/media/sdcard/rawgps{0}.csv'.format(time_string)
  
  print 'logging to the following files'
  print filename
  print raw_filename
  ser = serial.Serial('/dev/ttyMFD1', 9600)

  while(True):
    s = ser.readline()

    if(s.startswith("$GP")):
      
      append_to_file(raw_filename, s)
      try:
        msg = pynmea2.parse(s)
      except pynmea2.nmea.ParseError:
        continue
    
      if msg.sentence_type == 'RMC':
        s = '{0},{1},{2}\n'.format(
          msg.datetime, 
          msg.latitude, 
          msg.longitude)
        append_to_file(filename, s)
开发者ID:berickson,项目名称:Edison,代码行数:27,代码来源:gps.py


示例14: test_query

def test_query():
    data = 'CCGPQ,GGA'
    msg = pynmea2.parse(data)
    assert isinstance(msg, pynmea2.QuerySentence)
    assert msg.talker == 'CC'
    assert msg.listener == 'GP'
    assert msg.sentence_type == 'GGA'
开发者ID:countkisg,项目名称:pynmea2,代码行数:7,代码来源:test_pynmea.py


示例15: test_unknown_sentence

def test_unknown_sentence():
    data = 'PZZZABC,1,2,3'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.ProprietarySentence
    assert msg.manufacturer == 'ZZZ'
    assert msg.data == ['ABC', '1', '2', '3']
    assert msg.render(checksum=False, dollar=False) == data
开发者ID:Knio,项目名称:pynmea2,代码行数:7,代码来源:test_proprietary.py


示例16: parseGPS

	def parseGPS(self, str):
	    if str.find('GGA') > 0:
	        msg = pynmea2.parse(str)
	        if len(msg.lat) > 2:
	        	if self.environment != None:
	        		self.environment.gpsConnected = True
	        	self.gpsPos = (msg.lat + msg.lat_dir, msg.lon + msg.lon_dir)
	        	self.convertToDecimalDegrees()

	        	# Set time according to GPS time
	        	if not self.timeSet:
	        		print 'Setting system time to GPS time...'
	        		gpsTime = "%s:%s:%s" % (msg.timestamp.hour, msg.timestamp.minute, msg.timestamp.second)
	        		if gpsTime != None:
	        			os.system('sudo date -u --set="%s"' % gpsTime)
	        			self.timeSet = True
	        			print 'System time set.'

	        else:
	        	self.gpsPos = (None, None)
	        	if self.environment != None:
	        		self.environment.gpsConnected  = False

	     	if self.environment != None:
	        	self.environment.gpsPos = self.gpsPos
开发者ID:andreaskall,项目名称:VeraHMI,代码行数:25,代码来源:GPSHandler.py


示例17: test_extra_comma

def test_extra_comma():
    # extra comma after name
    data = "$PTNL,AVR,212604.30,+52.1800,Yaw,,,-0.0807,Roll,12.579,3,1.4,16*21"
    msg = pynmea2.parse(data)
    assert msg.manufacturer == 'TNL'
    assert msg.data == ['', 'AVR','212604.30','+52.1800','Yaw','','','-0.0807','Roll','12.579','3','1.4','16']
    assert msg.render() == data
开发者ID:jtornero,项目名称:pynmea2,代码行数:7,代码来源:test_proprietary.py


示例18: test_ubx00

def test_ubx00():
    data = '$PUBX,00,074440.00,4703.74203,N,00736.82976,E,576.991,D3,2.0,2.0,0.091,0.00,-0.032,,0.76,1.05,0.65,14,0,0*70'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.ubx.UBX00
    assert msg.timestamp == datetime.time(7, 44, 40)
    assert msg.latitude == 47.06236716666667
    assert msg.lat_dir == 'N'
开发者ID:jtornero,项目名称:pynmea2,代码行数:7,代码来源:test_proprietary.py


示例19: test_ubx04

def test_ubx04():
    data = '$PUBX,04,073824.00,131014,113903.99,1814,16,495176,342.504,21*18'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.ubx.UBX04
    assert msg.date == datetime.date(2014, 10, 13)
    assert msg.time == datetime.time(7, 38, 24)
    assert msg.clk_bias == 495176
开发者ID:jtornero,项目名称:pynmea2,代码行数:7,代码来源:test_proprietary.py


示例20: test_tnl

def test_tnl():
    data = '$PTNL,BPQ,224445.06,021207,3723.09383914,N,12200.32620132,W,EHT-5.923,M,5*60'
    msg = pynmea2.parse(data)
    assert type(msg) == pynmea2.tnl.TNLBPQ
    assert msg.datestamp == datetime.date(2007,12,2)
    assert msg.latitude == 37.384897319
    assert msg.longitude == -122.00543668866666
开发者ID:jtornero,项目名称:pynmea2,代码行数:7,代码来源:test_proprietary.py



注:本文中的pynmea2.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pynotify.get_server_caps函数代码示例发布时间:2022-05-27
下一篇:
Python statistics.FrequencyList类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap