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++/signal_system.h>
00052 #include <string>
00053
00054
00055
00056
00057
00058
00059
00060
00061 extern "C" {
00062 #include <gsm.h>
00063 }
00064 #include <AsyncTimer.h>
00065 #include <AsyncIpAddress.h>
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 namespace EchoLink
00091 {
00092
00093
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
00142 class Qso : public SigC::Object
00143 {
00144 public:
00145 class GsmVoicePacket
00146 {
00147 public:
00148 unsigned char version;
00149 unsigned char pt;
00150 unsigned short seqNum;
00151 unsigned long time;
00152 unsigned long ssrc;
00153 unsigned char data[33*4];
00154 };
00155
00159 typedef enum
00160 {
00161 STATE_DISCONNECTED,
00162 STATE_CONNECTING,
00163 STATE_BYE_RECEIVED,
00164 STATE_CONNECTED
00165 } State;
00166
00174 Qso(const Async::IpAddress& ip, const std::string& callsign="",
00175 const std::string& name="", const std::string& info="");
00176
00180 ~Qso(void);
00181
00190 bool initOk(void) { return init_ok; }
00191
00197 bool setLocalCallsign(const std::string& callsign);
00198
00203 const std::string& localCallsign(void) const { return callsign; }
00204
00210 bool setLocalName(const std::string& name);
00211
00216 const std::string& localName(void) const { return name; }
00217
00223 void setLocalInfo(const std::string& info);
00224
00229 const std::string& localInfo(void) const { return local_stn_info; }
00230
00243 bool connect(void);
00244
00262 bool accept(void);
00263
00269 bool disconnect(void);
00270
00276 bool sendInfoData(const std::string& info="");
00277
00283 bool sendChatData(const std::string& msg);
00284
00289 const Async::IpAddress& remoteIp(void) const
00290 {
00291 return remote_ip;
00292 }
00293
00300 int sendAudio(short *buf, int len);
00301
00310 bool sendAudioRaw(GsmVoicePacket *packet);
00311
00320 bool flushAudioSendBuffer(void);
00321
00326 void setRemoteName(const std::string& name) { remote_name = name; }
00327
00333 const std::string& remoteName(void) const { return remote_name; }
00334
00339 void setRemoteCallsign(const std::string& call) { remote_call = call; }
00340
00346 const std::string& remoteCallsign(void) const { return remote_call; }
00347
00355 bool isRemoteInitiated(void) const { return is_remote_initiated; }
00356
00362 bool receivingAudio(void) const { return receiving_audio; }
00363
00368 SigC::Signal1<void, const std::string&> infoMsgReceived;
00369
00374 SigC::Signal1<void, const std::string&> chatMsgReceived;
00375
00380 SigC::Signal1<void, State> stateChange;
00381
00388 SigC::Signal1<void, bool> isReceiving;
00389
00395 SigC::Signal2<int, short*, int> audioReceived;
00396
00406 SigC::Signal1<void, GsmVoicePacket*> audioReceivedRaw;
00407
00408
00409 protected:
00410
00411 private:
00412 static const int KEEP_ALIVE_TIME = 10000;
00413 static const int MAX_CONNECT_RETRY_CNT = 5;
00414 static const int CON_TIMEOUT_TIME = 50000;
00415 static const int RX_INDICATOR_HANG_TIME = 200;
00416 static const int SEND_BUFFER_SIZE = 4*160;
00417
00418 bool init_ok;
00419 char * sdes_packet;
00420 int sdes_length;
00421 State state;
00422 gsm gsmh;
00423 unsigned short next_audio_seq;
00424 Async::Timer * keep_alive_timer;
00425 int connect_retry_cnt;
00426 Async::Timer * con_timeout_timer;
00427 std::string callsign;
00428 std::string name;
00429 std::string local_stn_info;
00430 gsm_signal send_buffer[SEND_BUFFER_SIZE];
00431 int send_buffer_cnt;
00432 Async::IpAddress remote_ip;
00433 Async::Timer * rx_indicator_timer;
00434 struct timeval last_audio_packet_received;
00435 std::string remote_name;
00436 std::string remote_call;
00437 bool is_remote_initiated;
00438 bool receiving_audio;
00439
00440 Qso(const Qso&);
00441 Qso& operator=(const Qso&);
00442 void printData(const unsigned char *buf, int len);
00443 void handleCtrlInput(unsigned char *buf, int len);
00444 inline void handleByePacket(unsigned char *buf, int len);
00445 inline void handleSdesPacket(unsigned char *buf, int len);
00446 void handleAudioInput(unsigned char *buf, int len);
00447 inline void handleNonAudioPacket(unsigned char *buf, int len);
00448 inline void handleAudioPacket(unsigned char *buf, int len);
00449 void micAudioRead(void *buf, size_t len);
00450 bool sendSdesPacket(void);
00451 void sendKeepAlive(Async::Timer *timer);
00452 void setState(State state);
00453 void connectionTimeout(Async::Timer *timer);
00454 bool setupConnection(void);
00455 void cleanupConnection(void);
00456 bool sendGsmPacket(void);
00457 void checkRxActivity(Async::Timer *timer);
00458 bool sendByePacket(void);
00459
00460
00461 };
00462
00463
00464 }
00465
00466 #endif
00467
00468
00469
00470
00471
00472
00473