Skip to content

Commit adb4a92

Browse files
committed
Work on return codes
1 parent 0283002 commit adb4a92

17 files changed

Lines changed: 78 additions & 83 deletions

File tree

components/BLEManager/BLEManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ void BLEManager::outboundMsgTask()
11941194
// API Restart BLE
11951195
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11961196

1197-
void BLEManager::apiBLERestart(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
1197+
RaftRetCode BLEManager::apiBLERestart(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
11981198
{
11991199
// Stop advertising
12001200
stopAdvertising();
@@ -1204,7 +1204,7 @@ void BLEManager::apiBLERestart(const String &reqStr, String &respStr, const APIS
12041204
_bleRestartLastMs = millis();
12051205

12061206
// Restart in progress
1207-
Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
1207+
return Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
12081208
}
12091209

12101210
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

components/BLEManager/BLEManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,6 @@ class BLEManager : public SysModBase
169169
void outboundMsgTask();
170170
bool nimbleStart();
171171
bool nimbleStop();
172-
void apiBLERestart(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
172+
RaftRetCode apiBLERestart(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
173173
uint32_t parkmiller_next(uint32_t seed) const;
174174
};

components/CommandFile/CommandFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void CommandFile::addRestAPIEndpoints(RestAPIEndpointManager &endpointManager)
100100
// Run a file
101101
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102102

103-
void CommandFile::apiFileRun(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
103+
RaftRetCode CommandFile::apiFileRun(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
104104
{
105105
// File
106106
String fileName = RestAPIEndpointManager::getNthArgStr(reqStr.c_str(), 1);
@@ -140,7 +140,7 @@ void CommandFile::apiFileRun(const String &reqStr, String& respStr, const APISou
140140
rslt = true;
141141
}
142142

143-
Raft::setJsonBoolResult(reqStr.c_str(), respStr, rslt);
143+
return Raft::setJsonBoolResult(reqStr.c_str(), respStr, rslt);
144144
}
145145

146146
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

components/CommandFile/CommandFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CommandFile : public SysModBase
3232
private:
3333
// Helpers
3434
void applySetup();
35-
void apiFileRun(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
35+
RaftRetCode apiFileRun(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
3636

3737
//API Processing
3838
bool handleAPIFile(String& fileName);

components/CommandSerial/CommandSerial.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ bool CommandSerial::sendMsg(CommsChannelMsg& msg)
187187
// API
188188
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
189189

190-
void CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
190+
RaftRetCode CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
191191
{
192192
// Check valid
193193
if (!_pCommsCoreIF)
194194
{
195195
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "noCommsChannelManager");
196196
LOG_W(MODULE_PREFIX, "apiCommandSerial noCommsChannelManager");
197-
return;
197+
return RaftRetCode::RAFT_RET_INVALID_OBJECT;
198198
}
199199

200200
// Extract parameters
@@ -208,7 +208,7 @@ void CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, cons
208208
{
209209
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "notEnoughParams");
210210
LOG_W(MODULE_PREFIX, "apiCommandSerial not enough params %d", params.size());
211-
return;
211+
return RaftRetCode::RAFT_RET_INVALID_DATA;
212212
}
213213

214214
// Check type of command
@@ -225,7 +225,7 @@ void CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, cons
225225
{
226226
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "noPort");
227227
LOG_W(MODULE_PREFIX, "apiCommandSerial no port");
228-
return;
228+
return RaftRetCode::RAFT_RET_INVALID_DATA;
229229
}
230230

231231
// Find the port
@@ -245,13 +245,12 @@ void CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, cons
245245
// Set result
246246
String resultStr = String("\"bridgeID\":") + String(bridgeID);
247247
Raft::setJsonResult(reqStr.c_str(), respStr, true, nullptr, resultStr.c_str());
248-
return;
248+
return RaftRetCode::RAFT_RET_OK;
249249
}
250250
}
251251

252252
// If we get here the port name isn't found
253-
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "portNotFound");
254-
return;
253+
return Raft::setJsonErrorResult(reqStr.c_str(), respStr, "portNotFound");
255254
}
256255

257256
// Check if removing bridge
@@ -275,25 +274,18 @@ void CommandSerial::apiCommandSerial(const String &reqStr, String& respStr, cons
275274
serialPort.clearBridgeID();
276275

277276
// Set result
278-
Raft::setJsonResult(reqStr.c_str(), respStr, true);
279-
return;
277+
return Raft::setJsonResult(reqStr.c_str(), respStr, true);
280278
}
281279
}
282280

283281
// If we get here the port name isn't found
284-
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "portNotFound");
285-
return;
282+
return Raft::setJsonErrorResult(reqStr.c_str(), respStr, "portNotFound");
286283
}
287284

