Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab wfb-ng stats and make it possible to draw it on OSD #18

Open
seriyps opened this issue Oct 7, 2024 · 0 comments · May be fixed by #41
Open

Grab wfb-ng stats and make it possible to draw it on OSD #18

seriyps opened this issue Oct 7, 2024 · 0 comments · May be fixed by #41

Comments

@seriyps
Copy link
Collaborator

seriyps commented Oct 7, 2024

wfb-ng ground station provides a "stats_port" tcp-port where it reports the statistics which is used to draw the wfb-cli gs stats.

I think part of this information can be used in OSD.

The data format is msgpack prefixed by 32-bit-network-byte-order lenght.
https://docs.twisted.org/en/stable/api/twisted.protocols.basic.Int32StringReceiver.html

When connection to the TCP port is opened, wfb sends the initial packet:

type='cli_title',
cli_title=self.factory.cli_title or "",
is_cluster=self.factory.is_cluster,
log_interval=settings.common.log_interval,
temp_overheat_warning=settings.common.temp_overheat_warning

https://github.com/svpcom/wfb-ng/blob/eaa2c158d4d024e4860d2cf11537d9d03faee5cc/wfb_ng/protocols.py#L53-L57

And then keeps periodically sending TX stats (I guess less important for us):

type='tx',
timestamp = time.time(),
id=tx_id,
packets=packet_stats,
latency=ant_latency,
rf_temperature=rf_temperature

https://github.com/svpcom/wfb-ng/blob/eaa2c158d4d024e4860d2cf11537d9d03faee5cc/wfb_ng/protocols.py#L314C31-L319C60

and RX stats:

type='rx',
timestamp = time.time(),
id=rx_id,
tx_wlan=self.tx_sel,
packets=packet_stats,
rx_ant_stats=ant_stats,
session=session

https://github.com/svpcom/wfb-ng/blob/eaa2c158d4d024e4860d2cf11537d9d03faee5cc/wfb_ng/protocols.py#L301-L305

which might be more interesting.

Sample python script:

import msgpack
import socket
import struct

HOST = "localhost"
PORT = 8003

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    while True:
        size_b = s.recv(4)
        (size, ) = struct.unpack("!i", size_b)
        msg_b = s.recv(size)
        msg = msgpack.unpackb(msg_b, strict_map_key=False, use_list=False, raw=False)
        print(msg)

and its output

