Yate
yateradio.h
1
21
22#ifndef __YATERADIO_H
23#define __YATERADIO_H
24
25#include <yateclass.h>
26#include <yatexml.h>
27
28#ifdef _WINDOWS
29
30#ifdef LIBYRADIO_EXPORTS
31#define YRADIO_API __declspec(dllexport)
32#else
33#ifndef LIBYRADIO_STATIC
34#define YRADIO_API __declspec(dllimport)
35#endif
36#endif
37
38#endif /* _WINDOWS */
39
40#ifndef YRADIO_API
41#define YRADIO_API
42#endif
43
44
45namespace TelEngine {
46
47class GSML3Codec; // GSM Layer codec
48class RadioCapability; // Radio device capabilities
49class RadioInterface; // Generic radio interface
50
51class YRADIO_API GSML3Codec
52{
53 YNOCOPY(GSML3Codec);
54public:
58 enum Flags {
59 XmlDumpMsg = 0x01,
60 XmlDumpIEs = 0x02,
61 MSCoder = 0x04,
62 };
63
67 enum Status {
68 NoError = 0,
69 MsgTooShort,
70 UnknownProto,
71 ParserErr,
72 MissingParam,
73 IncorrectOptionalIE,
74 IncorrectMandatoryIE,
75 MissingMandatoryIE,
76 UnknownMsgType,
77 };
78
82 enum Protocol {
83 GCC = 0x00, // Group Call Control
84 BCC = 0x01, // Broadcast Call Control
85 EPS_SM = 0x02, // EPS Session Management
86 CC = 0x03, // Call Control; Call Related SS messages
87 GTTP = 0x04, // GPRS Transparent Transport Protocol (GTTP)
88 MM = 0x05, // Mobility Management
89 RRM = 0x06, // Radio Resources Management
90 EPS_MM = 0x07, // EPS Mobility Management
91 GPRS_MM = 0x08, // GPRS Mobility Management
92 SMS = 0x09, // SMS
93 GPRS_SM = 0x0a, // GPRS Session Management
94 SS = 0x0b, // Non Call Related SS messages
95 LCS = 0x0c, // Location services
96 Extension = 0x0e, // reserved for extension of the PD to one octet length
97 Test = 0x0f, // used by tests procedures described in 3GPP TS 44.014, 3GPP TS 34.109 and 3GPP TS 36.509
98 Unknown = 0xff,
99 };
100
104 enum Type {
105 NoType = 0,
106 T,
107 V,
108 TV,
109 LV,
110 TLV,
111 LVE,
112 TLVE,
113 };
114
118 enum XmlType {
119 Skip,
120 XmlElem,
121 XmlRoot,
122 };
123
128 PlainNAS = 0x00,
129 IntegrityProtect = 0x01,
130 IntegrityProtectCiphered = 0x02,
131 IntegrityProtectNewEPSCtxt = 0x03,
132 IntegrityProtectCipheredNewEPSCtxt = 0x04,
133 ServiceRequestHeader = 0xa0,
134 };
135
140
149 unsigned int decode(const uint8_t* in, unsigned int len, XmlElement*& out, const NamedList& params = NamedList::empty());
150
158 unsigned int encode(const XmlElement* in, DataBlock& out, const NamedList& params = NamedList::empty());
159
166 unsigned int decode(XmlElement* xml, const NamedList& params = NamedList::empty());
167
174 unsigned int encode(XmlElement* xml, const NamedList& params = NamedList::empty());
175
181 void setCodecDebug(DebugEnabler* enabler = 0, void* ptr = 0);
182
187 inline uint8_t flags() const
188 { return m_flags; }
189
195 inline void setFlags(uint8_t flgs, bool reset = false)
196 {
197 if (reset)
198 resetFlags();
199 m_flags |= flgs;
200 }
201
206 inline void resetFlags(uint8_t flgs = 0)
207 {
208 if (flgs)
209 m_flags &= ~flgs;
210 else
211 m_flags = 0;
212 }
213
218 inline void setPrintDbg(bool on = false)
219 { m_printDbg = on; }
220
225 inline bool printDbg() const
226 { return m_printDbg; }
227
232 inline DebugEnabler* dbg() const
233 { return m_dbg; }
234
239 inline void* ptr() const
240 { return m_ptr; }
241
249 static void decodeGSM7Bit(unsigned char* buf, unsigned int len, String& text,
250 unsigned int heptets = (unsigned int)-1);
251
258 static bool encodeGSM7Bit(const String& text, DataBlock& buf);
259
263 static const TokenDict s_typeDict[];
264
268 static const TokenDict s_protoDict[];
269
274
278 static const TokenDict s_errorsDict[];
279
284
289
290private:
291
292 unsigned int decodeXml(XmlElement* xml, const NamedList& params, const String& pduTag);
293 unsigned int encodeXml(XmlElement* xml, const NamedList& params, const String& pduTag);
294 void printDbg(int dbgLevel, const uint8_t* in, unsigned int len, XmlElement* xml, bool encode = false);
295
296 uint8_t m_flags; // Codec flags
297 // data used for debugging messages
298 DebugEnabler* m_dbg;
299 void* m_ptr;
300 // activate debug
301 bool m_printDbg;
302};
303
304
309class YRADIO_API RadioCapability
310{
311public:
316
317 unsigned maxPorts; // Available number of ports
318 unsigned currPorts; // Number of used (available) ports
319 uint64_t maxTuneFreq; // Maximum allowed tuning frequency (in Hz)
320 uint64_t minTuneFreq; // Minimum allowed tuning frequency (in Hz)
321 unsigned maxSampleRate; // Maximum allowed sampling rate (in Hz)
322 unsigned minSampleRate; // Minimum allowed sampling rate (in Hz)
323 unsigned maxFilterBandwidth; // Maximum allowed anti-alias filter bandwidth (in Hz)
324 unsigned minFilterBandwidth; // Minimum allowed anti-alias filter bandwidth (in Hz)
325 unsigned rxLatency; // Estimated radio latency (in samples)
326 unsigned txLatency; // Estimated transmit latency (in samples)
327};
328
329
335{
336public:
341 : samples(0), offs(0), valid(0)
342 {}
343
348 inline void reset(unsigned int value = 0)
349 { offs = valid = value; }
350
356 inline void reset(unsigned int offset, unsigned int validS) {
357 offs = offset;
358 valid = validS;
359 }
360
366 inline bool validSamples(unsigned int minSamples) const
367 { return !minSamples || minSamples >= offs || minSamples >= valid; }
368
369 float* samples; // Current read buffer
370 unsigned int offs; // Current buffer offset (in sample periods)
371 unsigned int valid; // The number of valid samples in buffer
372};
373
374
380{
381public:
389 inline RadioReadBufs(unsigned int len = 0, unsigned int validThres = 0)
390 : m_bufSamples(len), m_validMin(validThres)
391 {}
392
398 inline void reset(unsigned int len, unsigned int validThres) {
399 m_bufSamples = len;
400 m_validMin = validThres;
401 crt.reset();
402 aux.reset();
403 extra.reset();
404 }
405
410 inline unsigned int bufSamples() const
411 { return m_bufSamples; }
412
418 inline bool full(RadioBufDesc& buf) const
419 { return buf.offs >= m_bufSamples; }
420
426 inline bool valid(RadioBufDesc& buf) const
427 { return buf.validSamples(m_validMin); }
428
435
436 RadioBufDesc crt;
437 RadioBufDesc aux;
438 RadioBufDesc extra;
439
440protected:
441 unsigned int m_bufSamples; // Buffers length in sample periods
442 unsigned int m_validMin; // Valid samples threshold
443};
444
445
466class YRADIO_API RadioInterface : public RefObject, public DebugEnabler
467{
469public:
472 NoError = 0,
473 Failure = (1 << 1), // Unknown error
474 HardwareIOError = (1 << 2), // Communication error with HW
475 NotInitialized = (1 << 3), // Interface not initialized
476 NotSupported = (1 << 4), // Feature not supported
477 NotCalibrated = (1 << 5), // The radio is not calibrated
478 TooEarly = (1 << 6), // Timestamp is in the past
479 TooLate = (1 << 7), // Timestamp is in the future
480 OutOfRange = (1 << 8), // A requested parameter setting is out of range
481 NotExact = (1 << 9), // The affected value is not an exact match to the requested one
482 DataLost = (1 << 10), // Received data lost due to slow reads
483 Saturation = (1 << 11), // Data contain values outside of +/-1+/-j
484 RFHardwareFail = (1 << 12), // Failure in RF hardware
485 RFHardwareChange = (1 << 13), // Change in RF hardware, not outright failure
486 EnvironmentalFault = (1 << 14), // Environmental spec exceeded for radio HW
487 InvalidPort = (1 << 15), // Invalid port number
488 Pending = (1 << 16), // Operation is pending
489 Cancelled = (1 << 17), // Operation cancelled
490 Timeout = (1 << 18), // Operation timeout
491 HardwareNotAvailable = (1 << 19),// Device not found
492 InsufficientSpeed = (1 << 20), // Device has insufficient speed to fulfill required transfer rate
493 // Masks
494 // Errors indicating automatic application restart should not be performed
495 // These may indicate misconfig or hardware failures requiring system restart
496 NoAutoRestartMask = HardwareNotAvailable | InsufficientSpeed,
497 // Errors requiring radio or port shutdown
498 FatalErrorMask = HardwareIOError | RFHardwareFail | EnvironmentalFault | Failure |
499 NoAutoRestartMask,
500 // Errors that can be cleared
501 ClearErrorMask = TooEarly | TooLate | NotExact | DataLost | Saturation |
502 InvalidPort | Timeout,
503 // Errors that are specific to a single call
504 LocalErrorMask = NotInitialized | NotCalibrated | TooEarly | TooLate | OutOfRange |
505 NotExact | DataLost | Saturation | RFHardwareChange | InvalidPort,
506 };
507
513 PendingInitialize = 0, // initialize() is pending
514 PendingCount,
515 };
516
523 unsigned int pollPending(unsigned int oper, unsigned int waitMs = 0);
524
530 virtual unsigned int getInterface(String& devicePath) const
531 { return NotSupported; }
532
537 virtual const RadioCapability* capabilities() const
538 { return m_radioCaps; }
539
546 virtual unsigned int initialize(const NamedList& params = NamedList::empty()) = 0;
547
553 virtual unsigned int setLoopback(const char* name = 0)
554 { return NotSupported; }
555
566 virtual unsigned int setParams(NamedList& params, bool shareFate = true) = 0;
567
577 virtual unsigned int setDataDump(int dir = 0, int level = 0,
578 const NamedList* params = 0) = 0;
579
584 virtual unsigned int calibrate()
585 { return NotSupported; }
586
592 virtual unsigned int setPorts(unsigned count) = 0;
593
601 virtual unsigned int status(int port = -1) const = 0;
602
607 virtual void clearErrors()
608 { m_lastErr &= ~ClearErrorMask; }
609
624 virtual unsigned int send(uint64_t when, float* samples, unsigned size,
625 float* powerScale = 0) = 0;
626
639 virtual unsigned int recv(uint64_t& when, float* samples, unsigned& size) = 0;
640
653 virtual unsigned int read(uint64_t& when, RadioReadBufs& bufs,
654 unsigned int& skippedBufs);
655
661 virtual unsigned int getRxTime(uint64_t& when) const = 0;
662
668 virtual unsigned int getTxTime(uint64_t& when) const = 0;
669
677 virtual unsigned int setFreqOffset(float offs, float* newVal = 0) = 0;
678
684 virtual unsigned int setSampleRate(uint64_t hz) = 0;
685
691 virtual unsigned int getSampleRate(uint64_t& hz) const = 0;
692
698 virtual unsigned int setFilter(uint64_t hz) = 0;
699
705 virtual unsigned int getFilterWidth(uint64_t& hz) const = 0;
706
712 virtual unsigned int setTxFreq(uint64_t hz) = 0;
713
719 virtual unsigned int getTxFreq(uint64_t& hz) const = 0;
720
727 virtual unsigned int setTxPower(unsigned dBm) = 0;
728
734 virtual unsigned int setRxFreq(uint64_t hz) = 0;
735
741 virtual unsigned int getRxFreq(uint64_t& hz) const = 0;
742
747 virtual unsigned int setTxGain1(int val, unsigned port)
748 { return NotSupported; }
749
754 virtual unsigned int setTxGain2(int val, unsigned port)
755 { return NotSupported; }
756
761 virtual unsigned int setRxGain1(int val, unsigned port)
762 { return NotSupported; }
763
768 virtual unsigned int setRxGain2(int val, unsigned port)
769 { return NotSupported; }
770
780 virtual unsigned int setGain(bool tx, int val, unsigned int port,
781 int* newVal = 0) const
782 { return NotSupported; }
783
788 virtual const String& toString() const;
789
796 virtual void completeDevInfo(NamedList& p, bool full = false, bool retData = false);
797
804 virtual void setError(NamedList& p, unsigned int code, const char* str = 0);
805
812 static inline const char* errorName(int code, const char* defVal = 0)
813 { return lookup(code,errorNameDict(),defVal); }
814
819 static const TokenDict* errorNameDict();
820
821protected:
826 RadioInterface(const char* name);
827
833 inline void setPending(unsigned int oper, unsigned int code = Pending) {
834 Lock lck(m_mutex);
835 if (oper < PendingCount)
836 m_pendingCode[oper] = code;
837 }
838
839 unsigned int m_lastErr; // Last error that appeared during functioning
840 unsigned int m_totalErr; // All the errors that appeared
841 RadioCapability* m_radioCaps; // Radio capabilities
842
843private:
844 String m_name;
845 Mutex m_mutex;
846 unsigned int m_pendingCode[PendingCount];
847};
848
849
854class YRADIO_API RadioDataDesc
855{
856public:
861 Float = 0,
862 Int16 = 1,
863 };
864
868 enum TsType {
869 TsApp = 0, // Application level timestamp
870 TsBoard = 1, // Board (device) level timestamp
871 };
872
880 inline RadioDataDesc(uint8_t eType = Float, uint8_t tsType = TsApp,
881 uint8_t sLen = 2, uint8_t ports = 1)
882 : m_elementType(eType), m_sampleLen(sLen), m_ports(ports ? ports : 1),
883 m_tsType(tsType),
884#ifdef LITTLE_ENDIAN
885 m_littleEndian(true)
886#else
887 m_littleEndian(false)
888#endif
889 {
890 m_signature[0] = 'Y';
891 m_signature[1] = 'R';
892 m_signature[2] = 0;
893 }
894
895 uint8_t m_signature[3]; // File signature
896 uint8_t m_elementType; // Element data type
897 uint8_t m_sampleLen; // Sample length in elements
898 uint8_t m_ports; // The number of ports
899 uint8_t m_tsType; // Records timestamp type
900 bool m_littleEndian; // Endiannes
901};
902
903
909class YRADIO_API RadioDataFile : public String
910{
911public:
917 RadioDataFile(const char* name, bool dropOnError = true);
918
922 virtual ~RadioDataFile();
923
928 inline const RadioDataDesc& desc() const
929 { return m_header; }
930
935 inline bool valid() const
936 { return m_file.valid(); }
937
942 inline bool sameEndian() const
943 { return m_littleEndian == m_header.m_littleEndian; }
944
955 bool open(const char* fileName, const RadioDataDesc* data,
956 DebugEnabler* dbg = 0, int* error = 0);
957
967 bool write(uint64_t ts, const void* buf, uint32_t len, DebugEnabler* dbg = 0,
968 int* error = 0);
969
980 bool read(uint64_t& ts, DataBlock& buffer, DebugEnabler* dbg = 0, int* error = 0);
981
986 void terminate(DebugEnabler* dbg = 0);
987
994 static bool fixEndian(DataBlock& buf, unsigned int bytes);
995
996protected:
997 bool ioError(bool send, DebugEnabler* dbg, int* error, const char* extra);
998
999 bool m_littleEndian; // Machine endiannes
1000 bool m_dropOnError; // Terminate (close file) on error
1001 uint32_t m_chunkSize; // Item size (used to check data validity)
1002 RadioDataDesc m_header; // File header
1003 File m_file; // File to use
1004 DataBlock m_writeBuf;
1005};
1006
1007}; // namespace TelEngine
1008
1009#endif /* __YATERADIO_H */
1010
1011/* vi: set ts=8 sw=4 sts=4 noet: */
A class that holds just a block of raw data.
Definition yateclass.h:4237
A holder for a debug level.
Definition yateclass.h:312
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition yateclass.h:319
A stream file class.
Definition yateclass.h:7125
static const TokenDict s_errorsDict[]
Definition yateradio.h:278
static const TokenDict s_typeDict[]
Definition yateradio.h:263
static const TokenDict s_securityHeaders[]
Definition yateradio.h:273
void setCodecDebug(DebugEnabler *enabler=0, void *ptr=0)
Type
Definition yateradio.h:104
static const TokenDict s_protoDict[]
Definition yateradio.h:268
void resetFlags(uint8_t flgs=0)
Definition yateradio.h:206
EPSSecurityHeader
Definition yateradio.h:127
void * ptr() const
Definition yateradio.h:239
bool printDbg() const
Definition yateradio.h:225
uint8_t flags() const
Definition yateradio.h:187
Status
Definition yateradio.h:67
DebugEnabler * dbg() const
Definition yateradio.h:232
unsigned int encode(XmlElement *xml, const NamedList &params=NamedList::empty())
static void decodeGSM7Bit(unsigned char *buf, unsigned int len, String &text, unsigned int heptets=(unsigned int) -1)
unsigned int decode(XmlElement *xml, const NamedList &params=NamedList::empty())
static bool encodeGSM7Bit(const String &text, DataBlock &buf)
void setFlags(uint8_t flgs, bool reset=false)
Definition yateradio.h:195
GSML3Codec(DebugEnabler *dbg=0)
void setPrintDbg(bool on=false)
Definition yateradio.h:218
unsigned int decode(const uint8_t *in, unsigned int len, XmlElement *&out, const NamedList &params=NamedList::empty())
Flags
Definition yateradio.h:58
Protocol
Definition yateradio.h:82
unsigned int encode(const XmlElement *in, DataBlock &out, const NamedList &params=NamedList::empty())
static const TokenDict s_gmmRejectCause[]
Definition yateradio.h:288
XmlType
Definition yateradio.h:118
static const TokenDict s_mmRejectCause[]
Definition yateradio.h:283
Ephemeral mutex or semaphore locking object.
Definition yateclass.h:5833
Mutex support.
Definition yateclass.h:5607
A named string container class.
Definition yateclass.h:5016
static const NamedList & empty()
A buffer description.
Definition yateradio.h:335
void reset(unsigned int value=0)
Definition yateradio.h:348
void reset(unsigned int offset, unsigned int validS)
Definition yateradio.h:356
RadioBufDesc()
Definition yateradio.h:340
bool validSamples(unsigned int minSamples) const
Definition yateradio.h:366
Radio device capabilities Radio capability object describes the parameter ranges of the radio handwar...
Definition yateradio.h:310
Radio data file header This class describes records in radio data files.
Definition yateradio.h:855
ElementType
Definition yateradio.h:860
TsType
Definition yateradio.h:868
RadioDataDesc(uint8_t eType=Float, uint8_t tsType=TsApp, uint8_t sLen=2, uint8_t ports=1) uint8_t m_elementType
Definition yateradio.h:880
RadioDataFile(const char *name, bool dropOnError=true)
bool valid() const
Definition yateradio.h:935
static bool fixEndian(DataBlock &buf, unsigned int bytes)
bool write(uint64_t ts, const void *buf, uint32_t len, DebugEnabler *dbg=0, int *error=0)
void terminate(DebugEnabler *dbg=0)
virtual ~RadioDataFile()
bool read(uint64_t &ts, DataBlock &buffer, DebugEnabler *dbg=0, int *error=0)
const RadioDataDesc & desc() const
Definition yateradio.h:928
bool sameEndian() const
Definition yateradio.h:942
bool open(const char *fileName, const RadioDataDesc *data, DebugEnabler *dbg=0, int *error=0)
virtual unsigned int setFreqOffset(float offs, float *newVal=0)=0
virtual unsigned int setParams(NamedList &params, bool shareFate=true)=0
static const TokenDict * errorNameDict()
virtual unsigned int setSampleRate(uint64_t hz)=0
virtual unsigned int setLoopback(const char *name=0)
Definition yateradio.h:553
virtual unsigned int setRxGain2(int val, unsigned port)
Definition yateradio.h:768
virtual const RadioCapability * capabilities() const
Definition yateradio.h:537
virtual unsigned int setGain(bool tx, int val, unsigned int port, int *newVal=0) const
Definition yateradio.h:780
virtual void setError(NamedList &p, unsigned int code, const char *str=0)
virtual unsigned int getInterface(String &devicePath) const
Definition yateradio.h:530
virtual unsigned int setDataDump(int dir=0, int level=0, const NamedList *params=0)=0
ErrorCode
Definition yateradio.h:471
void setPending(unsigned int oper, unsigned int code=Pending)
Definition yateradio.h:833
unsigned int pollPending(unsigned int oper, unsigned int waitMs=0)
virtual unsigned int setRxGain1(int val, unsigned port)
Definition yateradio.h:761
virtual unsigned int setTxFreq(uint64_t hz)=0
virtual unsigned int setFilter(uint64_t hz)=0
virtual unsigned int send(uint64_t when, float *samples, unsigned size, float *powerScale=0)=0
virtual unsigned int recv(uint64_t &when, float *samples, unsigned &size)=0
virtual const String & toString() const
virtual unsigned int getFilterWidth(uint64_t &hz) const =0
virtual unsigned int setTxGain1(int val, unsigned port)
Definition yateradio.h:747
virtual unsigned int getRxFreq(uint64_t &hz) const =0
Operation
Definition yateradio.h:512
virtual unsigned int setTxPower(unsigned dBm)=0
virtual unsigned int calibrate()
Definition yateradio.h:584
virtual unsigned int setTxGain2(int val, unsigned port)
Definition yateradio.h:754
virtual void completeDevInfo(NamedList &p, bool full=false, bool retData=false)
static const char * errorName(int code, const char *defVal=0)
Definition yateradio.h:812
virtual unsigned int status(int port=-1) const =0
virtual unsigned int setPorts(unsigned count)=0
virtual unsigned int read(uint64_t &when, RadioReadBufs &bufs, unsigned int &skippedBufs)
virtual unsigned int getSampleRate(uint64_t &hz) const =0
RadioInterface(const char *name)
virtual unsigned int initialize(const NamedList &params=NamedList::empty())=0
virtual unsigned int getRxTime(uint64_t &when) const =0
virtual unsigned int getTxTime(uint64_t &when) const =0
virtual unsigned int setRxFreq(uint64_t hz)=0
virtual unsigned int getTxFreq(uint64_t &hz) const =0
virtual void clearErrors()
Definition yateradio.h:607
RadioInterface read buffers.
Definition yateradio.h:380
void reset(unsigned int len, unsigned int validThres)
Definition yateradio.h:398
RadioReadBufs(unsigned int len=0, unsigned int validThres=0)
Definition yateradio.h:389
String & dump(String &buf)
bool valid(RadioBufDesc &buf) const
Definition yateradio.h:426
unsigned int bufSamples() const
Definition yateradio.h:410
bool full(RadioBufDesc &buf) const
Definition yateradio.h:418
A C-style string handling class.
Definition yateclass.h:2131
Definition yatemime.h:34
Definition yateclass.h:848