its_mode1.h File Reference

ITS networking mode 1. More...

Include dependency graph for its_mode1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef enum _its1_result its1_result
typedef enum _its1_state its1_state

Enumerations

enum  _its1_result { RESULT_SUCCESSFUL, RESULT_FAILED }
enum  _its1_state {
  STATE_STARTUP, STATE_RUNNING, STATE_SEARCHING, STATE_ASSOCIATED,
  STATE_UNASSOCIATED
}

Functions

its1_result its1_controller_handle_association (uns16 pan_id, uns16 its_device_id)
uns8 its1_controller_init (uns16 my_device_id, uns16 network_id)
void its1_controller_process ()
void its1_controller_receive_callback (uns16 device_id, uns8 *data, uns8 data_length)
its1_result its1_controller_transmit (uns16 device_id, uns8 *data, uns8 data_length)
its1_result its1_device_init (uns16 my_device_id, uns16 network_id)
void its1_device_process ()
void its1_device_receive_callback (uns8 *data, uns8 data_length)
its1_result its1_device_transmit (uns8 *data, uns8 data_length)
its1_result its1_find_controller ()
void its1_setup_io ()

Variables

its1_state state

Detailed Description


Typedef Documentation

typedef enum _its1_result its1_result
typedef enum _its1_state its1_state

Enumeration Type Documentation

Enumerator:
RESULT_SUCCESSFUL 
RESULT_FAILED 

Enumerator:
STATE_STARTUP 
STATE_RUNNING 
STATE_SEARCHING 
STATE_ASSOCIATED 
STATE_UNASSOCIATED 


Function Documentation

its1_result its1_controller_handle_association ( uns16  pan_id,
uns16  its_device_id 
)

00062                                                                                   {
00063     // see if this device is in our list, if not, add it
00064 its_device_handle device_handle;
00065 
00066     device_handle = its_get_device(its_device_id);
00067     
00068     if (device_handle == ITS_DEVICE_NONE) {
00069         // in mode 1 we assume that 
00070         device_handle = its_add_device(/* device */ its_device_id, pan_id, /* short addr */ its_device_id);
00071         if (device_handle == ITS_DEVICE_NONE) {
00072             // panic!
00073             serial_print_str("Too many devices! association failed");
00074             return RESULT_FAILED;
00075         } else {
00076             // send association response
00077             its_transmit_to_handle(device_handle, ITS_ASSOC_RES, /* nil data */ 0, /* zero length */ 0);
00078             return RESULT_SUCCESSFUL;
00079             // although strictly speaking we should wait for the ack...
00080         }
00081             
00082     }
00083 }   

Here is the call graph for this function:

uns8 its1_controller_init ( uns16  my_device_id,
uns16  network_id 
)

00235                                                                 {
00236     
00237 uns8 lowest_channel_ed;
00238 uns8 my_ed[8] = ITS_EA;
00239 
00240     its_init();
00241     wpan_init();
00242     
00243     its_set_device_id(my_device_id);
00244     its_set_network_id(network_id); // network id = controller id = pan id in mode 1
00245     
00246     mrf24j40_set_pan_id(network_id);
00247     mrf24j40_set_short_address(my_device_id);   // same as device id
00248     mrf24j40_set_extended_address(&my_ed);
00249 
00250     serial_print_str("Controller startup\n");
00251     
00252     // Find a channel to play on
00253     serial_print_str("Choosing channel\n");
00254     
00255     lowest_channel_ed = mrf24j40_scan_for_lowest_channel_ed();
00256 
00257     serial_print_var("Chosing channel", lowest_channel_ed);
00258     serial_print_nl();  
00259 
00260     // Now set ourselves up on this channel
00261     mrf24j40_set_channel(lowest_channel_ed);
00262     
00263 }   

Here is the call graph for this function:

void its1_controller_process (  ) 

00279                                {
00280 }

void its1_controller_receive_callback ( uns16  device_id,
uns8 *  data,
uns8  data_length 
)
its1_result its1_controller_transmit ( uns16  device_id,
uns8 *  data,
uns8  data_length 
)

00265                                                                                     {
00266 
00267 its_device_handle device_handle;
00268 
00269     device_handle = its_get_device(device_id);
00270 
00271     its_transmit_to_handle(device_handle,  ITS_GENERIC_DATA, data, data_length);
00272 
00273 
00274 }

Here is the call graph for this function:

its1_result its1_device_init ( uns16  my_device_id,
uns16  network_id 
)

00289                                                                    {
00290 
00291 // ITS_EA is set in config.h
00292 
00293 uns8 my_ea[8] = ITS_EA;
00294 
00295     serial_print_str("Device startup\n");
00296 
00297     its_init();
00298     wpan_init();
00299     
00300     its_set_device_id(my_device_id);
00301     its_set_network_id(network_id); // network id = controller id = pan id in mode 1
00302     
00303     mrf24j40_set_pan_id(network_id);
00304     mrf24j40_set_short_address(my_device_id);   // same as device id
00305     mrf24j40_set_extended_address(&my_ea);
00306 
00307     state = STATE_UNASSOCIATED;
00308 }

Here is the call graph for this function:

void its1_device_process (  ) 

00316                            {
00317 
00318 uns16 test_tick;
00319 uns8 controller_ea[8] = CONTROLLER_EA;
00320 
00321     // are we searching?
00322     // has time limit expired?
00323     // go on to next channel
00324     // send its association request to everyone
00325     if (state == STATE_SEARCHING) {
00326         test_tick = tick_get_count();
00327         if (tick_calc_diff(tick_marker, test_tick) >= 250) {    // 250 = 1/4 second
00328             tick_marker = test_tick;
00329             if (channel == 0) { 
00330                 channel = MRF_FIRST_CHANNEL;
00331             } else {
00332                 if (channel == MRF_LAST_CHANNEL) {
00333                     // Didn't find the controller
00334                     state = STATE_UNASSOCIATED;
00335                     serial_print_str("Didn't find controller\n");
00336                 } else {
00337                     channel++;
00338                 }
00339             }
00340             // change channel
00341             serial_print_var("Trying channel ", channel);
00342             serial_print_nl();
00343             mrf24j40_set_channel(channel);
00344             // send broadcast association request
00345             its_transmit_to_ea(&controller_ea, 0xffff, ITS_ASSOC_REQ, /* nil data */ 0, /* zero length */ 0);
00346         } // timer for another channel
00347     } // we're searching    
00348 
00349 }

Here is the call graph for this function:

void its1_device_receive_callback ( uns8 *  data,
uns8  data_length 
)

Here is the caller graph for this function:

its1_result its1_device_transmit ( uns8 *  data,
uns8  data_length 
)

00352                                                                {
00353 
00354 // We want to transmit to our controller
00355         its_transmit_to_handle(controller_handle,  ITS_GENERIC_DATA, data, data_length);
00356 }

Here is the call graph for this function:

its1_result its1_find_controller (  ) 

00310                                    {
00311     state = STATE_SEARCHING;
00312     tick_marker = tick_get_count();
00313     channel = 0;
00314 }

Here is the call graph for this function:

void its1_setup_io (  ) 

00057                      {
00058     wpan_setup_io();
00059 }

Here is the call graph for this function:


Variable Documentation


Generated on Fri Aug 19 09:06:25 2011 for Pic Pack Library by  doxygen 1.6.1