*** stock_iot-lab_M3/openwsn/07-App/udpstorm/udpstorm.c Thu Apr 24 11:01:37 2014 --- riot-openwsn-wip/openwsn/07-App/udpstorm/udpstorm.c Thu Apr 24 16:55:54 2014 *************** *** 9,14 **** --- 9,17 ---- #include "scheduler.h" //#include "ADC_Channel.h" #include "IEEE802154E.h" + #include "idmanager.h" + + #include "thread.h" //=========================== defines ========================================= *************** *** 33,52 **** } udpstorm_vars_t; udpstorm_vars_t udpstorm_vars; ! //=========================== prototypes ====================================== ! error_t udpstorm_receive(OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options); ! void udpstorm_timer_cb(); ! void udpstorm_task_cb(); void udpstorm_sendDone(OpenQueueEntry_t* msg, ! error_t error); //=========================== public ========================================== ! void udpstorm_init() { // prepare the resource descriptor for the path udpstorm_vars.desc.path0len = sizeof(udpstorm_path0)-1; udpstorm_vars.desc.path0val = (uint8_t*)(&udpstorm_path0); --- 36,55 ---- } udpstorm_vars_t; udpstorm_vars_t udpstorm_vars; ! //static char openwsn_udpstorm_stack[KERNEL_CONF_STACKSIZE_MAIN]; //=========================== prototypes ====================================== ! owerror_t udpstorm_receive(OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options); ! void udpstorm_timer_cb(void); ! void udpstorm_task_cb(void); void udpstorm_sendDone(OpenQueueEntry_t* msg, ! owerror_t error); //=========================== public ========================================== ! void udpstorm_init(void) { // prepare the resource descriptor for the path udpstorm_vars.desc.path0len = sizeof(udpstorm_path0)-1; udpstorm_vars.desc.path0val = (uint8_t*)(&udpstorm_path0); *************** *** 65,71 **** //=========================== private ========================================= ! error_t udpstorm_receive(OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options) { return E_FAIL; --- 68,74 ---- //=========================== private ========================================= ! owerror_t udpstorm_receive(OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options) { return E_FAIL; *************** *** 73,87 **** //timer fired, but we don't want to execute task in ISR mode //instead, push task to scheduler with CoAP priority, and let scheduler take care of it ! void udpstorm_timer_cb(){ ! scheduler_push_task(udpstorm_task_cb,TASKPRIO_COAP); } ! void udpstorm_task_cb() { OpenQueueEntry_t* pkt; ! error_t outcome; uint8_t numOptions; if(udpstorm_vars.seqNum>=NUMPACKETS) { // we've sent enough packets --- 76,103 ---- //timer fired, but we don't want to execute task in ISR mode //instead, push task to scheduler with CoAP priority, and let scheduler take care of it ! void udpstorm_timer_cb(void){ ! scheduler_push_task(udpstorm_task_cb,TASKPRIO_COAP); ! /*thread_create(openwsn_udpstorm_stack, KERNEL_CONF_STACKSIZE_MAIN, ! PRIORITY_OPENWSN_UDPSTORM, CREATE_STACKTEST, ! udpstorm_task_cb, "udpstorm task cb");*/ } ! void udpstorm_task_cb(void) { OpenQueueEntry_t* pkt; ! owerror_t outcome; uint8_t numOptions; + // don't run if not synch + if (ieee154e_isSynch() == FALSE) return; + + // don't run on dagroot + if (idmanager_getIsDAGroot()) { + opentimers_stop(udpstorm_vars.timerId); + return; + } + + if(udpstorm_vars.seqNum>=NUMPACKETS) { // we've sent enough packets *************** *** 116,127 **** packetfunctions_reserveHeaderSize(pkt,sizeof(udpstorm_path0)-1); memcpy(&pkt->payload[0],&udpstorm_path0,sizeof(udpstorm_path0)-1); packetfunctions_reserveHeaderSize(pkt,1); ! pkt->payload[0] = (COAP_OPTION_LOCATIONPATH-COAP_OPTION_CONTENTTYPE) << 4 | ! sizeof(udpstorm_path0)-1; numOptions++; // content-type option packetfunctions_reserveHeaderSize(pkt,2); ! pkt->payload[0] = COAP_OPTION_CONTENTTYPE << 4 | 1; pkt->payload[1] = COAP_MEDTYPE_APPOCTETSTREAM; numOptions++; --- 132,143 ---- packetfunctions_reserveHeaderSize(pkt,sizeof(udpstorm_path0)-1); memcpy(&pkt->payload[0],&udpstorm_path0,sizeof(udpstorm_path0)-1); packetfunctions_reserveHeaderSize(pkt,1); ! pkt->payload[0] = ((COAP_OPTION_NUM_URIPATH) << 4) | ! (sizeof(udpstorm_path0)-1); numOptions++; // content-type option packetfunctions_reserveHeaderSize(pkt,2); ! pkt->payload[0] = COAP_OPTION_NUM_CONTENTFORMAT << 4 | 1; pkt->payload[1] = COAP_MEDTYPE_APPOCTETSTREAM; numOptions++; *************** *** 147,152 **** udpstorm_vars.seqNum++; } ! void udpstorm_sendDone(OpenQueueEntry_t* msg, error_t error) { openqueue_freePacketBuffer(msg); } \ No newline at end of file --- 163,168 ---- udpstorm_vars.seqNum++; } ! void udpstorm_sendDone(OpenQueueEntry_t* msg, owerror_t error) { openqueue_freePacketBuffer(msg); } \ No newline at end of file