Skip to content

Instantly share code, notes, and snippets.

@jhavard
Last active February 14, 2016 01:37
Show Gist options
  • Save jhavard/b58aad5b301a834e4a48 to your computer and use it in GitHub Desktop.
Save jhavard/b58aad5b301a834e4a48 to your computer and use it in GitHub Desktop.
Novra S300N Status Monitor
#!/awips2/python/bin/python
# This software is released into the public domain.
# If your jurisdiction does not recognize works
# released into the public domain, then this work
# is freely available to anyone for any reason,
# even if the original author finds that use
# morally abhorrent.
import s300
import sys
import time
n = s300.Novra()
while True:
sys.stdout.write("\x1B[2J\x1B[H")
_, _, _, _, freq, _, csr,lsr,isi,sig,cnr,addr = n.get_status()
print "CSR . . . :", csr
print "LSR . . . :", lsr
print "Signal . . :", sig
print "C/N . . . :", cnr
print time.ctime()
print addr
# This software is released into the public domain.
# If your jurisdiction does not recognize works
# released into the public domain, then this work
# is freely available to anyone for any reason,
# even if the original author finds that use
# morally abhorrent.
import socket
import struct
import time
import numpy
import sys
class Novra:
HOST = '0.0.0.0'
PORT = 6516
def __init__(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((self.HOST, self.PORT))
self.sock = s
def get_status(self):
data, addr = self.get_packet()
mac = "%02X:%02X:%02X:%02X:%02X:%02X" % struct.unpack('BBBBBB', data[4:10])
ip = "%d.%d.%d.%d" % struct.unpack('BBBB', data[10:14])
nm = "%d.%d.%d.%d" % struct.unpack('BBBB', data[14:18])
# wtf 9 and 10
# unicast status address
usa = "%d.%d.%d.%d" % struct.unpack('BBBB', data[22:26])
usp = struct.unpack('>H', data[26:28])[0]
bsp = struct.unpack('>H', data[28:30])[0]
freq = struct.unpack('>H', data[30:32])[0]
ferr = struct.unpack('>f', data[54:58])[0]
csr = struct.unpack('>H', data[36:38])[0]
isi = struct.unpack('>H', data[44:46])[0]
lsr = struct.unpack('>H', data[58:60])[0]
sig = struct.unpack('>h', data[78:80])[0]
cnr = float(struct.unpack('>H', data[80:82])[0]) / 10.0
return (mac, (ip, nm), (usa, usp), bsp, freq, ferr, csr,lsr,isi,sig,cnr, addr)
def get_packet(self):
s = self.sock
return s.recvfrom(512) # packets are 130 bytes long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment