From 10c8915d330cccac3d6f483f2fc64f944189eff6 Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Mon, 23 Jan 2023 22:28:43 +0000 Subject: [PATCH] Ensure correct functions are called for strcpy_P, strncmp_P, strlen_P etc. on non-AVR targets.. --- DCCEXParser.cpp | 4 ++-- FSH.h | 11 ++++++++++- RingStream.cpp | 2 +- WifiInterface.cpp | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index cbb152e..221d8b0 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -190,9 +190,9 @@ void DCCEXParser::setAtCommandCallback(AT_COMMAND_CALLBACK callback) // Parse an F() string void DCCEXParser::parse(const FSH * cmd) { DIAG(F("SETUP(\"%S\")"),cmd); - int size=strlen_P((char *)cmd)+1; + int size=STRLEN_P((char *)cmd)+1; char buffer[size]; - strcpy_P(buffer,(char *)cmd); + STRCPY_P(buffer,(char *)cmd); parse(&USB_SERIAL,(byte *)buffer,NULL); } diff --git a/FSH.h b/FSH.h index f4bf47e..d031935 100644 --- a/FSH.h +++ b/FSH.h @@ -47,7 +47,11 @@ typedef __FlashStringHelper FSH; #define FLASH PROGMEM #define GETFLASH(addr) pgm_read_byte_near(addr) - +#define STRCPY_P strcpy_P +#define STRCMP_P strcmp_P +#define STRNCPY_P strncpy_P +#define STRNCMP_P strncmp_P +#define STRLEN_P strlen_P #if defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) // AVR_MEGA memory deliberately placed at end of link may need _far functions @@ -80,5 +84,10 @@ typedef char FSH; #define GETFLASH(addr) (*(const byte *)(addr)) #define GETHIGHFLASH(data,offset) (*(const byte *)(GETFARPTR(data)+offset)) #define GETHIGHFLASHW(data,offset) (*(const uint16_t *)(GETFARPTR(data)+offset)) +#define STRCPY_P strcpy +#define STRCMP_P strcmp +#define STRNCPY_P strncpy +#define STRNCMP_P strncmp +#define STRLEN_P strlen #endif #endif diff --git a/RingStream.cpp b/RingStream.cpp index 9377a0a..12dbaa1 100644 --- a/RingStream.cpp +++ b/RingStream.cpp @@ -83,7 +83,7 @@ size_t RingStream::printFlash(const FSH * flashBuffer) { // Establish the actual length of the progmem string. char * flash=(char *)flashBuffer; -int16_t plength=strlen_P(flash); +int16_t plength=STRLEN_P(flash); if (plength==0) return 0; // just ignore empty string // Retain the buffer count as it will be modified by the marker+address insert diff --git a/WifiInterface.cpp b/WifiInterface.cpp index bdc8dad..f69cc2f 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -184,8 +184,8 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, checkForOK(1000, true); // Not always OK, sometimes "no change" const char *yourNetwork = "Your network "; - if (strncmp_P(yourNetwork, (const char*)SSid, 13) == 0 || strncmp_P("", (const char*)SSid, 13) == 0) { - if (strncmp_P(yourNetwork, (const char*)password, 13) == 0) { + if (STRNCMP_P(yourNetwork, (const char*)SSid, 13) == 0 || STRNCMP_P("", (const char*)SSid, 13) == 0) { + if (STRNCMP_P(yourNetwork, (const char*)password, 13) == 0) { // If the source code looks unconfigured, check if the // ESP8266 is preconfigured in station mode. // We check the first 13 chars of the SSid and the password @@ -258,7 +258,7 @@ wifiSerialState WifiInterface::setup2(const FSH* SSid, const FSH* password, i=0; do { - if (strncmp_P(yourNetwork, (const char*)password, 13) == 0) { + if (STRNCMP_P(yourNetwork, (const char*)password, 13) == 0) { // unconfigured StringFormatter::send(wifiStream, F("AT+CWSAP%s=\"DCCEX_%s\",\"PASS_%s\",%d,4\r\n"), oldCmd ? "" : "_CUR", macTail, macTail, channel);