Просмотр исходного кода

add: 添加mobile.tac()函数, 并在获取cellinfo失败是提示先执行reqCellInfo()

Wendal Chen 2 лет назад
Родитель
Сommit
d4d1e03406
2 измененных файлов с 34 добавлено и 2 удалено
  1. 26 2
      components/mobile/luat_lib_mobile.c
  2. 8 0
      components/mobile/luat_mobile.h

+ 26 - 2
components/mobile/luat_lib_mobile.c

@@ -495,6 +495,24 @@ static int l_mobile_eci(lua_State* L) {
     return 1;
 }
 
+/**
+获取当前服务小区的TAC或者LAC
+@api mobile.tac()
+@return int 当前eci值,若失败返回-1. 如果尚未注册到网络,会返回0
+@usage
+-- 本API于 2023.7.9 新增
+ */
+static int l_mobile_tac(lua_State* L) {
+    uint32_t tac;
+    if (luat_mobile_get_service_tac_or_lac(&tac) == 0) {
+        lua_pushinteger(L, tac);
+    }
+    else {
+        lua_pushinteger(L, -1);
+    }
+    return 1;
+}
+
 /**
 获取当前服务小区的eNBID(eNodeB Identifier)
 @api mobile.enbid()
@@ -566,7 +584,7 @@ static inline uint16_t u162bcd(uint16_t src) {
 ]]
 
 mobile.reqCellInfo(60)
--- 订阅
+-- 订阅
 sys.subscribe("CELL_INFO_UPDATE", function()
     log.info("cell", json.encode(mobile.getCellInfo()))
 end)
@@ -598,7 +616,12 @@ static int l_mobile_get_cell_info(lua_State* L) {
 
     // 当前仅返回lte信息
     if (info->lte_info_valid == 0 || info->lte_service_info.cid == 0) {
-        LLOGI("lte cell info not found");
+        if (0 == luat_mobile_get_service_cell_identifier(&info->lte_service_info.cid) && info->lte_service_info.cid) {
+            LLOGW("pls call mobile.reqCellInfo() and wait for CELL_INFO_UPDATE");
+        }
+        else {
+            LLOGI("lte cell info not found");
+        }
         goto exit;
     }
     
@@ -877,6 +900,7 @@ static const rotable_Reg_t reg_mobile[] = {
     {"rsrp",            ROREG_FUNC(l_mobile_rsrp)},
     {"snr",             ROREG_FUNC(l_mobile_snr)},
     {"eci",             ROREG_FUNC(l_mobile_eci)},
+    {"tac",             ROREG_FUNC(l_mobile_tac)},
     {"enbid",           ROREG_FUNC(l_mobile_enbid)},
     {"flymode",         ROREG_FUNC(l_mobile_flymode)},
     {"simid",           ROREG_FUNC(l_mobile_simid)},

+ 8 - 0
components/mobile/luat_mobile.h

@@ -461,6 +461,14 @@ int luat_mobile_get_last_notify_signal_strength(uint8_t *csq);
  * @return int =0成功,其他失败
  */
 int luat_mobile_get_service_cell_identifier(uint32_t *eci);
+
+/**
+ * @brief 获取当前服务小区的TAC或LAC
+ * 
+ * @param tac
+ * @return int =0成功,其他失败
+ */
+int luat_mobile_get_service_tac_or_lac(uint16_t *tac);
 /* --------------------------------------------------- cell info end --------------------------------------------------- */