aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/pb-send.h
blob: 7e21eda2d4d9d5b107f7a0b7d32103ba32c88976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once

#include "pb-types.h"
#include "pb-buf.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * \ingroup pbdrv-mod
 * \defgroup pb_send Send
 * \brief Functions for directly creating serialized message buffers
 * \{
 */

/**
 * \brief Utility function for replying to a message
 *
 * \param msg Message to reply to
 * \param reply Data to send as reply
 *
 * This function uses \c pb_i2c_send() to send \p reply to \p msg->sender.
 */
void pb_send_reply(const pb_msg_t * msg, const pb_buf_t * reply);

/**
 * \brief Create a serialized \ref PB_CMD_PROP "PROP" \ref PB_ACTION_REQ "REQ"
 * message
 *
 * \param propid Property ID to request
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_read_req(uint8_t propid);
/**
 * \brief Create a serialized \ref PB_CMD_PROP "PROP" \ref PB_ACTION_RES "RES"
 * message
 *
 * \param propid Requested property ID
 * \param value Pointer to structured data in property
 * \param size Size of \p value
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_read_res(uint8_t propid, const uint8_t * value, size_t size);
/**
 * \brief Create a serialized \ref PB_CMD_PROP "PROP" \ref PB_ACTION_SET "SET"
 * message
 *
 * \param propid Property ID to write
 * \param value Pointer to data to write to property
 * \param size Size of \p value
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_write_req(uint8_t propid, const uint8_t * value, size_t size);
/**
 * \brief Create a serialized \ref PB_CMD_STATE "STATE" \ref PB_ACTION_REQ
 * "REQ" message
 *
 * The current module's state is obtained using \c pb_hook_mod_state_read().
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_state_req();
/**
 * \brief Create a serialized \ref PB_CMD_STATE "STATE" \ref PB_ACTION_RES
 * "RES" message
 *
 * The current module's state is obtained using \c pb_hook_mod_state_read().
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_state_res();
/**
 * \brief Create a serialized \ref PB_CMD_STATE "STATE" \ref PB_ACTION_SET
 * "SET" message
 *
 * \param state Requested new state
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_state_set(pb_global_state_t state);
/**
 * \brief Create a serialized \ref PB_CMD_MAGIC "MAGIC" \ref PB_ACTION_REQ
 * "REQ" message
 *
 * The magic string is equal to \ref pb_cmd_magic_req.
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_magic_req();
/**
 * \brief Create a serialized \ref PB_CMD_MAGIC "MAGIC" \ref PB_ACTION_RES
 * "RES" message
 *
 * The magic string is equal to \ref pb_cmd_magic_res.
 *
 * \return Message buffer
 *
 * \note The buffer returned by this function must be free'd with \c
 * pb_buf_free().
 */
pb_buf_t pb_send_magic_res();

/// \}

#ifdef __cplusplus
}
#endif