Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]
Files | Defines | Typedefs | Functions

Main common include
[Common functions]

Files

file  common.h
 

Commonly used functions used by drivers.


Defines

#define __COMMON_H_SENSOR_CHECK__   1
#define MAX_ARR_SIZE   17
#define min2(a, b)   (a < b ? a : b)
#define min3(a, b, c)   (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c)
#define max2(a, b)   (a > b ? a : b)
#define max3(a, b, c)   (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c)
#define clip(a, b, c)   min2(c, max2(b, a))
#define STRTOK_MAX_TOKEN_SIZE   20
#define STRTOK_MAX_BUFFER_SIZE   50

Typedefs

typedef ubyte tByteArray [MAX_ARR_SIZE]
typedef sbyte tsByteArray [MAX_ARR_SIZE]
typedef ubyte tMassiveArray [128]
typedef ubyte tHugeByteArray [64]
typedef ubyte tBigByteArray [32]
typedef ubyte tIPaddr [4]
typedef int tIntArray [MAX_ARR_SIZE]

Functions

void clearI2CError (tSensors link, ubyte address)
void clearI2Cbus (tSensors link)
bool waitForI2CBus (tSensors link)
bool writeI2C (tSensors link, tByteArray &request, tByteArray &reply, int replylen)
bool writeI2C (tSensors link, tByteArray &request)
long getUID ()
bool strtok (char *buffer, char *token, char *seperator)

Detailed Description

Commonly used functions used by drivers


Define Documentation

#define __COMMON_H_SENSOR_CHECK__   1

< define this as 0 to remove the check

Definition at line 70 of file common.h.

#define clip (   a,
  b,
 
)    min2(c, max2(b, a))

Returns x if it is between min and max. If outside the range, it returns min or max.

Examples:
hitechnic-pir-test1.c, and mindsensors-lineleader-test3.c.

Definition at line 118 of file common.h.

#define max2 (   a,
 
)    (a > b ? a : b)

This function returns the bigger of the two numbers

Examples:
mindsensors-accelerometer-test2.c.

Definition at line 105 of file common.h.

#define max3 (   a,
  b,
 
)    (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c)

This function returns the biggest of the three numbers

Examples:
mindsensors-ps2ctrl-v4-test1.c.

Definition at line 111 of file common.h.

#define MAX_ARR_SIZE   17

Maximum buffer size for byte_array, can be overridden in your own program. It's 17 bytes big because the max I2C buffer size is 16, plus 1 byte to denote packet length.

Definition at line 86 of file common.h.

#define min2 (   a,
 
)    (a < b ? a : b)

This define returns the smaller of the two numbers

Definition at line 93 of file common.h.

#define min3 (   a,
  b,
 
)    (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c)

This define returns the smallest of the three numbers

Definition at line 99 of file common.h.

#define STRTOK_MAX_BUFFER_SIZE   50

Definition at line 407 of file common.h.

#define STRTOK_MAX_TOKEN_SIZE   20

Definition at line 406 of file common.h.


Typedef Documentation

typedef ubyte tBigByteArray[32]

32 byte array for large blobs of data

Examples:
benedettelli-nxt2wifi-test3.c, and humarobotics-wifiblock-test1.c.

Definition at line 129 of file common.h.

typedef ubyte tByteArray[MAX_ARR_SIZE]

Array of bytes as a struct, this is a work around for RobotC's inability to pass an array to a function.

Examples:
benedettelli-nxt2wifi-test1.c, eeprom-test1.c, eeprom-test2.c, mindsensors-ligthsensorarray-test1.c, mindsensors-lineleader-test2.c, and mindsensors-lineleader-test3.c.

Definition at line 125 of file common.h.

typedef ubyte tHugeByteArray[64]

64 byte array for very large blobs of data

Examples:
benedettelli-nxt2wifi-test1.c, benedettelli-nxt2wifi-test2.c, benedettelli-nxt2wifi-test3.c, and benedettelli-nxt2wifi-test4.c.

Definition at line 128 of file common.h.

typedef int tIntArray[MAX_ARR_SIZE]

Array of ints as a struct, this is a work around for RobotC's inability to pass an array to a function.

Examples:
mindsensors-lineleader-test4.c.

Definition at line 136 of file common.h.

typedef ubyte tIPaddr[4]

Struct for holding an IP address

Examples:
humarobotics-wifiblock-test1.c.

Definition at line 130 of file common.h.

typedef ubyte tMassiveArray[128]

128 byte array for very large blobs of data

Definition at line 127 of file common.h.

typedef sbyte tsByteArray[MAX_ARR_SIZE]

Definition at line 126 of file common.h.


Function Documentation

void clearI2Cbus ( tSensors  link )
void clearI2CError ( tSensors  link,
ubyte  address 
)

Clear out the error state on I2C bus by sending a bunch of dummy packets.

Parameters:
linkthe port number
addressthe I2C address we're sending to

Definition at line 151 of file common.h.

long getUID (  )

Create a unique ID (UID) for an NXT. This based on the last 3 bytes of the Bluetooth address. The first 3 bytes are manufacturer specific and identical for all NXTs and are therefore not used.

Returns:
a unique ID for the NXT.

Definition at line 396 of file common.h.

bool strtok ( char *  buffer,
char *  token,
char *  seperator 
)

Tokenise an array of chars, using a seperator

Parameters:
bufferpointer to buffer we're parsing
tokenpointer to buffer to hold the tokens as we find them
seperatorthe seperator used between tokens
Returns:
true if there are still tokens left, false if we're done

Definition at line 416 of file common.h.

bool waitForI2CBus ( tSensors  link )

Wait for the I2C bus to be ready for the next message

Parameters:
linkthe port number
Returns:
true if no error occured, false if it did

Definition at line 174 of file common.h.

bool writeI2C ( tSensors  link,
tByteArray request,
tByteArray reply,
int  replylen 
)

Write to the I2C bus. This function will clear the bus and wait for it be ready before any bytes are sent.

Parameters:
linkthe port number
requestthe data to be sent
replyarray to hold received data
replylenthe number of bytes (if any) expected in reply to this command
Returns:
true if no error occured, false if it did

Definition at line 271 of file common.h.

bool writeI2C ( tSensors  link,
tByteArray request 
)

Write to the I2C bus. This function will clear the bus and wait for it be ready before any bytes are sent.

Parameters:
linkthe port number
requestthe data to be sent
Returns:
true if no error occured, false if it did

Definition at line 211 of file common.h.