Compare commits

..

9 Commits

Author SHA1 Message Date
235c2dd60d fix(rx): minor fixes and improvements 2025-12-05 15:38:03 +01:00
0f4f05af03 fix(tx): minor corrections and improvements 2025-12-05 15:22:31 +01:00
5914817d22 fix(rx): receiver improvements 2025-12-04 00:20:26 +01:00
e10acf6d6c fix(rx): correct sample rate for RTLSDR 2025-12-03 22:46:08 +01:00
74be0095a3 feat: complementer scripts for tx and rx 2025-12-03 22:45:08 +01:00
3144612d0e refactor: rename pdu_rx to awgn_harness 2025-12-03 22:11:12 +01:00
1695944d82 simulation: simulate with RS-coding 2025-12-03 21:52:45 +01:00
3872ff5221 feat: flowgraphs for tx and rx 2025-11-30 17:10:40 +01:00
5bf5bfec5d feat(framing): framing done
refactor(framing): re-name hamming codec to 7,4 to reflect algorithm used
2025-11-30 13:44:41 +01:00
11 changed files with 1534 additions and 107 deletions

72
awgn_harness.py Normal file
View File

@@ -0,0 +1,72 @@
#!/usr/bin/env python
import asyncio
from time import sleep
import framing
from header import Onbeat_Header
PACKET_LEN=255*4 + 32
DATA_LEN=223*4
HEADER_LEN=32
async def tcp_client(file_2_send: str, callsign: str, rs_coding: bool = True):
port = 50001
reader, writer = await asyncio.open_connection(
'127.0.0.1', port)
with open(file_2_send, "rb") as file_to_send:
seq = 0
sent: list[list[int]] = []
while message := file_to_send.read(DATA_LEN if rs_coding == True else (PACKET_LEN - HEADER_LEN)):
sent.append([i for i in message])
frame = bytes(framing.encode_packet([i for i in message], callsign, seq, rs_coding))
writer.write(frame)
seq += 1
sleep(0.1)
else:
frame = bytes(framing.encode_packet([], callsign, seq, rs_coding))
for _ in range(0,16):
writer.write(frame)
sleep(0.1)
sent.append([])
output: list[tuple[Onbeat_Header, list[int]]] = []
packet_loss = 0
while message := await reader.read(PACKET_LEN):
try:
received = framing.decode_packet([i for i in message])
output.append(received)
if received[0].pkt_len == 0:
break
except Exception as e:
packet_loss += 1
print(e)
return sent, output
rs_coding = False
filename = "loremipsum"
sent, output = asyncio.run(tcp_client(filename, "HA5PLS", rs_coding))
output.sort(key=lambda packet: packet[0].pkt_sequence_id)
output.pop()
def hamming_dist(msg:int, got:int):
return bin(msg ^ got).count('1')
total_errors = sum([sum([hamming_dist(msg, got) for msg, got in zip(sent[pkt[0].pkt_sequence_id], pkt[1])]) for pkt in output])
rcv_len = sum([pkt[0].pkt_len for pkt in output]) * 8
ber = total_errors/rcv_len
print(f"Total errors: {total_errors}, BER: {ber}")
# file : bytes = b''
# filesize = 0
# for pkt in output:
# payload = bytes(pkt[1])
# file += payload
# filesize += pkt[0].pkt_len
# print(file.decode(errors="ignore"))
# print(f"Lost {packet_loss} packets during the transfer, filesize: {filesize}")

46
framing.py Normal file
View File

@@ -0,0 +1,46 @@
from header import Onbeat_Header, PROTOCOL_IDENTIFIER
from reedsolo import RSCodec
import numpy as np
PROTOCOL_V1_NOFEC = 1
PROTOCOL_V1_FEC = 2
RSC = RSCodec(255-223,255)
def decode_packet(packet: list[int]) -> tuple[Onbeat_Header, list[int]]:
if len(packet) < 32:
raise OverflowError(f"Packet is too small to be valid, len: {len(packet)}")
header_raw = packet[0:32]
header = Onbeat_Header(0, 0, "", 0, 0)
if header.decode(header_raw) != True:
raise RuntimeError("invalid CRC")
if header.protocol_id != PROTOCOL_IDENTIFIER:
raise ValueError(f"Protocol ID mismatch, got{header.protocol_id}, expected {PROTOCOL_IDENTIFIER}")
if header.pkt_len > len(packet) - 32:
raise OverflowError(f"Header not fully captured, len:{header.pkt_len}, maximal: {len(packet) - 32}")
elif header.pkt_len == 0:
return header, []
payload = packet[32:32+header.pkt_len]
if header.protocol_configuration == PROTOCOL_V1_FEC:
payload_decoded = np.empty((4, min(len(payload)//4-32, 255)), dtype=int)
for i in range(0,4):
payload_decoded[i] = RSC.decode(bytearray(payload[i::4]))[0]
payload = payload_decoded.flatten(order='F').tolist()
elif header.protocol_configuration == PROTOCOL_V1_NOFEC:
pass
else:
raise ValueError(f"Unknown protocol configuration: {header.protocol_configuration}")
return header, payload
def encode_packet(payload: list[int], callsign: str, sequence: int, rs_coding: bool = False) -> list[int]:
protocol_configuration = PROTOCOL_V1_NOFEC
if rs_coding == True:
protocol_configuration = PROTOCOL_V1_FEC
if len(payload) != 0:
for _ in range(0, len(payload)%4):
payload.append(0)
payload_encoded = np.empty((4, min((len(payload))//4+32, 255)), dtype=int)
for i in range(0,4):
payload_encoded[i] = RSC.encode(bytearray(payload[i::4]))
payload = payload_encoded.flatten(order='F').tolist()
header = Onbeat_Header(0, protocol_configuration, callsign, len(payload), sequence)
return header.encode() + payload

View File

@@ -19,7 +19,7 @@ DECODER_MATRIX = np.asarray([(0, 0, 1, 0, 0, 0, 0,),
def number_to_list(number: int, N: int) -> npt.NDArray:
"""Return the last N bits of a number as an MSB-first array"""
return np.array([(number >> (N-1-i)) % 2 for i in range(0, N)])
return np.array([(number >> (N-1-i)) % 2 for i in range(0, N)],dtype=int)
def list_to_number(array: npt.NDArray, N: int) -> int:
@@ -54,7 +54,8 @@ def decode_nibble(data: int) -> int:
syndrome = (PARITY_MATRIX @ data_asarr) % 2
error = list_to_number(syndrome, 3)
if error == 0:
return list_to_number(data_asarr, 4)
data_decoded = (DECODER_MATRIX @ data_asarr) % 2
return list_to_number(data_decoded, 4)
data_asarr[error - 1] ^= 1
data_decoded = (DECODER_MATRIX @ data_asarr) % 2
return list_to_number(data_decoded, 4)
@@ -86,12 +87,10 @@ if __name__ == "__main__":
data_corrected_2bit = hamming_7_4_decode(data_corrupted_2bit)
data_corrected_2bit_str = [int.to_bytes(int(i), 1, "big").decode(
encoding="utf-8", errors="ignore") for i in data_corrected_2bit]
print(f"Recovered data from 1-bit errors: {data_corrected_2bit_str}")
print(f"Recovered data from 2-bit errors: {data_corrected_2bit_str}")
data_corrupted_3bit = [data ^ (7 << (idx % 7))
for idx, data in enumerate(data_encoded)]
# print(f"Corrupt data with 3-bit errors: {data_corrupted_3bit}")
data_corrected_3bit = hamming_7_4_decode(data_corrupted_3bit)
data_corrected_3bit_str = [int.to_bytes(int(i), 1, "big").decode(
encoding="utf-8", errors="ignore") for i in data_corrected_3bit]
print(f"Recovered data from 1-bit errors: {data_corrected_3bit_str}")
data_corrected_noerr = hamming_7_4_decode(data_encoded)
data_corrected_noerr_str = [int.to_bytes(int(i), 1, "big").decode(
encoding="utf-8", errors="ignore") for i in data_corrected_noerr]
print(f"Recovered data from no errors: {data_corrected_noerr_str}")

View File

@@ -1,12 +1,12 @@
from hamming_8_4_codec import hamming_8_4_encode, hamming_8_4_decode
from crc import Configuration, Crc16
from hamming_7_4_codec import hamming_7_4_encode, hamming_7_4_decode
from crc import Calculator, Crc16
PROTOCOL_IDENTIFIER = 0x0
# CRC_POLY = (0xed2f << 1) + 1 # from https://users.ece.cmu.edu/~koopman/crc/index.html as "best 16-bit CRC" on 2025-10-24
ONBEAT_CRC = Configuration(Crc16.IBM_3740)
ONBEAT_CRC = Calculator(Crc16.IBM_3740)
class Onbeat_Header:
"""This class represents a header for a single packet of PLSTV."""
"""This class represents a header for a single packet of ONBEAT."""
def __init__(self, protocol_id, protocol_configuration: int, callsign: str, pkt_len: int, pkt_sequence_id: int):
if protocol_id >= 2 << 4:
@@ -20,9 +20,11 @@ class Onbeat_Header:
self.protocol_configuration = protocol_configuration
call_len = len(callsign.encode())
if call_len >= 10:
if call_len > 10:
raise OverflowError(
f"Callsign must be confined to 10 bytes, got {callsign} with length {call_len} (using UTF-8)")
for _ in range(call_len, 10):
callsign += "\0"
self.callsign = callsign
if pkt_len >= 2 << 16:
@@ -30,7 +32,7 @@ class Onbeat_Header:
f"Maximum allowed packet size is {2 << 16 - 1} got {pkt_len}")
self.pkt_len = pkt_len
if pkt_sequence_id >= 2 << 8:
if pkt_sequence_id >= 256:
raise OverflowError(
f"Packet sequence ID must be confined to 8 bits, got {pkt_sequence_id}")
self.pkt_sequence_id = pkt_sequence_id
@@ -39,27 +41,18 @@ class Onbeat_Header:
header_asints = []
header_asints += [(PROTOCOL_IDENTIFIER << 4) +
self.protocol_configuration]
header_asints += [(int.from_bytes(self.callsign.encode())
>> 8*i) % 2 << 8 for i in range(0, 10)]
header_asints += [(self.pkt_len >> 8), self.pkt_len % 2 << 8]
header_asints += [ord(c) for c in self.callsign]
header_asints += [(self.pkt_len >> 8), self.pkt_len % 256]
header_asints += [self.pkt_sequence_id]
header_crc = ONBEAT_CRC.checksum(bytes(header_asints))
header_asints += [header_crc]
return hamming_8_4_encode(header_asints)
header_asints += [header_crc >> 8, header_crc % 256]
return hamming_7_4_encode(header_asints)
def decode(self, header_encoded: list[int]):
header_corrected = hamming_8_4_decode(header_encoded)
checksum = ONBEAT_CRC.checksum(
bytes(header_corrected[14] << 8 + header_corrected[15]))
if checksum != 0:
raise ValueError(
"Checksum of header is non-zero, packet is invalid")
self.protocol_id = header_corrected[0] >> 4
self.protocol_configuration = header_corrected[0] % 16
callsign_numeric = 0
for i in range(1, 11):
callsign_numeric += header_corrected[i]
callsign_numeric <<= 8
self.callsign = int.to_bytes(callsign_numeric, byteorder="big").decode()
self.pkt_len = header_corrected[11] << 8 + header_corrected[12]
self.pkt_sequence_id = header_corrected[13]
def decode(self, header_encoded: list[int]) -> bool:
header_corrected = hamming_7_4_decode(header_encoded)
self.protocol_id = int(header_corrected[0] >> 4)
self.protocol_configuration = int(header_corrected[0] % 16)
self.callsign = bytes(header_corrected[1:11]).decode(errors="ignore")
self.pkt_len = int((header_corrected[11] << 8) + header_corrected[12])
self.pkt_sequence_id = int(header_corrected[13])
return ONBEAT_CRC.verify(bytearray(header_corrected[0:14]), (header_corrected[14] << 8) + header_corrected[15])

View File

@@ -90,7 +90,7 @@ blocks:
key: pmt.intern("packet_len")
offset: '0'
src: pmt.intern("src")
value: pmt.from_long(64)
value: pmt.from_long(8)
states:
bus_sink: false
bus_source: false
@@ -252,23 +252,6 @@ blocks:
coordinate: [272, 504.0]
rotation: 0
state: disabled
- name: data_len
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: ''
short_id: ''
type: ''
value: '1024'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [976, 24.0]
rotation: 0
state: enabled
- name: digital_constellation_modulator_0
id: digital_constellation_modulator
parameters:
@@ -288,7 +271,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1088, 296.0]
coordinate: [1096, 312.0]
rotation: 0
state: enabled
- name: pad_sink_0
@@ -306,25 +289,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1352, 320.0]
rotation: 0
state: enabled
- name: pad_sink_0_0
id: pad_sink
parameters:
affinity: ''
alias: ''
comment: ''
label: dbg
num_streams: '1'
optional: 'True'
type: byte
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [576, 136.0]
coordinate: [1352, 336.0]
rotation: 0
state: enabled
- name: pad_source_0
@@ -386,7 +351,6 @@ connections:
- [blocks_repack_bits_bb_1_0, '0', blocks_tagged_stream_mux_0, '1']
- [blocks_tagged_stream_mux_0, '0', digital_constellation_modulator_0, '0']
- [blocks_vector_source_x_0_0, '0', blocks_tagged_stream_mux_0, '0']
- [blocks_vector_source_x_0_0, '0', pad_sink_0_0, '0']
- [blocks_vector_source_x_0_0_0, '0', blocks_repack_bits_bb_1_0, '0']
- [blocks_vector_source_x_0_0_0_0, '0', blocks_repack_bits_bb_1_0_0, '0']
- [digital_constellation_modulator_0, '0', pad_sink_0, '0']

962
onbeat_rx.grc Normal file
View File

@@ -0,0 +1,962 @@
options:
parameters:
author: HA5PLS
catch_exceptions: 'True'
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: GPL 3.0 or later
description: Receiver flowgraph for onbeat
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: onbeat_rx
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: ONBEAT receiver
window_size: (1000,1000)
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: OVERSAMPLING
id: variable
parameters:
comment: ''
value: '100'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [288, 12.0]
rotation: 0
state: enabled
- name: RRC_ALPHA
id: variable
parameters:
comment: ''
value: '0.35'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [816, 12.0]
rotation: 0
state: enabled
- name: lo_freq
id: variable_qtgui_range
parameters:
comment: ''
gui_hint: ''
label: RX frequency
min_len: '200'
orient: QtCore.Qt.Horizontal
rangeType: int
start: '50'
step: '1'
stop: '3000'
value: '433'
widget: counter_slider
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [192, 96.0]
rotation: 0
state: true
- name: rx_gain
id: variable_qtgui_range
parameters:
comment: ''
gui_hint: ''
label: RX gain
min_len: '200'
orient: QtCore.Qt.Horizontal
rangeType: float
start: '0'
step: '0.1'
stop: '49.6'
value: '20'
widget: counter_slider
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [160, 256.0]
rotation: 0
state: true
- name: samp_rate
id: variable
parameters:
comment: ''
value: 1e6
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [192, 12.0]
rotation: 0
state: enabled
- name: symbol_map
id: variable
parameters:
comment: ''
value: '[0, 1, 3, 2]'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [712, 12.0]
rotation: 0
state: enabled
- name: ONBEAT_Demod_1
id: ONBEAT_Demod
parameters:
FULL_PACKET_LEN: 8*(4*255+2*16)
OVERSAMPLING: OVERSAMPLING
RRC_ALPHA: RRC_ALPHA
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
roc_tolerance: '0.8'
samp_rate: samp_rate
symbol_map: symbol_map
syncword: syncword
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [728, 412.0]
rotation: 0
state: enabled
- name: network_socket_pdu_1
id: network_socket_pdu
parameters:
affinity: ''
alias: ''
comment: ''
host: 0.0.0.0
maxoutbuf: '0'
minoutbuf: '0'
mtu: '10000'
port: rx_port
tcp_no_delay: 'False'
type: TCP_SERVER
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1104, 572.0]
rotation: 0
state: enabled
- name: qtgui_const_sink_x_0
id: qtgui_const_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: '"blue"'
color10: '"red"'
color2: '"red"'
color3: '"green"'
color4: '"black"'
color5: '"cyan"'
color6: '"magenta"'
color7: '"yellow"'
color8: '"dark red"'
color9: '"dark green"'
comment: ''
grid: 'False'
gui_hint: ''
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
legend: 'True'
marker1: '0'
marker10: '0'
marker2: '0'
marker3: '0'
marker4: '0'
marker5: '0'
marker6: '0'
marker7: '0'
marker8: '0'
marker9: '0'
name: '""'
nconnections: '1'
size: '128'
style1: '0'
style10: '0'
style2: '0'
style3: '0'
style4: '0'
style5: '0'
style6: '0'
style7: '0'
style8: '0'
style9: '0'
tr_chan: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: complex
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
xmax: '2'
xmin: '-2'
ymax: '2'
ymin: '-2'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1104, 316.0]
rotation: 0
state: enabled
- name: qtgui_eye_sink_x_0
id: qtgui_eye_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: blue
color2: blue
color3: blue
color4: blue
color5: blue
color6: blue
color7: blue
color8: blue
color9: blue
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
gui_hint: ''
label1: Signal 1
label10: Signal 10
label2: Signal 2
label3: Signal 3
label4: Signal 4
label5: Signal 5
label6: Signal 6
label7: Signal 7
label8: Signal 8
label9: Signal 9
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
nconnections: '1'
samp_per_symbol: '1'
size: '128'
srate: samp_rate
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: complex
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '1'
ymin: '-1'
yunit: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1104, 380.0]
rotation: 0
state: enabled
- name: qtgui_freq_sink_x_0
id: qtgui_freq_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
average: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '"blue"'
color10: '"dark blue"'
color2: '"red"'
color3: '"green"'
color4: '"black"'
color5: '"cyan"'
color6: '"magenta"'
color7: '"yellow"'
color8: '"dark red"'
color9: '"dark green"'
comment: ''
ctrlpanel: 'False'
fc: lo_freq*10e6
fftsize: '1024'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
label: Relative Gain
label1: ''
label10: ''''''
label2: ''''''
label3: ''''''
label4: ''''''
label5: ''''''
label6: ''''''
label7: ''''''
label8: ''''''
label9: ''''''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
norm_window: 'False'
showports: 'False'
tr_chan: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_tag: '""'
type: complex
units: dB
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
wintype: window.WIN_BLACKMAN_hARRIS
ymax: '10'
ymin: '-140'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [776, 224.0]
rotation: 0
state: enabled
- name: qtgui_time_sink_x_0
id: qtgui_time_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: dark blue
color2: red
color3: green
color4: black
color5: cyan
color6: magenta
color7: yellow
color8: dark red
color9: dark green
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
gui_hint: ''
label1: Signal 1
label10: Signal 10
label2: Signal 2
label3: Signal 3
label4: Signal 4
label5: Signal 5
label6: Signal 6
label7: Signal 7
label8: Signal 8
label9: Signal 9
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
name: '""'
nconnections: '1'
size: '1024'
srate: samp_rate/5
stemplot: 'False'
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: complex
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '1'
ymin: '-1'
yunit: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1104, 484.0]
rotation: 0
state: enabled
- name: rtlsdr_source_0
id: rtlsdr_source
parameters:
affinity: ''
alias: ''
ant0: ''
ant1: ''
ant10: ''
ant11: ''
ant12: ''
ant13: ''
ant14: ''
ant15: ''
ant16: ''
ant17: ''
ant18: ''
ant19: ''
ant2: ''
ant20: ''
ant21: ''
ant22: ''
ant23: ''
ant24: ''
ant25: ''
ant26: ''
ant27: ''
ant28: ''
ant29: ''
ant3: ''
ant30: ''
ant31: ''
ant4: ''
ant5: ''
ant6: ''
ant7: ''
ant8: ''
ant9: ''
args: '""'
bb_gain0: '20'
bb_gain1: '20'
bb_gain10: '20'
bb_gain11: '20'
bb_gain12: '20'
bb_gain13: '20'
bb_gain14: '20'
bb_gain15: '20'
bb_gain16: '20'
bb_gain17: '20'
bb_gain18: '20'
bb_gain19: '20'
bb_gain2: '20'
bb_gain20: '20'
bb_gain21: '20'
bb_gain22: '20'
bb_gain23: '20'
bb_gain24: '20'
bb_gain25: '20'
bb_gain26: '20'
bb_gain27: '20'
bb_gain28: '20'
bb_gain29: '20'
bb_gain3: '20'
bb_gain30: '20'
bb_gain31: '20'
bb_gain4: '20'
bb_gain5: '20'
bb_gain6: '20'
bb_gain7: '20'
bb_gain8: '20'
bb_gain9: '20'
bw0: '0'
bw1: '0'
bw10: '0'
bw11: '0'
bw12: '0'
bw13: '0'
bw14: '0'
bw15: '0'
bw16: '0'
bw17: '0'
bw18: '0'
bw19: '0'
bw2: '0'
bw20: '0'
bw21: '0'
bw22: '0'
bw23: '0'
bw24: '0'
bw25: '0'
bw26: '0'
bw27: '0'
bw28: '0'
bw29: '0'
bw3: '0'
bw30: '0'
bw31: '0'
bw4: '0'
bw5: '0'
bw6: '0'
bw7: '0'
bw8: '0'
bw9: '0'
clock_source0: ''
clock_source1: ''
clock_source2: ''
clock_source3: ''
clock_source4: ''
clock_source5: ''
clock_source6: ''
clock_source7: ''
comment: ''
corr0: '0'
corr1: '0'
corr10: '0'
corr11: '0'
corr12: '0'
corr13: '0'
corr14: '0'
corr15: '0'
corr16: '0'
corr17: '0'
corr18: '0'
corr19: '0'
corr2: '0'
corr20: '0'
corr21: '0'
corr22: '0'
corr23: '0'
corr24: '0'
corr25: '0'
corr26: '0'
corr27: '0'
corr28: '0'
corr29: '0'
corr3: '0'
corr30: '0'
corr31: '0'
corr4: '0'
corr5: '0'
corr6: '0'
corr7: '0'
corr8: '0'
corr9: '0'
dc_offset_mode0: '0'
dc_offset_mode1: '0'
dc_offset_mode10: '0'
dc_offset_mode11: '0'
dc_offset_mode12: '0'
dc_offset_mode13: '0'
dc_offset_mode14: '0'
dc_offset_mode15: '0'
dc_offset_mode16: '0'
dc_offset_mode17: '0'
dc_offset_mode18: '0'
dc_offset_mode19: '0'
dc_offset_mode2: '0'
dc_offset_mode20: '0'
dc_offset_mode21: '0'
dc_offset_mode22: '0'
dc_offset_mode23: '0'
dc_offset_mode24: '0'
dc_offset_mode25: '0'
dc_offset_mode26: '0'
dc_offset_mode27: '0'
dc_offset_mode28: '0'
dc_offset_mode29: '0'
dc_offset_mode3: '0'
dc_offset_mode30: '0'
dc_offset_mode31: '0'
dc_offset_mode4: '0'
dc_offset_mode5: '0'
dc_offset_mode6: '0'
dc_offset_mode7: '0'
dc_offset_mode8: '0'
dc_offset_mode9: '0'
freq0: lo_freq * 1e6
freq1: 100e6
freq10: 100e6
freq11: 100e6
freq12: 100e6
freq13: 100e6
freq14: 100e6
freq15: 100e6
freq16: 100e6
freq17: 100e6
freq18: 100e6
freq19: 100e6
freq2: 100e6
freq20: 100e6
freq21: 100e6
freq22: 100e6
freq23: 100e6
freq24: 100e6
freq25: 100e6
freq26: 100e6
freq27: 100e6
freq28: 100e6
freq29: 100e6
freq3: 100e6
freq30: 100e6
freq31: 100e6
freq4: 100e6
freq5: 100e6
freq6: 100e6
freq7: 100e6
freq8: 100e6
freq9: 100e6
gain0: rx_gain
gain1: '10'
gain10: '10'
gain11: '10'
gain12: '10'
gain13: '10'
gain14: '10'
gain15: '10'
gain16: '10'
gain17: '10'
gain18: '10'
gain19: '10'
gain2: '10'
gain20: '10'
gain21: '10'
gain22: '10'
gain23: '10'
gain24: '10'
gain25: '10'
gain26: '10'
gain27: '10'
gain28: '10'
gain29: '10'
gain3: '10'
gain30: '10'
gain31: '10'
gain4: '10'
gain5: '10'
gain6: '10'
gain7: '10'
gain8: '10'
gain9: '10'
gain_mode0: 'False'
gain_mode1: 'False'
gain_mode10: 'False'
gain_mode11: 'False'
gain_mode12: 'False'
gain_mode13: 'False'
gain_mode14: 'False'
gain_mode15: 'False'
gain_mode16: 'False'
gain_mode17: 'False'
gain_mode18: 'False'
gain_mode19: 'False'
gain_mode2: 'False'
gain_mode20: 'False'
gain_mode21: 'False'
gain_mode22: 'False'
gain_mode23: 'False'
gain_mode24: 'False'
gain_mode25: 'False'
gain_mode26: 'False'
gain_mode27: 'False'
gain_mode28: 'False'
gain_mode29: 'False'
gain_mode3: 'False'
gain_mode30: 'False'
gain_mode31: 'False'
gain_mode4: 'False'
gain_mode5: 'False'
gain_mode6: 'False'
gain_mode7: 'False'
gain_mode8: 'False'
gain_mode9: 'False'
if_gain0: '20'
if_gain1: '20'
if_gain10: '20'
if_gain11: '20'
if_gain12: '20'
if_gain13: '20'
if_gain14: '20'
if_gain15: '20'
if_gain16: '20'
if_gain17: '20'
if_gain18: '20'
if_gain19: '20'
if_gain2: '20'
if_gain20: '20'
if_gain21: '20'
if_gain22: '20'
if_gain23: '20'
if_gain24: '20'
if_gain25: '20'
if_gain26: '20'
if_gain27: '20'
if_gain28: '20'
if_gain29: '20'
if_gain3: '20'
if_gain30: '20'
if_gain31: '20'
if_gain4: '20'
if_gain5: '20'
if_gain6: '20'
if_gain7: '20'
if_gain8: '20'
if_gain9: '20'
iq_balance_mode0: '0'
iq_balance_mode1: '0'
iq_balance_mode10: '0'
iq_balance_mode11: '0'
iq_balance_mode12: '0'
iq_balance_mode13: '0'
iq_balance_mode14: '0'
iq_balance_mode15: '0'
iq_balance_mode16: '0'
iq_balance_mode17: '0'
iq_balance_mode18: '0'
iq_balance_mode19: '0'
iq_balance_mode2: '0'
iq_balance_mode20: '0'
iq_balance_mode21: '0'
iq_balance_mode22: '0'
iq_balance_mode23: '0'
iq_balance_mode24: '0'
iq_balance_mode25: '0'
iq_balance_mode26: '0'
iq_balance_mode27: '0'
iq_balance_mode28: '0'
iq_balance_mode29: '0'
iq_balance_mode3: '0'
iq_balance_mode30: '0'
iq_balance_mode31: '0'
iq_balance_mode4: '0'
iq_balance_mode5: '0'
iq_balance_mode6: '0'
iq_balance_mode7: '0'
iq_balance_mode8: '0'
iq_balance_mode9: '0'
maxoutbuf: '0'
minoutbuf: '0'
nchan: '1'
num_mboards: '1'
sample_rate: samp_rate * OVERSAMPLING
sync: sync
time_source0: ''
time_source1: ''
time_source2: ''
time_source3: ''
time_source4: ''
time_source5: ''
time_source6: ''
time_source7: ''
type: fc32
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [256, 332.0]
rotation: 0
state: disabled
- name: rx_port
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: ''
short_id: ''
type: str
value: '50002'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [408, 92.0]
rotation: 0
state: enabled
- name: soapy_rtlsdr_source_0
id: soapy_rtlsdr_source
parameters:
affinity: ''
agc: 'False'
alias: ''
bias: 'False'
bufflen: '16384'
center_freq: lo_freq*1e6
comment: ''
dev_args: ''
freq_correction: '0'
gain: rx_gain
maxoutbuf: '0'
minoutbuf: '0'
samp_rate: samp_rate
type: fc32
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [320, 232.0]
rotation: 0
state: enabled
- name: syncword
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: ''
short_id: ''
type: ''
value: '"0000011100001001000110110010110101110111100110001010100111111010"'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [448, 12.0]
rotation: 0
state: enabled
connections:
- [ONBEAT_Demod_1, '0', qtgui_const_sink_x_0, '0']
- [ONBEAT_Demod_1, '1', qtgui_eye_sink_x_0, '0']
- [ONBEAT_Demod_1, '2', qtgui_time_sink_x_0, '0']
- [ONBEAT_Demod_1, out, network_socket_pdu_1, pdus]
- [rtlsdr_source_0, '0', ONBEAT_Demod_1, '0']
- [rtlsdr_source_0, '0', qtgui_freq_sink_x_0, '0']
- [soapy_rtlsdr_source_0, '0', ONBEAT_Demod_1, '0']
- [soapy_rtlsdr_source_0, '0', qtgui_freq_sink_x_0, '0']
metadata:
file_format: 1
grc_version: 3.10.11.0

43
onbeat_rx_wrapper.py Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
import asyncio
import framing
from header import Onbeat_Header
import json
PACKET_LEN=255*4 + 32
DATA_LEN=223*4
HEADER_LEN=32
async def tcp_client():
port = 50002
reader, _ = await asyncio.open_connection(
'127.0.0.1', port)
# output: list[tuple[Onbeat_Header, list[int]]] = []
output: list[list[int]] = []
packet_loss = 0
while message := await reader.read(PACKET_LEN):
try:
received = framing.decode_packet([i for i in message])
output.append([i for i in message])
print("pkt received")
if received[0].pkt_len == 0:
break
except KeyboardInterrupt:
break
except Exception as e:
packet_loss += 1
print(e)
return output
rs_coding = False
filename = "loremipsum"
received = asyncio.run(tcp_client())
with open("rx_packets.json", mode="w") as packetfile:
json.dump(received, packetfile)

311
onbeat_tx.grc Normal file
View File

@@ -0,0 +1,311 @@
options:
parameters:
author: HA5PLS
catch_exceptions: 'True'
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: GPL 3.0 or later
description: Transmitter flowgraph for onbeat
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: onbeat_tx
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: ONBEAT transmitter
window_size: (1000,1000)
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: OVERSAMPLING
id: variable
parameters:
comment: ''
value: '100'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [288, 12.0]
rotation: 0
state: enabled
- name: RRC_ALPHA
id: variable
parameters:
comment: ''
value: '0.35'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [816, 12.0]
rotation: 0
state: enabled
- name: lo_freq
id: variable_qtgui_range
parameters:
comment: ''
gui_hint: ''
label: TX frequency
min_len: '200'
orient: QtCore.Qt.Horizontal
rangeType: int
start: '50'
step: '1'
stop: '3000'
value: '433'
widget: counter_slider
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [192, 92.0]
rotation: 0
state: true
- name: samp_rate
id: variable
parameters:
comment: ''
value: 1e6
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [192, 12.0]
rotation: 0
state: enabled
- name: symbol_map
id: variable
parameters:
comment: ''
value: '[0, 1, 3, 2]'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [712, 12.0]
rotation: 0
state: enabled
- name: ONBEAT_Mod_0
id: ONBEAT_Mod
parameters:
OVERSAMPLING: OVERSAMPLING
RRC_ALPHA: RRC_ALPHA
affinity: ''
alias: ''
comment: ''
data_len: '1'
maxoutbuf: '0'
minoutbuf: '0'
preamble: '[0x33 for i in range(0, 128*2, 8)]'
syncword: syncword
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [832, 176.0]
rotation: 0
state: enabled
- name: iio_pluto_sink_0
id: iio_pluto_sink
parameters:
affinity: ''
alias: ''
attenuation1: '5.0'
bandwidth: '20000000'
buffer_size: '32768'
comment: ''
cyclic: 'False'
filter: ''
filter_source: '''Auto'''
fpass: '0'
frequency: lo_freq * 1000000
fstop: '0'
len_tag_key: ''
samplerate: int(samp_rate)
type: fc32
uri: ''
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1168, 148.0]
rotation: 0
state: true
- name: network_socket_pdu_1
id: network_socket_pdu
parameters:
affinity: ''
alias: ''
comment: ''
host: 0.0.0.0
maxoutbuf: '0'
minoutbuf: '0'
mtu: '10000'
port: tx_port
tcp_no_delay: 'False'
type: TCP_SERVER
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [408, 184.0]
rotation: 0
state: enabled
- name: pdu_pdu_to_tagged_stream_0
id: pdu_pdu_to_tagged_stream
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
tag: packet_len
type: byte
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [608, 208.0]
rotation: 0
state: enabled
- name: qtgui_freq_sink_x_0
id: qtgui_freq_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
average: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '"blue"'
color10: '"dark blue"'
color2: '"red"'
color3: '"green"'
color4: '"black"'
color5: '"cyan"'
color6: '"magenta"'
color7: '"yellow"'
color8: '"dark red"'
color9: '"dark green"'
comment: ''
ctrlpanel: 'False'
fc: lo_freq * 1e6
fftsize: '1024'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
label: Relative Gain
label1: ''
label10: ''''''
label2: ''''''
label3: ''''''
label4: ''''''
label5: ''''''
label6: ''''''
label7: ''''''
label8: ''''''
label9: ''''''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
norm_window: 'False'
showports: 'False'
tr_chan: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_tag: '""'
type: complex
units: dB
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
wintype: window.WIN_BLACKMAN_hARRIS
ymax: '10'
ymin: '-140'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1176, 340.0]
rotation: 0
state: true
- name: syncword
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: ''
short_id: ''
type: ''
value: '"0000011100001001000110110010110101110111100110001010100111111010"'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [448, 12.0]
rotation: 0
state: enabled
- name: tx_port
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: ''
short_id: ''
type: str
value: '50001'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [408, 92.0]
rotation: 0
state: enabled
connections:
- [ONBEAT_Mod_0, '0', iio_pluto_sink_0, '0']
- [ONBEAT_Mod_0, '0', qtgui_freq_sink_x_0, '0']
- [network_socket_pdu_1, pdus, pdu_pdu_to_tagged_stream_0, pdus]
- [pdu_pdu_to_tagged_stream_0, '0', ONBEAT_Mod_0, '0']
metadata:
file_format: 1

