コード例 #1
0
int db2orbpkt(Dbptr db,int orb) {

	char			srcname[ORBSRCNAME_SIZE];
	static int		packetsz=0,nbytes;
	double			t;
	static char		*packet=0;
	static Packet	*pkt=0;
	int retcode = 0;
	
	if (pkt == 0) {
		pkt=newPkt();
	} else {
		clrPkt(pkt);
	}
	pkt->pkttype=suffix2pkttype("db");
	pkt->db=db;
	if (stuffPkt(pkt,srcname,&t,&packet,&nbytes,&packetsz) < 0) {
		complain(0,"stuffPkt failed for %s\\n",pkt->pkttype);
		retcode = -1;
	} else if (orbput(orb,srcname,t,packet,nbytes)) {
		complain (0, "orbput fails\n");
		retcode = -1;
	}
	return retcode;
}
コード例 #2
0
ファイル: send2orb.c プロジェクト: battistuz/antelope_contrib
int send2orb( int orb, uchar_t *data )
{
     
   uchar_t buffer[1024], *dptr;   
   double epoch;
   char srcname[64];
   int  ptype, psize = 0;


    
    if( (ptype = whatis_pkttype( data )) == -1) return 1;
    
    memcpy( &buffer[0], data, PLEN );
    dptr = &buffer[0];
    
    if( !(psize = hdr2packet( &dptr, Par.hdrtype,  &srcname[0] )) )  {
	complain( 0, "valid_pkt(): Not a valid packet. Wrong Header?\n");
	return 0;
    } 

    if( orbput( orb, &srcname[0], Par.time, dptr, psize ) < 0) {
	 complain( 0, "send2orb(): Can't send a packet to orbserver.\n"); 
	 return 0;
    }
      
    if( Log ) 
       complain( 0, "SRCNAME: %s-%lf \n", srcname, Par.time );
                 

    return 1;

}
コード例 #3
0
ファイル: _orb.c プロジェクト: vonseg/antelope_contrib
static PyObject *
python_orbput( PyObject *self, PyObject *args ) {
	char	*usage = "Usage: _orbput(orb, srcname, time, packet, nbytes)\n";
	int	orbfd;
	char	srcname[ORBSRCNAME_SIZE];
	double	pkttime;
	char	*pkt = 0;
	int	nbytes = 0;
	int	nbytes_pkt = 0;
	int	rc;

	if( ! PyArg_ParseTuple( args, "isds#i", &orbfd, srcname, &pkttime, &pkt, &nbytes_pkt, &nbytes) ) {

		if( ! PyErr_Occurred() ) {

			PyErr_SetString( PyExc_RuntimeError, usage );
		}

		return NULL;
	}

	rc = orbput( orbfd, srcname, pkttime, pkt, nbytes_pkt );

	return Py_BuildValue( "i", rc );
}
コード例 #4
0
static int
dbrows2orb(Dbptr db, int orb, char *prefix)
{
	Packet         *pkt;
	char            srcname[ORBSRCNAME_SIZE];
	double          time;
	char           *packet;
	int             nbytes, packetsize = 0;
	Dbptr           tmpdb;
	long            t, nrecords, r, ntables;
	Arr            *records = NULL;
	Tbl            *tables = NULL, *static_tables;
	char           *thistablename;
	Stbl           *stbl;
	char           *s;

	dbuntangle(db, &records);
	tables = keysarr(records);
	ntables = maxtbl(tables);
	if (ntables > 0)
		pkt = newPkt();
	if (prefix)
		strncpy(pkt->parts.src_net, prefix, PKT_TYPESIZE);
	pkt->pkttype = suffix2pkttype("db");
	for (t = 0; t < ntables; t++) {
		thistablename = gettbl(tables, t);
		tmpdb = dblookup(db, 0, thistablename, 0, 0);
		stbl = (Stbl *) getarr(records, thistablename);
		nrecords = maxstbl(stbl);
		if (nrecords > 0) {
			for (r = 0; r < nrecords; r++) {
				tmpdb.record = (long) getstbl(stbl, r);
				pkt->db = tmpdb;
				if (stuffPkt(pkt, srcname, &time, &packet, &nbytes, &packetsize) < 0) {
					elog_complain(0, "stuffPkt fails for pf packet");
					return (-1);
				}
				if (orbput(orb, srcname, time, packet, nbytes) < 0) {
					elog_complain(0, "Couldn't send packet to orb\n");
					return (-1);
				}
			}
		}
	}
	freetbl(tables, 0);
	dbfree_untangle(records);
	freePkt(pkt);
	if (verbose) {
		elog_notify(0, "%s: %d patcket(s) sent with sourcename: %s\n", s = strtime(now()), nrecords, srcname);
		free(s);
	}
	return (0);




}
コード例 #5
0
void WriteToOrb(SERVER *orb, UINT8 *das, int verbose, BOOL UseLoc)
{
static int count = 0;
double samprate, tstamp;
char buf[256];
struct reftek_dt dt;
int nbytes;
char *packet;
static int packetsz = 0;
static char srcname[ORBSRCNAME_SIZE];
static char *fid = "WriteToOrb";

/* Only deal with DT packets for which we can get sample rate */

    if (reftek_type(das) != REFTEK_DT) return;

    if (!reftek_dt(&dt, das, TRUE)) {
        rtp_log(RTP_ERR, "%s: DAS pkt dropped (can't decode)\n", fid);
        return;
    }

    if (!DeriveSampleRate(&dt, &samprate)) {
        rtp_log(RTP_ERR, "%s: DAS pkt dropped (unknown sample rate): %s\n",
            fid, reftek_str(das, buf)
        );
        return;
    }

/* Note decompression errors, if any */

    if (dt.dcerr) rtp_log(RTP_ERR, "%s: decompression error %d: %s\n",
        fid, dt.dcerr, reftek_str(das, buf)
    );

/* Convert to GENC format and send to ORB */

    ConvertPacket(&dt, samprate, UseLoc);

    if (stuffPkt(Pkt, srcname, &tstamp, &packet, &nbytes, &packetsz) < 0) {
        rtp_log(RTP_ERR, "stuffPkt routine failed for %s\n", Pkt->pkttype->name);
        return;
    }
    ++count;

    if (verbose) {
        showPkt(0, srcname, tstamp, packet, nbytes, stdout, PKT_TERSE);
    }

    if (orbput(orb->fd, srcname, dt.tstamp, packet, nbytes) != 0) {
        rtp_log(RTP_ERR, "orbput fails\n");
    }
}
コード例 #6
0
/*
 * Main program loop
 */
