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

📄 onewirecontainer18.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 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;import com.dalsemi.onewire.adapter.OneWireIOException;import com.dalsemi.onewire.OneWireException;import com.dalsemi.onewire.utils.CRC16;import com.dalsemi.onewire.utils.IOHelper;import com.dalsemi.onewire.adapter.DSPortAdapter;import java.util.Vector;import java.util.Enumeration;/** * <P> 1-Wire&#174 container for a SHA Transaction iButton, DS1963S. * This container encapsulates the functionality of the 1-Wire family type <B>18</B> (hex). * </P> * * <H3> Features </H3> * <UL> *   <LI> 4096 bits of read/write nonvolatile memory organized into 16 pages *   <li> 8 memory pages have 64-bit secrets and 32-bit read-only, non-rolling over write cycle counters *   <LI> Secrets are write only and have their own write cycle counters *   <li> On-chip 512-bit SHA-1 engine to compute 160-bit Message Authentication Codes *   <li> 256-bit scratchpad ensures integrity of data transfer *   <li> On-chip 16-bit CRC generator for safeguarding data transfers *   <li> Overdrive mode supports communication up to 142 kbits per second * </UL> * * <p>This container provides the functionality to use the raw power of the * DS1963S.  It does not immediately implement transactions and authentication. * The class {@link com.dalsemi.onewire.application.sha.SHAiButtonUser18 SHAiButton} does these. * The <code>SHAiButton</code> class exists on top of this class, making higher * level calls to implement transactions.</p> * <p>This container makes use of several optimizations to help it run fast * on TINI.  These optimizations do little for the PC, but they do not * slow down the PC.  Most methods are <code>synchronized</code> because they access * an instance byte array.  This is less expensive than creating new byte * arrays for every method, because there should * not be contention for the resources in this container between threads. * Threads should use the <code>com.dalsemi.onewire.adapter.DSPortAdapter</code> methods * <code>beginExclusive(boolean)</code> and <code>endExclusive()</code> to synchronize on the 1-Wire port.</p> * * <p>Notice that for maximum performance, programs should call the method <code>setSpeedCheck(boolean)</code> * with an argument <code>false</code> before any other methods that access the * 1-Wire.  A program that calls this function is assumed to understand and * control the speed of communication on the 1-Wire bus.  If the speed check is not disabled, * a call to the method <code>OneWireContainer.doSpeed()</code> will occur in almost every * function.  While this should guarantee that the 1-Wire bus is never at an unknown speed, * it will slow down throughput considerably.</p> * * <H3> Memory </H3> * * <p>In the interest of speed, this container has several methods to quickly access * the memory of a DS9163S.  These methods include: * <ul> *     <li> {@link #eraseScratchPad(int)                    <code>eraseScratchPad</code>} *     <li> {@link #readScratchPad(byte[],int)              <code>readScratchPad</code>} *     <li> {@link #writeScratchPad(int,int,byte[],int,int) <code>writeScratchPad</code>} *     <li> {@link #readMemoryPage(int,byte[],int)          <code>readMemoryPage</code>} *     <li> {@link #readAuthenticatedPage(int,byte[],int)   <code>readAuthenticatedPage</code>} *     <li> {@link #writeDataPage(int,byte[])               <code>writeDataPage</code>} * </ul></p> * * <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> Scratchpad with CRC and auto-hide</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 not-general-purpose volatile *         <LI> <I> Pages</I> 1 page of length 32 bytes *         <LI> <I> Page Features </I> page-device-CRC *         <li> <i> Extra information for each page</i>  Target address, offset, length 3 *      </UL> *   <LI> <B> Main Memory </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 256 starting at physical address 0 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Pages</I> 8 pages of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC *      </UL> *   <LI> <B> Memory with write cycle counter </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 256 starting at physical address 256 *         <LI> <I> Features</I> Read/Write general-purpose non-volatile *         <LI> <I> Pages</I> 8 pages of length 32 bytes giving 29 bytes Packet data payload *         <LI> <I> Page Features </I> page-device-CRC *         <li> <i> Extra information for each page</i>  Write cycle counter, length 3 *      </UL> *   <LI> <B> Write cycle counters and PRNG counter </B> *      <UL> *         <LI> <I> Implements </I> {@link com.dalsemi.onewire.container.MemoryBank MemoryBank}, *                  {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} *         <LI> <I> Size </I> 96 starting at physical address 608 *         <LI> <I> Features</I> Read-only not-general-purpose non-volatile *         <LI> <I> Pages</I> 3 pages of length 32 bytes *      </UL> * </UL> * * <H3> Usage </H3> * * <p>For examples on using the SHA iButton for transactions and authentications, see * the examples in the {@link com.dalsemi.onewire.application.sha.SHAiButtonUser18 SHAiButton} * usage section.</p> * * For examples regarding memory operations, * <uL> * <li> See the usage example in * {@link com.dalsemi.onewire.container.OneWireContainer OneWireContainer} * to enumerate the MemoryBanks. * <li> See the usage examples in * {@link com.dalsemi.onewire.container.MemoryBank MemoryBank} and * {@link com.dalsemi.onewire.container.PagedMemoryBank PagedMemoryBank} * for bank specific operations. * </uL> * * <H3> DataSheet </H3> * <DL> * <DD><A HREF="http://pdfserv.maxim-ic.com/arpdf/DS1963S.pdf"> http://pdfserv.maxim-ic.com/arpdf/DS1963S.pdf</A> * </DL> * * <p>Note that the protocol for transactions using SHA iButtons calls for * 2 iButtons.  One belongs to the system that grants authentication and * is authorized to validate money.  This iButton is usually called the * Coprocessor.  The other iButton is the device that contains digital * money that must be authenticated and verified to perform transactions. * This iButton is usually called a User iButton, Roaming iButton, * or Roving iButton.</p> * * @author KLA * @version 0.00, 28 Aug 2000 * @see com.dalsemi.onewire.application.sha.SHAiButtonUser18 * @see com.dalsemi.onewire.adapter.DSPortAdapter#beginExclusive(boolean) * @see com.dalsemi.onewire.adapter.DSPortAdapter#endExclusive() * @see OneWireContainer#doSpeed() */public class OneWireContainer18   extends OneWireContainer{   //turns on extra debugging output in all 1-wire containers   private static final boolean DEBUG = false;   //--------   //-------- Variables   //--------   /**    * Scratchpad access memory bank    */   private MemoryBankScratch scratch;   /**    * Main memory access memory bank    */   private MemoryBankNVCRC memory;   /**    * Main memory with counter access memory bank    */   private MemoryBankNVCRC memoryPlus;   /* number of times we wait for the 10101010... to appear    * on commands such as read_auth_page, copy_scratch...    */   private int block_wait_count = 20;   /* are we currently using resume?  some internal code    * makes use of the resume function, but often we can't    * tell from inside this class    */   private boolean resume = false;   /* should we call doSpeed every time we do something?    * this is the safe way to make sure we never loose    * communication, but this stuff has really gotta    * fly, so to make it fly, disable this before doing anything    * else!    */   private boolean doSpeedEnable = true;   private byte[] byte_buffer     = new byte [60];   //use this everywhere to communicate   private byte[] private_address = null;   static byte[] FF        = new byte [60];   //use this to fill an array with 0x0ff's   static   {      for (int i = 0; i < FF.length; i++)         FF [i] = ( byte ) 0x0ff;   }   //there's really no good reason for these to be public like they were in 0.00 OneWire release   private byte TA1;   private byte TA2;   private byte ES;   //--------   //-------- PUBLIC STATIC FINAL's   //--------   /* 1-Wire Protocol command to read the DS1963S memory.    * See the datasheet for more information.    *    * @see #readMemoryPage(int,byte[],int)    */   public static final byte READ_MEMORY = ( byte ) 0xF0;   /* 1-Wire Protocol command to write the DS1963S scratchpad.    * See the datasheet for more information.    *    * @see #writeScratchPad(int,int,byte[],int,int)    */   public static final byte WRITE_SCRATCHPAD = ( byte ) 0x0F;   /* 1-Wire Protocol command to match a signature to    * the one in the DS1963S scratchpad.  To verify a signature,    * the DS1963S goes into hidden mode.  It can only be verified    * with this command.  See the datasheet for more information.    *    * @see #matchScratchPad(byte[])    */   public static final byte MATCH_SCRATCHPAD = ( byte ) 0x3C;   /* 1-Wire Protocol command to erase the DS1963S scratchpad.    * Also brings the device out of hidden mode and back to    * normal operation.  See the datasheet for more information.    *    * @see #eraseScratchPad(int)    */   public static final byte ERASE_SCRATCHPAD = ( byte ) 0xC3;   /* 1-Wire Protocol command to read the DS1963S scratchpad.    * See the datasheet for more information.    *    * @see #readScratchPad(byte[],int)    */   public static final byte READ_SCRATCHPAD = ( byte ) 0xAA;   /* 1-Wire Protocol command to read an authenticated    * DS1963S memory page.  The device generates a signature for    * the page that is placed in the scratchpad.    * See the datasheet for more information.    *    * @see #readAuthenticatedPage(int,byte[],int)    */   public static final byte READ_AUTHENTICATED_PAGE = ( byte ) 0xA5;   /* 1-Wire Protocol command to copy the DS1963S scratchpad    * to a memory location.  See the datasheet for more information.    *    * @see #copyScratchPad()    */   public static final byte COPY_SCRATCHPAD = ( byte ) 0x55;   /* 1-Wire Protocol command to perform a SHA cryptographic    * function on the DS1963S.  See the datasheet for more information.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    */   public static final byte COMPUTE_SHA = ( byte ) 0x33;   //SHA commands   /* 1-Wire Protocol command to compute a master secret    * on the DS1963S.  See the datasheet for more information.    * This command should be used with the first partial secret.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    * @see #installMasterSecret(int,byte[],int)    */   public static final byte COMPUTE_FIRST_SECRET = ( byte ) 0x0F;   /* 1-Wire Protocol command to compute a master secret    * on the DS1963S.  See the datasheet for more information.    * This command should be used with any partial secret    * except the first.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    * @see #installMasterSecret(int,byte[],int)    */   public static final byte COMPUTE_NEXT_SECRET = ( byte ) 0xF0;   /* 1-Wire Protocol command to verify signatures    * on the DS1963S.  See the datasheet for more information.    * This command should be used to verify authentication    * and to verify user data.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    */   public static final byte VALIDATE_DATA_PAGE = ( byte ) 0x3C;   /* 1-Wire Protocol command to create a signature of a    * selected data page on the DS1963S.  See the datasheet for more information.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    */   public static final byte SIGN_DATA_PAGE = ( byte ) 0xC3;

⌨️ 快捷键说明

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