46
onbeat_tx_wrapper.py Normal file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env python
import asyncio
from time import sleep
import framing
# from header import Onbeat_Header
import json
PACKET_LEN=255*4 + 32
DATA_LEN=223*4
HEADER_LEN=32
async def tcp_client(file_2_send: str, callsign: str, rs_coding: bool = True):
port = 50001
_, writer = await asyncio.open_connection(
'127.0.0.1', port)
with open(file_2_send, "rb") as file_to_send:
seq = 0
sent: list[list[int]] = []
try:
while message := file_to_send.read(DATA_LEN if rs_coding == True else (PACKET_LEN - HEADER_LEN)):
sent.append([i for i in message])
frame = bytes(framing.encode_packet([i for i in message], callsign, seq%256, rs_coding))
writer.write(frame)
seq += 1
print(seq)
sleep(0.01)
else:
frame = bytes(framing.encode_packet([], callsign, seq%256, rs_coding))
for _ in range(0,4):
writer.write(frame)
sleep(0.01)
sent.append([])
except KeyboardInterrupt:
return sent
rs_coding = True
filename = "/home/lacko/live_output/2025-11-01_12-39_elektro_lrit_1.691 GHz/IMAGES/ELEKTRO-L3/2025-11-01_12-30-00/msu_gs_Color IR Merge.png"
sent = asyncio.run(tcp_client(filename, "HA5PLS", rs_coding))
with open("packets.json", mode="w") as packetfile:
json.dump(sent, packetfile)

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env python
import asyncio
from time import sleep
PACKET_LEN=128
async def tcp_client():
port = 50001
reader, writer = await asyncio.open_connection(
'127.0.0.1', port)
with open("loremipsum", "rb") as file_to_send:
while message := file_to_send.read(PACKET_LEN):
writer.write(message)
sleep(1)
while message := await reader.read(PACKET_LEN):
print(f"Got: {message.decode()}\n\n")
asyncio.run(tcp_client())

