EchoLib 1.3.5
EchoLinkQso.h
Go to the documentation of this file.
40#ifndef ECHOLINK_QSO_INCLUDED
41#define ECHOLINK_QSO_INCLUDED
42
43
44/****************************************************************************
45 *
46 * System Includes
47 *
48 ****************************************************************************/
49
50#include <sys/time.h>
51#include <sigc++/sigc++.h>
52#include <stdint.h>
53#include <string>
54
55
56/****************************************************************************
57 *
58 * Project Includes
59 *
60 ****************************************************************************/
61
62extern "C" {
63#include <gsm.h>
64}
65#include <AsyncTimer.h>
66#include <AsyncIpAddress.h>
67#include <AsyncAudioSink.h>
68#include <AsyncAudioSource.h>
69
70
71/****************************************************************************
72 *
73 * Local Includes
74 *
75 ****************************************************************************/
76
77
78
79/****************************************************************************
80 *
81 * Forward declarations
82 *
83 ****************************************************************************/
84
85
86
87/****************************************************************************
88 *
89 * Namespace
90 *
91 ****************************************************************************/
92
93namespace EchoLink
94{
95
96/****************************************************************************
97 *
98 * Forward declarations inside the declared namespace
99 *
100 ****************************************************************************/
101
102
103
104/****************************************************************************
105 *
106 * Defines & typedefs
107 *
108 ****************************************************************************/
109
110
111
112/****************************************************************************
113 *
114 * Exported Global Variables
115 *
116 ****************************************************************************/
117
118
119
120/****************************************************************************
121 *
122 * Class definitions
123 *
124 ****************************************************************************/
125
145class Qso
146 : public sigc::trackable, public Async::AudioSink, public Async::AudioSource
147{
148 public:
150 {
151 struct {
152 uint8_t version;
153 uint8_t pt;
154 uint16_t seqNum;
155 uint32_t time;
156 uint32_t ssrc;
158 uint8_t data[1024];
159 } __attribute__ ((packed));
160
167
178
186 Qso(const Async::IpAddress& ip, const std::string& callsign="",
187 const std::string& name="", const std::string& info="");
188
192 ~Qso(void);
193
202 bool initOk(void) { return init_ok; }
203
209 bool setLocalCallsign(const std::string& callsign);
210
215 const std::string& localCallsign(void) const { return callsign; }
216
222 bool setLocalName(const std::string& name);
223
228 const std::string& localName(void) const { return name; }
229
235 void setLocalInfo(const std::string& info);
236
241 const std::string& localInfo(void) const { return local_stn_info; }
242
255 bool connect(void);
256
274 bool accept(void);
275
281 bool disconnect(void);
282
288 bool sendInfoData(const std::string& info="");
289
295 bool sendChatData(const std::string& msg);
296
301 const Async::IpAddress& remoteIp(void) const
302 {
303 return remote_ip;
304 }
305
316 bool sendAudioRaw(RawPacket *raw_packet);
317
322 void setRemoteParams(const std::string& priv);
323
328 void setRemoteName(const std::string& name) { remote_name = name; }
329
335 const std::string& remoteName(void) const { return remote_name; }
336
341 void setRemoteCallsign(const std::string& call) { remote_call = call; }
342
348 const std::string& remoteCallsign(void) const { return remote_call; }
349
357 bool isRemoteInitiated(void) const { return is_remote_initiated; }
358
364 bool receivingAudio(void) const { return receiving_audio; }
365
370 State currentState(void) const { return state; }
371
376 sigc::signal<void, const std::string&> infoMsgReceived;
377
382 sigc::signal<void, const std::string&> chatMsgReceived;
383
388 sigc::signal<void, State> stateChange;
389
396 sigc::signal<void, bool> isReceiving;
397
407 sigc::signal<void, RawPacket*> audioReceivedRaw;
408
409
427 virtual int writeSamples(const float *samples, int count);
428
437 virtual void flushSamples(void);
438
446 virtual void resumeOutput(void);
447
454 void setUseGsmOnly(void);
455
456 protected:
465 virtual void allSamplesFlushed(void);
466
467
468 private:
469 struct Private;
470
471 static const int KEEP_ALIVE_TIME = 10000;
472 static const int MAX_CONNECT_RETRY_CNT = 5;
473 static const int CON_TIMEOUT_TIME = 50000;
474 static const int RX_INDICATOR_POLL_TIME = 100; // 10 times/s
475 static const int RX_INDICATOR_SLACK = 100; // 100ms extra time
476 static const int RX_INDICATOR_MAX_TIME = 1000; // Max 1s timeout
477 static const int FRAME_COUNT = 4;
478 static const int BUFFER_SIZE = FRAME_COUNT*160;
479 static const int BLOCK_TIME = FRAME_COUNT*1000*160/8000;
480
481 bool init_ok;
482 unsigned char sdes_packet[1500];
483 int sdes_length;
484 State state;
485 gsm gsmh;
486 uint16_t next_audio_seq;
487 Async::Timer * keep_alive_timer;
488 int connect_retry_cnt;
489 Async::Timer * con_timeout_timer;
490 std::string callsign;
491 std::string name;
492 std::string local_stn_info;
493 short receive_buffer[BUFFER_SIZE];
494 short send_buffer[BUFFER_SIZE];
495 int send_buffer_cnt;
496 Async::IpAddress remote_ip;
497 Async::Timer * rx_indicator_timer;
498 std::string remote_name;
499 std::string remote_call;
500 bool is_remote_initiated;
501 bool receiving_audio;
502 bool use_gsm_only;
503 Private *p;
504 int rx_timeout_left;
505
506 Qso(const Qso&);
507 Qso& operator=(const Qso&);
508 void printData(const unsigned char *buf, int len);
509 void handleCtrlInput(unsigned char *buf, int len);
510 inline void handleByePacket(unsigned char *buf, int len);
511 inline void handleSdesPacket(unsigned char *buf, int len);
512 void handleAudioInput(unsigned char *buf, int len);
513 inline void handleNonAudioPacket(unsigned char *buf, int len);
514 inline void handleAudioPacket(unsigned char *buf, int len);
515 void micAudioRead(void *buf, size_t len);
516 bool sendSdesPacket(void);
517 void sendKeepAlive(Async::Timer *timer);
518 void setState(State state);
519 void connectionTimeout(Async::Timer *timer);
520 bool setupConnection(void);
521 void cleanupConnection(void);
522 bool sendVoicePacket(void);
523 void checkRxActivity(Async::Timer *timer);
524 bool sendByePacket(void);
525
526}; /* class Qso */
527
528
529} /* namespace */
530
531#endif /* ECHOLINK_QSO_INCLUDED */
532
533
534
535/*
536 * This file has not been truncated
537 */
538