com.dalsemi.onewire.container
Class MemoryBankNVCRCPW

java.lang.Object
  |
  +--com.dalsemi.onewire.container.MemoryBankNV
        |
        +--com.dalsemi.onewire.container.MemoryBankNVCRC
              |
              +--com.dalsemi.onewire.container.MemoryBankNVCRCPW
All Implemented Interfaces:
MemoryBank, PagedMemoryBank

public class MemoryBankNVCRCPW
extends com.dalsemi.onewire.container.MemoryBankNVCRC

Memory bank class for the NVRAM with built-in CRC generation and Password protected memory read/write iButtons and 1-Wire Devices. An example of such a devices is the DS1922 Thermochron with 8k or password protected log memory.

Version:
1.00, 11 Feb 2002
Author:
SH

Field Summary
 boolean enablePower
          Enable Provided Power for some Password checking.
static byte READ_MEMORY_COMMAND
          Read Memory Command
static byte READ_MEMORY_CRC_PW_COMMAND
          Read Memory (with CRC and Password) Command
static byte READ_PAGE_WITH_CRC
          Write Scratchpad Command
 
Constructor Summary
MemoryBankNVCRCPW(PasswordContainer ibutton, MemoryBankScratchCRCPW scratch)
          Memory bank contstuctor.
 
Method Summary
 String getBankDescription()
          Query to see get a string description of the current memory bank.
 String getExtraInfoDescription()
          Query to get a string description of what is contained in the Extra Informationed return when reading pages in the current memory bank.
 int getExtraInfoLength()
          Query to get the length in bytes of extra information that is read when read a page in the current memory bank.
 int getMaxPacketDataLength()
          Query to get Maximum data page length in bytes for a packet read or written in the current memory bank.
 int getNumberPages()
          Query to get the number of pages in current memory bank.
 int getPageLength()
          Query to get page length in bytes in current memory bank.
 int getSize()
          Query to get the memory bank size in bytes.
 int getStartPhysicalAddress()
          Query to get the starting physical address of this bank.
 boolean hasExtraInfo()
          Checks to see if this memory bank's pages deliver extra information outside of the normal data space, when read.
 boolean hasPageAutoCRC()
          Query to see if current memory bank pages can be read with the contents being verified by a device generated CRC.
 boolean haveExtraInfo()
          Deprecated. As of 1-Wire API 0.01, replaced by MemoryBankNV.hasExtraInfo()
 boolean isGeneralPurposeMemory()
          Query to see if the current memory bank is general purpose user memory.
 boolean isNonVolatile()
          Query to see if current memory bank non-volatile.
 boolean isReadOnly()
          Query to see if current memory bank is read only.
 boolean isReadWrite()
          Query to see if current memory bank is read/write.
 boolean isWriteOnce()
          Query to see if current memory bank is write write once such as with EPROM technology.
 boolean needsPowerDelivery()
          Query to see if current memory bank pages need the adapter to have a 'PowerDelivery' feature in order to write to the memory.
 boolean needsProgramPulse()
          Query to see if current memory bank pages need the adapter to have a 'ProgramPulse' in order to write to the memory.
 void read(int startAddr, boolean readContinue, byte[] readBuf, int offset, int len)
          Read memory in the current bank with no CRC checking (device or data).
 void readPage(int page, boolean readContinue, byte[] readBuf, int offset)
          Read page in the current bank with no CRC checking (device or data).
 void readPage(int page, boolean readContinue, byte[] readBuf, int offset, byte[] extraInfo)
          Read page with extra information in the current bank with no CRC checking (device or data).
 void readPageCRC(int page, boolean readContinue, byte[] readBuf, int offset)
          Read a complete memory page with CRC verification provided by the device.
 void readPageCRC(int page, boolean readContinue, byte[] readBuf, int offset, byte[] extraInfo)
          Read a complete memory page with CRC verification provided by the device with extra information.
 int readPagePacket(int page, boolean readContinue, byte[] readBuf, int offset)
          Read a Universal Data Packet.
 int readPagePacket(int page, boolean readContinue, byte[] readBuf, int offset, byte[] extraInfo)
          Read a Universal Data Packet and extra information.
 void setWriteVerification(boolean doReadVerf)
          Set the write verification for the 'write()' method.
 void write(int startAddr, byte[] writeBuf, int offset, int len)
          Write memory in the current bank.
 void writePagePacket(int page, byte[] writeBuf, int offset, int len)
          Write a Universal Data Packet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

READ_MEMORY_CRC_PW_COMMAND

public static final byte READ_MEMORY_CRC_PW_COMMAND
Read Memory (with CRC and Password) Command

enablePower

public boolean enablePower
Enable Provided Power for some Password checking.

READ_PAGE_WITH_CRC

public static final byte READ_PAGE_WITH_CRC
Write Scratchpad Command

READ_MEMORY_COMMAND

public static final byte READ_MEMORY_COMMAND
Read Memory Command
Constructor Detail

MemoryBankNVCRCPW

public MemoryBankNVCRCPW(PasswordContainer ibutton,
                         MemoryBankScratchCRCPW scratch)
Memory bank contstuctor. Requires reference to the OneWireContainer this memory bank resides on.
Method Detail

readPageCRC

public void readPageCRC(int page,
                        boolean readContinue,
                        byte[] readBuf,
                        int offset,
                        byte[] extraInfo)
                 throws OneWireIOException,
                        OneWireException
Read a complete memory page with CRC verification provided by the device with extra information. Not supported by all devices. See the method 'hasPageAutoCRC()'. See the method 'hasExtraInfo()' for a description of the optional extra information.
Overrides:
readPageCRC in class com.dalsemi.onewire.container.MemoryBankNVCRC
Parameters:
page - page number to read
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.
readBuf - byte array to put data read. Must have at least 'getMaxPacketDataLength()' elements.
offset - offset into readBuf to place data
extraInfo - byte array to put extra info read into
Throws:
OneWireIOException -  
OneWireException -  

read

public void read(int startAddr,
                 boolean readContinue,
                 byte[] readBuf,
                 int offset,
                 int len)
          throws OneWireIOException,
                 OneWireException
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.
Overrides:
read in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
startAddr - starting physical address
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.
readBuf - byte array to place read data into
offset - offset into readBuf to place data
len - length in bytes to read
Throws:
OneWireIOException -  
OneWireException -  

write

public void write(int startAddr,
                  byte[] writeBuf,
                  int offset,
                  int len)
           throws OneWireIOException,
                  OneWireException
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.
Overrides:
write in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
startAddr - starting address
writeBuf - byte array containing data to write
offset - offset into writeBuf to get data
len - length in bytes to write
Throws:
OneWireIOException -  
OneWireException -  

readPage

public void readPage(int page,
                     boolean readContinue,
                     byte[] readBuf,
                     int offset)
              throws OneWireIOException,
                     OneWireException
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.
Overrides:
readPage in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
page - page number to read packet from
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.
readBuf - byte array to place read data into
offset - offset into readBuf to place data
Throws:
OneWireIOException -  
OneWireException -  

readPage

public void readPage(int page,
                     boolean readContinue,
                     byte[] readBuf,
                     int offset,
                     byte[] extraInfo)
              throws OneWireIOException,
                     OneWireException
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.
Overrides:
readPage in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
page - page number to read packet from
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.
readBuf - byte array to place read data into
offset - offset into readBuf to place data
extraInfo - byte array to put extra info read into
Throws:
OneWireIOException -  
OneWireException -  

readPagePacket

public int readPagePacket(int page,
                          boolean readContinue,
                          byte[] readBuf,
                          int offset,
                          byte[] extraInfo)
                   throws OneWireIOException,
                          OneWireException
Read a Universal Data Packet and extra information. See the method 'readPagePacket()' for a description of the packet structure. See the method 'hasExtraInfo()' for a description of the optional extra information some devices have.
Overrides:
readPagePacket in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
page - page number to read packet from
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.
readBuf - byte array to put data read. Must have at least 'getMaxPacketDataLength()' elements.
offset - offset into readBuf to place data
extraInfo - byte array to put extra info read into
Returns:
number of data bytes written to readBuf at the offset.
Throws:
OneWireIOException -  
OneWireException -  

readPageCRC

public void readPageCRC(int page,
                        boolean readContinue,
                        byte[] readBuf,
                        int offset)
                 throws OneWireIOException,
                        OneWireException
Read a complete memory page with CRC verification provided by the device. Not supported by all devices. See the method 'hasPageAutoCRC()'.
Overrides:
readPageCRC in class com.dalsemi.onewire.container.MemoryBankNV
Parameters:
page - page number to read
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.
readBuf - byte array to put data read. Must have at least 'getMaxPacketDataLength()' elements.
offset - offset into readBuf to place data
Throws:
OneWireIOException -  
OneWireException -  

getBankDescription

public String getBankDescription()
Query to see get a string description of the current memory bank.
Specified by:
getBankDescription in interface MemoryBank
Returns:
String containing the memory bank description

isGeneralPurposeMemory

public boolean isGeneralPurposeMemory()
Query to see if the current memory bank is general purpose user memory. If it is NOT then it is Memory-Mapped and writing values to this memory will affect the behavior of the 1-Wire device.
Specified by:
isGeneralPurposeMemory in interface MemoryBank
Returns:
'true' if current memory bank is general purpose

isReadWrite

public boolean isReadWrite()
Query to see if current memory bank is read/write.
Specified by:
isReadWrite in interface MemoryBank
Returns:
'true' if current memory bank is read/write

isWriteOnce

public boolean isWriteOnce()
Query to see if current memory bank is write write once such as with EPROM technology.
Specified by:
isWriteOnce in interface MemoryBank
Returns:
'true' if current memory bank can only be written once

isReadOnly

public boolean isReadOnly()
Query to see if current memory bank is read only.
Specified by:
isReadOnly in interface MemoryBank
Returns:
'true' if current memory bank can only be read

isNonVolatile

public boolean isNonVolatile()
Query to see if current memory bank non-volatile. Memory is non-volatile if it retains its contents even when removed from the 1-Wire network.
Specified by:
isNonVolatile in interface MemoryBank
Returns:
'true' if current memory bank non volatile.

needsProgramPulse

public boolean needsProgramPulse()
Query to see if current memory bank pages need the adapter to have a 'ProgramPulse' in order to write to the memory.
Specified by:
needsProgramPulse in interface MemoryBank
Returns:
'true' if writing to the current memory bank pages requires a 'ProgramPulse'.

needsPowerDelivery

public boolean needsPowerDelivery()
Query to see if current memory bank pages need the adapter to have a 'PowerDelivery' feature in order to write to the memory.
Specified by:
needsPowerDelivery in interface MemoryBank
Returns:
'true' if writing to the current memory bank pages requires 'PowerDelivery'.

getStartPhysicalAddress

public int getStartPhysicalAddress()
Query to get the starting physical address of this bank. Physical banks are sometimes sub-divided into logical banks due to changes in attributes.
Specified by:
getStartPhysicalAddress in interface MemoryBank
Returns:
physical starting address of this logical bank.

getSize

public int getSize()
Query to get the memory bank size in bytes.
Specified by:
getSize in interface MemoryBank
Returns:
memory bank size in bytes.

setWriteVerification

public void setWriteVerification(boolean doReadVerf)
Set the write verification for the 'write()' method.
Specified by:
setWriteVerification in interface MemoryBank
Parameters:
doReadVerf - true (default) verify write in 'write' false, don't verify write (used on Write-Once bit manipulation)

getNumberPages

public int getNumberPages()
Query to get the number of pages in current memory bank.
Specified by:
getNumberPages in interface PagedMemoryBank
Returns:
number of pages in current memory bank

getPageLength

public int getPageLength()
Query to get page length in bytes in current memory bank.
Specified by:
getPageLength in interface PagedMemoryBank
Returns:
page length in bytes in current memory bank

getMaxPacketDataLength

public int getMaxPacketDataLength()
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.
Specified by:
getMaxPacketDataLength in interface PagedMemoryBank
Returns:
max packet page length in bytes in current memory bank

hasPageAutoCRC

public boolean hasPageAutoCRC()
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.
Specified by:
hasPageAutoCRC in interface PagedMemoryBank
Returns:
'true' if current memory bank can be read with self generated CRC.

haveExtraInfo

public boolean haveExtraInfo()
Deprecated. As of 1-Wire API 0.01, replaced by MemoryBankNV.hasExtraInfo()

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.
Specified by:
haveExtraInfo in interface PagedMemoryBank
Returns:
'true' if reading the current memory bank pages provides extra information.

hasExtraInfo

public boolean hasExtraInfo()
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: readPage, readPageCRC, and readPagePacket.
Specified by:
hasExtraInfo in interface PagedMemoryBank
Returns:
true if reading the this memory bank's pages provides extra information
Since:
1-Wire API 0.01
See Also:
readPage(extra), readPageCRC(extra), readPagePacket(extra)

getExtraInfoLength

public int getExtraInfoLength()
Query to get the length in bytes of extra information that is read when read a page in the current memory bank. See 'hasExtraInfo()'.
Specified by:
getExtraInfoLength in interface PagedMemoryBank
Returns:
number of bytes in Extra Information read when reading pages in the current memory bank.

getExtraInfoDescription

public String getExtraInfoDescription()
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()'.
Specified by:
getExtraInfoDescription in interface PagedMemoryBank
Returns:
string describing extra information.

readPagePacket

public int readPagePacket(int page,
                          boolean readContinue,
                          byte[] readBuf,
                          int offset)
                   throws OneWireIOException,
                          OneWireException
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.
Specified by:
readPagePacket in interface PagedMemoryBank
Parameters:
page - page number to read packet from
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.
readBuf - byte array to put data read. Must have at least 'getMaxPacketDataLength()' elements.
offset - offset into readBuf to place data
Returns:
number of data bytes read from the device and written to readBuf at the offset.
Throws:
OneWireIOException -  
OneWireException -  

writePagePacket

public void writePagePacket(int page,
                            byte[] writeBuf,
                            int offset,
                            int len)
                     throws OneWireIOException,
                            OneWireException
Write a Universal Data Packet. See the method 'readPagePacket()' for a description of the packet structure.
Specified by:
writePagePacket in interface PagedMemoryBank
Parameters:
page - page number to write packet to
writeBuf - data byte array to write
offset - offset into writeBuf where data to write is
len - number of bytes to write
Throws:
OneWireIOException -  
OneWireException -  


Copyright © 1999-2003 Dallas Semiconductor. All Rights Reserved.