Skip to content

Commit

Permalink
Fixed problematic applications of PSTR and PROGMEM for ESP8266 by
Browse files Browse the repository at this point in the history
using conditional compilation to prevent them from being added.
  • Loading branch information
logos-electromechanical committed Sep 28, 2019
1 parent c0e2b75 commit c8072e7
Show file tree
Hide file tree
Showing 350 changed files with 4,213 additions and 1,046 deletions.
59 changes: 59 additions & 0 deletions scripts/esp8266_pstr_fix.py
@@ -0,0 +1,59 @@
#!/usr/bin/python3

import sys
import re
from pathlib import Path
import fileinput

""" This script is intended to fix the issue with flash strings on ESP866 described """
""" in issue #8 (https://github.com/frankjoshua/rosserial_arduino_lib/issues/8) """
""" It can also be used on the raw output of the rosserial_arduino library creation """
""" routines to add flash strings as appropriate. """
""" Written by Pierce Nichols (rocketgeek@gmail.com) 9/28/29 """

gettype_pattern = re.compile(r'^\s*const char \* getType\(\)\{\s*return\s*(PSTR|)\s*\(\s*"([\w/_]*)"\s*\);\s*\};\s*$')
getmd5_pattern = re.compile(r'^\s*const char \* getMD5\(\)\{\s*return\s*(PSTR|)\s*\(\s*"([0-9a-f]*)"\s*\);\s*\};\s*$')
getprogmem_pattern = re.compile(r'^\s*static const char ([A-Z]*)\[\] PROGMEM = "([\w/_]*)"\s*;\s*$')
code_start = ' const char * '
code_end = '");};'
code_gettype = 'getType() { return '
code_md5 = 'getMD5() { return '
code_norm = ' ("'
code_pstr = ' PSTR("'
pm_start = ' static const char '
pm_progmem = '[] PROGMEM = "'
pm_norm = '[] = "'
pm_end = '";'

def process_header (path_to_header):
for line in fileinput.input(path_to_header, inplace=True):
line = line.rstrip('\r\n')
gt_match = gettype_pattern.search(line)
md_match = getmd5_pattern.search(line)
pm_match = getprogmem_pattern.search(line)
if (gt_match):
print(" #ifdef ESP8266")
print(code_start + code_gettype + code_norm + gt_match.group(2) + code_end)
print(" #else")
print(code_start + code_gettype + code_pstr + gt_match.group(2) + code_end)
print(" #endif")
elif (md_match):
print(" #ifdef ESP8266")
print(code_start + code_md5 + code_norm + md_match.group(2) + code_end)
print(" #else")
print(code_start + code_md5 + code_pstr + md_match.group(2) + code_end)
print(" #endif")
elif (pm_match):
print("#ifdef ESP8266")
print(pm_start + pm_match.group(1) + pm_norm + pm_match.group(2) + pm_end)
print("#else")
print(pm_start + pm_match.group(1) + pm_progmem + pm_match.group(2) + pm_end)
print("#endif")
else:
print(line)

