Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Feature/add all dci message type #14

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/include/srsran/radio/channel_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <list>
#include <map>
#include <mutex>
#include <string> /* add missing dependency */

namespace srsran {

Expand Down
4 changes: 2 additions & 2 deletions lib/src/phy/ue/ngscope_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ int srsran_ngscope_tree_copy_rnti(ngscope_tree_t* q,
int ret = 0;
for(int i=0; i<q->nof_location; i++){
for(int j=0; j<MAX_NOF_FORMAT+1; j++){
if(q->dci_array[j][i].rnti == rnti){
// if(q->dci_array[j][i].rnti == rnti){
srsran_ngscope_tree_copy_dci_fromArray2PerSub(q, dci_per_sub, j, i);
ZERO_OBJECT(q->dci_array[j][i]);
ret++;;
}
// }
}
}
return ret;
Expand Down
32 changes: 32 additions & 0 deletions ngscope/hdr/dciLib/dci_sink_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define MAX_NOF_CELL 4
#define NOF_LOG_DCI 1000
#define MAX_CLIENT 5
#define MAX_NOF_RNTI_PER_DCI 40


// This structure is used for the DCI exchange between NG-Scope and the app receiver
// We include both downlink and uplink information
Expand Down Expand Up @@ -54,5 +56,35 @@ typedef struct{
uint16_t rnti;
}cell_config_t;

typedef struct {
uint16_t rnti;
uint32_t dl_tbs;
uint8_t dl_prb;
uint8_t dl_no_tbs_prb;

uint32_t ul_tbs;
uint8_t ul_prb;
uint8_t ul_no_tbs_prb;
} rnti_dci_t;

// Structure that is used for storing all RNTIs DCI data per cell between the
// dci sink server/client
typedef struct {
uint8_t cell_id;
uint64_t time_stamp;
uint16_t tti;
uint64_t total_dl_tbs;
uint16_t total_dl_prb;
uint16_t total_dl_no_tbs_prb;

uint64_t total_ul_tbs;
uint16_t total_ul_prb;
uint16_t total_ul_no_tbs_prb;

uint8_t nof_rnti;
rnti_dci_t rnti_list[MAX_NOF_RNTI_PER_DCI];
} cell_dci_t;



#endif
1 change: 1 addition & 0 deletions ngscope/hdr/dciLib/dci_sink_sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void sock_update_client_list_addr(client_list_t* q, struct sockaddr_in* addr);

int sock_send_config(ngscope_dci_sink_serv_t* q, cell_config_t* cell_config);
int sock_send_single_dci(ngscope_dci_sink_serv_t* q, ue_dci_t* ue_dci, int proto_v);
int sock_send_single_rnti_dci(ngscope_dci_sink_serv_t* q, cell_dci_t* cell_dci, int proto_v);

struct sockaddr_in sock_create_serv_addr(char serv_IP[40], int serv_port);
#endif
161 changes: 158 additions & 3 deletions ngscope/src/dciLib/dci_ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int push_dci_to_remote(sf_status_t* q, int cell_idx, uint16_t targetRNTI, int re
for (int i = 0; i < nof_ul_msg; i++) {
if (q->ul_msg[i].rnti == targetRNTI) {
ngscope_dci_msg_t dci_msg = q->ul_msg[i];
printf("ul tbs: %d", dci_msg.tb[0].tbs);
//printf("ul tbs: %d", dci_msg.tb[0].tbs);
ue_dci.ul_tbs = dci_msg.tb[0].tbs + dci_msg.tb[1].tbs;
if (dci_msg.tb[0].rv > 0 || dci_msg.tb[1].rv > 0) {
ue_dci.ul_reTx = 1;
Expand All @@ -188,12 +188,164 @@ int push_dci_to_remote(sf_status_t* q, int cell_idx, uint16_t targetRNTI, int re
}
}

printf("UE DCI dl_tbs: %d ul_tbs:%d \n", ue_dci.dl_tbs, ue_dci.ul_tbs);
//printf("UE DCI dl_tbs: %d ul_tbs:%d \n", ue_dci.dl_tbs, ue_dci.ul_tbs);
sock_send_single_dci(&dci_sink_serv, &ue_dci, 0);

return 1;
}

rnti_dci_t *get_rnti_dci(cell_dci_t *cell_dci, uint16_t rnti) {
if (cell_dci->nof_rnti >= 1) {
// fast return without entering the for loop
if (cell_dci->nof_rnti == 1) {
if (cell_dci->rnti_list[0].rnti == rnti) {
return &cell_dci->rnti_list[0];
}
} else {
for (uint8_t i = 0; i < cell_dci->nof_rnti; i++) {
if (cell_dci->rnti_list[i].rnti == rnti) {
return &cell_dci->rnti_list[i];
}
}
}
}
cell_dci->rnti_list[cell_dci->nof_rnti] = (rnti_dci_t){ rnti, 0, 0, 0, 0 , 0, 0 };
cell_dci->nof_rnti++;
return &cell_dci->rnti_list[cell_dci->nof_rnti - 1];
}

void print_ngscope_dci(const ngscope_dci_msg_t* dci_msg) {
printf("\trnti: %u\n", dci_msg->rnti);
printf("\tprb: %u\n", dci_msg->prb);
printf("\tharq: %u\n", dci_msg->harq);
printf("\tnof_tb: %d\n", dci_msg->nof_tb);
printf("\tdl: %s\n", dci_msg->dl ? "true" : "false");
printf("\tdecode_prob: %f\n", dci_msg->decode_prob);
printf("\tcorr: %f\n", dci_msg->corr);

// Print srsran_dci_format_t (assuming it has members, modify if it is different)
// printf("\tformat: %s\n", dci_msg->format); // Uncomment and adjust as needed

for (int i = 0; i < 2; i++) {
printf("\ttb[%d].mcs: %u\n", i, dci_msg->tb[i].mcs);
printf("\ttb[%d].tbs: %u\n", i, dci_msg->tb[i].tbs);
printf("\ttb[%d].rv: %u\n", i, dci_msg->tb[i].rv);
printf("\ttb[%d].ndi: %s\n", i, dci_msg->tb[i].ndi ? "true" : "false");
}

printf("\tphich.n_dmrs: %u\n", dci_msg->phich.n_dmrs);
printf("\tphich.n_prb_tilde: %u\n", dci_msg->phich.n_prb_tilde);
printf("\tphich.freq_hopping: %u\n", dci_msg->phich.freq_hopping);

printf("\tloc.L: %u\n", dci_msg->loc.L);
printf("\tloc.ncce: %u\n", dci_msg->loc.ncce);
printf("\tloc.checked: %s\n", dci_msg->loc.checked ? "true" : "false");
printf("\tloc.mean_llr: %f\n", dci_msg->loc.mean_llr);
}

int push_rnti_dci_to_remote(sf_status_t* q, int cell_idx, int remote_sock)
{
if (remote_sock <= 0) {
// printf("ERROR: sock not set!\n\n");
return -1;
}
cell_dci_t cell_dci;
cell_dci.cell_id = cell_idx;
cell_dci.time_stamp = q->timestamp_us;
cell_dci.tti = q->tti;
cell_dci.nof_rnti = 0;
cell_dci.total_dl_tbs = 0;
cell_dci.total_ul_tbs = 0;

cell_dci.total_dl_prb = 0;
cell_dci.total_ul_prb = 0;

cell_dci.total_dl_no_tbs_prb = 0;
cell_dci.total_ul_no_tbs_prb = 0;


for (int i = 0; i < MAX_NOF_RNTI_PER_DCI; i++) {
cell_dci.rnti_list[i] = (rnti_dci_t){ 0, 0, 0, 0, 0, 0, 0 };
}

int nof_dl_msg = q->nof_dl_msg;
int nof_ul_msg = q->nof_ul_msg;
uint8_t dl_rnti_skipped_prbs = 0;
uint8_t ul_rnti_skipped_prbs = 0;

for (int i = 0; i < nof_dl_msg; i++) {
ngscope_dci_msg_t dci_msg = q->dl_msg[i];
/* Only include allocation RNTIs */
if (dci_msg.rnti < 0x0001 || dci_msg.rnti > 0xFFF3) {
dl_rnti_skipped_prbs += dci_msg.prb;
continue;
}
rnti_dci_t *rnti_dci = get_rnti_dci(&cell_dci, dci_msg.rnti);

if (dci_msg.tb[0].rv > 0 || dci_msg.tb[1].rv > 0) {
rnti_dci->dl_no_tbs_prb += dci_msg.prb;
cell_dci.total_dl_no_tbs_prb += dci_msg.prb;
continue;
}
if (dci_msg.tb[0].mcs >= 28) {
rnti_dci->dl_no_tbs_prb += dci_msg.prb;
cell_dci.total_dl_no_tbs_prb += dci_msg.prb;
continue;
}
rnti_dci->dl_tbs += dci_msg.tb[0].tbs + dci_msg.tb[1].tbs;
rnti_dci->dl_prb += dci_msg.prb;
cell_dci.total_dl_tbs += dci_msg.tb[0].tbs + dci_msg.tb[1].tbs;
cell_dci.total_dl_prb += dci_msg.prb;
}

for (int i = 0; i < nof_ul_msg; i++) {
ngscope_dci_msg_t dci_msg = q->ul_msg[i];
/* Only include allocation RNTIs */
if (dci_msg.rnti < 0x0001 || dci_msg.rnti > 0xFFF3) {
ul_rnti_skipped_prbs += dci_msg.prb;
continue;
}
rnti_dci_t *rnti_dci = get_rnti_dci(&cell_dci, dci_msg.rnti);

if (dci_msg.tb[0].rv > 0) {
rnti_dci->ul_no_tbs_prb += dci_msg.prb;
cell_dci.total_ul_no_tbs_prb += dci_msg.prb;
continue;
}
if (dci_msg.tb[0].mcs >= 28) {
rnti_dci->ul_no_tbs_prb += dci_msg.prb;
cell_dci.total_ul_no_tbs_prb += dci_msg.prb;
continue;
}
/* Apparently, UL tbs is only one */
rnti_dci->ul_tbs += dci_msg.tb[0].tbs;
rnti_dci->ul_prb += dci_msg.prb;
cell_dci.total_ul_tbs += dci_msg.tb[0].tbs;
cell_dci.total_ul_prb += dci_msg.prb;
}

if (q->cell_dl_prb > 200 || q->cell_ul_prb > 200) {
printf("\r######\n");
printf(" q.filled : %b\n", q->filled);
printf(" q.cell_dl_prb : %i\n", q->cell_dl_prb);
printf(" q.cell_ul_prb : %i\n", q->cell_ul_prb);
printf(" cell_dci.dl_all_prb : %i\n",
(cell_dci.total_dl_prb + cell_dci.total_dl_no_tbs_prb + dl_rnti_skipped_prbs));
printf(" cell_dci.ul_all_prb : %i\n",
(cell_dci.total_ul_prb + cell_dci.total_ul_no_tbs_prb + ul_rnti_skipped_prbs));
printf(" cell_dci.total_dl_prb : %i\n", cell_dci.total_dl_prb);
printf(" cell_dci.total_ul_prb : %i\n", cell_dci.total_ul_prb);
printf(" cell_dci.total_dl_no_tbs_prb : %i\n", cell_dci.total_dl_no_tbs_prb);
printf(" cell_dci.total_ul_no_tbs_prb : %i\n", cell_dci.total_ul_no_tbs_prb);
printf("\r##########\n");
}


sock_send_single_rnti_dci(&dci_sink_serv, &cell_dci, 0);

return 1;
}

///* push to recorded dci to remote */
// int push_dci_to_remote(sf_status_t* q, int cell_idx, uint16_t targetRNTI, int remote_sock){
// if(remote_sock <= 0){
Expand Down Expand Up @@ -265,10 +417,13 @@ void update_cell_status_header(ngscope_cell_dci_ring_buffer_t* q, int remote_soc
check_dci_decoding_timeout(q);

int index = (q->cell_header + 1) % q->buf_size;

while (q->sub_stat[index].filled) {
q->cell_header = index;
q->sub_stat[index].filled = false;
push_dci_to_remote(&q->sub_stat[index], q->cell_idx, q->targetRNTI, remote_sock);
// TODO: Check which message type to send
// push_dci_to_remote(&q->sub_stat[index], q->cell_idx, q->targetRNTI, remote_sock);
push_rnti_dci_to_remote(&q->sub_stat[index], q->cell_idx, remote_sock);
// fprintf(fd,"%d\t%d\t%d\t%d\t\n", q->sub_stat[index].tti, q->cell_header, index, tti);
// printf("push tti:%d index:%d\n", q->sub_stat[index].tti, index);
// update the index
Expand Down
42 changes: 42 additions & 0 deletions ngscope/src/dciLib/dci_sink_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,48 @@ int sock_send_config(ngscope_dci_sink_serv_t* q, cell_config_t* cell_config)
return 1;
}

int sock_send_single_rnti_dci(ngscope_dci_sink_serv_t* q, cell_dci_t* cell_dci, int proto_v)
{
char buf[1000];
/**********************************************
Common part of the data:
preamble: 0xAB 0xAB 0xAB 0xAB
protocol version: 8 bits
cell_dci_t: 848
**********************************************/
// preamble here
buf[0] = (char) 0xAB;
buf[1] = (char) 0xAB;
buf[2] = (char) 0xAB;
buf[3] = (char) 0xAB;
int buf_idx = 4;

/************ Protocol Version ************/
memcpy(&buf[buf_idx], &proto_v, sizeof(uint8_t));
buf_idx += 1;

/*********** Cell DCI ***************/
memcpy(&buf[buf_idx], cell_dci, sizeof(cell_dci_t));
buf_idx += sizeof(cell_dci_t);

/* Send the data to all client via UDP */
pthread_mutex_lock(&q->client_list.mutex);
for (int i = 0; i < q->client_list.nof_client; i++) {
int ret = sendto(q->sink_sockfd,
(char*)buf,
buf_idx,
MSG_CONFIRM,
(const struct sockaddr*)&q->client_list.client_addr[i],
sizeof(struct sockaddr));
if (ret < 0) {
printf("ERROR in sending via socket!\n");
}
}
pthread_mutex_unlock(&q->client_list.mutex);

return 1;
}

struct sockaddr_in sock_create_serv_addr(char serv_IP[40], int serv_port)
{
struct sockaddr_in servaddr;
Expand Down
29 changes: 24 additions & 5 deletions ngscope/src/dciLib/task_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include <sys/time.h>
#include <unistd.h>
#include <stdint.h>
/* <thesis> */
#include <wchar.h>
#include <locale.h>
/* </thesis> */

#include "ngscope/hdr/dciLib/radio.h"
#include "ngscope/hdr/dciLib/task_scheduler.h"
Expand Down Expand Up @@ -520,7 +524,9 @@ void* task_scheduler_thread(void* p){
FILE* fd = fopen("task_scheduler.txt","w+");
//FILE* fd_1 = fopen("sf_sfn.txt","w+");


uint8_t print_index = 0;
uint8_t print_delay = 0;
setlocale(LC_CTYPE, "");
//uint64_t t1=0, t2=0, t3=0;
//uint64_t t1_sf_idx =0, t2_sf_idx=0;
while(!go_exit && (sf_cnt < task_scheduler.prog_args.nof_subframes || task_scheduler.prog_args.nof_subframes == -1)) {
Expand All @@ -534,7 +540,20 @@ void* task_scheduler_thread(void* p){
//printf("RET is:%d\n", ret);
if (ret < 0) {
ERROR("Error calling srsran_ue_sync_work()");
}else if(ret == 1){
}
else if (ret == 0) {
if (print_delay++ >= 100) {
printf("\r🔍 searching pss");
fflush(stdout);
print_delay = 0;
}
}
else if(ret == 1) {
if (print_delay++ >= 100) {
printf("\r%lc ", (wchar_t) (0x25F3 - (print_index++ % 4)));
fflush(stdout);
print_delay = 0;
}
//t1_sf_idx = timestamp_us();
sf_idx = srsran_ue_sync_get_sfidx(&task_scheduler.ue_sync);
//t2_sf_idx = timestamp_us();
Expand All @@ -549,7 +568,7 @@ void* task_scheduler_thread(void* p){
ue_mib_decode_sfn(&ue_mib, &task_scheduler.cell, &sfn_tmp, decode_pdcch);

if(sfn != sfn_tmp){
printf("current sfn:%d decoded sfn:%d\n",sfn, sfn_tmp);
//printf("current sfn:%d decoded sfn:%d\n",sfn, sfn_tmp);
}
if(sfn_tmp > 0){
//printf("decoded sfn from:%d\n",sfn_tmp);
Expand All @@ -568,7 +587,7 @@ void* task_scheduler_thread(void* p){
/***************** Tell the decoder to decode the PDCCH *********/
if(decode_pdcch){ // We only decode when we got the SFN
if((last_tti != 10239) && (last_tti+1 != tti) ){
printf("Last tti:%d current tti:%d\n", last_tti, tti);
//printf("Last tti:%d current tti:%d\n", last_tti, tti);
}
last_tti = tti;
/** Now we need to know where shall we put the IQ data of each subframe*/
Expand All @@ -588,7 +607,7 @@ void* task_scheduler_thread(void* p){
if(task_sf_ring_buffer_put(&task_tmp_buffer[rf_idx], buffers, sfn, sf_idx,
task_scheduler.prog_args.rf_nof_rx_ant, max_num_samples) == 0){
int nof_buf_sf = task_sf_ring_buffer_len(&task_tmp_buffer[rf_idx]);
printf("Skip %d subframe ring buf len:%d \n", sfn*10+sf_idx, nof_buf_sf);
//printf("Skip %d subframe ring buf len:%d \n", sfn*10+sf_idx, nof_buf_sf);
skip_tti_put(&skip_tti[rf_idx], sfn, sf_idx);
}
//int nof_buf_sf = get_nof_buffered_sf(rf_idx);
Expand Down
Loading
Loading