Package it.freedomotic.reactions

Examples of it.freedomotic.reactions.Command


    @Override
    protected void createCommands() {
        super.createCommands();

        Command a = new Command();
        a.setName("Set " + getPojo().getName() + " volume to 50%");
        a.setDescription("the TV " + getPojo().getName() + " changes its volume to 50%");
        a.setReceiver("app.events.sensors.behavior.request.objects");
        a.setProperty("object", getPojo().getName());
        a.setProperty("behavior", "volume");
        a.setProperty("value", "50");

        Command b = new Command();
        b.setName(getPojo().getName() + " volume up");
        b.setDescription("increases " + getPojo().getName() + " volume of one step");
        b.setReceiver("app.events.sensors.behavior.request.objects");
        b.setProperty("object", getPojo().getName());
        b.setProperty("behavior", "volume");
        b.setProperty("value", "next");

        Command c = new Command();
        c.setName(getPojo().getName() + " volume down");
        c.setDescription("decreases " + getPojo().getName() + " volume of one step");
        c.setReceiver("app.events.sensors.behavior.request.objects");
        c.setProperty("object", getPojo().getName());
        c.setProperty("behavior", "volume");
        c.setProperty("value", "previous");

        Command d = new Command();
        d.setName("Set its volume to 50%");
        d.setDescription("set its volume to 50%");
        d.setReceiver("app.events.sensors.behavior.request.objects");
        d.setProperty("object", "@event.object.name");
        d.setProperty("behavior", "volume");
        d.setProperty("value", "50");

        Command e = new Command();
        e.setName("Increase its volume");
        e.setDescription("increases its volume of one step");
        e.setReceiver("app.events.sensors.behavior.request.objects");
        e.setProperty("object", "@event.object.name");
        e.setProperty("behavior", "volume");
        e.setProperty("value", "next");

        Command f = new Command();
        f.setName("Decrease its volume");
        f.setDescription("decreases its volume of one step");
        f.setReceiver("app.events.sensors.behavior.request.objects");
        f.setProperty("object", "@event.object.name");
        f.setProperty("behavior", "volume");
        f.setProperty("value", "previous");


        Command g = new Command();
        g.setName("Set its volume to the value in the event");
        g.setDescription("set its volume to the value in the event");
        g.setReceiver("app.events.sensors.behavior.request.objects");
        g.setProperty("object", "@event.object.name");
        g.setProperty("behavior", "volume");
        g.setProperty("value", "@event.value");

        Command h = new Command();
        h.setName(getPojo().getName() + " channel down");
        h.setDescription("turns " + getPojo().getName() + " to the previous channel in the list");
        h.setReceiver("app.events.sensors.behavior.request.objects");
        h.setProperty("object", getPojo().getName());
        h.setProperty("behavior", "channel");
        h.setProperty("value", "previous");

        Command i = new Command();
        i.setName("Mute " + getPojo().getName());
        i.setDescription("mutes the volume of " + getPojo().getName());
        i.setReceiver("app.events.sensors.behavior.request.objects");
        i.setProperty("object", getPojo().getName());
        i.setProperty("behavior", "muted");
        i.setProperty("value", "true");

        Command l = new Command();
        l.setName("Unmute " + getPojo().getName());
        l.setDescription("unmutes the volume of " + getPojo().getName());
        l.setReceiver("app.events.sensors.behavior.request.objects");
        l.setProperty("object", getPojo().getName());
        l.setProperty("behavior", "muted");
        l.setProperty("value", "false");

        Command m = new Command();
        m.setName("Switch muted state for " + getPojo().getName());
        m.setDescription("switches unmuted state of " + getPojo().getName());
        m.setReceiver("app.events.sensors.behavior.request.objects");
        m.setProperty("object", getPojo().getName());
        m.setProperty("behavior", "muted");
        m.setProperty("value", "opposite");

        Command n = new Command();
        n.setName(getPojo().getName() + " channel up");
        n.setDescription("turns " + getPojo().getName() + " to the next channel in the list");
        n.setReceiver("app.events.sensors.behavior.request.objects");
        n.setProperty("object", getPojo().getName());
        n.setProperty("behavior", "channel");
        n.setProperty("value", "next");

        //avSelection related commands
        Command o = new Command();
        o.setName(getPojo().getName() + " next AV Selection");
        o.setDescription("select the " + getPojo().getName() + " next AV Selection");
        o.setReceiver("app.events.sensors.behavior.request.objects");
        o.setProperty("object", getPojo().getName());
        o.setProperty("behavior", "avSelection");
        o.setProperty("value", "next");

        Command p = new Command();
        p.setName(getPojo().getName() + " previous AV Selection");
        p.setDescription("select the " + getPojo().getName() + " previous AV Selection");
        p.setReceiver("app.events.sensors.behavior.request.objects");
        p.setProperty("object", getPojo().getName());
        p.setProperty("behavior", "avSelection");
        p.setProperty("value", "previous");

        //screenMode related commands
        Command q = new Command();
        q.setName(getPojo().getName() + " next Screen Mode");
        q.setDescription("select the " + getPojo().getName() + " next Screen Mode");
        q.setReceiver("app.events.sensors.behavior.request.objects");
        q.setProperty("object", getPojo().getName());
        q.setProperty("behavior", "screenMode");
        q.setProperty("value", "next");

        Command r = new Command();
        r.setName(getPojo().getName() + " previous Screen Mode");
        r.setDescription("select the " + getPojo().getName() + " previous Screen Mode");
        r.setReceiver("app.events.sensors.behavior.request.objects");
        r.setProperty("object", getPojo().getName());
        r.setProperty("behavior", "screenMode");
        r.setProperty("value", "previous");

        //screenMode related commands
        Command s = new Command();
        s.setName(getPojo().getName() + " next Input");
        s.setDescription("select the " + getPojo().getName() + " next Input");
        s.setReceiver("app.events.sensors.behavior.request.objects");
        s.setProperty("object", getPojo().getName());
        s.setProperty("behavior", "input");
        s.setProperty("value", "next");

        Command t = new Command();
        t.setName(getPojo().getName() + " previous Input");
        t.setDescription("select the " + getPojo().getName() + " previous Input");
        t.setReceiver("app.events.sensors.behavior.request.objects");
        t.setProperty("object", getPojo().getName());
        t.setProperty("behavior", "input");
        t.setProperty("value", "previous");

        CommandPersistence.add(a);
        CommandPersistence.add(b);
        CommandPersistence.add(c);
        CommandPersistence.add(d);
View Full Code Here


    }

    @Test
    public void testResolve_Command() {
        System.out.println("Commands resolving a set of references mixed with text like 'temperature is @event.temperature'");
        Command c = new Command();
        c.setName("say something using TTS");
        c.setProperty("zero", "@event.temperature");
        c.setProperty("one", "temperature is @event.temperature.");
        c.setProperty("two", "temperature is @event.temperature#celsius degree.");
        c.setProperty("three", "temperature in @event.zone is @event.temperature.");
        c.setProperty("four", "temperature in @event.zone is @event.temperature celsius degree.");
        c.setProperty("five", "temperature in @event.zone is @event.temperature celsius degree. @event.zone# is hot because temperature is +@event.temperature°C.");
        c.setProperty("six", "temperature in @event.zone is managed by object @event.object.name#.");
        //testing scripting
        c.setProperty("seven", "= seven=\"Current temperature is @event.temperature celsius degrees. In fahrenheit is \" + Math.floor(((@event.temperature+40)*1.8)-40) + \" degrees.\";");
        c.setProperty("eight", "= eight=10+5;"); //this always returns a double
        c.setProperty("nine", "= nine=Math.floor(10+5).toString();"); //print the number as is to avoid conversion to double
        //c.setProperty("ten", "= if (@event.temperature<= 20) ten=2; else what=@event.temperature/10;");
        GenericEvent event = new GenericEvent(this);
        event.addProperty("zone", "Kitchen");
        event.addProperty("temperature", "25");
        event.addProperty("object.name", "Indoor Thermometer");
        Resolver resolver = new Resolver();
        resolver.addContext("event.", event.getPayload());
        Command result = new Command();
        try {
            result = resolver.resolve(c);
        } catch (CloneNotSupportedException ex) {
            Assert.fail(ex.getMessage());
        } catch (VariableResolutionException ex) {
            Assert.fail(ex.getMessage());
        }
        assertEquals("25", result.getProperty("zero"));
        assertEquals("temperature is 25.", result.getProperty("one"));
        assertEquals("temperature is 25celsius degree.", result.getProperty("two"));
        assertEquals("temperature in Kitchen is 25.", result.getProperty("three"));
        assertEquals("temperature in Kitchen is 25 celsius degree.", result.getProperty("four"));
        assertEquals("temperature in Kitchen is 25 celsius degree. Kitchen is hot because temperature is +25°C.", result.getProperty("five"));
        assertEquals("temperature in Kitchen is managed by object Indoor Thermometer.", result.getProperty("six"));
        assertEquals("Current temperature is 25 celsius degrees. In fahrenheit is 77 degrees.", result.getProperty("seven"));
        //assertEquals("15.0", result.getProperty("eight"));
        //assertEquals("15", result.getProperty("nine"));       
        //assertEquals("15", result.getProperty("ten"));
    }
