diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_AT_UART_tencentos_tiny.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_AT_UART_tencentos_tiny.c index 70180de4..72283a0d 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_AT_UART_tencentos_tiny.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_AT_UART_tencentos_tiny.c @@ -45,15 +45,15 @@ extern void at_client_uart_rx_isr_cb(uint8_t *pdata, uint8_t len); */ void HAL_AT_UART_IRQHandler(void) { - uint8_t ch; - if(__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) - { - ch = (uint8_t) READ_REG(pAtUart->Instance->RDR)&0xFF; - /*this callback for at_client*/ - at_client_uart_rx_isr_cb(&ch, 1); - HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); - } - __HAL_UART_CLEAR_PEFLAG(pAtUart); + uint8_t ch; + if(__HAL_UART_GET_FLAG(pAtUart, UART_FLAG_RXNE) == SET) + { + ch = (uint8_t) READ_REG(pAtUart->Instance->RDR)&0xFF; + /*this callback for at_client*/ + at_client_uart_rx_isr_cb(&ch, 1); + HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin); + } + __HAL_UART_CLEAR_PEFLAG(pAtUart); } @@ -65,24 +65,25 @@ void HAL_AT_UART_IRQHandler(void) */ int HAL_AT_Uart_Send(void *data, uint32_t size) { - if(HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) - { - return size; - } - else - { - return 0; - } + if(HAL_OK == HAL_UART_Transmit(pAtUart, data, size, 0xFFFF)) + { + return size; + } + else + { + return 0; + } } int HAL_AT_Uart_Init(void) { - AT_Uart_Init(); - return QCLOUD_RET_SUCCESS; + AT_Uart_Init(); + return QCLOUD_RET_SUCCESS; } int HAL_AT_Uart_Deinit(void) { - return QCLOUD_RET_SUCCESS; + return QCLOUD_RET_SUCCESS; } -#endif + +#endif/*AT_TCP_ENABLED*/ diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Device_tencentos_tiny.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Device_tencentos_tiny.c index f75cfa22..dc72dcf9 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Device_tencentos_tiny.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Device_tencentos_tiny.c @@ -57,104 +57,104 @@ static char sg_sub_device_name[MAX_SIZE_OF_DEVICE_NAME + 1] = "YOUR_SUB_DEV_NAM static int device_info_copy(void *pdst, void *psrc, uint8_t max_len) { - if(strlen(psrc) > max_len){ - return QCLOUD_ERR_FAILURE; - } - memset(pdst, '\0', max_len); - strncpy(pdst, psrc, max_len); - return QCLOUD_RET_SUCCESS; + if(strlen(psrc) > max_len){ + return QCLOUD_ERR_FAILURE; + } + memset(pdst, '\0', max_len); + strncpy(pdst, psrc, max_len); + return QCLOUD_RET_SUCCESS; } #endif int HAL_SetDevInfo(void *pdevInfo) { - POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO); - int ret; - DeviceInfo *devInfo = (DeviceInfo *)pdevInfo; + POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO); + int ret; + DeviceInfo *devInfo = (DeviceInfo *)pdevInfo; #ifdef DEBUG_DEV_INFO_USED - ret = device_info_copy(sg_product_id, devInfo->product_id, MAX_SIZE_OF_PRODUCT_ID);//set product ID - ret |= device_info_copy(sg_device_name, devInfo->device_name, MAX_SIZE_OF_DEVICE_NAME);//set dev name + ret = device_info_copy(sg_product_id, devInfo->product_id, MAX_SIZE_OF_PRODUCT_ID);//set product ID + ret |= device_info_copy(sg_device_name, devInfo->device_name, MAX_SIZE_OF_DEVICE_NAME);//set dev name #ifdef AUTH_MODE_CERT - ret |= device_info_copy(sg_device_cert_file_name, devInfo->dev_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//set dev cert file name - ret |= device_info_copy(sg_device_privatekey_file_name, devInfo->dev_key_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//set dev key file name + ret |= device_info_copy(sg_device_cert_file_name, devInfo->dev_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//set dev cert file name + ret |= device_info_copy(sg_device_privatekey_file_name, devInfo->dev_key_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//set dev key file name #else - ret |= device_info_copy(sg_device_secret, devInfo->device_secret, MAX_SIZE_OF_DEVICE_SECRET);//set dev secret + ret |= device_info_copy(sg_device_secret, devInfo->device_secret, MAX_SIZE_OF_DEVICE_SECRET);//set dev secret #endif #else - Log_e("HAL_SetDevInfo not implement yet"); - ret = QCLOUD_ERR_DEV_INFO; + Log_e("HAL_SetDevInfo not implement yet"); + ret = QCLOUD_ERR_DEV_INFO; #endif - if(QCLOUD_RET_SUCCESS != ret) { - Log_e("Set device info err"); - ret = QCLOUD_ERR_DEV_INFO; - } - return ret; + if(QCLOUD_RET_SUCCESS != ret) { + Log_e("Set device info err"); + ret = QCLOUD_ERR_DEV_INFO; + } + return ret; } int HAL_GetDevInfo(void *pdevInfo) { - POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO); - int ret; - DeviceInfo *devInfo = (DeviceInfo *)pdevInfo; - memset((char *)devInfo, '\0', sizeof(DeviceInfo)); + POINTER_SANITY_CHECK(pdevInfo, QCLOUD_ERR_DEV_INFO); + int ret; + DeviceInfo *devInfo = (DeviceInfo *)pdevInfo; + memset((char *)devInfo, '\0', sizeof(DeviceInfo)); #ifdef DEBUG_DEV_INFO_USED - ret = device_info_copy(devInfo->product_id, sg_product_id, MAX_SIZE_OF_PRODUCT_ID);//get product ID - ret |= device_info_copy(devInfo->device_name, sg_device_name, MAX_SIZE_OF_DEVICE_NAME);//get dev name + ret = device_info_copy(devInfo->product_id, sg_product_id, MAX_SIZE_OF_PRODUCT_ID);//get product ID + ret |= device_info_copy(devInfo->device_name, sg_device_name, MAX_SIZE_OF_DEVICE_NAME);//get dev name #ifdef DEV_DYN_REG_ENABLED - ret |= device_info_copy(devInfo->product_secret, sg_product_secret, MAX_SIZE_OF_PRODUCT_SECRET );//get product ID + ret |= device_info_copy(devInfo->product_secret, sg_product_secret, MAX_SIZE_OF_PRODUCT_SECRET );//get product ID #endif #ifdef AUTH_MODE_CERT - ret |= device_info_copy(devInfo->dev_cert_file_name, sg_device_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//get dev cert file name - ret |= device_info_copy(devInfo->dev_key_file_name, sg_device_privatekey_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//get dev key file name + ret |= device_info_copy(devInfo->dev_cert_file_name, sg_device_cert_file_name, MAX_SIZE_OF_DEVICE_CERT_FILE_NAME);//get dev cert file name + ret |= device_info_copy(devInfo->dev_key_file_name, sg_device_privatekey_file_name, MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME);//get dev key file name #else - ret |= device_info_copy(devInfo->device_secret, sg_device_secret, MAX_SIZE_OF_DEVICE_SECRET);//get dev secret + ret |= device_info_copy(devInfo->device_secret, sg_device_secret, MAX_SIZE_OF_DEVICE_SECRET);//get dev secret #endif #else - Log_e("HAL_GetDevInfo not implement yet"); - ret = QCLOUD_ERR_DEV_INFO; + Log_e("HAL_GetDevInfo not implement yet"); + ret = QCLOUD_ERR_DEV_INFO; #endif - if(QCLOUD_RET_SUCCESS != ret){ - Log_e("Get device info err"); - ret = QCLOUD_ERR_DEV_INFO; - } - return ret; + if(QCLOUD_RET_SUCCESS != ret){ + Log_e("Get device info err"); + ret = QCLOUD_ERR_DEV_INFO; + } + return ret; } #ifdef GATEWAY_ENABLED int HAL_GetGwDevInfo(void *pgwDeviceInfo) { - POINTER_SANITY_CHECK(pgwDeviceInfo, QCLOUD_ERR_DEV_INFO); - int ret; - GatewayDeviceInfo *gwDevInfo = (GatewayDeviceInfo *)pgwDeviceInfo; - memset((char *)gwDevInfo, 0, sizeof(GatewayDeviceInfo)); + POINTER_SANITY_CHECK(pgwDeviceInfo, QCLOUD_ERR_DEV_INFO); + int ret; + GatewayDeviceInfo *gwDevInfo = (GatewayDeviceInfo *)pgwDeviceInfo; + memset((char *)gwDevInfo, 0, sizeof(GatewayDeviceInfo)); #ifdef DEBUG_DEV_INFO_USED - ret = HAL_GetDevInfo(&(gwDevInfo->gw_info));//get gw dev info - //only one sub-device is supported now - gwDevInfo->sub_dev_num = 1; - //copy sub dev info - ret = device_info_copy(gwDevInfo->sub_dev_info[0].product_id, sg_sub_device_product_id, MAX_SIZE_OF_PRODUCT_ID); - ret |= device_info_copy(gwDevInfo->sub_dev_info[0].device_name, sg_sub_device_name, MAX_SIZE_OF_DEVICE_NAME); + ret = HAL_GetDevInfo(&(gwDevInfo->gw_info));//get gw dev info + //only one sub-device is supported now + gwDevInfo->sub_dev_num = 1; + //copy sub dev info + ret = device_info_copy(gwDevInfo->sub_dev_info[0].product_id, sg_sub_device_product_id, MAX_SIZE_OF_PRODUCT_ID); + ret |= device_info_copy(gwDevInfo->sub_dev_info[0].device_name, sg_sub_device_name, MAX_SIZE_OF_DEVICE_NAME); #else - Log_e("HAL_GetDevInfo from json not implement yet"); - ret = QCLOUD_ERR_DEV_INFO; + Log_e("HAL_GetGwDevInfo from json not implement yet"); + ret = QCLOUD_ERR_DEV_INFO; #endif - if(QCLOUD_RET_SUCCESS != ret) { - Log_e("Get gateway device info err"); - ret = QCLOUD_ERR_DEV_INFO; - } - return ret; + if(QCLOUD_RET_SUCCESS != ret) { + Log_e("Get gateway device info err"); + ret = QCLOUD_ERR_DEV_INFO; + } + return ret; } #endif diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_OS_tencentos_tiny.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_OS_tencentos_tiny.c index 5e607f6c..34404227 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_OS_tencentos_tiny.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_OS_tencentos_tiny.c @@ -32,7 +32,6 @@ void HAL_SleepMs(_IN_ uint32_t ms) (void)tos_sleep_hmsm(0,0,0, ms); } - void HAL_Printf(_IN_ const char *fmt, ...) { va_list args; @@ -61,15 +60,14 @@ int HAL_Vsnprintf(_IN_ char *str, _IN_ const int len, _IN_ const char *format, v return vsnprintf(str, len, format, ap); } - void *HAL_Malloc(_IN_ uint32_t size) { - return tos_mmheap_alloc(size); + return tos_mmheap_alloc(size); } void HAL_Free(_IN_ void *ptr) { - tos_mmheap_free(ptr); + tos_mmheap_free(ptr); } void *HAL_MutexCreate(void) @@ -88,7 +86,7 @@ void *HAL_MutexCreate(void) void HAL_MutexDestroy(_IN_ void *mutex) { - k_err_t ret; + k_err_t ret; if (K_ERR_NONE != (ret = tos_mutex_destroy((k_mutex_t *)mutex))) { HAL_Printf("osal_mutex_destroy err, err:%d\n\r", ret); @@ -108,24 +106,24 @@ void HAL_MutexLock(_IN_ void *mutex) int HAL_MutexTryLock(_IN_ void *mutex) { - k_err_t ret; + k_err_t ret; - if (K_ERR_NONE != (ret = tos_mutex_pend_timed((k_mutex_t *)mutex, 0))) { - HAL_Printf("osal_mutex_lock err, err:%d\n\r", ret); - return (int)ret; - } + if (K_ERR_NONE != (ret = tos_mutex_pend_timed((k_mutex_t *)mutex, 0))) { + HAL_Printf("osal_mutex_lock err, err:%d\n\r", ret); + return (int)ret; + } - return 0; + return 0; } void HAL_MutexUnlock(_IN_ void *mutex) { - k_err_t ret; + k_err_t ret; - if (K_ERR_NONE != (ret = tos_mutex_post((k_mutex_t *)mutex))) { - HAL_Printf("osal_mutex_unlock err, err:%d\n\r", ret); - } + if (K_ERR_NONE != (ret = tos_mutex_post((k_mutex_t *)mutex))) { + HAL_Printf("osal_mutex_unlock err, err:%d\n\r", ret); + } } #if defined(PLATFORM_HAS_CMSIS) && defined(AT_TCP_ENABLED) @@ -135,53 +133,52 @@ void HAL_MutexUnlock(_IN_ void *mutex) */ void * HAL_ThreadCreate(uint16_t stack_size, int priority, char * taskname,void *(*fn)(void*), void* arg) { - osThreadId thread_t = (osThreadId)HAL_Malloc(sizeof(osThreadId)); + osThreadId thread_t = (osThreadId)HAL_Malloc(sizeof(osThreadId)); - osThreadDef(taskname, (os_pthread)fn, (osPriority)priority, 0, stack_size); - thread_t = osThreadCreate(osThread(taskname), arg); - if(NULL == thread_t){ - HAL_Printf("create thread fail\n\r"); - } + osThreadDef(taskname, (os_pthread)fn, (osPriority)priority, 0, stack_size); + thread_t = osThreadCreate(osThread(taskname), arg); + if(NULL == thread_t){ + HAL_Printf("create thread fail\n\r"); + } - return (void *)thread_t; + return (void *)thread_t; } int HAL_ThreadDestroy(void* threadId) { - return osThreadTerminate(threadId); + return osThreadTerminate(threadId); } void *HAL_SemaphoreCreate(void) { - return (void *)osSemaphoreCreate(NULL, 1); + return (void *)osSemaphoreCreate(NULL, 1); } void HAL_SemaphoreDestroy(void *sem) { - osStatus ret; + osStatus ret; - ret = osSemaphoreDelete ((osSemaphoreId)sem); - if(osOK != ret) - { - HAL_Printf("HAL_SemaphoreDestroy err, err:%d\n\r",ret); - } + ret = osSemaphoreDelete ((osSemaphoreId)sem); + if(osOK != ret) + { + HAL_Printf("HAL_SemaphoreDestroy err, err:%d\n\r",ret); + } } void HAL_SemaphorePost(void *sem) { - osStatus ret; + osStatus ret; - ret = osSemaphoreRelease ((osSemaphoreId) sem); + ret = osSemaphoreRelease ((osSemaphoreId) sem); - if(osOK != ret) - { - HAL_Printf("HAL_SemaphorePost err, err:%d\n\r",ret); - } + if(osOK != ret) + { + HAL_Printf("HAL_SemaphorePost err, err:%d\n\r",ret); + } } int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms) { - return osSemaphoreWait ((osSemaphoreId)sem, timeout_ms); - + return osSemaphoreWait ((osSemaphoreId)sem, timeout_ms); } #endif diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_TCP_lwip.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_TCP_lwip.c index 8d5bb482..5ddbf321 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_TCP_lwip.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_TCP_lwip.c @@ -45,8 +45,8 @@ static uint32_t _time_left(uint32_t t_end, uint32_t t_now) uintptr_t HAL_TCP_Connect(const char *host, uint16_t port) { - int ret; - struct addrinfo hints, *addr_list, *cur; + int ret; + struct addrinfo hints, *addr_list, *cur; int fd = 0; char port_str[6]; @@ -65,20 +65,20 @@ uintptr_t HAL_TCP_Connect(const char *host, uint16_t port) for (cur = addr_list; cur != NULL; cur = cur->ai_next) { fd = (int) socket( cur->ai_family, cur->ai_socktype, cur->ai_protocol ); - if( fd < 0 ) - { - ret = 0; - continue; - } + if( fd < 0 ) + { + ret = 0; + continue; + } - if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) - { - ret = fd + LWIP_SOCKET_FD_SHIFT; - break; - } + if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) + { + ret = fd + LWIP_SOCKET_FD_SHIFT; + break; + } - close( fd ); - ret = 0; + close( fd ); + ret = 0; } if (ret == 0) { diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Timer_tencentos_tiny.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Timer_tencentos_tiny.c index 477aa8b3..272612f6 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Timer_tencentos_tiny.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_Timer_tencentos_tiny.c @@ -42,18 +42,18 @@ uint32_t HAL_GetTimeMs(void) /*Get timestamp*/ long HAL_Timer_current_sec(void) { - return HAL_GetTimeMs() / 1000; + return HAL_GetTimeMs() / 1000; } char* HAL_Timer_current(void) { - long time_sec; + long time_sec; - time_sec = HAL_Timer_current_sec(); - memset(now_time_str, 0, 20); - snprintf(now_time_str, 20, "%ld", time_sec); + time_sec = HAL_Timer_current_sec(); + memset(now_time_str, 0, sizeof(now_time_str)); + snprintf(now_time_str, 20, "%ld", time_sec); - return now_time_str; + return now_time_str; } bool HAL_Timer_expired(Timer *timer) @@ -63,14 +63,14 @@ bool HAL_Timer_expired(Timer *timer) void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms) { - timer->end_time = HAL_GetTimeMs(); + timer->end_time = HAL_GetTimeMs(); timer->end_time += timeout_ms; } void HAL_Timer_countdown(Timer *timer, unsigned int timeout) { timer->end_time = HAL_GetTimeMs(); - timer->end_time += timeout * 1000; + timer->end_time += timeout * 1000; } int HAL_Timer_remain(Timer *timer) @@ -87,7 +87,7 @@ int HAL_Timer_remain(Timer *timer) void HAL_Timer_init(Timer *timer) { - timer->end_time = 0; + timer->end_time = 0; } #ifdef __cplusplus diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_lwip.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_lwip.c index 92471c6c..2aa13c85 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_lwip.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_lwip.c @@ -50,24 +50,24 @@ uintptr_t HAL_UDP_Connect(const char *host, unsigned short port) Log_d("establish udp connection with server(host=%s port=%s)", host, port_str); if (getaddrinfo(host, port_str, &hints, &addr_list) != 0) { - Log_e("getaddrinfo error,errno:%s",strerror(errno)); + Log_e("getaddrinfo error,errno:%s",strerror(errno)); return 0; } for (cur = addr_list; cur != NULL; cur = cur->ai_next) { - fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); - if (fd < 0) { - ret = 0; - continue; - } + fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol); + if (fd < 0) { + ret = 0; + continue; + } - if (0 == connect(fd, cur->ai_addr, cur->ai_addrlen)) { - ret = fd + LWIP_SOCKET_FD_SHIFT; - break; - } + if (0 == connect(fd, cur->ai_addr, cur->ai_addrlen)) { + ret = fd + LWIP_SOCKET_FD_SHIFT; + break; + } - close(fd); - ret = 0; + close(fd); + ret = 0; } if (0 == ret) { @@ -158,4 +158,4 @@ int HAL_UDP_ReadTimeout(uintptr_t fd, unsigned char *p_data, unsigned int datale return HAL_UDP_Read(fd, p_data, datalen); } -#endif +#endif/*COAP_COMM_ENABLED*/ diff --git a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_module.c b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_module.c index fbaaef2c..e03a60dc 100644 --- a/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_module.c +++ b/components/connectivity/qcloud-iot-explorer-sdk/port/TencentOS_tiny/HAL_UDP_module.c @@ -32,31 +32,30 @@ uintptr_t HAL_UDP_Connect(const char *host, unsigned short port) { int fd; - char port_str[PORT_BUFF_LEN]; + char port_str[PORT_BUFF_LEN] = {0}; - memset(port_str, 0, PORT_BUFF_LEN); - snprintf(port_str, PORT_BUFF_LEN, "%u", port); - Log_i("osal_udp_connect entry, host=%s port=%d(%s)", host , port, port_str); + snprintf(port_str, PORT_BUFF_LEN, "%u", port); + Log_i("osal_udp_connect entry, host=%s port=%d(%s)", host , port, port_str); - fd = tos_sal_module_connect("111.230.127.136", "5684", TOS_SAL_PROTO_UDP); - if (fd < 0) { - Log_i("net connect fail\n\r"); - if (QCLOUD_RET_SUCCESS == tos_sal_module_init()) { /* ÖØÐ³õʼ»¯Ä£×é */ - Log_i("net reinit success\n\r"); - fd = tos_sal_module_connect(host, port_str, TOS_SAL_PROTO_UDP); - if (fd < 0) { - Log_i("net connect fail\n\r"); - return NULL; - } else { - Log_i("net connect success, fd=%d\n\r", fd); - } + fd = tos_sal_module_connect("111.230.127.136", "5684", TOS_SAL_PROTO_UDP); + if (fd < 0) { + Log_i("net connect fail\n\r"); + if (QCLOUD_RET_SUCCESS == tos_sal_module_init()) { + Log_i("net reinit success\n\r"); + fd = tos_sal_module_connect(host, port_str, TOS_SAL_PROTO_UDP); + if (fd < 0) { + Log_i("net connect fail\n\r"); + return NULL; + } else { + Log_i("net connect success, fd=%d\n\r", fd); + } } else { - Log_i("net reinit fail\n\r"); - return NULL; - } - } + Log_i("net reinit fail\n\r"); + return NULL; + } + } - return fd; + return fd; } void HAL_UDP_Disconnect(uintptr_t fd) @@ -115,4 +114,4 @@ int HAL_UDP_ReadTimeout(uintptr_t fd, unsigned char *p_data, unsigned int datale return QCLOUD_RET_SUCCESS; } -#endif +#endif/*COAP_COMM_ENABLED*/