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

📄 onewirecontainer33.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      bank_vector.addElement(memoryPages[1]);      bank_vector.addElement(memoryPages[2]);      bank_vector.addElement(memstatus);      return bank_vector.elements();   }   /**    * Returns the instance of the Scratchpad memory bank.  Contains    * methods for reading/writing the Scratchpad contents.  Also,    * methods for Load First Secret, Compute Next Secret, and    * Refresh Scratchpad    *    * @return the instance of the Scratchpad memory bank    */   public MemoryBankScratchSHAEE getScratchpadMemoryBank()   {      return mbScratchpad;   }   /**    * Returns the instance of the Status page memory bank.    *    * @return the instance of the Status page memory bank    */   public MemoryBankSHAEE getStatusPageMemoryBank()   {      return memstatus;   }   /**    * Returns the instance of the memory bank for a particular page    *    * @param page the page for the requested memory bank;    *    * @return the instance of the memory bank for the specified page    */   public MemoryBankSHAEE getMemoryBankForPage(int page)   {      if(page==3)         page = 2;      return memoryPages[page];   }   /**    * Sets the bus master secret for this DS2432.    *    * @param newSecret Secret for this DS2432.    * @param offset index into array to copy the secret from    */   public void setContainerSecret(byte[] newSecret, int offset)   {      System.arraycopy(newSecret,offset,secret,0,8);      secretSet = true;   }   /**    * Get the secret of this device as an array of bytes.    *    * @param secretBuf array of bytes for holding the container secret    * @param offset index into array to copy the secret to    */   public void getContainerSecret (byte[] secretBuf, int offset)   {      System.arraycopy(secret,0,secretBuf,offset,8);   }   /**    * Get the current status of the secret.    *    * @return  boolean telling if the secret is set    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isContainerSecretSet()      throws OneWireIOException, OneWireException   {      //if(!container_check)      //   container_check = this.checkStatus();      return (secretSet);   }   /**    * Get the status of the secret, if it is write protected.    *    * @return  boolean telling if the secret is write protected.    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isSecretWriteProtected()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      return secretProtected;   }   /**    * Sets the challenge for the Read Authenticate Page    *    * @param challengeset  Challenge for all the memory banks.    */   public void setChallenge(byte [] challengeset, int offset)   {      System.arraycopy(challengeset,0,challenge,offset,3);   }   /**    * Get the challenge of this device as an array of bytes.    *    * @param get  array of bytes containing the iButton challenge    */   public void getChallenge(byte[] get, int offset)   {      System.arraycopy(challenge,0,get,offset,3);   }   /**    * Get the status of all the pages, if they are write protected.    *    * @return  boolean telling if all the pages are write protected.    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isWriteProtectAllSet()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      return memoryPages[2].readOnly;   }   /**    *  Write protects the secret for the DS2432.    */   public void writeProtectSecret()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      // write protect secret      //  - write status byte to address      //    ((8h) + physical) = 88h      memstatus.write(8,ACTIVATION_BYTE,0,1);      secretProtected = true;   }   /**    * Write protect pages 0 to 3    */   public void writeProtectAll()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      // write protect all pages      //  - write status byte to address      //    ((9h) + physical) = 89h      memstatus.write(9,ACTIVATION_BYTE,0,1);      memoryPages[0].writeprotect();      memoryPages[1].writeprotect();      memoryPages[2].writeprotect();   }   /**    * Sets the EPROM mode for page 1.  After setting, Page One can only be written to once.    */   public void setEPROMModePageOne()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      // Enable EPROM mode for page 1.      //  - write status byte to address      //    ((12h) + physical) = 8Ch      memstatus.write(12,ACTIVATION_BYTE,0,1);      memoryPages[1].setEPROM();   }   /**    * Tells if page one is in EPROM mode.    *    * @return  boolean telling if page one is in EPROM mode.    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isPageOneEPROMmode()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      return memoryPages[1].isWriteOnce();   }   /**    * Write protect page zero only.    */   public void writeProtectPageZero()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      // Enable Write protection for page zero.      //  - write status byte to address      //    ((13h) + physical) = 8Dh      memstatus.write(13,ACTIVATION_BYTE,0,1);      memoryPages[0].writeprotect();   }   /**    * Get the status of page zero, if it is write protected.    *    * @return  boolean telling if page zero is write protected.    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean isWriteProtectPageZeroSet()      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      return memoryPages[0].isReadOnly();   }   /**    * Compute Next Secret    *    * @param addr address of page to use for the next secret computation.    * @param parialsecret the data to put into the scrathpad in computing next secret.    */   public void computeNextSecret(int pageNum, byte[] partialsecret, int offset)      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      mbScratchpad.computeNextSecret(pageNum*32, partialsecret, offset);   }   /**    * Compute Next Secret using the current contents of data page and scratchpad.    *    * @param addr address of page to use for the next secret computation.    */   public void computeNextSecret(int pageNum)      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      mbScratchpad.computeNextSecret(pageNum*32);   }   /**    * Load First Secret    *    * @return              boolean saying if first secret was loaded    *    * @throws OneWireIOException    * @throws OneWireException    */   public boolean loadFirstSecret(byte[] data, int offset)      throws OneWireIOException, OneWireException   {      if(!container_check)         container_check = this.checkStatus();      mbScratchpad.loadFirstSecret(0x080, data, offset);      return true;   }   /**    * Refreshes a particular 8-byte set of data on a given page.    * This will correct any weakly-programmed EEPROM bits.  This    * feature is only available on the DS1961S, but is safely    * ignored on the DS2432.  The refresh consists of a Refresh Scratchpad    * command followed by a Load First Secret to the same offset.    *    * @param page the page number that contains the 8-bytes to refresh.    * @param offset the offset into the page for the 8-bytes to refresh.    *    * @return <code>true</code> if refresh is successful.    */   public boolean refreshPage(int page, int offset)      throws OneWireException, OneWireIOException   {      if(!container_check)         container_check = this.checkStatus();      int addr = page*32 + offset;      try      {         mbScratchpad.refreshScratchpad(addr);      }      catch(OneWireException owe)      {         // only return false for the DS2432 devices         // which do not support this command         return false;      }      mbScratchpad.loadFirstSecret(addr);      return true;   }   /**    * Refreshes all 32 bytes of data on a given page.    * This will correct any weakly-programmed EEPROM bits.  This    * feature is only available on the DS1961S, but is safely    * ignored on the DS2432.  The refresh consists of a Refresh Scratchpad    * command followed by a Load First Secret to the same offset, for    * all 8-byte offsets on the page.    *    * @param page the page number that will be refreshed.    *    * @return <code>true</code> if refresh is successful.    */   public boolean refreshPage(int page)      throws OneWireException, OneWireIOException   {      return refreshPage(page, 0) &&             refreshPage(page, 8) &&             refreshPage(page, 16) &&             refreshPage(page, 24);   }   /**    * To check the status of the part.    *    * @return boolean saying the part has been checked or was checked.    */   protected boolean checkStatus()      throws OneWireIOException, OneWireException   {      if(!container_check)      {         byte[] mem = new byte [8];         memstatus.read(8,false,mem,0,8);         if((mem [0] == ( byte ) 0xAA) || (mem [0] == ( byte ) 0x55))            secretProtected = true;         else            secretProtected = false;         if( ((mem [1] == ( byte ) 0xAA) || (mem [1] == ( byte ) 0x55)) ||             ((mem [5] == ( byte ) 0xAA) || (mem [5] == ( byte ) 0x55)) )         {            memoryPages[0].readWrite = false;            memoryPages[0].readOnly = true;         }         else         {            memoryPages[0].readWrite = true;            memoryPages[0].readOnly = false;         }         if((mem [4] == ( byte ) 0xAA) || (mem [4] == ( byte ) 0x55))            memoryPages[1].writeOnce = true;         else            memoryPages[1].writeOnce = false;         if((mem [5] == ( byte ) 0xAA) || (mem [5] == ( byte )0x55))         {            memoryPages[1].readWrite = false;            memoryPages[1].readOnly = true;         }         else         {            memoryPages[1].readWrite = true;            memoryPages[1].readOnly = false;         }         if((mem [5] == ( byte ) 0xAA) || (mem[5] == ( byte ) 0x55))         {            memoryPages[2].readWrite = false;            memoryPages[2].readOnly = true;         }         else         {            memoryPages[2].readWrite = true;            memoryPages[2].readOnly = false;         }         memstatus.checked = true;         memoryPages[0].checked = true;         memoryPages[1].checked = true;         memoryPages[2].checked = true;         container_check = true;      }      return container_check;   }   /**    * Initialize the memory banks and data associated with each.    */   private void initmem()   {      secretSet = false;

⌨️ 快捷键说明

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