std::string BundleAuthenticationBlock::calcMAC(const dtn::data::Bundle& bundle, const dtn::security::SecurityKey &key, const bool with_correlator, const dtn::data::Number &correlator)
		{
			std::string hmac_key = key.getData();
			ibrcommon::HMacStream hms((const unsigned char*)hmac_key.c_str(), static_cast<int>(hmac_key.length()));
			dtn::security::StrictSerializer ss(hms, BUNDLE_AUTHENTICATION_BLOCK, with_correlator, correlator);
			(dtn::data::DefaultSerializer&)ss << bundle;
			hms << std::flush;

			return ibrcommon::HashStream::extract(hms);
		}
Пример #2
0
	void jd_to_gregorian(jd_t jd, year_t& year, month_t& month, day_t& day, hour_t& hour, minute_t& minute, second_t& second) {
		hms(hms_from_jd(jd), hour, minute, second);
		jd = floor(jd - 0.5) + 0.5;
		long long a = static_cast<long long>(jd + 0.5) + 32044;
		long long b = (4 * a + 3) / 146097;
		long long c = a - b * 146097 / 4;
		long long d = (4 * c + 3) / 1461;
		long long e = c - 1461 * d / 4;
		long long m = (5 * e + 2) / 153;
		day = static_cast<day_t>(e - (153 * m + 2) / 5 + 1);
		month = static_cast<month_t>(m + 3 - 12 * (m / 10));
		year = b * 100 + d - 4800 + m / 10;
	}
Пример #3
0
	void jd_to_hebrew(jd_t jd, year_t& year, month_t& month, day_t& day, hour_t& hour, minute_t& minute, second_t& second) {
		hms(hms_from_jd(jd), hour, minute, second);
		jd = floor(jd) + 0.5;
		year_t count = static_cast<year_t>(floor(((jd - HEBREW_EPOCH) * 98496) / 35975351.0));
		year = count - 1;

		year_t i = count;
		while (jd >= hebrew_to_jd(i++, 7, 1))
			++year;

		month_t first = jd < hebrew_to_jd(year, 1, 1) ? 7 : 1;
		
		month = first;

		month_t j = first;
		while (jd > hebrew_to_jd(year, j++, hebrew_days_in_month(year, j)))
			++month;
			
		day = static_cast<day_t>(floor(jd - hebrew_to_jd(year, month, 1) + 1));
	}
