大家好、
在 cc2650上运行 UDP-client 进程时、我需要读取串行输入(DIO3)。 如果有人知道如何编辑代码、请按如下所示帮助我。udp-client.c、我只需要在数据包发送时读取可用的串行输入/以前的输入 AD 随数据包一起发送它们。 如果有人知道如何在代码中对其进行编码 、请编辑此代码并粘贴。非常有用。
#include "contiki.h"
#include "lib/random.h"
#include "sys/ctimer.h"
#include "net/IP/UIP.h"
#include "net/ipv6/uip-ds6.h"
#include "net/IP/UIP-udp-packet.h"
#include "sys/ctimer.h"
#ifdef with _COMPOWER
#include "powertrace.h"
#endif
#include
#include
#define UDP_CLIENT_PORT 8765
#define UDP_SERVER_PORT 5678
#define UDP_Example_ID 190
#define debug debug_print
#include "net/IP/UIP-debug.h"
ifndef 周期
#define period 60
#endif
#define START_INTERVAL (15 * CLOCK _second)
#define SEND_INTERVAL (周期* CLOCK 秒)
#define SEND_TIME (rand_rand()%(SEND_INTERVAL))
#define MAX_PAYLOAD_LEN 30.
静态结构 uip_udp_conn * client_conn;
静态 uip_ipaddr_t server_ipaddr;
/*------------------ *
进程(udp_client_process、"UDP 客户端进程");
autostart_processes (&udp_client_process);
/*------------------ *
静态空
TCPIP_handler (空)
{
char *str;
if (uip_newdata()){
STR = UIP_appdata;
STR[UIP_datalen ()]='\0';
printf ("数据恢复'%s'\n"、str);
}
}
/*------------------ *
静态空
send_packet (void * ptr)
{
静态 int seq_id;
char buf[MAX_PAYLOAD_LEN];
seq_id++;
printf ("数据发送到%d 'Hello %d'\n"、
server_ipaddr.u8[sizeof (server_ipaddr.u8)- 1]、seq_id);
sprintf (buf、"Hello %d from the client"、Seq_id);
uip_udp_packet_sendto (client_conn、buf、strlen (buf)、
&server_ipaddr、UIP_HTONS (UDP_SERVER_PORT);
}
/*------------------ *
静态空
print_local_addresses (void)
{
int i;
uint8_t state;
printf ("客户端 IPv6地址:");
对于(I = 0;I < UIP_DS6_ADDR_NB;i++){
状态= UIP_ds6_if.addr_list[i].state;
if (uip_ds6_if.addr_list[i].isused &&
(STATE = ADDR_Tentative || STATE = ADDR_Preferred)){
PRINT6ADDR (&UIP_ds6_if.addr_list[i].ipaddr);
printf ("\n");
//将地址设为“最终”*/
if (state ==ADDR_Tentative){
uip_ds6_if.addr_list[i].state = ADDR_Preferred;
}
}
}
}
/*------------------ *
静态空
SET_GLOBAL_ADDRESS (空)
{
uip_ipaddr_t ipaddr;
UIP_ip6addr (&ipaddr、0xaaaa、0、0、0、 0、0、0、0);
uip_ds6_set_addr_iid (&ipaddr、&uip_lladdr);
uip_ds6_addr_add (&ipaddr、0、ADDR_autoconf);
/*服务器地址的选择决定了其6LoPAN 报头压缩。
*(我们的地址将是压缩模式3、因为它来自我们的链路本地地址)
*当然,在 udp-server.c 中也必须选择此处所做的选择
*
*要使用监听器正确解码 Wireshark、请在6LowPAN 协议首选项中添加/64前缀、
*例如、将上下文0设置为 AAAA::。 目前、Wireshark 会复制上下文/128、然后覆盖它。
*(将上下文0设置为 AAAA:1111:2222:3333:4444将报告 AAAA 的16位压缩地址::1111:22ff:fe33:xxxx)
*
*注意 IPCMV6校验和验证取决于正确的未压缩地址。
*
#if 0
/*模式1 - 64位内联*/
uip_ip6addr (&server_ipaddr、0xaaaa、0、0、0、0、 0、0、0、1);
#Elif 1.
/*模式2 - 16位内联*/
uip_ip6addr (&server_ipaddr、0xaaaa、0、0、0、0、 0、0x00ff、0xfe00、1);
其他
/*模式3 -源自服务器本地链路(MAC)地址*/
uip_ip6addr (&server_ipaddr、0xaaaa、0、0、0、0、 0x0250、0xc2ff、0x羽毛8、0xcd1a);//redbe-econotag
#endif
}
/*------------------ *
process_thread (udp_client_process、EV、data)
{
静态结构 etimer 周期;
静态结构 ctimer backoff_timer;
#if with _COMPOWER
静态 int print = 0;
#endif
process_bege();
process_paus();
set_global_address();
printf ("UDP 客户端进程已启动\n");
print_local_addresses();
/*与远程主机的新连接*/
client_conn = UDP_new (NULL、UIP_HTONS (UDP_SERVER_PORT)、NULL);
if (client_conn =NULL){
printf ("没有可用的 UDP 连接、正在退出此过程!\n");
process_exit();
}
udp_bind (client_conn、UIP_HTONS (udp_client_port));
printf("创建了与服务器的连接");
PRINT6ADDR (&client_conn->ripaddr);
printf ("本地/远程端口%u/%u\n"、
UIP_HTONS (client_conn->lport)、UIP_HTONS (client_conn->rport);
#if with _COMPOWER
powertrace_sniff (POWERTRACE_ON);
#endif
etimer_set (&periodic、send_interval);
while (1){
process_yield ();
if (EV = TCPIP_EVENT){
TCPIP_handler();
}
if (etimer_expired (&periodic)){
etimer_reset (周期性);
ctimer_set (&backoff_timer、send_time、send_packet、NULL);
#if with _COMPOWER
如果(print ==0){
powertrace_print ("#P");
}
如果(++print == 3){
Print = 0;
}
#endif
}
}
process_end();
}
/*------------------ *