Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Trigger Distribution
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Trigger Distribution
Commits
d4ed5a47
Commit
d4ed5a47
authored
Sep 17, 2022
by
Dimitris Lampridis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw: update and document WRTD_ERR_MSG_BUF_SIZE
Closes
#7
.
parent
e3bc4d5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
29 deletions
+63
-29
usage_clib.rst
doc/usage_clib.rst
+34
-0
libwrtd.c
software/lib/libwrtd.c
+26
-26
libwrtd.h
software/lib/libwrtd.h
+3
-3
No files found.
doc/usage_clib.rst
View file @
d4ed5a47
...
...
@@ -92,6 +92,40 @@ Functions
examples. However, in a real application, users should always check the status code of every call
to a WRTD function, like in :numref:`lst-get_error`.
.. hint::
If you want to be sure that the buffer that you pass to :cpp:func:`wrtd_get_error`
is large enough, without having to resort to querying like in :numref:`lst-get_error`, you can
always allocate a buffer of :c:macro:`WRTD_ERR_MSG_BUF_SIZE`. WRTD guarantees that all error
messages shall not exceed this size.
.. doxygendefine:: WRTD_ERR_MSG_BUF_SIZE
.. code-block:: c
:caption: Retrieving the error message with a pre-defined buffer size
#include <libwrtd.h>
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char err_msg[WRTD_ERR_MSG_BUF_SIZE];
status = wrtd_init(1, false, NULL, &wrtd);
status = wrtd_get_attr_bool(wrtd, WRTD_GLOBAL_REP_CAP_ID,
WRTD_ATTR_EVENT_LOG_EMPTY);
if (status != WRTD_SUCCESS) {
/* retrieve the error code and message */
wrtd_get_error(wrtd, &err_code, WRTD_ERR_MSG_BUF_SIZE, err_msg)
printf("ERROR: %d, %s\n", err_code, err_msg);
return status;
}
wrtd_close(wrtd);
return 0;
}
.. _api_init:
Initialisation API
...
...
software/lib/libwrtd.c
View file @
d4ed5a47
...
...
@@ -260,8 +260,8 @@ wrtd_status wrtd_get_error(wrtd_dev *wrtd,
return
WRTD_ERROR_NOT_INITIALIZED
;
}
char
error_message
[
WRTD_ERR_MSG_BUF_S
Z
];
memset
(
error_message
,
0
,
WRTD_ERR_MSG_BUF_S
Z
);
char
error_message
[
WRTD_ERR_MSG_BUF_S
IZE
];
memset
(
error_message
,
0
,
WRTD_ERR_MSG_BUF_S
IZE
);
status
=
wrtd_error_message
(
wrtd
,
wrtd
->
err
,
error_message
);
WRTD_RETURN_IF_ERROR
(
status
);
...
...
@@ -316,7 +316,7 @@ wrtd_status wrtd_get_error(wrtd_dev *wrtd,
* @param[in] wrtd Device token. Can be NULL to allow calling this function
* even when initialisation has failed.
* @param[in] err_code #wrtd_status error code to convert.
* @param[out] err_message Buffer of
size defined as WRTD_ERR_MSG_BUF_SZ
* @param[out] err_message Buffer of
at least #WRTD_ERR_MSG_BUF_SIZE bytes
* to store the resulting string.
* @return #wrtd_status
*/
...
...
@@ -337,91 +337,91 @@ wrtd_status wrtd_error_message(wrtd_dev *wrtd,
switch
(
err_code
){
case
WRTD_SUCCESS
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
"WRTD_SUCCESS"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_SUCCESS"
);
break
;
case
WRTD_ERROR_INVALID_ATTRIBUTE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_INVALID_ATTRIBUTE"
);
break
;
case
WRTD_ERROR_ATTR_NOT_WRITEABLE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_ATTR_NOT_WRITEABLE"
);
break
;
case
WRTD_ERROR_ATTR_NOT_READABLE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_ATTR_NOT_READABLE"
);
break
;
case
WRTD_ERROR_INVALID_VALUE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_INVALID_VALUE"
);
break
;
case
WRTD_ERROR_NOT_INITIALIZED
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_NOT_INITIALIZED"
);
break
;
case
WRTD_ERROR_UNKNOWN_CHANNEL_NAME
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_UNKNOWN_CHANNEL_NAME"
);
break
;
case
WRTD_ERROR_OUT_OF_MEMORY
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_OUT_OF_MEMORY"
);
break
;
case
WRTD_ERROR_NULL_POINTER
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_NULL_POINTER"
);
break
;
case
WRTD_ERROR_UNEXPECTED_RESPONSE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_UNEXPECTED_RESPONSE"
);
break
;
case
WRTD_ERROR_RESOURCE_UNKNOWN
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_RESOURCE_UNKNOWN"
);
break
;
case
WRTD_ERROR_BADLY_FORMED_SELECTOR
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_BADLY_FORMED_SELECTOR"
);
break
;
case
WRTD_ERROR_ALARM_EXISTS
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_ALARM_EXISTS"
);
break
;
case
WRTD_ERROR_ALARM_DOES_NOT_EXIST
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_ALARM_DOES_NOT_EXIST"
);
break
;
case
WRTD_ERROR_VERSION_MISMATCH
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_VERSION_MISMATCH"
);
break
;
case
WRTD_ERROR_INTERNAL
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_INTERNAL"
);
break
;
case
WRTD_ERROR_UNKNOWN_LOG_TYPE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_UNKNOWN_LOG_TYPE"
);
break
;
case
WRTD_ERROR_RESOURCE_ACTIVE
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_RESOURCE_ACTIVE"
);
break
;
case
WRTD_ERROR_ATTR_GLOBAL
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_ATTR_GLOBAL"
);
break
;
case
WRTD_ERROR_OUT_OF_RESOURCES
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_OUT_OF_RESOURCES"
);
break
;
case
WRTD_ERROR_RULE_EXISTS
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_RULE_EXISTS"
);
break
;
case
WRTD_ERROR_RULE_DOES_NOT_EXIST
:
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
Z
,
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_S
IZE
,
"WRTD_ERROR_RULE_DOES_NOT_EXIST"
);
break
;
...
...
@@ -883,7 +883,7 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
wrtd_tstamp
*
value
)
{
wrtd_status
status
;
while
(
value
->
ns
>
((
1e9
)
-
1
))
{
value
->
seconds
++
;
value
->
ns
-=
1e9
;
...
...
software/lib/libwrtd.h
View file @
d4ed5a47
...
...
@@ -20,9 +20,6 @@ extern "C" {
// NOTE: corresponds roughly to IVI ViSession
typedef
struct
wrtd_dev
wrtd_dev
;
/*Size of buffer of at least 256 bytes to store the resulting error as string*/
#define WRTD_ERR_MSG_BUF_SZ 256
/**
* @enum wrtd_status
* White Rabbit Trigger Distribution error codes.
...
...
@@ -239,6 +236,9 @@ typedef enum wrtd_attr {
/** Size (in characters, including null termination) of an event log enty. */
#define WRTD_LOG_ENTRY_SIZE 120
/** Size (in characters, including null termination) of minimum error message bugger. */
#define WRTD_ERR_MSG_BUF_SIZE 256
/* ------------------------------------------------------------------- */
/* Function prototypes for the official WRTD API. Documented in wrtd.c */
/* ------------------------------------------------------------------- */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment