Skip to content

Commit 203a84c

Browse files
committed
updated lwmqtt
1 parent f6aa15b commit 203a84c

File tree

5 files changed

+112
-106
lines changed

5 files changed

+112
-106
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fmt:
55

66
update:
77
rm -rf ./lwmqtt
8-
git clone --branch v0.5.6 https://github.com/256dpi/lwmqtt.git ./lwmqtt
8+
git clone --branch v0.6.1 https://github.com/256dpi/lwmqtt.git ./lwmqtt
99
mkdir -p ./src/lwmqtt
1010
cp -r ./lwmqtt/src/*.c ./src/lwmqtt/
1111
cp -r ./lwmqtt/src/*.h ./src/lwmqtt/

src/lwmqtt/helpers.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include "helpers.h"
44

5-
uint8_t lwmqtt_read_bits(uint8_t byte, int pos, int num) {
6-
return (byte & (uint8_t)((~(0xFF << num)) << pos)) >> pos;
7-
}
5+
uint8_t lwmqtt_read_bits(uint8_t byte, int pos, int num) { return (byte & (uint8_t)((~(0xFF << num)) << pos)) >> pos; }
86

97
void lwmqtt_write_bits(uint8_t *byte, uint8_t value, int pos, int num) {
108
*byte = (*byte & ~(uint8_t)((~(0xFF << num)) << pos)) | (value << pos);

src/lwmqtt/lwmqtt.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
/**
99
* The error type used by all exposed APIs.
10+
*
11+
* If a function returns an error that operates on a connected client (e.g publish, keep_alive, etc.) the caller should
12+
* switch into a disconnected state, close and cleanup the current connection and start over by creating a new
13+
* connection.
1014
*/
1115
typedef enum {
1216
LWMQTT_SUCCESS = 0,
@@ -345,11 +349,12 @@ lwmqtt_err_t lwmqtt_disconnect(lwmqtt_client_t *client, uint32_t timeout);
345349
/**
346350
* Will yield control to the client and receive incoming packets from the network.
347351
*
348-
* Applications may peek on the network if there is data available to read before calling yield and potentially block
349-
* until the timeout is reached. Furthermore, applications may specify the amount of bytes available to read in order
350-
* to constrain the yield to only receive packets that are already inflight.
352+
* Single-threaded applications may peek on the network and assess if data is available to read before calling yield and
353+
* potentially block until the timeout is reached. Multi-threaded applications may select on the socket and block until
354+
* data is available and then yield to the client if data is available. All applications may specify the amount of bytes
355+
* available to read in order to constrain the yield to only receive packets that are already in-flight.
351356
*
352-
* If no availability data is given the yield will return after one packet has been successfully read or the deadline
357+
* If no availability info is given the yield will return after one packet has been successfully read or the deadline
353358
* has been reached but no single bytes has been received.
354359
*
355360
* Note: The message callback might be called with incoming messages as part of this call.
@@ -364,6 +369,9 @@ lwmqtt_err_t lwmqtt_yield(lwmqtt_client_t *client, size_t available, uint32_t ti
364369
/**
365370
* Will yield control to the client to keep the connection alive.
366371
*
372+
* This functions must be called at a rate slightly lower than 25% of the configured keep alive. If keep alive is zero,
373+
* the function must not be called at all.
374+
*
367375
* @param client - The client object.
368376
* @param timeout - The command timeout.
369377
* @return An error value.

src/lwmqtt/packet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw
132132

133133
// set username flag if present
134134
if (options.username.len > 0) {
135-
lwmqtt_write_bits(&flags, 1, 6, 1);
135+
lwmqtt_write_bits(&flags, 1, 7, 1);
136136

137137
// set password flag if present
138138
if (options.password.len > 0) {
139-
lwmqtt_write_bits(&flags, 1, 7, 1);
139+
lwmqtt_write_bits(&flags, 1, 6, 1);
140140
}
141141
}
142142

src/lwmqtt/packet.h

Lines changed: 96 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -48,137 +48,137 @@ lwmqtt_err_t lwmqtt_detect_packet_type(uint8_t *buf, size_t buf_len, lwmqtt_pack
4848
lwmqtt_err_t lwmqtt_detect_remaining_length(uint8_t *buf, size_t buf_len, uint32_t *rem_len);
4949

5050
/**
51-
* Encodes a connect packet into the supplied buffer.
52-
*
53-
* @param buf - The buffer into which the packet will be encoded.
54-
* @param buf_len - The length of the specified buffer.
55-
* @param len - The encoded length of the packet.
56-
* @param options - The options to be used to build the connect packet.
57-
* @param will - The last will and testament.
58-
* @return An error value.
59-
*/
51+
* Encodes a connect packet into the supplied buffer.
52+
*
53+
* @param buf - The buffer into which the packet will be encoded.
54+
* @param buf_len - The length of the specified buffer.
55+
* @param len - The encoded length of the packet.
56+
* @param options - The options to be used to build the connect packet.
57+
* @param will - The last will and testament.
58+
* @return An error value.
59+
*/
6060
lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_options_t options,
6161
lwmqtt_will_t *will);
6262

6363
/**
64-
* Decodes a connack packet from the supplied buffer.
65-
*
66-
* @param buf - The raw buffer data.
67-
* @param buf_len - The length of the specified buffer.
68-
* @param session_present - The session present flag.
69-
* @param return_code - The return code.
70-
* @return An error value.
71-
*/
64+
* Decodes a connack packet from the supplied buffer.
65+
*
66+
* @param buf - The raw buffer data.
67+
* @param buf_len - The length of the specified buffer.
68+
* @param session_present - The session present flag.
69+
* @param return_code - The return code.
70+
* @return An error value.
71+
*/
7272
lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_present,
7373
lwmqtt_return_code_t *return_code);
7474

7575
/**
76-
* Encodes a zero (disconnect, pingreq) packet into the supplied buffer.
77-
*
78-
* @param buf - The buffer into which the packet will be encoded.
79-
* @param buf_len - The length of the specified buffer.
80-
* @param len - The encoded length of the packet.
81-
* @param packet_type - The packets type.
82-
* @return An error value.
83-
*/
76+
* Encodes a zero (disconnect, pingreq) packet into the supplied buffer.
77+
*
78+
* @param buf - The buffer into which the packet will be encoded.
79+
* @param buf_len - The length of the specified buffer.
80+
* @param len - The encoded length of the packet.
81+
* @param packet_type - The packets type.
82+
* @return An error value.
83+
*/
8484
lwmqtt_err_t lwmqtt_encode_zero(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_packet_type_t packet_type);
8585

8686
/**
87-
* Decodes an ack (puback, pubrec, pubrel, pubcomp, unsuback) packet from the supplied buffer.
88-
*
89-
* @param buf - The raw buffer data.
90-
* @param buf_len - The length of the specified buffer.
91-
* @param packet_type - The packet type.
92-
* @param dup - The dup flag.
93-
* @param packet_id - The packet id.
94-
* @return An error value.
95-
*/
87+
* Decodes an ack (puback, pubrec, pubrel, pubcomp, unsuback) packet from the supplied buffer.
88+
*
89+
* @param buf - The raw buffer data.
90+
* @param buf_len - The length of the specified buffer.
91+
* @param packet_type - The packet type.
92+
* @param dup - The dup flag.
93+
* @param packet_id - The packet id.
94+
* @return An error value.
95+
*/
9696
lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_t packet_type, bool *dup,
9797
uint16_t *packet_id);
9898

9999
/**
100-
* Encodes an ack (puback, pubrec, pubrel, pubcomp) packet into the supplied buffer.
101-
*
102-
* @param buf - The buffer into which the packet will be encoded.
103-
* @param buf_len - The length of the specified buffer.
104-
* @param len - The encoded length of the packet.
105-
* @param packet_type - The packets type.
106-
* @param dup - The dup flag.
107-
* @param packet_id - The packet id.
108-
* @return An error value.
109-
*/
100+
* Encodes an ack (puback, pubrec, pubrel, pubcomp) packet into the supplied buffer.
101+
*
102+
* @param buf - The buffer into which the packet will be encoded.
103+
* @param buf_len - The length of the specified buffer.
104+
* @param len - The encoded length of the packet.
105+
* @param packet_type - The packets type.
106+
* @param dup - The dup flag.
107+
* @param packet_id - The packet id.
108+
* @return An error value.
109+
*/
110110
lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_packet_type_t packet_type, bool dup,
111111
uint16_t packet_id);
112112

113113
/**
114-
* Decodes a publish packet from the supplied buffer.
115-
*
116-
* @param buf - The raw buffer data.
117-
* @param buf_len - The length of the specified buffer.
118-
* @param dup - The dup flag.
119-
* @param packet_id - The packet id.
120-
* @param topic - The topic.
121-
* @parma msg - The message.
122-
* @return An error value.
123-
*/
114+
* Decodes a publish packet from the supplied buffer.
115+
*
116+
* @param buf - The raw buffer data.
117+
* @param buf_len - The length of the specified buffer.
118+
* @param dup - The dup flag.
119+
* @param packet_id - The packet id.
120+
* @param topic - The topic.
121+
* @parma msg - The message.
122+
* @return An error value.
123+
*/
124124
lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint16_t *packet_id, lwmqtt_string_t *topic,
125125
lwmqtt_message_t *msg);
126126

127127
/**
128-
* Encodes a publish packet into the supplied buffer.
129-
*
130-
* @param buf - The buffer into which the packet will be encoded.
131-
* @param buf_len - The length of the specified buffer.
132-
* @param len - The encoded length of the packet.
133-
* @param dup - The dup flag.
134-
* @param packet_id - The packet id.
135-
* @param topic - The topic.
136-
* @param msg - The message.
137-
* @return An error value.
138-
*/
128+
* Encodes a publish packet into the supplied buffer.
129+
*
130+
* @param buf - The buffer into which the packet will be encoded.
131+
* @param buf_len - The length of the specified buffer.
132+
* @param len - The encoded length of the packet.
133+
* @param dup - The dup flag.
134+
* @param packet_id - The packet id.
135+
* @param topic - The topic.
136+
* @param msg - The message.
137+
* @return An error value.
138+
*/
139139
lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bool dup, uint16_t packet_id,
140140
lwmqtt_string_t topic, lwmqtt_message_t msg);
141141

142142
/**
143-
* Encodes a subscribe packet into the supplied buffer.
144-
*
145-
* @param buf - The buffer into which the packet will be encoded.
146-
* @param buf_len - The length of the specified buffer.
147-
* @param len - The encoded length of the packet.
148-
* @param packet_id - The packet id.
149-
* @param count - The number of members in the topic_filters and qos_levels array.
150-
* @param topic_filters - The array of topic filter.
151-
* @param qos_levels - The array of requested QoS levels.
152-
* @return An error value.
153-
*/
143+
* Encodes a subscribe packet into the supplied buffer.
144+
*
145+
* @param buf - The buffer into which the packet will be encoded.
146+
* @param buf_len - The length of the specified buffer.
147+
* @param len - The encoded length of the packet.
148+
* @param packet_id - The packet id.
149+
* @param count - The number of members in the topic_filters and qos_levels array.
150+
* @param topic_filters - The array of topic filter.
151+
* @param qos_levels - The array of requested QoS levels.
152+
* @return An error value.
153+
*/
154154
lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count,
155155
lwmqtt_string_t *topic_filters, lwmqtt_qos_t *qos_levels);
156156

157157
/**
158-
* Decodes a suback packet from the supplied buffer.
159-
*
160-
* @param buf - The raw buffer data.
161-
* @param buf_len - The length of the specified buffer.
162-
* @param packet_id - The packet id.
163-
* @param max_count - The maximum number of members allowed in the granted_qos_levels array.
164-
* @param count - The number of members in the granted_qos_levels array.
165-
* @param granted_qos_levels - The granted QoS levels.
166-
* @return An error value.
167-
*/
158+
* Decodes a suback packet from the supplied buffer.
159+
*
160+
* @param buf - The raw buffer data.
161+
* @param buf_len - The length of the specified buffer.
162+
* @param packet_id - The packet id.
163+
* @param max_count - The maximum number of members allowed in the granted_qos_levels array.
164+
* @param count - The number of members in the granted_qos_levels array.
165+
* @param granted_qos_levels - The granted QoS levels.
166+
* @return An error value.
167+
*/
168168
lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, int max_count, int *count,
169169
lwmqtt_qos_t *granted_qos_levels);
170170

171171
/**
172-
* Encodes the supplied unsubscribe data into the supplied buffer, ready for sending
173-
*
174-
* @param buf - The buffer into which the packet will be encoded.
175-
* @param buf_len - The length of the specified buffer.
176-
* @param len - The encoded length of the packet.
177-
* @param packet_id - The packet id.
178-
* @param count - The number of members in the topic_filters array.
179-
* @param topic_filters - The array of topic filters.
180-
* @return An error value.
181-
*/
172+
* Encodes the supplied unsubscribe data into the supplied buffer, ready for sending
173+
*
174+
* @param buf - The buffer into which the packet will be encoded.
175+
* @param buf_len - The length of the specified buffer.
176+
* @param len - The encoded length of the packet.
177+
* @param packet_id - The packet id.
178+
* @param count - The number of members in the topic_filters array.
179+
* @param topic_filters - The array of topic filters.
180+
* @return An error value.
181+
*/
182182
lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count,
183183
lwmqtt_string_t *topic_filters);
184184

0 commit comments

Comments
 (0)