288285
// Unknown bridge action
289-
else
290-
{
291-
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "unknownAction");
292-
}
293-
}
294-
else
295-
{
296-
// Unknown command
297-
Raft::setJsonErrorResult(reqStr.c_str(), respStr, "unknownCommand");
286+
return Raft::setJsonErrorResult(reqStr.c_str(), respStr, "unknownAction");
298287
}
288+
289+
// Unknown command
290+
return Raft::setJsonErrorResult(reqStr.c_str(), respStr, "unknownCommand");
299291
}

components/CommandSerial/CommandSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@ class CommandSerial : public SysModBase
5252

5353
// Helpers
5454
bool sendMsg(CommsChannelMsg& msg);
55-
void apiCommandSerial(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
55+
RaftRetCode apiCommandSerial(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
5656
};

components/ESPOTAUpdate/ESPOTAUpdate.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool ESPOTAUpdate::fileStreamStart(const char* fileName, size_t fileLen)
157157
// Firmware update block (handle a firmware data block)
158158
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
159159

160-
RaftRetCode::RetCode ESPOTAUpdate::fileStreamDataBlock(FileStreamBlock& fileStreamBlock)
160+
RaftRetCode ESPOTAUpdate::fileStreamDataBlock(FileStreamBlock& fileStreamBlock)
161161
{
162162
// Get params
163163
const uint8_t *pBlock = fileStreamBlock.pBlock;
@@ -168,7 +168,7 @@ RaftRetCode::RetCode ESPOTAUpdate::fileStreamDataBlock(FileStreamBlock& fileStre
168168
{
169169
if (!fileStreamStart(fileStreamBlock.filename,
170170
fileStreamBlock.fileLenValid ? fileStreamBlock.fileLen : fileStreamBlock.contentLen))
171-
return RaftRetCode::INVALID_OPERATION;
171+
return RaftRetCode::RAFT_RET_INVALID_OPERATION;
172172
}
173173

174174
// Check if in progress
@@ -183,18 +183,18 @@ RaftRetCode::RetCode ESPOTAUpdate::fileStreamDataBlock(FileStreamBlock& fileStre
183183
{
184184
_otaDirectInProgress = false;
185185
LOG_E(MODULE_PREFIX, "esp_ota_write failed! err=0x%x", err);
186-
return RaftRetCode::OTHER_FAILURE;
186+
return RaftRetCode::RAFT_RET_OTHER_FAILURE;
187187
}
188188
}
189189

190190
// Check if final
191191
if (fileStreamBlock.finalBlock)
192192
{
193193
if (!firmwareUpdateEnd())
194-
return RaftRetCode::INVALID_DATA;
194+
return RaftRetCode::RAFT_RET_INVALID_DATA;
195195
}
196196

197-
return RaftRetCode::OK;
197+
return RaftRetCode::RAFT_RET_OK;
198198
}
199199

200200
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -259,7 +259,7 @@ bool ESPOTAUpdate::fileStreamCancelEnd(bool isNormalEnd)
259259
// Handle the API update
260260
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
261261

262-
RaftRetCode::RetCode ESPOTAUpdate::fwUpdateAPIPart(FileStreamBlock& fileStreamBlock)
262+
RaftRetCode ESPOTAUpdate::fwUpdateAPIPart(FileStreamBlock& fileStreamBlock)
263263
{
264264
// LOG_I(MODULE_PREFIX, "fwUpdateAPIPart %d, %d, %d, %d", contentLen, index, len, finalBlock);
265265

@@ -297,7 +297,7 @@ void ESPOTAUpdate::addRestAPIEndpoints(RestAPIEndpointManager& endpointManager)
297297
}
298298

299299
// ESP Firmware update
300-
RaftRetCode::RetCode ESPOTAUpdate::apiESPFirmwarePart(const String& reqStr, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo)
300+
RaftRetCode ESPOTAUpdate::apiESPFirmwarePart(const String& reqStr, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo)
301301
{
302302
// Handle with OTA update
303303
#ifdef DEBUG_ESP_OTA_UPDATE
@@ -307,13 +307,13 @@ RaftRetCode::RetCode ESPOTAUpdate::apiESPFirmwarePart(const String& reqStr, File
307307
return fwUpdateAPIPart(fileStreamBlock);
308308
}
309309

310-
void ESPOTAUpdate::apiESPFirmwareUpdateDone(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
310+
RaftRetCode ESPOTAUpdate::apiESPFirmwareUpdateDone(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
311311
{
312312
// Handle with OTA update
313313
#ifdef DEBUG_ESP_OTA_UPDATE
314314
// Debug
315315
LOG_I(MODULE_PREFIX, "apiESPFirmwareDone");
316316
#endif
317317
fwUpdateAPIFinal();
318-
Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
318+
return Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
319319
}

components/ESPOTAUpdate/ESPOTAUpdate.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ESPOTAUpdate : public SysModBase
3131

3232
// Start/Data/Cancel methods
3333
virtual bool fileStreamStart(const char* fileName, size_t fileLen) override final;
34-
virtual RaftRetCode::RetCode fileStreamDataBlock(FileStreamBlock& fileStreamBlock) override final;
34+
virtual RaftRetCode fileStreamDataBlock(FileStreamBlock& fileStreamBlock) override final;
3535
virtual bool fileStreamCancelEnd(bool isNormalEnd) override final;
3636

3737
// Get debug string
@@ -74,11 +74,11 @@ class ESPOTAUpdate : public SysModBase
7474
void onDataReceived(uint8_t *pDataReceived, size_t dataReceivedLen);
7575

7676
// API ESP Firmware update
77-
RaftRetCode::RetCode apiESPFirmwarePart(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo);
78-
void apiESPFirmwareUpdateDone(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
77+
RaftRetCode apiESPFirmwarePart(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo);
78+
RaftRetCode apiESPFirmwareUpdateDone(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
7979

8080
// Direct firmware update
81-
virtual RaftRetCode::RetCode fwUpdateAPIPart(FileStreamBlock& fileStreamBlock);
81+
virtual RaftRetCode fwUpdateAPIPart(FileStreamBlock& fileStreamBlock);
8282
void fwUpdateAPIFinal();
8383
bool firmwareUpdateEnd();
8484
};

components/FileManager/FileManager.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void FileManager::addRestAPIEndpoints(RestAPIEndpointManager& endpointManager)
115115
// Format file system
116116
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117117

118-
void FileManager::apiReformatFS(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
118+
RaftRetCode FileManager::apiReformatFS(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
119119
{
120120
// File system
121121
String fileSystemStr = RestAPIEndpointManager::getNthArgStr(reqStr.c_str(), 1);
@@ -128,6 +128,7 @@ void FileManager::apiReformatFS(const String &reqStr, String& respStr, const API
128128
if (pSysMan)
129129
pSysMan->systemRestart();
130130
}
131+
return RaftRetCode::RAFT_RET_OK;
131132
}
132133

133134
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -136,7 +137,7 @@ void FileManager::apiReformatFS(const String &reqStr, String& respStr, const API
136137
// The second part of the path is the folder - note that / must be replaced with ~ in folder
137138
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
138139

139-
void FileManager::apiFileList(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
140+
RaftRetCode FileManager::apiFileList(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
140141
{
141142
// File system
142143
String fileSystemStr = RestAPIEndpointManager::getNthArgStr(reqStr.c_str(), 1);
@@ -158,6 +159,7 @@ void FileManager::apiFileList(const String &reqStr, String& respStr, const APISo
158159
#ifdef DEBUG_FILE_MANAGER_FILE_LIST_DETAIL
159160
LOG_W(MODULE_PREFIX, "apiFileList respStr %s", respStr.c_str());
160161
#endif
162+
return RaftRetCode::RAFT_RET_OK;
161163
}
162164

163165
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -166,7 +168,7 @@ void FileManager::apiFileList(const String &reqStr, String& respStr, const APISo
166168
// The second part of the path is the folder and filename - note that / must be replaced with ~ in folder
167169
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
168170

169-
void FileManager::apiFileRead(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
171+
RaftRetCode FileManager::apiFileRead(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
170172
{
171173
// File system
172174
String fileSystemStr = RestAPIEndpointManager::getNthArgStr(reqStr.c_str(), 1);
@@ -180,10 +182,11 @@ void FileManager::apiFileRead(const String &reqStr, String& respStr, const APISo
180182
if (!pFileContents)
181183
{
182184
respStr = "";
183-
return;
185+
return RaftRetCode::RAFT_RET_CANNOT_START;
184186
}
185187
respStr = pFileContents;
186188
free(pFileContents);
189+
return RaftRetCode::RAFT_RET_OK;
187190
}
188191

189192
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -192,7 +195,7 @@ void FileManager::apiFileRead(const String &reqStr, String& respStr, const APISo
192195
// The second part of the path is the filename - note that / must be replaced with ~ in filename
193196
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194197

195-
void FileManager::apiDeleteFile(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
198+
RaftRetCode FileManager::apiDeleteFile(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo)
196199
{
197200
// File system
198201
String fileSystemStr = RestAPIEndpointManager::getNthArgStr(reqStr.c_str(), 1);
@@ -205,34 +208,34 @@ void FileManager::apiDeleteFile(const String &reqStr, String& respStr, const API
205208
filenameStr.replace("~", "/");
206209
if (filenameStr.length() != 0)
207210
rslt = fileSystem.deleteFile(fileSystemStr, filenameStr);
208-
Raft::setJsonBoolResult(reqStr.c_str(), respStr, rslt);
209211
LOG_I(MODULE_PREFIX, "deleteFile reqStr %s fs %s, filename %s rslt %s",
210212
reqStr.c_str(), fileSystemStr.c_str(), filenameStr.c_str(),
211213
rslt ? "ok" : "fail");
214+
return Raft::setJsonBoolResult(reqStr.c_str(), respStr, rslt);
212215
}
213216

214217
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
215218
// Upload file to file system - completed
216219
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
217220

218-
void FileManager::apiUploadFileComplete(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
221+
RaftRetCode FileManager::apiUploadFileComplete(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo)
219222
{
220223
#ifdef DEBUG_FILE_MANAGER_UPLOAD
221224
LOG_I(MODULE_PREFIX, "uploadFileComplete %s", reqStr.c_str());
222225
#endif
223-
Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
226+
return Raft::setJsonBoolResult(reqStr.c_str(), respStr, true);
224227
}
225228

226229
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
227230
// Upload file to file system - part of file
228231
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
229232

230-
RaftRetCode::RetCode FileManager::apiUploadFileBlock(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo)
233+
RaftRetCode FileManager::apiUploadFileBlock(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo)
231234
{
232235
if (_pProtocolExchange)
233236
return _pProtocolExchange->handleFileUploadBlock(req, fileStreamBlock, sourceInfo,
234237
FileStreamBase::FILE_STREAM_CONTENT_TYPE_FILE, "");
235-
return RaftRetCode::INVALID_OPERATION;
238+
return RaftRetCode::RAFT_RET_INVALID_OPERATION;
236239
}
237240

238241
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////

components/FileManager/FileManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,27 @@ class FileManager : public SysModBase
5757
void applySetup();
5858

5959
// Format file system
60-
void apiReformatFS(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
60+
RaftRetCode apiReformatFS(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
6161

6262
// List files on a file system
6363
// In the reqStr the first part of the path is the file system name (e.g. sd or local, can be blank to default)
6464
// The second part of the path is the folder - note that / must be replaced with ~ in folder
65-
void apiFileList(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
65+
RaftRetCode apiFileList(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
6666

6767
// Read file contents
6868
// In the reqStr the first part of the path is the file system name (e.g. sd or local)
6969
// The second part of the path is the folder and filename - note that / must be replaced with ~ in folder
70-
void apiFileRead(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
70+
RaftRetCode apiFileRead(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
7171

7272
// Delete file on the file system
7373
// In the reqStr the first part of the path is the file system name (e.g. sd or local)
7474
// The second part of the path is the filename - note that / must be replaced with ~ in filename
75-
void apiDeleteFile(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
75+
RaftRetCode apiDeleteFile(const String &reqStr, String& respStr, const APISourceInfo& sourceInfo);
7676

7777
// API upload file to file system - completed
78-
void apiUploadFileComplete(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
78+
RaftRetCode apiUploadFileComplete(const String &reqStr, String &respStr, const APISourceInfo& sourceInfo);
7979

8080
// Upload file to file system - part of file (from HTTP POST file)
81-
RaftRetCode::RetCode apiUploadFileBlock(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo);
81+
RaftRetCode apiUploadFileBlock(const String& req, FileStreamBlock& fileStreamBlock, const APISourceInfo& sourceInfo);
8282

8383
};

0 commit comments

Comments
 (0)