Changeset 559

Show
Ignore:
Timestamp:
04/29/08 19:12:09 (2 weeks ago)
Author:
agr
Message:

SAMPL update

Files:

Legend:

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

    r558 r559  
    357357    } 
    358358    // This is a NEW downstream flood packet 
    359     else if (downstream == 1 &&  check_subnet(p2p_pkt_in.subnet_mac, my_subnet_mac )==1 ) { 
     359    else if (downstream == 1 &&  check_subnet(ds_pkt.subnet_mac, my_subnet_mac )==1 ) { 
    360360        // Got downstream message from someone in subnet, so add to neighbor list  
    361361        neighbor_list_add( ds_pkt.last_hop_mac, ds_pkt.rssi, neighborlist_ttl ); 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/ff_config.txt

    r538 r559  
    2828# Sensor Short with LED 
    2929# 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x78 0x64 0xd3 0x00 0x00 0x00 0x00 0x00 
    30 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x10 0x64 0xd3 0x00 0x00 0x00 0x00 0x00 
     30# 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x78 0x64 0xd3 0x00 0x00 0x00 0x00 0x00 
     310x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x10 0x32 0xd3 0x00 0x00 0x00 0x00 0x00 
    3132 
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/main.c

    r548 r559  
    1515#include "xmpp_pkt_writer.h" 
    1616 
     17#define SEQ_CACHE_SIZE  24 
    1718 
    1819#define IGNORE_PACKET   0 
     
    2021#define P2P_PACKET      2 
    2122 
     23#define gw_subnet_2     0 
     24#define gw_subnet_1     0 
     25#define gw_subnet_0     0 
    2226#define gw_mac          0 
    23  
    2427 
    2528 
     
    4043  int size; 
    4144  char buffer[2048]; 
     45 
     46 
     47void seq_num_cache_init(); 
     48int seq_num_cache_check( uint8_t *mac_addr, uint8_t seq_num, uint8_t pkt_type); 
     49 
     50typedef struct seq_num_cache { 
     51  uint8_t addr[4]; 
     52  uint8_t seq_num; 
     53  uint8_t pkt_type; 
     54  int valid; 
     55} seq_num_cache_t; 
     56 
     57seq_num_cache_t seq_cache[SEQ_CACHE_SIZE]; 
    4258 
    4359SAMPL_DOWNSTREAM_PKT_T ds_pkt; 
     
    181197  // clear list of nodes 
    182198  node_list_init(); 
     199  seq_num_cache_init(); 
    183200 
    184201  sscanf(username,"%[^@]",name); 
     
    305322int i,ret; 
    306323int pkt_type; 
     324uint8_t mac[4]; 
    307325char node_name[MAX_NODE_LEN]; 
    308326SAMPL_GATEWAY_PKT_T gw_pkt; 
     
    324342else pkt_type=IGNORE_PACKET; 
    325343 
    326  
     344mac[3]=rx_buf[SUBNET_MAC_2]; 
     345mac[2]=rx_buf[SUBNET_MAC_1]; 
     346mac[1]=rx_buf[SUBNET_MAC_0]; 
     347mac[0]=rx_buf[GW_SRC_MAC]; 
     348 
     349// Check if it is a repeat packet 
     350if( seq_num_cache_check( mac , rx_buf[SEQ_NUM],rx_buf[PKT_TYPE])==1)  
     351
     352        if(debug_txt_flag==1) printf( "DUPLICATE PACKET!\n" ); 
     353                sprintf(node_name,"%02x%02x%02x%02x",rx_buf[SUBNET_MAC_2], 
     354                                rx_buf[SUBNET_MAC_1], 
     355                                rx_buf[SUBNET_MAC_0], 
     356                                rx_buf[GW_SRC_MAC] );  
     357                printf( "mac=%s seq_num=%d type=%d\n",node_name, rx_buf[SEQ_NUM],rx_buf[PKT_TYPE]); 
     358} else 
     359
    327360  // Create an event node if it doesn't already exist and if it is an infrastructure node 
    328361 
     
    358391        send_xmpp_ping_pkt( &gw_pkt ); 
    359392        if(debug_txt_flag==1) printf( "PING or ACK packet\n" ); 
    360  
    361                 break; 
     393        break; 
    362394 
    363395        case XMPP_PKT: 
    364396        xmpp_pkt_handler( &gw_pkt ); 
    365397        if(debug_txt_flag==1) printf( "XMPP packet\n" ); 
    366  
    367                 break; 
     398        break; 
     399 
     400 
     401        case EXTENDED_NEIGHBOR_LIST_PKT: 
     402        extended_nlist_pkt_handler( &gw_pkt ); 
     403        if(debug_txt_flag==1) printf( "Extended Neighbor List packet\n" ); 
     404        break; 
     405 
     406 
    368407        case FF_SENSOR_SHORT_PKT: 
    369408        send_xmpp_sensor_short_pkt( &gw_pkt ); 
    370409        if(debug_txt_flag==1) printf( "SENSOR_SHORT packet\n" ); 
    371  
    372                 break; 
     410        break; 
    373411 
    374412        case TRACEROUTE_PKT: 
    375413        if(debug_txt_flag==1) printf( "TRACEROUTE packet\n" ); 
    376  
    377                 break; 
     414        break; 
     415 
     416 
    378417        default: 
    379418        if(debug_txt_flag==1) printf( "Unknown Packet\n" ); 
    380419} 
    381          
     420
     421 
    382422} 
    383423 
     
    425465} 
    426466 
    427  
     467void seq_num_cache_init() 
     468
     469int i; 
     470for(i=0; i<SEQ_CACHE_SIZE; i++ ) seq_cache[i].valid=0; 
     471
     472 
     473int seq_num_cache_check( uint8_t *mac_addr, uint8_t seq_num, uint8_t pkt_type) 
     474
     475int i,j; 
     476int match; 
     477 
     478/* 
     479for(i=0; i<SEQ_CACHE_SIZE; i++ ) 
     480        { 
     481        if(seq_cache[i].valid!=0) printf( "cache %d: mac %02x%02x%02x%02x seq=%d type=%d ttl=%d\n", 
     482        i, seq_cache[i].addr[3],seq_cache[i].addr[2],seq_cache[i].addr[1], 
     483        seq_cache[i].addr[0],seq_cache[i].seq_num, seq_cache[i].pkt_type, seq_cache[i].valid ); 
     484        } 
     485*/ 
     486 
     487// This is to stop caching SAMPL reply packets. 
     488// Reply packets all come from the gateway with the same 
     489// seq number and packet type 
     490  if( mac_addr[0]==gw_mac && 
     491    mac_addr[1]==gw_subnet_2 && 
     492    mac_addr[2]==gw_subnet_1 && 
     493    mac_addr[3]==gw_subnet_0 ) return 0; 
     494 
     495for(i=0; i<SEQ_CACHE_SIZE; i++ ) 
     496
     497  if(seq_cache[i].valid>0) 
     498  { 
     499  seq_cache[i].valid--; 
     500  if( mac_addr[0]==seq_cache[i].addr[0] && 
     501    mac_addr[1]==seq_cache[i].addr[1] && 
     502    mac_addr[2]==seq_cache[i].addr[2] && 
     503    mac_addr[3]==seq_cache[i].addr[3] ) 
     504        {        
     505        seq_cache[i].valid=100; 
     506        // This is a repeat packet 
     507        if(seq_num==seq_cache[i].seq_num && pkt_type==seq_cache[i].pkt_type)  
     508        { 
     509                return 1; 
     510 
     511        } 
     512        else 
     513                { 
     514                        seq_cache[i].seq_num=seq_num; 
     515                        seq_cache[i].pkt_type=pkt_type; 
     516                        return 0; 
     517                } 
     518        } 
     519  } 
     520 
     521
     522 
     523 
     524for(i=0; i<SEQ_CACHE_SIZE; i++ ) 
     525
     526  if(seq_cache[i].valid==0) 
     527  { 
     528  seq_cache[i].addr[0]=mac_addr[0]; 
     529  seq_cache[i].addr[1]=mac_addr[1]; 
     530  seq_cache[i].addr[2]=mac_addr[2]; 
     531  seq_cache[i].addr[3]=mac_addr[3]; 
     532  seq_cache[i].seq_num=seq_num; 
     533  seq_cache[i].pkt_type=pkt_type; 
     534  seq_cache[i].valid=100; 
     535  return 0; 
     536  } 
     537
     538 
     539return 0; 
     540
  • nano-RK/projects/SAMPL/slip-clients/xmpp-client/xmpp_pkt_writer.c

    r548 r559  
    1010#include <ack_pkt.h> 
    1111#include <ff_basic_sensor_pkt.h> 
     12 
     13char buf[1024]; 
    1214 
    1315void xmpp_pkt_handler(SAMPL_GATEWAY_PKT_T *gw_pkt) 
     
    2830} 
    2931 
     32void extended_nlist_pkt_handler(SAMPL_GATEWAY_PKT_T *gw_pkt) 
     33{ 
     34char node_name[MAX_NODE_LEN]; 
     35uint8_t num_msgs,i; 
     36char timeStr[64]; 
     37time_t timestamp; 
     38int8_t rssi; 
     39 
     40        sprintf(node_name,"%02x%02x%02x%02x",gw_pkt->subnet_mac[2], 
     41                gw_pkt->subnet_mac[1], 
     42                gw_pkt->subnet_mac[0], 
     43                gw_pkt->src_mac); 
     44 
     45        // Check nodes and add them if need be 
     46        if(xmpp_flag==1) check_and_create_node(node_name); 
     47        // publish XML data for node 
     48        time(&timestamp); 
     49        strftime(timeStr,100,"%Y-%m-%d %X",localtime(&timestamp)); 
     50 
     51        sprintf(buf,"<Node id=\"%s\" type=\"FIREFLY\" timestamp=\"%s\">", node_name,timeStr ); 
     52 
     53        num_msgs=gw_pkt->payload[0]; 
     54        printf( "Extended Neighbor List %d:\n", num_msgs );  
     55        for(i=0; i<num_msgs; i++ ) 
     56        { 
     57        sprintf( node_name,"%02x%02x%02x%02x",gw_pkt->payload[1+i*5], 
     58                gw_pkt->payload[1+i*5+1], 
     59                gw_pkt->payload[1+i*5+2], 
     60                gw_pkt->payload[1+i*5+3] ); 
     61        rssi=(int8_t)gw_pkt->payload[1+i*5+4]; 
     62        sprintf( &buf[strlen(buf)],"<Link linkNode=\"%s\" rssi=\"%d\"/>",node_name,rssi ); 
     63        } 
     64        sprintf( &buf[strlen(buf)],"</Node>" ); 
     65         
     66        if(debug_txt_flag==1 ) printf( "Publish: %s\n",buf); 
     67//      if(xmpp_flag==1 ) ret = publish_to_node(node_name,buf); 
     68//      if(xmpp_flag && ret!=XMPP_NO_ERROR) printf( "XMPP Error: %s\n",ERROR_MESSAGE(ret)); 
     69 
     70 
     71        if(debug_txt_flag==1) printf( "Publish done\n"); 
     72} 
     73 
     74 
     75 
    3076 
    3177void send_xmpp_ping_pkt(SAMPL_GATEWAY_PKT_T *gw_pkt ) 
     
    3379PING_PKT_T p; 
    3480char node_name[MAX_NODE_LEN]; 
    35 char buf[1024]; 
    3681char timeStr[64]; 
    3782time_t timestamp; 
     
    66111FF_SENSOR_SHORT_PKT_T p; 
    67112char node_name[MAX_NODE_LEN]; 
    68 char buf[1024]; 
    69113char timeStr[64]; 
    70114time_t timestamp; 
     
    73117for(i=0; i<gw_pkt->num_msgs; i++ ) 
    74118  { 
    75    printf( "process %d\n",i ); 
    76119        sensor_short_pkt_get(&p, gw_pkt->payload, i); 
    77         printf( "s1 " ); 
    78120        sprintf(node_name,"%02x%02x%02x%02x",gw_pkt->subnet_mac[2], 
    79121                gw_pkt->subnet_mac[1], 
    80122                gw_pkt->subnet_mac[0], 
    81123                p.mac_addr);  
    82         printf( "s2 " ); 
    83124        if(debug_txt_flag==1) printf( "Data for node: %s\n",node_name ); 
    84125        // Check nodes and add them if need be 
     
    87128        time(&timestamp); 
    88129        strftime(timeStr,100,"%Y-%m-%d %X",localtime(&timestamp)); 
    89         printf( "s3 " ); 
    90130 
    91131        error=0; 
     
    100140        } 
    101141 
    102         printf( "s4 " ); 
    103142        if(error==0) 
    104143        { 
     
    109148        }        
    110149  } 
    111 printf( "done\n" ); 
    112150} 
    113151