{'type': 'cli_title', 'cli_title': 'WFB-ng_24.9.26.72534 @gs wlx782288192c76 [default]', 'is_cluster': False}
{'type': 'rx', 'timestamp': 1728342614.2870364, 'id': 'tunnel rx', 'tx_wlan': 0, 'packets': {'all': (0, 0), 'all_bytes': (0, 0), 'dec_ok': (0, 0), 'fec_rec': (0, 0), 'lost': (0, 0), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (0, 0), 'out_bytes': (0, 0)}, 'rx_ant_stats': {}, 'session': None}
{'type': 'rx', 'timestamp': 1728342615.1328719, 'id': 'video rx', 'tx_wlan': 0, 'packets': {'all': (661, 3967), 'all_bytes': (783901, 4704911), 'dec_ok': (661, 3967), 'fec_rec': (28, 271), 'lost': (0, 32), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (466, 2904), 'out_bytes': (528304, 3286747)}, 'rx_ant_stats': {((5805, 1, 20), 1): (661, -38, -37, -37, 8, 31, 37), ((5805, 1, 20), 0): (661, -42, -40, -40, 5, 30, 35)}, 'session': {'fec_type': 'VDM_RS', 'fec_k': 8, 'fec_n': 12, 'epoch': 0}}
{'type': 'tx', 'timestamp': 1728342615.147926, 'id': 'mavlink tx', 'packets': {'fec_timeouts': (0, 0), 'incoming': (0, 0), 'incoming_bytes': (0, 0), 'injected': (0, 0), 'injected_bytes': (0, 0), 'dropped': (0, 0), 'truncated': (0, 0)}, 'latency': {}, 'rf_temperature': {0: 42, 1: 42}}
{'type': 'tx', 'timestamp': 1728342615.1659813, 'id': 'tunnel tx', 'packets': {'fec_timeouts': (0, 0), 'incoming': (2, 1053), 'incoming_bytes': (0, 261), 'injected': (5, 2571), 'injected_bytes': (200, 100410), 'dropped': (0, 0), 'truncated': (0, 0)}, 'latency': {255: (5, 0, 26, 78, 166)}, 'rf_temperature': {0: 42, 1: 42}}
{'type': 'rx', 'timestamp': 1728342615.1976957, 'id': 'mavlink rx', 'tx_wlan': 0, 'packets': {'all': (24, 104), 'all_bytes': (11902, 51476), 'dec_ok': (24, 104), 'fec_rec': (0, 3), 'lost': (0, 0), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (12, 55), 'out_bytes': (5820, 26798)}, 'rx_ant_stats': {((5805, 1, 20), 1): (24, -38, -38, -38, 20, 28, 36), ((5805, 1, 20), 0): (24, -42, -40, -40, 18, 27, 34)}, 'session': {'fec_type': 'VDM_RS', 'fec_k': 1, 'fec_n': 2, 'epoch': 0}}
{'type': 'rx', 'timestamp': 1728342615.2883353, 'id': 'tunnel rx', 'tx_wlan': 0, 'packets': {'all': (0, 0), 'all_bytes': (0, 0), 'dec_ok': (0, 0), 'fec_rec': (0, 0), 'lost': (0, 0), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (0, 0), 'out_bytes': (0, 0)}, 'rx_ant_stats': {}, 'session': None}
{'type': 'rx', 'timestamp': 1728342616.1335232, 'id': 'video rx', 'tx_wlan': 0, 'packets': {'all': (652, 4619), 'all_bytes': (766797, 5471708), 'dec_ok': (652, 4619), 'fec_rec': (46, 317), 'lost': (0, 32), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (480, 3384), 'out_bytes': (538390, 3825137)}, 'rx_ant_stats': {((5805, 1, 20), 1): (652, -38, -37, -37, -1, 31, 37), ((5805, 1, 20), 0): (652, -41, -40, -39, 2, 30, 35)}, 'session': {'fec_type': 'VDM_RS', 'fec_k': 8, 'fec_n': 12, 'epoch': 0}}
{'type': 'tx', 'timestamp': 1728342616.1472914, 'id': 'mavlink tx', 'packets': {'fec_timeouts': (0, 0), 'incoming': (0, 0), 'incoming_bytes': (0, 0), 'injected': (0, 0), 'injected_bytes': (0, 0), 'dropped': (0, 0), 'truncated': (0, 0)}, 'latency': {}, 'rf_temperature': {0: 42, 1: 42}}
{'type': 'tx', 'timestamp': 1728342616.1666563, 'id': 'tunnel tx', 'packets': {'fec_timeouts': (0, 0), 'incoming': (2, 1055), 'incoming_bytes': (0, 261), 'injected': (5, 2576), 'injected_bytes': (200, 100610), 'dropped': (0, 0), 'truncated': (0, 0)}, 'latency': {255: (5, 0, 28, 74, 134)}, 'rf_temperature': {0: 42, 1: 42}}
{'type': 'rx', 'timestamp': 1728342616.197281, 'id': 'mavlink rx', 'tx_wlan': 0, 'packets': {'all': (13, 117), 'all_bytes': (6712, 58188), 'dec_ok': (13, 117), 'fec_rec': (1, 4), 'lost': (4, 4), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (8, 63), 'out_bytes': (3909, 30707)}, 'rx_ant_stats': {((5805, 1, 20), 1): (13, -38, -37, -37, 23, 30, 35), ((5805, 1, 20), 0): (13, -41, -40, -40, 21, 29, 34)}, 'session': {'fec_type': 'VDM_RS', 'fec_k': 1, 'fec_n': 2, 'epoch': 0}}
{'type': 'rx', 'timestamp': 1728342616.288323, 'id': 'tunnel rx', 'tx_wlan': 0, 'packets': {'all': (0, 0), 'all_bytes': (0, 0), 'dec_ok': (0, 0), 'fec_rec': (0, 0), 'lost': (0, 0), 'dec_err': (0, 0), 'bad': (0, 0), 'out': (0, 0), 'out_bytes': (0, 0)}, 'rx_ant_stats': {}, 'session': None}

This is where RX stats is created: https://github.com/svpcom/wfb-ng/blob/eaa2c158d4d024e4860d2cf11537d9d03faee5cc/src/rx.cpp#L488-L497

it->first.freq, it->first.mcs_index, it->first.bandwidth, it->first.antenna_id, it->second.count_all,
                it->second.rssi_min, it->second.rssi_sum / it->second.count_all, it->second.rssi_max,
                it->second.snr_min, it->second.snr_sum / it->second.count_all, it->second.snr_max

And this is where it is converted to msgpack format: https://github.com/svpcom/wfb-ng/blob/eaa2c158d4d024e4860d2cf11537d9d03faee5cc/src/rx.cpp#L488-L497

So

((5805, 1, 20), 1): (652, -38, -37, -37, -1, 31, 37)

likely means

  • 5805 - frequency
  • 1 - MCS index
  • 20 - bandwidth
  • 1 - antenna ID
  • 652 - count_all (number of samples?)
  • -38 - average RSSI
  • -37 rssi_min
  • -37 rssi_max
  • -1 average SNR
  • 31 snr_min
  • 37 snr_max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant