Exemplo n.º 1
0
        public async Task <MeadowDeviceInfo> GetDeviceInfoAsync(TimeSpan timeout, CancellationToken cancellationToken = default)
        {
            var command = new SimpleCommandBuilder(
                HcomMeadowRequestType.HCOM_MDOW_REQUEST_GET_DEVICE_INFORMATION)
                          .WithTimeout(timeout)
                          .WithResponseType(MeadowMessageType.DeviceInfo)
                          .WithCompletionResponseType(MeadowMessageType.Concluded)
                          .Build();


            try
            {
                var commandResponse =
                    await SendCommandAsync(command, cancellationToken)
                    .ConfigureAwait(false);

                if (commandResponse.IsSuccess)
                {
                    return(new MeadowDeviceInfo(commandResponse.Message !));
                }

                throw new DeviceInfoException();
            }
            catch (MeadowDeviceManagerException mdmEx)
            {
                throw new DeviceInfoException(mdmEx);
            }
        }
Exemplo n.º 2
0
        public async Task <bool> GetMonoRunStateAsync(CancellationToken cancellationToken = default)
        {
            Logger.LogDebug("Sending Mono Run State Request");

            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_RUN_STATE)
                .WithResponseType(MeadowMessageType.Data)
                .Build();

            var commandResponse =
                await SendCommandAsync(command, cancellationToken)
                .ConfigureAwait(false);

            var result = false;

            switch (commandResponse.Message)
            {
            case "On reset, Meadow will start MONO and run app.exe":
            case "Mono is enabled":
                result = true;
                break;

            case "On reset, Meadow will not start MONO, therefore app.exe will not run":
            case "Mono is disabled":
                result = false;
                break;
            }

            Logger.LogDebug("Mono Run State: {runState}", result ? "enabled" : "disabled");
            return(result);
        }
        public async Task <IList <string> > GetFilesAndFoldersAsync(
            TimeSpan timeout,
            CancellationToken cancellationToken = default)
        {
            var started = false;

            var items = new List <string>();

            EventHandler <MeadowMessageEventArgs> handler = (s, e) =>
            {
                if (e.MessageType == MeadowMessageType.Accepted)
                {
                    started = true;
                }
                else if (started == false)
                {   //ignore everything until we've started a new file list request
                    return;
                }

                if (e.MessageType == MeadowMessageType.Data)
                {
                    items.Add(e.Message);
                }
            };

            var command = new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4)
                          .WithResponseHandler(handler)
                          .Build();

            await SendCommandAsync(command, cancellationToken)
            .ConfigureAwait(false);

            return(items);
        }
Exemplo n.º 4
0
        public Task Uart1Apps(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_NO_TRACE_TO_UART)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 5
0
        public Task TraceEnableAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_SEND_TRACE_TO_HOST)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 6
0
        public Task RestartEsp32Async(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_RESTART_ESP32)
                .WithCompletionResponseType(MeadowMessageType.Concluded)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 7
0
        public Task QspiInitAsync(int value, CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_S25FL_QSPI_INIT)
                .WithUserData((uint)value)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 8
0
        public Task SetDeveloper4(uint userData, CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4)
                .WithUserData(userData)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 9
0
        public Task SetTraceLevelAsync(uint traceLevel, CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_CHANGE_TRACE_LEVEL)
                .WithUserData(traceLevel)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 10
0
        public Task NshDisableAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENABLE_DISABLE_NSH)
                .WithUserData(0)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
        public Task EraseFlashAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_BULK_FLASH_ERASE)
                .WithCompletionResponseType(MeadowMessageType.SerialReconnect)
                .WithTimeout(TimeSpan.FromMinutes(5))
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 12
0
        public Task EnterDfuModeAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENTER_DFU_MODE)
                .WithCompletionResponseType(MeadowMessageType.Accepted)
                .WithResponseFilter(x => true)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 13
0
        public async Task StartDebuggingAsync(int port, CancellationToken cancellationToken)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_START_DBG_SESSION)
                .WithCompletionResponseType(MeadowMessageType.Accepted)
                .WithResponseType(MeadowMessageType.Accepted)
                .Build();

            await SendCommandAsync(command, cancellationToken);
        }
Exemplo n.º 14
0
        public async Task ResetMeadowAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_RESET_PRIMARY_MCU)
                .WithCompletionResponseType(MeadowMessageType.SerialReconnect)
                .WithResponseType(MeadowMessageType.SerialReconnect)
                .Build();

            await SendCommandAsync(command, cancellationToken)
            .ConfigureAwait(false);
        }
Exemplo n.º 15
0
        public Task MonoFlashAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_FLASH)
                .WithCompletionFilter(
                    e => e.Message.StartsWith("Mono runtime successfully flashed."))
                .WithTimeout(TimeSpan.FromMinutes(5))
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
        public Task RenewFileSystemAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(
                    HcomMeadowRequestType.HCOM_MDOW_REQUEST_PART_RENEW_FILE_SYS)
                .WithCompletionResponseType(MeadowMessageType.SerialReconnect)
                .WithTimeout(TimeSpan.FromMinutes(5))
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
Exemplo n.º 17
0
        public async Task <string?> GetDeviceMacAddressAsync(CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(
                    HcomMeadowRequestType.HCOM_MDOW_REQUEST_READ_ESP_MAC_ADDRESS).Build();

            var commandResponse =
                await SendCommandAsync(command, cancellationToken)
                .ConfigureAwait(false);

            return(commandResponse.Message);
        }
Exemplo n.º 18
0
        public async Task MonoEnableAsync(CancellationToken cancellationToken = default)
        {
            Logger.LogDebug("Sending Mono Enable Request");
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_ENABLE)
                .WithCompletionResponseType(MeadowMessageType.SerialReconnect)
                .WithResponseType(MeadowMessageType.SerialReconnect)
                .Build();

            await SendCommandAsync(command, cancellationToken)
            .ConfigureAwait(false);
        }
        public Task FormatFileSystemAsync(uint partition = 0,
                                          CancellationToken cancellationToken = default)
        {
            var command =
                new SimpleCommandBuilder(
                    HcomMeadowRequestType.HCOM_MDOW_REQUEST_FORMAT_FLASH_FILE_SYS)
                .WithCompletionResponseType(MeadowMessageType.SerialReconnect)
                .WithTimeout(TimeSpan.FromMinutes(5))
                .WithUserData(partition)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
        public Task ForwardVisualStudioDataToMonoAsync(byte[] debuggerData,
                                                       uint userData,
                                                       CancellationToken cancellationToken =
                                                       default)
        {
            var command =
                new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEBUGGING_DEBUGGER_DATA)
                .WithData(debuggerData)
                .WithResponseType(MeadowMessageType.Accepted)
                .WithCompletionResponseType(MeadowMessageType.Accepted)
                .WithUserData(userData)
                .WithAcknowledgement(false)
                .Build();

            return(SendCommandAsync(command, cancellationToken));
        }
        public async Task <IDictionary <string, uint> > GetFilesAndCrcsAsync(
            TimeSpan timeout,
            int partition = 0,
            CancellationToken cancellationToken = default)
        {
            var started = false;

            EventHandler <MeadowMessageEventArgs> handler = (s, e) =>
            {
                if (e.MessageType == MeadowMessageType.FileListTitle)
                {
                    FilesOnDevice.Clear();
                    started = true;
                }
                else if (started == false)
                {
                    //ignore everything until we've started a new file list request
                    return;
                }

                if (e.MessageType == MeadowMessageType.FileListCrcMember)
                {
                    SetFileAndCrcsFromMessage(e.Message);
                }
            };

            var command = new SimpleCommandBuilder(HcomMeadowRequestType.HCOM_MDOW_REQUEST_LIST_PART_FILES_AND_CRC)
                          .WithResponseHandler(handler)
                          .WithUserData((uint)partition)
                          .Build();

            await SendCommandAsync(command, cancellationToken)
            .ConfigureAwait(false);

            return(FilesOnDevice);
        }
        public async Task <string?> GetInitialBytesFromFile(string fileName,
                                                            uint partition = 0,
                                                            CancellationToken cancellationToken =
                                                            default)
        {
            Logger.LogDebug("Getting initial bytes from {fileName}", fileName);
            var encodedFileName = System.Text.Encoding.UTF8.GetBytes(fileName);

            var command =
                new SimpleCommandBuilder(
                    HcomMeadowRequestType.HCOM_MDOW_REQUEST_GET_INITIAL_FILE_BYTES)
                .WithResponseType(MeadowMessageType.InitialFileData)
                .WithData(encodedFileName)
                .Build();

            var commandResponse = await SendCommandAsync(command, cancellationToken);

            if (!commandResponse.IsSuccess)
            {
                Logger.LogWarning("No bytes found for file.");
            }

            return(commandResponse.Message);
        }