project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp: Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem. sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately. sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades. sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for fastboot. Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
74 lines
2.3 KiB
C
74 lines
2.3 KiB
C
#include <rtthread.h>
|
||
|
||
#include <netdb.h> /* 为了解析主机名,需要包含netdb.h头文件 */
|
||
#include <sys/socket.h> /* 使用BSD socket,需要包含socket.h头文件 */
|
||
|
||
void tcp_senddata(const char *url, int port, int length)
|
||
{
|
||
struct hostent *host;
|
||
int sock, err, result, timeout, index;
|
||
struct sockaddr_in server_addr;
|
||
rt_uint8_t *buffer_ptr;
|
||
|
||
/* 通过函数入口参数url获得host地址(如果是域名,会做域名解析) */
|
||
host = gethostbyname(url);
|
||
/* 创建一个socket,类型是SOCKET_STREAM,TCP类型 */
|
||
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
|
||
{
|
||
/* 创建socket失败 */
|
||
rt_kprintf("Socket error\n");
|
||
return;
|
||
}
|
||
|
||
/* 申请内存 */
|
||
buffer_ptr = rt_malloc(length);
|
||
/* 构造发送数据 */
|
||
for (index = 0; index < length; index ++)
|
||
buffer_ptr[index] = index & 0xff;
|
||
|
||
timeout = 100;
|
||
/* 设置发送超时时间100ms */
|
||
setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
|
||
/* 初始化预连接的服务端地址 */
|
||
server_addr.sin_family = AF_INET;
|
||
server_addr.sin_port = htons(port);
|
||
server_addr.sin_addr = *((struct in_addr *)host->h_addr);
|
||
rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
|
||
|
||
/* 连接到服务端 */
|
||
err = connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
|
||
rt_kprintf("TCP thread connect error code: %d\n", err);
|
||
|
||
while (1)
|
||
{
|
||
/* 发送数据到sock连接 */
|
||
result = send(sock, buffer_ptr, length, MSG_DONTWAIT);
|
||
if (result < 0) //数据发送错误处理
|
||
{
|
||
rt_kprintf("TCP thread send error: %d\n", result);
|
||
closesocket(sock);
|
||
|
||
/* 关闭连接,重新创建连接 */
|
||
rt_thread_delay(10);
|
||
|
||
if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
|
||
rt_kprintf("TCP Socket error:%d\n", sock);
|
||
|
||
err = connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr));
|
||
rt_kprintf("TCP thread connect error code: %d\n", err);
|
||
}
|
||
else if (result == 0)
|
||
{
|
||
/* 打印send函数返回值为0的警告信息 */
|
||
rt_kprintf("\n Send warning,send function return 0.\r\n");
|
||
}
|
||
}
|
||
}
|
||
|
||
#ifdef RT_USING_FINSH
|
||
#include <finsh.h>
|
||
/* 输出tcpclient函数到finsh shell中 */
|
||
FINSH_FUNCTION_EXPORT(tcp_senddata, send a packet through tcp connection);
|
||
#endif
|
||
|