Arduino  1.8.10
GSM3VoiceCallService.cpp
[詳解]
1 /*
2 This file is part of the GSM3 communications library for Arduino
3 -- Multi-transport communications platform
4 -- Fully asynchronous
5 -- Includes code for the Arduino-Telefonica GSM/GPRS Shield V1
6 -- Voice calls
7 -- SMS
8 -- TCP/IP connections
9 -- HTTP basic clients
10 
11 This library has been developed by Telefnica Digital - PDI -
12 - Physical Internet Lab, as part as its collaboration with
13 Arduino and the Open Hardware Community.
14 
15 September-December 2012
16 
17 This library is free software; you can redistribute it and/or
18 modify it under the terms of the GNU Lesser General Public
19 License as published by the Free Software Foundation; either
20 version 2.1 of the License, or (at your option) any later version.
21 
22 This library is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 Lesser General Public License for more details.
26 
27 You should have received a copy of the GNU Lesser General Public
28 License along with this library; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 
31 The latest version of this library can always be found at
32 https://github.com/BlueVia/Official-Arduino
33 */
34 #include <GSM3VoiceCallService.h>
35 #include <Arduino.h>
36 
39 
40 // While there is only a shield (ShieldV1) we will include it by default
41 
42 #define GSM3VOICECALLSERVICE_SYNCH 0x01 // 1: synchronous 0: asynchronous
43 #define __TOUT__ 10000
44 
45 
46 
47 
49 {
50  if(synch)
53 }
54 
56 {
58  return IDLE_CALL;
59 
61 }
62 
64 {
66  return 0;
67 
69 }
70 
71 int GSM3VoiceCallService::voiceCall(const char* to, unsigned long timeout)
72 {
74  return 0;
75 
76  if(flags & GSM3VOICECALLSERVICE_SYNCH )
77  {
79  unsigned long m;
80  m=millis();
81  // Wait an answer for timeout
82  while(((millis()-m)< timeout )&&(getvoiceCallStatus()==CALLING))
83  delay(100);
84 
86  return 1;
87  else
88  return 0;
89  }
90  else
91  {
93  }
94 
95 }
96 
98 {
100  return 0;
101 
102  return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->answerCall());
103 }
104 
106 {
108  return 0;
109 
110  return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->hangCall());
111 }
112 
114 {
116  return 0;
117 
118  return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->retrieveCallingNumber(buffer, bufsize));
119 }
120 
121 int GSM3VoiceCallService::waitForAnswerIfNeeded(int returnvalue)
122 {
123  // If synchronous
124  if(flags & GSM3VOICECALLSERVICE_SYNCH )
125  {
126  unsigned long m;
127  m=millis();
128  // Wait for __TOUT__
129  while(((millis()-m)< __TOUT__ )&&(ready()==0))
130  delay(100);
131  // If everything was OK, return 1
132  // else (timeout or error codes) return 0;
133  if(ready()==1)
134  return 1;
135  else
136  return 0;
137  }
138  // If not synchronous just kick ahead the coming result
139  return ready();
140 }
141 
142 
143 
144 
unsigned long millis(void)
Definition: wiring.c:65
char buffer[42]
virtual GSM3_voiceCall_st getvoiceCallStatus()=0
GSM3MobileVoiceProvider * theGSM3MobileVoiceProvider
virtual int retrieveCallingNumber(char *buffer, int bufsize)=0
void delay(unsigned long)
Definition: wiring.c:106
int voiceCall(const char *to, unsigned long timeout=30000)
#define __TOUT__
m
Definition: wiring.c:53
virtual int ready()=0
int retrieveCallingNumber(char *buffer, int bufsize)
virtual int answerCall()=0
virtual int voiceCall(const char *number)=0
virtual int hangCall()=0
GSM3ShieldV1VoiceProvider theShieldV1VoiceProvider
#define GSM3VOICECALLSERVICE_SYNCH
GSM3VoiceCallService(bool synch=true)
GSM3_voiceCall_st getvoiceCallStatus()