⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shaibuttonuser.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999-2001 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.application.sha;import com.dalsemi.onewire.OneWireException;import com.dalsemi.onewire.adapter.OneWireIOException;import com.dalsemi.onewire.adapter.DSPortAdapter;import com.dalsemi.onewire.container.OneWireContainer;import com.dalsemi.onewire.application.file.OWFile;import com.dalsemi.onewire.utils.Address;import java.io.IOException;/** * <P>The abstract superclass for all users of a SHAiButton transaction system. * The user in a SHA transaction system mainly consists of a page (or pages) of * account data.  The abstract superclass guarantees an interface for retrieving * information about account data, as well as reading and writing that data.<P> * * <P><code>SHAiButtonUser</code> was defined for use with the DS1963S (family * code 0x18) and the DS1961S (family code 0x33).  The benefit to using our SHA * iButtons in a transaction is for device authentication.  Using a * challenge-response protocol, the DS1961S and the DS1963S can authenticate * themselves to the system before their actual account data is verified.  But, * if device authentication isn't important to your transaction, the * <code>SHAiButtonUser</code> can be extended to support any 1-Wire memory * device.</P> * * <P>The format of user's account data is not specified by this class, only * the interface for accessing it.  Each different SHATransaction is free to * implement whatever format is appropriate for the transaction type.</P> * * @see SHATransaction * @see SHAiButtonCopr * @see SHAiButtonUser18 * @see SHAiButtonUser33 * * @version 1.00 * @author  SKH */public abstract class SHAiButtonUser{   /**    * Turns on extra debugging output    */   static final boolean DEBUG = false;   /**    * Cache of 1-Wire Address    */   protected byte[] address = null;   /**    * local cache of accountData    */   protected final byte[] accountData = new byte[32];   /**    * page number account data is stored on    */   protected int accountPageNumber = -1;   /**    * used to construct appropriate string for OWFile constructor    */   protected final byte[] serviceFile = new byte[]{ (byte)'D',(byte)'L',                                                    (byte)'S',(byte)'M' };   /**    * stores string name of user's service file    */   protected String strServiceFilename = null;   /**    * maintains a cache of the fullBindCode, for later binding of    * coprocessor.    */   protected final byte[] fullBindCode = new byte[15];   /**    * local cache of writeCycleCounter for data page    */   protected int writeCycleCounter = -1;   /**    * force 1-wire container into overdrive speed    */   protected boolean forceOverdrive = false;   // ***********************************************************************   // Begin Accessor Methods   // ***********************************************************************   /**    * <P>Returns the page number of the first memory page where account    * data is stored.</P>    *    * @return page number where account data is stored.    */   public int getAccountPageNumber()   {      return this.accountPageNumber;   }   /**    * <P>Returns the TMEX filename of the user's account data file.</P>    *    * @return filename of user's account data file    */   public String getAccountFilename()   {      return this.strServiceFilename;   }   /**    *<P>Returns the 8 byte address of the OneWireContainer this    * SHAiButton refers to.</P>    *    * @return 8 byte array containing family code, address, and    *         crc8 of the OneWire device.    */   public byte[] getAddress()   {      byte[] data = new byte[8];      System.arraycopy(address,0,data,0,8);      return data;   }   /**    * <P>Copies the 8 byte address of the OneWireContainer into    * the provided array starting at the given offset.</P>    *    * @param data array with at least 8 bytes after offset    * @param offset the index at which copying starts    */   public void getAddress(byte[] data, int offset)   {      System.arraycopy(address, 0, data, offset, 8);   }   /**    * <P>Copies the specified number of bytes from the address    * of the OneWireContainer into the provided array starting    * at the given offset.</P>    *    * @param data array with at least cnt bytes after offset    * @param offset the index at which copying starts    * @param cnt the number of bytes to copy    */   public void getAddress(byte[] data, int offset, int cnt)   {      System.arraycopy(address, 0, data, offset, cnt);   }   /**    * Sets whether or not the container should be forced into    * overdrive.    *    * @param value if true, the container will be forced to overdrive    */   public void setForceOverdrive(boolean value)   {      this.forceOverdrive = value;   }   /**    * Reports whether or not the container is forced into    * overdrive.    *    * @return if true, the container will be forced to overdrive    */   public boolean getForceOverdrive()   {      return this.forceOverdrive;   }   /**    * <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>    *    * @param owc the 1-wire device where the service file will be created.    * @param filename the filename of the service file.    * @param formatDevice if <code>true</code>, the device is formatted    *        before creating the service file.    */   protected boolean createServiceFile(OneWireContainer owc, String filename,                                       boolean formatDevice)   {      boolean 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.getPageList()[0];         bRetVal = true;      }      catch(IOException ioe)      {         bRetVal = false;         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\         if(DEBUG)         {            ioe.printStackTrace();         }         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      }      try      {         owf.close();         return bRetVal;      }      catch(IOException ioe)      {         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\         if(DEBUG)         {            ioe.printStackTrace();         }         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\         /*well, at least I tried!*/         return false;      }   }   /**    * <P>Asserts that proper account info exists for this SHAiButtonUser    * and establishes a buffer for caching account data.</P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -