source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/GSM/src/GSM3VoiceCallService.cpp@ 175

Last change on this file since 175 was 175, checked in by ertl-honda, 8 years ago

ライブラリを Arduino IDE 1.7.9 にupdate

File size: 3.8 KB
Line 
1/*
2This 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
11This library has been developed by Telefónica Digital - PDI -
12- Physical Internet Lab, as part as its collaboration with
13Arduino and the Open Hardware Community.
14
15September-December 2012
16
17This library is free software; you can redistribute it and/or
18modify it under the terms of the GNU Lesser General Public
19License as published by the Free Software Foundation; either
20version 2.1 of the License, or (at your option) any later version.
21
22This library is distributed in the hope that it will be useful,
23but WITHOUT ANY WARRANTY; without even the implied warranty of
24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25Lesser General Public License for more details.
26
27You should have received a copy of the GNU Lesser General Public
28License along with this library; if not, write to the Free Software
29Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
31The latest version of this library can always be found at
32https://github.com/BlueVia/Official-Arduino
33*/
34#include <GSM3VoiceCallService.h>
35#include <Arduino.h>
36
37#include <GSM3ShieldV1VoiceProvider.h>
38GSM3ShieldV1VoiceProvider theShieldV1VoiceProvider;
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
48GSM3VoiceCallService::GSM3VoiceCallService(bool synch)
49{
50 GSM3ShieldV1VoiceProvider theShieldV1VoiceProvider; //needed to avoid hard fault in M0
51 if(synch)
52 flags |= GSM3VOICECALLSERVICE_SYNCH;
53 theGSM3MobileVoiceProvider->initialize();
54}
55
56GSM3_voiceCall_st GSM3VoiceCallService::getvoiceCallStatus()
57{
58 if(theGSM3MobileVoiceProvider==0)
59 return IDLE_CALL;
60 theShieldV1VoiceProvider.recognizeUnsolicitedEvent(1) ;
61 return theGSM3MobileVoiceProvider->getvoiceCallStatus();
62}
63
64int GSM3VoiceCallService::ready()
65{
66 if(theGSM3MobileVoiceProvider==0)
67 return 0;
68
69 return theGSM3MobileVoiceProvider->ready();
70}
71
72int GSM3VoiceCallService::voiceCall(const char* to, unsigned long timeout)
73{
74 if(theGSM3MobileVoiceProvider==0){
75 return 0;
76 }
77
78 if(flags & GSM3VOICECALLSERVICE_SYNCH )
79 {
80 theGSM3MobileVoiceProvider->voiceCall(to);
81 unsigned long m;
82 m=millis();
83 // Wait an answer for timeout
84 while(((millis()-m)< timeout )&&(getvoiceCallStatus()==CALLING)){
85 delay(100);
86 }
87 if(getvoiceCallStatus()==TALKING)
88 return 1;
89 else
90 return 0;
91 }
92 else
93 {
94 return theGSM3MobileVoiceProvider->voiceCall(to);
95 }
96
97}
98
99int GSM3VoiceCallService::answerCall()
100{
101 if(theGSM3MobileVoiceProvider==0)
102 return 0;
103
104 return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->answerCall());
105}
106
107int GSM3VoiceCallService::hangCall()
108{
109 if(theGSM3MobileVoiceProvider==0)
110 return 0;
111
112 return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->hangCall());
113}
114
115int GSM3VoiceCallService::retrieveCallingNumber(char* buffer, int bufsize)
116{
117 if(theGSM3MobileVoiceProvider==0)
118 return 0;
119
120 return waitForAnswerIfNeeded(theGSM3MobileVoiceProvider->retrieveCallingNumber(buffer, bufsize));
121}
122
123int GSM3VoiceCallService::waitForAnswerIfNeeded(int returnvalue)
124{
125 // If synchronous
126 if(flags & GSM3VOICECALLSERVICE_SYNCH )
127 {
128 unsigned long m;
129 m=millis();
130 // Wait for __TOUT__
131 while(((millis()-m)< __TOUT__ )&&(ready()==0))
132 delay(100);
133 // If everything was OK, return 1
134 // else (timeout or error codes) return 0;
135 if(ready()==1)
136 return 1;
137 else
138 return 0;
139 }
140 // If not synchronous just kick ahead the coming result
141 return ready();
142}
143
144
145
146
Note: See TracBrowser for help on using the repository browser.