with PySerialDriver(args.port[0], baud=1000000) as driver:
with Handler(Framer(driver.read, None, verbose=True)) as source:
try:
for msg, metadata in source.filter(SBP_MSG_BASELINE_NED):
print "%.4f,%.4f,%.4f" % (msg.n * 1e-3, msg.e * 1e-3, msg.d * 1e-3)
except KeyboardInterrupt:
pass
just change the filter to None and you will receive any msg type: |
for msg, metadata in source.filter():
if(isinstance(msg, sbp.navigation.MsgUtcTime)):
....
if(isinstance(msg, sbp.navigation.MsgBaselineNED)):
....
if(isinstance(msg, sbp.navigation.MsgPosLLH)):
print(msg.lat, msg.lon, msg.height, msg.h_accuracy)
....
data = b''BIG_MSG = 45 #a size bigger than the longest msg we care to decodePREAMBLE = 6 #this is the length of the preamble 0x55 plus the length and the message type bytes.GPSTimeOfWeek = 0while True:data += serialPort.read(100)while True:index = data.find(b"\x55") #the location of the first preamble byte#this line checks to see if there is enough data that it makes sense to even attempt to process the message.if len(data) < index + BIG_MSG or index == -1:continuelength = data[index+5] #the length of the actual messageoutput = ''msgType = data[index+1:index+3] #you can get these magic numbers from the SBP message specification#print("time: %s length: %s index: %s" % (struct.unpack('<i',data[index+6:index+10])[0], len(data), index))if msgType == b"\x0c\x02": #Rover NED'soutput = {'GPS_TimeOfWeek' : (struct.unpack('<i',data[index+6:index+10])[0]),#in milliseconds'north' : struct.unpack('<i',data[index+10:index+14])[0]*0.001,'east' : struct.unpack('<i',data[index+14:index+18])[0]*0.001,#FIXFLAG is an enumeration for readability in the log... you can just put the number if you wish.'fixmode' : FIXFLAG(data[index+27]).name}data = data[index+length+PREAMBLE:] #chop the data chunk we've already used.