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

📄 onewirecontainer33.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999 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.container;// importsimport java.util.Vector;import java.util.Enumeration;import com.dalsemi.onewire.utils.CRC16;import com.dalsemi.onewire.utils.*;import com.dalsemi.onewire.adapter.*;import com.dalsemi.onewire.OneWireException;import com.dalsemi.onewire.container.OneWireContainer;import com.dalsemi.onewire.container.MemoryBankScratchSHAEE;import com.dalsemi.onewire.container.MemoryBankSHAEE;/** * <P>1-Wire&#174 container for the '1K-Bit protected 1-Wire EEPROM with SHA-1 *  Engine' family type <B>33</B> (hex), Dallas Semiconductor part number: * <B>DS1961S,DS2432</B>. * * <H3> Features </H3> * <UL> *   <LI> 1128 bits of 5V EEPROM memory partitioned into four pages of 256 bits, *        a 64-bit write-only secret and up to 5 general purpose read/write *        registers. *   <LI> On-chip 512-bit SHA-1 engine to compute 160-bit Message Authentication *        Codes (MAC) and to generate secrets. *   <LI> Write access requires knowledge of the secret and the capability of *        computing and transmitting a 160-bit MAC as authorization. *   <LI> Secret and data memory can be write-protected (all or page 0 only) or *        put in EPROM-emulation mode ("write to 0", page0) *   <LI> unique, fatory-lasered and tested 64-bit registration number (8-bit *        family code + 48-bit serial number + 8-bit CRC tester) assures *        absolute traceablity because no two parts are alike. *   <LI> Built-in multidrop controller ensures compatibility with other 1-Wire *        net products. *   <LI> Reduces control, address, data and power to a single data pin. *   <LI> Directly connects to a single port pin of a microprocessor and *        communicates at up to 16.3k bits per second. *   <LI> Overdrive mode boosts communication speed to 142k bits per second. *   <LI> 8-bit family code specifies DS2432 communication requirements to reader. *   <LI> Presence detector acknowledges when reader first applies voltage. *   <LI> Low cost 6-lead TSOC surface mount package, or solder-bumped chip scale *        package. *   <LI> Reads and writes over a wide voltage range of 2.8V to 5.25V from -40C *        to +85C. * </UL> * * <P> The memory can also be accessed through the objects that are returned * from the {@link #getMemoryBanks() getMemoryBanks} method. </P> * * The following is a list of the MemoryBank instances that are returned: * * <UL> *   <LI> <B> Page Zero with write protection</B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 32 starting at physical address 0 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Page</I> 1 page of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC and write protection. *      </UL> *   <LI> <B> Page One with EPROM mode and write protection </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 32 starting at physical address 32 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Page</I> 1 page of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC, EPROM mode and write protection. *      </UL> *   <LI> <B> Page Two and Three with write protection </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 64 starting at physical address 64 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Pages</I> 2 pages of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC and write protection. *      </UL> *   <LI> <B> Status Page that contains the secret and the status. </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 24 starting at physical address 128 *         <LI> <I> Page Features </I> Contains secret and status for the iButton. *      </UL> * </UL> * * <DD> <H4> Example 1</H4> * Display some features of isMACValid where owd is an instanceof OneWireContainer33 and * bank is an instanceof PagedMemoryBank: * <PRE> <CODE> *  byte[] read_buf  = new byte [bank.getPageLength()]; *  byte[] extra_buf = new byte [bank.getExtraInfoLength()]; *  byte[] challenge = new byte [8]; * *  // read a page (use the most verbose and secure method) *  if (bank.hasPageAutoCRC()) *  { *     System.out.println("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.getAddress(); *        macvalid = owd.isMACValid(bank.getStartPhysicalAddress()+pg*bank.getPageLength(), *                                  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); *  } * </CODE> </PRE> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS2432.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS2432.pdf</A> * </DL> * * @see com.dalsemi.onewire.application.sha.SHAiButtonUser33 * @version 	0.00, 19 Dec 2000 * @author JPE */public class OneWireContainer33   extends OneWireContainer{   //turns on extra debugging output in all 1-wire containers   private static final boolean DEBUG = false;   //--------   //-------- Static Final Variables   //--------   /** Private Secret */   private byte[] secret 	= new byte [8];   /** Challenge to use for the Read Authenticate Methods */   private byte[] challenge = new byte [8];   /** The different memory banks for the container. */   private MemoryBankScratchSHAEE mbScratchpad;   private MemoryBankSHAEE memstatus;   private final MemoryBankSHAEE[] memoryPages = new MemoryBankSHAEE[4];   /** Buffer used to hold MAC for certain calls */   private byte[] MAC_buffer = new byte[20];   /** Flag to indicate if the secret has been set. */   protected boolean secretSet;   /** Flag to indicate if the secret is write protected. */   protected boolean secretProtected;   /** Flag to indicate if the adapter has been specified. */   protected boolean setAdapter;   /** Flag to indicate if the status has been checked. */   protected boolean container_check;   /** block of 0xFF's used for faster read pre-fill of 1-Wire blocks */   protected static final byte[] ffBlock = {                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF,                     (byte)0xFF,(byte)0xFF,(byte)0xFF,(byte)0xFF };   /** block of 0xFF's used for faster erase of blocks */   protected static final byte[] zeroBlock = {                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };   /** This byte is used to set flags in the status register */   private static final byte[] ACTIVATION_BYTE = {(byte)0xAA};   /**    * Default Constructor OneWireContainer33.    * Must call setupContainer before using.    */   public OneWireContainer33 ()   {      super();      System.arraycopy(ffBlock,0,secret,0,8);      System.arraycopy(ffBlock,0,challenge,0,8);      setAdapter = false;      container_check = false;   }   /**    * Create a container with a provided adapter object    * and the address of the iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public OneWireContainer33 (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);      System.arraycopy(ffBlock,0,secret,0,8);      System.arraycopy(ffBlock,0,challenge,0,8);      setAdapter = true;      container_check = false;      initmem();   }   /**    * Create a container with a provided adapter object    * and the address of the iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public OneWireContainer33 (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);      System.arraycopy(ffBlock,0,secret,0,8);      System.arraycopy(ffBlock,0,challenge,0,8);      setAdapter = true;      container_check = false;      initmem();   }   /**    * Create a container with a provided adapter object    * and the address of the iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public OneWireContainer33 (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);      System.arraycopy(ffBlock,0,secret,0,8);      System.arraycopy(ffBlock,0,challenge,0,8);      setAdapter = true;      container_check = false;      initmem();   }   //--------   //-------- Methods   //--------   /**    * Tells whether an adapter has been set.    *    * @return boolean telling weather an adapter has been set.    */   protected boolean adapterSet()   {      return setAdapter;   }   /**    * Provide this container the adapter object used to access this device    * and provide the address of this iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public void setupContainer (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super.setupContainer(sourceAdapter,newAddress);      if(!setAdapter)         initmem();      setAdapter = true;   }   /**    * Provide this container the adapter object used to access this device    * and provide the address of this iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public void setupContainer (DSPortAdapter sourceAdapter, long newAddress)   {      super.setupContainer(sourceAdapter,newAddress);      if(!setAdapter)         initmem();      setAdapter = true;   }   /**    * Provide this container the adapter object used to access this device    * and provide the address of this iButton or 1-Wire device.    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton.    * @param  newAddress        address of this 1-Wire device    */   public void setupContainer (DSPortAdapter sourceAdapter, String newAddress)   {      super.setupContainer(sourceAdapter,newAddress);      if(!setAdapter)         initmem();      setAdapter = true;   }   /**    * Retrieve the Dallas Semiconductor part number of the iButton    * as a string.  For example 'DS1992'.    *    * @return string represetation of the iButton name.    */   public String getName ()   {      return "DS1961S";   }   /**    * Retrieve the alternate Dallas Semiconductor part numbers or names.    * A 'family' of MicroLAN devices may have more than one part number    * depending on packaging.    *    * @return  the alternate names for this iButton or 1-Wire device    */   public String getAlternateNames ()   {      return "DS2432";   }   /**    * Retrieve a short description of the function of the iButton type.    *    * @return string represetation of the function description.    */   public String getDescription ()   {      return "1K-Bit protected 1-Wire EEPROM with SHA-1 Engine.";   }   /**    * Returns the maximum speed this iButton can communicate at.    *    * @return  max. communication speed.    */   public int getMaxSpeed ()   {      return DSPortAdapter.SPEED_OVERDRIVE;   }   /**    * Get an enumeration of memory bank instances that implement one or more    * of the following interfaces:    * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank},    * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank},    * and {@link com.dalsemi.onewire.container.OTPMemoryBank OTPMemoryBank}.    * @return <CODE>Enumeration</CODE> of memory banks    */   public Enumeration getMemoryBanks ()   {      Vector bank_vector = new Vector(4);      bank_vector.addElement(mbScratchpad);      bank_vector.addElement(memoryPages[0]);

⌨️ 快捷键说明

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