Changeset 579
- Timestamp:
- 05/08/08 11:55:22 (1 week ago)
- Files:
-
- nano-RK/projects/SAMPL/gateway/main.c (modified) (5 diffs)
- nano-RK/projects/SAMPL/mobile-example/location-sample/main.c (modified) (8 diffs)
- nano-RK/projects/SAMPL/mobile-example/location-sample/makefile (modified) (1 diff)
- nano-RK/projects/SAMPL/mobile-example/location-sample/nrk_cfg.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nano-RK/projects/SAMPL/gateway/main.c
r548 r579 37 37 #define gw_mac 0 38 38 39 #define TXT_DEBUG39 //#define TXT_DEBUG 40 40 //#define AUTO_PING 41 41 //#define NO_SLIP … … 118 118 val=read_eeprom_channel(&i); 119 119 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]); 121 121 printf ("MAC = 0x%x\r\n", my_mac); 122 122 printf ("Channel = %d\r\n", i); … … 182 182 if((local_rx_buf[CTRL_FLAGS] & (DS_MASK | US_MASK ))==0 ) 183 183 { 184 #ifdef TXT_DEBUG 184 185 nrk_kprintf( PSTR( "P2P->Gateway\r\n" )); 185 p2p_pkt.buf=local_rx_buf; 186 #endif 187 p2p_pkt.buf=local_rx_buf; 186 188 p2p_pkt.buf_len=len; 187 189 unpack_peer_2_peer_packet(&p2p_pkt); … … 214 216 if((local_rx_buf[CTRL_FLAGS] & DS_MASK)==0 && (local_rx_buf[CTRL_FLAGS] & US_MASK)!=0) 215 217 { 218 #ifdef TXT_DEBUG 216 219 nrk_kprintf( PSTR( "Upstream->Gateway\r\n" )); 217 us_pkt.buf=local_rx_buf; 220 #endif 221 us_pkt.buf=local_rx_buf; 218 222 us_pkt.buf_len=len; 219 223 unpack_upstream_packet(&us_pkt); … … 236 240 gw_pkt.dst_mac=gw_mac; 237 241 gw_pkt.num_msgs=us_pkt.num_msgs; 242 #ifdef TXT_DEBUG 238 243 printf( "us_payload=%d\r\n",us_pkt.payload_len ); 244 #endif 239 245 for(i=0; i<us_pkt.payload_len; i++ ) 240 246 gw_pkt.payload[i]=us_pkt.payload[i]; nano-RK/projects/SAMPL/mobile-example/location-sample/main.c
r564 r579 32 32 #include "../../include/sampl.h" 33 33 #include "../../include/pkt_packer.h" 34 #include <nrk_driver_list.h> 35 #include <nrk_driver.h> 36 #include <ff_basic_sensor.h> 34 37 35 38 #define REPLY_WAIT_SECS 1 36 39 #define ADXL_THRESH 9 37 40 #define my_subnet_mac_2 1 38 41 #define my_subnet_mac_1 0 39 42 #define my_subnet_mac_0 0 40 #define my_mac 10243 #define my_mac 0x68 41 44 42 45 #define TXT_DEBUG … … 47 50 void build_extended_neighbor_list_pkt(SAMPL_PEER_2_PEER_PKT_T *p2p_pkt,uint8_t *nlist,uint8_t nlist_size); 48 51 void build_ping_pkt(SAMPL_PEER_2_PEER_PKT_T *p2p_pkt); 52 void nrk_register_drivers(); 49 53 50 54 nrk_task_type MOBILE_TASK; … … 78 82 79 83 nrk_time_set (0, 0); 84 nrk_register_drivers(); 80 85 81 86 bmac_task_config (); … … 90 95 { 91 96 uint8_t j, i, error,unique; 92 uint8_t samples ;97 uint8_t samples,moved,fd; 93 98 int8_t len; 94 99 int8_t rssi, val; 95 100 uint8_t *local_rx_buf; 101 uint16_t adxlx,last_adxlx; 102 uint16_t adxly,last_adxly; 103 uint16_t adxlz,last_adxlz; 96 104 97 105 nrk_sig_t tx_done_signal; … … 134 142 cnt = 0; 135 143 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; 140 150 while (1) { 141 151 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); 161 191 #ifdef TXT_DEBUG 162 nrk_kprintf (PSTR ("\r\nSent Request:\r\n"));192 nrk_kprintf (PSTR ("Pinging...\r\n")); 163 193 #endif 164 nrk_led_clr (GREEN_LED);165 166 167 168 // Wait for packets or timeout169 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) { 171 201 172 202 timeout.secs = REPLY_WAIT_SECS; … … 267 297 } 268 298 269 nrk_wait_until_next_period (); 299 for(i=0; i<10; i++ ) nrk_wait_until_next_period (); 300 bmac_rx_pkt_release (); 270 301 271 302 } … … 340 371 MOBILE_TASK.Type = BASIC_TASK; 341 372 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; 344 375 MOBILE_TASK.cpu_reserve.secs = 1; 345 376 MOBILE_TASK.cpu_reserve.nano_secs = 500 * NANOS_PER_MS; … … 351 382 352 383 } 384 385 void nrk_register_drivers() 386 { 387 int8_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 396 val=nrk_register_driver( &dev_manager_ff_sensors,FIREFLY_SENSOR_BASIC); 397 if(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 22 22 SRC = $(TARGET).c 23 23 SRC += ../../include/pkt_packer.c 24 SRC += $(ROOT_DIR)/src/drivers/platform/$(PLATFORM_TYPE)/source/ff_basic_sensor.c 24 25 25 26 nano-RK/projects/SAMPL/mobile-example/location-sample/nrk_cfg.h
r564 r579 44 44 #define NRK_MAX_RESOURCE_CNT 10 45 45 46 #define NRK_MAX_DRIVER_CNT 1 46 47 47 48
