fix some calloc bug

1. some calloc fix
2. fix some document error
3. refactor kv API, to be compatible with ota API
This commit is contained in:
daishengdong
2020-04-24 11:58:42 +08:00
parent f6527d2d9a
commit 2e8c8c19e6
19 changed files with 77 additions and 93 deletions

View File

@@ -42,10 +42,10 @@ void task(void *arg)
#endif
#ifdef USING_ONCHIP_FLASH
err = tos_kv_init(&stm32l4_norflash_onchip_drv, &stm32l4_norflash_onchip_prop);
err = tos_kv_init(0x803d000, 0x803d000 + 2 * 2048, &stm32l4_norflash_onchip_drv, &stm32l4_norflash_onchip_prop);
printf("kv init, rc: %d\n", err);
#else
err = tos_kv_init(&stm32l4_qspiflash_drv, &stm32l4_qspiflash_prop);
err = tos_kv_init(0, 2 * 4096, &stm32l4_qspiflash_drv, &stm32l4_qspiflash_prop);
printf("kv init, rc: %d\n", err);
#endif

View File

@@ -25,14 +25,14 @@ void tcp_client_echo_task_entry(void *arg)
struct sockaddr_in target_sockaddr;
ip4_addr_t target_ser_ip;
int optval = 0;
int len = sizeof(int);
int optval = 0;
int len = sizeof(int);
struct timeval tv;
target_ser_t target_ser = *(target_ser_t*)arg;
if(!ipaddr_aton((const char *)target_ser.ip, &target_ser_ip))
if(!ipaddr_aton((const char *)target_ser.ip, &target_ser_ip))
{
LOG(LOG_LVL_ERROR, "[%s, %d]Convert target server ip addr failed.\r\n", __func__, __LINE__);
return;
@@ -58,23 +58,25 @@ void tcp_client_echo_task_entry(void *arg)
while (1)
{
if(connect(conn, (struct sockaddr *)&target_sockaddr, sizeof(struct sockaddr)) == -1)
{
LOG(LOG_LVL_ERROR, "[%s, %d]Connect target tcp server faild!\r\n", __func__, __LINE__);
OS_MsDelay(3000);
continue;
}
LOG(LOG_LVL_ERROR, "[%s, %d]Connect target tcp server successful!\r\n", __func__, __LINE__);
while (1)
{
ret = send(conn, "hello", strlen("hello"), 0);
//---------------recv data-----------------------//
memset(recv_data,0,sizeof(recv_data));
ret = recv(conn, recv_data, BUFSZ-1, 0);
getsockopt(conn, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)&len);
getsockopt(conn, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)&len);
if (ret < 0)
{
if(optval == EWOULDBLOCK){
@@ -99,26 +101,18 @@ void tcp_client_echo_task_entry(void *arg)
LOG(LOG_LVL_ERROR, "[%s, %d] recv = 0 (err optval = %d)\r\n", __func__, __LINE__, optval);
closesocket(conn);
break;
}
}
}
else
{
cli_recv_count += ret;
LOG(LOG_LVL_ERROR, "client_recv_count = %u\r\n", cli_recv_count);
}
//---------------send data-----------------------//
if(!strstr(recv_data,"TencentOS tiny"))
{
ret = send(conn, "tcp client push massage!", strlen("tcp client push massage!"), 0);
OS_MsDelay(2000);
}
else
{
ret = send(conn, recv_data, ret, 0);
}
getsockopt(conn, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)&len);
//---------------send data-----------------------//
LOG(LOG_LVL_INFO, "received: %s\r\n", recv_data);
getsockopt(conn, SOL_SOCKET, SO_ERROR, &optval, (socklen_t *)&len);
if (ret < 0)
{
if(optval == EWOULDBLOCK){
@@ -132,7 +126,7 @@ void tcp_client_echo_task_entry(void *arg)
LOG(LOG_LVL_ERROR, "[%s, %d] send < 0 (err optval = %d)\r\n", __func__, __LINE__, optval);
closesocket(conn);
break;
}
}
}
else if(ret == 0)
{
@@ -143,11 +137,13 @@ void tcp_client_echo_task_entry(void *arg)
LOG(LOG_LVL_ERROR, "[%s, %d] send = 0 (err optval = %d)\r\n", __func__, __LINE__, optval);
closesocket(conn);
break;
}
}
}
OS_MsDelay(3000);
}
}
closesocket(conn);
LOG(LOG_LVL_ERROR, "[%s, %d]tcp client sock closed.\r\n", __func__, __LINE__);
}
@@ -158,7 +154,7 @@ void tcp_client_echo_task_creat(uint8_t * ser_ip, uint32_t port)
target_ser_t ser = {0};
ser.ip = ser_ip;
ser.port = port;
osThreadCreate(osThread(tcp_client_echo_task_entry), &ser);
}

View File

@@ -26,8 +26,8 @@ void wifi_init_sta(void)
uint8_t macaddr[6] = {0}, macaddr_default[6] = {0};
wifi_config_t wifi_config = {
.sta = {
.ssid = "LN882x-AP",
.password = "",
.ssid = "SheldonDai",
.password = "srnr6x9xbhmb0",
0,
},
};
@@ -198,7 +198,7 @@ void application_entry(void *arg)
};
tcp_server_echo_task_creat(8087);
tcp_client_echo_task_creat((uint8_t *)"120.76.100.197", 10002);//ͨ<><CDA8>è<EFBFBD><C3A8><EFBFBD><EFBFBD>(IP:120.76.100.197) 10002<30>˿<EFBFBD>
tcp_client_echo_task_creat((uint8_t *)"39.108.190.129", 8000);//ͨ<><CDA8>è<EFBFBD><C3A8><EFBFBD><EFBFBD>(IP:120.76.100.197) 10002<30>˿<EFBFBD>
while(1)
{