1、指定的设备才能使用4glib 1644/3
authorSnickerSun <snickersun@163.com>
Fri, 24 Jan 2025 09:50:14 +0000 (17:50 +0800)
committerSnickerSun <snickersun@163.com>
Fri, 24 Jan 2025 09:50:14 +0000 (17:50 +0800)
2、优化日志输出
3、把net_test代码放到 4gTest路径给用户做参考使用

56 files changed:
.vscode/settings.json
code/sdk/application/brandy/brandy_standard/thread_init.c
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/boards/brandy_evb/board_config/board_evb.h
code/sdk/drivers/chips/brandy/clocks/drivers/acore/clocks_config_priv.c
code/sdk/drivers/chips/brandy/config/pmp_config.c
code/sdk/drivers/chips/brandy/porting/uart/uart_porting.c
code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c
code/sdk/interim_binary/brandy/libs/media/evb_standard/libjs_audio_capturer.a
code/sdk/middleware/chips/brandy/pm/service/pm_sleep.c
code/sdk/zhihui/4g/cat1Service/CMakeLists.txt
code/sdk/zhihui/4g/cat1Service/Service/cat1_ctl.c
code/sdk/zhihui/4g/cat1Service/Service/cat1_runtime.c
code/sdk/zhihui/4g/cat1Service/Service/cat1_server.c
code/sdk/zhihui/4g/cat1Service/Service/cat1_server_hal.c
code/sdk/zhihui/4g/cat1Service/Service/cat1_signlib.c [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/Service/cat1_tcpServer.c
code/sdk/zhihui/4g/cat1Service/Service/cat1_utils.c
code/sdk/zhihui/4g/cat1Service/include/cat1_ctl.h
code/sdk/zhihui/4g/cat1Service/include/cat1_log.h [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/include/cat1_porting.h [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/include/cat1_pub_api.h [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/include/cat1_runtime.h
code/sdk/zhihui/4g/cat1Service/include/cat1_server.h
code/sdk/zhihui/4g/cat1Service/include/cat1_server_hal.h
code/sdk/zhihui/4g/cat1Service/include/cat1_types.h [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/include/cat1_utils.h
code/sdk/zhihui/4g/cat1Service/include/custom_http_download.h [new file with mode: 0644]
code/sdk/zhihui/4g/cat1Service/lwip/CMakeLists.in
code/sdk/zhihui/4g/cat1Service/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h
code/sdk/zhihui/4g/cat1Service/lwip/src/api/tcpip.c
code/sdk/zhihui/4g/cat1Service/lwip/src/apps/sntp/sntp.c
code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.c [deleted file]
code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.h [deleted file]
code/sdk/zhihui/4g/cat1Service/slip/uart_slip.c
code/sdk/zhihui/4g/cat1Service/slip/uart_slip.h
code/sdk/zhihui/4gTest/CMakeLists.txt
code/sdk/zhihui/4gTest/cat1_at_cmd.c
code/sdk/zhihui/4gTest/cat1_porting.c
code/sdk/zhihui/4gTest/net_test/lwip_test.h [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c [new file with mode: 0644]
code/sdk/zhihui/4gTest/net_test/test_main.c [new file with mode: 0644]
code/sdk/zhihui/services/battery/service/battery_service.cpp
code/sdk/zhihui/services/battery/service/battery_service.h

index 68189f0..b8a8a5c 100644 (file)
         "mag_service.h": "c",
         "mmc5603_hal.h": "c",
         "clocks_config.h": "c",
-        "clocks_types.h": "c"
+        "clocks_types.h": "c",
+        "cat1_pub_api.h": "c",
+        "cat1_types.h": "c",
+        "cat1_utils.h": "c",
+        "cat1_ctl.h": "c",
+        "wearable_log.h": "c",
+        "stdint.h": "c",
+        "cat1_log.h": "c",
+        "hks_crypto_hal.h": "c",
+        "hks_template.h": "c",
+        "hks_config.h": "c",
+        "hks_crypto_ed25519.h": "c",
+        "hks_api.h": "c",
+        "hks_test_curve25519.h": "c",
+        "hks_test_log.h": "c",
+        "securec.h": "c",
+        "hks_type.h": "c"
     }
 }
\ No newline at end of file
index 93eebd0..0a12576 100644 (file)
@@ -136,7 +136,7 @@ app_task_definition_t g_app_tasks[] = {
     { { "bt_sdk", 0, NULL, 0, NULL, BTH_SDK_STACK_SIZE, TASK_PRIORITY_SDK, 0, 0 },
       (osThreadFunc_t)bt_acore_task_main, NULL, NULL, USE_DTCM_MEM },
 #ifdef SUPPORT_AT_CMD
-    { { "at_cmd", 0, NULL, 0, NULL, 0xC00, TASK_PRIORITY_APP, 0, 0 },
+    { { "at_cmd", 0, NULL, 0, NULL, 0x1C00, TASK_PRIORITY_APP, 0, 0 },
       (osThreadFunc_t)at_cmd_task_process_handler, NULL,
       (CreateQueueFunction_t)at_cmd_task_queue_init, USE_DTCM_MEM },
 #endif
index 9e37157..165e7fd 100644 (file)
@@ -117,6 +117,7 @@ target = {
                     'SW_UART_DEBUG', 'SAVE_EXC_INFO', 'HASH_MEM_COPY', 'JS_ENABLE', 'CONFIG_LOW_POWER_TEST',
                     'FT_SINGLE_UART',
                     'TPTYPE_FT6X46',
+                    'BOARD_FD230',
                     'CFG_FLASH_SIZE=16',
                                        'SUPPORT_CAT1_SERVICE',
                     'SUPPORT_BATTERY_SERVICE',
@@ -125,8 +126,8 @@ target = {
                           "liteos_port", 'lcd', 'qspi_display', 'dfx_file_operation',
                           'psram', 'hal_mipi', 'mipi_tx', 'non_os', 'touch',
                           'ulp_aon', 'hal_l2ram', 'bt_manager_at_service',
-                          'batterry_service',
-                          "cat1Service","cat1Test",
+                          'batterry_service',"huks_sdk",
+                          "cat1Service","cat1Test", 
                           'x_dpal', 'x_vfs', 'x_disk', 'x_fat', 'drv_mmc', 'fs_yaffs2', 'x_vfs_private',
                           'pm_service', 'pm_brandy', 'cmn_header', 'at_cmd', 'graphic_at_service', 'app_at_service', 'ohosfwk_at_service',
                           "audio_proc", "audio_dump", "audio_probe", "power_manager", "gpu_proc",'bts_header'],
index e347f78..887e383 100644 (file)
@@ -11,9 +11,9 @@
 #include "gpio_porting.h"
 #include "platform_types.h"
 
-#ifdef SUPPORT_CAT1_SERVICE
-#include "cat1_ctl.h"
-#endif
+// #ifdef SUPPORT_CAT1_SERVICE
+// #include "cat1_ctl.h"
+// #endif
 
 /**
  * @addtogroup connectivity_config_boards
@@ -91,12 +91,19 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = {
 // #endif
 
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },     // S_MGPIO5  NC
+#ifdef A5133_USE_HW_SPI
     { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },  // S_MGPIO6  SPI1 DI
     { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },  // S_MGPIO7 SPI1 DO
     { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },  // S_MGPIO8 SPI1 CLK
     { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },   // S_MGPIO9 SPI1 CS0
     { HAL_PIO_FUNC_SPI1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_MGPIO10 SPI1 CS1 NC
-
+#else
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },  // S_MGPIO6  SPI1 DI
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },  // S_MGPIO7 SPI1 DO
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },  // S_MGPIO8 SPI1 CLK
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_MGPIO9 SPI1 CS0
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_MGPIO10 SPI1 CS1 NC
+#endif
     { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO11 i2c0 SCL NC
     { HAL_PIO_FUNC_I2C0_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO12 I2C0 SDA
     { HAL_PIO_FUNC_I2C1_M1, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE }, // S_MGPIO13 I2C1 SCL touch i2c
@@ -172,8 +179,8 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = {
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE },  // S_AGPIO_L19  G_INT2  //��ʱ���� 
 
 
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE }, // S_AGPIO_L20  0.2C_CHRG
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },    // S_AGPIO_L21  NTC_VDD_ON ���ʹ� NTC������Դ
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE }, // S_AGPIO_L20  0.2C_CHRG
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },    // S_AGPIO_L21  NTC_VDD_ON 给低打开 NTC上拉电源
 #ifdef QSPI_DISPLAY
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },    // S_AGPIO_L22 QSPI TE
 #else
@@ -184,20 +191,23 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = {
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L25  //////////// audio pa reset
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L26 ���ʸ�λ PPG reset
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L27    LCM reset
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L28    CAT_1��λ CAT1_RESET_N  ������Ч
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },   // S_AGPIO_L29    charge done info ����Ƿ������
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L30   KP_MKIN1 ���� CAT1 �����
-    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },   // S_AGPIO_L31    KP_MKOUIT1 ���� ���� ,����
+#ifdef SUPPORT_A5133_SERVICE
+    //{ HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_ENBALE },   // S_AGPIO_L28    CAT_1复位 CAT1_RESET_N  拉低有效
+#else
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L28    CAT_1复位 CAT1_RESET_N  拉低有效
+#endif
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },   // S_AGPIO_L29    charge done info 检测是否充满电
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_L30   KP_MKIN1 唤醒 CAT1 ,输出
+#ifdef SUPPORT_A5133_SERVICE
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_AGPIO_L31  控制A5133开关
+#else
+    { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE },   // S_AGPIO_L31    KP_MKOUIT1 唤醒 蓝牙 ,输入
+#endif
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_AGPIO_L32    NC
 
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_R0   PRG_LED_POWER ON  ���ʵȵ�Դ���ƽ�
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_DISABLE },   // S_AGPIO_R1   SE_REST ��ȫоƬ��λ���ѽ�
-//   #if VIB_USE_PWM
-    // { HAL_PIO_FUNC_PWMP1_M2, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_AGPIO_R2     VIBR_PWM ������ƽ� ����Ԥ������������λ��
-    // { HAL_PIO_FUNC_PWMN1_M3, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_AGPIO_R2     VIBR_PWM ������ƽ� ����Ԥ������������λ��
-//   #else
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE },   // S_AGPIO_R2     VIBR_PWM ������ƽ� ����Ԥ������������λ��
-//   #endif
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_DOWN, HAL_PIO_IE_DISABLE  },   // S_AGPIO_R3     NC   
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_UP, HAL_PIO_IE_DISABLE  },    // S_AGPIO_R4     tp reset
     { HAL_PIO_FUNC_GPIO, HAL_PIO_DRIVE_MAX, HAL_PIO_PULL_MAX, HAL_PIO_IE_ENBALE  },   // S_AGPIO_R5     touch int
@@ -240,11 +250,8 @@ const hal_pio_config_t g_pio_function_config[PIN_MAX_NUMBER] = {
  */
 
 
-//Ĭ�Ͽ���Cat1 Ȼ���ٸ������þ����Ƿ�ر�. 
-//Ĭ�ϲ����� ppg checkidʧ�ܣ�ԭ��δ֪����ʱ��������cat1
-#define DEFAULT_POWERON_CAT1 0
+#define DEFAULT_POWERON_CAT1 1
 
-//��Ҫ����Ĭ������ģ��Լ���Ҫ����Ĭ�������жϺ����ġ�
 const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = {
 
 #if DEFAULT_POWERON_CAT1
@@ -258,23 +265,21 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = {
    // S_AGPIO_L28   Cat1 reset  ---- low reset
     {   S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
 #endif
-    // S_AGPIO_L17   HX3507_INT 
-    // {   S_AGPIO_L17, HAL_GPIO_DIRECTION_INPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
     // S_AGPIO_L12  SDIO_BT
     {   S_AGPIO_L12, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
     // S_AGPIO_L13   SCLK_BT
     {   S_AGPIO_L13, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
 
-     // S_AGPIO_L26 ���ʸ�λ PPG reset
+     // S_AGPIO_L26  PPG reset
     {   S_AGPIO_L26, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
-    // S_AGPIO_R0 PRG_LED_POWER ON  ���ʵȵ�Դ���ƽ�
+    // S_AGPIO_R0 PRG_LED_POWER ON  
     {   S_AGPIO_R0, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
 
-    //S_AGPIO_L21 NTC_VDD_ON ���ʹ� NTC������Դ ,Ĭ�Ϲر�
+    //S_AGPIO_L21 NTC_VDD_ON  NTC
     {   S_AGPIO_L21, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
-#if 1  //Ĭ��������� 
+#if 0  //默认正常充电 
 //    #define GPIO_PIN_ENABLE_CHARGE S_AGPIO_R9  //low enable
-// #define GPIO_PIN_ENABLE_CHARGE_0_2C S_AGPIO_L20   //low 0.2c �͵������
+// #define GPIO_PIN_ENABLE_CHARGE_0_2C S_AGPIO_L20   //low 0.2c 低电流充电
     {   S_AGPIO_R9, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
     {   S_AGPIO_L20, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
 #else
@@ -282,18 +287,13 @@ const hal_gpio_config_t g_gpio_function_config[PIN_MAX_NUMBER] = {
     {   S_AGPIO_L20, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
 #endif
 
-//Ĭ�Ϲر�����
     {   S_AGPIO_R2, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_LOW, 0, NULL },
-//Ĭ�Ͽ��� EXT LDO V3.0 V1.8
+// EXT LDO V3.0 V1.8
     {   S_AGPIO_L18, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
 
-    /**S_AGPIO_R1 GPO alipayĬ��resetpin*/
+    /**S_AGPIO_R1 GPO alipay resetpin*/
     {   S_AGPIO_R1, HAL_GPIO_DIRECTION_OUTPUT, HAL_GPIO_LEVEL_HIGH, 0, NULL },
-#ifdef SUPPORT_CAT1_SERVICE
-    /**cat1 ring input key*/
-    // {   S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_DEDGE,  cat1_ring_isr_callback},
-    {   S_AGPIO_L31, HAL_GPIO_DIRECTION_INPUT, NULL, GPIO_INTERRUPT_RISING_EDGE,  cat1_ring_isr_callback},
-#endif
+
 };
 /**
  * @}
index 5037787..025bdb9 100644 (file)
@@ -371,7 +371,7 @@ static const system_mcu_perip_clk_t g_system_mcu_perp_clk_set_config[] = {
     {HAL_CLOCKS_APP_UART_H1_CLK, TURN_ON},     // uart h1 clock\r
     {HAL_CLOCKS_APP_I2C0_CLK, TURN_OFF},       // i2c0 clock\r
     {HAL_CLOCKS_APP_I2C1_CLK, TURN_ON},        // i2c1 clock\r
-    {HAL_CLOCKS_APP_I2C2_CLK, TURN_OFF},       // i2c2 clock\r
+    {HAL_CLOCKS_APP_I2C2_CLK, TURN_ON},          // i2c2 clock\r
     {HAL_CLOCKS_APP_I2C3_CLK, TURN_ON},        // i2c3 clock\r
     {HAL_CLOCKS_APP_QSPI_1CS_CLK, TURN_ON},    // qspi clock\r
     {HAL_CLOCKS_APP_XIP_BUS_CLK, TURN_ON},     // xip bus clock\r
index d709c7e..8fc7df3 100644 (file)
@@ -6,7 +6,7 @@
 #include "stdbool.h"\r
 #include "drv_pmp.h"\r
 #include "memory_config.h"\r
-\r
+#include "product.h"\r
 #define L2MEM_DSP_ADDR_START    0x60100000\r
 #define L2MEM_DSP_ADDR_LEN      0x100000\r
 \r
index 2782934..3f06311 100644 (file)
 #include "SEGGER_RTT.h"
 #endif
 
+#ifdef SUPPORT_CAT1_SERVICE
+#include "cat1_pub_api.h"
+#endif
+
 #ifdef BUILD_APPLICATION_SSB
 #define UART_RX_BUFFER_SIZE 1
 #else
@@ -246,7 +250,13 @@ void log_factory_at_callback(const void *buffer, uint16_t length, bool remaining
 {
     log_uart_rx_callback(buffer, length, remaining);
     if (zdiag_is_enable() == false) {
+
+    #ifdef SUPPORT_CAT1_SERVICE
+//        if(!cat1_api_custom_is_cmd_rx_enabled())
+            at_cmd_msg_receive_handler((uint8_t *)buffer, length);
+    #else
         at_cmd_msg_receive_handler((uint8_t *)buffer, length);
+    #endif
         hal_uart_clear_pending(UART_BUS_1);
     }
 }
@@ -307,7 +317,7 @@ static void at_cmd_uart_rx_callback(const void *buf, uint16_t buf_len, bool rema
     #endif
 
     #ifdef SUPPORT_CAT1_SERVICE
-    slip_receive_handler((uint8_t *)buf, buf_len);
+    cat1_uart_receive_handler((uint8_t *)buf, buf_len);
     #endif
     hal_uart_clear_pending(SW_DEBUG_UART_BUS);
 }
index 979c3e2..a8e2870 100644 (file)
@@ -120,7 +120,12 @@ static void report_or_enqueue_event(input_event_info* touch_info, struct ts_driv
 static void report_event_to_power_manager(input_event_info *touch_info)\r
 {\r
     if (g_power_manager_cb != NULL) {\r
-        g_power_manager_cb(touch_info->tp_event, 0);\r
+        input_dev_data_t data;\r
+        convert_touch_info(&data, touch_info);\r
+        if (data.state == INDEV_STATE_UNKNOWN) {\r
+            return;\r
+        }\r
+        g_power_manager_cb(data.state, 0);\r
     }\r
     return;\r
 }\r
index 695bb3c..f5d8bc6 100644 (file)
Binary files a/code/sdk/interim_binary/brandy/libs/media/evb_standard/libjs_audio_capturer.a and b/code/sdk/interim_binary/brandy/libs/media/evb_standard/libjs_audio_capturer.a differ
index d4fc8a3..ec719d8 100644 (file)
@@ -224,11 +224,19 @@ void pm_enter_deep_sleep_only_ulp_wakeup(void)
         pm_wkup_event_by_ulp_callback();
     }
 }
-
+#ifdef SUPPORT_CAT1_SERVICE
+#include "cat1_pub_api.h"
+void pm_wkup_event_by_uart_callback(void)
+{
+    if(cat1_api_custom_is_cmd_rx_enabled())
+        uapi_pm_add_sleep_veto(PM_ID_DEBUG);
+}
+#else
 void pm_wkup_event_by_uart_callback(void)
 {
     uapi_pm_add_sleep_veto(PM_ID_DEBUG);
 }
+#endif
 
 static void pm_enter_deep_sleep(void)
 {
index 54d6afc..5880891 100644 (file)
@@ -19,10 +19,14 @@ set(PUBLIC_HEADER
 set(PRIVATE_HEADER
 ${CMAKE_CURRENT_SOURCE_DIR}/Service
 ${CMAKE_CURRENT_SOURCE_DIR}/slip
+${ROOT_DIR}/open_source/openharmony/base/security/huks/interfaces/innerkits/huks_standard/main/include
+${ROOT_DIR}/open_source/openharmony/base/iothardware/peripheral/interfaces/inner_api
+${ROOT_DIR}/open_source/openharmony/base/security/huks/frameworks/huks_standard/main/crypto_engine/mbedtls/include
+${ROOT_DIR}/open_source/openharmony/base/security/huks/frameworks/huks_standard/main/common/include
 )
 
 set(CAT1SERVICE_SOURCES
-${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_server_hal.c
+${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_signlib.c
 ${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_server.c
 ${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_tcpServer.c
 ${CMAKE_CURRENT_SOURCE_DIR}/Service/cat1_ctl.c
@@ -36,6 +40,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/slip/uart_slip.c
 # message(WARNING "lwipport_SRCS" ${lwipport_SRCS} "\n")
 # message(WARNING "PUBLIC_HEADER" ${PUBLIC_HEADER} "\n")
 # message(WARNING "LWIP_PORT_HEADER" ${LWIP_PORT_HEADER} "\n")
+
 set(SOURCES
     ${lwipcore_SRCS}
     ${lwipcore4_SRCS}
@@ -43,7 +48,7 @@ set(SOURCES
     ${lwipnetif_SRCS}
     ${lwipcore6_SRCS}
     ${lwipport_SRCS}
-    ${lwiptest_SRCS}
+    # ${lwiptest_SRCS}
     ${lwipsntp_SRCS}
     ${lwipmbedtls_SRCS}
     ${lwipsmtp_SRCS}
index e2c9dda..614a59b 100644 (file)
@@ -9,7 +9,7 @@
 #include "tcxo.h"
 #include "voice_call_volte_sample_wrapper.h"
 #include "los_base.h"
-#include "wearable_log.h"
+#include "cat1_log.h"
 #include "cat1_utils.h"
 
 
 //     { "seaenable", VoiceCAllSeaEnable }, VoiceCallVolteSample(2,(char *[]){"seaenable","100"})
 //     { "mute", VoiceCallMicMute },
 // };
+
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
 #include "pm.h"
 #include "pm_veto.h"
-uint32_t uapi_cat1_bat_on(uint32_t pwron)
+
+static ctl_pin_4g_t g_cat1_ctl_pins={
+    #if defined(BOARD_FD230)
+    PIN_NONE, //bat_pin
+    1,
+    S_AGPIO_L23, // pwr_pin
+    1,
+    S_AGPIO_L28,//reset_pin
+    0,
+    S_AGPIO_L31,//ring_pin
+    1,
+    S_AGPIO_L30,//wakemodem_pin
+    1,
+    #elif defined(BOARD_L22)
+    S_AGPIO_L14, //bat_pin
+    1,
+    S_AGPIO_L23, // pwr_pin
+    1,
+    PIN_NONE,//reset_pin
+    0,
+    S_AGPIO_L31,//ring_pin
+    1,
+    S_AGPIO_L30,//wakemodem_pin
+    1,
+    #elif defined(BOARD_W9)
+    S_AGPIO_L17, //bat_pin
+    1,
+    S_AGPIO_L23, // pwr_pin
+    1,
+    PIN_NONE,//reset_pin
+    0,
+    S_AGPIO_L31,//ring_pin
+    1,
+    S_AGPIO_L30,//wakemodem_pin
+    1,
+    #else
+    PIN_NONE, //bat_pin
+    1,
+    S_AGPIO_L23, // pwr_pin
+    1,
+    S_AGPIO_L28,//reset_pin
+    0,
+    S_AGPIO_L31,//ring_pin
+    1,
+    S_AGPIO_L30,//wakemodem_pin
+    1,
+    #endif
+};
+
+
+/**
+ * @brief 注册控制4G的gpio值,包括控制电源以及唤醒中断的IO
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_register_ctl_pin(ctl_pin_4g_t ctl_pin)
 {
+    g_cat1_ctl_pins.bat_pin = ctl_pin.bat_pin;
+    g_cat1_ctl_pins.bat_pin_en_value = ctl_pin.bat_pin_en_value;
+    g_cat1_ctl_pins.pwr_pin = ctl_pin.pwr_pin;
+    g_cat1_ctl_pins.pwr_pin_en_value = ctl_pin.pwr_pin_en_value;
+    g_cat1_ctl_pins.reset_pin = ctl_pin.reset_pin;
+    g_cat1_ctl_pins.reset_pin_en_value = ctl_pin.reset_pin_en_value;
+    g_cat1_ctl_pins.ring_pin = ctl_pin.ring_pin;
+    g_cat1_ctl_pins.ring_pin_en_value = ctl_pin.ring_pin_en_value;
+    g_cat1_ctl_pins.wakemodem_pin = ctl_pin.wakemodem_pin;
+    g_cat1_ctl_pins.wakemodem_pin_en_value = ctl_pin.wakemodem_pin_en_value;
+    return ERRCODE_SUCC;
+}
 
-#if defined(BOARD_L22)
-    pin_t bat_en_pin =  S_AGPIO_L14;
-#elif defined(BOARD_W9)
-    pin_t bat_en_pin =  S_AGPIO_L17;
+uint32_t cat1_api_cat1_bat_on(uint32_t pwron)
+{
+    pin_t en_pin =  g_cat1_ctl_pins.bat_pin;
+    uint8_t en_value = g_cat1_ctl_pins.bat_pin_en_value;
+
+    if (en_pin == PIN_NONE)   return 0xff;
 
     if( pwron == 0)
     {
-        uapi_gpio_set_dir(bat_en_pin, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(bat_en_pin, GPIO_LEVEL_LOW);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"BAT OFF Cat1! %d low  \r\n",bat_en_pin);
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Cat1 BAT Off! pin %d value low  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Cat1 BAT Off! pin %d value high  \r\n",en_pin);
+        }
     }else{
-        uapi_gpio_set_dir(bat_en_pin, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(bat_en_pin, GPIO_LEVEL_HIGH);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"BAT ON Cat1! %d high \r\n",bat_en_pin);
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Cat1 BAT On! pin %d value high  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Cat1 BAT On! pin %d value low  \r\n",en_pin);
+        }
     }
-#endif
-    
     return 0;
 }
-uint32_t uapi_cat1_power_on(uint32_t pwron)
+uint32_t cat1_api_cat1_power_on(uint32_t pwron)
 {
 
-    pin_t bat_en_pin =  S_AGPIO_L23;
+    pin_t en_pin =  g_cat1_ctl_pins.pwr_pin;
+    uint8_t en_value = g_cat1_ctl_pins.pwr_pin_en_value;
+    if (en_pin == PIN_NONE)   return 0xff;
     if( pwron == 0)
     {
-        uapi_gpio_set_dir(bat_en_pin, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(bat_en_pin, GPIO_LEVEL_LOW);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Power Cat1! %d low  \r\n",bat_en_pin);
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Power Cat1 Off! pin %d value low  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Power Cat1 Off! pin %d value high  \r\n",en_pin);
+        }
     }else{
-        uapi_gpio_set_dir(bat_en_pin, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(bat_en_pin, GPIO_LEVEL_HIGH);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Power Cat1! %d high \r\n",bat_en_pin);
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Power Cat1 On! pin %d value high  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Power Cat1 On! pin %d value low  \r\n",en_pin);
+        }
     }
-    
     return 0;
 }
-uint32_t uapi_cat1_reset(uint32_t pwron)
+uint32_t cat1_api_cat1_reset(uint32_t pwron)
 {
 
-#if defined(BOARD_FD230)
+    pin_t en_pin =  g_cat1_ctl_pins.reset_pin;
+    uint8_t en_value = g_cat1_ctl_pins.reset_pin_en_value;
+
+    if (en_pin == PIN_NONE)   return 0xff;
+
     if( pwron == 0)
     {
-        uapi_gpio_set_dir(S_AGPIO_L28, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L28, GPIO_LEVEL_HIGH);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"clear reset Cat1! L28 high \r\n");
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Cat1 reset Off! pin %d value low  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Cat1 reset Off! pin %d value high  \r\n",en_pin);
+        }
     }else{
-        uapi_gpio_set_dir(S_AGPIO_L28, GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L28, GPIO_LEVEL_LOW); 
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Reset Cat1! L28 low\r\n");
+        uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
+        if (en_value)   
+        {
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+            cat1_print_dbg("Cat1 reset On! pin %d value high  \r\n",en_pin);
+        }else{
+            uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            cat1_print_dbg("Cat1 reset On! pin %d value low  \r\n",en_pin);
+        }
     }
-#endif
     return 0;
 }
 
-bool uapi_cat1_get_power_stat(void)
-{
-#if defined(BOARD_FD230)
-   return (  GPIO_LEVEL_HIGH == uapi_gpio_get_output_val(S_AGPIO_L23));
-#elif defined(BOARD_L22) || defined(BOARD_W9)
-   return (  GPIO_LEVEL_HIGH == uapi_gpio_get_output_val(S_AGPIO_L14));
-#endif
-
-}
-
-static uint8_t cat1_voice=0;
-
-uint8_t volte_voice_state(void)
-{
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"volte_voice_state %d \n",cat1_voice);
-    return cat1_voice;
-}
-
-int32_t uapi_cat1_start_volte_voice(void)
+bool cat1_api_is_cat1_enabled(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_cat1_start_volte_voice\n");
 
-    int32_t ret = ERRCODE_FAIL;
-    int32_t argc = 1;
-    uint8_t *argv = (uint8_t *)"start";
-
-    if(cat1_voice==0)
+    pin_t en_pin =  g_cat1_ctl_pins.pwr_pin;
+    uint8_t en_value = g_cat1_ctl_pins.pwr_pin_en_value;
+    if (en_pin == PIN_NONE)   return false;
+    if ( en_value == uapi_gpio_get_output_val(en_pin))
     {
-        ret = VoiceCallVolteSample(argc, (const char **)&argv);
-        if(ret==0) 
-        cat1_voice=1;
+        return true;
+    }else{
+        return false;
     }
-    
- 
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret %d %d ",ret, cat1_voice);
-    
-    return ret;   
 }
 
-
-int32_t uapi_cat1_start_SCO_volte_voice(void)
+void power_on_cat1(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_cat1_start_SCO_volte_voice\n");
-
-    int32_t ret = ERRCODE_FAIL;
-    int32_t argc = 1;
-    uint8_t *argv = (uint8_t *)"startSCO";
-
-    if(cat1_voice==0)
-    {
-        ret = VoiceCallVolteSample(argc, (const char **)&argv);
-        if(ret==0) 
-        cat1_voice=2;
-    }
-
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret %d %d ",ret, cat1_voice);
-
-    return ret;   
-
+    #ifdef BOARD_FD230
+    cat1_api_cat1_power_on(1);    
+    cat1_api_cat1_reset(0);
+    #else
+    cat1_api_cat1_reset(0);
+    cat1_api_cat1_power_on(1);  
+    cat1_api_cat1_bat_on(1);
+    osDelay(900);
+    cat1_api_cat1_power_on(0);  
+    #endif
+ 
 }
 
-
-
-
-int32_t uapi_cat1_stop_volte_voice(void)
+void power_off_cat1(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_cat1_stop_volte_voice\n");
-
-    int32_t ret = ERRCODE_FAIL;
-    int32_t argc = 1;
-    uint8_t *argv = (uint8_t *)"stop";
-
-    if(cat1_voice!=0)
-    {
-        ret = VoiceCallVolteSample(argc, (const char **)&argv);
-        if(ret==0) 
-        cat1_voice=0;
-    }
-
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret %d %d ",ret, cat1_voice);
-
-    return ret;   
-
+    #ifdef BOARD_FD230
+    cat1_api_cat1_reset(1);
+    cat1_api_cat1_power_on(0); 
+    #else
+    cat1_api_cat1_bat_on(0);
+    cat1_api_cat1_reset(1);
+    cat1_api_cat1_power_on(1); 
+    #endif
 }
 
 
 extern void restart_sleep_cat1_timer(void);
 void cat1_ring_isr_callback(pin_t pin, uintptr_t param)
 {
-    // WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1_ring_isr_callback %d 0x%X\n",pin,param);
+    // cat1_print_warning("cat1_ring_isr_callback %d 0x%X\n",pin,param);
     uapi_gpio_clear_interrupt(pin);
     // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_ADD_CAT1VOTE,NULL,0);
-
-    #ifdef SUPPORT_CAT1_SERVICE
-        uapi_cat1_add_cat1_vote();
-    #endif
+    cat1_api_add_cat1_vote();
     //中断会在此添加休眠投票,在收到cat1的消息后,会移除投票进入休眠。
     //之前的5秒后移除投票延迟太久,与5秒更新一次信号强度
     #ifdef USE_CAT1_SLEEP_TIMER
@@ -190,84 +251,106 @@ void cat1_ring_isr_callback(pin_t pin, uintptr_t param)
 
 static uint8_t cat1_keepon_wakeup = 0;
 extern void set_skip_cat1_service_udp_transfer(uint8_t skip);
-void uapi_cat1_keep_wakeup(uint8_t keep_wakeup)
+void cat1_api_keep_wakeup(uint8_t keep_wakeup)
 {
     cat1_keepon_wakeup = keep_wakeup;
     set_skip_cat1_service_udp_transfer(keep_wakeup);
-    uapi_cat1_wakeup_cat1(cat1_keepon_wakeup);
+    cat1_api_wakeup_cat1(cat1_keepon_wakeup);
 }
-void uapi_cat1_wakeup_cat1(uint8_t wakeup)
+void cat1_api_wakeup_cat1(uint8_t wakeup)
 {
+    pin_t en_pin =  g_cat1_ctl_pins.wakemodem_pin;
+    uint8_t en_value = g_cat1_ctl_pins.wakemodem_pin_en_value;
     uint8_t wake=wakeup;
+    if (en_pin == PIN_NONE)   return ;
+
     if (cat1_keepon_wakeup == 1)
     {
         wake = 1;
     }
+    uapi_gpio_set_dir(en_pin, GPIO_DIRECTION_OUTPUT);
     if( wake == 1)
     {
-        // WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"wakeup cat1\n");
-        uapi_gpio_set_dir(S_AGPIO_L30, GPIO_DIRECTION_OUTPUT);
-        if(GPIO_LEVEL_HIGH != uapi_gpio_get_output_val(S_AGPIO_L30))
+        // cat1_print_warning("wakeup cat1\n");
+        if(en_value != uapi_gpio_get_output_val(en_pin))
         {
-            uapi_gpio_set_val(S_AGPIO_L30, GPIO_LEVEL_HIGH);
+            uapi_gpio_set_val(en_pin, en_value);
             LOS_Mdelay(100); //第一次唤醒 Cat1 需要延时等其正常运行
         }
        
-        // wstp_WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"wakeup Cat1! L30 high \r\n");
+        // wstp_cat1_print_dbg("wakeup Cat1! L30 high \r\n");
     }else{
-        // WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"sleep cat1\n");
-        uapi_gpio_set_dir(S_AGPIO_L30, GPIO_DIRECTION_OUTPUT);
-        if(GPIO_LEVEL_LOW != uapi_gpio_get_output_val(S_AGPIO_L30))
+        // cat1_print_warning("sleep cat1\n");
+        if(en_value == uapi_gpio_get_output_val(en_pin))
         {
-            uapi_gpio_set_val(S_AGPIO_L30, GPIO_LEVEL_LOW);
-        }
-        // wstp_WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sleep Cat1! L30 low\r\n");
+            if(en_value)
+                uapi_gpio_set_val(en_pin, GPIO_LEVEL_LOW);
+            else
+                uapi_gpio_set_val(en_pin, GPIO_LEVEL_HIGH);
+        }   
+        // wstp_cat1_print_dbg("sleep Cat1! L30 low\r\n");
     }
     
 }
 
-void uapi_cat1_pre_init(void)
+void cat1_suspend(void)
 {
-    char *argv[]={"setvolume","90"};
-    VoiceCallVolteSample(2,(const char**)argv); 
+
+    cat1_print_dbg("cat1_suspend\n");
+    
 }
 
 
-void uapi_cat1_suspend(void)
+void cat1_resume(void)
 {
+    cat1_print_dbg("cat1_resume\n");
 
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_cat1_suspend\n");
-
-    // //关闭唤醒对方
-    // uapi_cat1_wakeup_cat1(0);
+}
 
-    // //关闭Uart
 
-    // //中断唤醒你对方
-    // // uapi_gpio_set_dir(S_AGPIO_L30, GPIO_DIRECTION_OUTPUT);
-    // // uapi_gpio_set_val(S_AGPIO_L30, GPIO_LEVEL_LOW);
+void cat1_api_gpio_init(void)
+{
 
-    // //pcm 休眠设置为0 
-    // uapi_pin_set_mode(S_AGPIO_L1, (pin_mode_t)HAL_PIO_FUNC_GPIO);
-    // uapi_gpio_set_dir(S_AGPIO_L1, GPIO_DIRECTION_OUTPUT);
-    // uapi_gpio_set_val(S_AGPIO_L1, GPIO_LEVEL_LOW);
-    // uapi_pin_set_mode(S_AGPIO_L2, (pin_mode_t)HAL_PIO_FUNC_GPIO);
-    // uapi_gpio_set_dir(S_AGPIO_L2, GPIO_DIRECTION_OUTPUT);
-    // uapi_gpio_set_val(S_AGPIO_L2, GPIO_LEVEL_LOW);
-    // uapi_pin_set_mode(S_AGPIO_L3, (pin_mode_t)HAL_PIO_FUNC_GPIO);
-    // uapi_gpio_set_dir(S_AGPIO_L3, GPIO_DIRECTION_OUTPUT);
-    // uapi_gpio_set_val(S_AGPIO_L3, GPIO_LEVEL_LOW);
-    // uapi_pin_set_mode(S_AGPIO_L4, (pin_mode_t)HAL_PIO_FUNC_GPIO);
-    // uapi_gpio_set_dir(S_AGPIO_L4, GPIO_DIRECTION_OUTPUT);
-    // uapi_gpio_set_val(S_AGPIO_L4, GPIO_LEVEL_LOW);
+    pin_t gpiopin=g_cat1_ctl_pins.bat_pin;
+    if (gpiopin!=NULL)
+    {
+        uapi_pin_set_mode(gpiopin, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+        uapi_gpio_set_dir(gpiopin,GPIO_DIRECTION_OUTPUT);
+    }
+    gpiopin=g_cat1_ctl_pins.pwr_pin;
+    if (gpiopin!=NULL)
+    {
+        uapi_pin_set_mode(gpiopin, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+        uapi_gpio_set_dir(gpiopin,GPIO_DIRECTION_OUTPUT);
+    }
+    gpiopin=g_cat1_ctl_pins.reset_pin;
+    if (gpiopin!=NULL)
+    {
+        uapi_pin_set_mode(gpiopin, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+        uapi_gpio_set_dir(gpiopin,GPIO_DIRECTION_OUTPUT);
+    }
+    gpiopin=g_cat1_ctl_pins.wakemodem_pin;
+    if (gpiopin!=NULL)
+    {
+        uapi_pin_set_mode(gpiopin, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+        uapi_gpio_set_dir(gpiopin,GPIO_DIRECTION_OUTPUT);
+    }
 
-    
+    gpiopin=g_cat1_ctl_pins.ring_pin;
+    if (gpiopin!=NULL)
+    {
+        uapi_pin_set_mode(gpiopin, (pin_mode_t)HAL_PIO_FUNC_GPIO);
+        uapi_gpio_set_dir(gpiopin,GPIO_DIRECTION_INPUT);
+        if (g_cat1_ctl_pins.ring_pin_en_value)
+            uapi_gpio_register_isr_func(gpiopin, GPIO_INTERRUPT_RISING_EDGE,  cat1_ring_isr_callback );
+        else
+            uapi_gpio_register_isr_func(gpiopin, GPIO_INTERRUPT_FALLING_EDGE,  cat1_ring_isr_callback );
+    }
 }
 
 
-void uapi_cat1_resume(void)
+void cat1_api_uart_init(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_cat1_resume\n");
 
 }
 
index 9835b16..c458fd8 100644 (file)
@@ -3,25 +3,6 @@
 #include <stdint.h>
 
 
-
-typedef struct 
-{
-    uint8_t bt_powerOn;
-    uint8_t bt_ble_connectstat;
-    uint8_t bt_br_connectstat;
-    uint8_t bt_earphone_connectstat;
-    uint8_t android_app_connected;
-    uint16_t ble_kumi_service_handler;
-    uint16_t ble_factory_service_handler;
-    uint16_t ble_alipay_service_handler;
-    uint16_t ble_hrs_service_handler;
-    uint16_t ble_hid_service_handler;
-    uint16_t ble_ancs_client_id;
-    uint16_t ad2p_service_handler;
-    uint16_t spp_service_handler;
-    uint16_t hfp_service_handler;
-
-}bt_runtime_status_t;
 /**
  * cat1_powerOn 0,1
  * volte volte开关
@@ -48,604 +29,104 @@ typedef struct
     char modemVer[64] ;
 }cat1_runtime_status_t;
 
-/**
- * 设备实时状态记录
- * in_silent_mode 勿扰模式  1 勿扰模式, 0 正常模式
- * in_lowpower_mode 低电模式  1 低电模式, 0 正常模式
- * stepcount 步数
- * bt_powerOn 蓝牙开关 1 开 , 0 关
- * bt_ble_connectstat 设备已连接手机 1连接, 0 未连接
- * bt_br_connectstat 经典蓝牙连接状态 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp
- * bt_earphone_connectstat 连接耳机状态 1连接, 0 未连接
- * android_app_connected , 0 not connected, 1 android connected
- * cat1_runtime  cat1实时状态,详见 cat1_runtime_status_t 定义
- * */
-typedef struct 
-{
-    uint8_t enter_safemode;
-    uint8_t in_silent_mode;
-    uint8_t in_lowpower_mode;
-    uint8_t stepcount;
-    uint8_t vibmod;
-    bt_runtime_status_t bt_runtime;
-    cat1_runtime_status_t cat1_runtime;
-    char current_dial_name[32];
-    uint8_t time_hour_show_model;
-    uint8_t sleep_monitoring_status;//睡眠监测
-    uint8_t sleep_status;//睡眠状态
-    uint8_t nap_status;//小睡状态
-    uint8_t nap_monitoring_status;//小睡监测
-    uint8_t sedentary_status;
-    uint8_t drinkremind_status;
-    uint8_t train_status;//训练状态
-    uint8_t saveele_status;//省电模式状态
-    uint8_t lock_status;//密码锁状态
-    uint8_t motion_recognition_status;//运动识别开关状态
-    uint8_t sleep_mode_flag; // sleep mode flag
-    uint8_t absolute_static_state; // 绝对静止状态
-    uint8_t checkres_status;//校验文件状态
-    uint8_t repair_download_status;//升级下载状态
-    uint8_t hrs_passivity_status;//获取被动心率检测状态
-    uint8_t mmc_status; //是否为指南针页面
-    uint8_t is_factory_status;//是否恢复出厂
-    //读写锁
-    uint8_t rwlock_status;//手表状态(存储)
-    uint8_t lock_flag_training;//训练
-    uint8_t lock_flag_heartrate;//心率
-    uint8_t lock_flag_blood;//血氧
-    uint8_t lock_flag_sleep;//睡眠
-
-    uint8_t lock_flag_goal;//每日目标数据 5个数据一起锁
-
-    uint8_t respiratory_training_status; //呼吸训练开始状态
-    uint8_t heartrate_detect_status;//主动检测心率状态
-    uint8_t factory_test_status;//产测模式状态
-    uint8_t screen_always_on_status;//屏幕是否常亮状态
-    uint8_t wear_status;
-    uint8_t shutting_down_status;//是否处于关机状态
-    uint8_t transmitting_status;//是否处于ble传输状态
-
-    uint8_t atuoota_status;//是否处于自动ota状态
-} runtime_status_t;
-
-
-static runtime_status_t g_runtime={0};
-// runtime_status_t * get_device_runtime_status(void)
-// {
-//     return &g_runtime;
-// }
-
-void uapi_dev_runtime_atuoota_status_status(uint8_t data)
-{
-    g_runtime.atuoota_status=data;
-}
-
-
-uint8_t uapi_dev_runtime_get_atuoota_status(void)
-{
-    return g_runtime.atuoota_status;
-}
-
-void uapi_dev_runtime_set_transmitting_status(uint8_t data)
-{
-    g_runtime.transmitting_status=data;
-}
-
 
-uint8_t uapi_dev_runtime_get_transmitting_status(void)
-{
-    return g_runtime.transmitting_status;
-}
+static cat1_runtime_status_t g_runtime={0};
 
-void uapi_dev_runtime_set_cat1_powerstat(uint8_t cat1_powerOn)
+void cat1_api_runtime_set_cat1_powerstat(uint8_t cat1_powerOn)
 {
-    g_runtime.cat1_runtime.cat1_powerOn=cat1_powerOn;
+    g_runtime.cat1_powerOn=cat1_powerOn;
 }
-uint8_t uapi_dev_runtime_get_cat1_powerstat(void)
+uint8_t cat1_api_runtime_get_cat1_powerstat(void)
 {
-    return g_runtime.cat1_runtime.cat1_powerOn;
+    return g_runtime.cat1_powerOn;
 }
 
-void uapi_dev_runtime_set_cat1_networkstat(uint8_t network_on)
+void cat1_api_runtime_set_cat1_networkstat(uint8_t network_on)
 {
-    g_runtime.cat1_runtime.network_on=network_on;
+    g_runtime.network_on=network_on;
 }
 //获取网络开启状态
-uint8_t uapi_dev_runtime_get_cat1_networkstat(void)
+uint8_t cat1_api_runtime_get_cat1_networkstat(void)
 {
-    return g_runtime.cat1_runtime.network_on;
+    return g_runtime.network_on;
 }
 
 
-void uapi_dev_runtime_set_cat1_signal(int signal)
+void cat1_api_runtime_set_cat1_signal(int signal)
 {
-    g_runtime.cat1_runtime.signal=signal;
+    g_runtime.signal=signal;
 }
 //获取cat1信号强度
-int uapi_dev_runtime_get_cat1_signal(void)
+int cat1_api_runtime_get_cat1_signal(void)
 {
-    return g_runtime.cat1_runtime.signal;
+    return g_runtime.signal;
 }
 
-void uapi_dev_runtime_set_cat1_simstat(int simstat)
+void cat1_api_runtime_set_cat1_simstat(int simstat)
 {
-    g_runtime.cat1_runtime.sim=simstat;
+    g_runtime.sim=simstat;
 }
 //获取cat1的sim卡状态
-int uapi_dev_runtime_get_cat1_simstat(void)
+int cat1_api_runtime_get_cat1_simstat(void)
 {
-    return g_runtime.cat1_runtime.sim;
+    return g_runtime.sim;
 }
 
-void uapi_dev_runtime_set_cat1_networktype(uint8_t networtype)
+void cat1_api_runtime_set_cat1_networktype(uint8_t networtype)
 {
-    g_runtime.cat1_runtime.cat1_network_type=networtype;
+    g_runtime.cat1_network_type=networtype;
 }
 //获取网络类型
-uint8_t uapi_dev_runtime_get_cat1_networtype(void)
+uint8_t cat1_api_runtime_get_cat1_networktype(void)
 {
-    return g_runtime.cat1_runtime.cat1_network_type;
+    return g_runtime.cat1_network_type;
 }
 
 
-void uapi_dev_runtime_set_cat1_operator(char* cat1_operator)
+void cat1_api_runtime_set_cat1_operator(char* cat1_operator)
 {
     if (cat1_operator == NULL) return;
     int len=strlen(cat1_operator);
-    memset_s(g_runtime.cat1_runtime.opera,sizeof(g_runtime.cat1_runtime.opera),0,sizeof(g_runtime.cat1_runtime.opera));
-    memcpy_s(g_runtime.cat1_runtime.opera,sizeof(g_runtime.cat1_runtime.opera),cat1_operator,len);
+    memset_s(g_runtime.opera,sizeof(g_runtime.opera),0,sizeof(g_runtime.opera));
+    memcpy_s(g_runtime.opera,sizeof(g_runtime.opera),cat1_operator,len);
 }
-char* uapi_dev_runtime_get_cat1_operator(void)
+char* cat1_api_runtime_get_cat1_operator(void)
 {
-    return (char*)g_runtime.cat1_runtime.opera;
+    return (char*)g_runtime.opera;
 }    
 
-void uapi_dev_runtime_set_cat1_imei(char* imei)
+void cat1_api_runtime_set_cat1_imei(char* imei)
 {
     if (imei == NULL) return;
     int len=strlen(imei);
-    memset_s(g_runtime.cat1_runtime.imei,sizeof(g_runtime.cat1_runtime.imei),0,sizeof(g_runtime.cat1_runtime.imei));
-    memcpy_s(g_runtime.cat1_runtime.imei,sizeof(g_runtime.cat1_runtime.imei),imei,len);
+    memset_s(g_runtime.imei,sizeof(g_runtime.imei),0,sizeof(g_runtime.imei));
+    memcpy_s(g_runtime.imei,sizeof(g_runtime.imei),imei,len);
 }
-char* uapi_dev_runtime_get_cat1_imei(void)
+char* cat1_api_runtime_get_cat1_imei(void)
 {
-     return (char*)g_runtime.cat1_runtime.imei;
+     return (char*)g_runtime.imei;
 }
 
-void uapi_dev_runtime_set_cat1_pyver(char* pyver)
+void cat1_api_runtime_set_cat1_pyver(char* pyver)
 {
     if (pyver == NULL) return;
     int len=strlen(pyver);
-    memset_s(g_runtime.cat1_runtime.pyVer,sizeof(g_runtime.cat1_runtime.pyVer),0,sizeof(g_runtime.cat1_runtime.pyVer));
-    memcpy_s(g_runtime.cat1_runtime.pyVer,sizeof(g_runtime.cat1_runtime.pyVer),pyver,len);
+    memset_s(g_runtime.pyVer,sizeof(g_runtime.pyVer),0,sizeof(g_runtime.pyVer));
+    memcpy_s(g_runtime.pyVer,sizeof(g_runtime.pyVer),pyver,len);
 }
-char* uapi_dev_runtime_get_cat1_pyver(void)
+char* cat1_api_runtime_get_cat1_pyver(void)
 {
-     return (char*)g_runtime.cat1_runtime.pyVer;
+     return (char*)g_runtime.pyVer;
 }
 
-void uapi_dev_runtime_set_cat1_modemver(char* modemver)
+void cat1_api_runtime_set_cat1_modemver(char* modemver)
 {
     if (modemver == NULL) return;
     int len=strlen(modemver);
-    memset_s(g_runtime.cat1_runtime.modemVer,sizeof(g_runtime.cat1_runtime.modemVer),0,sizeof(g_runtime.cat1_runtime.modemVer));
-    memcpy_s(g_runtime.cat1_runtime.modemVer,sizeof(g_runtime.cat1_runtime.modemVer),modemver,len);
-}
-char* uapi_dev_runtime_get_cat1_modemver(void)
-{
-     return (char*)g_runtime.cat1_runtime.modemVer;
-}
-
-
-/**
- * 设置 dialname
-*/
-void uapi_dev_runtime_set_dialname(char* dialname)
-{
-
-    if (dialname == NULL) return;
-     //在runtime中备份一个安装文件名。
-    int dialnamelen=strlen((char*)dialname);
-    memset_s(g_runtime.current_dial_name,sizeof(g_runtime.current_dial_name),0,sizeof(g_runtime.current_dial_name));
-    memcpy_s(g_runtime.current_dial_name,sizeof(g_runtime.current_dial_name),dialname,dialnamelen);
-}
-/**
- * 获取 dialname
-*/
-char* uapi_dev_runtime_get_dialname(void)
-{
-    return (char*)&(g_runtime.current_dial_name[0]);
-}
-void uapi_dev_runtime_set_bt_powerstat(uint8_t stat)
-{
-    g_runtime.bt_runtime.bt_powerOn = stat;
-}
-void uapi_dev_runtime_set_ble_connect_stat(uint8_t  connect)
-{
-    g_runtime.bt_runtime.bt_ble_connectstat = connect;
-}
-void uapi_dev_runtime_set_br_connect_stat(uint8_t  connect)
-{
-    g_runtime.bt_runtime.bt_br_connectstat = connect;
-}
-void uapi_dev_runtime_set_earphone_connect_stat(uint8_t  connect)
-{
-    g_runtime.bt_runtime.bt_earphone_connectstat = connect;
-}
-
-
-
-uint8_t uapi_dev_runtime_get_bt_powerstat(void)
-{
-    return g_runtime.bt_runtime.bt_powerOn ;
-}
-uint8_t uapi_dev_runtime_get_ble_connect_stat(void)
-{
-    return g_runtime.bt_runtime.bt_ble_connectstat;
-}
-uint8_t uapi_dev_runtime_get_br_connect_stat(void)
-{
-    return g_runtime.bt_runtime.bt_br_connectstat ;
-}
-uint8_t uapi_dev_runtime_get_earphone_connect_stat(void)
-{
-    return g_runtime.bt_runtime.bt_earphone_connectstat ;
-}
-
-
-
-void uapi_dev_runtime_set_android_connection_status(uint8_t is_android)
-{
-    g_runtime.bt_runtime.android_app_connected = is_android;    
-}
-uint8_t uapi_dev_runtime_get_android_connection_status(void)
-{
-    return g_runtime.bt_runtime.android_app_connected;
-}
-
-uint8_t uapi_dev_runtime_get_time_hour_show_model(void)
-{
-    return g_runtime.time_hour_show_model;
-}
-void uapi_dev_runtime_set_time_hour_show_model(uint8_t hour_type)
-{
-    g_runtime.time_hour_show_model = hour_type;
-}
-//关机前,把runtime数据同步到config文件里
-void uapi_dev_runtime_sync_runtime_env_to_config(void)
-{
-    uint16_t timezone_quarters=uapi_get_timezone();
-    cm_set_timezone_quarters(timezone_quarters);
-    cm_set_hour_show_model(g_runtime.time_hour_show_model);
-}
-
-void uapi_dev_runtime_set_ancs_clientid(uint16_t clientid)
-{
-    g_runtime.bt_runtime.ble_ancs_client_id = clientid;
-}
-
-uint16_t uapi_dev_runtime_get_ancs_clientid(void)
-{
-    return g_runtime.bt_runtime.ble_ancs_client_id;
-}
-
-
-void uapi_dev_runtime_set_vibmod(uint8_t vibmod)
-{
-    g_runtime.vibmod=vibmod;
-}
-uint8_t uapi_dev_runtime_get_vibmod(void)
-{
-    return g_runtime.vibmod;
-}
-
-void uapi_dev_runtime_set_sleep_monitoring_status(uint8_t status)
-{
-    g_runtime.sleep_monitoring_status=status;
-}
-uint8_t uapi_dev_runtime_get_sleep_monitoring_status(void)
-{
-    return g_runtime.sleep_monitoring_status;
-}
-
-void uapi_dev_runtime_set_sleep_status(uint8_t status)
-{
-    g_runtime.sleep_status=status;
-}
-uint8_t uapi_dev_runtime_get_sleep_status(void)
-{
-    return g_runtime.sleep_status;
-}
-
-void uapi_dev_runtime_set_nap_status(uint8_t status)
-{
-    g_runtime.nap_status=status;
-}
-uint8_t uapi_dev_runtime_get_nap_status(void)
-{
-    return g_runtime.nap_status;
-}
-
-void uapi_dev_runtime_set_nap_monitoring_status(uint8_t status)
-{
-    g_runtime.nap_monitoring_status=status;
-}
-uint8_t uapi_dev_runtime_get_nap_monitoring_status(void)
-{
-    return g_runtime.nap_monitoring_status;
-}
-
-void uapi_dev_runtime_set_sedentary_status(uint8_t status)
-{
-    g_runtime.sedentary_status=status;
-}
-uint8_t uapi_dev_runtime_get_sedentary_status(void)
-{
-    return g_runtime.sedentary_status;
-}
-
-void uapi_dev_runtime_set_drinkremind_status(uint8_t status)
-{
-    g_runtime.drinkremind_status=status;
-}
-uint8_t uapi_dev_runtime_get_drinkremind_status(void)
-{
-    return g_runtime.drinkremind_status;
-}
-/*设置训练状态*/
-void uapi_dev_runtime_set_train_status(uint8_t status)
-{
-    g_runtime.train_status = status;
-}
-uint8_t uapi_dev_runtime_get_train_status(void)
-{
-    return g_runtime.train_status;
-}
-/*设置省电模式状态*/
-void uapi_dev_runtime_set_saveele_status(uint8_t status)
-{
-    g_runtime.saveele_status = status;
-}
-uint8_t uapi_dev_runtime_get_saveele_status(void)
-{
-    return g_runtime.saveele_status;
-}
-/*设置密码锁状态*/
-void uapi_dev_runtime_set_lock_status(uint8_t status)
-{
-    g_runtime.lock_status = status;
+    memset_s(g_runtime.modemVer,sizeof(g_runtime.modemVer),0,sizeof(g_runtime.modemVer));
+    memcpy_s(g_runtime.modemVer,sizeof(g_runtime.modemVer),modemver,len);
 }
-uint8_t uapi_dev_runtime_get_lock_status(void)
+char* cat1_api_runtime_get_cat1_modemver(void)
 {
-    return g_runtime.lock_status;
-}
-/*设置校验状态*/
-void uapi_dev_runtime_set_checkres_status(uint8_t status)
-{
-    g_runtime.checkres_status = status;
-}
-uint8_t uapi_dev_runtime_get_checkres_status(void)
-{
-    return g_runtime.checkres_status;
-}
-/*设置修复下载状态*/
-void uapi_dev_runtime_set_repair_download_status(uint8_t status)
-{
-    g_runtime.repair_download_status = status;
-}
-uint8_t uapi_dev_runtime_get_repair_download_status(void)
-{
-    return g_runtime.repair_download_status;
-}
-/*设置运动识别状态*/
-void uapi_dev_runtime_set_motion_recognition_status(uint8_t status)
-{
-    g_runtime.motion_recognition_status = status;
-}
-uint8_t uapi_dev_runtime_get_motion_recognition_status(void)
-{
-    return g_runtime.motion_recognition_status;
-}
-
-//设置呼吸训练状态
-void uapi_dev_runtime_set_respiratory_training_status(uint8_t status)
-{
-    g_runtime.respiratory_training_status = status;
-}
-uint8_t uapi_dev_runtime_get_respiratory_training_status(void)
-{
-    return g_runtime.respiratory_training_status;
-}
-
-//设置关机状态
-void uapi_dev_runtime_set_shutting_down_status(uint8_t status)
-{
-    g_runtime.shutting_down_status = status;
-}
-uint8_t uapi_dev_runtime_get_shutting_down_status(void)
-{
-    return g_runtime.shutting_down_status;
-}
-
-//设置是否常亮状态
-void uapi_dev_runtime_set_screen_always_on_status(uint8_t status)
-{
-    g_runtime.screen_always_on_status = status;
-}
-uint8_t uapi_dev_runtime_get_screen_always_on_status(void)
-{
-    return g_runtime.screen_always_on_status;
-}
-// sleep mode flag
-void uapi_sleep_mode_flag_set(uint8_t flag)
-{
-    g_runtime.sleep_mode_flag = flag;
-}
-
-uint8_t uapi_sleep_mode_flag_get(void)
-{
-    return g_runtime.sleep_mode_flag;
-}
-
-/*设置绝对静止状态*/
-void uapi_dev_runtime_set_absolute_static_status(uint8_t status)
-{
-    g_runtime.absolute_static_state = status;
-}
-
-uint8_t uapi_dev_runtime_get_absolute_static_status(void)
-{
-    return g_runtime.absolute_static_state;
-}
-
-
-// 安全模式
-void uapi_dev_runtime_set_safemode_flag(uint8_t status)
-{
-    g_runtime.enter_safemode = status;
-}
-// 安全模式
-uint8_t uapi_dev_runtime_get_safemode_flag(void)
-{
-    return g_runtime.enter_safemode;
-}
-
-//读写锁状态
-void uapi_dev_runtime_set_rwlock_status(uint8_t status)
-{
-    // 不能有set
-    // g_runtime.rwlock_status = status;
-}
-uint8_t uapi_dev_runtime_get_rwlock_status(void)
-{
-    //读写状态取决与所有的模块存储状态
-    g_runtime.rwlock_status = 0;
-    if(g_runtime.lock_flag_training)
-    {
-        //运动存储
-        g_runtime.rwlock_status = 1;
-    }
-    if(g_runtime.lock_flag_heartrate)
-    {
-        //心率存储
-        g_runtime.rwlock_status = 1;
-    }
-    if(g_runtime.lock_flag_blood)
-    {
-        //血氧存储
-        g_runtime.rwlock_status = 1;
-    }
-    if(g_runtime.lock_flag_sleep)
-    {
-        //睡眠存储
-        g_runtime.rwlock_status = 1;
-    }
-    return g_runtime.rwlock_status;
-}
-//设置运动存储
-void uapi_dev_runtime_set_train_storage_status(uint8_t status)
-{
-    g_runtime.lock_flag_training = status;
-}
-uint8_t uapi_dev_runtime_get_train_storage_status(void)
-{
-    return g_runtime.lock_flag_training;
-}
-//设置心率存储
-void uapi_dev_runtime_set_heartrate_storage_status(uint8_t status)
-{
-    g_runtime.lock_flag_heartrate = status;
-}
-uint8_t uapi_dev_runtime_get_heartrate_storage_status(void)
-{
-    return g_runtime.lock_flag_heartrate;
-}
-//设置血氧存储
-void uapi_dev_runtime_set_bloodoxygen_storage_status(uint8_t status)
-{
-    g_runtime.lock_flag_blood = status;
-}
-uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void)
-{
-    return g_runtime.lock_flag_blood;
-}
-//设置睡眠存储
-void uapi_dev_runtime_set_sleep_storage_status(uint8_t status)
-{
-    g_runtime.lock_flag_sleep = status;
-}
-uint8_t uapi_dev_runtime_get_sleep_storage_status(void)
-{
-    return g_runtime.lock_flag_sleep;
-}
-
-//设置目标数据存储
-void uapi_dev_runtime_set_goal_storage_status(uint8_t status)
-{
-    g_runtime.lock_flag_goal = status;
-}
-uint8_t uapi_dev_runtime_get_goal_storage_status(void)
-{
-    return g_runtime.lock_flag_goal;
-}
-//后续还需要补充。。。
-
-// 设置被动心率检测状态
-void uapi_dev_runtime_set_hrs_passivity(uint8_t status)
-{
-    g_runtime.hrs_passivity_status = status;
-}
-// 获取被动心率检测状态
-uint8_t uapi_dev_runtime_get_hrs_passivity_flag(void)
-{
-    return g_runtime.hrs_passivity_status;
-}
-//设置主动心率检测状态
-void uapi_dev_runtime_set_heartrate_detect_status(uint8_t status)
-{
-    g_runtime.heartrate_detect_status = status;
-}
-uint8_t uapi_dev_runtime_get_heartrate_detect_status(void)
-{
-    return g_runtime.heartrate_detect_status;
-}
-// 设置是否为指南针页面状态
-void uapi_dev_runtime_set_mmc_status(uint8_t status)
-{
-    g_runtime.mmc_status = status;
-}
-// 获取指南针页面状态
-uint8_t uapi_dev_runtime_get_mmc_status_flag(void)
-{
-    return g_runtime.mmc_status;
-}
-
-// 设置是否为产测模式
-void uapi_dev_runtime_set_factory_test_status(uint8_t status)
-{
-    g_runtime.factory_test_status = status;
-}
-// 获取是否为产测模式
-uint8_t uapi_dev_runtime_get_factory_test_status_flag(void)
-{
-    return g_runtime.factory_test_status;
-}
-
-// 设置是否为佩戴状态
-void uapi_dev_runtime_set_wear_status(uint8_t status)
-{
-    g_runtime.wear_status = status;
-}
-// 获取是否为佩戴状态
-uint8_t uapi_dev_runtime_get_wear_status_flag(void)
-{
-    return g_runtime.wear_status;
-}
-// 设置是否为恢复出厂
-void uapi_dev_runtime_set_restore_factory_status(uint8_t status) {
-  g_runtime.is_factory_status = status;
-}
-// 获取是否为恢复出厂
-uint8_t uapi_dev_runtime_get_restore_factory_status(void) {
-  return g_runtime.is_factory_status;
+     return (char*)g_runtime.modemVer;
 }
index 733d8f6..aad1ca8 100644 (file)
 #include <string.h>
 
 
-#include "wearable_log.h"
+#include "cat1_log.h"
 #include "cat1_runtime.h"
 
 #include "lwip/apps/sntp.h"
 // #include "graphic_service.h"
 #include "cat1_tcpServer.h"
+
+
+#include "cat1_pub_api.h"
+
 #ifdef __cplusplus
 
 extern "C" {
@@ -50,7 +54,7 @@ extern "C" {
 #include "cmsis_os.h"
 
 static uint8_t g_skip_cat1_service_udp_transfer = 0;
-
+static f_cat1_msg_callback g_cat1_msg_callback_func=NULL;
 #define PEER_IP "172.16.1.2"
 #define PEER_PORT 5000
 #define SERVER_IP "172.16.1.5"
@@ -109,6 +113,20 @@ void ble_get_cat1_at_msg(char *buffer,uint8_t len)
     memcpy_s(buffer,len,ble_buffer,strlen(ble_buffer));
 }
 
+
+
+static f_cat1_msg_callback g_msg_callback_func=NULL;
+/**
+ * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+ * */
+errcode_t cat1_register_msg_callback(f_cat1_msg_callback func)
+{
+    g_msg_callback_func=func;
+    return ERRCODE_SUCC;
+}
+
+
 static uint8_t get_int8_from_ascii_char( uint8_t ascii)
 {
 
@@ -363,28 +381,28 @@ static void udp_send_response(char *tx_buffer, uint8_t cmd, char *content)
     if( len > 0 ) {
         err = sendto(g_listen_sock, tx_buffer, len, 0, (struct sockaddr *)&sourceAddr, sizeof(sourceAddr));
         if (err < 0) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error occured during sending: errno %d\n", errno);
+            cat1_print_err("Error occured during sending: errno %d\n", errno);
                }
     } else {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error occured unkown send data\n");
+        cat1_print_err("Error occured unkown send data\n");
     }
 }
 #include "uart_porting.h"
 void udp_send_msg_toCat1(uint8_t cmd,char *content)
 {
 
-    if (!uapi_cat1_get_power_stat())
+    if (!cat1_api_is_cat1_enabled())
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error cat1 poweroff skipp send data\n");
+        cat1_print_warning("Error cat1 poweroff skipp send data\n");
         return ;
     }
-    uapi_cat1_wakeup_cat1(1);
+    cat1_api_wakeup_cat1(1);
     // uart_port_register_irq(UART_BUS_0);
     osal_irq_enable(UART_1_IRQN);
 
     if (g_skip_cat1_service_udp_transfer == 1)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP," g_skip_cat1_service_udp_transfer \n");
+        cat1_print_warning(" g_skip_cat1_service_udp_transfer \n");
         return ;
     }
     char station_tx_buffer[MAX_TCP_MSG_BUFFER_LEN] = {0};
@@ -394,7 +412,7 @@ void udp_send_msg_toCat1(uint8_t cmd,char *content)
 
      
     }
-     uapi_cat1_wakeup_cat1(0);
+     cat1_api_wakeup_cat1(0);
 }
 
 #define BOOTMSG_HEADER_STR "BOOTUP"
@@ -416,7 +434,7 @@ static int decodeSMS(char* msg)
     int msglen = strlen(msg)+1;
     if (msglen < 25)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"sms msg len is too short !\r\n");
+        cat1_print_err("sms msg len is too short !\r\n");
         return  -1;
     }
 
@@ -437,23 +455,23 @@ static int decodeSMS(char* msg)
         if((strlen(s)> 4) && (strncmp(s,"ref:",4) == 0) )
         {
             char* ptmp=s+4;
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ref  %s\r\n",ptmp);
+            cat1_print_dbg("ref  %s\r\n",ptmp);
             ref=atoi(ptmp);
         }else if ((strlen(s)> 10) && (strncmp(s,"total_num:",10) == 0) )
         {
 
             char* ptmp=s+10;
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"total_num  %s\r\n",ptmp);
+            cat1_print_dbg("total_num  %s\r\n",ptmp);
             num=atoi(ptmp);
         }else if ((strlen(s)> 4) && (strncmp(s,"seq:",4) == 0) )
         {
             char* ptmp=s+4;
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"seq  %s\r\n",ptmp);
+            cat1_print_dbg("seq  %s\r\n",ptmp);
             seq=atoi(ptmp);
         }else if ((strlen(s)> 5) && (strncmp(s,"data:",5) == 0) )
         {
             char* ptmp=s+5;
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"data  %s\r\n",ptmp);
+            cat1_print_dbg("data  %s\r\n",ptmp);
             pdu_decode_example(ptmp,ref,num,seq);
         }
     }
@@ -471,20 +489,20 @@ static int decodeVersion(char* msg)
     
     if (strlen(msg) < 50)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"msg len is too short !\r\n");
+        cat1_print_err("msg len is too short !\r\n");
         return  -1;
     }
     char buf[200] = {0};
     if (strncmp(msg,BOOTMSG_HEADER_STR,BOOTMSG_HEADER_STR_LEN) ==0)
     {
         strcpy(buf,msg+BOOTMSG_HEADER_STR_LEN+1);
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"BOOTMSG =============\r\n");
+        // cat1_print_dbg("BOOTMSG =============\r\n");
 
     }
     else if (strncmp(msg,VERMSG_HEADER_STR,VERMSG_HEADER_STR_LEN) ==0)
     {
         strcpy(buf,msg);
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"version =============\r\n");
+        // cat1_print_dbg("version =============\r\n");
 
     }else{
         return -2;
@@ -502,12 +520,12 @@ static int decodeVersion(char* msg)
         if((strncmp(s,"pyVer",5) == 0) && (strlen(s)> 5))
         {
             char* ptmp=s+6;            
-            char* pyverstr = uapi_dev_runtime_get_cat1_pyver();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"pyVer %s to %s\r\n",pyverstr,ptmp);
+            char* pyverstr = cat1_api_runtime_get_cat1_pyver();
+            cat1_print_dbg("pyVer %s to %s\r\n",pyverstr,ptmp);
             if ( strcmp(pyverstr,ptmp)!=0 )
             {
                 update++;
-                uapi_dev_runtime_set_cat1_pyver(ptmp);
+                cat1_api_runtime_set_cat1_pyver(ptmp);
             }
             if (strncmp(ptmp,"PY_SRV_V",8)==0 && strlen(ptmp)>8)
             {
@@ -518,34 +536,34 @@ static int decodeVersion(char* msg)
         }else if ((strncmp(s,"modemVer",8) == 0) && (strlen(s)> 8))
         {
             char* ptmp=s+9;
-            char* modemverstr=uapi_dev_runtime_get_cat1_modemver();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"modemVer %s to %s\r\n",modemverstr,ptmp);
+            char* modemverstr=cat1_api_runtime_get_cat1_modemver();
+            cat1_print_dbg("modemVer %s to %s\r\n",modemverstr,ptmp);
             
             if (strcmp(modemverstr,ptmp) != 0)
             {
                 update++;
-                uapi_dev_runtime_set_cat1_modemver(ptmp);
+                cat1_api_runtime_set_cat1_modemver(ptmp);
             }
         } else if (strncmp(s,"PY_",3) == 0 )
         {
-            char* pyverstr = uapi_dev_runtime_get_cat1_pyver();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"pyVer %s to %s\r\n",pyverstr,s);
+            char* pyverstr = cat1_api_runtime_get_cat1_pyver();
+            cat1_print_dbg("pyVer %s to %s\r\n",pyverstr,s);
 
             if ( strcmp(pyverstr,s)!=0 )
             {
                 update++;
-                uapi_dev_runtime_set_cat1_pyver(s);
+                cat1_api_runtime_set_cat1_pyver(s);
             }
 
         }else if (strncmp(s,"EG810M",6) == 0 )
         {
             
-            char* modemverstr=uapi_dev_runtime_get_cat1_modemver();
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"modemVer %s to %s\r\n",modemverstr,s);     
+            char* modemverstr=cat1_api_runtime_get_cat1_modemver();
+            cat1_print_dbg("modemVer %s to %s\r\n",modemverstr,s);     
             if (strcmp(modemverstr,s) != 0)
             {
                 update++;
-                uapi_dev_runtime_set_cat1_modemver(s);
+                cat1_api_runtime_set_cat1_modemver(s);
             }
         }
     }
@@ -565,7 +583,7 @@ static int decodeNetStat(char* msg)
     int update = 0;
     if (strlen(msg) < 50)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"msg len is too short !\r\n");
