2022-12-09 21:48:29 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2022-12-19 13:54:29 +00:00
|
|
|
|
2022-12-09 21:48:29 +00:00
|
|
|
@author: DJ2LS
|
2022-12-19 13:54:29 +00:00
|
|
|
python3 send_file.py --file cleanup.sh --dxcallsign DN2LS-0 --mycallsign DN2LS-2 --attempts 3
|
2022-12-09 21:48:29 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import socket
|
|
|
|
import json
|
|
|
|
|
|
|
|
# --------------------------------------------GET PARAMETER INPUTS
|
|
|
|
parser = argparse.ArgumentParser(description='Simons TEST TNC')
|
|
|
|
parser.add_argument('--port', dest="socket_port", default=3000, help="Set socket listening port.", type=int)
|
|
|
|
parser.add_argument('--host', dest="socket_host", default='localhost', help="Set the host, the socket is listening on.", type=str)
|
2022-12-19 13:54:29 +00:00
|
|
|
parser.add_argument('--dxcallsign', dest="dxcallsign", default='AA0AA', help="Select the destination callsign", type=str)
|
|
|
|
parser.add_argument('--mycallsign', dest="mycallsign", default='AA0AA', help="Select the own callsign", type=str)
|
2022-12-19 14:06:30 +00:00
|
|
|
parser.add_argument('--ping', dest="ping", action="store_true", help="Send PING")
|
|
|
|
parser.add_argument('--cq', dest="cq", action="store_true", help="Send CQ")
|
2022-12-09 21:48:29 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
HOST, PORT = args.socket_host, args.socket_port
|
2022-12-19 13:54:29 +00:00
|
|
|
dxcallsign = args.dxcallsign
|
|
|
|
mycallsign = args.mycallsign
|
2022-12-09 21:48:29 +00:00
|
|
|
|
2022-12-19 13:54:29 +00:00
|
|
|
# our command we are going to send
|
2022-12-19 14:05:04 +00:00
|
|
|
if args.ping:
|
|
|
|
command = {"type": "ping",
|
|
|
|
"command": "ping",
|
|
|
|
"dxcallsign": dxcallsign,
|
|
|
|
"mycallsign": mycallsign,
|
|
|
|
}
|
|
|
|
if args.cq:
|
|
|
|
command = {"type": "broadcast",
|
|
|
|
"command": "cqcqcq",
|
|
|
|
"mycallsign": mycallsign,
|
|
|
|
}
|
2022-12-09 21:48:29 +00:00
|
|
|
command = json.dumps(command)
|
|
|
|
command = bytes(command + "\n", 'utf-8')
|
|
|
|
# Create a socket (SOCK_STREAM means a TCP socket)
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|
|
|
# Connect to server and send data
|
|
|
|
sock.connect((HOST, PORT))
|
|
|
|
sock.sendall(command)
|