def handle(): """Return JSON Command dictionary **Example Response**: .. sourcecode: json { NO_OP: { subsystem: "CORE", name: "NO_OP", title: "NO_OP", opcode: 1, arguments: [], desc: "Standard NO_OP command. " }, SEQ_START: { subsystem: "CMD", name: "SEQ_START", title: "Start Sequence", opcode: 2, arguments: [ { name: "sequence_id", bytes: [0, 1], units: "none", fixed: false, type: "MSB_U16", desc: "Sequence ID" } ], desc: "This command starts a specified command sequence. " }, ... } """ return json.dumps(cmd.getDefaultDict().toJSON())
def cmddict(self): """PrimitiveType base for the ComplexType""" if self._cmddict is None: self._cmddict = cmd.getDefaultDict() return self._cmddict
def create_packets_from_results(self, packet_name, result_set): ''' Generate AIT Packets from a InfluxDB query ResultSet Extract Influx DB query results into one packet per result entry. This assumes that telemetry data was inserted in the format generated by :func:`InfluxDBBackend.insert`. Complex types such as CMD16 and EVR16 are evaluated if they can be properly encoded from the raw value in the query result. If there is no opcode / EVR-code for a particular raw value the value is skipped (and thus defaulted to 0). Arguments packet_name (string) The name of the AIT Packet to create from each result entry result_set (influxdb.resultset.ResultSet) The query ResultSet object to convert into packets Returns A list of packets extracted from the ResultSet object or None if an invalid packet name is supplied. ''' try: pkt_defn = tlm.getDefaultDict()[packet_name] except KeyError: log.error('Unknown packet name {} Unable to unpack ResultSet'.format(packet_name)) return None pkt = tlm.Packet(pkt_defn) pkts = [] for r in result_set.get_points(): new_pkt = tlm.Packet(pkt_defn) for f, f_defn in pkt_defn.fieldmap.iteritems(): field_type_name = f_defn.type.name if field_type_name == 'CMD16': if cmd.getDefaultDict().opcodes.get(r[f], None): setattr(new_pkt, f, cmd_def.name) elif field_type_name == 'EVR16': if evr.getDefaultDict().codes.get(r[f], None): setattr(new_pkt, f, r[f]) elif field_type_name == 'TIME8': setattr(new_pkt, f, r[f] / 256.0) elif field_type_name == 'TIME32': new_val = dmc.GPS_Epoch + dt.timedelta(seconds=r[f]) setattr(new_pkt, f, new_val) elif field_type_name == 'TIME40': sec = int(r[f]) microsec = r[f] * 1e6 new_val = dmc.GPS_Epoch + dt.timedelta(seconds=sec, microseconds=microsec) setattr(new_pkt, f, new_val) elif field_type_name == 'TIME64': sec = int(r[f]) microsec = r[f] % 1 * 1e6 new_val = dmc.GPS_Epoch + dt.timedelta(seconds=sec, microseconds=microsec) setattr(new_pkt, f, new_val) else: try: setattr(new_pkt, f, r[f]) except KeyError: log.info('Field not found in query results {} Skipping ...'.format(f)) pkts.append(new_pkt) return pkts
def testGetDefaultDict(): cmddict = cmd.getDefaultDict() assert cmddict is not None assert isinstance(cmddict, cmd.CmdDict)
def testGetDefaultDictWithExtension( testGetDefaultDictWithExtension_setup_teardown): cd = cmd.getDefaultDict() assert type(cd) == TestCmdDict
def create_packet_from_result(cls, packet_id, result): """Create an AIT Packet from an InfluxDB query ResultSet item Extract Influx DB query results entry into an AIT packet. This assumes that telemetry data was inserted in the format generated by :func:`InfluxDBBackend.insert`. Complex types such as CMD16 and EVR16 are evaluated if they can be properly encoded from the raw value in the query result. If there is no opcode / EVR-code for a particular raw value the value is skipped (and thus defaulted to 0). TODO: Reevaluate this assumption that missing opcodes / EVR-codes should be left as 0 if a match isn't found in the dictionary. Arguments packet_id (string or PacketDefinition) The "id" for the packet to create. If packet_id is a string it must name a valid PacketDefintion in the telemetry dictionary. Otherwise, it must be a PacketDefinition. result (dict) The :class:`influxdb.resultset.ResultSet` entry from which values should be extracted to form the AIT packet Returns A :class:`ait.core.tlm.Packet` with values initialized from the values in the ResultSet entry. If a field cannot be located in the result entry it will left as the default value in the Packet or set to None if it's a CMD / EVR type. """ if isinstance(packet_id, str): try: pkt_defn = tlm.getDefaultDict()[packet_id] except KeyError: log.error( f"Unknown packet name {packet_id} Unable to unpack ResultSet" ) return None elif isinstance(packet_id, tlm.PacketDefinition): pkt_defn = packet_id else: log.error( f"Unknown packet id type {packet_id}. Unable to unpack ResultSet" ) return None new_pkt = tlm.Packet(pkt_defn) cmd_dict = cmd.getDefaultDict() evr_dict = evr.getDefaultDict() for f, f_defn in pkt_defn.fieldmap.items(): field_type_name = f_defn.type.name if field_type_name == "CMD16": if cmd_dict.opcodes.get(result[f], None): cmd_def = cmd_dict.opcodes.get(result[f]) setattr(new_pkt, f, cmd_def.name) elif field_type_name == "EVR16": if evr_dict.codes.get(result[f], None): evr_def = evr_dict.codes.get(result[f]) setattr(new_pkt, f, evr_def.name) elif field_type_name == "TIME8": setattr(new_pkt, f, result[f] / 256.0) elif field_type_name == "TIME32": new_val = dmc.GPS_Epoch + dt.timedelta(seconds=result[f]) setattr(new_pkt, f, new_val) elif field_type_name == "TIME40": sec = int(result[f]) microsec = result[f] % 1 * 1e6 new_val = dmc.GPS_Epoch + dt.timedelta(seconds=sec, microseconds=microsec) setattr(new_pkt, f, new_val) elif field_type_name == "TIME64": sec = int(result[f]) microsec = result[f] % 1 * 1e6 new_val = dmc.GPS_Epoch + dt.timedelta(seconds=sec, microseconds=microsec) setattr(new_pkt, f, new_val) else: try: setattr(new_pkt, f, result[f]) except KeyError: log.info( "Field not found in query results {} Skipping ...". format(f)) return new_pkt