|
| 1 | +#ifndef HAVE_LTE_TRACKER_H |
| 2 | +#define HAVE_LTE_TRACKER_H |
| 3 | + |
| 4 | +// |
| 5 | +// Data structures used to communicate between threads. |
| 6 | +// |
| 7 | +// A packet of information that is sent from the main thread to each |
| 8 | +// tracker thread. |
| 9 | +typedef struct { |
| 10 | + itpp::cvec data; |
| 11 | + uint8 slot_num; |
| 12 | + uint8 sym_num; |
| 13 | + double late; |
| 14 | + double frequency_offset; |
| 15 | + double frame_timing; |
| 16 | +} td_fifo_pdu_t; |
| 17 | +// Structure to describe a cell which is currently being tracked. |
| 18 | +class tracked_cell_t { |
| 19 | + public: |
| 20 | + // Initializer |
| 21 | + tracked_cell_t( |
| 22 | + const uint16 & n_id_cell, |
| 23 | + const int8 & n_ports, |
| 24 | + const cp_type_t::cp_type_t & cp_type, |
| 25 | + const double & frame_timing |
| 26 | + ) : n_id_cell(n_id_cell), n_ports(n_ports), cp_type(cp_type), frame_timing(frame_timing) { |
| 27 | + fifo_peak_size=0; |
| 28 | + kill_me=false; |
| 29 | + sym_num=0; |
| 30 | + slot_num=0; |
| 31 | + target_cap_start_time=(cp_type==cp_type_t::NORMAL)?10:32; |
| 32 | + filling=0; |
| 33 | + buffer.set_size(128); |
| 34 | + buffer_offset=0; |
| 35 | + ac_fd.set_size(12); |
| 36 | + ac_fd=std::complex <double> (0,0); |
| 37 | + bulk_phase_offset=0; |
| 38 | + tracker_thread_ready=false; |
| 39 | + mib_decode_failures=0; |
| 40 | + crs_sp=itpp::vec(4); |
| 41 | + crs_sp=NAN; |
| 42 | + crs_np=itpp::vec(4); |
| 43 | + crs_np=NAN; |
| 44 | + crs_sp_av=itpp::vec(4); |
| 45 | + crs_sp_av=NAN; |
| 46 | + crs_np_av=itpp::vec(4); |
| 47 | + crs_np_av=NAN; |
| 48 | + } |
| 49 | + uint8 const n_symb_dl() const { |
| 50 | + return (cp_type==cp_type_t::NORMAL)?7:((cp_type==cp_type_t::EXTENDED)?6:-1); |
| 51 | + } |
| 52 | + boost::mutex mutex; |
| 53 | + boost::condition condition; |
| 54 | + boost::thread thread; |
| 55 | + // Indicates that the tracker process is ready to receive data. |
| 56 | + bool tracker_thread_ready; |
| 57 | + // These are not allowed to change |
| 58 | + const uint16 n_id_cell; |
| 59 | + const int8 n_ports; |
| 60 | + const cp_type_t::cp_type_t cp_type; |
| 61 | + // These are constantly changing |
| 62 | + double frame_timing; |
| 63 | + std::queue <td_fifo_pdu_t> fifo; |
| 64 | + uint32 fifo_peak_size; |
| 65 | + bool kill_me; |
| 66 | + // Calculated values returned by the cell tracker process. |
| 67 | + // Changing constantly. |
| 68 | + itpp::cvec ac_fd; |
| 69 | + // Tracker process uses these as local variables. |
| 70 | + double bulk_phase_offset; |
| 71 | + // The producer process (main) will use these members as |
| 72 | + // local variables... |
| 73 | + uint8 sym_num; |
| 74 | + uint8 slot_num; |
| 75 | + uint32 target_cap_start_time; |
| 76 | + double late; |
| 77 | + bool filling; |
| 78 | + itpp::cvec buffer; |
| 79 | + uint16 buffer_offset; |
| 80 | + double mib_decode_failures; |
| 81 | + itpp::vec crs_sp; |
| 82 | + itpp::vec crs_np; |
| 83 | + itpp::vec crs_sp_av; |
| 84 | + itpp::vec crs_np_av; |
| 85 | + private: |
| 86 | +}; |
| 87 | +// Structure that is used to record all the tracked cells. |
| 88 | +typedef struct { |
| 89 | + // List of cells which are currently being tracked. |
| 90 | + // Only the searcher can add elements to this list. |
| 91 | + // Only the main thread can remove elements from this list. |
| 92 | + boost::mutex mutex; |
| 93 | + std::list <tracked_cell_t *> tracked_cells; |
| 94 | +} tracked_cell_list_t; |
| 95 | +// Global data shared by all threads |
| 96 | +typedef struct { |
| 97 | + // The frequency offset of the dongle. This value will be updated |
| 98 | + // continuously. |
| 99 | + boost::mutex frequency_offset_mutex; |
| 100 | + double frequency_offset; |
| 101 | + // This value will never change. |
| 102 | + double fc; |
| 103 | +} global_thread_data_t; |
| 104 | +// IPC between main thread and searcher thread covering data capture issues. |
| 105 | +typedef struct { |
| 106 | + boost::mutex mutex; |
| 107 | + boost::condition condition; |
| 108 | + bool request; |
| 109 | + itpp::cvec capbuf; |
| 110 | + double late; |
| 111 | +} capbuf_sync_t; |
| 112 | +// IPC between main thread and producer thread. |
| 113 | +typedef struct { |
| 114 | + boost::mutex mutex; |
| 115 | + boost::condition condition; |
| 116 | + std::deque <uint8> fifo; |
| 117 | + uint32 fifo_peak_size; |
| 118 | +} sampbuf_sync_t; |
| 119 | + |
| 120 | +// Small helper function to increment the slot number and the symbol number. |
| 121 | +inline void slot_sym_inc( |
| 122 | + const uint8 n_symb_dl, |
| 123 | + uint8 & slot_num, |
| 124 | + uint8 & sym_num |
| 125 | +) { |
| 126 | + sym_num=itpp::mod(sym_num+1,n_symb_dl); |
| 127 | + if (sym_num==0) |
| 128 | + slot_num=itpp::mod(slot_num+1,20); |
| 129 | +} |
| 130 | + |
| 131 | +void producer_thread( |
| 132 | + sampbuf_sync_t & sampbuf_sync, |
| 133 | + capbuf_sync_t & capbuf_sync, |
| 134 | + global_thread_data_t & global_thread_data, |
| 135 | + tracked_cell_list_t & tracked_cell_list, |
| 136 | + double & fc |
| 137 | +); |
| 138 | + |
| 139 | +void tracker_thread( |
| 140 | + tracked_cell_t & tracked_cell, |
| 141 | + global_thread_data_t & global_thread_data |
| 142 | +); |
| 143 | + |
| 144 | +void searcher_thread( |
| 145 | + capbuf_sync_t & capbuf_sync, |
| 146 | + global_thread_data_t & global_thread_data, |
| 147 | + tracked_cell_list_t & tracked_cell_list |
| 148 | +); |
| 149 | + |
| 150 | +void display_thread( |
| 151 | + sampbuf_sync_t & sampbuf_sync, |
| 152 | + global_thread_data_t & global_thread_data, |
| 153 | + tracked_cell_list_t & tracked_cell_list |
| 154 | +); |
| 155 | + |
| 156 | +#endif |
| 157 | + |
0 commit comments