Skip to content

Commit 93fc09c

Browse files
committed
FileUtils:downloadFile() returns size
1 parent 1dce5e7 commit 93fc09c

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/GSMFileUtils.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool GSMFileUtils::begin(const bool restart)
1414
int status;
1515

1616
if (restart)
17-
MODEM.begin();
17+
MODEM.begin();
1818

1919
if (_debug) {
2020
MODEM.debug();
@@ -86,10 +86,8 @@ size_t GSMFileUtils::listFiles(String files[]) const
8686
return n;
8787
}
8888

89-
void GSMFileUtils::downloadFile(const String filename, const char buf[], uint32_t size, const bool append)
89+
uint32_t GSMFileUtils::downloadFile(const String filename, const char buf[], uint32_t size, const bool append)
9090
{
91-
String response;
92-
9391
if (!append)
9492
deleteFile(filename);
9593

@@ -107,16 +105,20 @@ void GSMFileUtils::downloadFile(const String filename, const char buf[], uint32_
107105
hex[i * 2] = (char)(n1 > 9 ? 'A' + n1 - 10 : '0' + n1);
108106
hex[i * 2 + 1] = (char)(n2 > 9 ? 'A' + n2 - 10 : '0' + n2);
109107
}
110-
for (auto h: hex)
108+
for (auto h : hex)
111109
MODEM.write(h);
112110

113-
int status = MODEM.waitForResponse(1000, &response);
111+
int status = MODEM.waitForResponse(1000);
112+
if (status != 1)
113+
return 0;
114114

115115
auto fileExists = _files.indexOf(filename) > 0;
116-
if (status && !fileExists) {
116+
if (!fileExists) {
117117
_getFileList();
118118
_countFiles();
119119
}
120+
121+
return size;
120122
}
121123

122124
uint32_t GSMFileUtils::readFile(const String filename, String* content)
@@ -144,7 +146,7 @@ uint32_t GSMFileUtils::readFile(const String filename, String* content)
144146
uint32_t size = sizePart.toInt() / 2;
145147
skip += 3;
146148

147-
String * _data = content;
149+
String* _data = content;
148150
(*_data).reserve(size);
149151

150152
for (auto i = 0; i < size; i++) {

src/GSMFileUtils.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ class GSMFileUtils {
1414
size_t listFiles(String list[]) const;
1515
uint32_t listFile(const String filename) const;
1616

17-
void downloadFile(const String filename, const char buf[], const uint32_t size, const bool append);
18-
void downloadFile(const String filename, const char buf[], const uint32_t size) { downloadFile(filename, buf, size, false); };
19-
void downloadFile(const String filename, const String& buf) { downloadFile(filename, buf.c_str(), buf.length(), false); }
17+
uint32_t downloadFile(const String filename, const char buf[], const uint32_t size, const bool append);
18+
uint32_t downloadFile(const String filename, const char buf[], const uint32_t size) { return downloadFile(filename, buf, size, false); };
19+
uint32_t downloadFile(const String filename, const String& buf) { return downloadFile(filename, buf.c_str(), buf.length(), false); }
2020

21-
void appendFile(const String filename, const String& buf) { downloadFile(filename, buf.c_str(), buf.length(), true); }
22-
void appendFile(const String filename, const char buf[], const uint32_t size) { downloadFile(filename, buf, size, true); }
21+
uint32_t appendFile(const String filename, const String& buf) { return downloadFile(filename, buf.c_str(), buf.length(), true); }
22+
uint32_t appendFile(const String filename, const char buf[], const uint32_t size) { return downloadFile(filename, buf, size, true); }
2323

2424
bool deleteFile(const String filename);
2525
int deleteFiles();
2626

2727
uint32_t readFile(const String filename, String* content);
2828
uint32_t readFile(const String filename, uint8_t* content);
29-
// size_t readBlock(const String filename, String* content, const bool binary = false);
3029
uint32_t readBlock(const String filename, const uint32_t offset, const uint32_t len, uint8_t* content);
3130

3231
uint32_t freeSpace();

0 commit comments

Comments
 (0)