From 53af74f75702905d5d4e03bb38c69b6e9dbd92eb Mon Sep 17 00:00:00 2001 From: dj2ls Date: Sun, 17 Apr 2022 22:16:13 +0200 Subject: [PATCH] first test with 6bit callsign encoding seems to work, but we have to redesign the way how we handle callsigns. This is really confusing... --- gui/package.json | 1 - tnc/data_handler.py | 29 ++++++++++++------------ tnc/helpers.py | 55 ++++++++++++++++++++++++++++++++++++--------- tnc/static.py | 4 ++-- 4 files changed, 61 insertions(+), 28 deletions(-) diff --git a/gui/package.json b/gui/package.json index c9c5f7d8..dabb31d3 100644 --- a/gui/package.json +++ b/gui/package.json @@ -39,7 +39,6 @@ "emoji-picker-element": "^1.11.3", "emoji-picker-element-data": "^1.3.0", "mime": "^3.0.0", - "npm-check-updates": "^12.5.9", "pouchdb": "^7.3.0", "pouchdb-find": "^7.3.0", "qth-locator": "^2.1.0", diff --git a/tnc/data_handler.py b/tnc/data_handler.py index daebbf74..437269cc 100644 --- a/tnc/data_handler.py +++ b/tnc/data_handler.py @@ -1037,7 +1037,7 @@ class DATA(): connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - connection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) + connection_frame[5:11] = helpers.callsign_to_bytes(self.mycallsign) while not static.ARQ_SESSION: @@ -1085,7 +1085,7 @@ class DATA(): self.arq_session_last_received = int(time.time()) static.DXCALLSIGN_CRC = bytes(data_in[3:5]) - static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) + static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:11])) helpers.add_to_heard_stations(static.DXCALLSIGN,static.DXGRID, 'DATA-CHANNEL', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) structlog.get_logger("structlog").info("SESSION [" + str(self.mycallsign, 'utf-8') + "]>>|<<[" + str(static.DXCALLSIGN, 'utf-8') + "]", state=static.ARQ_SESSION_STATE) @@ -1111,7 +1111,7 @@ class DATA(): disconnection_frame[:1] = frametype disconnection_frame[1:3] = static.DXCALLSIGN_CRC disconnection_frame[3:5] = static.MYCALLSIGN_CRC - disconnection_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) + disconnection_frame[5:11] = helpers.callsign_to_bytes(self.mycallsign) txbuffer = [disconnection_frame] static.TRANSMITTING = True @@ -1259,14 +1259,14 @@ class DATA(): connection_frame[:1] = frametype connection_frame[1:3] = static.DXCALLSIGN_CRC connection_frame[3:5] = static.MYCALLSIGN_CRC - connection_frame[5:13] = helpers.callsign_to_bytes(mycallsign) + connection_frame[5:11] = helpers.callsign_to_bytes(mycallsign) connection_frame[13:14] = bytes([n_frames_per_burst]) while not static.ARQ_STATE: time.sleep(0.01) for attempt in range(1,self.data_channel_max_retries+1): static.INFO.append("DATACHANNEL;OPENING") - structlog.get_logger("structlog").info("[TNC] ARQ | DATA | TX | [" + str(helpers.callsign_to_bytes(mycallsign), 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "]", attempt=str(attempt) + "/" + str(self.data_channel_max_retries)) + structlog.get_logger("structlog").info("[TNC] ARQ | DATA | TX | [" + str(mycallsign, 'utf-8') + "]>> <<[" + str(static.DXCALLSIGN, 'utf-8') + "]", attempt=str(attempt) + "/" + str(self.data_channel_max_retries)) txbuffer = [connection_frame] static.TRANSMITTING = True modem.MODEM_TRANSMIT_QUEUE.put([14,1,0,txbuffer]) @@ -1315,7 +1315,7 @@ class DATA(): self.is_IRS = True static.INFO.append("DATACHANNEL;RECEIVEDOPENER") static.DXCALLSIGN_CRC = bytes(data_in[3:5]) - static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) + static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:11])) n_frames_per_burst = int.from_bytes(bytes(data_in[13:14]), "big") frametype = int.from_bytes(bytes(data_in[:1]), "big") @@ -1448,7 +1448,7 @@ class DATA(): ping_frame[:1] = bytes([210]) ping_frame[1:3] = static.DXCALLSIGN_CRC ping_frame[3:5] = static.MYCALLSIGN_CRC - ping_frame[5:13] = helpers.callsign_to_bytes(self.mycallsign) + ping_frame[5:11] = helpers.callsign_to_bytes(self.mycallsign) txbuffer = [ping_frame] static.TRANSMITTING = True @@ -1473,7 +1473,7 @@ class DATA(): """ static.DXCALLSIGN_CRC = bytes(data_in[3:5]) - static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:13])) + static.DXCALLSIGN = helpers.bytes_to_callsign(bytes(data_in[5:11])) helpers.add_to_heard_stations(static.DXCALLSIGN, static.DXGRID, 'PING', static.SNR, static.FREQ_OFFSET, static.HAMLIB_FREQUENCY) static.INFO.append("PING;RECEIVING") @@ -1582,7 +1582,7 @@ class DATA(): beacon_frame = bytearray(14) beacon_frame[:1] = bytes([250]) - beacon_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) + beacon_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) beacon_frame[9:13] = static.MYGRID[:4] txbuffer = [beacon_frame] @@ -1615,7 +1615,7 @@ class DATA(): """ # 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:7])) dxgrid = bytes(data_in[9:13]).rstrip(b'\x00') jsondata = {"type" : "beacon", "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)} @@ -1636,7 +1636,7 @@ class DATA(): cq_frame = bytearray(14) cq_frame[:1] = bytes([200]) - cq_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) + cq_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) cq_frame[9:13] = static.MYGRID[:4] txbuffer = [cq_frame] @@ -1663,7 +1663,8 @@ class DATA(): """ # 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:7])) + print(dxcallsign) dxgrid = bytes(data_in[9:13]).rstrip(b'\x00') static.INFO.append("CQ;RECEIVING") structlog.get_logger("structlog").info("[TNC] CQ RCVD [" + str(dxcallsign, 'utf-8') + "]["+ str(dxgrid, 'utf-8') +"] ", snr=static.SNR) @@ -1692,7 +1693,7 @@ class DATA(): qrv_frame = bytearray(14) qrv_frame[:1] = bytes([201]) - qrv_frame[1:9] = helpers.callsign_to_bytes(self.mycallsign) + qrv_frame[1:7] = helpers.callsign_to_bytes(self.mycallsign) qrv_frame[9:13] = static.MYGRID[:4] txbuffer = [qrv_frame] @@ -1718,7 +1719,7 @@ class DATA(): """ # 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:7])) 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)} diff --git a/tnc/helpers.py b/tnc/helpers.py index 2d0f0c9a..e78023e3 100644 --- a/tnc/helpers.py +++ b/tnc/helpers.py @@ -66,6 +66,28 @@ def get_crc_16(data): crc_data = crc_data.to_bytes(2, byteorder='big') return crc_data +def get_crc_24(data): + """Author: DJ2LS + + Get the CRC24-OPENPGP of a byte string + https://github.com/GardenTools/CrcEngine#examples + + param: data = bytes() + + Args: + data: + + Returns: + + """ + crc_algorithm = crcengine.create(0x864cfb, 24, 0xb704ce, ref_in=False, + ref_out=False, xor_out=0, + name='crc-24-openpgp') + crc_data = crc_algorithm(data) + crc_data = crc_data.to_bytes(3, byteorder='big') + return crc_data + + def get_crc_32(data): """Author: DJ2LS @@ -163,21 +185,28 @@ def callsign_to_bytes(callsign): except: ssid = 0 - callsign = callsign[0] - - bytestring = bytearray(8) - bytestring[:len(callsign)] = callsign - bytestring[7:8] = bytes([ssid]) + #callsign = callsign[0] + #bytestring = bytearray(8) + #bytestring[:len(callsign)] = callsign + #bytestring[7:8] = bytes([ssid]) - return bytes(bytestring) + # ---- callsign with encoding always 6 bytes long + callsign = callsign[0].decode("utf-8") + ssid = bytes([ssid]).decode("utf-8") + return encode_call(callsign + ssid) + + + #return bytes(bytestring) def bytes_to_callsign(bytestring): """ + Convert our callsign, received by a frame to a callsign in a human readable format Args: bytestring: Returns: + bytes """ @@ -200,7 +229,7 @@ def bytes_to_callsign(bytestring): #-15 generic additional station, digi, mobile, wx, etc # we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign ) - + ''' callsign = bytes(bytestring[:7]) callsign = callsign.rstrip(b'\x00') ssid = int.from_bytes(bytes(bytestring[7:8]), "big") @@ -211,7 +240,11 @@ def bytes_to_callsign(bytestring): callsign = callsign.encode('utf-8') return bytes(callsign) - + ''' + decoded = decode_call(bytestring) + callsign = decoded[:-1] + ssid = ord(bytes(decoded[-1], "utf-8")) + return bytes(callsign + "-" + str(ssid), "utf-8") @@ -227,8 +260,7 @@ def check_callsign(callsign:bytes, crc_to_check:bytes): [True, Callsign + SSID] False """ - - crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc16 library + try: callsign = callsign.split(b'-') @@ -328,7 +360,7 @@ def encode_call(call): out_code_word = int(0) call = call.upper() # upper case to be save - + for x in call: int_val = ord(x)-48 # -48 reduce bits, begin with first number utf8 table out_code_word = out_code_word << 6 # shift left 6 bit, making space for a new char @@ -355,6 +387,7 @@ def decode_call(b_code_word:bytes): while code_word != 0: call = chr((code_word & 0b111111)+48) + call code_word = code_word >> 6 + call = call[0:-1] + ssid # remove the last char from call and replace with SSID return call diff --git a/tnc/static.py b/tnc/static.py index 1402fc7a..05ca3f61 100644 --- a/tnc/static.py +++ b/tnc/static.py @@ -8,7 +8,7 @@ Here we are saving application wide variables and stats, which have to be access Not nice, suggestions are appreciated :-) """ -VERSION = '0.3.4-alpha' +VERSION = '0.4.0-alpha' # DAEMON DAEMONPORT = 3001 @@ -83,7 +83,7 @@ ENABLE_FFT = False CHANNEL_BUSY = None # ARQ PROTOCOL VERSION -ARQ_PROTOCOL_VERSION = 0 +ARQ_PROTOCOL_VERSION = 1 # ARQ statistics ARQ_BYTES_PER_MINUTE_BURST = 0