Add NSA mode to working dl_tti messages from gNB
This commit is not currently building, but I wanted to be able to save the changes that I have added.
This commit is contained in:
@@ -14,53 +14,74 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "debug.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <syslog.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <debug.h>
|
||||
static nfapi_trace_level_t trace_level = NFAPI_TRACE_WARN;
|
||||
|
||||
#define MAX_MSG_LENGTH 2096
|
||||
#define TRACE_HEADER_LENGTH 44
|
||||
|
||||
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...);
|
||||
|
||||
// initialize the trace function to 0
|
||||
void (*nfapi_trace_g)(nfapi_trace_level_t level, const char* format, ...) = &nfapi_trace_dbg;
|
||||
|
||||
nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_ERROR;
|
||||
//nfapi_trace_level_t nfapi_trace_level_g = NFAPI_TRACE_WARN;
|
||||
|
||||
void nfapi_set_trace_level(nfapi_trace_level_t new_level)
|
||||
static void nfapi_trace_init(void)
|
||||
{
|
||||
nfapi_trace_level_g = new_level;
|
||||
static bool initialized;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
|
||||
const char *env = getenv("NFAPI_TRACE_LEVEL");
|
||||
if (!env)
|
||||
return;
|
||||
if (strcmp(env, "none") == 0)
|
||||
trace_level = NFAPI_TRACE_NONE;
|
||||
else if (strcmp(env, "error") == 0)
|
||||
trace_level = NFAPI_TRACE_ERROR;
|
||||
else if (strcmp(env, "warn") == 0)
|
||||
trace_level = NFAPI_TRACE_WARN;
|
||||
else if (strcmp(env, "note") == 0)
|
||||
trace_level = NFAPI_TRACE_NOTE;
|
||||
else if (strcmp(env, "info") == 0)
|
||||
trace_level = NFAPI_TRACE_INFO;
|
||||
else if (strcmp(env, "debug") == 0)
|
||||
trace_level = NFAPI_TRACE_DEBUG;
|
||||
else
|
||||
{
|
||||
nfapi_trace(NFAPI_TRACE_ERROR, __func__, "Invalid NFAPI_TRACE_LEVEL='%s'", env);
|
||||
return;
|
||||
}
|
||||
nfapi_trace(trace_level, __func__, "NFAPI_TRACE_LEVEL='%s'", env);
|
||||
}
|
||||
|
||||
void nfapi_trace_dbg(nfapi_trace_level_t level, const char *format, ...)
|
||||
nfapi_trace_level_t nfapi_trace_level()
|
||||
{
|
||||
if (level < nfapi_trace_level_g)
|
||||
return;
|
||||
char trace_buff[MAX_MSG_LENGTH + TRACE_HEADER_LENGTH];
|
||||
va_list p_args;
|
||||
struct timeval tv;
|
||||
pthread_t tid = pthread_self();
|
||||
nfapi_trace_init();
|
||||
return trace_level;
|
||||
}
|
||||
|
||||
(void)gettimeofday(&tv, NULL);
|
||||
void nfapi_trace(nfapi_trace_level_t level,
|
||||
char const *caller,
|
||||
char const *format, ...)
|
||||
{
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
printf("%ld%06ld [%c] %10u: %s: ",
|
||||
ts.tv_sec,
|
||||
ts.tv_nsec / 1000,
|
||||
"XEWNID"[level], // NFAPI_TRACE_NONE, NFAPI_TRACE_ERROR, ...
|
||||
(unsigned) pthread_self(),
|
||||
caller);
|
||||
|
||||
snprintf(trace_buff, sizeof(trace_buff), "%04u.%06u: 0x%02x: %10u: ", ((uint32_t)tv.tv_sec) & 0x1FFF, (uint32_t)tv.tv_usec, (uint32_t)level, (uint32_t)tid);
|
||||
int n = strlen(trace_buff);
|
||||
va_start(p_args, format);
|
||||
vsnprintf(trace_buff + n, sizeof(trace_buff) - n, format, p_args);
|
||||
va_end(p_args);
|
||||
fputs(trace_buff, stdout);
|
||||
fflush(stdout);
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
vprintf(format, ap);
|
||||
va_end(ap);
|
||||
|
||||
// Add a newline if the format string didn't have one
|
||||
int len = strlen(format);
|
||||
if (len == 0 || format[len - 1] != '\n')
|
||||
putchar('\n');
|
||||
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user