mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
first test run with saving data from tnc
This commit is contained in:
parent
af851d15f3
commit
76f24f2b31
|
@ -7,6 +7,7 @@ Created on Sun Dec 27 20:43:40 2020
|
|||
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
|
||||
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
|
||||
|
||||
import os
|
||||
import base64
|
||||
import sys
|
||||
import threading
|
||||
|
@ -865,13 +866,33 @@ class DATA:
|
|||
self.log.error(
|
||||
"[TNC] ARQ | RX | error occurred when saving data!",
|
||||
e=e,
|
||||
uuid = self.transmission_uuid,
|
||||
timestamp = timestamp,
|
||||
dxcall = static.DXCALLSIGN,
|
||||
dxgrid = static.DXGRID,
|
||||
data = base64_data
|
||||
uuid=self.transmission_uuid,
|
||||
timestamp=timestamp,
|
||||
dxcall=static.DXCALLSIGN,
|
||||
dxgrid=static.DXGRID,
|
||||
data=base64_data
|
||||
)
|
||||
|
||||
if static.ARQ_SAVE_TO_FOLDER:
|
||||
try:
|
||||
self.save_data_to_folder(
|
||||
self.transmission_uuid,
|
||||
timestamp,
|
||||
mycallsign,
|
||||
static.DXCALLSIGN,
|
||||
static.DXGRID,
|
||||
data_frame
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.error(
|
||||
"[TNC] ARQ | RX | can't save file to folder",
|
||||
e=e,
|
||||
uuid=self.transmission_uuid,
|
||||
timestamp=timestamp,
|
||||
dxcall=static.DXCALLSIGN,
|
||||
dxgrid=static.DXGRID,
|
||||
data=base64_data
|
||||
)
|
||||
self.send_data_to_socket_queue(
|
||||
freedata="tnc-message",
|
||||
arq="transmission",
|
||||
|
@ -3049,3 +3070,48 @@ class DATA:
|
|||
self.enqueue_frame_for_tx(
|
||||
frame_to_tx=[bytearray(126)], c2_mode=FREEDV_MODE.datac3.value
|
||||
)
|
||||
|
||||
def save_data_to_folder(self,
|
||||
transmission_uuid,
|
||||
timestamp,
|
||||
mycallsign,
|
||||
dxcallsign,
|
||||
dxgrid,
|
||||
data_frame
|
||||
):
|
||||
|
||||
"""Save data to folder"""
|
||||
|
||||
split_char = b"\x00;"
|
||||
|
||||
self.log.info("[TNC] ARQ | RX | saving data to folder")
|
||||
|
||||
decoded_data = data_frame.split(split_char)
|
||||
print(decoded_data)
|
||||
#uuid=decoded_data[3]
|
||||
message = decoded_data[4]
|
||||
filename = decoded_data[5]
|
||||
#filetype = decoded_data[6]
|
||||
data = decoded_data[7]
|
||||
|
||||
try:
|
||||
folder_path = "received"
|
||||
if not os.path.exists(folder_path):
|
||||
os.makedirs(folder_path)
|
||||
|
||||
callsign_path = f"{mycallsign}_{dxcallsign}"
|
||||
if not os.path.exists(f"{folder_path}/{callsign_path}"):
|
||||
os.makedirs(f"{folder_path}/{callsign_path}")
|
||||
|
||||
# save file to folder
|
||||
filename_complex = f"{timestamp}_{transmission_uuid}_{filename}"
|
||||
with open(f"{folder_path}/{callsign_path}/{filename_complex}", "wb") as file:
|
||||
file.write(data)
|
||||
|
||||
# save message to folder
|
||||
message_name = f"{timestamp}_{transmission_uuid}_msg.txt"
|
||||
with open(f"{folder_path}/{callsign_path}/{message_name}", "wb") as file:
|
||||
file.write(message)
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
14
tnc/main.py
14
tnc/main.py
|
@ -70,6 +70,15 @@ if __name__ == "__main__":
|
|||
type=str,
|
||||
help="Use the default config file config.ini",
|
||||
)
|
||||
|
||||
PARSER.add_argument(
|
||||
"--save-to-folder",
|
||||
dest="savetofolder",
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="Save received data to local folder",
|
||||
)
|
||||
|
||||
PARSER.add_argument(
|
||||
"--mycall",
|
||||
dest="mycall",
|
||||
|
@ -269,8 +278,9 @@ if __name__ == "__main__":
|
|||
)
|
||||
ARGS = PARSER.parse_args()
|
||||
|
||||
|
||||
|
||||
# set save to folder state for allowing downloading files to local file system
|
||||
static.ARQ_SAVE_TO_FOLDER = ARGS.savetofolder
|
||||
|
||||
if not ARGS.configfile:
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Not nice, suggestions are appreciated :-)
|
|||
import subprocess
|
||||
from enum import Enum
|
||||
|
||||
VERSION = "0.6.8-alpha.1"
|
||||
VERSION = "0.6.9-alpha.1-exp"
|
||||
|
||||
ENABLE_EXPLORER = False
|
||||
|
||||
|
@ -101,6 +101,8 @@ ARQ_COMPRESSION_FACTOR: int = 0
|
|||
ARQ_TRANSMISSION_PERCENT: int = 0
|
||||
ARQ_SPEED_LEVEL: int = 0
|
||||
TOTAL_BYTES: int = 0
|
||||
# set save to folder state for allowing downloading files to local file system
|
||||
ARQ_SAVE_TO_FOLDER: bool = False
|
||||
|
||||
# CHANNEL_STATE = 'RECEIVING_SIGNALLING'
|
||||
TNC_STATE: str = "IDLE"
|
||||
|
|
|
@ -35,6 +35,10 @@ ip, port = args.socket_host, args.socket_port
|
|||
connected = True
|
||||
data = bytes()
|
||||
|
||||
"""
|
||||
Nachricht
|
||||
{'command': 'rx_buffer', 'data-array': [{'uuid': '8dde227d-3a09-4f39-b34c-5f8281d719d1', 'timestamp': 1672043316, 'dxcallsign': 'DJ2LS-1', 'dxgrid': 'JN48cs', 'data': 'bQA7c2VuZF9tZXNzYWdlADsxMjMAO2VkY2NjZDAyLTUzMTQtNDc3Ni1hMjlkLTFmY2M1ZDI4OTM4ZAA7VGVzdAoAOwA7cGxhaW4vdGV4dAA7ADsxNjcyMDQzMzA5'}]}
|
||||
"""
|
||||
|
||||
def decode_and_save_data(encoded_data):
|
||||
decoded_data = base64.b64decode(encoded_data)
|
||||
|
@ -69,7 +73,7 @@ def decode_and_save_data(encoded_data):
|
|||
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
sock.connect((ip, port))
|
||||
|
||||
print(sock)
|
||||
while connected:
|
||||
chunk = sock.recv(1024)
|
||||
data += chunk
|
||||
|
@ -83,7 +87,6 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|||
for command in data:
|
||||
|
||||
jsondata = json.loads(command)
|
||||
data = bytes()
|
||||
|
||||
if jsondata.get('command') == "tnc_state":
|
||||
pass
|
||||
|
@ -105,7 +108,7 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|||
if jsondata.get('status') == 'received' and jsondata.get('arq') == 'transmission':
|
||||
decode_and_save_data(jsondata["data"])
|
||||
|
||||
# clear data buffer as soon as data has been read
|
||||
data = bytes()
|
||||
# clear data buffer as soon as data has been read
|
||||
data = bytes()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue