int main (int argc, char *argv[]) { FILE *fp; uint8_t tx_buf[128]; uint8_t rx_buf[128]; int32_t v,cnt,i,len; uint8_t nav_time_secs, reply_time_secs,checksum; int32_t tmp; time_t reply_timeout,nav_timeout,t; uint8_t cmd,error; char buf[1024]; time_t clockt; uint32_t epocht; SAMPL_GATEWAY_PKT_T gw_pkt; debug_txt_flag=0; if (argc < 3 || argc > 4) { printf ("Usage: server port [-d]\n"); printf (" d Debug Output\n"); exit (1); } if(argc==4) { // Grab dash command line options if(strstr(argv[3],"d")!=NULL ) { debug_txt_flag=1; } } v=slipstream_open(argv[1],atoi(argv[2]),NONBLOCKING); nav_time_secs=25; cnt = 0; while (1) { error=0; cmd=0; // Setup the packet to send out to the network // These values setup the internal data structure and probably don't // need to be changed ds_pkt.payload_len=0; ds_pkt.buf=tx_buf; ds_pkt.buf_len=DS_PAYLOAD_START; ds_pkt.payload_start=DS_PAYLOAD_START; ds_pkt.payload=&(tx_buf[DS_PAYLOAD_START]); // These are parameters that can be adjusted for different packets ds_pkt.pkt_type=CONTROL_PKT; ds_pkt.ctrl_flags= ENCRYPT | DS_MASK | LINK_ACK | DEBUG_FLAG; ds_pkt.seq_num=0; ds_pkt.priority=0; ds_pkt.ack_retry=10; ds_pkt.subnet_mac[0]=0; ds_pkt.subnet_mac[1]=0; ds_pkt.subnet_mac[2]=0; ds_pkt.hop_cnt=0; // Starting depth, always keep at 0 ds_pkt.hop_max=5; // Max tree depth ds_pkt.delay_per_level=1; // Reply delay per level in seconds ds_pkt.nav=30; // Time in seconds until next message to be sent ds_pkt.mac_check_rate=100; // B-mac check rate in ms ds_pkt.rssi_threshold=-40; // Reply RSSI threshold ds_pkt.last_hop_mac=0; ds_pkt.mac_filter_num=0; // Increase if MAC_FILTER is active ds_pkt.aes_ctr[0]=0; // Encryption AES counter ds_pkt.aes_ctr[1]=0; ds_pkt.aes_ctr[2]=0; ds_pkt.aes_ctr[3]=0; clockt = time(NULL); epocht = clockt; ds_pkt.epoch_time[0] = epocht & 0xff; // Epoch time ds_pkt.epoch_time[1] = (epocht>>8) & 0xff; ds_pkt.epoch_time[2] = (epocht>>16) & 0xff; ds_pkt.epoch_time[3] = (epocht>>24) & 0xff; ds_pkt.payload[0]=(-40); ds_pkt.payload[1]=0x01; ds_pkt.payload[2]=0x1f; ds_pkt.payload[3]=0xff; ds_pkt.payload[4]=0x1f; ds_pkt.payload[5]=0xff; checksum=0; for(i=0; i<6; i++ ) checksum+=ds_pkt.payload[i]; ds_pkt.payload[6]=checksum; ds_pkt.payload_len=7; // This takes the structure and packs it into the raw // array that is sent using SLIP pack_downstream_packet( &ds_pkt); // Add MAC filter entries below // downstream_packet_add_mac_filter( &ds_pkt, 2 ); // downstream_packet_add_mac_filter( &ds_pkt, 3 ); // downstream_packet_add_mac_filter( &ds_pkt, 4 ); // downstream_packet_add_mac_filter( &ds_pkt, 5 ); // Print your packet on the screen if(debug_txt_flag==1) print_ds_packet(&ds_pkt ); cnt++; if(error==0) v=slipstream_send(ds_pkt.buf,ds_pkt.buf_len); if(debug_txt_flag==1) { if (v == 0) printf( "Error sending\n" ); else printf( "Sent request %d\n",ds_pkt.seq_num); } nav_time_secs=ds_pkt.nav; reply_time_secs=ds_pkt.delay_per_level * ds_pkt.hop_max; t=time(NULL); reply_timeout=t+reply_time_secs+1; nav_timeout=t+nav_time_secs; // Collect Reply packets while(reply_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } // What for NAV and service incoming messages // This is the time window when the network is idle and can // be used for asynchronous communications. while(nav_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { // Check for mobile/p2p packets gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } } }
int main (int argc, char *argv[]) { FILE *fp; uint8_t tx_buf[128]; uint8_t rx_buf[128]; TRANSDUCER_PKT_T tran_pkt; TRANSDUCER_MSG_T tran_msg; int32_t v,cnt,i,len,j; uint8_t nav_time_secs, reply_time_secs; int32_t tmp; time_t reply_timeout,nav_timeout,t; uint8_t cmd,error; char buf[1024]; char mbuf[128]; uint8_t num_msgs; FF_POWER_RQST_PKT ff_pwr_rqst; uint8_t ff_pwr_mac[10]; SAMPL_GATEWAY_PKT_T gw_pkt; debug_txt_flag=0; if (argc < 4 ) { printf ("Usage: server port num-msgs [mac-addr] [-d]\n"); printf (" ex: ./jigo-ctrl localhost 5000 1 0x000000f0\n"); printf (" mac-addr MAC address of node to request read\n"); printf (" d Debug Output\n"); exit (1); } for(i=0; i<argc; i++ ) { // Grab dash command line options if(strstr(argv[i],"-d")!=NULL ) { debug_txt_flag=1; } } sscanf( argv[3],"%d", &tmp); num_msgs=tmp; if(num_msgs>9 ) { printf( "Sorry, too many messages...\n" ); return 0; } if(debug_txt_flag==1) printf( "Composing %d actuation msgs\n", num_msgs ); for(i=0; i<num_msgs; i++ ) { sscanf( argv[i+4],"%x",&tmp ); subnet_3=(tmp&0xff000000) >> 24; subnet_2=(tmp&0xff0000) >> 16; subnet_1=(tmp&0xff00) >> 8; ff_pwr_mac[i]=(tmp & 0xff); if(debug_txt_flag==1) printf( "MAC_ADDR: 0x%x ",ff_pwr_mac[i]); } v=slipstream_open(argv[1],atoi(argv[2]),NONBLOCKING); nav_time_secs=25; cnt = 0; while (1) { error=0; cmd=0; // Setup the packet to send out to the network // These values setup the internal data structure and probably don't // need to be changed ds_pkt.payload_len=0; ds_pkt.buf=tx_buf; ds_pkt.buf_len=DS_PAYLOAD_START; ds_pkt.payload_start=DS_PAYLOAD_START; ds_pkt.payload=&(tx_buf[DS_PAYLOAD_START]); // These are parameters that can be adjusted for different packets //ds_pkt.pkt_type=PING_PKT; ds_pkt.pkt_type=TRANSDUCER_PKT; ds_pkt.ctrl_flags= DS_MASK | DEBUG_FLAG | ENCRYPT; ds_pkt.seq_num=0; // Use the gateway's spiffy auto-cnt when set to 0 ds_pkt.priority=0; ds_pkt.ack_retry=10; ds_pkt.subnet_mac[0]=subnet_1; ds_pkt.subnet_mac[1]=subnet_2; ds_pkt.subnet_mac[2]=subnet_3; ds_pkt.hop_cnt=0; // Starting depth, always keep at 0 ds_pkt.hop_max=5; // Max tree depth ds_pkt.delay_per_level=1; // Reply delay per level in seconds ds_pkt.nav=0; // Time in seconds until next message to be sent ds_pkt.mac_check_rate=100; // B-mac check rate in ms ds_pkt.rssi_threshold=-45; // Reply RSSI threshold ds_pkt.last_hop_mac=0; ds_pkt.mac_filter_num=0; // Increase if MAC_FILTER is active ds_pkt.aes_ctr[0]=0; // Encryption AES counter ds_pkt.aes_ctr[1]=0; ds_pkt.aes_ctr[2]=0; ds_pkt.aes_ctr[3]=0; // At the top level you have a SAMPL packet (ds_pkt) // For transducers, this holds a single transducer pkt (tran_pkt) // Each transducer packet contains multiple transducer messages (tran_msg) // Transducers typically have helper functions used to pack the transducer messages. // Setup Transducer Packet tran_pkt.num_msgs=0; tran_pkt.checksum=0; tran_pkt.msgs_payload=buf; ff_pwr_rqst.socket=0; ff_pwr_rqst.pkt_type=DEBUG_PKT; for(i=0; i<num_msgs; i++ ) { // Setup Transducer Message tran_msg.mac_addr = ff_pwr_mac[i]; tran_msg.type = TRAN_POWER_PKT; tran_msg.len = 0; tran_msg.payload = mbuf; printf( "calling pack on mac %d\n",ff_pwr_mac[i] ); // Pack application specifc message into transducer message tran_msg.len=ff_power_rqst_pack(mbuf, &ff_pwr_rqst); printf( "calling add\n" ); // Add the transducer message to the transducer packet len=transducer_msg_add( &tran_pkt, &tran_msg); printf( "done with add payload len=%d\n",len ); // printf( "payload = " ); // for(j=0; j<len; j++ ) // printf( "%d ",ds_pkt.payload[j] ); // printf( "\n" ); } // Add the packet to the payload ds_pkt.payload_len = transducer_pkt_pack(&tran_pkt, ds_pkt.payload); // This takes the structure and packs it into the raw // array that is sent using SLIP pack_downstream_packet( &ds_pkt); // Add MAC filter entries below // downstream_packet_add_mac_filter( &ds_pkt, 0x07 ); // downstream_packet_add_mac_filter( &ds_pkt, 3 ); // downstream_packet_add_mac_filter( &ds_pkt, 4 ); // downstream_packet_add_mac_filter( &ds_pkt, 5 ); // Print your packet on the screen if(debug_txt_flag==1) print_ds_packet(&ds_pkt ); cnt++; for(i=0; i<ds_pkt.buf_len; i++ ) { printf( "%02x",ds_pkt.buf[i] ); } printf( "\n" ); if(error==0) v=slipstream_send(ds_pkt.buf,ds_pkt.buf_len); if(debug_txt_flag==1) { if (v == 0) printf( "Error sending\n" ); else printf( "Sent request %d\n",ds_pkt.seq_num); } //nav_time_secs=ds_pkt.nav; nav_time_secs=5; reply_time_secs=ds_pkt.delay_per_level * ds_pkt.hop_max+3; t=time(NULL); reply_timeout=t+reply_time_secs+1; nav_timeout=t+nav_time_secs; // Collect Reply packets while(reply_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } // What for NAV and service incoming messages // This is the time window when the network is idle and can // be used for asynchronous communications. while(nav_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { // Check for mobile/p2p packets gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } // only run once break; } }
int main (int argc, char *argv[]) { FILE *fp; uint8_t tx_buf[128]; uint8_t rx_buf[128]; TRANSDUCER_PKT_T tran_cmd_pkt; TRANSDUCER_MSG_T tran_msg_pkts[10]; int32_t v,cnt,i,len; uint8_t nav_time_secs, reply_time_secs; int32_t tmp; time_t reply_timeout,nav_timeout,t; uint8_t cmd,error; char buf[1024]; uint8_t num_msgs; SAMPL_GATEWAY_PKT_T gw_pkt; debug_txt_flag=0; if (argc < 5 ) { printf ("Usage: server port num-msgs [mac-addr socket state] [-d]\n"); printf (" ex: ./jigo-ctrl localhost 5000 1 0x000000f0 1 on\n"); printf (" mac-addr MAC address of node to actuate\n"); printf (" socket 0 or 1\n"); printf (" state on or off\n"); printf (" d Debug Output\n"); exit (1); } for(i=0; i<argc; i++ ) { // Grab dash command line options if(strstr(argv[i],"-d")!=NULL ) { debug_txt_flag=1; } } sscanf( argv[3],"%d", &num_msgs ); if(num_msgs>9 ) { printf( "Sorry, too many messages...\n" ); return 0; } if(debug_txt_flag==1) printf( "Composing %d actuation msgs\n", num_msgs ); for(i=0; i<num_msgs; i++ ) { sscanf( argv[(i*2)+4],"%x",&tmp ); subnet_3=(tmp&0xff000000) >> 24; subnet_2=(tmp&0xff0000) >> 16; subnet_1=(tmp&0xff00) >> 8; tran_msg_pkts[i].mac_addr=(tmp & 0xff); if(debug_txt_flag==1) printf( "MAC_ADDR: 0x%x ",tran_msg_pkts[i].mac_addr ); sscanf( argv[(i*2)+5],"%s",buf); tran_msg_pkts[i].key=TRAN_LED_BLINK; tran_msg_pkts[i].value=0; if(strstr(buf,"red")!=NULL) tran_msg_pkts[i].value|=TRAN_RED_LED_MASK; if(strstr(buf,"green")!=NULL) tran_msg_pkts[i].value|=TRAN_GREEN_LED_MASK; if(strstr(buf,"blue")!=NULL) tran_msg_pkts[i].value|=TRAN_BLUE_LED_MASK; if(strstr(buf,"orange")!=NULL) tran_msg_pkts[i].value|=TRAN_ORANGE_LED_MASK; } v=slipstream_open(argv[1],atoi(argv[2]),NONBLOCKING); nav_time_secs=25; cnt = 0; while (1) { error=0; cmd=0; // Setup the packet to send out to the network // These values setup the internal data structure and probably don't // need to be changed ds_pkt.payload_len=0; ds_pkt.buf=tx_buf; ds_pkt.buf_len=DS_PAYLOAD_START; ds_pkt.payload_start=DS_PAYLOAD_START; ds_pkt.payload=&(tx_buf[DS_PAYLOAD_START]); // These are parameters that can be adjusted for different packets //ds_pkt.pkt_type=PING_PKT; ds_pkt.pkt_type=TRANSDUCER_CMD_PKT; ds_pkt.ctrl_flags= DS_MASK | ENCRYPT; ds_pkt.seq_num=0; // Use the gateway's spiffy auto-cnt when set to 0 ds_pkt.priority=0; ds_pkt.ack_retry=10; ds_pkt.subnet_mac[0]=subnet_1; ds_pkt.subnet_mac[1]=subnet_2; ds_pkt.subnet_mac[2]=subnet_3; ds_pkt.hop_cnt=0; // Starting depth, always keep at 0 ds_pkt.hop_max=5; // Max tree depth ds_pkt.delay_per_level=0; // Reply delay per level in seconds ds_pkt.nav=0; // Time in seconds until next message to be sent ds_pkt.mac_check_rate=100; // B-mac check rate in ms ds_pkt.rssi_threshold=-45; // Reply RSSI threshold ds_pkt.last_hop_mac=0; ds_pkt.mac_filter_num=0; // Increase if MAC_FILTER is active ds_pkt.aes_ctr[0]=0; // Encryption AES counter ds_pkt.aes_ctr[1]=0; ds_pkt.aes_ctr[2]=0; ds_pkt.aes_ctr[3]=0; //tran_msg_pkts[0].mac_addr=0xf0; //tran_msg_pkts[0].key=TRAN_POWER_CTRL_SOCK_0; //tran_msg_pkts[0].value=SOCKET_OFF; tran_cmd_pkt.num_msgs=num_msgs; tran_cmd_pkt.msg=tran_msg_pkts; ds_pkt.payload_len=transducer_cmd_pkt_add( &tran_cmd_pkt, ds_pkt.payload); transducer_cmd_pkt_checksum( &tran_cmd_pkt, ds_pkt.payload); // This takes the structure and packs it into the raw // array that is sent using SLIP pack_downstream_packet( &ds_pkt); // Add MAC filter entries below // downstream_packet_add_mac_filter( &ds_pkt, 0x07 ); // downstream_packet_add_mac_filter( &ds_pkt, 3 ); // downstream_packet_add_mac_filter( &ds_pkt, 4 ); // downstream_packet_add_mac_filter( &ds_pkt, 5 ); // Print your packet on the screen if(debug_txt_flag==1) print_ds_packet(&ds_pkt ); cnt++; for(i=0; i<ds_pkt.buf_len; i++ ) { printf( "%02x",ds_pkt.buf[i] ); } printf( "\n" ); if(error==0) v=slipstream_send(ds_pkt.buf,ds_pkt.buf_len); if(debug_txt_flag==1) { if (v == 0) printf( "Error sending\n" ); else printf( "Sent request %d\n",ds_pkt.seq_num); } //nav_time_secs=ds_pkt.nav; nav_time_secs=5; reply_time_secs=ds_pkt.delay_per_level * ds_pkt.hop_max; t=time(NULL); reply_timeout=t+reply_time_secs+1; nav_timeout=t+nav_time_secs; // Collect Reply packets while(reply_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } // What for NAV and service incoming messages // This is the time window when the network is idle and can // be used for asynchronous communications. while(nav_timeout>time(NULL)) { v=slipstream_receive( rx_buf); if (v > 0) { // Check for mobile/p2p packets gw_pkt.buf=rx_buf; gw_pkt.buf_len=v; print_gw_packet_elements(&gw_pkt); } usleep(1000); } // only run once break; } }