Exemple #1
0
        static void displayStatus(Programmer programmer)
        {
            Console.Write(
                "Serial number:                  " + programmer.getSerialNumber() + "\n" +
                "Firmware version:               " + programmer.firmwareVersionString + "\n"
            );

            ProgrammerSettings settings = programmer.getSettings();

            Console.Write(
                "Settings:\n" +
                "  ISP Frequency:                " + Programmer.sckDurationToString(settings.sckDuration) + "\n" +
                // TODO: test displayStatus thoroughly, line by line, making sure that every line displays the correct thing for each possible value
                "  Line A Identity:              " + Programmer.lineIdentityToString(settings.lineAIdentity) + "\n" +
                "  Line B Identity:              " + Programmer.lineIdentityToString(settings.lineBIdentity) + "\n" +
                "  AVR ISP hardware version:     " + settings.hardwareVersion.ToString("X") + "\n" +
                "  AVR ISP software version:     " + settings.softwareVersionMajor.ToString("X") + "." + settings.softwareVersionMinor.ToString("X") + "\n" +
                "  Target VDD allowed minimum:   " + settings.targetVccAllowedMinimum + " mV\n" +
                "  Target VDD allowed max range: " + settings.targetVccAllowedMaximumRange + " mV\n"
                );
            Console.Write(
                "Last programming:\n" +
                "  Error: "
            );

            switch (programmer.getProgrammingError())
            {
                case ProgrammingError.None:
                    Console.Write("None\n");
                    break;
                case ProgrammingError.TargetVccBad:
                    Console.Write(
                        "Target VDD bad\n"+
                        "    Target VDD either went too low or had too much range, so programming was\n" +
                        "    aborted.  Make sure that the target is powered on and its batteries are not\n" +
                        "    too low (if applicable).\n");
                    break;
                case ProgrammingError.Synch:
                    Console.Write(
                        "Synch failed\n"+
                        "    The SPI command for entering programming mode was sent, but the expected\n" +
                        "    response from the target was not received.  Make sure that the ISP\n" +
                        "    frequency setting is less than 1/6th of the target's clock frequency.\n");
                    break;
                case ProgrammingError.IdleForTooLong:
                    Console.Write("Idle for too long\n" +
                        "    The programmer received no programming commands from the computer for more\n" +
                        "    than 0.3 seconds, so it left programming mode.  Make sure that the\n" +
                        "    programming software does not wait too long between successive programming\n" +
                        "    commands.\n");
                    break;
                case ProgrammingError.UsbNotConfigured:
                    Console.Write("USB not configured\n" +
                        "    The computer's USB controller deconfigured the progammer, so programming was\n" +
                        "    aborted.\n");
                    break;
                case ProgrammingError.UsbSuspend:
                    Console.Write("USB suspend\n" +
                        "    The computer's USB controller put the programmer in suspend mode, so\n" +
                        "    programming was aborted.\n");
                    break;
            }

            ushort min = programmer.getTargetVccMeasuredMinimum();
            ushort max = programmer.getTargetVccMeasuredMaximum();

            string minString;
            string rangeString;
            if (min <= max)
            {
                minString = min.ToString() + " mV";
                if (min < settings.targetVccAllowedMinimum)
                {
                    minString += " !";
                }

                rangeString = (max - min).ToString() + " mV";

                // We do the exact same comparison here that is done in the firmware.
                if ((byte)(max/32) > (byte)((min/32) + (settings.targetVccAllowedMaximumRange/32)))
                {
                    rangeString += " !";
                }
            }
            else
            {
                // Programmer hasn't programmed since it was las powered on.
                minString = rangeString = "N/A";
            }

            Console.Write(
                "  Measured Target VDD Minimum:  " + minString + "\n" +
                "  Measured Target VDD Range:    " + rangeString + "\n"
            );

            SloscopeOutputState outputA;
            SloscopeOutputState outputB;
            programmer.getSloscopeOutputState(out outputA, out outputB);

            Console.Write(
                "SLO-scope:\n" +
                "  State:                        " + programmer.getSloscopeState() + "\n" +
                "  Line A output:                " + outputA + "\n" +
                "  Line B output:                " + outputB + "\n"
            );
        }