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

📄 memorybankscratchshaee.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            }         }         // optionally extract the extra info         if (extraInfo != null)            System.arraycopy(read_scratchpad_buffer, 1,               extraInfo, 0, extraInfoLength);         // extract the page data         System.arraycopy(read_scratchpad_buffer, extraInfoLength + 1,            readBuf, offset, len);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)         Debug.debug("-----------------------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * Copy the scratchpad page to memory.    *    * @param  addr the address to copy the data to    * @param  len length byte is ignored, must always be 8.    *    * @throws OneWireIOException    * @throws OneWireException    */   public void copyScratchpad (int addr, int len)      throws OneWireIOException, OneWireException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("-----------------------------------------------------------");         Debug.debug("MemoryBankScratchSHAEE.copyScratchpad(int, int) called");         Debug.debug("  romID=" + owc33.getAddressAsString());         Debug.debug("  addr=0x" + Convert.toHexString((byte)addr));         Debug.debug("  len=" + len);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      synchronized(scratchpad_buffer)      {         readScratchpad(scratchpad_buffer, 0, 8, null);         copyScratchpad(addr, scratchpad_buffer, 0);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)         Debug.debug("-----------------------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * Copy the scratchpad page to memory.    *    * @param  addr the address to copy to    * @param  scratchpad the scratchpad contents that will be copied    * @param  offset the offset into scratchpad byte[] where scratchpad data begins    *    * @throws OneWireIOException    * @throws OneWireException    */   public void copyScratchpad (int addr, byte[] scratchpad, int offset)      throws OneWireIOException, OneWireException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("-----------------------------------------------------------");         Debug.debug("MemoryBankScratchSHAEE.copyScratchpad(int, byte[], int) called");         Debug.debug("  romID="+owc33.getAddressAsString());         Debug.debug("  addr=0x" + Convert.toHexString((byte)addr));         Debug.debug("  scratchpad", scratchpad, offset, 8);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      synchronized(page_data_buffer)      {         readMemory(addr&0xE0, false, page_data_buffer, 0, 32);         // readMemory clears the TA address set by write scratchpad, let's re-write it         writeScratchpad(addr, scratchpad, offset, 8);         copyScratchpad(addr, scratchpad, offset, page_data_buffer, 0);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)         Debug.debug("-----------------------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * Copy the scratchpad page to memory.    *    * @param  addr the address to copy to    * @param  scratchpad the scratchpad contents that will be copied    * @param  scratchpadOffset the offset into scratchpad byte[] where scratchpad data begins    * @param  pageData the data on the page of memory to be written to    * @param  pageDataOffset the offset into pageData byte[] where pageData begins    *    * @throws OneWireIOException    * @throws OneWireException    */   public void copyScratchpad (int addr,                               byte[] scratchpad, int scratchpadOffset,                               byte[] pageData, int pageDataOffset)      throws OneWireIOException, OneWireException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("-----------------------------------------------------------");         Debug.debug("MemoryBankScratchSHAEE.copyScratchpad(int, byte[], int, byte[], int) called");         Debug.debug("  romID=" + owc33.getAddressAsString());         Debug.debug("  addr=0x" + Convert.toHexString((byte)addr));         Debug.debug("  scratchpad", scratchpad, scratchpadOffset, 8);         Debug.debug("  pageData", pageData, pageDataOffset, 32);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      synchronized(MT_buffer)      {         // copy the secret into message block         owc33.getContainerSecret(MT_buffer, 0);         System.arraycopy(MT_buffer,4,MT_buffer,48,4);         // copy the current page contents into the buffer         System.arraycopy(pageData,pageDataOffset,MT_buffer,4,28);         System.arraycopy(scratchpad,scratchpadOffset,MT_buffer,32,8);         MT_buffer[40] = ( byte ) ((addr & 0x0E0) >>> 5);         System.arraycopy(owc33.getAddress(),0,MT_buffer,41,7);         System.arraycopy(ffBlock,0,MT_buffer,52,3);         // put in the padding         MT_buffer[55] = ( byte ) 0x80;         System.arraycopy(zeroBlock,0,MT_buffer,56,6);         MT_buffer[62] = ( byte ) 0x01;         MT_buffer[63] = ( byte ) 0xB8;         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//         if(DEBUG)         {            Debug.debug("MT_buffer", MT_buffer);         }         //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//         synchronized(MAC_buffer)         {            // do the SHA calculation to get MAC            SHA.ComputeSHA(MT_buffer, MAC_buffer, 0);            copyScratchpadWithMAC(addr, MAC_buffer, 0);          }      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)         Debug.debug("-----------------------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * Copy all 8 bytes of the Sratch Pad to a certain address in memory    * using the provided authorization MAC    *    * @param addr the address to copy the data to    * @param authMAC byte[] containing write authorization MAC    * @param authOffset offset into authMAC where authorization MAC begins    *    * @throws OneWireIOException    * @throws OneWireException    */   public void copyScratchpadWithMAC(int addr, byte[] authMAC, int authOffset)      throws OneWireIOException, OneWireException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("-----------------------------------------------------------");         Debug.debug("MemoryBankScratchSHAEE.copyScratchpadWithMAC(int, byte[], int) called");         Debug.debug("  romID=" + owc33.getAddressAsString());         Debug.debug("  addr=0x" + Convert.toHexString((byte)addr));         Debug.debug("  authMAC", authMAC, authOffset, 20);      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      synchronized(copy_scratchpad_buffer)      {         byte[] send_block = copy_scratchpad_buffer;         checkSpeed();         // access the device         if (ib.adapter.select(ib.getAddress()))         {            // ending address with data status            send_block[3] = 0x5F;//ES - always 0x5F            // address 2            send_block[2] = (byte)((addr>>8) & 0x0FF);//TA2            // address 1            send_block[1] = (byte)((addr) & 0x0FF);//TA1;            // Copy command            send_block[0] = COPY_SCRATCHPAD_COMMAND;            // send copy scratchpad command            ib.adapter.dataBlock(send_block, 0, 4);            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//            if(DEBUG)               Debug.debug("  send_block", send_block, 0, 4);            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//            // pause before sending appropriate MAC            try            {               Thread.sleep(2);            }            catch (InterruptedException e){}            // sending MAC            ib.adapter.dataBlock(authMAC, authOffset, 19);            // provide strong pull-up for copy            ib.adapter.setPowerDuration(DSPortAdapter.DELIVERY_INFINITE);            ib.adapter.startPowerDelivery(DSPortAdapter.CONDITION_AFTER_BYTE);            ib.adapter.putByte(authMAC[authOffset + 19]);            // pause before checking result            try            {               Thread.sleep(12);            }            catch (InterruptedException e){}            ib.adapter.setPowerNormal();            // get result            byte test = ( byte ) ib.adapter.getByte();            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//            if(DEBUG)               Debug.debug("  result=0x" + Convert.toHexString((byte)test));            //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//            if((test != ( byte ) 0xAA) && (test != ( byte ) 0x55))            {               if(test == ( byte ) 0xFF)                  throw new OneWireException("That area of memory is write-protected.");               else if(test == ( byte )0x00)                  throw new OneWireIOException("Error due to not matching MAC.");            }         }         else            throw new OneWireIOException("Device select failed.");      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)         Debug.debug("-----------------------------------------------------------");      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * Write to the scratchpad page of memory a NVRAM device.    *    * @param  addr physical address to copy data to    * @param  writeBuf byte array containing data to write    * @param  offset offset into readBuf to place data    * @param  len length in bytes to write    *    * @throws OneWireIOException    * @throws OneWireException    */   public void writeScratchpad (int addr, byte[] writeBuf, int offset,                                int len)      throws OneWireIOException, OneWireException   {      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("-----------------------------------------------------------");         Debug.debug("MemoryBankScratchSHAEE.writeScratchpad(int, byte[], int, int) called");         Debug.debug("  romID="+owc33.getAddressAsString());         Debug.debug("  addr=0x" + Convert.toHexString((byte)addr));         Debug.debug("  writeBuf" , writeBuf, offset, len);         Debug.stackTrace();      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      checkSpeed();      super.writeScratchpad(addr, writeBuf, offset, len);      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//      if(DEBUG)      {         Debug.debug("MemoryBankScratchSHAEE.writeScratchpad(int, byte[], int, int) finished");         Debug.debug("-----------------------------------------------------------");      }      //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//   }   /**    * 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  addr          the address to write to

⌨️ 快捷键说明

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