+        cat1_print_dbg("msg len is too short !\r\n");
         return  -1;
     }
     char buf[200] = {0};
@@ -593,27 +611,27 @@ static int decodeNetStat(char* msg)
     char* ppbuf = NULL;
     for (s = strtok_r(buf,p,&pchStrTmpIn); s!=NULL;s=strtok_r(NULL,p,&pchStrTmpIn))
     {
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"%s\r\n",s );
+        // cat1_print_dbg("%s\r\n",s );
         if(strncmp(s,"imei:",5) == 0)
         {
             ppbuf = s+5;
-            char* imei = uapi_dev_runtime_get_cat1_imei();
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== imei %s to %s\r\n",imei,ppbuf);            
+            char* imei = cat1_api_runtime_get_cat1_imei();
+            cat1_print_dbg("=== imei %s to %s\r\n",imei,ppbuf);            
             if ( strcmp(imei,ppbuf)!=0 )
             {
                 update++;
-                uapi_dev_runtime_set_cat1_imei(ppbuf);
+                cat1_api_runtime_set_cat1_imei(ppbuf);
             }   
             continue;
         }else if(strncmp(s,"sim:",4) == 0)
         {
             ppbuf=s+4;
             int simstat = atoi(ppbuf);
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== sim = %d\r\n",simstat);
-            if ( uapi_dev_runtime_get_cat1_simstat() != simstat)
+            cat1_print_dbg("=== sim = %d\r\n",simstat);
+            if ( cat1_api_runtime_get_cat1_simstat() != simstat)
             {
                 update++;
-                uapi_dev_runtime_set_cat1_simstat(simstat);
+                cat1_api_runtime_set_cat1_simstat(simstat);
             }  
             continue;
         }else if(strncmp(s,"oper:",5) == 0)
@@ -625,12 +643,12 @@ static int decodeNetStat(char* msg)
                 ppbuf=s+5;
         
 
-            char* opera=uapi_dev_runtime_get_cat1_operator();
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== opera %s to %s\r\n",opera,ppbuf);
+            char* opera=cat1_api_runtime_get_cat1_operator();
+            cat1_print_dbg("=== opera %s to %s\r\n",opera,ppbuf);
             if ( strcmp(opera,ppbuf)!=0 )
             {
                 update++;
-                uapi_dev_runtime_set_cat1_operator(ppbuf);
+                cat1_api_runtime_set_cat1_operator(ppbuf);
             } 
 
             continue;
@@ -638,11 +656,11 @@ static int decodeNetStat(char* msg)
         {
             ppbuf=s+7;
             int signals = atoi(ppbuf);
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== signal = %d\r\n",signals);
-            if ( uapi_dev_runtime_get_cat1_signal() != signals)
+            cat1_print_dbg("=== signal = %d\r\n",signals);
+            if ( cat1_api_runtime_get_cat1_signal() != signals)
             {
                 update++;
-                uapi_dev_runtime_set_cat1_signal(signals);
+                cat1_api_runtime_set_cat1_signal(signals);
             }  
             continue;
         }  
