Skip to content

Commit

Permalink
[errormap] add error mapping functions
Browse files Browse the repository at this point in the history
  • Loading branch information
step0035 committed May 4, 2023
1 parent dbf2430 commit 1583800
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/platform/Ameba/AmebaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,51 @@ CHIP_ERROR AmebaUtils::SetCurrentProvisionedNetwork()
exit:
return err;
}

CHIP_ERROR MapError(int32_t error, AmebaErrorType type)
{
if (type == AmebaErrorType::kDctError)
{
return AmebaDctMapError(error);
}
if (type == AmebaErrorType::kFlashError)
{
return AmebaFlashMapError(error);
}
if (type == AmebaErrorType::kWiFiError)
{
return AmebaWiFiMapError(error);
}
}

CHIP_ERROR AmebaDctMapError(int32_t error)
{
if (error == DCT_SUCCESS)
return CHIP_NO_ERROR;
if (error == DCT_ERR_NO_MEMORY)
return CHIP_ERROR_NO_MEMORY;
if (error == DCT_ERR_NOT_FIND)
return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND;
if (error == DCT_ERR_SIZE_OVER)
return CHIP_ERROR_INVALID_ARGUMENT;
if (error == DCT_ERR_MODULE_BUSY)
return CHIP_ERROR_BUSY;

return CHIP_ERROR_INTERNAL;
}

CHIP_ERROR AmebaFlashMapError(int32_t error)
{
if (error == 1)
return CHIP_NO_ERROR;

return CHIP_ERROR_INTERNAL;
}

CHIP_ERROR AmebaWiFiMapError(int32_t error)
{
if (error == RTW_SUCCESS)
return CHIP_NO_ERROR;

return CHIP_ERROR_INTERNAL;
}
15 changes: 15 additions & 0 deletions src/platform/Ameba/AmebaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ namespace chip {
namespace DeviceLayer {
namespace Internal {

enum class AmebaErrorType
{
kDctError,
kFlashError,
kWiFiError,
};

class AmebaUtils
{
public:
Expand All @@ -39,6 +46,14 @@ class AmebaUtils
static CHIP_ERROR WiFiConnectProvisionedNetwork(void);
static CHIP_ERROR WiFiConnect(const char * ssid, const char * password);
static CHIP_ERROR SetCurrentProvisionedNetwork(void);
static CHIP_ERROR WiFiConnect(void);

static CHIP_ERROR MapError(int32_t error, AmebaErrorType type);

private:
static CHIP_ERROR AmebaDctMapError(int32_t error);
static CHIP_ERROR AmebaFlashMapError(int32_t error);
static CHIP_ERROR AmebaWiFiMapError(int32_t error);
};

} // namespace Internal
Expand Down

0 comments on commit 1583800

Please sign in to comment.