/** * RIL_UNSOL_SIGNAL_STRENGTH * * Radio may report signal strength rather than have it polled. * * "data" is a const RIL_SignalStrength * */ void pollSignalStrength(void *arg) { RIL_SignalStrength_v6 signalStrength; (void) arg; if (getSignalStrength(&signalStrength) < 0) LOGE("%s() Polling the signal strength failed", __func__); else RIL_onUnsolicitedResponse(RIL_UNSOL_SIGNAL_STRENGTH, &signalStrength, sizeof(RIL_SignalStrength_v6)); }
/** * RIL_REQUEST_SIGNAL_STRENGTH * * Requests current signal strength and bit error rate. * * Must succeed if radio is on. */ void requestSignalStrength(void *data, size_t datalen, RIL_Token t) { (void) data; (void) datalen; RIL_SignalStrength_v6 signalStrength; if (getSignalStrength(&signalStrength) < 0) { LOGE("%s() Must never return an error when radio is on", __func__); RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); } else RIL_onRequestComplete(t, RIL_E_SUCCESS, &signalStrength, sizeof(RIL_SignalStrength_v6)); }
/* * This thread performs a scan operation based on the scanDirection value. * * scanDirection = 0: scan forward continuously, pausing at each found station * scanDirection = 1: scan forward until a station is found * scanDirection = -1: scan backward until a station is found */ void RadioWidget::run() { threadRunning = TRUE; int signal = 0; // loop while no station found or the mode is 'continuous scan' while ((signal <= 0) || (scanDirection == 0)) { if (scanDirection >= 0) { frequency = frequency + 0.2; if (frequency > 107.9) frequency = 87.9; } else { frequency = frequency - 0.2; if (frequency < 87.9) frequency = 107.9; } setFrequency(frequency); // don't know why, but lcd must be told to repaint to show the freq. QThread::postEvent( lcd, new QPaintEvent( QRect(0, 0, 580, 300) ) ); // check it thread cancel was requested if (threadRunning == FALSE) break; // pause is necessary for a correct reading of the signal strength QThread::msleep(200); signal = getSignalStrength(); // if in 'continuous scan' mode and station pause, stay here for 3 sec. if ((scanDirection == 0) && (signal > 0)) QThread::sleep(3); // check again to see if thread cancel was requested if (threadRunning == FALSE) break; } // untoggle all the control buttons scan->untoggle(); scanForward->untoggle(); scanBackward->untoggle(); threadRunning = FALSE; }
int initCellModem(Serial *serial) { size_t success = 0; size_t attempts = 0; g_cellmodem_status = CELLMODEM_STATUS_NOT_INIT; while (!success && attempts++ < 3) { closeNet(serial); if (attempts > 1) { pr_debug("SIM900: power cycling\r\n"); if (sendCommandOK(serial, "AT\r") == 1 && attempts > 1) { pr_debug("SIM900: powering down\r\n"); powerCycleCellModem(); } powerCycleCellModem(); } if (sendCommandRetry(serial, "ATZ\r", "OK", 2, 2) != 1) continue; if (sendCommandRetry(serial, "ATE0\r", "OK", 2, 2) != 1) continue; sendCommand(serial, "AT+CIPSHUT\r", "OK"); if (isNetworkConnected(serial, 60, 3) != 1) continue; getSignalStrength(serial); read_subscriber_number(serial); read_IMEI(serial); if (isDataReady(serial, 30, 2) != 1) continue; success = 1; } if ( success ) { g_cellmodem_status = CELLMODEM_STATUS_PROVISIONED; return 0; } else { g_cellmodem_status = CELLMODEM_STATUS_NO_NETWORK; return -1; } }
int Smabluetooth::connect() { disconnect(); //start thread quit.store(false); thread = std::thread([this] { worker_thread(); }); LOG(Info) << "Connecting to device!"; UniqueLock lock(mutex); //Wait until we get list of all devices while (state != STATE_DEVICE_LIST) { if (state == STATE_ERROR) { quit.store(true); thread.join(); state = STATE_NOT_CONNECTED; return -1; } if (event.wait_for(lock, std::chrono::seconds(5)) == std::cv_status::timeout) { LOG(Error) << "Connection timeout!"; quit.store(true); thread.join(); state = STATE_NOT_CONNECTED; return -1; } } state = STATE_CONNECTED; lock.unlock(); LOG(Info) << "Connected to device!"; int signalStrength = getSignalStrength(mac_inv); LOG(Info) <<"Signal strength: " << signalStrength; return 0; }