<< 点击显示目录 >> 主页 exOS使用助手 > exOS Automation Help > Development > Programming > exOS Communication API reference (exos_api.h) > EXOS_ERROR_CODE: Error Codes |
类型化枚举
{
exos_error_ok = 0、
exos_error_not_implemented = 5000、
exos_error_parameter_null、
exos_error_bad_datamodel_handle、
exos_error_bad_dataset_handle、
exos_error_bad_log_handle、
exos_error_bad_sync_handle、
exos_error_not_allowed、
exos_error_not_found、
exos_error_string_format、
exos_error_string_format, exos_error_message_format、
exos_error_no_data、
exos_error_buffer_overflow、
exos_error_timeout、
exos_error_bad_dataset_size、
exos_error_user、
exos_error_system、
exos_error_system_socket、
exos_error_system_socket_usage、
exos_error_system_malloc、
exos_error_system_lxi、
exos_error_not_ready、
exos_error_server_shutdown、
exos_error_bad_state
}exos_error_code;
•EXOS_ERROR_OK:
一切正常。成功
•5000: exos_error_not_implemented:
函数未执行。出现在 exos_datamodel_connect(), 因为应使用代码指定的特定函数。
•5001: exos_error_parameter_null:
本应大于 0/NULL 的参数/指针为 NULL 或 0。
•5002: exos_error_bad_datamodel_handle:
无效的 exos_datamodel_handle_t。大多数情况下,这是因为函数需要指向数据模型的指针,而 & 被遗忘了。
•5003: exos_error_bad_dataset_handle:
无效的 exos_dataset_handle_t。大多数情况下,这是因为函数需要指向数据集的指针,而 & 被遗忘了。
•5004: exos_error_bad_log_handle:
无效的 exos_log_handle_t。大多数情况下,这是因为函数需要指向日志句柄的指针,而 & 被遗忘了。
•5005: exos_error_bad_sync_handle:
数据集消息路由器出现内部错误 。如果出现这种情况,请联系我们。
•5006: exos_error_not_allowed:
"这是不可能的" - 发生在 exos_datamodel_init()、 exos_datamodel_connect()、 exos_dataset_init()、exos_dataset_connect() 中 , 如果它们没有按正确的顺序调用,或初始化了两次,或 发生 在exos_dataset_publish()中 , 如果数据集没有连接为 EXOS_DATASET_PUBLISH。
•5007: exos_error_not_found:
出现此错误的最可能情况是在 exos_dataset_connect() 函数中,API 会检查 browse_name (在 exos_dataset_init() 中给出 ) 是否 存在于数据模型中。如果在数据模型中找不到数据集,函数就会返回此错误。
在数据集出现 EXOS_STATE_ABORTED( 数据集消息路由器 回复)的情况下,也会出现 该错误 , 即数据集在另一端不存在。如果在 AR-Linux 连接的一侧编译了新的数据模型,而该数据模型使用的数据集不是另一侧系统的一部分,就会出现这种问题。exOS 提供了许多功能来避免这种情况,如果按照正常的方法创建 exOS 软件包,就不会出现这种情况。
•5008: exos_error_string_format:
该错误最有可能发生在 exos_dataset_connect() 函数中,在该函数中,API 会检查数据 模型 中 是否 存在 browse_name (在 exos_dataset_init() 中给出 )。如果 找到了 browse_name, 但数组 格式 不正确,如 Config[[1],则会出现字符串格式错误。
该错误也可能发生在 使用代码生成的配置字符串的exos_datamodel_connect_() 函数中 。 这种情况不太可能发生,除非以某种方式手动修改了代码。
•5009: exos_error_message_format:
内部信息协议无效时发生的内部错误。如果出现这种情况,请联系我们。
•5010: exos_error_no_data:
数据集信息路由器中的内部错误 。请联系我们。
•5011: exos_error_buffer_overflow:
数据集消息路由器 向 EXOS_STATE_ABORTED 发送数据集时 出错 。如果 调用 exos_dataset_publish()的 次数多于当前传输机制(TCP/IP、共享内存)所能处理 的次数,就会出现这种 情况 。请参阅 本章的 EXOS_DATASET_EVENT_TYPE 部分 或 预定义缓冲区中的 更多内容 ,以了解 应用程序中是否会出现此问题。
•5012: exos_error_timeout:
如果通信双方中的一方没有响应,就会触发内部错误。该错误不会转发给应用程序,但 如果通信方少于两个,则会触发 EXOS_STATE_DISCONNECTED。
•5013: EXOS_error_bad_dataset_size:
数据集消息路由器 在执行 exos_dataset_connect() 后立即 向 EXOS_STATE_ABORTED 发送数据集而 产生的错误 。如果 提供给 exos_dataset_init()的数据集大小 与给定数据集的实际大小不符,就会发生这种 情况 。
如果数据集大小大于 EXOS_API_MAX_DATASET_SIZE,exos_dataset_init()也会返回这个错误 。在这种情况下,数据集句柄没有被初始化,连续的 exos_dataset_connect() 将返回 EXOS_ERROR_BAD_DATASET_HANDLE。
•5014: exos_error_user:
当前未使用。
•5015: exos_error_system:
如果exostarget 配置或生成的 exos-api.conf中 存在错误,则 数据集消息路由器会出现内部 错误 。如果出现这种情况,请联系我们。
•5016: exos_error_system_socket:
绑定/连接/创建 zmq 通信套接字时出现的错误。如果出现这种情况,请联系我们。
•5017: exos_error_system_socket_usage:
在套接字上发送数据时出现运行错误。
•5018: exos_error_system_malloc:
分配内存时出错。可能是因为系统中的 RAM 内存不足。
•5019: exos_error_system_lxi:
如果 AR-Linux 连接出现问题,且无法通过正常的 EXOS_STATE_DISCONNECTED 处理 ,则数据集消息路由器出现内部错误 。
lxi 函数可能返回以下错误代码之一:
类型
{
LXI_ERR_OK, ///< 操作成功。
lxi_err_unknown_schema、
lxi_err_parse_schema、
LXI_ERR_not_supported、
lxi_err_invalid_op、
lxi_err_eth_process、
lxi_err_eth_socket、
lxi_err_send_busy、
lxi_err_no_mem、
LXI_ERR_SYS、
LXI_ERR_ARG、
LXI_ERR_NO_CONTENT、
lxi_err_disconnect、
LXI_ERR_MISSING、
LXI_ERR_RTH、
LXI_ERR_FULL、
LXI_ERR_EMPTY
} lxi_err_t;
•5020: exos_error_not_ready:
如果 数据集消息路由器 未启动和运行,并且使用 exos_datamodel_connect() 尝试 连接,则在 AR 系统上发生错误 。
•5021: exos_error_server_shutdown:
来自 数据集消息路由器的错误 , 该路由器正在将数据模型发送到 EXOS_STATE_ABORTED。该错误在 数据集消息路由器关闭时发生 ,例如在 更新exostarget 配置 时 。
•5022: exos_error_bad_state:
当数据模型处于 EXOS_STATE_DISCONNECTED 或 EXOS_STATE_ABORTED状态时,在 exos_dataset_publish() 和 exos_datamodel_set_operational()中发生的错误 。
所有 exos-api 函数都会返回 EXOS_ERROR_CODE。 如果编程正确,所有函数都应返回 EXOS_ERROR_OK。
出于同样的原因,在生成的模板中,函数调用通常都用 EXOS_ASSERT_OK包围 ,因为它们都应返回 EXOS_ERROR_OK。 EXOS_ASSERT_OK 宏基本上只用红色打印出错误发生的位置和函数返回的数据集。例如
文件 ./././exOS-Project/datamodel/examples/watertank.c 第 141 行中的错误
exos_dataset_connect_subscription(&vars->enable,datasetConnectionChanged,datasetChanged)
返回 5007(找不到资源(数据模型/数据集),已删除或未初始化)
而不是预期的 0
现在,如果想将错误输出截获到应用程序控制台以外的其他地方,就需要定义日志句柄,用于将错误信息转发到日志服务器。有关日志句柄和日志系统的更多信息,请参阅 exos_log.h API 参考资料
//定义用于记录 ASSERT 消息的日志句柄
#define EXOS_ASSERT_LOG &logger
#include "exos_log.h"。
...
exos_log_handle_t logger;
int main(void)
{
exos_log_init(&logger, "MyApplication");
EXOS_ASSERT_OK(exos_datamodel_init....
如果您需要以某种方式捕捉应用程序无法继续的错误,您可以指定一个 assert 回调,使 EXOS_ASSERT 调用您的函数。
//定义一个用户特定的断言函数--"err "变量保存当前错误编号
#define EXOS_ASSERT_CALLBACK print_and_die(err)
#include "exos_log.h"
void print_and_die(EXOS_ERROR_CODE err)
{
exos_log_stdout("\n\n error!! %d \n\n", err);
assert(0); //boom!
}
..
如果 数据集消息路由器 返回错误,相应的数据模型/数据集将进入 connection_state = EXOS_STATE_ABORTED ,错误代码可以 通过 error 成员 从 exos_datamodel_handle_t 和 exos_dataset_handle_t 结构 中读出 。
typedef enum
{
EXOS_ERROR_OK = 0,
EXOS_ERROR_NOT_IMPLEMENTED = 5000,
EXOS_ERROR_PARAMETER_NULL,
EXOS_ERROR_BAD_DATAMODEL_HANDLE,
EXOS_ERROR_BAD_DATASET_HANDLE,
EXOS_ERROR_BAD_LOG_HANDLE,
EXOS_ERROR_BAD_SYNC_HANDLE,
EXOS_ERROR_NOT_ALLOWED,
EXOS_ERROR_NOT_FOUND,
EXOS_ERROR_STRING_FORMAT,
EXOS_ERROR_MESSAGE_FORMAT,
EXOS_ERROR_NO_DATA,
EXOS_ERROR_BUFFER_OVERFLOW,
EXOS_ERROR_TIMEOUT,
EXOS_ERROR_BAD_DATASET_SIZE,
EXOS_ERROR_USER,
EXOS_ERROR_SYSTEM,
EXOS_ERROR_SYSTEM_SOCKET,
EXOS_ERROR_SYSTEM_SOCKET_USAGE,
EXOS_ERROR_SYSTEM_MALLOC,
EXOS_ERROR_SYSTEM_LXI,
EXOS_ERROR_NOT_READY,
EXOS_ERROR_SERVER_SHUTDOWN,
EXOS_ERROR_BAD_STATE
} EXOS_ERROR_CODE;
•EXOS_ERROR_OK:
Everything is OK. Success
•5000: EXOS_ERROR_NOT_IMPLEMENTED:
Function is not implemented. Occurs on exos_datamodel_connect() as the code genereated specific function should be used instead.
•5001: EXOS_ERROR_PARAMETER_NULL:
A parameter/pointer that should be greater than zero/NULL is NULL or zero.
•5002: EXOS_ERROR_BAD_DATAMODEL_HANDLE:
Invalid exos_datamodel_handle_t. Most of the time this is because the functions require a pointer to the datamodel, and the & was forgotten.
•5003: EXOS_ERROR_BAD_DATASET_HANDLE:
Invalid exos_dataset_handle_t. Most of the time this is because the functions require a pointer to the dataset, and the & was forgotten.
•5004: EXOS_ERROR_BAD_LOG_HANDLE:
Invalid exos_log_handle_t. Most of the time this is because the functions require a pointer to the log handle, and the & was forgotten.
•5005: EXOS_ERROR_BAD_SYNC_HANDLE:
Internal error in the Dataset Message Router. Please contact us if this occurs.
•5006: EXOS_ERROR_NOT_ALLOWED:
"This is not possible" - Happens in exos_datamodel_init(), exos_datamodel_connect(), exos_dataset_init(), exos_dataset_connect() if they are not called in the right order, or initialized twice, or in exos_dataset_publish() if the dataset was not connected as EXOS_DATASET_PUBLISH.
•5007: EXOS_ERROR_NOT_FOUND:
The most likely case when this error occurs is in the exos_dataset_connect() function, where the API checks if browse_name (given in the exos_dataset_init()) exists within the datamodel. The function returns this error in case the dataset cannot be found in the datamodel.
This error can also occur on a dataset in combination with going to EXOS_STATE_ABORTED, which is a Dataset Message Router reply, that the dataset does not exist on the opposite side. The problem can occur if a new datamodel is compiled on one side of the AR-Linux connection, and this uses a dataset which is not part of the other system. exOS offers a number of features to avoid this situation, and it should not occur if the normal practices of creating an exOS package are followed.
•5008: EXOS_ERROR_STRING_FORMAT:
The most likely case this error occurs is in the exos_dataset_connect() function, where the API checks if browse_name (given in the exos_dataset_init()) exists within the datamodel. In case the browse_name itself is found, but the array has a bad format, like Config[[1], the string format error occurs.
The error can also occur in the exos_datamodel_connect_() function, which uses the code-generated configuration string. This is rather unlikely to happen unless the code has somehow been altered manually.
•5009: EXOS_ERROR_MESSAGE_FORMAT:
Internal error which occurs if the internal message protocol is invalid. Please contact us if this occurs.
•5010: EXOS_ERROR_NO_DATA:
Internal error in the Dataset Message Router. Please contact us if this occurs.
•5011: EXOS_ERROR_BUFFER_OVERFLOW:
Error coming from the Dataset Message Router sending a dataset to EXOS_STATE_ABORTED. This occurs if there are more exos_dataset_publish() calls than the current transport mechanism (TCP/IP, shared memory) can handle. See more in the section EXOS_DATASET_EVENT_TYPE in this chapter or Predefined buffers if this problem occurs in the application.
•5012: EXOS_ERROR_TIMEOUT:
Internal error that is triggered if one of the communicating parties fail to respond. The error is not forwarded to the application, but triggers an EXOS_STATE_DISCONNECTED if less than two communicating parties remain.
•5013: EXOS_ERROR_BAD_DATASET_SIZE:
Error coming from the Dataset Message Router sending a dataset to EXOS_STATE_ABORTED immediately after an exos_dataset_connect(). This occurs if the size supplied to the exos_dataset_init() does not match the actual size of the given dataset.
This error can also be returned from exos_dataset_init() if the dataset size is larger than EXOS_API_MAX_DATASET_SIZE. In that case, the dataset handle is not initialized and a successive exos_dataset_connect() would return EXOS_ERROR_BAD_DATASET_HANDLE.
•5014: EXOS_ERROR_USER:
Currently not in use.
•5015: EXOS_ERROR_SYSTEM:
Internal error in the Dataset Message Router if there is an error in the exostarget configuration or the generated exos-api.conf. Please contact us if this occurs.
•5016: EXOS_ERROR_SYSTEM_SOCKET:
Error that occurs if there is a problem binding / connecting / creating the zmq communication sockets. Please contact us if this occurs.
•5017: EXOS_ERROR_SYSTEM_SOCKET_USAGE:
Runtime error sending data on a socket.
•5018: EXOS_ERROR_SYSTEM_MALLOC:
Error allocating memory. Probably because of insufficient RAM memory in the system.
•5019: EXOS_ERROR_SYSTEM_LXI:
Internal error in the Dataset Message Router if there is a problem with the AR-Linux connection that is not handled via a normal EXOS_STATE_DISCONNECTED.
The lxi functions may return one of the following error codes:
typedef enum
{
LXI_ERR_OK, ///< Operation successful.
LXI_ERR_UNKNOWN_SCHEMA,
LXI_ERR_PARSE_SCHEMA,
LXI_ERR_NOT_SUPPORTED,
LXI_ERR_INVALID_OP,
LXI_ERR_ETH_PROCESS,
LXI_ERR_ETH_SOCKET,
LXI_ERR_SEND_BUSY,
LXI_ERR_NO_MEM,
LXI_ERR_SYS,
LXI_ERR_ARG,
LXI_ERR_NO_CONTENT,
LXI_ERR_DISCONNECT,
LXI_ERR_MISSING,
LXI_ERR_RTH,
LXI_ERR_FULL,
LXI_ERR_EMPTY
} lxi_err_t;
•5020: EXOS_ERROR_NOT_READY:
Error occurring on AR systems if the Dataset Message Router is not up and running and a connection attempt is made using exos_datamodel_connect().
•5021: EXOS_ERROR_SERVER_SHUTDOWN:
Error coming from the Dataset Message Router that is sending a datamodel into EXOS_STATE_ABORTED. The error occurs when the Dataset Message Router is shut down, for example when the exostarget configuration is being updated.
•5022: EXOS_ERROR_BAD_STATE:
Error that occurs in exos_dataset_publish() and exos_datamodel_set_operational(), if the datamodel is in EXOS_STATE_DISCONNECTED or EXOS_STATE_ABORTED.
All exos-api functions return an EXOS_ERROR_CODE. All functions should return EXOS_ERROR_OK in case everything is programmed correctly.
For the same reason, function calls in the generated templates are usually surrounded with EXOS_ASSERT_OK, as they should alltoghether return EXOS_ERROR_OK. The EXOS_ASSERT_OK macro basically only prints in red where your error occured and which dataset the function returned. For example:
Error in file ../../exOS-Project/datamodel/examples/watertank.c line 141
exos_dataset_connect_subscription(&vars->enable,datasetConnectionChanged,datasetChanged)
returned 5007 (Ressource (datamodel/dataset) can not be found, its deleted or not initialized)
instead of expected 0
Now, If you want to have the error output captured somewhere else than the console of your application, you need to define the log handle that should be used to forward the error message to the log server. For more info on the log handle and the logging system, please see the exos_log.h API reference
//define the log handle that should be used for logging the ASSERT message
#define EXOS_ASSERT_LOG &logger
#include "exos_log.h"
...
exos_log_handle_t logger;
int main(void)
{
exos_log_init(&logger, "MyApplication");
EXOS_ASSERT_OK(exos_datamodel_init....
If you need to somehow catch this error that your application does not continue, you can specify an assert callback to make the EXOS_ASSERT call your function.
//define a user specific assert function - the "err" variable holds the current error number
#define EXOS_ASSERT_CALLBACK print_and_die(err)
#include "exos_log.h"
void print_and_die(EXOS_ERROR_CODE err)
{
exos_log_stdout("\n\n\n error!!! %d \n\n\n", err);
assert(0); //boom!
}
..
In case the Dataset Message Router returns with an error, the corresponding datamodel/dataset goes into connection_state = EXOS_STATE_ABORTED and the error code can be read out from the exos_datamodel_handle_t and exos_dataset_handle_t structures via the error member.