📄 dumbadapter.java
字号:
//-------- /** * This method does nothing in <code>DumbAdapter</code>. * * @param blocking <code>true</code> if want to block waiting * for an excluse access to the adapter * @return <code>true</code> */ public boolean beginExclusive (boolean blocking) { //DEBUG!!! RIGHT NOW THIS IS NOT IMPLEMENTED!!! return true; } /** * This method does nothing in <code>DumbAdapter</code>. * */ public void endExclusive () { //DEBUG!!! RIGHT NOW THIS IS NOT IMPLEMENTED!!! } //-------- //-------- Primitive 1-Wire Network data methods //-------- /** * Sends a bit to the 1-Wire Network. * This method does nothing in <code>DumbAdapter</code>. * * @param bitValue the bit value to send to the 1-Wire Network. */ public void putBit (boolean bitValue) { //this will not be implemented } /** * Gets a bit from the 1-Wire Network. * This method does nothing in <code>DumbAdapter</code>. * * @return <code>true</code> */ public boolean getBit () { //this will not be implemented return true; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param byteValue the byte value to send to the 1-Wire Network. */ public void putByte (int byteValue) { //this will not be implemented } /** * This method does nothing in <code>DumbAdapter</code>. * * @return the value 0x0ff */ public int getByte () { //this will not be implemented return 0x0ff; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param len length of data bytes to receive * * @return a new byte array of length <code>len</code> */ public byte[] getBlock (int len) { //this will not be implemented return new byte[len]; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param arr array in which to write the received bytes * @param len length of data bytes to receive */ public void getBlock (byte[] arr, int len) { //this will not be implemented } /** * This method does nothing in <code>DumbAdapter</code>. * * @param arr array in which to write the received bytes * @param off offset into the array to start * @param len length of data bytes to receive */ public void getBlock (byte[] arr, int off, int len) { //this will not be implemented } /** * This method does nothing in <code>DumbAdapter</code>. * * @param dataBlock array of data to transfer to and from the 1-Wire Network. * @param off offset into the array of data to start * @param len length of data to send / receive starting at 'off' */ public void dataBlock (byte dataBlock [], int off, int len) { //this will not be implemented } /** * Sends a Reset to the 1-Wire Network. * * @return the result of the reset. Potential results are: * <ul> * <li> 0 (RESET_NOPRESENCE) no devices present on the 1-Wire Network. * <li> 1 (RESET_PRESENCE) normal presence pulse detected on the 1-Wire * Network indicating there is a device present. * <li> 2 (RESET_ALARM) alarming presence pulse detected on the 1-Wire * Network indicating there is a device present and it is in the * alarm condition. This is only provided by the DS1994/DS2404 * devices. * <li> 3 (RESET_SHORT) inticates 1-Wire appears shorted. This can be * transient conditions in a 1-Wire Network. Not all adapter types * can detect this condition. * </ul> * Note that in <code>DumbAdapter</code>, the only possible results are 0 and 1. */ public int reset () { //this will not be implemented if (containers.size() > 0) return 1; return 0; } //-------- //-------- 1-Wire Network power methods //-------- /** * This method does nothing in <code>DumbAdapter</code>. * * @param timeFactor * <ul> * <li> 0 (DELIVERY_HALF_SECOND) provide power for 1/2 second. * <li> 1 (DELIVERY_ONE_SECOND) provide power for 1 second. * <li> 2 (DELIVERY_TWO_SECONDS) provide power for 2 seconds. * <li> 3 (DELIVERY_FOUR_SECONDS) provide power for 4 seconds. * <li> 4 (DELIVERY_SMART_DONE) provide power until the * the device is no longer drawing significant power. * <li> 5 (DELIVERY_INFINITE) provide power until the * setPowerNormal() method is called. * </ul> */ public void setPowerDuration (int timeFactor) { } /** * This method does nothing in <code>DumbAdapter</code>. * * @param changeCondition * <ul> * <li> 0 (CONDITION_NOW) operation should occur immediately. * <li> 1 (CONDITION_AFTER_BIT) operation should be pending * execution immediately after the next bit is sent. * <li> 2 (CONDITION_AFTER_BYTE) operation should be pending * execution immediately after next byte is sent. * </ul> * * @return <code>true</code> */ public boolean startPowerDelivery (int changeCondition) { return true; } /** * This method does nothing in <code>DumbAdapter</code>. * * @param timeFactor * <ul> * <li> 7 (DELIVERY_EPROM) provide program pulse for 480 microseconds * <li> 5 (DELIVERY_INFINITE) provide power until the * setPowerNormal() method is called. * </ul> */ public void setProgramPulseDuration (int timeFactor) { } /** * This method does nothing in <code>DumbAdapter</code>. * * @param changeCondition * <ul> * <li> 0 (CONDITION_NOW) operation should occur immediately. * <li> 1 (CONDITION_AFTER_BIT) operation should be pending * execution immediately after the next bit is sent. * <li> 2 (CONDITION_AFTER_BYTE) operation should be pending * execution immediately after next byte is sent. * </ul> * * @return <code>true</code> */ public boolean startProgramPulse (int changeCondition) { return true; } /** * This method does nothing in <code>DumbAdapter</code>. * */ public void startBreak () { } /** * This method does nothing in <code>DumbAdapter</code>. * */ public void setPowerNormal () { return; } //-------- //-------- 1-Wire Network speed methods //-------- /** * This method does nothing in <code>DumbAdapter</code>. * * @param speed * <ul> * <li> 0 (SPEED_REGULAR) set to normal communciation speed * <li> 1 (SPEED_FLEX) set to flexible communciation speed used * for long lines * <li> 2 (SPEED_OVERDRIVE) set to normal communciation speed to * overdrive * <li> 3 (SPEED_HYPERDRIVE) set to normal communciation speed to * hyperdrive * <li> >3 future speeds * </ul> * */ public void setSpeed (int speed) { sp = speed; } private int sp = 0; /** * This method does nothing in <code>DumbAdapter</code>. * * @return <the last value passed to the <code>setSpeed(int)</code> * method, or 0 */ public int getSpeed () { return sp; } //-------- //-------- Misc //-------- /** * Gets the container from this adapter whose address matches the address of a container * in the <code>DumbAdapter</code>'s internal <code>java.util.Vector</code>. * * @param address device address with which to find a container * * @return The <code>OneWireContainer</code> object, or <code>null</code> if no match could be found. * @see Address */ public OneWireContainer getDeviceContainer (byte[] address) { long addr = Address.toLong(address); synchronized (containers) { for (int i=0;i<containers.size();i++) { if (((OneWireContainer)containers.elementAt(i)).getAddressAsLong() == addr) return (OneWireContainer)containers.elementAt(i); } } return null; } /** * Gets the container from this adapter whose address matches the address of a container * in the <code>DumbAdapter</code>'s internal <code>java.util.Vector</code>. * * @param address device address with which to find a container * * @return The <code>OneWireContainer</code> object, or <code>null</code> if no match could be found. * @see Address */ public OneWireContainer getDeviceContainer (long address) { return getDeviceContainer(Address.toByteArray(address)); } /** * Gets the container from this adapter whose address matches the address of a container * in the <code>DumbAdapter</code>'s internal <code>java.util.Vector</code>. * * @param address device address with which to find a container * * @return The <code>OneWireContainer</code> object, or <code>null</code> if no match could be found. * @see Address */ public OneWireContainer getDeviceContainer (String address) { return getDeviceContainer(Address.toByteArray(address)); } /** * Returns a <code>OneWireContainer</code> object using the current 1-Wire network address. * The internal state of the port adapter keeps track of the last * address found and is able to create container objects from this * state. * * @return the <code>OneWireContainer</code> object */ public OneWireContainer getDeviceContainer () { // Mask off the upper bit. byte[] address = new byte [8]; getAddress(address); return getDeviceContainer(address); } /** * Checks to see if the family found is in the desired * include group. * * @return <code>true</code> if in include group */ protected boolean isValidFamily (byte[] address) { byte familyCode = address [0]; if (exclude != null) { for (int i = 0; i < exclude.length; i++) { if (familyCode == exclude [i]) { return false; } } } if (include != null) { for (int i = 0; i < include.length; i++) { if (familyCode == include [i]) { return true; } } return false; } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -