コード例 #1
0
    /// <summary>
    /// Read a page from a memory bank and print in hex
    /// </summary>
    /// <param name="bank">  PagedMemoryBank to read a page from </param>
    /// <param name="pg">  page to read </param>
    public static void dumpBankPage(OneWireContainer33 owd, PagedMemoryBank bank, int pg)
    {
        byte[] read_buf  = new byte [bank.PageLength];
        byte[] extra_buf = new byte [bank.ExtraInfoLength];
        byte[] challenge = new byte [8];
        byte[] secret    = new byte [8];
        byte[] sernum    = new byte [8];
        bool   macvalid  = false;

        try
        {
            // read a page (use the most verbose and secure method)
            if (bank.hasPageAutoCRC())
            {
                Debug.WriteLine("Using device generated CRC");

                if (bank.hasExtraInfo())
                {
                    bank.readPageCRC(pg, false, read_buf, 0, extra_buf);

                    owd.getChallenge(challenge, 0);
                    owd.getContainerSecret(secret, 0);
                    sernum   = owd.Address;
                    macvalid = OneWireContainer33.isMACValid(bank.StartPhysicalAddress + pg * bank.PageLength, sernum, read_buf, extra_buf, challenge, secret);
                }
                else
                {
                    bank.readPageCRC(pg, false, read_buf, 0);
                }
            }
            else
            {
                if (bank.hasExtraInfo())
                {
                    bank.readPage(pg, false, read_buf, 0, extra_buf);
                }
                else
                {
                    bank.readPage(pg, false, read_buf, 0);
                }
            }

            Debug.Write("Page " + pg + ": ");
            hexPrint(read_buf, 0, read_buf.Length);
            Debug.WriteLine("");

            if (bank.hasExtraInfo())
            {
                Debug.Write("Extra: ");
                hexPrint(extra_buf, 0, bank.ExtraInfoLength);
                Debug.WriteLine("");

                if (macvalid)
                {
                    Debug.WriteLine("Data validated with correct MAC.");
                }
                else
                {
                    Debug.WriteLine("Data not validated because incorrect MAC.");
                }
            }
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }
    }
コード例 #2
0
    /// <summary>
    /// Display the information about the current memory back provided.
    /// </summary>
    /// <param name="bank"> Memory Bank object. </param>
    public static void displayBankInformation(MemoryBank bank)
    {
        Debug.WriteLine("|------------------------------------------------------------------------");
        Debug.WriteLine("| Bank: (" + bank.BankDescription + ")");
        Debug.Write("| Implements : MemoryBank");

        if (bank is PagedMemoryBank)
        {
            Debug.Write(", PagedMemoryBank");
        }

        Debug.WriteLine("");
        Debug.WriteLine("| Size " + bank.Size + " starting at physical address " + bank.StartPhysicalAddress);
        Debug.Write("| Features:");

        if (bank.ReadWrite)
        {
            Debug.Write(" Read/Write");
        }

        if (bank.WriteOnce)
        {
            Debug.Write(" Write-once");
        }

        if (bank.ReadOnly)
        {
            Debug.Write(" Read-only");
        }

        if (bank.GeneralPurposeMemory)
        {
            Debug.Write(" general-purpose");
        }
        else
        {
            Debug.Write(" not-general-purpose");
        }

        if (bank.NonVolatile)
        {
            Debug.Write(" non-volatile");
        }
        else
        {
            Debug.Write(" volatile");
        }

        if (bank.needsProgramPulse())
        {
            Debug.Write(" needs-program-pulse");
        }

        if (bank.needsPowerDelivery())
        {
            Debug.Write(" needs-power-delivery");
        }

        // check if has paged services
        if (bank is PagedMemoryBank)
        {
            // caste to page bank
            PagedMemoryBank pbank = (PagedMemoryBank)bank;

            // page info
            Debug.WriteLine("");
            Debug.Write("| Pages: " + pbank.NumberPages + " pages of length ");
            Debug.Write(pbank.PageLength + " bytes ");

            if (bank.GeneralPurposeMemory)
            {
                Debug.Write("giving " + pbank.MaxPacketDataLength + " bytes Packet data payload");
            }

            if (pbank.hasPageAutoCRC())
            {
                Debug.WriteLine("");
                Debug.Write("| Page Features: page-device-CRC");
            }

            if (pbank.hasExtraInfo())
            {
                Debug.WriteLine("");
                Debug.WriteLine("| Extra information for each page:  " + pbank.ExtraInfoDescription + ", length " + pbank.ExtraInfoLength);
            }
            else
            {
                Debug.WriteLine("");
            }
        }
        else
        {
            Debug.WriteLine("");
        }

        Debug.WriteLine("|------------------------------------------------------------------------");
    }
