aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
blob: 1cabe44afdbcd45fb67827192d42d3705bb2dde3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* (C) 2014 by sysmocom - s.f.m.c. GmbH
 *
 * All Rights Reserved
 *
 * Author: Alvaro Neira Ayuso <anayuso@sysmocom.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/misc.h>

#include <osmo-bts/logging.h>

#include "sysmobts_misc.h"
#include "sysmobts_mgr.h"
#include "btsconfig.h"

static const char copyright[] =
	"(C) 2012 by Harald Welte <laforge@gnumonks.org>\r\n"
	"(C) 2014 by Holger Hans Peter Freyther\r\n"
	"License AGPLv3+: GNU AGPL version 2 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
	"This is free software: you are free to change and redistribute it.\r\n"
	"There is NO WARRANTY, to the extent permitted by law.\r\n";

static enum node_type go_to_parent(struct vty *vty)
{
	switch (vty->node) {
	case MGR_NODE:
		vty->node = CONFIG_NODE;
		break;
	default:
		vty->node = CONFIG_NODE;
	}
	return vty->node;
}

static int is_config_node(struct vty *vty, int node)
{
	switch (node) {
	case MGR_NODE:
		return 1;
	default:
		return 0;
	}
}

static struct vty_app_info vty_info = {
	.name           = "sysmobts-mgr",
	.version        = PACKAGE_VERSION,
	.go_parent_cb   = go_to_parent,
	.is_config_node = is_config_node,
	.copyright	= copyright,
};


#define MGR_STR			"Configure sysmobts-mgr\n"

static struct cmd_node mgr_node = {
	MGR_NODE,
	"%s(sysmobts-mgr)# ",
	1,
};

DEFUN(cfg_mgr, cfg_mgr_cmd,
	"sysmobts-mgr",
	MGR_STR)
{
	vty->node = MGR_NODE;
	return CMD_SUCCESS;
}

DEFUN(show_mgr, show_mgr_cmd, "show manager",
      SHOW_STR "Display information about the manager")
{
	vty_out(vty, "Current Temperatures%s", VTY_NEWLINE);
	vty_out(vty, " Digital: %f Celcius%s",
		sysmobts_temp_get(SYSMOBTS_TEMP_DIGITAL,
					SYSMOBTS_TEMP_INPUT) / 1000.0f,
		VTY_NEWLINE);
	vty_out(vty, " RF:      %f Celcius%s",
		sysmobts_temp_get(SYSMOBTS_TEMP_RF,
					SYSMOBTS_TEMP_INPUT) / 1000.0f,
		VTY_NEWLINE);
	if (is_sbts2050_master()) {
		int temp_pa, temp_board;
		struct sbts2050_power_status status;

		sbts2050_uc_check_temp(&temp_pa, &temp_board);
		vty_out(vty, " sysmoBTS 2050 PA: %d Celcius%s", temp_pa, VTY_NEWLINE);
		vty_out(vty, " sysmoBTS 2050 PA: %d CelciusC%s", temp_board, VTY_NEWLINE);

		sbts2050_uc_get_status(&status);
		vty_out(vty, "Power Status%s", VTY_NEWLINE);
		vty_out(vty, " Main Supply :(ON)  [(24.00)Vdc, %4.2f A]%s",
			status.main_supply_current, VTY_NEWLINE);
		vty_out(vty, " Master SF   : %s  [%6.2f Vdc, %4.2f A]%s",
			status.master_enabled ? "ON " : "OFF",
			status.master_voltage, status.master_current,
			VTY_NEWLINE);
		vty_out(vty, " Slave SF    : %s   [%6.2f Vdc, %4.2f A]%s",
			status.slave_enabled ? "ON" : "OFF",
			status.slave_voltage, status.slave_current,
			VTY_NEWLINE);
		vty_out(vty, " Power Amp   : %s  [%6.2f Vdc, %4.2f A]%s",
			status.pa_enabled ? "ON" : "OFF",
			status.pa_voltage, status.pa_current,
			VTY_NEWLINE);
		vty_out(vty, " PA Bias     : %s  [%6.2f Vdc, ---- A]%s",
			status.pa_enabled ? "ON" : "OFF",
			status.pa_bias_voltage,
			VTY_NEWLINE);
	}

	return CMD_SUCCESS;
}

static int config_write_mgr(struct vty *vty)
{
	vty_out(vty, "sysmobts-mgr%s", VTY_NEWLINE);
	return CMD_SUCCESS;
}

int sysmobts_mgr_vty_init(void)
{
	vty_init(&vty_info);

	install_element_ve(&show_mgr_cmd);

	install_node(&mgr_node, config_write_mgr);
	install_element(CONFIG_NODE, &cfg_mgr_cmd);
	vty_install_default(MGR_NODE);

	return 0;
}

int sysmobts_mgr_parse_config(const char *config_file)
{
	int rc;

	rc = vty_read_config_file(config_file, NULL);
	if (rc < 0) {
		fprintf(stderr, "Failed to parse the config file: '%s'\n",
				config_file);
		return rc;
	}

	return 0;
}