Skip to content

Commit

Permalink
remove dependency on 3rd party LinkedList lib
Browse files Browse the repository at this point in the history
use std::list intead of 3rd party LinkedList lib
  • Loading branch information
vortigont committed Jul 17, 2024
1 parent a2b6406 commit 70b652f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 34 deletions.
6 changes: 0 additions & 6 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"type": "git",
"url": "https://github.com/vortigont/pzem-edl.git"
},
"dependencies":
[
{"owner": "vortigont",
"name": "LinkedList",
"version": "https://github.com/vortigont/LinkedList"}
],
"build": {
"flags": "-std=gnu++14",
"unflags": "-std=gnu++11"
Expand Down
2 changes: 1 addition & 1 deletion src/msgq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void UartQ::stop_tx_msg_q(){

// очищаем все сообщения из очереди
TX_msg* msg = nullptr;
while (xQueueReceive(_t, &(msg), (portTickType)0) == pdPASS ){
while (xQueueReceive(_t, &(msg), (TickType_t)0) == pdPASS ){
delete msg;
}

Expand Down
4 changes: 2 additions & 2 deletions src/msgq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class UartQ : public MsgQ {
xSemaphoreGive(rts_sem); // сигналим что можно отправлять следующий пакет и мы готовы ловить ответ

// 'xQueueReceive' will "sleep" untill an event messages arrives from the RX event queue
if(xQueueReceive(rx_msg_q, reinterpret_cast<void*>(&event), (portTickType)portMAX_DELAY)) {
if(xQueueReceive(rx_msg_q, reinterpret_cast<void*>(&event), portMAX_DELAY)) {

//Handle received event
switch(event.type) {
Expand Down Expand Up @@ -426,7 +426,7 @@ class UartQ : public MsgQ {
// Task runs inside Infinite loop
for (;;){
// 'xQueueReceive' will "sleep" untill some message arrives from the msg queue
if(xQueueReceive(tx_msg_q, &(msg), (portTickType)portMAX_DELAY)) {
if(xQueueReceive(tx_msg_q, &(msg), portMAX_DELAY)) {

// if smg would expect a reply than I need to grab a semaphore from the RX queue task
if (msg->w4rx){
Expand Down
24 changes: 7 additions & 17 deletions src/pzem_edl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,6 @@ void PZ003::resetEnergyCounter(){

/* === PZPool immplementation === */

/**
* @brief Destroy the PZPool::PZPool object
* All registered devices and ports are destructed
*/
PZPool::~PZPool(){
meters.clear();
ports.clear();
}

bool PZPool::addPort(uint8_t _id, UART_cfg &portcfg, const char *descr){
if (port_by_id(_id))
return false; // port with such id already exist
Expand All @@ -208,10 +199,8 @@ bool PZPool::addPort(std::shared_ptr<PZPort> port){
if (port_by_id(port->id))
return false; // port with such id already exist

if (!ports.add(port))
return false; // some LinkedList error

uint8_t portid = port->id;
ports.emplace_back(port);

// RX handler lambda catches port-id here and suppies this id to the handler function
port->q->attach_RX_hndlr([this, portid](RX_msg *msg){
Expand Down Expand Up @@ -282,15 +271,16 @@ bool PZPool::addPZEM(const uint8_t port_id, PZEM *pz){

node->pzem.reset(std::move(pz));

return meters.add(node);
meters.emplace_back(std::move(node));
return true;
}

bool PZPool::removePZEM(const uint8_t pzem_id){
for (int i = 0; i != meters.size(); ++i) {
if (meters[i]->pzem->id == pzem_id){
meters.unlink(i);
for (auto i = meters.begin(); i != meters.end(); ++i ){
if ((*i)->pzem->id == pzem_id){
meters.erase(i);
return true;
}
}
}
return false;
}
Expand Down
9 changes: 4 additions & 5 deletions src/pzem_edl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ GitHub: https://github.com/vortigont/pzem-edl
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#include "pzem_modbus.hpp"
#include "LList.h"
#include <list>

#define POLLER_PERIOD PZEM_REFRESH_PERIOD // auto update period in ms
#define POLLER_MIN_PERIOD 2*PZEM_UART_TIMEOUT // minimal poller period
Expand Down Expand Up @@ -340,15 +340,14 @@ class PZPool {
};

protected:
LList<std::shared_ptr<PZPort>> ports; // list of registered ports
LList<std::shared_ptr<PZNode>> meters; // list of registered PZEM nodes
std::list< std::shared_ptr<PZPort> > ports; // list of registered ports
std::list< std::shared_ptr<PZNode> > meters; // list of registered PZEM nodes
std::shared_ptr<PZPort> port_by_id(uint8_t id);
const PZEM* pzem_by_id(uint8_t id) const;


public:
PZPool(){}
~PZPool();
PZPool() = default;
// Copy semantics : not implemented
PZPool(const PZPool&) = delete;
PZPool& operator=(const PZPool&) = delete;
Expand Down
6 changes: 3 additions & 3 deletions src/timeseries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ GitHub: https://github.com/vortigont/pzem-edl
#include <esp_heap_caps.h>

#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
#include "esp_psram.h"
#include <esp_psram.h>
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 0, 0)
#include <esp32/spiram.h>
#else
Expand Down Expand Up @@ -214,7 +214,7 @@ class RingBuff {

// Unary predicate for ID match
template <class T>
class MatchID : public std::unary_function<T, bool>{
class MatchID {
uint8_t _id;
public:
explicit MatchID(uint8_t id) : _id(id) {}
Expand Down Expand Up @@ -284,7 +284,7 @@ template <typename T>
class TSContainer {

public:
TSContainer<T>(){};
//TSContainer<T>(){};
//~TSContainer();

/**
Expand Down

0 comments on commit 70b652f

Please sign in to comment.