一種基于SOPC技術(shù)的EPA控制器
其部分報文處理程序如下:
/*報文發(fā)送*/
void SendTask(void *pdata){
struct netconn *conn;
struct ip_addr remote_addr,local_addr;
struct netbuf * buf;
struct udp_pcb * udpbuf;
struct pbuf * buf;
char text[] = A static test;
/*設(shè)置遠程主機的IP地址*/
remote_addr.addr = htonl(0x8080023D);
/*設(shè)置本地主機的IP地址*/
local_addr.addr = htonl(0x80800233);
for(;;){
/*建立一個新連接*/
conn = netconn_new(NETCONN_UDP);
/*綁定本地IP地址和端**/
netconn_bind(conn,local_addr,0x88BC);
/*連接遠程主機*/
netconn_connect(conn,remote_addr,0x88BC);
buf = netbuf_new();
/*建立任意的數(shù)據(jù)*/
netbuf_ref(buf,text,sizeof(text));
netconn_send(conn,buf);
netconn_delete(conn);
netbuf_delete(buf);
OSTimeDlyHMSM(0,0,1,0);
buf = pbuf_alloc(PBUF_RAW, 60,
PBUF_RAM);
memcpy(buf->payload,text,
sizeof(text));
udpbuf = udp_new();
udpbuf->local_port = 0x88bc;
udpbuf->remote_port = 0x88bc;
udpbuf->local_ip = local_addr;
udpbuf->remote_ip = remote_addr;
udp_bind(udpbuf, udpbuf->local_ip,
udpbuf->local_port);
udp_sendto(udpbuf,buf,remote_addr,udpbuf->remote_port);
udp_remove(udpbuf); //釋放
udp_pcb內(nèi)存
pbuf_free(buf);
OSTimeDlyHMSM(0,0,1,0);
/* Main initializes lwIP, creates a single task and starts task scheduler. */
void ReceiveTask(void * pdata){//該任務(wù)
和IP協(xié)議棧相關(guān),該任務(wù)由
_sys_thread_new函數(shù)來創(chuàng)建
struct netbuf * buf1,*buf2,*buf1_temp;
struct netconn * conn1,*conn2;
void * payload;
u16_t len;
struct ip_addr remote_addr,local_addr;
char text[] = I get a EPA packet,please
give me another,I need you, baby.;
remote_addr.addr = htonl
?。?x8080023D);
local_addr.addr = htonl(0x80800233);
conn1 = netconn_new(NETCONN_
UDP);
conn2 = netconn_new(NETCONN_
UDP);
p2p機相關(guān)文章:p2p原理
蜂鳴器相關(guān)文章:蜂鳴器原理
評論