コード例 #1
0
ファイル: c_multihop.c プロジェクト: cameliasarosi/CRime
/*---------------------------------------------------------------------------*/
int c_multihop_send(struct pipe *p, struct stackmodule_i *module) {
	PRINTF("c_multihop_send \n");
	printaddr(module->stack_id);
	packetbuf_compact();
	rimeaddr_t *nexthop;

	rimeaddr_t *tmpaddr = get_node_addr(module->stack_id, 0, 3);

	nexthop = c_forward(stack[module->stack_id].pip,
			stack[module->stack_id].amodule, module->module_id);
	if (nexthop == NULL) {
		PRINTF("multihop_send: no route\n");
		return 0;
	} else {
		set_node_addr(module->stack_id, 0, 2, nexthop);
		PRINTF("multihop_send: sending data towards %d.%d\n",
				nexthop->u8[0], nexthop->u8[1]);

		packetbuf_set_addr(PACKETBUF_ADDR_ERECEIVER, tmpaddr);
		rimeaddr_t *tmpaddr1 = get_node_addr(module->stack_id, 0, 1);
		packetbuf_set_addr(PACKETBUF_ADDR_ESENDER, tmpaddr1);

		rimeaddr_t  esender, ereceiver;
		rimeaddr_copy(&esender, packetbuf_addr(PACKETBUF_ADDR_ESENDER));
		rimeaddr_copy(&ereceiver, packetbuf_addr(PACKETBUF_ADDR_ERECEIVER));

		packetbuf_set_attr(PACKETBUF_ATTR_HOPS, 1);
		return 1;
	}
}
コード例 #2
0
ファイル: c_abc.c プロジェクト: sensorlab/CRime
/*---------------------------------------------------------------------------*/
void c_abc_recv(struct pipe *p, struct stackmodule_i *module) {
    int start_tm = START_TM;
    rimeaddr_t tmpaddr;

    rimeaddr_copy(&tmpaddr, packetbuf_addr(PACKETBUF_ADDR_SENDER));
    set_node_addr(module->stack_id, 1, 0, &tmpaddr);
    PRINTF("~c_abc_receive: packet %s (%d) on channel %d from %d.%d\n",
           (char *)packetbuf_dataptr(),
           packetbuf_datalen(), p->channel->channelno,
           tmpaddr.u8[0], tmpaddr.u8[1]);
    PRINTFE("\n %d \n", DURATION_TM(start_tm));
}
コード例 #3
0
ファイル: c_multihop.c プロジェクト: cameliasarosi/CRime
void c_multihop_recv(struct pipe *p, struct stackmodule_i *module) {
	PRINTF("c_multihop_recv \n");
	printaddr(module->stack_id);

	rimeaddr_t *nexthop = NULL;

	rimeaddr_t esender, ereceiver;

	/* Copy the packet attributes to avoid them being overwritten or
	 cleared by an application program that uses the packet buffer for
	 its own needs. */
	//rimeaddr_copy(&esender, packetbuf_addr(PACKETBUF_ADDR_ESENDER));
	rimeaddr_copy(&ereceiver, packetbuf_addr(PACKETBUF_ADDR_ERECEIVER));

	if (rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_ERECEIVER),
			&rimeaddr_node_addr)) {
		stack[module->stack_id].resend_flg = 1;
		PRINTF("for us!\n");
		p->multihop_param.hop_no = packetbuf_attr(PACKETBUF_ATTR_HOPS);
	} else {
		nexthop = c_forward(p, stack[module->stack_id].amodule, stack[module->stack_id].modno);
		PRINTF("nexthop: %d.%d \n", nexthop->u8[0], nexthop->u8[1]);

		packetbuf_set_attr(PACKETBUF_ATTR_HOPS,
				packetbuf_attr(PACKETBUF_ATTR_HOPS) + 1);
		if (nexthop) {
			set_node_addr(module->stack_id, 0, 2, nexthop);
			PRINTF("forwarding to %d.%d\n", nexthop->u8[0], nexthop->u8[1]);
			if (module->stack_id < STACKNO) {
				//stack_send(&stack[module->stack_id], module->module_id);
				stack_send(&stack[module->stack_id], module->module_id);

			}
		}
	}
}