Skip to content

Commit

Permalink
Bump version to v1.4.3
Browse files Browse the repository at this point in the history
* Add component
* Fix format ERaString...
  • Loading branch information
hung-eoh committed Nov 6, 2024
1 parent 1353e73 commit 5c9cf12
Show file tree
Hide file tree
Showing 28 changed files with 876 additions and 235 deletions.
6 changes: 6 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ setModbusStream KEYWORD2
setModbusDEPin KEYWORD2
setModbusDelays KEYWORD2
setModbusFailCounter KEYWORD2
setModbusLegacyProcess KEYWORD2
setModbusTimeout KEYWORD2
setModbusStreamTimeout KEYWORD2
setModbusInterval KEYWORD2
Expand Down Expand Up @@ -224,10 +225,12 @@ ERA_PIN_READ KEYWORD2
ERA_WRITE_DEFAULT KEYWORD2
ERA_PIN_WRITE_DEFAULT KEYWORD2
ERA_PIN_READ_DEFAULT KEYWORD2
ERA_REPORTABLE_CHANGE_PIN KEYWORD2
ERA_ON_CHANGE KEYWORD2
ERA_ON_RECEIVE KEYWORD2
ERA_ON_CHANGE_DEFAULT KEYWORD2
ERA_ON_RECEIVE_DEFAULT KEYWORD2
ERA_ON_PUBLISH_PROPERTY KEYWORD2
ERA_CONNECTED KEYWORD2
ERA_DISCONNECTED KEYWORD2
ERA_WAITING KEYWORD2
Expand All @@ -238,6 +241,8 @@ ERA_MODBUS_INFO KEYWORD2
ERA_INFO KEYWORD2
ERA_WRITE_CONFIG KEYWORD2
ERA_ATTACH_RUN KEYWORD2
ERA_DECIMAL_FLOAT KEYWORD2
ERA_DECIMAL_DOUBLE KEYWORD2

# Special defines
ERA_LOG KEYWORD2
Expand All @@ -263,6 +268,7 @@ MODBUS_STREAM_TIMEOUT KEYWORD2
ZIGBEE_BAUDRATE KEYWORD2
ZIGBEE_RXD_Pin KEYWORD2
ZIGBEE_TXD_Pin KEYWORD2
ZIGBEE_DECIMAL_VALUE KEYWORD2
ZIGBEE_STREAM_TIMEOUT KEYWORD2
ZIGBEE_PUBLISH_RETAINED KEYWORD2

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ERa",
"version": "1.4.2",
"version": "1.4.3",
"description": "E-Ra by EoH. An IoT Market Enabler! It supports WiFi, Ethernet, Zigbee, Modbus, Serial. Works with boards like Arduino, ESP8266, ESP32, STM32, Raspberry Pi...",
"keywords": "ERa, E-Ra, esp8266, esp32, stm32, raspberry-pi, http, mqtt, zigbee, modbus, sensors, control, device, smartphone, mobile, app, web, cloud, communication, protocol, iot, wifi, ethernet, serial",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ERa
version=1.4.2
version=1.4.3
author=EoH Ltd
license=MIT
maintainer=EoH Ltd <info@eoh.io>
Expand Down
4 changes: 4 additions & 0 deletions linux/MQTT/ERaMqttLinux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class ERaMqttLinux
bool publishState(bool online);
bool syncConfig();

void setConnected(bool enable) {
this->_connected = enable;
}

void setTimeout(uint32_t timeout) {
this->mqtt.setTimeout(timeout);
}
Expand Down
6 changes: 3 additions & 3 deletions linux/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

ERA_MAJOR = 1
ERA_MINOR = 4
ERA_PATCH = 2
ERA_VERSION = "1.4.2"
ERA_FIRMWARE_VERSION = "1.4.2"
ERA_PATCH = 3
ERA_VERSION = "1.4.3"
ERA_FIRMWARE_VERSION = "1.4.3"

BUTTON_GPIO = 16

Expand Down
117 changes: 104 additions & 13 deletions src/ERa/ERaApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ERa/ERaTransp.hpp>
#include <ERa/ERaTimer.hpp>
#include <ERa/ERaApiHandler.hpp>
#include <ERa/ERaComponentHandler.hpp>
#include <Utility/ERaQueue.hpp>
#include <Modbus/ERaModbusSimple.hpp>
#include <Zigbee/ERaZigbeeSimple.hpp>
Expand All @@ -21,6 +22,7 @@
template <class Proto, class Flash>
class ERaApi
: public ERaApiHandler
, public ERaComponentHandler
#if !defined(ERA_ABBR)
, public ERaProperty< ERaApi<Proto, Flash> >
#endif
Expand All @@ -44,6 +46,7 @@ class ERaApi

