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

C++ packetbuf_hdrptr函数代码示例

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

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



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

示例1: handle_beacon_send_timer

/*---------------------------------------------------------------------------*/
static void
handle_beacon_send_timer(struct net_buf *buf, void *p)
{
  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_BEACONFRAME;

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

  /* assume long for now */
  params.fcf.src_addr_mode = FRAME802154_LONGADDRMODE;
  linkaddr_copy((linkaddr_t *)&params.src_addr, &linkaddr_node_addr);

  /* Set the source PAN ID to the global variable. */
  params.src_pid = panid;

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

  params.dest_pid = 0xffff;

  params.seq = framer_802154_next_seqno();

  /* Calculate beacon length and copy it to packetbuf */
  beacon_payload_len = handler_802154_calculate_beacon_payload_length(beacon_payload, BEACON_PAYLOAD_BUFFER_SIZE);
  packetbuf_copyfrom(mbuf, beacon_payload, beacon_payload_len);

  /* Set payload and payload length */
  params.payload = packetbuf_dataptr(mbuf);
  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_sent++);
  }
}
开发者ID:CurieBSP,项目名称:zephyr,代码行数:59,代码来源:handler-802154.c


示例2: output

/*---------------------------------------------------------------------------*/
static int
output(struct channel *c)
{
  const struct packetbuf_attrlist *a;
  int byteptr, len;
  uint8_t *hdrptr;
  struct raw_hdr *hdr;
  
  /* Compute the total size of the final header by summing the size of
     all attributes that are used on this channel. */
  if(packetbuf_hdralloc(c->hdrsize + sizeof(struct raw_hdr)) == 0) {
    PRINTF("chameleon-raw: insufficient space for headers\n");
    return 0;
  }
  hdr = (struct raw_hdr *)packetbuf_hdrptr();
  hdr->channel[0] = c->channelno & 0xff;
  hdr->channel[1] = (c->channelno >> 8) & 0xff;

  hdrptr = ((uint8_t *)packetbuf_hdrptr()) + sizeof(struct raw_hdr);
  byteptr = 0;
  for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
#if CHAMELEON_WITH_MAC_LINK_ADDRESSES
    if(a->type == PACKETBUF_ADDR_SENDER ||
       a->type == PACKETBUF_ADDR_RECEIVER) {
      /* Let the link layer handle sender and receiver */
      PRINTF("%d.%d: pack_header leaving sender/receiver to link layer\n");
      continue;
    }
#endif /* CHAMELEON_WITH_MAC_LINK_ADDRESSES */
    PRINTF("%d.%d: pack_header type %d, len %d\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	   a->type, a->len);
    len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
    if(PACKETBUF_IS_ADDR(a->type)) {
      const rimeaddr_t *rimeaddr;
      /*      memcpy(&hdrptr[byteptr], (uint8_t *)packetbuf_attr_aget(a->type), len / 8);*/
      rimeaddr = packetbuf_addr(a->type);
      hdrptr[byteptr] = rimeaddr->u8[0];
      hdrptr[byteptr + 1] = rimeaddr->u8[1];
      
      PRINTF("%d.%d: address %d.%d\n",
	    rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	    ((uint8_t *)packetbuf_addr(a->type))[0],
	    ((uint8_t *)packetbuf_addr(a->type))[1]);
    } else {
      packetbuf_attr_t val;
      val = packetbuf_attr(a->type);
      memcpy(&hdrptr[byteptr], &val, len / 8);
      PRINTF("%d.%d: value %d\n",
	    rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	    val);
    }
    byteptr += len / 8;
  }

  return 1; /* Send out packet */
}
开发者ID:1uk3,项目名称:contiki,代码行数:58,代码来源:chameleon-raw.c


示例3: packet_input

