change file read, move global declaration
This commit is contained in:
parent
ca2d6c33d2
commit
5172faf7f2
67
gps_data.py
67
gps_data.py
@ -66,6 +66,9 @@ import pynmea2
|
|||||||
import os
|
import os
|
||||||
from gps_functions import cmd_list
|
from gps_functions import cmd_list
|
||||||
|
|
||||||
|
# Module for maidenhead grids
|
||||||
|
import maidenhead as mh
|
||||||
|
|
||||||
#Modules for APRS settings
|
#Modules for APRS settings
|
||||||
import ast
|
import ast
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -127,6 +130,12 @@ def header_ID(_data):
|
|||||||
# Work in progress, used to determine data format
|
# Work in progress, used to determine data format
|
||||||
## pass
|
## pass
|
||||||
|
|
||||||
|
def aprs_send(packet):
|
||||||
|
AIS = aprslib.IS(aprs_callsign, passwd=aprs_passcode,host=aprs_server, port=aprs_port)
|
||||||
|
AIS.connect()
|
||||||
|
AIS.sendall(packet)
|
||||||
|
AIS.close()
|
||||||
|
|
||||||
def user_setting_write(dmr_id, setting, value):
|
def user_setting_write(dmr_id, setting, value):
|
||||||
## try:
|
## try:
|
||||||
# Open file and load as dict for modification
|
# Open file and load as dict for modification
|
||||||
@ -168,6 +177,8 @@ def process_sms(from_id, sms):
|
|||||||
user_setting_write(int_id(from_id), re.sub(' .*|@','',sms), re.sub('@SSID| ','',sms))
|
user_setting_write(int_id(from_id), re.sub(' .*|@','',sms), re.sub('@SSID| ','',sms))
|
||||||
if '@COM' in sms:
|
if '@COM' in sms:
|
||||||
user_setting_write(int_id(from_id), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms))
|
user_setting_write(int_id(from_id), re.sub(' .*|@','',sms), re.sub('@COM |@COM','',sms))
|
||||||
|
if '@MH' in sms:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
if sms in cmd_list:
|
if sms in cmd_list:
|
||||||
logger.info('Executing command/script.')
|
logger.info('Executing command/script.')
|
||||||
@ -200,6 +211,7 @@ class DATA_SYSTEM(HBSYSTEM):
|
|||||||
pckt_seq = _seq
|
pckt_seq = _seq
|
||||||
# Try to classify header
|
# Try to classify header
|
||||||
if _call_type == call_type or (_call_type == 'vcsbk' and pckt_seq > 3): #int.from_bytes(_seq, 'big') > 3 ):
|
if _call_type == call_type or (_call_type == 'vcsbk' and pckt_seq > 3): #int.from_bytes(_seq, 'big') > 3 ):
|
||||||
|
global packet_assembly
|
||||||
if _dtype_vseq == 6 or _dtype_vseq == 'group':
|
if _dtype_vseq == 6 or _dtype_vseq == 'group':
|
||||||
global btf, hdr_start
|
global btf, hdr_start
|
||||||
hdr_start = str(header_ID(_data))
|
hdr_start = str(header_ID(_data))
|
||||||
@ -207,12 +219,13 @@ class DATA_SYSTEM(HBSYSTEM):
|
|||||||
logger.info(ahex(bptc_decode(_data)))
|
logger.info(ahex(bptc_decode(_data)))
|
||||||
logger.info('Blocks to follow: ' + str(ba2num(bptc_decode(_data)[65:72])))
|
logger.info('Blocks to follow: ' + str(ba2num(bptc_decode(_data)[65:72])))
|
||||||
btf = ba2num(bptc_decode(_data)[65:72])
|
btf = ba2num(bptc_decode(_data)[65:72])
|
||||||
|
# Try resetting packet_assembly
|
||||||
|
packet_assembly = ''
|
||||||
# Data blocks at 1/2 rate, see https://github.com/g4klx/MMDVM/blob/master/DMRDefines.h for data types. _dtype_seq defined here also
|
# Data blocks at 1/2 rate, see https://github.com/g4klx/MMDVM/blob/master/DMRDefines.h for data types. _dtype_seq defined here also
|
||||||
if _dtype_vseq == 7:
|
if _dtype_vseq == 7:
|
||||||
btf = btf - 1
|
btf = btf - 1
|
||||||
logger.info('Block #: ' + str(btf))
|
logger.info('Block #: ' + str(btf))
|
||||||
#logger.info(_seq)
|
#logger.info(_seq)
|
||||||
global packet_assembly
|
|
||||||
logger.info('Data block from ' + str(get_alias(int_id(_rf_src), subscriber_ids)) + '. DMR ID: ' + str(int_id(_rf_src)))
|
logger.info('Data block from ' + str(get_alias(int_id(_rf_src), subscriber_ids)) + '. DMR ID: ' + str(int_id(_rf_src)))
|
||||||
logger.info(ahex(bptc_decode(_data)))
|
logger.info(ahex(bptc_decode(_data)))
|
||||||
if _seq == 0:
|
if _seq == 0:
|
||||||
@ -236,31 +249,33 @@ class DATA_SYSTEM(HBSYSTEM):
|
|||||||
# Begin APRS format and upload
|
# Begin APRS format and upload
|
||||||
## aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(final_packet[29:36]) + str(final_packet[39]) + '/' + str(re.sub(',', '', final_packet[41:49])) + str(final_packet[52]) + '[/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
## aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(final_packet[29:36]) + str(final_packet[39]) + '/' + str(re.sub(',', '', final_packet[41:49])) + str(final_packet[52]) + '[/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
||||||
try:
|
try:
|
||||||
with open("./user_settings.txt", 'r') as f:
|
# Disable opening file for reading to reduce "collision" or reading and writing at same time.
|
||||||
user_settings = ast.literal_eval(f.read())
|
## with open("./user_settings.txt", 'r') as f:
|
||||||
if int_id(_rf_src) not in user_settings:
|
## user_settings = ast.literal_eval(f.read())
|
||||||
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + '/' + str(loc.lon[0:8]) + str(loc.lon_dir) + '[' + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read())
|
||||||
else:
|
if int_id(_rf_src) not in user_settings:
|
||||||
if user_settings[int_id(_rf_src)][1]['ssid'] == '':
|
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + '/' + str(loc.lon[0:8]) + str(loc.lon_dir) + '[' + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
||||||
ssid = user_ssid
|
else:
|
||||||
if user_settings[int_id(_rf_src)][3]['comment'] == '':
|
if user_settings[int_id(_rf_src)][1]['ssid'] == '':
|
||||||
comment = aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
ssid = user_ssid
|
||||||
if user_settings[int_id(_rf_src)][2]['icon'] == '':
|
if user_settings[int_id(_rf_src)][3]['comment'] == '':
|
||||||
icon_table = '/'
|
comment = aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
||||||
icon_icon = '['
|
if user_settings[int_id(_rf_src)][2]['icon'] == '':
|
||||||
if user_settings[int_id(_rf_src)][2]['icon'] != '':
|
icon_table = '/'
|
||||||
icon_table = user_settings[int_id(_rf_src)][2]['icon'][0]
|
icon_icon = '['
|
||||||
icon_icon = user_settings[int_id(_rf_src)][2]['icon'][1]
|
if user_settings[int_id(_rf_src)][2]['icon'] != '':
|
||||||
if user_settings[int_id(_rf_src)][1]['ssid'] != '':
|
icon_table = user_settings[int_id(_rf_src)][2]['icon'][0]
|
||||||
ssid = user_settings[int_id(_rf_src)][1]['ssid']
|
icon_icon = user_settings[int_id(_rf_src)][2]['icon'][1]
|
||||||
if user_settings[int_id(_rf_src)][3]['comment'] != '':
|
if user_settings[int_id(_rf_src)][1]['ssid'] != '':
|
||||||
comment = user_settings[int_id(_rf_src)][3]['comment']
|
ssid = user_settings[int_id(_rf_src)][1]['ssid']
|
||||||
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + icon_table + str(loc.lon[0:8]) + str(loc.lon_dir) + icon_icon + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + str(comment)
|
if user_settings[int_id(_rf_src)][3]['comment'] != '':
|
||||||
|
comment = user_settings[int_id(_rf_src)][3]['comment']
|
||||||
|
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + icon_table + str(loc.lon[0:8]) + str(loc.lon_dir) + icon_icon + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + str(comment)
|
||||||
logger.info(aprs_loc_packet)
|
logger.info(aprs_loc_packet)
|
||||||
logger.info('User comment: ' + comment)
|
logger.info('User comment: ' + comment)
|
||||||
logger.info('User SSID: ' + ssid)
|
logger.info('User SSID: ' + ssid)
|
||||||
logger.info('User icon: ' + icon_table + icon_icon)
|
logger.info('User icon: ' + icon_table + icon_icon)
|
||||||
f.close()
|
## f.close()
|
||||||
except:
|
except:
|
||||||
logger.info('Error or user settings file not found, proceeding with default settings.')
|
logger.info('Error or user settings file not found, proceeding with default settings.')
|
||||||
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + '/' + str(loc.lon[0:8]) + str(loc.lon_dir) + '[' + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
aprs_loc_packet = str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + str(user_ssid) + '>APRS,TCPIP*:/' + str(datetime.datetime.utcnow().strftime("%H%M%Sh")) + str(loc.lat[0:7]) + str(loc.lat_dir) + '/' + str(loc.lon[0:8]) + str(loc.lon_dir) + '[' + str(round(loc.true_course)).zfill(3) + '/' + str(round(loc.spd_over_grnd)).zfill(3) + '/' + aprs_comment + ' DMR ID: ' + str(int_id(_rf_src))
|
||||||
@ -270,11 +285,7 @@ class DATA_SYSTEM(HBSYSTEM):
|
|||||||
# Float values of lat and lon. Anything that is not a number will cause it to fail.
|
# Float values of lat and lon. Anything that is not a number will cause it to fail.
|
||||||
float(loc.lat)
|
float(loc.lat)
|
||||||
float(loc.lon)
|
float(loc.lon)
|
||||||
AIS = aprslib.IS(aprs_callsign, passwd=aprs_passcode,host=aprs_server, port=aprs_port)
|
aprs_send(aprs_loc_packet)
|
||||||
AIS.connect()
|
|
||||||
AIS.sendall(aprs_loc_packet)
|
|
||||||
AIS.close()
|
|
||||||
logger.info('Sent APRS packet')
|
|
||||||
except:
|
except:
|
||||||
logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.')
|
logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.')
|
||||||
# Get callsign based on DMR ID
|
# Get callsign based on DMR ID
|
||||||
@ -289,7 +300,7 @@ class DATA_SYSTEM(HBSYSTEM):
|
|||||||
process_sms(_rf_src, sms)
|
process_sms(_rf_src, sms)
|
||||||
packet_assembly = ''
|
packet_assembly = ''
|
||||||
else:
|
else:
|
||||||
logger.info('Unknown tpye SMS')
|
logger.info('Unknown type SMS')
|
||||||
logger.info(final_packet)
|
logger.info(final_packet)
|
||||||
packet_assembly = ''
|
packet_assembly = ''
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user