[Swlug] commenting - do you do it?
Rhys Sage
rhys_sage at yahoo.com
Tue Jul 12 00:54:45 UTC 2022
This is the badly obfuscated code I'm trying to work with. All I need to do is to get fields 7 and 8 of the $sgynmrc record. I'm fighting this %$%$ piece of code all the way. I don't know how the author had the face to put this up on github.
def L76X_Send_Command(self, data):
Check = ord(data[1])
for i in range(2, len(data)):
Check = Check ^ ord(data[i])
data = data + Temp[16]
data = data + Temp[int(Check/16)]
data = data + Temp[int(Check%16)]
self.config.Uart_SendString(data.encode())
self.config.Uart_SendByte('\r'.encode())
self.config.Uart_SendByte('\n'.encode())
print (data)
#print ("def L76X_Send_Command(self, data):")
def L76X_Gat_GNRMC(self):
data = self.config.Uart_ReceiveString(BUFFSIZE)
print (data)
print("def L76X_Gat_GNRMC(self):")
print ('\n')
add=0
self.Status = 0
# finds $GNYRMC
try:
for i in range(0, BUFFSIZE-71):
if(ord(data[add]) == 36 and ord(data[add+1]) == 71 and (ord(data[add+2]) == 78 \
or ord(data[add+2]) == 80) and ord(data[add+3]) == 82 and ord(data[add+4]) == 77\
and ord(data[add+5]) == 67):
# end obfuscated section used to find $SGNYRMC
x = 0
z = 0
while(x < 12):
if(add+z >= BUFFSIZE-1):
return
if(ord(data[add+z]) == 44):#,
x = x + 1
if(x == 1):
Time = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if(ord(data[add+z+k+1]) == 44):#,
break
if(ord(data[add+z+k+1]) == 46):#.
break
Time = (ord(data[add+z+k+1]) - 48) + Time*10
self.Time_H = Time/10000 + 8
self.Time_M = Time/100%100
self.Time_S = Time%100
if(self.Time_H >= 24):
self.Time_H = self.Time_H - 24
elif(x == 2):
if(ord(data[add+z+1]) == 65):#A
self.Status = 1
else:
self.Status = 0
elif(x == 3):
latitude = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if(ord(data[add+z+k+1]) == 44):#,
break
if(ord(data[add+z+k+1]) == 46):#.
continue
latitude = (ord(data[add+z+k+1]) - 48) + latitude*10
self.Lat = latitude / 1000000.0
elif(x == 4):
self.Lat_area = data[add+z+1]
elif(x == 5):
longitude = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if(ord(data[add+z+k+1]) == 44):#,
break
if(ord(data[add+z+k+1]) == 46):#.
continue
longitude = (ord(data[add+z+k+1]) - 48) + longitude*10
self.Lon = longitude / 1000000.0
elif(x == 6):
self.Lon_area = data[add+z+1]
return#Completion calculation
z = z + 1
add = add + 1
except TypeError:
for i in range(0, BUFFSIZE-71):
if((data[add]) == 36 and (data[add+1]) == 71 and ((data[add+2]) == 78 \
or (data[add+2]) == 80) and (data[add+3]) == 82 and (data[add+4]) == 77\
and (data[add+5]) == 67):
x = 0
z = 0
while(x < 12):
if(add+z >= BUFFSIZE-1):
return
if((data[add+z]) == 44):#,
x = x + 1
if(x == 1):
Time = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if((data[add+z+k+1]) == 44):#,
break
if((data[add+z+k+1]) == 46):#.
break
Time = ((data[add+z+k+1]) - 48) + Time*10
self.Time_H = Time/10000 + 8
self.Time_M = Time/100%100
self.Time_S = Time%100
if(self.Time_H >= 24):
self.Time_H = self.Time_H - 24
elif(x == 2):
if((data[add+z+1]) == 65):#A
self.Status = 1
else:
self.Status = 0
elif(x == 3):
latitude = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if((data[add+z+k+1]) == 44):#,
break
if((data[add+z+k+1]) == 46):#.
continue
latitude = ((data[add+z+k+1]) - 48) + latitude*10
self.Lat = latitude / 1000000.0
elif(x == 4):
self.Lat_area = data[add+z+1]
elif(x == 5):
longitude = 0
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if((data[add+z+k+1]) == 44):#,
break
if((data[add+z+k+1]) == 46):#.
continue
longitude = ((data[add+z+k+1]) - 48) + longitude*10
self.Lon = longitude / 1000000.0
elif(x == 6):
self.Lon_area = data[add+z+1]
return#Completion calculation
z = z + 1
add = add + 1
Rhys Sage
More information about the Swlug
mailing list