void extint_load_extension_configs(conn_t *conn) { int i; for (i=0; i < n_exts; i++) { ext_t *ext = ext_list[i]; send_encoded_msg_mc(conn->mc, "ADM", "ext_config_html", "%s", ext->name); } }
void extint_send_extlist(conn_t *conn) { int i; #define MAX_EXT_NAME 32 char *elist = (char *) malloc(N_EXT * MAX_EXT_NAME); strcpy(elist, "["); for (i=0; i < n_exts; i++) { ext_t *ext = ext_list[i]; // by now all the extensions have long since registered via ext_register() // send a list of all extensions to an object on the .js side sprintf(elist + strlen(elist), "\"%s\",", ext->name); } strcpy(&elist[strlen(elist)-1], "]"); //printf("elist = %s\n", elist); send_encoded_msg_mc(conn->mc, "MSG", "extint_list_json", "%s", elist); }
void w2a_admin(void *param) { int n, i, j; conn_t *conn = (conn_t *) param; static char json_buf[16384]; u4_t ka_time = timer_sec(); // send initial values send_msg(conn, SM_NO_DEBUG, "ADM init=%d", RX_CHANS); nbuf_t *nb = NULL; while (TRUE) { if (nb) web_to_app_done(conn, nb); n = web_to_app(conn, &nb); if (n) { char *cmd = nb->buf; cmd[n] = 0; // okay to do this -- see nbuf.c:nbuf_allocq() ka_time = timer_sec(); if (rx_common_cmd("W/F", conn, cmd)) continue; //printf("ADMIN: %d <%s>\n", strlen(cmd), cmd); i = strcmp(cmd, "SET init"); if (i == 0) { continue; } i = strcmp(cmd, "SET gps_update"); if (i == 0) { gps_stats_t::gps_chan_t *c; char *cp = json_buf; n = sprintf(cp, "{ \"FFTch\":%d, \"ch\":[ ", gps.FFTch); cp += n; for (i=0; i < gps_chans; i++) { c = &gps.ch[i]; int un = c->ca_unlocked; n = sprintf(cp, "%s{ \"ch\":%d, \"prn\":%d, \"snr\":%d, \"rssi\":%d, \"gain\":%d, \"hold\":%d, \"wdog\":%d" ", \"unlock\":%d, \"parity\":%d, \"sub\":%d, \"sub_renew\":%d, \"novfl\":%d }", i? ", ":"", i, c->prn, c->snr, c->rssi, c->gain, c->hold, c->wdog, un, c->parity, c->sub, c->sub_renew, c->novfl); cp += n; c->parity = 0; for (j = 0; j < SUBFRAMES; j++) { if (c->sub_renew & (1<<j)) { c->sub |= 1<<j; c->sub_renew &= ~(1<<j); } } } n = sprintf(cp, " ]"); cp += n; UMS hms(gps.StatSec/60/60); unsigned r = (timer_ms() - gps.start)/1000; if (r >= 3600) { n = sprintf(cp, ", \"run\":\"%d:%02d:%02d\"", r / 3600, (r / 60) % 60, r % 60); cp += n; } else { n = sprintf(cp, ", \"run\":\"%d:%02d\"", (r / 60) % 60, r % 60); cp += n; } if (gps.ttff) { n = sprintf(cp, ", \"ttff\":\"%d:%02d\"", gps.ttff / 60, gps.ttff % 60); cp += n; } else { n = sprintf(cp, ", \"ttff\":null"); cp += n; } if (gps.StatDay != -1) { n = sprintf(cp, ", \"gpstime\":\"%s %02d:%02d:%02.0f\"", Week[gps.StatDay], hms.u, hms.m, hms.s); cp += n; } else { n = sprintf(cp, ", \"gpstime\":null"); cp += n; } if (gps.StatLat) { n = sprintf(cp, ", \"lat\":\"%8.6f %c\"", gps.StatLat, gps.StatNS); cp += n; n = sprintf(cp, ", \"lon\":\"%8.6f %c\"", gps.StatLon, gps.StatEW); cp += n; n = sprintf(cp, ", \"alt\":\"%1.0f m\"", gps.StatAlt); cp += n; n = sprintf(cp, ", \"map\":\"<a href='http://wikimapia.org/#lang=en&lat=%8.6f&lon=%8.6f&z=18&m=b' target='_blank'>wikimapia.org</a>\"", gps.sgnLat, gps.sgnLon); cp += n; } else { n = sprintf(cp, ", \"lat\":null"); cp += n; } n = sprintf(cp, ", \"acq\":%d, \"track\":%d, \"good\":%d, \"fixes\":%d, \"adc_clk\":%.6f, \"adc_corr\":%d", gps.acquiring? 1:0, gps.tracking, gps.good, gps.fixes, (adc_clock - adc_clock_offset)/1e6, gps.adc_clk_corr); cp += n; n = sprintf(cp, " }"); cp += n; send_encoded_msg_mc(conn->mc, "ADM", "gps_update", "%s", json_buf); continue; } i = strcmp(cmd, "SET sdr_hu_update"); if (i == 0) { gps_stats_t::gps_chan_t *c; char *cp = json_buf; n = sprintf(cp, "{ "); cp += n; if (gps.StatLat) { n = sprintf(cp, "\"lat\":\"%8.6f\", \"lon\":\"%8.6f\"", gps.sgnLat, gps.sgnLon); cp += n; } n = sprintf(cp, " }"); cp += n; send_encoded_msg_mc(conn->mc, "ADM", "sdr_hu_update", "%s", json_buf); continue; } int force_check; i = sscanf(cmd, "SET force_check=%d force_build=%d", &force_check, &force_build); if (i == 2) { check_for_update(force_check); continue; } i = strcmp(cmd, "SET reload_index_params"); if (i == 0) { reload_index_params(); continue; } i = strcmp(cmd, "SET extint_load_extension_configs"); if (i == 0) { extint_load_extension_configs(conn); continue; } i = strcmp(cmd, "SET restart"); if (i == 0) { lprintf("ADMIN: restart requested by admin..\n"); exit(0); } i = strcmp(cmd, "SET reboot"); if (i == 0) { lprintf("ADMIN: reboot requested by admin..\n"); system("reboot"); while (true) usleep(100000); } i = strcmp(cmd, "SET power_off"); if (i == 0) { lprintf("ADMIN: power off requested by admin..\n"); system("poweroff"); while (true) usleep(100000); } printf("ADMIN: unknown command: <%s>\n", cmd); continue; } conn->keep_alive = timer_sec() - ka_time; bool keepalive_expired = (conn->keep_alive > KEEPALIVE_SEC); if (keepalive_expired) { printf("ADMIN KEEP-ALIVE EXPIRED\n"); rx_server_remove(conn); return; } TaskSleep(250000); } }
static void ll_printf(u4_t type, conn_t *c, const char *fmt, va_list ap) { int i, sl; char *s, *cp; #define VBUF 1024 if (!do_sdr) { //if (!background_mode) { if ((buf = (char*) malloc(VBUF)) == NULL) panic("log malloc"); vsnprintf(buf, VBUF, fmt, ap); // remove our override and call the actual underlying printf #undef printf printf("%s", buf); #define printf ALT_PRINTF evPrintf(EC_EVENT, EV_PRINTF, -1, "printf", buf); if (buf) free(buf); buf = 0; return; } if (appending) { s = last_s; } else { brem = VBUF; if ((buf = (char*) malloc(VBUF)) == NULL) panic("log malloc"); s = buf; start_s = s; } vsnprintf(s, brem, fmt, ap); sl = strlen(s); // because vsnprintf returns length disregarding limit, not the actual length brem -= sl+1; cp = &s[sl-1]; if (*cp != '\n' && brem && !(type & PRINTF_MSG)) { last_s = cp+1; appending = true; return; } else { appending = false; } // for logging, don't print an empty line at all if ((type & (PRINTF_REG | PRINTF_LOG)) && (!background_mode || strcmp(start_s, "\n") != 0)) { // remove non-ASCII since "systemctl status" gives [blob] message // unlike "systemctl log" which prints correctly int sl = strlen(buf); for (i=0; i < sl; i++) if (buf[i] > 0x7f) buf[i] = '?'; char up_chan_stat[64], *s = up_chan_stat; // uptime u4_t up = timer_sec(); u4_t sec = up % 60; up /= 60; u4_t min = up % 60; up /= 60; u4_t hr = up % 24; up /= 24; u4_t days = up; if (days) sl = sprintf(s, "%dd:%02d:%02d:%02d ", days, hr, min, sec); else sl = sprintf(s, "%d:%02d:%02d ", hr, min, sec); s += sl; // show state of all rx channels rx_chan_t *rx; for (rx = rx_chan, i=0; rx < &rx_chan[RX_CHANS]; rx++, i++) { *s++ = rx->busy? '0'+i : '.'; } *s++ = ' '; // show rx channel number if message is associated with a particular rx channel if (c != NULL) { for (i=0; i < RX_CHANS; i++) *s++ = (i == c->rx_channel)? '0'+i : ' '; } else { for (i=0; i < RX_CHANS; i++) *s++ = ' '; } *s = 0; if (((type & PRINTF_LOG) && (background_mode || log_foreground_mode)) || log_ordinary_printfs) { syslog(LOG_INFO, "%s %s", up_chan_stat, buf); } time_t t; char tb[32]; time(&t); ctime_r(&t, tb); tb[24]=0; // remove our override and call the actual underlying printf #undef printf printf("%s %s %s", tb, up_chan_stat, buf); #define printf ALT_PRINTF evPrintf(EC_EVENT, EV_PRINTF, -1, "printf", buf); } // attempt to also record message remotely if ((type & PRINTF_MSG) && msgs_mc) { if (type & PRINTF_FF) send_encoded_msg_mc(msgs_mc, "MSG", "status_msg", "\f%s", buf); else send_encoded_msg_mc(msgs_mc, "MSG", "status_msg", "%s", buf); } if (buf) free(buf); buf = 0; }