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

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

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

File size: 3.8 KB
Line 
1#include <GSM3ShieldV1CellManagement.h>
2
3GSM3ShieldV1CellManagement::GSM3ShieldV1CellManagement()
4{
5}
6
7bool GSM3ShieldV1CellManagement::parseQCCID_available(bool& rsp)
8{
9 char c;
10 bool iccidFound = false;
11 int i = 0;
12
13 while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 19))
14 {
15 if((c < 58) & (c > 47))
16 iccidFound = true;
17
18 if(iccidFound)
19 {
20 bufferICCID[i] = c;
21 i++;
22 }
23 }
24 bufferICCID[i]=0;
25
26 return true;
27}
28
29bool GSM3ShieldV1CellManagement::parseQENG_available(bool& rsp)
30{
31 char c;
32 char location[50] = "";
33 int i = 0;
34
35 if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG: ", true)))
36 rsp = false;
37 else
38 rsp = true;
39
40 if (!(theGSM3ShieldV1ModemCore.theBuffer().chopUntil("+QENG:", true)))
41 rsp = false;
42 else
43 rsp = true;
44
45 while(((c = theGSM3ShieldV1ModemCore.theBuffer().read()) != 0) & (i < 50))
46 {
47 location[i] = c;
48 i++;
49 }
50 location[i]=0;
51
52 char* res_tok = strtok(location, ",");
53 res_tok=strtok(NULL, ",");
54 strcpy(countryCode, res_tok);
55 res_tok=strtok(NULL, ",");
56 strcpy(networkCode, res_tok);
57 res_tok=strtok(NULL, ",");
58 strcpy(locationArea, res_tok);
59 res_tok=strtok(NULL, ",");
60 strcpy(cellId, res_tok);
61
62 return true;
63}
64
65int GSM3ShieldV1CellManagement::getLocation(char *country, char *network, char *area, char *cell)
66{
67 if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY))
68 return 2;
69
70 countryCode=country;
71 networkCode=network;
72 locationArea=area;
73 cellId=cell;
74
75 theGSM3ShieldV1ModemCore.openCommand(this,GETLOCATION);
76 getLocationContinue();
77
78 unsigned long timeOut = millis();
79 while(((millis() - timeOut) < 5000) & (ready() == 0));
80
81 return theGSM3ShieldV1ModemCore.getCommandError();
82}
83
84void GSM3ShieldV1CellManagement::getLocationContinue()
85{
86 bool resp;
87
88 switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
89 case 1:
90 theGSM3ShieldV1ModemCore.gss.tunedDelay(3000);
91 delay(3000);
92 theGSM3ShieldV1ModemCore.setCommandCounter(2);
93 theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG=1"), false);
94 theGSM3ShieldV1ModemCore.print("\r");
95 break;
96 case 2:
97 if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
98 {
99 theGSM3ShieldV1ModemCore.gss.tunedDelay(3000);
100 delay(3000);
101 theGSM3ShieldV1ModemCore.setCommandCounter(3);
102 theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QENG?"), false);
103 theGSM3ShieldV1ModemCore.print("\r");
104 }
105 else theGSM3ShieldV1ModemCore.closeCommand(1);
106 break;
107 case 3:
108 if (resp)
109 {
110 parseQENG_available(resp);
111 theGSM3ShieldV1ModemCore.closeCommand(3);
112 }
113 else theGSM3ShieldV1ModemCore.closeCommand(2);
114 break;
115 }
116}
117
118int GSM3ShieldV1CellManagement::getICCID(char *iccid)
119{
120 if((theGSM3ShieldV1ModemCore.getStatus() != GSM_READY) && (theGSM3ShieldV1ModemCore.getStatus() != GPRS_READY))
121 return 2;
122
123 bufferICCID=iccid;
124 theGSM3ShieldV1ModemCore.openCommand(this,GETICCID);
125 getICCIDContinue();
126
127 unsigned long timeOut = millis();
128 while(((millis() - timeOut) < 5000) & (ready() == 0));
129
130 return theGSM3ShieldV1ModemCore.getCommandError();
131}
132
133void GSM3ShieldV1CellManagement::getICCIDContinue()
134{
135 bool resp;
136
137 switch (theGSM3ShieldV1ModemCore.getCommandCounter()) {
138 case 1:
139 theGSM3ShieldV1ModemCore.setCommandCounter(2);
140 theGSM3ShieldV1ModemCore.genericCommand_rq(PSTR("AT+QCCID"), false);
141 theGSM3ShieldV1ModemCore.print("\r");
142 break;
143 case 2:
144 if (theGSM3ShieldV1ModemCore.genericParse_rsp(resp))
145 {
146 parseQCCID_available(resp);
147 theGSM3ShieldV1ModemCore.closeCommand(2);
148 }
149 else theGSM3ShieldV1ModemCore.closeCommand(1);
150 break;
151 }
152}
153
154void GSM3ShieldV1CellManagement::manageResponse(byte from, byte to)
155{
156 switch(theGSM3ShieldV1ModemCore.getOngoingCommand())
157 {
158 case NONE:
159 theGSM3ShieldV1ModemCore.gss.cb.deleteToTheEnd(from);
160 break;
161 case GETLOCATION:
162 getLocationContinue();
163 break;
164 case GETICCID:
165 getICCIDContinue();
166 break;
167 }
168}
Note: See TracBrowser for help on using the repository browser.