keep uncoded SSID 0 - 63 and changed to fixed binary code word length 6

This commit is contained in:
Jörg 2022-04-14 15:27:03 +02:00
parent 7c4ccac6a0
commit adbaa8e6f3

View file

@ -319,15 +319,14 @@ def decode_grid(b_code_word:bytes):
def encode_call(call, bytes_length=6):
def encode_call(call):
"""
@Auther: DB1UJ
@auther: DB1UJ
Args:
call:string: ham radio call sign [A-Z,0-9]
bytes_length:int: number of output bytes, have to fit 6 bits/sign, standard 6 bytes
call:string: ham radio call sign [A-Z,0-9], last char SSID 0-63
Returns:
bytes_length bytes (standard 6) contains 6 bits/sign encoded 8 char call sign (only upper letters + numbers)
6 bytes contains 6 bits/sign encoded 8 char call sign with binary SSID (only upper letters + numbers, SSID)
"""
out_code_word = int(0)
@ -337,24 +336,29 @@ def encode_call(call, bytes_length=6):
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
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
return out_code_word.to_bytes(length=bytes_length, byteorder='big')
return out_code_word.to_bytes(length=6, byteorder='big')
def decode_call(b_code_word:bytes):
"""
@Auther: DB1UJ
@auther: DB1UJ
Args:
b_code_word:bytes: 6 bytes with 6 bits/sign valid data char signs LSB
Returns:
call:str: upper case ham radio call sign [A-Z,0-9]
call:str: upper case ham radio call sign [A-Z,0-9] + binary SSID
"""
code_word = int.from_bytes(b_code_word, byteorder='big', signed=False)
ssid = chr(code_word & 0b111111) # save the uncoded binary SSID
call = str()
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