/* Copy function for baseband data that does a partial * corner turn (or transpose) based on nchan. In this case * out should point to the beginning of the data buffer. * block_pkt_idx is the seq number of this packet relative * to the beginning of the block. packets_per_block * is the total number of packets per data block (all channels). */ void guppi_udp_packet_data_copy_transpose(char *databuf, int nchan, unsigned block_pkt_idx, unsigned packets_per_block, const struct guppi_udp_packet *p) { const unsigned chan_per_packet = nchan; const size_t bytes_per_sample = 4; const unsigned samp_per_packet = guppi_udp_packet_datasize(p->packet_size) / bytes_per_sample / chan_per_packet; const unsigned samp_per_block = packets_per_block * samp_per_packet; char *iptr, *optr; unsigned isamp,ichan; iptr = guppi_udp_packet_data(p); for (isamp=0; isamp<samp_per_packet; isamp++) { optr = databuf + bytes_per_sample * (block_pkt_idx*samp_per_packet + isamp); for (ichan=0; ichan<chan_per_packet; ichan++) { memcpy(optr, iptr, bytes_per_sample); iptr += bytes_per_sample; optr += bytes_per_sample*samp_per_block; } } #if 0 // Old version... const unsigned pkt_idx = block_pkt_idx / nchan; const unsigned ichan = block_pkt_idx % nchan; const unsigned offset = ichan * packets_per_block / nchan + pkt_idx; memcpy(databuf + offset*guppi_udp_packet_datasize(p->packet_size), guppi_udp_packet_data(p), guppi_udp_packet_datasize(p->packet_size)); #endif }
/* Copy the data portion of a guppi udp packet to the given output * address. This function takes care of expanding out the * "missing" channels in 1SFA packets. */ void guppi_udp_packet_data_copy(char *out, const struct guppi_udp_packet *p) { if (p->packet_size==PACKET_SIZE_1SFA_OLD) { /* Expand out, leaving space for missing data. So far only * need to deal with 4k-channel case of 2 spectra per packet. * May need to be updated in the future if 1SFA works with * different numbers of channels. * * TODO: Update 5/12/2009, newer 1SFA modes always will have full * data contents, and the old 4k ones never really worked, so * this code can probably be deleted. */ const size_t pad = 16; const size_t spec_data_size = 4096 - 2*pad; memset(out, 0, pad); memcpy(out + pad, guppi_udp_packet_data(p), spec_data_size); memset(out + pad + spec_data_size, 0, 2*pad); memcpy(out + pad + spec_data_size + pad + pad, guppi_udp_packet_data(p) + spec_data_size, spec_data_size); memset(out + pad + spec_data_size + pad + pad + spec_data_size, 0, pad); } else { /* Packet has full data, just do a memcpy */ memcpy(out, guppi_udp_packet_data(p), guppi_udp_packet_datasize(p->packet_size)); } }