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

📄 memorybankscratch.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   }   /**    * Query to get  page length in bytes in current memory bank.    *    * @return   page length in bytes in current memory bank    */   public int getPageLength ()   {      return pageLength;   }   /**    * Query to get Maximum data page length in bytes for a packet    * read or written in the current memory bank.  See the 'ReadPagePacket()'    * and 'WritePagePacket()' methods.  This method is only usefull    * if the current memory bank is general purpose memory.    *    * @return  max packet page length in bytes in current memory bank    */   public int getMaxPacketDataLength ()   {      return maxPacketDataLength;   }   /**    * Query to see if current memory bank pages can be read with    * the contents being verified by a device generated CRC.    * This is used to see if the 'ReadPageCRC()' can be used.    *    * @return  'true' if current memory bank can be read with self    *          generated CRC.    */   public boolean hasPageAutoCRC ()   {      return pageAutoCRC;   }   /**    * Query to see if current memory bank pages when read deliver    * extra information outside of the normal data space.  Examples    * of this may be a redirection byte, counter, tamper protection    * bytes, or SHA-1 result.  If this method returns true then the    * methods 'ReadPagePacket()' and 'readPageCRC()' with 'extraInfo'    * parameter can be used.    *    * @return  'true' if reading the current memory bank pages    *                 provides extra information.    *    * @deprecated  As of 1-Wire API 0.01, replaced by {@link #hasExtraInfo()}    */   public boolean haveExtraInfo ()   {      return extraInfo;   }   /**    * Checks to see if this memory bank's pages deliver extra    * information outside of the normal data space,  when read.  Examples    * of this may be a redirection byte, counter, tamper protection    * bytes, or SHA-1 result.  If this method returns true then the    * methods with an 'extraInfo' parameter can be used:    * {@link #readPage(int,boolean,byte[],int,byte[]) readPage},    * {@link #readPageCRC(int,boolean,byte[],int,byte[]) readPageCRC}, and    * {@link #readPagePacket(int,boolean,byte[],int,byte[]) readPagePacket}.    *    * @return  <CODE> true </CODE> if reading the this memory bank's    *                 pages provides extra information    *    * @see #readPage(int,boolean,byte[],int,byte[]) readPage(extra)    * @see #readPageCRC(int,boolean,byte[],int,byte[]) readPageCRC(extra)    * @see #readPagePacket(int,boolean,byte[],int,byte[]) readPagePacket(extra)    * @since 1-Wire API 0.01    */   public boolean hasExtraInfo ()   {      return extraInfo;   }   /**    * Query to get the length in bytes of extra information that    * is read when read a page in the current memory bank.  See    * 'hasExtraInfo()'.    *    * @return  number of bytes in Extra Information read when reading    *          pages in the current memory bank.    */   public int getExtraInfoLength ()   {      return extraInfoLength;   }   /**    * Query to get a string description of what is contained in    * the Extra Informationed return when reading pages in the current    * memory bank.  See 'hasExtraInfo()'.    *    * @return string describing extra information.    */   public String getExtraInfoDescription ()   {      return extraInfoDescription;   }   /**    * Set the write verification for the 'write()' method.    *    * @param  doReadVerf   true (default) verify write in 'write'    *                      false, don't verify write (used on    *                      Write-Once bit manipulation)    */   public void setWriteVerification (boolean doReadVerf)   {      writeVerification = doReadVerf;   }   //--------   //-------- I/O methods   //--------   /**    * Read  memory in the current bank with no CRC checking (device or    * data). The resulting data from this API may or may not be what is on    * the 1-Wire device.  It is recommends that the data contain some kind    * of checking (CRC) like in the readPagePacket() method or have    * the 1-Wire device provide the CRC as in readPageCRC().  readPageCRC()    * however is not supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    *    * @param  startAddr     starting address    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       read() continious where the last one led off    *                       and it is inside a 'beginExclusive/endExclusive'    *                       block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    * @param  len           length in bytes to read    *    * @throws OneWireIOException    * @throws OneWireException    */   public void read (int startAddr, boolean readContinue, byte[] readBuf,                     int offset, int len)      throws OneWireIOException, OneWireException   {      // check if read exceeds memory      if ((startAddr + len) > size)         throw new OneWireException("Read exceeds memory bank end");      // attempt to put device at speed      checkSpeed();      // read the scratchpad, discard extra information      readScratchpad(readBuf, offset, len, null);   }   /**    * Write  memory in the current bank.  It is recommended that    * when writing  data that some structure in the data is created    * to provide error free reading back with read().  Or the    * method 'writePagePacket()' could be used which automatically    * wraps the data in a length and CRC.    *    * When using on Write-Once devices care must be taken to write into    * into empty space.  If write() is used to write over an unlocked    * page on a Write-Once device it will fail.  If write verification    * is turned off with the method 'setWriteVerification(false)' then    * the result will be an 'AND' of the existing data and the new data.    *    * @param  startAddr     starting address    * @param  writeBuf      byte array containing data to write    * @param  offset        offset into writeBuf to get data    * @param  len           length in bytes to write    *    * @throws OneWireIOException    * @throws OneWireException    */   public void write (int startAddr, byte[] writeBuf, int offset, int len)      throws OneWireIOException, OneWireException   {      // return if nothing to do      if (len == 0)         return;      // attempt to put device at speed      checkSpeed();      // check if write exceeds memory      if ((startAddr + len) > size)         throw new OneWireException("Write exceeds memory bank end");      // write the page of data to scratchpad      writeScratchpad(startPhysicalAddress + startAddr, writeBuf, offset,                      len);      // read to verify ok      byte[] raw_buf   = new byte [pageLength];      byte[] extra_buf = new byte [extraInfoLength];      readScratchpad(raw_buf, 0, 32, extra_buf);      // check to see if the same      for (int i = 0; i < len; i++)         if (raw_buf [i] != writeBuf [i + offset])         {            forceVerify();            throw new OneWireIOException(               "Read back verify had incorrect data");         }      // check to make sure that the address is correct      if ((((extra_buf [0] & 0x00FF) | ((extra_buf [1] << 8) & 0x00FF00))              & 0x00FFFF) != (startPhysicalAddress + startAddr))      {         forceVerify();         throw new OneWireIOException("Read back address had incorrect data");      }   }   //--------   //-------- PagedMemoryBank I/O methods   //--------   /**    * Read  page in the current bank with no    * CRC checking (device or data). The resulting data from this API    * may or may not be what is on the 1-Wire device.  It is recommends    * that the data contain some kind of checking (CRC) like in the    * readPagePacket() method or have the 1-Wire device provide the    * CRC as in readPageCRC().  readPageCRC() however is not    * supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPage() continious where the last one    *                       led off and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPage (int page, boolean readContinue, byte[] readBuf,                         int offset)      throws OneWireIOException, OneWireException   {      // check if read exceeds memory      if (page != 0)         throw new OneWireException("Page read exceeds memory bank end");      // attempt to put device at speed      checkSpeed();      // read the scratchpad, discard extra information      readScratchpad(readBuf, offset, pageLength, null);   }   /**    * Read  page with extra information in the current bank with no    * CRC checking (device or data). The resulting data from this API    * may or may not be what is on the 1-Wire device.  It is recommends    * that the data contain some kind of checking (CRC) like in the    * readPagePacket() method or have the 1-Wire device provide the    * CRC as in readPageCRC().  readPageCRC() however is not    * supported on all memory types, see 'hasPageAutoCRC()'.    * If neither is an option then this method could be called more    * then once to at least verify that the same thing is read consistantly.    * See the method 'hasExtraInfo()' for a description of the optional    * extra information some devices have.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPage() continious where the last one    *                       led off and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to place read data into    * @param  offset        offset into readBuf to place data    * @param  extraInfo     byte array to put extra info read into    *    * @throws OneWireIOException    * @throws OneWireException    */   public void readPage (int page, boolean readContinue, byte[] readBuf,                         int offset, byte[] extraInfo)      throws OneWireIOException, OneWireException   {      // check if read exceeds memory      if (page != 0)         throw new OneWireException("Page read exceeds memory bank end");      // attempt to put device at speed      checkSpeed();      // read the scratchpad, discard extra information      readScratchpad(readBuf, offset, pageLength, extraInfo);   }   /**    * Read a Universal Data Packet.    *    * The Universal Data Packet always starts on page boundaries but    * can end anywhere in the page.  The structure specifies the length of    * data bytes not including the length byte and the CRC16 bytes.    * There is one length byte. The CRC16 is first initialized to    * the page number.  This provides a check to verify the page that    * was intended is being read.  The CRC16 is then calculated over    * the length and data bytes.  The CRC16 is then inverted and stored    * low byte first followed by the high byte.  This is structure is    * used by this method to verify the data but is not returned, only    * the data payload is returned.    *    * @param  page          page number to read packet from    * @param  readContinue  if 'true' then device read is continued without    *                       re-selecting.  This can only be used if the new    *                       readPagePacket() continious where the last one    *                       stopped and it is inside a    *                       'beginExclusive/endExclusive' block.    * @param  readBuf       byte array to put data read. Must have at least    *                       'getMaxPacketDataLength()' elements.    * @param  offset        offset into readBuf to place data    *    * @return  number of data bytes read from the device and written to    *          readBuf at the offset.    *    * @throws OneWireIOException    * @throws OneWireException    */   public int readPagePacket (int page, boolean readContinue, byte[] readBuf,                              int offset)      throws OneWireIOException, OneWireException   {      byte[] raw_buf = new byte [pageLength];      // attempt to put device at speed      checkSpeed();      // read the scratchpad, discard extra information      readScratchpad(raw_buf, 0, pageLength, null);      // check if length is realistic      if (raw_buf [0] > maxPacketDataLength)      {         forceVerify();         throw new OneWireIOException("Invalid length in packet");      }

⌨️ 快捷键说明

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