blob: 653d159e3557c82171ad93a93243b8adbd08ecbd [file] [log] [blame]
Harald Welte940738e2018-03-07 07:50:57 +01001/*
2* Copyright 2018 sysmocom - s.f.m.c. GmbH
3*
4* This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion.
5*
6* This use of this software may be subject to additional restrictions.
7* See the LEGAL file in the main directory for details.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13*/
14
15#ifndef _LMS_DEVICE_H_
16#define _LMS_DEVICE_H_
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include "radioDevice.h"
23
24#include <lime/LMSDevice.h>
25#include <sys/time.h>
26#include <math.h>
27#include <string>
28#include <iostream>
29
30/** A class to handle a LimeSuite supported device */
31class LMSDevice:public RadioDevice {
32
33private:
34
35 lms_device_t *m_lms_dev;
36 lms_stream_t m_lms_Stream_rx;
37 lms_stream_t m_lms_Stream_tx;
38
39 int sps;
40
41 unsigned long long samplesRead; ///< number of samples read from LMS
42 unsigned long long samplesWritten; ///< number of samples sent to LMS
43
44 bool started; ///< flag indicates LMS has started
45 bool skipRx; ///< set if LMS is transmit-only.
46
47 TIMESTAMP ts_offset;
48
49public:
50
51 /** Object constructor */
52 LMSDevice(size_t sps);
53
54 /** Instantiate the LMS */
55 int open(const std::string &, int, bool);
56
57 /** Start the LMS */
58 bool start();
59
60 /** Stop the LMS */
61 bool stop();
62
63 /** Set priority not supported */
64 void setPriority(float prio = 0.5) {
65 } enum TxWindowType getWindowType() {
66 return TX_WINDOW_LMS1;
67 }
68
69 /**
70 Read samples from the LMS.
71 @param buf preallocated buf to contain read result
72 @param len number of samples desired
73 @param overrun Set if read buffer has been overrun, e.g. data not being read fast enough
74 @param timestamp The timestamp of the first samples to be read
75 @param underrun Set if LMS does not have data to transmit, e.g. data not being sent fast enough
76 @param RSSI The received signal strength of the read result
77 @return The number of samples actually read
78 */
79 int readSamples(std::vector < short *>&buf, int len, bool * overrun,
80 TIMESTAMP timestamp = 0xffffffff, bool * underrun =
81 NULL, unsigned *RSSI = NULL);
82 /**
83 Write samples to the LMS.
84 @param buf Contains the data to be written.
85 @param len number of samples to write.
86 @param underrun Set if LMS does not have data to transmit, e.g. data not being sent fast enough
87 @param timestamp The timestamp of the first sample of the data buffer.
88 @param isControl Set if data is a control packet, e.g. a ping command
89 @return The number of samples actually written
90 */
91 int writeSamples(std::vector < short *>&bufs, int len, bool * underrun,
92 TIMESTAMP timestamp = 0xffffffff, bool isControl =
93 false);
94
95 /** Update the alignment between the read and write timestamps */
96 bool updateAlignment(TIMESTAMP timestamp);
97
98 /** Set the transmitter frequency */
99 bool setTxFreq(double wFreq, size_t chan = 0);
100
101 /** Set the receiver frequency */
102 bool setRxFreq(double wFreq, size_t chan = 0);
103
104 /** Returns the starting write Timestamp*/
105 TIMESTAMP initialWriteTimestamp(void) {
106 return 20000;
107 }
108
109 /** Returns the starting read Timestamp*/
110 TIMESTAMP initialReadTimestamp(void) {
111 return 20000;
112 }
113
114 /** returns the full-scale transmit amplitude **/
115 double fullScaleInputValue() {
116 return 13500.0;
117 }
118
119 /** returns the full-scale receive amplitude **/
120 double fullScaleOutputValue() {
121 return 9450.0;
122 }
123
124 /** sets the receive chan gain, returns the gain setting **/
125 double setRxGain(double dB, size_t chan = 0);
126
127 /** get the current receive gain */
128 double getRxGain(size_t chan = 0) {
129 return rxGain;
130 }
131
132 /** return maximum Rx Gain **/
133 double maxRxGain(void);
134
135 /** return minimum Rx Gain **/
136 double minRxGain(void);
137
138 /** sets the transmit chan gain, returns the gain setting **/
139 double setTxGain(double dB, size_t chan = 0);
140
141 /** return maximum Tx Gain **/
142 double maxTxGain(void);
143
144 /** return minimum Rx Gain **/
145 double minTxGain(void);
146
147 /** sets the RX path to use, returns true if successful and false otherwise */
148 bool setRxAntenna(const std::string & ant, size_t chan = 0);
149
150 /* return the used RX path */
151 std::string getRxAntenna(size_t chan = 0);
152
153 /** sets the RX path to use, returns true if successful and false otherwise */
154 bool setTxAntenna(const std::string & ant, size_t chan = 0);
155
156 /* return the used RX path */
157 std::string getTxAntenna(size_t chan = 0);
158
159 /** Return internal status values */
160 inline double getTxFreq(size_t chan = 0) {
161 return 0;
162 }
163 inline double getRxFreq(size_t chan = 0) {
164 return 0;
165 }
166 inline double getSampleRate() {
167 return actualSampleRate;
168 }
169 inline double numberRead() {
170 return samplesRead;
171 }
172 inline double numberWritten() {
173 return samplesWritten;
174 }
175
176 std::vector < std::string > tx_paths, rx_paths;
177};
178
179#endif // _LMS_DEVICE_H_