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

📄 shaibuttonuser18.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      //hold container reference and address      if(!setiButton18(owc))         throw new OneWireException("Invalid SHA user");   }   /**    * <P>Creates a valid SHAiButtonUser object.  If the service file,    * whose name is taken from the <code>SHAiButtonCopr</code>, is not    * found on the user iButton, a OneWireException is thrown with the    * message "Invalid SHA user".</P>    *    * @param coprBindCode The Coprocessor Bind Code without the user-specific    *        information.    * @param fileName The file name of the account file    * @param fileNameExt The file extenstion of the account file    * @param owc The DS1963S iButton that this object will refer to.    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  This could be    *         caused by a physical interruption in the 1-Wire Network due to    *         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    *    * @see #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18,boolean,byte[])    * @see #SHAiButtonUser18(SHAiButtonCopr)    */   public SHAiButtonUser18(byte[] coprBindCode,                           byte[] fileName, int fileNameExt,                           OneWireContainer18 owc)      throws OneWireException, OneWireIOException   {      //save a copy of the binding code      System.arraycopy(coprBindCode, 0, this.fullBindCode, 0, 7);      System.arraycopy(this.fullBindCode,4,                       this.fullBindCode,12, 3);      //create string representation of service filename      System.arraycopy(fileName, 0, this.serviceFile, 0, 4);      this.strServiceFilename = new String(fileName) + "."                                + (int)fileNameExt;      //hold container reference and address      if(!setiButton18(owc))         throw new OneWireException("Invalid SHA user");   }   /**    * <P>Creates a mostly unitialized SHAiButtonUser object.  This constructor    * merely copies the coprocessors 7 byte binding code into a local cache    * and stores the name of the account service file used for all user    * iButtons.</P>    *    * <P>Since this constructor leaves data unitialized, you should be very    * careful with the use of it.  It is expected that after calling this    * constructor, the user will call <code>setiButton</code> to finish the    * initialization process.  On memory-starved platforms, this should help    * optimize memory usage.</P>    *    * @param copr The SHAiButtonCopr to which the user object is tied.  This    *        Coprocessor contains the necessary binding code and service    *        filename, necessary for both locating a user and recreating his    *        unique secret.    *    * @see #SHAiButtonUser18(SHAiButtonCopr,OneWireContainer18,boolean,byte[])    * @see #SHAiButtonUser18(SHAiButtonCopr)    */   public SHAiButtonUser18(SHAiButtonCopr copr)   {      //save a copy of the binding code      copr.getBindCode(this.fullBindCode,0);      System.arraycopy(this.fullBindCode,4,                       this.fullBindCode,12, 3);      //create string representation of service filename      copr.getFilename(this.serviceFile,0);      this.strServiceFilename = new String(this.serviceFile) + "."                                + (int)copr.getFilenameExt();   }   // ***********************************************************************   // Modifier Methods   //  - setiButton is the only essential modifier.  It updates all   //    data members based on consquences of the account file alone.   // ***********************************************************************   /**    * <P>Modifies this SHA iButton so that it refers to another DS1963S    * container.  This function only copies the reference to the    * OneWireContainer, copes the reference to it's 1-Wire address, and    * then asserts that the iButton contains a valid acccount info file    * associated with the system.</P>    *    * @param owc The <code>OneWireContainer18</code> this object will refer to.    *    * @return <code>true</code> if a valid account service file exists on    *         this <code>OneWireContainer18</code>.    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  This could be    *         caused by a physical interruption in the 1-Wire Network due to    *         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public synchronized boolean setiButton18(OneWireContainer18 owc)      throws OneWireException, OneWireIOException   {      //hold container reference      this.ibc = owc;      //and address      this.address = owc.getAddress(); //getAddress() doesn't malloc!      //clear account information      this.accountPageNumber = -1;      //make sure account info is properly setup      if(!checkAccountPageInfo(owc))         return false;      //setup the fullBindCode with rest of info      this.fullBindCode[4] = (byte)this.accountPageNumber;      System.arraycopy(this.address,0,                       this.fullBindCode,5,7);      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      if(DEBUG)      {         IOHelper.writeLine("------------------------------------");         IOHelper.writeLine("Loaded User");         IOHelper.writeLine("address");         IOHelper.writeBytesHex(owc.getAddress());         IOHelper.writeLine("accountPageNumber: " + accountPageNumber);         IOHelper.writeLine("serviceFilename: " + strServiceFilename);         IOHelper.writeLine("------------------------------------");      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\      return true;   }   /**    * <P>Modifies this SHA iButton so that it refers to another 1963S.    * If this object already has an appropriate instance of OneWireContainer,    * that instance is updated with the new address.</P>    *    * @param adapter The adapter that the device can be found on.    * @param address The address of the 1-Wire device    *    * @return <code>true</code> if a valid account service file exists on    *         this <code>OneWireContainer18</code>.    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  This could be    *         caused by a physical interruption in the 1-Wire Network due to    *         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public synchronized boolean setiButtonUser(DSPortAdapter adapter,                                              byte[] address)      throws OneWireException, OneWireIOException   {      if(this.ibc==null)         this.ibc = new OneWireContainer18();      this.ibc.setupContainer(adapter,address);      if(this.forceOverdrive)         this.ibc.setSpeed(DSPortAdapter.SPEED_OVERDRIVE, false);      return setiButton18(this.ibc);   }   /**    * <P>Modifies this SHA iButton so that it refers to another device.    * If this object does not already has an appropriate instance of    * OneWireContainer, it returns false immediately, because there is    * no adapter info available.  Otherwise, it reuses the same adapter.</P>    *    * @param address The address of the 1-Wire device    *    * @return <code>true</code> if a valid account service file exists on    *         this <code>OneWireContainer18</code>.    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  This could be    *         caused by a physical interruption in the 1-Wire Network due to    *         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public synchronized boolean setiButtonUser(byte[] address)      throws OneWireException, OneWireIOException   {      if(this.ibc==null)         return false;      this.ibc.setupContainer(this.ibc.getAdapter(),address);      if(this.forceOverdrive)         this.ibc.setSpeed(DSPortAdapter.SPEED_OVERDRIVE, false);      return setiButton18(this.ibc);   }   // ***********************************************************************   // End Modifier Methods   // ***********************************************************************   /**    * <P>Returns the value of the write cycle counter for the    * page where the account data is stored.  If the write    * cycle counter has ever been retrieved, this returns the    * cached value.  Otherwise, this method reads the value    * from the part.</P>    *    * @return the value of the write cycle counter for the    *         account data page.    *    * @throws OneWireIOException on a 1-Wire communication error such as    *         reading an incorrect CRC from a 1-Wire device.  This could be    *         caused by a physical interruption in the 1-Wire Network due to    *         shorts or a newly arriving 1-Wire device issuing a 'presence pulse'.    * @throws OneWireException on a communication or setup error with the 1-Wire    *         adapter    */   public synchronized int getWriteCycleCounter()      throws OneWireException, OneWireIOException   {      if(this.writeCycleCounter<0)      {         //need to get the writeCycleCounter.         int wcc = -1;         //don't worry, this should not happen in the critical path.         //so malloc-ing doesnt really matter         byte[] wcc_buffer = new byte[32];         //read the page, 19, containing the write-cycle counters         this.ibc.readMemoryPage(19, wcc_buffer, 0);         //get the offset into page for wcc         int offset = (this.accountPageNumber & 7) << 2;         //convert the four bytes, lsb first, into an int         wcc = (wcc_buffer[offset+3]&0x0ff);         wcc = (wcc << 8) | (wcc_buffer[offset+2]&0x0ff);         wcc = (wcc << 8) | (wcc_buffer[offset+1]&0x0ff);         wcc = (wcc << 8) | (wcc_buffer[offset]&0x0ff);         this.writeCycleCounter = wcc;      }      return this.writeCycleCounter;   }   /**    * Returns <code>true</code> if this buttons account data is stored    * on a page that has a write cycle counter.    *    * @return <code>true</code> if account page has write cycle counter.    */

⌨️ 快捷键说明

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