• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ packetbuf_dataptr函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中packetbuf_dataptr函数的典型用法代码示例。如果您正苦于以下问题:C++ packetbuf_dataptr函数的具体用法?C++ packetbuf_dataptr怎么用?C++ packetbuf_dataptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了packetbuf_dataptr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: request_recv

/*---------------------------------------------------------------------------*/
static void
request_recv(struct runicast_conn *c, const linkaddr_t *from, uint8_t seqno)
{
  const char *filename;
  uint8_t seq;

  if(packetbuf_datalen() < 2) {
    /* Bad filename, ignore request */
    printf("download: bad filename request (null)\n");
    return;
  }

  seq = ((uint8_t *)packetbuf_dataptr())[0];
  if(seq == req_last_seq) {
    PRINTF("download: ignoring duplicate request\n");
    return;
  }
  req_last_seq = seq;
  filename = ((char *)packetbuf_dataptr()) + 1;

  PRINTF("file requested: '%s'\n", filename);

  /* Initiate file transfer */
  leds_on(LEDS_GREEN);
  if(fd >= 0) {
    cfs_close(fd);
  }
  fd = cfs_open(filename, CFS_READ);
  if(fd < 0) {
    printf("download: bad filename request (no read access): %s\n", filename);
  } else {
    PRINTF("download: sending file: %s\n", filename);
  }

  rucb_close(&rucb);
  rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
  rucb_send(&rucb, from);
}
开发者ID:13416795,项目名称:contiki,代码行数:39,代码来源:shell-download.c


示例2: send_packet

/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
{
  int size;

  /* 3 bytes per packet attribute is required for serialization */
  uint8_t buf[PACKETBUF_NUM_ATTRS * 3 + PACKETBUF_SIZE + 3];
  int sid;

  packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &linkaddr_node_addr);

  /* ack or not ? */
  packetbuf_set_attr(PACKETBUF_ATTR_MAC_ACK, 1);

  if(NETSTACK_FRAMER.create_and_secure() < 0) {
    /* Failed to allocate space for headers */
    LOG6LBR_ERROR("br-rdc: send failed, too large header\n");
    mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);

  } else {
    /* here we send the data over SLIP to the radio-chip */
    size = 0;
    if(sixlbr_config_slip_serialize_tx_attrs) {
      size = packetutils_serialize_atts(&buf[3], sizeof(buf) - 3);
    }
    if(size < 0 || size + packetbuf_totlen() + 3 > sizeof(buf)) {
      LOG6LBR_ERROR("br-rdc: send failed, too large header\n");
      mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1);
    } else {
      sid = setup_callback(sent, ptr);
      if (sid != -1) {
        LOG6LBR_PRINTF(PACKET, RADIO_OUT, "write: %d (sid: %d, cb: %d)\n", packetbuf_datalen(), sid, callback_count);
        LOG6LBR_DUMP_PACKET(RADIO_OUT, packetbuf_dataptr(), packetbuf_datalen());

        buf[0] = '!';
        buf[1] = 'S';
        buf[2] = sid;             /* sequence or session number for this packet */

        /* Copy packet data */
        memcpy(&buf[3 + size], packetbuf_hdrptr(), packetbuf_totlen());
        callbacks[sid].buf_len = packetbuf_totlen() + size + 3;
        memcpy(callbacks[sid].buf, buf, callbacks[sid].buf_len);
        write_to_slip(buf, callbacks[sid].buf_len);
      } else {
        LOG6LBR_INFO("native-rdc queue full\n");
        mac_call_sent_callback(sent, ptr, MAC_TX_NOACK, 1);
      }
    }
  }
}
开发者ID:msolters,项目名称:6lbr,代码行数:51,代码来源:native-rdc.c


示例3: recv_runicast

