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

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

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

File size: 4.9 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
35#include <GSM3ShieldV1PinManagement.h>
36
37// constructor
38GSM3ShieldV1PinManagement::GSM3ShieldV1PinManagement()
39{
40};
41
42// reset the modem for direct access
43void GSM3ShieldV1PinManagement::begin()
44{
45 // reset hardware
46 gsm.HWrestart();
47
48 pin_used = false;
49
50 // check modem response
51 modemAccess.writeModemCommand("AT", 1000);
52 modemAccess.writeModemCommand("ATE0", 1000);
53}
54
55/*
56 Check PIN status
57*/
58int GSM3ShieldV1PinManagement::isPIN()
59{
60 String res = modemAccess.writeModemCommand("AT+CPIN?",1000);
61 // Check response
62 char res_to_compare[res.length()];
63 res.toCharArray(res_to_compare, res.length());
64 if(strstr(res_to_compare, "READY") != NULL)
65 return 0;
66 else if(strstr(res_to_compare, "SIM PIN") != NULL)
67 return 1;
68 else if(strstr(res_to_compare, "SIM PUK") != NULL)
69 return -1;
70 else
71 return -2;
72}
73
74/*
75 Check PIN code
76*/
77int GSM3ShieldV1PinManagement::checkPIN(String pin)
78{
79 String res = modemAccess.writeModemCommand("AT+CPIN=" + pin,1000);
80 // check response
81 char res_to_compare[res.length()];
82 res.toCharArray(res_to_compare, res.length());
83 if(strstr(res_to_compare, "OK") == NULL)
84 return -1;
85 else
86 return 0;
87}
88
89/*
90 Check PUK code
91*/
92int GSM3ShieldV1PinManagement::checkPUK(String puk, String pin)
93{
94 String res = modemAccess.writeModemCommand("AT+CPIN=\"" + puk + "\",\"" + pin + "\"",1000);
95 // check response
96 char res_to_compare[res.length()];
97 res.toCharArray(res_to_compare, res.length());
98 if(strstr(res_to_compare, "OK") == NULL)
99 return -1;
100 else
101 return 0;
102}
103
104/*
105 Change PIN code
106*/
107void GSM3ShieldV1PinManagement::changePIN(String old, String pin)
108{
109 String res = modemAccess.writeModemCommand("AT+CPWD=\"SC\",\"" + old + "\",\"" + pin + "\"",2000);
110 Serial.println(res);
111 // check response
112 char res_to_compare[res.length()];
113 res.toCharArray(res_to_compare, res.length());
114 if(strstr(res_to_compare, "OK") != NULL)
115 Serial.println("Pin changed succesfully.");
116 else
117 Serial.println("ERROR");
118}
119
120/*
121 Switch PIN status
122*/
123void GSM3ShieldV1PinManagement::switchPIN(String pin)
124{
125 String res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",2",1000);
126 // check response
127 char res_to_compare[res.length()];
128 res.toCharArray(res_to_compare, res.length());
129 if(strstr(res_to_compare, "0") != NULL)
130 {
131 res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",1,\"" + pin + "\"",1000);
132 // check response
133 char res_to_compare[res.length()];
134 res.toCharArray(res_to_compare, res.length());
135 if(strstr(res_to_compare, "OK") == NULL)
136 {
137 Serial.println("ERROR");
138 pin_used = false;
139 }
140 else
141 {
142 Serial.println("OK. PIN lock on.");
143 pin_used = true;
144 }
145 }
146 else if(strstr(res_to_compare, "1") != NULL)
147 {
148 res = modemAccess.writeModemCommand("AT+CLCK=\"SC\",0,\"" + pin + "\"",1000);
149 // check response
150 char res_to_compare[res.length()];
151 res.toCharArray(res_to_compare, res.length());
152 if(strstr(res_to_compare, "OK") == NULL)
153 {
154 Serial.println("ERROR");
155 pin_used = true;
156 }
157 else
158 {
159 Serial.println("OK. PIN lock off.");
160 pin_used = false;
161 }
162 }
163 else
164 {
165 Serial.println("ERROR");
166 }
167}
168
169/*
170 Check registrer
171*/
172int GSM3ShieldV1PinManagement::checkReg()
173{
174 delay(5000);
175 String res = modemAccess.writeModemCommand("AT+CREG?",1000);
176 // check response
177 char res_to_compare[res.length()];
178 res.toCharArray(res_to_compare, res.length());
179 if(strstr(res_to_compare, "1") != NULL)
180 return 0;
181 else if(strstr(res_to_compare, "5") != NULL)
182 return 1;
183 else
184 return -1;
185}
186
187/*
188 Return if PIN lock is used
189*/
190bool GSM3ShieldV1PinManagement::getPINUsed()
191{
192 return pin_used;
193}
194
195/*
196 Set if PIN lock is used
197*/
198void GSM3ShieldV1PinManagement::setPINUsed(bool used)
199{
200 pin_used = used;
201}
Note: See TracBrowser for help on using the repository browser.