/// <summary>
        /// Handle OnMessage events, which occur when we receive a message
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        void HandleOnMessage(object sender, MessageEventArgs e)
        {
            // if the message is a string, we can parse it
            if (e.IsText)
            {
                Logger.Log("[websocket] Received message: " + e.Data);

                // use rosbridge utilities to decode and parse message
                int    command    = -1;
                object properties = null;
                RosbridgeUtilities.DecodeROSJsonCommand(e.Data, out command, out properties);

                // got a command!
                // we let the game controller sort out if it's a real command or not
                // as well as what to do with the extra properties, if any

                // fire event indicating that we received a message
                if (this.receivedMsgEvent != null)
                {
                    // only send subset of msg that is actual message
                    this.receivedMsgEvent(this, command, properties);
                }
            }
            else if (e.IsBinary)
            {
                Logger.LogWarning("[websocket] Received byte array in message but we " +
                                  "were expecting a string message.");
            }
        }
Example #2
0
        public void HandleSpeechResultReceived(Dictionary <string, double> syllables)
        {
            Logger.Log("handle speech result received");
            if (this.clientSocket != null)
            {
                Logger.Log("about to send message");
                // send log string over ROS
                this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishSpeechResultMsg(
                                                  Constants.SPEECH_RESULT_ROSTOPIC2,
                                                  syllables, speechText
                                                  ));
//				this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg(
//					Constants.LOG_ROSTOPIC, Constants.LOG_ROSMSG_TYPE));
            }
        }
Example #3
0
        void setupROS()
        {
            // set up rosbridge websocket client
            // note: does not attempt to reconnect if connection fails!
            // demo mode does not use ROS!
            if (this.clientSocket == null)
            {
                Logger.Log("!!!!!!!!!!!!!!!!!!! socket setup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                // load file

                if (this.gameConfig.server.Equals("") || this.gameConfig.port.Equals(""))
                {
                    Logger.LogWarning("Do not have opal configuration... trying "
                                      + "hardcoded IP 192.168.1.103 and port 9090");
                    this.clientSocket = new RosbridgeWebSocketClient(
                        "192.168.1.103",                 // server, // can pass hostname or IP address
                        "9090");                         //port);
                }
                else
                {
                    this.clientSocket = new RosbridgeWebSocketClient(
                        this.gameConfig.server,                         // can pass hostname or IP address
                        this.gameConfig.port);
                    Logger.Log("!!!!!!!!!!!!!!!!!!! ros bridge web ..!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                }

                if (this.clientSocket.SetupSocket())
                {
                    Logger.Log("!!!!!!!!!!!!!!!!!!! socket setup successful!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
//					this.clientSocket.receivedMsgEvent +=
//						new ReceivedMessageEventHandler(HandleClientSocketReceivedMsgEvent);

                    Logger.Log("!!!!!!!!!!!!!!!!!!! after received meessage event handler!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg(
                                                      Constants.SPEECH_RESULT_ROSTOPIC2, Constants.SPEECH_RESULT_ROSMSG_TYPE));

                    // advertise that we will publish opal action messages
                    if (this.gameConfig.opalActionTopic == "")
                    {
                        Logger.LogWarning("Do not have opal configuration... trying "
                                          + "default topic " + Constants.DEFAULT_ACTION_ROSTOPIC);
                        Constants.ACTION_ROSTOPIC = Constants.DEFAULT_ACTION_ROSTOPIC;
                    }
                    else
                    {
                        Constants.ACTION_ROSTOPIC = this.gameConfig.opalActionTopic;
                    }
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg(
                                                      Constants.ACTION_ROSTOPIC, Constants.ACTION_ROSMSG_TYPE));

                    // advertise that we will publish opal audio messages
                    if (this.gameConfig.opalAudioTopic == "")
                    {
                        Logger.LogWarning("Do not have opal configuration... trying "
                                          + "default topic " + Constants.DEFAULT_AUDIO_ROSTOPIC);
                        Constants.AUDIO_ROSTOPIC = Constants.DEFAULT_AUDIO_ROSTOPIC;
                    }
                    else
                    {
                        Constants.AUDIO_ROSTOPIC = this.gameConfig.opalAudioTopic;
                    }
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg(
                                                      Constants.AUDIO_ROSTOPIC, Constants.AUDIO_ROSMSG_TYPE));

                    // advertise that we will subscribe to opal command messages
                    if (this.gameConfig.opalCommandTopic == "")
                    {
                        Logger.LogWarning("Do not have opal configuration... trying "
                                          + "default topic " + Constants.DEFAULT_CMD_ROSTOPIC);

                        Constants.CMD_ROSTOPIC = Constants.DEFAULT_CMD_ROSTOPIC;
                    }
                    else
                    {
                        Constants.CMD_ROSTOPIC = this.gameConfig.opalCommandTopic;
                    }
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonSubscribeMsg(
                                                      Constants.CMD_ROSTOPIC, Constants.CMD_ROSMSG_TYPE));

                    // advertise that we will publish opal log messages
                    if (this.gameConfig.opalLogTopic == "")
                    {
                        Logger.LogWarning("Do not have opal configuration... trying "
                                          + "default topic " + Constants.DEFAULT_LOG_ROSTOPIC);
                        Constants.LOG_ROSTOPIC = Constants.DEFAULT_LOG_ROSTOPIC;
                    }
                    else
                    {
                        Constants.LOG_ROSTOPIC = this.gameConfig.opalLogTopic;
                    }
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg(
                                                      Constants.LOG_ROSTOPIC, Constants.LOG_ROSMSG_TYPE));



                    // advertise that we will publish opal scene messages
                    if (this.gameConfig.opalSceneTopic == "")
                    {
                        Logger.LogWarning("Do not have opal configuration... trying "
                                          + "default topic " + Constants.DEFAULT_SCENE_ROSTOPIC);
                        Constants.SCENE_ROSTOPIC = Constants.DEFAULT_SCENE_ROSTOPIC;
                    }
                    else
                    {
                        Constants.SCENE_ROSTOPIC = this.gameConfig.opalSceneTopic;
                    }
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonSubscribeMsg(
                                                      Constants.SCENE_ROSTOPIC, Constants.SCENE_ROSMSG_TYPE));

                    // publish log message to opal log topic
                    this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg(
                                                      Constants.LOG_ROSTOPIC, "Opal game checking in!"));

                    Logger.Log("!!!!!!!!!!!!!!!!!!! setting up all ros topics !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                }
                else
                {
                    Logger.LogError("Could not set up websocket!");
                }
                // register log callback for Logger.Log calls
                //Application.logMessageReceivedThreaded += HandleApplicationLogMessageReceived;
            }
        }