rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* 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 | |
| 36 | #include <algorithm> |
| 37 | #include <iterator> |
| 38 | #include <stdexcept> |
| 39 | |
| 40 | #include "rfdesense/RfDesenseTxTestCdma.h" |
| 41 | #include "rfdesense/RfDesenseTxTestBase.h" |
| 42 | #include "util/log_extra.h" |
| 43 | #include "em.h" |
| 44 | |
| 45 | #undef LOG_TAG |
| 46 | #define LOG_TAG "EM_RfDesenseTxTestCdma" |
| 47 | |
| 48 | const int RfDesenseTxTestCdma::INDEX_BAND = 0; |
| 49 | const int RfDesenseTxTestCdma::INDEX_CHANNEL = 1; |
| 50 | const int RfDesenseTxTestCdma::INDEX_POWER = 2; |
| 51 | const int RfDesenseTxTestCdma::INDEX_MODULATION = 3; |
| 52 | std::string RfDesenseTxTestCdma::band = ""; |
| 53 | std::string RfDesenseTxTestCdma::channel = ""; |
| 54 | std::string RfDesenseTxTestCdma::power = ""; |
| 55 | std::string RfDesenseTxTestCdma::modulation = ""; |
| 56 | std::map<int, std::string> RfDesenseTxTestCdma::evdo_values = {{INDEX_BAND, "0"},{INDEX_CHANNEL, "384"},{INDEX_POWER, "23"}, {INDEX_MODULATION, "1"}}; |
| 57 | std::map<int, std::string> RfDesenseTxTestCdma::cdma_1x_values = {{INDEX_BAND, "0"},{INDEX_CHANNEL, "384"},{INDEX_POWER, "23"}, {INDEX_MODULATION, "0"}}; |
| 58 | |
| 59 | RfDesenseTxTestCdma::RfDesenseTxTestCdma(int type) { |
| 60 | modem_type = type; |
| 61 | std::map<int, std::string> tmp; |
| 62 | switch(modem_type){ |
| 63 | case utils::MODEM_CDMA_EVDO:{ |
| 64 | tmp = evdo_values; |
| 65 | break; |
| 66 | } |
| 67 | case utils::MODEM_CDMA_1X:{ |
| 68 | tmp = cdma_1x_values; |
| 69 | break; |
| 70 | } |
| 71 | default: |
| 72 | break; |
| 73 | } |
| 74 | if(!tmp.empty()) { |
| 75 | band = tmp[INDEX_BAND]; |
| 76 | channel = tmp[INDEX_CHANNEL]; |
| 77 | power = tmp [INDEX_POWER]; |
| 78 | modulation = tmp[INDEX_MODULATION]; |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | void RfDesenseTxTestCdma::show_default() { |
| 84 | std::string str; |
| 85 | int index = std::stoi(band); |
| 86 | std::string modem; |
| 87 | if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 88 | modem = "CDMA(EVDO) "; |
| 89 | } else if(modem_type == utils::MODEM_CDMA_1X){ |
| 90 | modem = "CDMA(1X) "; |
| 91 | } |
| 92 | str = modem + "parameters: Band: " |
| 93 | + std::string(rfdesense_cdma_band[index].name) |
| 94 | + ", modulation: " |
| 95 | + (std::stoi(modulation) == 0 ? |
| 96 | std::string("1x") : std::string("EVDO")) |
| 97 | + ", Channel(ARFCN): " + channel + ", Power Level(dBm): " + power; |
| 98 | emResultNotifyWithDone(str); |
| 99 | } |
| 100 | |
| 101 | RfDesenseTxTestCdma::~RfDesenseTxTestCdma() { |
| 102 | // TODO Auto-generated destructor stub |
| 103 | } |
| 104 | std::string RfDesenseTxTestCdma::modemTypeToString(int type) { |
| 105 | switch(modem_type){ |
| 106 | case utils::MODEM_CDMA_EVDO: |
| 107 | return "CDMA(EVD)"; |
| 108 | case utils::MODEM_CDMA_1X: |
| 109 | return "CDMA(1X)"; |
| 110 | default: |
| 111 | return "UNKNOWN"; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | std::string RfDesenseTxTestCdma::get_command(){ |
| 116 | int tx_power = 0; |
| 117 | if (!power.empty()) { |
| 118 | tx_power = std::stoi(power) + 60; |
| 119 | } |
| 120 | |
| 121 | if (modem_type == utils::MODEM_CDMA_1X) { |
| 122 | command = "AT+ECRFTX=1," + channel + "," + band + "," |
| 123 | + std::to_string(tx_power) |
| 124 | + "," |
| 125 | + (modulation == "1" ? "0" : "1"); |
| 126 | } else if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 127 | command = "AT+ERFTX=13,4," + channel + "," + band + "," |
| 128 | + std::to_string(tx_power); |
| 129 | } |
| 130 | return command; |
| 131 | } |
| 132 | |
| 133 | std::string RfDesenseTxTestCdma::get_band(){ |
| 134 | return band; |
| 135 | } |
| 136 | |
| 137 | std::string RfDesenseTxTestCdma::get_power(){ |
| 138 | return power; |
| 139 | } |
| 140 | |
| 141 | bool RfDesenseTxTestCdma::set_band(int value){ |
| 142 | std::string s; |
| 143 | if(value < 0 || value > 15) { |
| 144 | s = utils::format("band(%d) is out of range", value); |
| 145 | em_result_notify_fail(s); |
| 146 | LOG_D(LOG_TAG, "band(%d) is out of range", value); |
| 147 | return false; |
| 148 | } |
| 149 | band = std::to_string(value); |
| 150 | if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 151 | evdo_values[INDEX_BAND] = band; |
| 152 | } else if(modem_type == utils::MODEM_CDMA_1X) { |
| 153 | cdma_1x_values[INDEX_BAND] = band; |
| 154 | } else { |
| 155 | s = utils::format("modem(%s) is invalid", modemTypeToString(modem_type)); |
| 156 | em_result_notify_fail(s); |
| 157 | LOG_D(LOG_TAG, "modem(%s) is invalid", modemTypeToString(modem_type)); |
| 158 | return false; |
| 159 | } |
| 160 | em_result_notify_ok("band: " + std::string(rfdesense_cdma_band[value].name)); |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | bool RfDesenseTxTestCdma::set_modulation(int value){ |
| 165 | if (value != 0 && value != 1) { |
| 166 | LOG_D(LOG_TAG, "set_modulation value(%d) is out of range",value); |
| 167 | return false; |
| 168 | } |
| 169 | modulation = std::to_string(value); |
| 170 | if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 171 | evdo_values[INDEX_MODULATION] = modulation; |
| 172 | } else if(modem_type == utils::MODEM_CDMA_1X) { |
| 173 | cdma_1x_values[INDEX_MODULATION] = modulation; |
| 174 | } else { |
| 175 | std::string s; |
| 176 | s = utils::format("modem(%s) is invalid", modemTypeToString(modem_type)); |
| 177 | em_result_notify_fail(s); |
| 178 | LOG_D(LOG_TAG, "modem(%s) is invalid", modemTypeToString(modem_type)); |
| 179 | return false; |
| 180 | } |
| 181 | em_result_notify_ok("modulation: " + (value == 0 ?std::string("1x") : std::string("EVDO"))); |
| 182 | return true; |
| 183 | } |
| 184 | |
| 185 | bool RfDesenseTxTestCdma::set_channel(std::string str){ |
| 186 | channel = str; |
| 187 | if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 188 | evdo_values[INDEX_CHANNEL] = channel; |
| 189 | } else if(modem_type == utils::MODEM_CDMA_1X) { |
| 190 | cdma_1x_values[INDEX_CHANNEL] = channel; |
| 191 | } else { |
| 192 | std::string s; |
| 193 | s = utils::format("modem(%s) is invalid", modemTypeToString(modem_type)); |
| 194 | em_result_notify_fail(s); |
| 195 | LOG_D(LOG_TAG, "modem(%s) is invalid", modemTypeToString(modem_type)); |
| 196 | return false; |
| 197 | } |
| 198 | em_result_notify_ok("channel: " + channel); |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | bool RfDesenseTxTestCdma::set_power(std::string str){ |
| 203 | power = str; |
| 204 | if(modem_type == utils::MODEM_CDMA_EVDO) { |
| 205 | evdo_values[INDEX_POWER] = power; |
| 206 | } else if(modem_type == utils::MODEM_CDMA_1X) { |
| 207 | cdma_1x_values[INDEX_POWER] = power; |
| 208 | } else { |
| 209 | std::string s; |
| 210 | s = utils::format("modem(%s) is invalid", modemTypeToString(modem_type)); |
| 211 | em_result_notify_fail(s); |
| 212 | LOG_D(LOG_TAG, "modem(%s) is invalid", modemTypeToString(modem_type)); |
| 213 | return false; |
| 214 | } |
| 215 | em_result_notify_ok("power: " + power); |
| 216 | return true; |
| 217 | } |
| 218 | |
| 219 | void RfDesenseTxTestCdma::show_channel(){ |
| 220 | emResultNotifyWithDone("Channel(ARFCN): " + channel); |
| 221 | } |
| 222 | |
| 223 | void RfDesenseTxTestCdma::show_power(){ |
| 224 | emResultNotifyWithDone("Power level(dBm): " + power); |
| 225 | } |