/*---------------------------------------------------------------------------*/
static void
packet_input(void)
{
#if NETSTACK_CONF_WITH_IP64
  /* If NAT64 is enabled, IPv4 & ARP packets are sent to the IP64 module */
  ethernet_header_t *hdr = (ethernet_header_t *)packetbuf_hdrptr();
  if (hdr->et_protlen == UIP_HTONS(ETH_PROT_IP) ||
    hdr->et_protlen == UIP_HTONS(ETH_PROT_ARP)) {
    IP64_INPUT(packetbuf_hdrptr(), packetbuf_totlen());
    return;
  }
#endif /* NETSTACK_CONF_WITH_IP64 */
  if(NETSTACK_0_FRAMER.parse() < 0) {
    PRINTF("ieee8023_mac: failed to parse %u\n", (unsigned int)packetbuf_datalen()); 
#if IEEE8023_MAC_ADDRESS_FILTER
  } else if(!linkaddr6_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
      &linkaddr6_node_addr) &&
      !linkaddr6_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
      &linkaddr6_null)) {
    /*\note The framer should have done the multicast address
     * translation from 0x33 0x33 0xXX... to the 802.3xx null
     */     
    PRINTF("ieee8023_mac: not for us\n");
#endif /* IEEE8023_MAC_ADDRESS_FILTER */                
  } else {
    int duplicate = 0;
    duplicate = mac_sequence_is_duplicate();

    if(duplicate && ETH_SUPPORT_DUPLICATE_DETECTION) {
      /* Drop the packet. */
      PRINTF("ieee8023_mac: drop duplicate link layer packet %u\n",
      packetbuf_attr(PACKETBUF_ATTR_PACKET_ID));
    } else {
      mac_sequence_register_seqno();
    }
#if DEBUG
    int i;
    uint16_t original_datalen = packetbuf_totlen();
    uint8_t *original_dataptr = packetbuf_hdrptr();
    PRINTF("PKT[%u]:",original_datalen);
    for (i=0; i<original_datalen; i++) {
      PRINTF("%02x ",original_dataptr[i]);
    }
    PRINTF("\n");
#endif

    if(!(duplicate && ETH_SUPPORT_DUPLICATE_DETECTION)) {
      link_if_in(NETSTACK_8023);
      NETSTACK_0_NETWORK.input();
      link_if_in(NETSTACK_NULL);
    } else {
      PRINTF("IEEE8023_MAC: drop duplicate\n");
    }
  }       
}
开发者ID:ioannisg,项目名称:Contiki_ATSAM4EXPRO,代码行数:56,代码来源:ieee8023_mac.c


示例4: 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


示例5: output

/*---------------------------------------------------------------------------*/
static int
output(struct channel *c)
{
  const struct packetbuf_attrlist *a;
  int byteptr, len;
  uint8_t *hdrptr;
  struct raw_hdr *hdr;
  
  /* Compute the total size of the final header by summing the size of
     all attributes that are used on this channel. */
  packetbuf_hdralloc(c->hdrsize);
  hdrptr = packetbuf_hdrptr();
  byteptr = 0;
  for(a = c->attrlist; a->type != PACKETBUF_ATTR_NONE; ++a) {
    PRINTF("%d.%d: pack_header type %s, len %d\n",
	   rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	   packetbuf_attr_strings[a->type], a->len);
    len = (a->len & 0xf8) + ((a->len & 7) ? 8: 0);
    if(a->type == PACKETBUF_ADDR_SENDER ||
       a->type == PACKETBUF_ADDR_RECEIVER ||
       a->type == PACKETBUF_ADDR_ESENDER ||
       a->type == PACKETBUF_ADDR_ERECEIVER) {
      const rimeaddr_t *rimeaddr;
      /*      memcpy(&hdrptr[byteptr], (uint8_t *)packetbuf_attr_aget(a->type), len / 8);*/
      rimeaddr = packetbuf_addr(a->type);
      hdrptr[byteptr] = rimeaddr->u8[0];
      hdrptr[byteptr + 1] = rimeaddr->u8[1];
      
      PRINTF("%d.%d: address %d.%d\n",
	    rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	    ((uint8_t *)packetbuf_addr(a->type))[0],
	    ((uint8_t *)packetbuf_addr(a->type))[1]);
    } else {
      packetbuf_attr_t val;
      val = packetbuf_attr(a->type);
      memcpy(&hdrptr[byteptr], &val, len / 8);
      PRINTF("%d.%d: value %d\n",
	    rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1],
	    val);
    }
    byteptr += len / 8;
  }

  packetbuf_hdralloc(sizeof(struct raw_hdr));
  hdr = (struct raw_hdr *)packetbuf_hdrptr();
  hdr->channel = c->channelno;
  
  return 1; /* Send out packet */
}
开发者ID:hummingbird2012,项目名称:hummingbird,代码行数:50,代码来源:chameleon-raw.c


示例6: PROCESS_THREAD

PROCESS_THREAD(rime_udp_process, ev, data)
{
  static uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();

  broadcast_conn = udp_broadcast_new(HTONS(RIME_UDP_PORT), NULL);
  if(broadcast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a broadcast connection!\n");
  }

  uip_create_unspecified(&ipaddr);
  unicast_conn = udp_new(&ipaddr, HTONS(RIME_UDP_PORT), NULL);
  if(unicast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a unicast connection!\n");
  }

  udp_bind(unicast_conn, HTONS(RIME_UDP_PORT));

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    if(uip_newdata()) {
      packetbuf_clear();
      memmove(packetbuf_hdrptr(), uip_appdata, uip_datalen());
      PRINTF("rime-udp: received %d bytes\n", uip_datalen());
      receiver_callback(&rime_udp_driver);
    }
  }

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


示例7: rmh_send

/*---------------------------------------------------------------------------*/
int
rmh_send(struct rmh_conn *c, rimeaddr_t *to, uint8_t num_rexmit, uint8_t max_hops)
{
  rimeaddr_t *nexthop;
  struct data_hdr *hdr;

  c->num_rexmit = num_rexmit;

  if(c->cb->forward == NULL) {
    return 0;
  }

  nexthop = c->cb->forward(c, &rimeaddr_node_addr, to, NULL, 0);
  if(nexthop == NULL) {
    PRINTF("rmh_send: no route\n");
    return 0;
  } else {
    PRINTF("rmh_send: sending data\n");


    if(packetbuf_hdralloc(sizeof(struct data_hdr))) {
      hdr = packetbuf_hdrptr();
      rimeaddr_copy(&hdr->dest, to);
      rimeaddr_copy(&hdr->originator, &rimeaddr_node_addr);
      hdr->hops = 1;
      hdr->max_rexmits = num_rexmit;
      runicast_send(&c->c, nexthop, num_rexmit);
    }
    return 1;
  }
}
开发者ID:EDAyele,项目名称:wsn430,代码行数:32,代码来源:rmh.c


示例8: input_packet

/* -------------------------------------------------------------------- */
static void input_packet(void)
{
  static struct packet_s reference_packet;
  static uint16_t last_number;
  static uint16_t rx_ok;
  static uint16_t rx_corrupt;

  struct packet_s *p = (struct packet_s *) packetbuf_hdrptr();

  if(memcmp(p->filling, reference_packet.filling, sizeof(p->filling))) {
    /* corrupt packet detected */
    rx_corrupt++;
    return;
  }

  if(last_number > p->number) {
    printf("Out of 100 packets %u seen, %u good, %u corrupt\n",
        rx_ok + rx_corrupt + (uint16_t)rimestats.badcrc,
        rx_ok, rx_corrupt + (uint16_t)rimestats.badcrc);
    rx_ok = 0;
    rx_corrupt = 0;
    rimestats.badcrc = 0;
  }

  rx_ok++;
  last_number = p->number;
}
开发者ID:atiselsts,项目名称:contiki,代码行数:28,代码来源:test.c


示例9: send_announcement

static void
send_announcement(void *ptr)
{
  struct xmac_hdr *hdr;
  int announcement_len;

  /* Set up the probe header. */
  packetbuf_clear();
  hdr = packetbuf_dataptr();

  announcement_len = format_announcement((char *)hdr +
					 sizeof(struct xmac_hdr));

  if(announcement_len > 0) {
    packetbuf_set_datalen(sizeof(struct xmac_hdr) + announcement_len);
    hdr->dispatch = DISPATCH;
    hdr->type = TYPE_ANNOUNCEMENT;

    packetbuf_set_addr(PACKETBUF_ADDR_SENDER, &rimeaddr_node_addr);
    packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &rimeaddr_null);
    packetbuf_set_attr(PACKETBUF_ATTR_RADIO_TXPOWER, announcement_radio_txpower);
    if(NETSTACK_FRAMER.create() >= 0) {
      NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
    }
  }
}
开发者ID:lanada-sensor,项目名称:plb,代码行数:26,代码来源:xmac.c


示例10: send_packet

/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
  if(radio->send(packetbuf_hdrptr(), packetbuf_totlen()) == RADIO_TX_OK) {
    return MAC_TX_OK;
  }
  return MAC_TX_ERR;
}
开发者ID:arbraham,项目名称:hummingbird,代码行数:9,代码来源:nullmac.c


