File: smodlib.h

package info (click to toggle)
speaker 1.0.1-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 264 kB
  • ctags: 174
  • sloc: cpp: 1,521; tcl: 786; makefile: 91; sh: 22
file content (144 lines) | stat: -rw-r--r-- 5,339 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//***************************************************************
//  smodlib.h - header file for voice manipulation library for
//          USR Sportster voice modem with speakerphone.
//  Author: Eugene Anikin (anikin@anikin.ddns.org - subject:"Speaker")
//***************************************************************
#ifdef SND_LIBR
#error sndlib.h was already included!!!!!!
#endif
#define SND_LIBR

#define BUFFER_SIZE 512
#define DTMF_SIZE 128
#define DLE 020
#define ETX 003

// Setup serial port parameters.
// This class takes care of the tty settings.
// It restores original settings on destruction.
class PortParam
{
   protected:
      struct termios told;
      char*  PortName;
      int    IsSetup;

   public:
      PortParam(char* PortName);
      ~PortParam(){ if(IsSetup) RestorePortMode();
                    if (PortName) delete PortName; };

      int SetPortMode(int speed); 
      int RestorePortMode();
};

class VModem 
{
   private:
      ConfigInfo* conf; // This will be just a pointer to passed object!!!
      PortParam* ttyParm;
      int isParent;     // True if this is a parent process.
      int ParentID;     // parent process ID (used by a child -- receiving proc)
      int ChildID;      // child process ID (used by a parent -- main program)
      int pipeD[2];     // communications pipe -- used to transfer data from
                      // receiving proc to the parent. 
      int StopChild;   // Flag to terminate child...
      char LastRec;    // Last character popped from the pipe.
                        // Used in GotSignal exclusively!!!
   protected:
      int fd; // File descriptor of the opened modem port...

      char Data[BUFFER_SIZE]; // The major receiving buffer.
      int  inData;     // Tells how much stuff we have in the Data buffer.

      char DTMF[DTMF_SIZE];      // Receiving buffer for DTMF signals
      int  inDTMF;      // Number of received DTMF signals

      char PubDTMF[PUBDTMFSIZE]; // "Public" DTMF signals. Those that are not  
      int  inPubDTMF;            // used internally.

      int  MsgExchTimeOut; // Time out in secs for the message exchange func
   public:
      VModem(){conf = NULL; ttyParm = NULL;};
      VModem(ConfigInfo* con);
      int     Init(ConfigInfo* con);
      virtual ~VModem();
   
      // If the port has some data in it, read it and stuff
      // all appropriate buffers
      void  ReadFromPort();
//      void  GotSignal2(){ StopChild = 1; };

      // Checks the buffer for the one of the messages in MsgStr,
      // 1 on success
      // 0 if did not find
      // -1 if found ERROR
      // If the SavTo is not NULL, all the data (up to the string
      // if found) will be saved to that buffer, and Num will have 
      // number of transferred bytes.
      // If DelOnNotFound is 0 and the MsgStr was not found,
      // data in the original buffer will not be deleted!
      // Naturally, SavTo buffer must be not shorter than Data
      int CheckBuffer( char* MsgStr, char* SavTo = NULL, int* Num = NULL, 
                     int DelOnNotFound = 1 );

      /* Starts read communication with the modem */
      /* returns 0 on failure */
      int  InitRead();
      void StopRead(){ close(fd); ttyParm->RestorePortMode();};

      // Returns handle of the opened serial port...
      int  GetPortFD(){return fd;};

      // Received data access functions
      void FlushRecBuffer(){ inData = 0; inDTMF = 0; LastRec = '\0';}
      int GetRecBytes(){ return inData; };
      int GetRecDTMF(){ return inDTMF; };

      // Function that is called to process DTMF signals
      // returns 
      // 0 - Signal processed, no addittional action necessary
      // 1 - abort data transfer
      virtual int ProcessDTMF();
      virtual int ProcessDTMFChar(char DTM);

      void  ResetPubDTMF(){inPubDTMF = 0;};
      int   GetPubDTMF(char* ARRAY);

      // Execute sequence of commands. If some commands
      // times out, will repeat it up to three times
      int ExecuteSequence( CommandSequence* CommandSeq );

      // Returns 1 - success
      // 0 - failure or time out
      
      // Message exchange function. 
      // Returns 1 - success
      // 0 - failure (got ERROR)
      // -1 - time out.
      // First param - what to send (add nl,cr)
      // Second param - what to expect (several choices separate by |)
      // Ex: MsgExchange("ATZ", "OK|VCON");
      int MsgExchange( char* MsgSnd, char* MsgExpect );

      // Check if the message has arrived and return all the info 
      // in the buffer preceeding this message.
      // If the buffer is NULL, check message only. The buffer
      // should be at least BUFFER_SIZE big.
      // 1 on success
      // 0 if did not find
      // -1 if found ERROR
      // First param - what to expect
      // Ex: MsgCheck("RING")
      int MsgCheck( char* MsgExpect, char* buffer = NULL, int* inbuf = NULL )
         {return CheckBuffer(MsgExpect, buffer, inbuf, 0);};

      // Write everything modem says up to MsgExpect to the file.
      // Will be used in the answering machine.        
      int GrabAFile( char* FName, char* MsgSend ,char* Expect,char* Until);
      
      // Opposite to the GrabAFile. Read the file and send it to the
      // modem.
      int SendAFile( char* FName, char* MsgSend ,char* Expect,char* Until);
};