public static void Run(string[] args) { SecureString pw; Console.WriteLine("Nusbio initialization"); Nusbio.ActivateFastMode(); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { pw = AskForPW(nusbio, VolumeName); _sfsManager = new sFs.sFsManager(VolumeName, pw, nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3); _sFsREPLCommand = new sFs.sFsREPLCommand(_sfsManager); Cls(nusbio, true); Console.WriteLine(Environment.NewLine + Environment.NewLine); var ok = ReloadFileSystem(); if (!ok) { Cls(nusbio, true); if (ConsoleEx.Question(3, string.Format("Cannot access {0} with this password, retry password Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }) == 'Y') { Environment.Exit(1); } Cls(nusbio, true); // Re format - re init key var keyInfo = ConsoleEx.Question(4, string.Format("Would you like to format {0} Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }); if (keyInfo == 'N') { return; } FormatAndInitDisk(); } Cls(nusbio); while (nusbio.Loop()) { Console.Write(string.Format(@"{0}:\>", _sfsManager.VolumeName)); var cmd = Console.ReadLine(); var cmdLC = cmd.ToLowerInvariant(); var tokens = cmdLC.Split(' '); if (tokens.Length > 0) { if (tokens[0] == "exit") { nusbio.ExitLoop(); } if (tokens[0] == "format") { FormatAndInitDisk(); } if (tokens[0] == "cls") { Console.Clear(); } if (tokens[0] == "help") { Console.WriteLine(COMMAND_HELP); } if (tokens[0] == "del") { if (_sfsManager.Delete(cmd.Substring(4))) { if (_sfsManager.UpdateFileSystem()) { Console.WriteLine(SFS_COMMAND_MESSAGE_FILE_DELETED); } else { Console.WriteLine(SFS_COMMAND_ERR_SAVING_FAT); } } else { Console.WriteLine(SFS_COMMAND_ERR_CANNOT_FIND_FILE); } } if (tokens[0] == "compact") { if (_sfsManager.Compact()) { Console.WriteLine(SFS_COMMAND_MESSAGE_COMPACTAGE_DONE); } else { Console.WriteLine(SFS_COMMAND_ERR_COMPACTAGE_FAILED); } } if (tokens[0] == "type") { Console.WriteLine(_sFsREPLCommand.TypeCommand(cmd.Substring(5))); } if (tokens[0] == "open") { Console.WriteLine(_sFsREPLCommand.OpenCommand(cmd.Substring(5))); } if (tokens[0] == "dir") { Console.WriteLine(_sFsREPLCommand.DirCommand()); } if (tokens[0] == "dirall") { Console.WriteLine(_sFsREPLCommand.DirCommand(true)); } if (tokens[0] == "copy") { Console.WriteLine(_sFsREPLCommand.CopyFileCommand(cmd.Substring(5))); } } } } Console.Clear(); }
public static void Run(string[] args) { var pw = string.Empty; Console.WriteLine("Nusbio initialization"); Nusbio.ActivateFastMode(); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { pw = AskForPW(nusbio, VolumeName); _sfsManager = new sFs.sFsManager(VolumeName, pw, nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3); _sfsManager.Begin(); Cls(nusbio, true); Console.WriteLine(Environment.NewLine + Environment.NewLine); Console.WriteLine("Initializing private public key module"); var ppk = new PrivatePublicKeyHelper(true); //GeneratePrivateKeyPublicKey(pw); var ok = ReloadFileSystem(pw, ppk); if (!ok) { Cls(nusbio, true); if (ConsoleEx.Question(3, string.Format("Cannot access {0} with this password, retry Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }) == 'Y') { Environment.Exit(1); } Cls(nusbio, true); // Re format - re init key var keyInfo = ConsoleEx.Question(4, string.Format("Would you like to initialize {0} Y)es N)o", _sfsManager.VolumeName), new List <char> { 'Y', 'N' }); if (keyInfo == 'N') { return; } GeneratePrivateKeyPublicKey(pw); } Cls(nusbio); while (nusbio.Loop()) { if (Console.KeyAvailable) { var kk = Console.ReadKey(true); var k = kk.Key; if (kk.Modifiers == ConsoleModifiers.Control) { if (DigitKeys.Contains(k)) { var a = (int)k - 48; if (a == 0) { a = 10; } a--; ShowFile(a); } } else { if (k == ConsoleKey.A) { AddNewTextFile(pw); } if (k == ConsoleKey.B) { AddNewTextFile(pw, @"C:\Users\fredericaltorres\Dropbox\FTO\MonteChristro.jpg"); } if (k == ConsoleKey.D1) { EncrypteFile(ppk, ppk.PublicKey, "PublicKey"); } if (k == ConsoleKey.D2) { EncrypteFile(ppk, ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D3) { DecrypteFile(ppk, ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D4) { ExportKey(ppk.PublicKey, "PublicKey"); } if (k == ConsoleKey.D5) { ExportKey(ppk.PrivateKey, "PrivateKey"); } if (k == ConsoleKey.D6) { GeneratePrivateKeyPublicKey(pw); } if (k == ConsoleKey.U) { UnitTests(ppk, _sfsManager); } if (k == ConsoleKey.Q) { break; } } Cls(nusbio); } } } Console.Clear(); }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); Nusbio.ActivateFastMode(); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { //_eeprom = new EEPROM_25AA1024( // nusbio: nusbio, // clockPin: NusbioGpio.Gpio4, // mosiPin: NusbioGpio.Gpio5, // misoPin: NusbioGpio.Gpio2, // selectPin: NusbioGpio.Gpio6 // ); _eeprom = new EEPROM_25AA1024( nusbio: nusbio, clockPin: NusbioGpio.Gpio0, mosiPin: NusbioGpio.Gpio1, misoPin: NusbioGpio.Gpio2, selectPin: NusbioGpio.Gpio3 ); _eeprom.Begin(); // Noticed that we cannot detect if the EEPROM is connected or // not based on SPI command. The SPI command does not fail. // But return a buffer with garbage mostly all byte set to 255 // So based on the expected data of the first page we could // detect of the EEPROM is connected or not var r = _eeprom.ReadPage(0, _eeprom.PAGE_SIZE * 4); if (r.Succeeded) { if (r.Buffer[0] == 255) { Console.WriteLine("SPI EEPROM 25AA1024 not detected, hit enter to continue"); Console.ReadLine(); } } Cls(nusbio); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.W) { var a = ConsoleEx.Question(23, string.Format("Execute Write/Read/Write Test {0}k now Y)es, N)o", _eeprom.MaxKByte), new List <char>() { 'Y', 'N' }); if (a == 'Y') { Console.Clear(); ConsoleEx.TitleBar(0, "Writing EEPROM"); var testValue = 1 + 4 + 16 + 64; _eeprom.WriteAll(0, EEPROM_25AA1024.MakeBuffer((byte)testValue, _eeprom.MaxByte), (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 2, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow)); Console.Clear(); ConsoleEx.TitleBar(0, "Reading EEPROM"); var dataRead = _eeprom.ReadAll(16, (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 2, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow)); for (var z = 0; z < _eeprom.MaxByte; z++) { if (dataRead[z] != testValue) { throw new ArgumentException("Writing/Reading error"); } } WriteEEPROMPage(512); ReadAndVerifyEEPROMPage_BatchRead(512); } } if (k == ConsoleKey.R) { ReadAndVerifyEEPROMPage(10); Cls(nusbio); } if (k == ConsoleKey.A) { ReadAndVerifyEEPROMPage_BatchRead(512); ReadAndVerifyEEPROMPage(512); } if (k == ConsoleKey.B) { // This mode is slow, only read the first 64 pages out of 512 ReadAndVerifyEEPROMOnyByteAtTheTime(64); } if (k == ConsoleKey.Q) { break; } Cls(nusbio); } } } Console.Clear(); }