示例11: packetbuf_copyto

/*---------------------------------------------------------------------------*/
int
packetbuf_copyto(void *to)
{
  if(packetbuf->hdrlen + packetbuf->datalen > PACKETBUF_SIZE) {
    return 0;
  }
  memcpy(to, packetbuf_hdrptr(), packetbuf->hdrlen);
  memcpy((uint8_t *)to + packetbuf->hdrlen, packetbuf_dataptr(), packetbuf->datalen);
  return packetbuf->hdrlen + packetbuf->datalen;
}
开发者ID:kkrentz,项目名称:contiki,代码行数:11,代码来源:packetbuf.c


示例12: packetbuf_copyto

/*---------------------------------------------------------------------------*/
int
packetbuf_copyto(void *to)
{
  if(hdrlen + buflen > PACKETBUF_SIZE) {
    return 0;
  }
  memcpy(to, packetbuf_hdrptr(), hdrlen);
  memcpy((uint8_t *)to + hdrlen, packetbuf_dataptr(), buflen);
  return hdrlen + buflen;
}
开发者ID:13416795,项目名称:contiki,代码行数:11,代码来源:packetbuf.c


示例13: send_packet

/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
{
  int ret;
  if(NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen()) == RADIO_TX_OK) {
    ret = MAC_TX_OK;
  } else {
    ret =  MAC_TX_ERR;
  }
  mac_call_sent_callback(sent, ptr, ret, 1);
}
开发者ID:paolope,项目名称:Contiki-MspCodeWatcherImproved,代码行数:12,代码来源:nullrdc-noframer.c


示例14: send_packet

/*---------------------------------------------------------------------------*/
static int
send_packet(void)
{
  const rimeaddr_t *addr;

  addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
  PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
         addr->u8[RIMEADDR_SIZE-2], addr->u8[RIMEADDR_SIZE-1]);

  if(rimeaddr_cmp(&rimeaddr_null, addr)) {
    uip_udp_packet_send(broadcast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
  } else {
    uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
    uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
    uip_udp_packet_send(unicast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    uip_create_unspecified(&unicast_conn->ripaddr);
  }
  return 1;
}
开发者ID:kincki,项目名称:contiki,代码行数:22,代码来源:rime-udp.c


示例15: send_packet

/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent_callback, void *ptr)
{
  const rimeaddr_t *addr;

  addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
  PRINTF("rime-udp: Sending %d bytes to %d.%d\n", packetbuf_totlen(),
         addr->u8[0], addr->u8[1]);

  if(rimeaddr_cmp(&rimeaddr_null, addr)) {
    uip_udp_packet_send(broadcast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    mac_call_sent_callback(sent_callback, ptr, MAC_TX_OK, 1);
  } else {
    uip_ip6addr(&unicast_conn->ripaddr, 0xfe80, 0, 0, 0, 0, 0, 0, 0);
    uip_netif_addr_autoconf_set(&unicast_conn->ripaddr, (uip_lladdr_t *)addr);
    uip_udp_packet_send(unicast_conn,
                        packetbuf_hdrptr(), packetbuf_totlen());
    uip_create_unspecified(&unicast_conn->ripaddr);
  }
  return;
}
开发者ID:EmuxEvans,项目名称:ContikiCC2530Port,代码行数:23,代码来源:rime-udp.c


示例16: send_probe

/**
 * Send a probe packet.
 */
static void
send_probe(void)
{
  struct lpp_hdr *hdr;
  struct announcement_msg *adata;
  struct announcement *a;

  /* Set up the probe header. */
  packetbuf_clear();
  packetbuf_set_datalen(sizeof(struct lpp_hdr));
  hdr = packetbuf_dataptr();
  hdr->type = TYPE_PROBE;
  rimeaddr_copy(&hdr->sender, &rimeaddr_node_addr);
  /*  rimeaddr_copy(&hdr->receiver, packetbuf_addr(PACKETBUF_ADDR_RECEIVER));*/
  rimeaddr_copy(&hdr->receiver, &rimeaddr_null);

  packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &rimeaddr_null);
  {
    int hdrlen = NETSTACK_FRAMER.create();
    if(hdrlen == 0) {
      /* Failed to send */
      return;
    }
  }
  
  /* Construct the announcements */
  adata = (struct announcement_msg *)((char *)hdr + sizeof(struct lpp_hdr));
  
  adata->num = 0;
  for(a = announcement_list(); a != NULL; a = list_item_next(a)) {
    adata->data[adata->num].id = a->id;
    adata->data[adata->num].value = a->value;
    adata->num++;
  }

  packetbuf_set_datalen(sizeof(struct lpp_hdr) +
		      ANNOUNCEMENT_MSG_HEADERLEN +
		      sizeof(struct announcement_data) * adata->num);

  /*  PRINTF("Sending probe\n");*/

  /*  printf("probe\n");*/

  if(NETSTACK_RADIO.channel_clear()) {
    NETSTACK_RADIO.send(packetbuf_hdrptr(), packetbuf_totlen());
  } else {
    off_time_adjustment = random_rand() % (OFF_TIME / 2);
  }

  compower_accumulate(&compower_idle_activity);
}
开发者ID:Asterios,项目名称:contiki-econotag,代码行数:54,代码来源:lpp.c