コード例 #3
0
    /// <summary>
    /// Dump pages from memory.
    /// in the provided owd instance.
    ///
    /// @parameter owd device to check for memory banks.
    /// @parameter showContents flag to indicate if the packet memory bank contents will
    ///                      be displayed
    /// </summary>
    public static void dumpDevicePages(OneWireContainer owd, bool showContents)
    {
        byte[]    read_buf, extra_buf;
        int       reps, i, pg, numberPages;
        bool      found_bank = false, hasExtraInfo, hasPageAutoCRC, readContinue;
        Stopwatch stopWatch = new Stopwatch();

        // get the port names we can use and try to open, test and close each
        for (System.Collections.IEnumerator bank_enum = owd.MemoryBanks; bank_enum.MoveNext();)
        {
            // get the next memory bank
            MemoryBank mb = (MemoryBank)bank_enum.Current;

            // check if has paged services
            if (!(mb is PagedMemoryBank))
            {
                continue;
            }

            // cast to page bank
            PagedMemoryBank bank = (PagedMemoryBank)mb;

            // found a memory bank
            found_bank = true;

            // display bank information
            displayBankInformation(bank);

            read_buf  = new byte [bank.PageLength];
            extra_buf = new byte [bank.ExtraInfoLength];

            // get bank flags
            hasPageAutoCRC = bank.hasPageAutoCRC();
            hasExtraInfo   = bank.hasExtraInfo();
            numberPages    = bank.NumberPages;

            // get overdrive going so not a factor in time tests
            try
            {
                bank.read(0, false, read_buf, 0, 1);
            }
            catch (Exception)
            {
            }

            // dynamically change number of reps
            reps = 1000 / (read_buf.Length * bank.NumberPages);

            if (owd.MaxSpeed == DSPortAdapter.SPEED_OVERDRIVE)
            {
                reps *= 2;
            }

            if ((reps == 0) || showContents)
            {
                reps = 1;
            }

            if (!showContents)
            {
                Debug.Write("[" + reps + "]");
            }

            // start timer to time the dump of the bank contents
            stopWatch.Start();

            for (i = 0; i < reps; i++)
            {
                // loop to read all of the pages in bank
                readContinue = false;

                for (pg = 0; pg < numberPages; pg++)
                {
                    try
                    {
                        // read a page (use the most verbose and secure method)
                        if (hasPageAutoCRC)
                        {
                            if (hasExtraInfo)
                            {
                                bank.readPageCRC(pg, readContinue, read_buf, 0, extra_buf);
                            }
                            else
                            {
                                bank.readPageCRC(pg, readContinue, read_buf, 0);
                            }
                        }
                        else
                        {
                            if (hasExtraInfo)
                            {
                                bank.readPage(pg, readContinue, read_buf, 0, extra_buf);
                            }
                            else
                            {
                                bank.readPage(pg, readContinue, read_buf, 0);
                            }
                        }

                        readContinue = true;

                        if (showContents)
                        {
                            Debug.Write("Page " + pg + ": ");
                            hexPrint(read_buf, 0, read_buf.Length);
                            Debug.WriteLine("");

                            if (bank.hasExtraInfo())
                            {
                                Debug.Write("Extra: ");
                                hexPrint(extra_buf, 0, bank.ExtraInfoLength);
                                Debug.WriteLine("");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Exception in reading page: " + e + "TRACE: ");
                        Debug.WriteLine(e.ToString());
                        Debug.Write(e.StackTrace);

                        readContinue = false;
                    }
                }
            }

            stopWatch.Stop();

            Debug.WriteLine("     (time to read PAGES = " + (stopWatch.ElapsedMilliseconds / reps).ToString() + "ms)");
        }

        if (!found_bank)
        {
            Debug.WriteLine("XXXX Does not contain any general-purpose non-volatile page memory bank's");
        }
    }