static void recv_runicast(struct runicast_conn *c, rimeaddr_t *from, uint8_t seqno)
{
  printf("runicast message received from %d.%d, seqno %d\n", from->u8[0], from->u8[1], seqno);
  packetbuf_copyto(&filenameOriginatorRecv);
  printf("originator: %u\n", filenameOriginatorRecv.originator);
  printf("filename: %s\n", filenameOriginatorRecv.name);

  // request file from initiator
  rucb_open(&rucb, RUCB_CHANNEL, &rucb_call);
  packetbuf_clear();
  *((uint8_t *)packetbuf_dataptr()) = ++req_seq_counter;
  memcpy(((char *)packetbuf_dataptr()) + 1, filenameOriginatorRecv.name, strlen(filenameOriginatorRecv.name)+1);
  packetbuf_set_datalen(strlen(filenameOriginatorRecv.name) + 2);
  rimeaddr_t addr;
  addr.u8[0] = filenameOriginatorRecv.originator;
  addr.u8[1] = 0;
  filename_download = filenameOriginatorRecv.name;
  fd = cfs_open(filename_download, CFS_WRITE );
  runicast_send(&runicast, &addr, MAX_RETRANSMISSIONS);
  downloading = 1;
  process_start(&download_and_execute_process, NULL);

}
开发者ID:sebyx31,项目名称:contiki-exercises,代码行数:23,代码来源:contiki_exercise12.c


示例4: rrep_packet_received

/*---------------------------------------------------------------------------*/
static void
rrep_packet_received(struct unicast_conn *uc, const linkaddr_t *from)
{
  struct rrep_hdr *msg = packetbuf_dataptr();
  struct route_entry *rt;
  linkaddr_t dest;
  struct route_discovery_conn *c = (struct route_discovery_conn *)
    ((char *)uc - offsetof(struct route_discovery_conn, rrepconn));

  PRINTF("%d.%d: rrep_packet_received from %d.%d towards %d.%d len %d\n",
	 linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
	 from->u8[0],from->u8[1],
	 msg->dest.u8[0],msg->dest.u8[1],
	 packetbuf_datalen());

  PRINTF("from %d.%d hops %d rssi %d lqi %d\n",
	 from->u8[0], from->u8[1],
	 msg->hops,
	 packetbuf_attr(PACKETBUF_ATTR_RSSI),
	 packetbuf_attr(PACKETBUF_ATTR_LINK_QUALITY));

  insert_route(&msg->originator, from, msg->hops);

  if(linkaddr_cmp(&msg->dest, &linkaddr_node_addr)) {
    PRINTF("rrep for us!\n");
    rrep_pending = 0;
    ctimer_stop(&c->t);
    if(c->cb->new_route) {
      linkaddr_t originator;

      /* If the callback modifies the packet, the originator address
         will be lost. Therefore, we need to copy it into a local
         variable before calling the callback. */
      linkaddr_copy(&originator, &msg->originator);
      c->cb->new_route(c, &originator);
    }

  } else {
    linkaddr_copy(&dest, &msg->dest);

    rt = route_lookup(&msg->dest);
    if(rt != NULL) {
      PRINTF("forwarding to %d.%d\n", rt->nexthop.u8[0], rt->nexthop.u8[1]);
      msg->hops++;
      unicast_send(&c->rrepconn, &rt->nexthop);
    } else {
      PRINTF("%d.%d: no route to %d.%d\n", linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1], msg->dest.u8[0], msg->dest.u8[1]);
    }
  }
}
开发者ID:damini1406,项目名称:contiki,代码行数:51,代码来源:route-discovery.c


示例5: broadcast_subscription

/*--------------------Broadcast Generator---------------------------*/
void
broadcast_subscription(struct subscription_item *si) {
	struct subscribe_message *msg;
	packetbuf_clear();
	packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, MWARE_MSG_SUB);
	packetbuf_set_datalen(sizeof(struct subscribe_message));
	msg = packetbuf_dataptr();
	memcpy(&msg->id, &si->id, sizeof(struct identifier));
	memcpy(&msg->sub, &si->sub, sizeof(struct subscription));
	subscription_sync_jitter(&msg->sub,si);
	if (broadcast_send(&connection)) {
		subscription_update_last_shout(si);
	}
}
开发者ID:sengjea,项目名称:mware,代码行数:15,代码来源:mware.c


