Announcement

Collapse
No announcement yet.

Bug report: LegacyModule isI2cPortInReadMode() reports incorrectly if 9V is enabled

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bug report: LegacyModule isI2cPortInReadMode() reports incorrectly if 9V is enabled

    As evidenced by the ModernRoboticsNxtUltrasonicSensor code, enabling 9v is allowed to be used during I2C operation:

    Code:
    legacyModule.enableI2cReadMode(physicalPort, 2, 66, 1);
    legacyModule.enable9v(physicalPort, true);
    Setting read mode sets what I'll call the command byte to 0x81:
    Code:
    public void enableI2cReadMode(int physicalPort, int i2cAddress, int memAddress, int length) {
        this.a(physicalPort);
        this.b(length);
    
        try {
            this.a[physicalPort].getWriteLock().lock();
            byte[] var5 = this.a[physicalPort].getWriteBuffer();
            var5[0] = -127;
            var5[1] = (byte)i2cAddress;
            var5[2] = (byte)memAddress;
            var5[3] = (byte)length;
        } finally {
            this.a[physicalPort].getWriteLock().unlock();
        }
    
    }
    Enabling 9V or's in 0x02 to the command byte:
    Code:
    public void enable9v(int physicalPort, boolean enable) {
        if(Arrays.binarySearch(PORT_9V_CAPABLE, physicalPort) < 0) {
            throw new IllegalArgumentException("9v is only available on the following ports: " + Arrays.toString(PORT_9V_CAPABLE));
        } else {
            try {
                this.a[physicalPort].getWriteLock().lock();
                byte var3 = this.a[physicalPort].getWriteBuffer()[0];
                if(enable) {
                    var3 = (byte)(var3 | 2);
                } else {
                    var3 &= -3;
                }
    
                this.a[physicalPort].getWriteBuffer()[0] = var3;
            } finally {
                this.a[physicalPort].getWriteLock().unlock();
            }
    
            this.writeI2cCacheToController(physicalPort);
        }
    }
    But isI2cPortInReadMode() only tests the command byte for simple equality against 0x81.
    Code:
    public boolean isI2cPortInReadMode(int physicalPort) {
        this.a(physicalPort);
        boolean var2 = false;
    
        try {
            this.a[physicalPort].getReadLock().lock();
            byte[] var3 = this.a[physicalPort].getReadBuffer();
            var2 = var3[0] == -127;
        } finally {
            this.a[physicalPort].getReadLock().unlock();
        }
    
        return var2;
    }
    isI2cPortInWriteMode() has an analogous bug.


  • #2
    Thank you for this high quality bug report.

    Comment

    Working...
    X