rootpath = sys.argv[1] # First argument is the root of the directory tree to fix
p = Path(rootpath) # Turn it into a path
header_list = list(p.glob('**/*.h')) # Grab a list of all the header files in this directory tree
for header in header_list:
process_header(header)
14 changes: 11 additions & 3 deletions src/actionlib/TestAction.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestAction" ); };
const char * getMD5(){ return PSTR( "991e87a72802262dfbe5d1b3cf6efc9a" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestAction");};
#else
const char * getType() { return PSTR("actionlib/TestAction");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("991e87a72802262dfbe5d1b3cf6efc9a");};
#else
const char * getMD5() { return PSTR("991e87a72802262dfbe5d1b3cf6efc9a");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestActionFeedback.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestActionFeedback" ); };
const char * getMD5(){ return PSTR( "6d3d0bf7fb3dda24779c010a9f3eb7cb" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestActionFeedback");};
#else
const char * getType() { return PSTR("actionlib/TestActionFeedback");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("6d3d0bf7fb3dda24779c010a9f3eb7cb");};
#else
const char * getMD5() { return PSTR("6d3d0bf7fb3dda24779c010a9f3eb7cb");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestActionGoal.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestActionGoal" ); };
const char * getMD5(){ return PSTR( "348369c5b403676156094e8c159720bf" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestActionGoal");};
#else
const char * getType() { return PSTR("actionlib/TestActionGoal");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("348369c5b403676156094e8c159720bf");};
#else
const char * getMD5() { return PSTR("348369c5b403676156094e8c159720bf");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestActionResult.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestActionResult" ); };
const char * getMD5(){ return PSTR( "3d669e3a63aa986c667ea7b0f46ce85e" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestActionResult");};
#else
const char * getType() { return PSTR("actionlib/TestActionResult");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("3d669e3a63aa986c667ea7b0f46ce85e");};
#else
const char * getMD5() { return PSTR("3d669e3a63aa986c667ea7b0f46ce85e");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestFeedback.h
Expand Up @@ -54,10 +54,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestFeedback" ); };
const char * getMD5(){ return PSTR( "49ceb5b32ea3af22073ede4a0328249e" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestFeedback");};
#else
const char * getType() { return PSTR("actionlib/TestFeedback");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("49ceb5b32ea3af22073ede4a0328249e");};
#else
const char * getMD5() { return PSTR("49ceb5b32ea3af22073ede4a0328249e");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestGoal.h
Expand Up @@ -54,10 +54,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestGoal" ); };
const char * getMD5(){ return PSTR( "18df0149936b7aa95588e3862476ebde" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestGoal");};
#else
const char * getType() { return PSTR("actionlib/TestGoal");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("18df0149936b7aa95588e3862476ebde");};
#else
const char * getMD5() { return PSTR("18df0149936b7aa95588e3862476ebde");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestAction.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestAction" ); };
const char * getMD5(){ return PSTR( "dc44b1f4045dbf0d1db54423b3b86b30" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestAction");};
#else
const char * getType() { return PSTR("actionlib/TestRequestAction");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("dc44b1f4045dbf0d1db54423b3b86b30");};
#else
const char * getMD5() { return PSTR("dc44b1f4045dbf0d1db54423b3b86b30");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestActionFeedback.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestActionFeedback" ); };
const char * getMD5(){ return PSTR( "aae20e09065c3809e8a8e87c4c8953fd" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestActionFeedback");};
#else
const char * getType() { return PSTR("actionlib/TestRequestActionFeedback");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("aae20e09065c3809e8a8e87c4c8953fd");};
#else
const char * getMD5() { return PSTR("aae20e09065c3809e8a8e87c4c8953fd");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestActionGoal.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestActionGoal" ); };
const char * getMD5(){ return PSTR( "1889556d3fef88f821c7cb004e4251f3" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestActionGoal");};
#else
const char * getType() { return PSTR("actionlib/TestRequestActionGoal");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("1889556d3fef88f821c7cb004e4251f3");};
#else
const char * getMD5() { return PSTR("1889556d3fef88f821c7cb004e4251f3");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestActionResult.h
Expand Up @@ -48,10 +48,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestActionResult" ); };
const char * getMD5(){ return PSTR( "0476d1fdf437a3a6e7d6d0e9f5561298" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestActionResult");};
#else
const char * getType() { return PSTR("actionlib/TestRequestActionResult");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("0476d1fdf437a3a6e7d6d0e9f5561298");};
#else
const char * getMD5() { return PSTR("0476d1fdf437a3a6e7d6d0e9f5561298");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestFeedback.h
Expand Up @@ -30,10 +30,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestFeedback" ); };
const char * getMD5(){ return PSTR( "d41d8cd98f00b204e9800998ecf8427e" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestFeedback");};
#else
const char * getType() { return PSTR("actionlib/TestRequestFeedback");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("d41d8cd98f00b204e9800998ecf8427e");};
#else
const char * getMD5() { return PSTR("d41d8cd98f00b204e9800998ecf8427e");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestGoal.h
Expand Up @@ -207,10 +207,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestGoal" ); };
const char * getMD5(){ return PSTR( "db5d00ba98302d6c6dd3737e9a03ceea" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestGoal");};
#else
const char * getType() { return PSTR("actionlib/TestRequestGoal");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("db5d00ba98302d6c6dd3737e9a03ceea");};
#else
const char * getMD5() { return PSTR("db5d00ba98302d6c6dd3737e9a03ceea");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestRequestResult.h
Expand Up @@ -72,10 +72,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestRequestResult" ); };
const char * getMD5(){ return PSTR( "61c2364524499c7c5017e2f3fce7ba06" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestRequestResult");};
#else
const char * getType() { return PSTR("actionlib/TestRequestResult");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("61c2364524499c7c5017e2f3fce7ba06");};
#else
const char * getMD5() { return PSTR("61c2364524499c7c5017e2f3fce7ba06");};
#endif

};

}
#endif
#endif
14 changes: 11 additions & 3 deletions src/actionlib/TestResult.h
Expand Up @@ -54,10 +54,18 @@ namespace actionlib
return offset;
}

const char * getType(){ return PSTR( "actionlib/TestResult" ); };
const char * getMD5(){ return PSTR( "034a8e20d6a306665e3a5b340fab3f09" ); };
#ifdef ESP8266
const char * getType() { return ("actionlib/TestResult");};
#else
const char * getType() { return PSTR("actionlib/TestResult");};
#endif
#ifdef ESP8266
const char * getMD5() { return ("034a8e20d6a306665e3a5b340fab3f09");};
#else
const char * getMD5() { return PSTR("034a8e20d6a306665e3a5b340fab3f09");};
#endif

};

}
#endif
#endif

0 comments on commit c8072e7

Please sign in to comment.