Merge pull request #125 from mp-se/dev

Fix bug in template engine
This commit is contained in:
Magnus 2023-01-24 21:12:39 +01:00 committed by GitHub
commit cd1ada6744
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 61 additions and 10 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +1 @@
{ "project":"gravmon", "version":"1.2.0", "html": [ ] }
{ "project":"gravmon", "version":"1.2.1", "html": [ ] }

View File

@ -39,7 +39,7 @@ build_flags =
-DUSE_LITTLEFS=true
-DUSER_SSID=\""\"" # =\""myssid\""
-DUSER_SSID_PWD=\""\"" # =\""mypwd\""
-DCFG_APPVER="\"1.2.0\""
-DCFG_APPVER="\"1.2.1\""
#-DCFG_GITREV=\""beta-3\""
!python script/git_rev.py
lib_deps =
@ -102,8 +102,10 @@ lib_deps =
${common_env_data.lib_deps}
board = ${common_env_data.board}
build_type = release
#build_type = debug
board_build.filesystem = littlefs
build_src_filter = +<*> -<../test/tests*.cpp>
monitor_filters = esp8266_exception_decoder
[env:gravity-unit]
upload_speed = ${common_env_data.upload_speed}
@ -120,9 +122,10 @@ lib_deps =
https://github.com/bxparks/AUnit#v1.6.1
${common_env_data.lib_deps}
board = ${common_env_data.board}
build_type = release
build_type = debug
board_build.filesystem = littlefs
build_src_filter = +<*> -<main.cpp> +<../test/tests*.cpp>
monitor_filters = esp8266_exception_decoder
[env:gravity32-release]
framework = ${common_env_data.framework}

View File

@ -194,4 +194,17 @@ const char* TemplatingEngine::create(TemplatingEngine::Templates idx,
return "";
}
// added to support more unit test scenarios.
const char* TemplatingEngine::create(const char* formatTemplate) {
_baseTemplate = String(formatTemplate);
// Insert data into template.
transform();
_baseTemplate.clear();
if (_output) return _output;
return "";
}
// EOF

View File

@ -160,7 +160,8 @@ class TemplatingEngine {
}
}
}
strncat(_output, format + k, size - k);
// strncat(_output, format + k, size - k);
strncat(_output, format + k, strlen(format + k));
Log.notice(F("TPL : Transformed template %d chars to %d chars" CR),
strlen(format), strlen(_output));
@ -202,6 +203,7 @@ class TemplatingEngine {
float tempC, float runTime);
const char *create(TemplatingEngine::Templates idx,
bool useDefaultTemplate = false);
const char *create(const char *formatTemplate);
};
#endif // SRC_TEMPLATING_HPP_

View File

@ -7,7 +7,7 @@ Welcome to GravityMon
#####################
.. note::
This documentation reflects **v1.2.0**. Last updated 2022-12-06
This documentation reflects **v1.2.1**. Last updated 2023-01-23
What is GravityMon?
--------------------

View File

@ -3,6 +3,17 @@
Releases
########
v1.2.1
======
Issues adressed
++++++++++++++++
* BUG: Under some circumstances the last part of the format template was omitted.
Other
+++++
* Update tinyexpr library to latest baseline. For forumula evaluation.
v1.2.0
======

View File

@ -125,4 +125,26 @@ test(template_applyTemplate5) {
assertEqual(s, v);
}
test(template_applyTemplate6) {
TemplatingEngine e;
char buffer[20];
myConfig.setMDNS("gravitymon");
const char* tpl =
"<prtg><result><channel>Densite</channel><float>1</float><value>${gravity}</value></result>"
"<result><channel>Batterie</channel><float>1</float><value>${battery}</value></result>"
"<result><channel>Temperature</channel><float>1</float><value>${temp}</value></result></prtg>";
e.initialize(45.0, 1.123, 1.223, 21.2, 2.98);
String s = e.create(tpl);
String batt =
convertFloatToString(myBatteryVoltage.getVoltage(), &buffer[0], 2);
batt.trim();
String v = "<prtg><result><channel>Densite</channel><float>1</float><value>1.1230</value></result>"
"<result><channel>Batterie</channel><float>1</float><value>" + batt + "</value></result>"
"<result><channel>Temperature</channel><float>1</float><value>21.2</value></result></prtg>";
assertEqual(s, v);
}
// EOF