View File

@@ -37,7 +37,7 @@ blocks:
id: variable
parameters:
comment: ''
value: '10'
value: '2'
states:
bus_sink: false
bus_source: false
@@ -102,7 +102,7 @@ blocks:
label: ''
short_id: ''
type: eng_float
value: '100'
value: '3'
states:
bus_sink: false
bus_source: false
@@ -121,7 +121,7 @@ blocks:
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
roc_tolerance: '1'
roc_tolerance: '0.8'
samp_rate: samp_rate
symbol_map: symbol_map
syncword: syncword
@@ -140,7 +140,6 @@ blocks:
affinity: ''
alias: ''
comment: ''
data_len: data_len
maxoutbuf: '0'
minoutbuf: '0'
preamble: '[0x33 for i in range(0, 128*2, 8)]'
@@ -149,7 +148,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [464, 256.0]
coordinate: [480, 264.0]
rotation: 0
state: enabled
- name: blocks_tag_gate_0
@@ -168,7 +167,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [752, 264.0]
coordinate: [744, 280.0]
rotation: 0
state: enabled
- name: blocks_throttle2_0
@@ -189,7 +188,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1136, 264.0]
coordinate: [1144, 280.0]
rotation: 0
state: enabled
- name: channels_channel_model_0
@@ -203,14 +202,14 @@ blocks:
freq_offset: freq_offset
maxoutbuf: '0'
minoutbuf: '0'
noise_voltage: (1/EbN0*(1+RRC_ALPHA)/2)**0.5
noise_voltage: 1.0/sqrt(2* 10**(float(EbN0) / 10)) * sqrt(OVERSAMPLING/2)
seed: '0'
taps: '1.0'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [928, 232.0]
coordinate: [928, 248.0]
rotation: 0
state: enabled
- name: data_len
@@ -222,7 +221,7 @@ blocks:
label: ''
short_id: ''
type: intx
value: '128'
value: 255*4 + 32
states:
bus_sink: false
bus_source: false
@@ -247,6 +246,19 @@ blocks:
coordinate: [960, 136.0]
rotation: 0
state: enabled
- name: import_0
id: import
parameters:
alias: ''
comment: ''
imports: from math import log10, log2, sqrt
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [968, 24.0]
rotation: 0
state: enabled
- name: network_socket_pdu_1
id: network_socket_pdu
parameters:
@@ -647,7 +659,7 @@ blocks:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1320, 272.0]
coordinate: [1320, 288.0]
rotation: 0
state: enabled
- name: virtual_source_0