Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
BY70-1 AX.25 command generator
#!/usr/bin/env python3
import binascii
import sys
def ax25call(callsign):
s = callsign.split('-')
call = s[0].upper()[:6]
call = call + ' '*(6-len(call))
ssid = 0 if len(s) == 1 else int(s[1])
c = bytes(map(lambda c: c << 1, bytes(call, 'ascii')))
ss = bytes([0x60 | (ssid & 0xf) << 1 ])
return c + ss
dst = ax25call(sys.argv[1])
src = ax25call(sys.argv[2])
cmd = binascii.a2b_hex(sys.argv[3].replace(' ', ''))
packet = dst + src[:-1] + bytes([src[-1] | 1]) + b'\x03\xf0' + cmd
kiss = b'\xc0\x00' + packet.replace(b'\xdb', b'\xdb\xdd').replace(b'\xc0', b'\xdb\xdc') + b'\xc0'
sys.stdout.buffer.write(kiss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment