its_mode1.c File Reference

Include dependency graph for its_mode1.c:

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 ()
its1_result its1_device_transmit (uns8 *data, uns8 data_length)
its1_result its1_find_controller ()
void its1_setup_io ()
void wpan_data_received_callback (wpan_address *addr, uns8 *data, uns8 data_size)

Variables

uns8 channel
uns8 controller_handle
its1_state state = STATE_STARTUP
uns16 tick_marker

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:

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:

void wpan_data_received_callback ( wpan_address addr,
uns8 *  data,
uns8  data_size 
)

00155                                                                                  {
00156 
00157 
00158 
00159 uns8 count;
00160     wpan_print_address(addr);
00161     wpan_print_frame_type(frame_type);
00162     serial_print_str(" Data: ");
00163     for (count = 0; count < data_size; count++) {
00164         serial_print_int_hex(data[count]);
00165         serial_putc(' ');
00166         if ((data[count] > 31) && (data[count] < 127)) {
00167             serial_putc(data[count]);
00168         } else {
00169             serial_putc('?');
00170         }   
00171         serial_putc(' ');
00172     }
00173     serial_print_nl();
00174 
00175 
00176 
00177 
00178 
00179     // check frame type
00180     if ((data_size > 2) && (data[0] == 'I') && (data[1] == 'T')) {
00181         serial_print_str("ITS Packet received\n");
00182         uns8 length_header = data[2];
00183         uns8 length_data   = data[3+length_header+1];
00184         uns8 data_start    = 3+length_header+2;
00185         // okay, but is it an its association request?
00186         if (data[3] == ITS_ASSOC_RES) {
00187             serial_print_str("Received association response\n");
00188             if (state == STATE_SEARCHING) {
00189                 serial_print_str("Changing state to associated\n");
00190                 uns16 controller_device_id = data[8]; // device id of controller
00191                 controller_device_id <<= 8;
00192                 controller_device_id += data[7];
00193                 
00194                 uns8 device_handle = its_get_device(controller_device_id);
00195 
00196                 if (device_handle == ITS_DEVICE_NONE) {
00197 
00198                     device_handle = its_add_device(/* device */ controller_device_id, addr->source_pan_id, controller_device_id);
00199                     if (device_handle == ITS_DEVICE_NONE) {
00200                         // panic!
00201                         serial_print_str("Too many devices! association failed");
00202                         state = STATE_UNASSOCIATED;
00203                     } else {
00204                         controller_handle = device_handle;
00205                         state = STATE_ASSOCIATED;   // stop searching
00206                     }
00207                 } else { // it's already in the table
00208                     state = STATE_ASSOCIATED;
00209                 }   
00210                     
00211             }   
00212         }   // association response
00213         else if (data[3] == ITS_GENERIC_DATA) {
00214             // is it for us?
00215             // who cares right now!
00216             // todo...
00217             serial_print_str("Generic data pkt\n");
00218             // just issue the callback
00219             uns16 device_id = data[8];  // msb
00220             device_id  <<= 8;
00221             device_id += data[7];   // lsb
00222             its1_device_receive_callback(&data[data_start], data_size - data_start);
00223 
00224         }   // GENERIC DATA     
00225     }
00226 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

uns8 channel
its1_state state = STATE_STARTUP
uns16 tick_marker

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