Merged r11377:11390 from jcorgan/usrp-headers in to trunk.
[debian/gnuradio] / usrp / limbo / apps-inband / read_packets.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <iostream>
27 #include <usrp_inband_usb_packet.h>
28 #include <mblock/class_registry.h>
29 #include <vector>
30 #include <usrp_usb_interface.h>
31 #include <fstream>
32
33 typedef usrp_inband_usb_packet transport_pkt;   // makes conversion to gigabit easy
34
35 int main(int argc, char *argv[]) {
36
37   if(argc !=2) {
38     std::cout << "Usage: ./read_packets <data_file>\n";
39     return -1;
40   }
41
42   std::ifstream infile;
43   std::ofstream outfile;  
44
45   unsigned int pkt_size = transport_pkt::max_pkt_size();
46   unsigned int pkt_num=0;
47
48   transport_pkt *pkt;
49   char pkt_data[pkt_size];          // allocate the number of bytes for a single packet
50
51   pkt = (transport_pkt *)pkt_data;  // makes operations cleaner to read
52
53   // Open the file and read the packets, dumping information
54   infile.open(argv[1], std::ios::binary|std::ios::in);
55   if(!infile.is_open())
56     exit(-1);
57
58   //outfile.open("dump.dat",std::ios::out|std::ios::binary);  
59
60   // read 1 packet in to the memory
61   infile.read(pkt_data, pkt_size);
62
63   while(!infile.eof()) {
64   
65     printf("Packet %u\n", pkt_num);
66
67     if(pkt->start_of_burst())
68       printf("\tstart of burst\n");
69       
70     if(pkt->end_of_burst())
71       printf("\tend of burst\n");
72     
73 //    if(pkt->carrier_sense())
74 //      printf("\tcarrier sense\n");
75
76     if(pkt->underrun())
77       printf("\tunderrun\n");
78     
79     if(pkt->overrun())
80       printf("\toverrun\n");
81
82     printf("\tchannel: \t0x%x\n", pkt->chan());
83     printf("\ttimestamp: \t0x%x\n", pkt->timestamp());
84     //printf("\ttimestamp: \t%u\n", pkt->timestamp());
85     printf("\tlength: \t%u\n", pkt->payload_len());
86     printf("\trssi: \t%u\n", pkt->rssi());
87
88     printf("\tpayload: \n");
89     for(int i=0; i < pkt->payload_len(); i++)
90     //for(int i=0; i < pkt->max_payload(); i++)
91     {
92       printf("\t%d\t0x%x\n", i, *(pkt->payload()+i));
93       //outfile.write((const char*)(pkt->payload()+i),1);
94       //printf("\t\t0x%x\n", pkt->payload()+i);
95
96     }
97     printf("\n\n");
98
99     pkt_num++;
100   
101     // read 1 packet in to the memory
102     infile.read(pkt_data, pkt_size);
103
104   }
105
106   infile.close();
107   //outfile.close();
108
109 }