本文整理汇总了C++中packetbuf_dataptr函数的典型用法代码示例。如果您正苦于以下问题:C++ packetbuf_dataptr函数的具体用法?C++ packetbuf_dataptr怎么用?C++ packetbuf_dataptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了packetbuf_dataptr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
}
}
示例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);
}
示例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]);
}
}
}
示例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);
}
}
示例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++;
}
}
示例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();
}
示例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(¶ms, 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(¶ms);
if(packetbuf_hdralloc(mbuf, len)) {
frame802154_create(¶ms, 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++);
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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)
}
示例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);
}
}
示例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");
}
}
示例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;
}