using Plane.Protocols;
using System.Threading.Tasks;

namespace Plane.Copters
{
    partial class PlaneCopter
    {
        /// <summary>
        /// // 林俊清, 20160122, 不明确。目测是发送重启命令，在刷固件之前用到。
        /// </summary>
        /// <param name="bootloaderMode"></param>
        /// <returns>表示此命令异步发送操作的 <see cref="Task"/> 实例。</returns>
        public async Task RebootAsync(bool bootloaderMode = false)
        {
            int param1 = 1;
            if (bootloaderMode)
            {
                param1 = 3;
            }

            if (MAV.sysid != 0 && MAV.compid != 0)
            {
                await DoCommandAsync(MAVLink.MAV_CMD.PREFLIGHT_REBOOT_SHUTDOWN, param1, 0, 0, 0, 0, 0, 0).ConfigureAwait(false);
                await DoCommandAsync(MAVLink.MAV_CMD.PREFLIGHT_REBOOT_SHUTDOWN, 1, 0, 0, 0, 0, 0, 0).ConfigureAwait(false);
            }
            else
            {

                for (byte a = byte.MinValue; a < byte.MaxValue; a++)
                {
                    MAV.sysid = a;
                    await DoCommandAsync(MAVLink.MAV_CMD.PREFLIGHT_REBOOT_SHUTDOWN, param1, 0, 0, 0, 0, 0, 0).ConfigureAwait(false);
                }
            }
        }
    }
}