Пример #4
0
void DISPLAY::drawData(int page) {
    char s[80];
    switch(page) {
        case 0:
            if (EventCatch(EVT_PRN)) {
                sprintf(s, "%2d %3.0f", StatPRN, StatSNR);
                writeAt(4, 0, s);
            }
            if (EventCatch(EVT_BARS)) {
                setCursor(0, 1);
                for (int i=0; i<NUM_CHANS; i++) write(StatBars[i]);
            }
            break;
        case 1:
            if (EventCatch(EVT_POS)) {
                sprintf(s, "%-5d %8.5f %c", StatChans, StatLat, StatNS);
                writeAt(0, 0, s);
                sprintf(s, "%-5.0f %8.5f %c", StatAlt, StatLon, StatEW);
                writeAt(0, 1, s);
            }
            break;
        case 2:
            if (EventCatch(EVT_POS)) {
                UMS lat(StatLat), lon(StatLon);
                sprintf(s, "%2d\xDF%3d\xDF%7.3f %c", lat.u, lat.m, lat.s, StatNS);
                writeAt(0, 0, s);
                sprintf(s, "%2d\xDF%3d\xDF%7.3f %c", lon.u, lon.m, lon.s, StatEW);
                writeAt(0, 1, s);
            }
            break;
        case 3:
            if (EventCatch(EVT_TIME)) {
                UMS hms(StatSec/60/60);
                sprintf(s, "%s %02d:%02d:%02.0f", Week[StatDay], hms.u, hms.m, hms.s);
                writeAt(0, 0, s);
            }
    }
}
Пример #5
0
static void Command_Cd_f (void)
{
	LPCSTR    s;
	int       i,j;

	if (!cdaudio_started)
		return;

	if (COM_Argc()<2)
	{
		CONS_Printf ("cd [on] [off] [remap] [reset] [open]\n"
		             "   [info] [play <track>] [loop <track>]\n"
		             "   [stop] [resume]\n");
		return;
	}

	s = COM_Argv(1);

	// activate cd music
	if (!strncmp(s,"on",2))
	{
		cdEnabled = true;
		return;
	}

	// stop/deactivate cd music
	if (!strncmp(s,"off",3))
	{
		if (cdPlaying)
			I_StopCD ();
		cdEnabled = false;
		return;
	}

	// remap tracks
	if (!strncmp(s,"remap",5))
	{
		i = (int)COM_Argc() - 2;
		if (i <= 0)
		{
			CONS_Printf ("CD tracks remapped in that order :\n");
			for (j = 1; j < MAX_CD_TRACKS; j++)
				if (cdRemap[j] != j)
					CONS_Printf (" %2d -> %2d\n", j, cdRemap[j]);
			return;
		}
		for (j = 1; j <= i; j++)
			cdRemap[j] = (UINT8)atoi (COM_Argv (j+1));
		return;
	}

	// reset the CD driver, useful on some odd cd's
	if (!strncmp(s,"reset",5))
	{
		cdEnabled = true;
		if (cdPlaying)
			I_StopCD ();
		for (i = 0; i < MAX_CD_TRACKS; i++)
			cdRemap[i] = (UINT8)i;
		CD_Reset();
		cdValid = CD_ReadTrackInfo();
		return;
	}

	// any other command is not allowed until we could retrieve cd information
	if (!cdValid)
	{
		CONS_Printf ("CD is not ready.\n");
		return;
	}

	/* faB: not with MCI, didn't find it, useless anyway
	if (!strncmp(s,"open",4))
	{
		if (cdPlaying)
			I_StopCD ();
		bcd_open_door();
		cdValid = false;
		return;
	}*/

	if (!strncmp(s,"info",4))
	{
		if (!CD_ReadTrackInfo())
		{
			cdValid = false;
			return;
		}

		cdValid = true;

		if (m_nTracksCount <= 0)
			CONS_Printf ("No audio tracks\n");
		else
		{
			// display list of tracks
			// highlight current playing track
			for (i = 0; i < m_nTracksCount; i++)
			{
				CONS_Printf("%s%2d. %s  %s\n",
				            cdPlaying && (cdPlayTrack == i) ? "\2 " : " ",
				            i+1, m_nTracks[i].IsAudio ? "audio" : "data ",
				            hms(m_nTracks[i].Length));
			}
			CONS_Printf ("\2Total time : %s\n", hms(CD_TotalTime()));
		}
		if (cdPlaying)
		{
			CONS_Printf ("%s track : %d\n", cdLooping ? "looping" : "playing",
			             cdPlayTrack);
		}
		return;
	}

	if (!strncmp(s,"play",4))
	{
		I_PlayCD ((UINT8)atoi(COM_Argv (2)), false);
		return;
	}

	if (!strncmp(s,"stop",4))
	{
		I_StopCD ();
		return;
	}

	if (!strncmp(s,"loop",4))
	{
		I_PlayCD ((UINT8)atoi(COM_Argv (2)), true);
		return;
	}

	if (!strncmp(s,"resume",4))
	{
		I_ResumeCD ();
		return;
	}

	CONS_Printf ("cd command '%s' unknown\n", s);
}
Пример #6
0
void screen(char *source,double *lst_disp,double *utc_disp,double *tjd_disp,
	double *ra_disp,double *dec_disp, 
	double *ra_cat_disp, double *dec_cat_disp,
	double *az_disp,
	double *el_disp,int *icount,double *azoff,double *eloff,int *icflag,
	double *az_actual_corrected,double *el_actual_disp,double *tiltx, double *tilty,int *initflag,int *pvt,float *pressure, float *temperature, float *humidity,
	double *az_error, double *el_error,double *scan_unit, char *messg,
	unsigned short *track_flag, unsigned short *slew_flag,double *focus_counts, double *subx_counts, double *suby_counts,double *subtilt_counts,
double *subtilt_arcseconds,
	double *total_power_disp,double *syncdet_disp, int *integration,
		float *magnitude, char *sptype, float *windspeed, 
	float *winddirection,float *refraction, float *pmdaz, float *pmdel,
	double *smoothed_tracking_error, double *tsys, short *errorflag, short *waitflag, unsigned short *pmac_command_flag, int *antennaNumber, int
*radio_flag,int *padid,double *planetdistance,double *Az_cmd,
double *El_cmd, double *Az_cmd_rate,double *El_cmd_rate,int *milliseconds,
int *servomilliseconds,char *m3StateString)
{

int i,j,l;
short az_act_sign,az_sign,el_sign,dec_dum_sign,dec_app_sign,dec_cat_sign;
char k;
char str[2];
int lsth,lstm,ra_cat_h,ra_cat_m,dec_cat_d,dec_cat_m;
int dec_app_d,dec_app_m;
int ra_app_h,ra_app_m;
int utch,utcm;
int epochint;
int az_cmd_d,az_cmd_m,el_cmd_d,el_cmd_m;
int az_act_d,az_act_m,el_act_d,el_act_m;
double ra_cat_s,dec_cat_s,ra_app_s,dec_app_s,lsts,utcs;
double az_cmd_s,el_cmd_s,az_act_s,el_act_s;
int lstsi,utcsi,az_cmd_si,az_act_si,el_cmd_si,el_act_si;
double ha;


	ha=*lst_disp-*ra_disp;

if((*icount%30)==0) initialize();

	if(*icount==1) initialize();
/*
	if((*icount%2)!=0) return;
*/

	*az_disp=*az_disp/0.017453293;
	*el_disp=*el_disp/0.017453293;


	hms(ra_disp,&ra_app_h,&ra_app_m,&ra_app_s,&dec_dum_sign);
	hms(dec_disp,&dec_app_d,&dec_app_m,&dec_app_s,&dec_app_sign);
	hms(ra_cat_disp,&ra_cat_h,&ra_cat_m,&ra_cat_s,&dec_dum_sign);
	hms(dec_cat_disp,&dec_cat_d,&dec_cat_m,&dec_cat_s,&dec_cat_sign);
	hms(lst_disp,&lsth,&lstm,&lsts,&dec_dum_sign);
	hms(utc_disp,&utch,&utcm,&utcs,&dec_dum_sign);
	hms(az_disp,&az_cmd_d,&az_cmd_m,&az_cmd_s,&az_sign);
	hms(el_disp,&el_cmd_d,&el_cmd_m,&el_cmd_s,&el_sign);
	hms(az_actual_corrected,&az_act_d,&az_act_m,&az_act_s,&az_act_sign);
	hms(el_actual_disp,&el_act_d,&el_act_m,&el_act_s,&dec_dum_sign);



	lstsi=(int)lsts;
	utcsi=(int)utcs;
	az_cmd_si=(int)az_cmd_s;
	el_cmd_si=(int)el_cmd_s;
	az_act_si=(int)az_act_s;
	el_act_si=(int)el_act_s;
	
box(stdscr, '|','-');

move(1,59);
printw("M3:%7s",m3StateString);

/*
move(1,2);
printw("%f %f %f %f %d %d %f",*Az_cmd/3600000.,*El_cmd/3600000.,*Az_cmd_rate/3600000.,*El_cmd_rate/3600000.,*milliseconds,*servomilliseconds,*utc_disp);

move(2,2);
printw("%f %f %f",*az_disp,*el_disp,*utc_disp);
*/
move(2,2);
if(*antennaNumber==1) addstr("SMA Antenna-1    tracking   ");
if(*antennaNumber==2) addstr("SMA Antenna-2    tracking   ");
if(*antennaNumber==3) addstr("SMA Antenna-3    tracking   ");
if(*antennaNumber==4) addstr("SMA Antenna-4    tracking   ");
if(*antennaNumber==5) addstr("SMA Antenna-5    tracking   ");
if(*antennaNumber==6) addstr("SMA Antenna-6    tracking   ");
if(*antennaNumber==7) addstr("SMA Antenna-7    tracking   ");
if(*antennaNumber==8) addstr("SMA Antenna-8    tracking   ");
move(3,2);
printw("on pad: %d",*padid);
move(4,5);
addstr("LST");
move (4,15);
addstr("UTC");
move(4,25);
addstr("TJD");
/*
move(2,25);
addstr("SOURCE=");
*/
move(2,32);
addstr(source);
move(3,32);
addstr(sptype);
move(4,32);
printw("%3.1f",*magnitude);
move (5,3);
af(&lsth,str);
addch(str[0]);
addch(str[1]);
move(5,6);
af(&lstm,str);
addch(str[0]);
addch(str[1]);
move(5,9);
af(&lstsi,str);
addch(str[0]);
addch(str[1]);
move(5,13);
af(&utch,str);
addch(str[0]);
addch(str[1]);
move(5,16);
af(&utcm,str);
addch(str[0]);
addch(str[1]);
move(5,19);
af(&utcsi,str);
addch(str[0]);
addch(str[1]);
move(5,23);
printw("%lf",*tjd_disp);
move(6,3);
printw("%.4f",ha);
move(7,14);
addstr("RA");
move(7,30);
addstr("DEC");
move(9,2);
addstr("CATALOG");
move(9,12);
af(&ra_cat_h,str);
addch(str[0]);
addch(str[1]);
move(9,15);
af(&ra_cat_m,str);
addch(str[0]);
addch(str[1]);
move(9,18);
printw("%.3f",ra_cat_s);
move(9,27);
if (dec_cat_sign>0) addch('+');
if (dec_cat_sign<0) addch('-');
if (dec_cat_sign==0) addch(' ');
af(&dec_cat_d,str);
addch(str[0]);
addch(str[1]);
move(9,31);
af(&dec_cat_m,str);
addch(str[0]);
addch(str[1]);
move(9,34);
printw("%.2f",dec_cat_s);

move(11,2);
printw("APPARENT");
move(11,12);
af(&ra_app_h,str);
addch(str[0]);
addch(str[1]);
move(11,15);
af(&ra_app_m,str);
addch(str[0]);
addch(str[1]);
move(11,18);
printw("%.3f",ra_app_s);
move(11,27);
if(dec_app_sign>0)addch('+');
if(dec_app_sign<0)addch('-');
if(dec_app_sign==0)addch(' ');
af(&dec_app_d,str);
addch(str[0]);
addch(str[1]);
move(11,31);
af(&dec_app_m,str);
addch(str[0]);
addch(str[1]);
move(11,34);
printw("%.2f",dec_app_s);

move(13,14);
addstr("AZ");
move(13,30);
addstr("EL");

move(15,2);
addstr("CMD");
move(15,9);
if((az_sign<0)&&(az_cmd_d==0))addch('-');
move(15,10);
printw("%03d",az_cmd_d);
move(15,15);
af(&az_cmd_m,str);
addch(str[0]);
addch(str[1]);
move(15,18);
af(&az_cmd_si,str);
addch(str[0]);
addch(str[1]);
move(15,27);
if(el_sign>=0)addch(' ');
if(el_sign<0)addch('-');
move(15,28);
af(&el_cmd_d,str);
addch(str[0]);
addch(str[1]);
move(15,31);
af(&el_cmd_m,str);
addch(str[0]);
addch(str[1]);
move(15,34);
af(&el_cmd_si,str);
addch(str[0]);
addch(str[1]);
move(17,2);
addstr("ACTUAL");
move(17,9);
if((az_act_sign<0)&&(az_act_d==0))addch('-');
move(17,10);
printw("%03d",az_act_d);
move(17,15);
af(&az_act_m,str);
addch(str[0]);
addch(str[1]);
move(17,18);
af(&az_act_si,str);
addch(str[0]);
addch(str[1]);
move(17,28);
af(&el_act_d,str);
addch(str[0]);
addch(str[1]);
move(17,31);
af(&el_act_m,str);
addch(str[0]);
addch(str[1]);
move(17,34);
af(&el_act_si,str);
addch(str[0]);
addch(str[1]);
move(19,2);
addstr("ERROR");
move(19,11);
printw("%7.1f\"",(*az_error*3600.));
move(19,28);
printw("%7.1f\"",(*el_error*3600.));
/*move(18,23);
printw("(%.1f\")",*smoothed_tracking_error);
*/

move(20,12);
printw("(%6.0f)",*pmdaz);
move(20,32);
printw("(%6.0f)",*pmdel);
move(21,2);
addstr("OFFSETS(\")");
move(21,12);
printw("%6.0f",*azoff);
move(21,32);
printw("%6.0f",*eloff);
move(22,2);
printw("%6.0f",*scan_unit);
move(21,42);
addstr("TILTS");
move(21,50);
printw("%.1f",*tiltx);
move(21,63);
printw("%.1f",*tilty);
move(21,73);
printw("%5d",*integration);

/*

move(22,42);
printw("%3d",*errorflag);
move(22,50);
printw("%3d",*waitflag);
move(22,55);
printw("%3d",*pmac_command_flag);
*/
move(22,42);
printw("Planet dist.=%.6f AU",*planetdistance);

/*
move(22,42);
addstr("PVT");
move(22,46);
printw("%4d",*pvt);
move(22,52);
addstr("TF=");
printw("%1d",*track_flag);
move(22,57);
addstr("SF=");
printw("%1d",*slew_flag);
*/
move(18,42);
addstr("REFRACTION:");
move(18,53);
if(*radio_flag==1) printw("%5.1f \" (radio)   ",*refraction);
if(*radio_flag==0) printw("%5.1f \" (optical) ",*refraction);
move(19,42);
addstr("WEATHER:");
move(19,51);
printw("%4.1f C",*temperature);
move(19,59);
printw("%5.1f%%",*humidity);
move(19,67);
printw("%6.1f mbar",*pressure);
move(20,51);
printw("wind: %4.1f m/s,  %5.1f  deg",*windspeed,*winddirection);
move(2,42);
addstr(messg);
move(17,42);
addstr("SUB_Z:");
move(17,49);
printw("%8.0f cts, %4.2f mm ",*focus_counts, (*focus_counts)/2000.);

move(13,42);
addstr("SUB_X:");
move(13,49);
printw("%8.0f cts, %4.2f mm ",*subx_counts, (*subx_counts)/1000.);

move(15,42);
addstr("SUB_Y:");
move(15,49);
printw("%8.0f cts, %4.2f mm ",*suby_counts, (*suby_counts)/500.);

move(11,42);
addstr("SUB_TILT:");
move(11,52);
printw("%8.0f cts, %4.2f \" ",*subtilt_counts, *subtilt_arcseconds);

move(9,42);
addstr("CONT. DET. O/P:");
move(9,58);
printw("%8.2f mV", (*total_power_disp)*1000.);

move(7,42);
addstr("SYNC. DET. O/P:");
move(7,58);
printw("%8.2f mV", (*syncdet_disp)*1000.);

move(5,42);
addstr("TSYS:");
move(5,48);
printw("%05.0f", *tsys);
move(5,55);
addstr("K");


/*
for(l=1;l<23;l++)
{
move(l,40);
addstr("|");
}
*/
refresh();
}
Пример #7
0
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);
	}
}
Пример #8
0
/* Calculate geometric position of the Moon and apply
 * approximate corrections to find apparent position,
 * phase of the Moon, etc. for AA.ARC.
 */
