示例#1
0
def get_limit_dict():
    limit_dict = defaultdict(dict)
    for k, v in limits.getDefaultDict().iteritems():
        packet, field = k.split('.')
        limit_dict[packet][field] = v

    return limit_dict
示例#2
0
    def __init__(self, inputs, outputs, **kwargs):
        super(TelemetryLimitMonitor, self).__init__(inputs, outputs, **kwargs)

        self.limit_dict = defaultdict(dict)
        for k, v in limits.getDefaultDict().items():
            packet, field = k.split('.')
            self.limit_dict[packet][field] = v

        self.packet_dict = defaultdict(dict)
        for k, v in tlm.getDefaultDict().items():
            self.packet_dict[v.uid] = v

        self.notif_thrshld = ait.config.get('notifications.options.threshold', 1)
        self.notif_freq = ait.config.get('notifications.options.frequency', float('inf'))

        self.limit_trip_repeats = {}
        log.info('Starting telemetry limit monitoring')
示例#3
0
def handle():
    return json.dumps(limits.getDefaultDict().toJSON())
示例#4
0
def main():
    dn_limits = {}
    eu_limits = {}
    eu_values = {}

    ld = limits.getDefaultDict()
    td = tlm.getDefaultDict()

    all_vals = [[
        "Telem Point",
        "EU lower.error",
        "EU lower.warn",
        "EU upper.warn",
        "EU upper.error",
        "DN lower.error",
        "DN lower.warn",
        "DN upper.warn",
        "DN upper.error",
        "DN to EU LE",
        "DN to EU LW",
        "DN to EU UW",
        "DN to EU UE",
    ]]

    for source in sorted(ld.keys(), key=lambda x: x.split(".")[1]):
        log.info(f"Processing {source}")
        pkt_name, name = source.split(".")

        # Don't support limits specifying individual values. This is usually
        # used to specify enumerations that aren't valid and we don't properly
        # handle those cases.
        if ld[source].value is not None:
            log.warn(f'Skipping unsupported "value" limit {source}')
            continue

        dn_limits.setdefault(name, [None, None, None, None])
        eu_limits.setdefault(name, [None, None, None, None])
        eu_values.setdefault(name, [None, None, None, None])

        if ld[source].lower is not None:
            try:
                eu_limits[name][0] = ld[source].lower.error
            except AttributeError:
                pass

            try:
                eu_limits[name][1] = ld[source].lower.warn
            except AttributeError:
                pass

        if ld[source].upper is not None:
            try:
                eu_limits[name][2] = ld[source].upper.warn
            except AttributeError:
                pass

            try:
                eu_limits[name][3] = ld[source].upper.error
            except AttributeError:
                pass

        values = []

        defn = td[pkt_name]
        data = bytearray(defn.nbytes)
        packet = tlm.Packet(defn, data)
        for dn in range(65536):
            setattr(packet, name, dn)
            eu = getattr(packet, name)

            if eu is not None:
                values.append((dn, eu))

        values.sort(key=lambda pair: pair[1])

        for dn, eu in values:
            for n in range(4):
                if (eu_limits[name][n] is not None
                        and dn_limits[name][n] is None
                        and eu > eu_limits[name][n]):
                    value = dn - 1 if dn > 0 else 0
                    dn_limits[name][n] = value

                    setattr(packet, name, value)
                    eu_values[name][n] = getattr(packet, name)

            if all(dn_limits[name][n] is not None for n in range(4)):
                break

        values = [source]
        values.extend(map(str, eu_limits[name]))
        values.extend(map(str, dn_limits[name]))
        values.extend(map(str, eu_values[name]))
        all_vals.append(values)

    s = [[str(e) for e in row] for row in all_vals]
    lens = [max(map(len, col)) for col in zip(*s)]
    fmt = "\t".join("{{:{}}}".format(x) for x in lens)
    table = [fmt.format(*row) for row in s]
    print("\n".join(table))