Virgil IoT KIT
Macros | Enumerations
status_code.h File Reference

Status codes and macroses. More...

#include <virgil/iot/macros/macros.h>

Go to the source code of this file.

Macros

#define STATUS_CHECK(OPERATION, MESSAGE, ...)   CHECK(VS_CODE_OK == (OPERATION), (MESSAGE), ##__VA_ARGS__)
 Status code check and perform goto terminate if non-successful. More...
 
#define STATUS_CHECK_RET(OPERATION, MESSAGE, ...)   CHECK_RET(VS_CODE_OK == (ret_code = (OPERATION)), ret_code, (MESSAGE), ##__VA_ARGS__)
 Status code check and return vs_status_e if non-successful. More...
 
#define STATUS_CHECK_RET_BOOL(OPERATION, MESSAGE, ...)   BOOL_CHECK_RET(VS_CODE_OK == (OPERATION), (MESSAGE), ##__VA_ARGS__)
 Status code check and return bool if non-successful. More...
 

Enumerations

enum  vs_status_e {
  VS_CODE_COMMAND_NO_RESPONSE = 100, VS_CODE_OLD_VERSION = 1, VS_CODE_OK = 0, VS_CODE_ERR_NULLPTR_ARGUMENT = -1,
  VS_CODE_ERR_ZERO_ARGUMENT = -2, VS_CODE_ERR_INCORRECT_ARGUMENT = -3, VS_CODE_ERR_INCORRECT_PARAMETER = -4, VS_CODE_ERR_UNSUPPORTED_PARAMETER = -5,
  VS_CODE_ERR_AMBIGUOUS_INIT_CALL = -6, VS_CODE_ERR_CTX_NOT_READY = -7, VS_CODE_ERR_NOT_IMPLEMENTED = -8, VS_CODE_ERR_NOT_FOUND = -9,
  VS_CODE_ERR_NO_CALLBACK = -10, VS_CODE_ERR_UNREGISTERED_MAPPING_TYPE = -11, VS_CODE_ERR_INCORRECT_SEND_REQUEST = -12, VS_CODE_ERR_NO_MEMORY = -20,
  VS_CODE_ERR_TOO_SMALL_BUFFER = -21, VS_CODE_ERR_FORMAT_OVERFLOW = -22, VS_CODE_ERR_VERIFY = -30, VS_CODE_ERR_UNSUPPORTED = -31,
  VS_CODE_ERR_CRYPTO = -32, VS_CODE_ERR_FILE = -40, VS_CODE_ERR_FILE_READ = -41, VS_CODE_ERR_FILE_WRITE = -42,
  VS_CODE_ERR_FILE_DELETE = -43, VS_CODE_ERR_CLOUD = -50, VS_CODE_ERR_JSON = -51, VS_CODE_ERR_REQUEST_PREPARE = -52,
  VS_CODE_ERR_REQUEST_SEND = -53, VS_CODE_ERR_PRVS_UNKNOWN = -60, VS_CODE_ERR_SNAP_UNKNOWN = -70, VS_CODE_ERR_SNAP_NOT_MY_PACKET = -71,
  VS_CODE_ERR_SNAP_TOO_MUCH_SERVICES = -72, VS_CODE_ERR_THREAD = -80, VS_CODE_ERR_NO_SIMULATOR = -81, VS_CODE_ERR_SOCKET = -82,
  VS_CODE_ERR_PLC = -83, VS_CODE_ERR_NOINIT = -84, VS_CODE_ERR_INIT_SNAP = -90, VS_CODE_ERR_DEINIT_SNAP = -91,
  VS_CODE_ERR_TX_SNAP = -92, VS_CODE_ERR_MAC_SNAP = -93, VS_CODE_ERR_POLLING_INFO_CLIENT = -94, VS_CODE_ERR_USER = -128
}
 Status code. More...
 

Detailed Description

Status codes and macroses.

This file declares vs_status_e status codes. There are also macros to simplify return code checks :

vs_netif_t *netif;
const vs_mac_addr_t *mac;
vs_snap_prvs_devi_t *device_info;
uint16_t buf_sz;
uint32_t wait_ms;
// Goto terminate in case of error
STATUS_CHECK(vs_fldt_client_request_all_files(), "Unable to request all files");
// Return function in case of error
"Unable to receive device information during %d milliseconds", wait_ms);
// Error processing
terminate:

You can introduce your own error codes. They must start from VS_CODE_ERR_USER code.

Macro Definition Documentation

◆ STATUS_CHECK

