-
Notifications
You must be signed in to change notification settings - Fork 1
/
aprs_recv_loop.py
executable file
·84 lines (67 loc) · 3.36 KB
/
aprs_recv_loop.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python3
###############################################################################
# Copyright (C) 2020 Eric Craw, KF7EEL <kf7eel@qsl.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
# Interactive APRS script.
# This is a split from the shark-py-sms project to allow an APRS only setup.
# This is to accomodate users who do not use DMR but wish to still have an interactive
# messaging setup. This should work with any APRS compatable radio, even bridged DMR systems.
# https://github.com/kf7eel/shark-py-sms
# Feel free to modify and improve.
from core import *
import shutil
global AIS
def aprs_packet_receive_write(packet):
pak_str = packet.decode('utf-8',errors='ignore').strip()
# Parse packet into dictionary
parse_packet = aprslib.parse(pak_str)
if 'message' == parse_packet['format']:
if aprs_callsign == parse_packet['addresse'] and 'message_text' in parse_packet:
with open(packet_recv_folder + str(random.randint(1000, 9999)) + '.packet', "w") as packet_write_file:
print(pak_str)
packet_write_file.write(pak_str)
#os.system('mv ' + packet_write_file + ' ' + packet_process_folder)
#os.system('mv ' + packet_write_file + ' ' + packet_process_folder)
#shutil.move(packet_recv_folder + '*', packet_process_folder)
# Note to self, try mv in for loop, after you get off work
## try:
## os.system('mv ' + packet_recv_folder + '*.packet ' + packet_process_folder)
## except:
## print('excepted, no files?')
else:
print('Packet from: ' + parse_packet['from'] + ' Format: ' + parse_packet['format'] + ' - ' + time.strftime('%H:%M:%S'))
try:
for pckt in os.listdir(packet_recv_folder):
print(pckt)
#os.system('mv ' + packet_recv_folder + pckt + ' ' + packet_process_folder)
shutil.copyfile(packet_recv_folder + pckt, packet_process_folder + pckt)
os.remove(packet_recv_folder + pckt)
#print('packet moved')
except:
print('error with moving')
#shutil.move(packet_recv_folder + '*', packet_process_folder)
AIS = aprslib.IS(aprs_callsign, host=aprs_is_host, passwd=aprs_passcode, port=aprs_is_port)
Path(packet_recv_folder).mkdir(parents=True, exist_ok=True)
#AIS = aprslib.IS('N0CALL', host='rotate.aprs.net', passwd='-1', port=10152)
# Sends filter settings to APRS server
print(armds_intro)
AIS.set_filter(aprs_filter)
# Connect to APRS-IS
AIS.connect()
print('APRS-IS Packet Receiver')
print('Initializing... Waiting for packets.')
AIS.consumer(aprs_packet_receive_write, raw=True)