示例17: 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


示例18: create

/*---------------------------------------------------------------------------*/
static int
create(void)
{
  struct nullmac_hdr *hdr;

  if(packetbuf_hdralloc(sizeof(struct nullmac_hdr))) {
    hdr = packetbuf_hdrptr();
    linkaddr_copy(&(hdr->sender), &linkaddr_node_addr);
    linkaddr_copy(&(hdr->receiver), packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
    return sizeof(struct nullmac_hdr);
  }
  PRINTF("PNULLMAC-UT: too large header: %u\n", sizeof(struct nullmac_hdr));
  return FRAMER_FAILED;
}
开发者ID:13416795,项目名称:contiki,代码行数:15,代码来源:framer-nullmac.c


示例19: send_nack

/*---------------------------------------------------------------------------*/
static void
send_nack(struct rudolph0_conn *c)
{
  struct rudolph0_hdr *hdr;
  packetbuf_clear();
  packetbuf_hdralloc(sizeof(struct rudolph0_hdr));
  hdr = packetbuf_hdrptr();

  hdr->type = TYPE_NACK;
  hdr->version = c->current.h.version;
  hdr->chunk = c->current.h.chunk;

  PRINTF("Sending nack for %d:%d\n", hdr->version, hdr->chunk);
  polite_send(&c->nackc, c->send_interval / 2, sizeof(struct rudolph0_hdr));
}
开发者ID:21moons,项目名称:contiki,代码行数:16,代码来源:rudolph0.c


示例20: plb_send_strobe

/*---------------------------------------------------------------------------*/
static char
plb_send_strobe(rimeaddr_t *dst, int *acked, uint8_t type)
{
  PRINTF("plb_send_strobe  [dst: %u.%u] [type: %x]\n",dst->u8[0],dst->u8[1],type);

  uint8_t strobe[MAX_STROBE_SIZE];
  int strobe_len = 0;
  rtimer_clock_t wt;

  // Make PLB header
  packetbuf_clear();
  if( (strobe_len = plb_create_header(dst,type)) < 0 ){
    return -1;
  }

  // Make packet -> strobe
  strobe_len = strobe_len +1;	// assign space for packet type
  if( strobe_len > (int)sizeof(strobe)) {
    /* Failed to send */
    PRINTF("plb: send failed, too large header\n");
    return -1;
  }
  memcpy(strobe, packetbuf_hdrptr(), strobe_len);

  /* Send beacon and wait ack : STROBE_NUM_MAX times */
  int strobe_num = 0;
  radio_on();

  while((strobe_num < STROBE_NUM_MAX) && ((*acked) == 0)){
    PRINTF("plb_send_strobe : strobe %d\n",strobe_num);

#if DEBUG_PACKET
    print_packet(strobe, strobe_len);
#endif

    if(NETSTACK_RADIO.send(strobe, strobe_len) != RADIO_TX_OK){
      return -1;
    }
    strobe_num ++;

    (*acked) = plb_wait_ack(type);
    if(*acked){
      PRINTF("ack! return: %d\n", *acked);
    }
  }
  radio_off();
  return 0;
}
开发者ID:deawoo,项目名称:contiki-2.7-plb,代码行数:49,代码来源:plb_backup_0218.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ packetbuf_totlen函数代码示例发布时间:2022-05-30
下一篇:
C++ packetbuf_dataptr函数代码示例发布时间: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