Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
85192ad
1
DigiWhale Mar 18, 2022
50d592d
1
DigiWhale Mar 18, 2022
ac72834
1
DigiWhale Mar 18, 2022
be5d9c8
1
DigiWhale Mar 18, 2022
109b505
1
DigiWhale Mar 18, 2022
4a2b000
1
DigiWhale Mar 18, 2022
cbc68f0
1
DigiWhale Mar 18, 2022
84961f1
1
DigiWhale Mar 18, 2022
683693c
1
DigiWhale Mar 18, 2022
b4600be
1
DigiWhale Mar 18, 2022
682cdc1
1
DigiWhale Mar 18, 2022
e7ec5dd
1
DigiWhale Mar 18, 2022
3f07b7c
1
DigiWhale Mar 18, 2022
4ad8f3c
1
DigiWhale Mar 18, 2022
232d6c8
1
DigiWhale Mar 18, 2022
258888c
1
DigiWhale Mar 18, 2022
d1ba364
1
DigiWhale Mar 18, 2022
bc80433
1
DigiWhale Mar 18, 2022
4237861
1
DigiWhale Mar 18, 2022
46c41e9
1
DigiWhale Mar 18, 2022
e41868f
1
DigiWhale Mar 18, 2022
20bb98c
1
DigiWhale Mar 23, 2022
6e3c2f4
1
DigiWhale Mar 23, 2022
24f5746
1
DigiWhale Mar 23, 2022
758670a
1
DigiWhale Mar 23, 2022
f40aa9e
1
DigiWhale Mar 23, 2022
f77aefd
1
DigiWhale Mar 23, 2022
2abcf06
1
DigiWhale Mar 23, 2022
d44ef20
1
DigiWhale Mar 23, 2022
2832f34
1
DigiWhale Mar 23, 2022
1a9f5c4
1
DigiWhale Mar 23, 2022
60ea346
1
DigiWhale Mar 23, 2022
57dfad1
1
DigiWhale Mar 23, 2022
364e62f
1
DigiWhale Mar 23, 2022
078c671
1
DigiWhale Mar 23, 2022
68fd2a4
1
DigiWhale Mar 23, 2022
cb1a313
1
DigiWhale Mar 23, 2022
ac5070a
1
DigiWhale Mar 26, 2022
0101fc6
1
DigiWhale Mar 26, 2022
315e9c5
1
DigiWhale Mar 26, 2022
9ca498d
1
DigiWhale Mar 26, 2022
007f86a
1
DigiWhale Mar 26, 2022
e2dd7b8
1
DigiWhale Mar 26, 2022
6117385
1
DigiWhale Mar 26, 2022
a188e0e
1
DigiWhale Mar 26, 2022
a5ffb0b
1
DigiWhale Mar 26, 2022
3442ee9
1
DigiWhale Mar 26, 2022
e7ac3a6
1
DigiWhale Mar 26, 2022
a7bd3ce
1
DigiWhale Mar 26, 2022
6b1d2db
1
DigiWhale Mar 26, 2022
35a490d
1
DigiWhale Mar 26, 2022
dbc8c2a
1
DigiWhale Mar 26, 2022
7849af9
1
DigiWhale Mar 26, 2022
cd24c8b
1
DigiWhale Mar 26, 2022
1b10bfb
1
DigiWhale Mar 26, 2022
b57e38c
1
DigiWhale Mar 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ Uploaded only for the Raspberry Pi driver.

![L76X-GPS-Module-2.jpg](L76X-GPS-Module-2.jpg)

ttt

56 changes: 29 additions & 27 deletions python/L76X.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class L76X(object):
Status = 0
Lon_Baidu = 0.0
Lat_Baidu = 0.0
Lon_Goodle = 0.0
Lat_Goodle = 0.0
Lon_Google = 0.0
Lat_Google = 0.0

GPS_Lon = 0
GPS_Lat = 0
Expand Down Expand Up @@ -83,50 +83,52 @@ def __init__(self):

