From 0dd3322aec198a25be8d5e09442b87bd65f0f7ca Mon Sep 17 00:00:00 2001 From: Haoran Wan Date: Fri, 23 Feb 2024 21:04:21 -0500 Subject: [PATCH] log function done, google bugs to be solved --- CMakeLists.txt | 11 +- README.md | 2 +- nrscope/config/config.yaml | 4 +- nrscope/hdr/nrscope_def.h | 24 ++++ nrscope/hdr/nrscope_logger.h | 8 -- nrscope/hdr/radio_nr.h | 3 + nrscope/hdr/to_google.h | 19 +++ nrscope/src/CMakeLists.txt | 4 + nrscope/src/libs/load_config.cc | 4 + nrscope/src/libs/nrscope_def.cc | 28 ++++ nrscope/src/libs/nrscope_logger.cc | 40 ------ nrscope/src/libs/radio_nr.cc | 38 +++-- nrscope/src/libs/to_google.cc | 153 +++++++++++++++++++++ nrscope/src/libs/to_google.py | 81 +++++++++++ nrscope/src/tests/CMakeLists.txt | 1 - nrscope/src/tests/bigquery_table_create.py | 35 +---- nrscope/src/tests/google_client_cc_test.cc | 2 +- 17 files changed, 352 insertions(+), 105 deletions(-) create mode 100644 nrscope/hdr/to_google.h create mode 100644 nrscope/src/libs/to_google.cc create mode 100644 nrscope/src/libs/to_google.py diff --git a/CMakeLists.txt b/CMakeLists.txt index f15ac439..9c445c28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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) \ No newline at end of file +${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) \ No newline at end of file diff --git a/README.md b/README.md index 01edd0ab..f8525486 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/nrscope/config/config.yaml b/nrscope/config/config.yaml index f82f9be4..71bd7331 100644 --- a/nrscope/config/config.yaml +++ b/nrscope/config/config.yaml @@ -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 diff --git a/nrscope/hdr/nrscope_def.h b/nrscope/hdr/nrscope_def.h index 0ad5c08d..f1de5377 100644 --- a/nrscope/hdr/nrscope_def.h +++ b/nrscope/hdr/nrscope_def.h @@ -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; @@ -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. * diff --git a/nrscope/hdr/nrscope_logger.h b/nrscope/hdr/nrscope_logger.h index 99a0d5b7..2ed1bc3d 100644 --- a/nrscope/hdr/nrscope_logger.h +++ b/nrscope/hdr/nrscope_logger.h @@ -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; - }; - /*** * ... * diff --git a/nrscope/hdr/radio_nr.h b/nrscope/hdr/radio_nr.h index c9554105..eebf400b 100644 --- a/nrscope/hdr/radio_nr.h +++ b/nrscope/hdr/radio_nr.h @@ -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: @@ -60,6 +61,8 @@ class Radio{ // std::string ul_log_name; bool local_log; + bool to_google; + Radio(); //constructor ~Radio(); //deconstructor diff --git a/nrscope/hdr/to_google.h b/nrscope/hdr/to_google.h new file mode 100644 index 00000000..31535cfc --- /dev/null +++ b/nrscope/hdr/to_google.h @@ -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 \ No newline at end of file diff --git a/nrscope/src/CMakeLists.txt b/nrscope/src/CMakeLists.txt index e7bdbcdc..daf277cf 100644 --- a/nrscope/src/CMakeLists.txt +++ b/nrscope/src/CMakeLists.txt @@ -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) diff --git a/nrscope/src/libs/load_config.cc b/nrscope/src/libs/load_config.cc index 2cca9cea..4d816167 100644 --- a/nrscope/src/libs/load_config.cc +++ b/nrscope/src/libs/load_config.cc @@ -136,6 +136,10 @@ int load_config(std::vector& radios, std::string file_name){ radios[i].log_name = config_yaml[setting_name]["log_name"].as(); } + if(config_yaml[setting_name]["push_to_google"]){ + radios[i].to_google = config_yaml[setting_name]["push_to_google"].as(); + } + // std::cout << " nof_thread: " << radios[i].nof_thread << std::endl; }else{ diff --git a/nrscope/src/libs/nrscope_def.cc b/nrscope/src/libs/nrscope_def.cc index aa516cae..86f26365 100644 --- a/nrscope/src/libs/nrscope_def.cc +++ b/nrscope/src/libs/nrscope_def.cc @@ -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"; } \ No newline at end of file diff --git a/nrscope/src/libs/nrscope_logger.cc b/nrscope/src/libs/nrscope_logger.cc index f08aa088..930d2f4c 100644 --- a/nrscope/src/libs/nrscope_logger.cc +++ b/nrscope/src/libs/nrscope_logger.cc @@ -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"); diff --git a/nrscope/src/libs/radio_nr.cc b/nrscope/src/libs/radio_nr.cc index e5360dd2..b49122d8 100644 --- a/nrscope/src/libs/radio_nr.cc +++ b/nrscope/src/libs/radio_nr.cc @@ -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(); @@ -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){ @@ -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; diff --git a/nrscope/src/libs/to_google.cc b/nrscope/src/libs/to_google.cc new file mode 100644 index 00000000..dcbbeeae --- /dev/null +++ b/nrscope/src/libs/to_google.cc @@ -0,0 +1,153 @@ +#include "nrscope/hdr/to_google.h" + +namespace ToGoogle{ + PyObject *pName, *pModule, *pCreate, *pPush; + PyObject *pClient, *pDict, *pList; + PyObject *pInt, *pDouble, *pStr; + + std::thread google_thread; + std::mutex lock; + std::queue to_google_queue; + + bool run_google; + + int list_length; + int list_count; + + + void init_to_google(){ + setenv("PYTHONPATH", ".", 0); + + Py_Initialize(); + pName = PyUnicode_FromString((char*)"to_google"); + + pModule = PyImport_Import(pName); + Py_DECREF(pName); + + if (pModule != NULL) { + pCreate = PyObject_GetAttrString(pModule, "create_table_with_position_and_time"); + pPush = PyObject_GetAttrString(pModule, "push_data_to_table"); + /* pFunc is a new reference */ + + if (pCreate && PyCallable_Check(pCreate)) { + printf("Creating table...\n"); + pClient = PyObject_CallObject(pCreate, NULL); + }else { + Py_DECREF(pCreate); + Py_DECREF(pModule); + PyErr_Print(); + fprintf(stderr,"Call failed\n"); + return; + } + }else { + if (PyErr_Occurred()) + PyErr_Print(); + fprintf(stderr, "Cannot find function.\n"); + } + + list_count = 0; + list_length = 4000; + pList = PyList_New(list_length); + run_google = true; + google_thread = std::thread(to_google_thread); + } + + void push_node(LogNode input_log){ + lock.lock(); + to_google_queue.push(input_log); + lock.unlock(); + } + + void to_google_thread(){ + while(run_google){ + if(to_google_queue.size()>0){ + lock.lock(); + LogNode new_entry = to_google_queue.front(); + to_google_queue.pop(); + lock.lock(); + + int first_prb = SRSRAN_MAX_PRB_NR; + for (int i = 0; i < SRSRAN_MAX_PRB_NR && first_prb == SRSRAN_MAX_PRB_NR; i++) { + if (new_entry.grant.grant.prb_idx[i]) { + first_prb = i; + } + } + // Initialize and set values of dictionary. + pDict = PyDict_New(); + pDouble = PyFloat_FromDouble(new_entry.timestamp); + PyDict_SetItemString(pDict, "timestamp", pDouble); + pInt = PyLong_FromLong(new_entry.system_frame_idx); + PyDict_SetItemString(pDict, "system_frame_index", pInt); + pInt = PyLong_FromLong(new_entry.slot_idx); + PyDict_SetItemString(pDict, "slot_index", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.rnti); + PyDict_SetItemString(pDict, "rnti", pInt); + pStr = PyUnicode_FromString(srsran_rnti_type_str(new_entry.grant.grant.rnti_type)); + PyDict_SetItemString(pDict, "rnti_type", pStr); + pInt = PyLong_FromLong(new_entry.grant.grant.k); + PyDict_SetItemString(pDict, "k", pInt); + pStr = PyUnicode_FromString(sch_mapping_to_str(new_entry.grant.grant.mapping)); + PyDict_SetItemString(pDict, "mapping", pStr); + pInt = PyLong_FromLong(new_entry.grant.grant.S); + PyDict_SetItemString(pDict, "time_start", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.L); + PyDict_SetItemString(pDict, "time_length", pInt); + pInt = PyLong_FromLong(first_prb); + PyDict_SetItemString(pDict, "frequency_start", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.nof_prb); + PyDict_SetItemString(pDict, "frequency_length", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.nof_dmrs_cdm_groups_without_data); + PyDict_SetItemString(pDict, "nof_dmrs_cdm_groups", pInt); + pDouble = PyFloat_FromDouble(new_entry.grant.grant.beta_dmrs); + PyDict_SetItemString(pDict, "beta_dmrs", pDouble); + pInt = PyLong_FromLong(new_entry.grant.grant.nof_layers); + PyDict_SetItemString(pDict, "nof_layers", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.n_scid); + PyDict_SetItemString(pDict, "n_scid", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.tb_scaling_field); + PyDict_SetItemString(pDict, "tb_scaling_field", pInt); + pStr = PyUnicode_FromString(srsran_mod_string(new_entry.grant.grant.tb[0].mod)); + PyDict_SetItemString(pDict, "modulation", pStr); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].mcs); + PyDict_SetItemString(pDict, "mcs_index", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].tbs); + PyDict_SetItemString(pDict, "transport_block_size", pInt); + pDouble = PyFloat_FromDouble(new_entry.grant.grant.tb[0].R); + PyDict_SetItemString(pDict, "code_rate", pDouble); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].rv); + PyDict_SetItemString(pDict, "redundancy_version", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].ndi); + PyDict_SetItemString(pDict, "new_data_indicator", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].nof_re); + PyDict_SetItemString(pDict, "nof_re", pInt); + pInt = PyLong_FromLong(new_entry.grant.grant.tb[0].nof_bits); + PyDict_SetItemString(pDict, "nof_bits", pInt); + pStr = PyUnicode_FromString(srsran_mcs_table_to_str(new_entry.grant.sch_cfg.mcs_table)); + PyDict_SetItemString(pDict, "mcs_table", pStr); + pStr = PyUnicode_FromString(srsran_mcs_table_to_str(new_entry.grant.sch_cfg.mcs_table)); + PyDict_SetItemString(pDict, "xoverhead", pStr); + + PyList_SetItem(pList, list_count, pDict); + list_count += 1; + + if(list_count == list_length){ + list_count = 0; + if(pList != NULL){ + PyTuple_SetItem(pClient, 3, pList); + printf("Pushing data...\n"); + PyObject_CallObject(pPush, pClient); + Py_DECREF(pClient); + }else{ + fprintf(stderr,"Creating new dict failed\n"); + } + } + }else{ + usleep(1000); + } + } + } + + void exit_to_google(){ + run_google = false; + } +}; \ No newline at end of file diff --git a/nrscope/src/libs/to_google.py b/nrscope/src/libs/to_google.py new file mode 100644 index 00000000..b8dd201a --- /dev/null +++ b/nrscope/src/libs/to_google.py @@ -0,0 +1,81 @@ +from google.cloud import bigquery +from datetime import datetime +import time +import geocoder + +def create_table_with_position_and_time(): + # Get geolocation of the user + geo_loc = geocoder.ip('me').latlng + print(geo_loc) + geo_str = "" + if(float(geo_loc[0]) >= 0): + geo_str += "P_" + str(int(geo_loc[0])) + "_" + "{:.4f}".format(int(geo_loc[0] - int(geo_loc[0])) * 1000)[2:] + else: + geo_str += "N_" + str(int(abs(geo_loc[0]))) + "_" + "{:.4f}".format(abs(geo_loc[0] - int(geo_loc[0])))[2:] + + if(geo_loc[1] >= 0): + geo_str += "_P_" + str(int(geo_loc[1])) + "_" + "{:.4f}".format(geo_loc[1] - int(geo_loc[1]))[2:] + else: + geo_str += "_N_" + str(int(abs(geo_loc[1]))) + "_" + "{:.4f}".format(abs(geo_loc[1] - int(geo_loc[1])))[2:] + print("Current location is: ", geo_str) + + # Get current datetime + current_date_and_time = datetime.now() + current_iime = current_date_and_time.strftime('%Y_%m_%d_%H_%M_%S_%f') + print("The current time is", current_iime) + + # Construct a BigQuery client object. + client = bigquery.Client() + + # TODO(developer): Set table_id to the ID of the table to create. + table_id = "tutorial-explore.ngscope_dci_log."+geo_str+"_"+current_iime + + schema = [ + bigquery.SchemaField("timestamp", "FLOAT", mode="REQUIRED"), + bigquery.SchemaField("system_frame_index", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("slot_index", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("rnti", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("rnti_type", "STRING", mode="REQUIRED"), + bigquery.SchemaField("k", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("mapping", "STRING", mode="REQUIRED"), + bigquery.SchemaField("time_start", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("time_length", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("frequency_start", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("frequency_length", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("nof_dmrs_cdm_groups", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("beta_dmrs", "FLOAT", mode="REQUIRED"), + bigquery.SchemaField("nof_layers", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("n_scid", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("tb_scaling_field", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("modulation", "STRING", mode="REQUIRED"), + bigquery.SchemaField("mcs_index", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("transport_block_size", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("code_rate", "FLOAT", mode="REQUIRED"), + bigquery.SchemaField("redundancy_version", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("new_data_indicator", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("nof_re", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("nof_bits", "INTEGER", mode="REQUIRED"), + bigquery.SchemaField("mcs_table", "STRING", mode="REQUIRED"), + bigquery.SchemaField("xoverhead", "STRING", mode="REQUIRED"), + ] + + table = bigquery.Table(table_id, schema=schema) + table = client.create_table(table) # Make an API request. + + print( + "Create table {}.{}.{}".format(table.project, table.dataset_id, table.table_id) + ) + rows = [] + return client, table, schema, rows + +def push_data_to_table(client, table, schema, rows_input): + tic = time.perf_counter() + batch_size = len(rows_input) + client.insert_rows(table, rows_input, schema) + + toc = time.perf_counter() + print("Pushed {} entries to the google storage, taking {} s.".format(len(rows_input), toc-tic)) + +if __name__ == '__main__': + client, table, schema, rows = create_table_with_position_and_time() + push_data_to_table(client, table, schema, rows) \ No newline at end of file diff --git a/nrscope/src/tests/CMakeLists.txt b/nrscope/src/tests/CMakeLists.txt index ef988910..a741b928 100644 --- a/nrscope/src/tests/CMakeLists.txt +++ b/nrscope/src/tests/CMakeLists.txt @@ -43,7 +43,6 @@ target_link_libraries(google_client_cc srsue_phy if(PUSH_TO_GOOGLE) target_link_libraries(google_client ${PYTHON_LIBRARIES}) - target_link_libraries(google_client ${GOOGLE_CLOUD_CPP_STRORAGE_LIBRARIES}) # target_link_libraries(google_client_cc ${PYTHON_LIBRARIES}) # target_link_libraries(google_client_cc ${GOOGLE_CLOUD_CPP_STRORAGE_LIBRARIES}) endif() diff --git a/nrscope/src/tests/bigquery_table_create.py b/nrscope/src/tests/bigquery_table_create.py index 85882d56..bd3b5cd5 100644 --- a/nrscope/src/tests/bigquery_table_create.py +++ b/nrscope/src/tests/bigquery_table_create.py @@ -27,7 +27,6 @@ def create_table_with_position_and_time(): # Construct a BigQuery client object. client = bigquery.Client() - # TODO(developer): Set table_id to the ID of the table to create. table_id = "tutorial-explore.ngscope_dci_log."+geo_str+"_"+current_iime @@ -70,41 +69,13 @@ def create_table_with_position_and_time(): return client, table, schema, rows def push_data_to_table(client, table, schema, rows_input): - row = {'timestamp': 100.1, - 'system_frame_idex': 1021, - 'slot_index': 102, - 'rnti': 17042, - 'rnti_type': 'c-rnti', - 'k': 0, - 'mapping': 'A', - 'time_start': 0, - 'time_length': 12, - 'frequency_start': 0, - 'frequency_length': 1, - 'nof_dmrs_cdm_groups': 1, - 'beta_dmrs': 1.14, - 'nof_layers': 2, - 'n_scid': 1, - 'tb_scaling_field': 1, - 'modulation': '16QAM', - 'mcs_index': 8, - 'transport_block_size': 512, - 'code_rate': 0.516, - 'redundancy_version': 1, - 'new_data_indicator': 1, - 'nof_re': 12, - 'nof_bits': 132, - 'mcs_table': "256qam", - 'xoverhead': 0} - print(row) - print(rows_input[0]) tic = time.perf_counter() batch_size = len(rows_input) client.insert_rows(table, rows_input, schema) toc = time.perf_counter() - print("Pushed {} entries in batch of {} to the server, taking {} s, {} s for each batch on average".format(len(rows_input), batch_size, toc-tic, (toc-tic)/(len(rows_input)/batch_size))) + print("Pushed {} entries to the google storage, taking {} s.".format(len(rows_input), toc-tic)) if __name__ == '__main__': - client = create_table_with_position_and_time() - push_data_to_table(client) \ No newline at end of file + client, table, schema, rows = create_table_with_position_and_time() + push_data_to_table(client, table, schema, rows) \ No newline at end of file diff --git a/nrscope/src/tests/google_client_cc_test.cc b/nrscope/src/tests/google_client_cc_test.cc index 0afd77bb..3dcce4bd 100644 --- a/nrscope/src/tests/google_client_cc_test.cc +++ b/nrscope/src/tests/google_client_cc_test.cc @@ -5,7 +5,7 @@ int main(){ std::string filename("./a.csv"); NRScopeLog::init_logger(filename); printf("Finished log creating...\n"); - NRScopeLog::LogNode a; + LogNode a; // a.timestamp = 0.0; while(true){ NRScopeLog::push_node(a);