mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ba3088c4bd
into separate patch files
111 lines
3.2 KiB
Diff
111 lines
3.2 KiB
Diff
*** stock_iot-lab_M3/openwsn/07-App/udprand/udprand.c Thu Apr 24 11:01:37 2014
|
|
--- riot-openwsn-wip/openwsn/07-App/udprand/udprand.c Thu Apr 24 16:55:54 2014
|
|
***************
|
|
*** 8,13 ****
|
|
--- 8,17 ----
|
|
#include "openrandom.h"
|
|
#include "opencoap.h"
|
|
#include "scheduler.h"
|
|
+ #include "idmanager.h"
|
|
+ #include "IEEE802154E.h"
|
|
+
|
|
+ #include "thread.h"
|
|
|
|
//=========================== defines =========================================
|
|
|
|
***************
|
|
*** 21,41 ****
|
|
} udprand_vars_t;
|
|
|
|
udprand_vars_t udprand_vars;
|
|
!
|
|
//=========================== prototypes ======================================
|
|
|
|
! void udprand_timer();
|
|
|
|
//=========================== public ==========================================
|
|
|
|
! void udprand_init() {
|
|
udprand_vars.timerId = opentimers_start(openrandom_get16b()%UDPRANDPERIOD,
|
|
TIMER_PERIODIC,TIME_MS,
|
|
udprand_timer);
|
|
}
|
|
|
|
! void udprand_task(){
|
|
OpenQueueEntry_t* pkt;
|
|
//prepare packet
|
|
pkt = openqueue_getFreePacketBuffer(COMPONENT_UDPRAND);
|
|
if (pkt==NULL) {
|
|
--- 25,55 ----
|
|
} udprand_vars_t;
|
|
|
|
udprand_vars_t udprand_vars;
|
|
! //static char openwsn_udprand_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
|
//=========================== prototypes ======================================
|
|
|
|
! void udprand_timer(void);
|
|
|
|
//=========================== public ==========================================
|
|
|
|
! void udprand_init(void) {
|
|
udprand_vars.timerId = opentimers_start(openrandom_get16b()%UDPRANDPERIOD,
|
|
TIMER_PERIODIC,TIME_MS,
|
|
udprand_timer);
|
|
}
|
|
|
|
! void udprand_task(void){
|
|
OpenQueueEntry_t* pkt;
|
|
+
|
|
+ // don't run if not synch
|
|
+ if (ieee154e_isSynch() == FALSE) return;
|
|
+
|
|
+ // don't run on dagroot
|
|
+ if (idmanager_getIsDAGroot()) {
|
|
+ opentimers_stop(udprand_vars.timerId);
|
|
+ return;
|
|
+ }
|
|
+
|
|
//prepare packet
|
|
pkt = openqueue_getFreePacketBuffer(COMPONENT_UDPRAND);
|
|
if (pkt==NULL) {
|
|
***************
|
|
*** 60,70 ****
|
|
}
|
|
}
|
|
|
|
! void udprand_timer() {
|
|
! scheduler_push_task(udprand_task,TASKPRIO_COAP);
|
|
}
|
|
|
|
! void udprand_sendDone(OpenQueueEntry_t* msg, error_t error) {
|
|
msg->owner = COMPONENT_UDPRAND;
|
|
if (msg->creator!=COMPONENT_UDPRAND) {
|
|
openserial_printError(COMPONENT_UDPRAND,ERR_UNEXPECTED_SENDDONE,
|
|
--- 74,87 ----
|
|
}
|
|
}
|
|
|
|
! void udprand_timer(void) {
|
|
! scheduler_push_task(udprand_task,TASKPRIO_COAP);
|
|
! /*thread_create(openwsn_udprand_stack, KERNEL_CONF_STACKSIZE_MAIN,
|
|
! PRIORITY_OPENWSN_UDPRAND, CREATE_STACKTEST,
|
|
! udprand_task, "udprand task");*/
|
|
}
|
|
|
|
! void udprand_sendDone(OpenQueueEntry_t* msg, owerror_t error) {
|
|
msg->owner = COMPONENT_UDPRAND;
|
|
if (msg->creator!=COMPONENT_UDPRAND) {
|
|
openserial_printError(COMPONENT_UDPRAND,ERR_UNEXPECTED_SENDDONE,
|
|
***************
|
|
*** 78,81 ****
|
|
openqueue_freePacketBuffer(msg);
|
|
}
|
|
|
|
! //=========================== private =========================================
|
|
\ No newline at end of file
|
|
--- 95,98 ----
|
|
openqueue_freePacketBuffer(msg);
|
|
}
|
|
|
|
! //=========================== private =========================================
|