Skip to content

Commit

Permalink
Merge pull request mayeranalytics#18 from ArrEssJay/ubx-mon-span
Browse files Browse the repository at this point in the history
Support UBX-MON-SPAN
  • Loading branch information
Mayer Analytics authored Oct 8, 2020
2 parents 4276ffa + 2da2565 commit 44ccd88
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
8 changes: 8 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def testRXM(self):
self.assertEqual(rxm.reserved1, 0x48)
self.assertEqual(rxm.lpMode, 0x01)

def testMON_SPAN(self):
# F9P data payload
payload = b'\x00\x02\x00\x00\x39\x37\x37\x3A\x3A\x39\x39\x39\x39\x38\x38\x39\x39\x39\x3B\x3B\x3A\x3A\x39\x3B\x3F\x3C\x3D\x3E\x3C\x3D\x3F\x3F\x45\x3E\x40\x43\x66\x43\x55\x43\x47\x47\x44\x47\x49\x47\x4B\x48\x50\x47\x4C\x4E\x4F\x51\x56\x57\x5B\x5D\x60\x61\x66\x67\x69\x6C\x6E\x6F\x75\x73\x79\x79\x7A\x7D\x7E\x80\x83\x85\x86\x88\x87\x88\x8C\x8D\x8C\x8F\x92\x94\x95\x94\x93\x90\x8F\x8F\x8F\x8E\x8E\x90\x90\x8F\x8E\x8F\x91\x90\x92\x91\x93\x92\x91\x93\x94\x93\x94\x95\x99\x9E\xA3\xA6\xA5\xA0\x99\x96\x98\x98\x97\x97\x95\x97\x97\x97\x95\x94\x94\x99\x95\x94\x93\x92\x93\x9C\x93\x92\x92\x92\x94\x96\x97\x96\x95\x92\x90\x90\x8C\x8C\x8C\x8C\x8B\x8C\x8B\x8A\x8C\x8B\x8A\x8A\x8B\x8A\x8B\x8C\x8B\x8E\x8C\x8A\x89\x8B\x8B\x89\x89\x88\x87\x87\x85\x87\x86\x86\x84\x84\x84\x82\x82\x80\x80\x7E\x7D\x79\x79\x77\x75\x71\x71\x6E\x6D\x69\x65\x62\x5F\x5C\x57\x54\x52\x50\x4D\x4B\x4C\x4A\x4A\x49\x47\x47\x46\x45\x45\x42\x43\x42\x41\x41\x46\x40\x41\x3E\x42\x40\x40\x3D\x3D\x3D\x3D\x3C\x41\x3F\x3A\x3A\x39\x3A\x3A\x3A\x39\x39\x3A\x3A\x39\x38\x38\x3A\x39\x38\x38\x38\x39\x39\x38\x39\x00\x20\xA1\x07\x20\xA1\x07\x00\x82\xB3\x61\x5E\x33\x00\x00\x00\x34\x36\x33\x32\x36\x36\x36\x36\x36\x39\x38\x39\x39\x3A\x3B\x39\x3A\x42\x42\x41\x42\x40\x40\x41\x43\x49\x47\x46\x49\x47\x49\x4D\x4C\x51\x54\x51\x54\x57\x58\x5A\x5C\x5F\x5D\x60\x63\x64\x68\x68\x6B\x6C\x6E\x72\x73\x76\x78\x79\x7D\x7E\x81\x87\x84\x87\x88\x8A\x8B\x8C\x8E\x8E\x90\x91\x91\x94\x94\x95\x94\x96\x96\x97\x96\x96\x97\x97\x96\x99\x98\x99\x9A\x99\x99\x98\x99\x99\x9B\x9B\x9B\x99\x98\x97\x97\x96\x96\x96\x97\x94\x94\x94\x94\x94\x95\x94\x95\x94\x93\x96\x94\x94\x95\x95\x95\x96\x95\x95\x95\x95\x95\x94\x94\x91\x93\x94\x94\x93\x92\x97\x9C\x9A\x93\x92\x91\x91\x92\x91\x90\x91\x90\x8F\x8F\x90\x8F\x8F\x8E\x8E\x8C\x8E\x8F\x8D\x8E\x8D\x94\x8B\x8C\x8C\x8B\x8E\x8A\x89\x8B\x8B\x8B\x8C\x8D\x8B\x8B\x8A\x8B\x8A\x8B\x8A\x8B\x89\x8A\x89\x89\x88\x85\x86\x85\x84\x82\x81\x81\x7D\x7C\x7C\x79\x77\x74\x74\x71\x6E\x6C\x6A\x67\x66\x64\x61\x5F\x5E\x5B\x59\x57\x56\x56\x51\x50\x4E\x4D\x4B\x49\x49\x47\x44\x44\x43\x41\x3F\x3E\x3C\x3C\x3A\x3B\x3A\x38\x39\x37\x37\x38\x38\x37\x4A\x36\x35\x35\x34\x34\x34\x34\x33\x33\x32\x34\x33\x34\x33\x33\x32\x00\x20\xA1\x07\x20\xA1\x07\x00\x6A\xDA\xF4\x48\x2D\x00\x00\x00'
span=parseUBXPayload(UBX.MON._class, UBX.MON.SPAN._id, payload)
self.assertEqual(span.numRfBlocks, 2)
self.assertEqual(span.center_2, 1224006250)
self.assertEqual(span.spectra[1]['spectrumBinCenterFreqs'][0], 1160006250.0)

