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 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 <bool> WaitForResponseMessage(MeadowSerialDevice meadow, Predicate <MeadowMessageEventArgs> filter, int millisecondDelay = 10000) { var tcs = new TaskCompletionSource <bool>(); var result = false; EventHandler <MeadowMessageEventArgs> handler = (s, e) => { if (filter(e)) { result = true; tcs.SetResult(true); } }; if (meadow.DataProcessor != null) { meadow.DataProcessor.OnReceiveData += handler; } await Task.WhenAny(new Task[] { tcs.Task, Task.Delay(millisecondDelay) }); if (meadow.DataProcessor != null) { meadow.DataProcessor.OnReceiveData -= handler; } return(result); }
public static async Task QspiInit(MeadowSerialDevice meadow, int userData) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_S25FL_QSPI_INIT, userData : (uint)userData); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_S25FL_QSPI_INIT; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType, (uint)userData); }
public static async Task Uart1Trace(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_SEND_TRACE_TO_UART); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_SEND_TRACE_TO_UART; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
public static async Task NshEnable(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENABLE_DISABLE_NSH, userData : (uint)1); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENABLE_DISABLE_NSH; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType, (uint) 1); }
public static async Task SetDeveloper4(MeadowSerialDevice meadow, int userData) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4, userData : (uint)userData); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEVELOPER_4; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType, (uint)userData); }
public static async Task TraceDisable(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_NO_TRACE_TO_HOST); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_NO_TRACE_TO_HOST; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
public static void 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) { // No CSV, just the source file name. So we'll assume the targetFileName is correct TransmitFileInfoToExtFlash(meadow, meadowRequestType, fileName, targetFileName, partition, 0, false, 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; } for (int i = 0; i < csvArray.Length; i += 2) { // Send files one-by-one TransmitFileInfoToExtFlash(meadow, meadowRequestType, csvArray[i].Trim(), csvArray[i + 1].Trim(), partition, 0, false); } } }
public static async Task MonoRunState(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_RUN_STATE); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_MONO_RUN_STATE; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
public static async Task ResetMeadow(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_RESET_PRIMARY_MCU, doAcceptedCheck : false); // needs some time to complete restart Thread.Sleep(1000); }
public static async Task EnterDfuMode(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENTER_DFU_MODE); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_ENTER_DFU_MODE; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
// This method is called to sent to Visual Studio debugging to Mono public static void ForwardVisualStudioDataToMono(byte[] debuggerData, MeadowSerialDevice meadow, int userData) { // Console.WriteLine($"{DateTime.Now:HH:mm:ss.fff}-MDM-Forwarding {debuggerData.Length} bytes to Mono via hcom"); _meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_DEBUGGING_DEBUGGER_DATA; new SendTargetData(meadow).BuildAndSendSimpleData(debuggerData, _meadowRequestType, (uint)userData); }
public static async Task RenewFileSys(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_PART_RENEW_FILE_SYS, MeadowMessageType.SerialReconnect); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_PART_RENEW_FILE_SYS; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
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 Esp32ReadMac(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_READ_ESP_MAC_ADDRESS); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_READ_ESP_MAC_ADDRESS; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
public static async Task Esp32Restart(MeadowSerialDevice meadow) { await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_RESTART_ESP32); //_meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_RESTART_ESP32; //new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); }
private static void TransmitFileInfoToExtFlash(MeadowSerialDevice meadow, HcomMeadowRequestType requestType, string sourceFileName, string targetFileName, int partition, uint mcuAddr, bool deleteFile, bool lastInSeries = false) { var sw = new Stopwatch(); var sendTargetData = new SendTargetData(meadow, false); try { //---------------------------------------------- if (deleteFile == true) { // No data packets, no end-of-file message and no mcu address sendTargetData.BuildAndSendFileRelatedCommand(requestType, (UInt32)partition, 0, 0, 0, string.Empty, sourceFileName); return; } // If ESP32 file we must also send the MD5 has of the file string md5Hash = string.Empty; if (mcuAddr != 0) { using (var md5 = MD5.Create()) { using (var stream = File.OpenRead(sourceFileName)) { var hash = md5.ComputeHash(stream); md5Hash = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } } // Open, read and close the data file var fileBytes = File.ReadAllBytes(sourceFileName); var fileCrc32 = CrcTools.Crc32part(fileBytes, fileBytes.Length, 0); var fileLength = fileBytes.Length; sw.Start(); sw.Restart(); sendTargetData.SendTheEntireFile(requestType, targetFileName, (uint)partition, fileBytes, mcuAddr, fileCrc32, md5Hash, lastInSeries); sw.Stop(); if (sendTargetData.Verbose) { Console.WriteLine($"It took {sw.ElapsedMilliseconds:N0} millisec to send {fileLength:N0} bytes. FileCrc:{fileCrc32:x08}"); } } catch (Exception ex) { Debug.WriteLine($"TransmitFileInfoToExtFlash threw :{ex}"); throw; } }
//providing a numeric (0 = none, 1 = info and 2 = debug) public static async Task SetTraceLevel(MeadowSerialDevice meadow, int level) { if (level < 0 || level > 3) { throw new System.ArgumentOutOfRangeException(nameof(level), "Trace level must be between 0 & 3 inclusive"); } await ProcessCommand(meadow, HcomMeadowRequestType.HCOM_MDOW_REQUEST_CHANGE_TRACE_LEVEL, userData : (uint)level); }
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); }
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); }
//providing a numeric (0 = none, 1 = info and 2 = debug) public static void SetTraceLevel(MeadowSerialDevice meadow, int level) { if (level < 0 || level > 3) { throw new System.ArgumentOutOfRangeException(nameof(level), "Trace level must be between 0 & 3 inclusive"); } _meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_CHANGE_TRACE_LEVEL; new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType, (uint)level); }
public static void PartitionFileSystem(MeadowSerialDevice meadow, int numberOfPartitions = 2) { if (numberOfPartitions < 1 || numberOfPartitions > 8) { throw new IndexOutOfRangeException("Number of partitions must be between 1 & 8 inclusive"); } meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_PARTITION_FLASH_FS; new SendTargetData(meadow).SendSimpleCommand(meadowRequestType, (uint)numberOfPartitions); }
public static async Task ProcessCommand(MeadowSerialDevice meadow, HcomMeadowRequestType requestType, Predicate <MeadowMessageEventArgs> filter, uint userData = 0, bool doAcceptedCheck = true, int timeoutMs = 10000) { await new SendTargetData(meadow).SendSimpleCommand(requestType, userData, doAcceptedCheck); var result = await WaitForResponseMessage(meadow, filter, timeoutMs); if (!result) { throw new MeadowDeviceManagerException(requestType); } }
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 <string> GetDeviceSerialNumber(MeadowSerialDevice meadow, int timeoutMs = 1000) { _meadowRequestType = HcomMeadowRequestType.HCOM_MDOW_REQUEST_GET_DEVICE_INFORMATION; await new SendTargetData(meadow).SendSimpleCommand(_meadowRequestType); var result = await WaitForResponseMessage(meadow, p => p.MessageType == MeadowMessageType.DeviceInfo, millisecondDelay : timeoutMs); if (result.isSuccessful) { return(ParseDeviceInfo(result.message, "Serial Number: ", ",")); } return(string.Empty); }
public static void EnterEchoMode(MeadowSerialDevice meadow) { if (meadow == null) { Console.WriteLine("No current device"); return; } if (meadow.SerialPort == null && meadow.Socket == null) { Console.WriteLine("No current serial port or socket"); return; } meadow.Initialize(true); }
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 FlashEsp(MeadowSerialDevice device, string sourcePath) { Console.WriteLine($"Transferring {DownloadManager.NetworkMeadowCommsFilename}"); await MeadowFileManager.WriteFileToEspFlash(device, Path.Combine(sourcePath, DownloadManager.NetworkMeadowCommsFilename), mcuDestAddr : "0x10000"); await Task.Delay(1000); Console.WriteLine($"Transferring {DownloadManager.NetworkBootloaderFilename}"); await MeadowFileManager.WriteFileToEspFlash(device, Path.Combine(sourcePath, DownloadManager.NetworkBootloaderFilename), mcuDestAddr : "0x1000"); await Task.Delay(1000); Console.WriteLine($"Transferring {DownloadManager.NetworkPartitionTableFilename}"); await MeadowFileManager.WriteFileToEspFlash(device, Path.Combine(sourcePath, DownloadManager.NetworkPartitionTableFilename), mcuDestAddr : "0x8000"); await Task.Delay(1000); }