View Full Code Here

    @Override
    public void onMessage(final ObjectMessage message) {
        System.out.println("stomp request received");
        try {
            Command command = (Command) message.getObject();
            //XStream xstream = FreedomXStream.getXstream();
            //String xml = xstream.toXML(Freedomotic.environment.getPojo());
            System.out.println("XML Message from STOMP received");
            busService.reply(command, message.getJMSReplyTo(), message.getJMSCorrelationID());
        } catch (JMSException ex) {
View Full Code Here

     * Test of send method, of class BusService.
     */
    @Test
    public void testSendCommand() {
        LOG.info("Test bus send command asynch");
        Command command = new Command();
        command.setReceiver("unlistened.test.channel");
        assertFalse("Unsent command should be marked with executed=false flag", command.isExecuted());
        Command result = bus.send(command);
        assertTrue("Succesfully sent command should be marked as executed", result.isExecuted());
    }
View Full Code Here

     * Test of reply method, of class BusService.
     */
    @Test
    public void testSendCommandAndWaitTimeout() {
        LOG.info("Test send command and do not reply to test timeout");
        Command command = new Command();
        //send it on unlistened channel so it will not receive reply within timeout
        command.setReceiver("unlistened.test.channel");
        command.setReplyTimeout(2000); //wait reply for two seconds
        Command result = bus.send(command);
        assertEquals("Timeout reply command is the original command", result, command);
        assertFalse("Timeout reply marks the original command as not executed", result.isExecuted());
    }
View Full Code Here

            @Override
            public void onMessage(ObjectMessage message) {
                assertNotNull("Received message should be not null", message);
                try {
                    Command c = (Command) message.getObject();
                    c.setProperty("receiver-reply", "OK");
                } catch (JMSException ex) {
                    Logger.getLogger(BusServiceTest.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

        });
        listener.consumeCommandFrom("wait.for.reply.here");
       
        //prepare and send the command
        Command command = new Command();
        command.setReceiver("wait.for.reply.here");
        command.setReplyTimeout(2000); //wait reply for two seconds
        Command result = bus.send(command);
       
        //the reply should have the property addedd by the listener
        assertTrue("Command reply was received", result.getProperty("receiver-reply").equals("OK"));
    }
View Full Code Here

    public Command resolve(Command c)
            throws CloneNotSupportedException, VariableResolutionException {
        this.command = c;

        if ((context != null) && (command != null)) {
            Command clone = command.clone();
            mergeContextParamsIntoCommand(clone);
            performSubstitutionInCommand(clone);

            return clone;
        }
View Full Code Here

        List<Command> tmp = new ArrayList<Command>();

        try {
            for (Command originalCommand : commands) {
                //resolving values using context data
                Command clonedCmd = resolve(originalCommand);
                tmp.add(clonedCmd);
            }
        } catch (Exception e) {
            LOG.warning(Freedomotic.getStackTraceInfo(e));
        }
View Full Code Here

        NaturalLanguageProcessor nlp = new NaturalLanguageProcessor();
        List<NaturalLanguageProcessor.Rank> mostSimilar = nlp.getMostSimilarCommand(phrase, 10);

        if (!mostSimilar.isEmpty()) {
            Command c = mostSimilar.get(0).getCommand();
            System.out.println("execute speech command: " + c.getName());

            Resolver resolver = new Resolver();
            resolver.addContext("event.",
                    getPayload());

            try {
                Command resolvedCommand = resolver.resolve(c);
                busService.send(resolvedCommand);
            } catch (CloneNotSupportedException ex) {
                Logger.getLogger(SpeechEvent.class.getName()).log(Level.SEVERE, null, ex);
            } catch (VariableResolutionException ex) {
                Logger.getLogger(SpeechEvent.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

                                }

                                if (command.getReceiver()
                                        .equalsIgnoreCase(BehaviorManager.getMessagingChannel())) {
                                    //this command is for an object so it needs only to know only about event parameters
                                    Command resolvedCommand = commandResolver.resolve(command);
                                    //doing so we bypass messaging system gaining better performances
                                    BehaviorManager.parseCommand(resolvedCommand);
                                } else {
                                    //if the event has a target object we include also object info
                                    EnvObjectLogic targetObject =
                                            EnvObjectPersistence.getObjectByName(event.getProperty("object.name"));

                                    if (targetObject != null) {
                                        commandResolver.addContext("current.",
                                                targetObject.getExposedProperties());
                                        commandResolver.addContext("current.",
                                                targetObject.getExposedBehaviors());
                                    }

                                    final Command resolvedCommand = commandResolver.resolve(command);

                                    //it's not a user level command for objects (eg: turn it on), it is for another kind of actuator
                                    Command reply = busService.send(resolvedCommand); //blocking wait until executed

                                    if (reply == null) {
                                        LOG.log(Level.WARNING,
                                                "Unreceived reply within given time ({0}ms) for command {1}",
                                                new Object[]{command.getReplyTimeout(), command.getName()});
                                    } else {
                                        if (reply.isExecuted()) {
                                            LOG.log(Level.FINE, "Executed succesfully {0}", command.getName());
                                        } else {
                                            LOG.log(Level.WARNING, "Unable to execute command{0}", command.getName());
                                        }
                                    }
View Full Code Here

TOP

Related Classes of it.freedomotic.reactions.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.