@@ -79,6 +79,7 @@ Result FTP::configureBearer(const char *apn)
7979 preInit ();
8080 }
8181 }
82+ attempts = 0 ;
8283
8384 strcpy_P (buffer, BEARER_PROFILE_GPRS);
8485 strcpy_P (resp1, OK);
@@ -90,6 +91,30 @@ Result FTP::configureBearer(const char *apn)
9091 if (sendCmdAndWaitForResp (buffer, resp1, 2000 ) == FALSE )
9192 result = ERROR_BEARER_PROFILE_APN;
9293
94+ strcpy_P (buffer, QUERY_BEARER);
95+ strcpy_P (resp1, BEARER_OPEN);
96+ while (sendCmdAndWaitForResp (buffer, resp1, 2000 ) == FALSE && attempts < MAX_ATTEMPTS)
97+ {
98+ attempts++;
99+ if (attempts == MAX_ATTEMPTS)
100+ {
101+ result = ERROR_OPEN_GPRS_CONTEXT;
102+ }
103+ }
104+
105+ attempts = 0 ;
106+
107+ strcpy_P (buffer, OPEN_GPRS_CONTEXT);
108+ strcpy_P (resp1, OK);
109+ while (sendCmdAndWaitForResp (buffer, resp1, 2000 ) == FALSE && attempts < MAX_ATTEMPTS)
110+ {
111+ attempts++;
112+ if (attempts == MAX_ATTEMPTS)
113+ {
114+ result = ERROR_QUERY_GPRS_CONTEXT;
115+ }
116+ }
117+
93118 return result;
94119}
95120
@@ -99,14 +124,11 @@ Result FTP::putBegin(const char *fileName,
99124 const char *pass,
100125 const char *path)
101126{
102- Result result;
127+ Result result = SUCCESS ;
103128
104129 char buffer[64 ];
105130 char resp[12 ];
106131
107- // sendCmdAndWaitForResp("AT+FTPSSL=1\r\n", "OK", 2000);
108- // sendCmdAndWaitForResp("AT+SSLOPT=1,1\r\n", "OK", 2000);
109-
110132 delay (10000 );
111133 strcpy_P (buffer, AT_FTPCID);
112134 strcpy_P (resp, OK);
@@ -162,7 +184,26 @@ Result FTP::putBegin(const char *fileName,
162184
163185Result FTP::putWrite (const char *data, unsigned int size)
164186{
165- Result result;
187+ Result result = SUCCESS;
188+
189+ unsigned int attempts = 0 ;
190+ unsigned int MAX_ATTEMPTS = 10 ;
191+
192+ while (putWriteStart (size) != SUCCESS || putWriteEnd (data, size) != SUCCESS)
193+ {
194+ attempts++;
195+ if (attempts == MAX_ATTEMPTS)
196+ {
197+ return ERROR_FTPPUT11;
198+ }
199+ }
200+
201+ return result;
202+ }
203+
204+ Result FTP::putWriteStart (unsigned int size)
205+ {
206+ Result result = SUCCESS;
166207
167208 char buffer[32 ];
168209 char resp[32 ];
@@ -173,20 +214,31 @@ Result FTP::putWrite(const char *data, unsigned int size)
173214 {
174215 return ERROR_FTPPUT2;
175216 }
176- else
177- {
178- write (data, size);
179217
180- strcpy_P (resp, AT_FTPPUT1_RESP);
181- waitForResp (resp, 2000 );
218+ return result;
219+ }
220+
221+ Result FTP::putWriteEnd (const char *data, unsigned int size)
222+ {
223+ Result result = SUCCESS;
224+
225+ char buffer[32 ];
226+ char resp[32 ];
227+
228+ write (data, size);
229+
230+ strcpy_P (resp, AT_FTPPUT1_RESP);
231+ if (waitForResp (resp, 2000 ) == FALSE )
232+ {
233+ return ERROR_FTPPUT11;
182234 }
183235
184236 return result;
185237}
186238
187239Result FTP::putEnd ()
188240{
189- Result result;
241+ Result result = SUCCESS ;
190242 serialSIM800.flush ();
191243
192244 char buffer[32 ];
0 commit comments