@@ -688,24 +706,34 @@ static int decodeNetStat(char* msg)
     {
         int idx=0;
         pchStrTmpIn=NULL;
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"netstat %s\n",netstat);
+        // cat1_print_dbg("netstat %s\n",netstat);
         for (s = strtok_r(netstat,",",&pchStrTmpIn); s!=NULL;s=strtok_r(NULL,",",&pchStrTmpIn))
         {
-            // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"idx %d, value %s\n",idx,s);
+            // cat1_print_dbg("idx %d, value %s\n",idx,s);
             switch(idx)
             {
                 case 2:
                     {
                         int networkon = atoi(s) ;
-                        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== networkon = %d , %s \n",networkon,networkon==1?"connected":networkon==5?"roaming":"unkown");
+                        cat1_print_dbg("=== networkon = %d , %s \n",networkon,networkon==1?"connected":networkon==5?"roaming":"unkown");
                         switch(networkon)
                         {
                             case 1:
                             case 5:
-                                uapi_dev_runtime_set_cat1_networkstat(1);
+                                if (cat1_api_runtime_get_cat1_networkstat()==0)
+                                {
+                                    cat1_api_runtime_set_cat1_networkstat(1);
+                                    if (g_msg_callback_func!=NULL)
+                                        g_msg_callback_func(MESSAGE_4G_NETWORK_CONNECTED,NULL,0);
+                                }
                                 break;
                             default:
-                                uapi_dev_runtime_set_cat1_networkstat(0);
+                                if (cat1_api_runtime_get_cat1_networkstat()==1)
+                                {
+                                    cat1_api_runtime_set_cat1_networkstat(0);
+                                    if (g_msg_callback_func!=NULL)
+                                        g_msg_callback_func(MESSAGE_4G_NETWORK_DISCONNECTED,NULL,0);
+                                }
                                 break;
 
                         }
@@ -715,7 +743,7 @@ static int decodeNetStat(char* msg)
                 case 3:
                     {
                         int network_type  = atoi(s);
-                        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"=== network_type = %d , %s\n",network_type,
+                        cat1_print_dbg("=== network_type = %d , %s\n",network_type,
                         network_type==0?"GSM":network_type==1?"GSM COMPACT":network_type==2?"UTRAN":network_type==3?"GSM wEGPRS":network_type==4?"UTRAN wHSDPA":network_type==5?"UTRAN wHSUPA":network_type==6?"UTRAN wHSDPA HSUPA":network_type==7?"E_UTRAN":network_type==8?"UTRAN HSPAP":network_type==9?"E_UTRAN_CA":"NONE"
                         );
                         switch (network_type)
@@ -723,22 +751,22 @@ static int decodeNetStat(char* msg)
                             case 0:
                             case 1:
                             case 3:
-                                uapi_dev_runtime_set_cat1_networktype(1);
+                                cat1_api_runtime_set_cat1_networktype(1);
                                 break;
                             case 2:
                             case 4:
                             case 5:
                             case 6:
-                                uapi_dev_runtime_set_cat1_networktype(2);
+                                cat1_api_runtime_set_cat1_networktype(2);
                                 break;                            
                             case 7:
                             case 8:
-                                uapi_dev_runtime_set_cat1_networktype(4);
+                                cat1_api_runtime_set_cat1_networktype(4);
                                 break;   
                             case 9:                         
                             case 10:                                
                             default:
-                                uapi_dev_runtime_set_cat1_networktype(0);
+                                cat1_api_runtime_set_cat1_networktype(0);
                                 break;
                         }
                         
@@ -768,7 +796,7 @@ static int decodeNetStat(char* msg)
             if(read_size)
             {
                 PY_SRV_VER_CURRENT=atoi(read_buf);
-                printf("need_py_srv_ver_txt : %d\r\n",PY_SRV_VER_CURRENT);
+                cat1_print_dbg("need_py_srv_ver_txt : %d\r\n",PY_SRV_VER_CURRENT);
             }
             fclose(fp);
         }
@@ -781,10 +809,10 @@ static int decodeNetStat(char* msg)
         
         if (g_py_ver >= PY_SRV_VER_SUPORT_PY_OTA_MINI_VER &&  g_py_ver<PY_SRV_VER_CURRENT )
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"start cat1 python ota\n");
+            cat1_print_dbg("start cat1 python ota\n");
             Cat1_OTA(CAT1_TCP_START_OTA);
         }else{
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"current PyVer %d, mini pyVer %d , local pyVer %d,  skip cat1 python ota!\n",g_py_ver,PY_SRV_VER_SUPORT_PY_OTA_MINI_VER,PY_SRV_VER_CURRENT);
+            cat1_print_dbg("current PyVer %d, mini pyVer %d , local pyVer %d,  skip cat1 python ota!\n",g_py_ver,PY_SRV_VER_SUPORT_PY_OTA_MINI_VER,PY_SRV_VER_CURRENT);
         }
     }
     g_python_updated = 1;
@@ -837,7 +865,7 @@ void cat1_call_answer(void)
         if(osTimerIsRunning(g_timer_time_answer)==0  )
         {
             osStatus_t ret = osTimerStart(g_timer_time_answer,3000); 
-            WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_timer_time_answer timer ret %d\n",ret);
+            cat1_print_info("cat1 g_timer_time_answer timer ret %d\n",ret);
         }
     }
     // #endif
@@ -855,14 +883,14 @@ void cat1_call_dial(char* phonenum)
     // bool volte = OHOS::ConfigModel::GetInstance()->GetVoLTE_Call();
     bool volte = true;
     if (volte == true){
-         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"cat1_call_dial %s\n",phonenum);
+         cat1_print_info("cat1_call_dial %s\n",phonenum);
         // #if PY_SRV_VER_CURRENT >=16
         if(g_py_ver>=16)
         {
             if(osTimerIsRunning(g_timer_time_Dial)==0  )
             {
                 osStatus_t ret = osTimerStart(g_timer_time_Dial,5000); 
-                WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_timer_time_Dial timer ret %d\n",ret);
+                cat1_print_info("cat1 g_timer_time_Dial timer ret %d\n",ret);
             }
         }
           
@@ -885,7 +913,7 @@ void cat1_getsignal(void)
 }
 void cat1_gettime(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"UDP_CMD_GET_TIME\n");
+    cat1_print_dbg("UDP_CMD_GET_TIME\n");
     udp_send_msg_toCat1(UDP_CMD_GET_TIME,"0");
 }
 
@@ -909,7 +937,7 @@ void cat1_call_sms_send(char* phonenum,char* sms_txtdata)
 {
     if(phonenum==NULL||sms_txtdata==NULL)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 send sms param error!\n");
+        cat1_print_err("cat1 send sms param error!\n");
         return ;
     }
     int len_smstxt=strlen(phonenum)+strlen(sms_txtdata)+2;
@@ -941,26 +969,24 @@ int cat1_handle_call_incomming(char * msg)
 
     strncpy(phonenum,msg,phonenumlen-1);
     phonenum[phonenumlen-1]='\0';
-    WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 incomming call %s\n",phonenum);
-
-    incomingcall_event_sendmsg_toUI(phonenum);
-
+    cat1_print_info("cat1 incomming call %s\n",phonenum);
 
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_COMMING,phonenum,strlen(phonenum));
+            
     return 1;
 }
 
-void test_call_incomming(void)
-{
-    cat1_handle_call_incomming("10086");
-}
+
 
 int cat1_handle_networ_msg(char *msg)
 {
-    // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 cat1_handle_networ_msg %s\n",msg->buffer);
+    // cat1_print_info("cat1 cat1_handle_networ_msg %s\n",msg->buffer);
     if(decodeNetStat(msg) == 0)
     {        
-        // OHOS::ConfigModel::GetInstance()->Setimei(uapi_dev_runtime_get_cat1_imei());
-        cat1_msg_event_sendmsg_toUI("netupdate");
+        // OHOS::ConfigModel::GetInstance()->Setimei(cat1_api_runtime_get_cat1_imei());
+        if (g_msg_callback_func!=NULL)
+            g_msg_callback_func(MESSAGE_4G_NETWORK_STAT_CHANGED,NULL,0);
     }
     //显示UI 信号
     return 1;
@@ -969,7 +995,7 @@ int cat1_handle_networ_msg(char *msg)
 int cat1_handle_version_msg(char *msg)
 {
    
-    // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 cat1_handle_networ_msg %s\n",msg->buffer);
+    // cat1_print_info("cat1 cat1_handle_networ_msg %s\n",msg->buffer);
    
 
 // BOOTUP:pyVer,PY_SRV_V4,modemVer,EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312
@@ -979,9 +1005,12 @@ int cat1_handle_version_msg(char *msg)
     if(decodeVersion(msg) == 0)
     {
         
-        // OHOS::ConfigModel::GetInstance()->SetpyVer(uapi_dev_runtime_get_cat1_pyver());
-        // OHOS::ConfigModel::GetInstance()->SetmoderVer(uapi_dev_runtime_get_cat1_modemver());
-        cat1_msg_event_sendmsg_toUI("verupdate"); 
+        // OHOS::ConfigModel::GetInstance()->SetpyVer(cat1_api_runtime_get_cat1_pyver());
+        // OHOS::ConfigModel::GetInstance()->SetmoderVer(cat1_api_runtime_get_cat1_modemver());
+        // cat1_msg_event_sendmsg_toUI("verupdate"); 
+        if (g_msg_callback_func!=NULL)
+            g_msg_callback_func(MESSAGE_4G_VERSION_SYNCED,NULL,0);
+           
     }
     
     return 1;
@@ -991,7 +1020,7 @@ int cat1_handle_version_msg(char *msg)
 
 int cat1_handle_sms(char *msg)
 {
-    // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 cat1_handle_sms %s\n",smsmsg);
+    // cat1_print_info("cat1 cat1_handle_sms %s\n",smsmsg);
     if (decodeSMS(msg) ==0 )
     {
         //添加到消息列表里
@@ -1002,20 +1031,20 @@ int cat1_handle_sms(char *msg)
 int cat1_handle_timesync(char *timesync)
 {
    
-    // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 cat1_handle_timesync %s\n",timesync);
+    // cat1_print_info("cat1 cat1_handle_timesync %s\n",timesync);
 
     // ('24/03/01 07:15:36 8 0', 1709277336, 0)
     // "4294938528@(2106, 2, 7, 6, 28, 48, 6, 38)@8"
     //TODO:设置时间
     // if (g_time_synced == 0)
     {
-        if (uapi_set_time_from_cat1(timesync) == ERRCODE_SUCC)
+        if (cat1_set_time_from_cat1(timesync) == ERRCODE_SUCC)
         {
             g_time_synced = 1;
         }
     }
     
-    // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_time_synced %d\n",g_time_synced);
+    // cat1_print_info("cat1 g_time_synced %d\n",g_time_synced);
 
     return 1;
 }
@@ -1023,17 +1052,17 @@ int cat1_handle_timesync(char *timesync)
 #ifdef USE_CAT1_SLEEP_TIMER
 void mcu_remove_sleepvote_and_stoptimer(void)
 {
-    // uapi_cat1_wakeup_cat1(0);// 反馈给cat1,它也可以自己睡
+    // cat1_api_wakeup_cat1(0);// 反馈给cat1,它也可以自己睡
     if(osTimerIsRunning(g_timer_cat1_sleep)==1  )
     {
         osStatus_t ret = osTimerStop(g_timer_cat1_sleep);
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"osTimerStop  g_timer_cat1_sleep ret %d\n",ret);
+        // cat1_print_info("osTimerStop  g_timer_cat1_sleep ret %d\n",ret);
     }
-    uapi_cat1_remove_cat1_vote(); //接收到指令,让自己可以睡
+    cat1_api_remove_cat1_vote(); //接收到指令,让自己可以睡
 }
 static void timeout_handler_sleep_cat1(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"sleep mcu\n");
+    cat1_print_dbg("sleep mcu\n");
     // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE,NULL,0);
     mcu_remove_sleepvote_and_stoptimer();
 }
@@ -1043,54 +1072,72 @@ void restart_sleep_cat1_timer(void)
 {
     if (g_timer_cat1_sleep == NULL) 
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"g_timer_cat1_sleep is NULL \n");
+        cat1_print_err("g_timer_cat1_sleep is NULL \n");
         return ;
     }
     if(osTimerIsRunning(g_timer_cat1_sleep)==1  )
     {
         osStatus_t ret = osTimerStop(g_timer_cat1_sleep);
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"osTimerStop  g_timer_cat1_sleep ret %d\n",ret);
+        // cat1_print_info("osTimerStop  g_timer_cat1_sleep ret %d\n",ret);
     }
     if(osTimerIsRunning(g_timer_cat1_sleep)==0  )
     {
         // uint32_t tick = (uint32_t )osMs2Tick(5000); // 5 seconds  
         osStatus_t ret = osTimerStart(g_timer_cat1_sleep,5000); //5秒后重试同步时间
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"osTimerStart g_timer_cat1_sleep ret %d\n",ret);
+        // cat1_print_info("osTimerStart g_timer_cat1_sleep ret %d\n",ret);
     }
 }
 #endif
 
 static void time_sync_func(void)
 {
-    if(uapi_dev_runtime_get_saveele_status())
-    {
-        //省电模式直接返回
-        return;
-    }
-    // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"time_sync_func\n");
+    // if(cat1_api_runtime_get_saveele_status())
+    // {
+    //     //省电模式直接返回
+    //     return;
+    // }
+    // cat1_print_dbg("time_sync_func\n");
     
-    if (uapi_cat1_get_power_stat() == false )
+    if (cat1_api_is_cat1_enabled() == false )
     {
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"cat1 power off reset cat1_runtime \n");
+        // cat1_print_dbg("cat1 power off reset cat1_runtime \n");
         //开关是关的 则cat1所有状态清空
-        uapi_dev_runtime_set_cat1_powerstat(0);
-        uapi_dev_runtime_set_cat1_networkstat(0);
-        uapi_dev_runtime_set_cat1_signal(0);
-        uapi_dev_runtime_set_cat1_simstat(0);
-
+        if (cat1_api_runtime_get_cat1_powerstat()==1)
+        {
+            cat1_api_runtime_set_cat1_powerstat(0);
+            cat1_api_runtime_set_cat1_networkstat(0);
+            cat1_api_runtime_set_cat1_signal(0);
+            cat1_api_runtime_set_cat1_simstat(0);
+            cat1_api_runtime_set_cat1_networktype(0);
+            if (g_msg_callback_func!=NULL)
+            {
+                g_msg_callback_func(MESSAGE_4G_POWEROFF,NULL,0);
+                g_msg_callback_func(MESSAGE_4G_NETWORK_STAT_CHANGED,NULL,0);
+            }
+        }
+        if(osTimerIsRunning(g_timer_time_sync)==1 )
+        {
+            osStatus_t ret = osTimerStop(g_timer_time_sync);
+            cat1_print_info("cat1 powered off, stop timer  , ret %d\n",ret);
+        }
         return ;
     }else{
-        uapi_dev_runtime_set_cat1_powerstat(1);
-
+        if (cat1_api_runtime_get_cat1_powerstat()==0)
+        {
+            cat1_api_runtime_set_cat1_powerstat(1);           
+        }
+        
     }
 
+    
+
 #if USE_CAT1_CMD_SYNC_TIME
     
     if(osTimerIsRunning(g_timer_time_sync)==1 && g_time_synced == 1 )
     {
         // osStatus_t ret = osTimerStop(g_timer_time_sync);
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_time_synced == 1 stop timer  , ret %d\n",ret);
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_time_synced == 1 stop timer \n");
+        // cat1_print_info("cat1 g_time_synced == 1 stop timer  , ret %d\n",ret);
+        // cat1_print_info("cat1 g_time_synced == 1 stop timer \n");
         return ;
     }else{
         g_time_sync_retry_time ++;
@@ -1098,19 +1145,14 @@ static void time_sync_func(void)
     if( g_time_sync_retry_time >= MAX_TIME_SYNC_RETRY_TIME)
     {
         //  osStatus_t ret = osTimerStop(g_timer_time_sync);
-        //  WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_time_sync_retry_time >= %d stop timer ,ret %d\n",MAX_TIME_SYNC_RETRY_TIME,ret);
-        //  WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 g_time_sync_retry_time >= %d stop timer \n",MAX_TIME_SYNC_RETRY_TIME);
+        //  cat1_print_info("cat1 g_time_sync_retry_time >= %d stop timer ,ret %d\n",MAX_TIME_SYNC_RETRY_TIME,ret);
+        //  cat1_print_info("cat1 g_time_sync_retry_time >= %d stop timer \n",MAX_TIME_SYNC_RETRY_TIME);
         return ;
     }
     cat1_gettime();
 #endif
-
-    // if (uapi_get_screen_state() == 0)
-    // {
-         cat1_getsignal();
-    // }else{
-    //     // printf("Screen off skip get signal\n");
-    // }
+    if (cat1_api_need_update_signal())        
+        cat1_getsignal();
 }
 
 void restart_time_sync(void)
@@ -1120,10 +1162,10 @@ void restart_time_sync(void)
     g_time_sync_retry_time = 0;
     if(osTimerIsRunning(g_timer_time_sync)==0  )
     {
-        // WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 restart_time_sync timer \n");
+        // cat1_print_info("cat1 restart_time_sync timer \n");
         // uint32_t tick = (uint32_t )osMs2Tick(5000); // 60000: seconds of a minute
         osStatus_t ret = osTimerStart(g_timer_time_sync,5000); //5秒后重试同步时间
-        WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 restart_time_sync timer ret %d\n",ret);
+        cat1_print_info("cat1 restart_time_sync timer ret %d\n",ret);
     }
         
 }
@@ -1131,7 +1173,7 @@ void restart_time_sync(void)
 static void time_answer_func(void)
 {
     osTimerStop(g_timer_time_answer);
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"time_answer_func\n");
+    cat1_print_dbg("time_answer_func\n");
     cat1_handle_call_disconnected("callfail");
 }
 
@@ -1139,7 +1181,7 @@ static void time_answer_func(void)
 static void time_dial_func(void)
 {
     osTimerStop(g_timer_time_Dial);
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"time_dial_func\n");
+    cat1_print_dbg("time_dial_func\n");
     cat1_handle_call_disconnected("callfail");
 }
 
@@ -1147,186 +1189,76 @@ int cat1_handle_call_connected(char* phonenum)
 {
     // watch_replay_cat1_ANSWER();
 
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 call connected %s\n",phonenum);
+    cat1_print_dbg("cat1 call connected %s\n",phonenum);
     //声音处理
-    incomedcall_event_sendmsg_toUI(phonenum);
-    //uapi_cat1_start_volte_voice();
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_CONNECTED,phonenum,strlen(phonenum));
+        
+    cat1_api_start_cat1_volte_voice();
     return 1;
 }
 //来电挂断处理
 int cat1_handle_call_disconnected(char* phonenum)
 {
-    WEARABLE_LOGI(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1 call disconnected  %s\n",phonenum);
+    cat1_print_info("cat1 call disconnected  %s\n",phonenum);
     //TODO:  关闭声音
     // watch_replay_cat1_HANGUP();
-    
-    callend_event_sendmsg_toUI(phonenum);
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_DISCONNECTED,phonenum,strlen(phonenum));
+           
+    cat1_api_stop_cat1_volte_voice();
     return 1;
 }
-void get_software_version_toCat1(void)//发送固件版本到cat1
-{
-    char version_buf[128] = "Watch Soar V1.0";
-    // uint32_t version_len = 128;
-    // uapi_get_buildversion((uint8_t *)version_buf, version_len);
-    printf("version_buf %s\r\n",version_buf);
-    udp_send_msg_toCat1(UDP_MSG_GET_SOFTWARE_VESION,version_buf);
-    return;
-}
-void save_sim_iccid_toBle(char *msg)//保存SIM卡的ICCID到蓝牙
-{
-    // if(strncmp(msg,"ICCID:",6) == 0)//字符串是否有ICCID:字符串
-    // {
-    //     char* ppbuf = NULL;
-    //     ppbuf = msg+6;
-    //     printf("ppbuf %s\r\n",ppbuf);
-    //     OHOS::ConfigModel::GetInstance()->SetSimIccid(ppbuf);
-    // }
-    
-    return;
-}
-
-void get_sim_iccid_toCat1(void)//获取sim卡的ICCID到cat1
-{
-    // char iccid_buf[30] = {0};
-    // const char *imei_str = const_cast<char*>(OHOS::ConfigModel::GetInstance()->GetSimIccid().c_str());
-    // int len = strlen(imei_str);
-    // if(len == 0)
-    // {
-    //     printf("iccid len====0\r\n");
-    //     udp_send_msg_toCat1(UDP_MSG_GET_SIM_ICCID,"0");
-    // }else{
-    //     sprintf_s(iccid_buf,30,imei_str);
-    //     udp_send_msg_toCat1(UDP_MSG_GET_SIM_ICCID,iccid_buf);
-    // }  
-}
 
-void save_regist_time_toBle(char *msg)//保存注册的时间戳
-{
-    // if(strncmp(msg,"REGIST_TIME:",12) == 0)//字符串是否有ICCID:字符串
-    // {
-    //     char* ppbuf = NULL;
-    //     ppbuf = msg+12;
-    //     printf("time %s\r\n",ppbuf);
-    //     OHOS::ConfigModel::GetInstance()->SetRegistTime(ppbuf);
-    // }
-    return;
-}
-void send_dmp_mode_toCat1(uint8_t on)//设置
-{   
-    printf("set_telecom_dmp_switch_toCat1 on:%d\r\n",on);
-    char buf[10] ={0};
-    sprintf_s(buf,10,"%d",on);
-    udp_send_msg_toCat1(UDP_MSG_SET_TELECON_DMP_SWITCH,buf);//1开启 0关闭
-}
-int get_dmp_change_mode_toCat1(void)//获取切换模式TO CAT1
-{
-    // int state = OHOS::ConfigModel::GetInstance()->GetDmpChangeMode();
-    // return state;
-    return 1;
-}
-void set_dmp_change_mode_old(uint8_t mode)//获取切换模式TO CAT1
+void send_dtmf_number_toCat1(char ch)//发送dtfm 
 {
-    // OHOS::ConfigModel::GetInstance()->SetDmpChangeModeOld(mode);
-    return;
-}
-int get_dmp_change_mode_old(void)//获取切换模式TO CAT1
-{
-    // int state = OHOS::ConfigModel::GetInstance()->GetDmpChangeModeOld();
-    // return state;
-    return 1;
-}
-void get_regist_time_toCat1(void)//设置电信入库功能开关->CAT1
-{
-    // char time_buf[30] = {0};
-    // const char *time_str = const_cast<char*>(OHOS::ConfigModel::GetInstance()->GetRegistTime().c_str());
-    // int len = strlen(time_str);
-    // if(len == 0)
-    // {
-    //     printf("iccid len====0\r\n");
-    //     udp_send_msg_toCat1(UDP_MSG_GET_TELECON_DMP_TIMESEC,"0");
-    // }
-    // else
-    // {
-    //     sprintf_s(time_buf,30,time_str);
-    //     udp_send_msg_toCat1(UDP_MSG_GET_TELECON_DMP_TIMESEC,time_buf);
-    // }
-}
-void send_ble_mac_toCat1(void)//发送BLE mac地址 to CAT1
-{
-    errcode_t ret = 0;
-    uint8_t btaddr[6] = {0};
-    char btaddr_str[64] = {0};
-    uint32_t len = 6;
-    ret = uapi_get_nv_btaddr((uint8_t *)btaddr, &len);
-    sprintf_s((char *)btaddr_str,64,"%02X:%02X:%02X:%02X:%02X:%02X", btaddr[0], btaddr[1], btaddr[2], btaddr[3], btaddr[4], btaddr[5]);
-    udp_send_msg_toCat1(UDP_MSG_SEND_BLE_MAC_TO_CAT1,btaddr_str);
-}
-void send_dmp_factory_flag(void)//发送入库出厂标识
-{
-    // printf("send_dmp_factory_flag\r\n");
-    // char send_str[10] = {0};
-    // int state = OHOS::ConfigModel::GetInstance()->GetDmpFactoryStatus();
-    // sprintf_s((char *)send_str,10, "%d", state);
-    // udp_send_msg_toCat1(UDP_MSG_RECV_DMP_FACTORY,send_str);//发送和接收同一个指令
-}
-int get_dmp_factory_status(void)
-{
-    // int state = OHOS::ConfigModel::GetInstance()->GetDmpFactoryStatus();
-    // return state;
-    return false;
-}
-void set_dmp_china_mobile_factory_flag(char *msg)//设置factory状态
-{
-    // printf("set_dmp_china_mobile_factory_flag:%s\r\n",msg);
-    // int state = atoi(msg);
-    // OHOS::ConfigModel::GetInstance()->SetDmpFactoryStatus(state);
-}
-
-void send_dmp_cm_address_toCat1(void)//发送移动入库的地址to CAT1
-{
-    // char address_buf[30] = {0};
-    // const char *address_str = const_cast<char*>(OHOS::ConfigModel::GetInstance()->GetDmp_CM_address().c_str());
-    // int len = strlen(address_str);
-    // if(len != 0)
-    // {
-    //     printf("address_str:%s\r\n",address_str);
-    //     sprintf_s(address_buf,30,address_str);
-    //     udp_send_msg_toCat1(UDP_MSG_SEND_DMP_CM_ADDRESS,address_buf);
-    // }  
-}
-
-void set_dmp_cm_address_toCat1(char *address)//设置保存移动入库下发的上报地址
-{
-    // printf("set_dmp_cm_address_toCat1 %s\r\n",address);
-    // if(strncmp(address,"address:",8) == 0)//字符串是否有address:字符串
-    // {
-    //     char* ppbuf = NULL;
-    //     ppbuf = address+8;
-        
-    //     OHOS::ConfigModel::GetInstance()->SetDmp_CM_address(ppbuf);
-    // }
-    return;
-}
-void send_dtfm_number_toCat1(char ch)//发送dtfm 
-{
-    printf("ch:%c\r\n",ch);
+    cat1_print_dbg("ch:%c\r\n",ch);
     udp_send_msg_toCat1(UDP_MSG_SEND_DTMF_NUMBER,&ch);
 }
-void send_volte_switch_toCat1(void)//发送VOLTE->CAT1
-{
-    // bool Cat1_4G = OHOS::ConfigModel::GetInstance()->GetCat1_4Gability();
-    // if (Cat1_4G == 0)
-    //     return;
 
-    // bool volte = OHOS::ConfigModel::GetInstance()->GetVoLTE_Call();
-    // char send_str[5] = {0};
-    // sprintf_s((char *)send_str,5, "%d", volte);
-    // udp_send_msg_toCat1(UDP_MSG_SEND_VOLTE_SWITCH,send_str);
-}
-bool get_volte_switch(void)//
+/**
+ * @brief 发送指令给Cat1,输入 CMD_4G_T , cmd_buf 为指令所需参数.
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_cmd_send(CMD_4G_T cmd,void *cmd_buf,uint16_t cmdlen)
 {
-    // bool volte = OHOS::ConfigModel::GetInstance()->GetVoLTE_Call();
-    return true;
+
+    switch(cmd)
+    {
+        case CMD_4G_POWERON://无参数
+            cat1_api_enable_cat1(true);
+            break;
+        case CMD_4G_POWEROFF://无参数
+            cat1_api_enable_cat1(false);
+            break;
+        case CMD_4G_GET_SIGNAL://无参数
+            cat1_getsignal();
+            break;
+        case CMD_4G_GET_VERSION://无参数
+            cat1_getver();
+            break;
+        case CMD_4G_GET_TIME://无参数
+            cat1_gettime();
+            break;
+        case CMD_4G_MAKE_CALL://需要输入参数 电话号
+            cat1_call_dial(cmd_buf);
+            break;
+        case CMD_4G_ANSWER_CALL://无参数
+            cat1_call_answer();
+            break;
+        case CMD_4G_HUNGUP_CALL://无参数
+            cat1_call_hungup();
+            break;
+        case CMD_4G_SEND_DTMF://需要输入参数 DTMF NUM(单个数字) , 包括 0 ~ 9, * , #
+            send_dtmf_number_toCat1(((uint8_t*)cmd_buf)[0]);
+            break;
+        case CMD_4G_AT://需要AT指令,要求结尾带\r\n
+            cat1_at_cmd(cmd_buf);
+            break;
+        default:
+            break;
+    }
+    return ERRCODE_SUCC;
 }
 
 static int udp_packet_parse(char *rx_buffer, int len)
@@ -1335,7 +1267,7 @@ static int udp_packet_parse(char *rx_buffer, int len)
     int index = 0; 
     if (len <6 || rx_buffer == NULL)
     {
-        printf("len < 6 , format error !\n");
+        cat1_print_err("len < 6 , format error !\n");
         return -1;
     }
     uint8_t header0 = rx_buffer[0];
@@ -1347,7 +1279,7 @@ static int udp_packet_parse(char *rx_buffer, int len)
         // printf("msg format error or old msg format!\n");
         g_msg_format_type = 0;
     }
-    printf("g_msg_format_type %d\n",g_msg_format_type);
+    cat1_print_dbg("g_msg_format_type %d\n",g_msg_format_type);
     char * msg_buffer = NULL;
     int msg_buffer_len = 0;
     uint16_t cmd = 0;
@@ -1364,15 +1296,16 @@ static int udp_packet_parse(char *rx_buffer, int len)
         msg_buffer_len = msg->length;
         cmd = get_int8_from_ascii_char(rx_buffer[1]);
     }
-    printf("cmd %x,bufferlen %d , buffer %s \n",cmd,msg_buffer_len,msg_buffer);
+    cat1_print_dbg("cmd %x,bufferlen %d , buffer %s \n",cmd,msg_buffer_len,msg_buffer);
 
     udp_send_msg_toCat1(UDP_MSG_WATCH_REPLY_ACK,"0");
 
         switch (cmd) {
         case UDP_MSG_COMMING_CALL:
+        #ifdef SUPPORT_DMP
             if (get_volte_switch() == false) //如果VOLTE开关没有开启则不接CAT1的来电功能
                 break;
-            
+        #endif
             index = cat1_handle_call_incomming(msg_buffer);
             // uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_COMMING);
             break;
@@ -1383,6 +1316,8 @@ static int udp_packet_parse(char *rx_buffer, int len)
             break;
         case UDP_CMD_GET_TIME:
             index = cat1_handle_timesync(msg_buffer);
+            if (g_msg_callback_func!=NULL)
+                g_msg_callback_func(MESSAGE_4G_TIME_SYNCED,msg_buffer,strlen(msg_buffer));
             //  uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_TIME);
             break;
         case UDP_MSG_CALL_CONNECTED:
@@ -1400,11 +1335,11 @@ static int udp_packet_parse(char *rx_buffer, int len)
             // uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_DISCONNECTED);
             break;
         case UDP_CMD_CAT1_OTA_UPDATE:
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"CAT1_OTA_UPDATE reply %s\n",msg_buffer);
+            cat1_print_dbg("CAT1_OTA_UPDATE reply %s\n",msg_buffer);
             //  uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_OTA_UPDATE);
             break;
         case UDP_MSG_REPLY:
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"UDP_MSG_REPLY reply %s!!!!!!!\n",msg_buffer);
+            cat1_print_dbg("UDP_MSG_REPLY reply %s!!!!!!!\n",msg_buffer);
             //"BOOTUP,pyVer,PY_SRV_V4,modemVer,EG810MCNLAR06A01M08_VOLTE_OCPU_QPY_BETA0312"
             // VER:xxxxx
             // ICCID:xxxxxx
@@ -1413,7 +1348,11 @@ static int udp_packet_parse(char *rx_buffer, int len)
                 cat1_handle_version_msg(msg_buffer);
                 restart_time_sync();
                 cat1_getsignal();
-
+                if (g_msg_callback_func!=NULL)
+                {
+                    g_msg_callback_func(MESSAGE_4G_POWERON,NULL,0);
+                }
+#ifdef ENABLE_SNTP
                 if(sntp_enabled()==0)
                 {
                     sntp_init();
@@ -1422,8 +1361,10 @@ static int udp_packet_parse(char *rx_buffer, int len)
                     sntp_stop();
                     sntp_init();
                 }
-                
+#endif 
+
                 if(g_msg_format_type == 0) break;  //下面指令只有新格式才支持,因此返回
+                #if 0
                 int stateOld = get_dmp_change_mode_old();
                 int stateNew = get_dmp_change_mode_toCat1();//0 stateOld = 0 0-1
                 if (stateNew == 0){//关闭入库功能 把恢复出厂标识清0
@@ -1448,12 +1389,15 @@ static int udp_packet_parse(char *rx_buffer, int len)
                         send_dmp_factory_flag();
                     }
                 }
+            #endif
        
             }
             if(strstr(msg_buffer,"callanswer_success")!=NULL)
             {
                 osTimerStop(g_timer_time_answer);
-                incomedcall_event_sendmsg_toUI("callanswer_success");
+                // callconnected_event_sendmsg_toUI("callanswer_success");
+                if (g_msg_callback_func!=NULL)
+                    g_msg_callback_func(MESSAGE_4G_CALL_CONNECTED,"0",1);
                
             }
             if(strstr(msg_buffer,"callcmd_fail")!=NULL)
@@ -1474,11 +1418,15 @@ static int udp_packet_parse(char *rx_buffer, int len)
 
             break;
         case UDP_MSG_SEND_DMP_CM_ADDRESS://#接收移动入库CAT1下发的地址 BLE需要保存
+        #ifdef SUPPORT_DMP
             set_dmp_cm_address_toCat1(msg_buffer);
+        #endif
             // uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_DMP_CM_ADDRESS);
             break;
         case UDP_CMD_GET_CAT1VER:
             index = cat1_handle_version_msg(msg_buffer);
+            if (g_msg_callback_func!=NULL)
+                g_msg_callback_func(MESSAGE_4G_VERSION_SYNCED,msg_buffer,strlen(msg_buffer));
             //  uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_GET_CAT1VER);
             break;
         case UDP_CMD_MSG_ATCMD:
@@ -1486,17 +1434,24 @@ static int udp_packet_parse(char *rx_buffer, int len)
             memcpy_s(ble_buffer,20,msg_buffer,strlen(msg_buffer));
             if (strlen(msg_buffer) == 0)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ATCMD reply len(0): OK\n");
+                cat1_print_dbg("ATCMD reply len(0): OK\n");
+                if (g_msg_callback_func!=NULL)
+                g_msg_callback_func(MESSAGE_4G_AT_RECEIVED,"\r\nOK\r\n",strlen("\r\nOK\r\n"));
             }else{
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ATCMD reply len(%d): %s\n", strlen(msg_buffer),msg_buffer);
+                cat1_print_dbg("ATCMD reply len(%d): %s\n", strlen(msg_buffer),msg_buffer);
+                if (g_msg_callback_func!=NULL)
+                g_msg_callback_func(MESSAGE_4G_AT_RECEIVED,msg_buffer,strlen(msg_buffer));
             }
             //  uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_ATCMD);
+            
             break;
         case UDP_MSG_SAVE_SIM_ICCID://暂时不用
             break;
         case UDP_MSG_RECV_DMP_FACTORY:
             //  uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_RECV_DMP);
+        #ifdef SUPPORT_DMP
             set_dmp_china_mobile_factory_flag(msg_buffer);
+        #endif
             break;
         case UDP_MSG_RECV_CAT1_SMS_CONTENT://接收单条短信内容
         case UDP_MSG_SMS:
@@ -1504,7 +1459,7 @@ static int udp_packet_parse(char *rx_buffer, int len)
             // uapi_save_runtime_log(RUNTIME_LOG_CAT1_UDP_MSG_SMS);
             break;
         default:
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"error message: %s\n", rx_buffer);
+            cat1_print_err("error message: %s\n", rx_buffer);
             index = 1;
             break;
     }
@@ -1535,14 +1490,14 @@ static int udp_socket_init()
 
     int listen_sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
     if (listen_sock < 0) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Unable to create socket: errno %d\n", errno);
+        cat1_print_err("Unable to create socket: errno %d\n", errno);
         return -1;
     }
     setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
 
     int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
     if (err != 0) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Socket unable to bind: errno %d\n", errno);
+        cat1_print_err("Socket unable to bind: errno %d\n", errno);
         return -1;
     }
     
@@ -1565,7 +1520,7 @@ void cat1_server_task(void *pvParameters)
         if( g_listen_sock > 0 ) close(g_listen_sock);
         g_listen_sock = udp_socket_init();
         if( g_listen_sock < 0 ) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"socket init fail and retry\n");
+            cat1_print_err("socket init fail and retry\n");
             // vTaskDelay(1000/portTICK_RATE_MS);
             cat1_msleep(1000);
             continue;
@@ -1578,24 +1533,24 @@ void cat1_server_task(void *pvParameters)
                        memset(rx_buffer, 0, sizeof(rx_buffer));
             int len = recvfrom(g_listen_sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&sourceAddr, &addrLen);
             // Error occured during receiving
-            printf("recv len:%d rx_buffer:%s\r\n",len,rx_buffer);
+            cat1_print_dbg("recv len:%d rx_buffer:%s\r\n",len,rx_buffer);
             if (len < 0) {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"recv failed: errno %d\n", errno);
+                cat1_print_err("recv failed: errno %d\n", errno);
                 break;
             } else if (len == 0) {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Connection closed\n");
+                cat1_print_err("Connection closed\n");
                 break;
             }
             // Data received
             rx_buffer[len] = '\0'; // Null-terminate whatever we received and treat like a string
-            // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Received %d bytes, rx_buffer: %s\n", len, rx_buffer);
+            // cat1_print_dbg("Received %d bytes, rx_buffer: %s\n", len, rx_buffer);
             index = udp_packet_parse(rx_buffer, len);
             // if( index >= 0 ) {
             //     udp_send_response(tx_buffer, rx_buffer, "OK"/* msg_wifi_resp[index]*/);
             // }
 
             #ifndef USE_CAT1_SLEEP_TIMER
-            uapi_cat1_remove_cat1_vote(); //中断会添加休眠投票,此处代表已经收到cat1的消息,可以移除投票进入休眠了。
+            cat1_api_remove_cat1_vote(); //中断会添加休眠投票,此处代表已经收到cat1的消息,可以移除投票进入休眠了。
             #endif
         }
        }
@@ -1608,13 +1563,22 @@ void cat1_server_task(void *pvParameters)
 #include "soc_osal.h"
 #include "common_def.h"
 #include "los_printf.h"
-
+#include "uart_slip.h"
+#include "cat1_tcpServer.h"
 #define CAT1_SERVICE_TASK_SIZE       (0x800*5)
 #define CAT1_SERVICE_TASK_PRIO       5
 
+
 errcode_t cat1_server_init(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"cat1_server_init !\r\n");
+
+    if (permition_verify()!=ERRCODE_SUCC)
+    {
+        cat1_print_err("cat1_server_init dev verify failed!\r\n");
+        return ERRCODE_FAIL;
+    }else{
+        cat1_print_info("cat1_server_init !\r\n");
+    }
     app_task_definition_t taskcfg={0};
     taskcfg.create_queue_handle = NULL;
     taskcfg.attr.name="cat1_service";
