public void Execute(Command cmd)
        {
            if (cmd.HasChildren)
            {
                foreach (Command c in cmd.Children) Execute(c);
            }
            if (cmd.HasData)
            {
                //does the device support the action. It should by this point.
                if ((cmd.Action & cmd.TargetDevice.Capabilities.Caps) != cmd.Action){
                    //TODO: Should throw an error
                    return;
                }

                //does the protocol support the action?
                switch (cmd.TargetDevice.Protocol)
                {
                    case EDeviceProtocol.LWRF:
                        if ((cmd.Action & LWRF.Capabilities) != cmd.Action)
                        {
                            //TODO: Throw error
                            return;
                        }
                        mLWRF.Execute(cmd.TargetDevice.ID, cmd.Action);
                        break;
                    case EDeviceProtocol.AudioProto:
                        //TODO: Should throw an error
                        return;
                    default:
                        //TODO: Should throw and error
                        return;
                }

            }
        }
Beispiel #2
0
        public Command(string room, string item, string action, TheWorld world)
        {
            mSubCommands = new List<Command>();
            //is item a device class?
            bool itemIsDeviceClass = false;
            EDeviceClass itemClass = EDeviceClass.Kinect;
            Array vals = Enum.GetValues(typeof(EDeviceClass));
            foreach (EDeviceClass c in vals)
            {
                if (SoundsLike.Get(c, false) == item)
                {
                    itemIsDeviceClass = true;
                    itemClass = c;
                    break;
                }
            }

            //convert the action to a devicecapabilitiesenum
            EDeviceCapabilities actionResolved = EDeviceCapabilities.None;
            vals = Enum.GetValues(typeof(EDeviceCapabilities));
            foreach (EDeviceCapabilities c in vals)
            {
                if (SoundsLike.Get(c, true) == action)
                {
                    actionResolved = c;
                    break;
                }
            }

            //find the devices
            foreach (Room rm in world.ListRooms())
            {
                if (room == "" || rm.Name == room)
                {
                    foreach (Device d in rm.ListDevices())
                    {
                        bool hit = false;
                        if (itemIsDeviceClass)
                        {
                            if (itemClass == d.Class) hit = true;
                        }
                        else
                        {
                            if (item == d.FriendlyName) hit = true;
                        }
                        if (hit)
                        {
                            Command c = new Command(rm, d, actionResolved);
                            mSubCommands.Add(c);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public bool OnSpeechRecognised(string ID, RecognitionSuccess result)
        {
            string room = "";
            if (result.getSemanticValuesAsString("room") != null) room = result.getSemanticValuesAsString("room");
            string item = "";
            if (result.getSemanticValuesAsString("item") != null) item = result.getSemanticValuesAsString("item");
            string action = "";
            if (result.getSemanticValuesAsString("action") != null) action = result.getSemanticValuesAsString("action");

            Command c = new Command(room, item, action, this);
            Form1.server.protos.Execute(c);
            return true;
        }