Make pcap_source produce packed output, convert to unpacked using standard block.

git-svn-id: http://op25.osmocom.org/svn/trunk@278 65a5c917-d112-43f1-993d-58c26a4786be
This commit is contained in:
stevie 2011-04-03 12:57:26 +00:00
parent 898ef39212
commit b28ec65e9a
3 changed files with 27 additions and 36 deletions

View File

@ -58,13 +58,13 @@ op25_pcap_source_b::work(int nof_output_items, gr_vector_const_void_star& input_
{
try {
uint8_t *out = reinterpret_cast<uint8_t*>(output_items[0]);
const size_t SYMS_AVAIL = symbols_.size();
const size_t SYMS_REQD = static_cast<size_t>(nof_output_items);
for(size_t i = 0; i < SYMS_REQD; ++i) {
out[i] = symbols_[loc_++];
loc_ %= SYMS_AVAIL;
const size_t OCTETS_AVAIL = octets_.size();
const size_t OCTETS_REQD = static_cast<size_t>(nof_output_items);
for(size_t i = 0; i < OCTETS_REQD; ++i) {
out[i] = octets_[loc_++];
loc_ %= OCTETS_AVAIL;
}
return SYMS_REQD;
return OCTETS_REQD;
} catch(const std::exception& x) {
cerr << x.what() << endl;
exit(EXIT_FAILURE);
@ -76,14 +76,14 @@ op25_pcap_source_b::work(int nof_output_items, gr_vector_const_void_star& input_
}
op25_pcap_source_b::op25_pcap_source_b(const char *path, float delay) :
gr_sync_block ("pcap_source_b", gr_make_io_signature (0, 0, 0), gr_make_io_signature (1, 1, sizeof(uint8_t))),
gr_sync_block ("pcap_source_b",
gr_make_io_signature (0, 0, 0),
gr_make_io_signature (1, 1, sizeof(uint8_t))),
loc_(0),
SYMBOLS_PER_SEC_(4800.0),
symbols_(delay * SYMBOLS_PER_SEC_, 0)
octets_(delay * 1200, 0)
{
pcap_t *pcap;
char err[PCAP_ERRBUF_SIZE];
pcap = pcap_open_offline(path, err);
pcap_t *pcap = pcap_open_offline(path, err);
if(pcap) {
struct pcap_pkthdr hdr;
for(const uint8_t *octets; octets = pcap_next(pcap, &hdr);) {
@ -93,16 +93,13 @@ op25_pcap_source_b::op25_pcap_source_b(const char *path, float delay) :
const size_t P25CAI_OFS = ETHERNET_SZ + IP_SZ + UDP_SZ;
if(P25CAI_OFS < hdr.caplen) {
const size_t FRAME_SZ = hdr.caplen - P25CAI_OFS;
// push some zero symbols to separate frames
const size_t SILENCE_SYMS = 48;
symbols_.resize(symbols_.size() + SILENCE_SYMS, 0);
// push symbols from frame payload MSB first
symbols_.reserve(symbols_.capacity() + ((hdr.caplen - P25CAI_OFS) * 4));
// push some zero octets to separate frames
const size_t SILENCE_OCTETS = 48;
octets_.resize(octets_.size() + SILENCE_OCTETS, 0);
// push octets from frame payload into local buffer
octets_.reserve(octets_.capacity() + hdr.caplen - P25CAI_OFS);
for(size_t i = 0; i < FRAME_SZ; ++i) {
for(int16_t j = 6; j >= 0; j -= 2) {
dibit d = (octets[P25CAI_OFS + i] >> j) & 0x3;
symbols_.push_back(d);
}
octets_.push_back(octets[P25CAI_OFS + i]);
}
}
}

View File

@ -36,7 +36,7 @@ op25_pcap_source_b_sptr op25_make_pcap_source_b(const char *path, float delay);
/**
* op25_pcap_source_b is a GNU Radio block for reading from a
* tcpdump-formatted capture file and producing a stream of dibit symbols.
* tcpdump-formatted capture file and producing a stream of octets.
*/
class op25_pcap_source_b : public gr_sync_block
{
@ -75,24 +75,14 @@ private:
private:
/**
* Define dibit type
* The next octet to be read from the input file.
*/
typedef uint8_t dibit;
/**
* The next symbol to be read from the input file.
*/
size_t loc_;
size_t loc_;
/**
* The number of symbols/s produced by this block.
* Symbols from the input file.
*/
const float SYMBOLS_PER_SEC_;
/**
* Symbols from the input file.
*/
std::vector<dibit> symbols_;
std::vector<uint8_t> octets_;
};

View File

@ -112,6 +112,10 @@ class usrp_c4fm_tx_block(gr.top_block):
# open the pcap source
pcap = op25.pcap_source_b(filename, delay)
# convert octets into dibits
bits_per_symbol = 2
unpack = gr.packed_to_unpacked_bb(bits_per_symbol, gr.GR_MSB_FIRST)
# modulator
c4fm = p25_mod_bf(output_sample_rate=channel_rate)
@ -144,7 +148,7 @@ class usrp_c4fm_tx_block(gr.top_block):
u.tune(self.db.which(), self.db, freq)
self.db.set_enable(True)
self.connect(pcap, c4fm, interpolator, fm, gain, u)
self.connect(pcap, unpack, c4fm, interpolator, fm, gain, u)
# inject frames
#