void VCXYPadProperties::slotOKClicked() { QPtrList<XYChannelUnit>* list; // Update the X list list = m_parent->channelsX(); list->setAutoDelete(true); list->clear(); list->setAutoDelete(false); QListViewItemIterator xit(m_listX); while (xit.current()) { list->append(createChannelUnit(*xit)); ++xit; } // Update the Y list list = m_parent->channelsY(); list->setAutoDelete(true); list->clear(); list->setAutoDelete(false); QListViewItemIterator yit(m_listY); while (yit.current()) { list->append(createChannelUnit(*yit)); ++yit; } accept(); }
void ML_multi_Powell::powell(v_ratep_type& p, mat_ratep_type& xi, const double ftol, int& iter, double& fret, ptr_eval_func func ) { const int ITMAX = 200; const double TINY = 1.0e-25; int i, j, ibig; double del, fp, fptt, t; int n = p.size(); v_ratep_type pt(n), ptt(n), xit(n); fret = (this->*func)(p); for (j = 0; j < n; ++j) pt[j] = p[j]; for (iter = 0; ; ++iter) { fp = fret; ibig = 0; del = 0.0; for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) xit[j] = xi[j][i]; fptt = fret; linmin(p, xit, fret, func); if (fptt - fret > del) { del = fptt - fret; ibig = i + 1; } } if (2.0*(fp - fret) <= ftol*(std::abs(fp) + std::abs(fret)) + TINY) { return; } if (iter == ITMAX) { std::cerr << "powell(): exceeded max iterations " << ITMAX << std::endl; assert(false); } for (j = 0; j < n; ++j) { ptt[j] = 2.0*p[j] - pt[j]; xit[j] = p[j] - pt[j]; pt[j] = p[j]; } fptt = (this->*func)(ptt); if (fptt < fp) { t = 2.0*(fp - 2.0*fret + fptt)*SQR(fp - fret - del) - del*SQR(fp - fptt); if (t < 0.0) { linmin(p, xit, fret, func); for (j = 0; j < n; ++j) { xi[j][ibig-1] = xi[j][n-1]; xi[j][n-1] = xit[j]; } } } } }
void _panic(const char *str, const char *file, int line) { char *buf; asprintf(&buf, "PANIC: \"%s\" (%s, line %d)", str, file, line); if (background_mode) { syslog(LOG_ERR, "%s\n", buf); } xit(-1); }
void web_server_init(ws_init_t type) { user_iface_t *ui = user_iface; if (type == WS_INIT_START) { // send private/public ip addrs to registry FILE *pf = popen("hostname -i", "r"); char ip_pvt[64]; fscanf(pf, "%16s", ip_pvt); pclose(pf); char ip_pub[64]; pf = popen("curl -s ident.me", "r"); fscanf(pf, "%16s", ip_pub); pclose(pf); char *bp; asprintf(&bp, "curl -s -o /dev/null http://%s/php/register.php?reg=%d.%s.%d.%s", LOGGING_HOST, SERIAL_NUMBER, ip_pvt, ui->port, ip_pub); lprintf("private ip: %s public ip: %s\n", ip_pvt, ip_pub); system(bp); free(bp); } if (type == WS_INIT_CREATE) { // if specified, override the port number of the first UI if (port_override) { lprintf("overriding port from %d -> %d for \"%s\"\n", user_iface[0].port, port_override, user_iface[0].name); user_iface[0].port = port_override; } } // create webserver port(s) while (ui->port) { if (type == WS_INIT_CREATE) { ui->server = mg_create_server(NULL, ev_handler); char *s_port; asprintf(&s_port, "%d", ui->port); if (mg_set_option(ui->server, "listening_port", s_port) != NULL) { lprintf("network port %d for \"%s\" in use\n", ui->port, ui->name); lprintf("app already running in background?\ntry \"make stop\" (or \"m stop\") first\n"); xit(-1); } lprintf("webserver for \"%s\" on port %s\n", ui->name, mg_get_option(ui->server, "listening_port")); free(s_port); } else { // WS_INIT_START CreateTaskP(&web_server, LOW_PRIORITY, ui); } ui++; } }
void ev(int event, const char *s, const char *s2) { int i; ev_t *e = &evs[evc++]; u4_t now = timer_us(); int reset=0; u64_t freeS2 = (u64_t) s2 & 1; s2 = (char*) ((u64_t) s2 & ~1); if (!triggered && (event == EV_TRIGGER)) { epoch = last_time = now; for (i=0; i<NEVT; i++) tlast[i] = now; evc=0; triggered=1; if (freeS2) free((void*) s2); return; } if (!triggered) { if (freeS2) free((void*) s2); return; } if (event < 0) { event = -event; tlast[event] = now; reset=1; } e->event = event; e->reset = reset; e->s = s; e->s2 = s2; e->tseq = now - last_time; e->tlast = now - tlast[event]; e->tepoch = now - epoch; e->task = TaskName(); if (evc == NEV) { for (i=0; i<NEV; i++) { e = &evs[i]; printf("%4d %8s%c %7.3f %7.3f %9.3f %16s, %16s %s\n", i, evn[e->event], e->reset? '*':' ', (float) e->tlast / 1000, (float) e->tseq / 1000, (float) e->tepoch / 1000, e->task, e->s, e->s2); } xit(0); } last_time = now; }
void _sys_panic(const char *str, const char *file, int line) { char *buf; // errno might be overwritten if the malloc inside asprintf fails asprintf(&buf, "SYS_PANIC: \"%s\" (%s, line %d)", str, file, line); if (background_mode || log_foreground_mode) { syslog(LOG_ERR, "%s: %m\n", buf); } perror(buf); xit(-1); }
DVD::DVD ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { _hInstance = hInstance; _hPrevInstance = hPrevInstance; _lpCmdLine = lpCmdLine; _nCmdShow = nCmdShow; _wc.style = CS_SAVEBITS // CS_HREDRAW | CS_VREDRAW ; _wc.lpfnWndProc = (WNDPROC)WndProc; _wc.cbClsExtra = 0; _wc.cbWndExtra = 0; _wc.hInstance = hInstance; _wc.hIcon = LoadIcon( hInstance, _AppName ); _wc.hCursor = LoadCursor(NULL, IDC_ARROW); _wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); _wc.lpszMenuName = _AppName; _wc.lpszClassName = _AppName; if ( IS_WIN95 ) { if ( !RegisterWin95() ) e-xit(-1); } else if ( !RegisterClass(&_wc ) ) e-xit(-1); hInst = hInstance; _init_carac = false; }
void _panic(const char *str, bool coreFile, const char *file, int line) { char *buf; if (ev_dump) ev(EC_DUMP, EV_PANIC, -1, "panic", "dump"); asprintf(&buf, "%s: \"%s\" (%s, line %d)", coreFile? "DUMP":"PANIC", str, file, line); if (background_mode || log_foreground_mode) { syslog(LOG_ERR, "%s\n", buf); } printf("%s\n", buf); if (coreFile) abort(); xit(-1); }
void DVD::init_carac(HDC hdc) { if (! _init_carac) { _init_carac = true; _bits_per_pixel = GetDeviceCaps(hdc,BITSPIXEL); if ( (_bits_per_pixel %8) || (_bits_per_pixel == 0) || (_bits_per_pixel > 32) ) e-xit(-1); _nb_oct_pp = _bits_per_pixel /8; } }
void DVV::show_rect(int x1,int y1,int x2,int y2) { if(! BitBlt ( _hdc, // cible x1, y1, // x,y cible x2-x1, y2-y1, // largeur hauteur _hMemDC, // src x1, y1, // x y src SRCCOPY ) ) e-xit(-1); }
void DVV::bitm_set_rgb(int x,int y,int r,int g,int b) { if ( (y!= _last_y) || (x != _last_x) ) { flush_buf_b1(); _last_x0 = x; } _last_x =x+1; _last_y = y; switch(_nb_oct) { case 1: _im[x] = (r+g+b) /6; break; case 2: ((unsigned short *) _im)[x] = to_16(r,g,b); break; case 3 : { unsigned char *i = _im + 3*x; i[0] = r; i[1] = g; i[2] = b; } break; case 4 : { unsigned char *i = _im + 4*(x+_txB*y); i[0] = r; i[1] = g; i[2] = b; } break; default : e-xit(-1); } }
void bus_test() { u4_t i, a, a2, d, d2, dr, dw, c, m, m2; volatile u4_t v; //#define TEST_BUS #ifdef TEST_BUS a = d = 0; while (1) { a++; if ((a&0x3fff)==0) d++; //v = GPIO_IN(0); //_r(0); _w(a&0x7f, a&0xff); //printf("0x%02x\n", bus_read(RREG_A16_SWITCHES)); #if 0 bus_write(0x70, 0xff); bus_write(0x71, 0xf0); //bus_read(0x70); //bus_write(0x71, 0xff); //bus_write(0x71, 0xf0); #endif #if 0 printf("delay delay delay delay "); //bus_write(0x00a0, 0x00); //bus_read(0x0000); //bus_read(0x0001); //bus_read(0x0002); //bus_read(0x0003); #endif #if 0 bus_write(0x00a0, 0x55); bus_write(0x0001, 0x01); bus_write(0x0002, 0x02); bus_write(0x0003, 0x03); bus_write(0x0003, 0x84); bus_read(0x0000); #endif } #if 0 // test for this in the bus_read() routine and select read method int direct_cmp = 1; u4_t t0, t1; a = 0x7d00; direct_cmp = 0; t0 = bus_read(0x00); direct_cmp = 1; t1 = bus_read(0x00); printf("test bus read @0x%02x 0x%08x 0x%08x\n", a, t0, t1); a = 0x7d01; direct_cmp = 0; t0 = bus_read(0x00); direct_cmp = 1; t1 = bus_read(0x00); printf("test bus read @0x%02x 0x%08x 0x%08x\n", a, t0, t1); a = 0x7d02; direct_cmp = 0; t0 = bus_read(0x00); direct_cmp = 1; t1 = bus_read(0x00); printf("test bus read @0x%02x 0x%08x 0x%08x\n", a, t0, t1); a = 0x7d03; direct_cmp = 0; t0 = bus_read(0x00); direct_cmp = 1; t1 = bus_read(0x00); printf("test bus read @0x%02x 0x%08x 0x%08x\n", a, t0, t1); //bus_write(0xa0, 0x03); xit(0); #endif #if 0 for (i=0; i<100000000; i++) { //printf("."); fflush(stdout); bus_write(0x00a0, 0x00); bus_read(0x00a0); #if 0 bus_write(0x00a0, 0x00); bus_write(0x00a1, 0x01); bus_write(0x00a2, 0x02); bus_write(0x00a3, 0x03); bus_write(0x00a3, 0x84); #endif } #endif //w(0x80, 0x55); //w(0x10, 0); //r(0x80); //r(0x80); //r(0x80); //r(0x80); //r(0x60); //w(0x10, 0x1); //w(0x10, 0x0); xit(0); #endif //#define TEST_HPIB #ifdef TEST_HPIB int i; for (i=0; i<100000000; i++) { bus_read(0x02); bus_write(0x02, 0x00); bus_write(0x02, 0xff); bus_write(0x02, 0x00); bus_write(0x02, 0xff); } xit(0); #endif //#define HI_PHK #ifdef HI_PHK { int i, j; u1_t k; #define H 0x20|0x02|0x40|0x10|0x04 #define I 0x20|0x10 #define P 0x20|0x10|0x01|0x02|0x40 #define O 0x01|0x02|0x04|0x08|0x10|0x20 #define U 0x02|0x04|0x08|0x10|0x20 #define L 0x08|0x10|0x20 #define E 0x01|0x08|0x10|0x20|0x40 #define N 0x01|0x02|0x04|0x10|0x20 #define G 0x01|0x04|0x08|0x10|0x20 #define DASH 0x40 #define PERIOD 0x80 bus_write(0x70, H); bus_write(0x71, I); bus_write(0x72, P); bus_write(0x73, O); bus_write(0x74, U); bus_write(0x75, L); bus_write(0x76, DASH); bus_write(0x77, H); bus_write(0x78, E); bus_write(0x79, N); bus_write(0x7a, N); bus_write(0x7b, I); bus_write(0x7c, N); bus_write(0x7d, G); bus_write(0x7e, PERIOD); bus_write(0x7f, PERIOD); xit(0); for (j = 0; j < 1000000; j++) { bus_write(0x7f, 1 << (j&0x7)); usleep(100000); } xit(0); } #endif //#define TEST_DISPLAY #ifdef TEST_DISPLAY printf("test display..\n"); { int i, j; i = 0; #if 0 do { printf("x"); fflush(stdout); bus_write(0x66, 0x01); bus_write(0x67, 0x00); usleep(1000000); printf("."); fflush(stdout); bus_write(0x66, 0x00); bus_write(0x67, 0x00); usleep(1000000); } while (1); #endif #if 0 do { delay(1000); bus_write(0x69, 0x08); delay(1000); bus_write(0x69, 0x00); } while (1); #endif #if 1 do { delay(100); #if 1 for (j = 0; j < 16; j++) { bus_write(0x70 + j, 1 << (i&0x7)); } #endif for (j = 0; j < 16; j++) { bus_write(0x60 + j, (i&1)? 0xf:0); } i++; } while (1); #endif xit(0); } #endif #define TEST_KEYS #ifdef TEST_KEYS printf("test keys..\n"); { int i, j, col; u1_t k; i = 0; col = 0; do { k = bus_read(RREG_KEY_SCAN); if (((k&0xf) != 0xf)) { //{ printf("%02x ", k); fflush(stdout); //printf("%02x-%02x ", bus_read(RREG_A16_SWITCHES), k); col += 3; if (col > 100) { printf("\n"); col = 0; } } delay(100); #if 1 for (j = 0; j < 16; j++) { bus_write(0x70 + j, 1 << (i&0x7)); } #endif #if 1 for (j = 0; j < 16; j++) { bus_write(0x60 + j, (i&1)? 0xf:0); } i++; #endif } while (1); xit(0); } #endif //#define TEST_RAM_CLK10 #ifdef TEST_RAM_CLK10 { int i; #if 0 w(0x80, 0x00); for (i = 0; i < 0x100; i++) { // w(0x80, (i & 1)? 0xff:0); r(0x80); r(0x80); r(0x80); r(0x80); sleep(1); } #else w(0x80, 0x00); for (i = 0; i < 0xfffffff; i++) { d = bus_read(0x80) & 0xff; if ((d&1) != 0) { printf("%x ", d); fflush(stdout); } } #endif xit(0); } #endif //#define TEST_ROM #ifdef TEST_ROM //for (a = 0x6000; a < 0x6004; a++) { r(0x6000); r(0x6001); r(0xfffe); r(0xffff); //w(0x6000, 0xff); xit(0); #endif //#define TEST_RAM #ifdef TEST_RAM a2 = 0x200; m = 0x00; for (a = 0x80; a < a2; a++) { bus_write(a, a & 0xff); } { u1_t dsave[0x200]; for (a = 0x80; a < a2; a++) { dsave[a] = bus_read(a); } for (a = 0x80; a < a2; a++) { c = a & 0xff; if ((dsave[a]|m) != (c|m)) { printf("@0x%x 0x%x != %x\n", a, c|m, dsave[a]|m); } } } //#define CHECK_BACKWARDS #ifdef CHECK_BACKWARDS for (a = a2-1; a >= 0x80; a--) { d = bus_read(a); c = a & 0xff; if ((d|m) != (c|m)) printf("@0x%x 0x%x != %x\n", a, c|m, d|m); } #endif #endif //#define TEST_RAM2 #ifdef TEST_RAM2 for (a = 0x80; a <= 0x1ff; a++) { bus_write(a, a); } for (a = 0x80; a < 0x1ff; a++) { d = bus_read(a); if (d != a) printf("@0x%x != %x\n", a, d); } #endif xit(0); }
int main(int argc, char *argv[]) { int i, n; bool wasRunning = FALSE; bool save_cfg = FALSE; bool change_settings_ui(menu_e *menu, u1_t key, bool *skip_first, cfg_t *cfg); bool show_ip = FALSE; bool config_valid, config_key = FALSE; bool config_ip = FALSE, config_nm = FALSE, config_gw = FALSE, config_am = FALSE; u4_t key; menu_e menu; int addr_mode; int ip[4], nm[4], gw[4], bc[4]; FILE *cfp, *efp; char *config_file = ROOT_DIR "/.5370.config"; cfg_t *cfg = &cfg_buf; dsp_7seg_init(FALSE); // panic routine can't use display until bus is setup // silently ignores unrecognized arguments for (i=1; i<argc; i++) { if (strcmp(argv[i], "-bg") == 0) background_mode = TRUE; if (strcmp(argv[i], "-ip") == 0) show_ip = TRUE; if (strcmp(argv[i], "-no") == 0) menu_action = FALSE; if (strcmp(argv[i], "?")==0 || strcmp(argv[i], "-?")==0 || strcmp(argv[i], "--?")==0 || strcmp(argv[i], "-h")==0 || strcmp(argv[i], "h")==0 || strcmp(argv[i], "-help")==0 || strcmp(argv[i], "--h")==0 || strcmp(argv[i], "--help")==0) { printf( "-rcl|-recall [name] load key settings from named profile\n" "-hpib-hard use the original HPIB hardware interface, assuming installed\n" "-hpib-sim simulate the HPIB interface in software (debug mode)\n" "-hpib-net simulate and re-direct transfers over an Ethernet connection\n" "-ip show IP address of Ethernet interface and exit\n" ); xit(0); } } lprintf("HP%s v%d.%d\n", INST_STR, FIRMWARE_VER_MAJ, FIRMWARE_VER_MIN); lprintf("compiled: %s %s\n", __DATE__, __TIME__); sim_args(TRUE, argc, argv); hpib_args(TRUE, argc, argv); sim_init(); web_server_init(); if (!menu_action) printf("menu action disabled\n"); reset: // To support the action of the 'reset' key most code files have a reset routine that zeros static variables. // This is similar to the C runtime idea of zeroing the bss when a program is first run. if (wasRunning) { wasRunning = FALSE; net_reset(NET_HPIB); net_reset(NET_TELNET); web_server_stop(); skip_first = save_cfg = config_key = config_ip = config_nm = config_gw = config_am = FALSE; } sim_reset(); if (!(bus_read(RREG_LDACSR) & DSR_VOK)) { lprintf("waiting for 5370 power\n"); usleep(1000000); while (!(bus_read(RREG_LDACSR) & DSR_VOK)) { sched_yield(); usleep(250000); } lprintf("5370 power on\n"); usleep(1000000); } else { lprintf("5370 is powered on\n"); } // display firmware version dsp_7seg_init(TRUE); dsp_7seg_str(DSP_LEFT, INST_STR, DSP_CLEAR); dsp_7seg_chr(POS(10), 'v'); dsp_7seg_num(POS(11), POS_IS_LSD, FIRMWARE_VER_MAJ, DEFAULT_WIDTH, SPACE_FILL); dsp_7seg_num(POS(12), POS_IS_MSD, FIRMWARE_VER_MIN, FIELD_WIDTH(0), ZERO_FILL); dsp_7seg_dp(POS(12)); dsp_leds_clr_all(); delay(2000); if ((cfp = fopen(config_file, "r")) == NULL) { if (errno != ENOENT) sys_panic(config_file); config_valid = FALSE; } else { while (fgets(lbuf, LBUF, cfp)) { if ((sscanf(lbuf, "key 0x%x", &key) == 1) && (key == 0xcafe5370)) config_key = TRUE; else if (sscanf(lbuf, "am %d", &addr_mode) == 1) config_am = TRUE; else if (sscanf(lbuf, "ip %d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]) == 4) config_ip = TRUE; else if (sscanf(lbuf, "nm %d.%d.%d.%d", &nm[0], &nm[1], &nm[2], &nm[3]) == 4) config_nm = TRUE; else if (sscanf(lbuf, "gw %d.%d.%d.%d", &gw[0], &gw[1], &gw[2], &gw[3]) == 4) config_gw = TRUE; else ; } assert((addr_mode == 0) || (addr_mode == 1)); menu = cfg->menu = (addr_mode == 0)? M_DHCP : M_IP; if (config_key && config_ip && config_nm && config_gw && config_am) { printf("valid config file %s\n", config_file); config_valid = TRUE; if (menu == M_IP) { printf("setting interface address\n"); sprintf(lbuf, "ifconfig eth0 %d.%d.%d.%d netmask %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3], nm[0], nm[1], nm[2], nm[3]); if (menu_action) system(lbuf); sprintf(lbuf, "route add default %d.%d.%d.%d", gw[0], gw[1], gw[2], gw[3]); if (menu_action) system(lbuf); } } else { printf("invalid config file %s\n", config_file); config_valid = FALSE; } fclose(cfp); } if (!config_valid) { menu = cfg->menu = M_DHCP; // try DHCP first if not valid config } #define ENET_RETRY 20 if (menu == M_DHCP) { // see if interface configured by DHCP gw[3]=gw[2]=gw[1]=gw[0]=0; // ifconfig doesn't tell us the gateway, only the broadcast which we don't care about // sometimes the link is slow to come up, so retry a few times for (i=0; i<ENET_RETRY; i++) { if ((efp = popen("ifconfig eth0", "r")) == NULL) sys_panic("ifconfig eth0"); char *lp = lbuf; n=0; while (fgets(lp, LBUF, efp)) { if ((n = sscanf(lp, "%*[ ]inet addr:%d.%d.%d.%d Bcast:%d.%d.%d.%d Mask:%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3], &bc[0], &bc[1], &bc[2], &bc[3], &nm[0], &nm[1], &nm[2], &nm[3])) == 12) break; } pclose(efp); if (n == 12) break; delay(1000); } } else { i=0; // interface configured manually above } if (i != ENET_RETRY) { for (i=0; i<4; i++) { cfg->ip[i] = ip[i]; cfg->nm[i] = nm[i]; cfg->gw[i] = gw[i]; } if (menu == M_DHCP) lprintf("via DHCP "); lprintf("eth0: ip %d.%d.%d.%d mask %d.%d.%d.%d ", ip[0], ip[1], ip[2], ip[3], nm[0], nm[1], nm[2], nm[3]); if (menu != M_DHCP) lprintf("gw %d.%d.%d.%d", gw[0], gw[1], gw[2], gw[3]); lprintf("\n"); dsp_7seg_str(DSP_LEFT, "ip", DSP_CLEAR); display_ipaddr(cfg->ip); } else { lprintf("eth0: not configured from DHCP?"); dsp_7seg_str(DSP_LEFT, "no dhcp?", DSP_CLEAR); } if (!config_valid && (i == ENET_RETRY)) { // configuration not valid, DHCP failed, so set some defaults menu = cfg->menu = M_IP; bcopy(default_ipinfo, cfg->if_ipinfo, sizeof(default_ipinfo)); save_cfg = TRUE; } if (show_ip) xit(0); delay(2000); // show ip on display for a moment before continuing net_connect(NET_HPIB, SERVER, NULL, HPIB_TCP_PORT); net_connect(NET_TELNET, SERVER, NULL, TELNET_TCP_PORT); web_server_start(); // place a call here to setup your measurement extension code meas_extend_example_init(); // reset key held down during a reboot -- drop into menu mode preempt_reset_key(TRUE); // while in the boot routine the reset key either starts the app or saves the changed config app_state = S_MENU; while (1) { u1_t key; sim_input(); // for remote debugging of menu mode key = handler_dev_display_read(RREG_KEY_SCAN); // called instead of bus_read() so simulated keys will be returned switch(app_state) { case S_MENU: if (key != KEY(RESET)) { app_state = S_START; break; } dsp_7seg_str(DSP_LEFT, "ready", DSP_CLEAR); printf("ready\n"); dsp_led_set(RESET); wait_key_release(); dsp_led_clr(RESET); dsp_7seg_str(DSP_LEFT, "chg settings", DSP_CLEAR); printf("menu mode\n"); skip_first = TRUE; menu = M_HALT; // first menu item displayed // light up the keys valid during menu mode for (i=0; settings_keys[i].key; i++) { dsp_led_set(settings_keys[i].key); } app_state = S_MENU_POLL; break; case S_MENU_POLL: if (key == KEY(RESET)) { dsp_led_set(RESET); wait_key_release(); dsp_led_clr(RESET); app_state = S_MENU_DONE; break; } if (change_settings_ui(&menu, key, &skip_first, cfg)) save_cfg = TRUE; break; case S_MENU_DONE: if (!skip_first && (menu == M_HALT)) { // Debian takes a while to halt, but nicely clears the GPIOs so the // display goes blank right when halted. // Angstrom with Gnome disabled halts very fast, but doesn't // clear the GPIOs like Debian. So we get the PRU to poll the LEDs // until they go off, then blank the display. dsp_7seg_str(DSP_LEFT, " halting...", DSP_CLEAR); printf("halting...\n"); #ifdef DIST_DEBIAN if (menu_action) system("halt"); exit(0); #endif #ifdef DIST_ANGSTROM dsp_7seg_chr(POS(0), ' '); // preload address & data send_pru_cmd(PRU_HALT); if (menu_action) system("halt"); exit(0); #endif } else if (menu == M_CANCEL || (skip_first && (menu == M_HALT))) { app_state = S_START; break; } else { if (menu != M_DHCP) menu = M_IP; if (menu != cfg->menu) save_cfg = TRUE; } if (save_cfg) { dsp_7seg_str(DSP_LEFT, "config changed", DSP_CLEAR); delay(2000); cfg->menu = menu; if (menu == M_DHCP) { dsp_7seg_str(DSP_LEFT, "using dhcp mode", DSP_CLEAR); } else { dsp_7seg_str(DSP_LEFT, "using ip mode", DSP_CLEAR); } delay(2000); dsp_7seg_str(DSP_LEFT, "saving config", DSP_CLEAR); if ((cfp = fopen(config_file, "w")) == NULL) sys_panic(config_file); printf("writing config file %s\n", config_file); fprintf(cfp, "key 0xcafe5370\n"); fprintf(cfp, "am %d\n", (cfg->menu == M_DHCP)? 0:1); fprintf(cfp, "ip %d.%d.%d.%d\n", cfg->ip[0], cfg->ip[1], cfg->ip[2], cfg->ip[3]); fprintf(cfp, "nm %d.%d.%d.%d\n", cfg->nm[0], cfg->nm[1], cfg->nm[2], cfg->nm[3]); fprintf(cfp, "gw %d.%d.%d.%d\n", cfg->gw[0], cfg->gw[1], cfg->gw[2], cfg->gw[3]); fclose(cfp); delay(2000); } app_state = S_START; break; case S_START: if (wasRunning) { // if previous sim was interrupted must reset before starting new one goto reset; } preempt_reset_key(FALSE); sim_main(); preempt_reset_key(TRUE); handler_dev_display_read(RREG_KEY_SCAN); // flush extra sim reset key, if any delay(1000); // this sim was interrupted, so can't restart a new sim without doing a reset first wasRunning = TRUE; // if key still down after one second delay enter menu mode, else treat as simple reset if (handler_dev_display_read(RREG_KEY_SCAN) == KEY(RESET)) { app_state = S_MENU; } else { goto reset; } break; } } return 0; }
static void update_task(void *param) { conn_t *conn = (conn_t *) FROM_VOID_PARAM(param); bool force_check = (conn && conn->update_check == FORCE_CHECK); bool force_build = (conn && conn->update_check == FORCE_BUILD); bool ver_changed, update_install; lprintf("UPDATE: checking for updates\n"); // Run curl in a Linux child process otherwise this thread will block and cause trouble // if the check is invoked from the admin page while there are active user connections. int status = child_task("kiwi.upd", POLL_MSEC(1000), curl_makefile_ctask, NULL); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { lprintf("UPDATE: curl Makefile error, no Internet access? status=0x%08x WIFEXITED=%d WEXITSTATUS=%d\n", status, WIFEXITED(status), WEXITSTATUS(status)); if (force_check) report_result(conn); goto common_return; } FILE *fp; scallz("fopen Makefile.1", (fp = fopen("/root/" REPO_NAME "/Makefile.1", "r"))); int n1, n2; n1 = fscanf(fp, "VERSION_MAJ = %d\n", &pending_maj); n2 = fscanf(fp, "VERSION_MIN = %d\n", &pending_min); fclose(fp); ver_changed = (n1 == 1 && n2 == 1 && (pending_maj > version_maj || (pending_maj == version_maj && pending_min > version_min))); update_install = (admcfg_bool("update_install", NULL, CFG_REQUIRED) == true); if (force_check) { if (ver_changed) lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but check only\n", version_maj, version_min, pending_maj, pending_min); else lprintf("UPDATE: running most current version\n"); report_result(conn); goto common_return; } else if (ver_changed && !update_install && !force_build) { lprintf("UPDATE: version changed (current %d.%d, new %d.%d), but update install not enabled\n", version_maj, version_min, pending_maj, pending_min); } else if (ver_changed || force_build) { lprintf("UPDATE: version changed%s, current %d.%d, new %d.%d\n", force_build? " (forced)":"", version_maj, version_min, pending_maj, pending_min); lprintf("UPDATE: building new version..\n"); update_in_progress = true; rx_server_user_kick(-1); // kick everyone off to speed up build sleep(5); // Run build in a Linux child process so the server can continue to respond to connection requests // and display a "software update in progress" message. // This is because the calls to system() in update_build_ctask() block for the duration of the build. u4_t build_time = timer_sec(); status = child_task("kiwi.bld", POLL_MSEC(1000), update_build_ctask, TO_VOID_PARAM(force_build)); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { lprintf("UPDATE: build error, no Internet access? status=0x%08x WIFEXITED=%d WEXITSTATUS=%d\n", status, WIFEXITED(status), WEXITSTATUS(status)); goto common_return; } lprintf("UPDATE: build took %d secs\n", timer_sec() - build_time); lprintf("UPDATE: switching to new version %d.%d\n", pending_maj, pending_min); if (admcfg_int("update_restart", NULL, CFG_REQUIRED) == 0) { xit(0); } else { lprintf("UPDATE: rebooting Beagle..\n"); system("sleep 3; reboot"); } } else { lprintf("UPDATE: version %d.%d is current\n", version_maj, version_min); } if (daily_restart) { lprintf("UPDATE: daily restart..\n"); xit(0); } common_return: if (conn) conn->update_check = WAIT_UNTIL_NO_USERS; // restore default update_pending = update_task_running = update_in_progress = false; }
DVV::DVV ( DVD* dvd, int tx, int ty ) { _dwstyle = WS_OVERLAPPEDWINDOW; _txF = _txB = tx; _tyF = _tyB = ty; // Vu chez Frankies, Probabl Pb d'alignement . while (_txB%4) _txB ++; while (_tyB%4) _tyB ++; //=============================== // CREATION DE LA FENETRE //================================ { RECT r; r.left = 0; r.top = 0; r.right = _txF; r.bottom = _tyF; // renvoie les coordonnees de la Fenetre, y compris // enjolivures dans le systeme de coordonnees utilisateur AdjustWindowRect(&r,_dwstyle,FALSE); _hWnd = CreateWindow ( DVD::_AppName, DVD::_Elise_Name, _dwstyle, CW_USEDEFAULT, 0, r.right-r.left, r.bottom-r.top, NULL, NULL, dvd->_hInstance, NULL ); } if ( !_hWnd ) e-xit(-1); ShowWindow( _hWnd, dvd->_nCmdShow ); UpdateWindow( _hWnd ); _hdc = GetDC(_hWnd); dvd->init_carac(_hdc); _nb_oct = dvd->_nb_oct_pp; //=============================== // CREATION DU BITMAP DE 1 LIGNE //================================ _last_y = -1; _bmi = (BITMAPINFO *) malloc ( sizeof (BITMAPINFO) + NB_COLOUR*sizeof(RGBQUAD) + _txB*1*_nb_oct ); _bmi->bmiHeader.biSize = (DWORD) sizeof (BITMAPINFOHEADER) ; _bmi->bmiHeader.biWidth = (LONG) _txB ; _bmi->bmiHeader.biHeight = (LONG) 1 ; // -ny _bmi->bmiHeader.biPlanes = (WORD) 1 ; _bmi->bmiHeader.biBitCount = (WORD) (8 * _nb_oct); _bmi->bmiHeader.biCompression = (DWORD) BI_RGB ; _bmi->bmiHeader.biSizeImage = (DWORD) 0 ; _bmi->bmiHeader.biXPelsPerMeter = (LONG) 0 ; _bmi->bmiHeader.biYPelsPerMeter = (LONG) 0 ; _bmi->bmiHeader.biClrUsed = (LONG) NB_COLOUR ; _bmi->bmiHeader.biClrImportant = (LONG) NB_COLOUR ; // sans doute inutile avant de gerer les palettes, // surement a modifier avec gestion des palettes, // surement inutile en mode 16 ou 24 bits /* { int x; for (x=0; x<128; ++x) { _bmi->bmiColors[x] . rgbBlue = 2*x ; _bmi->bmiColors[x] . rgbGreen = 2*x ; _bmi->bmiColors[x] . rgbRed = 2*x ; _bmi->bmiColors[x] . rgbReserved = 0 ; } } */ int offset_im = _bmi->bmiHeader.biSize + NB_COLOUR*sizeof(RGBQUAD); _im = (unsigned char*)_bmi + offset_im; _hbm = CreateDIBitmap ( _hdc, (LPBITMAPINFOHEADER)_bmi, (DWORD)CBM_INIT, (LPSTR)_bmi + offset_im, (LPBITMAPINFO)_bmi, DIB_RGB_COLORS ); if (_hbm==0) e-xit(-1); //================================================ // CREATION DU DC/BITMAP // Copie betement dans le "Richard Simon" // Absolument pas bite une seule ligne de ce // charabia. Apparament ca marche. //================================================ _bi.biSize = sizeof(BITMAPINFOHEADER); _bi.biWidth = _txB; _bi.biHeight = _tyB; _bi.biPlanes = 1; _bi.biBitCount = 8*_nb_oct; _bi.biCompression = BI_RGB; _bi.biSizeImage = 0; _bi.biXPelsPerMeter = 0; _bi.biYPelsPerMeter = 0; _bi.biClrUsed = 0; _bi.biClrImportant = 0; // Create DIB. //............ _hBitmap = CreateDIBitmap( _hdc, &_bi, 0L, NULL,NULL, 0 ); // Allocate memory for BITMAPINFO structure. //.......................................... _hDIB = GlobalAlloc( GHND, sizeof( BITMAPINFOHEADER )+ NB_COLOUR * sizeof( RGBQUAD ) ); _lpbi = (BITMAPINFOHEADER*)GlobalLock( _hDIB ); // Copy bi to top of BITMAPINFO structure. //........................................ *_lpbi = _bi; // Use GetDIBits() to init bi struct data. //........................................ GetDIBits( _hdc, _hBitmap, 0, 50, NULL, (LPBITMAPINFO)_lpbi, DIB_RGB_COLORS ); GlobalUnlock( _hDIB ); // Create a memory device context // and select the DIB into it. //............................... _hMemDC = CreateCompatibleDC( _hdc ); SelectObject( _hMemDC, _hBitmap ); SetProp(_hWnd,"EliseThis",this); }
void _NextTaskL() #endif { int i; TASK *t, *tn; u4_t now, quanta; t = cur_task; // don't switch until quanta expired (if any) if (t->quanta && ((timer_ms() - start_ms) < t->quanta)) return; ev(EV_NEXTTASK, "NextTask", ""); now = timer_us(); quanta = now - start_us; t->usec += quanta; if (slice) { TSLICE *ts = &slices[slice-1]; ts->id = t->id; ts->usec = quanta; ts->wakeup = rx0_wakeup; ts->twoke = now - rx0_twoke; #ifdef DEBUG ts->s = s; #endif slice++; if (slice == NSLICES) { u4_t maxv=0; int maxi=0; for (i=0; i<NSLICES; i++) { ts = &slices[i]; if (ts->usec > maxv) { maxv = ts->usec; maxi = i; } } for (i=0; i<NSLICES; i++) { ts = &slices[i]; printf("%4d T%02d %7.3f %7.3f w%d %s %s %s %s\n", i, ts->id, ((float) ts->usec) / 1e3, ((float) ts->twoke) / 1e3, ts->wakeup, Tasks[ts->id].name, ts->s? ts->s : "", ts->msg, (i==maxi)? "############################################": ( (ts->usec>=2000.0)? "------------------------------------------":"") ); } xit(0); slice = 0; } } if (setjmp(t->jb)) { return; } //printf("P%d-%s %.3f ms pc %p\n", t->id, t->name, ((float) quanta) / 1e3, (void *) t->pc); fflush(stdout); for (i=0; i<MAX_TASKS; i++) { TASK *tp = Tasks + i; if (tp->valid && tp->deadline && (tp->deadline < now)) { tp->deadline = 0; tp->stopped = FALSE; tp->wakeup = TRUE; //printf("wake T%02d\n", tp->id); } } if (t->priority == HIGH_PRIORITY) { do { // after a high priority finishes run next high priority t = t->next; } while (t && t->stopped); if (!t) { // no other high priority, so run next low priority t = cur_low; do { t = t->next; if (!t) t = prio_low; } while (t->stopped); } } else { // run _all_ high priority after each low priority finishes for (t = prio_high; t && t->stopped; t = t->next) ; if (!t) { // no high priority so run next low priority t = cur_task; do { t = t->next; if (!t) t = prio_low; } while (t->stopped); } } cur_task = t; if (t->priority == LOW_PRIORITY) cur_low = t; t->run++; //printf("N%d-%s pc %p\n", t->id, t->name, (void *) t->pc); fflush(stdout); start_us = now; if (t->quanta) start_ms = timer_ms(); longjmp(t->jb, 1); }
int x_init(void) { dll_handle dl; const char *libnames[]={"X11",NULL}; Status (*xit)(void); /* Ensure we haven't already initialized */ if(x11_initialized) return(0); /* Set up the pipe for local events */ if(pipe(local_pipe)) return(-1); /* And the keyboard pipe */ if(pipe(key_pipe)) return(-1); /* Load X11 functions */ if((dl=xp_dlopen(libnames,RTLD_LAZY,7))==NULL) return(-1); if((xit=xp_dlsym(dl,XInitThreads))!=NULL) xit(); if((x11.XChangeGC=xp_dlsym(dl,XChangeGC))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCopyPlane=xp_dlsym(dl,XCopyPlane))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XFillRectangle=xp_dlsym(dl,XFillRectangle))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XDrawPoint=xp_dlsym(dl,XDrawPoint))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XFlush=xp_dlsym(dl,XFlush))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSync=xp_dlsym(dl,XSync))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XBell=xp_dlsym(dl,XBell))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XLookupString=xp_dlsym(dl,XLookupString))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XNextEvent=xp_dlsym(dl,XNextEvent))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XAllocSizeHints=xp_dlsym(dl,XAllocSizeHints))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSetWMNormalHints=xp_dlsym(dl,XSetWMNormalHints))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XResizeWindow=xp_dlsym(dl,XResizeWindow))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XMapWindow=xp_dlsym(dl,XMapWindow))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XFree=xp_dlsym(dl,XFree))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XFreePixmap=xp_dlsym(dl,XFreePixmap))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCreatePixmap=xp_dlsym(dl,XCreatePixmap))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCopyArea=xp_dlsym(dl,XCopyArea))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCreateBitmapFromData=xp_dlsym(dl,XCreateBitmapFromData))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XAllocColor=xp_dlsym(dl,XAllocColor))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XOpenDisplay=xp_dlsym(dl,XOpenDisplay))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCreateSimpleWindow=xp_dlsym(dl,XCreateSimpleWindow))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XCreateGC=xp_dlsym(dl,XCreateGC))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSelectInput=xp_dlsym(dl,XSelectInput))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XStoreName=xp_dlsym(dl,XStoreName))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XGetSelectionOwner=xp_dlsym(dl,XGetSelectionOwner))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XConvertSelection=xp_dlsym(dl,XConvertSelection))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XGetWindowProperty=xp_dlsym(dl,XGetWindowProperty))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XChangeProperty=xp_dlsym(dl,XChangeProperty))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSendEvent=xp_dlsym(dl,XSendEvent))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XPutImage=xp_dlsym(dl,XPutImage))==NULL) { xp_dlclose(dl); return(-1); } #ifndef XDestroyImage if((x11.XDestroyImage=xp_dlsym(dl,XDestroyImage))==NULL) { xp_dlclose(dl); return(-1); } #endif #ifndef XPutPixel if((x11.XPutPixel=xp_dlsym(dl,XPutPixel))==NULL) { xp_dlclose(dl); return(-1); } #endif if((x11.XCreateImage=xp_dlsym(dl,XCreateImage))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSetSelectionOwner=xp_dlsym(dl,XSetSelectionOwner))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSetIconName=xp_dlsym(dl,XSetIconName))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSynchronize=xp_dlsym(dl,XSynchronize))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XGetWindowAttributes=xp_dlsym(dl,XGetWindowAttributes))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XAllocWMHints=xp_dlsym(dl,XAllocWMHints))==NULL) { xp_dlclose(dl); return(-1); } if((x11.XSetWMProperties=xp_dlsym(dl,XSetWMProperties))==NULL) { xp_dlclose(dl); return(-1); } if(sem_init(&pastebuf_set, 0, 0)) { xp_dlclose(dl); return(-1); } if(sem_init(&pastebuf_used, 0, 0)) { xp_dlclose(dl); sem_destroy(&pastebuf_set); return(-1); } if(sem_init(&init_complete, 0, 0)) { xp_dlclose(dl); sem_destroy(&pastebuf_set); sem_destroy(&pastebuf_used); return(-1); } if(sem_init(&mode_set, 0, 0)) { xp_dlclose(dl); sem_destroy(&pastebuf_set); sem_destroy(&pastebuf_used); sem_destroy(&init_complete); return(-1); } if(pthread_mutex_init(©buf_mutex, 0)) { xp_dlclose(dl); sem_destroy(&pastebuf_set); sem_destroy(&pastebuf_used); sem_destroy(&init_complete); sem_destroy(&mode_set); return(-1); } _beginthread(x11_event_thread,1<<16,NULL); _beginthread(x11_mouse_thread,1<<16,NULL); sem_wait(&init_complete); if(!x11_initialized) { xp_dlclose(dl); sem_destroy(&pastebuf_set); sem_destroy(&pastebuf_used); sem_destroy(&init_complete); sem_destroy(&mode_set); pthread_mutex_destroy(©buf_mutex); return(-1); } return(0); }
int main(int argc, char *argv[]) { u2_t *up; int i; char s[32]; // enable generation of core file in /tmp scall("core_pattern", system("echo /tmp/core-%e-%s-%u-%g-%p-%t > /proc/sys/kernel/core_pattern")); const struct rlimit unlim = { RLIM_INFINITY, RLIM_INFINITY }; scall("setrlimit", setrlimit(RLIMIT_CORE, &unlim)); for (i=1; i<argc; ) { if (strcmp(argv[i], "-bg")==0) { background_mode = TRUE; bg=1; } if (strcmp(argv[i], "-off")==0) do_off = 1; if (strcmp(argv[i], "-down")==0) down = 1; if (strcmp(argv[i], "+gps")==0) do_gps = 1; if (strcmp(argv[i], "-gps")==0) do_gps = 0; if (strcmp(argv[i], "+sdr")==0) do_sdr = 1; if (strcmp(argv[i], "-sdr")==0) do_sdr = 0; if (strcmp(argv[i], "+fft")==0) do_fft = 1; if (strcmp(argv[i], "-stats")==0 || strcmp(argv[i], "+stats")==0) { if (i+1 < argc && isdigit(argv[i+1][0])) { i++; print_stats = strtol(argv[i], 0, 0); } else { print_stats = 1; } } if (strcmp(argv[i], "-eeprom")==0) create_eeprom = true; if (strcmp(argv[i], "-cmap")==0) color_map = 1; if (strcmp(argv[i], "-sim")==0) wf_sim = 1; if (strcmp(argv[i], "-real")==0) wf_real = 1; if (strcmp(argv[i], "-time")==0) wf_time = 1; if (strcmp(argv[i], "-port")==0) { i++; alt_port = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-p")==0) { alt_port = 8074; } if (strcmp(argv[i], "-dump")==0 || strcmp(argv[i], "+dump")==0) { i++; ev_dump = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-flip")==0) wf_flip = 1; if (strcmp(argv[i], "-start")==0) wf_start = 1; if (strcmp(argv[i], "-mult")==0) wf_mult = 1; if (strcmp(argv[i], "-multgen")==0) wf_mult_gen = 1; if (strcmp(argv[i], "-wmax")==0) wf_max = 1; if (strcmp(argv[i], "-olap")==0) wf_olap = 1; if (strcmp(argv[i], "-meas")==0) meas = 1; // do_fft if (strcmp(argv[i], "-none")==0) unwrap = 0; if (strcmp(argv[i], "-norm")==0) unwrap = 1; if (strcmp(argv[i], "-rev")==0) unwrap = 2; if (strcmp(argv[i], "-qi")==0) rev_iq = 1; if (strcmp(argv[i], "-ineg")==0) ineg = 1; if (strcmp(argv[i], "-qneg")==0) qneg = 1; if (strcmp(argv[i], "-file")==0) fft_file = 1; if (strcmp(argv[i], "-fftsize")==0) { i++; fftsize = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-fftuse")==0) { i++; fftuse = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-np")==0) { i++; noisePwr = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-rcordic")==0) rx_cordic = 1; if (strcmp(argv[i], "-rcic")==0) rx_cic = 1; if (strcmp(argv[i], "-rcic2")==0) rx_cic2 = 1; if (strcmp(argv[i], "-rdump")==0) rx_dump = 1; if (strcmp(argv[i], "-wcordic")==0) wf_cordic = 1; if (strcmp(argv[i], "-wcic")==0) wf_cic = 1; if (strcmp(argv[i], "-clkg")==0) spi_clkg = 1; if (strcmp(argv[i], "-wspr")==0) { i++; wspr = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-avg")==0) { i++; navg = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-tone")==0) { i++; tone = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-slc")==0) { i++; do_slice = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-rx")==0) { i++; rx_num = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-wf")==0) { i++; wf_num = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-spispeed")==0) { i++; spi_speed = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-spi")==0) { i++; spi_delay = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-ch")==0) { i++; gps_chans = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-y")==0) { i++; rx_yield = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-p0")==0) { i++; p0 = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-p1")==0) { i++; p1 = strtol(argv[i], 0, 0); } if (strcmp(argv[i], "-p2")==0) { i++; p2 = strtol(argv[i], 0, 0); } i++; while (i<argc && ((argv[i][0] != '+') && (argv[i][0] != '-'))) { i++; } } lprintf("KiwiSDR v%d.%d\n", VERSION_MAJ, VERSION_MIN); lprintf("compiled: %s %s\n", __DATE__, __TIME__); cfg_reload(CALLED_FROM_MAIN); if (!alt_port) { FILE *fp = fopen("/root/.kiwi_down", "r"); if (fp != NULL) { fclose(fp); lprintf("down by lock file\n"); down = 1; } } TaskInit(); bool need_hardware = (do_gps || do_sdr) && !down; // called early, in case another server already running so we can detect the busy socket and bail web_server_init(WS_INIT_CREATE); if (need_hardware) { peri_init(); fpga_init(); //pru_start(); u2_t ctrl = CTRL_EEPROM_WP; ctrl_clr_set(0xffff, ctrl); if (do_off) { printf("ADC_CLOCK *OFF*\n"); xit(0); } #ifdef BUILD_PROTOTYPE if (!do_gps) // prevent interference to GPS by external ADC clock on prototype #endif { ctrl |= adc_clock_enable? CTRL_OSC_EN : CTRL_ADCLK_GEN; } ctrl_clr_set(0, ctrl); if (ctrl & (CTRL_OSC_EN | CTRL_ADCLK_GEN)) printf("ADC_CLOCK %.6f MHz, CTRL_OSC_EN=%d, CTRL_ADCLK_GEN=%d\n", adc_clock/MHz, (ctrl&CTRL_OSC_EN)?1:0, (ctrl&CTRL_ADCLK_GEN)?1:0); else printf("ADC_CLOCK *OFF*\n"); } if (do_fft) { printf("==== IQ %s\n", rev_iq? "reverse":"normal"); if (ineg) printf("==== I neg\n"); if (qneg) printf("==== Q neg\n"); printf("==== unwrap %s\n", (unwrap==0)? "none" : ((unwrap==1)? "normal":"reverse")); } rx_server_init(); web_server_init(WS_INIT_START); if (do_gps) { if (!GPS_CHANS) panic("no GPS_CHANS configured"); gps_main(argc, argv); } #if 0 static int tty; if (!background_mode) { tty = open("/dev/tty", O_RDONLY | O_NONBLOCK); if (tty < 0) sys_panic("open tty"); } #endif #if 0 static int tty; if (!background_mode) { tty = open("/dev/tty", O_RDONLY | O_NONBLOCK); if (tty < 0) sys_panic("open tty"); } #endif static u64_t stats_deadline = timer_us64() + 1000000; static u64_t secs; while (TRUE) { if (!need_hardware) { usleep(10000); // pause so we don't hog the machine NextTask("main usleep"); continue; } #if 0 if (!background_mode && (now - last_input) >= 1000) { #define N_IBUF 32 char ib[N_IBUF+1]; int n = read(tty, ib, N_IBUF); printf("tty %d\n", n); if (n >= 1) { ib[n] = 0; webserver_collect_print_stats(1); } last_input = now; } #endif if ((secs % STATS_INTERVAL_SECS) == 0) { if (do_sdr) { webserver_collect_print_stats(!do_gps); if (!do_gps) nbuf_stat(); } TaskCheckStacks(); } NextTask("main stats"); if (!do_gps && print_stats) { if (!background_mode) { lprintf("ECPU %4.1f%% cmds %d/%d malloc %d\n", ecpu_use(), ecpu_cmds, ecpu_tcmds, kiwi_malloc_stat()); ecpu_cmds = ecpu_tcmds = 0; TaskDump(); printf("\n"); } } u64_t now_us = timer_us64(); s64_t diff = stats_deadline - now_us; if (diff > 0) TaskSleep(diff); stats_deadline += 1000000; secs++; } }