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 // Read connect response packet and verify it
len = readFullPacket(buffer, MAXBUFFERSIZE, CONNECT_TIMEOUT_MS); len = readFullPacket(buffer, MAXBUFFERSIZE, CONNECT_TIMEOUT_MS);
if (len != 4) if (len != 4) {
return -1; return -1;
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2)) }
if ((buffer[0] != (MQTT_CTRL_CONNECTACK << 4)) || (buffer[1] != 2)) {
return -1; return -1;
}
if (buffer[3] != 0) if (buffer[3] != 0)
return buffer[3]; return buffer[3];
@ -166,7 +168,8 @@ int8_t Adafruit_MQTT::connect() {
continue; continue;
boolean success = false; 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. // Construct and send subscription packet.
uint8_t len = subscribePacket(buffer, subscriptions[i]->topic, uint8_t len = subscribePacket(buffer, subscriptions[i]->topic,
subscriptions[i]->qos); subscriptions[i]->qos);
@ -261,7 +264,8 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize,
} }
} while (encodedByte & 0x80); } 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")); DEBUG_PRINTLN(F("Packet too big for buffer"));
@ -439,18 +443,15 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
uint32_t data = 0; uint32_t data = 0;
data = atoi((char *)sub->lastread); data = atoi((char *)sub->lastread);
sub->callback_uint32t(data); sub->callback_uint32t(data);
} } else if (sub->callback_double != NULL) {
else if (sub->callback_double != NULL) {
// huh lets do the callback in doublefloat mode // huh lets do the callback in doublefloat mode
double data = 0; double data = 0;
data = atof((char *)sub->lastread); data = atof((char *)sub->lastread);
sub->callback_double(data); sub->callback_double(data);
} } else if (sub->callback_buffer != NULL) {
else if (sub->callback_buffer != NULL) {
// huh lets do the callback in buffer mode // huh lets do the callback in buffer mode
sub->callback_buffer((char *)sub->lastread, sub->datalen); 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 // huh lets do the callback in io mode
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, ((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread,
sub->datalen); sub->datalen);
@ -467,20 +468,27 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
} }
Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
// Check if data is available to read. // 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); return handleSubscriptionPacket(len);
} }
Adafruit_MQTT_Subscribe *Adafruit_MQTT::handleSubscriptionPacket(uint16_t len) { Adafruit_MQTT_Subscribe *Adafruit_MQTT::handleSubscriptionPacket(uint16_t len) {
uint16_t i, topiclen, datalen; uint16_t i, topiclen, datalen;
if (!len) if (!len) {
return NULL; // No data available, just quit. 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); DEBUG_PRINTBUFFER(buffer, len);
if (len<3) return NULL; if (len < 3) {
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) return NULL; return NULL;
}
if ((buffer[0] & 0xF0) != (MQTT_CTRL_PUBLISH) << 4) {
return NULL;
}
// Parse out length of packet. // Parse out length of packet.
topiclen = buffer[3]; topiclen = buffer[3];

View File

@ -206,7 +206,8 @@ public:
// messages! // messages!
Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout = 0); 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); Adafruit_MQTT_Subscribe *handleSubscriptionPacket(uint16_t len);
void processPackets(int16_t timeout); void processPackets(int16_t timeout);