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

add:通过频点查找频段,mobile.scell增加频段信息

豆豆 3 месяцев назад
Родитель
Сommit
d4d5c141ea

+ 4 - 0
components/mobile/luat_lib_mobile.c

@@ -601,6 +601,10 @@ static int l_mobile_scell_extern_info(lua_State* L) {
     lua_pushinteger(L, info.pci);
     lua_setfield(L, -2, "pci");
 
+    ret = luat_mobile_get_band_from_earfcn(info.earfcn);
+    lua_pushinteger(L, ret);
+    lua_setfield(L, -2, "band");
+
     // 基站相关
     uint32_t eci = 0;
     uint16_t tac = 0;

+ 6 - 0
components/mobile/luat_mobile.h

@@ -894,6 +894,12 @@ int luat_mobile_get_isp_from_plmn(uint16_t mcc, uint8_t mnc);
  */
 int luat_mobile_get_plmn_from_imsi(char *imsi, uint16_t *mcc, uint8_t *mnc);
 
+/**
+ * @brief 通过DL EARFCN查找对应频段
+ * @param earfcn 下行频点
+ * @return >0为对应频段,=0未找到对应频段
+ */
+int luat_mobile_get_band_from_earfcn(uint32_t earfcn);
 
 /**
  * @brief 获取最近一次来电号码

+ 99 - 0
components/mobile/luat_mobile_common.c

@@ -199,3 +199,102 @@ int luat_mobile_get_plmn_from_imsi(char *imsi, uint16_t *mcc, uint8_t *mnc)
 	*mnc = temp;
 	return 0;
 }
+typedef struct{
+	uint8_t band;
+	uint32_t min_earfcn;
+	uint32_t max_earfcn;
+}earfcn_to_band_t;
+
+const earfcn_to_band_t g_band_list[] = {
+	{1, 0, 599},
+	{2, 600, 1199},
+	{3, 1200, 1949},
+	{4, 1950, 2399},
+	{5, 2400, 2649},
+	{7, 2750, 3449},
+	{8, 3450, 3799},
+	{9, 3800, 4149},
+	{10, 4150, 4749},
+	{11, 4750, 4949},
+	{12, 5010, 5179},
+	{13, 5180, 5279},
+	{14, 5280, 5379},
+	{17, 5730, 5849},
+	{18, 5850, 5999},
+	{19, 6000, 6149},
+	{20, 6150, 6449},
+	{21, 6450, 6599},
+	{22, 6600, 7399},
+	{24, 7700, 8039},
+	{25, 8040, 8689},
+	{26, 8690, 9039},
+	{27, 9040, 9209},
+	{28, 9210, 9659},
+	{29, 9660, 9769},
+	{30, 9770, 9869},
+	{31, 9870, 9919},
+	{32, 9920, 10359},
+	{33, 36000, 36199},
+	{34, 36200, 36349},
+	{35, 36350, 36949},
+	{36, 36950, 37549},
+	{37, 37550, 37749},
+	{38, 37750, 38249},
+	{39, 38250, 38649},
+	{40, 38650, 39649},
+	{41, 39650, 41589},
+	{42, 41590, 43589},
+	{43, 43590, 45589},
+	{44, 45590, 46589},
+	{45, 46590, 46789},
+	{46, 46790, 54539},
+	{47, 54540, 55239},
+	{48, 55240, 56739},
+	{49, 56740, 58239},
+	{50, 58240, 59089},
+	{51, 59090, 59139},
+	{52, 59140, 60139},
+	{53, 60140, 60254},
+	{65, 65536, 66435},
+	{66, 66436, 67335},
+	{67, 67336, 67535},
+	{68, 67536, 67835},
+	{69, 67836, 68335},
+	{70, 68336, 68585},
+	{71, 68586, 68935},
+	{72, 68936, 68985},
+	{73, 68986, 69035},
+	{74, 69036, 69465},
+	{75, 69466, 70315},
+	{76, 70316, 70365},
+	{85, 70366, 70545},
+	{87, 70546, 70595},
+	{88, 70596, 70645},
+};
+
+
+int luat_mobile_get_band_from_earfcn(uint32_t earfcn)
+{
+	uint32_t l = 0;
+	uint32_t h = (sizeof(g_band_list) / sizeof(g_band_list[0]) - 1);
+	while (l <= h)
+	{
+		uint16_t index = l + ((h - l) >> 1);
+		uint32_t min =  g_band_list[index].min_earfcn;
+		uint32_t max = g_band_list[index].max_earfcn;
+		if (earfcn >= min && earfcn <= max)
+		{
+			return g_band_list[index].band;
+		}
+		else if(earfcn > max)
+		{
+			l = index + 1;
+		}
+		else if(earfcn < min)
+		{
+			h = index - 1;
+		}
+	}
+	return 0;
+}
+