double cmdfile(void) // reads command file /* drives the schedule with stop time yyyy:ddd:hh:mm:ss or LST:hh:mm:ss or just : for immediate scheduling or :n for scheduling for n secs - will wait for source to be within limits followed by keywords: sourcename (any name in catalog) stow calibrate quit clearint // clears intergation record (turns on data file if not already on) [filename] [recmode] roff (turns off data file) freq fcenter_MHz [bandwidth_MHz] mode n for 25 point b for beamswitch */ { double secs, secnow, lst, freq, bw; int i, j, n, line, yr, day, hr, min, se, ss; int da, mn, sc; int ix, iy; char str[256], txt[256]; char *p, *k; FILE *file1; GdkColor color; if ((file1 = fopen(d1.cmdfnam, "r")) == NULL) { printf(" Unable to open %s\n", d1.cmdfnam); return 0.0; } secs = secnow = d1.secs; i = 1; line = 0; ss = 0; k = 0; str[255] = 0; while ((k = fgets(str, 80, file1)) != 0 && i == 1) { line++; // printf("line %d %s",line,str); if (str[0] != '*' && str[0] != ' ' && str[0] != '#' && strlen(str) > 2 && line > d1.cmdfline) { if (str[0] != 'L' && str[0] != ':') { // yyyy:ddd:hh:mm:ss sscanf(str, "%d:%d:%d:%d:%d", &yr, &day, &hr, &min, &se); secs = tosecs(yr, day, hr, min, se); } // d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str); if (str[0] == 'L' && strstr(str, "LST")) { // "LST:%2d:%2d:%2d",&hr,&min,&sec hr = min = se = 0; sscanf(str, "LST:%d:%d:%d", &hr, &min, &se); lst = gst(secnow) - d1.lon; secs = hr * 3600.0 + min * 60.0 + se - lst * 86400.0 / (PI * 2.0); if (secs < 0) secs += 86400.0; if (secs > 86400.0) secs -= 86400.0; if (secs < 0) secs += 86400.0; if (secs > 86400.0) secs -= 86400.0; secs += secnow; } // d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str); if (str[0] == ':' && str[1] != ' ') { ss = 0; sscanf(str, ":%d", &ss); secs += ss; } // d.dtext(440.0, ylim + 40.0, gg, Color.red, "cmd err " + str); for (n = 0; n < (int) strlen(str); n++) if (str[n] == '\n') str[n] = ' '; if (secs >= secnow) { // System.out.println("secs "+secs+" secnow "+secnow); for (j = 0; j < d1.nsou; j++) { if ((p = strstr(str, sounam[j]))) { strncpy(soutrack, sounam[j], sizeof(soutrack) - 1); if (ss < 2) secs += 2; // add time d1.track = 1; d1.bsw = 0; d1.azoff = 0; d1.eloff = 0; // check for mode if (p && *p) { // note p before *p p = strchr(p, ' '); if (p && *p) { if (strchr(p, 'n')) { d1.scan = 1; } if (strchr(p, 'b')) { d1.bsw = 1; } } } } } if (strstr(str, "azel")) { j = sscanf(str, "%*s %*s %lf %lf", &d1.azcmd, &d1.elcmd); if (j == 2) { if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("cmdf %s", str); } if (ss < 2) secs += 2; // add time d1.track = 0; soutrack[0] = 0; } } if (strstr(str, "offset")) { sscanf(str, "%*s %*s %lf %lf", &d1.azoff, &d1.eloff); } if (strstr(str, "stow")) { d1.azcmd = d1.azlim1; d1.elcmd = d1.ellim1; soutrack[0] = 0; d1.stow = 1; } if (strstr(str, "calibrate")) d1.docal = 1; if (strstr(str, "record")) { d1.record = 1; if (sscanf(str, "%*s %*s %255s", d1.filname) == 1) d1.foutstatus = 1; } if (strstr(str, "quit") && d1.stow == -1) { d1.run = 0; gtk_exit(0); } if (strstr(str, "roff")) d1.record = 0; if (strstr(str, "clearint")) d1.clearint = 1; if (strstr(str, "freq")) { bw = 4.0; sscanf(str, "%*s %*s %lf %lf", &freq, &bw); if (bw > 0 && bw <= 10.0) d1.fbw = bw / d1.bw; if (freq > 1200.0 && freq < 1800.0) { d1.freq = freq; d1.iffreq = d1.freq - d1.lofreq; d1.f1 = d1.iffreq / d1.bw - d1.fbw * 0.5; d1.f2 = d1.iffreq / d1.bw + d1.fbw * 0.5; d1.fc = (d1.f1 + d1.f2) * 0.5; if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("new freq %f %f\n", d1.freq, d1.iffreq); } d1.freqchng = 1; } } } i = 0; ix = midx * 1.05; iy = midy * 0.99; if (d1.displ && str[0]) { color.red = 0; color.green = 0xffff; color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color); gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midx * 0.4, midy * 0.05); sprintf(txt, "line %2d %s", line, str); gdk_draw_text(pixmap, fixed_font, drawing_area->style->fg_gc[GTK_STATE_NORMAL], ix, iy, txt, strlen(txt) - 1); } if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("line %2d %s\n", line, str); } } } d1.cmdfline = line; fclose(file1); if (k == 0) { if (d1.displ) { ix = midx * 1.05; iy = midy * 0.99; color.red = 0; color.green = 0xffff; color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color); gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midx * 0.4, midy * 0.05); sprintf(txt, "line %2d : end_of_file", line); gdk_draw_text(pixmap, fixed_font, drawing_area->style->fg_gc[GTK_STATE_NORMAL], ix, iy, txt, strlen(txt) - 1); } d1.cmdfl = 0; d1.cmdfline = 0; } return secs; }
void azel(double az, double el) // command antenna movement { int kk, n, mm, ax, axis, count, ccount, rcount, flip; int ix, iy, midxr, ixe; int yr, da, hr, mn, sc; int region1, region2, region3; unsigned int base; double azscale, elscale, azz, ell, ra, dec, x, y; double elnow, lenzero, elcount; GdkColor color; int azatstow = 0; int elatstow = 0; char m[80], recv[80], str[80], str2[80], txt[80]; mm = count = 0; d1.slew = 0; lenzero = 0; ix = midx * 1.55; ixe = midx * 0.25; midxr = midx * 2 - ix; if (d1.lat >= 0.0) sprintf(txt, "%s %4.1fN %5.1fW", d1.statnam, d1.lat * 180.0 / PI, d1.lon * 180.0 / PI); else sprintf(txt, "%s %4.1fS %5.1fW", d1.statnam, -d1.lat * 180.0 / PI, d1.lon * 180.0 / PI); iy = midy * 0.05; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } sprintf(txt, "cmd %5.1f %4.1f deg", d1.azcmd, d1.elcmd); iy = midy * 0.15; if (d1.displ) gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); else if (d1.debug) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("%s\n", txt); } sprintf(txt, "offsets %5.1f %4.1f deg", d1.azoff, d1.eloff); iy = midy * 0.25; if (d1.displ) gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); base = d1.azelport; if (d1.azelsim == 0) { outb(128 + 3, base + 3); outb(0x30, base); outb(0, base + 1); // 2400 8 data 1 stop noparity outb(3, base + 3); outb(7, base + 1); outb(1, base + 2); outb(3, base + 4); sprintf(str, "antenna drive status:"); if (d1.comerr > 0) { sprintf(txt, " comerr= %d", d1.comerr); iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); } } } else { sprintf(txt, "antenna simulated"); iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } } if (az > 360.0) az -= 360.0; /* Fold into reasonable range */ if (d1.south == 0) { az = az + 360.0; /* put az in range 180 to 540 */ if (az > 540.0) az -= 360.0; if (az < 180.0) az += 360.0; } region1 = region2 = region3 = 0; if (az >= d1.azlim1 && az < d1.azlim2 && el >= d1.ellim1 && el <= d1.ellim2) region1 = 1; if (az > d1.azlim1 + 180.0 && el > (180.0 - d1.ellim2)) region2 = 1; if (az < d1.azlim2 - 180.0 && el > (180.0 - d1.ellim2)) region3 = 1; if (!region1 && !region2 && !region3) { sprintf(txt, "cmd out of limits"); iy = midy * 0.10; if (d1.displ) { color.red = 0xffff; color.green = color.blue = 0; gdk_color_parse("red", &color); gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color); gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->fg_gc[GTK_STATE_NORMAL], ix, iy, txt, strlen(txt)); } d1.track = 0; if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("cmd out of limits az %f el %f\n", az, el); } if (d1.stow != -1) { d1.stow = 1; d1.elcmd = d1.ellim1; d1.azcmd = d1.azlim1; } return; } flip = 0; if (az > d1.azlim2) { az -= 180.0; el = 180.0 - el; flip = 1; } if (az < d1.azlim1 && flip == 0) { az += 180.0; el = 180.0 - el; flip = 1; } azz = az - d1.azlim1; ell = el - d1.ellim1; // scale = 52.0 * 27.0 / 120.0; azscale = d1.azcounts_per_deg; elscale = d1.elcounts_per_deg; if (!d1.rod) elcount = ell * elscale; else { lenzero = d1.rod1 * d1.rod1 + d1.rod2 * d1.rod2 - 2.0 * d1.rod1 * d1.rod2 * cos((d1.rod4 - d1.ellim1) * PI / 180.0) - d1.rod3 * d1.rod3; if (lenzero >= 0.0) lenzero = sqrt(lenzero); else lenzero = 0; elcount = d1.rod1 * d1.rod1 + d1.rod2 * d1.rod2 - 2.0 * d1.rod1 * d1.rod2 * cos((d1.rod4 - el) * PI / 180.0) - d1.rod3 * d1.rod3; if (elcount >= 0.0) elcount = (-sqrt(elcount) + lenzero) * d1.rod5; else elcount = 0; // increase in length drives to horizon } /* mm=1=clockwize incr.az mm=0=ccw mm=2= down when pointed south */ if ((int) elcount > d1.elcount) axis = 1; // move in elevation first else axis = 0; for (ax = 0; ax < 2; ax++) { if (axis == 0) { if (azz * azscale > d1.azcount - 0.5) { mm = 1; count = (int) (azz * azscale - d1.azcount + 0.5); } if (azz * azscale <= d1.azcount + 0.5) { mm = 0; count = (int) (d1.azcount - azz * azscale + 0.5); } } else { if (elcount > d1.elcount - 0.5) { mm = 3; count = (int) (elcount - d1.elcount + 0.5); } if (elcount <= d1.elcount + 0.5) { mm = 2; count = (int) (d1.elcount - elcount + 0.5); } } ccount = count; if (d1.stow == 1 && d1.azcmd == d1.azlim1 && d1.elcmd == d1.ellim1) // drive to stow { count = 5000; if (axis == 0) { mm = 0; if (azatstow == 1) count = 0; } if (axis == 1) { mm = 2; // complete azimuth motion to stow before completely drop in elevation if (elatstow == 1 || (ccount <= 2.0 * d1.countperstep && azatstow == 0)) count = 0; } flip = 0; } if (count > d1.countperstep && ccount > d1.countperstep) count = d1.countperstep; if (count >= d1.ptoler && d1.track != -1) { if (count > d1.ptoler && d1.stow != -1) { d1.slew = 1; sprintf(txt, "ant slewing"); if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); if (soutrack[0]) { if (axis) printf("ant slewing in el to %s\n", soutrack); else printf("ant slewing in az to %s\n", soutrack); } if (d1.stow == 1) { if (axis) printf("ant slewing in el to stow\n"); else printf("ant slewing in az to stow\n"); } } iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } } if (d1.displ) { x = d1.azcmd * midx / 180.0; if (d1.south == 0) x -= midx; if (x < 0) x += midx * 2; if (x > midx * 2) x -= midx * 2; y = midy * 2 - d1.elcmd * midy * 2.0 / 180.0; color.red = 0; color.green = 0; color.blue = 0xffff; gdk_color_parse("blue", &color); gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color); gdk_draw_line(pixmap, drawing_area->style->fg_gc[GTK_STATE_NORMAL], x - 4, y, x + 4, y); gdk_draw_line(pixmap, drawing_area->style->fg_gc[GTK_STATE_NORMAL], x, y - 4, x, y + 4); } sprintf(str, " move %d %d \n", mm, count); /* need space at start and end */ n = 0; if (d1.azelsim != 0) { if (count < 5000) sprintf(str2, "M %d \n", count); else sprintf(str2, "T %d \n", count); strcpy(recv, str2); // n = str2.length(); } // d.dtext(16.0, 64.0, gg, Color.black, // "trans " + str.substring(0, str.length() - 1) + " "); kk = 0; { if (d1.azelsim == 0) { while ((inb(base + 2) & 1) == 0 && kk < KKTIMEOUT) { inb(base); kk++; } strcpy(m, str); // printf("sending\n"); for (n = 0; (unsigned) n < strlen(m); n++) { outb(m[n], base); while ((inb(base + 5) & 32) != 32); } if (d1.debug) printf("sent %s", m); for (n = 0; n < 80; n++) recv[n] = 0; kk = 0; n = 0; rcount = 0; } while (kk < KKTIMEOUT && kk >= 0) { if (d1.azelsim == 0) { while ((inb(base + 5) & 1) != 0) { recv[n] = inb(base); // printf("n=%d recv=%1c val=%d\n",n,recv[n],recv[n]); if (d1.displ == 0) printf("waiting %d\n", kk); if (recv[n] == 13) { kk = -99; break; } // if (d1.displ == 0) // printf ("n=%d ch=%1c\n", n, recv[n]); n++; } } else if (kk > 1) kk = -99; if (kk > 0) { if (axis == 0) sprintf(txt, "waiting on azimuth %d ", kk); else sprintf(txt, "waiting on elevation %d ", kk); iy = midy * 0.1; d1.slew = 1; if (d1.displ) { ix = midx * 1.55; midxr = midx * 2 - ix; // cleararea(); x = d1.azcmd * midx / 180.0; if (d1.south == 0) x -= midx; if (x < 0) x += midx * 2; if (x > midx * 2) x -= midx * 2; y = midy * 2 - d1.elcmd * midy * 2.0 / 180.0; color.red = 0; color.green = 0; color.blue = 0xffff; gdk_color_parse("blue", &color); gtk_widget_modify_fg(drawing_area, GTK_STATE_NORMAL, &color); gdk_draw_line(pixmap, drawing_area->style->fg_gc[GTK_STATE_NORMAL], x - 4, y, x + 4, y); gdk_draw_line(pixmap, drawing_area->style->fg_gc[GTK_STATE_NORMAL], x, y - 4, x, y + 4); gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); sprintf(txt, "cmd %5.1f %4.1f deg", d1.azcmd, d1.elcmd); iy = midy * 0.15; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); sprintf(txt, "azel %5.1f %4.1f deg", d1.aznow, d1.elnow); iy = midy * 0.20; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); sprintf(txt, "offsets %5.1f %4.1f deg", d1.azoff, d1.eloff); iy = midy * 0.25; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); azel_to_radec(d1.secs, d1.aznow, d1.elnow, &ra, &dec); sprintf(txt, "ra %5.1f hr %4.1f deg", ra * 12.0 / PI, dec * 180.0 / PI); iy = midy * 0.30; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); color.green = color.red = color.blue = 0xffff; gtk_widget_modify_bg(button_stow, GTK_STATE_NORMAL, &color); if (!d1.plot) { Repaint(); } // cleararea(); while (gtk_events_pending() || d1.stopproc) { gtk_main_iteration(); // d1.plot = 0; } } else if (d1.debug) printf("%s\n", txt); sleep(1); } kk++; } if (d1.debug) printf("recv %s\n", recv); } // printf(" axis %d\n",axis); if (recv[0] != 'M' && recv[0] != 'T') { sprintf(txt, "comerr kk=%d n=%d mm%d", kk, n, count); iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); } d1.comerr++; // if (d1.fstatus == 1) // o.stroutfile(g, "* ERROR comerr"); if (d1.mainten == 0) d1.stow = 1; return; } // if (d1.azelsim != 0 && d1.azelsim < 10) sleep(1); sprintf(txt, "recv %s", str); iy = midy * 0.05; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt) - 1); } rcount = 0; sscanf(recv, "%*s %d", &rcount); if (rcount != count && ((axis == 0 && d1.azcmd != d1.azlim1) || (axis == 1 && d1.elcmd != d1.ellim1))) { // printf("lost count\n"); sprintf(txt, "lost count goto Stow"); d1.limiterr = 1; soutrack[0] = 0; iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); sprintf(txt, "ERROR: received %d counts out of %d counts expected", rcount, count); iy = midy * 0.15; gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); if (mm == 1) sprintf(txt, "while going clockwise in azimuth"); if (mm == 0) sprintf(txt, "while going counter-clockwise in azimuth"); if (mm == 3) sprintf(txt, "while going clockwise in elevation"); if (mm == 2) sprintf(txt, "while going counter-clockwise in elevation"); iy = midy * 0.20; gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); sprintf(txt, "motor stalled or limit prematurely reached"); iy = midy * 0.25; gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ixe, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ixe, iy, txt, strlen(txt)); } // if (d1.fstatus == 1) // stroutfile("* ERROR lost count"); if (d1.mainten == 0) { if (mm == 2 && recv[0] == 'T') // could hit limit at source set { d1.elcount = 0; d1.elnow = d1.ellim1; } elatstow = azatstow = 0; d1.stow = 1; d1.azcmd = d1.azlim1; d1.elcmd = d1.ellim1; } return; } if (mm == 2 && recv[0] == 'T') { elatstow = 1; d1.elcount = 0; d1.elnow = d1.ellim1; } if (mm == 0 && recv[0] == 'T') { azatstow = 1; d1.azcount = 0; d1.aznow = d1.azlim1; } if (recv[0] == 'T' && d1.stow == 0) { // printf("timeout from antenna\n"); sprintf(txt, "timeout from antenna"); iy = midy * 0.1; if (d1.displ) { gdk_draw_rectangle(pixmap, drawing_area->style->white_gc, TRUE, ix, iy - midy * 0.04, midxr, midy * 0.05); gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } } if (recv[0] == 'M') { if (axis == 0) { azatstow = 0; if (mm == 1) d1.azcount = d1.azcount + count; else d1.azcount = d1.azcount - count; } if (axis == 1) { elatstow = 0; if (mm == 3) d1.elcount = d1.elcount + count; else d1.elcount = d1.elcount - count; } } if (d1.azelsim == 0 && d1.slew) sleep(1); } axis++; if (axis > 1) axis = 0; } if (d1.track != -1) { if (d1.slew == 1) d1.track = 0; else d1.track = 1; } d1.aznow = d1.azlim1 + d1.azcount / azscale; if (d1.aznow > 360.0) d1.aznow = d1.aznow - 360.0; if (!d1.rod) elnow = d1.elcount / elscale; else { elnow = -d1.elcount / d1.rod5 + lenzero; elnow = d1.rod1 * d1.rod1 + d1.rod2 * d1.rod2 - d1.rod3 * d1.rod3 - elnow * elnow; elnow = elnow / (2.0 * d1.rod1 * d1.rod2); elnow = -acos(elnow) * 180.0 / PI + d1.rod4 - d1.ellim1; } d1.elnow = d1.ellim1 + elnow; if (d1.elnow > 90.0) { if (d1.aznow >= 180.0) d1.aznow = d1.aznow - 180.0; else d1.aznow = d1.aznow + 180.0; d1.elnow = 180.0 - d1.elnow; } // d.dtext(670.0, 40.0, gg, Color.black, // "azel " + d.dc(d1.aznow(), 5, 1) + " " + d.dc(d1.elnow(), 5, 1) + // " deg"); x = (int) (d1.aznow * 640.0 / 360.0); if (d1.south == 0) { x -= 320; if (x < 0) x += 640; } if (fabs(d1.aznow - d1.azlim1) < 1e-6 && fabs(d1.elnow - d1.ellim1) < 1e-6) { if (d1.displ) { color.green = 0xffff; color.red = color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_bg(button_stow, GTK_STATE_NORMAL, &color); gtk_tooltips_set_tip(tooltips, button_stow, "antenna at stow", NULL); gtk_tooltips_set_tip(tooltips, button_exit, "click to exit program", NULL); // printf("in green\n"); } d1.stow = -1; // at stow } else { if (d1.displ) { color.green = color.red = color.blue = 0xffff; gtk_widget_modify_bg(button_stow, GTK_STATE_NORMAL, &color); gtk_tooltips_set_tip(tooltips, button_stow, "click to stow antenna", NULL); if (d1.track != -1) gtk_tooltips_set_tip(tooltips, button_exit, "go to stow first", NULL); } if (d1.stow == -1) d1.stow = 0; } if (d1.stow != 0) { d1.track = 0; } if (d1.displ) { sprintf(txt, "azel %5.1f %4.1f deg", d1.aznow, d1.elnow); iy = midy * 0.20; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); azel_to_radec(d1.secs, d1.aznow, d1.elnow, &ra, &dec); sprintf(txt, "ra %5.1f hr %4.1f deg", ra * 12.0 / PI, dec * 180.0 / PI); iy = midy * 0.30; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); sprintf(txt, "cmd %5.1f %4.1f deg", d1.azcmd, d1.elcmd); iy = midy * 0.15; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); sprintf(txt, "offsets %5.1f %4.1f deg", d1.azoff, d1.eloff); iy = midy * 0.25; gdk_draw_text(pixmap, fixed_font, drawing_area->style->black_gc, ix, iy, txt, strlen(txt)); } else if (d1.debug) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); printf("now %s tant %5.1f Source: %s\n", txt, d1.tant, soutrack); } return; }
int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *button_clear, *button_azel, *button_freq, *button_offset; GtkWidget *button_help; GdkColor color; int i, ii; int yr, da, hr, mn, sc; double secstart; char buf[64]; GdkGeometry geometry; GdkWindowHints geo_mask; // GdkRectangle update_rect; sprintf(d1.catnam, "srt.cat"); sprintf(d1.hlpnam, "srt.hlp"); for (i = 0; i < argc - 1; i++) { sscanf(argv[i], "%63s", buf); if (strstr(buf, "-c") && strlen(buf) == 2) sscanf(argv[i + 1], "%63s", d1.catnam); if (strstr(buf, "-h") && strlen(buf) == 2) sscanf(argv[i + 1], "%63s", d1.hlpnam); } // d1.azelport = 0x3f8; // com1 default for old SRT d1.ver = 4; // SRT software version d1.secs = readclock(); d1.run = 1; d1.record = 0; d1.entry1 = d1.entry2 = d1.entry3 = d1.entry5 = d1.entry6 = d1.entry8 = d1.helpwindow = d1.vwindow = 0; d1.plot = 0; d1.start_time = 0.0; d1.start_sec = 0.0; d1.speed_up = 0; d1.ppos = 0; d1.printout = 1; d1.debug = 0; d1.freq = 1420.4; // default d1.bw = 0; // set to 2.4 for TV dongle 10 MHz for ADC card in init d1.fbw = 0; // set in init or srt.cat d1.nblk = 5; // number of blocks in vspectra d1.record_int_sec = 0; d1.freqcorr = 0; // frequency correction for L.O. may be needed for TV dongle d1.freqchng = 0; d1.clearint = 0; d1.record_clearint = 0; d1.noclearint = 0; d1.nfreq = NSPEC; d1.plotsec = 1; d1.displ = 1; d1.noisecal = 0; // used for old SRT mount and controller // d1.ptoler = 1; // d1.countperstep = 10000; // default large number for no stepping // d1.elcounts_per_deg = (52.0 * 27.0 / 120.0); // default for H-180 // d1.azcounts_per_deg = 8.0 * 32.0 * 60.0 / (360.0 * 9.0); // default for CASSIMOUNT // d1.rod = 1; // default to rod as on CASSIMOUNT // d1.rod1 = 14.25; // rigid arm length // d1.rod2 = 16.5; // distance from pushrod upper joint to el axis // d1.rod3 = 2.0; // pushrod collar offset // d1.rod4 = 110.0; // angle at horizon // d1.rod5 = 30.0; // pushrod counts per inch d1.azelsim = d1.radiosim = d1.fftsim = 0; d1.mainten = 0; d1.stowatlim = 1; d1.rms = -1; // display max not rms d1.calcons = 1.0; d1.caldone = 0; d1.nrfi = 0; d1.rfisigma = 6; // level for RFI reporting to screen d1.tload = 300.0; d1.tspill = 20.0; d1.beamw = 5.0; d1.comerr = 0; d1.limiterr = 0; d1.restfreq = 1420.406; /* H-line restfreq */ d1.delay = 0; d1.azoff = 0.0; d1.eloff = 0.0; d1.drift = 0; d1.tstart = 0; d1.tsys = 100.0; // expected on cold sky d1.pwroff = 0.0; d1.tant = 100.0; d1.calpwr = 0; d1.yfac = 0; d1.calon = 0; d1.calmode = 0; d1.docal = 0; d1.tcal = 290; // absorber or bushes d1.sourn = 0; d1.track = 0; d1.scan = 0; d1.bsw = 0; d1.nbsw = 1; d1.obsn = 0; d1.stopproc = 0; d1.fstatus = 0; d1.cmdfl = 0; d1.south = 1; d1.hgt = 0; d1.dongle = 0; // set to zero initially - set to 1 in Init_Device if dongle d1.npoly = 25; // number of terms in polynomial fit of bandpass pwrst = pwrprev = 0.0; soutrack[0] = 0; sprintf(d1.cmdfnam, "cmd.txt"); sprintf(d1.datadir, "./"); // default to local directory if (!catfile()) return 0; d1.foutstatus = 0; // to get permission su root chown root srtn then chmod u+s srtn then exit if (!d1.azelsim) { if (d1.printout) printf("initializing antenna controller\n"); i = rot2(&d1.aznow, &d1.elnow, -1, buf); // initialize i = rot2(&d1.aznow, &d1.elnow, 1, buf); // read if (i < 0) { printf("Couldn't talk to antenna controller\n"); return 0; } } else { if (d1.stowatlim) { d1.azprev = d1.azlim1; d1.elprev = d1.ellim1; } else { d1.azprev = d1.stowaz; d1.elprev = d1.stowel; } } setgid(getgid()); setuid(getuid()); if (d1.mainten == 0) { if (d1.stowatlim) { d1.azcmd = d1.azlim1; d1.elcmd = d1.ellim1; } else { d1.azcmd = d1.stowaz; d1.elcmd = d1.stowel; } d1.azcount = 0; d1.elcount = 0; d1.stow = 1; } if (d1.azlim1 > d1.azlim2) { d1.south = 0; // dish pointing North for southern hemisphere if (d1.azlim2 < 360.0) d1.azlim2 += 360.0; } if (!d1.radiosim) Init_Device(0); if (d1.displ) { gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); geometry.min_width = 500; geometry.min_height = 300; geo_mask = GDK_HINT_MIN_SIZE; gtk_window_set_geometry_hints(GTK_WINDOW(window), window, &geometry, geo_mask); //Table size determines number of buttons across the top table = gtk_table_new(30, NUMBUTTONS, TRUE); drawing_area = gtk_drawing_area_new(); gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); color.red = 0xffff; color.blue = 0xffff; color.green = 0xffff; gtk_widget_show(drawing_area); gtk_table_attach_defaults(GTK_TABLE(table), drawing_area, 0, NUMBUTTONS, 3, 30); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(quit), NULL); gtk_container_add(GTK_CONTAINER(window), table); g_signal_connect(G_OBJECT(drawing_area), "expose_event", (GtkSignalFunc) expose_event, NULL); g_signal_connect(G_OBJECT(drawing_area), "configure_event", (GtkSignalFunc) configure_event, NULL); g_signal_connect(G_OBJECT(drawing_area), "button_press_event", (GtkSignalFunc) button_press_event, NULL); gtk_widget_set_events(drawing_area, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); button_clear = gtk_button_new_with_label("clear"); button_stow = gtk_button_new_with_label("stow"); button_azel = gtk_button_new_with_label("azel"); button_npoint = gtk_button_new_with_label("npoint"); button_bsw = gtk_button_new_with_label("beamsw"); button_freq = gtk_button_new_with_label("freq"); button_offset = gtk_button_new_with_label("offset"); button_record = gtk_button_new_with_label("record"); button_cmdfl = gtk_button_new_with_label("cmdfl"); button_cal = gtk_button_new_with_label("cal"); button_help = gtk_button_new_with_label("help"); button_exit = gtk_button_new_with_label("exit"); g_signal_connect(G_OBJECT(button_clear), "clicked", G_CALLBACK(button_clear_clicked), NULL); g_signal_connect(G_OBJECT(button_stow), "clicked", G_CALLBACK(button_stow_clicked), NULL); g_signal_connect(G_OBJECT(button_azel), "clicked", G_CALLBACK(button_azel_clicked), NULL); g_signal_connect(G_OBJECT(button_npoint), "clicked", G_CALLBACK(button_npoint_clicked), NULL); g_signal_connect(G_OBJECT(button_bsw), "clicked", G_CALLBACK(button_bsw_clicked), NULL); g_signal_connect(G_OBJECT(button_freq), "clicked", G_CALLBACK(button_freq_clicked), NULL); g_signal_connect(G_OBJECT(button_offset), "clicked", G_CALLBACK(button_offset_clicked), NULL); g_signal_connect(G_OBJECT(button_record), "clicked", G_CALLBACK(button_record_clicked), NULL); g_signal_connect(G_OBJECT(button_cmdfl), "clicked", G_CALLBACK(button_cmdfl_clicked), NULL); g_signal_connect(G_OBJECT(button_cal), "clicked", G_CALLBACK(button_cal_clicked), NULL); g_signal_connect(G_OBJECT(button_help), "clicked", G_CALLBACK(button_help_clicked), NULL); g_signal_connect(G_OBJECT(button_exit), "clicked", G_CALLBACK(button_exit_clicked), NULL); // test setting up tooltips instead of the "enter"/"leave" used below tooltips = gtk_tooltips_new(); gtk_tooltips_set_tip(tooltips, button_clear, "click to clear integration and reset time plot to 1/4-scale", NULL); gtk_tooltips_set_tip(tooltips, button_stow, "click to stow antenna", NULL); gtk_tooltips_set_tip(tooltips, button_azel, "click to enter az el coordinates", NULL); gtk_tooltips_set_tip(tooltips, button_npoint, "click to start npoint scan", NULL); gtk_tooltips_set_tip(tooltips, button_bsw, "click to start beam switch", NULL); gtk_tooltips_set_tip(tooltips, button_freq, "click to enter new frequency in MHz [bandwidth] [nfreq]", NULL); gtk_tooltips_set_tip(tooltips, button_offset, "click to enter offsets", NULL); if (!d1.cmdfl) gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to start cmd file", NULL); else gtk_tooltips_set_tip(tooltips, button_cmdfl, "click to stop cmd file", NULL); gtk_tooltips_set_tip(tooltips, button_cal, "click to start calibration", NULL); gtk_tooltips_set_tip(tooltips, button_help, "click to open help window", NULL); record_tooltip(); gtk_table_attach(GTK_TABLE(table), button_clear, 0, 1, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_stow, 1, 2, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_azel, 2, 3, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_npoint, 3, 4, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_bsw, 4, 5, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_freq, 5, 6, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_offset, 6, 7, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_record, 7, 8, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_cmdfl, 8, 9, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_cal, 9, 10, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_help, 10, 11, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_table_attach(GTK_TABLE(table), button_exit, 11, 12, 0, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(button_clear); gtk_widget_show(button_stow); gtk_widget_show(button_azel); gtk_widget_show(button_npoint); gtk_widget_show(button_bsw); gtk_widget_show(button_freq); gtk_widget_show(button_offset); gtk_widget_show(button_record); gtk_widget_show(button_cmdfl); gtk_widget_show(button_cal); gtk_widget_show(button_help); gtk_widget_show(button_exit); gtk_widget_show(table); gtk_widget_show(window); clearpaint(); } ii = 0; if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); } zerospectra(0); for (i = 0; i < d1.nfreq; i++) bspec[i] = 1; secstart = d1.nsecstart = -1; d1.secs = readclock(); while (d1.run) { zerospectra(1); if (d1.clearint) { if (d1.displ) cleararea(); zerospectra(0); d1.clearint = 0; } if (d1.freqchng) { if (d1.dongle) Init_Device(1); if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s ", yr, da, hr, mn, sc, d1.timsource); } if (!d1.radiosim) { sleep(1); } zerospectra(0); d1.freqchng = 0; } if (d1.docal) { if (d1.docal == 1) { sprintf(d1.recnote, "* calibration started\n"); outfile(d1.recnote); } if (d1.bsw) { d1.bsw = 0; d1.azoff = 0.0; } if (d1.scan) { d1.scan = 0; d1.eloff = d1.azoff = 0.0; } if (d1.slew) d1.slew = 0; if (d1.docal == 1) cal(0); d1.docal = 2; cal(1); if (d1.integ >= NCAL) { cal(2); d1.docal = 0; } } if (d1.displ) cleararea(); azel(d1.azcmd, d1.elcmd); // allow time after cal if (d1.comerr == -1) return 0; if (!d1.slew) { pwr = 0.0; } if (!d1.slew) vspectra(); d1.secs = readclock(); aver(); d1.integ2++; if (d1.record_int_sec && d1.integ2 >= d1.record_int_sec) { outfile(" "); if (d1.record_clearint && d1.track && !d1.bsw && !d1.scan) d1.clearint = 1; d1.integ2 = 0; } if (d1.displ) { if (!d1.plot) Repaint(); while (gtk_events_pending() || d1.stopproc == 1) { gtk_main_iteration(); d1.plot = 0; } } if (!d1.displ && d1.domap) scanplot(); } return 0; }
void outfile(void) { int yr, da, hr, mn, sc, i, istart, istop; float freqsep, sigma; GdkColor color; static FILE *file1 = NULL; //static int n; if (!d1.record) return; if (d1.foutstatus == 0) // set filename { //n = 0; toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); d1.rday = da; if (d1.filname[0] == 0) sprintf(d1.filname, "%s%4d_%03d_%02d.rad", d1.datadir, yr, da, hr); if (d1.displ) { color.green = 0xffff; color.red = 0; color.blue = 0; gdk_color_parse("green", &color); gtk_widget_modify_bg(button_record, GTK_STATE_NORMAL, &color); } } if ((file1 = fopen(d1.filname, "a")) == NULL) { if ((file1 = fopen(d1.filname, "w")) == NULL) { d1.foutstatus = -99; printf("cannot write %s\n", d1.filname); return; } d1.obsn = 0; // file was new so reset obsn d1.foutstatus = 1; } else d1.foutstatus = 1; toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); if (d1.foutstatus == 1) { if (d1.newday && da != d1.rday) { fclose(file1); d1.foutstatus = 0; toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); sprintf(d1.filname, "%s%4d_%03d_%02d.rad", d1.datadir, yr, da, hr); if ((file1 = fopen(d1.filname, "w")) == NULL) { d1.foutstatus = -99; return; } d1.foutstatus = 1; } if (d1.printout) { toyrday(d1.secs, &yr, &da, &hr, &mn, &sc); printf("%4d:%03d:%02d:%02d:%02d %3s file: %s pwr %f\n", yr, da, hr, mn, sc, d1.timsource, d1.filname, pwr); } } freqsep = d1.bw / d1.nfreq; if (soutrack[0] > 0) fprintf(file1, "DATE %4d:%03d:%02d:%02d:%02d obsn %3d az %3.0f el %2.0f freq_MHz %10.4f Tsys %6.3f Tant %6.3f vlsr %7.2f glat %6.3f glon %6.3f source %s\n", yr, da, hr, mn, sc, d1.obsn, d1.aznow, d1.elnow, d1.freq, d1.tsys, d1.tant, d1.vlsr, d1.glat, d1.glon, soutrack); else fprintf(file1, "DATE %4d:%03d:%02d:%02d:%02d obsn %3d az %3.0f el %2.0f freq_MHz %10.4f Tsys %6.3f Tant %6.3f vlsr %7.2f glat %6.3f glon %6.3f source at_stow\n", yr, da, hr, mn, sc, d1.obsn, d1.aznow, d1.elnow, d1.freq, d1.tsys, d1.tant, d1.vlsr, d1.glat, d1.glon); if (d1.record_spec) { istart = d1.f1 * d1.nfreq + 0.5; istop = d1.f2 * d1.nfreq + 0.5; sigma = d1.tsys / sqrt((d1.nsam * d1.integ / (2.0e6 * d1.bw)) * freqsep * 1e6); if (d1.bsw) sigma = 2.0 * sigma; fprintf(file1, "Fstart %8.3f fstop %8.3f spacing %8.6f bw %8.3f fbw %8.3f MHz nfreq %d nsam %d npoint %d integ %5.0f sigma %8.3f bsw %d\n", istart * d1.bw / d1.nfreq + d1.efflofreq, istop * d1.bw / d1.nfreq + d1.efflofreq, freqsep, d1.bw, d1.fbw, d1.nfreq, d1.nsam, istop - istart, d1.integ * d1.nsam / (2.0e6 * d1.bw), sigma, d1.bsw); fprintf(file1, "Spectrum \n"); for (i = istart; i < istop; i++) fprintf(file1, "%8.3f ", aavspec[i]); fprintf(file1, "\n"); } d1.obsn++; if (d1.foutstatus == 1) fclose(file1); d1.rday = da; }
void zerospectra(int mode) { int i, j, yr, da, hr, mn, sc; double az, el, secs, ra, dec; secs = d1.secs; if (!mode) { for (i = 0; i < d1.nfreq; i++) avspec[i] = avspecoff[i] = avspecon[i] = 0; d1.pwron = d1.pwroff = 0; d1.numon = d1.numoff = d1.integ = 0; } if (d1.cmdfl && secs > d1.secstop && !d1.slew && !d1.scan && !d1.docal && mode) d1.secstop = cmdfile(); d1.vlsr = 0.0; az = -1; for (i = 0; d1.track >= 0 && i < d1.nsou; i++) { if (strstr(sounam[i], soutrack) && soutrack[0]) { toyrday(secs, &yr, &da, &hr, &mn, &sc); d1.year = yr; if (strstr(sounam[i], "Sun") || strstr(sounam[i], "Moon")) { if (strstr(sounam[i], "Sun")) sunradec(secs, &ra, &dec); else moonradec(secs, &ra, &dec); radec_azel(gst(secs) - ra - d1.lon, dec, d1.lat, &az, &el); } else if (soutype[i]) { az = ras[i] * PI / 180.0; el = decs[i] * PI / 180.0; azel_to_radec(secs, ras[i], decs[i], &ra, &dec); } else { precess(ras[i], decs[i], &ra, &dec, epoc[i], d1.year); radec_azel(gst(secs) - ra - d1.lon, dec, d1.lat, &az, &el); } d1.vlsr = vlsr(secs, ra, dec); sprintf(souinfo, "%s %4d", to_radecp(ra, dec), yr); } } if (d1.track && az >= 0.0) { if (d1.scan > 0) { i = (d1.scan - 1) / 5; j = (d1.scan - 1) % 5; d1.eloff = (i - 2) * d1.beamw * 0.5; d1.azoff = (j - 2) * d1.beamw * 0.5 / cos(el + d1.eloff * PI / 180.0); d1.scan++; if (d1.scan > 26) { d1.scan = 0; if (d1.displ) gtk_tooltips_set_tip(tooltips, button_npoint, "click to start npoint scan", NULL); d1.azoff = d1.eloff = 0; d1.domap = 1; } } if (d1.bsw == 1) d1.bswint = 0; if (d1.bsw > 0 && d1.bswint == 0) { if (d1.bsw == 1) d1.clearint = 1; i = (d1.bsw - 1) % 4; j = 0; if (i == 1) j = -1; if (i == 3) j = 1; d1.azoff = j * d1.beamw / cos(el); d1.bsw++; } } if (az >= 0 && d1.stow != 1) { d1.azcmd = az * 180.0 / PI + d1.azoff; d1.elcmd = el * 180.0 / PI + d1.eloff; // printf("inzero azcmd %f ellim2 %f\n",d1.azcmd,d1.ellim2); } else { azel_to_radec(secs, d1.azcmd, d1.elcmd, &ra, &dec); d1.vlsr = vlsr(secs, ra, dec); } if (mode == 0) { d1.integ = 0.0; pwr = 0.0; } }