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
7e872170
Commit
7e872170
authored
Sep 17, 2022
by
Dimitris Lampridis
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fixes' into proposed_master
parents
2fd3ae9a
16200441
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
33 deletions
+104
-33
usage_clib.rst
doc/usage_clib.rst
+41
-2
libwrtd.c
software/lib/libwrtd.c
+59
-30
libwrtd.h
software/lib/libwrtd.h
+4
-1
No files found.
doc/usage_clib.rst
View file @
7e872170
...
...
@@ -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
...
...
@@ -257,7 +291,7 @@ Functions
/* get the delay configured for "rule1" */
status = wrtd_get_attr_tstamp(wrtd, "rule1",
WRTD_ATTR_RULE_DELAY, &ts
"
);
WRTD_ATTR_RULE_DELAY, &ts);
wrtd_close(wrtd);
}
...
...
@@ -295,6 +329,7 @@ The Event Logging API provides functions for accessing the :ref:`event_log`.
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char *log_msg;
int buf_size;
...
...
@@ -332,6 +367,7 @@ The Event Logging API provides functions for accessing the :ref:`event_log`.
int main(void) {
wrtd_dev *wrtd;
wrtd_status status;
char log_msg[WRTD_LOG_ENTRY_SIZE];
status = wrtd_init(1, false, NULL, &wrtd);
...
...
@@ -368,6 +404,7 @@ Configuration of an Alarm happens by setting the relevant :ref:`Attributes <attr
int i, count;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
...
...
@@ -427,6 +464,7 @@ Configuration of a Rule happens by setting the relevant :ref:`Attributes <attrib
int i, count;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
...
...
@@ -487,7 +525,7 @@ Configuration of a Rule happens by setting the relevant :ref:`Attributes <attrib
/* Enable rule */
status = wrtd_set_attr_bool(wrtd, "rule1",
WRTD_ATTR_RULE_ENABLED,
T
rue);
WRTD_ATTR_RULE_ENABLED,
t
rue);
wrtd_close(wrtd);
...
...
@@ -516,6 +554,7 @@ relevant :ref:`Attributes <attribute>` via the :ref:`api_attr`.
int i, count, major, minor;
char rep_cap_id[16];
wrtd_dev *wrtd;
wrtd_status status;
status = wrtd_init(1, false, NULL, &wrtd);
...
...
software/lib/libwrtd.c
View file @
7e872170
...
...
@@ -257,8 +257,8 @@ wrtd_status wrtd_get_error(wrtd_dev *wrtd,
if
(
wrtd
==
NULL
)
return
WRTD_ERROR_NOT_INITIALIZED
;
char
error_message
[
256
];
memset
(
error_message
,
0
,
256
);
char
error_message
[
WRTD_ERR_MSG_BUF_SIZE
];
memset
(
error_message
,
0
,
WRTD_ERR_MSG_BUF_SIZE
);
status
=
wrtd_error_message
(
wrtd
,
wrtd
->
err
,
error_message
);
WRTD_RETURN_IF_ERROR
(
status
);
...
...
@@ -312,7 +312,8 @@ 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 at least 256 bytes to store the resulting string.
* @param[out] err_message Buffer of at least #WRTD_ERR_MSG_BUF_SIZE bytes
* to store the resulting string.
* @return #wrtd_status
*/
wrtd_status
wrtd_error_message
(
wrtd_dev
*
wrtd
,
...
...
@@ -332,71 +333,92 @@ wrtd_status wrtd_error_message(wrtd_dev *wrtd,
switch
(
err_code
){
case
WRTD_SUCCESS
:
snprintf
(
err_message
,
256
,
"WRTD_SUCCESS"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_SUCCESS"
);
break
;
case
WRTD_ERROR_INVALID_ATTRIBUTE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_INVALID_ATTRIBUTE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_INVALID_ATTRIBUTE"
);
break
;
case
WRTD_ERROR_ATTR_NOT_WRITEABLE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_ATTR_NOT_WRITEABLE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_ATTR_NOT_WRITEABLE"
);
break
;
case
WRTD_ERROR_ATTR_NOT_READABLE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_ATTR_NOT_READABLE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_ATTR_NOT_READABLE"
);
break
;
case
WRTD_ERROR_INVALID_VALUE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_INVALID_VALUE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_INVALID_VALUE"
);
break
;
case
WRTD_ERROR_NOT_INITIALIZED
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_NOT_INITIALIZED"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_NOT_INITIALIZED"
);
break
;
case
WRTD_ERROR_UNKNOWN_CHANNEL_NAME
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_UNKNOWN_CHANNEL_NAME"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_UNKNOWN_CHANNEL_NAME"
);
break
;
case
WRTD_ERROR_OUT_OF_MEMORY
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_OUT_OF_MEMORY"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_OUT_OF_MEMORY"
);
break
;
case
WRTD_ERROR_NULL_POINTER
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_NULL_POINTER"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_NULL_POINTER"
);
break
;
case
WRTD_ERROR_UNEXPECTED_RESPONSE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_UNEXPECTED_RESPONSE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_UNEXPECTED_RESPONSE"
);
break
;
case
WRTD_ERROR_RESOURCE_UNKNOWN
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_RESOURCE_UNKNOWN"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_RESOURCE_UNKNOWN"
);
break
;
case
WRTD_ERROR_BADLY_FORMED_SELECTOR
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_BADLY_FORMED_SELECTOR"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_BADLY_FORMED_SELECTOR"
);
break
;
case
WRTD_ERROR_ALARM_EXISTS
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_ALARM_EXISTS"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_ALARM_EXISTS"
);
break
;
case
WRTD_ERROR_ALARM_DOES_NOT_EXIST
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_ALARM_DOES_NOT_EXIST"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_ALARM_DOES_NOT_EXIST"
);
break
;
case
WRTD_ERROR_VERSION_MISMATCH
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_VERSION_MISMATCH"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_VERSION_MISMATCH"
);
break
;
case
WRTD_ERROR_INTERNAL
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_INTERNAL"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_INTERNAL"
);
break
;
case
WRTD_ERROR_UNKNOWN_LOG_TYPE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_UNKNOWN_LOG_TYPE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_UNKNOWN_LOG_TYPE"
);
break
;
case
WRTD_ERROR_RESOURCE_ACTIVE
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_RESOURCE_ACTIVE"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_RESOURCE_ACTIVE"
);
break
;
case
WRTD_ERROR_ATTR_GLOBAL
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_ATTR_GLOBAL"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_ATTR_GLOBAL"
);
break
;
case
WRTD_ERROR_OUT_OF_RESOURCES
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_OUT_OF_RESOURCES"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_OUT_OF_RESOURCES"
);
break
;
case
WRTD_ERROR_RULE_EXISTS
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_RULE_EXISTS"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_RULE_EXISTS"
);
break
;
case
WRTD_ERROR_RULE_DOES_NOT_EXIST
:
snprintf
(
err_message
,
256
,
"WRTD_ERROR_RULE_DOES_NOT_EXIST"
);
snprintf
(
err_message
,
WRTD_ERR_MSG_BUF_SIZE
,
"WRTD_ERROR_RULE_DOES_NOT_EXIST"
);
break
;
default:
...
...
@@ -834,7 +856,7 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
}
/**
* Set an attribute of type `timestamp`.
* Set an attribute of type `timestamp`
(#wrtd_tstamp)
.
*
* Modelled after the IVI-C SetAttribute family of functions.
*
...
...
@@ -842,13 +864,15 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
* @param[in] rep_cap_id ID (string) of concerned repeated capability.
* If it is a global attribute, use #WRTD_GLOBAL_REP_CAP_ID
* @param[in] id ID (#wrtd_attr) of concerned attribute.
* @param[in] value Value to write to the attribute.
* @param[in] value Value (#wrtd_tstamp) to write to the attribute.
* If the `ns` part is greater or equal to 1e9, the `seconds` part will be
* automatically increased and the `ns` part will be reduced accordingly.
* @return #wrtd_status
*/
wrtd_status
wrtd_set_attr_tstamp
(
wrtd_dev
*
wrtd
,
const
char
*
rep_cap_id
,
wrtd_attr
id
,
const
wrtd_tstamp
*
value
)
wrtd_tstamp
*
value
)
{
wrtd_status
status
;
...
...
@@ -865,6 +889,11 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
"parameter value"
,
__func__
);
}
while
(
value
->
ns
>=
1e9
)
{
value
->
seconds
++
;
value
->
ns
-=
1e9
;
}
switch
(
id
)
{
case
WRTD_ATTR_ALARM_TIME
:
return
wrtd_attr_set_alarm_time
...
...
@@ -902,7 +931,7 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
}
/**
* Get an attribute of type `timestamp`.
* Get an attribute of type `timestamp`
(#wrtd_tstamp)
.
*
* Modelled after the IVI-C GetAttribute family of functions.
*
...
...
@@ -910,7 +939,7 @@ wrtd_status wrtd_set_attr_tstamp(wrtd_dev *wrtd,
* @param[in] rep_cap_id ID (string) of concerned repeated capability.
* If it is a global attribute, use #WRTD_GLOBAL_REP_CAP_ID
* @param[in] id ID (#wrtd_attr) of concerned attribute.
* @param[out] value Retrieved attribute value.
* @param[out] value Retrieved attribute value
(#wrtd_tstamp)
.
* @return #wrtd_status
*/
wrtd_status
wrtd_get_attr_tstamp
(
wrtd_dev
*
wrtd
,
...
...
software/lib/libwrtd.h
View file @
7e872170
...
...
@@ -236,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 */
/* ------------------------------------------------------------------- */
...
...
@@ -302,7 +305,7 @@ wrtd_status wrtd_get_attr_string(wrtd_dev *wrtd,
wrtd_status
wrtd_set_attr_tstamp
(
wrtd_dev
*
wrtd
,
const
char
*
rep_cap_id
,
wrtd_attr
id
,
const
wrtd_tstamp
*
value
);
wrtd_tstamp
*
value
);
wrtd_status
wrtd_get_attr_tstamp
(
wrtd_dev
*
wrtd
,
const
char
*
rep_cap_id
,
...
...
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