1、添加cat1_server,采用UDP做服务,为此优化了lwip的相关设置,但是udp仍然会死机,因此暂时关闭此能力。
authorSnickerSun <snickersun@163.com>
Tue, 27 Feb 2024 13:00:14 +0000 (21:00 +0800)
committerSnickerSun <snickersun@163.com>
Tue, 27 Feb 2024 13:00:14 +0000 (21:00 +0800)
2、添加了cat1 的一些at指令入口,可用来对接电话指令等。
3、更正ppg service的一些日志

26 files changed:
code/sdk/application/brandy/brandy_standard/service_init.c
code/sdk/application/brandy/brandy_standard/thread_pri_init.c
code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/peripheral/CMakeLists.txt
code/sdk/drivers/peripheral/ppg/service/ppg_service.cpp
code/sdk/drivers/peripheral/slip/CMakeLists.txt
code/sdk/drivers/peripheral/slip/cat1Service/CMakeLists.txt [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.h [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.h [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.cpp [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.h [new file with mode: 0644]
code/sdk/drivers/peripheral/slip/udp_server.c [deleted file]
code/sdk/drivers/peripheral/slip/udp_server.h [deleted file]
code/sdk/drivers/peripheral/utils/CMakeLists.txt
code/sdk/drivers/peripheral/utils/cat1_ctl.c [deleted file]
code/sdk/drivers/peripheral/utils/cat1_ctl.h [deleted file]
code/sdk/open_source/openharmony/third_party/lwip/port/include/lwipopts.h
code/sdk/open_source/openharmony/third_party/lwip/src/api/sockets.c
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/sockets.h

index cfd1582..062767c 100755 (executable)
@@ -65,6 +65,9 @@
 #ifdef SUPPORT_AT_CUSTOMUTILS\r
 #include "custom_utils_at_cmd.h"\r
 #endif\r
+#ifdef SUPPORT_AT_CAT1\r
+#include "cat1_at_cmd.h"\r
+#endif\r
 \r
 #include "log_file.h"\r
 #ifdef CONFIG_OTA_UPDATE_SUPPORT\r
@@ -134,6 +137,11 @@ static void register_at_service(void)
     at_cmd_table_t *custom_utils_table = get_custom_utils_cmd_table(&custom_utils_cmd_count);\r
     at_cmd_add_moudle(custom_utils_table, custom_utils_cmd_count);\r
 #endif\r
+#ifdef SUPPORT_AT_CAT1\r
+    uint32_t cat1_cmd_count;\r
+    at_cmd_table_t *cat1_table = get_cat1_cmd_table(&cat1_cmd_count);\r
+    at_cmd_add_moudle(cat1_table, cat1_cmd_count);\r
+#endif\r
 \r
 #ifdef SUPPORT_AT_LIS2DOC\r
     uint32_t lis2doc_cmd_count;\r
index 44b6ad1..636b507 100755 (executable)
 #endif\r
 #include "clocks_config.h"\r
 \r
+#ifdef SUPPORT_CAT1_SERVICE\r
+#include "cat1_server.h"\r
+#endif\r
+\r
 #ifdef ENABLE_SLIP\r
 #include "uart_slip.h"\r
 #endif\r
@@ -341,7 +345,9 @@ static void thread_main(const void *unused)
 #ifdef ENABLE_SLIP\r
     slip_uart_init();\r
 #endif\r
-\r
+#ifdef SUPPORT_CAT1_SERVICE\r
+    cat1_server_init();\r
+#endif\r
     set_startup_finish_flag();\r
 }\r
 \r
index c016d5d..f219075 100755 (executable)
@@ -19,6 +19,8 @@ extern "C" {
 #endif
 #endif
 
+#define SUPPORT_CAT1_MODEM
+
 #ifndef BROADCAST_FEATURE_NAME
 #define BROADCAST_FEATURE_NAME "BROADCAST"
 #endif
@@ -49,6 +51,14 @@ typedef enum {
 #endif
 #ifdef SUPPORT_SPO2_NOTIFICATION
     TOPIC_EVENT_SPO2_UPDATE,
+#endif
+#ifdef SUPPORT_CAT1_MODEM
+    TOPIC_EVENT_CAT1_INCOMMING,
+    TOPIC_EVENT_CAT1_CALLCONNTED,
+    TOPIC_EVENT_CAT1_CALLENDED,
+    TOPIC_EVENT_CAT1_SIGNAL_UPDATE,
+    TOPIC_EVENT_CAT1_POWER_ON,
+    TOPIC_EVENT_CAT1_POWER_OFF,
 #endif
     TOPIC_END_NUM = 20000,
 } TopicNum;
index 9ce572d..7f4cc37 100755 (executable)
@@ -39,6 +39,14 @@ static const TopicToCore topicToCoreArray[] = {
     {TOPIC_EVENT_CHARGE_PLUG, A_CORE_MASK, 1},
     {TOPIC_EVENT_CHARGE_UNPLUG, A_CORE_MASK, 1},
 #endif
+#ifdef SUPPORT_CAT1_MODEM
+    {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1},
+    {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1},
+    {TOPIC_EVENT_CAT1_CALLENDED, A_CORE_MASK, 1},
+    {TOPIC_EVENT_CAT1_SIGNAL_UPDATE, A_CORE_MASK, 1},
+    {TOPIC_EVENT_CAT1_POWER_ON, A_CORE_MASK, 1},
+    {TOPIC_EVENT_CAT1_POWER_OFF, A_CORE_MASK, 1},
+#endif
 };
 
 /* 所有的topic,其对应的位图 */
index 3125dbb..b9198e6 100755 (executable)
@@ -47,6 +47,14 @@ const PriorityMapper g_pri_mapper[] = {
     {TOPIC_EVENT_HFP_WATCH_ACTIVE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_WATCH_TO_PHONE, PRIORITY_ONE},
     {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE},
+#ifdef SUPPORT_CAT1_MODEM
+    {TOPIC_EVENT_CAT1_INCOMMING, PRIORITY_ONE},
+    {TOPIC_EVENT_CAT1_CALLCONNTED, PRIORITY_ONE},
+    {TOPIC_EVENT_CAT1_CALLENDED, PRIORITY_ONE},
+    {TOPIC_EVENT_CAT1_SIGNAL_UPDATE, PRIORITY_ONE},
+    {TOPIC_EVENT_CAT1_POWER_ON, PRIORITY_ONE},
+    {TOPIC_EVENT_CAT1_POWER_OFF, PRIORITY_ONE},
+#endif
 #ifdef SUPPORT_SPO2_NOTIFICATION
     {TOPIC_EVENT_SPO2_UPDATE, PRIORITY_TWO},
     {TOPIC_EVENT_HEARTRATE_UPDATA, PRIORITY_TWO},
@@ -89,6 +97,14 @@ void MsgCenterSubscribe()
     MsgCenterSubscribeTopic(TOPIC_EVENT_HEARTRATE_UPDATA);
     MsgCenterSubscribeTopic(TOPIC_EVENT_WEARSTATE_UPDATE);
 #endif
+#ifdef SUPPORT_CAT1_MODEM
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_INCOMMING);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_CALLCONNTED);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_CALLENDED);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_SIGNAL_UPDATE);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_POWER_ON);
+    MsgCenterSubscribeTopic(TOPIC_EVENT_CAT1_POWER_OFF);
+#endif
 }
 
 static OHOS::UIViewGroup* showAlarmNotify(void)
