Skip to content

Commit

Permalink
log function done, google bugs to be solved
Browse files Browse the repository at this point in the history
  • Loading branch information
WanHaoRan committed Feb 24, 2024
1 parent 9123eab commit 0dd3322
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 105 deletions.
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,6 @@ if (PUSH_TO_GOOGLE)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
link_directories(${PYTHON_LIBRARY_DIR})

find_package(google_cloud_cpp_storage REQUIRED)
if(google_cloud_cpp_FOUND)
include_directories(${GOOGLE_CLOUD_CPP_INCLUDE_DIRS})
link_directories(${GOOGLE_CLOUD_CPP_LIBRARY_DIR})
endif(google_cloud_cpp_FOUND)
endif(PUSH_TO_GOOGLE)

# Backward-cpp
Expand Down Expand Up @@ -752,4 +746,7 @@ configure_file(${PROJECT_SOURCE_DIR}/nrscope/config/config.yaml
${CMAKE_CURRENT_BINARY_DIR}/nrscope/src/config.yaml)

configure_file(${PROJECT_SOURCE_DIR}/nrscope/src/tests/bigquery_table_create.py
${CMAKE_CURRENT_BINARY_DIR}/nrscope/src/tests/bigquery_table_create.py)
${CMAKE_CURRENT_BINARY_DIR}/nrscope/src/tests/bigquery_table_create.py)

configure_file(${PROJECT_SOURCE_DIR}/nrscope/src/libs/to_google.py
${CMAKE_CURRENT_BINARY_DIR}/nrscope/src/to_google.py)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sudo ./nrscope

(Feb 15, 2024) The "stop" problem on Feb 14 is solved with some optimization in SIB and RACH thread. After the decoder has all the SIBs in the cell, it skips the SIB search thread to save time. NG-Scope 5G can detect all incoming UEs (4 in the small cell) on the run and decode DCI continuously. Now wait for the Amarisoft hardware for testing.

(Feb 23, 2024) Added the local log recording function, the output log will be a .csv file and the meaning of each column is in the first row. If needed, set the `local_log` to `true` in the config.yaml and set the `log_name` with the file name.
(Feb 23, 2024) Added the local log recording function, the output log will be a .csv file and the meaning of each column is in the first row. If needed, set the `local_log` to `true` in the config.yaml and set the `log_name` with the file name. There are still some bugs in the google storage code.

## TODOs

Expand Down
4 changes: 3 additions & 1 deletion nrscope/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ usrp_setting_0:
nof_antennas: 1
scs_index: 1 #(0: 15kHz, 1: 30kHz, ..., the u in standard)
rf_log_level: "debug"

local_log: true
log_name: "/home/wanhr/Documents/data/nrscope/telemetry/a.csv"
push_to_google: false

push_to_google: true

# nof_thread: 2

Expand Down
24 changes: 24 additions & 0 deletions nrscope/hdr/nrscope_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ typedef struct _DCIFeedback{

} DCIFeedback;

typedef struct LogNode_ LogNode;
struct LogNode_{
double timestamp;
int system_frame_idx;
int slot_idx;
srsran_sch_cfg_nr_t grant;
};

