source: rtos_arduino/trunk/arduino_lib/libraries/GSM/examples/Tools/BandManagement/BandManagement.ino@ 136

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

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

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