1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
20 * @brief This file has the command line interface for the testmac application
21 * @file nr5g_fapi_cmd.c
22 * @ingroup group_source_utils
23 * @author Intel Corporation
26 #include "nr5g_fapi_std.h"
27 #include "nr5g_fapi_framework.h"
28 #include "nr5g_fapi_wls.h"
32 #define ORAN_5G_FAPI_LOGO "ORAN_5G_FAPI>"
35 NR5G_FAPI_CMGR_HELP = 0,
38 NR5G_FAPI_CMGR_WLS_STATS,
42 static char nr5g_fapi_cmd_registry[NUM_CMDS][CMD_SIZE] = {
43 {"help"}, {"exit"}, {"version"}, {"show wls stats"}
46 static char *nr5g_fapi_cmgr_char_get(
49 static char str[CMD_SIZE + 2];
52 while ((ch = getchar()) != EOF && n < CMD_SIZE && ch != '\n') {
57 if (n > 0 && n < CMD_SIZE) {
65 static int nr5g_fapi_cmgr_type(
69 for (i = 0; i < NUM_CMDS; i++) {
70 nr5g_fapi_cmd_registry[i][sizeof(nr5g_fapi_cmd_registry[i]) - 1] = 0;
71 len = strlen(nr5g_fapi_cmd_registry[i]);
73 if (!strncmp(cmd, nr5g_fapi_cmd_registry[i], len)) {
79 return NR5G_FAPI_CMGR_NULL;
82 //-------------------------------------------------------------------------------------------
83 /** @ingroup group_testmac
85 * @param[in] paramc Number of command line parameters
86 * @param[in] params Pointer to structure that has the command line parameter
87 * @param[in] *cmd_param Pointer to additional parameters
89 * @return 0 if SUCCESS
92 * This function prints the oran_5g_fapi version to the oran_5g_fapi console
95 //-------------------------------------------------------------------------------------------
96 static void nr5g_fapi_cmd_print_version(
99 //printf("\n ORAN_5G_FAPI Version: \n");
102 //-------------------------------------------------------------------------------------------
103 /** @ingroup group_testmac
105 * @param[in] paramc Number of command line parameters
106 * @param[in] params Pointer to structure that has the command line parameter
107 * @param[in] *cmd_param Pointer to additional parameters
109 * @return 0 if SUCCESS
112 * This function exits the testmac application
115 //-------------------------------------------------------------------------------------------
116 static void nr5g_fapi_cmd_exit(
117 p_nr5g_fapi_phy_ctx_t p_phy_ctx)
119 p_phy_ctx->process_exit = 0;
120 printf("Exitting App...\n");
124 //-------------------------------------------------------------------------------------------
125 /** @ingroup group_testmac
127 * @param[in] paramc Number of command line parameters
128 * @param[in] params Pointer to structure that has the command line parameter
129 * @param[in] *cmd_param Pointer to additional parameters
131 * @return 0 if SUCCESS
134 * This function lists all the pre-registered function and associated commands on screen.
135 * The commands are sorted alphabetically.
138 //-------------------------------------------------------------------------------------------
139 static void nr5g_fapi_cmd_help(
145 //-------------------------------------------------------------------------------------------
146 /** @ingroup group_testmac
148 * @param[in] paramc Number of command line parameters
149 * @param[in] params Pointer to structure that has the command line parameter
150 * @param[in] *cmd_param Pointer to additional parameters
152 * @return 0 if SUCCESS
155 * This function lists all the pre-registered function and associated commands on screen.
156 * The commands are sorted alphabetically.
159 //-------------------------------------------------------------------------------------------
160 static void nr5g_fapi_cmd_wls_stats(
163 nr5g_fapi_wls_print_stats();
166 //-------------------------------------------------------------------------------------------
167 /** @ingroup group_testmac
171 * @return 0 if SUCCESS
174 * This function initializes all the pre-defined commands with associated functions for the testmac
175 * application. It iscalled on system bootup
178 //-------------------------------------------------------------------------------------------
182 static int process_exit = 1;
186 //p_nr5g_fapi_cfg_t cfg = (p_nr5g_fapi_cfg_t) config; // start up config
187 p_nr5g_fapi_phy_ctx_t p_phy_ctx = nr5g_fapi_get_nr5g_fapi_phy_ctx();
191 while (process_exit) {
192 printf("%s", ORAN_5G_FAPI_LOGO);
194 cmd = nr5g_fapi_cmgr_char_get();
198 cmd_type = nr5g_fapi_cmgr_type(cmd);
200 case NR5G_FAPI_CMGR_VERS:
201 nr5g_fapi_cmd_print_version();
204 case NR5G_FAPI_CMGR_HELP:
205 nr5g_fapi_cmd_help();
208 case NR5G_FAPI_CMGR_EXIT:
209 nr5g_fapi_cmd_exit(p_phy_ctx);
212 case NR5G_FAPI_CMGR_WLS_STATS:
213 nr5g_fapi_cmd_wls_stats();
216 case NR5G_FAPI_CMGR_NULL:
218 printf("Warning: command (%s) not present\n", cmd);