From a456054d9b5d79f194f25835ca39272e8a32e467 Mon Sep 17 00:00:00 2001
From: laurent <laurent.thomas@open-cells.com>
Date: Mon, 22 Jun 2020 12:02:58 +0200
Subject: [PATCH] continue scope

---
 executables/ocp-gnb.c                       | 12 ++++-----
 openair1/PHY/TOOLS/nr_phy_scope.c           | 29 ++++++++++++++-------
 openair1/PHY/TOOLS/readme.md                | 12 +++++++++
 openair1/SCHED_NR_UE/phy_procedures_nr_ue.c |  6 ++---
 openair2/LAYER2/NR_MAC_UE/main_ue_nr.c      |  2 +-
 5 files changed, 40 insertions(+), 21 deletions(-)
 create mode 100644 openair1/PHY/TOOLS/readme.md

diff --git a/executables/ocp-gnb.c b/executables/ocp-gnb.c
index be7679f610..69687c6f19 100644
--- a/executables/ocp-gnb.c
+++ b/executables/ocp-gnb.c
@@ -99,10 +99,10 @@ int flexran_agent_start(mid_t mod_id) {
 }
 void flexran_agent_slice_update(mid_t module_idP) {
 }
-int proto_agent_start(mod_id_t mod_id, const cudu_params_t *p){
-	return 0;
+int proto_agent_start(mod_id_t mod_id, const cudu_params_t *p) {
+  return 0;
 }
-void proto_agent_stop(mod_id_t mod_id){
+void proto_agent_stop(mod_id_t mod_id) {
 }
 int split73=0;
 void sendFs6Ul(PHY_VARS_eNB *eNB, int UE_id, int harq_pid, int segmentID, int16_t *data, int dataLen, int r_offset) {
@@ -400,8 +400,8 @@ void OCPconfig_RU(RU_t *ru) {
   config_getlist( &RUParamList, RUParams, sizeof(RUParams)/sizeof(paramdef_t), NULL);
   AssertFatal( RUParamList.numelt == 1 && RC.nb_nr_L1_inst ==1,""  );
   ru->idx=0;
-  ru->nr_frame_parms                      = (NR_DL_FRAME_PARMS *)malloc(sizeof(NR_DL_FRAME_PARMS));
-  ru->frame_parms                         = (LTE_DL_FRAME_PARMS *)malloc(sizeof(LTE_DL_FRAME_PARMS));
+  ru->nr_frame_parms                      = (NR_DL_FRAME_PARMS *)calloc(sizeof(NR_DL_FRAME_PARMS),1);
+  ru->frame_parms                         = (LTE_DL_FRAME_PARMS *)calloc(sizeof(LTE_DL_FRAME_PARMS),1);
   ru->if_timing                           = synch_to_ext_device;
   ru->num_gNB                           = RUParamList.paramarray[j][RU_ENB_LIST_IDX].numelt;
   ru->gNB_list[i] = &RC.gNB[RUParamList.paramarray[j][RU_ENB_LIST_IDX].iptr[i]][0];
@@ -858,7 +858,7 @@ int main( int argc, char **argv ) {
   // once all RUs are ready initialize the rest of the gNBs ((dependence on final RU parameters after configuration)
   printf("ALL RUs ready - init gNBs\n");
   LOG_E(PHY,"configuring RU from file,  hardcoded one gNB for one RU, one carrier\n");
-  RU_t ru={0};
+  RU_t ru= {0};
   OCPconfig_RU(&ru);
   ru.nr_frame_parms->threequarter_fs=threequarter_fs;
   fill_rf_config(&ru,ru.rf_config_file);
diff --git a/openair1/PHY/TOOLS/nr_phy_scope.c b/openair1/PHY/TOOLS/nr_phy_scope.c
index 9d4648c94f..dfb148d34e 100644
--- a/openair1/PHY/TOOLS/nr_phy_scope.c
+++ b/openair1/PHY/TOOLS/nr_phy_scope.c
@@ -162,19 +162,28 @@ static void oai_xygraph(OAIgraph_t *graph, float *x, float *y, int len, int laye
 }
 
 static void genericLogPowerPerAntena(OAIgraph_t *graph, const int nb_ant, const scopeSample_t **data, const int len) {
-  float values[len];
-  float time[len];
+  float *values=malloc(len*sizeof(*values));
+  float *time=malloc(len*sizeof(*time));
 
   for (int ant=0; ant<nb_ant; ant++) {
     if (data[ant] != NULL) {
-      for (int i=0; i<len; i++) {
-        values[i] = 10*log10(1.0+SquaredNorm(data[ant][i]));
-        time[i] = i;
+      for (int i=0; i<len; i+=8) {
+        float *vals=values+i;
+        float *tim=time+i;
+        const scopeSample_t *in=&(data[ant][i]);
+
+        for (int k=0; k<8; k++ ) {
+          vals[k] = 10*log10(1.0+SquaredNorm(in[k]));
+          tim[k] = i+k;
+        }
       }
 
       oai_xygraph(graph,time,values, len, ant, 10);
     }
   }
+
+  free(values);
+  free(time);
 }
 
 static void genericPowerPerAntena(OAIgraph_t  *graph, const int nb_ant, const scopeSample_t **data, const int len) {
@@ -322,7 +331,7 @@ static OAI_phy_scope_t *create_phy_scope_gnb(void) {
   fl_set_object_color( obj, FL_BLACK, FL_WHITE );
   int curY=0,x,y,w,h;
   // Received signal
-  fdui->graph[0] = gNBcommonGraph( timeSignal, FL_FILL_XYPLOT, 0, curY, 400, 100,
+  fdui->graph[0] = gNBcommonGraph( timeSignal, FL_NORMAL_XYPLOT, 0, curY, 400, 100,
                                    "Received Signal (Time-Domain, dB)", FL_RED );
   // Time-domain channel response
   fdui->graph[1] = gNBcommonGraph( timeResponse, FL_NORMAL_XYPLOT, 410, curY, 400, 100,
@@ -330,7 +339,7 @@ static OAI_phy_scope_t *create_phy_scope_gnb(void) {
   fl_get_object_bbox(fdui->graph[0].graph,&x, &y,&w, &h);
   curY+=h;
   // Frequency-domain channel response
-  fdui->graph[2] = gNBcommonGraph( frequencyResponse, FL_FILL_XYPLOT, 0, curY, 800, 100,
+  fdui->graph[2] = gNBcommonGraph( frequencyResponse, FL_NORMAL_XYPLOT, 0, curY, 800, 100,
                                    "Channel Frequency  Response (RE, dB)", FL_RED );
   fl_get_object_bbox(fdui->graph[2].graph,&x, &y,&w, &h);
   curY+=h;
@@ -390,8 +399,8 @@ static void *scope_thread_gNB(void *arg) {
   //# ifdef ENABLE_XFORMS_WRITE_STATS
   //  FILE *gNB_stats = fopen("gNB_stats.txt", "w");
   //#endif
-  size_t stksize;
-  pthread_attr_t atr;
+  size_t stksize=0;
+  pthread_attr_t atr= {0};
   pthread_attr_getstacksize(&atr, &stksize);
   pthread_attr_setstacksize(&atr,32*1024*1024 );
   sleep(3); // no clean interthread barriers
@@ -649,7 +658,7 @@ static OAI_phy_scope_t *create_phy_scope_nrue( int ID ) {
   int curY=0,x,y,w,h;
   // Received signal
   fdui->graph[0] = nrUEcommonGraph(ueTimeResponse,
-                                   FL_FILL_XYPLOT, 0, curY, 400, 100, "Received Signal (Time-Domain, dB)", FL_RED );
+                                   FL_NORMAL_XYPLOT, 0, curY, 400, 100, "Received Signal (Time-Domain, dB)", FL_RED );
   // Time-domain channel response
   fdui->graph[1] = nrUEcommonGraph(ueChannelResponse,
                                    FL_NORMAL_XYPLOT, 400, curY, 400, 100, "Channel Impulse Response (samples, abs)", FL_RED );
diff --git a/openair1/PHY/TOOLS/readme.md b/openair1/PHY/TOOLS/readme.md
new file mode 100644
index 0000000000..f6671acc6d
--- /dev/null
+++ b/openair1/PHY/TOOLS/readme.md
@@ -0,0 +1,12 @@
+
+To use the scope, run the xNB or the UE with option "-d"  
+
+Usage in gdb
+In gdb, when you break, you can refresh immediatly the scope view by calling the display function.
+The first paramter is the graph context, nevertheless we keep the last value for a dirty call in gdb (so you can use '0')  
+
+Example with no variable known
+phy_scope_nrUE(0, PHY_vars_UE_g[0][0], 0, 0, 0)
+
+or
+phy_scope_gNB(0, phy_vars_gnb, phy_vars_ru, UE_id)
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index e5e48ee0ed..99e345e9f3 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -2989,10 +2989,8 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
 	 pdcch_vars->nb_search_space);
 #endif
 
-  fapi_nr_dci_indication_t dci_ind;
-  nr_downlink_indication_t dl_indication;
-  memset((void*)&dci_ind,0,sizeof(dci_ind));
-  memset((void*)&dl_indication,0,sizeof(dl_indication));
+  fapi_nr_dci_indication_t dci_ind={0};
+  nr_downlink_indication_t dl_indication={0};
   dci_cnt = nr_dci_decoding_procedure(ue,
 				      proc->frame_rx,
 				      nr_tti_rx,
diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c
index 61f9ab601e..c5154d7a1f 100644
--- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c
+++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c
@@ -50,7 +50,7 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst)
     //LOG_I(MAC, "[MAIN] init UE MAC functions \n");
     
     //init mac here
-    nr_ue_mac_inst = (NR_UE_MAC_INST_t *)malloc(sizeof(NR_UE_MAC_INST_t)*NB_NR_UE_MAC_INST);
+    nr_ue_mac_inst = (NR_UE_MAC_INST_t *)calloc(sizeof(NR_UE_MAC_INST_t),NB_NR_UE_MAC_INST);
     if (rrc_inst) {
       nr_rrc_mac_config_req_ue(0,0,0,NULL,rrc_inst->cell_group_config->spCellConfig);
       
-- 
2.26.2