示例6: recv_collect

/*---------------------------------------------------------------------------*/
static void
recv_collect(const rimeaddr_t *originator, u8_t seqno, u8_t hops)
{
  struct collect_msg *collect_msg;
  rtimer_clock_t latency;
  int len;
  
  collect_msg = packetbuf_dataptr();
  
#if TIMESYNCH_CONF_ENABLED
  latency = timesynch_time() - collect_msg->timestamp;
#else
  latency = 0;
#endif
  
  if(waiting_for_collect) {
    struct {
      uint16_t len;
      uint16_t originator;
      uint16_t seqno;
      uint16_t hops;
      uint16_t latency;
    } msg;

    if(packetbuf_datalen() >= COLLECT_MSG_HDRSIZE) {
      len = packetbuf_datalen() - COLLECT_MSG_HDRSIZE;

      if(collect_msg->crc == crc16_data(collect_msg->data, len, 0)) {
	msg.len = 5 + (packetbuf_datalen() - COLLECT_MSG_HDRSIZE) / 2;
	rimeaddr_copy((rimeaddr_t *)&msg.originator, originator);
	msg.seqno = seqno;
	msg.hops = hops;
	msg.latency = latency;
	/*    printf("recv_collect datalen %d\n", packetbuf_datalen());*/
	
	shell_output(&collect_command,
		     &msg, sizeof(msg),
		     collect_msg->data, packetbuf_datalen() - COLLECT_MSG_HDRSIZE);
      }
    }
  } else if(waiting_for_nodes) {
    char buf[40];
    snprintf(buf, sizeof(buf), "%d.%d, %d hops, latency %lu ms",
	     originator->u8[0], originator->u8[1],
	     hops, (1000L * latency) / RTIMER_ARCH_SECOND);
    shell_output_str(&nodes_command, "Message from node ", buf);
    messages_received++;
  }

}
开发者ID:EDAyele,项目名称:ptunes,代码行数:51,代码来源:shell-rime.c


示例7: PROCESS_THREAD

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_runicast_process, ev, data)
{
  struct shell_input *input;
  static rimeaddr_t receiver;
  int len;
  const char *nextptr;
  struct collect_msg *msg;
  char buf[30];
  
  PROCESS_BEGIN();
  
  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&runicast_command,
		     "runicast <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
  shell_output_str(&runicast_command, "Sending runicast packets to ", buf);

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == shell_event_input);
    input = data;

    len = input->len1 + input->len2;

    if(len == 0) {
      PROCESS_EXIT();
    }
    
    if(len < PACKETBUF_SIZE) {
      packetbuf_clear();
      packetbuf_set_datalen(len + COLLECT_MSG_HDRSIZE);
      msg = packetbuf_dataptr();
      memcpy(msg->data, input->data1, input->len1);
      memcpy(msg->data + input->len1, input->data2, input->len2);
#if TIMESYNCH_CONF_ENABLED
      msg->timestamp = timesynch_time();
#else
      msg->timestamp = 0;
#endif
      /*      printf("Sending %d bytes\n", len);*/
      runicast_send(&ruc, &receiver, 4);
    }
  }
  PROCESS_END();
}
开发者ID:Jean-Emile,项目名称:kevoree-IoT,代码行数:51,代码来源:shell-rime-debug-runicast.c


示例8: handler_802154_send_beacon_request