struct sib1_task_element{
srsran_ue_sync_nr_outcome_t outcome;
srsran_slot_cfg_t slot;
Expand All @@ -157,6 +165,22 @@ struct dci_task_element{

};

/**
* @brief Function brought from phch_cfg_nr.c
*
* @param mapping
* @return const char*
*/
const char* sch_mapping_to_str(srsran_sch_mapping_type_t mapping);

/**
* @brief Function brought from phch_cfg_nr.c
*
* @param xoverhead
* @return const char*
*/
const char* sch_xoverhead_to_str(srsran_xoverhead_t xoverhead);

/**
* Get the UNIX timestamp for now in microsecond.
*
Expand Down
8 changes: 0 additions & 8 deletions nrscope/hdr/nrscope_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
#include "nrscope/hdr/dci_decoder.h"

namespace NRScopeLog{
typedef struct LogNode_ LogNode;
struct LogNode_{
double timestamp;
int system_frame_idx;
int slot_idx;
srsran_sch_cfg_nr_t grant;
};

/***
* ...
*
Expand Down
3 changes: 3 additions & 0 deletions nrscope/hdr/radio_nr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "nrscope/hdr/harq_tracking.h"
#include "nrscope/hdr/task_scheduler.h"
#include "nrscope/hdr/nrscope_logger.h"
#include "nrscope/hdr/to_google.h"

class Radio{
public:
Expand Down Expand Up @@ -60,6 +61,8 @@ class Radio{
// std::string ul_log_name;
bool local_log;

bool to_google;

Radio(); //constructor
~Radio(); //deconstructor

Expand Down
19 changes: 19 additions & 0 deletions nrscope/hdr/to_google.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef TO_GOOGLE_H
#define TO_GOOGLE_H

#include "nrscope/hdr/nrscope_def.h"
#include "Python.h"

namespace ToGoogle{

void init_to_google();

void push_node(LogNode input_log);

void to_google_thread();

void exit_to_google();

};

#endif
4 changes: 4 additions & 0 deletions nrscope/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ target_link_libraries(nrscope srsue_phy
${Boost_LIBRARIES}
${YAML_CPP_LIBRARIES})

if(PUSH_TO_GOOGLE)
target_link_libraries(nrscope ${PYTHON_LIBRARIES})
endif()

if(PUSH_TO_GOOGLE)
target_link_libraries(nrscope ${GOOGLE_CLOUD_CPP_STRORAGE_LIBRARIES})
endif(PUSH_TO_GOOGLE)
Expand Down
4 changes: 4 additions & 0 deletions nrscope/src/libs/load_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ int load_config(std::vector<Radio>& radios, std::string file_name){
radios[i].log_name = config_yaml[setting_name]["log_name"].as<string>();
}

if(config_yaml[setting_name]["push_to_google"]){
radios[i].to_google = config_yaml[setting_name]["push_to_google"].as<bool>();
}


// std::cout << " nof_thread: " << radios[i].nof_thread << std::endl;
}else{
Expand Down
28 changes: 28 additions & 0 deletions nrscope/src/libs/nrscope_def.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,32 @@ double get_now_timestamp_in_double(){
std::chrono::microseconds us = std::chrono::duration_cast< std::chrono::microseconds >(time);

return (double) seconds.count() + ((double) (ms.count() % 1000)/1000.0) + ((double) (us.count() % 1000000)/1000000.0);
}

const char* sch_mapping_to_str(srsran_sch_mapping_type_t mapping)
{
switch (mapping) {
case srsran_sch_mapping_type_A:
return "A";
case srsran_sch_mapping_type_B:
return "B";
default:; // Do nothing
}
return "invalid";
}

const char* sch_xoverhead_to_str(srsran_xoverhead_t xoverhead)
{
switch (xoverhead) {
case srsran_xoverhead_0:
return "0";
case srsran_xoverhead_6:
return "6";
case srsran_xoverhead_12:
return "12";
case srsran_xoverhead_18:
return "18";
default:; // Do nothing
}
return "invalid";
}
40 changes: 0 additions & 40 deletions nrscope/src/libs/nrscope_logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,6 @@ namespace NRScopeLog{
char buff[2048];
bool run_log;

/**
* @brief Function brought from phch_cfg_nr.c
*
* @param mapping
* @return const char*
*/
static const char* sch_mapping_to_str(srsran_sch_mapping_type_t mapping)
{
switch (mapping) {
case srsran_sch_mapping_type_A:
return "A";
case srsran_sch_mapping_type_B:
return "B";
default:; // Do nothing
}
return "invalid";
}

/**
* @brief Function brought from phch_cfg_nr.c
*
* @param xoverhead
* @return const char*
*/
static const char* sch_xoverhead_to_str(srsran_xoverhead_t xoverhead)
{
switch (xoverhead) {
case srsran_xoverhead_0:
return "0";
case srsran_xoverhead_6:
return "6";
case srsran_xoverhead_12:
return "12";
case srsran_xoverhead_18:
return "18";
default:; // Do nothing
}
return "invalid";
}

void init_logger(std::string filename_input){
filename = filename_input;
FILE* pFile = fopen(filename.c_str(), "a");
Expand Down
38 changes: 24 additions & 14 deletions nrscope/src/libs/radio_nr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ int Radio::RadioInitandStart(){
srsran::srsran_band_helper::sync_raster_t ss = bands.get_sync_raster(band, cs_args.ssb_scs);
srsran_assert(ss.valid(), "Invalid synchronization raster");

// Set log and uploading to google threads
if(local_log){
NRScopeLog::init_logger(log_name);
}
if(to_google){
ToGoogle::init_to_google();
}

while (not ss.end()) {
// Get SSB center frequency
cs_args.ssb_freq_hz = ss.get_frequency();
Expand Down Expand Up @@ -254,9 +262,6 @@ int Radio::SyncandDownlinkInit(){
}

int Radio::RadioCapture(){

NRScopeLog::init_logger(log_name);

if(!task_scheduler_nrscope.sib1_inited){
// std::thread sib_init_thread {&SIBsDecoder::sib_decoder_and_reception_init, &sibs_decoder, arg_scs, &task_scheduler_nrscope, rf_buffer_t.to_cf_t()};
if(sibs_decoder.sib_decoder_and_reception_init(arg_scs, &task_scheduler_nrscope, rf_buffer_t.to_cf_t()) < SRSASN_SUCCESS){
Expand Down Expand Up @@ -322,33 +327,38 @@ int Radio::RadioCapture(){
rach_thread.join();
dci_thread.join();

if((task_scheduler_nrscope.result.dl_grants.size()>0 or task_scheduler_nrscope.result.ul_grants.size()>0) and local_log){
if((task_scheduler_nrscope.result.dl_grants.size()>0 or task_scheduler_nrscope.result.ul_grants.size()>0)){
for (uint32_t i = 0; i < task_scheduler_nrscope.nof_known_rntis; i++){
std::cout << "task_scheduler_nrscope.result.dl_grants[i].grant.rnti: " << task_scheduler_nrscope.result.dl_grants[i].grant.rnti << std::endl;
std::cout << "task_scheduler_nrscope.known_rntis[i]: " << task_scheduler_nrscope.known_rntis[i] << std::endl;
if(task_scheduler_nrscope.result.dl_grants[i].grant.rnti == task_scheduler_nrscope.known_rntis[i]){
NRScopeLog::LogNode log_node;
LogNode log_node;
log_node.slot_idx = slot.idx;
log_node.system_frame_idx = outcome.sfn;
log_node.timestamp = get_now_timestamp_in_double();
log_node.grant = task_scheduler_nrscope.result.dl_grants[i];
NRScopeLog::push_node(log_node);
if(local_log){
NRScopeLog::push_node(log_node);
}
if(to_google){
ToGoogle::push_node(log_node);
}
}

std::cout << "task_scheduler_nrscope.result.dl_grants[i].grant.rnti: " << task_scheduler_nrscope.result.ul_grants[i].grant.rnti <<
" task_scheduler_nrscope.known_rntis[i]: " << task_scheduler_nrscope.known_rntis[i] << std::endl;
if(task_scheduler_nrscope.result.ul_grants[i].grant.rnti == task_scheduler_nrscope.known_rntis[i]){
NRScopeLog::LogNode log_node;
LogNode log_node;
log_node.slot_idx = slot.idx;
log_node.system_frame_idx = outcome.sfn;
log_node.timestamp = get_now_timestamp_in_double();
log_node.grant = task_scheduler_nrscope.result.ul_grants[i];
NRScopeLog::push_node(log_node);
if(local_log){
NRScopeLog::push_node(log_node);
}
if(to_google){
ToGoogle::push_node(log_node);
}
}
}
}



gettimeofday(&t1, NULL);
task_scheduler_nrscope.result.processing_time_us = t1.tv_usec - t0.tv_usec;
std::cout << "time_spend: " << (t1.tv_usec - t0.tv_usec) << "(us)" << std::endl;
Expand Down
Loading

0 comments on commit 0dd3322

Please sign in to comment.