blob: 793e99f1295e485417f9c713dfaeccae93f8c8a2 [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/RfDesenseTxTestGsm.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#include "util/utils.h"
45
46#undef LOG_TAG
47#define LOG_TAG "EM_RfDesenseTxTestGsm"
48const int RfDesenseTxTestGsm::INDEX_BAND = 0;
49const int RfDesenseTxTestGsm::INDEX_CHANNEL = 1;
50const int RfDesenseTxTestGsm::INDEX_POWER = 2;
51const int RfDesenseTxTestGsm::INDEX_AFC = 3;
52const int RfDesenseTxTestGsm::INDEX_TSC = 4;
53const int RfDesenseTxTestGsm::INDEX_PATTERN = 5;
54std::string RfDesenseTxTestGsm::band = "128";
55std::string RfDesenseTxTestGsm::channel ="190";
56std::string RfDesenseTxTestGsm::power = "5";
57std::string RfDesenseTxTestGsm::afc = "4100";
58std::string RfDesenseTxTestGsm::tsc = "0";
59std::string RfDesenseTxTestGsm::pattern = "0";
60
61const std::vector<std::string> RfDesenseTxTestGsm::band_values = {"128","1", "2", "4", "8", "16"};
62const std::vector<std::vector<std::string>> RfDesenseTxTestGsm::gsm_gmsk_limits = {
63 {"190","128","251","128","251","5","5","19"},
64 {"63","1","124","1","124","5","5","19"},
65 {"62","0","124","975","1023","5","5","19"},
66 {"61","0","124","955","1023","5","5","19"},
67 {"700","512","885","512","885","0","0","15"},
68 {"661","512","810","512","885","0","0","15"}};
69
70std::shared_ptr<RfDesenseTxTestGsm> RfDesenseTxTestGsm::m_instance;
71std::mutex RfDesenseTxTestGsm::mutex;
72
73RfDesenseTxTestGsm::RfDesenseTxTestGsm() {
74
75}
76
77RfDesenseTxTestGsm::~RfDesenseTxTestGsm() {
78 // TODO Auto-generated destructor stub
79}
80
81std::shared_ptr<RfDesenseTxTestGsm> RfDesenseTxTestGsm::get_instance() {
82 if(!m_instance) {
83 mutex.lock();
84 if(!m_instance) {
85 m_instance = std::make_shared<RfDesenseTxTestGsm>();
86 }
87 mutex.unlock();
88 }
89 return m_instance;
90}
91
92std::string RfDesenseTxTestGsm::get_command() {
93 std::string command = "AT+ERFTX=2,1," + channel + "," + afc + "," + band + "," + tsc + "," + power + "," + pattern;
94 LOG_D(LOG_TAG, "GSM command: %s\n", command.c_str());
95 return command;
96}
97
98std::string RfDesenseTxTestGsm::get_band(){
99 return band;
100}
101
102std::string RfDesenseTxTestGsm::get_power(){
103 return power;
104}
105
106bool RfDesenseTxTestGsm::set_band(int value) {
107 LOG_D(LOG_TAG, "values: %d", value);
108 if (value < 0 || value >= band_values.size()) {
109 std::string s = utils::format("value(%d) is out of range\n", value);
110 LOG_D(LOG_TAG, s.c_str());
111 em_result_notify_fail(s);
112 return false;
113 }
114 this->band = band_values[value];
115 em_result_notify_ok("band: " + std::string(rfdesense_gsm_band[value].name));
116 return true;
117}
118
119bool RfDesenseTxTestGsm::set_pattern(int value) {
120 LOG_D(LOG_TAG, "values: %d", value);
121 if(value < 0 || value > 6) {
122 std::string s = utils::format("pattern(%s) is invalid, range is [0,6]\n" , pattern.c_str());
123 LOG_D(LOG_TAG, s.c_str());
124 em_result_notify_fail(s);
125 return false;
126 }
127 this->pattern = std::to_string(value);
128 em_result_notify_ok("pattern: " + std::string(rfdesense_gsm_pattern[value].name));
129 return true;
130}
131
132bool RfDesenseTxTestGsm::set_channel(std::string value){
133 int index = utils::find_index(band_values, band);
134 if(check_channel(index,value)) {
135 channel = value;
136 em_result_notify_ok("channel: " + channel);
137 return true;
138 }
139 return false;
140}
141
142bool RfDesenseTxTestGsm::set_power(std::string value){
143 int index = utils::find_index(band_values, band);
144 if(check_power(index, value)) {
145 power = value;
146 em_result_notify_ok("power: " + power);
147 return true;
148 }
149 return false;
150}
151bool RfDesenseTxTestGsm::set_afc(std::string value){
152 LOG_D(LOG_TAG,"set_afc: %s", value);
153 if(check_afc(value)){
154 afc = value;
155 em_result_notify_ok("afc: " + afc);
156 return true;
157 }
158 return false;
159}
160
161bool RfDesenseTxTestGsm::set_tsc(std::string value){
162 if(check_tsc(value)) {
163 tsc = value;
164 em_result_notify_ok("tsc: " + tsc);
165 return true;
166 }
167 return false;
168}
169
170bool RfDesenseTxTestGsm::check_channel(int index, std::string channel) {
171 std::string s;
172 if(index >= gsm_gmsk_limits.size()) {
173 s = utils::format("check_channel,index(%d) is invalid", index);
174 em_result_notify_fail(s);
175 LOG_D(LOG_TAG, "check_channel,index(%d) is invalid", index);
176 return false;
177 }
178 int value = -1;
179 try {
180 value = std::stoi(channel);
181 } catch (std::invalid_argument &err) {
182 s = utils::format("check_channel,channel(%s) is invalid, reason: %s", channel.c_str(), err.what());
183 em_result_notify_fail(s);
184 LOG_D(LOG_TAG, "check_channel,channel(%s) is invalid, reason: %s", channel.c_str(), err.what());
185 return false;
186 }
187 step = 1;
188 std::vector<std::string> limits = gsm_gmsk_limits[index];
189 min = std::stoi(limits[RfDesenseTxTestBase::CHANNEL_MIN]);
190 max = std::stoi(limits[RfDesenseTxTestBase::CHANNEL_MAX]);
191 min2 = std::stoi(limits[RfDesenseTxTestBase::CHANNEL_MIN2]);
192 max2 = std::stoi(limits[RfDesenseTxTestBase::CHANNEL_MAX2]);
193 if ((value < min || value > max) && (value < min2 || value > max2)) {
194 s = utils::format("check_channel,channel(%s) is invalid, range is [%d, %d] or [%d, %d]" , channel.c_str(), min, max, min2, max2);
195 em_result_notify_fail(s);
196 LOG_D(LOG_TAG, "check_channel,channel(%s) is invalid, range is [%d, %d] or [%d, %d]" , channel.c_str(), min, max, min2, max2);
197 return false;
198 }
199 return true;
200}
201
202bool RfDesenseTxTestGsm::check_power(int index ,std::string power) {
203 std::string s;
204 if(index >= gsm_gmsk_limits.size()) {
205 s = utils::format("check_power,index(%d) is invalid", index);
206 em_result_notify_fail(s);
207 LOG_D(LOG_TAG, "check_power,index(%d) is invalid", index);
208 return false;
209 }
210 int value = -1;
211 try {
212 value = std::stoi(power);
213 } catch (std::invalid_argument &err) {
214 s = utils::format("check_power,power(%s) is invalid, reason: %s", power.c_str(), err.what());
215 em_result_notify_fail(s);
216 LOG_D(LOG_TAG, "check_power,power(%s) is invalid, reason: %s", power.c_str(), err.what());
217 return false;
218 }
219 step = 1;
220 std::vector<std::string> limits = gsm_gmsk_limits[index];
221 min = std::stoi(limits[RfDesenseTxTestBase::POWER_MIN]);
222 max = std::stoi(limits[RfDesenseTxTestBase::POWER_MAX]);
223 if (value < min || value > max) {
224 s = utils::format("check_power,power(%s) is invalid, range is [%d, %d]" , power.c_str(), min, max);
225 em_result_notify_fail(s);
226 LOG_D(LOG_TAG, "check_power,power(%s) is invalid, range is [%d, %d]" , power.c_str(), min, max);
227 return false;
228 }
229 return true;
230}
231
232bool RfDesenseTxTestGsm::check_afc(std::string afc) {
233 std::string s;
234 int value = -1;
235 try {
236 value = std::stoi(afc);
237 } catch (std::invalid_argument &err) {
238 s = utils::format("check_afc, afc(%s) is invalid, reason: %s", afc.c_str(), err.what());
239 em_result_notify_fail(s);
240 LOG_D(LOG_TAG, "check_afc, afc(%s) is invalid, reason: %s", afc.c_str(), err.what());
241 return false;
242 }
243 if(value < 0 || value > 8191) {
244 em_result_notify_fail("check_afc,afc(%s) is invalid, range is (0,8191)");
245 LOG_D(LOG_TAG, "check_afc,afc(%s) is invalid, range is (0,8191)" , afc.c_str());
246 return false;
247 }
248 return true;
249}
250
251bool RfDesenseTxTestGsm::check_tsc(std::string tsc){
252 std::string s;
253 int value = -1;
254 try {
255 value = std::stoi(tsc);
256 } catch (std::invalid_argument &err) {
257 s = utils::format("check_tsc, tsc(%s) is invalid, reason: %s", tsc.c_str(), err.what());
258 em_result_notify_fail(s);
259 LOG_D(LOG_TAG, "check_tsc, tsc(%s) is invalid, reason: %s", tsc.c_str(), err.what());
260 return false;
261 }
262 if(value < 0 || value > 7) {
263 em_result_notify_fail("check_tsc, tsc(%s) is invalid, range is [0,7]");
264 LOG_D(LOG_TAG, "check_tsc, tsc(%s) is invalid, range is [0,7]" , tsc.c_str());
265 return false;
266 }
267 return true;
268}
269
270bool RfDesenseTxTestGsm::check_pattern(std::string pattern) {
271 int value = -1;
272 try {
273 value = std::stoi(pattern);
274 } catch (std::invalid_argument &err) {
275 LOG_D(LOG_TAG, "check_pattern, pattern(%s) is invalid, reason: %s\n", pattern.c_str(), err.what());
276 return false;
277 }
278 if(value < 0 || value > 6) {
279 LOG_D(LOG_TAG, "check_pattern, pattern(%s) is invalid, range is [0,6]\n" , pattern.c_str());
280 return false;
281 }
282 return true;
283}
284
285void RfDesenseTxTestGsm::show_default() {
286 int band_index = utils::find_index(band_values, band);
287 int pattern_index = std::stoi(pattern);
288 std::string temp = "GSM parameter: Band: " + std::string(rfdesense_gsm_band[band_index].name) +
289 ", Channel(ARFCN): " + channel + ", Power Level: " + power + ", AFC: " + afc + ", TSC: " + tsc +
290 ", PATTERN: " + std::string(rfdesense_gsm_pattern[pattern_index].name);
291 emResultNotifyWithDone(temp);
292}
293
294void RfDesenseTxTestGsm::show_channel(){
295 emResultNotifyWithDone("Channel(ARFCN): " + channel);
296}
297void RfDesenseTxTestGsm::show_power(){
298 emResultNotifyWithDone("Power Level: " + power);
299}
300void RfDesenseTxTestGsm::show_afc(){
301 emResultNotifyWithDone("AFC: " + afc);
302}
303void RfDesenseTxTestGsm::show_tsc(){
304 emResultNotifyWithDone("TSC: " + tsc);
305}