Exemple #1
0
        static void ShowFile(int fileIndex)
        {
            var fi = _sfsManager.FileInfos[fileIndex];

            Console.Clear();
            ConsoleEx.TitleBar(0, "Loading:" + fi.FileName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            fi = _sfsManager.LoadFileContent(fi);

            Console.Clear();
            ConsoleEx.TitleBar(0, "Viewing:" + fi.FileName, ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            ConsoleEx.Gotoxy(0, 1);

            if (fi.IsImage)
            {
                int exitCode = -1;
                var rr       = ExecuteProgram.ExecProgram("mspaint.exe", string.Format(@"""{0}""", fi.GetAsLocalTempFile()), true, ref exitCode, true, false);
                if (rr && exitCode == 0)
                {
                }
                else
                {
                    ConsoleEx.WriteLine(0, 3, "Cannot open the file", ConsoleColor.Red);
                    Pause();
                }
            }
            else
            {
                var text = fi.GetBufferAsUnicodeString();
                Console.WriteLine(text);
                Pause();
            }
            _sfsManager.Clean();
        }
Exemple #2
0
        private static bool DecrypteFile(PrivatePublicKeyHelper ppk, string key, string keyType)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Decrypte file with {0}", keyType), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            ConsoleEx.WriteLine(0, 2, "Filename:", ConsoleColor.Cyan);
            var fileName = Console.ReadLine();

            ConsoleEx.Gotoxy(0, 4);

            if (!File.Exists(fileName))
            {
                ConsoleEx.WriteLine(0, 3, "Cannot find the file", ConsoleColor.Red);
                Pause();
                return(false);
            }
            var sourceExtension = Path.GetExtension(fileName.Replace(ENCRYPTED_EXTENSION, ""));
            var dataFile        = File.ReadAllBytes(fileName);
            var dataEncrypted   = ppk.DecryptBuffer(dataFile, key);
            var tmpFile         = fileName + sourceExtension;

            File.WriteAllBytes(tmpFile, dataEncrypted);

            Console.WriteLine(string.Format("Encyrpted file is located at {0}", tmpFile), ConsoleColor.Cyan);
            Pause();
            return(true);
        }
Exemple #3
0
        static void ReadAndVerifyEEPROMPage(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k no batch standard SPI code", _eeprom.MaxKByte));
            ConsoleEx.Gotoxy(0, 2);

            var totalErrorCount = 0;
            var t = Stopwatch.StartNew();

            byte[] buf;

            for (var p = 0; p < numberOfPageToRead; p++)
            {
                if (p % 50 == 0 || p < 5)
                {
                    Console.WriteLine("Reading page {0}", p);
                }

                // The method ReadPage, use the default SPI method to transfer data
                var r = _eeprom.ReadPage(p * _eeprom.PAGE_SIZE, _eeprom.PAGE_SIZE);
                if (r.Succeeded)
                {
                    buf = r.Buffer;
                    for (var i = 0; i < _eeprom.PAGE_SIZE; i++)
                    {
                        var expected = i;
                        if (p == 2)
                        {
                            expected = NEW_WRITTEN_VALUE_1;
                        }
                        if (p == 3)
                        {
                            expected = NEW_WRITTEN_VALUE_2;
                        }

                        if (expectedSingleValue != -1)
                        {
                            expected = expectedSingleValue;
                        }

                        if (buf[i] != expected)
                        {
                            Console.WriteLine("Failed Page:{0} [{1}] = {2}, expected {3}", p, i, buf[i], expected);
                            totalErrorCount++;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("ReadBuffer failure");
                }
            }
            t.Stop();
            Console.WriteLine("{0} error(s), Data:{1}kb, Time:{2}, {3:0.00} kb/s",
                              totalErrorCount,
                              _eeprom.PAGE_SIZE * numberOfPageToRead, t.ElapsedMilliseconds, _eeprom.MaxByte * 1.0 / t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }
Exemple #4
0
        static bool GeneratePrivateKeyPublicKey(string pw)
        {
            var ok = false;

            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate new private/public key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            Console.Clear();
            ConsoleEx.TitleBar(0, "Generate Private/Public Key", ConsoleColor.Yellow, ConsoleColor.DarkBlue);
            var keyInfo = ConsoleEx.Question(3, "Re generate the private key and publick key Y)es N)o", new List <char> {
                'Y', 'N'
            });

            if (keyInfo == 'N')
            {
                return(ok);
            }

            keyInfo = ConsoleEx.Question(3, "Are you sure you want to generate Private/Public Key Y)es N)o", new List <char> {
                'Y', 'N'
            });
            if (keyInfo == 'N')
            {
                return(ok);
            }

            ConsoleEx.Gotoxy(0, 4);

            var ppk = new PrivatePublicKeyHelper(true);

            var privatek = _sfsManager.AddFile("PrivateKey");

            privatek.SetContentAsString(ppk.PrivateKey);
            var publicK = _sfsManager.AddFile("PublicKey");

            publicK.SetContentAsString(ppk.PublicKey);
            var readmeTxt = _sfsManager.AddFile("ReadMe.txt");

            readmeTxt.SetContentAsString(LoremIpsum);

            var rr = _sfsManager.WriteAsFileSystem();

            if (rr)
            {
                Console.WriteLine(string.Format("Keys were generated"), ConsoleColor.Cyan);
                ok = ReloadFileSystem(pw, ppk);
            }
            else
            {
                Console.WriteLine(string.Format("Error generating the keys"), ConsoleColor.Red);
            }

            Pause();
            return(ok);
        }
Exemple #5
0
        private static string AskForPW(Nusbio nusbio, string volumeName)
        {
            Cls(nusbio, true);
            ConsoleEx.Gotoxy(0, 1);
            Console.Write(string.Format("{0} - Password>", volumeName));
            var c = Console.ForegroundColor;

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Black;
            var pw = Console.ReadLine();

            Console.ForegroundColor = c;
            return(pw);
        }
Exemple #6
0
        private static SecureString AskForPW(Nusbio nusbio, string volumeName)
        {
            Cls(nusbio, true);
            ConsoleEx.Gotoxy(0, 1);
            Console.Write(string.Format("{0} - Password>", volumeName));
            var c = Console.ForegroundColor;

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Black;
            SecureString ss = PublicEncryptor.ConvertToSecureString(Console.ReadLine());

            Console.ForegroundColor = c;
            return(ss);
        }
Exemple #7
0
        static void ReadAndVerifyEEPROMPage_BatchRead(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k in 4 pages batch mode", _eeprom.MaxKByte));
            ConsoleEx.Gotoxy(0, 2);

            var t = Stopwatch.StartNew();

            EEPROM_25AA256_UnitTests.PerformanceTest_ReadPage(_eeprom);
            t.Stop();

            Console.WriteLine("Data:{0}kb, Time:{1}ms, {2:0.00} kb/s", _eeprom.MaxKByte, t.ElapsedMilliseconds, _eeprom.MaxByte * 1.0 / t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }
Exemple #8
0
        public static void RainbowDemo2(APA102LEDStrip ledStrip, int jStep)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rainbow Demo");
            ConsoleEx.WriteMenu(-1, 2, "Q)uit");
            ConsoleEx.WriteMenu(-1, 3, "");

            int brigthness = 6;
            int wait       = GetWaitTimeUnit(ledStrip) / 2;
            var quit       = false;

            ledStrip.AllOff();

            while (!quit)
            {
                for (var j = 0; j < 256; j += jStep)
                {
                    ConsoleEx.Gotoxy(0, 4);
                    ledStrip.Reset();

                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        ledStrip.AddRGBSequence(false, brigthness, RGBHelper.Wheel((i * 256 / ledStrip.MaxLed) + j));
                    }
                    for (var i = 0; i < ledStrip.MaxLed; i++)
                    {
                        var wheelIndex = (i * 256 / ledStrip.MaxLed) + j;
                        var bkColor    = ledStrip.LedColors[i];
                        Console.WriteLine(String.Format("Color:{0}, Wheel:{1}, rgb:{2}",
                                                        bkColor.Name, wheelIndex.ToString("000"), APA102LEDStrip.ToDecValue(bkColor)));
                    }
                    ledStrip.Show().Wait(wait);
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            quit = true;
                            break;
                        }
                    }
                }
            }
            ledStrip.AllOff();
        }
Exemple #9
0
        static void ReadAndVerifyEEPROMPage_BatchRead(int numberOfPageToRead, int expectedSingleValue = -1)
        {
            Console.Clear();

            var batchPageSize = 128; // Transfer batch of 32page x 256byte = 8k

            ConsoleEx.TitleBar(0, string.Format("Performance test reading all {0}k in {1} pages batch mode", _eeprom.MaxKByte, batchPageSize));
            ConsoleEx.Gotoxy(0, 2);

            var t = Stopwatch.StartNew();

            EEPROM_25AA1024_UnitTests.PerformanceTest_ReadPage(_eeprom, batchPageSize,
                                                               (pageIndex, maxPage) => ConsoleEx.WriteLine(0, 3, string.Format("{0:000} % done", 1.0 * pageIndex / maxPage * 100.0), ConsoleColor.Yellow));
            t.Stop();

            Console.WriteLine("Data:{0}kb, Time:{1}ms, {2:0.00} kb/s", _eeprom.MaxKByte, t.ElapsedMilliseconds, _eeprom.MaxByte * 1.0 / t.ElapsedMilliseconds);
            Console.WriteLine("Hit enter key");
            Console.ReadLine();
        }
Exemple #10
0
        public static void ColorsSequence(APA102LEDStrip ledStripe0, APA102LEDStrip ledStripe1)
        {
            var wait = 300;
            var quit = false;

            ledStripe0.Brightness = 7;
            ledStripe0.AllOff();

            Console.Clear();
            ConsoleEx.TitleBar(0, "Color Sequence Demo", ConsoleColor.White, ConsoleColor.DarkBlue);
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            var bkColors = TargetColors.Replace(Environment.NewLine, ",").Split(',').ToList();

            while (!quit)
            {
                foreach (var sBColor in bkColors)
                {
                    if (string.IsNullOrEmpty(sBColor.Trim()))
                    {
                        continue;
                    }

                    var bkColor = APA102LEDStrip.DrawingColors[sBColor];
                    ConsoleEx.Gotoxy(1, 2);
                    ConsoleEx.WriteLine(string.Format("Background Color:{0}, Html:{1}, Dec:{2}", bkColor.Name.PadRight(16), APA102LEDStrip.ToHexValue(bkColor), APA102LEDStrip.ToDecValue(bkColor)), ConsoleColor.DarkCyan);

                    ledStripe0.Reset().AddRGBSequence(true, ledStripe0.Brightness, ledStripe0.MaxLed, bkColor).Show();
                    ledStripe1.Reset().AddRGBSequence(true, ledStripe1.Brightness, ledStripe0.MaxLed, bkColor).Show().Wait(wait);

                    if (Console.KeyAvailable)
                    {
                        quit = true;
                        break;
                    }
                }
            }
            ledStripe0.AllOff();
            var k = Console.ReadKey(true).Key;
        }
Exemple #11
0
        static void Cls(Nusbio nusbio, bool justTitle = false)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);

            if (!justTitle)
            {
                ConsoleEx.WriteMenu(1, 1, "1-Encrypte with public key");
                ConsoleEx.WriteMenu(1, 2, "2-Encrypte with private key");
                ConsoleEx.WriteMenu(1, 3, "3-Decrypte with private key");
                ConsoleEx.WriteMenu(1, 4, "4-Export public Key");
                ConsoleEx.WriteMenu(1, 5, "5-Export private Key");
                ConsoleEx.WriteMenu(1, 6, "6-Generate Private/Publick key");
                ConsoleEx.WriteMenu(1, 7, "Q)uit");
                ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue);
                ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan);
            }
            if (_sfsManager != null && _sfsManager.FileInfos != null)
            {
                ConsoleEx.Gotoxy(0, 9);
                Console.WriteLine(@"Nusbio:\>Dir" + Environment.NewLine);
                Console.WriteLine(_sfsManager.Dir());
            }
        }
Exemple #12
0
 static void Cls(Nusbio nusbio, bool justTitle = false)
 {
     Console.Clear();
     ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue);
     ConsoleEx.Gotoxy(0, 1);
 }