int domoon()
{
int i, prtsav;
double ra0, dec0, r;
double x, y, z, lon0;
double c, s, temp;
double pp[3], qq[3];
double acos();

/* Compute obliquity of the ecliptic, coseps, and sineps
 */
epsiln(TDT);

/* Run the orbit calculation twice, at two different times,
 * in order to find the rate of change of R.A. and Dec.
 */

/* Calculate for 0.001 day ago
 */
prtsav = prtflg;
prtflg = 0; /* disable display */
moonll(TDT-0.001, moonpp, moonpol);
/*
lonlat( rearth, TDT, eapolar ); // precess earth to date
// lonlat( rearth, TDT, eapolar, 1 );
*/
ra0 = ra;
dec0 = dec;
lon0 = l;
prtflg = prtsav;

/* Calculate for present instant.
 */
moonll(TDT, moonpp, moonpol);

/* The rates of change.  These are used by altaz() to
 * correct the time of rising, transit, and setting.
 */
 dradt = ra - ra0;
 if (dradt >= PI)
   dradt = dradt - 2.0 * PI;
 if (dradt <= -PI)
   dradt = dradt + 2.0 * PI;
 dradt = 1000.0 * dradt;
 ddecdt = 1000.0*(dec-dec0);


/* Post the ecliptic longitude and latitude, in radians,
 * and the radius in au.
 */
obpolar[0] = l;
obpolar[1] = B;
r = 1.0/sin(p); /* distance in earth-radii */
ra0 = Rearth*r; /* factor is radius of earth in au */
obpolar[2] = ra0;

/* Rate of change in longitude, degrees per day
 * used for phase of the moon
 */
lon0 = 1000.0*RTD*(l - lon0);

/* convert to ecliptic rectangular coordinates */

z = ra0 * cos(B);
x = z * cos(l);
y = z * sin(l);
z = ra0 * sin(B);
/* convert to equatorial coordinates */
pp[0] = x;
pp[1] = y * coseps - z * sineps;
pp[2] = y * sineps + z * coseps;

/* Find sun-moon-earth angles */
precess( rearth, TDT, -1 );
for( i=0; i<3; i++ )
	qq[i] = rearth[i] + pp[i];
angles( pp, qq, rearth );

/* Display answers
 */
if( prtflg )
	{
	  /* Apparent ecliptic coordinates.
	     The nutation in longitude is added to the ecliptic longitude.
	     See AA page C2.  First rotate the coordinate system about the
	     x axis from mean equator to ecliptic.
	     Then rotate about the z axis by the nutation in longitude.  */
	  x = Mapp[0];
	  y = Mapp[1];
	  z = Mapp[2];
	  temp  =  coseps * y  +  sineps * z;
	  z     = -sineps * y  +  coseps * z;
	  y = temp;

	  c = cos(nutl);
	  s = sin(nutl);
	  temp = c * x - s * y;
	  y    = s * x + c * y;
	  x = temp;

	  Mapp[0] = zatan2( x, y );
	  Mapp[1] = asin( z );
	  Mapp[2] = Rem;
	printf( "Apparent geocentric longitude %.3f deg", RTD*Mapp[0] );
	printf( "   latitude %.3f deg\n", RTD*Mapp[1] );
	printf( "Distance %.3f Earth-radii\n", r );
	printf( "Horizontal parallax" );
	dms( p );
	printf( "Semidiameter" );
	x = 0.272453 * p  +  0.0799/RTS; /* AA page L6 */
	dms( x );

	x = RTD * acos(-ep);
	printf( "\nElongation from sun %.2f deg,", x );
	x = 0.5 * (1.0 + pq);
	printf( "  Illuminated fraction %.2f\n", x );

/* Find phase of the Moon by comparing Moon's longitude
 * with Earth's longitude.
 *
 * The number of days before or past indicated phase is
 * estimated by assuming the true longitudes change linearly
 * with time.  These rates are estimated for the date, but
 * do not stay constant.  The error can exceed 0.15 day in 4 days.
 */
/* Apparent longitude of sun.
 * Moon's longitude was already corrected for light time.
 */
	y = eapolar[0] - 20.496/(RTS*eapolar[2]);
	x = obpolar[0] - y;
	x = modtp( x ) * RTD;	/* difference in longitude */
	i = x/90;		/* number of quarters */
	x = (x - i*90.0);	/* phase angle mod 90 degrees */

/* days per degree of phase angle */
	z = 1.0/(lon0 - (0.9856/eapolar[2]));

	if( x > 45.0 )
		{
		y = -(x - 90.0)*z;
		if( y > 1.0 )
			printf( "Phase %.1f days before ", y );
		else
			printf( "Phase %.2f days before ", y );
		i = (i+1) & 3;
		}
	else
		{
		y = x*z;
		if( y > 1.0 )
			printf( "Phase %.1f days past ", y );
		else
			printf( "Phase %.2f days past ", y );
		}


	switch(i)
		{
		case 0: printf( "Full Moon\n" ); break;
		case 1: printf( "Third Quarter\n" ); break;
		case 2: printf( "New Moon\n" ); break;
		case 3: printf( "First Quarter\n" ); break;
		}
	} /* if prtflg */

printf( "    Apparent:  R.A." );
hms(ra);
printf( "Declination" );
dms(dec);
printf( "\n" );

/* Compute and display topocentric position (altaz.c)
 */
pp[0] = ra;
pp[1] = dec;
pp[2] = r * Rearth;
altaz( pp, UT );
return(0);
}
Пример #9
0
static void filltwh(SCAN *scan, XSCAN *xscan, int rec)
{
    int i, swapped = 0;
    float *next;
    float *twh;
    double fact;
	
	int CheckDataSize(int);
	
    twh = (float *)itwh;
    
    fact = twh[57];
    if (fact == 0.0) fact = 1.0;
    
    scan->ScanNo = itwh[0];
    scan->NChannel = (int)(twh[55+rec]/fact + 0.5);
    xscan->NChannel = (int)(twh[55+rec]/fact + 0.5);
    scan->Day   = itwh[28];
    scan->Month = itwh[27];
#ifdef DEBUG
    printf("NChannel=%d\n", xscan->NChannel);
    printf("ScanNo=%d\n", scan->ScanNo);
    printf("fact=%f\n", fact);
#endif

    if (scan->NChannel <= 0 || scan->ScanNo < 0 ||
        scan->Day < 0 || scan->Day > 31 ||
        scan->Month < 0 || scan->Month > 12) {
        swap_twh();
        fact = twh[57];
        if (fact == 0.0) fact = 1.0;
        scan->ScanNo = itwh[0];
        scan->NChannel = (int)(twh[55+rec]/fact + 0.5);
        scan->Day   = itwh[28];
        scan->Month = itwh[27];
#ifdef DEBUG
        printf("Swapped NChannel=%d\n", scan->NChannel);
        printf("        ScanNo=%d\n", scan->ScanNo);
        printf("        fact=%f\n", fact);
#endif
        if (scan->NChannel <= 0 || scan->ScanNo < 0 ||
            scan->Day < 0 || scan->Day > 31 ||
            scan->Month < 0 || scan->Month > 12) return;
        swapped = 1;
    }
    	
	if (CheckDataSize(scan->NChannel) < scan->NChannel) {
	    return;
	}
	
    scan->Year = itwh[29];
    if (scan->Year < 1900) scan->Year += 1900;
    hms(twh[12]/fact, &scan->UTHour, &scan->UTMin, &scan->UTSec);
    hms(twh[11]/fact, &scan->STHour, &scan->STMin, &scan->STSec);
    scan->ObsMode = itwh[30];
    scan->CSystem = 0;
    strncpy(scan->Name, (char *)(itwh+12), 12);
    scan->Name[11] = '\0';
    strncpy(scan->Project, (char *)(itwh+8), 4);
    strncpy(scan->Molecule, (char *)(itwh+260), 18);
    scan->Molecule[17] = '\0';
    scan->JulDate = (int)(twh[9]/fact + 0.5);
    scan->LMapOff = twh[90]/fact;
    scan->BMapOff = twh[91]/fact;
    scan->AzMapOff = twh[88]/fact;
    scan->ElMapOff = twh[89]/fact;
    scan->StepX = twh[140]/fact;
    scan->StepY = twh[141]/fact;
    scan->PosAngle = twh[142]/fact;
    scan->Equinox = twh[24]/fact;
    scan->Tsys = twh[45+rec]/fact;
    scan->Tcal = twh[41+rec]/fact;
    scan->IntTime = twh[47+rec]/fact;
    scan->AirTemp = twh[77]/fact;
    scan->Pressure = twh[78]/fact;
    scan->Humidity = twh[79]/fact;
    scan->VSource = (double)twh[49+rec]/fact;
    scan->VelRes = (double)twh[51+rec]/fact;
    scan->Bandwidth = (double)twh[53+rec]/fact;
    scan->FreqRes = scan->Bandwidth/scan->NChannel;
    next = twh+150;
    if (rec) next += (int)(twh[55]/fact + 0.5);
    for (i=0; i<scan->NChannel; i++) {
        if (swapped) swap((char *)next, sizeof(float));
        scan->c[i] = (*next++)/fact;
    }
    scan->Longitude = tod(itwh[42],itwh[43],itwh[44],swapped)/fact;
    scan->Latitude = tod(itwh[45],itwh[46],itwh[47],swapped)/fact;
    scan->Azimuth = tod(itwh[164],itwh[165],itwh[166],swapped)/fact;
    scan->Elevation = tod(itwh[167],itwh[168],itwh[169],swapped)/fact;
    scan->RestFreq = tod(itwh[70+3*rec],itwh[71+3*rec],itwh[72+3*rec],swapped)/fact;
    scan->SkyFreq = tod(itwh[76+3*rec],itwh[77+3*rec],itwh[78+3*rec],swapped)/fact;
}
Пример #10
0
void StatTask() {

	int i, j, prn;
	unsigned start = timer_ms();

	while (!ready) TaskSleep(1000000);
	
	while (1) {
		UMS lat(StatLat), lon(StatLon);
		UMS hms(StatSec/60/60);

		TaskSleep(1000000);
		
		if (print_stats == 2) {
			static int fixes;
			if (gps.fixes > fixes) {
				fixes = gps.fixes;
				if (StatLat) printf("wikimapia.org/#lang=en&lat=%9.6f&lon=%9.6f&z=18&m=b\n",
					(StatNS=='S')? -StatLat:StatLat, (StatEW=='W')? -StatLon:StatLon);
			}
			continue;
		}

		printf("\n\n\n\n\n\n");
#if DECIM_CMP
		printf("   CH    PRN    SNR     CA    ERR   RSSI   GAIN   BITS   WDOG     SUB");
#else
		//      12345 * 1234 123456 123456 123456 123456 123456 Up12345 123456 #########
		printf("   CH    PRN    SNR   RSSI   GAIN   BITS   WDOG     SUB  NOVFL");
#endif
		//printf("  LS    CS      LO     SLO     DLO      CA     SCA     DCA");
		printf("\n");

		for (i=0; i<gps_chans; i++) {
			stats_t *s = &stats[i];
			char c1, c2;
			double snew;
			printf("%5d %c ", i+1, (stats_fft == i)? '*':' ');
			show4(prn, prn);
			show6(snr, snr);
#if DECIM_CMP
			show6(snr, ca_dop);
			printf("       ");
#endif
			show6(rssi, rssi);
			show6(rssi, gain);
			show6(hold, hold);
			show6(rssi, wdog);
			
			printf("%c", s->ca_unlocked? 'U':' ');
			printf("%c", (s->sub & (1<<(PARITY-1)))? 'p':' ');
			s->sub &= ~(1<<(PARITY-1));		// clear parity
			for (j=4; j>=0; j--) {
				printf("%c", (s->sub & (1<<j))? '1'+j:' ');
				if (s->sub_next & (1<<j)) {
					s->sub |= 1<<j;
					s->sub_next &= ~(1<<j);
				}
			}

			show7(novfl, novfl);
			printf(" ");
			
#if 0
			if (s->rssi) printf("%6d:E %6d:P %6d:L ", s->pe/1000, s->pp/1000, s->pl/1000);
#endif
#if 0
			show3(rssi, lo_dop);
			show5(rssi, ca_dop);
			if (s->dir == ' ') s->f_lo=s->lo, s->f_ca=s->ca;
			snew = fabs(s->f_lo-s->lo);
			if (snew > s->s_lo) s->s_lo = snew;
			snew = fabs(s->f_ca-s->ca);
			if (snew > s->s_ca) s->s_ca = snew;
			showf7_1(lo, lo);
			showf7_1(s_lo, s_lo);
			showf7_1(d_lo, d_lo);
			showf7_4(ca, ca);
			showf7_4(s_ca, s_ca);
			showf7_4(d_ca, d_ca);
			c1 = c2 = '_';
			if (s->rssi) {
				s->to++;
				if (s->lo < s->l_lo) { s->l_lo=s->lo; s->dir='v'; s->to=0; c1='v'; } else
				if (s->lo > s->h_lo) { s->h_lo=s->lo; s->dir='^'; s->to=0; c1='^'; };
				if (s->ca < s->l_ca) { s->l_ca=s->ca; s->to=0; c2='v'; } else
				if (s->ca > s->h_ca) { s->h_ca=s->ca; s->to=0; c2='^'; };
			}
			printf("%c%c ", c1, c2);
			if (s->rssi) printf("%3d%c ", s->to, s->dir); else printf("     ");
#endif
			//if (s->dbug) printf("%9.6f %9.6f %6d %6d %6d ",
			//	s->dbug_d1, s->dbug_d2, s->dbug_i1, s->dbug_i2, s->dbug_i3);
			printf("  ");
			for (j=0; j < s->rssi*50/3000; j++) printf("#");
			printf ("\n");
#if DECIM_CMP
			printf("             ");
			show6(snr2, snr2);
			show6(snr2, ca_dop2);
			show6(snr2, ca_dop-s->ca_dop2);
			printf ("\n");
#endif
		}
		printf("\n");

		NextTask("stat1");

		printf(" SATS ");
			if (gps.tracking) printf("tracking %d", gps.tracking);
			if (gps.good) printf(", good %d", gps.good);
			printf("\n");
		printf("  LAT ");
			if (StatLat) printf("%9.5fd %c    %3dd %2dm %6.3fs %c    ", StatLat, StatNS, lat.u, lat.m, lat.s, StatNS);
			if (StatLat) printf("%3dd %6.3fm %c", lat.u, lat.fm, StatNS);
			printf("\n");
		printf("  LON ");
			if (StatLat) printf("%9.5fd %c    %3dd %2dm %6.3fs %c    ", StatLon, StatEW, lon.u, lon.m, lon.s, StatEW);
			if (StatLat) printf("%3dd %6.3fm %c", lon.u, lon.fm, StatEW);
			printf("\n");
		printf("  ALT ");
			if (StatLat) printf("%1.0f m", StatAlt);
			printf("\n");
		printf(" TIME ");
			if (StatDay != -1) printf("%s %02d:%02d:%02.0f GPST", Week[StatDay], hms.u, hms.m, hms.s);
			printf("\n");
		printf("FIXES ");
			if (gps.fixes) printf("%d", gps.fixes);
			printf("\n");
		printf(" TTFF ");
			if (stats_ttff) printf("%d:%02d", stats_ttff / 60, stats_ttff % 60);
			printf("\n");
		printf("  RUN ");
			unsigned r = (timer_ms() - start)/1000;
			if (r >= 3600) printf("%02d:", r / 3600);
			printf("%02d:%02d", (r / 60) % 60, r % 60);
			printf("\n");
		printf("  MAP ");
			if (StatLat) printf("wikimapia.org/#lang=en&lat=%9.6f&lon=%9.6f&z=18&m=b",
				(StatNS=='S')? -StatLat:StatLat, (StatEW=='W')? -StatLon:StatLon);
			printf("\n");
		printf(" ECPU ");
			printf("%4.1f%% cmds %d/%d", ecpu_use(), ecpu_cmds, ecpu_tcmds);
			ecpu_cmds = ecpu_tcmds = 0;
			printf("\n");
		int offset = (int)(adc_clock - adc_clock_nom);
		printf("  DECIM: %d  FFT: %d -> %d  CCF: %5.3fs  MIN_SIG: %d  ADC_CLK: %.6f %s%d (%d)  ACQ: %d",
			decim, FFT_LEN, FFT_LEN/decim, fft_msec, min_sig,
			adc_clock/1000000.0, (offset >= 0)? "+":"", offset, gps.adc_clk_corr, gps.acquiring);
			printf("\n");

		printf("\n");

		NextTask("stat2");		
		TaskDump();
	}
}
Пример #11
0
Picture*
image(Angle ra, Angle dec, Angle wid, Angle hig)
{
	Pix *p;
	uchar *b, *up;
	int i, j, sx, sy, x, y;
	char file[50];
	Picture *pic;
	Img* ip;
	int lowx, lowy, higx, higy;
	int slowx, slowy, shigx, shigy;
	Header *h;
	Angle d, bd;
	Plate *pp, *bp;

	if(gam.gamma == 0)
		gam.gamma = -1;
	if(gam.max == gam.min) {
		gam.max = 17600;
		gam.min = 2500;
	}
	gam.absgamma = gam.gamma;
	gam.neg = 0;
	if(gam.absgamma < 0) {
		gam.absgamma = -gam.absgamma;
		gam.neg = 1;
	}
	gam.mult1 = 1. / (gam.max - gam.min);
	gam.mult2 = 255. * gam.mult1;

	if(nplate == 0)
		getplates();

	bp = 0;
	bd = 0;
	for(i=0; i<nplate; i++) {
		pp = &plate[i];
		d = dist(ra, dec, pp->ra, pp->dec);
		if(bp == 0 || d < bd) {
			bp = pp;
			bd = d;
		}
	}

	if(debug)
		Bprint(&bout, "best plate: %s %s disk %d %s\n",
			hms(bp->ra), dms(bp->dec),
			bp->disk, bp->rgn);

	h = getheader(bp->rgn);
	xypos(h, ra, dec, 0, 0);
	if(wid <= 0 || hig <= 0) {
		lowx = h->x;
		lowy = h->y;
		lowx = (lowx/500) * 500;
		lowy = (lowy/500) * 500;
		higx = lowx + 500;
		higy = lowy + 500;
	} else {
		lowx = h->x - wid*ARCSECONDS_PER_RADIAN*1000 /
			(h->param[Pxpixelsz]*h->param[Ppltscale]*2);
		lowy = h->y - hig*ARCSECONDS_PER_RADIAN*1000 /
			(h->param[Pypixelsz]*h->param[Ppltscale]*2);
		higx = h->x + wid*ARCSECONDS_PER_RADIAN*1000 /
			(h->param[Pxpixelsz]*h->param[Ppltscale]*2);
		higy = h->y + hig*ARCSECONDS_PER_RADIAN*1000 /
			(h->param[Pypixelsz]*h->param[Ppltscale]*2);
	}
	free(h);

	if(lowx < 0) lowx = 0;
	if(higx < 0) higx = 0;
	if(lowy < 0) lowy = 0;
	if(higy < 0) higy = 0;
	if(lowx > 14000) lowx = 14000;
	if(higx > 14000) higx = 14000;
	if(lowy > 14000) lowy = 14000;
	if(higy > 14000) higy = 14000;

	if(debug)
		Bprint(&bout, "xy on plate: %d,%d %d,%d\n",
			lowx,lowy, higx, higy);

	if(lowx >= higx || lowy >=higy) {
		Bprint(&bout, "no image found\n");
		return 0;
	}

	b = malloc((higx-lowx)*(higy-lowy)*sizeof(*b));
	if(b == 0) {
 emalloc:
		fprint(2, "malloc error\n");
		return 0;
	}
	memset(b, 0, (higx-lowx)*(higy-lowy)*sizeof(*b));

	slowx = lowx/500;
	shigx = (higx-1)/500;
	slowy = lowy/500;
	shigy = (higy-1)/500;

	for(sx=slowx; sx<=shigx; sx++)
	for(sy=slowy; sy<=shigy; sy++) {
		if(sx < 0 || sx >= nelem(rad28) || sy < 0 || sy >= nelem(rad28)) {
			fprint(2, "bad subplate %d %d\n", sy, sx);
			free(b);
			return 0;
		}
		sprint(file, "%s/%s/%s.%c%c",
			dssmount(bp->disk),
			bp->rgn, bp->rgn,
			rad28[sy],
			rad28[sx]);

		ip = dssread(file);
		if(ip == 0) {
			fprint(2, "can't read %s: %r\n", file);
			free(b);
			return 0;
		}

		x = sx*500;
		y = sy*500;
		for(j=0; j<ip->ny; j++) {
			if(y+j < lowy || y+j >= higy)
				continue;
			p = &ip->a[j*ip->ny];
			up = b + (higy - (y+j+1))*(higx-lowx) + (x - lowx);
			for(i=0; i<ip->nx; i++) {
				if(x+i >= lowx && x+i < higx)
					*up = dogamma(*p);
				up++;
				p += 1;
			}
		}
		free(ip);
	}

	pic = malloc(sizeof(Picture));
	if(pic == 0){
		free(b);
		goto emalloc;
	}
	pic->minx = lowx;
	pic->miny = lowy;
	pic->maxx = higx;
	pic->maxy = higy;
	pic->data = b;
	strcpy(pic->name, bp->rgn);
	return pic;
}
Пример #12
0
	void jd_to_islamic(jd_t jd, year_t & year, month_t & month, day_t & day, hour_t & hour, minute_t & minute, second_t & second) {
		jd_to_islamic(jd, year, month, day);
		hms((jd + 0.5) - floor(jd + 0.5), hour, minute, second);
	}