mikroSDK Reference Manual
coap_client_request.h
Go to the documentation of this file.
1
31#ifndef _COAP_CLIENT_REQUEST_H
32#define _COAP_CLIENT_REQUEST_H
33
34//Dependencies
35#include "core/net.h"
36#include "coap/coap_client.h"
37#include "coap/coap_option.h"
38
39//C++ guard
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44
49typedef enum
50{
51 COAP_REQ_STATE_UNUSED = 0,
52 COAP_REQ_STATE_INIT = 1,
53 COAP_REQ_STATE_TRANSMIT = 2,
54 COAP_REQ_STATE_RECEIVE = 3,
55 COAP_REQ_STATE_SEPARATE = 4,
56 COAP_REQ_STATE_OBSERVE = 5,
57 COAP_REQ_STATE_DONE = 6,
58 COAP_REQ_STATE_RESET = 7,
59 COAP_REQ_STATE_TIMEOUT = 8,
60 COAP_REQ_STATE_CANCELED = 9
62
63
68typedef enum
69{
70 COAP_REQUEST_STATUS_SUCCESS = 0,
71 COAP_REQUEST_STATUS_FAILURE = 1,
72 COAP_REQUEST_STATUS_RESET = 2,
73 COAP_REQUEST_STATUS_TIMEOUT = 3,
74 COAP_REQUEST_STATUS_CANCELED = 4
76
77
82typedef error_t (*CoapRequestCallback)(CoapClientContext *context,
83 CoapClientRequest *request, CoapRequestStatus status, void *param);
84
85
91{
93 CoapClientContext *context;
99#if (COAP_CLIENT_OBSERVE_SUPPORT == ENABLED)
100 uint32_t observeSeqNum;
101#endif
102#if (COAP_CLIENT_BLOCK_SUPPORT == ENABLED)
105#endif
108 void *param;
109};
110
111
112//CoAP client related functions
113CoapClientRequest *coapClientCreateRequest(CoapClientContext *context);
114
115error_t coapClientSetRequestTimeout(CoapClientRequest *request,
116 systime_t timeout);
117
118error_t coapClientSendRequest(CoapClientRequest *request,
119 CoapRequestCallback callback, void *param);
120
121error_t coapClientCancelRequest(CoapClientRequest *request);
122void coapClientDeleteRequest(CoapClientRequest *request);
123
124CoapMessage *coapClientGetRequestMessage(CoapClientRequest *request);
125CoapMessage *coapClientGetResponseMessage(CoapClientRequest *request);
126
127error_t coapClientSetType(CoapMessage *message, CoapMessageType type);
128error_t coapClientGetType(const CoapMessage *message, CoapMessageType *type);
129
130error_t coapClientSetMethodCode(CoapMessage *message, CoapCode code);
131error_t coapClientGetMethodCode(const CoapMessage *message, CoapCode *code);
132
133error_t coapClientGetResponseCode(const CoapMessage *message, CoapCode *code);
134
135error_t coapClientSetUriPath(CoapMessage *message, const char_t *path);
136
137error_t coapClientGetUriPath(const CoapMessage *message, char_t *path,
138 size_t maxLen);
139
140error_t coapClientSetUriQuery(CoapMessage *message, const char_t *queryString);
141
142error_t coapClientGetUriQuery(const CoapMessage *message, char_t *queryString,
143 size_t maxLen);
144
145error_t coapClientGetLocationPath(const CoapMessage *message, char_t *path,
146 size_t maxLen);
147
148error_t coapClientGetLocationQuery(const CoapMessage *message,
149 char_t *queryString, size_t maxLen);
150
151error_t coapClientSetOpaqueOption(CoapMessage *message, uint16_t optionNum,
152 uint_t optionIndex, const uint8_t *optionValue, size_t optionLen);
153
154error_t coapClientSetStringOption(CoapMessage *message, uint16_t optionNum,
155 uint_t optionIndex, const char_t *optionValue);
156
157error_t coapClientSetUintOption(CoapMessage *message, uint16_t optionNum,
158 uint_t optionIndex, uint32_t optionValue);
159
160error_t coapClientGetOpaqueOption(const CoapMessage *message, uint16_t optionNum,
161 uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen);
162
163error_t coapClientGetStringOption(const CoapMessage *message, uint16_t optionNum,
164 uint_t optionIndex, const char_t **optionValue, size_t *optionLen);
165
166error_t coapClientGetUintOption(const CoapMessage *message, uint16_t optionNum,
167 uint_t optionIndex, uint32_t *optionValue);
168
169error_t coapClientDeleteOption(CoapMessage *message, uint16_t optionNum,
170 uint_t optionIndex);
171
172error_t coapClientSetPayload(CoapMessage *message, const void *payload,
173 size_t payloadLen);
174
175error_t coapClientGetPayload(const CoapMessage *message, const uint8_t **payload,
176 size_t *payloadLen);
177
178error_t coapClientWritePayload(CoapMessage *message, const void *data,
179 size_t length);
180
181error_t coapClientReadPayload(CoapMessage *message, void *data, size_t size,
182 size_t *length);
183
184//C++ guard
185#ifdef __cplusplus
186}
187#endif
188
189#endif
CoAP client.
error_t(* CoapRequestCallback)(CoapClientContext *context, CoapClientRequest *request, CoapRequestStatus status, void *param)
Request completed callback.
Definition coap_client_request.h:82
CoapRequestState
CoAP request states.
Definition coap_client_request.h:50
CoapRequestStatus
Request status.
Definition coap_client_request.h:69
CoapMessageType
CoAP message types.
Definition coap_common.h:88
CoapCode
CoAP method and response codes.
Definition coap_common.h:113
CoAP option formatting and parsing.
CoapBlockSize
Block size parameter.
Definition coap_option.h:200
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
uint32_t systime_t
System time.
Definition os_port_none.h:90
CoAP message.
Definition coap_message.h:56
CoAP request.
Definition coap_client_request.h:91
systime_t timeout
Request timeout.
Definition coap_client_request.h:95
systime_t retransmitStartTime
Time at which the last message was sent.
Definition coap_client_request.h:96
CoapBlockSize txBlockSzx
TX block size.
Definition coap_client_request.h:103
systime_t startTime
Request start time.
Definition coap_client_request.h:94
uint_t retransmitCount
Retransmission counter.
Definition coap_client_request.h:98
uint32_t observeSeqNum
Sequence number for reordering detection.
Definition coap_client_request.h:100
void * param
Callback function parameter.
Definition coap_client_request.h:108
systime_t retransmitTimeout
Retransmission timeout.
Definition coap_client_request.h:97
CoapRequestState state
CoAP request state.
Definition coap_client_request.h:92
CoapBlockSize rxBlockSzx
RX block size.
Definition coap_client_request.h:104
CoapClientContext * context
CoAP client context.
Definition coap_client_request.h:93
CoapRequestCallback callback
Callback function to invoke when the request completes.
Definition coap_client_request.h:107
CoapMessage message
CoAP request message.
Definition coap_client_request.h:106