source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino@ 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: 2.8 KB
Line 
1/*
2 Band Management
3
4 This sketch, for the Arduino GSM shield, checks the band
5 currently configured in the modem and allows you to change
6 it.
7
8 Please check http://www.worldtimezone.com/gsm.html
9 Usual configurations:
10 Europe, Africa, Middle East: E-GSM(900)+DCS(1800)
11 USA, Canada, South America: GSM(850)+PCS(1900)
12 Mexico: PCS(1900)
13 Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)
14
15
16 Circuit:
17 * GSM shield
18
19 ATTENTION: to work correctly with M0/M0 pro you have to connect pin 2 to pin 4 of the shield
20
21 created 12 June 2012
22 by Javier Zorzano, Scott Fitzgerald
23
24 This example is in the public domain.
25 */
26
27// libraries
28#include <GSM.h>
29
30// initialize the library instance
31GSMBand band;
32
33void setup()
34{
35 // initialize serial communications and wait for port to open:
36 SerialUSB.begin(9600);
37 while (!SerialUSB) {
38 ; // wait for serial port to connect. Needed for Leonardo only
39 }
40
41 // Beginning the band manager restarts the modem
42 SerialUSB.println("Restarting modem...");
43 band.begin();
44 SerialUSB.println("Modem restarted.");
45
46};
47
48
49void loop()
50{
51 // Get current band
52 String bandName = band.getBand(); // Get and print band name
53 SerialUSB.print("Current band:");
54 SerialUSB.println(bandName);
55 SerialUSB.println("Want to change the band you’re on?");
56 String newBandName;
57 newBandName = askUser();
58 // Tell the user what we are about to do…
59 SerialUSB.print("\nConfiguring band ");
60 SerialUSB.println(newBandName);
61 // Change the band
62 boolean operationSuccess;
63 operationSuccess = band.setBand(newBandName);
64 // Tell the user if the operation was OK
65 if (operationSuccess)
66 {
67 SerialUSB.println("Success");
68 }
69 else
70 {
71 SerialUSB.println("Error while changing band");
72 }
73
74 if (operationSuccess)
75 {
76 while (true);
77 }
78}
79
80// This function offers the user different options
81// through the Serial interface
82// The user selects one
83String askUser()
84{
85 String newBand;
86 SerialUSB.println("Select band:");
87 // Print the different options
88 SerialUSB.println("1 : E-GSM(900)");
89 SerialUSB.println("2 : DCS(1800)");
90 SerialUSB.println("3 : PCS(1900)");
91 SerialUSB.println("4 : E-GSM(900)+DCS(1800) ex: Europe");
92 SerialUSB.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am.");
93 SerialUSB.println("6 : GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900)");
94
95 // Empty the incoming buffer
96 while (SerialUSB.available())
97 SerialUSB.read();
98
99 // Wait for an answer, just look at the first character
100 while (!SerialUSB.available());
101 char c = SerialUSB.read();
102 if (c == '1')
103 newBand = GSM_MODE_EGSM;
104 else if (c == '2')
105 newBand = GSM_MODE_DCS;
106 else if (c == '3')
107 newBand = GSM_MODE_PCS;
108 else if (c == '4')
109 newBand = GSM_MODE_EGSM_DCS;
110 else if (c == '5')
111 newBand = GSM_MODE_GSM850_PCS;
112 else if (c == '6')
113 newBand = GSM_MODE_GSM850_EGSM_DCS_PCS;
114 else
115 newBand = "GSM_MODE_UNDEFINED";
116 return newBand;
117}
118
119
120
121
122
Note: See TracBrowser for help on using the repository browser.