GNU Radio's DIFI Package
The DIFI Out of Tree (OOT) Module allows users to leverage and easily use cloud resources in GNU Radio.
difi_source_cpp_impl.h
Go to the documentation of this file.
1// -*- c++ -*-
2// Copyright (c) Microsoft Corporation and Welkin Sciences, LLC.
3// Licensed under the GNU General Public License v3.0 or later.
4// See License.txt in the project root for license information.
5
6#ifndef INCLUDED_DIFI_SOURCE_CPP_IMPL_H
7#define INCLUDED_DIFI_SOURCE_CPP_IMPL_H
8
9#include <deque>
10#include <algorithm>
11#include <complex>
12#include <iostream>
13#include <deque>
14#include <iterator>
15#include <pmt/pmt.h>
16
17#include <difi/difi_common.h>
19
20namespace gr {
21namespace difi {
22
23class tcp_server;
24class udp_socket;
25template <class T>
27{
28 double parse_vita_fixed_double(u_int64_t bits)
29 {
30 return (double)(bits) / (1<<20);
31 }
32 double parse_vita_fixed_double(int64_t bits)
33 {
34 return (double)(bits) / (1<<20);
35 }
36 float parse_vita_fixed_float(int16_t bits)
37 {
38 return (float)(bits) / (1<<7);
39 }
40 struct header_data {
41 u_int16_t pkt_n;
42 u_int8_t type;
43 u_int32_t header;
44 u_int32_t stream_num;
45 };
46
47 struct context_packet {
48 u_int64_t class_id;
49 u_int32_t full; //seconds
50 u_int64_t frac; //picoseconds
51 u_int32_t cif;
52 u_int32_t ref_point;
53 double bw; //Hertz
54 double if_ref_freq; //Hertz
55 double rf_ref_freq; //Hertz
56 double if_band_offset; //Hertz
57 float ref_lvl; //dBm
58 float rf_gain, if_gain; //dB
59 double samp_rate; //Hertz
60 int64_t t_adj; //femtoseconds
61 u_int32_t t_cal; //seconds
62 u_int32_t state_indicators;
63 u_int64_t payload_format;
64 };
65
66
67private:
68 template <typename M>
69 static M unpack_16(int8_t *start)
70 {
71 int16_t re;
72 memcpy(&re, start, 2);
73 int16_t imag;
74 memcpy(&imag, start + 2, 2);
75 return M(re, imag);
76 }
77
78 template <typename M>
79 static M unpack_8(int8_t *start)
80 {
81 int8_t re;
82 memcpy(&re, start, 1);
83 int8_t imag;
84 memcpy(&imag, start + 1, 1);
85 return M(re, imag);
86 }
87
88
89 typedef enum
90 {
91 throw_exe = 0,
92 ignore = 1,
93 warnings_forward = 2,
94 warnings_no_forward = 3
95 }context_behavior;
96
97 T (*d_unpacker)(int8_t *);
98 void parse_header(header_data& data);
99 pmt::pmt_t make_pkt_n_dict(int pkt_n, int size_gotten);
100 void unpack_context(context_packet& context);
101 void unpack_context_alt(context_packet& context);
102 pmt::pmt_t make_context_dict(header_data& header, int size_gotten);
103 int buffer_and_send(T* out, int noutput_items);
104
105 bool d_send;
106 u_int32_t d_last_full;
107 u_int64_t d_last_frac;
108 int32_t d_static_bits;
109 u_int32_t d_unpack_idx_size;
110 int d_behavior;
111 int d_stream_number;
112 long d_last_pkt_n;
113 pmt::pmt_t d_context;
114 std::vector<int8_t> d_packet_buffer;
115 std::deque<char> d_deque;
116 tcp_server* p_tcpserver;
117 udp_socket* p_udpsocket;
118
119public:
120 difi_source_cpp_impl(std::string ip_addr,
121 uint32_t port,
122 uint8_t socket_type,
123 int stream_number,
124 int bit_depth,
125 int context_pkt_behavior);
127 int work(int noutput_items,
128 gr_vector_const_void_star& input_items,
129 gr_vector_void_star& output_items);
130 static const uint VITA_PKT_MOD = 16;
131 static const uint MS_DATA_VITA_HEADER = 0x18;
132};
133
134} // namespace difi
135} // namespace gr
136
137#endif /* INCLUDED_DIFI_SOURCE_CPP_IMPL_H */
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
static const uint VITA_PKT_MOD
Definition difi_source_cpp_impl.h:130
difi_source_cpp_impl(std::string ip_addr, uint32_t port, uint8_t socket_type, int stream_number, int bit_depth, int context_pkt_behavior)
static const uint MS_DATA_VITA_HEADER
Definition difi_source_cpp_impl.h:131
Definition difi_source_cpp.h:18
Definition tcp_server.h:17
Definition udp_socket.h:16
Definition difi_common.h:14
Definition difi_common.h:13