int main(int iArgCount, char *aArgList[]) {

	uint8_t *aBBAPkt; /* Buffer to hold a bba packet read from the wire */
	struct stBBAPacketInfo oPktInfo; /* Struct to hold information from the packet header */
	double dPrevTime;
	int bOKToSend;
	char *sOutPkt; /* Packet to put onto the orb */
	int iOutPktLen; /* Length of sOutPkt */

	elog_init(iArgCount, aArgList);

	/* Parse out command line options */
	if (parseCommandLineOptions(iArgCount, aArgList) == RESULT_SUCCESS) {

		/* Read in the parameter file */
		if (paramFileRead() == RESULT_FAILURE) {
			elog_complain(1,
					"main(): Error encountered during paramFileRead() operation.");
			dcbbaCleanup(-1);
		}

		/* Exit if bPFValidateFlag is set */
		if (oConfig.bPFValidateFlag == TRUE) {
			elog_notify(
					0,
					"main(): Parameter File %s validated successfully. Exiting.",
					oConfig.sParamFileName);
			dcbbaCleanup(0);
		}

		/* Allocate memory for our packet */
		allot (uint8_t *, aBBAPkt, oConfig.iBBAPktBufSz);

		/* Set up a signal handler to re-read the parameter file on SIGUSR1*/
		signal(SIGUSR1, sig_hdlr);

		/* Connect to the ORB */
		if ((orbfd = orbopen(oConfig.sOrbName, "w&")) < 0) {
			elog_complain(1, "orbopen: unable to connect to ORB \"%s\".",
					oConfig.sOrbName);
			dcbbaCleanup(-1);
		}

		/* Connect to Data Concentrator's Data read port */
		if (dcDataConnect(oConfig.iConnectionType, oConfig.sDCConnectionParams)
				== RESULT_SUCCESS) {
			dPrevTime = now();

			/*** BEGIN MAIN LOOP ***/
			while (readFromDC(&oPktInfo, aBBAPkt) == RESULT_SUCCESS) {
				bOKToSend = TRUE;
				/* Check the packet age */
				/*if (fabs(oPktInfo.dPktTime - dPrevTime) > 86400.0) {
				 dPrevTime = now();
				 if (fabs(oPktInfo.dPktTime - dPrevTime) > 86400.0) {
				 elog_complain(
				 0,
				 "%s packet has bad time - %s (epoch:%lf). Will discard packet.\n",
				 oPktInfo.sSrcname, sTimeStamp = strtime(
				 oPktInfo.dPktTime), oPktInfo.dPktTime);
				 free(sTimeStamp);
				 bOKToSend = FALSE;
				 } else
				 dPrevTime = oPktInfo.dPktTime;
				 } else
				 dPrevTime = oPktInfo.dPktTime;*/

				if (bOKToSend == TRUE) {
					/* Add orb header to Packet */
					iOutPktLen = (int) stuffBBAPkt(&oPktInfo, aBBAPkt, &sOutPkt);
					if (iOutPktLen == 0) {
						/* There was an error stuffing the packet*/
						elog_complain(
								1,
								"An error occurred while adding the ORB header to the raw packet. Not submitting to the orb.");
					} else if (sOutPkt == 0) {
						elog_die(1,
								"Output packet length was non-zero but pointer to Output packet is null");
					} else {

						/* put it into the orb */
						if (oConfig.bVerboseModeFlag == TRUE) {
							showPkt(0, oPktInfo.sSrcname, oPktInfo.dPktTime,
									sOutPkt, iOutPktLen, stderr, PKT_UNSTUFF);
							showPkt(0, oPktInfo.sSrcname, oPktInfo.dPktTime,
									sOutPkt, iOutPktLen, stderr, PKT_DUMP);
						}

						if (orbput(orbfd, oPktInfo.sSrcname, oPktInfo.dPktTime,
								sOutPkt, iOutPktLen)) {
							elog_complain(0, "orbput() failed in main()\n");
							dcbbaCleanup(-1);
						}

						if (oConfig.bVerboseModeFlag == TRUE)
							elog_notify(0, "packet submitted under %s\n",
									oPktInfo.sSrcname);

						/* Free the packet */
						free(sOutPkt);
					}
				}
			}

			/*
			 * If we get here, it means readFromDC failed to get a packet from oDCDataBNS.
			 * This could be either that an EOF was reached if we were reading from a file,
			 * or that the socket died unexpectedly.
			 */
			dcbbaCleanup(-1);
		}

		/* Else unable to connect, cleanup with failure (-1) exit code */
		else
			dcbbaCleanup(-1);

	} else {
コード例 #7
0
ファイル: cs2orb.c プロジェクト: Nikolaus/ZAMG_Antelope
main ( int argc, char **argv )

{
	char orbname[20]="zagsun6";
	int orb;
	tstations_struc stations ;
	char name[5] = "ORB" ;
	char sname[5] = "Q003" ;
	short int data_mask = CSIM_DATA ;
	pclient_struc client ;
	pclient_station station ;
	pdata_user data ;
	boolean alert_flag ;
	int ret ;
	int i, j ;
	Steim *blockette;
	int *sdata, npts;
	PktChannel pktchan;
	unsigned short int quality = 0;
	unsigned short int pinno = 0;
	char *packet = NULL;
	int nbytes = 0;
	int bufsiz = 0;
	char srcname[256];
	int fix_MOTA=0;
	int fix_WATA=0;
	int fix_SQTA=0;
	/*
	double fouryears=epoch(2004000)-epoch(1996000);
	double eightyears=epoch(2004000)-epoch(1996000);
	double twelveyears=epoch(2008000)-epoch(1996000);
	double twentyyears=epoch(2016000)-epoch(1996000);
	  */
	double sixteenyears=epoch(2012000)-epoch(1996000);
    Pf *mypf;


	/* Niko, leap second July 2012 */
	/* subtract another second for the leap-second 2006-01-01 */
	/* no more... Udo corrected the time again...
	eightyears -= 1;
	sixteenyears -= 1.0;
	*/
	/*schaltsekunde 2009-01-01*/
	/*double twokohnine=epoch(2009001); */

	elog_init ( argc, argv ) ;

	if (argc < 2) {
		usage();
		exit (1);
	}
	/*strcpy(orbname,"zagsun6");*/
	/*orbname = argv[2];*/
	strncpy (sname, argv[1], 4);
	sname[4] = '\0';
	for (argc-=3,argv+=3; argc>0; argc--,argv++) {
		if (!strcmp(*argv, "-v")) {
			verbose = 1;
		} else {
			fprintf (stderr, "cs2orb: Unrecognized option '%s'.\n", *argv);
			usage();
			exit (1);
		}
	}

putenv("PFPATH=/home/comserv/pf");
    if ( pfread ( "cs2orb", &mypf ) != 0 ) 
                die ( 1, "Can't read parameter file\n" ) ; 
    fix_MOTA=pfget_int(mypf,"MOTA");
    fix_WATA=pfget_int(mypf,"WATA");
    fix_SQTA=pfget_int(mypf,"SQTA");

	/* orb setup stuff */

	orb = orbopen (orbname, "w&");
	if (orb < 0) {
		clear_register (1);
		fprintf (stderr, "cs2orb: orbopen() error for '%s'.\n", orbname);
		exit (1);
	}

	/* comserv setup stuff */

	cs_setup (&stations, name, sname, TRUE, TRUE, 10, 5, data_mask , 6000) ;
	client = cs_gen ( &stations ) ;

	/* Trace setup stuff */

	blockette = newsteim();
	blockette->record_size = 512 ;

	/* Data packet read loop */

	while (1) {
		/* Look for a packet */
		ret = cs_scan ( client , &alert_flag ) ;

		/* Sleep and loop if nothing there */
		if (ret == -1) { sleep (1); continue; }

		/* Grab the station structure pointer */
		station = (pclient_station) ((long int) client + client->offsets[ret]) ;

		/* Printout station status */
		if (alert_flag) {
			complain (0, "Station %4s status: %s\n", long_str(station->name.l), &(stats[station->status])) ;
		}

		/* Sleep and loop if no valid data */
		if (!(station->valdbuf)) { sleep (1); continue; }

		/* Grab the data buffer pointer */
		data = (pdata_user) ((long int) client + station->dbufoffset) ;

		/* Loop over number of data buffers */
		for (i=0; i<station->valdbuf; i++,data=(pdata_user) ((long int)data + station->dbufsize)) {

			/* Set data blockette record */
			blockette->record = (pvoid) &(data->data_bytes) ;

			/* Parse the SEED header */
			if ( parse_seed_data_header( blockette ) ) {
				complain ( 0, "Problems parsing SEED header or 1000 blockette.\n" ) ;
				continue ;
			}
			/* niko netzname at fuer antelope */
			strcpy (blockette->sdh.net,"OE");
			
			sprintf (srcname, "%s_%s_%s", blockette->sdh.net, blockette->sdh.sta, blockette->sdh.chan);
			if (verbose) printf ("%s:", srcname);

			/* Not a data packet */
			if (!(blockette->sdh.nsamp) || !(blockette->sdh.samprate_factor)) {
				if (verbose) printf (" No data\n");
				continue;
			}

			if (verbose) printf ("%s", strtime(blockette->sdh.epoch));

			/* Uncompress the data */
			if ( usteim (blockette, &sdata, &npts) ) {
				clear_register (1);
				continue;
			}

			if (verbose) {
				for (j=0; j<10; j++) printf (" %5d", sdata[j]);
				printf ("\n");
			}

			/* Stuff packet for orb */
			strcpy (pktchan.net, blockette->sdh.net);
			
			strcpy (pktchan.sta, blockette->sdh.sta);
			strcpy (pktchan.chan, blockette->sdh.chan);
			/* pktchan.time = blockette->sdh.epoch+eightyears; 
			pktchan.time = blockette->sdh.epoch+twelveyears; */
			pktchan.time = blockette->sdh.epoch+sixteenyears;
			/*pktchan.time = blockette->sdh.epoch+twentyyears;*/
			pktchan.samprate = blockette->sdh.samprate;
			switch (pktchan.chan[0]) {
				case 'H':	pktchan.calib = 1.589446;
						break;
				/*
				case 'E':	pktchan.calib = 0.06/0.707;
				changed to 0.257 (~0.36*0.707)
				*/
				case 'E':	pktchan.calib = 0.257;		
				/* 
				incl. dämpfung -> stimmt wenn antelope diesen wert mit TF multipl.
				*/
						break;
				default:	pktchan.calib = 1.0;
						break;
			}
			
			if (!strcmp(pktchan.sta,"GAGA")) {
				/*Uhrenkorrektur template  */
				pktchan.time -= 1.0;
			}
			if (!strcmp(pktchan.sta,"no-MOTA")) {
				/*Uhrenkorrektur MOTA  */
				pktchan.time -= 1.0;
			}
			if ( fix_MOTA != 0 && !strcmp(pktchan.sta,"MOTA")) {
				/*Uhrenkorrektur MOTA  */
				pktchan.time += (double)(fix_MOTA);
			}
			if (fix_SQTA != 0 && !strcmp(pktchan.sta,"SQTA")) {
				/*Uhrenkorrektur SQTA  */
				pktchan.time += (double)(fix_SQTA);
			}
			if ( fix_WATA !=0 && !strcmp(pktchan.sta,"WATA")) {
				/*Uhrenkorrektur WATA  */
				pktchan.time += (double)(fix_WATA);
			}
			/* solve the problem with omitted segtype, which chops the db */
			if (!strcmp(pktchan.sta,"OBKA")) {
				switch (pktchan.chan[1]) {
					case 'H':	strcpy(pktchan.segtype,"V");
						break;
					case 'L':	strcpy(pktchan.segtype,"A");
						break;
					default:	;
						break;
				}
				
			}
			/* pktchan.calib = 1.0; */
			pktchan.nsamp = blockette->sdh.nsamp;
			pktchan.data = sdata;
			pktchan.nbytes = 4*pktchan.nsamp;
			pktchan.datatype = trINT;
			if (!stuff_iwc_tracebuf ( quality, pinno, &pktchan, &packet, &nbytes, &bufsiz ) ) {
				complain (0, "stuff_iwc_tracebuf error.\n");
				exit (1);
			}

			/* Put to orb */
			if ( orbput ( orb, srcname, pktchan.time, packet, nbytes ) ) {
				complain (0, "orbput error.\n");
				exit (1);
			}
			orbflush (orb);
		}
	}
}