Browse Source

0.8.113

* code cleanup
* fix ESP32-C3 compile
pull/1626/head
lumapu 9 months ago
parent
commit
177420fce2
  1. 4
      src/CHANGES.md
  2. 2
      src/defines.h
  3. 34
      src/hm/hmInverter.h
  4. 6
      src/hm/hmSystem.h
  5. 2
      src/hm/nrfHal.h
  6. 2
      src/hms/cmtHal.h
  7. 3
      src/plugins/Display/epdHal.h
  8. 10
      src/utils/spiPatcher.h
  9. 2
      src/web/RestApi.h

4
src/CHANGES.md

@ -1,5 +1,9 @@
# Development Changes
## 0.8.113 - 2024-04-25
* code cleanup
* fix ESP32-C3 compile
## 0.8.112 - 2024-04-24
* improved wizard
* converted ePaper and Ethernet to hal-SPI

2
src/defines.h

@ -13,7 +13,7 @@
//-------------------------------------
#define VERSION_MAJOR 0
#define VERSION_MINOR 8
#define VERSION_PATCH 112
#define VERSION_PATCH 113
//-------------------------------------
typedef struct {
uint8_t ch;

34
src/hm/hmInverter.h

@ -84,7 +84,7 @@ struct record_t {
byteAssign_t* assign = nullptr; // assignment of bytes in payload
uint8_t length = 0; // length of the assignment list
T *record = nullptr; // data pointer
uint32_t ts = 0; // timestamp of last received payload
uint32_t ts = 0; // Timestamp of last received payload
uint8_t pyldLen = 0; // expected payload length for plausibility check
MqttSentStatus mqttSentStatus = MqttSentStatus:: NEW_DATA; // indicates the current MqTT sent status
};
@ -146,7 +146,7 @@ class Inverter {
statistics_t radioStatistics; // information about transmitted, failed, ... packets
HeuristicInv heuristics; // heuristic information / logic
uint8_t curCmtFreq = 0; // current used CMT frequency, used to check if freq. was changed during runtime
uint32_t tsMaxAcPower = 0; // holds the timestamp when the MaxAC power was seen
uint32_t tsMaxAcPower = 0; // holds the Timestamp when the MaxAC power was seen
bool commEnabled = true; // 'pause night communication' sets this field to false
public:
@ -189,7 +189,7 @@ class Inverter {
cb(InverterDevInform_Simple, false); // get hardware version
} else if((alarmLastId != alarmMesIndex) && (alarmMesIndex != 0)) {
cb(AlarmData, false); // get last alarms
} else if((0 == mGridLen) && generalConfig->readGrid) { // read grid profile
} else if((0 == mGridLen) && GeneralConfig->readGrid) { // read grid profile
cb(GridOnProFilePara, false);
} else if (mGetLossInterval > AHOY_GET_LOSS_INTERVAL) { // get loss rate
mGetLossInterval = 1;
@ -213,7 +213,7 @@ class Inverter {
if (getChannelFieldValue(CH0, FLD_PART_NUM, rec) == 0) {
cb(0x0f, false); // hard- and firmware version for missing HW part nr, delivered by frame 1
mIvRxCnt +=2;
} else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && generalConfig->readGrid) // read grid profile
} else if((getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec) == 0) && GeneralConfig->readGrid) // read grid profile
cb(0x10, false); // legacy GPF command
}
}
@ -270,16 +270,18 @@ class Inverter {
if(InverterStatus::OFF != status) {
mDevControlRequest = true;
devControlCmd = cmd;
//assert(App);
//App->triggerTickSend(0);
assert(App);
App->triggerTickSend(id);
return true;
}
return (InverterStatus::OFF != status);
return false;
}
bool setDevCommand(uint8_t cmd) {
if(InverterStatus::OFF != status)
bool retval = (InverterStatus::OFF != status);
if(retval)
devControlCmd = cmd;
return (InverterStatus::OFF != status);
return retval;
}
void addValue(uint8_t pos, const uint8_t buf[], record_t<> *rec) {
@ -409,14 +411,14 @@ class Inverter {
if(recordMeas.ts == 0)
return false;
if(((*timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
if(((*Timestamp) - recordMeas.ts) < INVERTER_INACT_THRES_SEC)
avail = true;
if(avail) {
if(status < InverterStatus::PRODUCING)
status = InverterStatus::STARTING;
} else {
if(((*timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
if(((*Timestamp) - recordMeas.ts) > INVERTER_OFF_THRES_SEC) {
if(status != InverterStatus::OFF) {
status = InverterStatus::OFF;
actPowerLimit = 0xffff; // power limit will be read once inverter becomes available
@ -817,8 +819,8 @@ class Inverter {
}
public:
static uint32_t *timestamp; // system timestamp
static cfgInst_t *generalConfig; // general inverter configuration from setup
static uint32_t *Timestamp; // system timestamp
static cfgInst_t *GeneralConfig; // general inverter configuration from setup
static IApp *App;
uint16_t mDtuRxCnt = 0;
@ -837,9 +839,9 @@ class Inverter {
};
template <class REC_TYP>
uint32_t *Inverter<REC_TYP>::timestamp {0};
uint32_t *Inverter<REC_TYP>::Timestamp {0};
template <class REC_TYP>
cfgInst_t *Inverter<REC_TYP>::generalConfig {0};
cfgInst_t *Inverter<REC_TYP>::GeneralConfig {0};
template <class REC_TYP>
IApp *Inverter<REC_TYP>::App {nullptr};
@ -948,7 +950,7 @@ T calcMaxPowerAcCh0(Inverter<> *iv, uint8_t arg0) {
}
}
if(acPower > acMaxPower) {
iv->tsMaxAcPower = *iv->timestamp;
iv->tsMaxAcPower = *iv->Timestamp;
return acPower;
}
}

6
src/hm/hmSystem.h

@ -16,8 +16,8 @@ class HmSystem {
HmSystem() {}
void setup(uint32_t *timestamp, cfgInst_t *config, IApp *app) {
INVERTERTYPE::timestamp = timestamp;
INVERTERTYPE::generalConfig = config;
INVERTERTYPE::Timestamp = timestamp;
INVERTERTYPE::GeneralConfig = config;
INVERTERTYPE::App = app;
//mInverter[0].app = app;
}
@ -26,7 +26,7 @@ class HmSystem {
DPRINTLN(DBG_VERBOSE, F("hmSystem.h:addInverter"));
INVERTERTYPE *iv = &mInverter[id];
iv->id = id;
iv->config = &mInverter[0].generalConfig->iv[id];
iv->config = &INVERTERTYPE::GeneralConfig->iv[id];
DPRINT(DBG_VERBOSE, "SERIAL: " + String(iv->config->serial.b[5], HEX));
DPRINTLN(DBG_VERBOSE, " " + String(iv->config->serial.b[4], HEX));
if((iv->config->serial.b[5] == 0x11) || (iv->config->serial.b[5] == 0x10)) {

2
src/hm/nrfHal.h

@ -42,7 +42,7 @@ class nrfHal: public RF24_hal, public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI2_HOST;
#else
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif
mSpiPatcher = SpiPatcher::getInstance(mHostDevice);

2
src/hms/cmtHal.h

@ -40,7 +40,7 @@ class cmtHal : public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI2_HOST;
#else
mHostDevice = (14 == clk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == clk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif
mSpiPatcher = SpiPatcher::getInstance(mHostDevice);

3
src/plugins/Display/epdHal.h

@ -11,6 +11,7 @@
#include <esp_rom_gpio.h>
#include <GxEPD2_BW.h>
#define EPD_DEFAULT_SPI_SPEED 4000000 // 4 MHz
class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
@ -41,7 +42,7 @@ class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
#if defined(CONFIG_IDF_TARGET_ESP32S3)
mHostDevice = SPI3_HOST;
#else
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI3_HOST;
mHostDevice = (14 == sclk) ? SPI2_HOST : SPI_HOST_OTHER;
#endif
mSpiPatcher = SpiPatcher::getInstance(mHostDevice);

10
src/utils/spiPatcher.h

@ -15,6 +15,12 @@
#include <driver/spi_master.h>
#include <freertos/semphr.h>
#if (SOC_SPI_PERIPH_NUM > 2)
#define SPI_HOST_OTHER SPI3_HOST
#else
#define SPI_HOST_OTHER SPI2_HOST
#endif
class SpiPatcher {
protected:
explicit SpiPatcher(spi_host_device_t dev) :
@ -74,8 +80,10 @@ class SpiPatcher {
assert(mBusState == ESP_OK);
if(SPI2_HOST == host_id)
mHost2Cnt++;
#if (SOC_SPI_PERIPH_NUM > 2)
if(SPI3_HOST == host_id)
mHost3Cnt++;
#endif
if((mHost2Cnt > 3) || (mHost3Cnt > 3))
DPRINTLN(DBG_ERROR, F("maximum number of SPI devices reached (3)"));
@ -112,7 +120,7 @@ class SpiPatcher {
SemaphoreHandle_t mutex;
StaticSemaphore_t mutex_buffer;
uint8_t mHost2Cnt = 0, mHost3Cnt = 0;
spi_host_device_t mDev = SPI3_HOST;
spi_host_device_t mDev = SPI2_HOST;
esp_err_t mBusState = ESP_FAIL;
spi_bus_config_t mBusConfig;
};

2
src/web/RestApi.h

@ -1014,8 +1014,6 @@ class RestApi {
iv->powerLimit[1] = AbsolutNonPersistent;
accepted = iv->setDevControlRequest(ActivePowerContr);
if(accepted)
mApp->triggerTickSend(iv->id);
} else if(F("dev") == jsonIn[F("cmd")]) {
DPRINTLN(DBG_INFO, F("dev cmd"));
iv->setDevCommand(jsonIn[F("val")].as<int>());

Loading…
Cancel
Save