diff options
Diffstat (limited to 'src/osmo-bts-litecell15/misc/lc15bts_misc.c')
-rw-r--r-- | src/osmo-bts-litecell15/misc/lc15bts_misc.c | 335 |
1 files changed, 328 insertions, 7 deletions
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_misc.c b/src/osmo-bts-litecell15/misc/lc15bts_misc.c index 5ff8e312..0aeb3842 100644 --- a/src/osmo-bts-litecell15/misc/lc15bts_misc.c +++ b/src/osmo-bts-litecell15/misc/lc15bts_misc.c @@ -41,11 +41,13 @@ #include <osmocom/vty/telnet_interface.h> #include <osmocom/vty/logging.h> +#include "lc15bts_mgr.h" #include "btsconfig.h" #include "lc15bts_misc.h" #include "lc15bts_par.h" #include "lc15bts_mgr.h" #include "lc15bts_temp.h" +#include "lc15bts_power.h" /********************************************************************* * Temperature handling @@ -58,7 +60,7 @@ static const struct { enum lc15bts_par ee_par; } temp_data[] = { { - .name = "supply", + .name = "supply_temp", .has_max = 1, .sensor = LC15BTS_TEMP_SUPPLY, .ee_par = LC15BTS_PAR_TEMP_SUPPLY_MAX, @@ -74,22 +76,22 @@ static const struct { .ee_par = LC15BTS_PAR_TEMP_FPGA_MAX, }, { - .name = "logrf", + .name = "rmsdet", .has_max = 1, - .sensor = LC15BTS_TEMP_LOGRF, - .ee_par = LC15BTS_PAR_TEMP_LOGRF_MAX, + .sensor = LC15BTS_TEMP_RMSDET, + .ee_par = LC15BTS_PAR_TEMP_RMSDET_MAX, }, { .name = "ocxo", .has_max = 1, .sensor = LC15BTS_TEMP_OCXO, .ee_par = LC15BTS_PAR_TEMP_OCXO_MAX, }, { - .name = "tx0", + .name = "tx0_temp", .has_max = 0, .sensor = LC15BTS_TEMP_TX0, .ee_par = LC15BTS_PAR_TEMP_TX0_MAX, }, { - .name = "tx1", + .name = "tx1_temp", .has_max = 0, .sensor = LC15BTS_TEMP_TX1, .ee_par = LC15BTS_PAR_TEMP_TX1_MAX, @@ -106,6 +108,41 @@ static const struct { } }; +static const struct { + const char *name; + int has_max; + enum lc15bts_power_source sensor_source; + enum lc15bts_power_type sensor_type; + enum lc15bts_par ee_par; +} power_data[] = { + { + .name = "supply_volt", + .has_max = 1, + .sensor_source = LC15BTS_POWER_SUPPLY, + .sensor_type = LC15BTS_POWER_VOLTAGE, + .ee_par = LC15BTS_PAR_VOLT_SUPPLY_MAX, + } +}; + +static const struct { + const char *name; + int has_max; + enum lc15bts_vswr_sensor sensor; + enum lc15bts_par ee_par; +} vswr_data[] = { + { + .name = "tx0_vswr", + .has_max = 0, + .sensor = LC15BTS_VSWR_TX0, + .ee_par = LC15BTS_PAR_VSWR_TX0_MAX, + }, { + .name = "tx1_vswr", + .has_max = 0, + .sensor = LC15BTS_VSWR_TX1, + .ee_par = LC15BTS_PAR_VSWR_TX1_MAX, + } +}; + void lc15bts_check_temp(int no_rom_write) { int temp_old[ARRAY_SIZE(temp_data)]; @@ -117,7 +154,7 @@ void lc15bts_check_temp(int no_rom_write) rc = lc15bts_par_get_int(temp_data[i].ee_par, &ret); temp_old[i] = ret * 1000; - temp_cur[i] = lc15bts_temp_get(temp_data[i].sensor); + lc15bts_temp_get(temp_data[i].sensor, &temp_cur[i]); if (temp_cur[i] < 0 && temp_cur[i] > -1000) { LOGP(DTEMP, LOGL_ERROR, "Error reading temperature (%d)\n", temp_data[i].sensor); continue; @@ -143,6 +180,80 @@ void lc15bts_check_temp(int no_rom_write) } } +void lc15bts_check_power(int no_rom_write) +{ + int power_old[ARRAY_SIZE(power_data)]; + int power_cur[ARRAY_SIZE(power_data)]; + int i, rc; + + for (i = 0; i < ARRAY_SIZE(power_data); i++) { + int ret; + rc = lc15bts_par_get_int(power_data[i].ee_par, &ret); + power_old[i] = ret * 1000; + + lc15bts_power_sensor_get(power_data[i].sensor_source, power_data[i].sensor_type, &power_cur[i]); + if (power_cur[i] < 0 && power_cur[i] > -1000) { + LOGP(DTEMP, LOGL_ERROR, "Error reading power (%d) (%d)\n", power_data[i].sensor_source, power_data[i].sensor_type); + continue; + } + + LOGP(DTEMP, LOGL_DEBUG, "Current %s power: %d.%d C\n", + power_data[i].name, power_cur[i]/1000, power_cur[i]%1000); + + if (power_cur[i] > power_old[i]) { + LOGP(DTEMP, LOGL_NOTICE, "New maximum %s " + "power: %d.%d C\n", power_data[i].name, + power_cur[i]/1000, power_old[i]%1000); + + if (!no_rom_write) { + rc = lc15bts_par_set_int(power_data[i].ee_par, + power_cur[i]/1000); + if (rc < 0) + LOGP(DTEMP, LOGL_ERROR, "error writing new %s " + "max power %d (%s)\n", power_data[i].name, + rc, strerror(errno)); + } + } + } +} + +void lc15bts_check_vswr(int no_rom_write) +{ + int vswr_old[ARRAY_SIZE(vswr_data)]; + int vswr_cur[ARRAY_SIZE(vswr_data)]; + int i, rc; + + for (i = 0; i < ARRAY_SIZE(vswr_data); i++) { + int ret; + rc = lc15bts_par_get_int(vswr_data[i].ee_par, &ret); + vswr_old[i] = ret * 1000; + + lc15bts_vswr_get(vswr_data[i].sensor, &vswr_cur[i]); + if (vswr_cur[i] < 0 && vswr_cur[i] > -1000) { + LOGP(DTEMP, LOGL_ERROR, "Error reading vswr (%d)\n", vswr_data[i].sensor); + continue; + } + + LOGP(DTEMP, LOGL_DEBUG, "Current %s vswr: %d.%d C\n", + vswr_data[i].name, vswr_cur[i]/1000, vswr_cur[i]%1000); + + if (vswr_cur[i] > vswr_old[i]) { + LOGP(DTEMP, LOGL_NOTICE, "New maximum %s " + "vswr: %d.%d C\n", vswr_data[i].name, + vswr_cur[i]/1000, vswr_old[i]%1000); + + if (!no_rom_write) { + rc = lc15bts_par_set_int(vswr_data[i].ee_par, + vswr_cur[i]/1000); + if (rc < 0) + LOGP(DTEMP, LOGL_ERROR, "error writing new %s " + "max vswr %d (%s)\n", vswr_data[i].name, + rc, strerror(errno)); + } + } + } +} + /********************************************************************* * Hours handling *********************************************************************/ @@ -235,3 +346,213 @@ int lc15bts_firmware_reload(enum lc15bts_firmware_type type) } return 0; } + +/********************************************************************************** +THIS SHOULD BE IN ANOTHER FILE +***********************************************************************************/ + +int lc15bts_led_write(char *path, char *str) +{ + int fd; + + if((fd = open(path, O_WRONLY)) == -1) + { + return 0; + } + + write(fd, str, strlen(str)+1); + close(fd); + return 1; +} + +static struct lc15bts_led led_entries[] = { + { + .name = "led0", + .fullname = "led red", + .path = "/var/lc15/leds/led0/brightness" + }, + { + .name = "led1", + .fullname = "led green", + .path = "/var/lc15/leds/led1/brightness" + } +}; + +char *blink_pattern_command[] = BLINK_PATTERN_COMMAND; +static char *current_blink_pattern; +static uint8_t reload_now = 0; + +void led_set_red() +{ + lc15bts_led_write(led_entries[0].path, "1"); + lc15bts_led_write(led_entries[1].path, "0"); +} + +void led_set_green() +{ + lc15bts_led_write(led_entries[0].path, "0"); + lc15bts_led_write(led_entries[1].path, "1"); +} + +void led_set_orange() +{ + LOGP(DTEMP, LOGL_NOTICE,"LED orange called new code\n"); + lc15bts_led_write(led_entries[0].path, "1"); + lc15bts_led_write(led_entries[1].path, "1"); +} + +void led_set_off() +{ + lc15bts_led_write(led_entries[0].path, "0"); + lc15bts_led_write(led_entries[1].path, "0"); +} + +void led_sleep(double sec) +{ + int i; + long msec = (long )(sec*1000); + + for(i = 0; i < msec; i++) + { + if(reload_now == 1) + { + reload_now = 0; + break; + } + usleep(1000); + } +} +void call_led_cmd(char *cmdstr) +{ + double sec; + + if(strstr(cmdstr, "set red") != NULL) + { + led_set_red(); + } + else if(strstr(cmdstr, "set green") != NULL) + { + led_set_green(); + } + else if(strstr(cmdstr, "set orange") != NULL) + { + led_set_orange(); + } + else if(strstr(cmdstr, "set off") != NULL) + { + led_set_off(); + } + else if(strstr(cmdstr, "sleep") != NULL) + { + sec = atof(cmdstr+6); + led_sleep(sec); + } + else + { + LOGP(DTEMP, LOGL_ERROR,"Command not found\n"); + } +} + +void led_light_pattern(char *pattern) +{ + char str[1024]; + char *pstr; + char *sep; + + strcpy(str, pattern); + pstr = str; + while((sep = strsep(&pstr, ";")) != NULL) + { + call_led_cmd(sep); + } +} + +void led_light_loop(int times) +{ + int i; + + if(times == 0) + { + for(;;) + led_light_pattern(current_blink_pattern); + } + else + { + for(i = 0; i < times; i++) + led_light_pattern(current_blink_pattern); + } +} + +void led_set_pattern(char *pattern) +{ + if(current_blink_pattern != pattern) + { + current_blink_pattern = pattern; + reload_now = 1; + LOGP(DTEMP, LOGL_NOTICE,"LED pattern changed to %s\n", pattern); + } +} + + +/*** led interface ***/ + +void led_set(int pattern_id) +{ + LOGP(DTEMP, LOGL_NOTICE, "blink pattern command : %d\n", pattern_id); + led_set_pattern(blink_pattern_command[pattern_id]); +} + +void led_ctrl_check() +{ + led_light_loop(0); +} + +void led_test(void) +{ + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_NORMAL); + led_light_loop(12); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_BSC_DOWN); + led_light_loop(12); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_BTS_DOWN); + led_light_loop(12); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_PA1_OFF); + led_light_loop(3); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_SUPPLY_LOW); + led_light_loop(6); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_SUPPLY_MIN); + led_light_loop(6); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_VSWR_HIGH); + led_light_loop(8); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_HIGH_TEMP); + led_light_loop(6); + + led_set(BLINK_PATTERN_FLASH_ALL); + led_light_loop(1); + led_set(BLINK_PATTERN_MAX_TEMP); + led_light_loop(6); + + LOGP(DTEMP, LOGL_NOTICE,"LED test finished\n"); +} |