コード例 #1
0
    /// <summary>
    /// Read a page packet 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 dumpBankPagePacket(PagedMemoryBank bank, int pg)
    {
        byte[] read_buf  = new byte [bank.PageLength];
        byte[] extra_buf = new byte [bank.ExtraInfoLength];
        int    read_rslt;

        try
        {
            // read a page packet (use the most verbose method)
            if (bank.hasExtraInfo())
            {
                read_rslt = bank.readPagePacket(pg, false, read_buf, 0, extra_buf);
            }
            else
            {
                read_rslt = bank.readPagePacket(pg, false, read_buf, 0);
            }

            Debug.Write("Packet " + pg + ", len " + read_rslt + ": ");
            hexPrint(read_buf, 0, read_rslt);
            Debug.WriteLine("");

            if (bank.hasExtraInfo())
            {
                Debug.Write("Extra: ");
                hexPrint(extra_buf, 0, bank.ExtraInfoLength);
                Debug.WriteLine("");
            }
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }
    }
コード例 #2
0
 /// <summary>
 /// Write a UDP packet to the specified page in the
 /// provided PagedMemoryBank.
 /// </summary>
 /// <param name="bank">  PagedMemoryBank to write packet to </param>
 /// <param name="data">  data to write in a byte array </param>
 /// <param name="pg">    page number to write packet to </param>
 public static void bankWritePacket(PagedMemoryBank bank, byte[] data, int pg)
 {
     try
     {
         bank.writePagePacket(pg, data, 0, data.Length);
         Debug.WriteLine("");
         Debug.WriteLine("wrote packet length " + data.Length + " on page " + pg);
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
     }
 }
コード例 #3
0
ファイル: MemoryBankEPROM.cs プロジェクト: henrikmbach/ownet
		//--------
		//-------- Constructor
		//--------
		
		/// <summary> Memory bank contstuctor.  Requires reference to the OneWireContainer
		/// this memory bank resides on.  Requires reference to memory banks used
		/// in OTP operations.
		/// </summary>
		public MemoryBankEPROM(OneWireContainer ibutton)
		{
			
			// keep reference to ibutton where memory bank is
			ib = ibutton;
			
			// get references to MemoryBanks used in OTP operations, assume no locking/redirection
			mbLock = null;
			mbRedirect = null;
			mbLockRedirect = null;
			lockOffset = 0;
			redirectOffset = 0;
			lockRedirectOffset = 0;
			
			// initialize attributes of this memory bank - DEFAULT: Main memory DS1985 w/o lock stuff
			generalPurposeMemory = true;
			bankDescription = "Main Memory";
			numberPages = 64;
			size = 2048;
			pageLength = 32;
			maxPacketDataLength = 29;
			readWrite = false;
			writeOnce = true;
			readOnly = false;
			nonVolatile = true;
			pageAutoCRC = true;
			redirectPage_Renamed_Field = false;
			lockPage_Renamed_Field = false;
			lockRedirectPage_Renamed_Field = false;
			programPulse = true;
			powerDelivery = false;
			extraInfo = true;
			extraInfoLength = 1;
			extraInfoDescription = "Inverted redirection page";
			writeVerification = true;
			startPhysicalAddress = 0;
			READ_PAGE_WITH_CRC = MAIN_READ_PAGE_COMMAND;
			WRITE_MEMORY_COMMAND = MAIN_WRITE_COMMAND;
			numCRCBytes = 2;
			crcAfterAddress = true;
			normalReadCRC = false;
			doSetSpeed = true;
			
			// create the ffblock (used for faster 0xFF fills)
			ffBlock = new byte[50];
			
			for (int i = 0; i < 50; i++)
				ffBlock[i] = (byte) SupportClass.Identity(0xFF);
		}
コード例 #4
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("|------------------------------------------------------------------------");
    }
コード例 #5
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);
        }
    }
コード例 #6
0
        private void ReadMemoryBank(MemoryBank mb, out byte[] readBuf)
        {
            int size = mb.Size;

            readBuf = new byte[size];

            byte[][] extraInfo = null;
            try
            {
                Debug.WriteLine("Reading memory...");

                if (mb is PagedMemoryBank)
                {
                    PagedMemoryBank pmb       = (PagedMemoryBank)mb;
                    int             len       = pmb.PageLength;
                    int             numPgs    = (size / len) + (size % len > 0 ? 1 : 0);
                    bool            hasExtra  = pmb.hasExtraInfo();
                    int             extraSize = pmb.ExtraInfoLength;
                    if (hasExtra)
                    {
                        extraInfo[numPgs] = new byte[numPgs];
                        for (var i = 0; i < numPgs; i++)
                        {
                            extraInfo[0] = new byte[extraSize];
                        }
                    }
                    int retryCnt = 0;
                    for (int i = 0; i < numPgs;)
                    {
                        try
                        {
                            bool readContinue = (i > 0) && (retryCnt == 0);
                            if (hasExtra)
                            {
                                pmb.readPage(i, readContinue, readBuf, i * len, extraInfo[i]);
                                Debug.WriteLine("Read Extra Info!");
                            }
                            else
                            {
                                pmb.readPage(i, readContinue, readBuf, i * len);
                            }
                            i++;
                            retryCnt = 0;
                        }
                        catch (Exception e)
                        {
                            if (++retryCnt > 15)
                            {
                                throw e;
                            }
                        }
                    }
                }
                else
                {
                    int retryCnt = 0;
                    while (true)
                    {
                        try
                        {
                            mb.read(0, false, readBuf, 0, size);
                            break;
                        }
                        catch (Exception e)
                        {
                            if (++retryCnt > 15)
                            {
                                throw e;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                Debug.Write(e.StackTrace);
                return;
            }

            Debug.WriteLine("Done Reading memory...");
        }
コード例 #7
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");
        }
    }
コード例 #8
0
    /// <summary>
    /// Dump valid memory packets from general-purpose memory.
    /// in the provided  MemoryContainer 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 dumpDevicePackets(OneWireContainer owd, bool showContents)
    {
        byte[]    read_buf, extra_buf;
        int       read_rslt;
        bool      found_bank = false;
        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 desired type, only look for packets in general non-volatile
            if (!mb.GeneralPurposeMemory || !mb.NonVolatile)
            {
                continue;
            }

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

            // found a memory bank
            found_bank = true;

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

            // display bank information
            displayBankInformation(bank);

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

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

            // loop to read all of the pages in bank
            bool readContinue = false;

            for (int pg = 0; pg < bank.NumberPages; pg++)
            {
                try
                {
                    // read a page packet (use the most verbose and secure method)
                    if (bank.hasExtraInfo())
                    {
                        read_rslt = bank.readPagePacket(pg, readContinue, read_buf, 0, extra_buf);
                    }
                    else
                    {
                        read_rslt = bank.readPagePacket(pg, readContinue, read_buf, 0);
                    }

                    if (read_rslt >= 0)
                    {
                        readContinue = true;

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

                            if (bank.hasExtraInfo())
                            {
                                Debug.Write("Extra: ");
                                hexPrint(extra_buf, 0, bank.ExtraInfoLength);
                                Debug.WriteLine("");
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("Error reading page : " + pg);

                        readContinue = false;
                    }
                }
                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 PACKETS = " + stopWatch.ElapsedMilliseconds + "ms)");
        }

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