Add 'capi ifcstatus' CLI command
This commit is contained in:
parent
10384d0bbf
commit
e957372537
13
chan_capi.c
13
chan_capi.c
|
@ -8237,6 +8237,9 @@ static struct ast_cli_entry cc_cli_cmd[] = {
|
|||
AST_CLI_DEFINE(pbxcli_capi_qsig_do_debug, CC_CLI_TEXT_QSIG_DEBUG),
|
||||
AST_CLI_DEFINE(pbxcli_capi_qsig_no_debug, CC_CLI_TEXT_QSIG_NO_DEBUG),
|
||||
AST_CLI_DEFINE(pbxcli_capi_chatinfo, CC_CLI_TEXT_CHATINFO),
|
||||
#ifdef DIVA_STATUS
|
||||
AST_CLI_DEFINE(pbxcli_capi_ifc_status, CC_CLI_TEXT_IFC_STATUSINFO),
|
||||
#endif
|
||||
};
|
||||
#else
|
||||
static struct ast_cli_entry cli_info =
|
||||
|
@ -8253,6 +8256,10 @@ static struct ast_cli_entry cli_qsig_no_debug =
|
|||
{ { CC_MESSAGE_NAME, "qsig", "no", "debug", NULL }, pbxcli_capi_qsig_no_debug, CC_CLI_TEXT_QSIG_NO_DEBUG, qsig_no_debug_usage };
|
||||
static struct ast_cli_entry cli_chatinfo =
|
||||
{ { CC_MESSAGE_NAME, "chatinfo", NULL }, pbxcli_capi_chatinfo, CC_CLI_TEXT_CHATINFO, chatinfo_usage };
|
||||
#ifdef DIVA_STATUS
|
||||
static struct ast_cli_entry cli_ifcstate =
|
||||
{ { CC_MESSAGE_NAME, "ifcstate", NULL }, pbxcli_capi_ifc_status, CC_CLI_TEXT_IFC_STATUSINFO, diva_status_ifc_state_usage };
|
||||
#endif
|
||||
#endif
|
||||
|
||||
const struct ast_channel_tech capi_tech = {
|
||||
|
@ -8893,6 +8900,9 @@ int unload_module(void)
|
|||
ast_cli_unregister(&cli_qsig_debug);
|
||||
ast_cli_unregister(&cli_qsig_no_debug);
|
||||
ast_cli_unregister(&cli_chatinfo);
|
||||
#ifdef DIVA_STATUS
|
||||
ast_cli_unregister(&cli_ifcstate);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CC_AST_HAS_VERSION_1_4
|
||||
|
@ -9016,6 +9026,9 @@ int load_module(void)
|
|||
ast_cli_register(&cli_qsig_debug);
|
||||
ast_cli_register(&cli_qsig_no_debug);
|
||||
ast_cli_register(&cli_chatinfo);
|
||||
#ifdef DIVA_STATUS
|
||||
ast_cli_register(&cli_ifcstate);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ast_register_application(commandapp, pbx_capicommand_exec, commandsynopsis, commandtdesc);
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include "divastatus_parameters.h"
|
||||
#include "divastatus_ifc.h"
|
||||
#include "divastatus.h"
|
||||
#define CC_USE_INOTIFY
|
||||
//#define CC_USE_INOTIFY
|
||||
#ifdef CC_USE_INOTIFY
|
||||
#include <fcntl.h>
|
||||
#include <sys/inotify.h>
|
||||
|
@ -77,6 +77,14 @@ static void diva_status_cleanup_wd(int wd);
|
|||
static int divaFsWd = -1; /*! \brief Diva fs state */
|
||||
#endif
|
||||
|
||||
#ifdef CC_AST_HAS_VERSION_1_6
|
||||
static
|
||||
#endif
|
||||
char diva_status_ifc_state_usage[] =
|
||||
"Usage: " CC_MESSAGE_NAME " ifcstate\n"
|
||||
" Show info about interfaces.\n";
|
||||
|
||||
|
||||
static int inotifyFd = -1; /*! \brief inotify descriptor */
|
||||
static diva_entity_queue_t controller_q; /*! \brief Active controllers. \note List changed only while CAPI thread is not running */
|
||||
|
||||
|
@ -431,26 +439,26 @@ static int diva_status_get_controller_state(int controller, diva_status_ifc_stat
|
|||
|
||||
case DivaStateIfcState_LAYER2_STATE:
|
||||
if (state->ifcType == DivaStatusIfcPri) {
|
||||
state->ifcL1State = (strcmp ("'Layer2 UP'", v) == 0) ? DivaStatusIfcL2OK : DivaStatusIfcL2Error;
|
||||
state->ifcL2State = (strcmp ("'Layer2 UP'", v) == 0) ? DivaStatusIfcL2OK : DivaStatusIfcL2Error;
|
||||
}
|
||||
break;
|
||||
|
||||
case DivaStateIfcState_D2_X_FRAMES:
|
||||
case DivaStateIfcState_D1_X_FRAMES:
|
||||
state->ifcTxDStatistics.Frames = (unsigned int)atol(v);
|
||||
break;
|
||||
case DivaStateIfcState_D2_X_BYTES:
|
||||
case DivaStateIfcState_D1_X_BYTES:
|
||||
state->ifcTxDStatistics.Bytes = (unsigned int)atol(v);
|
||||
break;
|
||||
case DivaStateIfcState_D2_X_ERRORS:
|
||||
case DivaStateIfcState_D1_X_ERRORS:
|
||||
state->ifcTxDStatistics.Errors = (unsigned int)atol(v);
|
||||
break;
|
||||
case DivaStateIfcState_D2_R_FRAMES:
|
||||
case DivaStateIfcState_D1_R_FRAMES:
|
||||
state->ifcRxDStatistics.Frames = (unsigned int)atol(v);
|
||||
break;
|
||||
case DivaStateIfcState_D2_R_BYTES:
|
||||
case DivaStateIfcState_D1_R_BYTES:
|
||||
state->ifcRxDStatistics.Bytes = (unsigned int)atol(v);
|
||||
break;
|
||||
case DivaStateIfcState_D2_R_ERRORS:
|
||||
case DivaStateIfcState_D1_R_ERRORS:
|
||||
state->ifcRxDStatistics.Errors = (unsigned int)atol(v);
|
||||
break;
|
||||
|
||||
|
@ -475,15 +483,15 @@ static int diva_status_get_controller_state(int controller, diva_status_ifc_stat
|
|||
ast_free (data);
|
||||
|
||||
if ((data = diva_status_read_file(controller, DIVA_READ_ALARM_FILE)) != 0) {
|
||||
state->ifcAlarms.Red = strcmp("TRUE", data);
|
||||
state->ifcAlarms.Red = strcmp("TRUE", data) == 0;
|
||||
ast_free(data);
|
||||
}
|
||||
if ((data = diva_status_read_file(controller, DIVA_YELLOW_ALARM_FILE)) != 0) {
|
||||
state->ifcAlarms.Yellow = strcmp("TRUE", data);
|
||||
state->ifcAlarms.Yellow = strcmp("TRUE", data) == 0;
|
||||
ast_free(data);
|
||||
}
|
||||
if ((data = diva_status_read_file(controller, DIVA_BLUE_ALARM_FILE)) != 0) {
|
||||
state->ifcAlarms.Blue = strcmp("TRUE", data);
|
||||
state->ifcAlarms.Blue = strcmp("TRUE", data) == 0;
|
||||
ast_free(data);
|
||||
}
|
||||
if ((data = diva_status_read_file(controller, DIVA_SERIAL_FILE)) != 0) {
|
||||
|
@ -585,7 +593,7 @@ const char* diva_status_interface_state_name(diva_status_interface_state_t state
|
|||
|
||||
case DivaStatusInterfaceStateNotAvailable:
|
||||
default:
|
||||
return "not available";
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -603,3 +611,66 @@ const char* diva_status_hw_state_name(diva_status_hardware_state_t hwState)
|
|||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef CC_AST_HAS_VERSION_1_6
|
||||
char *pbxcli_capi_ifc_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
#else
|
||||
int pbxcli_capi_ifc_status(int fd, int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
diva_entity_link_t* link;
|
||||
#ifdef CC_AST_HAS_VERSION_1_6
|
||||
int fd = a->fd;
|
||||
|
||||
if (cmd == CLI_INIT) {
|
||||
e->command = CC_MESSAGE_NAME " ifcstate";
|
||||
e->usage = diva_status_ifc_state_usage;
|
||||
return NULL;
|
||||
} else if (cmd == CLI_GENERATE)
|
||||
return NULL;
|
||||
if (a->argc != e->args)
|
||||
return CLI_SHOWUSAGE;
|
||||
#else
|
||||
|
||||
if (argc != 2)
|
||||
return RESULT_SHOWUSAGE;
|
||||
#endif
|
||||
|
||||
if ( diva_q_get_head(&controller_q) == NULL) {
|
||||
ast_cli(fd, "There are no interraces in " CC_MESSAGE_NAME " instance.\n");
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ast_cli(fd, CC_MESSAGE_NAME " interfaces\n");
|
||||
ast_cli(fd, "%s %-9s%-4s%-4s%-4s%-7s%-5s%8s%12s%12s%12s%12s\n",
|
||||
"CAPI#", "State", "L1", "L2", "RED", "YELLOW", "BLUE", "D-Rx-Frames", "D-Rx-Bytes","D-Tx-Frames", "D-Tx-Bytes", "D-Errors");
|
||||
|
||||
for (link = diva_q_get_head(&controller_q); link != 0; link = diva_q_get_next(link)) {
|
||||
diva_status_ifc_t *controllerState = DIVAS_CONTAINING_RECORD(link, diva_status_ifc_t, link);
|
||||
diva_status_ifc_state_t* state = &controllerState->state[controllerState->currentState];
|
||||
ast_cli(fd, "%3d%-2s %-9s%-4s%-4s%-4s%-7s%-3s %12d %11d %11d %11d %11d\n",
|
||||
controllerState->capiController, "",
|
||||
diva_status_interface_state_name(diva_status_get_interface_state_from_idi_state (state)),
|
||||
((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ?
|
||||
(state->ifcL1State == DivaStatusIfcL1OK ? "On" : "Off") : "-",
|
||||
((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ?
|
||||
(state->ifcL2State == DivaStatusIfcL2OK ? "On" : "Off") : "-",
|
||||
((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ?
|
||||
(state->ifcAlarms.Red != 0 ? "On" : "Off") : "-",
|
||||
((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ?
|
||||
(state->ifcAlarms.Yellow != 0 ? "On" : "Off") : "-",
|
||||
((state->ifcType == DivaStatusIfcPri) && (state->hwState == DivaStatusHardwareStateOK)) ?
|
||||
(state->ifcAlarms.Blue != 0 ? "On" : "Off") : "-",
|
||||
state->ifcRxDStatistics.Frames, state->ifcRxDStatistics.Bytes,
|
||||
state->ifcTxDStatistics.Frames, state->ifcTxDStatistics.Bytes,
|
||||
state->ifcRxDStatistics.Errors + state->ifcTxDStatistics.Errors
|
||||
);
|
||||
}
|
||||
|
||||
#ifdef CC_AST_HAS_VERSION_1_6
|
||||
return CLI_SUCCESS;
|
||||
#else
|
||||
return RESULT_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -83,6 +83,15 @@ diva_status_interface_state_t diva_status_get_interface_state(int controller);
|
|||
const char* diva_status_interface_state_name(diva_status_interface_state_t state);
|
||||
const char* diva_status_hw_state_name(diva_status_hardware_state_t hwState);
|
||||
|
||||
#ifdef CC_AST_HAS_VERSION_1_6
|
||||
char *pbxcli_capi_ifc_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
|
||||
#else
|
||||
int pbxcli_capi_ifc_status(int fd, int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
#define CC_CLI_TEXT_IFC_STATUSINFO "Show " CC_MESSAGE_BIGNAME " interface info"
|
||||
#ifndef CC_AST_HAS_VERSION_1_6
|
||||
extern char diva_status_ifc_state_usage[];
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue