Example #1
0
int srslte_ue_mib_decode(srslte_ue_mib_t * q,
                  uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN], uint32_t *nof_tx_ports, int *sfn_offset)
{
  int ret = SRSLTE_SUCCESS;
  cf_t *ce_slot1[SRSLTE_MAX_PORTS]; 

  /* Run FFT for the slot symbols */
  srslte_ofdm_rx_sf(&q->fft);
            
  /* Get channel estimates of sf idx #0 for each port */
  ret = srslte_chest_dl_estimate(&q->chest, q->sf_symbols, q->ce, 0);
  if (ret < 0) {
    return SRSLTE_ERROR;
  }
  /* Reset decoder if we missed a frame */
  if (q->frame_cnt > 8) {
    INFO("Resetting PBCH decoder after %d frames\n", q->frame_cnt);
    srslte_ue_mib_reset(q);
  }
  
  for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
    ce_slot1[i] = &q->ce[i][SRSLTE_SLOT_LEN_RE(q->chest.cell.nof_prb, q->chest.cell.cp)];
  }

  /* Decode PBCH */
  ret = srslte_pbch_decode(&q->pbch, &q->sf_symbols[SRSLTE_SLOT_LEN_RE(q->chest.cell.nof_prb, q->chest.cell.cp)], 
                    ce_slot1, 0,
                    bch_payload, nof_tx_ports, sfn_offset);
  

  if (ret < 0) {
    fprintf(stderr, "Error decoding PBCH (%d)\n", ret);      
  } else if (ret == 1) {
    INFO("MIB decoded: %u\n", q->frame_cnt);
    srslte_ue_mib_reset(q);
    ret = SRSLTE_UE_MIB_FOUND; 
  } else {
    ret = SRSLTE_UE_MIB_NOTFOUND;
    INFO("MIB not decoded: %u\n", q->frame_cnt);
    q->frame_cnt++;
  }    
  
  return ret;
}
Example #2
0
int main(int argc, char **argv) {
  srslte_pbch_t pbch;
  uint8_t bch_payload_tx[SRSLTE_BCH_PAYLOAD_LEN], bch_payload_rx[SRSLTE_BCH_PAYLOAD_LEN];
  int i, j;
  cf_t *ce[SRSLTE_MAX_PORTS];
  int nof_re;
  cf_t *slot1_symbols[SRSLTE_MAX_PORTS];
  uint32_t nof_rx_ports; 

  parse_args(argc,argv);

  nof_re = SRSLTE_SLOT_LEN_RE(cell.nof_prb, SRSLTE_CP_NORM); 

  /* init memory */
  for (i=0;i<cell.nof_ports;i++) {
    ce[i] = malloc(sizeof(cf_t) * nof_re);
    if (!ce[i]) {
      perror("malloc");
      exit(-1);
    }
    for (j=0;j<nof_re;j++) {
      ce[i][j] = 1;
    }
    slot1_symbols[i] = malloc(sizeof(cf_t) * nof_re);
    if (!slot1_symbols[i]) {
      perror("malloc");
      exit(-1);
    }

  }
  if (srslte_pbch_init(&pbch, cell)) {
    fprintf(stderr, "Error creating PBCH object\n");
    exit(-1);
  }

  srand(time(NULL));
  for (i=0;i<SRSLTE_BCH_PAYLOAD_LEN;i++) {
    bch_payload_tx[i] = rand()%2;
  }

  srslte_pbch_encode(&pbch, bch_payload_tx, slot1_symbols, 0);

  /* combine outputs */
  for (i=1;i<cell.nof_ports;i++) {
    for (j=0;j<nof_re;j++) {
      slot1_symbols[0][j] += slot1_symbols[i][j];
    }
  }
  
  srslte_pbch_decode_reset(&pbch);
  if (1 != srslte_pbch_decode(&pbch, slot1_symbols[0], ce, 0, bch_payload_rx, &nof_rx_ports, NULL)) {
    printf("Error decoding\n");
    exit(-1);
  }

  srslte_pbch_free(&pbch);

  for (i=0;i<cell.nof_ports;i++) {
    free(ce[i]);
    free(slot1_symbols[i]);
  }
  printf("Tx ports: %d - Rx ports: %d\n", cell.nof_ports, nof_rx_ports);
  printf("Tx payload: ");
  srslte_vec_fprint_hex(stdout, bch_payload_tx, SRSLTE_BCH_PAYLOAD_LEN);
  printf("Rx payload: ");
  srslte_vec_fprint_hex(stdout, bch_payload_rx, SRSLTE_BCH_PAYLOAD_LEN);

  if (nof_rx_ports == cell.nof_ports && !memcmp(bch_payload_rx, bch_payload_tx, sizeof(uint8_t) * SRSLTE_BCH_PAYLOAD_LEN)) {
    printf("OK\n");
    exit(0);
  } else {
    printf("Error\n");
    exit(-1);
  }
}
Example #3
0
int main(int argc, char **argv) {
  uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
  int n;
  uint32_t nof_tx_ports, sfn_offset; 
  cf_t *ce_slot1[SRSLTE_MAX_PORTS]; 
  
  if (argc < 3) {
    usage(argv[0]);
    exit(-1);
  }

  parse_args(argc,argv);

  if (base_init()) {
    fprintf(stderr, "Error initializing receiver\n");
    exit(-1);
  }

  int frame_cnt = 0; 
  int nof_decoded_mibs = 0; 
  int nread = 0; 
  do {
    nread = srslte_filesource_read(&fsrc, input_buffer, FLEN);

    if (nread > 0) {
      // process 1st subframe only
      srslte_ofdm_rx_sf(&fft, input_buffer, fft_buffer);

      /* Get channel estimates for each port */
      srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0);

      INFO("Decoding PBCH\n", 0);
      
      for (int i=0;i<SRSLTE_MAX_PORTS;i++) {
        ce_slot1[i] = &ce[i][SRSLTE_SLOT_LEN_RE(cell.nof_prb, cell.cp)];
      }

      srslte_pbch_decode_reset(&pbch);
      n = srslte_pbch_decode(&pbch, &fft_buffer[SRSLTE_SLOT_LEN_RE(cell.nof_prb, cell.cp)], 
                      ce_slot1, srslte_chest_dl_get_noise_estimate(&chest), 
                      bch_payload, &nof_tx_ports, &sfn_offset);
      if (n == 1) {
        nof_decoded_mibs++;
      } else if (n < 0) {
        fprintf(stderr, "Error decoding PBCH\n");
        exit(-1);
      }
      frame_cnt++;
    } else if (nread < 0) {
      fprintf(stderr, "Error reading from file\n");
      exit(-1);
    }
  } while(nread > 0 && frame_cnt < nof_frames);

  base_free();
  if (frame_cnt == 1) {
    if (n == 0) {
      printf("Could not decode PBCH\n");
      exit(-1);
    } else {
      printf("MIB decoded OK. Nof ports: %d. SFN offset: %d Payload: ", nof_tx_ports, sfn_offset);    
      srslte_vec_fprint_hex(stdout, bch_payload, SRSLTE_BCH_PAYLOAD_LEN);
      if (nof_tx_ports == 2 && sfn_offset == 0 && !memcmp(bch_payload, bch_payload_file, SRSLTE_BCH_PAYLOAD_LEN)) {
        printf("This is the signal.1.92M.dat file\n");
        exit(0);
      } else {
        printf("This is an unknown file\n");
        exit(-1);
      }
    }
  } else {
    printf("Decoded %d/%d MIBs\n", nof_decoded_mibs, frame_cnt);
  }
}