Example #1
0
    def op_get_instrument_state(self, content, headers, msg):
        """
        Service operation: .
        """
        # Step 1: Extract the arguments from the UI generated message content
        commandInput = content['commandInput']

        if 'instrumentID' in commandInput:
            inst_id = str(commandInput['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if not agent_pid:
            raise StandardError("No agent found for instrument " +
                                str(inst_id))

        iaclient = InstrumentAgentClient(proc=self, target=agent_pid)
        inst_cap = yield iaclient.get_capabilities()
        if not inst_cap:
            raise StandardError("No capabilities available for instrument " +
                                str(inst_id))

        ci_commands = inst_cap['ci_commands']
        instrument_commands = inst_cap['instrument_commands']
        instrument_parameters = inst_cap['instrument_parameters']
        ci_parameters = inst_cap['ci_parameters']

        values = yield iaclient.get_from_instrument(instrument_parameters)
        resvalues = {}
        if values:
            resvalues = values

        yield self.reply_ok(msg, resvalues)
Example #2
0
def main():
    """
    Initializes container
    """
    logging.info("ION CONTAINER initializing... [Start an Instrument Agent]")

    processes = []
    processes.extend(agent_procs)
    processes.extend(service_procs)

    # Start the processes
    sup = yield bootstrap.bootstrap(None, processes)

    eval_start_arguments()

    simulator = Simulator(INSTRUMENT_ID, 9000)
    simulator.start()

    ia_procs = [
        {'name':'SBE49IA','module':'ion.agents.instrumentagents.SBE49_IA','class':'SBE49InstrumentAgent','spawnargs':{'instrument-id':INSTRUMENT_ID}},
    ]
    yield bootstrap.spawn_processes(ia_procs, sup=sup)

    ia_pid = sup.get_child_id('SBE49IA')
    iaclient = InstrumentAgentClient(proc=sup, target=ia_pid)
    yield iaclient.register_resource(INSTRUMENT_ID)
Example #3
0
def main():
    """
    Initializes container
    """
    logging.info("ION CONTAINER initializing... [LCA Java Integration Demo]")

    processes = []
    processes.extend(agent_procs)
    processes.extend(demo_procs)

    # Start the processes
    sup = yield bootstrap.bootstrap(None, processes)

    simulator = Simulator(INSTRUMENT_ID, 9000)
    simulator.start()

    irc = InstrumentRegistryClient(proc=sup)

    ir1 = InstrumentResource.create_new_resource()
    ir1.name = "Demo_CTD_1"
    ir1.model = "SBE49"
    ir1.serial_num = "12345"
    ir1.fw_version = "1.334"
    ir1.manufactorer = "SeaBird"
    ir1 = yield irc.register_instrument_instance(ir1)
    ir1_ref = ir1.reference(head=True)

    ir2 = InstrumentResource.create_new_resource()
    ir2.name = "Demo_CTD_2"
    ir2.model = "SBE49"
    ir2.serial_num = "12399"
    ir2.fw_version = "1.335"
    ir2.manufactorer = "SeaBird"
    ir2 = yield irc.register_instrument_instance(ir2)

    dprc = DataProductRegistryClient(proc=sup)

    dp1 = DataProductResource.create_new_resource()
    dp1.instrument_ref = ir1_ref
    dp1.name = "Demo_Data_Product_1"
    dp1.dataformat = "binary"
    dp1 = yield dprc.register_data_product(dp1)

    ia_procs = [
        {
            'name': 'SBE49IA',
            'module': 'ion.agents.instrumentagents.SBE49_IA',
            'class': 'SBE49InstrumentAgent',
            'spawnargs': {
                'instrument-id': INSTRUMENT_ID
            }
        },
    ]
    yield bootstrap.spawn_processes(ia_procs, sup=sup)

    ia_pid = sup.get_child_id('SBE49IA')
    iaclient = InstrumentAgentClient(proc=sup, target=ia_pid)
    yield iaclient.register_resource(INSTRUMENT_ID)
Example #4
0
    def op_start_instrument_agent(self, content, headers, msg):
        """
        Service operation: Starts an instrument agent for a type of
        instrument.
        """
        if 'instrumentID' in content:
            inst_id = str(content['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        if 'model' in content:
            model = str(content['model'])
        else:
            raise ValueError("Input for model not present")

        if model != 'SBE49':
            raise ValueError("Only SBE49 supported!")

        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if agent_pid:
            raise StandardError("Agent already started for instrument " +
                                str(inst_id))

        simulator = Simulator(inst_id)
        simulator.start()

        topicname = "Inst/RAW/" + inst_id
        topic = PubSubTopicResource.create(topicname, "")

        # Use the service to create a queue and register the topic
        topic = yield self.dpsc.define_topic(topic)

        iagent_args = {}
        iagent_args['instrument-id'] = inst_id
        driver_args = {}
        driver_args['port'] = simulator.port
        driver_args['publish-to'] = topic.RegistryIdentity
        iagent_args['driver-args'] = driver_args

        iapd = ProcessDesc(
            **{
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent',
                'spawnargs': iagent_args
            })

        iagent_id = yield self.spawn_child(iapd)
        iaclient = InstrumentAgentClient(proc=self, target=iagent_id)
        yield iaclient.register_resource(inst_id)

        yield self.reply_ok(msg, "OK")
Example #5
0
    def plc_init(self):
        self.instrument_id = self.spawn_args.get('instrument-id', '123')
        self.instrument_port = self.spawn_args.get('port', 9000)

        yield self._configure_driver(self.spawn_args)

        logging.info(
            "INIT DRIVER for instrument ID=%s, port=%s, publish-to=%s" %
            (self.instrument_id, self.instrument_port, self.publish_to))

        self.iaclient = InstrumentAgentClient(proc=self,
                                              target=self.proc_supid)

        logging.debug("Instrument driver initialized")
Example #6
0
    def op_execute_command(self, content, headers, msg):
        """
        Service operation: Execute a command on an instrument.
        """

        # Step 1: Extract the arguments from the UI generated message content
        commandInput = content['commandInput']

        if 'instrumentID' in commandInput:
            inst_id = str(commandInput['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        command = []
        if 'command' in commandInput:
            command_op = str(commandInput['command'])
        else:
            raise ValueError("Input for command not present")

        command.append(command_op)

        arg_idx = 0
        while True:
            argname = 'cmdArg' + str(arg_idx)
            arg_idx += 1
            if argname in commandInput:
                command.append(str(commandInput[argname]))
            else:
                break

        # Step 2: Find the agent id for the given instrument id
        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if not agent_pid:
            yield self.reply_err(
                msg, "No agent found for instrument " + str(inst_id))
            defer.returnValue(None)

        # Step 3: Interact with the agent to execute the command
        iaclient = InstrumentAgentClient(proc=self, target=agent_pid)
        commandlist = [
            command,
        ]
        logging.info("Sending command to IA: " + str(commandlist))
        cmd_result = yield iaclient.execute_instrument(commandlist)

        yield self.reply_ok(msg, cmd_result)
Example #7
0
    def setUp(self):
        yield self._start_container()

        services = [
            {
                'name': 'instreg',
                'module': 'ion.services.coi.agent_registry',
                'class': 'AgentRegistryService'
            },
            {
                'name': 'instreg',
                'module': 'ion.services.sa.instrument_registry',
                'class': 'InstrumentRegistryService'
            },
            {
                'name': 'pubsub_registry',
                'module': 'ion.services.dm.distribution.pubsub_registry',
                'class': 'DataPubSubRegistryService'
            },
            {
                'name': 'pubsub_service',
                'module': 'ion.services.dm.distribution.pubsub_service',
                'class': 'DataPubsubService'
            },
            {
                'name': 'dprodreg',
                'module': 'ion.services.sa.data_product_registry',
                'class': 'DataProductRegistryService'
            },
            {
                'name': 'instmgmt',
                'module': 'ion.services.sa.instrument_management',
                'class': 'InstrumentManagementService'
            },
            {
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent'
            },
        ]

        sup = yield self._spawn_processes(services)

        #self.agreg_client = AgentRegistryClient(proc=sup)
        #yield self.agreg_client.clear_registry()

        self.ia_pid = sup.get_child_id('SBE49IA')
        self.iaclient = InstrumentAgentClient(proc=sup, target=self.ia_pid)

        self.imc = InstrumentManagementClient(proc=sup)

        self.newInstrument = {
            'manufacturer': "SeaBird Electronics",
            'model': "unknown model",
            'serial_num': "1234",
            'fw_version': "1"
        }

        instrument = yield self.imc.create_new_instrument(self.newInstrument)
        self.inst_id = instrument.RegistryIdentity
        logging.info("*** Instrument created with ID=" + str(self.inst_id))

        self.simulator = Simulator(self.inst_id, 9000)
        self.simulator.start()

        yield self.iaclient.register_resource(self.inst_id)