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
00304
00305
00314 bool sendAudioRaw(GsmVoicePacket *packet);
00315
00324
00325
00330 void setRemoteName(const std::string& name) { remote_name = name; }
00331
00337 const std::string& remoteName(void) const { return remote_name; }
00338
00343 void setRemoteCallsign(const std::string& call) { remote_call = call; }
00344
00350 const std::string& remoteCallsign(void) const { return remote_call; }
00351
00359 bool isRemoteInitiated(void) const { return is_remote_initiated; }
00360
00366 bool receivingAudio(void) const { return receiving_audio; }
00367
00372 State currentState(void) const { return state; }
00373
00378 SigC::Signal1<void, const std::string&> infoMsgReceived;
00379
00384 SigC::Signal1<void, const std::string&> chatMsgReceived;
00385
00390 SigC::Signal1<void, State> stateChange;
00391
00398 SigC::Signal1<void, bool> isReceiving;
00399
00405
00406
00416 SigC::Signal1<void, GsmVoicePacket*> audioReceivedRaw;
00417
00418
00430 virtual int writeSamples(const float *samples, int count);
00431
00440 virtual void flushSamples(void);
00441
00449 virtual void resumeOutput(void);
00450
00451
00452 protected:
00461 virtual void allSamplesFlushed(void);
00462
00463
00464 private:
00465 static const int KEEP_ALIVE_TIME = 10000;
00466 static const int MAX_CONNECT_RETRY_CNT = 5;
00467 static const int CON_TIMEOUT_TIME = 50000;
00468 static const int RX_INDICATOR_HANG_TIME = 200;
00469 static const int SEND_BUFFER_SIZE = 4*160;
00470
00471 bool init_ok;
00472 char * sdes_packet;
00473 int sdes_length;
00474 State state;
00475 gsm gsmh;
00476 uint16_t next_audio_seq;
00477 Async::Timer * keep_alive_timer;
00478 int connect_retry_cnt;
00479 Async::Timer * con_timeout_timer;
00480 std::string callsign;
00481 std::string name;
00482 std::string local_stn_info;
00483 gsm_signal send_buffer[SEND_BUFFER_SIZE];
00484 int send_buffer_cnt;
00485 Async::IpAddress remote_ip;
00486 Async::Timer * rx_indicator_timer;
00487 struct timeval last_audio_packet_received;
00488 std::string remote_name;
00489 std::string remote_call;
00490 bool is_remote_initiated;
00491 bool receiving_audio;
00492
00493 Qso(const Qso&);
00494 Qso& operator=(const Qso&);
00495 void printData(const unsigned char *buf, int len);
00496 void handleCtrlInput(unsigned char *buf, int len);
00497 inline void handleByePacket(unsigned char *buf, int len);
00498 inline void handleSdesPacket(unsigned char *buf, int len);
00499 void handleAudioInput(unsigned char *buf, int len);
00500 inline void handleNonAudioPacket(unsigned char *buf, int len);
00501 inline void handleAudioPacket(unsigned char *buf, int len);
00502 void micAudioRead(void *buf, size_t len);
00503 bool sendSdesPacket(void);
00504 void sendKeepAlive(Async::Timer *timer);
00505 void setState(State state);
00506 void connectionTimeout(Async::Timer *timer);
00507 bool setupConnection(void);
00508 void cleanupConnection(void);
00509 bool sendGsmPacket(void);
00510 void checkRxActivity(Async::Timer *timer);
00511 bool sendByePacket(void);
00512
00513
00514 };
00515
00516
00517 }
00518
00519 #endif
00520
00521
00522
00523
00524
00525
00526