Exemple #1
0
    /// <summary>
    /// Display file details
    /// </summary>
    /// <param name="owfile"> 1-Wire file to show details of </param>
    internal static void showDetails(OWFile owfile)
    {
        int[]           page_list;
        int             local_pg;
        PagedMemoryBank pmb;

        // check if this directory/file exists
        if (!owfile.exists())
        {
            Debug.WriteLine("-----------------------------------------------");
            Debug.WriteLine("Directory/file not found!");
            Debug.WriteLine("-----------------------------------------------");
            return;
        }

        // get the list of pages that make up this directory/file
        Debug.WriteLine("Page allocation of " + (owfile.File ? "file:" : "directory:"));

        try
        {
            page_list = owfile.PageList;
        }
        catch (IOException e)
        {
            Debug.WriteLine(e);
            return;
        }

        // loop to display info and contents of each page
        for (int pg = 0; pg < page_list.Length; pg++)
        {
            local_pg = owfile.getLocalPage(page_list[pg]);
            Debug.WriteLine("Filesystem page=" + page_list[pg] + ", local PagedMemoryBank page=" + owfile.getLocalPage(page_list[pg]));
            pmb = owfile.getMemoryBankForPage(page_list[pg]);
            byte[] read_buf = new byte[pmb.PageLength];
            try
            {
                pmb.readPage(local_pg, false, read_buf, 0);
                hexPrint(read_buf, 0, read_buf.Length);
                Debug.WriteLine("");
            }
            catch (OneWireException e)
            {
                Debug.WriteLine(e);
            }
        }
    }
Exemple #2
0
        /// <summary>
        /// <P>Asserts that proper account info exists for this SHAiButtonUser
        /// and establishes a buffer for caching account data.</P>
        /// </summary>
        /// <param name="ibc"> the OneWireContainer whose account info is checked </param>
        /// <returns> whether or not the device is initialized properly </returns>
        protected internal virtual bool checkAccountPageInfo(OneWireContainer ibc)
        {
            lock (this)
            {
                //this flag should only be set if there is valid data
                if (accountPageNumber <= 0)
                {
                    try
                    {
                        //create a file object representing service file
                        OWFile owf = new OWFile(ibc, strServiceFilename);

                        //check to see if file exists
                        if (!owf.exists())
                        {
                            return(false);
                        }

                        //get the page number for the file
                        //this.accountPageNumber = owf.getPageList()[0];
                        this.accountPageNumber = owf.StartPage;

                        //close the file
                        owf.close();

                        //mark the cache as dirty
                        this.accountData[0] = 0;

                        //clear the write cycle counter
                        this.writeCycleCounter = -1;
                    }
                    catch (System.Exception e)
                    {
                        this.accountPageNumber = -1;
                        if (DEBUG)
                        {
                            OneWireEventSource.Log.Debug(e.ToString());
                            OneWireEventSource.Log.Debug(e.StackTrace);
                        }
                    }
                }

                return(this.accountPageNumber > 0);
            }
        }
Exemple #3
0
        /// <summary>
        /// <P>Create's empty service file for the user with the given filename.
        /// Also, it populates <code>accountPageNumber</code> with the page
        /// that the service file is stored on.</P>
        /// </summary>
        /// <param name="owc"> the 1-wire device where the service file will be created. </param>
        /// <param name="filename"> the filename of the service file. </param>
        /// <param name="formatDevice"> if <code>true</code>, the device is formatted
        ///        before creating the service file. </param>
        protected internal virtual bool createServiceFile(OneWireContainer owc, string filename, bool formatDevice)
        {
            bool   bRetVal = false;
            OWFile owf     = new OWFile(owc, strServiceFilename);

            try
            {
                if (formatDevice)
                {
                    owf.format();
                }

                if (!owf.exists())
                {
                    owf.createNewFile();
                }

                //save reference to page number for service file
                this.accountPageNumber = owf.PageList[0];

                bRetVal = true;
            }
            catch (IOException ioe)
            {
                bRetVal = false;

                OneWireEventSource.Log.Debug(ioe.ToString());
                OneWireEventSource.Log.Debug(ioe.StackTrace);
            }

            try
            {
                owf.close();
                return(bRetVal);
            }
            catch (IOException ioe)
            {
                OneWireEventSource.Log.Debug(ioe.ToString());
                OneWireEventSource.Log.Debug(ioe.StackTrace);

                /*well, at least I tried!*/
                return(false);
            }
        }