Changeset 535
- Timestamp:
- 04/23/08 13:40:34 (6 months ago)
- Files:
-
- nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.c (modified) (3 diffs)
- nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.h (modified) (3 diffs)
- nano-RK/projects/SAMPL/app_pkt_handlers/nck_pkt.c (added)
- nano-RK/projects/SAMPL/app_pkt_handlers/nck_pkt.h (added)
- nano-RK/projects/SAMPL/client/aggregate.c (modified) (1 diff)
- nano-RK/projects/SAMPL/client/globals.h (modified) (1 diff)
- nano-RK/projects/SAMPL/client/main.c (modified) (1 diff)
- nano-RK/projects/SAMPL/client/makefile (modified) (1 diff)
- nano-RK/projects/SAMPL/include/sampl.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.c
r506 r535 5 5 #include <control_pkt.h> 6 6 #include <ack_pkt.h> 7 #include <nck_pkt.h> 7 8 8 9 … … 10 11 { 11 12 ACK_PKT_T p; 13 NCK_PKT_T n; 12 14 CONTROL_PKT_T r; 13 uint8_t num_pkts,i,selected; 15 uint8_t num_pkts,i,selected,checksum; 16 nrk_time_t t; 14 17 15 route_pkt_get(&r, ds_pkt->payload, i); 16 bmac_set_cca_thresh (r.cca_threshold); 18 checksum=control_pkt_get(&r, ds_pkt->payload, 0); 19 20 if(checksum==r.checksum && r.mobile_reserve_seconds!=0) 21 { 22 bmac_set_cca_thresh (r.cca_threshold); 23 if((r.ctrl_flags_1 & GLOBAL_DEBUG_MASK )!=0) admin_debug_flag=1; 24 else admin_debug_flag=0; 25 t.secs=r.mobile_reserve_seconds; 26 t.nano_secs=0; 27 i=nrk_reserve_set(mobile_reserve, &t,r.mobile_reserve_cnt, NULL); 17 28 // add route persistence here... 18 // add reservation control19 // add debugging enable / disable20 29 21 // build ACK reply packet 30 nrk_kprintf( PSTR("Control Pkt:\r\n")); 31 nrk_kprintf( PSTR(" CCA:")); 32 printf( "%d",(int8_t)r.cca_threshold ); 33 nrk_kprintf( PSTR("\r\n Debug:")); 34 printf( "%d",(r.ctrl_flags_1 & GLOBAL_DEBUG_MASK)); 35 nrk_kprintf( PSTR("\r\n Mobile Reserve time:")); 36 printf( "%d",r.mobile_reserve_seconds); 37 nrk_kprintf( PSTR(" sec\r\n Mobile Reserve count:")); 38 printf( "%d",r.mobile_reserve_cnt); 39 nrk_kprintf( PSTR("\r\n")); 40 41 42 // build ACK reply packet 22 43 p.mac_addr=my_mac; 23 pkt->payload_len = ping_pkt_add( &p, pkt->payload,0);44 pkt->payload_len = ack_pkt_add( &p, pkt->payload,0); 24 45 pkt->num_msgs=1; 25 46 pkt->pkt_type=ACK_PKT; 47 } 48 else 49 { 50 nrk_kprintf( PSTR( "Control packet failed checksum\r\n")); 51 nrk_kprintf( PSTR(" pkt: " )); 52 printf( "%d",r.checksum ); 53 nrk_kprintf( PSTR(" calc: " )); 54 printf( "%d\r\n",checksum ); 55 // build NCK reply packet 56 n.mac_addr=my_mac; 57 pkt->payload_len = nck_pkt_add( &n, pkt->payload,0); 58 pkt->num_msgs=1; 59 pkt->pkt_type=NCK_PKT; 60 } 26 61 27 62 return NRK_OK; … … 30 65 31 66 32 voidcontrol_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index )67 uint8_t control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ) 33 68 { 69 uint8_t i,c; 34 70 // 1 byte offset for number of messages 35 71 p->cca_threshold=buf[index*CONTROL_PKT_SIZE]; 36 72 p->ctrl_flags_1=buf[index*CONTROL_PKT_SIZE+1]; 73 p->mobile_reserve_cnt=(((uint16_t)buf[index*CONTROL_PKT_SIZE+2])<<8)|buf[index*CONTROL_PKT_SIZE+3]; 74 p->mobile_reserve_seconds=(((uint16_t)buf[index*CONTROL_PKT_SIZE+4])<<8)|buf[index*CONTROL_PKT_SIZE+5]; 75 p->checksum=buf[index*CONTROL_PKT_SIZE+6]; 76 c=0; 77 for(i=0; i<CONTROL_PKT_SIZE-1; i++ ) 78 { 79 c+=buf[index*CONTROL_PKT_SIZE+i]; 80 printf( "c=%d\r\n",c ); 81 } 82 return c; 37 83 } 38 84 nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.h
r475 r535 6 6 7 7 8 #define CONTROL_PKT_SIZE 2 8 #define CONTROL_PKT_SIZE 7 9 10 #define GLOBAL_DEBUG_MASK 0x01 9 11 10 12 typedef struct control_pkt … … 12 14 uint8_t cca_threshold; // Byte 0 13 15 uint8_t ctrl_flags_1; // Byte 1 16 uint16_t mobile_reserve_cnt; // Byte 2 and 3 17 uint16_t mobile_reserve_seconds; // Byte 4 and 5 18 uint8_t checksum; // Byte 4 and 5 14 19 } CONTROL_PKT_T; 15 20 … … 17 22 18 23 int8_t control_generate(FF_UPSTREAM_PKT_T *pkt, FF_DOWNSTREAM_PKT_T *ds_pkt); 19 void control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ); 24 // This function returns a computed checksum to compare against the normal checksum 25 uint8_t control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ); 20 26 21 27 #endif nano-RK/projects/SAMPL/client/aggregate.c
r506 r535 41 41 ack_aggregate(us_pkt_in, us_pkt ); 42 42 break; 43 case NCK_PKT: 44 nck_aggregate(us_pkt_in, us_pkt ); 45 break; 43 46 case PING_PKT: 44 47 ping_aggregate(us_pkt_in, us_pkt ); nano-RK/projects/SAMPL/client/globals.h
r506 r535 8 8 uint32_t mac_address; 9 9 uint8_t admin_debug_flag; 10 int8_t mobile_reserve; 10 11 11 12 nano-RK/projects/SAMPL/client/main.c
r530 r535 82 82 uint8_t last_flood_rssi; 83 83 84 int8_t mobile_reserve;85 84 86 85 uint8_t aes_key[16]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e, 0x0f}; nano-RK/projects/SAMPL/client/makefile
r510 r535 28 28 SRC += ../app_pkt_handlers/ping_pkt.c 29 29 SRC += ../app_pkt_handlers/ack_pkt.c 30 SRC += ../app_pkt_handlers/nck_pkt.c 30 31 SRC += ../app_pkt_handlers/route_pkt.c 31 32 SRC += ../app_pkt_handlers/trace.c nano-RK/projects/SAMPL/include/sampl.h
r530 r535 82 82 #define WIRELESS_UPDATE_PKT 0x02 83 83 #define ACK_PKT 0x03 84 #define ERROR_PKT 0x0484 #define NCK_PKT 0x04 85 85 #define ROUTE_PKT 0x05 86 86 #define SENSOR_LONG_PKT 0x06
