Streamtools: Rescaler to change the vertical/horizontal stacking
[jpcrr.git] / streamtools / cutdump.cpp
blob2561ee34d6a686eebd94be89adc8ba4c4c4b8c7f
1 #include "newpacket.hpp"
2 #include "timeparse.hpp"
3 #include <iostream>
4 #include <sstream>
5 #include <list>
6 #include <map>
7 #include <vector>
8 #include <cstdio>
9 #include <cstring>
10 #include <stdexcept>
11 #include <algorithm>
13 int real_main(int argc, char** argv)
15 std::map<std::string, uint16_t> channel_assignments;
16 std::vector<struct channel> chans;
17 uint16_t dummy_channel = 0;
18 if(argc != 5) {
19 std::cerr << "syntax: muxdump.exe <input> <start> <end> <output>" << std::endl;
20 exit(1);
23 read_channel rchan(argv[1]);
24 write_channel wchan(argv[4]);
25 uint64_t low = parse_timespec(argv[2]);
26 uint64_t high = parse_timespec(argv[3]);
27 if(low > high) {
28 std::cerr << "Start of region must be before end." << std::endl;
29 exit(1);
32 //Create dummy channel.
33 channel_assignments["<DUMMY>"] = dummy_channel = (uint16_t)chans.size();
34 struct channel c;
35 c.c_channel = (uint16_t)chans.size();
36 c.c_type = 3;
37 c.c_channel_name = "<DUMMY>";
38 chans.push_back(c);
39 wchan.start_segment(chans);
41 packet* p;
42 while((p = rchan.read())) {
43 if(p->rp_timestamp < low || p->rp_timestamp > high)
44 continue;
45 if(!channel_assignments.count(p->rp_channel_name)) {
46 //No channel yet, create.
47 channel_assignments[p->rp_channel_name] = (uint16_t)chans.size();
48 struct channel c;
49 c.c_channel = (uint16_t)chans.size();
50 c.c_type = p->rp_major;
51 c.c_channel_name = p->rp_channel_name;
52 chans.push_back(c);
53 wchan.start_segment(chans);
55 uint16_t chan = channel_assignments[p->rp_channel_name];
56 if(chans[chan].c_type != p->rp_major) {
57 //Change type.
58 chans[chan].c_type = p->rp_major;
59 wchan.start_segment(chans);
61 p->rp_channel = chan;
62 p->rp_timestamp -= low;
63 wchan.write(*p);
64 delete p;
67 struct packet p2;
68 p2.rp_channel = dummy_channel;
69 p2.rp_timestamp = high - low;
70 p2.rp_minor = 0;
71 wchan.write(p2);
73 return 0;