Changeset 579

Show
Ignore:
Timestamp:
05/08/08 11:55:22 (1 week ago)
Author:
agr
Message:

mobile node update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nano-RK/projects/SAMPL/gateway/main.c

    r548 r579  
    3737#define gw_mac          0 
    3838 
    39 #define TXT_DEBUG 
     39//#define TXT_DEBUG 
    4040//#define AUTO_PING 
    4141//#define NO_SLIP 
     
    118118  val=read_eeprom_channel(&i); 
    119119  val=read_eeprom_aes_key(&aes_key); 
    120   printf ("Netmask = 0x%02x%02x%02x\r\n", my_subnet_mac[2], my_subnet_mac[1], my_subnet_mac[0]); 
     120  printf ("Netmask = 0x%x %x %x\r\n", my_subnet_mac[2], my_subnet_mac[1], my_subnet_mac[0]); 
    121121  printf ("MAC = 0x%x\r\n", my_mac); 
    122122  printf ("Channel = %d\r\n", i); 
     
    182182        if((local_rx_buf[CTRL_FLAGS] & (DS_MASK | US_MASK ))==0 ) 
    183183        { 
     184        #ifdef TXT_DEBUG 
    184185        nrk_kprintf( PSTR( "P2P->Gateway\r\n" )); 
    185         p2p_pkt.buf=local_rx_buf; 
     186        #endif 
     187        p2p_pkt.buf=local_rx_buf; 
    186188        p2p_pkt.buf_len=len; 
    187189        unpack_peer_2_peer_packet(&p2p_pkt); 
     
    214216        if((local_rx_buf[CTRL_FLAGS] & DS_MASK)==0 && (local_rx_buf[CTRL_FLAGS] & US_MASK)!=0) 
    215217        { 
     218        #ifdef TXT_DEBUG 
    216219        nrk_kprintf( PSTR( "Upstream->Gateway\r\n" )); 
    217         us_pkt.buf=local_rx_buf; 
     220        #endif 
     221        us_pkt.buf=local_rx_buf; 
    218222        us_pkt.buf_len=len; 
    219223        unpack_upstream_packet(&us_pkt); 
     
    236240        gw_pkt.dst_mac=gw_mac; 
    237241        gw_pkt.num_msgs=us_pkt.num_msgs; 
     242        #ifdef TXT_DEBUG 
    238243        printf( "us_payload=%d\r\n",us_pkt.payload_len ); 
     244        #endif 
    239245        for(i=0; i<us_pkt.payload_len; i++ ) 
    240246                gw_pkt.payload[i]=us_pkt.payload[i]; 
  • nano-RK/projects/SAMPL/mobile-example/location-sample/main.c

    r564 r579  
    3232#include "../../include/sampl.h" 
    3333#include "../../include/pkt_packer.h" 
     34#include <nrk_driver_list.h> 
     35#include <nrk_driver.h> 
     36#include <ff_basic_sensor.h> 
    3437 
    3538#define REPLY_WAIT_SECS 1 
    36  
     39#define ADXL_THRESH     9  
    3740#define my_subnet_mac_2   1      
    3841#define my_subnet_mac_1   0      
    3942#define my_subnet_mac_0   0      
    40 #define my_mac            102 
     43#define my_mac            0x68 
    4144 
    4245#define TXT_DEBUG 
     
    4750void build_extended_neighbor_list_pkt(SAMPL_PEER_2_PEER_PKT_T *p2p_pkt,uint8_t *nlist,uint8_t nlist_size); 
    4851void build_ping_pkt(SAMPL_PEER_2_PEER_PKT_T *p2p_pkt); 
     52void nrk_register_drivers(); 
    4953 
    5054nrk_task_type MOBILE_TASK; 
     
    7882 
    7983  nrk_time_set (0, 0); 
     84  nrk_register_drivers(); 
    8085 
    8186  bmac_task_config (); 
     
    9095{ 
    9196  uint8_t j, i,  error,unique; 
    92   uint8_t samples
     97  uint8_t samples,moved,fd
    9398  int8_t len; 
    9499  int8_t rssi, val; 
    95100  uint8_t *local_rx_buf; 
     101  uint16_t adxlx,last_adxlx; 
     102  uint16_t adxly,last_adxly; 
     103  uint16_t adxlz,last_adxlz; 
    96104 
    97105  nrk_sig_t tx_done_signal; 
     
    134142  cnt = 0; 
    135143 
    136     check_period.secs = 0; 
    137     check_period.nano_secs = DEFAULT_CHECK_RATE * NANOS_PER_MS; 
    138     val = bmac_set_rx_check_rate (check_period); 
    139  
     144  check_period.secs = 0; 
     145  check_period.nano_secs = DEFAULT_CHECK_RATE * NANOS_PER_MS; 
     146  val = bmac_set_rx_check_rate (check_period); 
     147  adxlx=0; last_adxlx=0; 
     148  adxly=0; last_adxly=0; 
     149  adxlz=0; last_adxlz=0; 
    140150  while (1) { 
    141151 
    142  
    143  
    144     my_nlist_elements=0; 
    145  
    146 for(samples=0; samples<5; samples++ ) 
    147 
    148     nrk_led_set (GREEN_LED); 
    149     check_period.secs = 0; 
    150     check_period.nano_secs = DEFAULT_CHECK_RATE * NANOS_PER_MS; 
    151     val = bmac_set_rx_check_rate (check_period); 
    152     build_ping_pkt( &p2p_pkt ); 
    153     // Pack data structure values in buffer before transmit 
    154     pack_peer_2_peer_packet(&p2p_pkt); 
    155     // For blocking transmits, use the following function call. 
    156     val = bmac_tx_pkt (p2p_pkt.buf, p2p_pkt.buf_len); 
    157  
    158     check_period.secs = 0; 
    159     check_period.nano_secs = p2p_pkt.check_rate * NANOS_PER_MS; 
    160     val = bmac_set_rx_check_rate (check_period); 
     152        nrk_led_clr(ORANGE_LED); 
     153        do { 
     154 
     155/* 
     156        // This section checks the accelerometer for motion 
     157        fd=nrk_open(FIREFLY_SENSOR_BASIC,READ); 
     158        if(fd==NRK_ERROR) nrk_kprintf(PSTR("Failed to open sensor driver\r\n")); 
     159 
     160        moved=0; 
     161        val=nrk_set_status(fd,SENSOR_SELECT,ACC_X); 
     162        val=nrk_read(fd,&adxlx,2); 
     163        if(adxlx>last_adxlx) { if(adxlx-last_adxlx>ADXL_THRESH) moved=1;        }  
     164        else{ if(last_adxlx-adxlx>ADXL_THRESH) moved=1;} 
     165 
     166        nrk_close(fd); 
     167        last_adxlx=adxlx; 
     168        last_adxly=adxly; 
     169        last_adxlz=adxlz; 
     170        if(moved==0) nrk_wait_until_next_period(); 
     171        } while(moved==0); 
     172        nrk_led_set(ORANGE_LED); 
     173*/ 
     174          my_nlist_elements=0; 
     175 
     176          for(samples=0; samples<3; samples++ ) 
     177          { 
     178                  nrk_led_set (GREEN_LED); 
     179                  check_period.secs = 0; 
     180                  check_period.nano_secs = DEFAULT_CHECK_RATE * NANOS_PER_MS; 
     181                  val = bmac_set_rx_check_rate (check_period); 
     182                  build_ping_pkt( &p2p_pkt ); 
     183                  // Pack data structure values in buffer before transmit 
     184                  pack_peer_2_peer_packet(&p2p_pkt); 
     185                  // For blocking transmits, use the following function call. 
     186                  val = bmac_tx_pkt (p2p_pkt.buf, p2p_pkt.buf_len); 
     187 
     188                  check_period.secs = 0; 
     189                  check_period.nano_secs = p2p_pkt.check_rate * NANOS_PER_MS; 
     190                  val = bmac_set_rx_check_rate (check_period); 
    161191#ifdef TXT_DEBUG 
    162     nrk_kprintf (PSTR ("\r\nSent Request:\r\n")); 
     192                 nrk_kprintf (PSTR ("Pinging...\r\n")); 
    163193#endif 
    164     nrk_led_clr (GREEN_LED); 
    165  
    166  
    167  
    168     // Wait for packets or timeout 
    169     nrk_time_get (&start); 
    170     while (1) { 
     194                 nrk_led_clr (GREEN_LED); 
     195 
     196 
     197 
     198                 // Wait for packets or timeout 
     199                 nrk_time_get (&start); 
     200                 while (1) { 
    171201 
    172202      timeout.secs = REPLY_WAIT_SECS; 
     
    267297  } 
    268298  
    269     nrk_wait_until_next_period (); 
     299    for(i=0; i<10; i++ ) nrk_wait_until_next_period (); 
     300        bmac_rx_pkt_release (); 
    270301     
    271302  } 
     
    340371  MOBILE_TASK.Type = BASIC_TASK; 
    341372  MOBILE_TASK.SchType = PREEMPTIVE; 
    342   MOBILE_TASK.period.secs = 10; 
    343   MOBILE_TASK.period.nano_secs = 0
     373  MOBILE_TASK.period.secs = 0; 
     374  MOBILE_TASK.period.nano_secs = 500*NANOS_PER_MS
    344375  MOBILE_TASK.cpu_reserve.secs = 1; 
    345376  MOBILE_TASK.cpu_reserve.nano_secs = 500 * NANOS_PER_MS; 
     
    351382 
    352383} 
     384 
     385void nrk_register_drivers() 
     386{ 
     387int8_t val; 
     388 
     389// Register the Basic FireFly Sensor device driver 
     390// Make sure to add:  
     391//     #define NRK_MAX_DRIVER_CNT   
     392//     in nrk_cfg.h 
     393// Make sure to add:  
     394//     SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/ff_basic_sensor.c 
     395//     in makefile 
     396val=nrk_register_driver( &dev_manager_ff_sensors,FIREFLY_SENSOR_BASIC); 
     397if(val==NRK_ERROR) nrk_kprintf( PSTR("Failed to load my ADC driver\r\n") ); 
     398 
     399} 
     400 
  • nano-RK/projects/SAMPL/mobile-example/location-sample/makefile

    r564 r579  
    2222SRC = $(TARGET).c 
    2323SRC += ../../include/pkt_packer.c 
     24SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/ff_basic_sensor.c 
    2425 
    2526 
  • nano-RK/projects/SAMPL/mobile-example/location-sample/nrk_cfg.h

    r564 r579  
    4444#define NRK_MAX_RESOURCE_CNT           10  
    4545 
     46#define NRK_MAX_DRIVER_CNT              1     
    4647 
    4748