diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h index 4ec7128d4..13bcc2f08 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/mac.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/mac.h @@ -60,7 +60,6 @@ class mac : public timer_callback { public: mac() : timers_db((uint32_t) NOF_MAC_TIMERS), tr_end_time(1024*10), tr_start_time(1024*10) {started=false;} - ~mac(); bool init(phy *phy_h, tti_sync *ttisync, log *log_h, bool pcap_=false); void stop(); int get_tti(); diff --git a/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h b/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h index e27d66603..89ea4a9af 100644 --- a/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h +++ b/srsapps/ue/mac/include/srsapps/ue/mac/pdu.h @@ -229,7 +229,8 @@ private: bool F_bit; uint8_t ce_payload[MAX_CE_PAYLOAD_LEN*8]; uint32_t sizeof_ce(uint32_t lcid, bool is_ul); - uint8_t buff_size_table(uint32_t buffer_size); + uint8_t buff_size_table(uint32_t buffer_size); + }; class sch_pdu : public pdu @@ -250,6 +251,9 @@ public: bool update_space_sdu(uint32_t nbytes); bool update_space_sdu(uint32_t nbytes, bool is_first); void fprint(FILE *stream); +private: + uint8_t pdu_pcap_tmp[1024*64]; + }; diff --git a/srsapps/ue/mac/src/mac.cc b/srsapps/ue/mac/src/mac.cc index e9b8b0ae0..ca3bf6ad8 100644 --- a/srsapps/ue/mac/src/mac.cc +++ b/srsapps/ue/mac/src/mac.cc @@ -40,13 +40,6 @@ namespace srslte { namespace ue { -mac::~mac() -{ - if(pcap && pcap_file) { - MAC_LTE_PCAP_Close(pcap_file); - } -} - bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_, bool pcap_) { started = false; @@ -83,6 +76,10 @@ bool mac::init(phy *phy_h_, tti_sync* ttisync_, log* log_h_, bool pcap_) void mac::stop() { + if (pcap && pcap_file) { + MAC_LTE_PCAP_Close(pcap_file); + printf("Closing MAC PCAP file\n"); + } started = false; pthread_join(mac_thread, NULL); } @@ -159,7 +156,7 @@ void* mac::mac_thread_fnc(void *arg) { void mac::main_radio_loop() { setup_timers(); - while(1) { + while(started) { if (!is_synchronized) { srslte_cell_t cell; uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN]; diff --git a/srsapps/ue/mac/src/pdu.cc b/srsapps/ue/mac/src/pdu.cc index d4ef9adc0..d30a803a6 100644 --- a/srsapps/ue/mac/src/pdu.cc +++ b/srsapps/ue/mac/src/pdu.cc @@ -100,7 +100,8 @@ void sch_pdu::parse_packet(uint8_t *ptr, FILE *pcap_file) 4 /* Subframe number */ }; - MAC_LTE_PCAP_WritePDU(pcap_file, &context, ptr, pdu_len); + srslte_bit_unpack_vector(ptr, pdu_pcap_tmp, pdu_len*8); + MAC_LTE_PCAP_WritePDU(pcap_file, &context, pdu_pcap_tmp, pdu_len); fprintf(stdout, "Wrote DL MAC PDU, len=%d\n", pdu_len); } @@ -202,7 +203,8 @@ bool sch_pdu::write_packet(uint8_t* ptr, FILE *pcap_file) 4 /* Subframe number */ }; - MAC_LTE_PCAP_WritePDU(pcap_file, &context, init_ptr, pdu_len); + srslte_bit_unpack_vector(init_ptr, pdu_pcap_tmp, pdu_len*8); + MAC_LTE_PCAP_WritePDU(pcap_file, &context, pdu_pcap_tmp, pdu_len); fprintf(stdout, "Wrote UL MAC PDU, len=%d\n", pdu_len); } } diff --git a/srsapps/ue/mac/test/mac_test.cc b/srsapps/ue/mac/test/mac_test.cc index f614d7c25..690ab8ebd 100644 --- a/srsapps/ue/mac/test/mac_test.cc +++ b/srsapps/ue/mac/test/mac_test.cc @@ -307,19 +307,23 @@ uint8_t reply[2] = {0x00, 0x04}; srslte::radio_uhd radio_uhd; srslte::ue::phy phy; srslte::ue::mac mac; + +prog_args_t prog_args; void sig_int_handler(int signo) { - //radio_uhd.write_trace("radio"); - phy.write_trace("phy"); - mac.write_trace("mac"); + if (prog_args.do_trace) { + //radio_uhd.write_trace("radio"); + phy.write_trace("phy"); + mac.write_trace("mac"); + } + mac.stop(); exit(0); } int main(int argc, char *argv[]) { - prog_args_t prog_args; srslte::ue::tti_sync_cv ttisync(10240); srslte::log_stdout mac_log("MAC"), phy_log("PHY"); @@ -336,9 +340,9 @@ int main(int argc, char *argv[]) break; } + // Capture SIGINT to write traces + signal(SIGINT, sig_int_handler); if (prog_args.do_trace) { - // Capture SIGINT to write traces - signal(SIGINT, sig_int_handler); //radio_uhd.start_trace(); phy.start_trace(); mac.start_trace(); @@ -356,7 +360,7 @@ int main(int argc, char *argv[]) phy.init_agc(&radio_uhd, &ttisync, &phy_log); } // Init MAC - mac.init(&phy, &ttisync, &mac_log); + mac.init(&phy, &ttisync, &mac_log, true); // Set RX freq radio_uhd.set_rx_freq(prog_args.uhd_rx_freq);