private void ResetButton_Click(object sender, RoutedEventArgs e)
        {
            _dataContext.AddOutput("Reset Button is clicked!");
            var resetCommand = new PoseCommand(0, 0, 0);

            _commands.Enqueue(resetCommand);

            new Thread(CommandExecutor.SharedInstance.Execute).Start();

            Scroller.ScrollToBottom();
        }
        public void addPoseCommandAction(PoseCommandAction action, String mode)
        {
            PoseCommand command;

            if (!modePoseCommands.TryGetValue(mode, out command))
            {
                command = new PoseCommand();
                modePoseCommands.Add(mode, command);
            }
            command.addAction(action);
        }
        public void Execute(PoseCommand command)
        {
            if ((SerialPort == null) || !SerialPort.IsConnected)
            {
                return;
            }

            command.SendTimeStamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            // command text is based on target pose and current pose
            SerialPort.WriteLine(command.CommandText);
        }
        public void Callback(SerialPort sender, PoseCommand command)
        {
            var sp = sender;

            while (sp.BytesToRead > 0)
            {
                var d = sp.ReadLine();

                if (command != null)
                {
                    command.Receive(d);
                    LogHandler?.Invoke(command.ToReceiveLog());
                    // if the gcommand is executed
                    if (d.Equals("OK\r", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // update the current position
                        if (command.NextPosePosition != null)
                        {
                            CommandStore.SharedInstance.CurrentPosePosition = command.NextPosePosition;
                        }

                        // report current position
                        CommandExecutor.SharedInstance.brain.Arm.ReportPose(
                            CommandExecutor.SharedInstance.RegisterId.Value,
                            command.SendTimeStamp.ToString(),
                            CommandStore.SharedInstance.CurrentPosePosition.X,
                            CommandStore.SharedInstance.CurrentPosePosition.Y,
                            CommandStore.SharedInstance.CurrentPosePosition.Z);

                        LogHandler?.Invoke($"Reported Pose: {CommandStore.SharedInstance.CurrentPosePosition.X}, {CommandStore.SharedInstance.CurrentPosePosition.Y}, {CommandStore.SharedInstance.CurrentPosePosition.Z}");

                        // clean the current command
                        CommandStore.SharedInstance.CurrentCommand = null;

                        // clean the waiting flag
                        lock (CommandExecutor.SharedInstance)
                        {
                            IsWaitingResponse = false;
                        }
                    }
                }
            }
        }