Files

1049 lines
37 KiB
C

/**
* NOTE:
*
* HAL_TCP_xxx API reference implementation: wrappers/os/ubuntu/HAL_TCP_linux.c
*
*/
#include <stdarg.h>
#include "infra_types.h"
#include "infra_defs.h"
#include "infra_compat.h"
#include "wrappers_defs.h"
#include "wrappers.h"
#include "semphr.h"
#include "app_init/app_init.h"
#include "publicdata/publicdata.h"
#include "plat_comm/impl/bs_connect_impl.h"
#include "plat_comm/plat_comm_task.h"
#include "app_init/task_lock.h"
/**
?*
?* 函数 HAL_Firmware_Persistence_Start() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Firmware_Persistence_Start() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Firmware_Persistence_Start(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Firmware_Persistence_Start, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
char new_firmware_version[IOTX_FIRMWARE_VER_LEN] = {0};
void HAL_Firmware_Persistence_Start(void)
{
return;
}
/**
?*
?* 函数 HAL_Firmware_Persistence_Stop() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Firmware_Persistence_Stop() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Firmware_Persistence_Stop(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Firmware_Persistence_Stop, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_Firmware_Persistence_Stop(void)
{
return (int)1;
}
/**
?*
?* 函数 HAL_Firmware_Persistence_Write() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Firmware_Persistence_Write() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Firmware_Persistence_Write(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Firmware_Persistence_Write, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_Firmware_Persistence_Write(char *buffer, uint32_t length)
{
return 0;
}
/**
?*
?* 函数 HAL_Free() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Free() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Free(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Free, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Deallocate memory block
*
* @param[in] ptr @n Pointer to a memory block previously allocated with platform_malloc.
* @return None.
* @see None.
* @note None.
*/
void HAL_Free(void *ptr)
{
if(ptr == NULL)
return;
vPortFree(ptr);
return;
}
/**
?*
?* 函数 HAL_GetFirmwareVersion() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_GetFirmwareVersion() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_GetFirmwareVersion(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_GetFirmwareVersion, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Get firmware version
*
* @param [ou] version: array to store firmware version, max length is IOTX_FIRMWARE_VER_LEN
* @return the actual length of firmware version
*/
int HAL_GetFirmwareVersion(char *version)
{
char _firmware_version[IOTX_FIRMWARE_VER_LEN] = {0};
int len = 0;
memcpy(_firmware_version, &g_t_share_data.t_sys_var_cfg.s_sdk_data.firmware_version[0], IOTX_FIRMWARE_VER_LEN);
memset(version, 0x0, IOTX_FIRMWARE_VER_LEN);
len = strlen(_firmware_version);
strncpy(version, _firmware_version, IOTX_FIRMWARE_VER_LEN);
version[len] = '\0';
return strlen(version);
}
/**
?*
?* 函数 HAL_Kv_Get() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Kv_Get() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Kv_Get(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Kv_Get, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_KV_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_Kv_Get(const char *key, void *val, int *buffer_len)
{
return (int)1;
}
/**
?*
?* 函数 HAL_Kv_Set() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Kv_Set() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Kv_Set(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Kv_Set, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_KV_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_Kv_Set(const char *key, const void *val, int len, int sync)
{
return (int)1;
}
/**
?*
?* 函数 HAL_Malloc() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Malloc() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Malloc(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Malloc, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
*
* @param [in] size @n specify block size in bytes.
* @return A pointer to the beginning of the block.
* @see None.
* @note Block value is indeterminate.
*/
void *HAL_Malloc(uint32_t size)
{
char* mallocDebug = pvPortMalloc(size);
return (void*)mallocDebug;
}
/**
?*
?* 函数 HAL_MutexCreate() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_MutexCreate() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_MutexCreate(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_MutexCreate, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Create a mutex.
*
* @retval NULL : Initialize mutex failed.
* @retval NOT_NULL : The mutex handle.
* @see None.
* @note None.
*/
void *HAL_MutexCreate(void)
{
return (void *)xSemaphoreCreateMutex();
}
/**
?*
?* 函数 HAL_MutexDestroy() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_MutexDestroy() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_MutexDestroy(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_MutexDestroy, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Destroy the specified mutex object, it will release related resource.
*
* @param [in] mutex @n The specified mutex.
* @return None.
* @see None.
* @note None.
*/
void HAL_MutexDestroy(void *mutex)
{
if (mutex != NULL) {
vSemaphoreDelete((SemaphoreHandle_t)mutex);
}
}
/**
?*
?* 函数 HAL_MutexLock() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_MutexLock() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_MutexLock(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_MutexLock, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Waits until the specified mutex is in the signaled state.
*
* @param [in] mutex @n the specified mutex.
* @return None.
* @see None.
* @note None.
*/
void HAL_MutexLock(void *mutex)
{
if (mutex != NULL) {
xSemaphoreTake((SemaphoreHandle_t)mutex, portMAX_DELAY);
}
}
/**
?*
?* 函数 HAL_MutexUnlock() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_MutexUnlock() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_MutexUnlock(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_MutexUnlock, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Releases ownership of the specified mutex object..
*
* @param [in] mutex @n the specified mutex.
* @return None.
* @see None.
* @note None.
*/
void HAL_MutexUnlock(void *mutex)
{
if (mutex != NULL) {
xSemaphoreGive((SemaphoreHandle_t)mutex);
}
}
/**
?*
?* 函数 HAL_Random() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Random() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Random(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Random, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
uint32_t HAL_Random(uint32_t region)
{
srand(get_current_seconds()); //用时间做种,每次产生随机数不一样 rand()%(b-a)+a [a,b)//(后期添加)
return (rand()%(region-0)+0); //[0, region)之间的随机整数//(后期添加)
}
/**
?*
?* 函数 HAL_Read() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Read() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Read(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Read, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief write data to terminal
*
* @param[in] fd @n device descriptor.
* @param[out] data pointer to the buffer which will store incoming data
* @param[out] count number of bytes received
* @return count number of bytes received.
* @see None.
* @note None.
*/
int HAL_Read(int fd, void *buf, int len)
{
return (int)1;
}
/**
?*
?* 函数 HAL_SSL_Destroy() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SSL_Destroy() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SSL_Destroy(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SSL_Destroy, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/tls/HAL_TLS_mbedtls.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int32_t HAL_SSL_Destroy(uintptr_t handle)
{
return (int32_t)1;
}
/**
?*
?* 函数 HAL_SSL_Establish() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SSL_Establish() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SSL_Establish(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SSL_Establish, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/tls/HAL_TLS_mbedtls.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
uintptr_t HAL_SSL_Establish(const char *host,
uint16_t port,
const char *ca_crt,
uint32_t ca_crt_len)
{
return (uintptr_t)1;
}
/**
?*
?* 函数 HAL_SSL_Read() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SSL_Read() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SSL_Read(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SSL_Read, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/tls/HAL_TLS_mbedtls.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_SSL_Read(uintptr_t handle, char *buf, int len, int timeout_ms)
{
return (int)1;
}
/**
?*
?* 函数 HAL_SSL_Write() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SSL_Write() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SSL_Write(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SSL_Write, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/tls/HAL_TLS_mbedtls.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_SSL_Write(uintptr_t handle, const char *buf, int len, int timeout_ms)
{
return (int)1;
}
/**
?*
?* 函数 HAL_SetFirmwareVersion() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SetFirmwareVersion() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SetFirmwareVersion(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SetFirmwareVersion, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_SetFirmwareVersion(const char *version)
{
return (int)1;
}
/**
?*
?* 函数 HAL_SleepMs() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_SleepMs() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_SleepMs(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_SleepMs, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Sleep thread itself.
*
* @param [in] ms @n the time interval for which execution is to be suspended, in milliseconds.
* @return None.
* @see None.
* @note None.
*/
void HAL_SleepMs(uint32_t ms)
{
mSleep(ms);
return;
}
/**
?*
?* 函数 HAL_Snprintf() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Snprintf() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Snprintf(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Snprintf, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Writes formatted data to string.
*
* @param [out] str: @n String that holds written text.
* @param [in] len: @n Maximum length of character will be written
* @param [in] fmt: @n Format that contains the text to be written, it can optionally contain embedded format specifiers
that specifies how subsequent arguments are converted for output.
* @param [in] ...: @n the variable argument list, for formatted and inserted in the resulting string replacing their respective specifiers.
* @return bytes of character successfully written into string.
* @see None.
* @note None.
*/
int HAL_Snprintf(char *str, const int len, const char *fmt, ...)
{
//说明:在c中,当无法列出传递函数的所有实参的类型和数目时,可用省略号指定参数表
// 例:void foo(...); void foo(para_list, ...);
va_list args; //va_list是一个字符指针,可理解为指向当前参数的一个指针,取参必须通过它进行
int rc;
va_start(args, fmt); //对args初始化,让它指向可变参数表里的第一个参数,这是通过va_start()实现的,第一个参数时va_list本身,第二个参数是在变参表前面紧挨着恶的一个变量,即...之前的参数
rc = vsnprintf(str, len, fmt, args);
va_end(args);
return rc;
}
/**
?*
?* 函数 HAL_Srandom() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Srandom() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Srandom(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Srandom, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
void HAL_Srandom(uint32_t seed)
{
srand(seed);
return;
}
/**
?*
?* 函数 HAL_TCP_Destroy() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_TCP_Destroy() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_TCP_Destroy(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_TCP_Destroy, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_TCP_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Destroy the specific TCP connection.
*
* @param [in] fd: @n Specify the TCP connection by handle.
*
* @return The result of destroy TCP connection.
* @retval < 0 : Fail.
* @retval 0 : Success.
*/
int HAL_TCP_Destroy(uintptr_t fd)
{
#if(BS_GWSDK_EN)
s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag = -1;
Plat_Comm_LOG("HAL TCP Destroy\n");
#endif
return (int)1;
}
/**
?*
?* 函数 HAL_TCP_Establish() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_TCP_Establish() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_TCP_Establish(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_TCP_Establish, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_TCP_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Establish a TCP connection.
*
* @param [in] host: @n Specify the hostname(IP) of the TCP server
* @param [in] port: @n Specify the TCP port of TCP server
*
* @return The handle of TCP connection.
@retval (uintptr_t)(-1): Fail.
@retval All other values(0 included): Success, the value is handle of this TCP connection.
*/
uintptr_t HAL_TCP_Establish(const char *host, uint16_t port)
{
#if(BS_GWSDK_EN)
char hostIp[64];
U8_T u8_ret ;
S_4G_CONFIG_PARA s_4g_para;
SYS_FIX_CFG_T *t_sys_fix_cfg = &g_t_share_data.t_sys_fix_cfg;
static uint16_t portRcd = 0;
U8_T u8_out_cnt =0;
snprintf(hostIp, 64, "%s,%u", host, port);
//获取4G模块配置参数
memset(&s_4g_para , 0 ,sizeof(S_4G_CONFIG_PARA));
s_4g_para.socketA_IP = (U8_T *)hostIp; //
s_4g_para.socketB_IP = NULL;
s_4g_para.u8_Sim_Type = t_sys_fix_cfg->s_net_cfg.u_net_comm_para.bits.bit_sim_anp_type;
s_4g_para.u8_socketB_en = t_sys_fix_cfg->s_net_cfg.u_net_comm_para.bits.bit_platB_en;
if(portRcd != port)
{
portRcd = port;
s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag = -1;
v_wh_gm5_data_init(&s_4g_para); //4G模块控制数据 初始化
s_bs_task_ctrl.s_bs_ctrl[0].ulong_restart_timer = get_current_seconds();
Plat_Comm_LOG("sdk connet IP = %s\n",s_4g_para.socketA_IP);
}
else
{
if(s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag >= 0) //已经连接直接退出
return 1;
}
s_bs_task_ctrl.s_bs_ctrl[0].ulong_restart_timer = get_current_seconds();
Plat_Comm_LOG("sdk connet [%d]\n",s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag);
while (1)
{
u8_ret = 0;
HAL_TASK_WDT_CLEAR(); //清空看门狗计数
// 无线模块WH_GM5初始化
if(s8_WH_GM5_init() == 0) //如果4g配置成功
{
s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag = 0;
if(s8_check_socket_LinkState(0) >= 0) //查询网路连接状态
{
mSleep(100);
v_4g_uart_cache_clear(); //4G模块配置完毕 清除串口缓存区中的数据
return 1;
}
}
if(u8_out_cnt++ > NUM_250 || //防止以上超时退出条件不满足 再加一层计数退出判断--此计数按睡眠周期执行 250*100ms
(u8_ret == 0 && u32_safe_seconds_since(s_bs_task_ctrl.s_bs_ctrl[0].ulong_restart_timer) > NUM_120)) //120分钟 没连上 则重新连接
{
s_bs_task_ctrl.s_gwsdk_ctrl.gw_connet_flag = -1;
v_wh_gm5_data_init(&s_4g_para); //4G模块控制数据 初始化
s_bs_task_ctrl.s_bs_ctrl[0].ulong_restart_timer = get_current_seconds();
Plat_Comm_LOG("sdk connet 2 min err u8_out_cnt= %d , IP=%s\n",u8_out_cnt,s_4g_para.socketA_IP);
return 0;
}
mSleep(100);
}
#endif
return (uintptr_t)0;
}
/**
?*
?* 函数 HAL_TCP_Read() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_TCP_Read() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_TCP_Read(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_TCP_Read, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_TCP_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Read data from the specific TCP connection with timeout parameter.
* The API will return immediately if 'len' be received from the specific TCP connection.
*
* @param [in] fd @n A descriptor identifying a TCP connection.
* @param [out] buf @n A pointer to a buffer to receive incoming data.
* @param [out] len @n The length, in bytes, of the data pointed to by the 'buf' parameter.
* @param [in] timeout_ms @n Specify the timeout value in millisecond. In other words, the API block 'timeout_ms' millisecond maximumly.
*
* @retval -2 : TCP connection error occur.
* @retval -1 : TCP connection be closed by remote server.
* @retval 0 : No any data be received in 'timeout_ms' timeout period.
* @retval (0, len] : The total number of bytes be received in 'timeout_ms' timeout period.
* @see None.
*/
int32_t HAL_TCP_Read(uintptr_t fd, char *buf, uint32_t len, uint32_t timeout_ms)
{
int32_t total = 0;
uint32_t timerCnt = 0;
/* 蜂窝网络场景下,4G 模块可能分片发送,至少等待 500ms 收集完整报文 */
uint32_t effective = (timeout_ms > 500U) ? timeout_ms : 500U;
uint32_t maxCnt = effective / 20U;
do
{
int32_t rcvLen = u16_bs_recv(0, (U8_T*)(buf + total), len - total);
if(rcvLen > 0)
{
total += rcvLen;
if(total >= (int32_t)len)
{
return total;
}
continue; /* 收到数据,不 sleep,立即尝试继续读取 */
}
mSleep(20);
timerCnt++;
}while(timerCnt < maxCnt);
return total;
}
/**
?*
?* 函数 HAL_TCP_Write() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_TCP_Write() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_TCP_Write(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_TCP_Write, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_TCP_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Write data into the specific TCP connection.
* The API will return immediately if 'len' be written into the specific TCP connection.
*
* @param [in] fd @n A descriptor identifying a connection.
* @param [in] buf @n A pointer to a buffer containing the data to be transmitted.
* @param [in] len @n The length, in bytes, of the data pointed to by the 'buf' parameter.
* @param [in] timeout_ms @n Specify the timeout value in millisecond. In other words, the API block 'timeout_ms' millisecond maximumly.
*
* @retval < 0 : TCP connection error occur..
* @retval 0 : No any data be write into the TCP connection in 'timeout_ms' timeout period.
* @retval (0, len] : The total number of bytes be written in 'timeout_ms' timeout period.
* @see None.
*/
int32_t HAL_TCP_Write(uintptr_t fd, const char *buf, uint32_t len, uint32_t timeout_ms)
{
v_bs_send(0, (U8_T*)buf, len);
return (int32_t)len;
}
/**
?*
?* 函数 HAL_UTC_Get() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_UTC_Get() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_UTC_Get(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_UTC_Get, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
long HAL_UTC_Get(void)
{
return (long)1;
}
/**
?*
?* 函数 HAL_UTC_Set() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_UTC_Set() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_UTC_Set(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_UTC_Set, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_UTC_Set(long s)
{
return (int)1;
}
/**
?*
?* 函数 HAL_UptimeMs() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_UptimeMs() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_UptimeMs(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_UptimeMs, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief Retrieves the number of milliseconds that have elapsed since the system was boot.
*
* @return the number of milliseconds.
* @see None.
* @note None.
*/
uint64_t HAL_UptimeMs(void)
{
return (uint64_t)(u64_get_current_millis());
}
/**
?*
?* 函数 HAL_Vsnprintf() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Vsnprintf() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Vsnprintf(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Vsnprintf, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
int HAL_Vsnprintf(char *str, const int len, const char *format, va_list ap)
{
return vsnprintf(str, len, format, ap); //(int)1;
}
/**
?*
?* 函数 HAL_Write() 需要SDK的使用者针对SDK将运行的硬件平台填充实现, 供SDK调用
?* ---
?* Interface of HAL_Write() requires to be implemented by user of SDK, according to target device platform
?*
?* 如果需要参考如何实现函数 HAL_Write(), 可以查阅SDK移植到 Ubuntu Linux 上时的示例代码
?* ---
?* If you need guidance about how to implement HAL_Write, you can check its reference implementation for Ubuntu platform
?*
?* https://code.aliyun.com/linkkit/c-sdk/blob/v3.0.1/wrappers/os/ubuntu/HAL_OS_linux.c
?*
?*
?* 注意! HAL_XXX() 系列的函数虽然有阿里提供的对应参考实现, 但不建议您不做任何修改/检视的应用于您的商用设备!
?*?
?* 注意! 参考示例实现仅用于解释各个 HAL_XXX() 系列函数的语义!
?*?
?*/
/**
* @brief write data to terminal
*
* @param[in] fd @n device descriptor.
* @param[in] data pointer to the start of data
* @param[in] size number of bytes to transmit
* @return count number of bytes received.
* @see None.
* @note None.
*/
int HAL_Write(int fd, const void *buf, int len)
{
return (int)1;
}