Esempio n. 1
0
        /// <summary>
        /// Run any action after 1 frame
        /// </summary>
        /// <param name="task">the task you want to run after 1 frame</param>
        private IEnumerator DelayActionFrameCoroutine(int frames, IThreadTask task)
        {
            for (int i = 0; i < frames; i++)
            {
                yield return(new WaitForEndOfFrame());
            }

            task.Invoke();
        }
Esempio n. 2
0
        public void PostTask(IThreadTask task)
        {
            if (!m_IsRunning)
            {
                Log.w("Work Thread Not Start.");
                return;
            }

            m_TaskLoop.PostTask(task);
            m_ResetEvent.Set();
        }
Esempio n. 3
0
 /// <summary>
 /// Add an action to the UN thread
 /// </summary>
 /// <param name="action">the action</param>
 public void RunOnThread(IThreadTask action)
 {
     if (threadEnabled)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(OnThreadProcess), action);
     }
     else
     {
         RunOnUnityThread(action);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Add an action to the uConstruct thread
 /// </summary>
 /// <param name="action">the action</param>
 public static void RunOnUConstructThread(IThreadTask action)
 {
     if (enabled)
     {
         UConstructThreadActions.Add(action);
     }
     else
     {
         RunOnUnityThread(action);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Add an action to the unity thread
        /// </summary>
        /// <param name="action">the action</param>
        public void RunOnUnityThread(IThreadTask action)
        {
            if (action == null)
            {
                return;
            }

            if (inUnityThread)
            {
                action.Invoke();
            }
            else
            {
                UnityThreadQueuedActions.Add(action);
            }
        }
Esempio n. 6
0
        public void PostTask(IThreadTask task)
        {
            lock (m_Lock)
            {
                if (m_AddTaskList == null)
                {
                    m_AddTaskList = new List <IThreadTask>();
                }

                if (m_TaskList == null)
                {
                    m_TaskList = new List <IThreadTask>();
                }

                m_AddTaskList.Add(task);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Called when the thread needs to process the task.
        /// </summary>
        /// <param name="processObject"></param>
        protected void OnThreadProcess(System.Object processObject)
        {
            IThreadTask task = processObject as IThreadTask;

            if (task != null)
            {
                try
                {
                    task.Invoke();
                }
                catch (UnityException ex)
                {
                    Debug.LogError("uNature Thread Manager : Error caught while running thread action : \n" + ex);
                }
            }
            else
            {
                Debug.LogError("uNature Thread Manager : Unrecognized thread process : " + processObject.ToString());
            }
        }
Esempio n. 8
0
       void touch_panel_mgr_OnPanelCmdEvent(string cmd, params int[] param)
       {
           if (voiceThread != null)
           {
               voiceThread.Abort();
               voiceThread.Join();
               System.Threading.Thread.Sleep(1000);
           }
           if (cmd.ToUpper() == "NORMAL")
           {
               voiceThread = new ThreadPlaySound(param[0], param[1], Status, touch_panel_mgr,this);
             //new System.Threading.Thread(new ParameterizedThreadStart(PlaySpeechTask));
              
           }
           if (cmd == "Silence")
           {
               voiceThread = new ThreadPlay20KTest(param[1], Status, touch_panel_mgr,this);
           }

           voiceThread.Start();
       }
Esempio n. 9
0
       void kenwood_OnSlaveReceiveEvent(object sender, byte[] data)
       {
           try
           {
               if (data[0]!=0  && data[0] != this.id)
                   return;

               string cmd = System.Text.ASCIIEncoding.ASCII.GetString(data);
               if (cmd[1] == 'P') //play   p+index + times
               {

                   if(data[0]!=0)
                   kenwood.Reply(new byte[] { data[0], (byte)'P', (byte)1 });
                   int inx = cmd[2];
                   int repeat = cmd[3];

                   Console.WriteLine("預錄詞命令接收,停止現有任務中!");
                   if (voiceThread != null)
                   {
                       voiceThread.Abort();
                       voiceThread.Join();
                      // System.Threading.Thread.Sleep(1000);
                   }
                   Console.WriteLine("預錄詞{0},{1}次",inx+1,repeat);
                   voiceThread = new ThreadPlaySound(inx, repeat, Status, touch_panel_mgr,this);  // new System.Threading.Thread(new ParameterizedThreadStart(PlaySpeechTask)  );
                   // voiceThread.Start(new int[] { inx, repeat });
                   voiceThread.Start();
               }
               if (cmd[1] == 'T') //tetsing   p+index + times
               {
                   if (data[0] != 0)  //if brocast data[0]==0 no nedd to reply
                   kenwood.Reply(new byte[] { data[0], (byte)'T' });
                  int repeat = cmd[3];
                   bool IsSilent = cmd[2]==1?true:false;
                   Console.WriteLine("測試命令接收,停止現有任務中!");
                 
                   if (voiceThread != null)
                   {
                       voiceThread.Abort();
                       voiceThread.Join();
                      // System.Threading.Thread.Sleep(1000);
                   }
                   
               

                   if (!IsSilent)
                   {

                       Console.WriteLine("開始測試!");
                       voiceThread = new ThreadPlaySpeechTest(0, repeat, Status, touch_panel_mgr, this);  // new System.Threading.Thread(new ParameterizedThreadStart(PlaySpeechTask)  );

                   }
                   else
                   {
                       Console.WriteLine("開始測試!");
                       voiceThread = new ThreadPlay20KTest(repeat, Status, touch_panel_mgr, this);
                   }
                   // voiceThread.Start(new int[] { inx, repeat });
                   voiceThread.Start();
               }
               else if (cmd[1] == 'S') //get play status  [id status cnt]
               {

                   // bit 0~bit7    play  testing  door   power1  power2   amp/speaker
                   byte[] statusdata = new byte[2];
                   Status.CopyTo(statusdata, 0);
                   int pcnt = 0;
                   if (voiceThread != null)
                       pcnt = voiceThread.PlayCnt;
                   if (data[0] != 0)
                   kenwood.Reply(new byte[] { data[0], (byte)'S', statusdata[0],statusdata[1] ,(byte)pcnt });
               }
               else if (cmd[1] == 'X')
               {
                   if (data[0] != 0)
                   kenwood.Reply(new byte[] { data[0], (byte)'X' });
                   Console.WriteLine("中止現有任務!");
                   if (voiceThread != null)
                   {
                       voiceThread.Abort();
                      // voiceThread.Join();
                     //  Status.Set((int)StatusIndex.BUSY, false);
                       Console.WriteLine("任務已中止!");
                       System.Threading.Thread.Sleep(1000);
                   }
                  
               }
               else if (cmd[1] == 'E') //echo
               {

                   if (data[0] != 0)
                   kenwood.Reply(new byte[] { data[0], (byte)'E'});

                   System.Threading.Thread th = new Thread(
                       () =>
                       {
                           Console.WriteLine("Echo begin!");
                           if (IOCard != null)
                           {
                               lock(IOCard)
                               IOCard.SetIO(1, 1, true);
                           }
                           System.Threading.Thread.Sleep(9000);
                           if (IOCard != null)
                           {
                               lock (IOCard)
                               IOCard.SetIO(1, 1, false);
                           }
                           Console.WriteLine("Echo end!");
                       }
                  );

                   th.Start();
                     //  voiceThread.Abort();
                      // do swich ptt of radio here 
               }
               else if (cmd[1] == 'V')  //voice broadcast
               {
                
                   if (cmd[2] == 1)   // switch ptt of wireless to active 
                   {
                       Console.WriteLine("PTT 切入!");
                       Status.Set((int)StatusIndex.BUSY, true);
                       if (IOCard != null)
                       {
                           lock(IOCard)
                            IOCard.SetIO(1, 2, true);
                       }
                   }
                   else    // switch ptt to normal
                   {
                       Status.Set((int)StatusIndex.BUSY, false); ;
                       Console.WriteLine("PTT 結束!");
                       if (IOCard != null)
                       {
                           lock(IOCard)
                             IOCard.SetIO(1, 2, false);
                       }
                   }
                   if (data[0] != 0)
                       kenwood.Reply(new byte[] { data[0], (byte)'V' });

               }
               else if (cmd[1] == 'U') //Set Date Time
               {
                   Console.WriteLine("Set Date Time");
                   SetSysDateTime(2000 + cmd[2],cmd[3],cmd[4],cmd[5],cmd[6],cmd[7]);
                   if (data[0] != 0)
                       kenwood.Reply(new byte[] { data[0], (byte)'U' });
                 
               }

           }
           catch (Exception ex)
           {
               Console.WriteLine(ex.Message + "," + ex.StackTrace);
           }

          
           //throw new NotImplementedException();
       }
Esempio n. 10
0
 public void PostTask(IThreadTask task)
 {
     m_TaskLoop.PostTask(task);
 }
Esempio n. 11
0
 public ResultTask(IThreadTask task)
 {
     m_Task = task;
 }
Esempio n. 12
0
        /// <summary>
        /// Run any action with a specific delay of seconds.
        /// </summary>
        /// <param name="task">the task you want to run after the specific amount of seconds</param>
        /// <param name="time">the specific amount of seconds to wait</param>
        private IEnumerator DelayActionSecondsCoroutine(IThreadTask task, float time)
        {
            yield return(new WaitForSeconds(time));

            task.Invoke();
        }
Esempio n. 13
0
 /// <summary>
 /// Run any action after 1 frame
 /// </summary>
 /// <param name="task">the task you want to run after 1 frame</param>
 public void DelayActionFrames(int frames, IThreadTask task)
 {
     StartCoroutine(DelayActionFrameCoroutine(frames, task));
 }
Esempio n. 14
0
 /// <summary>
 /// Run any action with a specific delay of seconds.
 /// </summary>
 /// <param name="task">the task you want to run after the specific amount of seconds</param>
 /// <param name="time">the specific amount of seconds to wait</param>
 public void DelayActionSeconds(IThreadTask task, float time)
 {
     StartCoroutine(DelayActionSecondsCoroutine(task, time));
 }
Esempio n. 15
0
 public void AddTask(IThreadTask task)
 {
     this.InvokeMethod(() => { _tasks.Add(task); task.Start(); });
 }
Esempio n. 16
0
 /// <summary>
 /// Add an action to the unity thread
 /// </summary>
 /// <param name="action">the action</param>
 public static void RunOnUnityThread(IThreadTask action)
 {
     UnityThreadQueuedActions.Add(action);
 }