optimize the codes with lwip and opcua
This commit is contained in:
@@ -84,6 +84,10 @@ int MountSDCard(void)
|
||||
#include <connect_adc.h>
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_I2C
|
||||
#include <connect_i2c.h>
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI
|
||||
#include <connect_spi.h>
|
||||
#endif
|
||||
@@ -688,6 +692,10 @@ void InitBoardHardware()
|
||||
Imrt1052HwAdcInit();
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_I2C
|
||||
Imrt1052HwI2cInit();
|
||||
#endif
|
||||
|
||||
#ifdef BSP_USING_SPI
|
||||
Imrt1052HwSpiInit();
|
||||
#endif
|
||||
|
||||
@@ -143,7 +143,7 @@ static int BoardI2cDevBend(void)
|
||||
}
|
||||
|
||||
/*BOARD I2C INIT*/
|
||||
int Stm32HwI2cInit(void)
|
||||
int Imrt1052HwI2cInit(void)
|
||||
{
|
||||
static int init_flag = 0;
|
||||
x_err_t ret = EOK;
|
||||
|
||||
@@ -65,7 +65,6 @@ void I2cEEpromTestWrite(void)
|
||||
|
||||
int I2cEEpromTest(void)
|
||||
{
|
||||
Stm32HwI2cInit();
|
||||
BOARD_InitI2C1Pins();
|
||||
I2cHardwareInit();
|
||||
I2cEEpromTestWrite();
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef struct Stm32I2c
|
||||
|
||||
#define i2c_print KPrintf
|
||||
|
||||
int Stm32HwI2cInit(void);
|
||||
int Imrt1052HwI2cInit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -245,7 +245,6 @@ netconn_delete(struct netconn *conn)
|
||||
err = ERR_OK;
|
||||
} else
|
||||
#endif /* LWIP_NETCONN_FULLDUPLEX */
|
||||
//tst by wly
|
||||
{
|
||||
err = netconn_prepare_delete(conn);
|
||||
}
|
||||
|
||||
@@ -497,18 +497,6 @@ get_socket(int fd)
|
||||
return sock;
|
||||
}
|
||||
|
||||
void pr_socket_buf(void)
|
||||
{
|
||||
int i;
|
||||
lw_debug("socket:\n");
|
||||
for (i = 0; i < NUM_SOCKETS; ++i) {
|
||||
// if (!sockets[i].conn)
|
||||
lw_debug("%d: conn %p rcv %d send %d wait %d\n", i, sockets[i].conn, sockets[i].rcvevent, sockets[i].sendevent,
|
||||
sockets[i].select_waiting);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allocate a new socket for a given netconn.
|
||||
*
|
||||
@@ -600,7 +588,6 @@ free_socket_free_elements(int is_tcp, struct netconn *conn, union lwip_sock_last
|
||||
}
|
||||
if (conn != NULL) {
|
||||
/* netconn_prepare_delete() has already been called, here we only free the conn */
|
||||
lw_debug("lw: [%s] tcp %d socket %d accept %d recv %d\n", __func__, is_tcp, conn->socket, conn->acceptmbox, conn->recvmbox);
|
||||
netconn_delete(conn);
|
||||
}
|
||||
}
|
||||
@@ -673,8 +660,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||
|
||||
newsock = alloc_socket(newconn, 1);
|
||||
if (newsock == -1) {
|
||||
lw_debug("lw: [%s] recv %d\n", __func__, newconn->recvmbox);
|
||||
pr_socket_buf();
|
||||
netconn_delete(newconn);
|
||||
sock_set_errno(sock, ENFILE);
|
||||
done_socket(sock);
|
||||
@@ -711,8 +696,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||
err = netconn_peer(newconn, &naddr, &port);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
|
||||
lw_debug("lw: [%s] recv %x\n", __func__, newconn->recvmbox);
|
||||
|
||||
netconn_delete(newconn);
|
||||
free_socket(nsock, 1);
|
||||
sock_set_errno(sock, err_to_errno(err));
|
||||
@@ -1756,8 +1739,6 @@ lwip_socket(int domain, int type, int protocol)
|
||||
i = alloc_socket(conn, 0);
|
||||
|
||||
if (i == -1) {
|
||||
lw_debug("lw: [%s] recv %d delete no socket\n", __func__, conn->recvmbox);
|
||||
pr_socket_buf();
|
||||
netconn_delete(conn);
|
||||
set_errno(ENFILE);
|
||||
return -1;
|
||||
@@ -1766,7 +1747,6 @@ lwip_socket(int domain, int type, int protocol)
|
||||
done_socket(&sockets[i - LWIP_SOCKET_OFFSET]);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
||||
set_errno(0);
|
||||
lw_debug("lw: [%s] new socket %d %p\n", __func__, i, conn);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@@ -250,10 +250,9 @@ typedef unsigned int nfds_t;
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
#define lw_print //KPrintf
|
||||
#define lw_trace() //KPrintf("lw: [%s][%d] passed!\n", __func__, __LINE__)
|
||||
#define lw_error() //KPrintf("lw: [%s][%d] failed!\n", __func__, __LINE__)
|
||||
#define lw_debug KPrintf
|
||||
#define lw_error KPrintf
|
||||
#define lw_notice KPrintf
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@@ -355,7 +355,7 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len)
|
||||
* it can send them more efficiently by combining them together).
|
||||
* To prompt the system to send data now, call tcp_output() after
|
||||
* calling tcp_write().
|
||||
*
|
||||
*
|
||||
* This function enqueues the data pointed to by the argument dataptr. The length of
|
||||
* the data is passed as the len parameter. The apiflags can be one or more of:
|
||||
* - TCP_WRITE_FLAG_COPY: indicates whether the new memory should be allocated
|
||||
@@ -1386,17 +1386,13 @@ tcp_output(struct tcp_pcb *pcb)
|
||||
/* In the case of fast retransmit, the packet should not go to the tail
|
||||
* of the unacked queue, but rather somewhere before it. We need to check for
|
||||
* this case. -STJ Jul 27, 2004 */
|
||||
lw_debug("check %s seg %p useg %p\n", __func__, seg, useg);
|
||||
if (TCP_SEQ_LT(lwip_ntohl(seg->tcphdr->seqno), lwip_ntohl(useg->tcphdr->seqno))) {
|
||||
/* add segment to before tail of unacked list, keeping the list sorted */
|
||||
struct tcp_seg **cur_seg = &(pcb->unacked);
|
||||
lw_debug("check %s ", __func__);
|
||||
while (*cur_seg &&
|
||||
TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) {
|
||||
lw_debug("%p -> ", *cur_seg);
|
||||
cur_seg = &((*cur_seg)->next );
|
||||
}
|
||||
lw_debug("\n");
|
||||
seg->next = (*cur_seg);
|
||||
(*cur_seg) = seg;
|
||||
} else {
|
||||
|
||||
@@ -18,40 +18,18 @@
|
||||
* @date 2021.12.15
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_RAW
|
||||
|
||||
#include "ping.h"
|
||||
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/init.h"
|
||||
#include "netif/ethernet.h"
|
||||
|
||||
#include "board.h"
|
||||
#include "pin_mux.h"
|
||||
#include "clock_config.h"
|
||||
|
||||
#include <transform.h>
|
||||
#include <sys_arch.h>
|
||||
#include "connect_ethernet.h"
|
||||
#include "sys_arch.h"
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void *LwipSetIPTask(void *param)
|
||||
static void LwipSetIPTask(void *param)
|
||||
{
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
}
|
||||
|
||||
void LwipSetIPTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
pthread_t th_id;
|
||||
pthread_attr_t attr;
|
||||
|
||||
attr.schedparam.sched_priority = LWIP_DEMO_TASK_PRIO;
|
||||
attr.stacksize = LWIP_TASK_STACK_SIZE;
|
||||
|
||||
if(argc >= 4)
|
||||
{
|
||||
lw_print("lw: [%s] ip %s mask %s gw %s\n", __func__, argv[1], argv[2], argv[3]);
|
||||
@@ -65,12 +43,7 @@ void LwipSetIPTest(int argc, char *argv[])
|
||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||
}
|
||||
|
||||
result = pthread_create(&th_id, &attr, LwipSetIPTask, NULL);
|
||||
if (0 == result) {
|
||||
lw_print("lw: [%s] thread %d successfully!\n", __func__, th_id);
|
||||
} else {
|
||||
lw_print("lw: [%s] failed! error code is %d\n", __func__, result);
|
||||
}
|
||||
sys_thread_new("SET ip address", LwipSetIPTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
@@ -98,4 +71,3 @@ void LwipShowIPTask(int argc, char *argv[])
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
showip, LwipShowIPTask, GetIp [IP] [Netmask] [Gateway]);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lwip_demo.h
|
||||
* @brief lwip demo relative struct and definition
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
|
||||
#ifndef __LWIP_DEMO_H__
|
||||
#define __LWIP_DEMO_H__
|
||||
|
||||
typedef struct LwipTcpSocketStruct
|
||||
{
|
||||
char ip[6];
|
||||
uint16_t port;
|
||||
char *buf;
|
||||
}LwipTcpSocketParamType;
|
||||
|
||||
#define LWIP_TEST_MSG_SIZE 128
|
||||
|
||||
#define LWIP_TEST_STACK_SIZE 4096
|
||||
#define LWIP_TEST_TASK_PRIO 20
|
||||
|
||||
#endif /* __LWIP_DEMO_H__ */
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
@@ -11,45 +11,32 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file tcp_echo_socket_demo.c
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @file lwip_tcp_demo.c
|
||||
* @brief TCP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xizi.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "lwip_demo.h"
|
||||
#include "sys_arch.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "tcpecho_raw.h"
|
||||
|
||||
#define MSG_SIZE 128
|
||||
|
||||
typedef struct LwipTcpSocketStruct
|
||||
{
|
||||
char ip[6];
|
||||
uint16_t port;
|
||||
char *buf; // test buffer
|
||||
}LwipTcpSocketParamType;
|
||||
|
||||
// this is for test in shell, in fact, shell restrict the length of input string, which is less then 128
|
||||
char tcp_send_msg[MSG_SIZE] = {0};
|
||||
char tcp_target[] = {192, 168, 250, 252};
|
||||
uint16_t tcp_port = LWIP_TARGET_PORT;
|
||||
char tcp_demo_msg[LWIP_TEST_MSG_SIZE] = {0};
|
||||
char tcp_demo_ip[] = {192, 168, 250, 252};
|
||||
u16_t tcp_demo_port = LWIP_TARGET_PORT;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static void LwipTcpSendTask(void *arg)
|
||||
{
|
||||
lw_notice("LwipTcpSendTask start.\n");
|
||||
|
||||
int fd = -1;
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
lw_notice("Socket error\n");
|
||||
lw_error("Socket error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +50,7 @@ static void LwipTcpSendTask(void *arg)
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
|
||||
{
|
||||
lw_notice("Unable to connect\n");
|
||||
lw_error("Unable to connect\n");
|
||||
closesocket(fd);
|
||||
return;
|
||||
}
|
||||
@@ -71,9 +58,9 @@ static void LwipTcpSendTask(void *arg)
|
||||
lw_notice("tcp connect success, start to send.\n");
|
||||
lw_notice("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
|
||||
|
||||
sendto(fd, tcp_send_msg, strlen(tcp_send_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
|
||||
sendto(fd, tcp_demo_msg, strlen(tcp_demo_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
|
||||
|
||||
lw_notice("Send tcp msg: %s ", tcp_send_msg);
|
||||
lw_notice("Send tcp msg: %s ", tcp_demo_msg);
|
||||
|
||||
closesocket(fd);
|
||||
return;
|
||||
@@ -82,31 +69,31 @@ static void LwipTcpSendTask(void *arg)
|
||||
void LwipTcpSendTest(int argc, char *argv[])
|
||||
{
|
||||
LwipTcpSocketParamType param;
|
||||
memset(tcp_send_msg, 0, MSG_SIZE);
|
||||
memset(tcp_demo_msg, 0, LWIP_TEST_MSG_SIZE);
|
||||
if(argc >= 2)
|
||||
{
|
||||
strncpy(tcp_send_msg, argv[1], strlen(argv[1]));
|
||||
strncpy(tcp_demo_msg, argv[1], strlen(argv[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(tcp_send_msg, "hello world", strlen("hello world"));
|
||||
strncpy(tcp_demo_msg, "hello world", strlen("hello world"));
|
||||
}
|
||||
strcat(tcp_send_msg, "\r\n");
|
||||
strcat(tcp_demo_msg, "\r\n");
|
||||
|
||||
if(argc >= 3)
|
||||
{
|
||||
if(sscanf(argv[2], "%d.%d.%d.%d:%d", &tcp_target[0], &tcp_target[1], &tcp_target[2], &tcp_target[3], &tcp_port) == EOK)
|
||||
if(sscanf(argv[2], "%d.%d.%d.%d:%d", &tcp_demo_ip[0], &tcp_demo_ip[1], &tcp_demo_ip[2], &tcp_demo_ip[3], &tcp_demo_port) == EOK)
|
||||
{
|
||||
sscanf(argv[2], "%d.%d.%d.%d", &tcp_target[0], &tcp_target[1], &tcp_target[2], &tcp_target[3]);
|
||||
sscanf(argv[2], "%d.%d.%d.%d", &tcp_demo_ip[0], &tcp_demo_ip[1], &tcp_demo_ip[2], &tcp_demo_ip[3]);
|
||||
}
|
||||
}
|
||||
lw_notice("get ipaddr %d.%d.%d.%d:%d\n", tcp_target[0], tcp_target[1], tcp_target[2], tcp_target[3], tcp_port);
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_target);
|
||||
lw_notice("get ipaddr %d.%d.%d.%d:%d\n", tcp_demo_ip[0], tcp_demo_ip[1], tcp_demo_ip[2], tcp_demo_ip[3], tcp_demo_port);
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_demo_ip);
|
||||
|
||||
memcpy(param.ip, tcp_target, 4);
|
||||
param.port = tcp_port;
|
||||
param.buf = malloc(MSG_SIZE);
|
||||
memcpy(param.buf, tcp_send_msg, MSG_SIZE);
|
||||
memcpy(param.ip, tcp_demo_ip, 4);
|
||||
param.port = tcp_demo_port;
|
||||
param.buf = malloc(LWIP_TEST_MSG_SIZE);
|
||||
memcpy(param.buf, tcp_demo_msg, LWIP_TEST_MSG_SIZE);
|
||||
|
||||
sys_thread_new("tcp send", LwipTcpSendTask, ¶m, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 AIIT XUOS Lab
|
||||
* Copyright (c) 2022 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
@@ -15,25 +15,23 @@
|
||||
* @brief One UDP demo based on LwIP
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-05-29
|
||||
* @date 2022-03-21
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <xizi.h>
|
||||
#include "board.h"
|
||||
#include "sys_arch.h"
|
||||
#include "lwip/udp.h"
|
||||
#include <lwip/sockets.h>
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
|
||||
#define UDP_TASK_STACK_SIZE 4096
|
||||
#define UDP_TASK_PRIO 15
|
||||
#define PBUF_SIZE 27
|
||||
|
||||
static struct udp_pcb *udpecho_raw_pcb;
|
||||
|
||||
char udp_demo_ip[] = {192, 168, 250, 252};
|
||||
uint16_t udp_demo_port = LWIP_TARGET_PORT;
|
||||
u16_t udp_demo_port = LWIP_TARGET_PORT;
|
||||
|
||||
char hello_str[] = {"hello world\r\n"};
|
||||
char udp_send_msg[] = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
|
||||
char udp_demo_msg[] = "\nThis one is UDP package!!!\n";
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
@@ -47,7 +45,7 @@ static void LwipUDPSendTask(void *arg)
|
||||
socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (socket_fd < 0)
|
||||
{
|
||||
lw_print("Socket error\n");
|
||||
lw_error("Socket error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,45 +57,43 @@ static void LwipUDPSendTask(void *arg)
|
||||
|
||||
if (connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
|
||||
{
|
||||
lw_print("Unable to connect\n");
|
||||
lw_error("Unable to connect\n");
|
||||
closesocket(socket_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
lw_print("UDP connect success, start to send.\n");
|
||||
lw_print("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
|
||||
lw_notice("UDP connect success, start to send.\n");
|
||||
lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
|
||||
|
||||
sendto(socket_fd, udp_send_msg, strlen(udp_send_msg), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
|
||||
lw_notice("Send UDP msg: %s ", udp_send_msg);
|
||||
sendto(socket_fd, udp_demo_msg, strlen(udp_demo_msg), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
|
||||
lw_notice("Send UDP msg: %s ", udp_demo_msg);
|
||||
closesocket(socket_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
void *LwipUdpSendTest(int argc, char *argv[])
|
||||
{
|
||||
int result = 0;
|
||||
sys_thread_t th_id;
|
||||
|
||||
memset(udp_send_msg, 0, sizeof(udp_send_msg));
|
||||
memset(udp_demo_msg, 0, sizeof(udp_demo_msg));
|
||||
|
||||
if(argc == 1)
|
||||
{
|
||||
lw_print("lw: [%s] gw %d.%d.%d.%d\n", __func__, udp_demo_ip[0], udp_demo_ip[1], udp_demo_ip[2], udp_demo_ip[3]);
|
||||
strncpy(udp_send_msg, hello_str, strlen(hello_str));
|
||||
strncpy(udp_demo_msg, hello_str, strlen(hello_str));
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy(udp_send_msg, argv[1], strlen(argv[1]));
|
||||
strncat(udp_send_msg, "\r\n", 2);
|
||||
strncpy(udp_demo_msg, argv[1], strlen(argv[1]));
|
||||
strncat(udp_demo_msg, "\r\n", 2);
|
||||
if(argc == 3)
|
||||
{
|
||||
sscanf(argv[2], "%d.%d.%d.%d", &udp_demo_ip[0], &udp_demo_ip[1], &udp_demo_ip[2], &udp_demo_ip[3]);
|
||||
}
|
||||
}
|
||||
|
||||
lw_print("lw: [%s] gw %d.%d.%d.%d\n", __func__, udp_demo_ip[0], udp_demo_ip[1], udp_demo_ip[2], udp_demo_ip[3]);
|
||||
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||
sys_thread_new("udp socket send", LwipUDPSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
lwip_config_net(lwip_ipaddr, lwip_netmask, udp_demo_ip);
|
||||
sys_thread_new("udp send", LwipUDPSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
|
||||
@@ -116,6 +112,7 @@ static void LwipUdpRecvTask(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
udp_len = p->tot_len;
|
||||
lw_notice("Receive data :%dB\r\n", udp_len);
|
||||
|
||||
@@ -158,5 +155,5 @@ void LwipUdpRecvTest(void)
|
||||
}
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
|
||||
UDPRecv, LwipUdpRecvTest, UDP server echo);
|
||||
UDPRecv, LwipUdpRecvTest, UDP Receive echo);
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
#ifndef FLASH_SPI_H
|
||||
#define FLASH_SPI_H
|
||||
|
||||
#ifdef RESOURCES_SPI_SFUD
|
||||
#include <sfud_port.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @file shell_port.c
|
||||
* @author Letter (NevermindZZT@gmail.com)
|
||||
* @brief
|
||||
* @brief
|
||||
* @version 0.1
|
||||
* @date 2019-02-22
|
||||
*
|
||||
*
|
||||
* @copyright (c) 2019 Letter
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include "xizi.h"
|
||||
@@ -26,11 +26,11 @@ char *shellBuffer;
|
||||
ShellFs shellFs;
|
||||
char *shellPathBuffer;
|
||||
|
||||
HardwareDevType console;
|
||||
HardwareDevType console;
|
||||
|
||||
/**
|
||||
* @brief Shell write
|
||||
*
|
||||
* @brief Shell write
|
||||
*
|
||||
* @param data write data
|
||||
*/
|
||||
void userShellWrite(char data)
|
||||
@@ -40,7 +40,7 @@ void userShellWrite(char data)
|
||||
|
||||
/**
|
||||
* @brief shell read
|
||||
*
|
||||
*
|
||||
* @param data read data
|
||||
* @return char read status
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ signed char userShellRead(char *data)
|
||||
#ifdef SHELL_ENABLE_FILESYSTEM
|
||||
/**
|
||||
* @brief list file
|
||||
*
|
||||
*
|
||||
* @param path path
|
||||
* @param buffer result buffer
|
||||
* @param maxLen the maximum buffer size
|
||||
@@ -86,14 +86,14 @@ size_t userShellListDir(char *path, char *buffer, size_t maxLen)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the shell
|
||||
*
|
||||
* @brief Initialize the shell
|
||||
*
|
||||
*/
|
||||
int userShellInit(void)
|
||||
{
|
||||
shellBuffer = x_malloc(512*sizeof(char));
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef SHELL_ENABLE_FILESYSTEM
|
||||
shellPathBuffer = x_malloc(512*sizeof(char));
|
||||
shellPathBuffer[0] = '/';
|
||||
@@ -102,7 +102,7 @@ int userShellInit(void)
|
||||
shellFs.listdir = userShellListDir;
|
||||
shellFsInit(&shellFs, shellPathBuffer, 512);
|
||||
shellSetPath(&shell, shellPathBuffer);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
shell.write = userShellWrite;
|
||||
shell.read = userShellRead;
|
||||
@@ -114,13 +114,13 @@ int userShellInit(void)
|
||||
serial_dev_param->serial_set_mode = 0;
|
||||
serial_dev_param->serial_stream_mode = SIGN_OPER_STREAM;
|
||||
BusDevOpen(console);
|
||||
|
||||
shellInit(&shell, shellBuffer, 4096);
|
||||
|
||||
shellInit(&shell, shellBuffer, 512);
|
||||
int32 tid;
|
||||
tid = KTaskCreate("letter-shell",
|
||||
shellTask, &shell,
|
||||
SHELL_TASK_STACK_SIZE, SHELL_TASK_PRIORITY);
|
||||
|
||||
|
||||
StartupKTask(tid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user