Exemplo n.º 1
0
class Period(object):
    """Period.
  
  Statistics on the period of observations received from the base
station. As complete observation sets are received, their time
of reception is compared with the prior set''s time of reception.
This measurement provides a proxy for link quality as incomplete
or missing sets will increase the period.  Long periods
can cause momentary RTK solution outages.

  
  Parameters
  ----------
  avg : int
    Average period
  pmin : int
    Minimum period
  pmax : int
    Maximum period
  current : int
    Smoothed estimate of the current period

  """
    _parser = construct.Embedded(
        construct.Struct(
            'avg' / construct.Int32sl,
            'pmin' / construct.Int32sl,
            'pmax' / construct.Int32sl,
            'current' / construct.Int32sl,
        ))
    __slots__ = [
        'avg',
        'pmin',
        'pmax',
        'current',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.avg = kwargs.pop('avg')
            self.pmin = kwargs.pop('pmin')
            self.pmax = kwargs.pop('pmax')
            self.current = kwargs.pop('current')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = Period._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return Period.build(d)
Exemplo n.º 2
0
class Latency(object):
    """Latency.
  
  Statistics on the latency of observations received from the base
station. As observation packets are received their GPS time is
compared to the current GPS time calculated locally by the
receiver to give a precise measurement of the end-to-end
communication latency in the system.

  
  Parameters
  ----------
  avg : int
    Average latency
  lmin : int
    Minimum latency
  lmax : int
    Maximum latency
  current : int
    Smoothed estimate of the current latency

  """
    _parser = construct.Embedded(
        construct.Struct(
            'avg' / construct.Int32sl,
            'lmin' / construct.Int32sl,
            'lmax' / construct.Int32sl,
            'current' / construct.Int32sl,
        ))
    __slots__ = [
        'avg',
        'lmin',
        'lmax',
        'current',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.avg = kwargs.pop('avg')
            self.lmin = kwargs.pop('lmin')
            self.lmax = kwargs.pop('lmax')
            self.current = kwargs.pop('current')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = Latency._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return Latency.build(d)
Exemplo n.º 3
0
class GPSTime(object):
    """GPSTime.
  
  A wire-appropriate receiver clock time, defined as the time
since the beginning of the week on the Saturday/Sunday
transition. In most cases, observations are epoch aligned
so ns field will be 0.

  
  Parameters
  ----------
  tow : int
    Milliseconds since start of GPS week
  ns_residual : int
    Nanosecond residual of millisecond-rounded TOW (ranges
from -500000 to 500000)

  wn : int
    GPS week number

  """
    _parser = construct.Embedded(
        construct.Struct(
            'tow' / construct.Int32ul,
            'ns_residual' / construct.Int32sl,
            'wn' / construct.Int16ul,
        ))
    __slots__ = [
        'tow',
        'ns_residual',
        'wn',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.tow = kwargs.pop('tow')
            self.ns_residual = kwargs.pop('ns_residual')
            self.wn = kwargs.pop('wn')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GPSTime._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GPSTime.build(d)
Exemplo n.º 4
0
class GnssSignalDep(object):
    """GnssSignalDep.
  
  Deprecated.
  
  Parameters
  ----------
  sat : int
    Constellation-specific satellite identifier.

Note: unlike GnssSignal, GPS satellites are encoded as
(PRN - 1). Other constellations do not have this offset.

  code : int
    Signal constellation, band and code
  reserved : int
    Reserved

  """
    _parser = construct.Embedded(
        construct.Struct(
            'sat' / construct.Int16ul,
            'code' / construct.Int8ul,
            'reserved' / construct.Int8ul,
        ))
    __slots__ = [
        'sat',
        'code',
        'reserved',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sat = kwargs.pop('sat')
            self.code = kwargs.pop('code')
            self.reserved = kwargs.pop('reserved')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GnssSignalDep._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GnssSignalDep.build(d)
Exemplo n.º 5
0
class GridElement(object):
    """GridElement.
  
  Contains one tropo delay (mean and stddev), plus STEC residuals (mean and
stddev) for each satellite at the grid point.

  
  Parameters
  ----------
  index : int
    Index of the grid point
  tropo_delay_correction : TroposphericDelayCorrection
    Wet and hydrostatic vertical delays (mean, stddev)
  stec_residuals : array
    STEC residuals for each satellite (mean, stddev)

  """
    _parser = construct.Embedded(
        construct.Struct(
            'index' / construct.Int16ul,
            'tropo_delay_correction' /
            construct.Struct(TroposphericDelayCorrection._parser),
            construct.GreedyRange('stec_residuals' /
                                  construct.Struct(STECResidual._parser)),
        ))
    __slots__ = [
        'index',
        'tropo_delay_correction',
        'stec_residuals',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.index = kwargs.pop('index')
            self.tropo_delay_correction = kwargs.pop('tropo_delay_correction')
            self.stec_residuals = kwargs.pop('stec_residuals')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GridElement._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GridElement.build(d)
Exemplo n.º 6
0
class STECSatElement(object):
    """STECSatElement.
  
  STEC polynomial for the given satellite.
  
  Parameters
  ----------
  sv_id : SvId
    Unique space vehicle identifier
  stec_quality_indicator : int
    Quality of the STEC data. Encoded following RTCM DF389 specifcation
but in units of TECU instead of m.

  stec_coeff : array
    Coefficents of the STEC polynomial in the order of C00, C01, C10, C11


  """
    _parser = construct.Embedded(
        construct.Struct(
            'sv_id' / construct.Struct(SvId._parser),
            'stec_quality_indicator' / construct.Int8ul,
            'stec_coeff' / construct.Array(4, construct.Int16sl),
        ))
    __slots__ = [
        'sv_id',
        'stec_quality_indicator',
        'stec_coeff',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sv_id = kwargs.pop('sv_id')
            self.stec_quality_indicator = kwargs.pop('stec_quality_indicator')
            self.stec_coeff = kwargs.pop('stec_coeff')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = STECSatElement._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return STECSatElement.build(d)
Exemplo n.º 7
0
class TrackingChannelState(object):
    """TrackingChannelState.
  
  Tracking channel state for a specific satellite signal and
measured signal power.

  
  Parameters
  ----------
  sid : GnssSignal
    GNSS signal being tracked
  fcn : int
    Frequency channel number (GLONASS only)
  cn0 : int
    Carrier-to-Noise density.  Zero implies invalid cn0.

  """
    _parser = construct.Embedded(
        construct.Struct(
            'sid' / construct.Struct(GnssSignal._parser),
            'fcn' / construct.Int8ul,
            'cn0' / construct.Int8ul,
        ))
    __slots__ = [
        'sid',
        'fcn',
        'cn0',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sid = kwargs.pop('sid')
            self.fcn = kwargs.pop('fcn')
            self.cn0 = kwargs.pop('cn0')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = TrackingChannelState._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return TrackingChannelState.build(d)
Exemplo n.º 8
0
class TroposphericDelayCorrection(object):
    """TroposphericDelayCorrection.
  
  Troposphere vertical delays (mean and standard deviation) at the grid
point.

  
  Parameters
  ----------
  hydro : int
    Hydrostatic vertical delay
  wet : int
    Wet vertical delay
  stddev : int
    stddev

  """
    _parser = construct.Embedded(
        construct.Struct(
            'hydro' / construct.Int16sl,
            'wet' / construct.Int8sl,
            'stddev' / construct.Int8ul,
        ))
    __slots__ = [
        'hydro',
        'wet',
        'stddev',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.hydro = kwargs.pop('hydro')
            self.wet = kwargs.pop('wet')
            self.stddev = kwargs.pop('stddev')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = TroposphericDelayCorrection._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return TroposphericDelayCorrection.build(d)
Exemplo n.º 9
0
class STECResidual(object):
    """STECResidual.
  
  STEC residual (mean and standard deviation) for the given satellite
at the grid point,

  
  Parameters
  ----------
  sv_id : SvId
    space vehicle identifier
  residual : int
    STEC residual
  stddev : int
    stddev

  """
    _parser = construct.Embedded(
        construct.Struct(
            'sv_id' / construct.Struct(SvId._parser),
            'residual' / construct.Int16sl,
            'stddev' / construct.Int8ul,
        ))
    __slots__ = [
        'sv_id',
        'residual',
        'stddev',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sv_id = kwargs.pop('sv_id')
            self.residual = kwargs.pop('residual')
            self.stddev = kwargs.pop('stddev')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = STECResidual._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return STECResidual.build(d)
Exemplo n.º 10
0
class SubSystemReport(object):
    """SubSystemReport.
  
  Report the general and specific state of a sub-system.  If the generic
state is reported as initializing, the specific state should be ignored.

  
  Parameters
  ----------
  component : int
    Identity of reporting subsystem
  generic : int
    Generic form status report
  specific : int
    Subsystem specific status code

  """
    _parser = construct.Embedded(
        construct.Struct(
            'component' / construct.Int16ul,
            'generic' / construct.Int8ul,
            'specific' / construct.Int8ul,
        ))
    __slots__ = [
        'component',
        'generic',
        'specific',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.component = kwargs.pop('component')
            self.generic = kwargs.pop('generic')
            self.specific = kwargs.pop('specific')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = SubSystemReport._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return SubSystemReport.build(d)
Exemplo n.º 11
0
class SolutionInputType(object):
    """SolutionInputType.
  
  Metadata describing which sensors were involved in the solution.
The structure is fixed no matter what the actual sensor type is.
The sensor_type field tells you which sensor we are talking about. It also tells you
whether the sensor data was actually used or not.
The flags field, always a u8, contains the sensor-specific data.
The content of flags, for each sensor type, is described in the relevant structures in this section.

  
  Parameters
  ----------
  sensor_type : int
    The type of sensor
  flags : int
    Refer to each InputType description

  """
    _parser = construct.Embedded(
        construct.Struct(
            'sensor_type' / construct.Int8ul,
            'flags' / construct.Int8ul,
        ))
    __slots__ = [
        'sensor_type',
        'flags',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sensor_type = kwargs.pop('sensor_type')
            self.flags = kwargs.pop('flags')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = SolutionInputType._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return SolutionInputType.build(d)
Exemplo n.º 12
0
class TrackingChannelStateDepB(object):
    """TrackingChannelStateDepB.
  
  Deprecated.
  
  Parameters
  ----------
  state : int
    Status of tracking channel
  sid : GnssSignalDep
    GNSS signal being tracked
  cn0 : float
    Carrier-to-noise density

  """
    _parser = construct.Embedded(
        construct.Struct(
            'state' / construct.Int8ul,
            'sid' / construct.Struct(GnssSignalDep._parser),
            'cn0' / construct.Float32l,
        ))
    __slots__ = [
        'state',
        'sid',
        'cn0',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.state = kwargs.pop('state')
            self.sid = kwargs.pop('sid')
            self.cn0 = kwargs.pop('cn0')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = TrackingChannelStateDepB._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return TrackingChannelStateDepB.build(d)
Exemplo n.º 13
0
class MeasurementState(object):
    """MeasurementState.
  
  Measurement Engine tracking channel state for a specific satellite signal 
and measured signal power. 
The mesid field for Glonass can either 
carry the FCN as 100 + FCN where FCN is in [-7, +6] or 
the Slot ID (from 1 to 28)

  
  Parameters
  ----------
  mesid : GnssSignal
    Measurement Engine GNSS signal being tracked (carries either Glonass FCN or SLOT)
  cn0 : int
    Carrier-to-Noise density.  Zero implies invalid cn0.

  """
    _parser = construct.Embedded(
        construct.Struct(
            'mesid' / construct.Struct(GnssSignal._parser),
            'cn0' / construct.Int8ul,
        ))
    __slots__ = [
        'mesid',
        'cn0',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.mesid = kwargs.pop('mesid')
            self.cn0 = kwargs.pop('cn0')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = MeasurementState._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return MeasurementState.build(d)
Exemplo n.º 14
0
class GnssSignal(object):
    """GnssSignal.
  
  Signal identifier containing constellation, band, and satellite identifier

  
  Parameters
  ----------
  sat : int
    Constellation-specific satellite identifier. This field for Glonass can  
either be (100+FCN) where FCN is in [-7,+6] or 
the Slot ID in [1,28]

  code : int
    Signal constellation, band and code

  """
    _parser = construct.Embedded(
        construct.Struct(
            'sat' / construct.Int8ul,
            'code' / construct.Int8ul,
        ))
    __slots__ = [
        'sat',
        'code',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.sat = kwargs.pop('sat')
            self.code = kwargs.pop('code')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GnssSignal._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GnssSignal.build(d)
Exemplo n.º 15
0
class CarrierPhase(object):
    """CarrierPhase.
  
  Carrier phase measurement in cycles represented as a 40-bit
fixed point number with Q32.8 layout, i.e. 32-bits of whole
cycles and 8-bits of fractional cycles. This phase has the
same sign as the pseudorange.

  
  Parameters
  ----------
  i : int
    Carrier phase whole cycles
  f : int
    Carrier phase fractional part

  """
    _parser = construct.Embedded(
        construct.Struct(
            'i' / construct.Int32sl,
            'f' / construct.Int8ul,
        ))
    __slots__ = [
        'i',
        'f',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.i = kwargs.pop('i')
            self.f = kwargs.pop('f')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = CarrierPhase._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return CarrierPhase.build(d)
Exemplo n.º 16
0
class GPSTimeSec(object):
    """GPSTimeSec.
  
  A GPS time, defined as the number of
seconds since beginning of the week on the Saturday/Sunday
transition.

  
  Parameters
  ----------
  tow : int
    Seconds since start of GPS week
  wn : int
    GPS week number

  """
    _parser = construct.Embedded(
        construct.Struct(
            'tow' / construct.Int32ul,
            'wn' / construct.Int16ul,
        ))
    __slots__ = [
        'tow',
        'wn',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.tow = kwargs.pop('tow')
            self.wn = kwargs.pop('wn')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GPSTimeSec._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GPSTimeSec.build(d)
Exemplo n.º 17
0
class CodeBiasesContent(object):
    """CodeBiasesContent.
  
  Code biases are to be added to pseudorange.
The corrections conform with typical RTCMv3 MT1059 and 1065.

  
  Parameters
  ----------
  code : int
    Signal constellation, band and code
  value : int
    Code bias value

  """
    _parser = construct.Embedded(
        construct.Struct(
            'code' / construct.Int8ul,
            'value' / construct.Int16sl,
        ))
    __slots__ = [
        'code',
        'value',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.code = kwargs.pop('code')
            self.value = kwargs.pop('value')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = CodeBiasesContent._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return CodeBiasesContent.build(d)
Exemplo n.º 18
0
class SvId(object):
    """SvId.
  
  A (Constellation ID, satellite ID) tuple that uniquely identifies
a space vehicle

  
  Parameters
  ----------
  satId : int
    ID of the space vehicle within its constellation
  constellation : int
    Constellation ID to which the SV belongs

  """
    _parser = construct.Embedded(
        construct.Struct(
            'satId' / construct.Int8ul,
            'constellation' / construct.Int8ul,
        ))
    __slots__ = [
        'satId',
        'constellation',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.satId = kwargs.pop('satId')
            self.constellation = kwargs.pop('constellation')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = SvId._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return SvId.build(d)
Exemplo n.º 19
0
class TrackingChannelCorrelation(object):
    """TrackingChannelCorrelation.
  
  Structure containing in-phase and quadrature correlation components.

  
  Parameters
  ----------
  I : int
    In-phase correlation
  Q : int
    Quadrature correlation

  """
    _parser = construct.Embedded(
        construct.Struct(
            'I' / construct.Int32sl,
            'Q' / construct.Int32sl,
        ))
    __slots__ = [
        'I',
        'Q',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.I = kwargs.pop('I')
            self.Q = kwargs.pop('Q')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = TrackingChannelCorrelation._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return TrackingChannelCorrelation.build(d)
Exemplo n.º 20
0
class OdoInputType(object):
    """OdoInputType.
  
  Metadata around the Odometry sensors involved in the fuzed solution.
Accessible through sol_in[N].flags in a MSG_SOLN_META.

  
  Parameters
  ----------
  flags : int
    Instrument ODO rate, grade, and quality.

  """
    _parser = construct.Embedded(construct.Struct('flags' /
                                                  construct.Int8ul, ))
    __slots__ = [
        'flags',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.flags = kwargs.pop('flags')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = OdoInputType._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return OdoInputType.build(d)
Exemplo n.º 21
0
class GNSSInputType(object):
    """GNSSInputType.
  
  Metadata around the GNSS sensors involved in the fuzed solution.
Accessible through sol_in[N].flags in a MSG_SOLN_META.

  
  Parameters
  ----------
  flags : int
    flags that store all relevant info specific to this sensor type.

  """
    _parser = construct.Embedded(construct.Struct('flags' /
                                                  construct.Int8ul, ))
    __slots__ = [
        'flags',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.flags = kwargs.pop('flags')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GNSSInputType._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GNSSInputType.build(d)
Exemplo n.º 22
0
    "cam_multiplier_limit" / construct.Int16ub,
    construct.Padding(2)
)
header_cmd2 = construct.Struct(
    'JDN_base' / construct.Int16ul,
    construct.Padding(2),
    'seconds' / construct.Int32ul
)
header = construct.Struct(
    'packet_type' / construct.Int16ul,
    'cmd_id' / construct.Int16ul,
    'payload_size' / construct.Int16ul,
    'seq_id' / construct.Int16ul,
    construct.Embedded(
        construct.Switch(lambda ctx: ctx.cmd_id,
                         {
                             0: construct.If(
                                 lambda ctx: ctx.payload_size >= header_cmd0.sizeof(),
                                 header_cmd0),
                             1: construct.If(
                                 lambda ctx: ctx.payload_size == header_cmd1.sizeof(),
                                 header_cmd1),
                             2: construct.If(
                                 lambda ctx: ctx.payload_size == header_cmd2.sizeof(),
                                 header_cmd2)
                         },
                         default=construct.Pass
                         )
    )
)
Exemplo n.º 23
0
class PhaseBiasesContent(object):
    """PhaseBiasesContent.
  
  Phase biases are to be added to carrier phase measurements.
The corrections conform with typical RTCMv3 MT1059 and 1065.

  
  Parameters
  ----------
  code : int
    Signal constellation, band and code
  integer_indicator : int
    Indicator for integer property
  widelane_integer_indicator : int
    Indicator for two groups of Wide-Lane(s) integer property
  discontinuity_counter : int
    Signal phase discontinuity counter.
Increased for every discontinuity in phase.

  bias : int
    Phase bias for specified signal

  """
    _parser = construct.Embedded(
        construct.Struct(
            'code' / construct.Int8ul,
            'integer_indicator' / construct.Int8ul,
            'widelane_integer_indicator' / construct.Int8ul,
            'discontinuity_counter' / construct.Int8ul,
            'bias' / construct.Int32sl,
        ))
    __slots__ = [
        'code',
        'integer_indicator',
        'widelane_integer_indicator',
        'discontinuity_counter',
        'bias',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.code = kwargs.pop('code')
            self.integer_indicator = kwargs.pop('integer_indicator')
            self.widelane_integer_indicator = kwargs.pop(
                'widelane_integer_indicator')
            self.discontinuity_counter = kwargs.pop('discontinuity_counter')
            self.bias = kwargs.pop('bias')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = PhaseBiasesContent._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return PhaseBiasesContent.build(d)
Exemplo n.º 24
0
class GridDefinitionHeader(object):
    """GridDefinitionHeader.
  
  Defines the grid for MSG_SSR_GRIDDED_CORRECTION messages.
Also includes an RLE encoded validity list.

  
  Parameters
  ----------
  region_size_inverse : int
    region_size (deg) = 10 / region_size_inverse
0 is an invalid value.

  area_width : int
    grid height (deg) = grid idth (deg) = area_width / region_size
0 is an invalid value.

  lat_nw_corner_enc : int
    North-West corner latitdue (deg) = region_size * lat_nw_corner_enc - 90
  lon_nw_corner_enc : int
    North-West corner longtitude (deg) = region_size * lon_nw_corner_enc - 180
  num_msgs : int
    Number of messages in the dataset
  seq_num : int
    Postion of this message in the dataset

  """
    _parser = construct.Embedded(
        construct.Struct(
            'region_size_inverse' / construct.Int8ul,
            'area_width' / construct.Int16ul,
            'lat_nw_corner_enc' / construct.Int16ul,
            'lon_nw_corner_enc' / construct.Int16ul,
            'num_msgs' / construct.Int8ul,
            'seq_num' / construct.Int8ul,
        ))
    __slots__ = [
        'region_size_inverse',
        'area_width',
        'lat_nw_corner_enc',
        'lon_nw_corner_enc',
        'num_msgs',
        'seq_num',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.region_size_inverse = kwargs.pop('region_size_inverse')
            self.area_width = kwargs.pop('area_width')
            self.lat_nw_corner_enc = kwargs.pop('lat_nw_corner_enc')
            self.lon_nw_corner_enc = kwargs.pop('lon_nw_corner_enc')
            self.num_msgs = kwargs.pop('num_msgs')
            self.seq_num = kwargs.pop('seq_num')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GridDefinitionHeader._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GridDefinitionHeader.build(d)
Exemplo n.º 25
0
Tauth = construct.Struct(
    "size" / SizeField,
    "type" / construct.Const(MessageType.Tauth.value, TypeField),
    "tag" / TagField,
    "afid" / FidField,
    "uname" / StringField,
    "aname" / StringField
)

# size[4] Rauth tag[2] aqid[13]
Rauth = construct.Struct(
    "size" / SizeField,
    "type" / construct.Const(MessageType.Rauth.value, TypeField),
    "tag" / TagField,
    "aqid" / construct.Embedded(
        QidField
    )
)

# size[4] Rerror tag[2] ename[s]
Rerror = construct.Struct(
    "size" / SizeField,
    "type" / construct.Const(MessageType.Rerror.value, TypeField),
    "tag" / TagField,
    "ename" / StringField * "error name"
) * "error response"

# size[4] Tflush tag[2] oldtag[2]
Tflush = construct.Struct(
    "size" / SizeField,
    "type" / construct.Const(MessageType.Tflush.value, TypeField),
Exemplo n.º 26
0
class AcqSvProfile(object):
    """AcqSvProfile.
  
  Profile for a specific SV for debugging purposes
The message describes SV profile during acquisition time.
The message is used to debug and measure the performance.

  
  Parameters
  ----------
  job_type : int
    SV search job type (deep, fallback, etc)
  status : int
    Acquisition status 1 is Success, 0 is Failure
  cn0 : int
    CN0 value. Only valid if status is '1'
  int_time : int
    Acquisition integration time
  sid : GnssSignal
    GNSS signal for which acquisition was attempted
  bin_width : int
    Acq frequency bin width
  timestamp : int
    Timestamp of the job complete event
  time_spent : int
    Time spent to search for sid.code
  cf_min : int
    Doppler range lowest frequency
  cf_max : int
    Doppler range highest frequency
  cf : int
    Doppler value of detected peak. Only valid if status is '1'
  cp : int
    Codephase of detected peak. Only valid if status is '1'

  """
    _parser = construct.Embedded(
        construct.Struct(
            'job_type' / construct.Int8ul,
            'status' / construct.Int8ul,
            'cn0' / construct.Int16ul,
            'int_time' / construct.Int8ul,
            'sid' / construct.Struct(GnssSignal._parser),
            'bin_width' / construct.Int16ul,
            'timestamp' / construct.Int32ul,
            'time_spent' / construct.Int32ul,
            'cf_min' / construct.Int32sl,
            'cf_max' / construct.Int32sl,
            'cf' / construct.Int32sl,
            'cp' / construct.Int32ul,
        ))
    __slots__ = [
        'job_type',
        'status',
        'cn0',
        'int_time',
        'sid',
        'bin_width',
        'timestamp',
        'time_spent',
        'cf_min',
        'cf_max',
        'cf',
        'cp',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.job_type = kwargs.pop('job_type')
            self.status = kwargs.pop('status')
            self.cn0 = kwargs.pop('cn0')
            self.int_time = kwargs.pop('int_time')
            self.sid = kwargs.pop('sid')
            self.bin_width = kwargs.pop('bin_width')
            self.timestamp = kwargs.pop('timestamp')
            self.time_spent = kwargs.pop('time_spent')
            self.cf_min = kwargs.pop('cf_min')
            self.cf_max = kwargs.pop('cf_max')
            self.cf = kwargs.pop('cf')
            self.cp = kwargs.pop('cp')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = AcqSvProfile._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return AcqSvProfile.build(d)
Exemplo n.º 27
0
class GriddedCorrectionHeader(object):
    """GriddedCorrectionHeader.
  
  The 3GPP message contains nested variable length arrays
which are not suppported in SBP, so each grid point will
be identified by the index.

  
  Parameters
  ----------
  time : GPSTimeSec
    GNSS reference time of the correction
  num_msgs : int
    Number of messages in the dataset
  seq_num : int
    Position of this message in the dataset
  update_interval : int
    Update interval between consecutive corrections. Encoded
following RTCM DF391 specification.

  iod_atmo : int
    IOD of the SSR atmospheric correction

  tropo_quality_indicator : int
    Quality of the troposphere data. Encoded following RTCM DF389
specifcation in units of m.


  """
    _parser = construct.Embedded(
        construct.Struct(
            'time' / construct.Struct(GPSTimeSec._parser),
            'num_msgs' / construct.Int16ul,
            'seq_num' / construct.Int16ul,
            'update_interval' / construct.Int8ul,
            'iod_atmo' / construct.Int8ul,
            'tropo_quality_indicator' / construct.Int8ul,
        ))
    __slots__ = [
        'time',
        'num_msgs',
        'seq_num',
        'update_interval',
        'iod_atmo',
        'tropo_quality_indicator',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.time = kwargs.pop('time')
            self.num_msgs = kwargs.pop('num_msgs')
            self.seq_num = kwargs.pop('seq_num')
            self.update_interval = kwargs.pop('update_interval')
            self.iod_atmo = kwargs.pop('iod_atmo')
            self.tropo_quality_indicator = kwargs.pop(
                'tropo_quality_indicator')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = GriddedCorrectionHeader._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return GriddedCorrectionHeader.build(d)
Exemplo n.º 28
0
class STECHeader(object):
    """STECHeader.
  
  A full set of STEC information will likely span multiple SBP
messages, since SBP message a limited to 255 bytes.  The header
is used to tie multiple SBP messages into a sequence.

  
  Parameters
  ----------
  time : GPSTimeSec
    GNSS reference time of the correction
  num_msgs : int
    Number of messages in the dataset
  seq_num : int
    Position of this message in the dataset
  update_interval : int
    Update interval between consecutive corrections. Encoded
following RTCM DF391 specification.

  iod_atmo : int
    IOD of the SSR atmospheric correction


  """
    _parser = construct.Embedded(
        construct.Struct(
            'time' / construct.Struct(GPSTimeSec._parser),
            'num_msgs' / construct.Int8ul,
            'seq_num' / construct.Int8ul,
            'update_interval' / construct.Int8ul,
            'iod_atmo' / construct.Int8ul,
        ))
    __slots__ = [
        'time',
        'num_msgs',
        'seq_num',
        'update_interval',
        'iod_atmo',
    ]

    def __init__(self, payload=None, **kwargs):
        if payload:
            self.from_binary(payload)
        else:
            self.time = kwargs.pop('time')
            self.num_msgs = kwargs.pop('num_msgs')
            self.seq_num = kwargs.pop('seq_num')
            self.update_interval = kwargs.pop('update_interval')
            self.iod_atmo = kwargs.pop('iod_atmo')

    def __repr__(self):
        return fmt_repr(self)

    def from_binary(self, d):
        p = STECHeader._parser.parse(d)
        for n in self.__class__.__slots__:
            setattr(self, n, getattr(p, n))

    def to_binary(self):
        d = dict([(k, getattr(obj, k)) for k in self.__slots__])
        return STECHeader.build(d)
Exemplo n.º 29
0
class Game:
    command_id = namedtuple("packet_type",
                            ("register", "error", "update", "start", "state"))(
                                register=0,
                                error=1,
                                update=2,
                                start=3,
                                state=4)
    players_struct = construct.Struct("x" / construct.Int16ul,
                                      "y" / construct.Int16ul,
                                      "score" / construct.Int8ul,
                                      "active" / construct.Int8ul)
    command_state = construct.Struct(
        "puck_x" / construct.Int16ul, "puck_y" / construct.Int16ul,
        "players" / construct.Array(4, players_struct))
    command_update = construct.Struct("x" / construct.Int16ul,
                                      "y" / construct.Int16ul)
    command_register = construct.Struct("id" / construct.String(36))
    command = construct.Struct(
        "type" / construct.Int8ul,
        construct.Embedded(
            construct.Switch(lambda ctx: ctx.type, {
                command_id.update: command_update,
                command_id.register: command_register,
                command_id.state: command_state,
            },
                             default=construct.Pass)))

    def __init__(self):
        self.sockets = []
        self.redis = rredis.from_url(os.environ.get("REDIS_URL"))

    def add_state_socket(self, ws):
        sock = ClientSocket(ws)
        data = sock.receive()
        if data:
            data = self.command.parse(data)
        if data and data.type == self.command_id.register:
            sock.set_id(data.id)
            self.sockets.append(sock)
        else:
            sock.close()

    def update(self):
        while True:
            games = ast.literal_eval(self.redis.get("games"))
            self.update_games(games)
            # Send states
            for ws in list(self.sockets):
                # Clear inactive sockets
                if ws.is_closed():
                    for game in list(games):
                        for player in range(0, len(game["players"])):
                            if game["players"][player]["id"] == ws.get_id():
                                game["players"][player]["id"] = None
                                game["players"][player]["active"] = 0
                        if self.active_players(game["players"]) == 0:
                            games.remove(game)
                    self.sockets.remove(ws)
                    continue
                # Send state
                for game in games:
                    for player in game["players"]:
                        if player["id"] == ws.get_id():
                            ws.send(self.build_state_packet(game), True)
            self.redis.set("games", games)
            gevent.sleep(0.05)

    @staticmethod
    def update_games(games):
        if len(games):
            games[0]["puck"]["x"] += 1

    def start(self):
        self.redis.set("games", [])
        gevent.spawn(self.update)

    def add_request_socket(self, ws):
        sock = ClientSocket(ws)
        while not sock.is_closed():
            data = sock.receive()
            if not data:
                sock.close()
                return
            data = self.command.parse(data)
            # Register
            if data and data.type == self.command_id.register and sock.get_id(
            ) is None:
                client_id = self.get_new_client_id()
                sock.set_id(client_id)
                if client_id:
                    sock.send(
                        self.command.build(
                            dict(type=self.command_id.register, id=client_id)),
                        True)
                else:
                    sock.send(
                        self.command.build(dict(type=self.command_id.error)),
                        True)
            # Position Update
            elif data.type == self.command_id.update:
                self.update_player_position(sock.client_id, data.x, data.y)

    def get_new_client_id(self):
        games = ast.literal_eval(self.redis.get("games"))
        new_player_id = str(uuid.uuid4())
        # Make sure the id is unique
        for game in games:
            for player in game["players"]:
                if player["id"] == new_player_id:
                    return self.get_new_client_id()
        # Find an open game
        found_game = False
        for game in games:
            if self.active_players(game["players"]) < 4:
                found_game = True
                # Add player to game
                for player in range(0, len(game["players"])):
                    if game["players"][player]["active"] == 0:
                        game["players"][player]["id"] = new_player_id
                        game["players"][player]["active"] = 1
                        break
                # Check if game can start
                if self.active_players(game["players"]) == 4:
                    for player in game["players"]:
                        for sock in self.sockets:
                            if sock.get_id() == player["id"]:
                                sock.send(
                                    self.command.build(
                                        dict(type=self.command_id.start)),
                                    True)
        # Create game if an open one was not found
        if not found_game:
            game = {"players": [], "puck": {"x": 0, "y": 0}}
            for player_num in range(0, 4):
                game["players"].append({
                    "id": None,
                    "x": 0,
                    "y": 0,
                    "score": 0,
                    "active": 0
                })
            game["players"][0]["id"] = new_player_id
            game["players"][0]["active"] = 1
            games.append(game)
        self.redis.set("games", games)
        return new_player_id

    def build_state_packet(self, game):
        state = dict(type=self.command_id.state,
                     puck_x=game["puck"]["x"],
                     puck_y=game["puck"]["y"],
                     players=game["players"])
        return self.command.build(state)

    def update_player_position(self, client_id, x, y):
        games = ast.literal_eval(self.redis.get("games"))
        for game in games:
            for player in game["players"]:
                if player["id"] == client_id:
                    player["x"] = x
                    player["y"] = y
        self.redis.set("games", games)

    @staticmethod
    def active_players(players):
        count = 0
        for player in players:
            if player["active"] == 1:
                count += 1
        return count
Exemplo n.º 30
0
 construct.Embedded(
     construct.Switch(
         'block',
         lambda ctx: ctx.block_start,
         {
             0x3B:
             construct.Struct(
                 # workaround for Pass not working
                 'terminator',
                 construct.Value('terminator',
                                 lambda ctx: 'terminator'),
             ),
             0x2C:
             _image_block,
             0x21:
             construct.Struct(
                 'ext',
                 construct.ULInt8('ext_label'),
                 construct.Embedded(
                     construct.Switch(
                         'extension',
                         lambda ctx: ctx.ext_label,
                         {
                             0xFF: _application_extension,
                             0xFE: _comment_extension,
                             0xF9: _gce_extension,
                         },
                         default=_unknown_extension,
                     ), ),
             ),
         },
     ), ),