aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinh-Quang Nguyen <minh-quang.nguyen@nutaq.com>2017-01-16 20:06:23 -0500
committerMinh-Quang Nguyen <minh-quang.nguyen@nutaq.com>2017-01-17 09:21:41 -0500
commit412946754d71378d8f23e819b7cbc84e9cc8c7c6 (patch)
treeb4b7ebeb3a2a33c156a62ea5cc7ba9eda927f424
parent390ac9725ff0c825fa38ca465c0c7c1f4dc84d28 (diff)
LC15: Refactor BTS manager
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_led.c113
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_led.h12
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_mgr.h26
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_mgr_temp.c10
-rw-r--r--src/osmo-bts-litecell15/misc/lc15bts_mgr_vty.c2
5 files changed, 85 insertions, 78 deletions
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_led.c b/src/osmo-bts-litecell15/misc/lc15bts_led.c
index 9899e9b3..85007914 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_led.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_led.c
@@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
-#include "lc15bts_mgr.h"
#include "lc15bts_led.h"
static struct lc15bts_led led_entries[] = {
@@ -41,25 +39,7 @@ static const struct value_string lc15bts_led_strs[] = {
{ 0, NULL }
};
-static struct lc15bts_sleep_time {
- int sleep_sec;
- int sleep_usec;
-};
-
-static struct lc15bts_led_timer {
- uint8_t idx;
- struct osmo_timer_list timer;
- struct lc15bts_sleep_time param;
-};
-
-static struct lc15bts_led_control {
- struct lc15bts_led_timer timers[_LC15BTS_LED_MAX];
- uint32_t led_flags;
-};
-
char *blink_pattern_command[] = BLINK_PATTERN_COMMAND;
-static char *current_blink_pattern;
-struct lc15bts_led_control lc15bts_leds;
static int lc15bts_led_write(char *path, char *str)
{
@@ -99,12 +79,13 @@ static void led_set_off()
lc15bts_led_write(led_entries[1].path, "0");
}
-static void led_sleep(struct lc15bts_led_timer *led_timer, void (*led_timer_cb)(void *_data)) {
+static void led_sleep( struct lc15bts_mgr_instance *mgr, struct lc15bts_led_timer *led_timer, void (*led_timer_cb)(void *_data)) {
/* Cancel any pending timer */
osmo_timer_del(&led_timer->timer);
/* Start LED timer */
led_timer->timer.cb = led_timer_cb;
- led_timer->timer.data = &led_timer->idx;
+ led_timer->timer.data = mgr;
+ mgr->lc15bts_leds.active_timer = led_timer->idx;
osmo_timer_schedule(&led_timer->timer, led_timer->param.sleep_sec, led_timer->param.sleep_usec);
LOGP(DTEMP, LOGL_DEBUG,"%s timer scheduled for %d sec + %d usec\n", get_value_string(lc15bts_led_strs, led_timer->idx), led_timer->param.sleep_sec, led_timer->param.sleep_usec);
@@ -127,30 +108,34 @@ static void led_sleep(struct lc15bts_led_timer *led_timer, void (*led_timer_cb)(
}
static void led_sleep_cb(void *_data) {
- uint8_t i, active_timer = *(uint8_t*)_data;
+ struct lc15bts_mgr_instance *mgr = _data;
+ uint8_t i, active_timer = mgr->lc15bts_leds.active_timer;
- osmo_timer_del(&lc15bts_leds.timers[active_timer].timer);
+ osmo_timer_del(&mgr->lc15bts_leds.timers[active_timer].timer);
- LOGP(DTEMP, LOGL_DEBUG,"%s timer expired in %d sec + %d usec \n", get_value_string(lc15bts_led_strs, active_timer), lc15bts_leds.timers[active_timer].param.sleep_sec, lc15bts_leds.timers[active_timer].param.sleep_usec);
+ LOGP(DTEMP, LOGL_DEBUG,"%s timer expired in %d sec + %d usec \n",
+ get_value_string(lc15bts_led_strs, active_timer),
+ mgr->lc15bts_leds.timers[active_timer].param.sleep_sec,
+ mgr->lc15bts_leds.timers[active_timer].param.sleep_usec);
/* start next LED timer */
- if (!strcmp(current_blink_pattern, blink_pattern_command[BLINK_PATTERN_VSWR_HIGH])) {
+ if (!strcmp(mgr->lc15bts_leds.current_blink_pattern, blink_pattern_command[BLINK_PATTERN_VSWR_HIGH])) {
switch (active_timer) {
case LC15BTS_LED_RED:
- if (lc15bts_leds.timers[LC15BTS_LED_GREEN].param.sleep_sec + lc15bts_leds.timers[LC15BTS_LED_GREEN].param.sleep_usec)
- led_sleep(&lc15bts_leds.timers[LC15BTS_LED_GREEN], led_sleep_cb);
+ if (mgr->lc15bts_leds.timers[LC15BTS_LED_GREEN].param.sleep_sec + mgr->lc15bts_leds.timers[LC15BTS_LED_GREEN].param.sleep_usec)
+ led_sleep(mgr, &mgr->lc15bts_leds.timers[LC15BTS_LED_GREEN], led_sleep_cb);
else
led_set_off();
break;
case LC15BTS_LED_GREEN:
- if (lc15bts_leds.timers[LC15BTS_LED_ORANGE].param.sleep_sec + lc15bts_leds.timers[LC15BTS_LED_ORANGE].param.sleep_usec)
- led_sleep(&lc15bts_leds.timers[LC15BTS_LED_ORANGE], led_sleep_cb);
+ if (mgr->lc15bts_leds.timers[LC15BTS_LED_ORANGE].param.sleep_sec + mgr->lc15bts_leds.timers[LC15BTS_LED_ORANGE].param.sleep_usec)
+ led_sleep(mgr, &mgr->lc15bts_leds.timers[LC15BTS_LED_ORANGE], led_sleep_cb);
else
led_set_off();
break;
case LC15BTS_LED_ORANGE:
- if (lc15bts_leds.timers[LC15BTS_LED_RED].param.sleep_sec + lc15bts_leds.timers[LC15BTS_LED_RED].param.sleep_usec)
- led_sleep(&lc15bts_leds.timers[LC15BTS_LED_RED], led_sleep_cb);
+ if (mgr->lc15bts_leds.timers[LC15BTS_LED_RED].param.sleep_sec + mgr->lc15bts_leds.timers[LC15BTS_LED_RED].param.sleep_usec)
+ led_sleep(mgr, &mgr->lc15bts_leds.timers[LC15BTS_LED_RED], led_sleep_cb);
else
led_set_off();
break;
@@ -159,16 +144,16 @@ static void led_sleep_cb(void *_data) {
}
} else {
for (i = 0; i < _LC15BTS_LED_MAX; i++) {
- if (i != lc15bts_leds.timers[active_timer].idx) {
- if (lc15bts_leds.timers[i].param.sleep_sec + lc15bts_leds.timers[i].param.sleep_usec) {
- led_sleep(&lc15bts_leds.timers[i], led_sleep_cb);
+ if (i != mgr->lc15bts_leds.timers[active_timer].idx) {
+ if (mgr->lc15bts_leds.timers[i].param.sleep_sec + mgr->lc15bts_leds.timers[i].param.sleep_usec) {
+ led_sleep(mgr, &mgr->lc15bts_leds.timers[i], led_sleep_cb);
}
}
}
}
}
-static void call_led_cmd(char *cmdstr)
+static void call_led_cmd(struct lc15bts_mgr_instance *mgr, char *cmdstr)
{
double sec, int_sec, frac_sec;
struct lc15bts_sleep_time led_param;
@@ -177,13 +162,13 @@ static void call_led_cmd(char *cmdstr)
led_param.sleep_usec = 0;
if (strstr(cmdstr, "set red") != NULL)
- lc15bts_leds.led_flags = LC15BTS_LED_RED;
+ mgr->lc15bts_leds.led_flags = LC15BTS_LED_RED;
else if (strstr(cmdstr, "set green") != NULL)
- lc15bts_leds.led_flags = LC15BTS_LED_GREEN;
+ mgr->lc15bts_leds.led_flags = LC15BTS_LED_GREEN;
else if (strstr(cmdstr, "set orange") != NULL)
- lc15bts_leds.led_flags = LC15BTS_LED_ORANGE;
+ mgr->lc15bts_leds.led_flags = LC15BTS_LED_ORANGE;
else if (strstr(cmdstr, "set off") != NULL)
- lc15bts_leds.led_flags = LC15BTS_LED_OFF;
+ mgr->lc15bts_leds.led_flags = LC15BTS_LED_OFF;
else if (strstr(cmdstr, "sleep") != NULL) {
sec = atof(cmdstr + 6);
/* split time into integer and fractional of seconds */
@@ -191,15 +176,15 @@ static void call_led_cmd(char *cmdstr)
led_param.sleep_sec = (int)int_sec;
led_param.sleep_usec = (int)frac_sec;
- if ((lc15bts_leds.led_flags >= LC15BTS_LED_RED) && (lc15bts_leds.led_flags < _LC15BTS_LED_MAX)) {
- lc15bts_leds.timers[lc15bts_leds.led_flags].param = led_param;
- lc15bts_leds.timers[lc15bts_leds.led_flags].idx = lc15bts_leds.led_flags;
+ if ((mgr->lc15bts_leds.led_flags >= LC15BTS_LED_RED) && (mgr->lc15bts_leds.led_flags < _LC15BTS_LED_MAX)) {
+ mgr->lc15bts_leds.timers[mgr->lc15bts_leds.led_flags].param = led_param;
+ mgr->lc15bts_leds.timers[mgr->lc15bts_leds.led_flags].idx = mgr->lc15bts_leds.led_flags;
LOGP(DTEMP, LOGL_DEBUG,"%s control flags = 0x%x, %f = %d sec + %d usec\n",
- get_value_string(lc15bts_led_strs, lc15bts_leds.led_flags),
- lc15bts_leds.led_flags, sec,
- lc15bts_leds.timers[lc15bts_leds.led_flags].param.sleep_sec,
- lc15bts_leds.timers[lc15bts_leds.led_flags].param.sleep_usec);
+ get_value_string(lc15bts_led_strs, mgr->lc15bts_leds.led_flags),
+ mgr->lc15bts_leds.led_flags, sec,
+ mgr->lc15bts_leds.timers[mgr->lc15bts_leds.led_flags].param.sleep_sec,
+ mgr->lc15bts_leds.timers[mgr->lc15bts_leds.led_flags].param.sleep_usec);
}
} else
LOGP(DTEMP, LOGL_ERROR,"Command not found\n");
@@ -207,7 +192,7 @@ static void call_led_cmd(char *cmdstr)
return;
}
-static void led_light_pattern(char *pattern)
+static void led_light_pattern(char *pattern, struct lc15bts_mgr_instance *mgr)
{
char str[1024];
char *pstr;
@@ -216,34 +201,34 @@ static void led_light_pattern(char *pattern)
strcpy(str, pattern);
pstr = str;
while ((sep = strsep(&pstr, ";")) != NULL) {
- call_led_cmd(sep);
+ call_led_cmd(mgr, sep);
}
}
-static void led_set_pattern(char *pattern)
+static void led_set_pattern(struct lc15bts_mgr_instance *mgr, char *pattern)
{
int i;
- if (current_blink_pattern != pattern) {
- current_blink_pattern = pattern;
- LOGP(DTEMP, LOGL_NOTICE,"LED pattern changed to %s\n", pattern);
+ if (mgr->lc15bts_leds.current_blink_pattern != pattern) {
+ mgr->lc15bts_leds.current_blink_pattern = pattern;
+ LOGP(DTEMP, LOGL_NOTICE,"LED pattern changed to %s\n", mgr->lc15bts_leds.current_blink_pattern);
for (i = 0; i < _LC15BTS_LED_MAX; i++) {
/* delete all LED timers */
- osmo_timer_del(&lc15bts_leds.timers[i].timer);
+ osmo_timer_del(&mgr->lc15bts_leds.timers[i].timer);
/* re-initialize everything */
- lc15bts_leds.timers[i].param.sleep_sec = 0;
- lc15bts_leds.timers[i].param.sleep_usec = 0;
- lc15bts_leds.led_flags = 0;
+ mgr->lc15bts_leds.timers[i].param.sleep_sec = 0;
+ mgr->lc15bts_leds.timers[i].param.sleep_usec = 0;
+ mgr->lc15bts_leds.led_flags = 0;
}
/* trigger new LED pattern */
led_set_off();
- led_ctrl_check();
+ led_ctrl_check(mgr);
}
}
/*** led interface ***/
-void led_set(int pattern_id)
+void led_set(struct lc15bts_mgr_instance *mgr, int pattern_id)
{
if (pattern_id > BLINK_PATTERN_MAX_ITEM - 1) {
LOGP(DTEMP, LOGL_ERROR, "Invalid LED pattern : %d. LED pattern must be between %d..%d\n",
@@ -253,19 +238,19 @@ void led_set(int pattern_id)
return;
}
LOGP(DTEMP, LOGL_NOTICE, "blink pattern command : %d\n", pattern_id);
- led_set_pattern(blink_pattern_command[pattern_id]);
+ led_set_pattern(mgr, blink_pattern_command[pattern_id]);
}
-void led_ctrl_check(void)
+void led_ctrl_check(struct lc15bts_mgr_instance *mgr)
{
int i;
- led_light_pattern(current_blink_pattern);
+ led_light_pattern(mgr->lc15bts_leds.current_blink_pattern, mgr);
/* Start expected LED timers only */
for (i = 0; i < _LC15BTS_LED_MAX; i++) {
- if (lc15bts_leds.timers[i].param.sleep_sec + lc15bts_leds.timers[i].param.sleep_usec) {
- led_sleep(&lc15bts_leds.timers[i], led_sleep_cb);
+ if (mgr->lc15bts_leds.timers[i].param.sleep_sec + mgr->lc15bts_leds.timers[i].param.sleep_usec) {
+ led_sleep(mgr, &mgr->lc15bts_leds.timers[i], led_sleep_cb);
}
}
}
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_led.h b/src/osmo-bts-litecell15/misc/lc15bts_led.h
index e035fe18..0eed42cb 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_led.h
+++ b/src/osmo-bts-litecell15/misc/lc15bts_led.h
@@ -12,16 +12,10 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/utils.h>
-enum LC15BTS_LED_ENUM {
- LC15BTS_LED_RED = 0,
- LC15BTS_LED_GREEN,
- LC15BTS_LED_ORANGE,
- LC15BTS_LED_OFF,
- _LC15BTS_LED_MAX
-};
+#include "lc15bts_mgr.h"
/* public function prototypes */
-void led_set(int pattern_id);
-void led_ctrl_check(void);
+void led_set(struct lc15bts_mgr_instance *mgr, int pattern_id);
+void led_ctrl_check(struct lc15bts_mgr_instance *mgr);
#endif
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_mgr.h b/src/osmo-bts-litecell15/misc/lc15bts_mgr.h
index d79bd870..82adc6c6 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_mgr.h
+++ b/src/osmo-bts-litecell15/misc/lc15bts_mgr.h
@@ -76,6 +76,14 @@ enum lc15bts_sensor_state {
STATE_CRITICAL, /* We have an issue. Wait for below warning */
};
+enum lc15bts_leds_name {
+ LC15BTS_LED_RED = 0,
+ LC15BTS_LED_GREEN,
+ LC15BTS_LED_ORANGE,
+ LC15BTS_LED_OFF,
+ _LC15BTS_LED_MAX
+};
+
struct lc15bts_alarms{
int high_temp;
int max_temp;
@@ -113,6 +121,17 @@ struct lc15bts_vswr_limit {
int thresh_crit_max;
};
+struct lc15bts_sleep_time {
+ int sleep_sec;
+ int sleep_usec;
+};
+
+struct lc15bts_led_timer {
+ uint8_t idx;
+ struct osmo_timer_list timer;
+ struct lc15bts_sleep_time param;
+};
+
enum mgr_vty_node {
MGR_NODE = _LAST_OSMOVTY_NODE + 1,
@@ -177,6 +196,13 @@ struct lc15bts_mgr_instance {
int calib_from_loop;
struct osmo_timer_list calib_timeout;
} calib;
+
+ struct {
+ struct lc15bts_led_timer timers[_LC15BTS_LED_MAX];
+ uint32_t led_flags;
+ char *current_blink_pattern;
+ uint8_t active_timer;
+ } lc15bts_leds;
};
int lc15bts_mgr_vty_init(void);
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_mgr_temp.c b/src/osmo-bts-litecell15/misc/lc15bts_mgr_temp.c
index d087502b..38e3d578 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_mgr_temp.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_mgr_temp.c
@@ -589,15 +589,16 @@ void select_led_pattern(struct lc15bts_mgr_instance *mgr)
/* check by priority */
for (i = 0; i < sizeof(led_priority)/sizeof(uint8_t); i++) {
if(led[led_priority[i]] == 1) {
- led_set(led_priority[i]);
+ led_set(mgr, led_priority[i]);
break;
}
}
}
-static void led_ctrl_check_cb(void *unused)
+static void led_ctrl_check_cb(void *_data)
{
- led_ctrl_check();
+ struct lc15bts_mgr_instance *mgr = _data;
+ led_ctrl_check(mgr);
/* Check every minute? XXX make it configurable! */
osmo_timer_schedule(&led_ctrl_timer, 60, 0);
LOGP(DTEMP, LOGL_DEBUG,"LED control timer expired\n");
@@ -607,7 +608,8 @@ int lc15bts_mgr_led_init(struct lc15bts_mgr_instance *mgr)
{
s_mgr = mgr;
led_ctrl_timer.cb = led_ctrl_check_cb;
- led_ctrl_check_cb(NULL);
+ led_ctrl_timer.data = s_mgr;
+ led_ctrl_check_cb(s_mgr);
return 0;
}
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_mgr_vty.c b/src/osmo-bts-litecell15/misc/lc15bts_mgr_vty.c
index daa7c81e..9c338139 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_mgr_vty.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_mgr_vty.c
@@ -730,7 +730,7 @@ DEFUN(set_led_pattern, set_led_pattern_cmd,
return CMD_WARNING;
}
- led_set(pattern_id);
+ led_set(s_mgr, pattern_id);
return CMD_SUCCESS;
}