EchoLinkQso.h
Go to the documentation of this file.00001
00040 #ifndef ECHOLINK_QSO_INCLUDED
00041 #define ECHOLINK_QSO_INCLUDED
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include <sys/time.h>
00051 #include <sigc++/sigc++.h>
00052 #include <stdint.h>
00053 #include <string>
00054
00055
00056
00057
00058
00059
00060
00061
00062 extern "C" {
00063 #include <gsm.h>
00064 }
00065 #include <AsyncTimer.h>
00066 #include <AsyncIpAddress.h>
00067 #include <AsyncAudioSink.h>
00068 #include <AsyncAudioSource.h>
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 namespace EchoLink
00094 {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00145 class Qso
00146 : public SigC::Object, public Async::AudioSink, public Async::AudioSource
00147 {
00148 public:
00149 class GsmVoicePacket
00150 {
00151 public:
00152 uint8_t version;
00153 uint8_t pt;
00154 uint16_t seqNum;
00155 uint32_t time;
00156 uint32_t ssrc;
00157 uint8_t data[33*4];
00158 } __attribute__ ((packed));
00159
00163 typedef enum
00164 {
00165 STATE_DISCONNECTED,
00166 STATE_CONNECTING,
00167 STATE_BYE_RECEIVED,
00168 STATE_CONNECTED
00169 } State;
00170
00178 Qso(const Async::IpAddress& ip, const std::string& callsign="",
00179 const std::string& name="", const std::string& info="");
00180
00184 ~Qso(void);
00185
00194 bool initOk(void) { return init_ok; }
00195
00201 bool setLocalCallsign(const std::string& callsign);
00202
00207 const std::string& localCallsign(void) const { return callsign; }
00208
00214 bool setLocalName(const std::string& name);
00215
00220 const std::string& localName(void) const { return name; }
00221
00227 void setLocalInfo(const std::string& info);
00228
00233 const std::string& localInfo(void) const { return local_stn_info; }
00234
00247 bool connect(void);
00248
00266 bool accept(void);
00267
00273 bool disconnect(void);
00274
00280 bool sendInfoData(const std::string& info="");
00281
00287 bool sendChatData(const std::string& msg);
00288
00293 const Async::IpAddress& remoteIp(void) const
00294 {
00295 return remote_ip;
00296 }
00297
00306 bool sendAudioRaw(GsmVoicePacket *packet);
00307
00312 void setRemoteName(const std::string& name) { remote_name = name; }
00313
00319 const std::string& remoteName(void) const { return remote_name; }
00320
00325 void setRemoteCallsign(const std::string& call) { remote_call = call; }
00326
00332 const std::string& remoteCallsign(void) const { return remote_call; }
00333
00341 bool isRemoteInitiated(void) const { return is_remote_initiated; }
00342
00348 bool receivingAudio(void) const { return receiving_audio; }
00349
00354 State currentState(void) const { return state; }
00355
00360 SigC::Signal1<void, const std::string&> infoMsgReceived;
00361
00366 SigC::Signal1<void, const std::string&> chatMsgReceived;
00367
00372 SigC::Signal1<void, State> stateChange;
00373
00380 SigC::Signal1<void, bool> isReceiving;
00381
00391 SigC::Signal1<void, GsmVoicePacket*> audioReceivedRaw;
00392
00393
00405 virtual int writeSamples(const float *samples, int count);
00406
00415 virtual void flushSamples(void);
00416
00424 virtual void resumeOutput(void);
00425
00426
00427 protected:
00436 virtual void allSamplesFlushed(void);
00437
00438
00439 private:
00440 static const int KEEP_ALIVE_TIME = 10000;
00441 static const int MAX_CONNECT_RETRY_CNT = 5;
00442 static const int CON_TIMEOUT_TIME = 50000;
00443 static const int RX_INDICATOR_HANG_TIME = 200;
00444 static const int SEND_BUFFER_SIZE = 4*160;
00445
00446 bool init_ok;
00447 unsigned char sdes_packet[1500];
00448 int sdes_length;
00449 State state;
00450 gsm gsmh;
00451 uint16_t next_audio_seq;
00452 Async::Timer * keep_alive_timer;
00453 int connect_retry_cnt;
00454 Async::Timer * con_timeout_timer;
00455 std::string callsign;
00456 std::string name;
00457 std::string local_stn_info;
00458 gsm_signal send_buffer[SEND_BUFFER_SIZE];
00459 int send_buffer_cnt;
00460 Async::IpAddress remote_ip;
00461 Async::Timer * rx_indicator_timer;
00462 struct timeval last_audio_packet_received;
00463 std::string remote_name;
00464 std::string remote_call;
00465 bool is_remote_initiated;
00466 bool receiving_audio;
00467
00468 Qso(const Qso&);
00469 Qso& operator=(const Qso&);
00470 void printData(const unsigned char *buf, int len);
00471 void handleCtrlInput(unsigned char *buf, int len);
00472 inline void handleByePacket(unsigned char *buf, int len);
00473 inline void handleSdesPacket(unsigned char *buf, int len);
00474 void handleAudioInput(unsigned char *buf, int len);
00475 inline void handleNonAudioPacket(unsigned char *buf, int len);
00476 inline void handleAudioPacket(unsigned char *buf, int len);
00477 void micAudioRead(void *buf, size_t len);
00478 bool sendSdesPacket(void);
00479 void sendKeepAlive(Async::Timer *timer);
00480 void setState(State state);
00481 void connectionTimeout(Async::Timer *timer);
00482 bool setupConnection(void);
00483 void cleanupConnection(void);
00484 bool sendGsmPacket(void);
00485 void checkRxActivity(Async::Timer *timer);
00486 bool sendByePacket(void);
00487
00488
00489 };
00490
00491
00492 }
00493
00494 #endif
00495
00496
00497
00498
00499
00500
00501