/* called to send a beacon request */
void
handler_802154_send_beacon_request(void)
{
  struct net_buf *mbuf;
  frame802154_t params;
  uint8_t len;

  mbuf = l2_buf_get_reserve(0);
  if(!mbuf) {
    return;
  }

  /* init to zeros */
  memset(&params, 0, sizeof(params));

  /* use packetbuf for sending ?? */
  packetbuf_clear(mbuf);
  /* Build the FCF. */
  params.fcf.frame_type = FRAME802154_CMDFRAME;

  /* Insert IEEE 802.15.4 (2006) version bits. */
  params.fcf.frame_version = FRAME802154_IEEE802154_2006;

  params.fcf.src_addr_mode = FRAME802154_NOADDR;

  params.fcf.dest_addr_mode = FRAME802154_SHORTADDRMODE;
  params.dest_addr[0] = 0xFF;
  params.dest_addr[1] = 0xFF;

  params.dest_pid = 0xffff;

  params.seq = chseqno;

  packetbuf_set_datalen(mbuf, 1);
  params.payload = packetbuf_dataptr(mbuf);
  /* set the type in the payload */
  params.payload[0] = FRAME802154_BEACONREQ;
  params.payload_len = packetbuf_datalen(mbuf);
  len = frame802154_hdrlen(&params);

  if(packetbuf_hdralloc(mbuf, len)) {
    frame802154_create(&params, packetbuf_hdrptr(mbuf), len);
    if(NETSTACK_RADIO.send(mbuf, packetbuf_hdrptr(mbuf),
             packetbuf_totlen(mbuf)) != RADIO_TX_OK) {
      l2_buf_unref(mbuf);
      return;
    }
    HANDLER_802154_STAT(handler_802154_stats.beacons_reqs_sent++);
  }
}
开发者ID:CurieBSP,项目名称:zephyr,代码行数:51,代码来源:handler-802154.c


示例9: gateway_announce_recv

static void
gateway_announce_recv(struct trickle_conn *c)
{
  struct gateway_msg *msg;
  msg = packetbuf_dataptr();
  PRINTF("%d.%d: gateway message: %d.%d\n",
	 linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
	 msg->gateway.u8[0], msg->gateway.u8[1]);

  if(!is_gateway) {
    uip_over_mesh_set_gateway(&msg->gateway);
  }
  
}
开发者ID:exziled,项目名称:WeatherSystem,代码行数:14,代码来源:uip-over-mesh.c


示例10: PROCESS_THREAD

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rime_ping_process, ev, data)
{
  static int i;
  static struct etimer timeout, periodic;
  static rimeaddr_t receiver;
  struct rime_ping_msg *ping;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&rime_ping_command,
		     "ping <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
  shell_output_str(&rime_ping_command, "Sending 4 pings to ", buf);

  for(i = 0; i < 4; ++i) {
    packetbuf_clear();
    ping = packetbuf_dataptr();
    packetbuf_set_datalen(sizeof(struct rime_ping_msg));
#if TIMESYNCH_CONF_ENABLED
    ping->pingtime = timesynch_time();
#else
    ping->pingtime = rtimer_arch_now();
#endif
    mesh_send(&mesh, &receiver);

    etimer_set(&timeout, CLOCK_SECOND * 8);
    etimer_set(&periodic, CLOCK_SECOND * 1);
    waiting_for_pong = 1;
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout) ||
			     waiting_for_pong == 0);
    if(waiting_for_pong == 0) {
      PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
    } else {
      shell_output_str(&rime_ping_command,
		       "Timed out", "");
    }
    waiting_for_pong = 0;
  }
  PROCESS_END();
}
开发者ID:Jean-Emile,项目名称:kevoree-IoT,代码行数:50,代码来源:shell-rime-ping.c


示例11: input_packet

