[Swlug] Quick Pythom question.
Rhys Sage
rhys_sage at yahoo.com
Thu Jul 14 21:11:32 UTC 2022
After finding the GitHub code was very flaky with faked references to Baidu and Glonass satellites, I cleaned up the mess by removing a few yards of pointless code and the deleted the bit that read the satellite downstream before rewriting it... Here's my final solution which gives more data to the user, takes up less space and is actually commented.
def L76X_Gat_GNRMC(self):
#we are only after the GNRMC field and only want:
# latitude, longtitude, direction, time and speed. Nothing else is of
# any importance - maybe data valid might be needed - don't yet know
data = self.config.Uart_ReceiveString(BUFFSIZE)
stringy = data.decode('UTF-8')
StLen = len(stringy)
if (stringy.find("$GNRMC") >-1):
#crop everything before the first field
StartPoint = stringy.index("$GNRMC")+7
stringy = stringy[StartPoint: (StLen - StartPoint)]
#crop everything from the second $
EndPoint = stringy.index("$")
stringy = stringy[0:EndPoint]
#now make it into a list
Listy = stringy.split(',')
RSTime = Listy[0]
RSValid = Listy[1]
RSLattitude = Listy[2]
RSNSHemisphere = Listy[3]
RSLongtitude = Listy[4]
RSWEHemisphere = Listy[5]
RSGroundSpeed = Listy[6]
RSDirection = Listy[7]
RSDate = Listy[8]
RSVariation = Listy[9]
RSChecksum = Listy[10]
#now return the required values to the program. That, for the drone operation will be
return RSTime, RSLattitude, RSLongtitude, RSGroundSpeed, RSDirection, RSDate, RSVariation
Rhys Sage
More information about the Swlug
mailing list