lejos.nxt.remote
Class RemoteSensorPort

java.lang.Object
  extended by lejos.nxt.remote.RemoteSensorPort
All Implemented Interfaces:
ADSensorPort, BasicSensorPort, I2CPort, NXTProtocol, SensorConstants

public class RemoteSensorPort
extends Object
implements NXTProtocol, ADSensorPort, I2CPort

Emulates a Sensor Port using LCP


Field Summary
 
Fields inherited from interface lejos.nxt.remote.NXTProtocol
ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_DEFRAG, NXJ_DISCONNECT, NXJ_GET_AUTO_RUN, NXJ_GET_DEFAULT_PROGRAM, NXJ_GET_KEY_CLICK_VOLUME, NXJ_GET_SLEEP_TIME, NXJ_GET_VERSION, NXJ_GET_VOLUME, NXJ_PACKET_MODE, NXJ_SET_AUTO_RUN, NXJ_SET_DEFAULT_PROGRAM, NXJ_SET_KEY_CLICK_VOLUME, NXJ_SET_SLEEP_TIME, NXJ_SET_VOLUME, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TRANSITIONCNTMODE, WRITE
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
 
Fields inherited from interface lejos.nxt.I2CPort
ALWAYS_ACTIVE, ERR_ABORT, ERR_BUS_BUSY, ERR_BUSY, ERR_FAULT, ERR_INVALID_LENGTH, ERR_INVALID_PORT, HIGH_SPEED, LEGO_MODE, MAX_IO, NO_RELEASE, STANDARD_MODE
 
Fields inherited from interface lejos.nxt.SensorConstants
BLACK, BLANK_INDEX, BLUE, BLUE_INDEX, GREEN, GREEN_INDEX, MAX_AD_RAW, MAX_TYPE, MIN_TYPE, MODE_ANGLESTEP, MODE_BOOLEAN, MODE_CELSIUS, MODE_FARENHEIT, MODE_PCTFULLSCALE, MODE_PERIODCOUNTER, MODE_RAW, MODE_TRANSITIONCNT, RED, RED_INDEX, TYPE_ANGLE, TYPE_COLORBLUE, TYPE_COLORFULL, TYPE_COLORGREEN, TYPE_COLORNONE, TYPE_COLORRED, TYPE_CUSTOM, TYPE_HISPEED, TYPE_LIGHT_ACTIVE, TYPE_LIGHT_INACTIVE, TYPE_LOWSPEED, TYPE_LOWSPEED_9V, TYPE_NO_SENSOR, TYPE_REFLECTION, TYPE_SOUND_DB, TYPE_SOUND_DBA, TYPE_SWITCH, TYPE_TEMPERATURE, WHITE, YELLOW
 
Constructor Summary
RemoteSensorPort(NXTCommand nxtCommand, int id)
           
 
Method Summary
 int getId()
          Get the port number
 int getMode()
          Get the sensor mode
 NXTCommand getNXTCommand()
          Get the NXTCommand object used for remote access
 int getType()
          Get the sensor type
 int i2cComplete(byte[] buffer, int offset, int numBytes)
           
 void i2cDisable()
          Disable I2C on the port - null for remote ports
 void i2cEnable(int mode)
          Enable I2C on the port - null for remote ports
 int i2cStart(int address, byte[] writeBuffer, int writeOffset, int writeLength, int readLength)
          Start an I2C transaction.
 int i2cStatus()
          Test if I2C is busy
 int i2cTransaction(int deviceAddress, byte[] writeBuf, int writeOffset, int writeLen, byte[] readBuf, int readOffset, int readLen)
          High level i2c interface.
 void i2cWaitIOComplete()
          Wait for the current IO operation on the i2c port to complete.
 boolean readBooleanValue()
          Reads the boolean value of the sensor.
 int readRawValue()
          Reads the raw value of the sensor.
 int readValue()
          Returns value compatible with Lego firmware.
 void setMode(int mode)
          Set the sensor mode
 void setType(int type)
          Set the sensor type
 void setTypeAndMode(int type, int mode)
          Set the sensor type and mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteSensorPort

public RemoteSensorPort(NXTCommand nxtCommand,
                        int id)
Method Detail

getId

public int getId()
Get the port number

Returns:
the port number

getType

public int getType()
Get the sensor type

Specified by:
getType in interface BasicSensorPort
Returns:
the sensor type

getMode

public int getMode()
Get the sensor mode

Specified by:
getMode in interface BasicSensorPort
Returns:
the sensor mode

setTypeAndMode

public void setTypeAndMode(int type,
                           int mode)
Set the sensor type and mode

Specified by:
setTypeAndMode in interface BasicSensorPort
Parameters:
type - the sensor type
mode - the sensor mode

setType

public void setType(int type)
Set the sensor type

Specified by:
setType in interface BasicSensorPort
Parameters:
type - the sensor type

setMode

public void setMode(int mode)
Set the sensor mode

Specified by:
setMode in interface BasicSensorPort
Parameters:
mode - the sensor mode

readBooleanValue

public boolean readBooleanValue()
Reads the boolean value of the sensor.

Specified by:
readBooleanValue in interface ADSensorPort
Returns:
Boolean value of sensor.

readRawValue

public int readRawValue()
Reads the raw value of the sensor.

Specified by:
readRawValue in interface ADSensorPort
Returns:
Raw sensor value. Range is device dependent.

readValue

public int readValue()
Returns value compatible with Lego firmware.

Specified by:
readValue in interface ADSensorPort

getNXTCommand

public NXTCommand getNXTCommand()
Get the NXTCommand object used for remote access

Returns:
the NXTCommand object

i2cStatus

public int i2cStatus()
Test if I2C is busy

Specified by:
i2cStatus in interface I2CPort
Returns:
the status value (see ErrorMessages)

i2cDisable

public void i2cDisable()
Disable I2C on the port - null for remote ports

Specified by:
i2cDisable in interface I2CPort

i2cEnable

public void i2cEnable(int mode)
Enable I2C on the port - null for remote ports

Specified by:
i2cEnable in interface I2CPort
Parameters:
mode - One or more of the mode bits above.

i2cStart

public int i2cStart(int address,
                    byte[] writeBuffer,
                    int writeOffset,
                    int writeLength,
                    int readLength)
Start an I2C transaction. The remote implementation is synchronous.

Parameters:
address - the I2C address (x01 - x7F)
writeBuffer - data to write
writeOffset - offset of the data in the write buffer
writeLength - length of the data to write
readLength - Number of bytes to read
Returns:
the status value

i2cComplete

public int i2cComplete(byte[] buffer,
                       int offset,
                       int numBytes)

i2cWaitIOComplete

public void i2cWaitIOComplete()
Wait for the current IO operation on the i2c port to complete.


i2cTransaction

public int i2cTransaction(int deviceAddress,
                          byte[] writeBuf,
                          int writeOffset,
                          int writeLen,
                          byte[] readBuf,
                          int readOffset,
                          int readLen)
High level i2c interface. Perform a complete i2c transaction and return the results. Writes the specified data to the device and then reads the requested bytes from it.

Specified by:
i2cTransaction in interface I2CPort
Parameters:
deviceAddress - The I2C device address.
writeBuf - The buffer containing data to be written to the device.
writeOffset - The offset of the data within the write buffer
writeLen - The number of bytes to write.
readBuf - The buffer to use for the transaction results
readOffset - Location to write the results to
readLen - The length of the read
Returns:
< 0 error otherwise the number of bytes read