@@ -221,6 +237,38 @@ void MsgCenterNotifyHeartRateProc(const Topic topic, Request* req)
     }
 }
 #endif
+#ifdef SUPPORT_CAT1_MODEM
+void MsgCenterNotifyCatIncomingCallProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+void MsgCenterNotifyCat1CallConnectedProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+void MsgCenterNotifyCat1CallEndedProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+void MsgCenterNotifyCat1SignalUpdateProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+void MsgCenterNotifyCat1PowerOffProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+void MsgCenterNotifyCat1PowerOnProc(const Topic topic, Request* req)
+{
+    unused(topic);
+    unused(req);
+}
+#endif
 /* 订阅事件通知逻辑可定制 */
 static msg_center_notify_table_t g_msg_center_notify_table[] = {
     {TOPIC_EVENT_ALARM_RING,         MsgCenterNotifyAlarmProc},
@@ -240,6 +288,14 @@ static msg_center_notify_table_t g_msg_center_notify_table[] = {
     {TOPIC_EVENT_WEARSTATE_UPDATE,      MsgCenterNotifyWearStateProc},
     {TOPIC_EVENT_HEARTRATE_UPDATA,      MsgCenterNotifyHeartRateProc},
 #endif
+#ifdef SUPPORT_CAT1_MODEM
+    {TOPIC_EVENT_CAT1_INCOMMING,      MsgCenterNotifyCatIncomingCallProc},
+    {TOPIC_EVENT_CAT1_CALLCONNTED,      MsgCenterNotifyCat1CallConnectedProc},
+    {TOPIC_EVENT_CAT1_CALLENDED,      MsgCenterNotifyCat1CallEndedProc},
+    {TOPIC_EVENT_CAT1_SIGNAL_UPDATE,      MsgCenterNotifyCat1SignalUpdateProc},
+    {TOPIC_EVENT_CAT1_POWER_ON,      MsgCenterNotifyCat1PowerOnProc},
+    {TOPIC_EVENT_CAT1_POWER_OFF,      MsgCenterNotifyCat1PowerOffProc},
+#endif
 };
 
 static msg_center_notify_table_t *MsgCenterGetNotifyTblCb(uint8_t idx)
index 6754e2e..4db6cfb 100755 (executable)
@@ -155,6 +155,7 @@ target = {
                           "vibrator_service",
                           "lwIP",
                           "slip",
+                          "cat1_service",
                           "audio_manager",
                           "custom_utils",
                           "rotary_encoder",
index 4971908..8e944fc 100644 (file)
@@ -11,6 +11,7 @@ add_subdirectory_if_exist(ppg)
 add_subdirectory_if_exist(touch)
 add_subdirectory_if_exist(vibrator)
 add_subdirectory_if_exist(slip)
+add_subdirectory_if_exist(slip/cat1Service)
 add_subdirectory_if_exist(utils)
 add_subdirectory_if_exist(rotary_encoder)
 add_subdirectory_if_exist(vibrator/service)
index 891b0ab..2fb55d4 100644 (file)
@@ -253,16 +253,16 @@ errcode_t uapi_ppg_service_init(void)
 {
     if (osal_msg_queue_create("ppg_service_queue", PPG_SERVICE_MSG_COUNT, &g_app_queue,
                               0, sizeof(PPG_CMD_TYPE_T)) != ERRCODE_SUCC) {
-        PRINT_ERR("[mag][service] app create mail fail\n");
+        PRINT_ERR("[ppg][service] app create mail fail\n");
         return ERRCODE_FAIL;
     }
 
 
     osal_task *task_handle = osal_kthread_create((osal_kthread_handler)ppg_service_check_task, NULL,
-                                                 "ppg_service_service", PPG_SERVICE_TASK_SIZE);
+                                                 "ppg_service", PPG_SERVICE_TASK_SIZE);
     if (task_handle == NULL) {
         osal_msg_queue_is_full(g_app_queue);
-        PRINT_ERR("create mag service thread fail!\r\n");
+        PRINT_ERR("create ppg service thread fail!\r\n");
         return ERRCODE_FAIL;
     }
 
index 4cd1aca..7aad393 100644 (file)
@@ -12,7 +12,7 @@ set(SOURCES ${SOURCES}
     ${CMAKE_CURRENT_SOURCE_DIR}/asio.c
     ${CMAKE_CURRENT_SOURCE_DIR}/slipif.c
     ${CMAKE_CURRENT_SOURCE_DIR}/uart_slip.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/udp_server.c
+    # ${CMAKE_CURRENT_SOURCE_DIR}/udp_server.c
     # ${LWIP_PORT_SOURCES}
 )
 set(PUBLIC_HEADER
@@ -20,7 +20,6 @@ set(PUBLIC_HEADER
     ${ROOT_DIR}/open_source/openharmony/third_party/lwip/port
 )
 set(PUBLIC_DEFINES
-    SUPPORT_AT_SLIP
 )
 set(PRIVATE_HEADER
 )
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/CMakeLists.txt b/code/sdk/drivers/peripheral/slip/cat1Service/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ce50b70
--- /dev/null
@@ -0,0 +1,60 @@
+#===============================================================================
+# @brief    cmake file
+# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved.
+#===============================================================================
+
+set(COMPONENT_NAME "cat1_service")
+
+set(PUBLIC_HEADER
+${CMAKE_CURRENT_SOURCE_DIR}
+)
+set(PRIVATE_HEADER
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
+    ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include
+)
+
+set(SOURCES
+${CMAKE_CURRENT_SOURCE_DIR}/cat1_at_cmd.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/cat1_server_hal.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/cat1_server.cpp
+${CMAKE_CURRENT_SOURCE_DIR}/cat1_ctl.cpp
+)
+
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+    -std=c++11
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-c++11-narrowing
+    -Wno-error=unused-function
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+set(PUBLIC_DEFINES
+SUPPORT_CAT1_SERVICE
+SUPPORT_AT_CAT1
+)
+
+set(PRIVATE_DEFINES
+)
+
+build_component()
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.cpp
new file mode 100644 (file)
index 0000000..5b9f8e8
--- /dev/null
@@ -0,0 +1,188 @@
+
+#include "at_cmd_api.h"
+#include "pm_control.h"
+#include "cat1_server.h"
+#include "cat1_at_cmd.h"
+#include "cat1_ctl.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
+#define PPG_MAX_ARGC            8
+#define PPG_MAX_ARGV_LEN        64
+
+#define PPG_SUCCESS             0
+#define PPG_FAILED              (-1)
+
+static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen,
+        uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN], uint32_t* argc)
+{
+    uint32_t pos = 0;
+    *argc = 0;
+
+    for (uint32_t i = 0; i < paraLen; i++) {
+        if ((para[i] == ' ' || para[i] == '\n') && pos != 0) {
+            argv[*argc][pos] = '\0';
+            *argc += 1;
+            pos = 0;
+            if (*argc >= PPG_MAX_ARGC) {
+                return PPG_FAILED;
+            }
+        } else {
+            argv[*argc][pos] = para[i];
+            pos++;
+            if (pos >= PPG_MAX_ARGV_LEN) {
+                return PPG_FAILED;
+            }
+        }
+    }
+    if (pos != 0) {
+        *argc += 1;
+    }
+
+    return PPG_SUCCESS;
+}
+
+
+static uint32_t cat1_power(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    // char *mode = (char*)argv[0];
+    int enabled = atoi((char*)argv[0]);
+    
+    printf("CAT1TEST ATCMD  power  enable %d \n",enabled);
+
+
+
+    return ERRCODE_SUCC;
+}
+static uint32_t cat1_dial(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    char *phoneno = (char*)argv[0];
+
+    printf("CAT1TEST ATCMD  dial   %s \n",phoneno);
+
+
+
+    return ERRCODE_SUCC;
+}
+static uint32_t cat1_answer(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    printf("CAT1TEST ATCMD  answer   \n");
+
+    return ERRCODE_SUCC;
+}
+static uint32_t cat1_hungup(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    
+    printf("CAT1TEST ATCMD  hungup   \n");
+
+
+
+    return ERRCODE_SUCC;
+}
+static uint32_t cat1_getsignal(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    uint8_t argv[PPG_MAX_ARGC][PPG_MAX_ARGV_LEN] = { 0 };
+    uint32_t argc = 0;
+
+    int ret = ConvertCmdToParam(para, paraLen, argv, &argc);
+    if (ret != PPG_SUCCESS) {
+        printf("CAT1TEST ATCMD Convert Command Failed\n");
+        return ERRCODE_FAIL;
+    }
+
+    if (argc != 1) {
+        printf("CAT1TEST ATCMD Set Parameter Failed\n");
+        return ERRCODE_FAIL;
+    }
+    
+    printf("CAT1TEST ATCMD  getsignal  \n");
+
+
+
+    return ERRCODE_SUCC;
+}
+static const at_cmd_table_t g_cat1_cmd[] = {
+    { (char *)"AT^CAT1POWER",      cat1_power, (char *)"1" },
+    { (char *)"AT^CAT1DIAL",      cat1_dial, (char *)"1" },
+    { (char *)"AT^CAT1ANSWER",      cat1_answer, (char *)"1" },
+    { (char *)"AT^CAT1HUNGUP",      cat1_hungup, (char *)"1" },
+    { (char *)"AT^CAT1GETSIGNAL",      cat1_getsignal, (char *)"1" },
+};
+
+at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count)
+{
+    *cmd_count = ARRAY_COUNT(g_cat1_cmd);
+    return (at_cmd_table_t *)g_cat1_cmd;
+}
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_at_cmd.h
new file mode 100644 (file)
index 0000000..84aa281
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n
+ *
+ * Description: Provides at cmd register func \n
+ * Author: @CompanyNameTag \n
+ * History: \n
+ * 2022-07-20, Create file. \n
+ */
+#ifndef CAT1_AT_PROCESS_H
+#define CAT1_AT_PROCESS_H
+
+#include <stdint.h>
+#include <stdio.h>
+#include "errcode.h"
+#include "soc_osal.h"
+#include "at_cmd_api.h"
+
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+at_cmd_table_t *get_cat1_cmd_table(uint32_t *cmd_count);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+#endif
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp
new file mode 100644 (file)
index 0000000..918dc05
--- /dev/null
@@ -0,0 +1,47 @@
+
+
+#include "platform_core.h"
+#include "stdint.h"
+#include "pinctrl.h"
+#include "cat1_ctl.h"
+#include "gpio.h"
+#include "gpio_porting.h"
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+uint32_t uapi_cat1_power_on(uint32_t pwron)
+{
+
+    if( pwron == 0)
+    {
+        uapi_gpio_set_dir(S_AGPIO_L23, GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L23, GPIO_LEVEL_LOW);
+        // wstp_print("Power OFF Cat1! L23 low  \r\n");
+    }else{
+        uapi_gpio_set_dir(S_AGPIO_L23, GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L23, GPIO_LEVEL_HIGH);
+        // wstp_print("Power ON Cat1! L23 high \r\n");
+    }
+    
+    return 0;
+}
+uint32_t uapi_cat1_reset(uint32_t pwron)
+{
+    if( pwron == 0)
+    {
+        uapi_gpio_set_dir(S_AGPIO_L28, GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L28, GPIO_LEVEL_HIGH);
+        // wstp_print("clear reset Cat1! L28 high \r\n");
+    }else{
+        uapi_gpio_set_dir(S_AGPIO_L28, GPIO_DIRECTION_OUTPUT);
+        uapi_gpio_set_val(S_AGPIO_L28, GPIO_LEVEL_LOW); 
+        // wstp_print("Reset Cat1! L28 low\r\n");
+    }
+
+    return 0;
+}
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.h
new file mode 100644 (file)
index 0000000..ac9b349
--- /dev/null
@@ -0,0 +1,19 @@
+\r
+#ifndef __CAT1_CTL_H\r
+#define __CAT1_CTL_H\r
+\r
+#include "stdint.h"\r
+\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+#endif /* __cplusplus */\r
+uint32_t uapi_cat1_power_on(uint32_t pwron);\r
+uint32_t uapi_cat1_reset(uint32_t pwron);\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+#endif /* __cplusplus */\r
+#endif\r
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
new file mode 100644 (file)
index 0000000..2a24bef
--- /dev/null
@@ -0,0 +1,384 @@
+/* BSD Socket API Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+
+#include "lwip/ip.h"
+#include "lwip/netif.h"
+#include "lwip/init.h"
+#include "lwip/inet_chksum.h"
+
+#include "lwip/err.h"
+#include "lwip/sockets.h"
+#include "lwip/sys.h"
+#include <lwip/netdb.h>
+// #include <netinet/in.h>
+#include "lwip/inet.h"
+
+// #include <string.h>
+// #include <sys/param.h>
+#include <string.h>
+
+
+
+
+
+#include "wearable_log.h"
+
+// #include "graphic_service.h"
+
+#ifdef __cplusplus
+
+extern "C" {
+
+#endif /* __cplusplus */
+
+
+
+#include "errcode.h"
+#include "errno.h"
+#include "uart_slip.h"
+#include "cat1_server.h"
+#include "cat1_server_hal.h"
+#include "tcxo.h"
+
+#define PEER_IP "172.16.1.2"
+#define PEER_PORT 5000
+
+#define PORT 1000 
+#define SSID_LENGTH        32
+#define PASSWORD_LENGTH    64
+
+enum UDP_COMMAND_HEAD {
+    UDP_CHANGE_WEB_NETWORK = '0',  // web config
+    UDP_WIFI_STATUS = '1',               // status
+    UDP_CHANGE_AP = '2',                 // ap mode
+    UDP_CHANGE_STATION = '3',            // station mode
+    UDP_OTA_UPDATE = '4',                // ota upgrade
+    UDP_APP_VERSION = '5',               // app version
+    UDP_SMART_CONFIG = '6',              // smartconfig
+    UDP_CONFIG_QUERY = '7',              // config query
+    UDP_EVENT_REPORT = 'F'         // auto report
+};
+// current work station
+enum SSS_WORKING_STATUS {
+    SSS_WORKING_NONE = 0,   // do nothing
+    SSS_WORKING_REINIT,     // reinit uart slip
+    SSS_WORKING_RESTART,    // restart device
+    SSS_WORKING_OTA         // ota ing
+};
+
+// static char *msg_wifi_resp[] = 
+// {
+//     "OK",    // op success
+//     "ERROR", // op failure
+//     "0",     // no init 
+//     "1",     // station mode, wifi connected
+//     "2",     // station mode, wifi connecting
+//     "3",     // web config mode
+//     "4",     // ap mode
+//     "5",     // ota ing
+//     "6",     // smart config mode
+// };
+#define RESP_STATUS_OFSET  2
+
+#pragma pack(push)
+#pragma pack(1)
+struct tcp_msg_t {
+    char head[2];
+    int length;
+    char buffer[512];
+};
+#pragma pack(pop)
+
+
+static int g_listen_sock = 0;
+struct sockaddr_in sourceAddr = {0};
+
+static struct tcp_msg_t *unpack_tlv_format(char *rx_buffer, int length)
+{
+    char temp[8];
+    struct tcp_msg_t *msg = (struct tcp_msg_t *)rx_buffer;
+    strncpy(temp, (char *)&msg->length, 4);
+    temp[4] = '\0';
+    msg->length = atoi(temp);
+
+    if( length != msg->length+6 ) return NULL;
+    return msg;
+}
+
+static int pack_tlv_format(char *tx_buffer, char *head, char *content)
+{
+    int content_length = (int)strlen(content);
+    if( content == NULL || head == NULL || content_length > 9999 ) {
+        return -1;
+    }
+
+    struct tcp_msg_t *msg = (struct tcp_msg_t *)tx_buffer;
+    strncpy(msg->head, head, 2);
+    //sprintf((char *)(&msg->length), "%04d", (unsigned char)content_length);
+    sprintf(&tx_buffer[2], "%04d", content_length);
+    
+    strcpy(msg->buffer, content);
+    return strlen(content)+6;
+}
+
+static void udp_send_response(char *tx_buffer, char *head, char *content)
+{
+    // remain lock using
+    int len = pack_tlv_format(tx_buffer, head, content);
+    int err = 0;
+    if( len > 0 ) {
+        err = sendto(g_listen_sock, tx_buffer, len, 0, (struct sockaddr *)&sourceAddr, sizeof(sourceAddr));
+        if (err < 0) {
+            printf("Error occured during sending: errno %d\n", errno);
+               }
+    } else {
+        printf("Error occured unkown send data\n");
+    }
+}
+
+void udp_ota_update(char *content)
+{
+    char ota_tx_buffer[128] = {0};
+    char ota_head[2] = {0};
+    ota_head[0] = 'F';
+    ota_head[1] = UDP_EVENT_REPORT;
+    udp_send_response(ota_tx_buffer, ota_head, content);
+}
+
+void udp_station_update(char *content)
+{
+    char station_tx_buffer[128] = {0};
+    char station_head[2] = {0};
+    if( sourceAddr.sin_port != 0 ) {
+        station_head[0] = 'F';
+        station_head[1] = UDP_EVENT_REPORT;
+        udp_send_response(station_tx_buffer, station_head, content);
+    }
+}
+
+
+static int resolve_config_query(struct tcp_msg_t *msg)
+{
+    int index = -1;
+    char config_tx_buffer[256] = {0};
+    char buffer[128];
+    if( msg->buffer == NULL && msg->buffer[0] != '0') return 1;
+
+    // memset(buffer, 0x00, sizeof(buffer));
+    // index = quec_config_query_entry(msg->buffer, buffer);
+    // if( index == 0 ) {
+    //     udp_send_response(config_tx_buffer, msg->head, buffer);
+    // } else {
+    //     index = 1;
+    // }
+
+    return index;
+}
+
+static int resolve_msg_ota(struct tcp_msg_t *msg)
+{
+    int index = 0;
+    if( msg->buffer == NULL ) return 1;
+#ifdef QUECTEL_CONFIG_OTA_SUPPORT
+    extern int ota_app_main(char *ota_server);
+    //printf("ota url = %s\n", msg->buffer);
+    int ret = ota_app_main(msg->buffer);
+    if( ret != 0 ) {
+        index = 1;
+    }
+#else
+    index = 1;
+#endif
+    return index;
+}
+const char* build_sdk = "602";
+const char* build_model = "debug";
+const char* build_version = "v1.0";
+const char* build_time = "240222";
+
+static int resolve_msg_app_version(struct tcp_msg_t *msg)
+{
+    int index = -1;
+    char version_tx_buffer[256] = {0};
+    if( msg->buffer == NULL && msg->buffer[0] != '0') return 1;
+    char version[128] = {0};
+    snprintf(version, 128, "sdk: %s\nmodel: %s\nversion: %s\ntime: %s",
+        build_sdk, build_model, build_version, build_time);
+    
+    udp_send_response(version_tx_buffer, msg->head, version);
+    return index;
+}
+
+static int udp_packet_parse(char *rx_buffer, int len)
+{
+    struct tcp_msg_t *msg = unpack_tlv_format(rx_buffer, len);
+    int index = 0;
+    if(  msg->head[1] != UDP_WIFI_STATUS ) { // ota only status check
+        return 1;
+    }
+    if( msg != NULL ) {
+        switch (msg->head[1]) {
+            case UDP_OTA_UPDATE:
+                           index = resolve_msg_ota(msg);
+                break;
+            case UDP_APP_VERSION:
+                index = resolve_msg_app_version(msg);
+                break;
+            case UDP_CONFIG_QUERY:
+                           index = resolve_config_query(msg);
+                break;
+                   default:
+                           printf("error message: %s\n", rx_buffer);
+                index = 1;
+                break;
+        }
+    } else {
+        printf("wrong format msg and exit\n");
+        index = 1;
+    }
+    return index;
+}
+
+static int udp_socket_init()
+{
+    int addr_family;
+    int ip_protocol;
+    int opt = 1;
+    struct sockaddr_in destAddr;
+    char addr_str[128];
+
+    // destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+    destAddr.sin_addr.s_addr = inet_addr("172.16.1.5");
+    destAddr.sin_family = AF_INET;
+    destAddr.sin_port = htons(PORT);
+    addr_family = AF_INET;
+    ip_protocol = IPPROTO_IP;
+    inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
+
+    int listen_sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
+    if (listen_sock < 0) {
+        printf("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) {
+        printf("Socket unable to bind: errno %d\n", errno);
+        return -1;
+    }
+    
+    sourceAddr.sin_addr.s_addr = inet_addr(PEER_IP);
+    sourceAddr.sin_family = AF_INET;
+    sourceAddr.sin_port = htons(PEER_PORT);
+
+    return listen_sock;
+}
+
+int cat1_server_task(void *pvParameters)
+{
+    char rx_buffer[512];
+    char tx_buffer[256];
+    int index;
+    socklen_t addrLen = sizeof(sourceAddr);
+    while (1) {
+        if( g_listen_sock > 0 ) close(g_listen_sock);
+        g_listen_sock = udp_socket_init();
+        if( g_listen_sock < 0 ) {
+            printf("socket init fail and retry\n");
+            // vTaskDelay(1000/portTICK_RATE_MS);
+            uapi_tcxo_delay_ms(1000);
+            continue;
+        }
+
+        while (1) {
+
+            
+                       memset(rx_buffer, 0, sizeof(rx_buffer));
+
+            // uapi_tcxo_delay_ms(1000);
+            // continue;
+
+            int len = recvfrom(g_listen_sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&sourceAddr, &addrLen);
+            // Error occured during receiving
+            if (len < 0) {
+                printf("recv failed: errno %d\n", errno);
+                break;
+            } else if (len == 0) {
+                printf("Connection closed\n");
+                break;
+            }
+            // Data received
+            rx_buffer[len] = '\0'; // Null-terminate whatever we received and treat like a string
+            printf("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]*/);
+            }
+
+            // if( quec_wifi_status.s_status == SSS_WORKING_RESTART ) {
+            //     //station_wifi_set_info("","");
+
+            //     tcp_device_restart();
+            // } else if( quec_wifi_status.s_status == SSS_WORKING_REINIT ) {
+            //     user_netif_deinit();
+               //     // vTaskDelay(1000/portTICK_RATE_MS);
+               //     user_netif_init();
+            //     quec_wifi_status.s_status = SSS_WORKING_NONE;
+            //     break;
+            // }
+        }
+       }
+       return 0;
+}
+
+
+
+
+#if 0
+void wifi_status()
+{
+    char tx_buffer[128] = {0};
+    int index = resolve_msg_wifi_status(NULL);
+    char *head = "FF";
+    int len = pack_tlv_format(tx_buffer, head, msg_wifi_status[index]);
+    printf("wifi_status len = %d, msg = [%s]\n",len, tx_buffer);
+}
+#endif
+
+#include "osal_msgqueue.h"
+#include "thread_init.h"
+#include "soc_osal.h"
+#include "common_def.h"
+#include "los_printf.h"
+
+#define CAT1_SERVICE_TASK_SIZE       0x800
+#define CAT1_SERVICE_TASK_PRIO       5
+
+errcode_t cat1_server_init(void)
+{
+
+    // osal_task *task_handle = osal_kthread_create((osal_kthread_handler)cat1_server_task, NULL,
+    //                                              "cat1_service", CAT1_SERVICE_TASK_SIZE);
+    // if (task_handle == NULL) {
+    //     PRINT_ERR("create cat1 service thread fail!\r\n");
+    //     return ERRCODE_FAIL;
+    // }
+
+    // osal_kthread_set_priority(task_handle, CAT1_SERVICE_TASK_PRIO);
+
+    return ERRCODE_SUCC;
+}
+
+#ifdef __cplusplus
+
+}
+
+#endif /* __cplusplus */
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.h
new file mode 100644 (file)
index 0000000..a9435a4
--- /dev/null
@@ -0,0 +1,26 @@
+/* BSD Socket API Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+#ifndef __CAT1_SERVER_H
+#define __CAT1_SERVER_H
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+void udp_ota_update(char *content);
+
+errcode_t cat1_server_init(void);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+#endif
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.cpp
new file mode 100644 (file)
index 0000000..8a19fc8
--- /dev/null
@@ -0,0 +1,99 @@
+/* BSD Socket API Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <string.h>
+
+#include "wearable_log.h"
+#include "securec.h"
+#include "broadcast_service.h"
+#include "broadcast_feature.h"
+#include "service_id_define.h"
+#include "samgr_lite.h"
+#include "thread_adapter.h"
+#include "graphic_service.h"
+
+#ifdef __cplusplus
+
+extern "C" {
+
+#endif /* __cplusplus */
+
+
+
+#include "errcode.h"
+#include "errno.h"
+
+#include "cat1_server_hal.h"
+
+
+static void CustomEventPublish(uint16_t topic, uint8_t *data , uint32_t size)
+{
+    int32 ret;
+    
+    Request *request = NULL;
+    BroadcastApi *broadcastApi = NULL;
+    IUnknown *api = NULL;
+
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish topic=%u!!", topic);
+
+    /* alloc request */
+    request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size);
+    if (request == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed");
+        return;
+    }
+    request->msgId = topic;
+    ret = memcpy_s(request->data, size, (const void *)data, size);
+    if (ret != EOK) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish memcpy_s rateDataTmp fail! ret = %d", ret);
+        return;
+    }
+    request->len = size;
+    request->msgValue = 0;
+
+    /* public request */
+    api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);
+    if (api == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
+    if (ret != 0 || broadcastApi == NULL) {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed");
+        SAMGR_FreeRequestMsg(request);
+        return;
+    }
+    broadcastApi->PublishTopic((IUnknown *)broadcastApi, request);
+    broadcastApi->Release((IUnknown *)broadcastApi);
+    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish end!!");
+
+    return;
+}
+
+
+
+static errcode_t incomingcall_event_notify(char* callno)
+{
+    CustomEventPublish(TOPIC_EVENT_STEPDATA_UPDATE,(uint8_t*)callno,strlen(callno));
+    return 0;
+}
+errcode_t incomingcall_event_sendmsg_toUI(char* callno)
+{
+    /**通过UI事件发送Notify*/
+    GraphicService::GetInstance()->PostGraphicEvent(std::bind(incomingcall_event_notify, callno));
+    return ERRCODE_SUCC;
+}
+
+
+#ifdef __cplusplus
+
+}
+
+#endif /* __cplusplus */
diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.h b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.h
new file mode 100644 (file)
index 0000000..b4ba3a3
--- /dev/null
@@ -0,0 +1,25 @@
+/* BSD Socket API Example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+#ifndef __CAT1_SERVER_HAL_H
+#define __CAT1_SERVER_HAL_H
+#ifdef __cplusplus
+#if __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+
+
+errcode_t incomingcall_event_sendmsg_toUI(char* callno);
+
+#ifdef __cplusplus
+#if __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __cplusplus */
+#endif
diff --git a/code/sdk/drivers/peripheral/slip/udp_server.c b/code/sdk/drivers/peripheral/slip/udp_server.c
deleted file mode 100644 (file)
index df0f981..0000000
+++ /dev/null
@@ -1,549 +0,0 @@
-/* BSD Socket API Example
-
-   This example code is in the Public Domain (or CC0 licensed, at your option.)
-
-   Unless required by applicable law or agreed to in writing, this
-   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-   CONDITIONS OF ANY KIND, either express or implied.
-*/
-#include <string.h>
-#include <sys/param.h>
-#include <string.h>
-
-// #include "freertos/FreeRTOS.h"
-// #include "freertos/task.h"
-// #include "esp_system.h"
-// #include "esp_log.h"
-// #include "esp_netif.h"
-// #include "esp_event.h"
-// #include "nvs.h"
-// #include "nvs_flash.h"
-#include <netinet/in.h>
-#include "lwip/err.h"
-#include "lwip/sockets.h"
-#include "lwip/sys.h"
-#include <lwip/netdb.h>
-// #include "esp_wifi.h"
-#include "errno.h"
-#include "uart_slip.h"
-// #include "wifi_ap.h"
-// #include "wifi_station.h"
-// #include "web_server.h"
-#include "udp_server.h"
-// #include "app_version.h"
-
-#ifdef QUECTEL_CONFIG_SMARTCONFIG_SUPPORT
-#include "smartconfig.h"
-#endif
-
-extern int g_wifi_station_status;
-extern int g_wifi_ap_status;
-extern int g_wifi_ota_status;
-
-web_config_t tcp_web_config = {0};
-
-#define PEER_IP "172.16.1.2"
-#define PEER_PORT 5000
-
-#define PORT 1000 
-#define SSID_LENGTH        32
-#define PASSWORD_LENGTH    64
-
-enum UDP_COMMAND_HEAD {
-    UDP_CHANGE_WEB_NETWORK = '0',  // web config
-    UDP_WIFI_STATUS = '1',               // status
-    UDP_CHANGE_AP = '2',                 // ap mode
-    UDP_CHANGE_STATION = '3',            // station mode
-    UDP_OTA_UPDATE = '4',                // ota upgrade
-    UDP_APP_VERSION = '5',               // app version
-    UDP_SMART_CONFIG = '6',              // smartconfig
-    UDP_CONFIG_QUERY = '7',              // config query
-    UDP_EVENT_REPORT = 'F'         // auto report
-};
-// current work station
-enum SSS_WORKING_STATUS {
-    SSS_WORKING_NONE = 0,   // do nothing
-    SSS_WORKING_REINIT,     // reinit uart slip
-    SSS_WORKING_RESTART,    // restart device
-    SSS_WORKING_OTA         // ota ing
-};
-
-static char *msg_wifi_resp[] = 
-{
-    "OK",    // op success
-    "ERROR", // op failure
-    "0",     // no init 
-    "1",     // station mode, wifi connected
-    "2",     // station mode, wifi connecting
-    "3",     // web config mode
-    "4",     // ap mode
-    "5",     // ota ing
-    "6",     // smart config mode
-};
-#define RESP_STATUS_OFSET  2
-
-#pragma pack(push)
-#pragma pack(1)
-struct tcp_msg_t {
-    char head[2];
-    int length;
-    char buffer[512];
-};
-#pragma pack(pop)
-
-// status 0: init, 1: station  2: softap
-typedef struct _quec_wifi_status_t {
-    int mode;
-    enum SSS_WORKING_STATUS s_status;
-} quec_wifi_status_t;
-quec_wifi_status_t quec_wifi_status ={0, 0};
-
-static int g_listen_sock = 0;
-struct sockaddr_in sourceAddr = {0};
-
-extern int quec_config_query_entry(char *key, char *buffer);
-
-void set_current_wifi_stat(enum WIFI_CURRENT_SETTINNG stat)
-{
-   quec_wifi_status.mode = stat;
-}
-
-static void tcp_device_restart()
-{
- 
-}
-
-static void stop_current_wifi()
-{
-
-}
-
-static struct tcp_msg_t *unpack_tlv_format(char *rx_buffer, int length)
-{
-    char temp[8];
-    struct tcp_msg_t *msg = (struct tcp_msg_t *)rx_buffer;
-    strncpy(temp, (char *)&msg->length, 4);
-    temp[4] = '\0';
-    msg->length = atoi(temp);
-
-    if( length != msg->length+6 ) return NULL;
-    return msg;
-}
-
-static int pack_tlv_format(char *tx_buffer, char *head, char *content)
-{
-    int content_length = (int)strlen(content);
-    if( content == NULL || head == NULL || content_length > 9999 ) {
-        return -1;
-    }
-
-    struct tcp_msg_t *msg = (struct tcp_msg_t *)tx_buffer;
-    strncpy(msg->head, head, 2);
-    //sprintf((char *)(&msg->length), "%04d", (unsigned char)content_length);
-    sprintf(&tx_buffer[2], "%04d", content_length);
-    
-    strcpy(msg->buffer, content);
-    return strlen(content)+6;
-}
-
-static void udp_send_response(char *tx_buffer, char *head, char *content)
-{
-    // remain lock using
-    int len = pack_tlv_format(tx_buffer, head, content);
-    int err = 0;
-    if( len > 0 ) {
-        err = sendto(g_listen_sock, tx_buffer, len, 0, (struct sockaddr *)&sourceAddr, sizeof(sourceAddr));
-        if (err < 0) {
-            printf("Error occured during sending: errno %d\n", errno);
-               }
-    } else {
-        printf("Error occured unkown send data\n");
-    }
-}
-
-void udp_ota_update(char *content)
-{
-    char ota_tx_buffer[128] = {0};
-    char ota_head[2] = {0};
-    ota_head[0] = 'F';
-    ota_head[1] = UDP_EVENT_REPORT;
-    udp_send_response(ota_tx_buffer, ota_head, content);
-}
-
-void udp_station_update(char *content)
-{
-    char station_tx_buffer[128] = {0};
-    char station_head[2] = {0};
-    if( sourceAddr.sin_port != 0 ) {
-        station_head[0] = 'F';
-        station_head[1] = UDP_EVENT_REPORT;
-        udp_send_response(station_tx_buffer, station_head, content);
-    }
-}
-
-static int resolve_msg_ap_connect(struct tcp_msg_t *msg)
-{
-    int ret = 0;
-    int index = 0;
-       char ssid[SSID_LENGTH];
-       char password[PASSWORD_LENGTH];
-    if( msg == NULL || msg->buffer == NULL ) return 1;
-    //ptr = strtok(data, ",");
-    char *ptr = strchr(msg->buffer, ',');
-    if( ptr == NULL )  {
-        return 1;
-    }
-    if( strlen(&ptr[1]) < 1 || strlen(&ptr[1]) >= PASSWORD_LENGTH ) {
-        return 1;
-    }
-    memset(password, 0, PASSWORD_LENGTH);
-       strncpy(password, &ptr[1], strlen(&ptr[1]));
-
-    ptr[0] = '\0';
-    if( strlen(msg->buffer) < 1 || strlen(msg->buffer) >= SSID_LENGTH ) {
-        return 1;
-    }
-    memset(ssid, 0, SSID_LENGTH);
-       strncpy(ssid, msg->buffer, strlen(msg->buffer));
-   
-       printf("ssid: %s,password: %s\r\n", ssid, password);
-       return index;
-}
-
-static int resolve_msg_wifi_status(struct tcp_msg_t *msg)
-{
-    int index = 0;
-    //printf("quec_wifi_status.mode = %d\n", quec_wifi_status.mode);
-    if( g_wifi_ota_status == 1 ) {
-        return 5; // ota ing
-    }
-    int web_server_status = 0;
-#ifdef QUECTEL_CONFIG_SMARTCONFIG_SUPPORT
-    int smartconfig_status = 0;
-#endif
-    if( quec_wifi_status.mode == WIFI_CURRENT_SETTINNG_STATION) { // station
-
-#ifdef QUECTEL_CONFIG_SMARTCONFIG_SUPPORT        
-       smartconfig_status = get_smartconfig_status();
-        if( smartconfig_status != -1 ) {
-            index = 6;
-        }
-       else
-#endif
-       if( g_wifi_station_status == 1 ) {
-            index = 1; // connected success
-        } else {
-            index = 2;  // connected fail
-        }
-    } else if( quec_wifi_status.mode == WIFI_CURRENT_SETTINNG_SOFTAP ){
-        web_server_status = get_web_server_status();
-        if( web_server_status == 1 ) {
-            index = 3; // web server start
-        } else if( g_wifi_ap_status == 1 ) {
-            index = 4; // ap construct
-        }
-    }
-    return index;
-}
-
-static int resolve_msg_ap_construct(struct tcp_msg_t *msg)
-{
-    int ret = 0;
-    int index = 0;
-    char ssid[SSID_LENGTH];
-       char password[PASSWORD_LENGTH];
-    if( msg->buffer == NULL ) return 1;
-    //ptr = strtok(data, ",");
-    char *ptr = strchr(msg->buffer, ',');
-    if( ptr == NULL )  {
-        return 1;
-    }
-    if( strlen(&ptr[1]) < 1 || strlen(&ptr[1]) >= PASSWORD_LENGTH ) {
-        return 1;
-    }
-    memset(password, 0, PASSWORD_LENGTH);
-       strncpy(password, &ptr[1], strlen(&ptr[1]));
-
-    ptr[0] = '\0';
-    if( strlen(msg->buffer) < 1 || strlen(msg->buffer) >= SSID_LENGTH ) {
-        return 1;
-    }
-    memset(ssid, 0, SSID_LENGTH);
-       strncpy(ssid, msg->buffer, strlen(msg->buffer));
-    stop_current_wifi();
-
-       //printf("ssid: %s,password: %s\r\n", ssid, password);
-    ret = softap_wifi_init(ssid, password, 0);
-    if( ret == 0 ) {
-        index = 0;
-    } else {
-        index = 1;
-    }
-    web_server_status_reset();
-    quec_wifi_status.mode = WIFI_CURRENT_SETTINNG_SOFTAP;
-    quec_wifi_status.s_status = SSS_WORKING_REINIT;
-    return index;
-}
-
-static int resolve_msg_web_network(struct tcp_msg_t *msg)
-{
-    int index = 0;
-    char ssid[SSID_LENGTH];
-       char password[PASSWORD_LENGTH];
-    if( msg->buffer == NULL ) return 1;
-
-    if( (msg->length == 1) && (msg->buffer[0] == '0') ) {
-        strcpy(tcp_web_config.user, "");
-        strcpy(tcp_web_config.password, "");
-        quec_wifi_status.mode = WIFI_CURRENT_SETTINNG_SOFTAP;
-        quec_wifi_status.s_status = SSS_WORKING_RESTART;
-        return index;
-    }
-    //ptr = strtok(data, ",");
-    char *ptr = strchr(msg->buffer, ',');
-    if( ptr == NULL )  {
-        return 1;
-    }
-    if( strlen(&ptr[1]) < 1 || strlen(&ptr[1]) >= PASSWORD_LENGTH ) {
-        return 1;
-    }
-    memset(password, 0, PASSWORD_LENGTH);
-       strncpy(password, &ptr[1], strlen(&ptr[1]));
-
-    ptr[0] = '\0';
-    if( strlen(msg->buffer) < 1 || strlen(msg->buffer) >= SSID_LENGTH ) {
-        return 1;
-    }
-    memset(ssid, 0, SSID_LENGTH);
-       strncpy(ssid, msg->buffer, strlen(msg->buffer));
-       //printf("ssid: %s,password: %s\r\n", ssid, password);
- 
-    memcpy(tcp_web_config.user, ssid, 32);
-    memcpy(tcp_web_config.password, password, 64);
-    quec_wifi_status.mode = WIFI_CURRENT_SETTINNG_SOFTAP;
-    quec_wifi_status.s_status = SSS_WORKING_RESTART;
-    return index;
-}
-
-static int resolve_msg_smartconfig_network(struct tcp_msg_t *msg)
-{
-    int index = 0;
-#ifdef QUECTEL_CONFIG_SMARTCONFIG_SUPPORT
-    if( msg->buffer == NULL || msg->length != 1 ) return 1;
-    printf("msg->buffer[0] = %c\n", msg->buffer[0]);
-    if( msg->buffer[0] == '0' ) {
-        stop_smartconfig();
-        quec_wifi_status.mode = WIFI_CURRENT_SETTINNG_STATION;
-        quec_wifi_status.s_status = SSS_WORKING_RESTART;
-        return index;
-    }
-    stop_current_wifi();
-    web_server_status_reset();
-
-    int ret = start_smartconfig(msg->buffer[0] - '1');
-    if( ret != 0 ) {
-        printf("start_smartconfig ret = %d\n", ret);
-        return 1;
-    }
-
-    quec_wifi_status.mode = WIFI_CURRENT_SETTINNG_STATION;
-    quec_wifi_status.s_status = SSS_WORKING_REINIT;
-#else
-    index = 1;
-#endif
-    return index;
-}
-
-static int resolve_config_query(struct tcp_msg_t *msg)
-{
-    int index = -1;
-    char config_tx_buffer[256] = {0};
-    char buffer[128];
-    if( msg->buffer == NULL && msg->buffer[0] != '0') return 1;
-
-    memset(buffer, 0x00, sizeof(buffer));
-    index = quec_config_query_entry(msg->buffer, buffer);
-    if( index == 0 ) {
-        udp_send_response(config_tx_buffer, msg->head, buffer);
-    } else {
-        index = 1;
-    }
-
-    return index;
-}
-
-static int resolve_msg_ota(struct tcp_msg_t *msg)
-{
-    int index = 0;
-    if( msg->buffer == NULL ) return 1;
-#ifdef QUECTEL_CONFIG_OTA_SUPPORT
-    extern int ota_app_main(char *ota_server);
-    //printf("ota url = %s\n", msg->buffer);
-    int ret = ota_app_main(msg->buffer);
-    if( ret != 0 ) {
-        index = 1;
-    }
-#else
-    index = 1;
-#endif
-    return index;
-}
-const char* build_sdk = "602";
-const char* build_model = "debug";
-const char* build_version = "v1.0";
-const char* build_time = "240222";
-
-static int resolve_msg_app_version(struct tcp_msg_t *msg)
-{
-    int index = -1;
-    char version_tx_buffer[256] = {0};
-    if( msg->buffer == NULL && msg->buffer[0] != '0') return 1;
-    char version[128] = {0};
-    snprintf(version, 128, "sdk: %s\nmodel: %s\nversion: %s\ntime: %s",
-        build_sdk, build_model, build_version, build_time);
-    
-    udp_send_response(version_tx_buffer, msg->head, version);
-    return index;
-}
-
-static int udp_packet_parse(char *rx_buffer, int len)
-{
-    struct tcp_msg_t *msg = unpack_tlv_format(rx_buffer, len);
-    int index = 0;
-    if( g_wifi_ota_status == 1 && msg->head[1] != UDP_WIFI_STATUS ) { // ota only status check
-        return 1;
-    }
-    if( msg != NULL ) {
-        switch (msg->head[1]) {
-            case UDP_WIFI_STATUS:
-                   index = resolve_msg_wifi_status(msg);
-                index += RESP_STATUS_OFSET;
-                break;
-            case UDP_CHANGE_WEB_NETWORK:
-                           index = resolve_msg_web_network(msg);
-                break;
-                   case UDP_CHANGE_AP:
-                           index = resolve_msg_ap_construct(msg);
-                break;
-                   case UDP_CHANGE_STATION:
-                           index = resolve_msg_ap_connect(msg);
-                break;
-            case UDP_OTA_UPDATE:
-                           index = resolve_msg_ota(msg);
-                break;
-            case UDP_APP_VERSION:
-                index = resolve_msg_app_version(msg);
-                break;
-            case UDP_SMART_CONFIG:
-                           index = resolve_msg_smartconfig_network(msg);
-                break;
-            case UDP_CONFIG_QUERY:
-                           index = resolve_config_query(msg);
-                break;
-                   default:
-                           printf("error message: %s\n", rx_buffer);
-                index = 1;
-                break;
-        }
-    } else {
-        printf("wrong format msg and exit\n");
-        index = 1;
-    }
-    return index;
-}
-
-static int udp_socket_init()
-{
-    int addr_family;
-    int ip_protocol;
-    int opt = 1;
-    struct sockaddr_in destAddr;
-    char addr_str[128];
-
-    // destAddr.sin_addr.s_addr = htonl(INADDR_ANY);
-    destAddr.sin_addr.s_addr = inet_addr("172.16.1.5");
-    destAddr.sin_family = AF_INET;
-    destAddr.sin_port = htons(PORT);
-    addr_family = AF_INET;
-    ip_protocol = IPPROTO_IP;
-    inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
-
-    int listen_sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
-    if (listen_sock < 0) {
-        printf("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) {
-        printf("Socket unable to bind: errno %d\n", errno);
-        return -1;
-    }
-    
-    sourceAddr.sin_addr.s_addr = inet_addr(PEER_IP);
-    sourceAddr.sin_family = AF_INET;
-    sourceAddr.sin_port = htons(PEER_PORT);
-
-    return listen_sock;
-}
-
-void udp_server_task(void *pvParameters)
-{
-    char rx_buffer[512];
-    char tx_buffer[256];
-    int index;
-    uint addrLen = sizeof(sourceAddr);
-    while (1) {
-        if( g_listen_sock > 0 ) close(g_listen_sock);
-        g_listen_sock = udp_socket_init();
-        if( g_listen_sock < 0 ) {
-            printf("socket init fail and retry\n");
-            // vTaskDelay(1000/portTICK_RATE_MS);
-            continue;
-        }
-
-        while (1) {
-                       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
-            if (len < 0) {
-                printf("recv failed: errno %d\n", errno);
-                break;
-            } else if (len == 0) {
-                printf("Connection closed\n");
-                break;
-            }
-            // Data received
-            rx_buffer[len] = '\0'; // Null-terminate whatever we received and treat like a string
-            printf("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, msg_wifi_resp[index]);
-            }
-
-            if( quec_wifi_status.s_status == SSS_WORKING_RESTART ) {
-                //station_wifi_set_info("","");
-
-                tcp_device_restart();
-            } else if( quec_wifi_status.s_status == SSS_WORKING_REINIT ) {
-                user_netif_deinit();
-                   // vTaskDelay(1000/portTICK_RATE_MS);
-                   user_netif_init();
-                quec_wifi_status.s_status = SSS_WORKING_NONE;
-                break;
-            }
-        }
-       }
-       
-}
-#if 0
-void wifi_status()
-{
-    char tx_buffer[128] = {0};
-    int index = resolve_msg_wifi_status(NULL);
-    char *head = "FF";
-    int len = pack_tlv_format(tx_buffer, head, msg_wifi_status[index]);
-    printf("wifi_status len = %d, msg = [%s]\n",len, tx_buffer);
-}
-#endif
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/slip/udp_server.h b/code/sdk/drivers/peripheral/slip/udp_server.h
deleted file mode 100644 (file)
index a2fac0f..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* BSD Socket API Example
-
-   This example code is in the Public Domain (or CC0 licensed, at your option.)
-
-   Unless required by applicable law or agreed to in writing, this
-   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-   CONDITIONS OF ANY KIND, either express or implied.
-*/
-#ifndef __UDP_SERVER_H
-#define __UDP_SERVER_H
-
-// status 0: init, 1: station  2: softap
-enum WIFI_CURRENT_SETTINNG {
-    WIFI_CURRENT_SETTINNG_NONE = 0,
-    WIFI_CURRENT_SETTINNG_STATION,
-    WIFI_CURRENT_SETTINNG_SOFTAP
-};
-
-typedef struct _web_config_t {
-    int used;
-    char user[36];
-    char password[64];
-} web_config_t;
-
-void set_current_wifi_stat(enum WIFI_CURRENT_SETTINNG stat);
-
-void udp_server_task(void *pvParameters);
-
-void udp_ota_update(char *content);
-#endif
index 1bfcf49..33ba8c3 100644 (file)
@@ -6,7 +6,6 @@ set(COMPONENT_NAME "custom_utils")
 
 set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/custom_utils.c
-    ${CMAKE_CURRENT_SOURCE_DIR}/cat1_ctl.c
     ${CMAKE_CURRENT_SOURCE_DIR}/custom_utils_at_cmd.c
 )
 
