/*---------------------------------------------------------------------------*/ void stunicast_open(struct stunicast_conn *c, uint16_t channel, const struct stunicast_callbacks *u) { unicast_open(&c->c, channel, &stunicast); c->u = u; }
/*---------------------------------------------------------------------------*/ void multihop_open(struct multihop_conn *c, uint16_t channel, const struct multihop_callbacks *callbacks) { unicast_open(&c->c, channel, &data_callbacks); channel_set_attributes(channel, attributes); c->cb = callbacks; }
PROCESS_THREAD(deluge_process, ev, data) { static struct etimer et; static unsigned time_counter; static unsigned r_rand; PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); deluge_event = process_alloc_event(); broadcast_open(&deluge_broadcast, DELUGE_BROADCAST_CHANNEL, &broadcast_call); unicast_open(&deluge_uc, DELUGE_UNICAST_CHANNEL, &unicast_call); r_interval = T_LOW; PRINTF("Maintaining state for object %s of %d pages\n", current_object.filename, OBJECT_PAGE_COUNT(current_object)); deluge_state = DELUGE_STATE_MAINTAIN; for(r_interval = T_LOW;;) { if(neighbor_inconsistency) { /* Deluge M.2 */ r_interval = T_LOW; neighbor_inconsistency = 0; } else { /* Deluge M.3 */ r_interval = (2 * r_interval >= T_HIGH) ? T_HIGH : 2 * r_interval; } r_rand = r_interval / 2 + ((unsigned)random_rand() % (r_interval / 2)); recv_adv = 0; old_summary = 0; /* Deluge M.1 */ ctimer_set(&summary_timer, r_rand * CLOCK_SECOND, (void *)(void *)advertise_summary, ¤t_object); /* Deluge M.4 */ ctimer_set(&profile_timer, r_rand * CLOCK_SECOND, (void *)(void *)send_profile, ¤t_object); LONG_TIMER(et, time_counter, r_interval); } exit: unicast_close(&deluge_uc); broadcast_close(&deluge_broadcast); if(current_object.cfs_fd >= 0) { cfs_close(current_object.cfs_fd); } if(current_object.pages != NULL) { free(current_object.pages); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ error_t bcp_forwarding_engine_init() { //Initialize the queues, stacks, and pools // memb_init(&send_stack_mem); // memb_init(&snoop_queue_mem); // memb_init(&send_stack_mem); // memb_init(&send_stack_mem); pmesg(200, "%s :: %s :: Line #%d\n", __FILE__, __func__, __LINE__); list_init(send_stack); list_init(snoop_queue); list_init(q_entry_pool); list_init(message_pool); list_init(snoop_pool); //Initialize defaults beaconSending = false; extraBeaconSending = false; isRunningForwardingEngine = false; sending = false; radioOn = false; seqno = 0; nullSeqNo = 0; beaconHdr = &beaconMsgBuffer; //call BeaconSend.getPayload(&beaconMsgBuffer, call BeaconSend.maxPayloadLength()); dataCRCSuccessCount = 0; dataCRCFailCount = 0; snoopCRCSuccessCount = 0; snoopCRCFailCount = 0; sendQeOccupied = false; virtualQueueSize = 0; localTXCount = 0; loopbackMsgPtr = &loopbackMsg; rimeaddr_copy(¬ifyBurstyLinkNeighbor_m, &rimeaddr_node_addr); latestForwardedTableInit(); process_start(&sendDataTask, NULL); //start the sendDataTask process_start(&sendBeaconTask, NULL); //start the sendBeaconTask clock_init(); //initialie clock for use in random_rand() random_init(clock_time()); //provide seed to RNG #ifndef BEACON_ONLY process_start(&snoopHandlerTask, NULL); //start the snoopHandlerTask #endif //Open connections broadcast_open(&broadcast, 129, &broadcast_call); unicast_open(&unicast, 130, &unicast_callbacks); //Register for callbacks register_cb_set_next_hop_address(routerForwarder_setNextHopAddress); register_cb_set_notify_bursty_neighbor(routerForwarder_setNotifyBurstyLinkNeighbor); return SUCCESS; }
PROCESS_THREAD(main_process, ev, data) { static struct etimer et; static int i; static struct application_struct new_task; PROCESS_BEGIN(); broadcast_open(&broadcast, 129, &broadcast_call); unicast_open(&uc, 146, &unicast_callbacks); saved_seq_numbers[node_id -1]=0; for(i=0; i<24;i++){ //hourly_load[i]=0; //state[i]=0; } etimer_set(&et, CLOCK_SECOND * 2 + random_rand() % (CLOCK_SECOND * 2)); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); new_task.load=node_id; new_task.lower_slot=1; new_task.upper_slot=2; process_start(&schedule_task,&new_task); /* Shared_Write(node_id,node_id+5); PROCESS_WAIT_EVENT_UNTIL(ev == event_2pc_to_comm ); printf("ouf\n"); printf(" load at slot %d is %d\n",node_id,hourly_load[node_id]); Shared_Comp_and_Swap(node_id,10,node_id+7); PROCESS_WAIT_EVENT_UNTIL(ev == event_2pc_to_comm ); printf("ouf2\n"); printf(" load at slot %d is %d\n",node_id,hourly_load[node_id]); if(!(strcmp(data,"BCAST_S"))){ printf("Comp and Swap was succ\n"); } else{ printf("Comp and Swap was not succ\n"); } */ //process_start(&start_2pc_process,&new_msg); //event_start_bcast = process_alloc_event(); //process_post(&start_2pc_process,event_start_bcast,NULL); //process_start(&start_2pc_process,&new_msg); //process_start(&start_2pc_process,NULL); //process_post(&start_2pc_process,NULL,&new_msg); while(1) PROCESS_WAIT_EVENT(); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void shell_rime_debug_init(void) { unicast_open(&uc, SHELL_RIME_CHANNEL_UNICAST, &unicast_callbacks); broadcast_open(&broadcast, SHELL_RIME_CHANNEL_BROADCAST, &broadcast_callbacks); shell_register_command(&broadcast_command); shell_register_command(&unicast_command); }
/*---------------------------------------------------------------------------*/ void route_discovery_open(struct route_discovery_conn *c, clock_time_t time, uint16_t channels, const struct route_discovery_callbacks *callbacks) { netflood_open(&c->rreqconn, time, channels + 0, &rreq_callbacks); unicast_open(&c->rrepconn, channels + 1, &rrep_callbacks); c->cb = callbacks; }
/*---------------------------------------------------------------------------*/ void shell_netperf_init(void) { runicast_open(&ctrl, SHELL_RIME_CHANNEL_NETPERF, &runicast_callbacks); broadcast_open(&broadcast, SHELL_RIME_CHANNEL_NETPERF + 1, &broadcast_callbacks); unicast_open(&unicast, SHELL_RIME_CHANNEL_NETPERF + 2, &unicast_callbacks); mesh_open(&mesh, SHELL_RIME_CHANNEL_NETPERF + 3, &mesh_callbacks); rucb_open(&rucb, SHELL_RIME_CHANNEL_NETPERF + 5, &rucb_callbacks); shell_register_command(&netperf_command); }
/*---------------------------------------------------------------------------*/ void route_discovery_expicit_open(struct route_discovery_conn *c, clock_time_t time, uint16_t netflood_channel, uint16_t unicast_channel, const struct route_discovery_callbacks *callbacks) { netflood_open(&c->rreqconn, time, netflood_channel, &rreq_callbacks); unicast_open(&c->rrepconn, unicast_channel, &rrep_callbacks); c->cb = callbacks; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rime_unicast_sender, ev, data) { PROCESS_EXITHANDLER(unicast_close(&uc)); PROCESS_BEGIN(); unicast_open(&uc, 146, &unicast_callbacks); // channel = 145 while(1){ PROCESS_YIELD(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(example_unicast_process, ev, data) { static int i = 0; static struct etimer et; PROCESS_EXITHANDLER(unicast_close(&uc)); PROCESS_BEGIN(); unicast_open(&uc, 128, &unicast_callbacks); printf("rimeaddr_node_addr = [%u, %u]\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1]); /* Put receiver node in listening mode */ if (rimeaddr_node_addr.u8[0] == receiver_node_rime_addr[0] && rimeaddr_node_addr.u8[1] == receiver_node_rime_addr[1]) { /* * Exit process * Received messages handled by 'recv_uc(...)' */ printf("Receiver node listening\n"); } else { /* Sending messages */ printf("Write a character on serial link to send message\n"); PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message); etimer_set(&et, 1 * CLOCK_SECOND); while (1) { char msg[64]; int len; rimeaddr_t addr; PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); len = 1 + sprintf(msg, "hello world #%u", i); i++; packetbuf_copyfrom(msg, len); addr.u8[0] = receiver_node_rime_addr[0]; addr.u8[1] = receiver_node_rime_addr[1]; unicast_send(&uc, &addr); printf("unicast message sent [%i bytes]\n", len); etimer_reset(&et); } } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(hello_world_process, ev, data) { PROCESS_EXITHANDLER(unicast_close(&uc)) PROCESS_BEGIN(); printf("Hello, world\n"); //linkaddr_set_node_addr(&server); print_rime_address(); unicast_open(&uc, 0x17, &uc_rx); for(;;) { PROCESS_YIELD(); } PROCESS_END(); }
/*---------------------------------------------------------------------------*/ void uip_over_mesh_init(uint16_t channels) { PRINTF("Our address is %d.%d (%d.%d.%d.%d)\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], uip_hostaddr.u8[0], uip_hostaddr.u8[1], uip_hostaddr.u8[2], uip_hostaddr.u8[3]); unicast_open(&dataconn, channels, &data_callbacks); route_discovery_open(&route_discovery, ROUTE_DISCOVERY_INTERVAL, channels + 1, &rdc); trickle_open(&gateway_announce_conn, ROUTE_TRICKLE_INTERVAL, channels + 3, &trickle_call); route_init(); /* Set lifetime to 30 seconds for non-refreshed routes. */ route_set_lifetime(30); }
PROCESS_THREAD(sensys_tx, ev, data) { PROCESS_EXITHANDLER() PROCESS_BEGIN(); // Initial configurations on CC2420 and resetting the timer leds_off(LEDS_ALL); cc2420_set_txpower(POWER); cc2420_set_channel(CHANNEL_SENDER); unicast_open(&uc, RIME_SENDER, &unicast_callbacks); ctimer_stop(&timer1); // Ready to send... leds_on(LEDS_BLUE); while(1) { PROCESS_WAIT_EVENT(); } PROCESS_END(); }
PROCESS_THREAD(send_process, ev, data) { static struct etimer et; linkaddr_t addr; PROCESS_BEGIN(); unicast_open(&uc, 128, &unicast_call); while(1){ etimer_set(&et, CLOCK_SECOND); PROCESS_WAIT_UNTIL(etimer_expired(&et)); leds_toggle(LEDS_BLUE); packetbuf_copyfrom("hellohellohellohellohello", 30); addr.u8[0] = 1; addr.u8[1] = 0; printf("unicast sending\n"); unicast_send(&uc, &addr); } PROCESS_END(); }
PROCESS_THREAD(shell_uc_open_process, ev, data) { uint16_t channel; long channel_long; const char *next; char buf[6]; PROCESS_BEGIN(); channel_long = shell_strtolong((char *)data, &next); if(channel_long <= 0 || channel_long > 65535){ shell_output_str(&uc_open_command, "channel has to be in range of [1-65535]", ""); PROCESS_EXIT(); } channel = (uint16_t) channel_long; snprintf(buf, sizeof(buf), "%d", channel); struct unicast_entry *to_add = memb_alloc(&unicast_mem); list_add(unicast_list, to_add); to_add->channel = channel; unicast_open(&to_add->c, channel, &unicast_callback); shell_output_str(&uc_open_command, "opened unicast connection on channel: ", buf); PROCESS_END(); }
PROCESS_THREAD(rime_unicast_sender, ev, data) { PROCESS_EXITHANDLER(unicast_close(&uc)); PROCESS_BEGIN(); leds_init(); leds_off(LEDS_ALL); SENSORS_ACTIVATE(button_sensor);//activate button unicast_open(&uc, 290, &unicast_callbacks); // channel = 122 while(1) { static struct etimer et; rimeaddr_t addr; PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor); //etimer_set(&et, CLOCK_SECOND); //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); packetbuf_copyfrom(SECRET, 15); // String + Length to be send //packetbuf_copyfrom("ekhais8ca6Aej0", 15); // String + Length to be send addr.u8[0] = 0x28; // Address of receiving Node addr.u8[1] = 0x1; if(!rimeaddr_cmp(&addr, &rimeaddr_node_addr)) { printf("Message sent\n"); // debug message unicast_send(&uc, &addr); } } PROCESS_END(); }
void open_unicast() { unicast_open(&uc, 146, &unicast_callbacks); }
/*---------------------------------------------------------------------------*/ void shell_rime_sendcmd_init(void) { unicast_open(&uc, SHELL_RIME_CHANNEL_SENDCMD, &unicast_callbacks); shell_register_command(&sendcmd_command); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(demo_source, ev, data) { static struct etimer et; rimeaddr_t addr; //PROCESS_EXITHANDLER(unicast_close(&unicast);) PROCESS_BEGIN(); // unicast init // unicast_open(&unicast, 146, &unicast_callbacks); // UART init // slip_arch_init(115200); // DATA Storing // data_sensing=(uint8_t *) malloc(UART_Full+1 * sizeof(uint8_t)); //size+1 은 첫번째에 indicator 넣기 위함! data_sensing[0]='B'; //sensor 식별자 sensor A or sensor B //data_sensing[UART_Full]=90; while (1) { etimer_set(&et, CLOCK_SECOND/10); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); //printf("%d\t%c\n",data_sensing[0],data_sensing[0]); /* RAIDO_LISTEN : * Wait start signal from Sink Node */ if(CURRENT_STATE==RAIDO_LISTEN){ PRINTF("CURRENT_STATE: %d. RAIDO_LISTEN \n",CURRENT_STATE); leds_on(RAIDO_LISTEN); if (RADIO_Input=='S'){ UART_out('S'); CURRENT_STATE=UART_START; RADIO_Input=NULL; } } /* UART_SEND : * 1. Sensor Interface로 부터 Sensing Complete(C) 신호를 받은 경우 * 2. Sensor Interface로 부터 1회 UART 전송을 완료하고 SUCCESS신호를 받은경우 * -> NEXT(N) 신호를 전달하여 다음 데이터 요구 * 1. Sensor Interface로 부터 (!SUCCESS)를 받은 경우 * ->Retransmission(R) 신호 전달 */ else if(CURRENT_STATE==UART_SEND){ PRINTF("CURRENT_STATE: %d. UART_SEND \n",CURRENT_STATE); leds_on(UART_SEND); if(UART_Success==1) UART_out('N'); else if (UART_Success==0) UART_out('R'); CURRENT_STATE=UART_LISTEN; } /* UART_READY : * 1회 전송 가능 data 량을 Sensor interface 로 부터 받은 경우 * data를 packet화 하여 unicast 전송 */ else if(CURRENT_STATE==UART_READY){ PRINTF("CURRENT_STATE: %d. UART_READY \n",CURRENT_STATE); leds_on(UART_READY); //헤더 붙이고, 데이터 패킷화 하여 전송하기 packetbuf_copyfrom(data_sensing, UART_Full+1); addr.u8[0] = 4; addr.u8[1] = 0; //send to F2 unicast_send(&unicast, &addr); CURRENT_STATE=RADIO_SENT; } else if(CURRENT_STATE==RADIO_SENT){ RADIO_NumSend++; PRINTF("CURRENT_STATE: %d. RADIO_SNET \t RADIO_NumSend : %d\n",CURRENT_STATE,RADIO_NumSend); leds_on(RADIO_SENT); if(RADIO_NumSend>=END_SENSING)//End 인 경우 { UART_End=1; //이건 아마 필요없는 기능이 될듯 CURRENT_STATE=RAIDO_LISTEN; RADIO_NumSend=0; } else{ CURRENT_STATE=UART_SEND; } } else if(CURRENT_STATE==UART_START){ PRINTF("CURRENT_STATE: %d. UART_START \n",UART_START); leds_on(UART_START); } else if(CURRENT_STATE==UART_LISTEN){ PRINTF("CURRENT_STATE: %d. UART_LISTEN \n",UART_LISTEN); leds_on(UART_LISTEN); } else { PRINTF("NONE STATE \t%d\n",CURRENT_STATE); leds_on(0); } } PROCESS_END(); }