|
|
@@ -18,68 +18,16 @@
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
|
-#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
-#include <stdarg.h>
|
|
|
-#include <string.h>
|
|
|
-
|
|
|
-#include <sys/time.h>
|
|
|
-
|
|
|
-#include "infra_config.h"
|
|
|
-#include "infra_compat.h"
|
|
|
+#include "infra_types.h"
|
|
|
#include "infra_defs.h"
|
|
|
#include "wrappers_defs.h"
|
|
|
|
|
|
-#define ALI_IOTKIT_HAL_OS_DEBUG
|
|
|
-
|
|
|
-#ifdef ALI_IOTKIT_HAL_OS_DEBUG
|
|
|
#define DBG_TAG "ali.os"
|
|
|
#define DBG_LVL DBG_INFO
|
|
|
#include <rtdbg.h>
|
|
|
-#else
|
|
|
-#define LOG_D(...)
|
|
|
-#define LOG_I(...)
|
|
|
-#define LOG_W(...)
|
|
|
-#define LOG_E(...)
|
|
|
-#endif
|
|
|
-
|
|
|
-#ifdef DYNAMIC_REGISTER
|
|
|
- char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1ZETBPbycq";
|
|
|
- char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "L68wCVXYUaNg1Ey9";
|
|
|
- char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "example1";
|
|
|
- char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "";
|
|
|
-#else
|
|
|
- #ifdef DEVICE_MODEL_ENABLED
|
|
|
- char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1RIsMLz2BJ";
|
|
|
- char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "fSAF0hle6xL0oRWd";
|
|
|
- char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "example1";
|
|
|
- char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "RDXf67itLqZCwdMCRrw0N5FHbv5D7jrE";
|
|
|
- #else
|
|
|
- char _product_key[IOTX_PRODUCT_KEY_LEN + 1] = "a1MZxOdcBnO";
|
|
|
- char _product_secret[IOTX_PRODUCT_SECRET_LEN + 1] = "h4I4dneEFp7EImTv";
|
|
|
- char _device_name[IOTX_DEVICE_NAME_LEN + 1] = "test_01";
|
|
|
- char _device_secret[IOTX_DEVICE_SECRET_LEN + 1] = "t9GmMf2jb3LgWfXBaZD2r3aJrfVWBv56";
|
|
|
- #endif
|
|
|
-#endif
|
|
|
-
|
|
|
-#undef perror
|
|
|
-#define perror rt_kprintf
|
|
|
|
|
|
-#define HAL_OS_LOG_MAXLEN 512
|
|
|
-
|
|
|
-static char log_buf[HAL_OS_LOG_MAXLEN];
|
|
|
-
|
|
|
-int HAL_GetFirmwareVersion(char *version)
|
|
|
-{
|
|
|
- RT_ASSERT(version);
|
|
|
-
|
|
|
- char *ver = "app-1.0.0-20180101.1000";
|
|
|
- int len = strlen(ver);
|
|
|
- memset(version, 0x0, IOTX_FIRMWARE_VER_LEN);
|
|
|
- strncpy(version, ver, IOTX_FIRMWARE_VER_LEN);
|
|
|
- version[len] = '\0';
|
|
|
- return strlen(version);
|
|
|
-}
|
|
|
+static char log_buf[RT_CONSOLEBUF_SIZE];
|
|
|
|
|
|
void *HAL_MutexCreate(void)
|
|
|
{
|
|
|
@@ -128,7 +76,7 @@ void *HAL_SemaphoreCreate(void)
|
|
|
{
|
|
|
char name[10] = {0};
|
|
|
static uint8_t sem_num = 0;
|
|
|
- snprintf(name, sizeof(name), "sem%02d", ((++sem_num)%100));
|
|
|
+ rt_snprintf(name, sizeof(name), "sem%02d", ((++sem_num)%100));
|
|
|
rt_sem_t sem = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);
|
|
|
if (!sem)
|
|
|
{
|
|
|
@@ -308,121 +256,7 @@ void HAL_Printf(const char *fmt, ...)
|
|
|
va_list args;
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
- rt_vsnprintf(log_buf, HAL_OS_LOG_MAXLEN, fmt, args);
|
|
|
+ rt_vsnprintf(log_buf, RT_CONSOLEBUF_SIZE, fmt, args);
|
|
|
va_end(args);
|
|
|
rt_kprintf("%s", log_buf);
|
|
|
}
|
|
|
-
|
|
|
-extern void rt_hw_cpu_reset();
|
|
|
-
|
|
|
-#ifndef rt_hw_cpu_reset
|
|
|
-void rt_hw_cpu_reset()
|
|
|
-{
|
|
|
-}
|
|
|
-#endif
|
|
|
-void HAL_Reboot(void)
|
|
|
-{
|
|
|
- rt_hw_cpu_reset();
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_SetProductKey(char* product_key)
|
|
|
-{
|
|
|
- int len = strlen(product_key);
|
|
|
-
|
|
|
- if (len > IOTX_PRODUCT_KEY_LEN)
|
|
|
- return -1;
|
|
|
- memset(_product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
|
|
|
- strncpy(_product_key, product_key, len);
|
|
|
-
|
|
|
- return len;
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_SetDeviceName(char* device_name)
|
|
|
-{
|
|
|
- int len = strlen(device_name);
|
|
|
-
|
|
|
- if (len > IOTX_DEVICE_NAME_LEN)
|
|
|
- return -1;
|
|
|
- memset(_device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
|
|
|
- strncpy(_device_name, device_name, len);
|
|
|
-
|
|
|
- return len;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int HAL_SetDeviceSecret(char* device_secret)
|
|
|
-{
|
|
|
- int len = strlen(device_secret);
|
|
|
-
|
|
|
- if (len > IOTX_DEVICE_SECRET_LEN)
|
|
|
- return -1;
|
|
|
- memset(_device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
|
|
|
- strncpy(_device_secret, device_secret, len);
|
|
|
-
|
|
|
- return len;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-int HAL_SetProductSecret(char* product_secret)
|
|
|
-{
|
|
|
- int len = strlen(product_secret);
|
|
|
-
|
|
|
- if (len > IOTX_PRODUCT_SECRET_LEN)
|
|
|
- return -1;
|
|
|
- memset(_product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
|
|
|
- strncpy(_product_secret, product_secret, len);
|
|
|
-
|
|
|
- return len;
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_GetProductKey(char product_key[IOTX_PRODUCT_KEY_LEN + 1])
|
|
|
-{
|
|
|
- memset(product_key, 0x0, IOTX_PRODUCT_KEY_LEN + 1);
|
|
|
- strncpy(product_key, _product_key, IOTX_PRODUCT_KEY_LEN);
|
|
|
-
|
|
|
- return strlen(product_key);
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_GetProductSecret(char product_secret[IOTX_PRODUCT_SECRET_LEN + 1])
|
|
|
-{
|
|
|
- memset(product_secret, 0x0, IOTX_PRODUCT_SECRET_LEN + 1);
|
|
|
- strncpy(product_secret, _product_secret, IOTX_PRODUCT_SECRET_LEN);
|
|
|
-
|
|
|
- return strlen(product_secret);
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_GetDeviceName(char device_name[IOTX_DEVICE_NAME_LEN + 1])
|
|
|
-{
|
|
|
- memset(device_name, 0x0, IOTX_DEVICE_NAME_LEN + 1);
|
|
|
- strncpy(device_name, _device_name, IOTX_DEVICE_NAME_LEN);
|
|
|
-
|
|
|
- return strlen(device_name);
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_GetDeviceSecret(char device_secret[IOTX_DEVICE_SECRET_LEN + 1])
|
|
|
-{
|
|
|
- memset(device_secret, 0x0, IOTX_DEVICE_SECRET_LEN + 1);
|
|
|
- strncpy(device_secret, _device_secret, IOTX_DEVICE_SECRET_LEN);
|
|
|
-
|
|
|
- return strlen(device_secret);
|
|
|
-}
|
|
|
-
|
|
|
-void HAL_Firmware_Persistence_Start(void)
|
|
|
-{
|
|
|
- LOG_I("OTA start... [Not implemented]");
|
|
|
- return;
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_Firmware_Persistence_Write(char *buffer, uint32_t length)
|
|
|
-{
|
|
|
- LOG_I("OTA write... [Not implemented]");
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-int HAL_Firmware_Persistence_Stop(void)
|
|
|
-{
|
|
|
- /* check file md5, and burning it to flash ... finally reboot system */
|
|
|
-
|
|
|
- LOG_I("OTA finish... [Not implemented]");
|
|
|
- return 0;
|
|
|
-}
|