embeddedlibrary
reusable software modules for embedded systems
nrf24network.h File Reference

Go to the source code of this file.

Data Structures

union  nrfnet_address_t
 
struct  nrfnet_msg_t
 
struct  nrfnet_s
 

Macros

#define NRF24_CHANNEL_BRANCH_1   30
 
#define NRF24_CHANNEL_BRANCH_2   34
 
#define NRF24_CHANNEL_BRANCH_3   38
 
#define NRF24_CHANNEL_BRANCH_4   42
 
#define NRF24_CHANNEL_BRANCH_5   46
 
#define NRF24_CHANNEL_BRANCH_6   50
 
#define NRF24_ADDRESS_MASK   0x6C6C6C7800
 
#define NRF24_MIN_WINDOW_MS   200
 
#define NRF24_BRANCH_WINDOW_MS   100
 
#define NRF24_TICK_MS   10
 
#define NRF24_MISSING_NODE_TIMEOUT   500
 
#define NRFNET_MSG_BUFFER_LENGTH   16
 
#define nrf24_NetworkISRHandlerN(net)   nRF24_ISR(&net.radio)
 

Typedefs

typedef void(* nrf24_handler_fn_t) (uint8_t *data, uint8_t len, uint8_t from)
 
typedef struct nrfnet_s nrfnet_t
 

Enumerations

enum  nrf24_msg_id {
  SYSTEM_MSG = 0, CONTROL_MSG, SENSOR_MSG, CHAT_MSG,
  CHAT_TEA_MSG, CHAT_RSA_MSG, ENIGMA_MSG, BOMBERMAN_MSG,
  IR_REMOTE_MSG, DRUM_MSG, PONG_MSG, RGB_MATRIX_MSG,
  WHEEL_LIGHT_MSG, SNAKE_MSG, TEST_MSG, LAST_MSG_ID
}
 
enum  nrf24_system_msg { NULL_MSG = 0 }
 
enum  nrf24_control_msg {
  ONBOARD_LED, LINEAR_ACTUATOR, COFFEE_POT, TOASTER,
  LAST_CONTROL_ID
}
 
enum  nrf24_sensor_msg { TEMPERATURE_SENSOR, SPEED_SENSOR, TORQUE_SENSOR, LAST_SENSOR_ID }
 
enum  nrf24_address {
  MASTER = 0x00, LECAKES = 0x08, ALEYAN, AMRITKAR,
  CANDELARIA, CARLUCCIO, DONOW, LECAKES_ALL = 0x0F,
  BLAZEJEWSKI = 0x10, HAAS, HARRIS, HENSHAW,
  JACOBSEN, KLODNICKI, BLAZEJEWSKI_ALL = 0x17, MORRIS = 0x18,
  LABARCK, LIU, RITCHIE_III, RUPP,
  RUSSO, MORRIS_ALL = 0x1F, TRAFFORD = 0x20, WHALEN,
  WIBLE, MACCARONE, VOTTA, TRAFFORD_ALL = 0x27,
  MERLINO = 0x28, GOODMAN, MUHLBAIER, LAST_ADDRESS,
  ALL_ALL = 0x3F
}
 
enum  nrfstate_e { NRFNET_INITIALIZED = 0x00, NRFNET_NORMAL_STATE = 0x00, NRFNET_WAITING_FOR_MIN_WINDOW }
 
enum  nrfrole_e { ROLE_MASTER, ROLE_BRANCH, ROLE_LEAF }
 
enum  pipe_status_e { CHILD_INITIALIZED, CHILD_ACTIVE, CHILD_MISSING }
 

Functions

void nrf24_NetworkInit (void(*ce)(uint8_t), void(*csn)(uint8_t), uint8_t spi_channel)
 Initialize nRF24 Network Module. More...
 
void nrf24_NetworkInitN (nrfnet_t *net, void(*ce)(uint8_t), void(*csn)(uint8_t), uint8_t spi_channel, uint8_t node)
 
void nrf24_RegisterMsgHandler (enum nrf24_msg_id msg_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterMsgHandlerN (nrfnet_t *net, enum nrf24_msg_id msg_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_SendMsg (uint8_t to, enum nrf24_msg_id msg_id, uint8_t *data, uint8_t len)
 
void nrf24_SendMsgN (nrfnet_t *net, uint8_t to, enum nrf24_msg_id msg_id, uint8_t *data, uint8_t len)
 
void nrf24_RegisterControlHandler (enum nrf24_control_msg control_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterControlHandlerN (nrfnet_t *net, enum nrf24_control_msg control_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterSensorHandler (enum nrf24_sensor_msg sensor_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_RegisterSensorHandlerN (nrfnet_t *net, enum nrf24_sensor_msg sensor_id, nrf24_handler_fn_t fn_ptr)
 
void nrf24_NetworkISRHandler (void)
 
char * NameFromAddress (uint8_t address)
 
uint8_t AddressFromName (char *name)
 

Detailed Description

Author
Michael Muhlbaier

Typedef Documentation

typedef void(* nrf24_handler_fn_t) (uint8_t *data, uint8_t len, uint8_t from)

function pointer type for consuming certain msg_id's

Enumeration Type Documentation

Enumerator
LAST_CONTROL_ID 

reserved name to determine number of control msgs supported

Enumerator
SYSTEM_MSG 

built-in / MM

CONTROL_MSG 

general control msg / max payload 5+ bytes

SENSOR_MSG 

general sensor msg / max payload 4+ bytes

CHAT_MSG 

built-in / Jon W.

CHAT_TEA_MSG 

Jon W. Name TBD.

CHAT_RSA_MSG 

Jon W. Name TBD.

ENIGMA_MSG 

Team Enigma.

BOMBERMAN_MSG 

George L.

IR_REMOTE_MSG 

Jimmy+Josh.

DRUM_MSG 

Matt and Tom.

PONG_MSG 

Lee, Dan, Eric, and Lee aka Team James Ritchie III.

RGB_MATRIX_MSG 

A Team.

WHEEL_LIGHT_MSG 

Know.

SNAKE_MSG 

Merlino.

TEST_MSG 

Used for testing the network.

LAST_MSG_ID 

reserved name to determine number of message IDs supported

Enumerator
LAST_SENSOR_ID 

reserved name to determine number of sensors supported

Function Documentation

uint8_t AddressFromName ( char *  name)
Parameters
namepointer to name to lookup
Returns
address network address
char* NameFromAddress ( uint8_t  address)

Convert network address to name

Parameters
addressaddress to convert to name
Returns
string pointer to name
void nrf24_NetworkInit ( void(*)(uint8_t)  ce,
void(*)(uint8_t)  csn,
uint8_t  spi_channel 
)

Initialize nRF24 Network Module.

Parameters
ceFunction pointer to Chip Enable signal function. If input to the function is 0 the CE line should output GND. If the input to the function is 1 the CE pin should output 3.3V
csnFunction pointer to Not Chip Select signal function. If input to the function is 0 the CSN line should output GND. If the input to the function is 1 the CSN pin should output 3.3V
spi_channelSPI channel number to be passed to the SPI Module
void nrf24_RegisterControlHandler ( enum nrf24_control_msg  control_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a control message Handler for a specific control ID

Same as nrf24_RegisterMsgHandler() except the Handler will be called when the message ID is CONTROL_MSG and the control_id (byte after msg ID, i.e. byte 4) matches control_id.

Parameters
control_idControl ID to register Handler for
fn_ptrPointer to Handler function
void nrf24_RegisterMsgHandler ( enum nrf24_msg_id  msg_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a message Handler for a specific message ID

When a message with a message ID that matches msg_id is received the Handler function will be called with a data pointer to the remaining payload (data), the length of the remaining payload (len), and the from address (from).

Only one handler per message ID may be registered.

Handlers for SYSTEM_MSG, CONTROL_MSG, SENSOR_MSG, and CHAT_MSG are built-in but can be overridden.

Example:

1 void PongHandler(uint8_t * data, uint8_t len, uint8_t from) {
2  // implement pong handler
3 }
4 nrf24_RegisterMsgHandler(PONG_MSG, PongHandler);
Parameters
msg_idMessage ID to register Handler for
fn_ptrPointer to Handler function
void nrf24_RegisterSensorHandler ( enum nrf24_sensor_msg  sensor_id,
nrf24_handler_fn_t  fn_ptr 
)

Register a sensor message Handler for a specific sensor ID

Same as nrf24_RegisterMsgHandler() except the Handler will be called when the message ID is SENSOR_MSG and the sensor_id (byte after msg ID, i.e. byte 4) matches sensor_id.

Parameters
sensor_idSensor ID to register Handler for
fn_ptrPointer to Handler function
void nrf24_SendMsg ( uint8_t  to,
enum nrf24_msg_id  msg_id,
uint8_t *  data,
uint8_t  len 
)

Send a message over the nRF24 network

Parameters
toaddress to send message to (use enum nrf24_address for now)
msg_idMessage ID
datapointer to data payload (address bytes and message ID will be generated automatically, this pointer should point to the fourth byte of the payload).
lenlength to the data payload (min 0, max 29)