| 150 | |
| 151 | |
| 152 | void SDRPostThread::run() { |
| 153 | #ifdef __APPLE__ |
| 154 | pthread_t tID = pthread_self(); // ID of this thread |
| 155 | int priority = sched_get_priority_max( SCHED_FIFO); |
| 156 | sched_param prio = {priority}; // scheduling priority of thread |
| 157 | pthread_setschedparam(tID, SCHED_FIFO, &prio); |
| 158 | #endif |
| 159 | |
| 160 | // std::cout << "SDR post-processing thread started.." << std::endl; |
| 161 | |
| 162 | iqDataInQueue = std::static_pointer_cast<SDRThreadIQDataQueue>(getInputQueue("IQDataInput")); |
| 163 | iqDataOutQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQDataOutput")); |
| 164 | iqVisualQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQVisualDataOutput")); |
| 165 | iqActiveDemodVisualQueue = std::static_pointer_cast<DemodulatorThreadInputQueue>(getOutputQueue("IQActiveDemodVisualDataOutput")); |
| 166 | |
| 167 | while (!stopping) { |
| 168 | SDRThreadIQDataPtr data_in; |
| 169 | |
| 170 | if (!iqDataInQueue->pop(data_in, HEARTBEAT_CHECK_PERIOD_MICROS)) { |
| 171 | continue; |
| 172 | } |
| 173 | |
| 174 | bool doUpdate = false; |
| 175 | |
| 176 | if (data_in && !data_in->data.empty()) { |
| 177 | |
| 178 | if(data_in->numChannels > 1) { |
| 179 | if (chanMode == 1) { |
| 180 | runPFBCH(data_in.get()); |
| 181 | } else if (chanMode == 2) { |
| 182 | runPFBCH2(data_in.get()); |
| 183 | } |
| 184 | } else { |
| 185 | runSingleCH(data_in.get()); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | for (const auto& demod : runDemods) { |
| 190 | if (abs(frequency - demod->getFrequency()) > (sampleRate / 2)) { |
| 191 | doUpdate = true; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | //Only update the list of demodulators here |
| 196 | if (doUpdate || doRefresh.load()) { |
| 197 | updateActiveDemodulators(); |
| 198 | doRefresh.store(false); |
| 199 | } |
| 200 | } //end while |
| 201 | |
| 202 | //Be safe, remove as many elements as possible |
| 203 | iqVisualQueue->flush(); |
| 204 | iqDataInQueue->flush(); |
| 205 | iqDataOutQueue->flush(); |
| 206 | iqActiveDemodVisualQueue->flush(); |
| 207 | |
| 208 | // std::cout << "SDR post-processing thread done." << std::endl; |
| 209 | } |