@@ -1622,36 +1586,48 @@ errcode_t cat1_server_init(void)
     taskcfg.attr.stack_size = CAT1_SERVICE_TASK_SIZE;
     taskcfg.func = cat1_server_task;
     taskcfg.use_mem = USE_EXTEND_MEM;
+
+    cat1_api_porting_init();
+
+    cat1_api_gpio_init();
+    
+    cat1_api_uart_init();
+
+    netif_service_init();
     
-    errcode_t ret=uapi_create_osThread_custom(&taskcfg);
+    errcode_t ret=cat1_create_osThread_custom(&taskcfg);
     if(ret != ERRCODE_SUCC)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create cat1_service failed %d!\r\n",ret);
+        cat1_print_err("create cat1_service failed %d!\r\n",ret);
         return ERRCODE_FAIL;
     }
     
     g_timer_time_sync = osTimerNew((osTimerFunc_t)time_sync_func, osTimerPeriodic, NULL, NULL);
     if (g_timer_time_sync == NULL)
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+        cat1_print_err("g_timer_time_sync create failed\n");
 
     restart_time_sync();
 
     g_timer_time_Dial = osTimerNew((osTimerFunc_t)time_dial_func, osTimerPeriodic, NULL, NULL);
     if (g_timer_time_Dial == NULL)
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+        cat1_print_err("g_timer_time_sync create failed\n");
 
     g_timer_time_answer = osTimerNew((osTimerFunc_t)time_answer_func, osTimerPeriodic, NULL, NULL);
     if (g_timer_time_answer == NULL)
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_time_sync create failed\n");
+        cat1_print_err("g_timer_time_sync create failed\n");
 
     
 #ifdef USE_CAT1_SLEEP_TIMER
     g_timer_cat1_sleep = osTimerNew((osTimerFunc_t)timeout_handler_sleep_cat1, osTimerPeriodic, NULL, NULL);
     if (g_timer_cat1_sleep == NULL)
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"g_timer_cat1_sleep create failed\n");
+        cat1_print_err("g_timer_cat1_sleep create failed\n");
     //第一次启动,要确保去除已经添加过的cat1 Vote
     restart_sleep_cat1_timer();
 #endif
+
+
+    cat1_tcp_server_init();
+
     return ERRCODE_SUCC;
 }
 
index 6ad75b8..a001f97 100644 (file)
 #include <string.h>
 
 #ifdef __cplusplus
-
 extern "C" {
-
 #endif /* __cplusplus */
 
-
-
 #include "errcode.h"
 #include "errno.h"
-
 #include "cat1_server_hal.h"
 #include "cat1_utils.h"
-
-
-static errcode_t calldial_event_notify(char* callno)
-{
-
-    return 0;
-}
-
-
-static errcode_t incomingcall_event_notify(char* callno)
-{
-    return 0;
-}
-
-static errcode_t incomed_call_event_notify(char* callno)
-{
-    return 0;
-}
-
-static errcode_t callend_event_notify(char* callno)
-{
-    return 0;
-}
-
-static errcode_t cat1msg_event_notify(char* callno)
-{
-    return 0;
-}
-//传地址应设置固定内存,否则异进程内存安全没法保证
+#include "cat1_porting.h"
+#include "cat1_pub_api.h"
+
+
+    //    MESSAGE_4G_POWERON,//无参数 (BOOTUP)
+    // MESSAGE_4G_POWEROFF,//无参数
+    // MESSAGE_4G_NETWORK_CONNECTED,//无参数
+    // MESSAGE_4G_NETWORK_DISCONNECTED,//无参数
+    // MESSAGE_4G_NETWORK_STAT_CHANGED,//含signal,sim,运营商,
+    // MESSAGE_4G_CALL_COMMING,//带电话号
+    // MESSAGE_4G_CALL_CONNECTED,//带电话号
+    // MESSAGE_4G_CALL_DISCONNECTED,//带电话号
+    // MESSAGE_4G_SMS_RECEIVED, //返回值为字符串
+    // MESSAGE_4G_AT_RECEIVED, //返回值为字符串
+    // MESSAGE_4G_TIME_SYNCED,//时间同步完成
+    // MESSAGE_4G_VERSION_SYNCED,//版本同步完成
 
 int callend_event_sendmsg_toUI(char* callno)
 {
     /**通过UI事件发送Notify*/
-    
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_DISCONNECTED,callno,strlen(callno));
     return ERRCODE_SUCC;
 }
 
-int incomedcall_event_sendmsg_toUI(char* callno)
+int callconnected_event_sendmsg_toUI(char* callno)
 {
     /**通过UI事件发送Notify*/
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_CONNECTED,callno,strlen(callno));
     return ERRCODE_SUCC;
 }
 
@@ -69,30 +54,19 @@ int incomedcall_event_sendmsg_toUI(char* callno)
 int incomingcall_event_sendmsg_toUI(char* callno)
 {
     /**通过UI事件发送Notify*/
-
-    return ERRCODE_SUCC;
-}
-
-int calldial_event_sendmsg_toUI(char* callno)
-{
-    /**通过UI事件发送Notify*/
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_CALL_COMMING,callno,strlen(callno));
     return ERRCODE_SUCC;
 }
 
-int cat1_msg_event_sendmsg_toUI(char* callno)
+int cat1_msg_event_sendmsg_toUI(char* sms)
 {
     /**通过UI事件发送Notify*/
+    if (g_msg_callback_func!=NULL)
+        g_msg_callback_func(MESSAGE_4G_SMS_RECEIVED,sms,strlen(sms));
     return ERRCODE_SUCC;
 }
 
-void up_report_timer(void)
-{
-}
-
-
-
 #ifdef __cplusplus
-
 }
-
 #endif /* __cplusplus */
diff --git a/code/sdk/zhihui/4g/cat1Service/Service/cat1_signlib.c b/code/sdk/zhihui/4g/cat1Service/Service/cat1_signlib.c
new file mode 100644 (file)
index 0000000..e776a98
--- /dev/null
@@ -0,0 +1,492 @@
+/*
+ * Copyright (c) 2021 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if 0
+#include "hks_param.h"
+#include "hks_api.h"
+#include "hks_type.h"
+#include "securec.h"
+#include "cat1_log.h"
+
+#define HKS_TEST_ASSERT(test) \
+    if (!(test)) { \
+        printf("[ASSERT][%s](%d):fail\n", __func__, __LINE__); \
+    }
+static int32_t TestGenerateEd25519Key(struct HksBlob alias);
+static int32_t TestImportEd25519(struct HksBlob alias, struct HksBlob *pubKeyInfo);
+static int32_t TestEd25519SignTeeVerifyLocal();
+static int32_t TestCurve25519SignWrong();
+static int32_t TestCurve25519verifyWrong();
+
+#define TEST_ALIAS_ED25519 "test_ed25519"
+#define TEST_PLAIN_TEST_ED25519 "This is a plain text! Hello world and thanks for watching ED25519~"
+#define TEST_CURVE_256 256
+#define TEST_CURVE_512 512
+
+static uint8_t g_buffer[TEST_CURVE_256];
+static uint32_t g_bufferSize = TEST_CURVE_256;
+static uint8_t g_pubKey[TEST_CURVE_512] = {0};
+static uint32_t g_pubKeyLen = TEST_CURVE_512;
+
+int32_t TestGenerateEd25519Key(struct HksBlob alias)
+{
+    cat1_print_info("Test_GenerateEd25519!\n");
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam keySizeParam = {0};
+    keySizeParam.tag = HKS_TAG_KEY_SIZE;
+    keySizeParam.uint32Param = TEST_CURVE_256;
+    ret = HksAddParams(paramSet, &keySizeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN | HKS_KEY_PURPOSE_VERIFY;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_NONE;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksGenerateKey(&alias, paramSet, NULL);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+static int32_t TestSignEd25519(struct HksBlob alias)
+{
+    struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
+
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_NONE;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksBlob signature = { TEST_CURVE_256, g_buffer };
+    ret = HksSign(&alias, paramSet, &msg, &signature);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    g_bufferSize = signature.size;
+    cat1_print_info("TestSignEd25519 signature size is %u", signature.size);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+static int32_t TestVerifyEd25519(struct HksBlob alias)
+{
+    struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
+
+    cat1_print_info("TestVerifyEd25519!\n");
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_NONE;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksBlob signature = { g_bufferSize, g_buffer };
+    ret = HksVerify(&alias, paramSet, &msg, &signature);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+int32_t TestImportEd25519(struct HksBlob alias, struct HksBlob *pubKeyInfo)
+{
+    cat1_print_info("TestImportEd25519!\n");
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam keySizeParam = {0};
+    keySizeParam.tag = HKS_TAG_KEY_SIZE;
+    keySizeParam.uint32Param = TEST_CURVE_256;
+    ret = HksAddParams(paramSet, &keySizeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_NONE;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksImportKey(&alias, paramSet, pubKeyInfo);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+static int32_t TestExportImportEd25519SignVerify(struct HksBlob alias)
+{
+    uint8_t pubKey[32] = {0};
+    uint32_t pubKeyLen = 32;
+    struct HksBlob pubKeyInfo = { pubKeyLen, pubKey };
+    int32_t ret = TestGenerateEd25519Key(alias);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksExportPublicKey(&alias, NULL, &pubKeyInfo);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = TestSignEd25519(alias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksDeleteKey(&alias, NULL);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksBlob newAlias = { strlen("test_ed25519_2"), (uint8_t *)"test_ed25519_2" };
+    ret = TestImportEd25519(newAlias, &pubKeyInfo);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestVerifyEd25519(newAlias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksDeleteKey(&newAlias, NULL);
+    HKS_TEST_ASSERT(ret == 0);
+    return ret;
+}
+
+int32_t TestCurve25519All()
+{
+    struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
+    int32_t ret = TestGenerateEd25519Key(ed25519Alias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestSignEd25519(ed25519Alias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestVerifyEd25519(ed25519Alias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksDeleteKey(&ed25519Alias, NULL);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = TestExportImportEd25519SignVerify(ed25519Alias);
+    cat1_print_info("ret=%d",ret);
+    HKS_TEST_ASSERT(ret == 0);
+    return ret;
+}
+
+static int32_t BuildTeeSignParamSet(struct HksParamSet **paramSet)
+{
+    int32_t ret = HksInitParamSet(paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(*paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
+    ret = HksAddParams(*paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(*paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_NONE;
+    ret = HksAddParams(*paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksBuildParamSet(paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    return ret;
+}
+
+static int32_t BuildLocalVerifyParamSet(struct HksParamSet **paramSet)
+{
+    int32_t ret = HksInitParamSet(paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(*paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam isKeyAlias = {0};
+    isKeyAlias.tag = HKS_TAG_IS_KEY_ALIAS;
+    isKeyAlias.boolParam = false;
+    ret = HksAddParams(*paramSet, &isKeyAlias, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam keySizeParam = {0};
+    keySizeParam.tag = HKS_TAG_KEY_SIZE;
+    keySizeParam.uint32Param = TEST_CURVE_256;
+    ret = HksAddParams(*paramSet, &keySizeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
+    ret = HksAddParams(*paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA512;
+    ret = HksAddParams(*paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksBuildParamSet(paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    return ret;
+}
+
+int32_t TestEd25519SignTeeVerifyLocal()
+{
+    cat1_print_dbg("TestEd25519SignTeeVerifyLocal enter!");
+
+    struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
+    struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
+    struct HksBlob signature = { TEST_CURVE_256, g_buffer };
+    struct HksParamSet *paramSetSign = NULL;
+    struct HksParamSet *paramSetVerify = NULL;
+    struct HksBlob pubKeyInfo = { g_pubKeyLen, g_pubKey };
+
+    int32_t ret = TestGenerateEd25519Key(ed25519Alias);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksExportPublicKey(&ed25519Alias, NULL, &pubKeyInfo);
+    HKS_TEST_ASSERT(ret == 0);
+    cat1_print_info("HksExportPublicKey puKey size is %u", pubKeyInfo.size);
+
+    ret = BuildTeeSignParamSet(&paramSetSign);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksSign(&ed25519Alias, paramSetSign, &msg, &signature);
+    HKS_TEST_ASSERT(ret == 0);
+    cat1_print_info("Test_Ed25519_Sign_TEE signature size is %u", signature.size);
+
+    ret = BuildLocalVerifyParamSet(&paramSetVerify);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksVerify(&pubKeyInfo, paramSetVerify, &msg, &signature);
+    HKS_TEST_ASSERT(ret == 0);
+    cat1_print_info("Test_Ed25519_Verify_Local Success");
+
+    ret = HksDeleteKey(&ed25519Alias, NULL);
+    HKS_TEST_ASSERT(ret == 0);
+
+    HksFreeParamSet(&paramSetSign);
+    HksFreeParamSet(&paramSetVerify);
+    cat1_print_dbg("TestEd25519SignTeeVerifyLocal End!\n");
+    return ret;
+}
+
+static int32_t TestSignEd25519Wrong(struct HksBlob alias)
+{
+    struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
+
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_VERIFY;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA256;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_PKCS5;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+    struct HksBlob signature = { TEST_CURVE_256, g_buffer };
+    ret = HksSign(&alias, paramSet, &msg, &signature);
+    HKS_TEST_ASSERT(ret != 0);
+    g_bufferSize = signature.size;
+    cat1_print_info("TestSignEd25519 signature size is %u", signature.size);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+int32_t TestCurve25519SignWrong()
+{
+    struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
+    int32_t ret = TestGenerateEd25519Key(ed25519Alias);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestSignEd25519Wrong(ed25519Alias);
+    HKS_TEST_ASSERT(ret != 0);
+    int32_t retTwo = HksDeleteKey(&ed25519Alias, NULL);
+    HKS_TEST_ASSERT(retTwo == 0);
+    if ((ret != 0) && (retTwo == 0)) {
+        return 0;
+    }
+    return 1;
+}
+
+static int32_t TestVerifyEd25519Wrong(struct HksBlob alias)
+{
+    struct HksBlob msg = {strlen(TEST_PLAIN_TEST_ED25519), (uint8_t *)TEST_PLAIN_TEST_ED25519};
+
+    cat1_print_info("TestVerifyEd25519!\n");
+    struct HksParamSet *paramSet = NULL;
+    int32_t ret = HksInitParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam algParam = {0};
+    algParam.tag = HKS_TAG_ALGORITHM;
+    algParam.uint32Param = HKS_ALG_ED25519;
+    ret = HksAddParams(paramSet, &algParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam purposeParam = {0};
+    purposeParam.tag = HKS_TAG_PURPOSE;
+    purposeParam.uint32Param = HKS_KEY_PURPOSE_SIGN;
+    ret = HksAddParams(paramSet, &purposeParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam digestParam = {0};
+    digestParam.tag = HKS_TAG_DIGEST;
+    digestParam.uint32Param = HKS_DIGEST_SHA256;
+    ret = HksAddParams(paramSet, &digestParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksParam paddingParam = {0};
+    paddingParam.tag = HKS_TAG_PADDING;
+    paddingParam.uint32Param = HKS_PADDING_PKCS5;
+    ret = HksAddParams(paramSet, &paddingParam, 1);
+    HKS_TEST_ASSERT(ret == 0);
+
+    ret = HksBuildParamSet(&paramSet);
+    HKS_TEST_ASSERT(ret == 0);
+
+    struct HksBlob signature = { g_bufferSize, g_buffer };
+    ret = HksVerify(&alias, paramSet, &msg, &signature);
+    HKS_TEST_ASSERT(ret != 0);
+    HksFreeParamSet(&paramSet);
+    return ret;
+}
+
+int32_t TestCurve25519verifyWrong()
+{
+    struct HksBlob ed25519Alias = { strlen(TEST_ALIAS_ED25519), (uint8_t *)TEST_ALIAS_ED25519 };
+    int32_t ret = TestGenerateEd25519Key(ed25519Alias);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestSignEd25519(ed25519Alias);
+    HKS_TEST_ASSERT(ret == 0);
+    ret = TestVerifyEd25519Wrong(ed25519Alias);
+    HKS_TEST_ASSERT(ret != 0);
+    int32_t retTwo = HksDeleteKey(&ed25519Alias, NULL);
+    HKS_TEST_ASSERT(retTwo == 0);
+    if ((ret != 0) && (retTwo == 0)) {
+        return 0;
+    }
+    return 1;
+}
+#endif
\ No newline at end of file
index a74e71a..dad4cf1 100644 (file)
 #include <string.h>
 
 #include "../../../../../open_source/openharmony/third_party/cJSON/cJSON.h"
-#include "wearable_log.h"
+#include "cat1_log.h"
 #include "cat1_runtime.h"
 #include "osal_timer.h"
-#include "lwip/apps/sntp.h"
-
 #include <sys/time.h>
 
-#ifdef SUPPORT_BLE_SERVICE
-
-#ifdef BLE_INSTRUCT
-#include "bleInstruct.h"
-#endif
-
-#include "bleANCS.h"
-#endif
 #include "cat1_utils.h"
 #include "cat1_runtime.h"
 #include "cat1_tcpServer.h"
 
 #ifdef __cplusplus
-
 extern "C" {
-
 #endif /* __cplusplus */
 
 
@@ -196,27 +184,27 @@ static void udp_send_response(char *tx_buffer,uint8_t mode, uint8_t cmd, char *c
     if( len > 0 ) {
         err = sendto(g_listen_sock, tx_buffer, len, 0, (struct sockaddr *)&filesourceAddr, sizeof(filesourceAddr));
         if (err < 0) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error occured during sending: errno %d\n", errno);
+            cat1_print_err("Error occured during sending: errno %d\n", errno);
                }
     } else {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error occured unkown send data\n");
+        cat1_print_err("Error occured unkown send data\n");
     }
 }
 #include "uart_porting.h"
 void ble_tcp_send_msg_toCat1(uint8_t mode,uint8_t cmd,char *content)
 {
-    if (!uapi_cat1_get_power_stat())
+    if (!cat1_api_is_cat1_enabled())
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Error cat1 poweroff skipp send data\n");
+        cat1_print_err("Error cat1 poweroff skipp send data\n");
         return ;
     }
-    uapi_cat1_wakeup_cat1(1);
+    cat1_api_wakeup_cat1(1);
     // uart_port_register_irq(UART_BUS_0);
     osal_irq_enable(UART_1_IRQN);
 
     if (g_skip_cat1_service_udp_transfer == 1)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP," g_skip_cat1_service_udp_transfer \n");
+        cat1_print_err(" g_skip_cat1_service_udp_transfer \n");
         return ;
     }
     char station_tx_buffer[MAX_TCP_MSG_BUFFER_LEN] = {0};
@@ -224,7 +212,7 @@ void ble_tcp_send_msg_toCat1(uint8_t mode,uint8_t cmd,char *content)
         
         udp_send_response(station_tx_buffer,mode,cmd, content);
     }
-    uapi_cat1_wakeup_cat1(0);
+    cat1_api_wakeup_cat1(0);
 }
 
 
@@ -425,7 +413,7 @@ static void  cat1_file_Timer_CallBack(int data_tmp)
     if(timerOut_count > 0){
         timerOut_count--;
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"timerOut_count = !!%d cat1_ota_flag:%d\r\n",timerOut_count,cat1_ota_flag);
+    cat1_print_dbg("timerOut_count = !!%d cat1_ota_flag:%d\r\n",timerOut_count,cat1_ota_flag);
     if(timerOut_count==0){
         if(cat1_ota_flag == CAT1_TCP_START_OTA || cat1_ota_flag == CAT1_TCP_START_SEND_ALLFILE_FINESH
         || cat1_ota_flag == CAT1_TCP_START_SEND_FILE_DATA  || cat1_ota_flag == CAT1_TCP_START_SEND_SINGLE_FILE_INFO
@@ -526,7 +514,7 @@ void read_dir(void){
         tick = 1000;// osMs2Tick(1000);
         retTimer = osTimerStart(file_transfer_timer, tick);
         if (retTimer != osOK && file_transfer_timer != NULL) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+            cat1_print_err("StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
             osTimerDelete(file_transfer_timer);
             file_transfer_timer = NULL;
         }
@@ -992,14 +980,14 @@ static int udp_socket_file_init()
 
     int listen_sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
     if (listen_sock < 0) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Unable to create socket: errno %d\n", errno);
+        cat1_print_err("Unable to create socket: errno %d\n", errno);
         return -1;
     }
     setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
 
     int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
     if (err != 0) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Socket unable to bind: errno %d\n", errno);
+        cat1_print_err("Socket unable to bind: errno %d\n", errno);
         return -1;
     }
     
@@ -1022,7 +1010,7 @@ void cat1_server_file_task(void *pvParameters)
         if( g_listen_sock > 0 ) close(g_listen_sock);
         g_listen_sock = udp_socket_file_init();
         if( g_listen_sock < 0 ) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"socket init fail and retry\n");
+            cat1_print_err("socket init fail and retry\n");
             // vTaskDelay(1000/portTICK_RATE_MS);
             cat1_msleep(1000);
             continue;
@@ -1037,22 +1025,22 @@ void cat1_server_file_task(void *pvParameters)
             // Error occured during receiving
             printf("file recv len:%d rx_buffer:%s\r\n",len,rx_buffer);
             if (len < 0) {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"recv failed: errno %d\n", errno);
+                cat1_print_err("recv failed: errno %d\n", errno);
                 break;
             } else if (len == 0) {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Connection closed\n");
+                cat1_print_err("Connection closed\n");
                 break;
             }
             // Data received
             rx_buffer[len] = '\0'; // Null-terminate whatever we received and treat like a string
-            // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"Received %d bytes, rx_buffer: %s\n", len, rx_buffer);
+            // cat1_print_err("Received %d bytes, rx_buffer: %s\n", len, rx_buffer);
             index = udp_packet_parse(rx_buffer, len);
             // if( index >= 0 ) {
             //     udp_send_response(tx_buffer, rx_buffer, "OK"/* msg_wifi_resp[index]*/);
             // }
 
             #ifndef USE_CAT1_SLEEP_TIMER
-            uapi_cat1_remove_cat1_vote(); //中断会添加休眠投票,此处代表已经收到cat1的消息,可以移除投票进入休眠了。
+            cat1_api_remove_cat1_vote(); //中断会添加休眠投票,此处代表已经收到cat1的消息,可以移除投票进入休眠了。
             #endif
         }
        }
@@ -1071,7 +1059,7 @@ void cat1_server_file_task(void *pvParameters)
 
 errcode_t cat1_tcp_server_init(void)
 {
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"cat1_tcp_server_init !\r\n");
+    cat1_print_info("cat1_tcp_server_init !\r\n");
     app_task_definition_t taskcfg={0};
     taskcfg.create_queue_handle = NULL;
     taskcfg.attr.name="cat1_service_file";
@@ -1080,10 +1068,10 @@ errcode_t cat1_tcp_server_init(void)
     taskcfg.func = cat1_server_file_task;
     taskcfg.use_mem = USE_EXTEND_MEM;
     
-    errcode_t ret=uapi_create_osThread_custom(&taskcfg);
+    errcode_t ret=cat1_create_osThread_custom(&taskcfg);
     if(ret != ERRCODE_SUCC)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create cat1_service_file failed %d!\r\n",ret);
+        cat1_print_err("create cat1_service_file failed %d!\r\n",ret);
         return ERRCODE_FAIL;
     }
     return ERRCODE_SUCC;
index bf2185f..855c480 100644 (file)
@@ -51,7 +51,7 @@
 
 #include "cat1_utils.h"
 
-errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg)
+errcode_t cat1_create_osThread_custom(app_task_definition_t *task_cfg)
 {
     if (task_cfg==NULL)
         return ERRCODE_FAIL;
@@ -70,19 +70,19 @@ errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg)
     return ERRCODE_SUCC;
 }
 
-errcode_t uapi_terminate_thread(void* thread_id)
+errcode_t cat1_terminate_thread(void* thread_id)
 {
     osStatus_t ret = osThreadTerminate((osThreadId_t)thread_id);
     return ret;
 }
 
-errcode_t uapi_suspend_thread(void* thread_id)
+errcode_t cat1_suspend_thread(void* thread_id)
 {
     osStatus_t ret = osThreadSuspend((osThreadId_t)thread_id);
     return ret;
 }
 
-errcode_t uapi_resume_thread(void* thread_id)
+errcode_t cat1_resume_thread(void* thread_id)
 {
     osStatus_t ret = osThreadResume((osThreadId_t)thread_id);
     return ret;
@@ -178,168 +178,17 @@ void uapi_reboot_device(void)
 }
 
 
-
-#include "upg.h"
-#include "upg_porting.h"
-errcode_t uaip_cmd_update_request(void)
-{
-    errcode_t ret;
-    upg_prepare_info_t t = {0};
-    t.package_len = 4 ; //文件升级的前提下,只要package_len 大于0 即可。 
-    ret = uapi_upg_prepare(&t);
-    if (ret != ERRCODE_SUCC) {
-        printf("uapi_upg_prepare error = 0x%x\r\n", ret);
-        return ret;
-    } else {
-        printf("uapi_upg_prepare OK!!\r\n");
-    }
-    ret = uapi_upg_request_upgrade(false);
-    if (ret != ERRCODE_SUCC) {
-        printf("uapi_upg_request_upgrade error = 0x%x\r\n", ret);
-    } else {
-        printf("uapi_upg_request_upgrade OK!!\r\n");
-        /* app中下载后直接开始升级流程,升级流程结束后重启 */
-        // uapi_calendar_store_date();
-
-        update_version_report_log();//版本升级记录
-
-        shutdown_reboot_prejobs(UPDATE_TYPE);
-
-
-        //重启前要保存时间
-        // uapi_calendar_store_date();
-        // osDelay(50);
-        // reset_deal_with_fs();
-        // osDelay(50);
-        /* IOT设备重启 */
-       
-    }
-    return ret;
-}
-
-
 #include "systick.h"
 #include "sys/time.h"
 #include "time.h"
 #include "chip_system_time.h"
 
-errcode_t uapi_get_timestampe_ms(uint32_t *tm)
-{
-    struct timeval tv = { 0 };
-
-    if (gettimeofday(&tv, NULL)) {
-        return ERRCODE_FAIL;
-    }
-    *tm = (uint32_t)(tv.tv_sec*1000 + tv.tv_usec/1000 );
-        
-    return ERRCODE_SUCC;
-}
-
-/*获取秒级时间戳*/
-errcode_t uapi_get_timestampe_ss(uint32_t *tm)
-{
-    if (tm == NULL) {
-        return ERRCODE_FAIL;
-    }
- 
-    *tm = get_current_timestamp();
-    //printf("[timestamp:%u]\n", *tm);
-    return ERRCODE_SUCC;
-}
-
-errcode_t uapi_get_timestampe_ss_extend(uint32_t *tm,int year, int month, int day, int hour, int minute, int second) 
-{
-    if (tm == NULL) {
-        return ERRCODE_FAIL;
-    }
-    PRINT("year[%d],mon[%d],day[%d],hour[%d],min[%d],sec[%d] \n",year,month,day,hour,minute,second);
-    struct tm timeinfo;
-    timeinfo.tm_year = year - 1900;
-    timeinfo.tm_mon = month - 1;
-    timeinfo.tm_mday = day;
-    timeinfo.tm_hour = hour;
-    timeinfo.tm_min = minute;
-    timeinfo.tm_sec = second;
-    timeinfo.tm_isdst = -1;
-    *tm = mktime(&timeinfo);
-    return ERRCODE_SUCC;
-}
-
-errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_quarters)
-{    
-    return sync_time_utc(seconds,zone_quarters);
-}
-
-errcode_t uaip_sntp_set_time_utc(uint32_t seconds)
-{
-
-
-    int zone_quarters = uapi_get_timezone();
-   
-    errcode_t ret = sync_time_utc(seconds,zone_quarters);
-
-    time_t rawtime;
-    struct tm timeinfo;
-    time(&rawtime);
-    localtime_r(&rawtime,&timeinfo);
-
-    printf("uaip_sntp_set_time_utc set time success %04d-%02d-%02d %02d:%02d:%02d %d , ret %X\n",
-    timeinfo.tm_year + 1900,
-    timeinfo.tm_mon + 1,
-    timeinfo.tm_mday,
-    timeinfo.tm_hour,
-    timeinfo.tm_min,
-    timeinfo.tm_sec,zone_quarters,ret);
-    printf("utc timestamp %d , local timestamp %d, timezone %ld\n",get_current_timestamp(),get_local_timestamp(),timezone);
-    
-     return ERRCODE_SUCC;
-}
-/*已经包含timezone时间,*/
-errcode_t uaip_set_time_local(uint32_t seconds)
-{
-     int zone_quarters = uapi_get_timezone();
-
-    sync_time(seconds,zone_quarters);
-
-    time_t rawtime;
-    struct tm timeinfo;
-    time(&rawtime);
-    localtime_r(&rawtime,&timeinfo);
-
-    printf("uaip_set_time_local set time success %04d-%02d-%02d %02d:%02d:%02d %d\n",
-    timeinfo.tm_year + 1900,
-    timeinfo.tm_mon + 1,
-    timeinfo.tm_mday,
-    timeinfo.tm_hour,
-    timeinfo.tm_min,
-    timeinfo.tm_sec,zone_quarters);
-
-    printf("utc timestamp %d , local timestamp %d\n",get_current_timestamp(),get_local_timestamp());
-    
-    return ERRCODE_SUCC;
-
-}
-
-errcode_t uaip_set_time_local_full(uint32_t year,uint32_t month, uint32_t day, uint32_t hour,uint32_t minutes,uint32_t seconds)
-{
-    uint32_t allseconds=0;
-    struct tm tm = { 0 };
-    tm.tm_yday = year - 1900;
-    tm.tm_mon = month - 1;
-    tm.tm_mday = day;
-    tm.tm_hour = hour;
-    tm.tm_min = minutes;
-    tm.tm_sec = seconds;
-    allseconds = (uint32_t)__tm_to_secs(&tm);
-    return uaip_set_time_local(allseconds);
-}
-
 #define BITS_PER_BYTE               8
 #define HEXADECIMAL                 16
 #define DECIMAL                     10
-#define TIME_YEAR_OFFSET        123
-#define TIME_ZONE_OFF           (8 * 60)
-#define TIME_SECSPERMIN         60     /* second per minute */
+#define TIME_YEAR_OFFSET            123
+#define TIME_ZONE_OFF               (8 * 60)
+#define TIME_SECSPERMIN             60     /* second per minute */
 static uint32_t get_sec_time_from_cat1time(char* time , uint32_t *second , int *zone)
 {
 
@@ -544,7 +393,7 @@ static int decodeTime(char* time,uint32_t *timeseconds,int *zone)
     return 0;
     
 } 
-errcode_t uapi_set_time_from_cat1(char* cat1time)
+errcode_t cat1_set_time_from_cat1(char* cat1time)
 {
     int zone = 0;
      uint32_t sec = 0;
@@ -587,313 +436,54 @@ errcode_t uapi_set_time_from_cat1(char* cat1time)
     return ERRCODE_SUCC;
 }       
 
-/*
- * @brief 获取当地[年-月-日]日期
- * @return 格式为:[年.月.日]的字符串
-*/
-char *uapi_get_local_yyyymmdd_date(void)
-{
-
-    time_t rawtime;
-    struct tm* timeinfo;
-    time(&rawtime);
-    timeinfo = localtime(&rawtime);
-    char *buffer = (char*)malloc(80); // 动态分配内存
-    if(buffer == NULL)
-    {
-        return NULL; // 内存分配失败
-    }
-
-    // 格式化输出当前时间为 "YYYY-MM-DD HH:MM:SS" 形式
-    sprintf(buffer,"%04d.%02d.%02d\n",
-    timeinfo->tm_year + 1900,
-    timeinfo->tm_mon + 1,
-    timeinfo->tm_mday);
-    
-    return buffer;
-}
-
-/// @brief 获取日期
-errcode_t uapi_get_yyyymmddhhmmss_Date(char *date)
-{
-    if(date != NULL)
-    {
-        time_t rawtime;
-        struct tm* timeinfo;
-        time(&rawtime);
-        timeinfo = localtime(&rawtime);
-
-        sprintf(date,"%04d%02d%02d%02d%02d%02d",
-        timeinfo->tm_year + 1900,
-        timeinfo->tm_mon + 1,
-        timeinfo->tm_mday,
-        timeinfo->tm_hour,
-        timeinfo->tm_min,
-        timeinfo->tm_sec);
-    }
-    return ERRCODE_SUCC;
-}
 
+static time_ctl_funcs_t *g_cat1_time_funcs=NULL;
 
-/**
- * @param {uint32_t} time 时间戳
- * @param {char} *p_time 字符串
- * @param {char} date_separator 日期分隔符
- * @param {char} time_separator 时间分隔符
- * @param {date_format_t} format 日期格式选项
- * @brief 通过时间戳获取日期
- */
-errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format)
+/*sntp同步UTC 时间 , 采用默认timezone,或者已经保存的timezone*/
+errcode_t cat1_sntp_set_time_utc(uint32_t seconds)
 {
-    if (p_time == NULL)
+    if (g_cat1_time_funcs!=NULL)
     {
-        return ERRCODE_FAIL;
-    }
-
-    time_t rawtime = (time_t)time;
-    struct tm *timeinfo = localtime(&rawtime);
-
-    if (timeinfo == NULL)
-    {
-        return ERRCODE_FAIL;
-    }
-
-    switch (format)
-    {
-        case DATE_Y_M_D:
-            sprintf(p_time, "%04d%c%02d%c%02d", timeinfo->tm_year + 1900, date_separator, timeinfo->tm_mon + 1, date_separator, timeinfo->tm_mday);
-            break;
-        case DATE_Y_M_D_H_M:
-            sprintf(p_time, "%04d%c%02d%c%02d %02d%c%02d", timeinfo->tm_year + 1900, date_separator, timeinfo->tm_mon + 1, date_separator,
-                    timeinfo->tm_mday, timeinfo->tm_hour, time_separator, timeinfo->tm_min);
-            break;
-        case DATE_M_D:
-            sprintf(p_time, "%02d%c%02d", timeinfo->tm_mon + 1, date_separator, timeinfo->tm_mday);
-            break;
-        case DATE_H_M_S:
-            sprintf(p_time, "%02d%c%02d%c%02d", timeinfo->tm_hour, time_separator, timeinfo->tm_min, time_separator, timeinfo->tm_sec);
-            break;
-        case DATE_H_M:
-            sprintf(p_time, "%02d%c%02d", timeinfo->tm_hour, time_separator, timeinfo->tm_min);
-            break;
-        case DATE_M_S:
-            sprintf(p_time, "%02d%c%02d", timeinfo->tm_min, time_separator, timeinfo->tm_sec);
-            break;
-        case DATE_M_D_H_M:
-            sprintf(p_time, "%02d%c%02d %02d%c%02d", timeinfo->tm_mon + 1, date_separator, timeinfo->tm_mday, timeinfo->tm_hour, time_separator, timeinfo->tm_min);
-            break;
-        default:
-            sprintf(p_time, "%04d%c%02d%c%02d %02d%c%02d%c%02d", timeinfo->tm_year + 1900, date_separator, timeinfo->tm_mon + 1, date_separator,
-                    timeinfo->tm_mday, timeinfo->tm_hour, time_separator, timeinfo->tm_min, time_separator, timeinfo->tm_sec);
-            break;
-    }
+        if (g_cat1_time_funcs->sync_time_utc!=NULL && g_cat1_time_funcs->get_timezone!=NULL)
+        {
+            uint16_t timezone=g_cat1_time_funcs->get_timezone();
 
-    return ERRCODE_SUCC;
-}
-/**
- * @param {char} *p_time
- * @param {char} 隔断符
- * @brief 获取日期
- */
-errcode_t uapi_get_YYMMDD_Time(char *p_time, char separator)
-{
-    if (p_time == NULL)
-    {
-        return ERRCODE_FAIL; // 返回空指针错误码
+            return g_cat1_time_funcs->sync_time_utc(seconds,timezone);
+        }
+        return ERRCODE_SUCC;
     }
-
-    time_t currtime;
-    struct tm *timeinfo;
-    time(&currtime);
-    timeinfo = localtime(&currtime);
-
-    // 根据传入的分隔符参数选择中间分隔符
-    char sep[2] = {separator, '\0'};
-
-    // 将年月日信息存储到 p_time 变量中,使用指定的分隔符
-    sprintf(p_time, "%02d%s%02d%s%02d", timeinfo->tm_year + 1900, sep, timeinfo->tm_mon + 1, sep, timeinfo->tm_mday);
-
-    return ERRCODE_SUCC;
+    return ERRCODE_FAIL;
+    
 }
 
 /**
- * @param {char} *p_time
- * @param {char} 隔断符
- * @param {uint8_t} n天前
- * @brief 获取日期
- */
-errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,int8_t day)
-{
-    if (p_time == NULL)
-    {
-        return ERRCODE_FAIL; // 返回空指针错误码
-    }
-
-    time_t currtime;
-    struct tm *timeinfo;
-    time(&currtime);
-    currtime=currtime-day*24*60*60;
-   // printf("uapi_get_YYMMDD_Time_extend : %d\r\n",currtime);
-
-    timeinfo = localtime(&currtime);
-
-
-    // 根据传入的分隔符参数选择中间分隔符
-    char sep[2] = {separator, '\0'};
-
-    // 将年月日信息存储到 p_time 变量中,使用指定的分隔符
-    sprintf(p_time, "%02d%s%02d%s%02d", timeinfo->tm_year + 1900, sep, timeinfo->tm_mon + 1, sep, timeinfo->tm_mday);
-
-    return ERRCODE_SUCC;
-}
-/**
- * @param {char} *p_time
- * @param {char} 隔断符
- * @param {bool} 是否包含秒
- * @brief 获取时间
- */
-errcode_t uapi_get_HHMMSS_Time(char *p_time, char separator, bool include_seconds)
-{
-    if (p_time == NULL)
-    {
-        return ERRCODE_FAIL; // 返回空指针错误码
-    }
-
-    time_t currtime;
-    struct tm *timeinfo;
-    time(&currtime);
-    timeinfo = localtime(&currtime);
-
-    // 根据传入的分隔符参数选择中间分隔符
-    char sep[2] = {separator, '\0'};
-
-    // 根据传入的 include_seconds 参数决定是否包含秒
-    if (include_seconds)
-    {
-        sprintf(p_time, "%02d%s%02d%s%02d", timeinfo->tm_hour, sep, timeinfo->tm_min, sep, timeinfo->tm_sec);
-    }
-    else
-    {
-        sprintf(p_time, "%02d%s%02d", timeinfo->tm_hour, sep, timeinfo->tm_min);
-    }
-
-    return ERRCODE_SUCC;
-}
-/*打印时间戳*/
-void print_current_time(void)
+ * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑
+ *         用来实现sntp的时间同步,包含timezone的存储和utc时间同步
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+ * */
+errcode_t cat1_register_time_ctl_functions(time_ctl_funcs_t *funcs)
 {
-    char current_time[9]; // 分配内存给current_time
-    if (uapi_get_HHMMSS_Time(current_time, ':', true) != ERRCODE_SUCC)
-    {
-        return;
-    }
-    printf("Current_time: %s\n", current_time);
-
-    uint32_t tm;
-    if(uapi_get_timestampe_ms(&tm) != ERRCODE_SUCC)
-    {
-        return;
-    }
-    printf("Current timestamp in milliseconds: %u\n", tm);
+        g_cat1_time_funcs = funcs;
+        return ERRCODE_SUCC;
 }
-const char *weekDays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
-errcode_t uapi_get_WeekStr(char *p_week)
-{
-    time_t currtime;
-    struct tm *timeinfo;
-    time(&currtime);
-    timeinfo = localtime(&currtime);
 
-    // 获取星期信息
-    strcpy(p_week, weekDays[timeinfo->tm_wday]);
-
-    return ERRCODE_SUCC; // 假设成功获取星期信息
-}
-
-/*系统声音设置*/
-void uapi_systemVolumeSet(int32_t sounding)
-{
-    #ifdef FD230
-    SystemVolumeSet(sounding);
-    #endif
-}
-
-/*系统声音获取*/
-int uapi_systemVolumeGet(void)
-{
-    return SystemVolumeGet();
-}
-
-//通话音量设置
-void uapi_callVolumeSet(int32_t sounding)
-{
-    #ifdef FD230
-    CallVolumeSet(sounding);
-    #endif
-}
-
-//通话音量获取
-int uapi_callVolumeGet(void)
-{
-    return CallVolumeGet();
-}
-
-#ifdef SUPPORT_CAT1_SERVICE
-
-void power_on_cat1(void)
-{
-    #ifdef FD230
-    uapi_cat1_power_on(1);    
-    uapi_cat1_reset(0);
-    #else
-    uapi_cat1_reset(0);
-    uapi_cat1_power_on(1);  
-    uapi_cat1_bat_on(1);
-    osDelay(900);
-    uapi_cat1_power_on(0);  
-    #endif
- 
-}
-
-void power_off_cat1(void)
-{
-    #ifdef FD230
-    uapi_cat1_reset(1);
-    uapi_cat1_power_on(0); 
-    #else
-    uapi_cat1_bat_on(0);
-    uapi_cat1_reset(1);
-    uapi_cat1_power_on(1); 
-    #endif
-}
-
-
-#else
-void power_on_cat1(void)
-{
-}
-void power_off_cat1(void)
-{
-}
-
-#endif
 //设置4G能力开关是否开启
-void uapi_set4GCapability(bool isopen)
+void cat1_api_enable_cat1(bool isopen)
 {
     errcode_t ret = 0;
     void *tcp_thread_id = NULL;
     if(isopen)
     {
         power_on_cat1();
-        // if(!uapi_dev_runtime_get_saveele_status())
+        // if(!cat1_api_runtime_get_saveele_status())
         {
-            uapi_dev_runtime_set_cat1_powerstat(1);
+            // cat1_api_runtime_set_cat1_powerstat(1);
         }
         /*4G 开电有时有干扰进日志串口,因此关闭日志串口*/
-        // uapi_custom_set_uart_rx_enable_flag(false);
+        cat1_api_custom_enable_cmd_rx(false);
 
             tcp_thread_id = tcp_get_thread_id();
-            ret = uapi_resume_thread(tcp_thread_id);
+            ret = cat1_resume_thread(tcp_thread_id);
             if(ret != ERRCODE_SUCC)
                 PRINT("tcpip_thread_resume failed ret : %d \n",ret);
             else
@@ -902,16 +492,16 @@ void uapi_set4GCapability(bool isopen)
     else
     {
         power_off_cat1();
-        // if(!uapi_dev_runtime_get_saveele_status())
+        // if(!cat1_api_runtime_get_saveele_status())
         {
-            uapi_dev_runtime_set_cat1_powerstat(0);
+            // cat1_api_runtime_set_cat1_powerstat(0);
         }
         /*4G 开电有时有干扰进日志串口,因此关闭4G才开启日志串口*/
-        uapi_custom_set_uart_rx_enable_flag(true);
+        cat1_api_custom_enable_cmd_rx(true);
     
-        uapi_cat1_remove_cat1_vote();
+        cat1_api_remove_cat1_vote();
         tcp_thread_id = tcp_get_thread_id();
-        ret = uapi_suspend_thread(tcp_thread_id);
+        ret = cat1_suspend_thread(tcp_thread_id);
         if(ret != ERRCODE_SUCC)
             PRINT("tcpip_thread_suspend failed ret : %d \n",ret);
         else
@@ -919,6 +509,7 @@ void uapi_set4GCapability(bool isopen)
     }
 }
 
+
 #include <sys/stat.h>
 
 int removeFilesInFolder(const char *folderPath) 
@@ -1162,7 +753,7 @@ static bool g_enable_uart_rx = true;
  *        true 代表 接收缓存
  *        false 代表 不接收缓存
 */
-bool uapi_custom_uart_rx_enable_flag(void)
+bool cat1_api_custom_is_cmd_rx_enabled(void)
 {
     #ifdef SUPPORT_AUTO_OTA
         return true;
@@ -1175,7 +766,7 @@ bool uapi_custom_uart_rx_enable_flag(void)
 /**
  * 设置 uart rx enable flag
 */
-void uapi_custom_set_uart_rx_enable_flag(bool enable_uart)
+void cat1_api_custom_enable_cmd_rx(bool enable_uart)
 {
     g_enable_uart_rx = enable_uart;
 }
@@ -1206,7 +797,7 @@ errcode_t uapi_get_nv_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr)
     uint32_t max_input_len = *len_btaddr;
     memcpy_s(buf_btaddr,max_input_len,btinfo.bd_addr,sizeof(btinfo.bd_addr));
     *len_btaddr = sizeof(btinfo.bd_addr);
-    printf("get nv local_addr : ******%02x%02x%02x\n", buf_btaddr[3], buf_btaddr[4], buf_btaddr[5]);
+    // printf("get nv local_addr : ******%02x%02x%02x\n", buf_btaddr[3], buf_btaddr[4], buf_btaddr[5]);
 
 #endif
 
@@ -1236,7 +827,7 @@ errcode_t uapi_set_nv_btaddr(uint8_t *buf_btaddr, uint32_t len_btaddr)
       
         return nvRet; 
     } 
-    printf("set nv local_addr : ******%02x%02x%02x\n", buf_btaddr[3], buf_btaddr[4], buf_btaddr[5]);
+    cat1_print_warning("set nv local_addr : ******%02x%02x%02x\n", buf_btaddr[3], buf_btaddr[4], buf_btaddr[5]);
     
 #endif
     
@@ -1244,21 +835,28 @@ errcode_t uapi_set_nv_btaddr(uint8_t *buf_btaddr, uint32_t len_btaddr)
 }
 
 
-
-errcode_t permition_verify(void)
+static uint8_t g_device_info[64]={0};
+uint8_t *cat1_get_devid(void)
 {
-
     errcode_t ret ;
     uint8_t bd_addr[BD_ADDR_LEN]={0};
-    uint8_t name[BTSDK_DEVNAME_LEN]={0};
     uint32_t  addrlen = sizeof(bd_addr);
     ret = uapi_get_nv_btaddr(bd_addr,&addrlen);
     if (ret != ERRCODE_SUCC) { 
         /* ERROR PROCESS */ 
-        printf("uapi_get_nv_btaddr failed ret %d , addrlen %d\n",ret,addrlen);
+        cat1_print_err("get_nv_btaddr failed ret %d , addrlen %d\n",ret,addrlen);
         return ERRCODE_FAIL; 
     } 
-
+    uint8_t soc_id[20]={0}; // 20 is soc id length
+    uapi_soc_read_id(soc_id, 20); // 20 is soc id length
+    uint16_t sum = 0x0;
+    for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits
+        uint16_t ptmp16= *((uint16_t *)&soc_id[i]);
+        sum += ptmp16;
+        sprintf(&g_device_info[i*2],"%04X", ptmp16);
+        // if ((i + 2) % 8 == 0) { printf("\r\n"); } // 2&8 will word wrap
+    }
+    
  //如果  281106856959
     if ( bd_addr[5] == 0x59 &&
         bd_addr[4] == 0x69 &&
@@ -1268,20 +866,86 @@ errcode_t permition_verify(void)
         bd_addr[0] == 0x28 )
     {   
         
-        uint8_t soc_id[20]; // 20 is soc id length
-        uapi_soc_read_id(soc_id, 20); // 20 is soc id length
-        uint16_t sum = 0x0;
-        printf("[soc id:]\r\n");
-        for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits
-            uint16_t ptmp16= *((uint16_t *)&soc_id[i]);
-            sum += ptmp16;
-            printf("0x%04X  ", ptmp16);
-            if ((i + 2) % 8 == 0) { printf("\r\n"); } // 2&8 will word wrap
-        }
-        printf("get socid sum 0x%04X\r\n",sum);       
+        srand(sum);
+        //默认是:281106856959
+        cat1_print_warning("是默认值,修改地址\n");
+        bd_addr[3] = rand() % 0xFF;  
+        bd_addr[4] = rand() % 0xFF;
+        bd_addr[5] = rand() % 0xFF;
+
+        cat1_print_warning("uapi_set_nv_btaddr : ******%02x%02x%02x\n", bd_addr[3], bd_addr[4], bd_addr[5]);
+        ret = uapi_set_nv_btaddr(bd_addr, addrlen);
+        if (ret != ERRCODE_SUCC) { 
+            /* ERROR PROCESS */ 
+            cat1_print_err("uapi_set_nv_btaddr failed ret %d\n",ret);
+            return ERRCODE_FAIL; 
+        } 
 
     }
+    sprintf_s(&g_device_info[40],24,"%02X%02X%02X%02X%02X%02X",bd_addr[0],bd_addr[1],bd_addr[2],bd_addr[3],bd_addr[4],bd_addr[5]);
+    // printf("get socid %s\r\n",g_device_info);
+    return &g_device_info[0];
+}
 
-    return ERRCODE_SUCC;
+/***
+ * 
+ed25519
+-----BEGIN OPENSSH PRIVATE KEY-----
+481anNy7bmDFuP14MGt3IkbwHWw2XF0Wz/rRgvGW0hA=
+-----END OPENSSH PRIVATE KEY-----
+pubkey
+hZjSYq6zqk0wpoS9832kU17tk3695esgtPoP982gMe4=
+
+socid
+5DD457905600274442D744A6030A0F78824300011C1D2BB841B8
+
+signature
+
+jS9ymjuCk47AtHaefOYhrEmFyVqIEENC8wc5aknsj2j7mF/T+2hVUv+WTMqYpLciI+9AiJt9jETtd18jtXr8BA==
+
+
+=============rsa
+
+摘要算法SHA1
+
+-----BEGIN RSA PRIVATE KEY-----
+MIIBOwIBAAJBAJ4yb9/P7pSlneSg72zIwmASaDXl8FX4ZCKqrDUHQ8oj2UyWYrId
+H053CrMin45E7pjXSnCTenrG0arstP+OQ60CAwEAAQJAGOLi1hDiHZjDMrr9hz26
+1D25DpeOXBvf9tMmFY5/w83qE72IjEUD/giEVJIYNWOppQfnHDS1TdTzySz6nNSV
+IQIhAM6p5ALOg2ljE8LQSIkYBzpf3BNpaYeiZLEqggMr9M6hAiEAw/aKqbD3/jz4
+KfGz31AcN/7DoKfhQyDux0mQpcz9VY0CIQCI7FzKU0MT5vXnxBHa6xWW4n4wSk4F
+9F0cWJqNOWlYIQIhAKQfD/Me7BRaK921ONiG15tuG5mqANef9VujGSpDjMjhAiAy
+6Gx/pTOjVXkpmgs/9Zt4vUft0y3ZhzUPFZxwKtxDPw==
+-----END RSA PRIVATE KEY-----
+-----BEGIN PUBLIC KEY-----
+MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ4yb9/P7pSlneSg72zIwmASaDXl8FX4
+ZCKqrDUHQ8oj2UyWYrIdH053CrMin45E7pjXSnCTenrG0arstP+OQ60CAwEAAQ==
+-----END PUBLIC KEY-----
 
+
+signature
+NRQcvn1gp+JCeYA9EJU/0RzbKFQenqWqQUFJyckUgecqx8RYthHvNDi7I1R16PJ0H8yl7qZ3eC3h1GEaKCTrww==
+*/
+
+const uint8_t sign_str[]="NRQcvn1gp+JCeYA9EJU/0RzbKFQenqWqQUFJyckUgecqx8RYthHvNDi7I1R16PJ0H8yl7qZ3eC3h1GEaKCTrww==";
+const uint8_t pubkey_str[]="-----BEGIN PUBLIC KEY-----\nMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ4yb9/P7pSlneSg72zIwmASaDXl8FX4\nZCKqrDUHQ8oj2UyWYrIdH053CrMin45E7pjXSnCTenrG0arstP+OQ60CAwEAAQ==\n-----END PUBLIC KEY-----";
+
+const uint8_t *devid_str[]={"5DD457905600274442D744A6030A0F78824300011C1D2BB841B8","5DD457905600274442D744A6030A0F78824300011C1D2BB841B8"};
+
+errcode_t permition_verify(void)
+{
+    uint8_t *devid = cat1_get_devid();
+    cat1_print_info("[socid]%s\r\n",devid);
+    int devlist_size = sizeof(devid_str)/sizeof(devid[0]);
+
+    cat1_print_info("[keylist]%d\r\n",devlist_size);
+    for(int i=0;i<devlist_size;i++)
+    {
+        if( strncmp(devid,devid_str[i],52) == 0)
+        {
+            return ERRCODE_SUCC;
+        }
+    }
+    
+    return ERRCODE_FAIL;
 }
index b895f17..a37589a 100644 (file)
@@ -2,49 +2,43 @@
 #ifndef __CAT1_CTL_H\r
 #define __CAT1_CTL_H\r
 \r
-#include "stdint.h"\r
-#include "platform_core.h"\r
 \r
 #ifdef __cplusplus\r
-#if __cplusplus\r
 extern "C" {\r
 #endif /* __cplusplus */\r
-#endif /* __cplusplus */\r
 \r
+#include "stdint.h"\r
+#include "platform_core.h"\r
+\r
+\r
+void cat1_api_gpio_init(void);\r
+void cat1_api_uart_init(void);\r
 \r
 /**set powerpin 1/0*/\r
-uint32_t uapi_cat1_power_on(uint32_t pwron);\r
+uint32_t cat1_api_cat1_power_on(uint32_t pwron);\r
 /**set resetpin 0/1*/\r
-uint32_t uapi_cat1_reset(uint32_t pwron);\r
+uint32_t cat1_api_cat1_reset(uint32_t pwron);\r
 \r
-uint32_t uapi_cat1_bat_on(uint32_t pwron);\r
+uint32_t cat1_api_cat1_bat_on(uint32_t pwron);\r
 \r
-/**���Ϻ�����set powerpin 1 ��set resetpin 0*/\r
+/**set powerpin 1 ,set resetpin 0*/\r
 void power_on_cat1(void);\r
-/**���Ϻ�����set powerpin 0 ��set resetpin 1*/\r
+/**set powerpin 0 ,set resetpin 1*/\r
 void power_off_cat1(void);\r
 \r
-void cat1_ring_isr_callback(pin_t pin, uintptr_t param);\r
-int32_t uapi_cat1_start_volte_voice(void);\r
-\r
-int32_t uapi_cat1_stop_volte_voice(void);\r
-\r
-uint8_t volte_voice_state(void);\r
+void cat1_api_wakeup_cat1(uint8_t wakeup);\r
+void cat1_api_keep_wakeup(uint8_t keep_wakeup);\r
 \r
-int32_t uapi_cat1_start_SCO_volte_voice(void);\r
+void cat1_suspend(void);\r
+void cat1_resume(void);\r
 \r
-void uapi_cat1_remove_cat1_vote(void);\r
-void uapi_cat1_add_cat1_vote(void);\r
-void uapi_cat1_wakeup_cat1(uint8_t wakeup);\r
-void uapi_cat1_keep_wakeup(uint8_t keep_wakeup);\r
-bool uapi_cat1_get_power_stat(void);\r
-\r
-void uapi_cat1_suspend(void);\r
-void uapi_cat1_resume(void);\r
+/**\r
+ * @brief cat1唤醒蓝牙中断处理函数,要加入 board_evb.h 或者自己配置到gpio中断中\r
+ * \r
+*/\r
+void cat1_ring_isr_callback(pin_t pin, uintptr_t param);\r
 \r
 #ifdef __cplusplus\r
-#if __cplusplus\r
 }\r
 #endif /* __cplusplus */\r
-#endif /* __cplusplus */\r
 #endif\r
diff --git a/code/sdk/zhihui/4g/cat1Service/include/cat1_log.h b/code/sdk/zhihui/4g/cat1Service/include/cat1_log.h
new file mode 100644 (file)
index 0000000..1dc42fc
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
+ *
+ * Description: Board log port. \n
+ *
+ * History: \n
+ * 2023-05-06, Create file. \n
+ */
+#ifndef CAT1_LOG_PORT_H
+#define CAT1_LOG_PORT_H
+
+#include <stdio.h>
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+extern uint8_t g_cat1_enable_debug;
+typedef enum{
+    CAT1_LOG_LEVEL_ERROR,
+    CAT1_LOG_LEVEL_WARNING,
+    CAT1_LOG_LEVEL_INFO,
+    CAT1_LOG_LEVEL_DBG,
+    CAT1_LOG_LEVEL_MAX
+} CAT1_LOG_LEVEL_E;
+/* 通过printf直接打印,不需要日志时需要注释掉define后半部分. */
+#define cat1_print_dbg(fmt, args...)         { if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_DBG)  printf("[CAT1_DBG]" fmt "\n", ##args);}
+#define cat1_print_info(fmt, args...)        { if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_INFO)  printf("[CAT1_INFO]" fmt "\n", ##args);}
+#define cat1_print_warning(fmt, args...)     { if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_WARNING) printf("[CAT1_WRN]" fmt "\n", ##args);}
+#define cat1_print_err(fmt, args...)         { if (g_cat1_enable_debug>=CAT1_LOG_LEVEL_ERROR) printf("[CAT1_ERR]" fmt "\n", ##args);}
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
diff --git a/code/sdk/zhihui/4g/cat1Service/include/cat1_porting.h b/code/sdk/zhihui/4g/cat1Service/include/cat1_porting.h
new file mode 100644 (file)
index 0000000..1ef3cd7
--- /dev/null
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n
+ *
+ * Description: Button driver header file \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2023-02-24, Create file. \n
+ */
+#ifndef CAT1_PORTING_H
+#define CAT1_PORTING_H
+#include "cat1_types.h"
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/***********用户需要实现的代码***********/
+
+
+int32_t cat1_api_start_cat1_volte_voice(void);
+
+int32_t cat1_api_stop_cat1_volte_voice(void);
+
+uint8_t cat1_api_get_cat1_volte_voice_state(void);
+
+
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
diff --git a/code/sdk/zhihui/4g/cat1Service/include/cat1_pub_api.h b/code/sdk/zhihui/4g/cat1Service/include/cat1_pub_api.h
new file mode 100644 (file)
index 0000000..378f737
--- /dev/null
@@ -0,0 +1,115 @@
+#ifndef CAT1_PUB_API_H
+#define CAT1_PUB_API_H
+
+#include "cat1_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/***************移植过程中系统需要使用的函数*******************/
+
+
+/**
+ * @brief 串口接收函数,加入到uart_porting 中断处理中 
+*/
+void cat1_uart_receive_handler(uint8_t *buffer, int32_t size);
+
+/**
+ * return cmd uart rx enable flag
+ *        true 代表 接收缓存
+ *        false 代表 不接收缓存
+*/
+bool cat1_api_custom_is_cmd_rx_enabled(void);
+
+/**
+ * @brief cat1 服务初始化.
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_server_init(void);
+
+/**
+ * @brief cat1 开关机设置, 输入 true 开机, false 关机
+*/
+void cat1_api_enable_cat1(bool isopen);
+
+/**
+ * @brief 获取cat1是否使能(开机)状态
+ * 
+*/
+bool cat1_api_is_cat1_enabled(void);
+
+/**
+ * @brief 用户实现,在cat1指令执行完毕后,取消投票
+*/
+void cat1_api_remove_cat1_vote(void);
+/**
+ * @brief 用户实现,在cat1指令执行前,添加投票
+*/
+void cat1_api_add_cat1_vote(void);
+
+/**
+ * @brief 发送指令给Cat1,输入 CMD_4G_T , cmd_buf 为指令所需参数.
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_cmd_send(CMD_4G_T cmd,void *cmd_buf,uint16_t cmdlen);
+
+/**
+ * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+ * */
+errcode_t cat1_register_msg_callback(f_cat1_msg_callback func);
+
+
+/**
+ * @brief 注册控制4G的gpio值,包括控制电源以及唤醒中断的IO
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_register_ctl_pin(ctl_pin_4g_t ctl_pin);
+
+/**
+ * @brief 注册消息回调函数,需要用户自己实现回调函数处理逻辑
+ *         用来实现sntp的时间同步,包含timezone的存储和utc时间同步
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+ * */
+errcode_t cat1_register_time_ctl_functions(time_ctl_funcs_t *funcs);
+
+/***
+ * @brief 移植初始化代码,需要用户实现,开机会被 cat1_server_init()执行
+ * 
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+errcode_t cat1_api_porting_init(void);
+
+/**
+ * @brief 唤醒Cat1,开放给自定义cat1操作时使用,防止cat1 没有被唤醒,标准指令内部都已经执行了该指令,并且执行完内部指令后,会自动关闭唤醒cat1的io
+*/
+void cat1_api_wakeup_cat1(uint8_t wakeup);
+
+/**
+ * @brief 保持唤醒Cat1,开放给自定义cat1操作时使用,keep_wakeup=1 可以防止cat1 在执行内部指令后被自动关闭。keep_wakeup = 0后 标准指令执行完毕io会被自动关闭。
+*/
+void cat1_api_keep_wakeup(uint8_t keep_wakeup);
+
+/**
+ * @brief 用户自行实现,根据业务需要,确认是否5秒更新一次信号强度
+ * @return 1 需要更新信号 0 停止跟新信号
+*/
+uint8_t cat1_api_need_update_signal(void);
+
+/******************* get Cat1 runtime status **********************/
+uint8_t cat1_api_runtime_get_cat1_powerstat(void);
+uint8_t cat1_api_runtime_get_cat1_networkstat(void);
+int cat1_api_runtime_get_cat1_signal(void);
+int cat1_api_runtime_get_cat1_simstat(void);
+uint8_t cat1_api_runtime_get_cat1_networktype(void);    
+// char* cat1_api_runtime_get_cat1_operator(void);  //暂未解析  
+char* cat1_api_runtime_get_cat1_imei(void);    
+char* cat1_api_runtime_get_cat1_pyver(void);    
+char* cat1_api_runtime_get_cat1_modemver(void);    
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
\ No newline at end of file
index df57caf..487a3ba 100644 (file)
 #include <stdio.h>
 #include "errcode.h"
 #include "soc_osal.h"
+#include "cat1_types.h"
 
 #ifdef __cplusplus
-#if __cplusplus
 extern "C" {
 #endif /* __cplusplus */
-#endif /* __cplusplus */
 
-typedef enum{
-    CAT1_2G,
-    CAT1_3G,
-    CAT1_4G,
-    CAT1_5G
-} cat1_network_type_t;
 
 /**
  * 获取 设备实时状态变量
  * 详细内容见 runtime_status_t 定义
 */
-// runtime_status_t * get_device_runtime_status(void);
-
-/**
- * 设置 dialname
-*/
-void uapi_dev_runtime_set_dialname(char* dialname);
-/**
- * 获取 dialname
-*/
-char* uapi_dev_runtime_get_dialname(void);
-
-
-void uapi_dev_runtime_set_vibmod(uint8_t vibmod);
-
-uint8_t uapi_dev_runtime_get_vibmod(void);
-
-void uapi_dev_runtime_set_sleep_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_sleep_status(void);
-void uapi_dev_runtime_set_nap_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_nap_status(void);
-
-// 睡眠监测模式状态设置及获取
-// 从睡眠整个功能开始触发到退出
-// 1-active; 0-deactive
-void uapi_dev_runtime_set_sleep_monitoring_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_sleep_monitoring_status(void);
-
-void uapi_dev_runtime_set_nap_monitoring_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_nap_monitoring_status(void);
-void uapi_dev_runtime_set_sedentary_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_sedentary_status(void);
-void uapi_dev_runtime_set_drinkremind_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_drinkremind_status(void);
-
-/*
-    设置训练状态
-    0 未训练;训练结束
-    1 训练中
-*/
-void uapi_dev_runtime_set_train_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_train_status(void);
-
-/*
-    设置训练状态
-    0 未开启省电
-    1 开启省电模式
-*/
-void uapi_dev_runtime_set_saveele_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_saveele_status(void);
-
-/*
-    设置密码锁状态
-    0 未开启密码锁
-    1 开启密码锁
-*/
-void uapi_dev_runtime_set_lock_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_lock_status(void);
-
-/*
-    校验状态
-    0 未校验
-    1 校验中
-    2 校验成功
-    3 校验失败
-*/
-void uapi_dev_runtime_set_checkres_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_checkres_status(void);
-
-/*
-    修复下载状态
-    0 未修复
-    1 正在修复
-    2 修复成功
-    3 修复失败
-*/
-void uapi_dev_runtime_set_repair_download_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_repair_download_status(void);
-
-/*
-    读写锁状态
-    0 未锁定
-    1 锁定
-*/
-void uapi_dev_runtime_set_rwlock_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_rwlock_status(void);
-
-/*
-    训练存储
-    0 未存储
-    1 正在存储
-*/
-void uapi_dev_runtime_set_train_storage_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_train_storage_status(void);
-
-/*
-    心率存储
-    0 未存储
-    1 正在存储
-*/
-void uapi_dev_runtime_set_heartrate_storage_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_heartrate_storage_status(void);
-
-/*
-    血氧存储
-    0 未存储
-    1 正在存储
-*/
-void uapi_dev_runtime_set_bloodoxygen_storage_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void);
-
-/*
-    睡眠存储
-    0 未存储
-    1 正在存储
-*/
-void uapi_dev_runtime_set_sleep_storage_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_sleep_storage_status(void);
-
-/*
-    每日目标数据存储
-    0 未存储
-    1 正在存储
-*/
-void uapi_dev_runtime_set_goal_storage_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_goal_storage_status(void);
-
-/*
-    主动检测心率
-    0 未开启
-    1 开启
-*/
-void uapi_dev_runtime_set_heartrate_detect_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_heartrate_detect_status(void);
-
-
-/*运动识别*/
-void uapi_dev_runtime_set_motion_recognition_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_motion_recognition_status(void);
-
-
-//呼吸训练
-void uapi_dev_runtime_set_respiratory_training_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_respiratory_training_status(void);
-
-//设置屏幕是否常亮
-void uapi_dev_runtime_set_screen_always_on_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_screen_always_on_status(void);
-
-//关机状态
-void uapi_dev_runtime_set_shutting_down_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_shutting_down_status(void);
 /***************************************cat1 runtime 变量设置获取函数**************************************************/
 
+void cat1_api_runtime_set_cat1_powerstat(uint8_t cat1_powerOn);
+uint8_t cat1_api_runtime_get_cat1_powerstat(void);
 
-void uapi_dev_runtime_set_cat1_powerstat(uint8_t cat1_powerOn);
-uint8_t uapi_dev_runtime_get_cat1_powerstat(void);
-
-void uapi_dev_runtime_set_cat1_networkstat(uint8_t network_on);
-uint8_t uapi_dev_runtime_get_cat1_networkstat(void);
+void cat1_api_runtime_set_cat1_networkstat(uint8_t network_on);
+uint8_t cat1_api_runtime_get_cat1_networkstat(void);
 
-void uapi_dev_runtime_set_cat1_signal(int signal);
-int uapi_dev_runtime_get_cat1_signal(void);
+void cat1_api_runtime_set_cat1_signal(int signal);
+int cat1_api_runtime_get_cat1_signal(void);
 
-void uapi_dev_runtime_set_cat1_simstat(int simstat);
-int uapi_dev_runtime_get_cat1_simstat(void);
+void cat1_api_runtime_set_cat1_simstat(int simstat);
+int cat1_api_runtime_get_cat1_simstat(void);
 
-void uapi_dev_runtime_set_cat1_networktype(uint8_t networtype);
-uint8_t uapi_dev_runtime_get_cat1_networtype(void);    
+void cat1_api_runtime_set_cat1_networktype(uint8_t networtype);
+uint8_t cat1_api_runtime_get_cat1_networktype(void);    
 
 
-void uapi_dev_runtime_set_cat1_operator(char* cat1_operator);
-char* uapi_dev_runtime_get_cat1_operator(void);    
+void cat1_api_runtime_set_cat1_operator(char* cat1_operator);
+char* cat1_api_runtime_get_cat1_operator(void);    
 
-void uapi_dev_runtime_set_cat1_imei(char* cat1_operator);
-char* uapi_dev_runtime_get_cat1_imei(void);    
+void cat1_api_runtime_set_cat1_imei(char* cat1_operator);
+char* cat1_api_runtime_get_cat1_imei(void);    
 
-void uapi_dev_runtime_set_cat1_pyver(char* cat1_operator);
-char* uapi_dev_runtime_get_cat1_pyver(void);    
+void cat1_api_runtime_set_cat1_pyver(char* cat1_operator);
+char* cat1_api_runtime_get_cat1_pyver(void);    
 
-void uapi_dev_runtime_set_cat1_modemver(char* cat1_operator);
-char* uapi_dev_runtime_get_cat1_modemver(void);    
+void cat1_api_runtime_set_cat1_modemver(char* cat1_operator);
+char* cat1_api_runtime_get_cat1_modemver(void);    
 
 
-/***************************************蓝牙runtime 变量设置获取函数**************************************************/
-/**
- * 设置蓝牙开关状态
-*/
-void uapi_dev_runtime_set_bt_powerstat(uint8_t stat);
-/**
- * 设置ble(手机协议)连接状态 1连接, 0 未连接
-*/
-void uapi_dev_runtime_set_ble_connect_stat(uint8_t connect);
-/**
- * 设置经典蓝牙协议连接状态, 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp
-*/
-void uapi_dev_runtime_set_br_connect_stat(uint8_t  connect);
-/**
- *  设置耳机连接状态 1连接, 0 未连接
-*/
-void uapi_dev_runtime_set_earphone_connect_stat(uint8_t  connect);
-
-/**
- * 获取蓝牙电源状态 1开启0 关闭
-*/
-uint8_t uapi_dev_runtime_get_bt_powerstat(void);
-/**
- * 获取ble(手机协议)连接状态 1 连接,0 未连接
-*/
-uint8_t uapi_dev_runtime_get_ble_connect_stat(void);
-
-/**
- * 获取经典蓝牙协议连接状态, 0 未连接, 1 连接a2dp 2 连接hfp 3 连接 a2dp+hfp
-*/
-uint8_t uapi_dev_runtime_get_br_connect_stat(void);
-/**
- * 获取耳机连接状态 1连接, 0 未连接
-*/
-uint8_t uapi_dev_runtime_get_earphone_connect_stat(void);
-
-/**
- * 设置 android app connect status
-*/
-void uapi_dev_runtime_set_android_connection_status(uint8_t is_android);
-/**
- * 获取 android app connect status
-*/
-uint8_t uapi_dev_runtime_get_android_connection_status(void);
-
-/**
- *
-*/
-void uapi_dev_runtime_sync_runtime_env_to_config(void);
-
-
-uint8_t uapi_dev_runtime_get_time_hour_show_model(void);
-void uapi_dev_runtime_set_time_hour_show_model(uint8_t hour_type);
-
-void uapi_dev_runtime_set_ancs_clientid(uint16_t clientid);
-uint16_t uapi_dev_runtime_get_ancs_clientid(void);
-
-
-// sleep mode flag
-void uapi_sleep_mode_flag_set(uint8_t flag);
-uint8_t uapi_sleep_mode_flag_get(void);
-
-void uapi_dev_runtime_set_absolute_static_status(uint8_t status);
-uint8_t uapi_dev_runtime_get_absolute_static_status(void);
-
-
-// 安全模式
-void uapi_dev_runtime_set_safemode_flag(uint8_t status);
-// 安全模式
-uint8_t uapi_dev_runtime_get_safemode_flag(void);
-
-
-void uapi_dev_runtime_set_hrs_passivity(uint8_t status);
-// 获取被动心率检测状态
-uint8_t uapi_dev_runtime_get_hrs_passivity_flag(void);
-
-void uapi_dev_runtime_set_mmc_status(uint8_t status);
-// 获取指南针页面状态
-uint8_t uapi_dev_runtime_get_mmc_status_flag(void);
-
-// 设置是否为产测模式
-void uapi_dev_runtime_set_factory_test_status(uint8_t status);
-// 获取是否为产测模式
-uint8_t uapi_dev_runtime_get_factory_test_status_flag(void);
-
-// 设置是否为佩戴状态
-void uapi_dev_runtime_set_wear_status(uint8_t status);
-// 获取是否为佩戴状态
-uint8_t uapi_dev_runtime_get_wear_status_flag(void);
-
-// 设置是否为恢复出厂
-void uapi_dev_runtime_set_restore_factory_status(uint8_t status);
-// 获取是否为恢复出厂
-uint8_t uapi_dev_runtime_get_restore_factory_status(void);
-
-void uapi_dev_runtime_set_transmitting_status(uint8_t data);
-
-uint8_t uapi_dev_runtime_get_transmitting_status(void);
-
-
-void uapi_dev_runtime_atuoota_status_status(uint8_t data);
-
-uint8_t uapi_dev_runtime_get_atuoota_status(void);
-
 #ifdef __cplusplus
-#if __cplusplus
 }
 #endif /* __cplusplus */
-#endif /* __cplusplus */
 
 #endif
index adef5d6..a2acc6e 100644 (file)
@@ -23,14 +23,13 @@ void cat1_call_answer(void);
 
 void cat1_getsignal(void);
 void cat1_call_dial(char* phonenum);
-void test_call_incomming(void);
+
 void cat1_call_sms_send(char* phonenum,char* sms_txt);
 void cat1_gettime(void);
 void cat1_getver(void);
 void restart_time_sync(void);
 void cat1_at_cmd(char* cmd);
 void send_version_to_cat1(char *version);//发送固件版本到cat1
-errcode_t cat1_server_init(void);
 void get_software_version_to_cat1(void);//获取软件版本号到cat1
 void save_sim_iccid_to_ble(char *msg);//保存SIM卡的ICCID到蓝牙
 void get_sim_iccid_to_cat1(void);//获取sim卡的ICCID到cat1
@@ -40,7 +39,7 @@ void get_regist_time_toCat1(void);
 
 void ble_get_cat1_at_msg(char *buffer,uint8_t len);
 
-void send_dtfm_number_toCat1(char ch);//发送dtfm
+void send_dtmf_number_toCat1(char ch);//发送dtfm
 void send_volte_switch_toCat1(void); //发送VOLTE开关标识到CAT1
 int cat1_handle_call_disconnected(char* phonenum);
 
@@ -49,6 +48,9 @@ uint8_t set_call_hungup_flag(uint8_t data);
 
 void cat1_call_hungup_timer(void);
 
+
+
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 4c5290b..45b3aa2 100644 (file)
@@ -9,20 +9,14 @@
 #ifndef __CAT1_SERVER_HAL_H
 #define __CAT1_SERVER_HAL_H
 #ifdef __cplusplus
-#if __cplusplus
 extern "C" {
 #endif /* __cplusplus */
-#endif /* __cplusplus */
 
-int incomedcall_event_sendmsg_toUI(char* callno);
-int callend_event_sendmsg_toUI(char* callno);
-int incomingcall_event_sendmsg_toUI(char* callno);
-int calldial_event_sendmsg_toUI(char* callno);
-int cat1_msg_event_sendmsg_toUI(char* callno);
-void up_report_timer(void);
+// int callconnected_event_sendmsg_toUI(char* callno);
+// int callend_event_sendmsg_toUI(char* callno);
+// int incomingcall_event_sendmsg_toUI(char* callno);
+// int cat1_msg_event_sendmsg_toUI(char* callno);
 #ifdef __cplusplus
-#if __cplusplus
 }
 #endif /* __cplusplus */
-#endif /* __cplusplus */
 #endif