/*---------------------------------------------------------------------------*/
static uint8_t
input_packet(struct net_buf *buf)
{
  frame802154_t frame;
  int len;

  len = packetbuf_datalen(buf);
  PRINTF("6MAC: received %d bytes\n", len);

  if(frame802154_parse(packetbuf_dataptr(buf), len, &frame) &&
     packetbuf_hdrreduce(buf, len - frame.payload_len)) {
    if(frame.fcf.dest_addr_mode) {
      if(frame.dest_pid != mac_src_pan_id &&
         frame.dest_pid != FRAME802154_BROADCASTPANDID) {
        /* Not broadcast or for our PAN */
        PRINTF("6MAC: for another pan %u (0x%x)\n", frame.dest_pid,
               frame.dest_pid);
        goto error;
      }
      if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr)) {
        packetbuf_set_addr(buf, PACKETBUF_ADDR_RECEIVER, (linkaddr_t *)&frame.dest_addr);
#if !NETSTACK_CONF_BRIDGE_MODE
        if(!linkaddr_cmp(packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER),
                         &linkaddr_node_addr)) {
          /* Not for this node */
	  PRINTF("6MAC: not for us, we are ");
	  PRINTLLADDR((uip_lladdr_t *)&linkaddr_node_addr);
	  PRINTF(" recipient is ");
	  PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
	  PRINTF("\n");
	  goto error;
        }
#endif
      }
    }
    packetbuf_set_addr(buf, PACKETBUF_ADDR_SENDER, (linkaddr_t *)&frame.src_addr);

    PRINTF("6MAC-IN: type 0x%X sender ", frame.fcf.frame_type);
    PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(buf, PACKETBUF_ADDR_SENDER));
    PRINTF(" receiver ");
    PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(buf, PACKETBUF_ADDR_RECEIVER));
    PRINTF(" len %u\n", packetbuf_datalen(buf));
    return NETSTACK_MAC.input(buf);
  } else {
    PRINTF("6MAC: failed to parse hdr\n");
  }
error:
  return 0;
}
开发者ID:32bitmicro,项目名称:zephyr,代码行数:50,代码来源:sicslowmac.c


示例12: recv_runicast

static void
recv_runicast(struct runicast_conn *c, const linkaddr_t *from, uint8_t seqno)
{
	struct history_entry *e = NULL;
	int16_t data, id;

	for(e = list_head(history_table); e != NULL; e = e->next)
	{
		if(linkaddr_cmp(&e->addr, from))
		{
			break;
		}
	}

	if(e == NULL)
	{
		/* Create new history entry */
		e = memb_alloc(&history_mem);
		if(e == NULL)
		{
			e = list_chop(history_table); /* Remove oldest at full history */
		}
		linkaddr_copy(&e->addr, from);
		e->seq = seqno;
		list_push(history_table, e);
	}
	else
	{
		/* Detect duplicate callback */
		if(e->seq == seqno)
		{
			printf("runicast message received from %d.%d, seqno %d (DUPLICATE)\n",
					from->u8[0], from->u8[1], seqno);
		}
		/* Update existing history entry */
		e->seq = seqno;
	}

	printf("Basestation: runicast message received from %d.%d, seqno %d\n",
			from->u8[0], from->u8[1], seqno);

	struct runicast_message *received_msg = packetbuf_dataptr();

	if (received_msg->type == RUNICAST_TYPE_TEMP)
	{
		time_delay = received_msg->data;

		printf("Temperature from actuator %d has value %d",id,data)
	}
开发者ID:e-nikolov,项目名称:NES2015,代码行数:49,代码来源:basestation.c


示例13: recv_uc

static void
recv_uc(struct unicast_conn *c, const rimeaddr_t *from)
{
  printf("Unicast message received from %d.%d : '%s'\n", from->u8[0], from->u8[1], (char *)packetbuf_dataptr());
  printf("The Received Signal Strength is: %d\n", (cc2420_last_rssi -45) );

  char *recvdmsg = (char *)packetbuf_dataptr();
  char *no = strchr(recvdmsg, ' ');  
  leds_toggle(LEDS_ALL);

  if(from->u8[0] == 1)
  {
    unicast_ack(from , no);
  }
}
开发者ID:NitinSRKalavala,项目名称:RSSI-and-PRR-using-Tmotes,代码行数:15,代码来源:assignment1.c


示例14: broadcast_publication

void
broadcast_publication(struct subscription_item *si) {
	struct publish_message *msg;
	packetbuf_clear();
	packetbuf_set_attr(PACKETBUF_ATTR_PACKET_TYPE, MWARE_MSG_PUB);
	packetbuf_set_datalen(sizeof(struct publish_message));
	msg = packetbuf_dataptr();
	memcpy(&msg->id, &si->id,sizeof(struct identifier));
	rimeaddr_copy(&msg->next_hop, &si->next_hop);
	msg->data = si->data;
	msg->node_count = si->node_count;
	if (broadcast_send(&connection)) {
		subscription_print(si, "bp");
	}
}
开发者ID:sengjea,项目名称:mware,代码行数:15,代码来源:mware.c


示例15: read_packet

/*---------------------------------------------------------------------------*/
static int
read_packet(void)
{
  frame802154_t frame;
  int len;
  packetbuf_clear();
  len = radio->read(packetbuf_dataptr(), PACKETBUF_SIZE);
  if(len > 0) {
    packetbuf_set_datalen(len);
    if(frame802154_parse(packetbuf_dataptr(), len, &frame) &&
       packetbuf_hdrreduce(len - frame.payload_len)) {
      if(frame.fcf.dest_addr_mode) {
        if(frame.dest_pid != mac_src_pan_id &&
           frame.dest_pid != FRAME802154_BROADCASTPANDID) {
          /* Not broadcast or for our PAN */
          PRINTF("6MAC: for another pan %u\n", frame.dest_pid);
          return 0;

        }
        if(!is_broadcast_addr(frame.fcf.dest_addr_mode, frame.dest_addr.u8)) {
          packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &frame.dest_addr);
        }
      }
      packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &frame.src_addr);

      PRINTF("6MAC-IN: %2X", frame.fcf.frame_type);
      PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER));
      PRINTADDR(packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
      PRINTF("%u\n", packetbuf_datalen());
      return packetbuf_datalen();
    } else {
      PRINTF("6MAC: failed to parse hdr\n");
    }
  }
  return 0;
}
开发者ID:kincki,项目名称:contiki,代码行数:37,代码来源:sicslowmac.c