typedef void* TaskHandle_t;
typedef ERaApiHandler Handler;
typedef ERaComponentHandler ComponentHandler;

protected:
#if !defined(ERA_ABBR)
Expand Down Expand Up @@ -181,7 +184,21 @@ class ERaApi

template <typename T, typename... Args>
void configIdWrite(ERaInt_t configId, const T& value, const Args&... tail) {
this->configIdMultiWrite(configId, value, tail...);
this->configIdWriteMulti(configId, value, tail...);
}

void configIdObject(const char* value) {
ERaDataJson data(value);
this->configIdObject(data);
}

void configIdObject(cJSON* value) {
ERaDataJson data(value);
this->configIdObject(data);
}

void configIdObject(ERaDataJson& value) {
this->configIdWriteMultiReal(value, false);
}

template <typename T>
Expand Down Expand Up @@ -319,6 +336,14 @@ class ERaApi
}
}

bool setVirtualNextRetained(int pin, bool nextRetained) {
return this->ERaPinRp.setVPinNextRetained(pin, nextRetained);
}

bool getVirtualNextRetained(int pin, bool& retained) {
return this->ERaPinRp.getVPinNextRetained(pin, retained);
}

Flash& getFlash() const {
return this->flash;
}
Expand Down Expand Up @@ -347,6 +372,14 @@ class ERaApi
this->enableAppLoop = enable;
}

void setERaComponent(ERaComponent& _component) override {
ComponentHandler::addComponent(_component);
}

void setERaComponent(ERaComponent* _pComponent) override {
ComponentHandler::addComponent(_pComponent);
}

void callERaProHandler(const char* deviceId, const cJSON* const root);

protected:
Expand All @@ -365,7 +398,9 @@ class ERaApi
void processArduinoPinRequest(const ERaDataBuff& arrayTopic, const char* payload);
void processVirtualPinRequest(const ERaDataBuff& arrayTopic, const char* payload);
void initPinConfig();
void parseArduinoPinConfig(cJSON* root);
void parsePinConfig(const char* str);
void processPinConfig(cJSON* root, const char* hash, const char* buf);
void storePinConfig(const char* str);
void removePinConfig();

Expand Down Expand Up @@ -395,13 +430,17 @@ class ERaApi
this->initERaApiTask();

ERaWatchdogFeed();

ComponentHandler::begin();

ERaWatchdogFeed();
}