diff --git a/code/sdk/zhihui/4g/cat1Service/include/cat1_types.h b/code/sdk/zhihui/4g/cat1Service/include/cat1_types.h
new file mode 100644 (file)
index 0000000..cfa0401
--- /dev/null
@@ -0,0 +1,108 @@
+#ifndef CAT1_TYPES_H
+#define CAT1_TYPES_H
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include "chip_io.h"
+#include "errcode.h"
+#include "time.h"
+#include "sys/time.h"
+#include "platform_core.h"
+
+
+typedef enum _4g_message
+{
+    MESSAGE_4G_POWERON,//无参数 (BOOTUP)
+    MESSAGE_4G_POWEROFF,//无参数
+    MESSAGE_4G_NETWORK_CONNECTED,//无参数
+    MESSAGE_4G_NETWORK_DISCONNECTED,//无参数
+    MESSAGE_4G_NETWORK_STAT_CHANGED,//含signal,sim,运营商,
+    MESSAGE_4G_CALL_COMMING,//带电话号
+    MESSAGE_4G_CALL_CONNECTED,//带电话号
+    MESSAGE_4G_CALL_DISCONNECTED,//带电话号
+    MESSAGE_4G_SMS_RECEIVED, //返回值为字符串
+    MESSAGE_4G_AT_RECEIVED, //返回值为字符串
+    MESSAGE_4G_TIME_SYNCED,//时间同步完成
+    MESSAGE_4G_VERSION_SYNCED,//版本同步完成
+    MESSAGE_4G_MAX,
+} MESSAGE_4G_T;
+
+
+typedef enum _4g_cmd
+{
+    CMD_4G_POWERON,//无参数
+    CMD_4G_POWEROFF,//无参数
+    CMD_4G_GET_SIGNAL,//无参数
+    CMD_4G_GET_VERSION,//无参数
+    CMD_4G_GET_TIME,//无参数
+    CMD_4G_MAKE_CALL,//需要输入参数 电话号
+    CMD_4G_ANSWER_CALL,//无参数
+    CMD_4G_HUNGUP_CALL,//无参数
+    CMD_4G_SEND_DTMF, //需要输入参数 DTMF NUM(单个数字) , 包括 0 ~ 9, * , #
+    CMD_4G_AT, //需要AT指令,要求结尾带\r\n
+    CMD_4G_MAX,
+} CMD_4G_T;
+
+typedef struct {
+    uint8_t bat_pin; //控制Cat1 battery 的gpio,没有控制,设置为 PIN_NONE 即可
+    uint8_t bat_pin_en_value;
+    uint8_t pwr_pin; //控制cat1开机键的gpio
+    uint8_t pwr_pin_en_value;
+    uint8_t reset_pin; //控制cat1重置键的gpio
+    uint8_t reset_pin_en_value;
+    uint8_t ring_pin; //cat1唤醒蓝牙用的gpio
+    uint8_t ring_pin_en_value;
+    uint8_t wakemodem_pin; //蓝牙唤醒cat1用的gpio
+    uint8_t wakemodem_pin_en_value;
+} ctl_pin_4g_t;
+
+
+typedef enum{
+    CAT1_2G,
+    CAT1_3G,
+    CAT1_4G,
+    CAT1_5G
+} cat1_network_type_t;
+
+
+
+/**
+ * @brief Cat1返回的消息处理函数,客户自行定义同类型函数实现对消息的处理.
+ *          输入 MESSAGE_4G_T 
+ *          输入 msg_buf 为根据MESSAGE类型传入的对应参数
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+*/
+typedef errcode_t (*f_cat1_msg_callback)(MESSAGE_4G_T msg, void *msg_buf, uint16_t msglen);
+
+
+/**
+ * @brief 获取系统时区 单位 quarters(15分钟) 
+ * @return 时区 单位quarter(15分钟).
+*/
+typedef uint16_t (*f_get_timezone)(void);
+
+/**
+ * @brief 设置时区(单位quarter,15分钟)
+ * @return void.
+*/
+typedef void (*f_set_timezone)(uint16_t timezone_quarters);
+/**
+ * @brief  同步时间到系统,输入 utc_timestamp(单位秒) 加 时区(单位quarter,15分钟)
+ * @return void.
+ */
+typedef uint32_t (*f_sync_time_utc)(uint32_t timestamp, uint32_t timezone_quarters);
+
+typedef struct 
+{
+    f_get_timezone get_timezone;
+    f_set_timezone set_timezone;
+    f_sync_time_utc sync_time_utc;
+} time_ctl_funcs_t;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
\ No newline at end of file
index 3ab5c6e..f3eb9cc 100644 (file)
@@ -8,10 +8,12 @@
  */
 #ifndef CAT1_UTILS_H
 #define CAT1_UTILS_H
+#include "cat1_types.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
-
+#include "cat1_log.h"
 #include "hal_gpio.h"
 #include "soc_osal.h"
 #include "platform_core.h"
@@ -19,12 +21,6 @@ extern "C" {
 #include "thread_init.h"
 #include "pdu.h"
 
-#ifdef  SINGLE_USER_PARTITION
-#define EXC_TAR_PATH "/user/log"
-#else
-#define EXC_TAR_PATH "/user/tar"
-#endif
-
 #define TASK_PRIORITY_APP           (osPriority_t)(17)
 #define TASK_PRIORITY_LOG           (osPriority_t)(18)
 #define TASK_PRIORITY_CMD           (osPriority_t)(17)
@@ -33,400 +29,66 @@ extern "C" {
 #define TASK_PRIORITY_DFX_MSG       (osPriority_t)(18)
 #define TASK_PRIORITY_TRANSMIT      (osPriority_t)(20)
 
-#define OPEN_SCREEN_ALWAYS_ON 1   //屏幕常亮
-#define CANCEL_SCREEN_ALWAYS_ON 0 //取消屏幕常亮
-// reboot
-typedef enum {
-    SHUTDOWN_TYPE,
-    REBOOT_TYPE,
-    UPDATE_TYPE,
-} DONING_SHUTDOWN_TYPE;
-
-
-
-uint32_t zh_get_sn(uint8_t *buf_sn, uint32_t *len_sn);
-uint32_t zh_set_sn(uint8_t *buf_sn, uint32_t len_sn);
-
 void uapi_poweroff_device(void);
 void uapi_reboot_device(void);
 
-extern uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len);
-
-errcode_t uaip_cmd_update_request(void);
-
-/**获取单位ms的时间戳*/
-errcode_t uapi_get_timestampe_ms(uint32_t *tm);
-/*获取单位秒的时间戳*/
-errcode_t uapi_get_timestampe_ss(uint32_t *tm);
-errcode_t uapi_get_timestampe_ss_extend(uint32_t *tm,int year, int month, int day, int hour, int minute, int second); 
-/**返回timezone quarters*/
-uint16_t uapi_get_timezone(void);
-/**set timezone quarters*/
-void uapi_set_timezone(uint16_t timezone_quarters);
-
-/**设置utc时间+timezone*/
-errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_quarters);
-
 /*sntp同步UTC 时间 , 采用默认timezone,或者已经保存的timezone*/
-errcode_t uaip_sntp_set_time_utc(uint32_t seconds);
-
-/*已经包含timezone时间,*/
-errcode_t uaip_set_time_local(uint32_t seconds);
-
-/*已经包含timezone时间,*/
-errcode_t uaip_set_time_local_full(uint32_t year,uint32_t month, uint32_t day, uint32_t hour,uint32_t minutes,uint32_t seconds);
+errcode_t cat1_sntp_set_time_utc(uint32_t seconds);
 
 /**根据cat1获取的时间字串设置时间 */
-errcode_t uapi_set_time_from_cat1(char* cat1time);
-
-/**获取日期*/
-errcode_t uapi_get_yyyymmddhhmmss_Date(char *date);
-/*获取日期扩展版*/
-errcode_t uapi_get_YYMMDD_Time_extend(char *p_time, char separator,int8_t day);
-
-/*获取日期*/
-errcode_t uapi_get_YYMMDD_Time(char *p_time, char separator);
-/*获取时间*/
-errcode_t uapi_get_HHMMSS_Time(char *p_time, char separator, bool include_seconds);
-/*打印时间戳*/
-void print_current_time(void);
-/*获取星期*/
-errcode_t uapi_get_WeekStr(char *p_week);
-/*设置屏幕亮屏*/
-void uapi_set_screen_on_api(void);
-/*获取Vote状态*/
-errcode_t get_vote_status(char *str,size_t str_size);
-
-int get_save_runtime_vote_status(void);
-
-/**
- * @brief 日期格式选项枚举
- */
-typedef enum {
-    DATE_TIME_DEFULL,   // 年 月 日 时:分:秒
-    DATE_Y_M_D,         // 年 月 日
-    DATE_Y_M_D_H_M,     // 年 月 日 时 分
-    DATE_M_D,           // 月 日
-    DATE_H_M_S,         // 时 分 秒
-    DATE_H_M,           // 时 分
-    DATE_M_S,           // 分 秒
-    DATE_M_D_H_M        // 月 日 时 分
-} date_format_t;
-
-/*通过时间戳解析时间字符串*/
-errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format);
-
-char *uapi_get_local_yyyymmdd_date(void);
-
-void ScreenAlwaysOnCtr(uint8_t turnOnFlag);
-
-// Is the screen always on
-bool mmi_screen_always_on_flag_get(void);
-
-void mmi_screen_on_off_by_flip_wrist(bool value);
-
-void uapi_setScreenBrightness(int value);
-
-void uapi_setScreenDuration(int32_t time);
-
-int32_t uapi_get_screen_state(void);
-
-void uapi_systemVolumeSet(int32_t sounding);
-int uapi_systemVolumeGet(void);
-void uapi_callVolumeSet(int32_t sounding);
-int uapi_callVolumeGet(void);
-// void uapi_vibrationModeSet(int value);
-void uapi_set4GCapability(bool isopen);
-
-errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr);
-errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname);
-errcode_t uapi_get_nv_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr);
-errcode_t uapi_get_nv_btname(uint8_t *buf_btname, uint32_t *len_btname);
-
-/*
-cywee chipinfo 转换 btmac地址,确保之前被chipinfo激活的密钥,用bt mac仍然可以激活
-要在init_btaddr_btname之前执行
-*/
-errcode_t change_mac_from_chipinfo_map(void);
-
-
-errcode_t init_btaddr_btname(void);
-
-
-errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg);
-errcode_t uapi_terminate_thread(void* thread_id);
-errcode_t uapi_suspend_thread(void* thread_id);
-errcode_t uapi_resume_thread(void* thread_id);
-errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len);
-
-//获取固件版本号
-errcode_t uapi_get_fw_version(uint8_t *_major, uint8_t *_mid,uint8_t *_minor);
-
-/**
- * @}
- */
-
-// 使能翻腕亮灭屏功能接口
-// cmd: 1-active;other-deactive
-void uapi_take_to_wake(int cmd);
-
-
-//获取lcd id
-void lcd_getid(uint32_t *id);
-
-//获取TP ID
-void touch_getid(uint16_t *id);
-void get_tp_info(int16_t *x,int16_t *y);
-
-//获取触摸屏状态
-void touch_getstate(void);
-
-//获取MMC5063 ID
-void mmc5603_getid(unsigned char *id);
-void mmc5603_getdata(float *fAzimuth);
-
-//flash整片擦除
-void flash_getid(uint32_t *id);
-void flash_erase(void);
-
-void get_gsensor_single(uint8_t *databuf);
-
-
-void shutdown_reboot_prejobs(uint8_t type);
-
-void start_shutdown_or_reboot(uint8_t type);
-
-uint8_t is_doing_shutdown_or_reboot(void);
-
-
-
-bool start_custom_ble_service(void);
-bool stop_custom_ble_service(void);
-
-bool start_alipay_ble_service(void);
-bool stop_alipay_ble_service(void);
-
-bool enable_hfp_service(bool _enable);
-bool enable_a2dp_service(bool _enable);
-bool enable_spp_service(bool _enable);
-
-uint32_t uapi_calendar_recover_date(void);
-uint32_t uapi_calendar_store_date(void);
-
+errcode_t cat1_set_time_from_cat1(char* cat1time);
 
-#define CUSTOM_CMD_MSG_TYPE_ADD_CAT1VOTE 0x01
-#define CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME 0x02
-#define CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME 0x03
-#define CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE 0x04
-#define CUSTOM_CMD_MSG_TYPE_RESTORE_FACTORY_SETTING 0x05
-#define CUSTOM_CMD_MSG_TYPE_STARTOTA 0x06
-#define CUSTOM_CMD_MSG_TYPE_LCD_TEST 0x07
-#define CUSTOM_CMD_MSG_TYPE_LCD_COLOR_TEST 0x08
-#define CUSTOM_CMD_MSG_TYPE_TP_TEST 0x09
-#define CUSTOM_CMD_MSG_TYPE_CROWN_TEST 0x0A
-#define CUSTOM_CMD_MSG_TYPE_VIBRATOR_TEST 0x0B
+uint8_t *cat1_get_devid(void);
 
-#define CUSTOM_CMD_MSG_BR_CONNECT 0x0C
-
-#define CUSTOM_CMD_MSG_CHECK_RES 0x0D
-#define CUSTOM_CMD_MSG_DOWNLOAD_RES 0x0E
-
-#define CUSTOM_CMD_MSG_TYPE_TOUCH_RESUME 0x0F
-
-#define CUSTOM_CMD_MSG_TIMECALL_BACK 0x10
-
-#define CUSTOM_CMD_MSG_BLE_ADV_CHECK 0x11
-
-#define CUSTOM_CMD_MSG_CHECK_DIAL_SPACE 0x12
-
-#define CUSTOM_CMD_MSG_CAT1_AUDIO_START 0x13
-
-#define CUSTOM_CMD_MSG_CAT1_AUDIO_STOP 0x14
-
-#define CUSTOM_CMD_MSG_CAT1_MIC_CTRL 0x15
-
-#define CUSTOM_CMD_MSG_TYPE_AGING_TEST 0x16
-
-//
-#define CUSTOM_CMD_MSG_CAT_HFP_SCO_CONNECT 0x17
-
-#define CUSTOM_CMD_MSG_CAT_HFP_DIS_SCO_CONNECT 0x18
-
-#define CUSTOM_CMD_MSG_CAT_HFP_SCO_AUDIO_START 0x19
-
-
-typedef enum {
-    BR_HFP_CONNECT=1,
-    BR_HFP_DISCONNECT,
-    BR_A2DP_CONNECT,
-    BR_A2DP_DISCONNECT,
-    BR_RECONNECT,
-    BR_HFP_CONNECT_FAIL,
-   
-} CUSTOM_CMD_MSG_BR_CONNECT_TYPE;
-
-errcode_t uapi_custom_cmd_service_init(void);
-errcode_t do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen);
-errcode_t do_custom_cmd_service_check_msg_head(int cmd, void *params, int paramlen);
-
-/***custom file operate cmd service*/
-#define CUSTOM_FILEOPERATE_MSG_TYPE_SPORTDATA_SAVE 0x01 //运动数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_HEARTRATE_SAVE 0x02 //心率数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_BLOODXYGEN_SAVE 0x03//血氧数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGEDATA_SAVE 0x04//消息数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_SAVE 0x05//睡眠数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_SAVE 0x06//小睡数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ 0x07 //读取睡眠时间
-#define CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_READ 0x08   //读取小睡数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPMODLE_UPDATE 0x09//更新睡眠model数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_MMCDATA_SAVE 0x0A //存储指南针数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_MMCDATA_READ 0x0B  //读取指南针数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_MUSICNAME_READ 0x0C  //读取音乐文件名
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_RECORDING_SPACE_READ 0x0D //读取录音空间
-#define CUSTOM_FILEOPERATE_MSG_TYPE_HEART_DATA_LIST 0x0E //存储心率数据列表
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_AGING_DATA_READ 0x0F //读取老化数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_AGING_DATA_SAVE 0x10 //存储老化数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_POPUP_WINDOWS_DATA_LIST 0x11 //存储弹窗数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_READ 0x12 //读取佩戴数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_SAVE 0x13 //存储佩戴数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_READ 0x14 //读取电池数据
-#define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_SAVE 0x15 //存储电池数据
-
-#define CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY 0x16 //消息数据
-
-errcode_t uapi_custom_fileoperate_service_init(void);
-errcode_t do_custom_fileoperate_service_check_msg(int cmd, void *params, int paramlen);
+errcode_t cat1_create_osThread_custom(app_task_definition_t *task_cfg);
+errcode_t cat1_terminate_thread(void* thread_id);
+errcode_t cat1_suspend_thread(void* thread_id);
+errcode_t cat1_resume_thread(void* thread_id);
 
 
 int uapi_delete_files(const char *file_path);
-void uapi_restore_factory_setting(void);
-
-errcode_t custom_i2c_init(uint8_t bus_index);
-void custom_i2c_reset(uint8_t i2cbus, uint16_t i2c_clock);
-errcode_t custom_i2c_write_reg(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, int busIndex);
-errcode_t custom_i2c_read_regs(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *readData, int readDataSize, int busIndex);
-errcode_t custom_i2c_transfer(uint16_t slaveAddr, uint16_t reg, int regLength, uint8_t *writeData, int writeDataSize, uint8_t *readData, int readDataSize, int busIndex);
-errcode_t custom_i2c_test(void);
-
-uint32_t custom_i2c_suspend(void);
-uint32_t custom_i2c_resume(void);
-
-void uapi_cywee_get_id(uint8_t *id);
-int custom_exit_lpm(void);
-
-void uapi_cywee_time_sync(void);
-void uapi_cywee_get_chipinfo(char *databuf,uint8_t len);
-void uapi_cywee_get_version(char *databuf,uint8_t len);
-void uapi_cywee_save_mac_key(const uint8_t *key_data,uint16_t len);
-uint8_t* uapi_cywee_get_mac_key(void);
-void uapi_get_sleep_date_on_log(char *time);
-void uapi_ppg_get_id(uint8_t *chip_id);
 
-
-int32_t uapi_microhone_switch(bool isopen);
-void uapi_check_spk(bool isopen);
-void uapi_check_mic(bool isopen);
-void uapi_factorytest_set_lcd_color(int color);
-void uapi_factorytest_enter_test_view(int cmd);
-void uapi_factorytest_enter_test_tp_view(void);
-void uapi_factorytest_enter_test_lcd_view(void);
-void uapi_factorytest_enter_test_button_view(void);
-void uapi_factorytest_hide_test_lcd_button(void);
-void uapi_factorytest_hide_test_tp_button(void);
 void uapi_efuse_test_write(uint8_t *data,uint32_t byte_number,uint8_t len);
 void uapi_efuse_test_read(uint32_t byte_number,uint8_t len);
 void uapi_gei_btmac_and_chipinfo(void);
-uint8_t uapi_get_cywee_active_state(void);
-void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len);
-void uapi_save_file_data(char *path,uint8_t *data,uint16_t len,char *mode);
-uint8_t uapi_get_cywee_static_state(void);
-void uapi_get_a5133_rxdata(uint8_t *databuf,uint8_t len);
+
 uint16_t CRC16_XMODEM(uint8_t *bytes,uint16_t length);
 uint16_t CRC16_X25(uint8_t *di, uint32_t len);
-errcode_t uapi_a5133_set_send_data(uint8_t *senddata,uint8_t datalen);
-void a5133_demo_msg_change_callback(void);
-void uapi_get_a5133_rxdata_timestamp(uint32_t *timestamp);
-uint32_t uapi_get_a5133_update_state(void);
-uint32_t uapi_get_a5133_update_state1(void);
 
 errcode_t uapi_start_audio_test(int volume);
 errcode_t uapi_stop_audio_test(void);
 
-void uapi_save_sleep_flag(uint8_t *data,uint16_t len);
-
-void start_save_file_thread(void);
 void uapi_create_folder(char *dir_path);
 uint32_t uapi_get_file_size(char *filepath);
-/**
- * 资源文件校验码保存在文件 /user/fileschecksum.txt 中
- * 读出每一行,输入本函数,检测文件是否正常。
- * 输入: 
- *      /music/ring/ring.mp3,523621,8c0b93aae3b2ee12e6cf58336a092c43
- * 输出:
- *      outputfile 显示到UI中使用 ,文件错误或者缺失的时候用到。
- * return true 正确
- *        false 文件错误,或者缺失 
-*/
-bool check_file(char* buffer,int inputlen,char* outputfile,int max_outputsize);
 
 /**
  * return uart enable flag
  *        true 代表 接收缓存
  *        false 代表 不接收缓存
 */
-bool uapi_custom_uart_rx_enable_flag(void);
-
-
+bool cat1_api_custom_is_cmd_rx_enabled(void);
 /**
  * 设置 uart rx enable flag
 */
-void uapi_custom_set_uart_rx_enable_flag(bool enable_uart);
+void cat1_api_custom_enable_cmd_rx(bool enable_uart);
 
+void mcu_reset(void);
+void mcu_poweroff(void);
 
+void remove_debug_vote(void);
 
 /**
- * param direction 0 = X , 1 = Y
-*/
-void enable_drag(uint8_t direction, uint8_t enable);
-
-/**
- * param direction 0 = X , 1 = Y
-*/
-void set_drag_limit(uint8_t direction, uint16_t limit);
-/**
- * param direction 0 = X , 1 = Y
-*/
-uint16_t get_drag_limit(uint8_t direction);
-
-errcode_t touch_resume_in_cmd_queue(void);
-
-/**
- * 在BluetoothModel.cpp中有实现
-*/
-void BtInitSpp(void);
-
+ * @brief 写密钥
+ * @return 成功 ERRCODE_SUCC 或者其他失败ERRCODE .
+ * */
+errcode_t cat1_write_security_key(void *se_keybuf,uint16_t se_keylen);
 
 
-void mcu_reset(void);
-void mcu_poweroff(void);
+//来电
+int cat1_handle_call_incomming(char * msg);
 
-/**
- * 获取offline log 开关标识 需要采用 ./autobuild.sh uoffline 【 CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE=1】编译才有效
-*/
-uint8_t get_offline_log_nv(void);
-/**
- * 设置 offline log 开关标识,需要采用 ./autobuild.sh uoffline 【CONFIG_DFX_SUPPORT_OFFLINE_LOG_FILE=1】编译才有效
-*/
-errcode_t enable_offline_log_nv(uint8_t log_enable);
 
-void remove_debug_vote(void);
+errcode_t permition_verify(void);
 
 #ifdef __cplusplus
 }
diff --git a/code/sdk/zhihui/4g/cat1Service/include/custom_http_download.h b/code/sdk/zhihui/4g/cat1Service/include/custom_http_download.h
new file mode 100644 (file)
index 0000000..8d4829b
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __CUSTOM_HTTP_DOWNLOAD_H_
+#define __CUSTOM_HTTP_DOWNLOAD_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#include "errcode.h"
+#ifdef SUPPORT_CAT1_SERVICE
+#include "lwip/apps/http_client.h"
+/**
+ * uint8_t *server, 
+ * uint16_t port,
+ * uint8_t *uri, 
+ * uint8_t *otadatapath, 
+ * httpc_result_fn callback_result_fn, 
+ * httpc_headers_done_fn callback_headers_done_fn,  
+ * httpc_file_rx_fn callback_file_rx_fn
+*/
+errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *uri, uint8_t *otadatapath, httpc_result_fn callback_result_fn, httpc_headers_done_fn callback_headers_done_fn,  httpc_file_rx_fn callback_file_rx_fn);
+/**
+ * stop函数要在result里面执行,表示下载结束
+*/
+errcode_t http_single_download_stop(void);
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif
\ No newline at end of file
index f435874..36f1349 100644 (file)
@@ -45,22 +45,22 @@ set(lwipport_SRCS
     ${LWIP_DIR}/port/lwip-2.1/enhancement/src/lwip_ifaddrs.c
 
 )
-set(lwiptest_SRCS
-    ${LWIP_DIR}/port/test/test_main.c
-    ${LWIP_DIR}/port/test/net_socket_test_001.c
-    ${LWIP_DIR}/port/test/net_socket_test_002.c
-    ${LWIP_DIR}/port/test/net_socket_test_003.c
-    ${LWIP_DIR}/port/test/net_socket_test_004.c
-    ${LWIP_DIR}/port/test/net_socket_test_005.c
-    ${LWIP_DIR}/port/test/net_socket_test_006.c
-    ${LWIP_DIR}/port/test/net_socket_test_007.c
-    ${LWIP_DIR}/port/test/net_socket_test_008.c
-    # ${LWIP_DIR}/port/test/net_socket_test_009.c
-    # ${LWIP_DIR}/port/test/net_socket_test_010.c
-    ${LWIP_DIR}/port/test/net_socket_test_011.c
-    ${LWIP_DIR}/port/test/net_socket_test_012.c
-    ${LWIP_DIR}/port/test/net_socket_test_013.c
-)
+# set(lwiptest_SRCS
+#    ${LWIP_DIR}/port/test/test_main.c
+#    ${LWIP_DIR}/port/test/net_socket_test_001.c
+#    ${LWIP_DIR}/port/test/net_socket_test_002.c
+#    ${LWIP_DIR}/port/test/net_socket_test_003.c
+#    ${LWIP_DIR}/port/test/net_socket_test_004.c
+#    ${LWIP_DIR}/port/test/net_socket_test_005.c
+#    ${LWIP_DIR}/port/test/net_socket_test_006.c
+#    ${LWIP_DIR}/port/test/net_socket_test_007.c
+#    ${LWIP_DIR}/port/test/net_socket_test_008.c
+#    # ${LWIP_DIR}/port/test/net_socket_test_009.c
+#    # ${LWIP_DIR}/port/test/net_socket_test_010.c
+#    ${LWIP_DIR}/port/test/net_socket_test_011.c
+#    ${LWIP_DIR}/port/test/net_socket_test_012.c
+#    ${LWIP_DIR}/port/test/net_socket_test_013.c
+#)
 # set(LWIP_SOURCES
 #     ${lwipcore_SRCS}
 #     ${lwipcore4_SRCS}
index 4a360d9..6589e42 100644 (file)
 
 #define SNTP_CHECK_RESPONSE             2
 
-#define SNTP_SET_SYSTEM_TIME(sec)   uaip_sntp_set_time_utc(sec)
+#define SNTP_SET_SYSTEM_TIME(sec)   cat1_sntp_set_time_utc(sec)
 
 #endif /* _LWIP_PORTING_LWIPOPTS_H_ */
index 3424842..05fb3e8 100644 (file)
@@ -625,7 +625,7 @@ tcpip_init(tcpip_init_done_fn initfunc, void *arg)
     taskcfg.func = tcpip_thread;
     taskcfg.use_mem = USE_EXTEND_MEM;
     
-    errcode_t ret=uapi_create_osThread_custom(&taskcfg);
+    errcode_t ret=cat1_create_osThread_custom(&taskcfg);
     if(ret != ERRCODE_SUCC)
       printf("create tcpip_thread failed %d\n",ret);
     else
index 5b58a15..67f8185 100644 (file)
@@ -610,12 +610,12 @@ sntp_request(void *arg)
   ip_addr_t sntp_server_address;
   err_t err;  
   LWIP_UNUSED_ARG(arg);
-  if (uapi_dev_runtime_get_ble_connect_stat())  
-  {
-      LWIP_DEBUGF(SNTP_DEBUG_STATE, ("ble connected, skip sntp_request.\n"));
-      return;
-  }
-  uapi_cat1_wakeup_cat1(1);
+  // if (cat1_api_runtime_get_ble_connect_stat())  
+  // {
+  //     LWIP_DEBUGF(SNTP_DEBUG_STATE, ("ble connected, skip sntp_request.\n"));
+  //     return;
+  // }
+  cat1_api_wakeup_cat1(1);
   /* initialize SNTP server address */
 #if SNTP_SERVER_DNS
   if (sntp_servers[sntp_current_server].name) {
@@ -626,7 +626,7 @@ sntp_request(void *arg)
     if (err == ERR_INPROGRESS) {
       /* DNS request sent, wait for sntp_dns_found being called */
       LWIP_DEBUGF(SNTP_DEBUG_STATE, ("sntp_request: Waiting for server address to be resolved.\n"));
-      uapi_cat1_wakeup_cat1(0);
+      cat1_api_wakeup_cat1(0);
       return;
     } else if (err == ERR_OK) {
       sntp_servers[sntp_current_server].addr = sntp_server_address;
@@ -648,7 +648,7 @@ sntp_request(void *arg)
     sys_untimeout(sntp_try_next_server, NULL);
     sys_timeout((u32_t)SNTP_RETRY_TIMEOUT, sntp_try_next_server, NULL);
   }
-  uapi_cat1_wakeup_cat1(0);
+  cat1_api_wakeup_cat1(0);
 }
 
 /**
diff --git a/code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.c b/code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.c
deleted file mode 100644 (file)
index 54a49eb..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * Copyright (c) CompanyNameMagicTag 2023-2023. All rights reserved.
- * Description: get time
- * Author:
- * Create:
- */
-
-#include "cat1_porting.h"
-
-/**
- * return quarters for timezone 
-*/
-uint16_t uapi_get_timezone(void)
-{
-    /*从系统中获取timezone*/
-    return (8*15) ;
-}
diff --git a/code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.h b/code/sdk/zhihui/4g/cat1Service/porting/cat1_porting.h
deleted file mode 100644 (file)
index dcfd79c..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Copyright (c) @CompanyNameMagicTag 2023-2023. All rights reserved. \n
- *
- * Description: Button driver header file \n
- * Author: @CompanyNameTag \n
- * History: \n
- * 2023-02-24, Create file. \n
- */
-#ifndef CAT1_UTILS_H
-#define CAT1_UTILS_H
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-#include <stdio.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include "calendar.h"
-#include "chip_io.h"
-#include "errcode.h"
-#include "time.h"
-#include "sys/time.h"
-/**
- * @brief  Print the time represented by the given calendar date
- * @return void.
- */
-void print_time(calendar_t *date);
-
-/**
- * @brief  Save the current system time to non-volatile memory
- * @return void.
- */
-void save_time(void);
-
-/**
- * @brief  Get the current system time as a Unix timestamp
- * @return void.
- */
-uint32_t get_current_timestamp(void);
-
-/**
- * @brief  Get the current system time as a timeval struct and a tm
- * @return void.
- */
-void get_current_time(struct timeval *tv, struct tm *tm);
-
-/**
- * @brief  Restore the system time from the saved non-volatile
- * @return void.
- */
-void restore_time(void);
-
-/**
- * @brief  Synchronize the system time with the given timestamp and timezone
- * @return void.
- */
-uint32_t sync_time(uint32_t timestamp, uint32_t timezone);
-
-/**
- * @brief  use for test
- * @return void.
- */
-void test_time(void);
-
-/**
- * @brief  Get the current system time as a local timestamp with timezone offset
- * @return void.
- */
-uint32_t get_local_timestamp(void);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif
\ No newline at end of file
index 803ae8d..d49ba64 100644 (file)
@@ -30,7 +30,7 @@
 #include "irmalloc.h"
 #include "errcode.h"
 #include "common_def.h"
-#include "wearable_log.h"
+#include "cat1_log.h"
 #include "thread_init.h"
 struct netif sl_netif;
 
@@ -43,7 +43,7 @@ typedef struct {
     uint32_t size;
     uint8_t *buffer;
 } slip_uart_cmd_t;
-void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size)
+void do_uart_net_cmd(int cmd,uint8_t *buffer,uint32_t size)
 {
     int ret;
 
@@ -51,7 +51,7 @@ void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size)
 
     mail.buffer = osal_kmalloc(size+1, OSAL_GFP_KERNEL);
     if (mail.buffer == NULL) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"uart message buffer memory alloc fail, length is %d "NEWLINE, size);
+        cat1_print_err("uart message buffer memory alloc fail, length is %d "NEWLINE, size);
         return;
     }
     memset_s(mail.buffer,size+1,0,size+1);
@@ -59,11 +59,11 @@ void do_uart_slip_cmd(int cmd,uint8_t *buffer,uint32_t size)
     mail.cmd = cmd;
     mail.size = size;
     // unsigned int quesize=osal_msg_queue_get_msg_num(g_slip_cmd_queue);
-    //  WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"do_uart_slip_cmd quesize %d\n",quesize);
+    //  cat1_print_err("do_uart_net_cmd quesize %d\n",quesize);
     ret = osal_msg_queue_write_copy(g_slip_cmd_queue, (void *)&mail,
                                     sizeof(slip_uart_cmd_t), 0);
     if (ret != OSAL_SUCCESS) {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"Error uart_slip cmd msg %d send failed! err=0x%02X!"NEWLINE,cmd, ret);
+        cat1_print_err("Error uart_net cmd msg %d send failed! err=0x%02X!"NEWLINE,cmd, ret);
     }
     
 }
@@ -76,7 +76,7 @@ static void uart_event_task(void const *arg)
     uint32_t msgsize = (uint32_t)sizeof(slip_uart_cmd_t);
     
     ret = user_netif_init();
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"user_netif_init ret=0x%02X! \r\n",ret);
+    cat1_print_info("user_netif_init ret=0x%02X! \r\n",ret);
 
     while (1) {
 
@@ -90,7 +90,7 @@ static void uart_event_task(void const *arg)
 
         if (mail.cmd == UART_SLIP_CMD_MSG_READ_DATA) {
        
-                WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"recv size=%d! %s \r\n",mail.size,mail.buffer);
+                // cat1_print_dbg("recv size=%d! %s \r\n",mail.size,mail.buffer);
                        slipif_received_bytes(&sl_netif, mail.buffer, mail.size);
                        // slipif_process_rxqueue(&sl_netif);
 
@@ -124,7 +124,7 @@ int user_netif_init(void)
     IP_ADDR4(&gw, 172, 16, 1, 2);
     temp = netif_add(&sl_netif, &ipaddr, &netmask, &gw, &int_no, slipif_init, ip_input);
        if( temp == NULL ) {
-               WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"fail to netif init\n");
+               cat1_print_err("fail to netif init\n");
         return -1;
        }
     netif_set_up(&sl_netif);
@@ -141,14 +141,14 @@ int user_netif_init(void)
 }
 #define USE_SLIP_SERVICE
 
-void slip_receive_handler(uint8_t *buffer, int32_t size)
+void cat1_uart_receive_handler(uint8_t *buffer, int32_t size)
 {
 
-       // WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"slip_receive_handler %d \n",size);
+       // cat1_print_dbg("cat1_uart_receive_handler %d \n",size);
     if (slipif_initialled == true)
     {
     #ifdef USE_SLIP_SERVICE
-        do_uart_slip_cmd(UART_SLIP_CMD_MSG_READ_DATA,buffer,size);
+        do_uart_net_cmd(UART_SLIP_CMD_MSG_READ_DATA,buffer,size);
     #else
         slipif_received_bytes(&sl_netif, buffer, size);
     #endif
@@ -159,38 +159,38 @@ void slip_receive_handler(uint8_t *buffer, int32_t size)
 #define SLIP_CMD_TASK_MSG_COUNT 512
 #define SLIP_CMD_TASK_SIZE (0x800*2)
 #define SLIP_CMD_TASK_PRIO 4
-void create_slip_uart_queue(void)
+void create_net_uart_queue(void)
 {
 
-    if (osal_msg_queue_create("uart_slip_cmd_queue", SLIP_CMD_TASK_MSG_COUNT, &g_slip_cmd_queue,
+    if (osal_msg_queue_create("uart_net_cmd_queue", SLIP_CMD_TASK_MSG_COUNT, &g_slip_cmd_queue,
                               0, sizeof(slip_uart_cmd_t)) != ERRCODE_SUCC) {
-        LWIP_DEBUGF(SLIP_DEBUG, ("[slip][service] app create mail fail\n"));
+        LWIP_DEBUGF(SLIP_DEBUG, ("[net][service] app create mail fail\n"));
     }
 }
-int slip_uart_init(void)
+int netif_service_init(void)
 {
 
 
-    PRINT("slip_uart_init !\r\n");
+    cat1_print_info("netif_service_init !\r\n");
 
 #ifdef USE_SLIP_SERVICE
     app_task_definition_t taskcfg={0};
-    taskcfg.create_queue_handle = create_slip_uart_queue;
-    taskcfg.attr.name="uart_slip_service";
+    taskcfg.create_queue_handle = create_net_uart_queue;
+    taskcfg.attr.name="netif_service";
     taskcfg.attr.priority = osPriorityHigh;//osPriorityNormal; GUI osPriorityAboveNormal2
     taskcfg.attr.stack_size = SLIP_CMD_TASK_SIZE;
     taskcfg.func = uart_event_task;
     taskcfg.use_mem = USE_DTCM_MEM;
     
-    errcode_t ret=uapi_create_osThread_custom(&taskcfg);
+    errcode_t ret=cat1_create_osThread_custom(&taskcfg);
     if(ret != ERRCODE_SUCC)
     {
-        PRINT("create uart_slip_service failed %d!\r\n",ret);
+        cat1_print_err("create netif_service failed %d!\r\n",ret);
         return ERRCODE_FAIL;
     }
 #else
     errcode_t ret = user_netif_init();
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_MAIN_SERVICE,"user_netif_init ret=0x%02X! \r\n",ret);
+    cat1_print_info("user_netif_init ret=0x%02X! \r\n",ret);
 #endif
     return ERRCODE_SUCC;
 }
index 029c6b4..1f866a2 100644 (file)
@@ -21,7 +21,7 @@
 /**
  * @brief init uart config and config uart as slip netif bridge
  */
-int slip_uart_init(void);
+int netif_service_init(void);
 
 /**
  * @brief remove slip netif
index ca1b768..89e1224 100644 (file)
@@ -11,10 +11,26 @@ ${CMAKE_CURRENT_SOURCE_DIR}
 )
 set(PRIVATE_HEADER
 )
-
+set(lwiptest_SRCS
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/test_main.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_001.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_002.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_003.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_004.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_005.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_006.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_007.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_008.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_009.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_010.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_011.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_012.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/net_test/net_socket_test_013.c
+)
 set(SOURCES
-${CMAKE_CURRENT_SOURCE_DIR}/cat1_at_cmd.c
-${CMAKE_CURRENT_SOURCE_DIR}/cat1_porting.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/cat1_at_cmd.c
+    ${CMAKE_CURRENT_SOURCE_DIR}/cat1_porting.c
+    ${lwiptest_SRCS}
 )
 
 set(COMPONENT_PUBLIC_CCFLAGS
index 98d35c2..e009080 100644 (file)
@@ -1,10 +1,8 @@
 
 #include "at_cmd_api.h"
 #include "pm_control.h"
-#include "cat1_server.h"
-#include "cat1_tcpServer.h"
 #include "cat1_at_cmd.h"
-#include "cat1_ctl.h"
+#include "cat1_pub_api.h"
 #include <stdio.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -83,9 +81,9 @@ static uint32_t cat1_power(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 
     if(enabled == 1)
     {
-        power_on_cat1();
+        cat1_api_enable_cat1(true);
     }else{
-        power_off_cat1();
+        cat1_api_enable_cat1(false);
     }
 
     return ERRCODE_SUCC;
@@ -110,7 +108,7 @@ static uint32_t at_cat1_dial(uint8_t *para, uint32_t paraLen, char *strCommonCmd
 
     printf("CAT1TEST ATCMD  dial   %s \n",phoneno);
 
-    cat1_call_dial(phoneno);
+    cat1_cmd_send(CMD_4G_MAKE_CALL,phoneno,strlen(phoneno));
 
     return ERRCODE_SUCC;
 }
@@ -119,18 +117,16 @@ static uint32_t at_cat1_answer(uint8_t *para, uint32_t paraLen, char *strCommonC
     UNUSED(strCommonCmd);
 
     printf("CAT1TEST ATCMD  answer   \n");
-    cat1_call_answer();
+    cat1_cmd_send(CMD_4G_ANSWER_CALL,NULL,0);
     return ERRCODE_SUCC;
 }
 static uint32_t at_cat1_hungup(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
 
-    
     printf("CAT1TEST ATCMD  hungup   \n");
 
-
-    cat1_call_hungup();
+    cat1_cmd_send(CMD_4G_HUNGUP_CALL,NULL,0);
     return ERRCODE_SUCC;
 }
 
@@ -141,7 +137,7 @@ static uint32_t at_cat1_gettime(uint8_t *para, uint32_t paraLen, char *strCommon
     
     printf("CAT1TEST ATCMD  gettime  \n");
 
-    cat1_gettime();
+    cat1_cmd_send(CMD_4G_GET_TIME,NULL,0);
 
     return ERRCODE_SUCC;
 }
@@ -153,7 +149,7 @@ static uint32_t at_cat1_getsignal(uint8_t *para, uint32_t paraLen, char *strComm
     
     printf("CAT1TEST ATCMD  getsignal  \n");
 
-    cat1_getsignal();
+    cat1_cmd_send(CMD_4G_GET_SIGNAL,NULL,0);
 
     return ERRCODE_SUCC;
 }
@@ -161,7 +157,7 @@ static uint32_t at_cat1_getver(uint8_t *para, uint32_t paraLen, char *strCommonC
 {
     UNUSED(strCommonCmd);
     printf("CAT1TEST ATCMD  cat1 getver  \n");
-    cat1_getver();
+    cat1_cmd_send(CMD_4G_GET_VERSION,NULL,0);
 
     return ERRCODE_SUCC;
 }
@@ -194,10 +190,16 @@ static uint32_t cat1_wakeup(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
     // char *mode = (char*)argv[0];
     int enabled = atoi((char*)argv[0]);
     if(enabled == 0)
-        uapi_cat1_wakeup_cat1(0);
+    {
+        cat1_api_keep_wakeup(0);
+        cat1_api_wakeup_cat1(0);
+    }
     else 
-        uapi_cat1_wakeup_cat1(1);
-    printf("CAT1TEST ATCMD  wakeup cat1   enabled = %d\n",enabled);
+    {
+        cat1_api_keep_wakeup(1);
+        cat1_api_wakeup_cat1(1);
+    }
+    printf("CAT1TEST ATCMD  keepwakeup cat1  enabled = %d\n",enabled);
 
     return ERRCODE_SUCC;
 }
@@ -213,10 +215,12 @@ static uint32_t cat1_ping(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
         printf("CAT1TEST ATCMD Convert Command Failed\n");
         return ERRCODE_FAIL;
     }
-    uapi_cat1_wakeup_cat1(1);
+    cat1_api_wakeup_cat1(1);
+    cat1_api_keep_wakeup(1);
     u32_t sret= OsShellPing( argc, (const char *)argv[0]);
     printf("CAT1TEST ATCMD  ping   ret = 0x%X\n",sret);
-    uapi_cat1_wakeup_cat1(0);
+    cat1_api_keep_wakeup(0);
+    cat1_api_wakeup_cat1(0);
     return ERRCODE_SUCC;
 }
 static uint32_t cat1_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
@@ -236,83 +240,16 @@ static uint32_t cat1_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCm
     return ERRCODE_SUCC;
 }
 
-static uint32_t AT_CALL_ifconfig(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
-    uint32_t argc = 0;
-
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
-    if (ret != CUSTOM_UTILS_SUCCESS) {
-        printf("CAT1TEST ATCMD Convert Command Failed\n");
-        return ERRCODE_FAIL;
-    }
-
-    // if (argc != 1) {
-    //     printf("CAT1TEST ATCMD Set Parameter Failed\n");
-    //     return ERRCODE_FAIL;
-    // }
-    test_call_incomming();
-    
-    return ERRCODE_SUCC;
-}
-
-static uint32_t AT_cat1_checkota(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    printf("CAT1TEST ATCMD  cat1 checkota\n");
-    cat1_ota_update("0");
-    return ERRCODE_SUCC;
-}
 static uint32_t at_cat1_atcmd(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
     printf("CAT1TEST ATCMD %s \n",para);
-    cat1_at_cmd((char*)para);
-    return ERRCODE_SUCC;
-}
-
-
-static uint32_t ADD_ADDRESS(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
-    uint32_t argc = 0;
+    cat1_cmd_send(CMD_4G_AT,para,strlen(para));
 
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
-    if (ret != CUSTOM_UTILS_SUCCESS) {
-        printf("CAT1TEST ATCMD Convert Command Failed\n");
-        return ERRCODE_FAIL;
-    }
-    #ifdef FD230
-    OHOS::add_addressbook_by_AT((char *)argv[0],(char *)argv[1]);
-    #endif
-    //uapi_cat1_wakeup_cat1(1);
-    //u32_t sret= OsShellPing( argc, (const char *)argv[0]);
-    //printf("CAT1TEST ATCMD  ping   ret = 0x%X\n",sret);
-    //uapi_cat1_wakeup_cat1(0);
-   
     return ERRCODE_SUCC;
 }
 
 
-static uint32_t read_ADDRESS(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
-    uint32_t argc = 0;
-
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
-    if (ret != CUSTOM_UTILS_SUCCESS) {
-        printf("CAT1TEST ATCMD Convert Command Failed\n");
-        return ERRCODE_FAIL;
-    }
-    #ifdef FD230
-    OHOS::read_addressbook_bin_file();
-    #endif
-    return ERRCODE_SUCC;
-}
-
 #include "audio_manager_c_wrapper.h"
 
 static uint32_t VoiceCallSetVolume(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
@@ -337,58 +274,10 @@ static uint32_t VoiceCallSetVolume(uint8_t *para, uint32_t paraLen, char *strCom
     return 0;
 }
 
-static uint32_t VoiceCallcontrol(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-    UNUSED(strCommonCmd);
-    uint8_t argv[CUSTOM_UTILS_MAX_ARGC][CUSTOM_UTILS_MAX_ARGV_LEN] = { 0 };
-    uint32_t argc = 0;
-
-    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
-    if (ret != CUSTOM_UTILS_SUCCESS) {
-        printf("CAT1TEST ATCMD Convert Command Failed\n");
-        return ERRCODE_FAIL;
-    }
-
-    int32_t linearVolume = atoi((char *)argv[0]);
-    if(linearVolume)
-    {
-        uapi_cat1_start_volte_voice();
-    }
-    else
-    {
-        uapi_cat1_stop_volte_voice();
-    }
-    return 0;
-}
-
-
-static uint32_t custom_cat1_start_ota_pyupdate(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-#ifdef SUPPORT_CAT1_SERVICE
-    Cat1_OTA(CAT1_TCP_START_OTA);
-#endif
-    return ERRCODE_SUCC;
-}
-static uint32_t custom_cat1_stop_ota_pyupdate(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-#ifdef SUPPORT_CAT1_SERVICE
-    Cat1_OTA(CAT1_TCP_STOP_OTA);
-#endif
-    return ERRCODE_SUCC;
-}
-static uint32_t custom_cat1_send_bak_mode(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
-{
-
-#ifdef SUPPORT_CAT1_SERVICE
-    send_bak_mode_toCat1();
-#endif
-    return ERRCODE_SUCC;
-}
-
 #ifdef SUPPORT_CAT1_SERVICE
 #include "lwip/altcp_tls.h"
 #include "lwip/apps/http_client.h"
-#define USING_HTTPS
+// #define USING_HTTPS
 #ifdef USING_HTTPS
 
 // SSL CA PEMs  
@@ -456,7 +345,7 @@ errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *ur
         g_http_download_started = 1;
     }
      //通讯开始,唤醒cat1
-    uapi_cat1_keep_wakeup(1);
+    cat1_api_keep_wakeup(1);
     //httpc_connection_t settings = {0};
 
 
@@ -510,7 +399,7 @@ errcode_t http_single_download_start( uint8_t *server, uint16_t port,uint8_t *ur
 errcode_t http_single_download_stop(void)
 {
     //通讯结束,休眠cat1
-    uapi_cat1_keep_wakeup(0);
+    cat1_api_keep_wakeup(0);
     g_http_download_started = 0;
     return ERRCODE_SUCC;
 }
@@ -554,7 +443,7 @@ static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char
     }
 
     //通讯开始,唤醒cat1
-    uapi_cat1_keep_wakeup(1);
+    cat1_api_keep_wakeup(1);
     uint8_t *server = (uint8_t*)argv[0];
     uint16_t port = atoi((const char*)argv[1]);
     uint8_t *uri = (uint8_t*)argv[2];
@@ -581,22 +470,14 @@ static const at_cmd_table_t g_cat1_cmd[] = {
     { (char *)"AT^CAT1HUNGUP",      at_cat1_hungup, (char *)"1" },
     { (char *)"AT^CAT1GETSIGNAL",   at_cat1_getsignal, (char *)"1" },
     { (char *)"AT^CAT1GETTIME",     at_cat1_gettime, (char *)"1" },
+    { (char *)"AT^CAT1GETVER",      at_cat1_getver, (char *)"1" },
     { (char *)"AT^CAT1NETTEST",     cat1_nettest, (char *)"1" },
     { (char *)"AT^PING",            cat1_ping, (char *)"1" },
-    { (char *)"AT^CAT1WAKECAT1",    cat1_wakeup, (char *)"1" },
+    { (char *)"AT^WAKECAT1",        cat1_wakeup, (char *)"1" },
     { (char *)"AT^IFCONFIG",        cat1_ifconfig, (char *)"1" },
-    { (char *)"AT^CAT1GETVER",      at_cat1_getver, (char *)"1" },
     { (char *)"AT^CAT1AT",          at_cat1_atcmd, (char *)"1" },
-    { (char *)"AT^CAT1OTA",         AT_cat1_checkota, (char *)"1" },
-       { (char *)"AT^CALL_1",          AT_CALL_ifconfig, (char *)"1" },
     { (char *)"AT^CALLVOLUME",      VoiceCallSetVolume, (char *)"1" },
-    { (char *)"AT^CALLVOICE",       VoiceCallcontrol, (char *)"1" },
-    
-    { (char *)"AT^CAT1STARTOTAPY",  custom_cat1_start_ota_pyupdate, (char *)" "},
-    { (char *)"AT^CAT1STOPOTAPY",   custom_cat1_stop_ota_pyupdate, (char *)" "},
-    { (char *)"AT^CAT1SENDBAKMODE", custom_cat1_send_bak_mode, (char *)" "},
     { (char *)"AT^HTTPDOWNLOAD",     custom_start_ota_download, (char *)" " },
-
 };
 
 at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count)
index 9084b1b..9e90a50 100644 (file)
@@ -6,18 +6,24 @@
  */
 
 #include "cat1_porting.h"
-#include "wearable_log.h"
+#include "cat1_log.h"
 #include "pm_definition.h"
+
+uint8_t g_cat1_enable_debug=CAT1_LOG_LEVEL_INFO;
+
+static uint16_t g_timezone_quarters = 0xFFFF;
 /**
  * return quarters for timezone 
 */
-uint16_t uapi_get_timezone(void)
+static uint16_t get_timezone(void)
 {
     /*从系统中获取timezone*/
-    return (8*15) ;
+    if (g_timezone_quarters==0xFFFF) 
+        return (8*15) ;
+    
+    return g_timezone_quarters;
 }
 
-
 #define SECONDS_PER_MINUTE      60 /* seconds per minute */
 #define MINUTES_PER_HOUR        60   /* minutes per hour */
 #define MINUTES_PER_QUARTER     15   /* seconds per quarter */
@@ -28,7 +34,11 @@ uint16_t uapi_get_timezone(void)
 #define MAX_TIMEZONE_HOURS      24
 #define TIME_MAX                64
 
-uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters)
+static void set_timezone(uint16_t timezone_quarters)
+{
+    g_timezone_quarters = timezone_quarters;
+}
+static uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters)
 {
     printf("sync time utc timestamp %d, timezone_in_quarters %d \r\n", timestamp, timezone_quarters);
     uint32_t seconds;
@@ -39,7 +49,7 @@ uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters)
         return ERRCODE_FAIL;
     } 
     seconds = timestamp;
-    uapi_set_timezone(timezone_quarters);
+    set_timezone(timezone_quarters);
     struct timeval tv = {0};
     struct timezone tzone = {0};
     tv.tv_sec = seconds;
@@ -48,29 +58,167 @@ uint32_t sync_time_utc(uint32_t timestamp, uint32_t timezone_quarters)
     tzone.tz_minuteswest = timezone_quarters * MINUTES_PER_QUARTER;
     return settimeofday(&tv, &tzone);
 }
-void uapi_set_timezone(uint16_t timezone_quarters)
-{
-    
-}
 
+static time_ctl_funcs_t g_cat1_time_ctl_funcs={
+    get_timezone,
+    set_timezone,
+    sync_time_utc,
+};
 
-void uapi_cat1_remove_cat1_vote(void)
+
+void cat1_api_remove_cat1_vote(void)
 {
     uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1);
     if (cnt == 1) {
         uapi_pm_remove_sleep_veto(PM_ID_CAT1);
     } else {
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has delete pm_id_cat1 vote\r\n");
+        // cat1_print_dbg("CAT1 SERVICE MCU has delete pm_id_cat1 vote\r\n");
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"\r\nCAT1 SERVICE MCU SLEEP SUCCESS\r\n");
+    cat1_print_dbg("\r\nCAT1 SERVICE MCU SLEEP SUCCESS\r\n");
 }
-void uapi_cat1_add_cat1_vote(void)
+void cat1_api_add_cat1_vote(void)
 {
     uint8_t cnt = pm_veto_get_id_cnt(PM_ID_CAT1);
     if (cnt == 0) {
         uapi_pm_add_sleep_veto(PM_ID_CAT1);
     } else {
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n");
+        // cat1_print_dbg("CAT1 SERVICE MCU has got pm_id_cat1 vote\r\n");
     }
-    WEARABLE_LOGE(WEARABLE_LOG_MODULE_MAIN_SERVICE,"\r\nCAT1 SERVICE MCU WAKEUP SUCCESS\r\n");
+    cat1_print_dbg("\r\nCAT1 SERVICE MCU WAKEUP SUCCESS\r\n");
+}
+
+static uint8_t cat1_voice=0;
+
+uint8_t cat1_api_get_cat1_volte_voice_state(void)
+{
+    cat1_print_dbg("cat1_api_get_cat1_volte_voice_state %d \n",cat1_voice);
+    return cat1_voice;
+}
+
+int32_t cat1_api_start_cat1_volte_voice(void)
+{
+    cat1_print_dbg("cat1_api_start_cat1_volte_voice\n");
+
+    int32_t ret = ERRCODE_FAIL;
+    int32_t argc = 1;
+    uint8_t *argv = (uint8_t *)"start";
+
+    if(cat1_voice==0)
+    {
+        ret = VoiceCallVolteSample(argc, (const char **)&argv);
+        if(ret==0) 
+        cat1_voice=1;
+    }
+    
+ 
+    cat1_print_dbg("ret %d %d ",ret, cat1_voice);
+    
+    return ret;   
+}
+
+int32_t cat1_api_stop_cat1_volte_voice(void)
+{
+    cat1_print_dbg("cat1_api_stop_cat1_volte_voice\n");
+
+    int32_t ret = ERRCODE_FAIL;
+    int32_t argc = 1;
+    uint8_t *argv = (uint8_t *)"stop";
+
+    if(cat1_voice!=0)
+    {
+        ret = VoiceCallVolteSample(argc, (const char **)&argv);
+        if(ret==0) 
+        cat1_voice=0;
+    }
+
+    cat1_print_dbg("ret %d %d ",ret, cat1_voice);
+
+    return ret;   
+
+}
+
+#include "power_display_service.h"
+/*获取屏幕状态: return 1 need update */
+uint8_t cat1_api_need_update_signal(void)
+{
+    const power_display_svr_api_t *display_api = power_display_svr_get_api();
+    screen_state_t state = display_api->get_screen_state();
+    // printf("uapi_get_screen_state = %s . \r\n", state==SCREEN_ON?"on":"off");
+    if( state == SCREEN_ON){
+        return 1;
+    }else{
+        return 0;
+    }
+}
+errcode_t cat1_msg_callback(MESSAGE_4G_T msg, void *msg_buf, uint16_t msglen)
+{
+
+    switch(msg)
+    {
+        case MESSAGE_4G_POWERON://无参数
+            cat1_print_warning("MESSAGE_4G_POWERON pyver(%s) modemver(%s)",
+                cat1_api_runtime_get_cat1_pyver(),
+                cat1_api_runtime_get_cat1_modemver()
+                );
+            break;
+        case MESSAGE_4G_POWEROFF: //无参数
+            cat1_print_warning("MESSAGE_4G_POWEROFF");
+            break;
+        case MESSAGE_4G_NETWORK_CONNECTED: //无参数
+            cat1_print_warning("MESSAGE_4G_NETWORK_CONNECTED");
+            break;
+        case MESSAGE_4G_NETWORK_DISCONNECTED: //无参数
+            cat1_print_warning("MESSAGE_4G_NETWORK_DISCONNECTED");
+            break;
+        case MESSAGE_4G_NETWORK_STAT_CHANGED: //含signal,sim,运营商,
+            cat1_print_warning("MESSAGE_4G_NETWORK_STAT_CHANGED netstat(%d),signal(%d),sim(%d),network(%s),imei(%s)",
+                cat1_api_runtime_get_cat1_networkstat(),
+                cat1_api_runtime_get_cat1_signal(),
+                cat1_api_runtime_get_cat1_simstat(),
+                cat1_api_runtime_get_cat1_networktype()==0?"无网络":(cat1_api_runtime_get_cat1_networktype()==1?"GSM":(cat1_api_runtime_get_cat1_networktype()==2?"3G":"4G/LTE")),
+                cat1_api_runtime_get_cat1_imei()
+            );
+            break;
+        case MESSAGE_4G_CALL_COMMING: //带电话号
+            cat1_print_warning("MESSAGE_4G_CALL_COMMING %s",msg_buf);
+            break;
+        case MESSAGE_4G_CALL_CONNECTED: //带电话号
+            cat1_print_warning("MESSAGE_4G_CALL_CONNECTED %s",msg_buf);
+            break;
+        case MESSAGE_4G_CALL_DISCONNECTED: //带电话号
+            cat1_print_warning("MESSAGE_4G_CALL_DISCONNECTED %s",msg_buf);
+            break;
+        case MESSAGE_4G_SMS_RECEIVED: //返回值为字符串
+            cat1_print_warning("MESSAGE_4G_SMS_RECEIVED");
+            break;
+        case MESSAGE_4G_AT_RECEIVED: //返回值为字符串
+            cat1_print_warning("MESSAGE_4G_AT_RECEIVED");
+            break;
+        default:
+
+            break;
+    }
+    return ERRCODE_SUCC;
+}
+
+errcode_t cat1_api_porting_init(void)
+{
+
+    cat1_register_time_ctl_functions(&g_cat1_time_ctl_funcs);
+    ctl_pin_4g_t pins={
+        PIN_NONE, //bat_pin
+        1,
+        S_AGPIO_L23, // pwr_pin
+        1,
+        S_AGPIO_L28,//reset_pin
+        0,
+        S_AGPIO_L31,//ring_pin  
+        1,//risingEdge
+        S_AGPIO_L30,//wakemodem_pin
+        1,
+        };
+    cat1_register_ctl_pin(pins);
+    cat1_register_msg_callback(cat1_msg_callback);
+
+    return ERRCODE_SUCC;
 }
diff --git a/code/sdk/zhihui/4gTest/net_test/lwip_test.h b/code/sdk/zhihui/4gTest/net_test/lwip_test.h
new file mode 100644 (file)
index 0000000..3359688
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LWIP_TEST_H
+#define LWIP_TEST_H
+
+#include "lwip/arch.h"
+#include "lwip/sockets.h"
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include "securec.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int g_testCase;
+extern int g_testError;
+extern int g_testTemp;
+#define LWIP_TEST_RET_OK    0
+#define LWIP_TEST_RET_ERR   1
+
+#define LOCALHOST "127.0.0.1"
+#define STACK_IP LOCALHOST
+#define STACK_PORT 2277
+#define PEER_PORT STACK_PORT
+#define SERVER_PORT STACK_PORT
+#define CLIENT_PORT 2288
+#define PEER_IP LOCALHOST
+#define BUF_SIZE (128 * 1)
+#define IOV_LENGTH 2
+#define STACK_TEST_SIZE (0x800UL)
+
+#define ICUNIT_ASSERT_NOT_EQUAL(a, b, c)  if ((a) == (b)) { \
+                                              g_testError = (c); \
+                                              LWIP_ASSERT("lwip test", 0); \
+                                          }
+#define ICUNIT_ASSERT_EQUAL(a, b, c)      if ((a) != (b)) { \
+                                              g_testError = (c); \
+                                              LWIP_ASSERT("lwip test", 0); \
+                                          }
+
+                                          
+#include "debug_print.h"
+
+#define LogPrintln(fmt, arg...) \
+    PRINT("[lwip] %s: " fmt "\n", __FUNCTION__, ##arg)
+    
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LWIP_TEST_H */
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_001.c
new file mode 100644 (file)
index 0000000..a92e9ba
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+
+#define TEST_CASE 110
+
+int SocketTest(void)
+{
+    LogPrintln("net_socket_test_001.c enter");
+    g_testCase = TEST_CASE;
+    int fd = socket(0, 0, 0);
+    LWIP_ASSERT("socket invalid param.", fd == -1);
+    return LWIP_TEST_RET_OK;
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_002.c
new file mode 100644 (file)
index 0000000..139b8ef
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define MSG "Hi, I am UDP"
+#define TEST_CASE 120
+
+static char g_buf[BUF_SIZE + 1] = { 0 };
+
+void UdpTestTask(void *p)
+{
+    (void)p;
+    LogPrintln("net_socket_test_002.c enter");
+    g_testCase = TEST_CASE;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    int ret;
+    struct msghdr msg = { 0 };
+    struct iovec iov[IOV_LENGTH] = { 0 };
+    int recvCount = 0;
+
+    /* socket creation */
+    sfd = socket(AF_INET, SOCK_DGRAM, 0);
+    LWIP_ASSERT("socket invalid param.", sfd != -1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT);
+    ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LWIP_ASSERT("socket invalid param.", ret == 0);
+
+    /* send */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    clnAddr.sin_port = htons(PEER_PORT);
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), MSG);
+    ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr,
+        (socklen_t)sizeof(clnAddr));
+    LWIP_ASSERT("socket invalid param.", ret != -1);
+
+    ret = ioctlsocket(sfd, FIONREAD, &recvCount);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 1);
+    LogPrintln("udp recv count %d", recvCount);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
+        &clnAddrLen);
+    LWIP_ASSERT("socket invalid param.", ret == strlen(MSG));
+
+    /* sendmsg */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    clnAddr.sin_port = htons(PEER_PORT);
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), MSG);
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = IOV_LENGTH;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = strlen(MSG);
+    iov[1].iov_base = g_buf;
+    iov[1].iov_len = strlen(MSG);
+    ret = sendmsg(sfd, &msg, 0);
+    LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG));
+
+    /* recvmsg */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = 1;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = sizeof(g_buf);
+    ret = recvmsg(sfd, &msg, 0);
+    LWIP_ASSERT("socket invalid param.", ret == IOV_LENGTH * strlen(MSG));
+
+    /* close socket */
+    ret = closesocket(sfd);
+    LWIP_ASSERT("socket invalid param.", ret != -1);
+    return;
+}
+
+int UdpTest()
+{
+    int ret = sys_thread_new("udp_test", UdpTestTask, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+    return ret;
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_003.c
new file mode 100644 (file)
index 0000000..d9e8961
--- /dev/null
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define SRV_MSG "Hi, I am TCP server"
+#define CLI_MSG "Hi, I am TCP client"
+#define TEST_CASE 130
+
+static char g_buf[BUF_SIZE + 1] = { 0 };
+
+static int SampleTcpServer()
+{
+    g_testCase++;
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    struct msghdr msg = { 0 };
+    struct iovec iov[IOV_LENGTH] = { 0 };
+    int ret;
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create server socket inet stream: %d", lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT);
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    LogPrintln("listen socket %d: %d", lsfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
+
+    /* send */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
+    ret = send(sfd, g_buf, strlen(SRV_MSG), 0);
+    LogPrintln("server send on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recv(sfd, g_buf, sizeof(g_buf), 0);
+    LogPrintln("server recv on socket %d: %d", sfd, ret);
+    LogPrintln("ser:%s", g_buf);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 6);
+
+    /* sendmsg */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    clnAddr.sin_port = htons(PEER_PORT);
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = IOV_LENGTH;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = strlen(SRV_MSG);
+    iov[1].iov_base = g_buf;
+    iov[1].iov_len = strlen(SRV_MSG);
+    ret = sendmsg(sfd, &msg, 0);
+    LogPrintln("sendmsg on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 7);
+
+    /* recvmsg */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = 1;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = sizeof(g_buf);
+    ret = recvmsg(sfd, &msg, 0);
+    LogPrintln("recvmsg on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(CLI_MSG), 8);
+
+    ret = shutdown(sfd, SHUT_RDWR);
+    LogPrintln("shutdown socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 9);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11);
+
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+    g_testCase++;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    int ret;
+    struct msghdr msg = { 0 };
+    struct iovec iov[IOV_LENGTH] = { 0 };
+    struct sockaddr addr;
+    socklen_t addrLen = sizeof(addr);
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create client socket inet stream: %d", sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(PEER_PORT);
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 11);
+
+    /* test getpeername */
+    ret = getpeername(sfd, &addr, &addrLen);
+    LogPrintln("getpeername %d %s:%d: %d", \
+        sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 12);
+    ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13);
+    ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
+        inet_addr(PEER_IP), 14);
+
+    /* test getsockname */
+    ret = getsockname(sfd, &addr, &addrLen);
+    LogPrintln("getsockname %d %s:%d: %d", \
+        sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 15);
+    ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 16);
+    ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
+        inet_addr(STACK_IP), 17);
+
+    /* send */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
+    ret = send(sfd, g_buf, strlen(CLI_MSG), 0);
+    LogPrintln("client send on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 18);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recv(sfd, g_buf, sizeof(g_buf), 0);
+    LogPrintln("client recv on socket %d: %d", sfd, ret);
+    LogPrintln("cli:%s", g_buf);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19);
+
+    /* sendmsg */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    clnAddr.sin_port = htons(PEER_PORT);
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = IOV_LENGTH;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = strlen(CLI_MSG);
+    iov[1].iov_base = g_buf;
+    iov[1].iov_len = strlen(CLI_MSG);
+    ret = sendmsg(sfd, &msg, 0);
+    LogPrintln("sendmsg on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 2 * strlen(CLI_MSG), 20);
+
+    /* recvmsg */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
+    msg.msg_name = &clnAddr;
+    msg.msg_namelen = sizeof(clnAddr);
+    msg.msg_iov = iov;
+    msg.msg_iovlen = 1;
+    iov[0].iov_base = g_buf;
+    iov[0].iov_len = sizeof(g_buf);
+    ret = recvmsg(sfd, &msg, 0);
+    LogPrintln("recvmsg on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, IOV_LENGTH * strlen(SRV_MSG), 21);
+
+    ret = shutdown(sfd, SHUT_RDWR);
+    LogPrintln("shutdown socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 22);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpServer();
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpClient();
+}
+
+void TcpTest()
+{
+    LogPrintln("net_socket_test_003.c enter");
+    g_testCase = TEST_CASE;
+    int ret;
+    ret = sys_thread_new("tcp_server", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+
+    ret = sys_thread_new("tcp_client", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_004.c
new file mode 100644 (file)
index 0000000..e1a8410
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+
+#define TEST_CASE 140
+#define OPT_TIMEOUT 1000
+
+int SockOptTest()
+{
+    LogPrintln("net_socket_test_004.c enter");
+    g_testCase = TEST_CASE;
+    int ret, error, flag;
+    struct timeval timeout;
+    socklen_t len;
+
+    int fd = socket(AF_INET, SOCK_STREAM, 0);
+    ICUNIT_ASSERT_NOT_EQUAL(fd, -1, 1);
+
+    error = -1;
+    len = sizeof(error);
+    ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
+    LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \
+        fd, ret, error, len, errno);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+    ICUNIT_ASSERT_EQUAL(error, 0, 3);
+
+    len = sizeof(timeout);
+    ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 4);
+
+    timeout.tv_sec = OPT_TIMEOUT;
+    len = sizeof(timeout);
+    ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, len);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 5);
+
+    (void)memset_s(&timeout, len, 0, len);
+    ret = getsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, &len);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 6);
+    ICUNIT_ASSERT_EQUAL(timeout.tv_sec, OPT_TIMEOUT, 7);
+
+    error = -1;
+    len = sizeof(error);
+    ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
+    LogPrintln("getsockopt(%d, SOL_SOCKET, SO_ERROR, &error, &len)=%d, error=%d, len=%d, errno=%d", \
+        fd, ret, error, len, errno);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 8);
+    ICUNIT_ASSERT_EQUAL(error, 0, 9);
+
+    flag = 1;
+    ret = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag));
+    LogPrintln("setsockopt(TCP_NODELAY) ret=%d", ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 10);
+
+    ret = closesocket(fd);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 11);
+
+    return LWIP_TEST_RET_OK;
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_005.c
new file mode 100644 (file)
index 0000000..c7ec428
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+
+#define TEST_CASE 150
+
+int ByteOrderTest(void)
+{
+    LogPrintln("net_socket_test_005.c enter");
+#if BYTE_ORDER == LITTLE_ENDIAN
+    g_testCase = TEST_CASE + 1;
+    uint32_t hl = ntohl(0x12345678);
+    ICUNIT_ASSERT_EQUAL(hl, 0x78563412, 1);
+
+    uint32_t nl = htonl(0x12345678);
+    ICUNIT_ASSERT_EQUAL(nl, 0x78563412, 2);
+
+    uint16_t hs = ntohs(0x1234);
+    ICUNIT_ASSERT_EQUAL(hs, 0x3412, 3);
+
+    uint16_t ns = htons(0x1234);
+    ICUNIT_ASSERT_EQUAL(ns, 0x3412, 4);
+#else
+    g_testCase = TEST_CASE;
+    uint32_t hl = ntohl(0x12345678);
+    ICUNIT_ASSERT_EQUAL(hl, 0x12345678, 5);
+
+    uint32_t nl = htonl(0x12345678);
+    ICUNIT_ASSERT_EQUAL(nl, 0x12345678, 6);
+
+    uint16_t hs = ntohs(0x1234);
+    ICUNIT_ASSERT_EQUAL(hs, 0x1234, 7);
+
+    uint16_t ns = htons(0x1234);
+    ICUNIT_ASSERT_EQUAL(ns, 0x1234, 8);
+#endif
+    return LWIP_TEST_RET_OK;
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_006.c
new file mode 100644 (file)
index 0000000..59a2789
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+
+#define TEST_CASE 160
+#define TEMP_BUF_SIZE 32
+int InetTest()
+{
+    LogPrintln("net_socket_test_006.c enter");
+    g_testCase = TEST_CASE;
+    struct in_addr in;
+    int ret = inet_pton(AF_INET, "300.10.10.10", &in);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 1);
+
+    ret = inet_pton(AF_INET, "10.11.12.13", &in);
+    ICUNIT_ASSERT_EQUAL(ret, 1, 2);
+#if BYTE_ORDER == LITTLE_ENDIAN
+    g_testCase++;
+    ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0d0c0b0a, 3);
+#else
+    ICUNIT_ASSERT_EQUAL(in.s_addr, 0x0a0b0c0d, 4);
+#endif
+
+    const char *p = inet_ntoa(in);
+    ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 5);
+
+    char buf[TEMP_BUF_SIZE];
+    p = inet_ntop(AF_INET, &in, buf, sizeof(buf));
+    ICUNIT_ASSERT_EQUAL(p, buf, 6);
+    ICUNIT_ASSERT_EQUAL(strcmp(p, "10.11.12.13"), 0, 7);
+
+    return LWIP_TEST_RET_OK;
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_007.c
new file mode 100644 (file)
index 0000000..bb4d6c9
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+static char g_buf[BUF_SIZE + 1] = { 0 };
+static char g_buf_temp[BUF_SIZE + 1] = { 0 };
+
+#define SEND_UDP_COUNT 10000  // send count
+#define TEST_CASE 170
+
+static void UdpTestMoreTask(void *p)
+{
+    (void)p;
+    LogPrintln("net_socket_test_007.c enter");
+    if (g_testCase < TEST_CASE) {
+        g_testCase = TEST_CASE;
+    } else {
+        g_testCase++;
+    }
+
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    int ret;
+    int i;
+
+    /* socket creation */
+    sfd = socket(AF_INET, SOCK_DGRAM, 0);
+    LWIP_ASSERT("socket invalid param.", sfd != -1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT);
+    ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LWIP_ASSERT("socket invalid param.", ret == 0);
+
+    /* send */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    clnAddr.sin_port = htons(PEER_PORT);
+    if (g_buf_temp[0] == '\0') {
+        for (i = 0; i < BUF_SIZE; i++) {
+            g_buf_temp[i] = 'U';
+        }
+        g_buf_temp[BUF_SIZE] = '\0';
+    }
+
+    LogPrintln("udp begin send");
+    for (i = 0; i < SEND_UDP_COUNT; i++) {
+        ret = memcpy_s(g_buf, sizeof(g_buf), g_buf_temp, sizeof(g_buf_temp));
+        ICUNIT_ASSERT_EQUAL(ret, EOK, 1);
+        ret = sendto(sfd, g_buf, BUF_SIZE, 0, (struct sockaddr*)&clnAddr, (socklen_t)sizeof(clnAddr));
+        LWIP_ASSERT("socket invalid param.", ret != -1);
+
+        /* recv */
+        (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+        ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
+            &clnAddrLen);
+        LWIP_ASSERT("socket invalid param.", ret == BUF_SIZE);
+    }
+    LogPrintln("udp end send");
+
+    /* close socket */
+    ret = closesocket(sfd);
+    LWIP_ASSERT("socket invalid param.", ret != -1);
+}
+
+void UdpTestMore()
+{
+    int ret;
+    ret = sys_thread_new("udp_more", UdpTestMoreTask, NULL,
+        STACK_TEST_SIZE * 2, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
+}
+
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_008.c
new file mode 100644 (file)
index 0000000..f46106a
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define SEND_TCP_COUNT 1000  // send count
+#define STACK_PORT_8 2288
+#define TEST_CASE 180
+
+static char g_serverSendBuf[BUF_SIZE + 1] = { 0 };
+static char g_clientRecvBuf[BUF_SIZE + 1] = { 0 };
+
+static void InitMsgBuf()
+{
+    int i;
+    if (g_serverSendBuf[0] != '\0') {
+        return;
+    }
+    for (i = 0; i < BUF_SIZE; i++) {
+        g_serverSendBuf[i] = 'S';
+    }
+    g_serverSendBuf[BUF_SIZE] = '\0';
+}
+
+static int SampleTcpServer()
+{
+    g_testCase++;
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    int ret;
+    int i;
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create server socket inet stream: %d", lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT_8);
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    LogPrintln("listen socket %d: %d", lsfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
+
+    for (i = 0; i < SEND_TCP_COUNT; i++) {
+        /* send */
+        ret = send(sfd, g_serverSendBuf, BUF_SIZE, 0);
+        ICUNIT_ASSERT_EQUAL(ret, BUF_SIZE, 5);
+    }
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+    g_testCase++;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    int ret;
+    int i;
+    struct sockaddr addr;
+    socklen_t addrLen = sizeof(addr);
+    int recvCount = 0;
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create client socket inet stream: %d", sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 7);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(STACK_PORT_8);
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 8);
+
+    /* test getpeername */
+    ret = getpeername(sfd, &addr, &addrLen);
+    LogPrintln("getpeername %d %s:%d: %d",
+        sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 9);
+    ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 10);
+    ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
+        inet_addr(PEER_IP), 11);
+
+    /* test getsockname */
+    ret = getsockname(sfd, &addr, &addrLen);
+    LogPrintln("getsockname %d %s:%d: %d",
+        sfd, inet_ntoa(((struct sockaddr_in*)&addr)->sin_addr), ntohs(((struct sockaddr_in*)&addr)->sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 12);
+    ICUNIT_ASSERT_EQUAL(addrLen, sizeof(struct sockaddr_in), 13);
+    ICUNIT_ASSERT_EQUAL(((struct sockaddr_in*)&addr)->sin_addr.s_addr, \
+        inet_addr(STACK_IP), 14);
+
+    LogPrintln("tcp begin recv");
+    for (i = 0; i < 2 * SEND_TCP_COUNT; i++) {
+        /* recv */
+        (void)memset_s(g_clientRecvBuf, sizeof(g_clientRecvBuf), 0, sizeof(g_clientRecvBuf));
+        ret = recv(sfd, g_clientRecvBuf, BUF_SIZE, 0);
+        recvCount += ret;
+        if (recvCount >= BUF_SIZE * SEND_TCP_COUNT) {
+            LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i);
+            break;
+        }
+    }
+    ICUNIT_ASSERT_EQUAL(recvCount, BUF_SIZE * SEND_TCP_COUNT, recvCount);
+    LogPrintln("tcp end recv");
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17);
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpServer();
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpClient();
+}
+
+void TcpTestMore()
+{
+    LogPrintln("net_socket_test_008.c enter");
+    if (g_testCase < TEST_CASE) {
+        g_testCase = TEST_CASE;
+    }
+
+    int ret;
+    InitMsgBuf();
+    ret = sys_thread_new("tcp_server_more", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 17);
+
+    ret = sys_thread_new("tcp_client_more", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 18);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_009.c
new file mode 100644 (file)
index 0000000..95b678f
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define SRV_MSG "Hi, I am TCP server"
+#define CLI_MSG "Hi, I am TCP client"
+
+#define TEST_CASE 190
+#define STACK_PORT_9 2299
+#define TIME_OUT 10   // timeout 10s
+
+static char g_buf[BUF_SIZE + 1] = { 0 };
+
+static int SampleTcpServer()
+{
+#if LWIP_SOCKET_SELECT
+    g_testCase++;
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    fd_set fdsr;
+    struct timeval tv;
+    int ret;
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create server socket inet stream: %d", lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT_9);
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    LogPrintln("listen socket %d: %d", lsfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    FD_ZERO(&fdsr);
+    FD_SET(lsfd, &fdsr);
+    // timeout setting
+    tv.tv_sec = TIME_OUT;
+    tv.tv_usec = 0;
+
+    ret = select(lsfd + 1, &fdsr, NULL, NULL, &tv);
+    if (ret < 0) {
+        LogPrintln("select error");
+        ICUNIT_ASSERT_EQUAL(-1, 0, 4);
+    } else if (ret == 0) {
+        LogPrintln("select timeout");
+        ICUNIT_ASSERT_EQUAL(-1, 0, 5);
+    }
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6);
+
+    /* send */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), SRV_MSG);
+    ret = send(sfd, g_buf, strlen(SRV_MSG), 0);
+    LogPrintln("server send on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 7);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9);
+#endif
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+#if LWIP_SOCKET_SELECT
+    g_testCase++;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    int ret;
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create client socket inet stream: %d", sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(STACK_PORT_9);
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 11);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recv(sfd, g_buf, sizeof(g_buf), 0);
+    LogPrintln("client recv on socket %d: %d", sfd, ret);
+    LogPrintln("cli:%s", g_buf);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 12);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
+#endif
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpServer();
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpClient();
+}
+
+void TcpTestSelect()
+{
+    LogPrintln("net_socket_test_009.c enter");
+    g_testCase = TEST_CASE;
+    int ret;
+    ret = sys_thread_new("tcp_server_select", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+
+    ret = sys_thread_new("tcp_client_select", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_010.c
new file mode 100644 (file)
index 0000000..354cbbd
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define SRV_MSG "Hi, I am TCP server"
+#define CLI_MSG "Hi, I am TCP client"
+
+#define TEST_CASE 200
+#define STACK_PORT_10 2230
+#define POLL_OPEN_MAX 10
+#define TIME_OUT (1000 * 10) // timeout 10s
+static char g_buf[BUF_SIZE + 1] = { 0 };
+
+static int SampleTcpServer()
+{
+#if LWIP_SOCKET_POLL
+    g_testCase++;
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    struct pollfd client[POLL_OPEN_MAX] = {0};
+    int ret;
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create server socket inet stream: %d", lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT_10);
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("bind socket %d to %s:%d: %d", lsfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    LogPrintln("listen socket %d: %d", lsfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    client[0].fd = lsfd;
+    client[0].events = POLLIN;
+    ret = poll(client, 1, TIME_OUT);
+    if (ret < 0) {
+        LogPrintln("poll error");
+        ICUNIT_ASSERT_EQUAL(-1, 0, 4);
+    } else if (ret == 0) {
+        LogPrintln("poll timeout");
+        ICUNIT_ASSERT_EQUAL(-1, 0, 5);
+    }
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    LogPrintln("accept socket %d: %d <%s:%d>", lsfd, sfd, inet_ntoa(clnAddr.sin_addr), ntohs(clnAddr.sin_port));
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 6);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recv(sfd, g_buf, sizeof(g_buf), 0);
+    LogPrintln("server recv on socket %d: %d", sfd, ret);
+    LogPrintln("ser:%s", g_buf);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 7);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 9);
+#endif
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+#if LWIP_SOCKET_POLL
+    g_testCase++;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    int ret;
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    LogPrintln("create client socket inet stream: %d", sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(STACK_PORT_10);
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LogPrintln("connect socket %d to %s:%d: %d", sfd, inet_ntoa(srvAddr.sin_addr), ntohs(srvAddr.sin_port), ret);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 11);
+
+    /* send */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), CLI_MSG);
+    ret = send(sfd, g_buf, strlen(CLI_MSG), 0);
+    LogPrintln("client send on socket %d: %d", sfd, ret);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(CLI_MSG), 12);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
+#endif
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpServer();
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    (void)SampleTcpClient();
+}
+
+void TcpTestPoll()
+{
+    LogPrintln("net_socket_test_010.c enter");
+    g_testCase = TEST_CASE;
+    int ret;
+    ret = sys_thread_new("tcp_server_poll", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+
+    ret = sys_thread_new("tcp_client_poll", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_011.c
new file mode 100644 (file)
index 0000000..c64f9b7
--- /dev/null
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include <lwip/netif.h>
+#include <lwip/netifapi.h>
+#include <lwip/pbuf.h>
+#include <lwip/ip4_addr.h>
+#include <lwip/ip4.h>
+#include <lwip/ip.h>
+#include <lwip/def.h>
+#include <lwip/udp.h>
+#include <lwip/inet_chksum.h>
+#include "lwip/prot/iana.h"
+
+#define MSG "Hi, I am testing BT netif."
+#define STACK_IP_BT "192.168.167.1"
+#define PEER_IP_BT "100.100.100.100"
+#define GATEWAY_IP_BT "192.168.167.239"
+#define NETIF_MAC "121212"
+#define PEER_MAC "454545"
+#define NETIF_NAME_BT "bt1000"
+#define TEST_CASE 210
+static char g_buf[BUF_SIZE + 1] = { 0 };
+struct netif *btProxyNf = NULL;
+
+static void ReplayArpTask();
+static void ArpPackageProc(struct netif *netif, struct pbuf *p);
+extern void driverif_input(struct netif *netif, struct pbuf *p);
+static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p);
+
+static void ReplayUdpEncodeEthernet(struct netif *netif, struct pbuf *p)
+{
+    int ret;
+    ret = pbuf_add_header(p, SIZEOF_ETH_HDR);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 1);
+
+    struct eth_hdr *ethhdr;
+    ethhdr = (struct eth_hdr *)p->payload;
+    ethhdr->type = lwip_htons(ETHTYPE_IP);
+    SMEMCPY(&ethhdr->dest, NETIF_MAC, ETH_HWADDR_LEN);
+    SMEMCPY(&ethhdr->src,  PEER_MAC, ETH_HWADDR_LEN);
+
+    driverif_input(netif, p);
+}
+
+static void ReplayUdpEncodeIp(struct pbuf *p, ip4_addr_t *src, ip4_addr_t *dest)
+{
+    struct ip_hdr *iphdr;
+    int ret;
+#if CHECKSUM_GEN_IP_INLINE
+    u32_t chk_sum = 0;
+#endif /* CHECKSUM_GEN_IP_INLINE */
+
+   // ip header
+    ret = pbuf_add_header(p, IP_HLEN);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+    iphdr = (struct ip_hdr *)p->payload;
+    IPH_TTL_SET(iphdr, UDP_TTL);
+    IPH_PROTO_SET(iphdr, IP_PROTO_UDP);
+
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += PP_NTOHS(IP_PROTO_UDP | (ttl << 8));
+#endif /* CHECKSUM_GEN_IP_INLINE */
+
+    /* dest cannot be NULL here */
+    ip4_addr_copy(iphdr->dest, *dest);
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += ip4_addr_get_u32(&iphdr->dest) & 0xFFFF;
+    chk_sum += ip4_addr_get_u32(&iphdr->dest) >> 16;
+#endif /* CHECKSUM_GEN_IP_INLINE */
+
+    u16_t ip_hlen = IP_HLEN;
+    IPH_VHL_SET(iphdr, 4, ip_hlen / 4);
+    IPH_TOS_SET(iphdr, 0);
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += PP_NTOHS(tos | (iphdr->_v_hl << 8));
+#endif /* CHECKSUM_GEN_IP_INLINE */
+    IPH_LEN_SET(iphdr, lwip_htons(p->tot_len));
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += iphdr->_len;
+#endif /* CHECKSUM_GEN_IP_INLINE */
+    IPH_OFFSET_SET(iphdr, 0);
+    IPH_ID_SET(iphdr, lwip_htons(0));
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += iphdr->_id;
+#endif /* CHECKSUM_GEN_IP_INLINE */
+    ip4_addr_copy(iphdr->src, *src);
+
+#if CHECKSUM_GEN_IP_INLINE
+    chk_sum += ip4_addr_get_u32(&iphdr->src) & 0xFFFF;
+    chk_sum += ip4_addr_get_u32(&iphdr->src) >> 16;
+    chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
+    chk_sum = (chk_sum >> 16) + chk_sum;
+    chk_sum = ~chk_sum;
+    IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
+        iphdr->_chksum = (u16_t)chk_sum; /* network order */
+    }
+#if LWIP_CHECKSUM_CTRL_PER_NETIF
+    else {
+        IPH_CHKSUM_SET(iphdr, 0);
+    }
+#endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
+#else /* CHECKSUM_GEN_IP_INLINE */
+    IPH_CHKSUM_SET(iphdr, 0);
+#if CHECKSUM_GEN_IP
+    IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_IP) {
+        IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, ip_hlen));
+    }
+#endif /* CHECKSUM_GEN_IP */
+#endif /* CHECKSUM_GEN_IP_INLINE */
+
+    ReplayUdpEncodeEthernet(btProxyNf, p);
+}
+
+static void ReplayUdp(void *ptemp)
+{
+    struct udp_hdr *udphdr;
+    ip4_addr_t sipaddr, dipaddr;
+    int size = strlen(MSG);
+    int ret;
+    (void)ptemp;
+
+    LogPrintln("encode udp replay packet");
+    inet_pton(AF_INET, PEER_IP_BT, &sipaddr);
+    inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
+
+    struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
+    u16_t chksum = LWIP_CHKSUM_COPY(p->payload, MSG, size);
+
+    // udp header
+    ret = pbuf_add_header(p, UDP_HLEN);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 1);
+    udphdr = (struct udp_hdr *)p->payload;
+    udphdr->src = lwip_htons(STACK_PORT);
+    udphdr->dest = lwip_htons(STACK_PORT);
+    udphdr->len = lwip_htons(p->tot_len);
+    /* in UDP, 0 checksum means 'no checksum' */
+    u16_t udpchksum = ip_chksum_pseudo_partial(p, IP_PROTO_UDP, p->tot_len, UDP_HLEN, &sipaddr, &dipaddr);
+    u32_t acc = udpchksum + (u16_t)~(chksum);
+    udpchksum = FOLD_U32T(acc);
+    if (udpchksum == 0x0000) {
+        udpchksum = 0xffff;
+    }
+    udphdr->chksum = udpchksum;
+    udphdr->chksum = 0;
+
+    ReplayUdpEncodeIp(p, &sipaddr, &dipaddr);
+}
+
+static void ReplayUdpTask()
+{
+    int ret;
+    ret = sys_thread_new("replay_udp", ReplayUdp, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 3);
+}
+
+static void ParsePackageIpUdp(struct netif *netif, struct pbuf *btBuf)
+{
+    // get scr_addr and dest_addr from ip head
+    const struct ip_hdr *iphdr;
+    iphdr = (const struct ip_hdr *)btBuf->payload;
+    ip4_addr_p_t ip4_addr_scr = iphdr->src;
+    ip4_addr_p_t ip4_addr_dest = iphdr->dest;
+    char buf[32];
+    int dataLen;
+
+    // get scr_port and dest port from tcp head
+    u16_t scr_port, dest_port;
+    void *data;
+    struct udp_hdr *udphdr;
+    udphdr = (struct udp_hdr *)((u8_t *)iphdr + IPH_HL_BYTES(iphdr));
+    scr_port = udphdr->src;
+    dest_port = udphdr->dest;
+    data = (void *)((u8_t *)udphdr + UDP_HLEN);
+
+    LogPrintln("======Bt netif send package======");
+    LogPrintln("netif full name %s", netif->full_name);
+    (void)inet_ntop(AF_INET, &ip4_addr_scr.addr, buf, sizeof(buf));
+    LogPrintln("package src ip %s", buf);
+    (void)inet_ntop(AF_INET, &ip4_addr_dest.addr, buf, sizeof(buf));
+    LogPrintln("package dest ip %s", buf);
+    LogPrintln("package src port %d", lwip_ntohs(scr_port));
+    LogPrintln("package dest port %d", lwip_ntohs(dest_port));
+    LogPrintln("send data %s", (char *)data);
+    dataLen = lwip_ntohs(udphdr->len) - UDP_HLEN;
+    LogPrintln("send data length %d", dataLen);
+    ICUNIT_ASSERT_EQUAL(dataLen, strlen(MSG), 4);
+    LogPrintln("=================================");
+
+    ReplayUdpTask();
+}
+
+static void ParsePackageEthernet(struct netif *netif, struct pbuf *p)
+{
+    u16_t next_hdr_offset = SIZEOF_ETH_HDR;
+    // get src mac and dest mac
+    struct eth_hdr *ethhdr;
+    ethhdr = (struct eth_hdr *)p->payload;
+    u16_t type = ethhdr->type;
+
+    switch (type) {
+#if LWIP_IPV4 && LWIP_ARP
+        /* IP packet? */
+        case PP_HTONS(ETHTYPE_IP): // 0x0008
+            if (!(netif->flags & NETIF_FLAG_ETHARP)) {
+                return;
+            }
+            /* skip Ethernet header (min. size checked above) */
+            if (pbuf_remove_header(p, next_hdr_offset)) {
+                return;
+            } else {
+                /* pass to IP layer */
+                ParsePackageIpUdp(netif, p);
+            }
+            break;
+
+        case PP_HTONS(ETHTYPE_ARP): // 0x0608
+            if (!(netif->flags & NETIF_FLAG_ETHARP)) {
+                return;
+            }
+            /* skip Ethernet header (min. size checked above) */
+            if (pbuf_remove_header(p, next_hdr_offset)) {
+                return;
+            } else {
+                /* pass p to ARP module */
+                LogPrintln("recv arp packet");
+                ArpPackageProc(netif, p);
+            }
+            break;
+#endif /* LWIP_IPV4 && LWIP_ARP */
+
+        default:
+            LogPrintln("type is other %d", type);
+            break;
+    }
+}
+
+static void BtProxySend(struct netif *netif, struct pbuf *p)
+{
+    if (netif == NULL || p == NULL) {
+        LogPrintln("%s : netif = NUll or p = NULL!", __func__);
+        return;
+    }
+#if ETH_PAD_SIZE
+    (void)pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
+#endif
+    ParsePackageEthernet(netif, p);
+}
+
+static struct netif *CreateBtNetIf()
+{
+    struct netif *btNetif = NULL;
+    btNetif = (struct netif *)malloc(sizeof(struct netif));
+    if (btNetif == NULL) {
+        LogPrintln("%s fail : netif malloc fail!", __func__);
+        LWIP_ASSERT("btNetif malloc fail.", 0);
+        return NULL;
+    }
+    (void)memset_s(btNetif, sizeof(struct netif), 0, sizeof(struct netif));
+    btNetif->drv_send = BtProxySend;
+    btNetif->link_layer_type = BT_PROXY_IF;
+    btNetif->hwaddr_len = ETH_HWADDR_LEN;
+    (void)memcpy_s(&btNetif->hwaddr, sizeof(btNetif->hwaddr), NETIF_MAC, ETH_HWADDR_LEN);
+    (void)memcpy_s(&btNetif->full_name, sizeof(btNetif->full_name), NETIF_NAME_BT, sizeof(NETIF_NAME_BT));
+    ip4_addr_t gw, ipaddr, netmask;
+    IP4_ADDR(&gw, 192, 168, 167, 239);
+    IP4_ADDR(&ipaddr, 192, 168, 167, 1);
+    IP4_ADDR(&netmask, 255, 255, 255, 255);
+    int ret = 0;
+    if ((ret = netifapi_netif_add(btNetif, &ipaddr, &netmask, &gw, btNetif, driverif_init, tcpip_input)) != ERR_OK) {
+        LogPrintln("%s : netifapi_netif_add fail!,ret=%d", __func__, ret);
+        LWIP_ASSERT("btNetif add fail.", 0);
+        return NULL;
+    }
+    LogPrintln("netifapi_netif_add success!");
+    netif_set_link_up(btNetif);
+    netifapi_netif_set_up(btNetif);
+    return btNetif;
+}
+
+static void UdpTestNetifTask(void *p)
+{
+    (void)p;
+    LogPrintln("net_socket_test_011.c enter");
+    g_testCase = TEST_CASE;
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    struct ifreq nif;
+    int ret;
+
+    btProxyNf = CreateBtNetIf();
+
+    /* socket creation */
+    sfd = socket(AF_INET, SOCK_DGRAM, 0);
+    LWIP_ASSERT("socket invalid param.", sfd != -1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP_BT);
+    srvAddr.sin_port = htons(STACK_PORT);
+    ret = bind(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    LWIP_ASSERT("socket invalid param.", ret == 0);
+
+    char *inface = NETIF_NAME_BT;
+    (void)strcpy_s(nif.ifr_name, sizeof(nif.ifr_name), inface);
+    if (setsockopt(sfd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&nif, sizeof(nif)) < 0) {
+        LogPrintln("set intaface fail");
+        LWIP_ASSERT("set intaface fail.", 0);
+    }
+
+    /* send */
+    clnAddr.sin_family = AF_INET;
+    clnAddr.sin_addr.s_addr = inet_addr(PEER_IP_BT);
+    clnAddr.sin_port = htons(PEER_PORT);
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    (void)strcpy_s(g_buf, sizeof(g_buf), MSG);
+    ret = sendto(sfd, g_buf, strlen(MSG), 0, (struct sockaddr*)&clnAddr,
+        (socklen_t)sizeof(clnAddr));
+    LogPrintln("client send success: %d", sfd);
+    LWIP_ASSERT("socket invalid param.", ret != -1);
+
+    /* recv */
+    (void)memset_s(g_buf, sizeof(g_buf), 0, sizeof(g_buf));
+    ret = recvfrom(sfd, g_buf, sizeof(g_buf), 0, (struct sockaddr*)&clnAddr,
+        &clnAddrLen);
+    LWIP_ASSERT("socket invalid param.", ret == strlen(MSG));
+    LogPrintln("cli recv: %s", g_buf);
+
+    /* close socket */
+    ret = closesocket(sfd);
+    LWIP_ASSERT("socket invalid param.", ret != -1);
+    return;
+}
+
+int UdpTestNetif()
+{
+    int ret = sys_thread_new("udp_test_netif", UdpTestNetifTask, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+    return ret;
+}
+
+static void ArpPackageProc(struct netif *netif, struct pbuf *p)
+{
+    struct etharp_hdr *hdr;
+    ip4_addr_t sipaddr, dipaddr;
+    hdr = (struct etharp_hdr *)p->payload;
+
+    if (hdr->opcode != PP_HTONS(ARP_REQUEST)) {
+        LogPrintln("opcode %d is not arp request", hdr->opcode);
+        return;
+    }
+
+    inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr);
+    inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
+    if (memcmp(&hdr->dipaddr, &sipaddr, sizeof(ip4_addr_t)) != EOK) {
+        LogPrintln("hdr->dipaddr %u is invalid", hdr->dipaddr);
+        return;
+    }
+
+    ReplayArpTask();
+}
+
+static void ReplayArpEncodeEthernet(struct netif *netif, struct pbuf *p)
+{
+    int ret;
+    ret = pbuf_add_header(p, SIZEOF_ETH_HDR);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 1);
+
+    struct eth_hdr *ethhdr;
+    ethhdr = (struct eth_hdr *)p->payload;
+    ethhdr->type = lwip_htons(ETHTYPE_ARP);
+    SMEMCPY(&ethhdr->dest, NETIF_MAC, ETH_HWADDR_LEN);
+    SMEMCPY(&ethhdr->src,  PEER_MAC, ETH_HWADDR_LEN);
+
+    driverif_input(netif, p);
+}
+
+static void ReplayArp(void *ptemp)
+{
+    struct etharp_hdr *hdr;
+    ip4_addr_t sipaddr, dipaddr;
+
+    (void)ptemp;
+    LogPrintln("encode arp replay packet");
+    inet_pton(AF_INET, GATEWAY_IP_BT, &sipaddr);
+    inet_pton(AF_INET, STACK_IP_BT, &dipaddr);
+    struct pbuf *p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM);
+    hdr = (struct etharp_hdr *)p->payload;
+    hdr->opcode = PP_HTONS(ARP_REPLY);
+    /* Write the ARP MAC-Addresses */
+    SMEMCPY(&hdr->shwaddr, PEER_MAC, ETH_HWADDR_LEN);
+    SMEMCPY(&hdr->dhwaddr, NETIF_MAC, ETH_HWADDR_LEN);
+    /* Copy struct ip4_addr_wordaligned to aligned ip4_addr, to support compilers without
+        * structure packing. */
+    IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->sipaddr, &sipaddr);
+    IPADDR_WORDALIGNED_COPY_FROM_IP4_ADDR_T(&hdr->dipaddr, &dipaddr);
+    hdr->hwtype = PP_HTONS(LWIP_IANA_HWTYPE_ETHERNET);
+    hdr->proto = PP_HTONS(ETHTYPE_IP);
+    /* set hwlen and protolen */
+    hdr->hwlen = ETH_HWADDR_LEN;
+    hdr->protolen = sizeof(ip4_addr_t);
+
+    ReplayArpEncodeEthernet(btProxyNf, p);
+}
+
+static void ReplayArpTask()
+{
+    int ret;
+    ret = sys_thread_new("replay_arp", ReplayArp, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_012.c
new file mode 100644 (file)
index 0000000..9967c8b
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define SRV_MSG "Hi, I am TCP server"
+#define CLI_MSG "Hi, I am TCP client"
+#define TEST_CASE 220
+#define TEST_COUNT 100
+#define STACK_PORT_TCP_DUP_START 3000
+
+static int g_portServer = STACK_PORT_TCP_DUP_START;
+static int g_portClient = STACK_PORT_TCP_DUP_START;
+
+static char g_bufServer[BUF_SIZE + 1] = { 0 };
+static char g_bufClient[BUF_SIZE + 1] = { 0 };
+
+static int SampleTcpServer()
+{
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    int ret;
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(g_portServer);
+    g_portServer++;
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
+
+    /* send */
+    (void)memset_s(g_bufServer, sizeof(g_bufServer), 0, sizeof(g_bufServer));
+    (void)strcpy_s(g_bufServer, sizeof(g_bufServer), SRV_MSG);
+    ret = send(sfd, g_bufServer, strlen(SRV_MSG), 0);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 5);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 10);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 11);
+
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    int ret;
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 10);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(g_portClient);
+    g_portClient++;
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    ICUNIT_ASSERT_EQUAL(ret, 0, 11);
+
+    /* recv */
+    (void)memset_s(g_bufClient, sizeof(g_bufClient), 0, sizeof(g_bufClient));
+    ret = recv(sfd, g_bufClient, sizeof(g_bufClient), 0);
+    ICUNIT_ASSERT_EQUAL(ret, strlen(SRV_MSG), 19);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    g_testCase++;
+
+    int i;
+    for (i = 0; i < TEST_COUNT; i++) {
+        (void)SampleTcpServer();
+    }
+    LogPrintln("tcp server g_portServer = %d", g_portServer);
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    g_testCase++;
+
+    int i;
+    for (i = 0; i < TEST_COUNT; i++) {
+        (void)SampleTcpClient();
+    }
+    LogPrintln("tcp server g_portClient = %d", g_portClient);
+}
+
+void TcpTestDup()
+{
+    LogPrintln("net_socket_test_012.c enter");
+    g_testCase = TEST_CASE;
+    int ret;
+    ret = sys_thread_new("tcp_server_dup", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+
+    ret = sys_thread_new("tcp_client_dup", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c b/code/sdk/zhihui/4gTest/net_test/net_socket_test_013.c
new file mode 100644 (file)
index 0000000..e1a7623
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "lwip_test.h"
+#include "lwipopts.h"
+#include <arch/sys_arch.h>
+#include <lwip/sys.h>
+
+#define TEST_CASE 230
+#define STACK_PORT_TCP_LONG 2231
+#define TCP_LONG_BUF_SIZE (2 * 1024)
+
+static int SampleTcpServer()
+{
+    int sfd, lsfd;
+    struct sockaddr_in srvAddr = { 0 };
+    struct sockaddr_in clnAddr = { 0 };
+    socklen_t clnAddrLen = sizeof(clnAddr);
+    int ret;
+    static char serverBuf[TCP_LONG_BUF_SIZE] = {0};
+
+    /* tcp server */
+    lsfd = socket(AF_INET, SOCK_STREAM, 0);
+    ICUNIT_ASSERT_NOT_EQUAL(lsfd, -1, 1);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(STACK_IP);
+    srvAddr.sin_port = htons(STACK_PORT_TCP_LONG);
+    ret = bind(lsfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    ICUNIT_ASSERT_EQUAL(ret, 0, 2);
+
+    ret = listen(lsfd, 0);
+    ICUNIT_ASSERT_EQUAL(ret, 0, 3);
+
+    sfd = accept(lsfd, (struct sockaddr*)&clnAddr, &clnAddrLen);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 4);
+
+    /* send */
+    ret = send(sfd, serverBuf, TCP_LONG_BUF_SIZE, 0);
+    ICUNIT_ASSERT_EQUAL(ret, TCP_LONG_BUF_SIZE, 6);
+
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 7);
+    ret = closesocket(lsfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 8);
+
+    return 0;
+}
+
+static int SampleTcpClient()
+{
+    int sfd;
+    struct sockaddr_in srvAddr = { 0 };
+    int ret, i;
+    int recvCount = 0;
+    static char clientBuf[TCP_LONG_BUF_SIZE] = {0};
+
+    /* tcp client connection */
+    sfd = socket(AF_INET, SOCK_STREAM, 0);
+    ICUNIT_ASSERT_NOT_EQUAL(sfd, -1, 9);
+
+    srvAddr.sin_family = AF_INET;
+    srvAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    srvAddr.sin_port = htons(STACK_PORT_TCP_LONG);
+    ret = connect(sfd, (struct sockaddr*)&srvAddr, sizeof(srvAddr));
+    ICUNIT_ASSERT_EQUAL(ret, 0, 10);
+
+    /* recv */
+    for (i = 0; i < TCP_LONG_BUF_SIZE; i++) {
+        ret = recv(sfd, clientBuf, TCP_LONG_BUF_SIZE, 0);
+        recvCount += ret;
+        if (recvCount >= TCP_LONG_BUF_SIZE) {
+            LogPrintln("client recv on socket %d: %d, i = %d", sfd, recvCount, i);
+            break;
+        }
+    }
+    ICUNIT_ASSERT_NOT_EQUAL(i, TCP_LONG_BUF_SIZE, 12);
+    ret = closesocket(sfd);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 13);
+    return 0;
+}
+
+static void TcpServerRoutine(void *p)
+{
+    (void)p;
+    g_testCase++;
+    (void)SampleTcpServer();
+}
+
+static void TcpClientRoutine(void *p)
+{
+    (void)p;
+    g_testCase++;
+    (void)SampleTcpClient();
+}
+
+void TcpTestLong()
+{
+    LogPrintln("net_socket_test_013.c enter");
+    g_testCase = TEST_CASE;
+    int ret;
+    ret = sys_thread_new("tcp_server_long", TcpServerRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 23);
+
+    ret = sys_thread_new("tcp_client_long", TcpClientRoutine, NULL,
+        STACK_TEST_SIZE, TCPIP_THREAD_PRIO);
+    ICUNIT_ASSERT_NOT_EQUAL(ret, -1, 24);
+}
diff --git a/code/sdk/zhihui/4gTest/net_test/test_main.c b/code/sdk/zhihui/4gTest/net_test/test_main.c
new file mode 100644 (file)
index 0000000..ad6ee11
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
+ * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ *    conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ *    of conditions and the following disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used
+ *    to endorse or promote products derived from this software without specific prior written
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sys/socket.h"
+// #include "hos_cmsis_adp.h"
+#include "cmsis_os2.h"
+#include "lwip_test.h"
+
+#define LWIP_TEST_TIMEOUT 1000 // timeout 1s
+#define LWIP_TEST_COUNT_FLAG 100
+
+#define SOCKET_TEST     10
+#define UDP_TEST        20
+#define TCP_TEST        30
+#define OPT_TEST        40
+#define ORDER_TEST      50
+#define INET_TEST       60
+#define UDP_MORE_TEST   70
+#define TCP_MORE_TEST   80
+#define TCP_SELECT_TEST 90
+#define TCP_POLL_TEST   100
+#define NETIF_TEST      110
+#define TCP_DUP_TEST    120
+#define TCP_LONG_TEST   130
+
+int g_lwipTimerCount = 0;
+int g_testCase = LWIP_TEST_COUNT_FLAG;
+int g_testError = 0;
+int g_testTemp = LWIP_TEST_COUNT_FLAG;
+extern void abort(void);
+extern int SocketTest(void);
+extern int UdpTest(void);
+extern void TcpTest();
+extern int SockOptTest();
+extern int ByteOrderTest(void);
+extern int InetTest();
+extern int UdpTestMore(void);
+extern void TcpTestMore();
+extern void TcpTestSelect();
+extern void TcpTestPoll();
+extern int UdpTestNetif(void);
+extern void TcpTestDup();
+extern void TcpTestLong();
+
+
+osTimerId_t g_lwipTestTimerId = NULL;
+
+// time out 1s
+static void LwipTestTimeoutCallback(void const *argument)
+{
+    
+    g_lwipTimerCount++;
+    LogPrintln("LwipTestTimeoutCallback enter %d",g_lwipTimerCount);
+    if(g_lwipTimerCount > 130)
+    {
+           if (g_lwipTestTimerId != NULL) {
+                osTimerStop(g_lwipTestTimerId);
+           }
+           g_lwipTimerCount = 0;
+    }
+    switch (g_lwipTimerCount) {
+        case SOCKET_TEST:
+            SocketTest();
+            break;
+        case UDP_TEST:
+            UdpTest();
+            break;
+        case TCP_TEST:
+            TcpTest();
+            break;
+        case OPT_TEST:
+            SockOptTest();
+            break;
+        case ORDER_TEST:
+            ByteOrderTest();
+            break;
+        case INET_TEST:
+            InetTest();
+            break;
+        case UDP_MORE_TEST:
+            UdpTestMore();
+            break;
+        case TCP_MORE_TEST:
+            TcpTestMore();
+            break;
+        case TCP_SELECT_TEST:
+            // TcpTestSelect();
+            break;
+        case TCP_POLL_TEST:
+            // TcpTestPoll();
+            break;
+        case NETIF_TEST:
+            UdpTestNetif();
+            break;
+        case TCP_DUP_TEST:
+            TcpTestDup();
+            break;
+        case TCP_LONG_TEST:
+            TcpTestLong();
+            break;
+        default:
+          break;
+    }
+}
+
+
+void LwipTestStartTimer(uint32_t timeout)
+{
+    osStatus_t status;
+    LogPrintln("LwipTestStartTimer timeout %d",timeout);
+
+    if (g_lwipTestTimerId != NULL) {
+        status = osTimerStart(g_lwipTestTimerId, timeout);
+        if (status != osOK) {
+            return;
+        }
+    } else {
+        g_lwipTestTimerId = osTimerNew((osTimerFunc_t)LwipTestTimeoutCallback, osTimerPeriodic, NULL, NULL);
+        if (g_lwipTestTimerId == NULL) {
+            return;
+        }
+        status = osTimerStart(g_lwipTestTimerId, timeout);
+        if (status != osOK) {
+            return;
+        }
+    }
+}
+
+void LwipTestEnter()
+{
+    LwipTestStartTimer(LWIP_TEST_TIMEOUT);
+}
index 0ad451c..061a702 100644 (file)
@@ -142,91 +142,28 @@ void battery_file_check(BATTERY_DATA_T newStruct, const char *filename)
     fclose(fp);
 }
 
-
-void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length)
-{
-    if(!len)
-        return;
-    *length = len;
-    *data = (BATTERY_DATA_T *)malloc(len);
-
-    if(*data == NULL)
-        return;
-
-    memcpy_s(*data,len,bat_t,len);
-    free(bat_t);
-}
-
-void battery_get_data(void)   
+static uint32_t get_current_timestamp(void)
 {
-    len = uapi_get_file_size(BAT_FILE_PATH);
-    if(!len)
-      return;
-
-    bat_t = (BATTERY_DATA_T *)malloc(len);
-    if(bat_t == NULL)
-        return;
-
-    FILE *fp;
-
-    fp = fopen(BAT_FILE_PATH, "rb"); 
-    if (fp == NULL) 
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file open failed");
-        free(bat_t);
-        return;
-    }
-
-    if(fread(bat_t, 1, len, fp) != len)
-    {
-        free(bat_t);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file read failed");
+    uint32_t timestamp = 0;
+    struct timeval current_time = {0};
+    if (gettimeofday(&current_time, NULL)) {
+        return 0;
     }
-    fclose(fp);
-}
-
-//保存电池信息到文件
-void battery_save_data(void)
-{
-    // len = uapi_get_file_size("/user/userdata/battery_data.bin");
-    // if(len > sizeof(BATTERY_DATA_T) * 24 * 7)
-    // {
-    //     uapi_delete_files("/user/userdata/battery_data.bin");
-    // }
-
-    BATTERY_DATA_T data;
-    float voltage;
-    uint8_t percent = batteryservice_get_voltage(&voltage);
-    data.voltage = voltage;
-    data.percent = percent;
-    uapi_get_timestampe_ss(&data.tm);
-    data.stat = get_charge_stat();
-    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data.voltage : %f , data[i].percent : %d  tm : %d",data.voltage,data.percent,data.tm);
-    // uapi_save_file_data("user/userdata/battery_data.bin",(uint8_t *)&data,sizeof(BATTERY_DATA_T),"ab");
-    battery_file_check(data,BAT_FILE_PATH);
-    // uapi_save_file_data("/user/userdata/battery.bin",&percent,1,"wb");
-}
-
-//保存电量到文件
-static void battery_save_percent(void)
-{
-    float voltage;
-    uint8_t percent = batteryservice_get_voltage(&voltage);
-    uapi_save_file_data("/user/userdata/battery.bin",&percent,1,"wb");
-    PRINT("battery_save_percent : %d",percent);
+    struct tm tm;
+    localtime_r(&current_time.tv_sec, &tm);
+    timestamp = (uint32_t)current_time.tv_sec;
+    return timestamp;
 }
-
-//从文件中读取电量
-uint8_t battery_get_percent_onstart(void)
+/*获取秒级时间戳*/
+static errcode_t get_timestampe_ss(uint32_t *tm)
 {
-    uint8_t percent = 0;
-    uint16_t len = 1;
-    uapi_get_file_data("/user/userdata/battery.bin",&percent,&len);
-    PRINT("battery_get_percent_onstart : %d",percent);
-    if(percent <= 100 && percent >= 0)
-        return percent;
-    else
-        return 0;
+    if (tm == NULL) {
+        return ERRCODE_FAIL;
+    }
+ 
+    *tm = get_current_timestamp();
+    //printf("[timestamp:%u]\n", *tm);
+    return ERRCODE_SUCC;
 }
 
 
@@ -698,7 +635,7 @@ errcode_t uapi_battery_init(void)
     taskcfg.func = battery_check_task;
     taskcfg.use_mem = USE_EXTEND_MEM;
     
-    errcode_t ret=uapi_create_osThread_custom(&taskcfg);
+    errcode_t ret=cat1_create_osThread_custom(&taskcfg);
     if(ret != ERRCODE_SUCC)
     {
         PRINT("create battery_service failed %d!\r\n",ret);
index 73627a4..d536090 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * @Author: penglei 1624952103@qq.com
  * @Date: 2024-10-25 14:42:28
- * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-12-02 11:16:37
+ * @LastEditors: SnickerSun snickersun@163.com
+ * @LastEditTime: 2025-01-23 09:36:05
  * @FilePath: /FD230/code/sdk/application/battery/service/battery_service.h
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -59,9 +59,6 @@ uint8_t battery_get_percent_onstart(void);
 //0 停止充电 , 1 低电流充电, 2 正常电流充电
 int get_charge_current_status(void);
 uint8_t get_02c_value(void);
-void battery_get_data(void);
-void battery_save_data(void);
-void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length);
 
 #ifdef __cplusplus
 #if __cplusplus