mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
C
92 lines
1.9 KiB
C
4 years ago
|
/**
|
||
8 years ago
|
*
|
||
4 years ago
|
* \section COPYRIGHT
|
||
8 years ago
|
*
|
||
4 years ago
|
* Copyright 2013-2021 Software Radio Systems Limited
|
||
8 years ago
|
*
|
||
4 years ago
|
* By using this file, you agree to the terms and conditions set
|
||
|
* forth in the LICENSE file which can be found at the top level of
|
||
|
* the distribution.
|
||
8 years ago
|
*
|
||
|
*/
|
||
|
|
||
|
/******************************************************************************
|
||
|
* File: trace.h
|
||
|
* Description:
|
||
|
* Reference:
|
||
|
*****************************************************************************/
|
||
|
|
||
4 years ago
|
#ifndef SRSRAN_TRACE_H
|
||
|
#define SRSRAN_TRACE_H
|
||
8 years ago
|
|
||
|
#include <stdio.h>
|
||
|
#include <string>
|
||
6 years ago
|
#include <sys/time.h>
|
||
8 years ago
|
#include <vector>
|
||
|
|
||
4 years ago
|
namespace srsran {
|
||
5 years ago
|
|
||
|
template <class elemType>
|
||
8 years ago
|
class trace
|
||
|
{
|
||
|
public:
|
||
5 years ago
|
trace(uint32_t nof_elems_) : tti(nof_elems_), data(nof_elems_)
|
||
|
{
|
||
|
rpm = 0;
|
||
|
nof_elems = nof_elems_;
|
||
|
wrapped = false;
|
||
8 years ago
|
};
|
||
5 years ago
|
void push_cur_time_us(uint32_t cur_tti)
|
||
|
{
|
||
|
struct timeval t;
|
||
|
gettimeofday(&t, NULL);
|
||
|
elemType us = t.tv_sec * 1e6 + t.tv_usec;
|
||
8 years ago
|
push(cur_tti, us);
|
||
|
}
|
||
5 years ago
|
void push(uint32_t value_tti, elemType value)
|
||
|
{
|
||
8 years ago
|
tti[rpm] = value_tti;
|
||
|
data[rpm] = value;
|
||
|
rpm++;
|
||
|
if (rpm >= nof_elems) {
|
||
5 years ago
|
rpm = 0;
|
||
8 years ago
|
wrapped = true;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
bool writeToBinary(std::string filename)
|
||
|
{
|
||
|
FILE* f = fopen(filename.c_str(), "w");
|
||
8 years ago
|
if (f != NULL) {
|
||
5 years ago
|
uint32_t st = wrapped ? (rpm + 1) : 0;
|
||
8 years ago
|
do {
|
||
5 years ago
|
writeToBinaryValue(f, st++);
|
||
8 years ago
|
if (st >= nof_elems) {
|
||
5 years ago
|
st = 0;
|
||
8 years ago
|
}
|
||
5 years ago
|
} while (st != rpm);
|
||
8 years ago
|
fclose(f);
|
||
5 years ago
|
return true;
|
||
8 years ago
|
} else {
|
||
|
perror("fopen");
|
||
5 years ago
|
return false;
|
||
8 years ago
|
}
|
||
|
}
|
||
5 years ago
|
|
||
8 years ago
|
private:
|
||
|
std::vector<uint32_t> tti;
|
||
|
std::vector<elemType> data;
|
||
5 years ago
|
uint32_t rpm;
|
||
|
uint32_t nof_elems;
|
||
|
bool wrapped;
|
||
|
|
||
|
void writeToBinaryValue(FILE* f, uint32_t idx)
|
||
|
{
|
||
|
fwrite(&tti[idx], 1, sizeof(uint32_t), f);
|
||
8 years ago
|
fwrite(&data[idx], 1, sizeof(elemType), f);
|
||
|
}
|
||
|
};
|
||
|
|
||
4 years ago
|
} // namespace srsran
|
||
5 years ago
|
|
||
4 years ago
|
#endif // SRSRAN_TRACE_H
|