예제 #1
0
        public void I2CRetryTest()
        {
            Console.WriteLine("Starting I2C retry test...");

            Stopwatch timer = new Stopwatch();

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0x0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.StartMask = 0;

            Console.WriteLine("Setting retry count to 0");
            FX3.I2CRetryCount = 0;
            Assert.AreEqual(0, FX3.I2CRetryCount, "ERROR: Setting not applied correctly");

            Console.WriteLine("Attempting to read non-existent device... (address 0)");
            timer.Start();
            try
            {
                FX3.I2CReadBytes(pre, 128, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            timer.Stop();
            Console.WriteLine("Elapsed time: " + timer.ElapsedMilliseconds.ToString() + "ms");
            CheckFirmwareResponsiveness();
        }
예제 #2
0
        public void I2CReadTest()
        {
            Console.WriteLine("Starting I2C read test...");

            byte[] InitialRead, SecondRead;

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            for (uint readLen = 2; readLen < 256; readLen += 2)
            {
                Console.WriteLine("Testing " + readLen.ToString() + " byte read");
                InitialRead = FX3.I2CReadBytes(pre, readLen, 1000);
                SecondRead  = FX3.I2CReadBytes(pre, readLen, 1000);
                for (int i = 0; i < InitialRead.Count(); i++)
                {
                    Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
                }
            }
        }
예제 #3
0
        private void TestI2CFunctionality()
        {
            byte[] InitialRead, SecondRead;

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            InitialRead = FX3.I2CReadBytes(pre, 64, 1000);
            SecondRead  = FX3.I2CReadBytes(pre, 64, 1000);
            for (int i = 0; i < InitialRead.Count(); i++)
            {
                Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
            }
        }
예제 #4
0
        public void ErrorLogRobustnessTest()
        {
            Console.WriteLine("Starting error log robustness test...");

            List <FX3ErrorLog> initialLog, log;

            I2CPreamble preRead = new I2CPreamble();

            preRead.DeviceAddress = 0xA0;
            preRead.PreambleData.Add(0);
            preRead.PreambleData.Add(0);
            preRead.PreambleData.Add(0xA1);
            preRead.StartMask = 4;

            I2CPreamble preWrite = new I2CPreamble();

            preWrite.DeviceAddress = 0;
            preWrite.PreambleData.Add(0);
            preWrite.StartMask = 0;

            Console.WriteLine("Rebooting FX3...");
            FX3.Disconnect();
            System.Threading.Thread.Sleep(500);
            Connect();

            Console.WriteLine("Getting initial error log...");
            initialLog = FX3.GetErrorLog();
            foreach (FX3ErrorLog entry in initialLog)
            {
                Console.WriteLine(entry.ToString());
            }

            Console.WriteLine("Starting I2C Read...");
            try
            {
                FX3.I2CReadBytes(preRead, 32, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Starting invalid I2C write...");
            try
            {
                FX3.I2CWriteBytes(preWrite, new byte[] { 1, 2, 3, 4 }, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, true);

            initialLog.Clear();
            foreach (FX3ErrorLog entry in log)
            {
                initialLog.Add(entry);
            }

            Console.WriteLine("Starting I2C stream...");
            FX3.StartI2CStream(preRead, 64, 10);
            System.Threading.Thread.Sleep(2000);

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Rebooting FX3...");
            FX3.Disconnect();
            System.Threading.Thread.Sleep(500);
            Connect();

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            CheckLogEquality(initialLog, log, false);

            Console.WriteLine("Starting I2C Read...");
            try
            {
                FX3.I2CReadBytes(preRead, 32, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Generating new error log...");
            GenerateErrorLog();

            Console.WriteLine("Getting error log...");
            log = FX3.GetErrorLog();
            Assert.AreEqual(initialLog.Count + 1, log.Count, "ERROR: Invalid log count");
            CheckLogEquality(initialLog, log, true);
        }
예제 #5
0
        public void I2CBitRateTest()
        {
            Console.WriteLine("Starting I2C bit rate test...");

            Console.WriteLine("Testing input validation...");
            uint startingBitRate;
            int  numExpections = 0;

            startingBitRate = FX3.I2CBitRate;
            Assert.AreEqual(100000, startingBitRate, "ERROR: Invalid default I2C bit rate");
            try
            {
                FX3.I2CBitRate = 99999;
            }
            catch (Exception e)
            {
                numExpections++;
                Console.WriteLine(e.Message);
            }
            Assert.AreEqual(1, numExpections, "ERROR: Expected exception to be thrown");
            Assert.AreEqual(startingBitRate, FX3.I2CBitRate, "ERROR: Expected I2C bit rate setting to be rejected");

            try
            {
                FX3.I2CBitRate = 1000001;
            }
            catch (Exception e)
            {
                numExpections++;
                Console.WriteLine(e.Message);
            }
            Assert.AreEqual(2, numExpections, "ERROR: Expected exception to be thrown");
            Assert.AreEqual(startingBitRate, FX3.I2CBitRate, "ERROR: Expected I2C bit rate setting to be rejected");

            Console.WriteLine("Testing reads across valid bit rate range...");

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            byte[] InitialRead, SecondRead;

            Console.WriteLine("Performing initial flash read...");
            const uint READ_LEN = 1024;

            InitialRead = FX3.I2CReadBytes(pre, READ_LEN, 2000);
            for (uint bitrate = 100000; bitrate <= 1000000; bitrate += 100000)
            {
                Console.WriteLine("Testing " + bitrate.ToString() + "bits/s...");
                FX3.I2CBitRate = bitrate;
                Assert.AreEqual(bitrate, FX3.I2CBitRate, "ERROR: Setting bit rate failed");
                SecondRead = FX3.I2CReadBytes(pre, READ_LEN, 2000);
                for (int i = 0; i < InitialRead.Count(); i++)
                {
                    Assert.AreEqual(InitialRead[i], SecondRead[i], "ERROR: Expected flash read data to match");
                }
            }
        }