drop progmem support

This commit is contained in:
ladyada 2016-08-09 14:21:46 -04:00
parent cba09e7499
commit 5f3a1e2322
2 changed files with 20 additions and 21 deletions

View File

@ -59,11 +59,11 @@ static uint8_t *stringprint(uint8_t *p, char *s) {
}
*/
static uint8_t *stringprint_P(uint8_t *p, const char *s, uint16_t maxlen=0) {
static uint8_t *stringprint(uint8_t *p, const char *s, uint16_t maxlen=0) {
// If maxlen is specified (has a non-zero value) then use it as the maximum
// length of the source string to write to the buffer. Otherwise write
// the entire source string.
uint16_t len = strlen_P(s);
uint16_t len = strlen(s);
if (maxlen > 0 && len > maxlen) {
len = maxlen;
}
@ -74,7 +74,7 @@ static uint8_t *stringprint_P(uint8_t *p, const char *s, uint16_t maxlen=0) {
*/
p[0] = len >> 8; p++;
p[0] = len & 0xFF; p++;
strncpy_P((char *)p, s, len);
strncpy((char *)p, s, len);
return p+len;
}
@ -455,7 +455,6 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
while (elapsed < (uint32_t)timeout) {
Adafruit_MQTT_Subscribe *sub = readSubscription(timeout - elapsed);
if (sub) {
//Serial.println("**** sub packet received");
if (sub->callback_uint32t != NULL) {
@ -474,12 +473,12 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
}
else if (sub->callback_buffer != NULL) {
// huh lets do the callback in buffer mode
//serial.print("*** calling buffer callback with : "); serial.println(data);
//Serial.print("*** calling buffer callback with : "); Serial.println((char *)sub->lastread);
sub->callback_buffer((char *)sub->lastread, sub->datalen);
}
else if (sub->callback_io != NULL) {
// huh lets do the callback in io mode
//serial.print("*** calling io instance callback with : "); serial.println(data);
//Serial.print("*** calling io instance callback with : "); Serial.println((char *)sub->lastread);
((sub->io_feed)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);
}
}
@ -512,11 +511,11 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
if (subscriptions[i]) {
// Skip this subscription if its name length isn't the same as the
// received topic name.
if (strlen_P(subscriptions[i]->topic) != topiclen)
if (strlen(subscriptions[i]->topic) != topiclen)
continue;
// Stop if the subscription topic matches the received topic. Be careful
// to make comparison case insensitive.
if (strncasecmp_P((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
if (strncasecmp((char*)buffer+4, subscriptions[i]->topic, topiclen) == 0) {
DEBUG_PRINT(F("Found sub #")); DEBUG_PRINTLN(i);
break;
}
@ -601,9 +600,9 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
// fill in packet[1] last
#if MQTT_PROTOCOL_LEVEL == 3
p = stringprint_P(p, PSTR("MQIsdp"));
p = stringprint(p, "MQIsdp");
#elif MQTT_PROTOCOL_LEVEL == 4
p = stringprint_P(p, PSTR("MQTT"));
p = stringprint(p, "MQTT");
#else
#error "MQTT level not supported"
#endif
@ -641,10 +640,10 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
p++;
if(MQTT_PROTOCOL_LEVEL == 3) {
p = stringprint_P(p, clientid, 23); // Limit client ID to first 23 characters.
p = stringprint(p, clientid, 23); // Limit client ID to first 23 characters.
} else {
if (pgm_read_byte(clientid) != 0) {
p = stringprint_P(p, clientid);
p = stringprint(p, clientid);
} else {
p[0] = 0x0;
p++;
@ -655,15 +654,15 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
}
if (will_topic && pgm_read_byte(will_topic) != 0) {
p = stringprint_P(p, will_topic);
p = stringprint_P(p, will_payload);
p = stringprint(p, will_topic);
p = stringprint(p, will_payload);
}
if (pgm_read_byte(username) != 0) {
p = stringprint_P(p, username);
p = stringprint(p, username);
}
if (pgm_read_byte(password) != 0) {
p = stringprint_P(p, password);
p = stringprint(p, password);
}
len = p - packet;
@ -683,7 +682,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_P(topic); // topic length
len += strlen(topic); // topic length
if(qos > 0) {
len += 2; // qos packet id
}
@ -706,7 +705,7 @@ uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
} while ( len > 0 );
// topic comes before packet identifier
p = stringprint_P(p, topic);
p = stringprint(p, topic);
// add packet identifier. used for checking PUBACK in QOS > 0
if(qos > 0) {
@ -743,7 +742,7 @@ uint8_t Adafruit_MQTT::subscribePacket(uint8_t *packet, const char *topic,
// increment the packet id
packet_id_counter++;
p = stringprint_P(p, topic);
p = stringprint(p, topic);
p[0] = qos;
p++;
@ -774,7 +773,7 @@ uint8_t Adafruit_MQTT::unsubscribePacket(uint8_t *packet, const char *topic) {
// increment the packet id
packet_id_counter++;
p = stringprint_P(p, topic);
p = stringprint(p, topic);
len = p - packet;
packet[1] = len-2; // don't include the 2 bytes of fixed header data

View File

@ -49,7 +49,7 @@ class Adafruit_MQTT_FONA : public Adafruit_MQTT {
bool connectServer() {
char server[40];
strncpy_P(server, servername, 40);
strncpy(server, servername, 40);
#ifdef ADAFRUIT_SLEEPYDOG_H
Watchdog.reset();
#endif