xj | de81d1d | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | #include "rfAutomaticTest.h" |
| 2 | #include<common.h> |
| 3 | /* |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | #include "gps/gps_test.h" |
| 8 | #ifdef __cplusplus |
| 9 | } |
| 10 | #endif |
| 11 | */ |
| 12 | #include <log/log.h> |
| 13 | #include "libtel/lynq_call.h" |
| 14 | #include "libtel/lynq_sim.h" |
| 15 | #undef LOG_TAG |
| 16 | #define LOG_TAG "Factory_RfAutomaticTxTest" |
| 17 | //extern void get_gps_test(); |
| 18 | //extern C lynq_get_sim_status(); |
| 19 | const int RfAutomaticTest::MSG_TELE = 3; |
| 20 | const int RfAutomaticTest::MSG_GPS = 2; |
| 21 | const int RfAutomaticTest::MSG_SIM = 1; |
| 22 | const int RfAutomaticTest::MSG_NULL = 0; |
| 23 | |
| 24 | RfAutomaticTest* RfAutomaticTest::m_instance = NULL; |
| 25 | std::mutex RfAutomaticTest::mMutex; |
| 26 | // Method implements of RequestHandleThread |
| 27 | RfAutomaticTest::RequestHandleThread::RequestHandleThread(RfAutomaticTest* tx) : m_looper(NULL) { |
| 28 | mTx = tx; |
| 29 | RLOGD( "RequestHandleThread created"); |
| 30 | } |
| 31 | |
| 32 | RfAutomaticTest::RequestHandleThread::~RequestHandleThread() { |
| 33 | mTx = NULL; |
| 34 | RLOGD( "RequestHandleThread destroyed"); |
| 35 | } |
| 36 | RfAutomaticTest::RfRequestMessage::RfRequestMessage(RfAutomaticTest* tx) : mTx(tx),mMsgType(0), |
| 37 | response(""),responselen(0), slot(0), e(ERROR) { |
| 38 | } |
| 39 | |
| 40 | RfAutomaticTest::RfRequestMessage::~RfRequestMessage() { |
| 41 | RLOGD( "RequestHandleThread destroyed"); |
| 42 | } |
| 43 | |
| 44 | void RfAutomaticTest::RfRequestHandler::handleMessage(const Message& message) { |
| 45 | RLOGD( "handleMessage msg->mMsgType: %d", mMsg->mMsgType); |
| 46 | if(mTx != NULL) { |
| 47 | mTx->factory_test_onebyone(mMsg); |
| 48 | } else { |
| 49 | RLOGD( "handleMessage mTx is null"); |
| 50 | } |
| 51 | } |
| 52 | void RfAutomaticTest::factory_test_onebyone(sp<RfRequestMessage> msg){ |
| 53 | RLOGD( "FactoryTestOneByOne, type: %d,slot:%d,auto_reqId:%d", msg->mMsgType,msg->slot,auto_reqId); |
| 54 | int responselen = msg->responselen; |
| 55 | std::string response = msg->response; |
| 56 | if(msg->slot != 0){ |
| 57 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 58 | if(msg->slot == auto_reqId){ |
| 59 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 60 | switch (msg->mMsgType) { |
| 61 | // case MSG_NULL: { |
| 62 | // mCurrentFlag = MSG_SIM; |
| 63 | // auto_reqId = lynq_get_sim_status(); |
| 64 | // } |
| 65 | case MSG_SIM: { |
| 66 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 67 | |
| 68 | if(msg->e == SUCCESS){ |
| 69 | mFactoryResult[0] = 1; |
| 70 | }else{ |
| 71 | mFactoryResult[0] = 0; |
| 72 | mFactoryResult[1] = 0; |
| 73 | mCurrentFlag = MSG_GPS; |
| 74 | // get_gps_test(); |
| 75 | break; |
| 76 | } |
| 77 | mCurrentFlag = MSG_TELE; |
| 78 | // auto_reqId = get_call(); |
| 79 | auto_reqId = 88; |
| 80 | RLOGD( "get_call,auto_reqId:%d",auto_reqId); |
| 81 | break; |
| 82 | } |
| 83 | case MSG_TELE:{ |
| 84 | if(msg->e == SUCCESS){ |
| 85 | mFactoryResult[1] = 1; |
| 86 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 87 | }else{ |
| 88 | mFactoryResult[1] = 0; |
| 89 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 90 | |
| 91 | } |
| 92 | mCurrentFlag = MSG_GPS; |
| 93 | // get_gps_test(); |
| 94 | break ; |
| 95 | } |
| 96 | default: |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | }else if(msg->mMsgType == MSG_NULL ){ |
| 101 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 102 | mCurrentFlag = MSG_SIM; |
| 103 | auto_reqId = 99; |
| 104 | //auto_reqId = lynq_get_sim_status(); |
| 105 | RLOGD( "lynq_get_sim_status,auto_reqId:%d",auto_reqId); |
| 106 | |
| 107 | } |
| 108 | else if(MSG_GPS == msg->mMsgType){ |
| 109 | int i; |
| 110 | RLOGD("%s, %s, %d", __FILE__, __FUNCTION__, __LINE__); |
| 111 | |
| 112 | if(msg->e == SUCCESS){ |
| 113 | mFactoryResult[2] = 1; |
| 114 | }else{ |
| 115 | mFactoryResult[2] = 0; |
| 116 | } |
| 117 | mCurrentFlag = 0; |
| 118 | for(i = 0; i<3;i++){ |
| 119 | RLOGD("mFactoryResult[%d]:%d",i,mFactoryResult[i]); |
| 120 | } |
| 121 | unregister_factory_auto_hook_raw(); |
| 122 | }else{ |
| 123 | RLOGE("Error11111,Unknown location"); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | sp<RfAutomaticTest::RfRequestHandler> RfAutomaticTest::sendMessage(sp<RfRequestMessage> msg, int delayms) { |
| 128 | RLOGD( "sendMessage msg token=%d delayms=%d", msg->mMsgType, delayms); |
| 129 | sp<RfRequestHandler> handler = new RfRequestHandler(this); |
| 130 | handler->mMsg = msg; |
| 131 | if(mRequestHandleThread.get()) { |
| 132 | sp<Looper> looper = mRequestHandleThread->getLooper(); |
| 133 | if(looper.get()) { |
| 134 | if (delayms > 0) { |
| 135 | looper->sendMessageDelayed(ms2ns(delayms),handler, handler->m_dummyMsg); |
| 136 | } else { |
| 137 | looper->sendMessage(handler, handler->m_dummyMsg); |
| 138 | } |
| 139 | } else { |
| 140 | RLOGD( "looper fail"); |
| 141 | } |
| 142 | } else { |
| 143 | RLOGD( "mRequestHandleThread fail"); |
| 144 | } |
| 145 | |
| 146 | return handler; |
| 147 | } |
| 148 | |
| 149 | RfAutomaticTest::RfRequestHandler:: ~RfRequestHandler() { |
| 150 | mTx = NULL; |
| 151 | RLOGD( "RfRequestHandler destroyed"); |
| 152 | } |
| 153 | |
| 154 | bool RfAutomaticTest::RequestHandleThread::threadLoop() { |
| 155 | RLOGD( "RequestHandleThread threadLoop"); |
| 156 | // start message loop |
| 157 | m_looper = Looper::prepare(0); |
| 158 | int result; |
| 159 | do { |
| 160 | result = m_looper->pollAll(-1); |
| 161 | RLOGD( "RequestHandleThread threadLoop, pull message result = %d", result); |
| 162 | } while (result == Looper::POLL_WAKE || result == Looper::POLL_CALLBACK); |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | sp<Looper> RfAutomaticTest::RequestHandleThread::getLooper() { |
| 167 | return m_looper; |
| 168 | } |
| 169 | RfAutomaticTest::RfAutomaticTest(): mCurrentFlag(0) { |
| 170 | |
| 171 | } |
| 172 | |
| 173 | RfAutomaticTest::~RfAutomaticTest() { |
| 174 | RLOGD("RfDesenseTxTest destroyed"); |
| 175 | } |
| 176 | |
| 177 | void RfAutomaticTest::handle_request(string response,int responselen,int slot, RIL_Errcode e) { |
| 178 | sp<RfRequestMessage> msg = new RfRequestMessage(this); |
| 179 | RLOGD("RfDesenseTxTest handle_request"); |
| 180 | msg->mMsgType = mCurrentFlag; |
| 181 | msg->response = response; |
| 182 | msg->responselen = responselen; |
| 183 | msg->slot = slot; |
| 184 | msg->e = e; |
| 185 | sendMessage(msg, 1000); |
| 186 | } |
| 187 | void RfAutomaticTest::init() { |
| 188 | register_factory_auto_hook_raw(m_instance); |
| 189 | mRequestHandleThread = new RequestHandleThread(this); |
| 190 | mRequestHandleThread->run(); |
| 191 | } |
| 192 | RfAutomaticTest* RfAutomaticTest::getInstance() { |
| 193 | if(!m_instance) { |
| 194 | mMutex.lock(); |
| 195 | if(!m_instance) { |
| 196 | m_instance = new RfAutomaticTest(); |
| 197 | m_instance->init(); |
| 198 | } |
| 199 | mMutex.unlock(); |
| 200 | } |
| 201 | return m_instance; |
| 202 | } |