sysmobts-mgr: Make it possible to not write to the EEPROM

For testing/trial it is better to not write to the EEPROM
but it is still good to see how the logic is working.
This commit is contained in:
Holger Hans Peter Freyther 2014-01-16 13:49:50 +01:00
parent 3e110ae141
commit 19224b4b9b
3 changed files with 53 additions and 18 deletions

View File

@ -1,6 +1,7 @@
/* Main program for SysmoBTS management daemon */
/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
* (C) 2014 by Holger Hans Peter Freyther
*
* All Rights Reserved
*
@ -39,6 +40,7 @@
#include "misc/sysmobts_misc.h"
#include "misc/sysmobts_mgr.h"
static int no_eeprom_write = 0;
static int daemonize = 0;
void *tall_mgr_ctx;
@ -51,7 +53,7 @@ void *tall_mgr_ctx;
static struct osmo_timer_list temp_timer;
static void check_temp_timer_cb(void *unused)
{
sysmobts_check_temp();
sysmobts_check_temp(no_eeprom_write);
osmo_timer_schedule(&temp_timer, TEMP_TIMER_SECS, 0);
}
@ -59,19 +61,45 @@ static void check_temp_timer_cb(void *unused)
static struct osmo_timer_list hours_timer;
static void hours_timer_cb(void *unused)
{
sysmobts_update_hours();
sysmobts_update_hours(no_eeprom_write);
osmo_timer_schedule(&hours_timer, HOURS_TIMER_SECS, 0);
}
static void print_help(void)
{
printf("sysmobts-mgr [-n]\n");
printf(" -n Do not write to EEPROM\n");
}
static int parse_options(int argc, char **argv)
{
int opt;
while ((opt = getopt(argc, argv, "nh")) != -1) {
switch (opt) {
case 'n':
no_eeprom_write = 1;
break;
case 'h':
print_help();
return -1;
default:
return -1;
}
}
return 0;
}
static void signal_handler(int signal)
{
fprintf(stderr, "signal %u received\n", signal);
switch (signal) {
case SIGINT:
sysmobts_check_temp();
sysmobts_update_hours();
sysmobts_check_temp(no_eeprom_write);
sysmobts_update_hours(no_eeprom_write);
exit(0);
break;
case SIGABRT:
@ -126,12 +154,14 @@ int main(int argc, char **argv)
void *tall_msgb_ctx;
int rc;
rc = parse_options(argc, argv);
if (rc < 0)
exit(2);
tall_mgr_ctx = talloc_named_const(NULL, 1, "bts manager");
tall_msgb_ctx = talloc_named_const(tall_mgr_ctx, 1, "msgb");
msgb_set_talloc_ctx(tall_msgb_ctx);
//handle_options(argc, argv);
mgr_log_init(NULL);
signal(SIGINT, &signal_handler);

View File

@ -106,7 +106,7 @@ static const struct {
}
};
void sysmobts_check_temp(void)
void sysmobts_check_temp(int no_eeprom_write)
{
int temp_old[ARRAY_SIZE(temp_data)];
int temp_hi[ARRAY_SIZE(temp_data)];
@ -135,12 +135,15 @@ void sysmobts_check_temp(void)
LOGP(DTEMP, LOGL_NOTICE, "New maximum %s "
"temperature: %d.%d C\n", temp_data[i].name,
temp_hi[i]/1000, temp_hi[i]%1000);
rc = sysmobts_par_set_int(SYSMOBTS_PAR_TEMP_DIG_MAX,
if (!no_eeprom_write) {
rc = sysmobts_par_set_int(SYSMOBTS_PAR_TEMP_DIG_MAX,
temp_hi[0]/1000);
if (rc < 0)
LOGP(DTEMP, LOGL_ERROR, "error writing new %s "
"max temp %d (%s)\n", temp_data[i].name,
rc, strerror(errno));
if (rc < 0)
LOGP(DTEMP, LOGL_ERROR, "error writing new %s "
"max temp %d (%s)\n", temp_data[i].name,
rc, strerror(errno));
}
}
}
}
@ -150,7 +153,7 @@ void sysmobts_check_temp(void)
*********************************************************************/
static time_t last_update;
int sysmobts_update_hours(void)
int sysmobts_update_hours(int no_eeprom_write)
{
time_t now = time(NULL);
int rc, op_hrs;
@ -188,9 +191,11 @@ int sysmobts_update_hours(void)
LOGP(DTEMP, LOGL_INFO, "Total hours of Operation: %u\n",
op_hrs);
rc = sysmobts_par_set_int(SYSMOBTS_PAR_HOURS, op_hrs);
if (rc < 0)
return rc;
if (!no_eeprom_write) {
rc = sysmobts_par_set_int(SYSMOBTS_PAR_HOURS, op_hrs);
if (rc < 0)
return rc;
}
last_update = now;
}

View File

@ -16,9 +16,9 @@ enum sysmobts_temp_type {
int sysmobts_temp_get(enum sysmobts_temp_sensor sensor,
enum sysmobts_temp_type type);
void sysmobts_check_temp(void);
void sysmobts_check_temp(int no_eeprom_write);
int sysmobts_update_hours(void);
int sysmobts_update_hours(int no_epprom_write);
enum sysmobts_firmware_type {
SYSMOBTS_FW_FPGA,