Browse Source

【更新】独立出来 wrapper.c,用于连云的参数配置
【更新】调试日志加入方式

Murphy 6 years ago
parent
commit
0c672b545e
5 changed files with 131 additions and 190 deletions
  1. 2 2
      SConscript
  2. 4 170
      ports/rtthread/HAL_OS_rtthread.c
  3. 0 9
      ports/rtthread/HAL_TCP_rtthread.c
  4. 0 9
      ports/rtthread/HAL_UDP_rtthread.c
  5. 125 0
      ports/wrapper.c

+ 2 - 2
SConscript

@@ -248,6 +248,7 @@ src += Split("""
 ports/rtthread/HAL_OS_rtthread.c
 ports/rtthread/HAL_TCP_rtthread.c
 ports/rtthread/HAL_UDP_rtthread.c
+ports/wrapper.c
 """)
 
 if GetDepend(['SUPPORT_TLS']) or GetDepend(['COAP_DTLS_SUPPORT']):
@@ -257,7 +258,6 @@ if GetDepend(['SUPPORT_TLS']):
 if GetDepend(['COAP_DTLS_SUPPORT']):
     src += Glob('port/tls/mbedtls/HAL_DTLS_mbedtls.c')
 CPPPATH += [cwd + '/iotkit-embedded/wrappers']
-CPPPATH += [cwd + '/iotkit-embedded/wrappers/tls']
 #### wrappers | port end ####
 
 #
@@ -271,6 +271,6 @@ if GetDepend(['PKG_USING_ALI_IOTKIT_DEV_MODEL_SAMPLE']):
     CPPPATH += [cwd + '/iotkit-embedded/samples/dev_model']
 #### samples end ####
 
-group = DefineGroup('ali-iotkit', src, depend = [''], CPPPATH = CPPPATH)
+group = DefineGroup('ali-iotkit', src, depend = ['PKG_USING_ALI_IOTKIT'], CPPPATH = CPPPATH)
 
 Return('group')

+ 4 - 170
ports/rtthread/HAL_OS_rtthread.c

@@ -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;
-}

+ 0 - 9
ports/rtthread/HAL_TCP_rtthread.c

@@ -30,18 +30,9 @@
 #include <netinet/tcp.h>
 #include <netdb.h>
 
-#define ALI_IOTKIT_HAL_TCP_DEBUG
-
-#ifdef ALI_IOTKIT_HAL_TCP_DEBUG
 #define DBG_TAG                        "ali.tcp"
 #define DBG_LVL                        DBG_INFO
 #include <rtdbg.h>
-#else
-#define LOG_D(...)
-#define LOG_I(...)
-#define LOG_W(...)
-#define LOG_E(...)
-#endif
 
 extern void HAL_Printf(const char *fmt, ...);
 extern uint64_t HAL_UptimeMs(void);

+ 0 - 9
ports/rtthread/HAL_UDP_rtthread.c

@@ -29,18 +29,9 @@
 #include <netdb.h>
 #include <unistd.h>
 
-#define ALI_IOTKIT_HAL_UDP_DEBUG
-
-#ifdef ALI_IOTKIT_HAL_UDP_DEBUG
 #define DBG_TAG                        "ali.udp"
 #define DBG_LVL                        DBG_INFO
 #include <rtdbg.h>
-#else
-#define LOG_D(...)
-#define LOG_I(...)
-#define LOG_W(...)
-#define LOG_E(...)
-#endif
 
 void *HAL_UDP_create(char *host, unsigned short port)
 {

+ 125 - 0
ports/wrapper.c

@@ -0,0 +1,125 @@
+#include <rtthread.h>
+#include <string.h>
+
+#include "wrappers_defs.h"
+
+#define DBG_TAG                        "ali.tcp"
+#define DBG_LVL                        DBG_INFO
+#include <rtdbg.h>
+
+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]   = "";
+
+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);
+}
+
+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);
+}
+
+RT_WEAK void HAL_Firmware_Persistence_Start(void)
+{
+    LOG_I("OTA start... [Not implemented]");
+    return;
+}
+
+RT_WEAK int HAL_Firmware_Persistence_Write(char *buffer, uint32_t length)
+{
+    LOG_I("OTA write... [Not implemented]");
+    return 0;
+}
+
+RT_WEAK 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;
+}