def L76X_Send_Command(self, data):
Check = ord(data[1])
# print(Check)
for i in range(2, len(data)):
Check = Check ^ ord(data[i])
data = data + Temp[16]
data = data + Temp[(Check/16)]
# print(data)
data = data + Temp[Check//16]
data = data + Temp[(Check%16)]
self.config.Uart_SendString(data)
self.config.Uart_SendByte('\r')
self.config.Uart_SendByte('\n')
print data
self.config.Uart_SendString(data.encode())
self.config.Uart_SendByte('\r'.encode())
self.config.Uart_SendByte('\n'.encode())
# print(data)

def L76X_Gat_GNRMC(self):
data = self.config.Uart_ReceiveString(BUFFSIZE)
print data
print '\n'
# print(data)
# print('\n')
add=0
self.Status = 0
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):
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(ord(data[add+z]) == 44):#,
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(ord(data[add+z+k+1]) == 44):#,
if(data[add+z+k+1]) == 44:#,
break
if(ord(data[add+z+k+1]) == 46):#.
if(data[add+z+k+1]) == 46:#.
break
Time = (ord(data[add+z+k+1]) - 48) + Time*10
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(ord(data[add+z+1]) == 65):#A
if(data[add+z+1]) == 65:#A
self.Status = 1
else:
self.Status = 0
Expand All @@ -135,11 +137,11 @@ def L76X_Gat_GNRMC(self):
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if(ord(data[add+z+k+1]) == 44):#,
if(data[add+z+k+1]) == 44:#,
break
if(ord(data[add+z+k+1]) == 46):#.
if(data[add+z+k+1]) == 46:#.
continue
latitude = (ord(data[add+z+k+1]) - 48) + latitude*10
latitude = (data[add+z+k+1]) - 48 + latitude*10
self.Lat = latitude / 1000000.0
elif(x == 4):
self.Lat_area = data[add+z+1]
Expand All @@ -148,11 +150,11 @@ def L76X_Gat_GNRMC(self):
for k in range(0, BUFFSIZE-1):
if(add+z+k >= BUFFSIZE-1):
return
if(ord(data[add+z+k+1]) == 44):#,
if(data[add+z+k+1]) == 44:#,
break
if(ord(data[add+z+k+1]) == 46):#.
if(data[add+z+k+1]) == 46:#.
continue
longitude = (ord(data[add+z+k+1]) - 48) + longitude*10
longitude = (data[add+z+k+1]) - 48 + longitude*10

self.Lon = longitude / 1000000.0
elif(x == 6):
Expand All @@ -176,8 +178,8 @@ def transformLon(self, x, y):
return ret

def bd_encrypt(self):
x = self.Lon_Goodle
y = self.Lat_Goodle
x = self.Lon_Google
y = self.Lat_Google
z = math.sqrt(x * x + y * y) + 0.00002 * math.sin(y * x_pi)
theta = math.atan2(y, x) + 0.000003 * math.cos(x * x_pi)
self.Lon_Baidu = z * math.cos(theta) + 0.0065
Expand All @@ -192,8 +194,8 @@ def transform(self):
math.sqrtMagic = math.sqrt(magic)
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * math.sqrtMagic) * pi)
dLon = (dLon * 180.0) / (a / math.sqrtMagic * math.cos(radLat) * pi)
self.Lat_Goodle = self.GPS_Lat + dLat
self.Lon_Goodle = self.GPS_Lon + dLon
self.Lat_Google = self.GPS_Lat + dLat - 0.00003
self.Lon_Google = self.GPS_Lon + dLon - .00293

def L76X_Baidu_Coordinates(self, U_Lat, U_Lon):
self.GPS_Lat = U_Lat % 1 *100 / 60 + math.floor(U_Lat)
Expand Down
39 changes: 24 additions & 15 deletions python/main.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
import L76X
import time
import math
import traceback
import redis_class

