1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/pkg/openwsn/patches/07-App_udplatency_udplatency.c.patch
2014-05-14 15:06:50 +02:00

224 lines
7.2 KiB
Diff

*** stock_iot-lab_M3/openwsn/07-App/udplatency/udplatency.c Thu Apr 24 11:01:37 2014
--- riot-openwsn-wip/openwsn/07-App/udplatency/udplatency.c Thu Apr 24 16:55:54 2014
***************
*** 12,21 ****
#include "idmanager.h"
#include "neighbors.h"
! //=========================== defines =========================================
! /// inter-packet period (in mseconds)
! #define UDPLATENCYPERIOD 30000
//=========================== variables =======================================
--- 12,20 ----
#include "idmanager.h"
#include "neighbors.h"
! #include "thread.h"
! //=========================== defines =========================================
//=========================== variables =======================================
***************
*** 24,51 ****
} udplatency_vars_t;
udplatency_vars_t udplatency_vars;
//=========================== prototypes ======================================
! void udplatency_timer();
//=========================== public ==========================================
! void udplatency_init() {
! //don't run on dagroot
! if (idmanager_getIsDAGroot()) return;
!
! udplatency_vars.timerId = opentimers_start(UDPLATENCYPERIOD,
! TIMER_PERIODIC,TIME_MS,
! udplatency_timer);
}
! void udplatency_task(){
OpenQueueEntry_t* pkt;
open_addr_t * p;
open_addr_t q;
! //prepare packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_UDPLATENCY);
if (pkt==NULL) {
openserial_printError(COMPONENT_UDPLATENCY,ERR_NO_FREE_PACKET_BUFFER,
--- 23,60 ----
} udplatency_vars_t;
udplatency_vars_t udplatency_vars;
+ uint16_t seqNum;
+
+ //static char openwsn_udplatency_stack[KERNEL_CONF_STACKSIZE_MAIN];
//=========================== prototypes ======================================
! void udplatency_timer(void);
//=========================== public ==========================================
! void udplatency_init(void) {
! seqNum = 0;
! udplatency_vars.timerId = opentimers_start(UDPLATENCYPERIOD,
! TIMER_PERIODIC,TIME_MS,
! udplatency_timer);
}
! void udplatency_task(void) {
OpenQueueEntry_t* pkt;
open_addr_t * p;
open_addr_t q;
! // don't run if not synch
! if (ieee154e_isSynch() == FALSE) return;
!
! // don't run on dagroot
! if (idmanager_getIsDAGroot()) {
! opentimers_stop(udplatency_vars.timerId);
! return;
! }
!
! // prepare packet
pkt = openqueue_getFreePacketBuffer(COMPONENT_UDPLATENCY);
if (pkt==NULL) {
openserial_printError(COMPONENT_UDPLATENCY,ERR_NO_FREE_PACKET_BUFFER,
***************
*** 58,106 ****
pkt->l4_protocol = IANA_UDP;
pkt->l4_sourcePortORicmpv6Type = WKP_UDP_LATENCY;
pkt->l4_destination_port = WKP_UDP_LATENCY;
! pkt->l3_destinationAdd.type = ADDR_128B;
memcpy(&pkt->l3_destinationAdd.addr_128b[0],&ipAddr_motedata,16);
! //the payload contains the 64bit address of the sender + the ASN
! packetfunctions_reserveHeaderSize(pkt,sizeof(asn_t));
! asnWriteToPkt(pkt);//gets asn from mac layer.
packetfunctions_reserveHeaderSize(pkt,8);
p=idmanager_getMyID(ADDR_64B);
! pkt->payload[0]=p->addr_64b[0];
! pkt->payload[1]=p->addr_64b[1];
! pkt->payload[2]=p->addr_64b[2];
! pkt->payload[3]=p->addr_64b[3];
! pkt->payload[4]=p->addr_64b[4];
! pkt->payload[5]=p->addr_64b[5];
! pkt->payload[6]=p->addr_64b[6];
! pkt->payload[7]=p->addr_64b[7];
neighbors_getPreferredParentEui64(&q);
! if (q.type==ADDR_64B){
packetfunctions_reserveHeaderSize(pkt,8);
! //copy my preferred parent so we can build the topology
! pkt->payload[0]=q.addr_64b[0];
! pkt->payload[1]=q.addr_64b[1];
! pkt->payload[2]=q.addr_64b[2];
! pkt->payload[3]=q.addr_64b[3];
! pkt->payload[4]=q.addr_64b[4];
! pkt->payload[5]=q.addr_64b[5];
! pkt->payload[6]=q.addr_64b[6];
! pkt->payload[7]=q.addr_64b[7];
}
! //send packet
! if ((openudp_send(pkt))==E_FAIL) {
openqueue_freePacketBuffer(pkt);
}
}
! void udplatency_timer() {
! scheduler_push_task(udplatency_task,TASKPRIO_COAP);
}
! void udplatency_sendDone(OpenQueueEntry_t* msg, error_t error) {
msg->owner = COMPONENT_UDPLATENCY;
if (msg->creator!=COMPONENT_UDPLATENCY) {
openserial_printError(COMPONENT_UDPLATENCY,ERR_UNEXPECTED_SENDDONE,
--- 67,132 ----
pkt->l4_protocol = IANA_UDP;
pkt->l4_sourcePortORicmpv6Type = WKP_UDP_LATENCY;
pkt->l4_destination_port = WKP_UDP_LATENCY;
! pkt->l3_destinationAdd.type = ADDR_128B;
memcpy(&pkt->l3_destinationAdd.addr_128b[0],&ipAddr_motedata,16);
! // the payload contains the 64bit address of the sender + the ASN
! packetfunctions_reserveHeaderSize(pkt, sizeof(asn_t));
! ieee154e_getAsn(pkt->payload);//gets asn from mac layer.
packetfunctions_reserveHeaderSize(pkt,8);
p=idmanager_getMyID(ADDR_64B);
! pkt->payload[0] = p->addr_64b[0];
! pkt->payload[1] = p->addr_64b[1];
! pkt->payload[2] = p->addr_64b[2];
! pkt->payload[3] = p->addr_64b[3];
! pkt->payload[4] = p->addr_64b[4];
! pkt->payload[5] = p->addr_64b[5];
! pkt->payload[6] = p->addr_64b[6];
! pkt->payload[7] = p->addr_64b[7];
neighbors_getPreferredParentEui64(&q);
! if (q.type==ADDR_64B) {
packetfunctions_reserveHeaderSize(pkt,8);
! // copy my preferred parent so we can build the topology
! pkt->payload[0] = q.addr_64b[0];
! pkt->payload[1] = q.addr_64b[1];
! pkt->payload[2] = q.addr_64b[2];
! pkt->payload[3] = q.addr_64b[3];
! pkt->payload[4] = q.addr_64b[4];
! pkt->payload[5] = q.addr_64b[5];
! pkt->payload[6] = q.addr_64b[6];
! pkt->payload[7] = q.addr_64b[7];
}
!
! // insert Sequence Number
! packetfunctions_reserveHeaderSize(pkt,sizeof(seqNum));
! pkt->payload[0] = (seqNum >> 8) & 0xff;
! pkt->payload[1] = seqNum & 0xff;
!
! // send packet
! if ((openudp_send(pkt)) == E_FAIL) {
openqueue_freePacketBuffer(pkt);
}
+
+ // increment seqNum
+ seqNum++;
+
+ // close timer when test finish
+ if (seqNum > NUMPKTTEST) {
+ opentimers_stop(udplatency_vars.timerId);
+ }
}
! void udplatency_timer(void) {
! scheduler_push_task(udplatency_task,TASKPRIO_COAP);
! /*thread_create(openwsn_udplatency_stack, KERNEL_CONF_STACKSIZE_MAIN,
! PRIORITY_OPENWSN_UDPLATENCY, CREATE_STACKTEST,
! udplatency_task, "udplatency task");*/
}
! void udplatency_sendDone(OpenQueueEntry_t* msg, owerror_t error) {
msg->owner = COMPONENT_UDPLATENCY;
if (msg->creator!=COMPONENT_UDPLATENCY) {
openserial_printError(COMPONENT_UDPLATENCY,ERR_UNEXPECTED_SENDDONE,
***************
*** 114,117 ****
openqueue_freePacketBuffer(msg);
}
! //=========================== private =========================================
\ No newline at end of file
--- 140,143 ----
openqueue_freePacketBuffer(msg);
}
! //=========================== private =========================================