diff --git a/code/sdk/drivers/peripheral/utils/cat1_ctl.c b/code/sdk/drivers/peripheral/utils/cat1_ctl.c
deleted file mode 100644 (file)
index 2534a13..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-#include "platform_core.h"
-#include "stdint.h"
-#include "pinctrl.h"
-#include "cat1_ctl.h"
-uint32_t uapi_cat1_power_on(uint32_t pwron)
-{
-
-    if( pwron == 0)
-    {
-        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_LOW);
-        // wstp_print("Power OFF Cat1! L23 low  \r\n");
-    }else{
-        uapi_gpio_set_dir(S_AGPIO_L23, HAL_GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L23, HAL_GPIO_LEVEL_HIGH);
-        // wstp_print("Power ON Cat1! L23 high \r\n");
-    }
-    
-    return 0;
-}
-uint32_t uapi_cat1_reset(uint32_t pwron)
-{
-    if( pwron == 0)
-    {
-        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_HIGH);
-        // wstp_print("clear reset Cat1! L28 high \r\n");
-    }else{
-        uapi_gpio_set_dir(S_AGPIO_L28, HAL_GPIO_DIRECTION_OUTPUT);
-        uapi_gpio_set_val(S_AGPIO_L28, HAL_GPIO_LEVEL_LOW); 
-        // wstp_print("Reset Cat1! L28 low\r\n");
-    }
-
-    return 0;
-}
\ No newline at end of file
diff --git a/code/sdk/drivers/peripheral/utils/cat1_ctl.h b/code/sdk/drivers/peripheral/utils/cat1_ctl.h
deleted file mode 100644 (file)
index ba5313d..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-\r
-#ifndef __CAT1_CTL_H\r
-#define __CAT1_CTL_H\r
-\r
-#include "stdint.h"\r
-uint32_t uapi_cat1_power_on(uint32_t pwron);\r
-uint32_t uapi_cat1_reset(uint32_t pwron);\r
-\r
-#endif\r
index 064ac93..3787af9 100644 (file)
@@ -41,7 +41,7 @@
 #endif
 
 #define LWIP_NETCONN                    0
-#define LWIP_SOCKET                     0
+#define LWIP_SOCKET                     1
 #define SYS_LIGHTWEIGHT_PROT            0
 #define LWIP_COMPAT_MUTEX               2
 #define LWIP_IPV4                       1
@@ -89,4 +89,9 @@
 #define LWIP_MDNS_RESPONDER             1
 #define SLIP_DEBUG                      0x80U //LWIP_DBG_ON
 #define LWIP_DEBUG
+
+#define LWIP_POSIX_SOCKETS_IO_NAMES     0
+#define MEMP_MEM_MALLOC                 1
+#define LWIP_UDP                        1
+#define LWIP_TCP                        1
 #endif /* LWIP_HDR_LWIPOPTS_H__ */
index 23759d5..092ee24 100644 (file)
@@ -2534,6 +2534,7 @@ lwip_poll_should_wake(const struct lwip_select_cb *scb, int fd, int has_recveven
 #endif /* LWIP_SOCKET_POLL */
 
 #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL
+#define poll_check_waiters(...)
 /**
  * Callback registered in the netconn layer for each socket-netconn.
  * Processes recvevent (data available) and wakes up tasks waiting for select.
@@ -2647,6 +2648,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
  * select_cb_list during our UNPROTECT/PROTECT. We use a generational counter to
  * detect this change and restart the list walk. The list is expected to be small
  */
+
 static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent)
 {
   struct lwip_select_cb *scb;
index 7d089b7..82df7a2 100644 (file)
@@ -695,7 +695,7 @@ ssize_t lwip_recvfrom_internal(int s, void *mem, size_t len, int flags, struct s
 #define ioctl(s,cmd,argp)                         lwip_ioctl(s,cmd,argp)
 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
 #endif /* LWIP_COMPAT_SOCKETS != 2 */
-
+#define DF_NADDR(addr) ip_addr_t naddr = addr
 #endif /* LWIP_COMPAT_SOCKETS */
 
 #ifdef __cplusplus