示例16: PROCESS_THREAD

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(cooja_radio_process, ev, data)
{
  int len;
  char dupbuf[PACKETBUF_SIZE];
  int duplen;

  PROCESS_BEGIN();

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);

    packetbuf_clear();
    len = radio_read(packetbuf_dataptr(), PACKETBUF_SIZE);
    memcpy(dupbuf, packetbuf_dataptr(), len);
    duplen = len;
    if(len > 0) {
      PRINTF("COOJA: receiving %d bytes @ %lu\n", len, clock_time());
      packetbuf_set_datalen(len);
      NETSTACK_RDC.input();
    }
  }

  PROCESS_END();
}
开发者ID:kincki,项目名称:contiki,代码行数:25,代码来源:cooja-radio.c


示例17: recv_from_abc

/*---------------------------------------------------------------------------*/
static void recv_from_abc(struct abc_conn *bc)
{

	if (bc == NULL)
	{
		PRINTF("[pbroadcast.c] Error: ABC Connection is NULL\n");
		return;
	}

	linkaddr_t sender;
	struct p_broadcast_conn *c = (struct p_broadcast_conn *)bc;

	linkaddr_copy(&sender, packetbuf_addr(PACKETBUF_ADDR_SENDER));

	uint16_t actual_hash = packet_hash(packetbuf_dataptr(), packetbuf_datalen() - sizeof(uint16_t));
	uint8_t *hash_ptr = packetbuf_dataptr() + (uintptr_t)(packetbuf_datalen() - sizeof(uint16_t));
	uint16_t transmitted_hash = (hash_ptr[1] << 8) + (hash_ptr[0]);

	PRINTF("[pbroadcast.c] Received message of size %d from %d.%d.\n", packetbuf_datalen() - sizeof(uint16_t), sender.u8[0], sender.u8[1]);
	PRINTF("[pbroadcast.c] ^ Data: ");
	DEBUG_DUMP_DATA(packetbuf_dataptr(), packetbuf_datalen());
	PRINTF("\n");

	PRINTF("[pbroadcast.c] ^ Hash: %02X\n", transmitted_hash);

	if (actual_hash != transmitted_hash)
	{
		PRINTF("[pbroadcast.c] ^ Incorrect hash (expected %02X, but is %02X); discarding received packet.\n", transmitted_hash, actual_hash);
		return;
	}

	if (c->received)
	{
		c->received(c, &sender, packetbuf_dataptr(), packetbuf_datalen() - sizeof(uint16_t));
	}
}
开发者ID:tud-bp-sensornet,项目名称:sensornet,代码行数:37,代码来源:pbroadcast.c


