I have some inclination to implement bitbus support in the enhanced NBC/NXC firmware but have not gotten around to doing anything like that yet. Maybe someday in 2012.
I also have no intention of using the bluetooth address or the brick name or anything like that at the firmware level for addressing a message to a specific NXT.
The addressing ability is only implemented when the Comm module's HsDataMode is set to DATA_MODE_NXT rather than its default value of DATA_MODE_RAW. This allows you to send Direct Command and System Command messages to another NXT over RS485 via all of the NXC API functions for these DC and SC messages. See all of the Remote* functions, which for your convenience I have listed below.
Code: Select all
RemoteBluetoothFactoryReset(byte conn)
RemoteCloseFile(byte conn, byte handle)
RemoteConnectionIdle(byte conn)
RemoteConnectionWrite(byte conn, byte buffer[])
RemoteDatalogRead(byte conn, bool remove, byte & cnt, byte & log[])
RemoteDatalogSetTimes(byte conn, long synctime)
RemoteDeleteFile(byte conn, string filename)
RemoteDeleteUserFlash(byte conn)
RemoteFindFirstFile(byte conn, string mask, byte & handle, string & name, long & size)
RemoteFindNextFile(byte conn, byte & handle, string & name, long & size)
RemoteGetBatteryLevel(byte conn, int & value)
RemoteGetBluetoothAddress(byte conn, byte & btaddr[])
RemoteGetConnectionCount(byte conn, byte & cnt)
RemoteGetConnectionName(byte conn, byte idx, string & name)
RemoteGetContactCount(byte conn, byte & cnt)
RemoteGetContactName(byte conn, byte idx, string & name)
RemoteGetCurrentProgramName(byte conn, string & name)
RemoteGetDeviceInfo(byte conn, string & name, byte & btaddr[], byte & btsignal[], long & freemem)
RemoteGetFirmwareVersion(byte conn, byte & pmin, byte & pmaj, byte & fmin, byte & fmaj)
RemoteGetInputValues(byte conn, InputValuesType & params)
RemoteGetOutputState(byte conn, OutputStateType & params)
RemoteGetProperty(byte conn, byte property, variant & value)
RemoteIOMapRead(byte conn, long id, int offset, int & numbytes, byte & data[])
RemoteIOMapWriteBytes(byte conn, long id, int offset, byte data[])
RemoteIOMapWriteValue(byte conn, long id, int offset, variant value)
RemoteKeepAlive(byte conn)
RemoteLowspeedGetStatus(byte conn, byte & value)
RemoteLowspeedRead(byte conn, byte port, byte & bread, byte & data[])
RemoteLowspeedWrite(byte conn, byte port, byte txlen, byte rxlen, byte data[])
RemoteMessageRead(byte conn, byte queue)
RemoteMessageWrite(byte conn, byte queue, string msg)
RemoteOpenAppendData(byte conn, string filename, byte & handle, long & size)
RemoteOpenRead(byte conn, string filename, byte & handle, long & size)
RemoteOpenWrite(byte conn, string filename, long size, byte & handle)
RemoteOpenWriteData(byte conn, string filename, long size, byte & handle)
RemoteOpenWriteLinear(byte conn, string filename, long size, byte & handle)
RemotePlaySoundFile(byte conn, string filename, bool bloop)
RemotePlayTone(byte conn, unsigned int frequency, unsigned int duration)
RemotePollCommand(byte conn, byte bufnum, byte & len, byte & data[])
RemotePollCommandLength(byte conn, byte bufnum, byte & length)
RemoteRead(byte conn, byte & handle, int & numbytes, byte & data[])
RemoteRenameFile(byte conn, string oldname, string newname)
RemoteResetMotorPosition(byte conn, byte port, bool brelative)
RemoteResetScaledValue(byte conn, byte port)
RemoteResetTachoCount(byte conn, byte port)
RemoteSetBrickName(byte conn, string name)
RemoteSetInputMode(byte conn, byte port, byte type, byte mode)
RemoteSetOutputState(byte conn, byte port, char speed, byte mode, byte regmode, char turnpct, byte runstate, unsigned long tacholimit)
RemoteSetProperty(byte conn, byte prop, variant value)
RemoteStartProgram(byte conn, string filename)
RemoteStopProgram(byte conn)
RemoteStopSound(byte conn)
RemoteWrite(byte conn, byte & handle, int & numbytes, byte data[])
The connection should be specified via a constant so that the macros emit the correct code for these "inline functions". The correct constants to use are from nbcommon.h:
Code: Select all
#define CONN_BT0 0x0 /*!< Bluetooth connection 0 */
#define CONN_BT1 0x1 /*!< Bluetooth connection 1 */
#define CONN_BT2 0x2 /*!< Bluetooth connection 2 */
#define CONN_BT3 0x3 /*!< Bluetooth connection 3 */
#define CONN_HS4 0x4 /*!< RS485 (hi-speed) connection (port 4, all devices) */
#define CONN_HS_ALL 0x4 /*!< RS485 (hi-speed) connection (port 4, all devices) */
#define CONN_HS_1 0x5 /*!< RS485 (hi-speed) connection (port 4, device address 1) */
#define CONN_HS_2 0x6 /*!< RS485 (hi-speed) connection (port 4, device address 2) */
#define CONN_HS_3 0x7 /*!< RS485 (hi-speed) connection (port 4, device address 3) */
#define CONN_HS_4 0x8 /*!< RS485 (hi-speed) connection (port 4, device address 4) */
#define CONN_HS_5 0x9 /*!< RS485 (hi-speed) connection (port 4, device address 5) */
#define CONN_HS_6 0xa /*!< RS485 (hi-speed) connection (port 4, device address 6) */
#define CONN_HS_7 0xb /*!< RS485 (hi-speed) connection (port 4, device address 7) */
#define CONN_HS_8 0xc /*!< RS485 (hi-speed) connection (port 4, device address 8) */
You use SetHsAddress(byte Address) to set your NXT's address to something other than its default value of HS_ADDRESS_ALL (0). The correct constants to use with SetHsAddress are in nbccommon.h:
Code: Select all
#define HS_ADDRESS_ALL 0 /*!< HsAddress all devices */
#define HS_ADDRESS_1 1 /*!< HsAddress device address 1 */
#define HS_ADDRESS_2 2 /*!< HsAddress device address 2 */
#define HS_ADDRESS_3 3 /*!< HsAddress device address 3 */
#define HS_ADDRESS_4 4 /*!< HsAddress device address 4 */
#define HS_ADDRESS_5 5 /*!< HsAddress device address 5 */
#define HS_ADDRESS_6 6 /*!< HsAddress device address 6 */
#define HS_ADDRESS_7 7 /*!< HsAddress device address 7 */
#define HS_ADDRESS_8 8 /*!< HsAddress device address 8 */
One way to use RS485 between two NXT's is via the same mailbox message scheme that you would use via Bluetooth and the standard firmware. This would involve the RemoteMessageRead and RemoteMessageWrite API functions.
John Hansen