public MessageEventArgs SendMessage(string sendto, MessageEventArgs msg)
 {
     if (evSendMessage != null)
     {
         return evSendMessage(sendto, this.ID, msg);
     }
     else
         return null;
 }
Esempio n. 2
0
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {

            if (message.MsgType == MessageEventArgs.MessageType.COMMAND)
            {
                if (message.Cmd == "NextSlide")
                {
                    NextSlide();
                }
                else if (message.Cmd == "PreviousSlide")
                {
                    PreviousSlide();
                }
                else if (message.Cmd.StartsWith("RunPPT"))
                {
                    string file = message.CmdArgs[0];
                    RunPresentation(file);
                }
                else if (message.Cmd == "ClosePPT")
                {
                    Presentation.SlideShowWindow.View.Exit();
                }
                else if (message.Cmd == "ShowPhoto")
                {
                    string picfile = message.CmdArgs[0];
                    ShowPictureNewSlide(picfile);
                }
                else if (message.Cmd == "FetchQuizAnswers")
                {
                    bool disagree = false;
                    int useranswer = -1, useranswer2 = -1;
                    try
                    {
                    	TPD.AnswerDistribution(out disagree, out useranswer, out useranswer2);
                    }
                    catch (System.Exception ex)
                    {
                        Debug.WriteLine("{0}: quiz data is not ready! {1}", this.ID, ex);
                    }
                    string[] data = new string[] { disagree.ToString(), useranswer.ToString(), useranswer2.ToString()};
                    MessageEventArgs backmsg = new MessageEventArgs(data);
                    return backmsg;
                }
            }

            return null;
        }
Esempio n. 3
0
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {
            if (message.MsgType == MessageEventArgs.MessageType.COMMAND)
            {
                if (message.Cmd == "ChangeRobotMood")
                {
                    string valstr = message.CmdArgs[0];
                    double valence = Double.Parse(valstr);
                    // Draw
                    AddPointToCurve("Valence", valence);
                }
                else if (message.Cmd == "TextSenti")
                {
                    if (cbSentiText.Checked == true)
                    {
                        string sentence = message.CmdArgs[0];
                        double valence = SentiText(sentence);
                        // Draw
                        AddPointToCurve("Valence", valence);

                        return new MessageEventArgs(valence as Object);
                    }
                    else
                    {
                        return new MessageEventArgs(200 as Object);
                    }
                }
                else if (message.Cmd == "TextSentiStart")
                {
                    LaunchSentimentStrength();
                    areSentiStrengthLaunched.WaitOne(5000);
                    return null;
                }
                else if (message.Cmd == "TextSentiStop")
                {
                    StopJavaProgram();
                    return null;
                }
            }

            return null;
        }
Esempio n. 4
0
 private void SendMessage(string sendto, MessageEventArgs message)
 {
     if (Dockees.ContainsKey(sendto))
     {
         Dockees[sendto].MessageHandler(this.ID, message);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Central message distributor.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="sendto"></param>
        /// <param name="sendfrom"></param>
        private MessageEventArgs MessageCenter(string sendto, string sendfrom, MessageEventArgs message)
        {
            if (sendto == "ScriptEngine")
            {
                if (IsExternalScriptEngine == true) sendto = "ExternalScriptEngine";
            }

            if (Dockees.ContainsKey(sendto))
            {
                MessageEventArgs backmsg = Dockees[sendto].MessageHandler(sendfrom, message);
                return backmsg;
            }
            else
                return null;
        }
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {
            if (message.MsgType == MessageEventArgs.MessageType.COMMAND)
            {
                if (message.Cmd == "NaoSpeechFinished")
                {
                    int len = int.Parse(message.CmdArgs[0]);
                    //Debug.WriteLine("{0}: NAO speech finished - {1}", this.ID, len );

                    SpeechDone();
                }
                else if (message.Cmd == "TTSNotConnected")
                {
                    Console.WriteLine("{0}: Speech is not said: {1}", this.ID, "TTSNotConnected!");
                    SpeechDone();
                }
                else if (message.Cmd == "NaoBehaviorFinished")
                {
                    string behaviorname = message.CmdArgs[0];
                    Debug.WriteLine("{0}: NAO behavior finished - {1}", this.ID, behaviorname);

                    BehaviorDone();
                }
                else if (message.Cmd == "NaoBehaviorNotExecuted")
                {
                    string behaviorname = message.CmdArgs[0];
                    Debug.WriteLine("{0}: NAO behavior NOT executed! - {1}", this.ID, behaviorname);
                    BehaviorDone();
                }
            }

            return null;
        }
Esempio n. 7
0
 public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
 {
     if (message.MsgType == MessageEventArgs.MessageType.TEXT)
     {
         if (message.TextMsg == "Connect")
         {
             c.connect();
         }
         else if (message.TextMsg == "Run")
         {
             NaoMove((c.run()).ToLower());
         }
         else if (message.TextMsg == "Ask")
         {
             string answer;
             do{
                 answer = c.run().ToLower();
                 Console.WriteLine("Answer: " + answer);
             }while(answer != "ja" && answer != "nee");
             string[] data = new string[] { answer.ToString() };
             MessageEventArgs backmsg = new MessageEventArgs(data);
             return backmsg;
         }
         else if (message.TextMsg == "Close")
         {
             c.close();
         }
     }
     return null;
 }
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {
            if(message.MsgType==MessageEventArgs.MessageType.COMMAND)
            {
                if (message.Cmd == "Say")
                {
                    string texttosay = message.CmdArgs[0];

                    // Change robot mood
                    if (this.NaoAffect.SentiAffect.SentiTextEnabled)
                    {
                        /* TODO: TextSentiment is not available in this version.
                        //SendMessage("TextSentiment", new MessageEventArgs("TextSenti", new string [] {texttosay}));
                        MessageEventArgs backdata = this.NaoAffect.SentiAffect.MessageHandler(this.ID, new MessageEventArgs("TextSenti", new string[] { texttosay }));
                        double valence = (double)backdata.DataReturn;
                        */
                    }

                    NaoClient.Say(texttosay);
                }
                else if (message.Cmd == "InitSentiText") // maybe put into SentiAffect itself
                {
                    this.NaoAffect.SentiAffect.MessageHandler(this.ID, new MessageEventArgs("TextSentiStart", new string[]{}));
                }
                else if (message.Cmd == "ChangeRobotMood")
                {
                    string moodstr = message.CmdArgs[0];
                    string[] vad = moodstr.Split(',');
                    string valence = vad[0];
                    //string arousal = vad[1];
                    //string dominance = vad[2];
                    Invoke((MethodInvoker)delegate() {
                        this.NaoAffect.Valence = double.Parse(valence);
                    });
                }
                else if (message.Cmd == "ExecuteBehavior")
                {
                    string behaviorname = message.CmdArgs[0];
                    HandleBehavior(behaviorname);
                }
                else if (message.Cmd == "CapturePhoto")
                {
                    string imgfile = HandleCameraPhoto();
                    return new MessageEventArgs(imgfile);
                }
                else if (message.Cmd == "Config")
                {
                    string config = message.CmdArgs[0];
                    HandleConfig(config);
                }
                else if (message.Cmd == "CheckIdleMoveConflicts")
                {
                    string behaviorname = message.CmdArgs[0];
                    if(IsLegInvolved(behaviorname))
                    {
                        if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();
                    }
                    if (IsHeadInvolved(behaviorname))
                    {
                       if(this.NaoIdleMoveHead != null) this.NaoIdleMoveHead.Stop();
                    }
                }
            }
            else if(message.MsgType == MessageEventArgs.MessageType.TEXT)
            {
                if (message.TextMsg == "ScriptEnded")
                {
                    if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();
                }
                else if (message.TextMsg == "ScriptPaused")
                {
                    if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();
                }
            }

            return null;
        }
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {

            return null;
        }
Esempio n. 10
0
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {
            if (message.MsgType == MessageEventArgs.MessageType.COMMAND)
            {
                /*if (message.Cmd == "Say")
                {            

                }*/
            }
            return null;
        }
Esempio n. 11
0
        public MessageEventArgs MessageHandler(string sendfrom, MessageEventArgs message)
        {
            if(message.MsgType==MessageEventArgs.MessageType.COMMAND)
            {
                if (message.Cmd == "Say")
                {
                    string texttosay = message.CmdArgs[0];

                    // Change robot mood
                    if (this.NaoAffect.SentiAffect.SentiTextEnabled) // a CheckBox needs to be checked manually
                    {
                    	//SendMessage("TextSentiment", new MessageEventArgs("TextSenti", new string [] {texttosay}));

                        MessageEventArgs backdata = this.NaoAffect.SentiAffect.MessageHandler(this.ID, new MessageEventArgs("TextSenti", new string[] { texttosay }));
                        double valence = (double)backdata.DataReturn;
                        
                    }

                    NaoClient.Say(texttosay);
                }
                else if (message.Cmd == "ChangeRobotMood")
                {
                    string moodstr = message.CmdArgs[0];
                    string[] vad = moodstr.Split(',');
                    string valence = vad[0];
                    //string arousal = vad[1];
                    //string dominance = vad[2]; 
                    Invoke((MethodInvoker)delegate(){ 
                        this.NaoAffect.Valence = double.Parse(valence);
                    });

                    this.NaoAffect.SentiAffect.MessageHandler(this.ID, new MessageEventArgs("ChangeRobotMood", new string[] { valence }));
                }
                else if (message.Cmd == "PointToRaisedHands") // respond to students' raising hands
                {
                    double y = Convert.ToDouble(message.CmdArgs[0]), z = Convert.ToDouble(message.CmdArgs[1]), x = 400;
                    IBehaviorProfile prh = new BehaviorProfilePointingOmni(x, y, z);
                    MotionTimeline mtl = prh.LoadBehavior(0);
                    NaoClient.ExecuteBehaviorInQueue(mtl);
                }
                else if (message.Cmd == "CheckBehavior")
                {
                    string behaviorname = message.CmdArgs[0];
                    bool b = false;
                    if (behaviorname == "Twinkle" 
                        || behaviorname == "GangnamLong"
                        || behaviorname == "Wink"
                        || behaviorname == "Kick"
                        || behaviorname == "StandHead"
                        || behaviorname == "AllOn"
                        || behaviorname == "AllOff" 
                        || behaviorname == "EyesOn"
                        || behaviorname == "EyesOff"
                        || behaviorname == "RandomEyes"
                        || behaviorname == "Walk"
                        || behaviorname == "StandUp"
                        || behaviorname == "Squat"
                        || behaviorname == "Pushups"
                        || behaviorname == "Macarena") 
                        b = true; // temp solution
                    else b= this.BehaviorGenerator.ContainsKey(behaviorname);
                    return new MessageEventArgs(b as object);
                }
                else if (message.Cmd == "ExecuteBehavior")
                {
                    string behaviorname = message.CmdArgs[0];
                    HandleBehavior(behaviorname);
                }
                else if (message.Cmd == "CapturePhoto")
                {
                    string imgfile = HandleCameraPhoto();
                    return new MessageEventArgs(imgfile);
                }
                else if (message.Cmd == "Config")
                {
                    string config = message.CmdArgs[0];
                    if (config == "text_senti_enabled") // maybe put into SentiAffect itself
                    {
                        this.NaoAffect.SentiAffect.MessageHandler(this.ID, new MessageEventArgs("TextSentiStart", new string[] { }));
                    }
                    else if (config == "constant_head")
                    {
                        this.NaoClient.RecoverHead = false;
                    }
                    else if (config == "forwardlooking_head")
                    {
                        this.NaoClient.HeadYawInhibition = true;
                    }
                    else if (config == "freelooking_head")
                    {
                        this.NaoClient.HeadYawInhibition = false;
                    }
                    else
                    {
                        ConfigRobot(config);
                    }
                }
                else if (message.Cmd == "CheckIdleMoveConflicts")
                {
                    string behaviorname = message.CmdArgs[0];
                    if (IsLegInvolved(behaviorname))
                    {
                        if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();
                    }
                    //if (IsHeadInvolved(behaviorname))
                    //{
                    //    if (this.NaoIdleMoveHead != null) this.NaoIdleMoveHead.Stop();
                    //}
                }
                
            }
            else if(message.MsgType == MessageEventArgs.MessageType.TEXT)
            {
                if (message.TextMsg == "ScriptEnded")
                {
                    if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();
                }
                else if (message.TextMsg == "ScriptPaused")
                {
                    if (this.NaoIdleMoveLeg != null) this.NaoIdleMoveLeg.Stop();

                    Debug.WriteLine("{0}: Script paused!", this.ID);
                }
            }

            return null;
        }