Changeset 559
- Timestamp:
- 04/29/08 19:12:09 (2 weeks ago)
- Files:
-
- nano-RK/projects/SAMPL/client/main.c (modified) (1 diff)
- nano-RK/projects/SAMPL/slip-clients/xmpp-client/ff_config.txt (modified) (1 diff)
- nano-RK/projects/SAMPL/slip-clients/xmpp-client/main.c (modified) (8 diffs)
- nano-RK/projects/SAMPL/slip-clients/xmpp-client/xmpp_pkt_writer.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nano-RK/projects/SAMPL/client/main.c
r558 r559 357 357 } 358 358 // 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 ) { 360 360 // Got downstream message from someone in subnet, so add to neighbor list 361 361 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 28 28 # Sensor Short with LED 29 29 # 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 31 0x01 0x01 0xb9 0x07 0x00 0xf0 0x00 0x00 0x00 0x00 0x00 0x06 0x01 0x10 0x32 0xd3 0x00 0x00 0x00 0x00 0x00 31 32 nano-RK/projects/SAMPL/slip-clients/xmpp-client/main.c
r548 r559 15 15 #include "xmpp_pkt_writer.h" 16 16 17 #define SEQ_CACHE_SIZE 24 17 18 18 19 #define IGNORE_PACKET 0 … … 20 21 #define P2P_PACKET 2 21 22 23 #define gw_subnet_2 0 24 #define gw_subnet_1 0 25 #define gw_subnet_0 0 22 26 #define gw_mac 0 23 24 27 25 28 … … 40 43 int size; 41 44 char buffer[2048]; 45 46 47 void seq_num_cache_init(); 48 int seq_num_cache_check( uint8_t *mac_addr, uint8_t seq_num, uint8_t pkt_type); 49 50 typedef 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 57 seq_num_cache_t seq_cache[SEQ_CACHE_SIZE]; 42 58 43 59 SAMPL_DOWNSTREAM_PKT_T ds_pkt; … … 181 197 // clear list of nodes 182 198 node_list_init(); 199 seq_num_cache_init(); 183 200 184 201 sscanf(username,"%[^@]",name); … … 305 322 int i,ret; 306 323 int pkt_type; 324 uint8_t mac[4]; 307 325 char node_name[MAX_NODE_LEN]; 308 326 SAMPL_GATEWAY_PKT_T gw_pkt; … … 324 342 else pkt_type=IGNORE_PACKET; 325 343 326 344 mac[3]=rx_buf[SUBNET_MAC_2]; 345 mac[2]=rx_buf[SUBNET_MAC_1]; 346 mac[1]=rx_buf[SUBNET_MAC_0]; 347 mac[0]=rx_buf[GW_SRC_MAC]; 348 349 // Check if it is a repeat packet 350 if( 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 { 327 360 // Create an event node if it doesn't already exist and if it is an infrastructure node 328 361 … … 358 391 send_xmpp_ping_pkt( &gw_pkt ); 359 392 if(debug_txt_flag==1) printf( "PING or ACK packet\n" ); 360 361 break; 393 break; 362 394 363 395 case XMPP_PKT: 364 396 xmpp_pkt_handler( &gw_pkt ); 365 397 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 368 407 case FF_SENSOR_SHORT_PKT: 369 408 send_xmpp_sensor_short_pkt( &gw_pkt ); 370 409 if(debug_txt_flag==1) printf( "SENSOR_SHORT packet\n" ); 371 372 break; 410 break; 373 411 374 412 case TRACEROUTE_PKT: 375 413 if(debug_txt_flag==1) printf( "TRACEROUTE packet\n" ); 376 377 break; 414 break; 415 416 378 417 default: 379 418 if(debug_txt_flag==1) printf( "Unknown Packet\n" ); 380 419 } 381 420 } 421 382 422 } 383 423 … … 425 465 } 426 466 427 467 void seq_num_cache_init() 468 { 469 int i; 470 for(i=0; i<SEQ_CACHE_SIZE; i++ ) seq_cache[i].valid=0; 471 } 472 473 int seq_num_cache_check( uint8_t *mac_addr, uint8_t seq_num, uint8_t pkt_type) 474 { 475 int i,j; 476 int match; 477 478 /* 479 for(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 495 for(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 524 for(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 539 return 0; 540 } nano-RK/projects/SAMPL/slip-clients/xmpp-client/xmpp_pkt_writer.c
r548 r559 10 10 #include <ack_pkt.h> 11 11 #include <ff_basic_sensor_pkt.h> 12 13 char buf[1024]; 12 14 13 15 void xmpp_pkt_handler(SAMPL_GATEWAY_PKT_T *gw_pkt) … … 28 30 } 29 31 32 void extended_nlist_pkt_handler(SAMPL_GATEWAY_PKT_T *gw_pkt) 33 { 34 char node_name[MAX_NODE_LEN]; 35 uint8_t num_msgs,i; 36 char timeStr[64]; 37 time_t timestamp; 38 int8_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(×tamp); 49 strftime(timeStr,100,"%Y-%m-%d %X",localtime(×tamp)); 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 30 76 31 77 void send_xmpp_ping_pkt(SAMPL_GATEWAY_PKT_T *gw_pkt ) … … 33 79 PING_PKT_T p; 34 80 char node_name[MAX_NODE_LEN]; 35 char buf[1024];36 81 char timeStr[64]; 37 82 time_t timestamp; … … 66 111 FF_SENSOR_SHORT_PKT_T p; 67 112 char node_name[MAX_NODE_LEN]; 68 char buf[1024];69 113 char timeStr[64]; 70 114 time_t timestamp; … … 73 117 for(i=0; i<gw_pkt->num_msgs; i++ ) 74 118 { 75 printf( "process %d\n",i );76 119 sensor_short_pkt_get(&p, gw_pkt->payload, i); 77 printf( "s1 " );78 120 sprintf(node_name,"%02x%02x%02x%02x",gw_pkt->subnet_mac[2], 79 121 gw_pkt->subnet_mac[1], 80 122 gw_pkt->subnet_mac[0], 81 123 p.mac_addr); 82 printf( "s2 " );83 124 if(debug_txt_flag==1) printf( "Data for node: %s\n",node_name ); 84 125 // Check nodes and add them if need be … … 87 128 time(×tamp); 88 129 strftime(timeStr,100,"%Y-%m-%d %X",localtime(×tamp)); 89 printf( "s3 " );90 130 91 131 error=0; … … 100 140 } 101 141 102 printf( "s4 " );103 142 if(error==0) 104 143 { … … 109 148 } 110 149 } 111 printf( "done\n" );112 150 } 113 151
