Пример #1
0
void convertchan2beam( ifstream& datastrm) {
  ostringstream ossmsg;

	int pktSize = chanpkt1.getDataSize() + sizeof(beamHdr);

  for (;;) {
    datastrm.read((char *) &chanpkt1, pktSize);  
    if (datastrm.gcount() != pktSize) {
      if (datastrm.eof()) return;  // EOF should occur on this read 
      ossmsg << "(1) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
    chanpkt1.marshall();
    memcpy( reinterpret_cast<void *>(&beamHdr), 
	reinterpret_cast<void *>(&chanpkt1), sizeof(beamHdr)) ;
    
    datastrm.read((char *) &chanpkt2, pktSize);  
    if (datastrm.gcount() != pktSize) {
      ossmsg << "(2) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
    chanpkt2.marshall();
    short2char(reinterpret_cast<signed char *>(beampkt.getData()),
		reinterpret_cast <signed short *>(chanpkt1.getData()),
		reinterpret_cast <signed short *>(chanpkt2.getData()),
      		chanpkt1.getDataSize());


    // sanity check for 0xaabbccdd endian order value
    if (beamHdr.order != ATADataPacketHeader::CORRECT_ENDIAN) {
      mylog("output packet header does not contain 0xaabbccdd endian value");
      exit(EXIT_FAILURE);
    } 
    // fix some of the fields to make packets look like they came
    // from the beamformer
    beamHdr.src = ATADataPacketHeader::BEAM_104MHZ;  // not really 
    beamHdr.chan = 1;
    beamHdr.seq = sequence_num++;
    beamHdr.len = 2048;
    memcpy( reinterpret_cast<void *>(&beampkt), 
		reinterpret_cast<void *>(&beamHdr), sizeof(beamHdr));
    // write the SonATA channelizer compatible packet to stdout
    cout.write((char *) &beampkt, pktSize); 
  }
}
Пример #2
0
void convertchan2beam( ifstream& datastrm) {
  ostringstream ossmsg;

	int pktSize = chanpkt1.getDataSize() + sizeof(beamHdr);

  for (;;) {
    datastrm.read((char *) &chanpkt1, pktSize);  
    if (datastrm.gcount() != pktSize) {
      if (datastrm.eof()) return;  // EOF should occur on this read 
      ossmsg << "(1) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
        ossmsg << "Packets: " << packetCount << endl
                << seqGaps << " gap(s) in sequence; " << totalMissedPackets
                << " Total Missed Packets" << endl;
	mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
    chanpkt1.marshall();

// Copy the header into the output buffer

    memcpy( reinterpret_cast<void *>(&beamHdr), 
	reinterpret_cast<void *>(&chanpkt1), sizeof(beamHdr)) ;
    

	if (packetCount == 0)
	{
		expected[0] = expected[1] = beamHdr.seq;
	}

// Check for missing packets
	checkForMissingPackets(&beamHdr );
    datastrm.read((char *) &chanpkt2, pktSize);  
    if (datastrm.gcount() != pktSize) {
      ossmsg << "(2) unexpected data file read count " <<
        dec << datastrm.gcount();
      mylog(ossmsg);
        ossmsg << "Packets: " << packetCount << endl
                << seqGaps << " gap(s) in sequence; " << totalMissedPackets
                << " Total Missed Packets" << endl;
	mylog(ossmsg);
      exit(EXIT_FAILURE);
    }
// Read the next packet

    chanpkt2.marshall();
    memcpy( reinterpret_cast<void *>(&chanHdr), 
	reinterpret_cast<void *>(&chanpkt2), sizeof(chanHdr)) ;
// Check for missing packets
	checkForMissingPackets( &chanHdr );
// Convert both packets' data to 8 bit complex and store in 
// output buffer.

    short2char(reinterpret_cast<signed char *>(beampkt.getData()),
		reinterpret_cast <signed short *>(chanpkt1.getData()),
		reinterpret_cast <signed short *>(chanpkt2.getData()),
      		chanpkt1.getDataSize());


    // sanity check for 0xaabbccdd endian order value
    if (beamHdr.order != ATADataPacketHeader::CORRECT_ENDIAN) {
      mylog("output packet header does not contain 0xaabbccdd endian value");
        ossmsg << "Packets: " << packetCount << endl
                << seqGaps << " gap(s) in sequence; " << totalMissedPackets
                << " Total Missed Packets" << endl;
	mylog(ossmsg);
      exit(EXIT_FAILURE);
    } 
    // fix some of the fields to make packets look like they came
    // from the beamformer
    beamHdr.src = ATADataPacketHeader::BEAM_104MHZ;  // not really 
    beamHdr.chan = 1;
    beamHdr.seq = sequence_num++;
    beamHdr.len = 2048;
    memcpy( reinterpret_cast<void *>(&beampkt), 
		reinterpret_cast<void *>(&beamHdr), sizeof(beamHdr));
    // write the SonATA channelizer compatible packet to stdout
    cout.write((char *) &beampkt, pktSize); 
  }
}
Пример #3
0
bool
SoftimageInput::open (const std::string& name, ImageSpec& spec)
{
    // Remember the filename
    m_filename = name;
    
    m_fd = Filesystem::fopen (m_filename, "rb");
    if (!m_fd) {
        error ("Could not open file \"%s\"", name.c_str());
        return false;
    }
    
    // Try read the header
    if (! m_pic_header.read_header (m_fd)) {
        error ("\"%s\": failed to read header", m_filename.c_str());
        close();
        return false;
    }

    // Check whether it has the pic magic number
    if (m_pic_header.magic != 0x5380f634) {
        error ("\"%s\" is not a Softimage Pic file, magic number of 0x%X is not Pic",
               m_filename.c_str(), m_pic_header.magic);
               close();
               return false;
    }

    // Get the ChannelPackets
    ChannelPacket curPacket;
    int nchannels = 0;
    do {
        // Read the next packet into curPacket and store it off
        if (fread (&curPacket, 1, sizeof (ChannelPacket), m_fd) != sizeof (ChannelPacket)) {
            error ("Unexpected end of file \"%s\".", m_filename.c_str());
            close();
            return false;
        }
        m_channel_packets.push_back (curPacket);

        // Add the number of channels in this packet to nchannels
        nchannels += curPacket.channels().size();
    } while (curPacket.chained);

    // Get the depth per pixel per channel
    TypeDesc chanType = TypeDesc::UINT8;
    if (curPacket.size == 16)
        chanType = TypeDesc::UINT16;

    // Set the details in the ImageSpec
    m_spec = ImageSpec (m_pic_header.width, m_pic_header.height, nchannels, chanType);
    m_spec.attribute ("BitsPerSample", (int)curPacket.size);
    
    if (m_pic_header.comment[0] != 0) {
        char comment[81];
        strncpy (comment, m_pic_header.comment, 80);
        comment[80] = 0;
        m_spec.attribute ("ImageDescription", comment);
    }

    // Build the scanline index
    fpos_t curPos;
    fgetpos (m_fd, &curPos);
    m_scanline_markers.push_back(curPos);

    spec = m_spec;
    return true;
}
Пример #4
0
/**
* Handle a single packet for this channel
*
* Description:\n
*	Given an input packet, checks to make sure that the packet belongs
*	to this channel (fatal error if not).  If the packet is late (i.e.,
*	the current sequence number is greater than the packet sequence
*	number, the packet is discarded and the "out of sequence" counter
*	is bumped.  If the packet is not late, it is processed.\n
*	Processing consists of converting the linear (X & Y) input
*	polarization to circular (LCP & RCP), buffering the resulting
*	data until there is enough data to perform the DFB, then
*	queuing the channel to a worker thread for DFB processing.\n\n
* Notes:\n
*	Handles startup of the activity.
* 	There are two ways to handle single polarization: (1) clone the
* 	active polarization packets to make the inactive polarization
* 	packets, which results in two identical data streams, for which
* 	all processing is done except reporting signals.  (2) Create
* 	a single data stream and eliminate downstream processing of the
* 	inactive polarization.  Either method requires that the number
* 	of polarizations be checked at certain points during the
* 	processing.\n
* 	This version clones the active polarization into the inactive
* 	polarization to create a dual-pol stream.
*
* @param	pkt the input data packet.
*
* @see		addPacket
*/
Error
Channel::handlePacket_(ChannelPacket *pkt)
{
	// if we're not in an observation, discard the data without even
	// looking at it
	switch (getState()) {
	case DX_ACT_PEND_BASE_ACCUM:
	case DX_ACT_RUN_BASE_ACCUM:
	case DX_ACT_PEND_DC:
	case DX_ACT_RUN_DC:
		break;
	default:
		pktList->free(pkt);
		return (0);
	}

	// if the collection has been aborted internally, just throw away
	// all packets.  This can occur when the two polarizations are not
	// synchronized, and will eventually stop data collection.
	if (abortCollection) {
		pktList->free(pkt);
		return (0);
	}
	++stats.netStats.total;
	// validate the packet.  It must be our packet (correct src and pol)
	// and have the data valid bit set.
	ATADataPacketHeader& hdr = pkt->getHeader();
	if (hdr.src != channelSpec.src || hdr.chan != (uint32_t) channelSpec.chan) {
		++stats.netStats.wrong;
		pktList->free(pkt);
		return (0);
	}
	if (!(hdr.flags & ATADataPacketHeader::DATA_VALID)) {
		++stats.netStats.invalid;
		stats.inputStats.reset();
		pktList->free(pkt);
		curSeq = 0;
		return (0);
	}

	// reject all packets which don't match the correct polarization(s)
	if (hdr.polCode != rPol && hdr.polCode != lPol) {
		++stats.netStats.wrong;
		pktList->free(pkt);
		return (0);
	}

	// handle data collection startup
	Error err = 0;
	if (getState() == DX_ACT_PEND_BASE_ACCUM
			|| getState() == DX_ACT_PEND_DC) {
		// check for correct version number
		if (hdr.version != ATADataPacketHeader::CURRENT_VERSION) {
//			setState(DX_ACT_NONE);
			pktList->free(pkt);
			return (ERR_IPV);
		}

		int32_t t = hdr.absTime >> 32;
		NssDate start = activity->getStartTime();
#if (LOG_PACKET_TIMES)
		// send a message to the SSE logging activity start time and
		// packet time of first packtet received
		if (!armed) {
			timeval tv;
			gettimeofday(&tv, NULL);
			LogWarning(ERR_NE, activity->getActivityId(),
					"t = %u, Start time = %u, first pkt time = %u",
					tv.tv_sec, start.tv_sec, t);
		}
#endif
		if (!armed || t < start.tv_sec) {
			armed = true;
			if (t >= start.tv_sec)
				err = ERR_STAP;
			pktList->free(pkt);
			return (err);
		}
		else {
#if (LOG_PACKET_TIMES)
			// send a message to the SSE logging activity start time and
			// packet time of start packet
			timeval tv;
			gettimeofday(&tv, NULL);
			LogWarning(ERR_NE, activity->getActivityId(),
					"t = %u, Start time = %u, start pkt time = %u",
					tv.tv_sec, start.tv_sec, t);
#endif
			// start the data collection, recording the actual start time
			// and setting the packet sequence number
			if (getState() == DX_ACT_PEND_BASE_ACCUM)
				setState(DX_ACT_RUN_BASE_ACCUM);
			else
				setState(DX_ACT_RUN_DC);
			startSeq = curSeq = hdr.seq;
			// register the actual start time
			timeval s = ATADataPacketHeader::absTimeToTimeval(hdr.absTime);
			start.tv_sec = s.tv_sec;
			start.tv_usec = s.tv_usec;
			activity->setActualStartTime(start);
			// set the channel frequency from the packet header
			channelSpec.freq = hdr.freq;
			activity->setSkyFreq(hdr.freq);
		}
	}

	// test for out-of-sync between packet streams (this would normally
	// be one stream received, other not due to channelizer crash).  This
	// will stop data collection and send a message to the SSE.
	int32_t e = r.size() - l.size();
	if (!singlePol && abs(e) >= MAX_PACKET_ERROR) {
		pktList->free(pkt);
		abortCollection = true;
		return (ERR_PSU);
	}
	if (abs(e) > abs(data.err))
		data.err = e;

	// all late packets can be immediately discarded
	if (getState() != DX_ACT_RUN_BASE_ACCUM
			&& getState() != DX_ACT_RUN_DC) {
		pktList->free(pkt);
	}
	else if (hdr.seq < curSeq) {
		++stats.netStats.late;
		pktList->free(pkt);
	}
	else {
		// insert the packet
		addPacket(pkt);
		// if this is a single polarization, clone the packet for the
		// other polarization
		if (singlePol) {
			ChannelPacket *tmp = static_cast<ChannelPacket *> (pktList->alloc());
			memcpy(tmp, pkt, sizeof(ChannelPacket));
			ATADataPacketHeader& hdr = tmp->getHeader();
			hdr.polCode = inactivePol;
			addPacket(tmp);
		}
	}
	return (0);
}