2021-01-06 12:17:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Fri Dec 25 21:25:14 2020
|
|
|
|
|
|
|
|
@author: DJ2LS
|
|
|
|
"""
|
|
|
|
|
|
|
|
import time
|
2021-03-12 13:14:36 +00:00
|
|
|
import crcengine
|
2021-01-06 12:17:17 +00:00
|
|
|
import static
|
2022-01-05 13:15:59 +00:00
|
|
|
|
2021-01-06 12:17:17 +00:00
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2021-08-15 10:34:28 +00:00
|
|
|
def wait(seconds):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
seconds:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-08-14 18:00:32 +00:00
|
|
|
timeout = time.time() + seconds
|
2021-09-25 13:24:25 +00:00
|
|
|
|
2021-08-14 18:00:32 +00:00
|
|
|
while time.time() < timeout:
|
|
|
|
time.sleep(0.01)
|
2021-10-05 17:59:32 +00:00
|
|
|
return True
|
2022-04-11 09:10:32 +00:00
|
|
|
|
|
|
|
|
2021-02-10 18:43:59 +00:00
|
|
|
|
2021-01-06 12:17:17 +00:00
|
|
|
def get_crc_8(data):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""Author: DJ2LS
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
Get the CRC8 of a byte string
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
param: data = bytes()
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
data:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
"""
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_algorithm = crcengine.new('crc8-ccitt') # load crc8 library
|
2021-01-06 12:17:17 +00:00
|
|
|
crc_data = crc_algorithm(data)
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_data = crc_data.to_bytes(1, byteorder='big')
|
2021-01-06 12:17:17 +00:00
|
|
|
return crc_data
|
|
|
|
|
2021-03-12 13:14:36 +00:00
|
|
|
|
2021-01-06 12:17:17 +00:00
|
|
|
def get_crc_16(data):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""Author: DJ2LS
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
Get the CRC16 of a byte string
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
param: data = bytes()
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
data:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
2021-03-12 13:39:36 +00:00
|
|
|
"""
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc16 library
|
2021-01-06 12:17:17 +00:00
|
|
|
crc_data = crc_algorithm(data)
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_data = crc_data.to_bytes(2, byteorder='big')
|
2021-03-12 13:14:36 +00:00
|
|
|
return crc_data
|
|
|
|
|
2022-04-17 20:16:13 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-01-24 18:42:59 +00:00
|
|
|
def get_crc_32(data):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""Author: DJ2LS
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-01-24 18:42:59 +00:00
|
|
|
Get the CRC32 of a byte string
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-01-24 18:42:59 +00:00
|
|
|
param: data = bytes()
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
data:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
2022-01-24 18:42:59 +00:00
|
|
|
"""
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_algorithm = crcengine.new('crc32') # load crc16 library
|
2022-01-24 18:42:59 +00:00
|
|
|
crc_data = crc_algorithm(data)
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_data = crc_data.to_bytes(4, byteorder='big')
|
2022-01-24 18:42:59 +00:00
|
|
|
return crc_data
|
2021-03-12 15:18:41 +00:00
|
|
|
|
2021-09-25 13:24:25 +00:00
|
|
|
|
2021-10-24 12:44:55 +00:00
|
|
|
def add_to_heard_stations(dxcallsign, dxgrid, datatype, snr, offset, frequency):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
dxcallsign:
|
|
|
|
dxgrid:
|
|
|
|
datatype:
|
|
|
|
snr:
|
|
|
|
offset:
|
|
|
|
frequency:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-02-21 11:20:36 +00:00
|
|
|
|
2021-03-16 14:21:58 +00:00
|
|
|
# check if buffer empty
|
|
|
|
if len(static.HEARD_STATIONS) == 0:
|
2022-04-11 09:10:32 +00:00
|
|
|
static.HEARD_STATIONS.append([dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency])
|
2021-03-16 14:21:58 +00:00
|
|
|
# if not, we search and update
|
|
|
|
else:
|
|
|
|
for i in range(0, len(static.HEARD_STATIONS)):
|
|
|
|
# update callsign with new timestamp
|
|
|
|
if static.HEARD_STATIONS[i].count(dxcallsign) > 0:
|
2022-04-11 09:10:32 +00:00
|
|
|
static.HEARD_STATIONS[i] = [dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency]
|
2021-03-16 14:21:58 +00:00
|
|
|
break
|
|
|
|
# insert if nothing found
|
|
|
|
if i == len(static.HEARD_STATIONS) - 1:
|
2022-04-11 09:10:32 +00:00
|
|
|
static.HEARD_STATIONS.append([dxcallsign, dxgrid, int(time.time()), datatype, snr, offset, frequency])
|
2021-03-16 14:21:58 +00:00
|
|
|
break
|
2021-09-25 13:24:25 +00:00
|
|
|
|
|
|
|
|
2021-03-16 14:21:58 +00:00
|
|
|
# for idx, item in enumerate(static.HEARD_STATIONS):
|
|
|
|
# if dxcallsign in item:
|
|
|
|
# item = [dxcallsign, int(time.time())]
|
2021-09-25 13:24:25 +00:00
|
|
|
# static.HEARD_STATIONS[idx] = item
|
|
|
|
|
2022-02-21 11:20:36 +00:00
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-02-21 11:20:36 +00:00
|
|
|
def callsign_to_bytes(callsign):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
callsign:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-02-21 11:20:36 +00:00
|
|
|
# http://www.aprs.org/aprs11/SSIDs.txt
|
2022-04-11 09:10:32 +00:00
|
|
|
#-0 Your primary station usually fixed and message capable
|
|
|
|
#-1 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-2 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-3 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-4 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-5 Other networks (Dstar, Iphones, Androids, Blackberry's etc)
|
|
|
|
#-6 Special activity, Satellite ops, camping or 6 meters, etc
|
|
|
|
#-7 walkie talkies, HT's or other human portable
|
|
|
|
#-8 boats, sailboats, RV's or second main mobile
|
|
|
|
#-9 Primary Mobile (usually message capable)
|
|
|
|
#-10 internet, Igates, echolink, winlink, AVRS, APRN, etc
|
|
|
|
#-11 balloons, aircraft, spacecraft, etc
|
|
|
|
#-12 APRStt, DTMF, RFID, devices, one-way trackers*, etc
|
|
|
|
#-13 Weather stations
|
|
|
|
#-14 Truckers or generally full time drivers
|
|
|
|
#-15 generic additional station, digi, mobile, wx, etc
|
|
|
|
|
2022-02-21 11:20:36 +00:00
|
|
|
# try converting to bytestring if possible type string
|
2022-04-11 09:10:32 +00:00
|
|
|
try:
|
|
|
|
callsign = bytes(callsign, 'utf-8')
|
2022-02-21 11:20:36 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
# we need to do this step to reduce the needed paypload by the callsign ( stripping "-" out of the callsign )
|
|
|
|
callsign = callsign.split(b'-')
|
2022-02-21 11:20:36 +00:00
|
|
|
try:
|
|
|
|
ssid = int(callsign[1])
|
|
|
|
except:
|
|
|
|
ssid = 0
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-04-17 20:16:13 +00:00
|
|
|
#callsign = callsign[0]
|
|
|
|
#bytestring = bytearray(8)
|
|
|
|
#bytestring[:len(callsign)] = callsign
|
|
|
|
#bytestring[7:8] = bytes([ssid])
|
|
|
|
|
|
|
|
# ---- callsign with encoding always 6 bytes long
|
|
|
|
callsign = callsign[0].decode("utf-8")
|
|
|
|
ssid = bytes([ssid]).decode("utf-8")
|
|
|
|
return encode_call(callsign + ssid)
|
2022-02-21 11:20:36 +00:00
|
|
|
|
2022-04-17 20:16:13 +00:00
|
|
|
|
|
|
|
#return bytes(bytestring)
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-02-21 11:20:36 +00:00
|
|
|
def bytes_to_callsign(bytestring):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
2022-04-17 20:16:13 +00:00
|
|
|
Convert our callsign, received by a frame to a callsign in a human readable format
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Args:
|
2022-04-11 09:10:32 +00:00
|
|
|
bytestring:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
2022-04-17 20:16:13 +00:00
|
|
|
bytes
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
"""
|
2022-02-21 11:20:36 +00:00
|
|
|
|
|
|
|
# http://www.aprs.org/aprs11/SSIDs.txt
|
2022-04-11 09:10:32 +00:00
|
|
|
#-0 Your primary station usually fixed and message capable
|
|
|
|
#-1 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-2 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-3 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-4 generic additional station, digi, mobile, wx, etc
|
|
|
|
#-5 Other networks (Dstar, Iphones, Androids, Blackberry's etc)
|
|
|
|
#-6 Special activity, Satellite ops, camping or 6 meters, etc
|
|
|
|
#-7 walkie talkies, HT's or other human portable
|
|
|
|
#-8 boats, sailboats, RV's or second main mobile
|
|
|
|
#-9 Primary Mobile (usually message capable)
|
|
|
|
#-10 internet, Igates, echolink, winlink, AVRS, APRN, etc
|
|
|
|
#-11 balloons, aircraft, spacecraft, etc
|
|
|
|
#-12 APRStt, DTMF, RFID, devices, one-way trackers*, etc
|
|
|
|
#-13 Weather stations
|
|
|
|
#-14 Truckers or generally full time drivers
|
|
|
|
#-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 )
|
2022-04-17 20:16:13 +00:00
|
|
|
'''
|
2022-02-21 11:20:36 +00:00
|
|
|
callsign = bytes(bytestring[:7])
|
2022-04-11 09:10:32 +00:00
|
|
|
callsign = callsign.rstrip(b'\x00')
|
2022-02-21 11:20:36 +00:00
|
|
|
ssid = int.from_bytes(bytes(bytestring[7:8]), "big")
|
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
callsign = callsign + b'-'
|
|
|
|
callsign = callsign.decode('utf-8')
|
2022-02-21 11:20:36 +00:00
|
|
|
callsign = callsign + str(ssid)
|
2022-04-11 09:10:32 +00:00
|
|
|
callsign = callsign.encode('utf-8')
|
|
|
|
|
|
|
|
return bytes(callsign)
|
2022-04-17 20:16:13 +00:00
|
|
|
'''
|
|
|
|
decoded = decode_call(bytestring)
|
|
|
|
callsign = decoded[:-1]
|
|
|
|
ssid = ord(bytes(decoded[-1], "utf-8"))
|
|
|
|
return bytes(callsign + "-" + str(ssid), "utf-8")
|
2022-03-19 11:42:10 +00:00
|
|
|
|
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
|
|
|
|
def check_callsign(callsign:bytes, crc_to_check:bytes):
|
2022-03-19 11:42:10 +00:00
|
|
|
"""
|
|
|
|
Funktion to check a crc against a callsign to calculate the ssid by generating crc until we got it
|
|
|
|
|
|
|
|
Args:
|
|
|
|
callsign: Callsign which we want to check
|
2022-04-11 09:10:32 +00:00
|
|
|
crc_to_check: The CRC which we want the callsign to check against
|
2022-03-19 11:42:10 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
[True, Callsign + SSID]
|
|
|
|
False
|
|
|
|
"""
|
2022-04-17 20:16:13 +00:00
|
|
|
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-03-19 11:42:10 +00:00
|
|
|
try:
|
2022-04-11 09:10:32 +00:00
|
|
|
callsign = callsign.split(b'-')
|
|
|
|
callsign = callsign[0] # we want the callsign without SSID
|
|
|
|
|
2022-03-19 11:42:10 +00:00
|
|
|
except:
|
|
|
|
callsign = callsign
|
2022-04-16 14:28:04 +00:00
|
|
|
|
2022-03-19 11:42:10 +00:00
|
|
|
for ssid in static.SSID_LIST:
|
2022-04-11 09:10:32 +00:00
|
|
|
#for ssid in range(0,254):
|
|
|
|
call_with_ssid = bytearray(callsign)
|
|
|
|
call_with_ssid.extend('-'.encode('utf-8'))
|
|
|
|
call_with_ssid.extend(str(ssid).encode('utf-8'))
|
2022-03-19 11:42:10 +00:00
|
|
|
|
|
|
|
callsign_crc = get_crc_16(call_with_ssid)
|
|
|
|
|
|
|
|
if callsign_crc == crc_to_check:
|
|
|
|
print(call_with_ssid)
|
|
|
|
return [True, bytes(call_with_ssid)]
|
2022-04-11 09:10:32 +00:00
|
|
|
|
2022-04-10 20:45:05 +00:00
|
|
|
return [False, ""]
|
2022-04-14 06:44:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def encode_grid(grid):
|
|
|
|
"""
|
2022-04-14 08:26:48 +00:00
|
|
|
@auther: DB1UJ
|
2022-04-14 06:44:09 +00:00
|
|
|
Args:
|
|
|
|
grid:string: maidenhead QTH locater [a-r][a-r][0-9][0-9][a-x][a-x]
|
|
|
|
Returns:
|
|
|
|
4 bytes contains 26 bit valid data with encoded grid locator
|
|
|
|
"""
|
|
|
|
out_code_word = int(0)
|
|
|
|
|
|
|
|
grid = grid.upper() # upper case to be save
|
|
|
|
|
|
|
|
int_first = ord(grid[0])-65 # -65 offset for 'A' become zero, utf8 table
|
|
|
|
int_sec = ord(grid[1])-65 # -65 offset for 'A' become zero, utf8 table
|
|
|
|
|
2022-04-14 08:26:48 +00:00
|
|
|
int_val = (int_first * 18) + int_sec # encode for modulo devision, 2 numbers in 1
|
2022-04-14 06:44:09 +00:00
|
|
|
|
|
|
|
out_code_word = (int_val & 0b111111111) # only 9 bit LSB A - R * A - R is needed
|
|
|
|
out_code_word = out_code_word << 9 # shift 9 bit left having space next bits, letter A-R * A-R
|
|
|
|
|
|
|
|
int_val = int(grid[2:4]) # number string to number int, highest value 99
|
|
|
|
out_code_word = out_code_word | (int_val & 0b1111111) # using bit OR to add new value
|
|
|
|
out_code_word = out_code_word << 7 # shift 7 bit left having space next bits, letter A-X
|
|
|
|
|
|
|
|
int_val = ord(grid[4])-65 # -65 offset for 'A' become zero, utf8 table
|
|
|
|
out_code_word = out_code_word | (int_val & 0b11111) # using bit OR to add new value
|
|
|
|
out_code_word = out_code_word << 5 # shift 5 bit left having space next bits, letter A-X
|
|
|
|
|
|
|
|
int_val = ord(grid[5])-65 # -65 offset for 'A' become zero, utf8 table
|
|
|
|
out_code_word = out_code_word | (int_val & 0b11111) # using bit OR to add new value
|
|
|
|
|
|
|
|
return out_code_word.to_bytes(length=4, byteorder='big')
|
|
|
|
|
|
|
|
def decode_grid(b_code_word:bytes):
|
|
|
|
"""
|
2022-04-14 08:26:48 +00:00
|
|
|
@auther: DB1UJ
|
2022-04-14 06:44:09 +00:00
|
|
|
Args:
|
|
|
|
b_code_word:bytes: 4 bytes with 26 bit valid data LSB
|
|
|
|
Returns:
|
|
|
|
grid:str: upper case maidenhead QTH locater [A-R][A-R][0-9][0-9][A-X][A-X]
|
|
|
|
"""
|
|
|
|
code_word = int.from_bytes(b_code_word, byteorder='big', signed=False)
|
|
|
|
|
|
|
|
grid = chr((code_word & 0b11111) + 65)
|
|
|
|
code_word = code_word >> 5
|
|
|
|
|
|
|
|
grid = chr((code_word & 0b11111) + 65) + grid
|
|
|
|
code_word = code_word >> 7
|
|
|
|
|
|
|
|
grid = str(int(code_word & 0b1111111)) + grid
|
|
|
|
if (code_word & 0b1111111) < 10:
|
|
|
|
grid = '0' + grid
|
|
|
|
code_word = code_word >> 9
|
|
|
|
|
|
|
|
int_val = int(code_word & 0b111111111)
|
|
|
|
int_first = int_val // 18
|
|
|
|
int_sec = int_val % 18
|
|
|
|
grid = chr(int(int_first)+65) + chr(int(int_sec)+65) + grid
|
|
|
|
|
|
|
|
return grid
|
2022-04-14 10:41:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-04-14 13:27:03 +00:00
|
|
|
def encode_call(call):
|
2022-04-14 10:41:58 +00:00
|
|
|
"""
|
2022-04-14 13:27:03 +00:00
|
|
|
@auther: DB1UJ
|
2022-04-14 10:41:58 +00:00
|
|
|
Args:
|
2022-04-14 13:27:03 +00:00
|
|
|
call:string: ham radio call sign [A-Z,0-9], last char SSID 0-63
|
2022-04-14 10:41:58 +00:00
|
|
|
|
|
|
|
Returns:
|
2022-04-14 13:27:03 +00:00
|
|
|
6 bytes contains 6 bits/sign encoded 8 char call sign with binary SSID (only upper letters + numbers, SSID)
|
2022-04-14 10:41:58 +00:00
|
|
|
"""
|
|
|
|
out_code_word = int(0)
|
|
|
|
|
|
|
|
call = call.upper() # upper case to be save
|
2022-04-17 20:16:13 +00:00
|
|
|
|
2022-04-14 10:41:58 +00:00
|
|
|
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
|
|
|
|
out_code_word = out_code_word | (int_val & 0b111111) # bit OR adds the new char, masked with AND 0b111111
|
2022-04-14 13:27:03 +00:00
|
|
|
out_code_word = out_code_word >> 6 # clean last char
|
|
|
|
out_code_word = out_code_word << 6 # make clean space
|
|
|
|
out_code_word = out_code_word | (ord(call[-1]) & 0b111111) # add the SSID uncoded only 0 - 63
|
2022-04-14 10:41:58 +00:00
|
|
|
|
2022-04-14 13:27:03 +00:00
|
|
|
return out_code_word.to_bytes(length=6, byteorder='big')
|
2022-04-14 10:41:58 +00:00
|
|
|
|
|
|
|
def decode_call(b_code_word:bytes):
|
|
|
|
"""
|
2022-04-14 13:27:03 +00:00
|
|
|
@auther: DB1UJ
|
2022-04-14 10:41:58 +00:00
|
|
|
Args:
|
|
|
|
b_code_word:bytes: 6 bytes with 6 bits/sign valid data char signs LSB
|
|
|
|
|
|
|
|
Returns:
|
2022-04-14 13:27:03 +00:00
|
|
|
call:str: upper case ham radio call sign [A-Z,0-9] + binary SSID
|
2022-04-14 10:41:58 +00:00
|
|
|
"""
|
|
|
|
code_word = int.from_bytes(b_code_word, byteorder='big', signed=False)
|
2022-04-14 13:27:03 +00:00
|
|
|
ssid = chr(code_word & 0b111111) # save the uncoded binary SSID
|
2022-04-14 10:41:58 +00:00
|
|
|
|
|
|
|
call = str()
|
|
|
|
while code_word != 0:
|
|
|
|
call = chr((code_word & 0b111111)+48) + call
|
|
|
|
code_word = code_word >> 6
|
2022-04-17 20:16:13 +00:00
|
|
|
|
2022-04-14 13:27:03 +00:00
|
|
|
call = call[0:-1] + ssid # remove the last char from call and replace with SSID
|
2022-04-14 10:41:58 +00:00
|
|
|
|
|
|
|
return call
|
|
|
|
|