在线时间16 小时
UID303348
ST金币0
蝴蝶豆0
注册时间2011-7-5
金牌会员
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
/* Private typedef -----------------------------------------------------------*/
static struct tcp_pcb *TcpPCB;
#define TCP_PORT 1234
uint8_t test[10]={1,2,3,4,5,6,7,8,9,0};
uint8_t RX[100];
uint32_t y;
extern uint8_t LocalDisplay[82];
/* Private function prototypes -----------------------------------------------*/
void LwIP_Init(void);
err_t tcp_client_accept(void *arg, struct tcp_pcb *pcb, err_t err);
static err_t tcp_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initialize the client application.
* @param None
* @retval None
*/
void tcp_client_init(void)
{
struct tcp_pcb *tpcb;
struct ip_addr ipaddr;
IP4_ADDR(&ipaddr, 192, 168, 1, 125); //远程主机
/* Create a new TCP control block */
tpcb = tcp_new();
/* Assign to the new pcb a local IP address and a port number */
tcp_bind(tpcb, IP_ADDR_ANY, TCP_PORT);
/* Connect to the server: send the SYN */
tcp_connect(tpcb, &ipaddr, TCP_PORT, tcp_client_accept);
}
/**
* @brief This funtion is called when a TCP connection has been established on the port TCP_PORT.
* @param arg user supplied argument
* @param pcb the tcp_pcb which accepted the connection
* @param err error value
* @retval ERR_OK
*/
err_t tcp_client_accept(void *arg, struct tcp_pcb *tpcb, err_t err)
{
/* Specify the function that should be called when the TCP connection receives data */
tcp_recv(tpcb, tcp_client_recv);
return ERR_OK;
}
/**
* @brief This function is called when a data is received over the TCP_PORT.
* The received data contains the number of the led to be toggled.
* @param arg user supplied argument
* @param pcb the tcp_pcb which accepted the connection
* @param p the packet buffer that was received
* @param err error value
* @retval ERR_OK
*/
static err_t tcp_client_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
uint8_t Data_len;
uint8_t hello[1] ={2};
/* Read Data*/
Data_len = p->len;
memcpy(RX, p->payload, Data_len);
tcp_write(tpcb,&hello,sizeof(hello),1);
tcp_output(tpcb);
/* Free the p buffer */
pbuf_free(p);
return ERR_OK;
} |
|