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

📄 onewirecontainer18.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
   /* 1-Wire Protocol command to create a random challenge    * using the DS1963S's pseudo random number generator.    * See the datasheet for more information.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    * @see #SHAiButton#generateChallenge(int,int,byte[])    */   public static final byte COMPUTE_CHALLENGE = ( byte ) 0xCC;   /* 1-Wire Protocol command to authenticate a host    * on the DS1963S.  See the datasheet for more information.    *    * @see #SHAFunction(byte,int)    * @see #SHAFunction(byte)    */   public static final byte AUTH_HOST = ( byte ) 0xAA;   /* 1-Wire Protocol command that allows quick reselection    * of the DS1963S.  Normally, selection involved a nine byte sequence:    * one byte for the Select Command, and the eight byte address of the    * 1-Wire device.  The 1963S remembers if it was the last device to    * communicate with the master on the 1-Wire bus.  If it was, and it    * receives the <code>RESUME</code> command, then it is selected.    *    * @see #useResume(boolean)    */   public static final byte RESUME = ( byte ) 0xA5;   //--------   //-------- Constructors   //--------   /**    * Creates a new <code>OneWireContainer</code> for communication with a DS1963S SHA iButton.    * Note that the method <code>setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[])</code>    * must be called to set the correct <code>DSPortAdapter</code> device address.    *    * @see com.dalsemi.onewire.container.OneWireContainer#setupContainer(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) setupContainer(DSPortAdapter,byte[])    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer18(DSPortAdapter,byte[])    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer18(DSPortAdapter,long)    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer18(DSPortAdapter,String)    */   public OneWireContainer18 ()   {      super(null,0);      if(private_address==null)         private_address = new byte [8];      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a DS1963S SHA iButton.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1963S SHA iButton    *    * @see #OneWireContainer18()    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer18(DSPortAdapter,long)    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer18(DSPortAdapter,String)    */   public OneWireContainer18 (DSPortAdapter sourceAdapter, byte[] newAddress)   {      super(sourceAdapter, newAddress);      if(private_address==null)         private_address = new byte [8];      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a DS1963S SHA iButton.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1963S SHA iButton    *    * @see #OneWireContainer18()    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer18(DSPortAdapter,byte[])    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,java.lang.String) OneWireContainer18(DSPortAdapter,String)    */   public OneWireContainer18 (DSPortAdapter sourceAdapter, long newAddress)   {      super(sourceAdapter, newAddress);      if(private_address==null)         private_address = new byte [8];      // initialize the memory banks      initMem();   }   /**    * Creates a new <code>OneWireContainer</code> for communication with a DS1963S SHA iButton.    *    * @param  sourceAdapter     adapter object required to communicate with    * this iButton    * @param  newAddress        address of this DS1963S SHA iButton    *    * @see #OneWireContainer18()    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,byte[]) OneWireContainer18(DSPortAdapter,byte[])    * @see #OneWireContainer18(com.dalsemi.onewire.adapter.DSPortAdapter,long)   OneWireContainer18(DSPortAdapter,long)    */   public OneWireContainer18 (DSPortAdapter sourceAdapter, String newAddress)   {      super(sourceAdapter, newAddress);      if(private_address==null)         private_address = new byte [8];      // initialize the memory banks      initMem();   }   //--------   //-------- Methods   //--------   /**    * <p>Provides this container with the adapter object used to access this device and    * the address of the iButton or 1-Wire device.  Overrides the <code>OneWireContainer</code>    * method for speed, as the <code>OneWireContainer</code> version has    * a byte array allocation.  Since there is a call to <code>setupContainer()</code>    * in the critical path of a transaction (when a roving SHA iButton is    * introduced to the 1-Wire Bus), this must occur quickly.  This improves performance    * on TINI.</p>    *    * @param  sourceAdapter     adapter object required to communicate with    *                           this iButton    * @param  newAddress        address of this 1-Wire device    *    * @see com.dalsemi.onewire.utils.Address    */   public void setupContainer (DSPortAdapter sourceAdapter, byte[] newAddress)   {      // get a reference to the source adapter (will need this to communicate)      this.adapter = sourceAdapter;      // set the Address      synchronized (this)      {         if(private_address==null)            private_address = new byte[8];         System.arraycopy(newAddress, 0, private_address, 0, 8);         this.address = private_address;      }      // set desired speed to be SPEED_REGULAR by default with no fallback      speed           = adapter.SPEED_REGULAR;      speedFallBackOK = false;   }   /**    * Get the Dallas Semiconductor part number of the iButton    * or 1-Wire Device as a <code>java.lang.String</code>.    * For example "DS1992".    *    * @return iButton or 1-Wire device name    */   public String getName ()   {      return "DS1963S";   }   /**    * Retrieve the alternate Dallas Semiconductor part numbers or names.    * A 'family' of MicroLAN devices may have more than one part number    * depending on packaging.  There can also be nicknames such as    * "Crypto iButton".    *    * @return  the alternate names for this iButton or 1-Wire device    */   public String getAlternateNames ()   {      return "SHA-1 iButton";   }   /**    * Get a short description of the function of this iButton    * or 1-Wire Device type.    *    * @return device description    */   public String getDescription ()   {      return "4096 bits of read/write nonvolatile memory. Memory "             + "is partitioned into sixteen pages of 256 bits each. "             + "Has overdrive mode.  One-chip 512-bit SHA-1 engine "             + "and secret storage.";   }   /**    * Returns the maximum speed this iButton device can    * communicate at.    *    * @return maximum speed    * @see DSPortAdapter#setSpeed    */   public int getMaxSpeed ()   {      return DSPortAdapter.SPEED_OVERDRIVE;   }   /**    * Gets 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 = new Vector(4);      // scratchpad      bank.addElement(scratch);      // NVRAM (no write cycle)      bank.addElement(memory);      // NVRAM (with write cycle counters)      bank.addElement(memoryPlus);      // Page Write cycle counters      MemoryBankNV cnt = new MemoryBankNV(this,                                          ( MemoryBankScratch ) scratch);      cnt.numberPages          = 3;      cnt.size                 = 96;      cnt.bankDescription      = "Write cycle counters and PRNG counter";      cnt.startPhysicalAddress = 608;      cnt.readOnly             = true;      cnt.pageAutoCRC          = false;      cnt.generalPurposeMemory = false;      cnt.readWrite            = false;      bank.addElement(cnt);      return bank.elements();   }   /**    * Construct the memory banks used for I/O.    */   private void initMem ()   {      // scratchpad      scratch = new MemoryBankScratchSHA(this);      // NVRAM (no write cycle)      memory                      = new MemoryBankNVCRC(this,              ( MemoryBankScratch ) scratch);      memory.numberPages          = 8;      memory.size                 = 256;      memory.extraInfoLength      = 8;      memory.readContinuePossible = false;      memory.numVerifyBytes       = 8;      // NVRAM (with write cycle counters)      memoryPlus                      = new MemoryBankNVCRC(this,              ( MemoryBankScratch ) scratch);      memoryPlus.numberPages          = 8;      memoryPlus.size                 = 256;      memoryPlus.bankDescription      = "Memory with write cycle counter";      memoryPlus.startPhysicalAddress = 256;      memoryPlus.extraInfo            = true;      memoryPlus.extraInfoDescription = "Write cycle counter";      memoryPlus.extraInfoLength      = 8;      memoryPlus.readContinuePossible = false;      memoryPlus.numVerifyBytes       = 8;   }   ////////////////////////////////////////////////////////////////////   //SHAiButton real methods!!!!!!   ////////////////////////////////////////////////////////////////////   /**    * Directs the container to avoid the calls to doSpeed() in methods that communicate    * with the SHA iButton. To ensure that all parts can talk to the 1-Wire bus    * at their desired speed, each method contains a call    * to <code>doSpeed()</code>.  However, this is an expensive operation.    * If a user manages the bus speed in an    * application,  call this method with <code>doSpeedCheck</code>    * as <code>false</code>.  The default behavior is    * to call <code>doSpeed()</code>.    *    * @param doSpeedCheck <code>true</code> for <code>doSpeed()</code> to be called before every    * 1-Wire bus access, <code>false</code> to skip this expensive call    *    * @see OneWireContainer#doSpeed()    */   public synchronized void setSpeedCheck (boolean doSpeedCheck)   {      doSpeedEnable = doSpeedCheck;   }   /**    * <p>Tells this <code>OneWireContainer18</code> whether it can use the <code>RESUME</code> command.    * The <code>RESUME</code> command allows the DS1963S to be re-selected for communication    * quickly by using a one <code>byte</code> <code>RESUME</code> command rather than a    * nine <code>byte</code> selection sequence.  If another 1-Wire device is accessed,    * <code>useResume(false)</code> must be called, a normal selection of the part    * must be performed, and then <code>useResume(true)</code> can be called.</p>    *    * @param set <code>true</code> to use the one <code>byte</code> <code>RESUME</code> command    * instead of the nine <code>byte</code> select command    *    * @see #RESUME    */   public synchronized void useResume (boolean set)   {      resume = set;   }   /**    * <p>Erases the scratchpad of the DS1963S.  The cryptographic features    * of the DS1963S leave the device in 'hidden mode', which makes most    * memory functions inaccessible.  A call to <code>eraseScratchPad(int)</code>    * brings the device out of 'hidden mode', filling the scratchpad    * with 0x0FF <code>bytes</code>.</p>    *    * <p>The argument <code>page</code> is usually unimportant, except in cases    * where a memory page needs to be erased.  Erase a memory page by calling    * <code>eraseScratchPad(page_number)</code>, followed by <code>readScratchPad()</code>    * and then <code>copyScratchPad()</code>.    *    * @param page the target page number    *    * @return true if successful, false if the operation failed while waiting for the    * DS1963S's output to alternate (see the datasheet for a description)

⌨️ 快捷键说明

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