blob: f945a712937045331e2c3a1e684d94696dc53f58 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 *
10 * MediaTek Inc. (C) 2016. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35#include "rfdesense/RfDesenseTxTestTd.h"
36
37#include <algorithm>
38#include <iterator>
39#include <stdexcept>
40
41#include "em.h"
42#include "rfdesense/RfDesenseTxTestBase.h"
43#include "util/log_extra.h"
44
45#undef LOG_TAG
46#define LOG_TAG "EM_RfDesenseTxTestTd"
47const int RfDesenseTxTestTd::INDEX_BAND = 0;
48const int RfDesenseTxTestTd::INDEX_CHANNEL = 1;
49const int RfDesenseTxTestTd::INDEX_POWER = 2;
50std::string RfDesenseTxTestTd::band = "";
51std::string RfDesenseTxTestTd::channel= "";
52std::string RfDesenseTxTestTd::power= "";
53const std::vector<std::string> RfDesenseTxTestTd::tdscdma_band_values = {"1","6"};
54const std::vector<std::vector<std::string>> RfDesenseTxTestTd::tdscdma_limits = {
55 {"10087","10054","10121","10054","10121","24","10","24"},
56 {"9500","9404","9596","9404","9596","24","10","24"}};
57const std::vector<std::string> RfDesenseTxTestTd::wcdma_band_values = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","19","20","21","22"};
58const std::vector<std::vector<std::string>> RfDesenseTxTestTd::wcdma_limits = {
59 {"9750","9612","9888","9612","9888","23","-55","24"},
60 {"9262","9262","9538","12","287","23","-55","24"},
61 {"937","937","1288","937","1288","23","-55","24"},
62 {"1312","1312","1513","1662","1862","23","-55","24"},
63 {"4132","4132","4233","782","862","23","-55","24"},
64 {"4162","4162","4188","812","837","23","-55","24"},
65 {"2012","2012","2338","2362","2687","23","-55","24"},
66 {"2712","2712","2863","2712","2863","23","-55","24"},
67 {"8762","8762","8912","8762","8912","23","-55","24"},
68 {"2887","2887","3163","3187","3462","23","-55","24"},
69 {"3487","3487","3562","3487","3562","23","-55","24"},
70 {"3617","3617","3678","3707","3767","23","-55","24"},
71 {"3792","3792","3818","3842","3867","23","-55","24"},
72 {"3892","3892","3918","3942","3967","23","-55","24"},
73 {"312","312","363","387","437","23","-55","24"},
74 {"4287","4287","4413","4287","4413","23","-55","24"},
75 {"462","462","512","462","512","23","-55","24"},
76 {"4437","4437","4813","4437","4813","23","-55","24"}};
77std::map<int, std::string> RfDesenseTxTestTd::tdscdam_values = {{INDEX_BAND, "1"},{INDEX_CHANNEL, "10087"},{INDEX_POWER, "24"}};
78std::map<int, std::string> RfDesenseTxTestTd::wcdma_values = {{INDEX_BAND, "1"},{INDEX_CHANNEL, "9750"},{INDEX_POWER, "23"}};
79
80RfDesenseTxTestTd::RfDesenseTxTestTd(int modemType) {
81 this->modem_type = modemType;
82 if(modem_type == utils::MODEM_TDSCDMA){
83 band = tdscdam_values[INDEX_BAND];
84 channel = tdscdam_values[INDEX_CHANNEL];
85 power = tdscdam_values[INDEX_POWER];
86 } else if(modem_type == utils::MODEM_WCDMA) {
87 band = wcdma_values[INDEX_BAND];
88 channel = wcdma_values[INDEX_CHANNEL];
89 power = wcdma_values[INDEX_POWER];
90 }
91}
92
93RfDesenseTxTestTd::~RfDesenseTxTestTd() {
94 // TODO Auto-generated destructor stub
95}
96
97std::string RfDesenseTxTestTd::modemTypeToString(int type) {
98 switch(modem_type){
99 case utils::MODEM_TDSCDMA:
100 return "TDSCDMA";
101 case utils::MODEM_WCDMA:
102 return "MODEM_WCDMA";
103 default:
104 return "UNKNOWN";
105 }
106}
107
108std::string RfDesenseTxTestTd::get_command() {
109 std::string command = "AT+ERFTX=0,0," + band + "," + channel + "," + power;
110 LOG_D(LOG_TAG, "GSM command: %s", command.c_str());
111 return command;
112}
113
114std::string RfDesenseTxTestTd::get_band(){
115 return band;
116}
117
118std::string RfDesenseTxTestTd::get_power(){
119 return power;
120}
121
122bool RfDesenseTxTestTd::check_channel(int index, std::string channel) {
123 std::string s;
124 std::vector<std::vector<std::string>> limits;
125 if(modem_type == utils::MODEM_TDSCDMA){
126 limits = tdscdma_limits;
127 } else if(modem_type == utils::MODEM_WCDMA) {
128 limits = wcdma_limits;
129 } else {
130 s = utils::format("check_channel(): modem type (%s) isn't right", modemTypeToString(modem_type));
131 em_result_notify_fail(s);
132 LOG_D(LOG_TAG, "check_channel(): modem type (%s) isn't right", modemTypeToString(modem_type));
133 return false;
134 }
135
136 if(index >= limits.size()) {
137 s = utils::format("check_channel,index(%d) is invalid", index);
138 em_result_notify_fail(s);
139 LOG_D(LOG_TAG, "check_channel,index(%d) is invalid", index);
140 return false;
141 }
142 int value = -1;
143 try {
144 value = std::stoi(channel);
145 } catch (std::invalid_argument &err) {
146 s = utils::format("check_channel,channel(%s) is invalid, reason: %s", channel.c_str(), err.what());
147 em_result_notify_fail(s);
148 LOG_D(LOG_TAG, "check_channel,channel(%s) is invalid, reason: %s", channel.c_str(), err.what());
149 return false;
150 }
151 step = 1;
152 std::vector<std::string> limit = limits[index];
153 min = std::stoi(limit[RfDesenseTxTestBase::CHANNEL_MIN]);
154 max = std::stoi(limit[RfDesenseTxTestBase::CHANNEL_MAX]);
155 min2 = std::stoi(limit[RfDesenseTxTestBase::CHANNEL_MIN2]);
156 max2 = std::stoi(limit[RfDesenseTxTestBase::CHANNEL_MAX2]);
157 if ((value < min || value > max) && (value < min2 || value > max2)) {
158 s = utils::format("check_channel,channel(%s) is invalid, range is [%d, %d] or [%d, %d]" , channel.c_str(), min, max, min2, max2);
159 em_result_notify_fail(s);
160 LOG_D(LOG_TAG, "check_channel,channel(%s) is invalid, range is [%d, %d] or [%d, %d]" , channel.c_str(), min, max, min2, max2);
161 return false;
162 }
163 return true;
164}
165
166bool RfDesenseTxTestTd::check_power(int index ,std::string power) {
167 std::string s;
168 std::vector<std::vector<std::string>> limits;
169 if(modem_type == utils::MODEM_TDSCDMA){
170 limits = tdscdma_limits;
171 } else if(modem_type == utils::MODEM_WCDMA) {
172 limits = wcdma_limits;
173 } else {
174 s = utils::format("check_power(): modem type (%s) isn't right", modemTypeToString(modem_type));
175 em_result_notify_fail(s);
176 LOG_D(LOG_TAG, "check_power(): modem type (%s) isn't right", modemTypeToString(modem_type));
177 return false;
178 }
179 if(index >= limits.size()) {
180 s = utils::format("check_power,index(%d) is invalid", index);
181 em_result_notify_fail(s);
182 LOG_D(LOG_TAG, "check_power,index(%d) is invalid", index);
183 return false;
184 }
185 int value = -1;
186 try {
187 value = std::stoi(power);
188 } catch (std::invalid_argument &err) {
189 s = utils::format("check_power,power(%s) is invalid, reason: %s", power.c_str(), err.what());
190 em_result_notify_fail(s);
191 LOG_D(LOG_TAG, "check_power,power(%s) is invalid, reason: %s", power.c_str(), err.what());
192 return false;
193 }
194 step = 1;
195 std::vector<std::string> limit = limits[index];
196 min = std::stoi(limit[RfDesenseTxTestBase::POWER_MIN]);
197 max = std::stoi(limit[RfDesenseTxTestBase::POWER_MAX]);
198 if (value < min || value > max) {
199 s = utils::format("check_power,power(%s) is invalid, range is [%d, %d]" , power.c_str(), min, max);
200 em_result_notify_fail(s);
201 LOG_D(LOG_TAG, "check_power,power(%s) is invalid, range is [%d, %d]" , power.c_str(), min, max);
202 return false;
203 }
204 if (step != 1 && (value - min) % step != 0) {
205 return false;
206 }
207 return true;
208}
209
210void RfDesenseTxTestTd::show_default() {
211 std::string temp;
212 if(modem_type == utils::MODEM_TDSCDMA){
213 int band_index = utils::find_index(tdscdma_band_values, band);
214 temp = "TDSCDMA parameters: Band: " + std::string(rfdesense_tdscdma_band[band_index].name) +
215 ", Channel(ARFCN): " + channel + ", Power Level(dBm): " + power;
216 } else if(modem_type == utils::MODEM_WCDMA) {
217 int band_index = utils::find_index(wcdma_band_values, band);
218 temp = "WCDMA parameters: Band: " + std::string(rfdesense_wcdma_band[band_index].name) +
219 ", Channel(ARFCN): " + channel + ", Power Level(dBm): " + power;
220 }
221 if(!temp.empty()) {
222 emResultNotifyWithDone(temp);
223 } else {
224 em_result_notify_fail("show_default");
225 LOG_D(LOG_TAG, "temp is null ");
226 }
227}
228
229bool RfDesenseTxTestTd::set_band(int value) {
230 std::string s;
231 std::vector<std::string> band_values;
232 if(modem_type == utils::MODEM_TDSCDMA){
233 band_values = tdscdma_band_values;
234 } else if(modem_type == utils::MODEM_WCDMA) {
235 band_values = wcdma_band_values;
236 } else {
237 s = utils::format("set_band(): modem type (%s) isn't right", modemTypeToString(modem_type));
238 em_result_notify_fail(s);
239 LOG_D(LOG_TAG, "set_band(): modem type (%s) isn't right", modemTypeToString(modem_type));
240 return false;
241 }
242 if(value < 0 || value >= band_values.size()) {
243 s = utils::format("set band(). value(%d) is out of range", value);
244 em_result_notify_fail(s);
245 LOG_D(LOG_TAG, "set band(). value(%d) is out of range", value);
246 return false;
247 }
248 band = band_values[value];
249 if(modem_type == utils::MODEM_TDSCDMA){
250 tdscdam_values[INDEX_BAND] = band;
251 } else if(modem_type == utils::MODEM_WCDMA) {
252 wcdma_values[INDEX_BAND] = band;
253 }
254 std::string temp;
255 if(modem_type == utils::MODEM_TDSCDMA){
256 em_result_notify_ok(std::string("band: ") + rfdesense_tdscdma_band[value].name);
257 } else if(modem_type == utils::MODEM_WCDMA) {
258 em_result_notify_ok(std::string("band: ") + rfdesense_wcdma_band[value].name);
259 }
260 return true;
261}
262
263bool RfDesenseTxTestTd::set_channel(std::string str) {
264 std::string s;
265 std::vector<std::string> band_values;
266 if(modem_type == utils::MODEM_TDSCDMA){
267 band_values = tdscdma_band_values;
268 } else if(modem_type == utils::MODEM_WCDMA) {
269 band_values = wcdma_band_values;
270 } else {
271 s = utils::format("set_channel(): modem type (%s) isn't right", modemTypeToString(modem_type));
272 em_result_notify_fail(s);
273 LOG_D(LOG_TAG, "set_channel(): modem type (%s) isn't right", modemTypeToString(modem_type));
274 return false;
275 }
276 int index = utils::find_index(band_values, band);
277 if(index < 0 ) {
278 s = utils::format("set_channel(%s) isn't invalid", band.c_str());
279 em_result_notify_fail(s);
280 LOG_D(LOG_TAG, "set_channel(%s) isn't invalid", band.c_str());
281 return false;
282 }
283 if(!check_channel(index, str)) return false;
284 channel = str;
285 if(modem_type == utils::MODEM_TDSCDMA){
286 tdscdam_values[INDEX_CHANNEL] = channel;
287 } else if(modem_type == utils::MODEM_WCDMA) {
288 wcdma_values[INDEX_CHANNEL] = channel;
289 }
290 em_result_notify_ok("channel: " + channel);
291 return true;
292}
293
294bool RfDesenseTxTestTd::set_power(std::string str) {
295 std::string s;
296 std::vector<std::string> band_values;
297 if(modem_type == utils::MODEM_TDSCDMA){
298 band_values = tdscdma_band_values;
299 } else if(modem_type == utils::MODEM_WCDMA) {
300 band_values = wcdma_band_values;
301 } else {
302 s = utils::format("set_power(): modem type (%s) isn't right", modemTypeToString(modem_type));
303 em_result_notify_fail(s);
304 LOG_D(LOG_TAG, "set_power(): modem type (%s) isn't right", modemTypeToString(modem_type));
305 return false;
306 }
307 int index = utils::find_index(band_values, band);
308 if(index < 0 ) {
309 s = utils::format("set_power(%s) isn't invalid", band.c_str());
310 em_result_notify_fail(s);
311 LOG_D(LOG_TAG, "set_power(%s) isn't invalid", band.c_str());
312 return false;
313 }
314 if(!check_power(index, str)) return false;
315 power = str;
316 if(modem_type == utils::MODEM_TDSCDMA){
317 tdscdam_values[INDEX_POWER] = str;
318 } else if(modem_type == utils::MODEM_WCDMA) {
319 wcdma_values[INDEX_POWER] = str;
320 }
321 em_result_notify_ok("power: " + power);
322 return true;
323}
324
325void RfDesenseTxTestTd::show_channel() {
326 emResultNotifyWithDone("Channel(UarfCN): " + channel);
327}
328
329void RfDesenseTxTestTd::show_power() {
330 emResultNotifyWithDone("Power Level(dBm): " + power);
331}