bool run() {
bool run(bool skipTask) {
ERA_RUN_YIELD();

if (!this->isTaskRunning()) {
this->handlerAPI(true);
this->handlerAPI(true, skipTask);
}

ERaWatchdogFeed();
Expand Down Expand Up @@ -429,7 +468,7 @@ class ERaApi
return this->thisProto().getTransp().run();
}

void handlerAPI(bool feed) {
void handlerAPI(bool feed, bool skipTask) {
#if !defined(ERA_ABBR)
Property::run();
#endif
Expand All @@ -440,6 +479,23 @@ class ERaApi
}

Handler::run();

if (feed) {
ERaWatchdogFeed();
}

this->thisProto().runEdge();

ComponentHandler::run();

if (feed) {
ERaWatchdogFeed();
}

if (skipTask) {
return;
}
this->runERaApiTask();
}

void switchTask() {
Expand All @@ -454,7 +510,7 @@ class ERaApi

void runAPI() {
for (;;) {
this->handlerAPI(false);
this->handlerAPI(false, true);
ERA_API_YIELD();
if (this->autoSwitchTask &&
this->connected()) {
Expand Down Expand Up @@ -668,15 +724,19 @@ class ERaApi
}

template <typename... Args>
void configIdMultiWrite(const Args&... tail) {
ERaRsp_t rsp;
void configIdWriteMulti(const Args&... tail) {
ERaDataJson data;
data.add_multi(tail...);
this->configIdWriteMultiReal(data, false);
}

void configIdWriteMultiReal(ERaDataJson& value, bool json = false) {
ERaRsp_t rsp;
rsp.type = ERaTypeWriteT::ERA_WRITE_CONFIG_ID_MULTI;
rsp.json = false;
rsp.json = json;
rsp.retained = ERA_MQTT_PUBLISH_RETAINED;
rsp.id = 0;
rsp.param = data.getObject();
rsp.param = value.getObject();
this->thisProto().sendCommand(rsp);
}

Expand Down Expand Up @@ -943,6 +1003,18 @@ void ERaApi<Proto, Flash>::initPinConfig() {
ptr = nullptr;
}

template <class Proto, class Flash>
inline
void ERaApi<Proto, Flash>::parseArduinoPinConfig(cJSON* root) {
cJSON* item = cJSON_GetObjectItem(root, "arduino_pin");
if (!cJSON_IsObject(item)) {
return;
}

this->ERaPinRp.deleteAll();
this->thisProto().processArduinoPinConfig(item);
}

template <class Proto, class Flash>
inline
void ERaApi<Proto, Flash>::parsePinConfig(const char* str) {
Expand All @@ -957,9 +1029,9 @@ void ERaApi<Proto, Flash>::parsePinConfig(const char* str) {
if (cJSON_IsString(item)) {
this->ERaPinRp.updateHashID(item->valuestring);
}
item = cJSON_GetObjectItem(root, "command");
if (cJSON_IsString(item)) {
this->thisProto().processDownCommand(str, root, item);
item = cJSON_GetObjectItem(root, "configuration");
if (cJSON_IsObject(item)) {
this->parseArduinoPinConfig(item);
}

cJSON_Delete(root);
Expand All @@ -969,6 +1041,23 @@ void ERaApi<Proto, Flash>::parsePinConfig(const char* str) {
ERA_LOG(TAG, ERA_PSTR("Pin configuration loaded from flash"));
}

template <class Proto, class Flash>
inline
void ERaApi<Proto, Flash>::processPinConfig(cJSON* root, const char* hash, const char* buf) {
if (!this->ERaPinRp.updateHashID(hash)) {
this->ERaPinRp.restartAll();
return;
}

this->ERaPinRp.deleteAll();
this->thisProto().processArduinoPinConfig(root);
#if !defined(ERA_ABBR)
Property::updateProperty(this->ERaPinRp);
#endif
this->storePinConfig(buf);
ERaWriteConfig(ERaConfigTypeT::ERA_PIN_CONFIG);
}

template <class Proto, class Flash>
inline
void ERaApi<Proto, Flash>::storePinConfig(const char* str) {
Expand Down Expand Up @@ -1007,6 +1096,7 @@ void ERaApi<Proto, Flash>::removePinConfig() {
root = nullptr;
return;
}

cJSON* data = cJSON_GetObjectItem(root, "data");
cJSON* item = cJSON_GetObjectItem(data, "hash_id");
if (cJSON_IsString(item)) {
Expand All @@ -1016,6 +1106,7 @@ void ERaApi<Proto, Flash>::removePinConfig() {
if (cJSON_IsString(item)) {
this->thisProto().Proto::Handler::begin(item->valuestring);
}

cJSON_Delete(root);
root = nullptr;

Expand Down Expand Up @@ -1221,7 +1312,7 @@ void ERaApi<Proto, Flash>::appLoop() {
if (this->isTaskRunning()) {
return;
}
this->handlerAPI(true);
this->handlerAPI(true, false);
}

template <class Proto, class Flash>
Expand Down
11 changes: 11 additions & 0 deletions src/ERa/ERaCallbacksHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdlib.h>
#include <stdint.h>
#include <ERa/ERaComponent.hpp>
#include <ERa/ERaTransp.hpp>
#include <ERa/ERaLogger.hpp>
#include <ERa/ERaCallbacks.hpp>
Expand All @@ -27,6 +28,16 @@ class ERaCallbacksHelper
ERA_FORCE_UNUSED(pCallbacks);
}

virtual void setERaComponent(ERaComponent& _component) {
ERA_LOG_WARNING(TAG, ERA_PSTR("setERaComponent callback default."));
ERA_FORCE_UNUSED(_component);
}

virtual void setERaComponent(ERaComponent* _pComponent) {
ERA_LOG_WARNING(TAG, ERA_PSTR("setERaComponent callback default."));
ERA_FORCE_UNUSED(_pComponent);
}

virtual void setERaTransp(ERaTransp& _transp) {
ERA_LOG_WARNING(TAG, ERA_PSTR("setERaTransp callback default."));
ERA_FORCE_UNUSED(_transp);
Expand Down
36 changes: 36 additions & 0 deletions src/ERa/ERaComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef INC_ERA_COMPONENT_HPP_
#define INC_ERA_COMPONENT_HPP_

#include <stdint.h>
#include <stddef.h>

class ERaComponent
{
public:
ERaComponent()
: next(NULL)
{}
virtual ~ERaComponent()
{}

virtual void begin() = 0;
virtual void run() = 0;

ERaComponent* getNext() const {
return this->next;
}

void setNext(ERaComponent& component) {
this->next = &component;
}

void setNext(ERaComponent* component) {
this->next = component;
}

protected:
private:
ERaComponent* next;
};

#endif /* INC_ERA_COMPONENT_HPP_ */
Loading

0 comments on commit 5c9cf12

Please sign in to comment.