blob: 82cd6d8b4a4189d34c0848a55065088a832891d7 [file] [log] [blame]
b.liu86b7ff22024-04-03 14:25:55 +08001#include "lynq_qser_network.h"
2#include "mbtk_type.h"
3#include "mbtk_info_api.h"
4
5#include <stdio.h>
6#include <stdlib.h>
7
8
9char *tech_domain[] = {"NONE", "3GPP", "3GPP2"};
10char *radio_tech[] = {"unknown",
11 "TD_SCDMA", "GSM", "HSPAP", "LTE", "EHRPD", "EVDO_B",
12 "HSPA", "HSUPA", "HSDPA", "EVDO_A", "EVDO_0", "1xRTT",
13 "IS95B", "IS95A", "UMTS", "EDGE", "GPRS", "NONE"};
14
15void nw_event_ind_handler (
16 nw_client_handle_type h_nw,
17 u_int32_t ind_flag,
18 void *ind_msg_buf,
19 u_int32_t ind_msg_len,
20 void *contextPtr)
21{
22 uint8 *net_data = NULL;
23
24 net_data = (uint8*)ind_msg_buf;
25
26 if(ind_msg_buf && ind_msg_len > 0)//无处理原始数据传输过来
27 {
28 if(*net_data == 0)
29 { // CS
30 printf("CS:act=%d, mode=%d\n", *(net_data + 1), *(net_data + 2));
31 }
32 else
33 { // PS
34 printf("PS[%s]:act=%d, mode=%d\n", *(net_data + 3) == 0 ? "GSM/WCDMA" : "LTE", *(net_data + 1), *(net_data + 2));
35 }
36 }
37 else
38 {
39 printf("NET_CB : NULL");
40 }
41
42}
43
44
45int main(int argc, char *argv[])
46{
47 char operator[10];
48 int opt;
49 int lv_voll = 0;
50 nw_client_handle_type handle = -1;
51 mbtk_log_init("radio", "NW_TEST");
52
53 while(1)
54 {
55 printf("=========network main=========\n"
56 "\t0 exit\n"
57 "\t1 network init\n"
58 "\t2 network add rx msg handle\n"
59 "\t3 network band set config\n"
60 "\t4 network get operator name\n"
61 "\t5 network get reg status\n"
62 "\t6 network get signal strength\n"
63 "\t7 network set oos config\n"
64 "\t8 network get oos config\n"
65 "\t9 network set rf config\n"
66 "\t10 network get rf config\n"
67 "\t11 network deinit\n"
68 "operator: >> ");
69
70 fgets(operator, sizeof(operator), stdin);
71 fflush(stdin);
72 opt = atoi(operator);
73 switch (opt)
74 {
75 case 0:
76 printf("main exit\n");
77 return 0;
78 case 1:
79 qser_nw_client_init(&handle);
80 break;
81 case 2:
82 qser_nw_add_rx_msg_handler(handle, nw_event_ind_handler, NULL);
83 break;
84 case 3:
85 {
86 //漫游开关现在不支持,所以就不用配置
87 printf("please input \n"
88 "\t1:GSM \n"
89 "\t2:WCDMA \n"
90 "\t4:CDMA \n"
91 "\t8:EVDO \n"
92 "\t16:LTE \n"
93 "\t32:TDSCDMA \n"
94 );
95 memset(operator,0x00, sizeof(operator));
96 fgets(operator, sizeof(operator)-1, stdin);
97 fflush(stdin);
98 opt = atoi(operator);
99 QSER_NW_CONFIG_INFO_T t_info;
100 switch(opt)
101 {
102 case 1:
103 t_info.preferred_nw_mode = QSER_NW_MODE_GSM;//2G
104 break;
105 case 2:
106 t_info.preferred_nw_mode = QSER_NW_MODE_WCDMA;//3G
107 break;
108 case 4:
109 t_info.preferred_nw_mode = QSER_NW_MODE_CDMA;//3G
110 break;
111 case 8:
112 t_info.preferred_nw_mode = QSER_NW_MODE_EVDO;//3G
113 break;
114 case 16:
115 t_info.preferred_nw_mode = QSER_NW_MODE_LTE;//4G
116 break;
117 case 32:
118 t_info.preferred_nw_mode = QSER_NW_MODE_TDSCDMA;//3G
119 break;
120 default:
121 t_info.preferred_nw_mode = QSER_NW_MODE_LTE;//4G
122 break;
123 }
124 qser_nw_set_config(handle, &t_info);
125 }
126 break;
127 case 4:
128 {
129 QSER_NW_OPERATOR_NAME_INFO_T t_info;
130 int err = qser_nw_get_operator_name(handle, &t_info);
131 if(err)
132 {
133 printf("Error : %d\n", err);
134 } else
135 {
136 printf("Operator : %s, %s, %s, %s\n", t_info.long_eons, t_info.short_eons, t_info.mcc, t_info.mnc);
137 }
138 }
139 break;
140 case 5:
141 {
142 QSER_NW_REG_STATUS_INFO_T reg;
143 int err = qser_nw_get_reg_status(handle, &reg);
144 if(err)
145 {
146 printf("Error : %d\n", err);
147 }
148 else
149 {
150 if(reg.voice_registration_details_3gpp_valid)
151 {
152 printf("voice_registration_details_3gpp: tech_domain=%d, radio_tech=%d, mcc=%s, mnc=%s, roaming=%d, forbidden=%d, cid=0x%X, lac=%d, psc=%d, tac=%d\n",
153 reg.voice_registration_details_3gpp.tech_domain,
154 reg.voice_registration_details_3gpp.radio_tech,
155 reg.voice_registration_details_3gpp.mcc,
156 reg.voice_registration_details_3gpp.mnc,
157 reg.voice_registration_details_3gpp.roaming,
158 reg.voice_registration_details_3gpp.forbidden,
159 reg.voice_registration_details_3gpp.cid,
160 reg.voice_registration_details_3gpp.lac,
161 reg.voice_registration_details_3gpp.psc,
162 reg.voice_registration_details_3gpp.tac);
163 }
164 if(reg.data_registration_details_3gpp_valid)
165 {
166 printf("data_registration_details_3gpp: tech_domain=%d, radio_tech=%d, mcc=%s, mnc=%s, roaming=%d, forbidden=%d, cid=0x%X, lac=%d, psc=%d, tac=%d\n",
167 reg.data_registration_details_3gpp.tech_domain,
168 reg.data_registration_details_3gpp.radio_tech,
169 reg.data_registration_details_3gpp.mcc,
170 reg.data_registration_details_3gpp.mnc,
171 reg.data_registration_details_3gpp.roaming,
172 reg.data_registration_details_3gpp.forbidden,
173 reg.data_registration_details_3gpp.cid,
174 reg.data_registration_details_3gpp.lac,
175 reg.data_registration_details_3gpp.psc,
176 reg.data_registration_details_3gpp.tac);
177 }
178 //printf("Data Reg: radio_tech = %d, lac = %x, cid = %x\n", reg.data_registration_details_3gpp.radio_tech, reg.data_registration_details_3gpp.lac, reg.data_registration_details_3gpp.cid);
179 //printf("Voice Reg: radio_tech = %d, lac = %x, cid = %x\n", reg.voice_registration_details_3gpp.radio_tech, reg.voice_registration_details_3gpp.lac, reg.voice_registration_details_3gpp.cid);
180 }
181 }
182 break;
183 case 6:
184 {
185 QSER_NW_SIGNAL_STRENGTH_INFO_T sig;
186 int err = qser_nw_get_signal_strength(handle, &sig);
187 if(err)
188 {
189 printf("Error : %d\n", err);
190 }
191 else
192 {
193 if (sig.gsm_sig_info_valid == TRUE)
194 printf("Signal GSM: rssi = %d\n", sig.gsm_sig_info.rssi);
195 else if (sig.lte_sig_info_valid == TRUE)
196 printf("Signal LTE: rssi = %d, rsrp = %d, rsrq = %d, snr = %d\n", sig.lte_sig_info.rssi , sig.lte_sig_info.rsrp, sig.lte_sig_info.rsrq, sig.lte_sig_info.snr);
197 else if (sig.wcdma_sig_info_valid == TRUE)
198 printf("Signal UTRAN: rssi = %d, ecio = %d\n", sig.wcdma_sig_info.rssi , sig.wcdma_sig_info.ecio);
199 else
200 printf("Signal type not supported \n");
201 }
202 }
203 break;
204 case 7:
205 {
206 QSER_NW_OOS_CONFIG_INFO_T pt_info_s;
207 memset(&pt_info_s, 0x00, sizeof(QSER_NW_OOS_CONFIG_INFO_T));
208 /*取值范围0-255,设置时间自定义
209 phase 1 5次 次数无法更改,这五次都是以10秒为一次的间隔搜网
210 phase 2 5次 次数无法更改,这五次都是以15秒为一次的间隔搜网
211 phase 3 不限制次数的秒数设置,第三阶段不限制次数以20秒为一次的间隔搜网
212 如果要关闭OOS配置,则把min step max 全部配置为0即可
213 */
214 pt_info_s.type = QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN;//平台提供自定义配置搜网时间间隔
215 {
216 pt_info_s.u.full_band_scan_info.t_min = 10;//phase 1
217 pt_info_s.u.full_band_scan_info.t_step = 15;//phase 2
218 pt_info_s.u.full_band_scan_info.t_num = 0;//可以不配置,并没有使用
219 pt_info_s.u.full_band_scan_info.t_max = 20;//phase 3
220 }
221 printf("set OOS %d %d %d \n",pt_info_s.u.full_band_scan_info.t_min, pt_info_s.u.full_band_scan_info.t_step, pt_info_s.u.full_band_scan_info.t_max);
222 //pt_info_s.type = QSER_NW_OOS_CFG_TYPE_FAST_SCAN;平台本身有历史频点优先处理的逻辑(无接口不需要我们进行处理)
223 qser_nw_set_oos_config(handle, &pt_info_s);
224 }
225 break;
226 case 8:
227 {
228 QSER_NW_OOS_CONFIG_INFO_T pt_info_g;
229 qser_nw_get_oos_config(handle, &pt_info_g);
230 if (pt_info_g.type == QSER_NW_OOS_CFG_TYPE_FULL_BAND_SCAN)
231 printf("TYPE: %d min: %d setp: %d max: %d\n", pt_info_g.type, pt_info_g.u.full_band_scan_info.t_min, pt_info_g.u.full_band_scan_info.t_step, pt_info_g.u.full_band_scan_info.t_max);
232 else
233 printf("type not supported \n");
234 }
235 break;
236 case 9:
237 {
238 printf("please input 0 or 1 or 4: \n");
239 memset(operator,0x00, sizeof(operator));
240 fgets(operator, sizeof(operator)-1, stdin);
241 fflush(stdin);
242 opt = atoi(operator);
243 printf("rf_mode: [%d]\n",opt);
244 qser_nw_set_rf_mode(handle, opt);
245 }
246 break;
247 case 10:
248 {
249 int rf_t;
250 qser_nw_get_rf_mode(handle, &rf_t);
251 printf(">>>rf_mode = [%d]\n",rf_t);
252 }
253 break;
254 case 11:
255 qser_nw_client_deinit(handle);
256 break;
257 default:
258 break;
259 }
260
261 }
262
263 return 0;
264}
265