From aeb63f5d312026bcc53b1733a6a16b52808cbb09 Mon Sep 17 00:00:00 2001 From: lumapu Date: Thu, 30 Jun 2022 22:28:54 +0200 Subject: [PATCH] * compiles with PlatformIO --- tools/esp8266/.gitignore | 5 + tools/esp8266/app.cpp | 5 +- tools/esp8266/app.h | 2 +- tools/esp8266/defines.h | 2 +- tools/esp8266/{esp8266.ino => esp8266.cpp} | 21 +-- tools/esp8266/hmDefines.h | 2 +- tools/esp8266/hmRadio.h | 1 + tools/esp8266/main.h | 7 +- tools/esp8266/mqtt.h | 4 +- tools/esp8266/platformio.ini | 16 ++ .../esp8266/test/hmClassTest/hmClassTest.sln | 31 ---- .../hmClassTest/hmClassTest.vcxproj | 147 ------------------ .../hmClassTest/hmClassTest.vcxproj.filters | 22 --- .../hmClassTest/hmClassTest.vcxproj.user | 4 - tools/esp8266/test/hmClassTest/src/main.cpp | 105 ------------- 15 files changed, 39 insertions(+), 335 deletions(-) create mode 100644 tools/esp8266/.gitignore rename tools/esp8266/{esp8266.ino => esp8266.cpp} (80%) create mode 100644 tools/esp8266/platformio.ini delete mode 100644 tools/esp8266/test/hmClassTest/hmClassTest.sln delete mode 100644 tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj delete mode 100644 tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.filters delete mode 100644 tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.user delete mode 100644 tools/esp8266/test/hmClassTest/src/main.cpp diff --git a/tools/esp8266/.gitignore b/tools/esp8266/.gitignore new file mode 100644 index 00000000..89cc49cb --- /dev/null +++ b/tools/esp8266/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 1b05bf3e..6b043b18 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -84,8 +84,7 @@ void app::setup(uint32_t timeout) { DPRINTLN(DBG_INFO, F("add inverter: ") + String(name) + ", SN: " + String(invSerial, HEX)); for(uint8_t j = 0; j < 4; j++) { - mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, name, MAX_NAME_LENGTH); - snprintf(iv->chName[j], MAX_NAME_LENGTH, "%s", name); + mEep->read(ADDR_INV_CH_NAME + (i * 4 * MAX_NAME_LENGTH) + j * MAX_NAME_LENGTH, iv->chName[j], MAX_NAME_LENGTH); } } @@ -375,7 +374,7 @@ void app::handleIntr(void) { //----------------------------------------------------------------------------- bool app::buildPayload(uint8_t id) { DPRINTLN(DBG_VERBOSE, F("app::buildPayload")); - uint16_t crc = 0xffff, crcRcv; + uint16_t crc = 0xffff, crcRcv = 0x0000; if(mPayload[id].maxPackId > MAX_PAYLOAD_ENTRIES) mPayload[id].maxPackId = MAX_PAYLOAD_ENTRIES; diff --git a/tools/esp8266/app.h b/tools/esp8266/app.h index 1970ed7d..f8d6cc68 100644 --- a/tools/esp8266/app.h +++ b/tools/esp8266/app.h @@ -6,11 +6,11 @@ #ifndef __APP_H__ #define __APP_H__ +#include "main.h" #include #include #include "defines.h" -#include "main.h" #include "CircularBuffer.h" #include "hmSystem.h" diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index f12bcba6..9df39440 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -21,7 +21,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 4 -#define VERSION_PATCH 21 +#define VERSION_PATCH 22 //------------------------------------- diff --git a/tools/esp8266/esp8266.ino b/tools/esp8266/esp8266.cpp similarity index 80% rename from tools/esp8266/esp8266.ino rename to tools/esp8266/esp8266.cpp index 4ddd706a..72caa280 100644 --- a/tools/esp8266/esp8266.ino +++ b/tools/esp8266/esp8266.cpp @@ -3,19 +3,18 @@ // Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ //----------------------------------------------------------------------------- -#include "Arduino.h" - -#include -#include -#include -#include - -#include +#include "dbg.h" #include "app.h" #include "config.h" app myApp; +//----------------------------------------------------------------------------- +IRAM_ATTR void handleIntr(void) { + myApp.handleIntr(); +} + + //----------------------------------------------------------------------------- void setup() { myApp.setup(WIFI_TRY_CONNECT_TIME); @@ -29,9 +28,3 @@ void setup() { void loop() { myApp.loop(); } - - -//----------------------------------------------------------------------------- -ICACHE_RAM_ATTR void handleIntr(void) { - myApp.handleIntr(); -} diff --git a/tools/esp8266/hmDefines.h b/tools/esp8266/hmDefines.h index 38a2fc4e..fabd596c 100644 --- a/tools/esp8266/hmDefines.h +++ b/tools/esp8266/hmDefines.h @@ -6,7 +6,7 @@ #ifndef __HM_DEFINES_H__ #define __HM_DEFINES_H__ -#include "debug.h" +#include "dbg.h" #include diff --git a/tools/esp8266/hmRadio.h b/tools/esp8266/hmRadio.h index bb750b15..18058e76 100644 --- a/tools/esp8266/hmRadio.h +++ b/tools/esp8266/hmRadio.h @@ -6,6 +6,7 @@ #ifndef __RADIO_H__ #define __RADIO_H__ +#include "dbg.h" #include #include #include "crc.h" diff --git a/tools/esp8266/main.h b/tools/esp8266/main.h index 6f051694..68f9df5c 100644 --- a/tools/esp8266/main.h +++ b/tools/esp8266/main.h @@ -6,6 +6,7 @@ #ifndef __MAIN_H__ #define __MAIN_H__ +#include "dbg.h" #include "Arduino.h" #include @@ -21,7 +22,6 @@ #include "eep.h" #include "defines.h" #include "crc.h" -#include "debug.h" const byte mDnsPort = 53; @@ -108,8 +108,9 @@ class Main { uint16_t max; uint8_t frag; ESP.getHeapStats(&free, &max, &frag); - - Serial.printf("free: 0x%x - max: 0x%x - frag: %d%%\n", free, max, frag); + DPRINT(DBG_VERBOSE, F("free: ") + String(free)); + DPRINT(DBG_VERBOSE, F(" - max: ") + String(max) + "%"); + DPRINTLN(DBG_VERBOSE, F(" - frag: ") + String(frag)); } char mStationSsid[SSID_LEN]; diff --git a/tools/esp8266/mqtt.h b/tools/esp8266/mqtt.h index 79dbecc5..0ed21cb3 100644 --- a/tools/esp8266/mqtt.h +++ b/tools/esp8266/mqtt.h @@ -21,9 +21,7 @@ class mqtt { memset(mTopic, 0, MQTT_TOPIC_LEN); } - ~mqtt() { - delete mClient; - } + ~mqtt() { } void setup(const char *broker, const char *topic, const char *user, const char *pwd, uint16_t port) { DPRINTLN(DBG_VERBOSE, F("mqtt.h:setup")); diff --git a/tools/esp8266/platformio.ini b/tools/esp8266/platformio.ini new file mode 100644 index 00000000..e5c80a45 --- /dev/null +++ b/tools/esp8266/platformio.ini @@ -0,0 +1,16 @@ +[platformio] +src_dir = . + +[env:d1_mini] +platform = espressif8266 +framework = arduino +board = d1_mini +monitor_speed = 115200 +board_build.f_cpu = 80000000L +;build_flags = -DDEBUG_ESP_PORT=Serial + +lib_deps = + RF24 + PubSubClient + Time + ESP Async WebServer diff --git a/tools/esp8266/test/hmClassTest/hmClassTest.sln b/tools/esp8266/test/hmClassTest/hmClassTest.sln deleted file mode 100644 index a303a142..00000000 --- a/tools/esp8266/test/hmClassTest/hmClassTest.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.32002.261 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hmClassTest", "hmClassTest\hmClassTest.vcxproj", "{4D899C12-DE0E-4CDB-B48C-FDFEC331F219}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Debug|x64.ActiveCfg = Debug|x64 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Debug|x64.Build.0 = Debug|x64 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Debug|x86.ActiveCfg = Debug|Win32 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Debug|x86.Build.0 = Debug|Win32 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Release|x64.ActiveCfg = Release|x64 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Release|x64.Build.0 = Release|x64 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Release|x86.ActiveCfg = Release|Win32 - {4D899C12-DE0E-4CDB-B48C-FDFEC331F219}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {7C291F74-09F6-4C84-99E1-6E7294062385} - EndGlobalSection -EndGlobal diff --git a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj b/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj deleted file mode 100644 index bbf9cbd2..00000000 --- a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj +++ /dev/null @@ -1,147 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - - - - 16.0 - Win32Proj - {4d899c12-de0e-4cdb-b48c-fdfec331f219} - hmClassTest - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.filters b/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.filters deleted file mode 100644 index fee0814f..00000000 --- a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Quelldateien - - - \ No newline at end of file diff --git a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.user b/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.user deleted file mode 100644 index 88a55094..00000000 --- a/tools/esp8266/test/hmClassTest/hmClassTest/hmClassTest.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/esp8266/test/hmClassTest/src/main.cpp b/tools/esp8266/test/hmClassTest/src/main.cpp deleted file mode 100644 index 3b30364d..00000000 --- a/tools/esp8266/test/hmClassTest/src/main.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#ifdef _MSC_VER -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include -#include -#include -#include - - -//----------------------------------------------------------------------------- -#define MAX_NUM_INVERTERS 3 -#define MAX_NAME_LENGTH 16 -#define NDEBUG -#define NO_RADIO - -#include "../../../hmDefines.h" -#include "../../../hmInverter.h" -#include "../../../hmSystem.h" - - - -//----------------------------------------------------------------------------- -typedef int RadioType; -typedef int BufferType; -typedef Inverter InverterType; -typedef HmSystem HmSystemType; - - -//----------------------------------------------------------------------------- -void valToBuf(InverterType *iv, uint8_t fld, uint8_t ch, float val, uint8_t bufPos); - - -//----------------------------------------------------------------------------- -int main(int argc, char* argv[]) { - HmSystemType sys; - InverterType *iv0, *iv1; - uint8_t buf[30] = { 0xcc }; - - iv0 = sys.addInverter("HM1200", 0x1122334455ULL, INV_TYPE_HM1200); - iv1 = sys.addInverter("HM600", 0x1234567891ULL, INV_TYPE_HM600); - - valToBuf(iv0, FLD_UDC, CH1, 29.5, 3); - valToBuf(iv0, FLD_UDC, CH3, 30.6, 9); - valToBuf(iv0, FLD_YD, CH1, 1234, 5); - valToBuf(iv0, FLD_YD, CH2, 1199, 7); - valToBuf(iv0, FLD_YD, CH3, 899, 11); - valToBuf(iv0, FLD_YD, CH4, 932, 13); - valToBuf(iv0, FLD_YT, CH1, 40.123, 13); - valToBuf(iv0, FLD_YT, CH2, 57.231, 1); - valToBuf(iv0, FLD_YT, CH3, 59.372, 3); - valToBuf(iv0, FLD_YT, CH4, 43.966, 7); - - iv0->doCalculations(); - for(uint8_t i = 0; i < iv0->listLen; i ++) { - float val = iv0->getValue(i); - if(0.0 != val) { - printf("%10s [CH%d] = %.3f %s\n", iv0->getFieldName(i), iv0->getChannel(i), val, iv0->getUnit(i)); - } - } - - return 0; -} - - -//----------------------------------------------------------------------------- -void valToBuf(InverterType *iv, uint8_t fld, uint8_t ch, float val, uint8_t bufPos) { - uint8_t buf[30] = { 0xcc }; - uint8_t len; - uint16_t factor; - - switch(fld) { - default: len = 2; break; - case FLD_YT: len = 4; break; - } - - switch(fld) { - case FLD_YD: factor = 1; break; - case FLD_UDC: - case FLD_PDC: - case FLD_UAC: - case FLD_PAC: - case FLD_PCT: - case FLD_T: factor = 10; break; - case FLD_IDC: - case FLD_IAC: - case FLD_F: factor = 100; break; - default: factor = 1000; break; - } - - uint8_t *p = &buf[bufPos]; - - uint32_t intval = (uint32_t)(val * factor); - if(2 == len) { - p[0] = (intval >> 8) & 0xff; - p[1] = (intval ) & 0xff; - } - else { - p[0] = (intval >> 24) & 0xff; - p[1] = (intval >> 16) & 0xff; - p[2] = (intval >> 8) & 0xff; - p[3] = (intval ) & 0xff; - } - iv->addValue(iv->getPosByChFld(ch, fld), buf); -}