示例18: PROCESS_THREAD

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sendcmd_process, ev, data)
{
  struct cmd_msg  *msg;
  int len;
  linkaddr_t addr;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  addr.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&sendcmd_command,
             "sendcmd <node addr>: receiver must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  addr.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", addr.u8[0], addr.u8[1]);
  shell_output_str(&sendcmd_command, "Sending command to ", buf);

  /* Get the length of the command line, excluding a terminating NUL character. */
  len = strlen((char *)nextptr);

  /* Check the length of the command line to see that it is small
     enough to fit in a packet. We count with 32 bytes of header,
     which may be a little too much, but at least we are on the safe
     side. */
  if(len > PACKETBUF_SIZE - 32) {
    snprintf(buf, sizeof(buf), "%d", len);
    shell_output_str(&sendcmd_command, "command line too large: ", buf);
    PROCESS_EXIT();
  }

  packetbuf_clear();
  msg = packetbuf_dataptr();
  packetbuf_set_datalen(len + 1 + CMDMSG_HDR_SIZE);
  strcpy(msg->sendcmd, nextptr);

  /* Terminate the string with a NUL character. */
  msg->sendcmd[len] = 0;
  msg->crc = crc16_data((unsigned char *)msg->sendcmd, len, 0);
  /*    printf("sendcmd sending '%s'\n", msg->sendcmd);*/
  unicast_send(&uc, &addr);

  PROCESS_END();
}
开发者ID:13416795,项目名称:contiki,代码行数:49,代码来源:shell-rime-sendcmd.c


示例19: adv_packet_received

/*---------------------------------------------------------------------------*/
static void
adv_packet_received(struct ipolite_conn *ipolite, const rimeaddr_t *from)
{
  struct announcement_msg *adata = packetbuf_dataptr();
  int i;

  PRINTF("%d.%d: adv_packet_received from %d.%d with %d announcements\n",
	 rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	 from->u8[0], from->u8[1], adata->num);

  for(i = 0; i < adata->num; ++i) {
    announcement_heard(from,
		       adata->data[i].id,
		       adata->data[i].value);
  }
}
开发者ID:soohyunc,项目名称:contiki-2.x,代码行数:17,代码来源:polite-announcement.c


示例20: netflood_send

/*---------------------------------------------------------------------------*/
int
netflood_send(struct netflood_conn *c, uint8_t seqno)
{
  if(packetbuf_hdralloc(sizeof(struct netflood_hdr))) {
    struct netflood_hdr *hdr = packetbuf_hdrptr();
    rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
    rimeaddr_copy(&c->last_originator, &hdr->originator);
    c->last_originator_seqno = hdr->originator_seqno = seqno;
    hdr->hops = 0;
    PRINTF("%d.%d: netflood sending '%s'\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	   (char *)packetbuf_dataptr());
    return ipolite_send(&c->c, 0, 4);
  }
  return 0;
}
开发者ID:Inscribe,项目名称:msp430xf1611,代码行数:17,代码来源:netflood.c



注:本文中的packetbuf_dataptr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ packetbuf_hdrptr函数代码示例发布时间:2022-05-30
下一篇:
C++ packetbuf_datalen函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap