source: rtos_arduino/trunk/arduino_lib/libraries/GSM/src/GSM3ShieldV2.cpp@ 136

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

ライブラリとOS及びベーシックなサンプルの追加.

File size: 7.5 KB
Line 
1/*
2This file is part of GSM3ShieldV2 library developed by Arduino.org (http://arduino.org).
3
4 GSM3ShieldV2 library is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 GSM3ShieldV2 library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GSM3ShieldV2 library. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <GSM3ShieldV1ModemVerification.h>
19#include <GSM3ShieldV2.h>
20
21
22// constructor
23GSM3ShieldV2::GSM3ShieldV2(bool db)
24{
25 debug=db;
26}
27
28GSM3ShieldV2::GSM3ShieldV2()
29{
30}
31
32// get position (longitude and latitude)
33String GSM3ShieldV2::getPosition()
34{
35 String Result = "";
36 String number;
37 // AT command for obtain the current Location
38 String modemResponse = modemAccess.writeModemCommand("AT+QCELLLOC=1", 1000);
39 // Parse and check response
40 char res_to_compare[modemResponse.length()];
41 modemResponse.toCharArray(res_to_compare, modemResponse.length());
42 if(strstr(res_to_compare,"OK") == NULL)
43 {
44 if(debug==true) Serial.println(modemResponse);
45 Result =" Position not lock ";
46 }
47 else
48 {
49 if(debug==true) Serial.println(modemResponse);
50 Result = modemResponse.substring(12, 33);
51
52 }
53 return Result;
54}
55// set speaker loudness (this command have not effect. Refer to Quectel M10 datasheet for further informaions )
56String GSM3ShieldV2::speakerLoudness(int level) // set the speaker Volume
57 // 0: Low speaker volume
58 // 1: Low speaker volume
59 // 2: Medium speaker volume
60 // 3: High speaker volume
61{
62 String Result ="", modemResponse;
63 // Send the AT command for set the speaker volume
64 switch(level)
65 {
66 case 0:
67 modemResponse = modemAccess.writeModemCommand("ATL0",300); // set low volume
68 break;
69
70 case 1:
71 modemResponse = modemAccess.writeModemCommand("ATL1",300); // set low volume
72 break;
73
74 case 2:
75 modemResponse = modemAccess.writeModemCommand("ATL2",300); // set medium volume
76 break;
77
78 case 3:
79 modemResponse = modemAccess.writeModemCommand("ATL3",300); // set High volume
80 break;
81 }
82
83 char res_to_compare[modemResponse.length()];
84 modemResponse.toCharArray(res_to_compare, modemResponse.length());
85 if(strstr(res_to_compare,"OK") == NULL)
86 {
87 Result =" Error !";
88 if(debug==true) Serial.println(Result);
89 }
90 else
91 {
92 Result = modemResponse.substring(1, 45);
93 if(debug==true) Serial.println(Result);
94 return Result;
95 }
96}
97// set speaker mode
98String GSM3ShieldV2::speakerMode(int mode) // Set the speaker on mode
99 // 0: Speaker is always off
100 // 1: Speaker is on until TA inform TE that carrier has been detected
101 // 2: Speaker is always on when TA is off-hook
102{
103 int spkMode=0;
104 char Mode[2],command[5];
105
106 Mode[1]='\0';
107 command[4]='\0';
108
109 spkMode=mode;
110 if((spkMode < 0) || (spkMode > 2)) spkMode=DEFAULT_speakerMode;
111 strcpy(command,"ATM");
112 itoa(spkMode,Mode,10);
113 strcat(command,Mode);
114 String modemResponse=modemAccess.writeModemCommand(command,300);
115 if(debug==true) Serial.println(modemResponse);
116
117 return modemResponse;
118
119}
120// set alert sound mode
121String GSM3ShieldV2::alertSoundMode(int mode) // silent the alert sound
122 // 0: Normal mode
123 // 1: Silent mode
124{
125 int soundMode=0;
126 char Mode[2],command[10];
127
128 Mode[1]='\0';
129 command[9]='\0';
130
131 soundMode=mode;
132 if((soundMode < 0) || (soundMode > 1)) soundMode=DEFAULT_AlertSoundMode;
133 strcpy(command,"AT+CALM=");
134 itoa(soundMode,Mode,10);
135 strcat(command,Mode);
136 String modemResponse=modemAccess.writeModemCommand(command,300);
137 if(debug==true) Serial.println(modemResponse);
138
139 return modemResponse;
140}
141// set ringer sound level
142String GSM3ShieldV2::ringerSoundLevel(int level) // Set the ringer volume (0-100)
143{
144 char command[12], lev[4];
145 int ringLevel=level;
146 if((ringLevel < 0) || (ringLevel > 100)) ringLevel=DEFAULT_RingerSoundLevel;
147
148 command[11]='\0';
149 lev[3]='\0';
150 strcpy(command,"AT+CRSL=");
151 itoa(ringLevel,lev,10);
152 strcat(command,lev);
153 String modemResponse=modemAccess.writeModemCommand(command,300);
154 if(debug==true) Serial.println(modemResponse);
155 return modemResponse;
156
157
158}
159// set lodspeaker volume level
160String GSM3ShieldV2::loudSpeakerVolumeLevel(int level) // Set the Speaker volume (0-100)
161{
162 char command[12], lev[4];
163 int speakerLevel=level;
164 if((speakerLevel < 0) || (speakerLevel > 100)) speakerLevel=DEFAULT_LoudSpeakerVolumeLevel;
165
166 command[11]='\0';
167 lev[3]='\0';
168 strcpy(command,"AT+CLVL=");
169 itoa(speakerLevel,lev,10);
170 strcat(command,lev);
171 String modemResponse=modemAccess.writeModemCommand(command,300);
172 if(debug==true) Serial.println(modemResponse);
173 return modemResponse;
174}
175// set mute control
176String GSM3ShieldV2::muteControl(int mode) // switch on or off mute
177 // 0: Mute off
178 // 1: Mute on
179{
180 char command[10], mod[2];
181 int muteCtrl=mode;
182 if((muteCtrl < 0) || (muteCtrl > 1)) muteCtrl=DEFAULT_muteControl; //operazione non permessa
183
184 command[9]='\0';
185 mod[1]='\0';
186 strcpy(command,"AT+CMUT=");
187 itoa(muteCtrl,mod,10);
188 strcat(command,mod);
189 String modemResponse=modemAccess.writeModemCommand(command,300);
190 if(debug==true) Serial.println(modemResponse);
191 return modemResponse;
192}
193// set microphone gain
194String GSM3ShieldV2::microphoneGainLevel(int channel, int gain) // Set the microphone channel and level
195 // Channel:
196 // 0: Normal Microphone
197 // 1: Headset Microphone
198 // 2: Loudspeaker Microphone
199 // Gain: (0-15)
200{
201 char chn[2], gn[3],command[13];
202
203 chn[1]='\0';
204 gn[2]='\0';
205 command[12]='\0';
206
207 if((channel < 0) || (channel > 2)) itoa(DEFAULT_Channel,chn,10);
208 else itoa(channel,chn,10);
209
210 if((gain < 0) || (gain > 15)) itoa(DEFAULT_MicrophoneGainLevel,gn,10);
211 else itoa(gain,gn,10);
212
213 strcpy(command,"AT+QMIC=");
214 strcat(command,chn);
215 strcat(command,",");
216 strcat(command,gn);
217 String modemResponse=modemAccess.writeModemCommand(command,300);
218 if(debug==true) Serial.println(modemResponse);
219 return modemResponse;
220
221}
222// set audio channel
223String GSM3ShieldV2::swapAudioChannel(int channel) // Set the audio channel
224 // 0: Normal audio channel
225 // 1: headset audio channel
226 // 2: Loudspeaker audio chanel
227{
228 char chn[2], command[12];
229
230 chn[1]='\0';
231 command[11]='\0';
232
233 if((channel < 0) || (channel > 2)) itoa(DEFAULT_Channel,chn,10);
234 else itoa(channel,chn,10);
235 strcpy(command,"AT+QAUDCH=");
236 strcat(command,chn);
237 String modemResponse=modemAccess.writeModemCommand(command,300);
238 if(debug==true) Serial.println(modemResponse);
239 return modemResponse;
240}
241// set the module echo mode (Refer Quectel M10 datasheet for further informaions)
242void GSM3ShieldV2::CommandEcho(int value)
243{
244 switch(value)
245 {
246 case 0: modemAccess.writeModemCommand("ATE0",300);
247 break;
248
249 case 1: modemAccess.writeModemCommand("ATE1",300);
250 break;
251
252 default:
253 break;
254 }
255}
Note: See TracBrowser for help on using the repository browser.