def testMON_VER(self):
payload = b'\x52\x4f\x4d\x20\x43\x4f\x52\x45\x20\x33\x2e\x30\x31\x20\x28\x31\x30\x37\x38\x38\x38\x29\x00\x00\x00\x00\x00\x00\x00\x00\x30\x30\x30\x38\x30\x30\x30\x30\x00\x00\x46\x57\x56\x45\x52\x3d\x53\x50\x47\x20\x33\x2e\x30\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x52\x4f\x54\x56\x45\x52\x3d\x31\x38\x2e\x30\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x47\x50\x53\x3b\x47\x4c\x4f\x3b\x47\x41\x4c\x3b\x42\x44\x53\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x53\x42\x41\x53\x3b\x49\x4d\x45\x53\x3b\x51\x5a\x53\x53\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
ver = parseUBXPayload(UBX.MON._class, UBX.MON.VER._id, payload)
Expand Down
1 change: 1 addition & 0 deletions ubx/Types.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class U:
fmt = None # Not needed
def __init__(self, _ord, N, allowed=[]):
self.ord = _ord
self._size = N
self.N = N
self.ctype = "uint8_t[{}]".format(self.N)
def parse(self, msg):
Expand Down
32 changes: 30 additions & 2 deletions ubx/UBX/MON.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Monitoring Messages: Communication Status, CPU Load, Stack Usage, Task Status. """

from ubx.UBXMessage import initMessageClass, addGet
from ubx.Types import CH, U1, U2, X1, X4

from ubx.Types import CH, U, U1, U2, U4, X1, X4

@initMessageClass
class MON:
Expand Down Expand Up @@ -45,3 +44,32 @@ class Fields:
pinIrq = X4(15) # Mask of Pins Value using the PIO Irq
pullH = X4(16) # Mask of Pins Value using the PIO Pull High Resistor
pullL = X4(17) # Mask of Pins Value using the PIO Pull Low Resistor

@addGet
class SPAN:
"""3.14.12.1 Signal Characteristics."""

_id = 0x31

class Fields:
version = U1(1, allowed={0: "SPAN Message V 0"}) # Message version (Currently 0)
numRfBlocks = U1(2) # Number of RF blocks included
reserved0 = U(3,2) # Reserved
class Repeated:
spectrum = U(1,256) # Spectrum Bins (dB unreferenced)
span = U4(2) # Spectrum span (Hz)
res = U4(3) # Bin Resolution (Hz)
center = U4(4) # Center of spectrum span (Hz)
pga = U1(5) # PGA gain (dB)
reserved1 = U(6,3) # Reserved

@property
def spectra(self):
return [{
"centerFreq": self.__getattribute__(f'center_{blockNum}'),
"span": self.__getattribute__(f'span_{blockNum}'),
"res": self.__getattribute__(f'res_{blockNum}'),
"pga": self.__getattribute__(f'pga_{blockNum}'),
"spectrumBinCenterFreqs": [ self.__getattribute__(f'center_{blockNum}') + self.__getattribute__(f'span_{blockNum}') * (i - 128) / 256 for i in range(256)],
"spectrum": [rfBin for rfBin in self.__getattribute__(f'spectrum_{blockNum}')]
} for blockNum in range(1,self.numRfBlocks+1) ]

0 comments on commit 44ccd88

Please sign in to comment.