Reformatted with clang-format

This commit is contained in:
Lucas Jandrew 2020-11-06 10:20:52 -05:00
parent c952333c40
commit f3f5c18c6d
3 changed files with 53 additions and 44 deletions

View File

@ -152,10 +152,12 @@ int8_t Adafruit_MQTT::connect() {
// Read connect response packet and verify it
len = readFullPacket(buffer, MAXBUFFERSIZE, CONNECT_TIMEOUT_MS);
if (len != 4)
if (len != 4) {
return -1;
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2))
}
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2)) {
return -1;
}
if (buffer[3] != 0)
return buffer[3];
@ -166,7 +168,8 @@ int8_t Adafruit_MQTT::connect() {
continue;
boolean success = false;
for (uint8_t retry=0; (retry<3) && !success; retry++) { // retry until we get a suback
for (uint8_t retry = 0; (retry < 3) && !success;
retry++) { // retry until we get a suback
// Construct and send subscription packet.
uint8_t len = subscribePacket(buffer, subscriptions[i]->topic,
subscriptions[i]->qos);
@ -261,11 +264,12 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize,
}
} while (encodedByte & 0x80);
DEBUG_PRINT(F("Packet Length:\t")); DEBUG_PRINTLN(value);
DEBUG_PRINT(F("Packet Length:\t"));
DEBUG_PRINTLN(value);
if (value > (maxsize - (pbuff-buffer) - 1)) {
if (value > (maxsize - (pbuff - buffer) - 1)) {
DEBUG_PRINTLN(F("Packet too big for buffer"));
rlen = readPacket(pbuff, (maxsize - (pbuff-buffer) - 1), timeout);
rlen = readPacket(pbuff, (maxsize - (pbuff - buffer) - 1), timeout);
} else {
rlen = readPacket(pbuff, value, timeout);
}
@ -439,18 +443,15 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
uint32_t data = 0;
data = atoi((char *)sub->lastread);
sub->callback_uint32t(data);
}
else if (sub->callback_double != NULL) {
} else if (sub->callback_double != NULL) {
// huh lets do the callback in doublefloat mode
double data = 0;
data = atof((char *)sub->lastread);
sub->callback_double(data);
}
else if (sub->callback_buffer != NULL) {
} else if (sub->callback_buffer != NULL) {
// huh lets do the callback in buffer mode
sub->callback_buffer((char *)sub->lastread, sub->datalen);
}
else if (sub->callback_io != NULL) {
} else if (sub->callback_io != NULL) {
// huh lets do the callback in io mode
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread,
sub->datalen);
@ -467,20 +468,27 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
}
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
// Check if data is available to read.
uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
uint16_t len =
readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet
return handleSubscriptionPacket(len);
}
Adafruit_MQTT_Subscribe *Adafruit_MQTT::handleSubscriptionPacket(uint16_t len) {
uint16_t i, topiclen, datalen;
if (!len)
if (!len) {
return NULL; // No data available, just quit.
DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len);
}
DEBUG_PRINT("Packet len: ");
DEBUG_PRINTLN(len);
DEBUG_PRINTBUFFER(buffer, len);
if (len<3) return NULL;
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) return NULL;
if (len < 3) {
return NULL;
}
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) {
return NULL;
}
// Parse out length of packet.
topiclen = buffer[3];
@ -671,7 +679,7 @@ uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
// calc length of non-header data
len += 2; // two bytes to set the topic size
len += strlen(topic); // topic length
if(qos > 0) {
if (qos > 0) {
len += 2; // qos packet id
}
len += bLen; // payload length

View File

@ -206,7 +206,8 @@ public:
// messages!
Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout = 0);
// Handle any data coming in for subscriptions and fires them off to the appropriate callback
// Handle any data coming in for subscriptions and fires them off to the
// appropriate callback
Adafruit_MQTT_Subscribe *handleSubscriptionPacket(uint16_t len);
void processPackets(int16_t timeout);