Skip to content

Commit f3f5c18

Browse files
committed
Reformatted with clang-format
1 parent c952333 commit f3f5c18

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

Adafruit_MQTT.cpp

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ int8_t Adafruit_MQTT::connect() {
152152

153153
// Read connect response packet and verify it
154154
len = readFullPacket(buffer, MAXBUFFERSIZE, CONNECT_TIMEOUT_MS);
155-
if (len != 4)
155+
if (len != 4) {
156156
return -1;
157-
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2))
157+
}
158+
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2)) {
158159
return -1;
160+
}
159161
if (buffer[3] != 0)
160162
return buffer[3];
161163

@@ -166,7 +168,8 @@ int8_t Adafruit_MQTT::connect() {
166168
continue;
167169

168170
boolean success = false;
169-
for (uint8_t retry=0; (retry<3) && !success; retry++) { // retry until we get a suback
171+
for (uint8_t retry = 0; (retry < 3) && !success;
172+
retry++) { // retry until we get a suback
170173
// Construct and send subscription packet.
171174
uint8_t len = subscribePacket(buffer, subscriptions[i]->topic,
172175
subscriptions[i]->qos);
@@ -213,13 +216,13 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer,
213216

214217
uint8_t packetType = (buffer[0] >> 4);
215218
if (packetType == waitforpackettype) {
216-
return len;
219+
return len;
217220
} else {
218-
if (packetType == MQTT_CTRL_PUBLISH) {
219-
handleSubscriptionPacket(len);
220-
} else {
221-
ERROR_PRINTLN(F("Dropped a packet"));
222-
}
221+
if (packetType == MQTT_CTRL_PUBLISH) {
222+
handleSubscriptionPacket(len);
223+
} else {
224+
ERROR_PRINTLN(F("Dropped a packet"));
225+
}
223226
}
224227
}
225228
return 0;
@@ -261,11 +264,12 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize,
261264
}
262265
} while (encodedByte & 0x80);
263266

264-
DEBUG_PRINT(F("Packet Length:\t")); DEBUG_PRINTLN(value);
267+
DEBUG_PRINT(F("Packet Length:\t"));
268+
DEBUG_PRINTLN(value);
265269

266-
if (value > (maxsize - (pbuff-buffer) - 1)) {
267-
DEBUG_PRINTLN(F("Packet too big for buffer"));
268-
rlen = readPacket(pbuff, (maxsize - (pbuff-buffer) - 1), timeout);
270+
if (value > (maxsize - (pbuff - buffer) - 1)) {
271+
DEBUG_PRINTLN(F("Packet too big for buffer"));
272+
rlen = readPacket(pbuff, (maxsize - (pbuff - buffer) - 1), timeout);
269273
} else {
270274
rlen = readPacket(pbuff, value, timeout);
271275
}
@@ -435,22 +439,19 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
435439
Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
436440
if (sub) {
437441
if (sub->callback_uint32t != NULL) {
438-
// huh lets do the callback in integer mode
439-
uint32_t data = 0;
440-
data = atoi((char *)sub->lastread);
441-
sub->callback_uint32t(data);
442-
}
443-
else if (sub->callback_double != NULL) {
444-
// huh lets do the callback in doublefloat mode
445-
double data = 0;
446-
data = atof((char *)sub->lastread);
447-
sub->callback_double(data);
448-
}
449-
else if (sub->callback_buffer != NULL) {
450-
// huh lets do the callback in buffer mode
451-
sub->callback_buffer((char *)sub->lastread, sub->datalen);
452-
}
453-
else if (sub->callback_io != NULL) {
442+
// huh lets do the callback in integer mode
443+
uint32_t data = 0;
444+
data = atoi((char *)sub->lastread);
445+
sub->callback_uint32t(data);
446+
} else if (sub->callback_double != NULL) {
447+
// huh lets do the callback in doublefloat mode
448+
double data = 0;
449+
data = atof((char *)sub->lastread);
450+
sub->callback_double(data);
451+
} else if (sub->callback_buffer != NULL) {
452+
// huh lets do the callback in buffer mode
453+
sub->callback_buffer((char *)sub->lastread, sub->datalen);
454+
} else if (sub->callback_io != NULL) {
454455
// huh lets do the callback in io mode
455456
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread,
456457
sub->datalen);
@@ -466,21 +467,28 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
466467
}
467468
}
468469
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
469-
// Check if data is available to read.
470-
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
471-
return handleSubscriptionPacket(len);
470+
// Check if data is available to read.
471+
uint16_t len =
472+
readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
473+
return handleSubscriptionPacket(len);
472474
}
473475

474476
Adafruit_MQTT_Subscribe *Adafruit_MQTT::handleSubscriptionPacket(uint16_t len) {
475-
uint16_t i, topiclen, datalen;
477+
uint16_t i, topiclen, datalen;
476478

477-
if (!len)
478-
return NULL; // No data available, just quit.
479-
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
479+
if (!len) {
480+
return NULL; // No data available, just quit.
481+
}
482+
DEBUG_PRINT("Packet len: ");
483+
DEBUG_PRINTLN(len);
480484
DEBUG_PRINTBUFFER(buffer, len);
481485

482-
if (len<3) return NULL;
483-
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) return NULL;
486+
if (len < 3) {
487+
return NULL;
488+
}
489+
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) {
490+
return NULL;
491+
}
484492

485493
// Parse out length of packet.
486494
topiclen = buffer[3];
@@ -671,7 +679,7 @@ uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
671679
// calc length of non-header data
672680
len += 2; // two bytes to set the topic size
673681
len += strlen(topic); // topic length
674-
if(qos > 0) {
682+
if (qos > 0) {
675683
len += 2; // qos packet id
676684
}
677685
len += bLen; // payload length

Adafruit_MQTT.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ class Adafruit_MQTT {
206206
// messages!
207207
Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout = 0);
208208

209-
// Handle any data coming in for subscriptions and fires them off to the appropriate callback
209+
// Handle any data coming in for subscriptions and fires them off to the
210+
// appropriate callback
210211
Adafruit_MQTT_Subscribe *handleSubscriptionPacket(uint16_t len);
211212

212213
void processPackets(int16_t timeout);

Adafruit_MQTT_Client.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
5555
uint16_t len = 0;
5656
int16_t t = timeout;
5757

58-
if (maxlen == 0) { // handle zero-length packets
59-
return 0;
60-
}
58+
if (maxlen == 0) { // handle zero-length packets
59+
return 0;
60+
}
6161

6262
while (client->connected() && (timeout >= 0)) {
6363
// DEBUG_PRINT('.');
@@ -69,7 +69,7 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
6969
// DEBUG_PRINTLN((uint8_t)c, HEX);
7070
len++;
7171

72-
if (len == maxlen) { // we read all we want, bail
72+
if (len == maxlen) { // we read all we want, bail
7373
DEBUG_PRINT(F("Read data:\t"));
7474
DEBUG_PRINTBUFFER(buffer, len);
7575
return len;

0 commit comments

Comments
 (0)