//device Id information is processed when the message is received //this will request the device Id and return true it was set successfully public override async Task <bool> SetDeviceInfo(int timeoutInMs = 5000) { var timeOutTask = Task.Delay(timeoutInMs); bool isDeviceIdSet = false; EventHandler <MeadowMessageEventArgs> handler = null; var tcs = new TaskCompletionSource <bool>(); handler = (s, e) => { if (e.MessageType == MeadowMessageType.DeviceInfo) { isDeviceIdSet = true; tcs.SetResult(true); } }; dataProcessor.OnReceiveData += handler; MeadowDeviceManager.GetDeviceInfo(this); await Task.WhenAny(new Task[] { timeOutTask, tcs.Task }); dataProcessor.OnReceiveData -= handler; return(isDeviceIdSet); }
public static async Task ListFilesAndCrcs(MeadowSerialDevice meadow, int partition = 0) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_LIST_PART_FILES_AND_CRC, userData : (uint)partition, timeoutMs : 30000); //meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_LIST_PART_FILES_AND_CRC; //new SendTargetData(meadow).SendSimpleCommand(meadowRequestType, (uint)partition); }
public static async Task VerifyErasedFlash(MeadowSerialDevice meadow) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_VERIFY_ERASED_FLASH, timeoutMs : 30000); //meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_VERIFY_ERASED_FLASH; //new SendTargetData(meadow).SendSimpleCommand(meadowRequestType); }
public static async Task FormatFileSystem(MeadowSerialDevice meadow, int partition) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_FORMAT_FLASH_FILE_SYS, userData : (uint)partition); //meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_FORMAT_FLASH_FILE_SYS; //new SendTargetData(meadow).SendSimpleCommand(meadowRequestType, (uint)partition); }
public static async Task CreateFileSystem(MeadowSerialDevice meadow) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_CREATE_ENTIRE_FLASH_FS); //meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_CREATE_ENTIRE_FLASH_FS; //new SendTargetData(meadow).SendSimpleCommand(meadowRequestType); }
public static async Task PartitionFileSystem(MeadowSerialDevice meadow, int numberOfPartitions = 2) { if (numberOfPartitions < 1 || numberOfPartitions > 8) { throw new IndexOutOfRangeException("Number of partitions must be between 1 & 8 inclusive"); } await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_PARTITION_FLASH_FS, userData : (uint)numberOfPartitions); }
//device name is processed when the message is received //this will request the device name and return true it was successfully public override async Task GetDeviceName(int timeoutInMs = 1000) { var result = await MeadowDeviceManager.GetDeviceName(this, timeoutInMs); if (!result.isSuccessful) { throw new DeviceInfoException(); } }
public static async Task DeleteFile(MeadowSerialDevice meadow, string fileName, int partition = 0) { await Task.WhenAll( Task.Run(() => TransmitFileInfoToExtFlash(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_DELETE_FILE_BY_NAME, fileName, fileName, partition, 0, true)), MeadowDeviceManager.WaitForResponseMessage(meadow, x => x.MessageType == MeadowMessageType.Concluded)); //meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_DELETE_FILE_BY_NAME; //TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileName, fileName, partition, 0, true); }
public static async Task MonoUpdateRt(MeadowSerialDevice meadow, string fileName, string targetFileName = null, int partition = 0) { if (string.IsNullOrWhiteSpace(targetFileName)) { targetFileName = Path.GetFileName(fileName); } await Task.WhenAll( Task.Run(() => TransmitFileInfoToExtFlash(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_UPDATE_RUNTIME, fileName, targetFileName, partition, 0, false, true)), MeadowDeviceManager.WaitForResponseMessage(meadow, x => x.MessageType == MeadowMessageType.Concluded, 300000)); }
public static async Task <bool> WriteFileToFlash(MeadowSerialDevice meadow, string fileName, string targetFileName = null, int partition = 0) { meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_FILE_TRANSFER; if (string.IsNullOrWhiteSpace(targetFileName)) { targetFileName = Path.GetFileName(fileName); } // For the STM32F7 on meadow, we need source file and destination file names. string[] csvArray = fileName.Split(','); if (csvArray.Length == 1) { await Task.WhenAll( Task.Run(() => TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileName, targetFileName, partition, 0, false, true)), MeadowDeviceManager.WaitForResponseMessage(meadow, x => x.MessageType == MeadowMessageType.Concluded)); // No CSV, just the source file name. So we'll assume the targetFileName is correct //TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileName, targetFileName, partition, 0, false, true); return(true); } else { // At this point, the fileName field should contain a CSV string containing the source // and destionation file names, always in an even number. if (csvArray.Length % 2 != 0) { Console.WriteLine("Please provide a CSV input with file names \"source, destination, source, destination\""); return(false); } for (int i = 0; i < csvArray.Length; i += 2) { // Send files one-by-one bool lastFile = i == csvArray.Length - 2 ? true : false; TransmitFileInfoToExtFlash(meadow, meadowRequestType, csvArray[i].Trim(), csvArray[i + 1].Trim(), partition, 0, false, lastFile); } } return(false); }
public static async Task EraseFlash(MeadowSerialDevice meadow) { // not sure why this responds with a SerialReconnect message await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_BULK_FLASH_ERASE, MeadowMessageType.SerialReconnect, timeoutMs : 200000); }
// fileName - is the name of the file on this host PC // targetFileName - is the name of the file on the F7 public static async Task WriteFileToEspFlash(MeadowSerialDevice meadow, string fileName, string targetFileName = null, int partition = 0, string mcuDestAddr = null) { meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_START_ESP_FILE_TRANSFER; // For the ESP32 on the meadow, we don't need the target file name, we just need the // MCU's destination address and the file's binary. // Assume if no mcuDestAddr that the fileName is a CSV with both file names and Mcu Addr if (mcuDestAddr != null) { // Since the mcuDestAddr is used we'll assume the fileName field just contains // a single file. if (string.IsNullOrWhiteSpace(targetFileName)) { // While not used by the ESP32 it cost nothing to send it and can help // with debugging targetFileName = Path.GetFileName(fileName); } // Convert mcuDestAddr from a string to a 32-bit unsigned int, but first // insure it starts with 0x UInt32 mcuAddr = 0; if (mcuDestAddr.StartsWith("0x") || mcuDestAddr.StartsWith("0X")) { mcuAddr = UInt32.Parse(mcuDestAddr.Substring(2), System.Globalization.NumberStyles.HexNumber); } else { Console.WriteLine($"The '--McuDestAddr' argument must be followed with an address in the form '0x1800'"); return; } await Task.WhenAll( Task.Run(() => TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileName, targetFileName, partition, mcuAddr, false, true)), MeadowDeviceManager.WaitForResponseMessage(meadow, x => x.MessageType == MeadowMessageType.Concluded)); } else { // At this point, the fileName field should contain a CSV string containing the destination // addresses followed by file's location within the host's file system. // E.g. "0x8000, C:\Blink\partition-table.bin, 0x1000, C:\Blink\bootloader.bin, 0x10000, C:\Blink\blink.bin" string[] fileElement = fileName.Split(','); if (fileElement.Length % 2 != 0) { Console.WriteLine("Please provide a CSV input with \"address, fileName, address, fileName\""); return; } UInt32 mcuAddr; for (int i = 0; i < fileElement.Length; i += 2) { // Trim any white space from this mcu addr and file name fileElement[i] = fileElement[i].Trim(); fileElement[i + 1] = fileElement[i + 1].Trim(); if (fileElement[i].StartsWith("0x") || fileElement[i].StartsWith("0X")) { // Fill in the Mcu Addr mcuAddr = UInt32.Parse(fileElement[i].Substring(2), System.Globalization.NumberStyles.HexNumber); } else { Console.WriteLine("Please provide a CSV input with addresses like 0x1234"); return; } // Meadow.CLI --Esp32WriteFile --SerialPort Com26 --File // "0x8000, C:\Download\Esp32\Hello\partition-table.bin, 0x1000, C:\Download\Esp32\Hello\bootloader.bin, 0x10000, C:\Download\Esp32\Hello\hello-world.bin" // File Path and Name targetFileName = Path.GetFileName(fileElement[i + 1]); bool lastFile = i == fileElement.Length - 2 ? true : false; // this may need need to be awaited? TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileElement[i + 1], targetFileName, partition, mcuAddr, false, lastFile); } } }
public static async Task ListFiles(MeadowSerialDevice meadow, int partition = 0) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_LIST_PARTITION_FILES, userData : (uint)partition); }
public static async Task CreateFileSystem(MeadowSerialDevice meadow) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_CREATE_ENTIRE_FLASH_FS); }
public static async Task InitializeFileSystem(MeadowSerialDevice meadow, int partition) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_INITIALIZE_FLASH_FS, userData : (uint)partition); }
public static async Task EraseFlash(MeadowSerialDevice meadow) { await MeadowDeviceManager.ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_BULK_FLASH_ERASE, timeoutMs : 200000); }