source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/GSM/src/GSM3ShieldV1ScanNetworks.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.2 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 <GSM3ShieldV1ScanNetworks.h>
36
37GSM3ShieldV1ScanNetworks::GSM3ShieldV1ScanNetworks(bool trace): modem(trace)
38{
39}
40
41GSM3_NetworkStatus_t GSM3ShieldV1ScanNetworks::begin()
42{
43 modem.begin();
44 modem.restartModem();
45 // check modem response
46 modem.writeModemCommand("AT", 1000);
47 modem.writeModemCommand("ATE0", 1000);
48 return IDLE;
49}
50
51String GSM3ShieldV1ScanNetworks::getCurrentCarrier()
52{
53 String modemResponse = modem.writeModemCommand("AT+COPS?", 2000);
54
55 // Parse and check response
56 char res_to_split[modemResponse.length()];
57 modemResponse.toCharArray(res_to_split, modemResponse.length());
58 if(strstr(res_to_split,"ERROR") == NULL){
59 // Tokenizer
60 char *ptr_token;
61 ptr_token = strtok(res_to_split, "\"");
62 ptr_token = strtok(NULL, "\"");
63 String final_result = ptr_token;
64 return final_result;
65 }else{
66 return String(NULL);
67 }
68}
69
70String GSM3ShieldV1ScanNetworks::getSignalStrength()
71{
72 String modemResponse = modem.writeModemCommand("AT+CSQ", 2000);
73 char res_to_split[modemResponse.length()];
74 modemResponse.toCharArray(res_to_split, modemResponse.length());
75 if((strstr(res_to_split,"ERROR") == NULL) | (strstr(res_to_split,"99") == NULL)){
76 // Tokenizer
77 char *ptr_token;
78 ptr_token = strtok(res_to_split, ":");
79 ptr_token = strtok(NULL, ":");
80 ptr_token = strtok(ptr_token, ",");
81 String final_result = ptr_token;
82 final_result.trim();
83 return final_result;
84 }else{
85 return String(NULL);
86 }
87}
88
89String GSM3ShieldV1ScanNetworks::readNetworks()
90{
91 String modemResponse = modem.writeModemCommand("AT+COPS=?",20000);
92 String result;
93 bool inQuotes=false;
94 int quoteCounter=0;
95 for(unsigned int i=0; i<modemResponse.length();i++)
96 {
97 if(modemResponse[i]=='"')
98 {
99 if(!inQuotes)
100 {
101 inQuotes=true;
102 quoteCounter++;
103 if(quoteCounter==1)
104 result+="> ";
105 }
106 else
107 {
108 inQuotes=false;
109 if(quoteCounter==3)
110 quoteCounter=0;
111 if(quoteCounter==1)
112 result+="\n";
113
114 }
115 }
116 else
117 {
118 if(inQuotes&&(quoteCounter==1))
119 {
120 result+=modemResponse[i];
121 }
122 }
123 }
124 return result;
125}
126
Note: See TracBrowser for help on using the repository browser.