Common Component
Installation
The component requires ESP-IDF 5.0 and higher and is installed using IDF Component Manager.
Add this to the idf_component.yml
in the project main
directory or in the component directory:
dependencies:
plasmapper/pl_common: "^1.2.2"
Add this to the source code:
#include "pl_common.h"
Add extern "C"
to the app_main
function:
extern "C" void app_main(void) {...}
Add this to the sdkconfig.defaults
in the project directory or configure the values using Project Configuration:
CONFIG_COMPILER_CXX_RTTI=y
Features
PL::Lockable
- a base class for any lockable object. Descendant classes should overridePL::Lockable::Lock()
andPL::Lockable::Unlock()
.PL::LockGuard
- a RAII-style lock guard class. It is used to lock an object inside a code block:PL::LockGuard lg (PL::Lockable&);
.PL::Mutex
- a mutex class. It inheritsPL::Lockable
and overridesPL::Lockable::Lock()
andPL::Lockable::Unlock()
with FreeRTOS xSemaphoreTakeRecursive and xSemaphoreGiveRecursive.PL::Buffer
- a lockable buffer class. The memory is either allocated when the buffer is initialized or the buffer uses an already preallocated data. Buffer also can be initialized with a shared lockable (for example when one buffer is a part of another buffer). PL::Buffer::data andPL::Buffer::size
.PL::TypedBuffer
- a class template for a buffer with typed data. It inheritsPL::Buffer
and has a typed public memberPL::TypedBuffer::data
.PL::Event
- an event class template. It can be added as a public member to the class and used by class member functions to generate events usingPL::Event::Generate()
and by external objects to subscribe/unsubscribe for events usingPL::Event::AddHandler()
/PL::Event::RemoveHandler()
.PL::EventHanler
- an event handler class template. If class handles only one event it can inherit this class and overridePL::EventHanler::HandleEvent()
method. For classes with multiple event handlerstemplate<class HandlerClass> void PL::Event::AddHandler(std::shared_ptr<HandlerClass>, void(HandlerClass::*)(Source&, Args...))
should be used.PL::Stream
- a base class for any stream. A number ofPL::Stream::Read()
andPL::Stream::Write()
functions read and write from/to the stream. Reading and writing to/fromPL::Buffer
object checks the data size and locks the object so these methods can be used in multithreaded applications.PL::HardwareInterface
- a base class for any hardware interface. Descendant classes should overridePL::HardwareInterface::Initialize()
,PL::HardwareInterface::Enable()
,PL::HardwareInterface::Disable()
,PL::HardwareInterface::IsEnabled()
,PL::HardwareInterface::Lock()
andPL::HardwareInterface::Unlock()
.PL::Server
- a base class for any server. Descendant classes should overridePL::Server::Enable()
,PL::Server::Disable()
,PL::Server::IsEnabled()
,PL::Server::Lock()
andPL::Server::Unlock()
.PL::StreamServer
- aPL::Server
implementation using aPL::Stream
for communication with client. The descendant class should overridePL::StreamServer::HandleRequest()
to handle the client request.PL::StreamServer::HandleRequest()
is only called when there is incoming data in the internal buffer.
Thread safety
Class method thread safety is implemented by having the PL::Lockable
as a base class and creating the class object lock guard at the beginning of the methods.
PL::StreamServer
task method locks both the PL::StreamServer
and the PL::Stream
objects for the duration of the transaction.
API reference
- Types
- PL::Lockable class
- PL::LockGuard class
- PL::Mutex class
- PL::Buffer class
- PL::TypedBuffer class
- PL::Event class
- PL::EventHandler class
- PL::Stream class
- PL::HardwareInterface class
HardwareInterface
HardwareInterface::HardwareInterface()
HardwareInterface::Initialize()
HardwareInterface::Enable()
HardwareInterface::Disable()
HardwareInterface::IsEnabled()
HardwareInterface::GetName()
HardwareInterface::SetName()
HardwareInterface::Lock()
HardwareInterface::Unlock()
HardwareInterface::enabledEvent
HardwareInterface::disabledEvent
- PL::Server class
- PL::StreamServer class
StreamServer
StreamServer::StreamServer()
StreamServer::Lock()
StreamServer::Unlock()
StreamServer::Enable()
StreamServer::Disable()
StreamServer::IsEnabled()
StreamServer::GetStream()
StreamServer::SetStream()
StreamServer::SetTaskParameters()
StreamServer::GetName()
StreamServer::SetName()
StreamServer::enabledEvent
StreamServer::disabledEvent
StreamServer::defaultTaskParameters
StreamServer::HandleRequest()