try:
redis = redis_class.RedisClient(host='192.168.0.150', port=6379, password="Redis2019!")
x=L76X.L76X()
x.L76X_Set_Baudrate(9600)
x.L76X_Send_Command(x.SET_NMEA_BAUDRATE_115200)
time.sleep(2)
x.L76X_Set_Baudrate(115200)

x.L76X_Send_Command(x.SET_POS_FIX_400MS);
x.L76X_Send_Command(x.SET_POS_FIX_100MS)

#Set output message
x.L76X_Send_Command(x.SET_NMEA_OUTPUT);
x.L76X_Send_Command(x.SET_NMEA_OUTPUT)

x.L76X_Exit_BackupMode();
x.L76X_Exit_BackupMode()
while(1):
x.L76X_Gat_GNRMC()
if(x.Status == 1):
print 'Already positioned'
redis.set('sat_use', 6)
else:
print 'No positioning'
print 'Time %d:'%x.Time_H,
print '%d:'%x.Time_M,
print '%d'%x.Time_S

print 'Lon = %f'%x.Lon,
print ' Lat = %f'%x.Lat
redis.set('sat_use', 0)
# print('Time %d:'%x.Time_H,)
# print('%d:'%x.Time_M,)
# print('%d'%x.Time_S)
# print(int(time.time() * 1000))
# print('Lon = %f'%x.Lon,)
# print(' Lat = %f'%x.Lat)
x.L76X_Google_Coordinates(x.Lat, x.Lon)
x.L76X_Baidu_Coordinates(x.Lat, x.Lon)
print 'Baidu coordinate %f'%x.Lat_Baidu,
print ',%f'%x.Lon_Baidu
except:
print(x.Lat_Google, -x.Lon_Google)
redis.set('gps_lng', -x.Lon_Google)
redis.set('gps_lat', x.Lat_Google)
# print(type(x.Lon))
# print('Baidu coordinate %f'%x.Lat_Baidu,)
# print(',%f'%x.Lon_Baidu)
except Exception as e:
print(traceback.format_exc())
#GPIO.cleanup()
print "\nProgram end"
print("\nProgram end")
exit()
72 changes: 72 additions & 0 deletions python/redis_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import redis
import datetime
import json

class RedisClient(object):
def __init__(self, host, port, password, database=0):
self.db = redis.Redis(host=host, port=port, password=password, db=database)
self.host = host
self.port = port
self.password = password

def get(self, key, start_index=0, end_index=0):
try:
value = self.db.get(key).decode()
if value.isalpha():
pass
elif "." in value and not ":" in value:
value = float(value)
elif value.count("-") > 1 and ":" in value:
value = datetime.datetime.strptime(value, "%Y-%m-%d %H:%M:%S.%f").timestamp()
elif value.count("-") >= 3:
pass
elif value.count("-") == 1 and value[1:].isnumeric():
value = int(value)
elif value.isnumeric():
value = int(value)
else:
pass
except Exception as e:
decoded_list = []
value = self.db.lrange(key, start_index, end_index)
for i in range(len(value)):
if '{' in value[i].decode():
value[i] = json.loads(value[i].decode())
decoded_list.append(value[i])
else:
decoded_list.append(value[i].decode())
value = decoded_list
return value

def get_all_keys(self):
keys = self.db.keys()
for i in range(len(keys)):
keys[i] = keys[i].decode()
return keys

def get_all_keys_and_values(self):
key_value_dict = {}
keys = self.get_all_keys()
for i in range(len(keys)):
value = self.get(keys[i])
key_value_dict[keys[i]] = value
return key_value_dict

def set(self, key, value):
self.db.set(key, value)

def set_multiple(self, key_value_dict):
pipe = self.db.pipeline()
for key, value in key_value_dict.items():
pipe.set(key, value)
pipe.execute()

def delete(self, key):
self.db.delete(key)

def exists(self, key):
return self.db.exists(key)

if __name__ == '__main__':
redis = RedisClient(host='192.168.0.150', port=6379, password="Redis2019!")
print(redis.get_all_keys_and_values())