#define STATUS_CHECK (   OPERATION,
  MESSAGE,
  ... 
)    CHECK(VS_CODE_OK == (OPERATION), (MESSAGE), ##__VA_ARGS__)

Status code check and perform goto terminate if non-successful.

  1. OPERATION is compared with VS_CODE_OK.
  2. If they are not equal, MESSAGES is logged and function jumps to terminate label.
Warning
terminate label must be present in current function.
Parameters
[in]OPERATIONOperation to be checked.
[in]MESSAGEString with printf-like parameter to be logged in case of non-successful operation.

◆ STATUS_CHECK_RET

#define STATUS_CHECK_RET (   OPERATION,
  MESSAGE,
  ... 
)    CHECK_RET(VS_CODE_OK == (ret_code = (OPERATION)), ret_code, (MESSAGE), ##__VA_ARGS__)

Status code check and return vs_status_e if non-successful.

  1. OPERATION result code is saved to the vs_status_e ret_code variable.
  2. if ret_code is not equal to VS_CODE_OK, MESSAGES is logged and function returns ret_code.
Warning
vs_status_e ret_code must be initialized.
Parameters
[in]OPERATIONOperation to be checked.
[in]MESSAGEString with printf-like parameter to be logged in case of non-successful operation.
Returns
OPERATION's vs_status_e ret_code in case of non-successful result.

◆ STATUS_CHECK_RET_BOOL

#define STATUS_CHECK_RET_BOOL (   OPERATION,
  MESSAGE,
  ... 
)    BOOL_CHECK_RET(VS_CODE_OK == (OPERATION), (MESSAGE), ##__VA_ARGS__)

Status code check and return bool if non-successful.

  1. OPERATION is compared with VS_CODE_OK.
  2. If they are not equal, MESSAGES is logged and function returns false.
Parameters
[in]OPERATIONOperation to be checked.
[in]MESSAGEString with printf-like parameter to be logged in case of non-successful operation.
Returns
false in case of non-successful result.

Enumeration Type Documentation

◆ vs_status_e

Status code.

Zero value VS_CODE_OK is used for non-error values. Negative values mean error

Enumerator
VS_CODE_COMMAND_NO_RESPONSE 

No need in response.

VS_CODE_OLD_VERSION 

Provided file is not newer than the current file.

VS_CODE_OK 

Successful operation.

VS_CODE_ERR_NULLPTR_ARGUMENT 

Argument is NULL pointer while it must be not NULL.

VS_CODE_ERR_ZERO_ARGUMENT 

Argument is zero while it must be not zero.

VS_CODE_ERR_INCORRECT_ARGUMENT 

Incorrect argument.

VS_CODE_ERR_INCORRECT_PARAMETER 

Incorrect parameter.

VS_CODE_ERR_UNSUPPORTED_PARAMETER 

Unsupported parameter.

VS_CODE_ERR_AMBIGUOUS_INIT_CALL 

Ambiguous initialization call.

VS_CODE_ERR_CTX_NOT_READY 

Context is not ready.

VS_CODE_ERR_NOT_IMPLEMENTED 

This feature is not implemented.

VS_CODE_ERR_NOT_FOUND 

Entity has not been found.

VS_CODE_ERR_NO_CALLBACK 

There is no callback.

VS_CODE_ERR_UNREGISTERED_MAPPING_TYPE 

Unsupported mapping type.

VS_CODE_ERR_INCORRECT_SEND_REQUEST 

Incorrect send request.

VS_CODE_ERR_NO_MEMORY 

No memory.

VS_CODE_ERR_TOO_SMALL_BUFFER 

Buffer is too small.

VS_CODE_ERR_FORMAT_OVERFLOW 

Incorrect data format.

VS_CODE_ERR_VERIFY 

Incorrect result of verification.

VS_CODE_ERR_UNSUPPORTED 

Unsupported crypto data.

VS_CODE_ERR_CRYPTO 

Error during crypto operation processing.

VS_CODE_ERR_FILE 

Error during file processing.

VS_CODE_ERR_FILE_READ 

Error during file read.

VS_CODE_ERR_FILE_WRITE 

Error during file write.

VS_CODE_ERR_FILE_DELETE 

Error during file delete.

VS_CODE_ERR_CLOUD 

Error during operation with cloud.

VS_CODE_ERR_JSON 

Error during JSON processing.

VS_CODE_ERR_REQUEST_PREPARE 

Error during request preparation.

VS_CODE_ERR_REQUEST_SEND 

Error during request send.

VS_CODE_ERR_PRVS_UNKNOWN 

Provision error.

VS_CODE_ERR_SNAP_UNKNOWN 

SNAP error.

VS_CODE_ERR_SNAP_NOT_MY_PACKET 

SNAP error "not my packet".

VS_CODE_ERR_SNAP_TOO_MUCH_SERVICES 

Too much services to be registered by SNAP.

VS_CODE_ERR_THREAD 

Error during thread processing.

VS_CODE_ERR_NO_SIMULATOR 

No simulator has been found.

VS_CODE_ERR_SOCKET 

Error during socket operations.

VS_CODE_ERR_PLC 

PLC error.

VS_CODE_ERR_NOINIT 

Not initialized.

VS_CODE_ERR_INIT_SNAP 

Error while vs_netif_t .

init call

VS_CODE_ERR_DEINIT_SNAP 

Error while vs_netif_t .

deinit call

VS_CODE_ERR_TX_SNAP 

Error while vs_netif_t .

tx call

VS_CODE_ERR_MAC_SNAP 

Error while vs_netif_t .

mac call

VS_CODE_ERR_POLLING_INFO_CLIENT 

Error while starting polling.

VS_CODE_ERR_USER 

User specific error codes start with this value.

vs_mac_addr_t
MAC address.
Definition: snap-structs.h:252
STATUS_CHECK
#define STATUS_CHECK(OPERATION, MESSAGE,...)
Status code check and perform goto terminate if non-successful.
Definition: status_code.h:145
vs_snap_prvs_device_info
vs_status_e vs_snap_prvs_device_info(const vs_netif_t *netif, const vs_mac_addr_t *mac, vs_snap_prvs_devi_t *device_info, uint16_t buf_sz, uint32_t wait_ms)
Request device information.
vs_snap_prvs_devi_t
Device information.
Definition: prvs-structs.h:83
STATUS_CHECK_RET
#define STATUS_CHECK_RET(OPERATION, MESSAGE,...)
Status code check and return vs_status_e if non-successful.
Definition: status_code.h:159
vs_netif_t
Network interface.
Definition: snap-structs.h:293
VS_CODE_ERR_INCORRECT_ARGUMENT
@ VS_CODE_ERR_INCORRECT_ARGUMENT
Incorrect argument.
Definition: status_code.h:83
vs_fldt_client_request_all_files
vs_status_e vs_fldt_client_request_all_files(void)
Request all files data.