mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Merge pull request #169 from kronenpj/feature_#156
Proof of concept for automatic "can you hear me" response to CQ.
This commit is contained in:
commit
93c7e572bb
1 changed files with 72 additions and 6 deletions
|
@ -124,7 +124,7 @@ class DATA():
|
||||||
if data[0] == 'CQ':
|
if data[0] == 'CQ':
|
||||||
# [0] CQ
|
# [0] CQ
|
||||||
self.transmit_cq()
|
self.transmit_cq()
|
||||||
|
|
||||||
elif data[0] == 'STOP':
|
elif data[0] == 'STOP':
|
||||||
# [0] STOP
|
# [0] STOP
|
||||||
self.stop_transmission()
|
self.stop_transmission()
|
||||||
|
@ -208,7 +208,7 @@ class DATA():
|
||||||
#if bytes(bytes_out[1:3]) == self.mycallsign_CRC or bytes(bytes_out[2:4]) == self.mycallsign_CRC or frametype == 200 or frametype == 250:
|
#if bytes(bytes_out[1:3]) == self.mycallsign_CRC or bytes(bytes_out[2:4]) == self.mycallsign_CRC or frametype == 200 or frametype == 250:
|
||||||
_valid1, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[1:3]))
|
_valid1, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[1:3]))
|
||||||
_valid2, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[2:4]))
|
_valid2, _ = helpers.check_callsign(self.mycallsign, bytes(bytes_out[2:4]))
|
||||||
if _valid1 or _valid2 or frametype in [200, 210, 250]:
|
if _valid1 or _valid2 or frametype in [200, 201, 210, 250]:
|
||||||
|
|
||||||
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
|
# CHECK IF FRAMETYPE IS BETWEEN 10 and 50 ------------------------
|
||||||
frame = frametype - 10
|
frame = frametype - 10
|
||||||
|
@ -259,6 +259,12 @@ class DATA():
|
||||||
structlog.get_logger("structlog").debug("CQ RECEIVED....")
|
structlog.get_logger("structlog").debug("CQ RECEIVED....")
|
||||||
self.received_cq(bytes_out[:-2])
|
self.received_cq(bytes_out[:-2])
|
||||||
|
|
||||||
|
# QRV FRAME
|
||||||
|
elif frametype == 201:
|
||||||
|
structlog.get_logger("structlog").debug("QRV RECEIVED!")
|
||||||
|
self.received_qrv(bytes_out[:-2])
|
||||||
|
|
||||||
|
|
||||||
# PING FRAME
|
# PING FRAME
|
||||||
elif frametype == 210:
|
elif frametype == 210:
|
||||||
structlog.get_logger("structlog").debug("PING RECEIVED....")
|
structlog.get_logger("structlog").debug("PING RECEIVED....")
|
||||||
|
@ -1609,7 +1615,7 @@ class DATA():
|
||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# here we add the received station to the heard stations buffer
|
# here we add the received station to the heard stations buffer
|
||||||
dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:9]))
|
dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:9]))
|
||||||
dxgrid = bytes(data_in[9:13]).rstrip(b'\x00')
|
dxgrid = bytes(data_in[9:13]).rstrip(b'\x00')
|
||||||
|
|
||||||
|
@ -1622,7 +1628,6 @@ class DATA():
|
||||||
helpers.add_to_heard_stations(dxcallsign,dxgrid, 'BEACON', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY)
|
helpers.add_to_heard_stations(dxcallsign,dxgrid, 'BEACON', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def transmit_cq(self):
|
def transmit_cq(self):
|
||||||
"""
|
"""
|
||||||
Transmit a CQ
|
Transmit a CQ
|
||||||
|
@ -1640,9 +1645,9 @@ class DATA():
|
||||||
static.TRANSMITTING = True
|
static.TRANSMITTING = True
|
||||||
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
|
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
|
||||||
if static.ENABLE_FSK:
|
if static.ENABLE_FSK:
|
||||||
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',3,500,txbuffer])
|
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer])
|
||||||
else:
|
else:
|
||||||
modem.MODEM_TRANSMIT_QUEUE.put([14,3,500,txbuffer])
|
modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer])
|
||||||
# wait while transmitting
|
# wait while transmitting
|
||||||
while static.TRANSMITTING:
|
while static.TRANSMITTING:
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
@ -1665,6 +1670,67 @@ class DATA():
|
||||||
structlog.get_logger("structlog").info("[TNC] CQ RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR)
|
structlog.get_logger("structlog").info("[TNC] CQ RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR)
|
||||||
helpers.add_to_heard_stations(dxcallsign, dxgrid, 'CQ CQ CQ', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY)
|
helpers.add_to_heard_stations(dxcallsign, dxgrid, 'CQ CQ CQ', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY)
|
||||||
|
|
||||||
|
# TODO: Add configuration option to enable responding to CQ.
|
||||||
|
self.transmit_qrv()
|
||||||
|
|
||||||
|
|
||||||
|
def transmit_qrv(self):
|
||||||
|
"""
|
||||||
|
Called if we send a QRV frame
|
||||||
|
Args:
|
||||||
|
data_in:bytes:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Nothing
|
||||||
|
"""
|
||||||
|
# Sleep a random amount of time before responding to make it more likely to be
|
||||||
|
# heard when many stations respond. Each DATAC0 frame is 0.44 sec (440ms) in
|
||||||
|
# duration, plus overhead. Set the wait interval to be random between 0 and 2s
|
||||||
|
# in 0.5s increments.
|
||||||
|
helpers.wait(randrange(0, 20, 5) / 10.0)
|
||||||
|
static.INFO.append("QRV;SENDING")
|
||||||
|
structlog.get_logger("structlog").info("[TNC] Sending QRV!")
|
||||||
|
|
||||||
|
qrv_frame = bytearray(14)
|
||||||
|
qrv_frame[:1] = bytes([201])
|
||||||
|
qrv_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign)
|
||||||
|
qrv_frame[9:13] = static.MYGRID[:4]
|
||||||
|
txbuffer = [qrv_frame]
|
||||||
|
|
||||||
|
static.TRANSMITTING = True
|
||||||
|
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
|
||||||
|
if static.ENABLE_FSK:
|
||||||
|
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer])
|
||||||
|
else:
|
||||||
|
modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer])
|
||||||
|
|
||||||
|
# wait while transmitting
|
||||||
|
while static.TRANSMITTING:
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
def received_qrv(self, data_in:bytes):
|
||||||
|
"""
|
||||||
|
Called if we receive a QRV frame
|
||||||
|
Args:
|
||||||
|
data_in:bytes:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
|
# here we add the received station to the heard stations buffer
|
||||||
|
dxcallsign = helpers.bytes_to_callsign(bytes(data_in[1:9]))
|
||||||
|
dxgrid = bytes(data_in[9:13]).rstrip(b'\x00')
|
||||||
|
|
||||||
|
jsondata = {"type" : "qrv", "status" : "received", "uuid" : str(uuid.uuid4()), "timestamp": int(time.time()), "mycallsign" : str(self.mycallsign, 'utf-8'), "dxcallsign": str(dxcallsign, 'utf-8'), "dxgrid": str(dxgrid, 'utf-8'), "snr": str(static.SNR)}
|
||||||
|
json_data_out = json.dumps(jsondata)
|
||||||
|
sock.SOCKET_QUEUE.put(json_data_out)
|
||||||
|
|
||||||
|
static.INFO.append("QRV;RECEIVING")
|
||||||
|
structlog.get_logger("structlog").info("[TNC] QRV RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR)
|
||||||
|
helpers.add_to_heard_stations(dxcallsign,dxgrid, 'QRV', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY)
|
||||||
|
|
||||||
|
|
||||||
# ------------ CALUCLATE TRANSFER RATES
|
# ------------ CALUCLATE TRANSFER RATES
|
||||||
def calculate_transfer_rate_rx(self, rx_start_of_transmission:float, receivedbytes:int) -> list:
|
def calculate_transfer_rate_rx(self, rx_start_of_transmission:float, receivedbytes:int) -> list:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue