📄 onewirecontainer41.java
字号:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// ***************************************************************************** /** * Returns the length in bytes of the Read-Only password. * * @return the length in bytes of the Read-Only password. */ public int getReadOnlyPasswordLength() throws OneWireException { return PASSWORD_LENGTH; } /** * Returns the length in bytes of the Read/Write password. * * @return the length in bytes of the Read/Write password. */ public int getReadWritePasswordLength() throws OneWireException { return PASSWORD_LENGTH; } /** * Returns the length in bytes of the Write-Only password. * * @return the length in bytes of the Write-Only password. */ public int getWriteOnlyPasswordLength() throws OneWireException { throw new OneWireException("The DS1922 does not have a write only password."); } /** * Returns the absolute address of the memory location where * the Read-Only password is written. * * @return the absolute address of the memory location where * the Read-Only password is written. */ public int getReadOnlyPasswordAddress() throws OneWireException { return READ_ACCESS_PASSWORD; } /** * Returns the absolute address of the memory location where * the Read/Write password is written. * * @return the absolute address of the memory location where * the Read/Write password is written. */ public int getReadWritePasswordAddress() throws OneWireException { return READ_WRITE_ACCESS_PASSWORD; } /** * Returns the absolute address of the memory location where * the Write-Only password is written. * * @return the absolute address of the memory location where * the Write-Only password is written. */ public int getWriteOnlyPasswordAddress() throws OneWireException { throw new OneWireException("The DS1922 does not have a write password."); } /** * Returns true if this device has a Read-Only password. * If false, all other functions dealing with the Read-Only * password will throw an exception if called. * * @return <code>true</code> always, since DS1922 has Read-Only password. */ public boolean hasReadOnlyPassword() { return true; } /** * Returns true if this device has a Read/Write password. * If false, all other functions dealing with the Read/Write * password will throw an exception if called. * * @return <code>true</code> always, since DS1922 has Read/Write password. */ public boolean hasReadWritePassword() { return true; } /** * Returns true if this device has a Write-Only password. * If false, all other functions dealing with the Write-Only * password will throw an exception if called. * * @return <code>false</code> always, since DS1922 has no Write-Only password. */ public boolean hasWriteOnlyPassword() { return false; } /** * Returns true if the device's Read-Only password has been enabled. * * @return <code>true</code> if the device's Read-Only password has been enabled. */ public boolean getDeviceReadOnlyPasswordEnable() throws OneWireException { return readOnlyPasswordEnabled; } /** * Returns true if the device's Read/Write password has been enabled. * * @return <code>true</code> if the device's Read/Write password has been enabled. */ public boolean getDeviceReadWritePasswordEnable() throws OneWireException { return readWritePasswordEnabled; } /** * Returns true if the device's Write-Only password has been enabled. * * @return <code>true</code> if the device's Write-Only password has been enabled. */ public boolean getDeviceWriteOnlyPasswordEnable() throws OneWireException { throw new OneWireException("The DS1922 does not have a Write Only Password."); } /** * Returns true if this device has the capability to enable one type of password * while leaving another type disabled. i.e. if the device has Read-Only password * protection and Write-Only password protection, this method indicates whether or * not you can enable Read-Only protection while leaving the Write-Only protection * disabled. * * @return <code>true</code> if the device has the capability to enable one type * of password while leaving another type disabled. */ public boolean hasSinglePasswordEnable() { return false; } /** * <p>Enables/Disables passwords for this Device. This method allows you to * individually enable the different types of passwords for a particular * device. If <code>hasSinglePasswordEnable()</code> returns true, * you can selectively enable particular types of passwords. Otherwise, * this method will throw an exception if all supported types are not * enabled.</p> * * <p>For this to be successful, either write-protect passwords must be disabled, * or the write-protect password(s) for this container must be set and must match * the value of the write-protect password(s) in the device's register.</p> * * <P><B> * WARNING: Enabling passwords requires that both the read password and the * read/write password be re-written to the part. Before calling this method, * you should set the container read password and read/write password values. * This will ensure that the correct value is written into the part. * </B></P> * * @param enableReadOnly if <code>true</code> Read-Only passwords will be enabled. * @param enableReadWrite if <code>true</code> Read/Write passwords will be enabled. * @param enableWriteOnly if <code>true</code> Write-Only passwords will be enabled. */ public void setDevicePasswordEnable(boolean enableReadOnly, boolean enableReadWrite, boolean enableWriteOnly) throws OneWireException, OneWireIOException { if(enableWriteOnly) throw new OneWireException( "The DS1922 does not have a write only password."); if(enableReadOnly != enableReadWrite) throw new OneWireException( "Both read-only and read/write will be set with enable."); if(!isContainerReadOnlyPasswordSet()) throw new OneWireException("Container Read Password is not set"); if(!isContainerReadWritePasswordSet()) throw new OneWireException("Container Read/Write Password is not set"); // must write both passwords for this to work byte[] bothPasswordsEnable = new byte[17]; bothPasswordsEnable[0] = (enableReadOnly?ENABLE_BYTE:DISABLE_BYTE); getContainerReadOnlyPassword(bothPasswordsEnable, 1); getContainerReadWritePassword(bothPasswordsEnable, 9); register.write(PASSWORD_CONTROL_REGISTER&0x3F, bothPasswordsEnable, 0, 17); if(enableReadOnly) { readOnlyPasswordEnabled = true; readWritePasswordEnabled = true; } else { readOnlyPasswordEnabled = false; readWritePasswordEnabled = false; } } /** * <p>Enables/Disables passwords for this device. If the part has more than one * type of password (Read-Only, Write-Only, or Read/Write), all passwords * will be enabled. This function is equivalent to the following: * <code> owc41.setDevicePasswordEnable( * owc41.hasReadOnlyPassword(), * owc41.hasReadWritePassword(), * owc41.hasWriteOnlyPassword() ); </code></p> * * <p>For this to be successful, either write-protect passwords must be disabled, * or the write-protect password(s) for this container must be set and must match * the value of the write-protect password(s) in the device's register.</P> * * <P><B> * WARNING: Enabling passwords requires that both the read password and the * read/write password be re-written to the part. Before calling this method, * you should set the container read password and read/write password values. * This will ensure that the correct value is written into the part. * </B></P> * * @param enableAll if <code>true</code>, all passwords are enabled. Otherwise, * all passwords are disabled. */ public void setDevicePasswordEnableAll(boolean enableAll) throws OneWireException, OneWireIOException { setDevicePasswordEnable(enableAll, enableAll, false); } /** * <p>Writes the given password to the device's Read-Only password register. Note * that this function does not enable the password, just writes the value to * the appropriate memory location.</p> * * <p>For this to be successful, either write-protect passwords must be disabled, * or the write-protect password(s) for this container must be set and must match * the value of the write-protect password(s) in the device's register.</p> * * <P><B> * WARNING: Setting the read password requires that both the read password * and the read/write password be written to the part. Before calling this * method, you should set the container read/write password value. * This will ensure that the correct value is written into the part. * </B></P> * * @param password the new password to be written to the device's Read-Only * password register. Length must be * <code>(offset + getReadOnlyPasswordLength)</code> * @param offset the starting point for copying from the given password array */ public void setDeviceReadOnlyPassword(byte[] password, int offset) throws OneWireException, OneWireIOException { if (getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MISSION_IN_PROGRESS)) throw new OneWireIOException( "OneWireContainer41-Cannot change password while mission is in progress."); if(!isContainerReadWritePasswordSet()) throw new OneWireException("Container Read/Write Password is not set"); // must write both passwords for this to work byte[] bothPasswords = new byte[16]; System.arraycopy(password, offset, bothPasswords, 0, 8); getContainerReadWritePassword(bothPasswords, 8); register.write(READ_ACCESS_PASSWORD&0x3F, bothPasswords, 0, 16); setContainerReadOnlyPassword(password, offset); } /** * <p>Writes the given password to the device's Read/Write password register. Note * that this function does not enable the password, just writes the value to * the appropriate memory location.</p> * * <p>For this to be successful, either write-protect passwords must be disabled, * or the write-protect password(s) for this container must be set and must match * the value of the write-protect password(s) in the device's register.</p> * * @param password the new password to be written to the device's Read-Write * password register. Length must be * <code>(offset + getReadWritePasswordLength)</code> * @param offset the starting point for copying from the given password array */ public void setDeviceReadWritePassword(byte[] password, int offset) throws OneWireException, OneWireIOException { if (getFlag(GENERAL_STATUS_REGISTER, GSR_BIT_MISSION_IN_PROGRESS)) throw new OneWireIOException( "OneWireContainer41-Cannot change password while mission is in progress."); register.write(READ_WRITE_ACCESS_PASSWORD&0x3F, password, offset, 8); setContainerReadWritePassword(password,offset); } /** * <p>Writes the given password to the device's Write-Only password register. Note * that this function does not enable the password, just writes the value to * the appropriate memory location.</p> * * <p>For this to be successful, either write-protect passwords must be disabled, * or the write-protect password(s) for this container must be set and must match * the value of the write-protect password(s) in the devi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -