예제 #1
0
        public void UpdateAppList(TableApp[] apps)
        {
            string json = string.Empty;

            json += "{\"message_type\": \"app_list\", \"apps\": [";

            for (int i = 0; i < apps.Length; i++)
            {
                TableApp app = apps[i];
                if (!app.selectable)
                {
                    continue;
                }

                var           name    = app.GetName().Replace("TableApp", "");
                StringBuilder newText = new StringBuilder(name.Length * 2);
                newText.Append(name[0]);
                for (int j = 1; j < name.Length; j++)
                {
                    if (char.IsUpper(name[j]) && name[j - 1] != ' ')
                    {
                        newText.Append(' ');
                    }
                    newText.Append(name[j]);
                }

                name = newText.ToString();

                json += "{\"id\": \"" + app.GetName() + "\", \"name\": \"" + name + "\", \"features\": " + JObject.FromObject(app.GetFeatures()).ToString() + "}";
                if (i < apps.Length - 1)
                {
                    json += ",";
                }
            }

            json += "]}";

            Send(json);
        }
예제 #2
0
        public void ExecuteCommand(string command)
        {
            command = command.Trim();
            string argument = string.Empty;

            if (command.Contains(' '))
            {
                argument = command.Substring(command.IndexOf(' '));
                command  = command.Substring(0, command.IndexOf(' '));
            }

            if (command.StartsWith("GET"))
            {
                string   key         = "";
                string[] headerLines = argument.Split('\n');
                foreach (string line in headerLines)
                {
                    if (line.Contains("Sec-WebSocket-Key:"))
                    {
                        key = line.Replace("Sec-WebSocket-Key: ", "").Trim();
                        break;
                    }
                }

                Program.LogFullLength("MAGIC", "The WebSocket Sec-Key is: '" + key + "'");

                Send("HTTP/1.1 101 Switching Protocols\r\n" +
                     "Upgrade: websocket\r\n" +
                     "Connection: Upgrade\r\n" +
                     "Sec-WebSocket-Accept: " + AcceptKey(ref key) + "\r\n\r\n");
            }
            else if (command.Contains("stop"))
            {
                ShutdownServer();
            }
            else if (command.Contains("serial") && !string.IsNullOrWhiteSpace(argument))
            {
                Program.serialController.Write(argument.Trim());
            }
            else if (command.Contains("init"))
            {
                Program.tableAppManager.LaunchApp(new TableAppIdle());

                string appList = string.Empty;
                for (int i = 0; i < TableAppManager.apps.Length; i++)
                {
                    TableApp a = TableAppManager.apps[i];
                    if (a.selectable)
                    {
                        appList += a.GetName() + ":" + (int)a.userInterface + "|";
                    }
                }


                Send("setup " + appList.Trim('|').Trim());
            }
            else if (command.Contains("input") && !string.IsNullOrWhiteSpace(argument))
            {
                Program.TriggerInput(argument.Trim());
            }
            else if (command.Contains("app") && !string.IsNullOrWhiteSpace(argument))
            {
                Program.tableAppManager.LaunchApp(Apps.TableAppManager.GetAppById(argument.Trim()));
            }
            else if (command.Contains("renderer") && !string.IsNullOrWhiteSpace(argument))
            {
                Program.CreateRenderer(argument.Trim());
            }
            else if (command.Contains("help"))
            {
                Send("Help - List of commands\n");
                Send("stop                   -       Shutdown the server\n");
                Send("serial [command]       -       Run a serial command\n");
                Send("init                   -       Get a list of apps\n");
                Send("input [input]          -       Triggers an input event. e.g. pad_start\n");
                Send("app [name]             -       Starts an app. e.g. TableAppIdle\n");
                Send("renderer [name]        -       Changes the renderer. e.g. remote\n");
                Send("help                   -       Shows this list of commands\n");
                Send("#######################");
            }
            else
            {
                Send("Command " + command + " not found. Run 'help' for a list of commands");
            }
        }
예제 #3
0
        public void HandleInput(string json)
        {
            try
            {
                JObject data = JObject.Parse(json);

                switch ((string)data.GetValue("message_type"))
                {
                case "start_app":
                    TableApp app = TableAppManager.GetAppById((string)data.GetValue("app"));
                    Program.tableAppManager.LaunchApp(app);

                    CustomInterface customInterface = app.GetCustomInterface();
                    Send("{\"message_type\": \"show_interface\", \"app\": {\"name\": \"" + app.GetName().Replace("TableApp", "") + "\", \"id\": \"" + app.GetName() + "\"}, \"interface\": {\"items\": " + customInterface.toJson() + "}}");
                    break;

                case "input":
                    JObject input = JObject.Parse(data["input"].ToString());

                    Program.tableAppManager.GetCurrentApp()
                    .OnCustomInterfaceInput((string)input.GetValue("id"), (string)input.GetValue("value"));
                    break;
                }
            }
            catch (Exception e)
            {
                Program.LogFullLength(TAG, "Parsing received message failed! " + e.ToString());
            }
        }