Changeset 535

Show
Ignore:
Timestamp:
04/23/08 13:40:34 (6 months ago)
Author:
agr
Message:

sampl control pkt update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.c

    r506 r535  
    55#include <control_pkt.h> 
    66#include <ack_pkt.h> 
     7#include <nck_pkt.h> 
    78 
    89 
     
    1011{ 
    1112ACK_PKT_T p; 
     13NCK_PKT_T n; 
    1214CONTROL_PKT_T r; 
    13 uint8_t num_pkts,i,selected; 
     15uint8_t num_pkts,i,selected,checksum; 
     16nrk_time_t t; 
    1417 
    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); 
    1728  // add route persistence here... 
    18   // add reservation control 
    19   // add debugging enable / disable 
    2029 
    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 
    2243  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); 
    2445  pkt->num_msgs=1; 
    2546  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  } 
    2661 
    2762return NRK_OK;   
     
    3065 
    3166 
    32 void control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ) 
     67uint8_t control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ) 
    3368{ 
     69uint8_t i,c; 
    3470   // 1 byte offset for number of messages 
    3571   p->cca_threshold=buf[index*CONTROL_PKT_SIZE]; 
    3672   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; 
     77for(i=0; i<CONTROL_PKT_SIZE-1; i++ )    
     78{ 
     79        c+=buf[index*CONTROL_PKT_SIZE+i]; 
     80printf( "c=%d\r\n",c ); 
     81} 
     82  return c; 
    3783} 
    3884 
  • nano-RK/projects/SAMPL/app_pkt_handlers/control_pkt.h

    r475 r535  
    66 
    77 
    8 #define CONTROL_PKT_SIZE        2 
     8#define CONTROL_PKT_SIZE        7 
     9 
     10#define GLOBAL_DEBUG_MASK       0x01     
    911 
    1012typedef struct control_pkt  
     
    1214        uint8_t cca_threshold;  // Byte 0 
    1315        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 
    1419} CONTROL_PKT_T; 
    1520 
     
    1722 
    1823int8_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 
     25uint8_t control_pkt_get( CONTROL_PKT_T *p, uint8_t *buf, uint8_t index ); 
    2026 
    2127#endif 
  • nano-RK/projects/SAMPL/client/aggregate.c

    r506 r535  
    4141        ack_aggregate(us_pkt_in, us_pkt );       
    4242        break; 
     43  case NCK_PKT: 
     44        nck_aggregate(us_pkt_in, us_pkt );       
     45        break; 
    4346  case PING_PKT: 
    4447        ping_aggregate(us_pkt_in, us_pkt );      
  • nano-RK/projects/SAMPL/client/globals.h

    r506 r535  
    88uint32_t mac_address; 
    99uint8_t admin_debug_flag; 
     10int8_t mobile_reserve; 
    1011 
    1112 
  • nano-RK/projects/SAMPL/client/main.c

    r530 r535  
    8282uint8_t last_flood_rssi; 
    8383 
    84 int8_t mobile_reserve; 
    8584 
    8685uint8_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  
    2828SRC += ../app_pkt_handlers/ping_pkt.c 
    2929SRC += ../app_pkt_handlers/ack_pkt.c 
     30SRC += ../app_pkt_handlers/nck_pkt.c 
    3031SRC += ../app_pkt_handlers/route_pkt.c 
    3132SRC += ../app_pkt_handlers/trace.c 
  • nano-RK/projects/SAMPL/include/sampl.h

    r530 r535  
    8282#define  WIRELESS_UPDATE_PKT    0x02 
    8383#define  ACK_PKT                0x03 
    84 #define  ERROR_PKT            0x04 
     84#define  NCK_PKT              0x04 
    8585#define  ROUTE_PKT              0x05 
    8686#define  SENSOR_LONG_PKT        0x06