Commit b9bc559b authored by Joanne Hugé's avatar Joanne Hugé

Initial commit

parents
# Setup
Ensure you have python3
python3 -m venv env
source env/bin/activate
pip install -r requirements.txt
# Usage
```
# Get current gain
python adjust-gain.py 'ws://[2a11:9ac0:63::11]:9001' password
# Set tx_gain to 70 and rx_gain to 40
python adjust-gain.py 'ws://[2a11:9ac0:63::11]:9001' password 70 40
# Get signal level
python get-signal-level.py 'ws://[2a11:9ac0:63::11]:9001' password
--P0/TX 0-- --P0/TX 1-- --P0/RX 0-- --P0/RX 1--
RMS MAX RMS MAX RMS MAX RMS MAX
-23.727 -7.729 -23.723 -7.522 -57.524 -25.478 -54.660 -15.883
-23.747 -7.148 -23.743 -7.522 -57.535 -26.055 -54.678 -15.700
-23.752 -7.729 -23.749 -7.522 -57.540 -25.804 -54.687 -15.572
-23.738 -7.729 -23.735 -7.522 -57.540 -25.640 -54.688 -15.962
```
import asyncio
import hmac
import hashlib
import json
import sys
import websockets
async def adjust_gain(uri, password, tx_gain=0, rx_gain=0):
async with websockets.connect(uri, origin="Test") as websocket:
rsp = await websocket.recv()
print(f"< {rsp}")
data = json.loads(rsp)
res = hmac.new(
"{}:{}:{}".format(data['type'], password, data['name']).encode(),
msg=data['challenge'].encode(),
digestmod=hashlib.sha256
).hexdigest()
msg = f'{{"message":"authenticate", "res": "{res}"}}'
await websocket.send(msg)
print(f"> {msg}")
rsp = await websocket.recv()
print(f"< {rsp}")
if tx_gain:
msg = f'{{"message":"rf", "tx_gain": {tx_gain}, "rx_gain": {rx_gain} }}'
else:
msg = f'{{"message":"rf", }}'
await websocket.send(msg)
await websocket.send(msg)
print(f"> {msg}")
rsp = await websocket.recv()
print(f"< {rsp}")
if len(sys.argv) < 3:
print("Usage: ./adjust-gain.py WS_URL PASSWORD [TX_GAIN RX_GAIN]")
exit(1)
asyncio.run(adjust_gain(*sys.argv[1:]))
import asyncio
import hmac
import hashlib
import json
import sys
import time
import websockets
channel_count = 2
async def get_spl(uri, password):
async with websockets.connect(uri, origin="Test") as websocket:
rsp = await websocket.recv()
data = json.loads(rsp)
res = hmac.new(
"{}:{}:{}".format(data['type'], password, data['name']).encode(),
msg=data['challenge'].encode(),
digestmod=hashlib.sha256
).hexdigest()
msg = f'{{"message":"authenticate", "res": "{res}"}}'
await websocket.send(msg)
rsp = await websocket.recv()
while True:
l = []
for i in range(channel_count):
l.append('{:^17}'.format(f'--P0/TX {i}--'))
for i in range(channel_count):
l.append('{:^17}'.format(f'--P0/RX {i}--'))
print(' '.join(l))
print(('{:^8} {:^8}'.format('RMS', 'MAX')) * 4)
for i in range(10):
time.sleep(1)
msg = f'{{"message":"stats", "samples": true}}'
await websocket.send(msg)
rsp = await websocket.recv()
samples = json.loads(rsp)['samples']
l = []
for i in range(channel_count):
tx = samples['tx']
l.append('{:^8.3f} {:^8.3f}'.format(tx[i]['rms'], tx[i]['max']))
for i in range(channel_count):
rx = samples['rx']
l.append('{:^8.3f} {:^8.3f}'.format(rx[i]['rms'], rx[i]['max']))
print(' '.join(l))
if len(sys.argv) != 3:
print("Usage: ./adjust-gain.py WS_URL PASSWORD")
exit(1)
asyncio.run(get_spl(*sys.argv[1:]))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment