Lydia - Printhead
Loading...
Searching...
No Matches
Bridge Class Reference

#include <Bridge.h>

Inheritance diagram for Bridge:
[legend]

Public Member Functions

 Bridge (Component *_owner)
 
short debug ()
 Virtual function to debug the component.
 
SComponentInfohasMethod (ushort id, String method)
 
short list ()
 
virtual short onMessage (int id, E_CALLS verb, E_MessageFlags flags, const void *user, Component *src)
 Handles incoming messages.
 
SComponentInforegisterMemberFunction (ushort id, Component *clazz, char *method, ComponentFnPtr ptr)
 
short setup ()
 Virtual function to set up the component.
 
- Public Member Functions inherited from Component
void clearFlag (byte flag)
 Clears a specific flag for the component.
 
 Component ()
 Default constructor for the Component class.
 
 Component (String _name)
 Constructor for the Component class with a specified name.
 
 Component (String _name, short _id)
 Constructor for the Component class with a specified name and ID.
 
 Component (String _name, short _id, int _flags)
 Constructor for the Component class with a specified name, ID, and flags.
 
 Component (String _name, short _id, int _flags, Component *_owner)
 Constructor for the Component class with a specified name, ID, flags, and owner.
 
virtual short debug (short val0, short val1)
 Virtual function to debug the component.
 
virtual short destroy ()
 Virtual function to destroy the component.
 
void disable ()
 Disables the component.
 
void enable ()
 Enables the component.
 
bool enabled ()
 Checks if the component is enabled.
 
bool hasFlag (byte flag)
 Checks if the component has a specific flag.
 
virtual short info ()
 Virtual function to display information about the component.
 
virtual short info (short val0, short val1)
 Virtual function to display information about the component.
 
virtual short loop ()
 Virtual function to run the component in a loop.
 
virtual short onError (short id, short error)
 
virtual short onRawResponse (short size, uint8_t rxBuffer[])
 
virtual short onRegisterMethods (Bridge *bridge)
 
virtual short onResponse (short error)
 
void setFlag (byte flag)
 Sets a specific flag for the component.
 
 ~Component ()
 Destructor for the Component class.
 
- Public Member Functions inherited from ModbusGateway
short getAddress ()
 
MB_FC getFunctionCode ()
 
short getNumberAddresses ()
 
virtual String getRegisterDescription (short flags=0)
 
const chargetRegisterMode ()
 
 ModbusGateway ()
 
 ModbusGateway (short _addr)
 
 ModbusGateway (short _addr, short _fc)
 
void setAddress (short _addr)
 
void setFunctionCode (MB_FC fc)
 
void setGateway (Mudbus *mudbus)
 
void setNumberAddresses (short _nbAddr)
 
void setRegisterMode (MB_REGISTER_MODE mode)
 

Static Public Attributes

static constexpr charMETHOD_DELIMITER = C_STR(":")
 
- Static Public Attributes inherited from Component
static const int COMPONENT_DEFAULT = 1 << OBJECT_RUN_FLAGS::E_OF_LOOP | 1 << OBJECT_RUN_FLAGS::E_OF_SETUP
 The default run flags for a component.
 
static const int COMPONENT_NO_ID = 0
 The default ID for a component.
 

Additional Inherited Members

- Public Attributes inherited from Component
int flags
 The run flags for the component.
 
const short id
 The ID of the component.
 
millis_t last
 The last tick time in milliseconds.
 
String name
 The name of the component.
 
int nFlags
 The network capabilities of the component.
 
millis_t now
 The current time in milliseconds.
 
Componentowner
 The owner of the component.
 
- Public Attributes inherited from ModbusGateway
short addr
 
MB_FC fn
 
uchar lastMQSlot
 
Mudbusmudbus
 
short nbAddr
 
short registerMode
 

Detailed Description

Definition at line 26 of file Bridge.h.

Constructor & Destructor Documentation

◆ Bridge()

Bridge::Bridge ( Component * _owner)

Definition at line 19 of file Bridge.cpp.

20{
21}
static const int COMPONENT_DEFAULT
The default run flags for a component.
Definition Component.h:26
Component()
Default constructor for the Component class.
Definition Component.h:36
Definition xtimer.h:21

Member Function Documentation

◆ debug()

short Bridge::debug ( )
virtual

Virtual function to debug the component.

Parameters
streamThe stream to output the debug information to.
Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 41 of file Bridge.cpp.

42{
43 return E_OK;
44}
#define E_OK

◆ hasMethod()

SComponentInfo * Bridge::hasMethod ( ushort id,
String method )

Definition at line 28 of file Bridge.cpp.

29{
30 uchar s = componentList.size();
31 for (uchar i = 0; i < s; i++)
32 {
34 if (val->key == id && val->methodName.equals(methodName))
35 {
36 return val;
37 }
38 }
39 return NULL;
40}
Vector< SComponentInfo * > componentList
Definition Bridge.cpp:18
short key
Definition Bridge.h:15
String methodName
Definition Bridge.h:17
bool at(unsigned long time, handler_t h, void *opaque=NULL)
Definition xtimer.h:33
unsigned char uchar
Definition types.h:7

◆ list()

short Bridge::list ( )

Definition at line 45 of file Bridge.cpp.

46{
47 uchar s = componentList.size();
48 for (uchar i = 0; i < s; i++)
49 {
51 Log.verboseln("\tRegistered Method: %d::%s::%s", val->key, ((Component *)val->instance)->name.c_str(), val->methodName.c_str());
52 }
53 return E_OK;
54}
The Component class represents a generic component.
Definition Component.h:21
void * instance
Definition Bridge.h:16

◆ onMessage()

short Bridge::onMessage ( int id,
E_CALLS verb,
E_MessageFlags flags,
const void * user,
Component * src )
virtual

Handles incoming messages.

This function is called when a message is received by the component. It processes the message and returns a short value indicating the status of the operation.

Parameters
idThe ID of the message.
verbThe type of operation to be performed.
flagsThe flags associated with the message.
userA pointer to user-defined data.
srcThe source component that sent the message.
Returns
A short value indicating the status of the operation.

Reimplemented from Component.

Definition at line 111 of file Bridge.cpp.

112{
113
114#ifdef BRIDGE_DEBUG_CALL_METHOD
115 Log.verboseln("Bridge::onMessage: %d::%d::%d::%s - from ", id, verb, flags, CC_STR(user), src->name.c_str());
116#endif
117
118 switch (verb)
119 {
120 case E_CALLS::EC_USER:
121 case E_CALLS::EC_NONE:
122 case E_CALLS::EC_COMMAND:
123 case E_CALLS::EC_FUNC:
124 {
125 return E_OK;
126 }
127 case E_CALLS::EC_METHOD:
128 {
129 char *strings[4];
130 char *ptr = NULL;
131 byte index = 0;
133
134 while (ptr != NULL && index < NB_PAYLOAD_ELEMENTS)
135 {
136 strings[index] = ptr;
137 index++;
139 }
140
141 char *_method = strings[0];
142
144 if (method)
145 {
146 short arg0 = convertTo<short>(CC_STR(strings[1]));
147 short arg1 = convertTo<short>(CC_STR(strings[2]));
148 Component *component = (Component *)method->instance;
149 ComponentFnPtr ptr = method->mPtr;
150 short ret = (component->*ptr)(arg0, arg1);
151#ifdef BRIDGE_DEBUG_CALL_METHOD
152 Log.verboseln("Called method: %s(%d)::%s with : %d | %d = %d", component->name.c_str(), id, _method, arg0, arg1, ret);
153#endif
154 return ret;
155 }
156 else
157 {
158#ifdef BRIDGE_DEBUG_CALL_METHOD
159 Log.errorln("Method not found: %d::%s", id, _method);
160 list();
161#endif
162 }
163 return E_OK;
164 }
165 }
166 return E_NOT_FOUND;
167}
#define NB_PAYLOAD_ELEMENTS
Definition Bridge.cpp:13
short(Component::* ComponentFnPtr)(short, short)
Function pointer type for component member functions.
Definition Component.h:268
short convertTo< short >(cchar *str)
static constexpr char * METHOD_DELIMITER
Definition Bridge.h:46
short list()
Definition Bridge.cpp:45
SComponentInfo * hasMethod(ushort id, String method)
Definition Bridge.cpp:28
const short id
The ID of the component.
Definition Component.h:196
int flags
The run flags for the component.
Definition Component.h:201
#define E_NOT_FOUND
Definition error_codes.h:8
#define C_STR(s)
Definition macros.h:433
#define CC_STR(s)
Definition macros.h:432

◆ registerMemberFunction()

SComponentInfo * Bridge::registerMemberFunction ( ushort id,
Component * clazz,
char * method,
ComponentFnPtr ptr )

Definition at line 56 of file Bridge.cpp.

57{
58 #ifdef DISABLE_BRIDGE
59 // #pragma message("Bridge::registerMemberFunction : Bridge is disabled!")
60 return NULL;
61 #endif
62#ifndef DISABLE_BRIDGE
63 if (!clazz)
64 {
65 // Log.verboseln("Register member method: %d : invalid class", id);
66 return NULL;
67 }
68
69 if (!strlen(method))
70 {
71 // Log.verboseln("Register member method: %d : invalid method name", id);
72 return NULL;
73 }
74 if (!id)
75 {
76 // Log.verboseln("Register member method: %d : invalid component id", id);
77 return NULL;
78 }
79 if (componentList.size() > MAX_COMPONENTS)
80 {
81 // Log.errorln("Bridge::registerMemberFunction : Max components reached : %d", MAX_COMPONENTS);
82 return NULL;
83 }
85 if (meth)
86 {
87#ifdef BRIDGE_DEBUG_REGISTER
88 Log.verboseln("Register class member: %s::%s already registered!", clazz, method);
89#endif
90 }
91 else
92 {
93 meth = new SComponentInfo(id, clazz, method, ptr);
94 componentList.push_back(meth);
95#ifdef BRIDGE_DEBUG_REGISTER
96 if (clazz->name)
97 {
98 Log.verboseln("Register member method: %s (%d)::%s", clazz->name.c_str(), id, method);
99 }
100 else
101 {
102 Log.verboseln("Register member method: %d::%s : invalid name", id, method);
103 }
104#endif
105 }
106 return meth;
107#endif
108 return NULL;
109}
#define MAX_COMPONENTS
Definition Bridge.cpp:9

◆ setup()

short Bridge::setup ( )
virtual

Virtual function to set up the component.

Returns
The error code indicating the success or failure of the operation.

Reimplemented from Component.

Definition at line 22 of file Bridge.cpp.

23{
25 return E_OK;
26}
static Component * componentsArray[MAX_COMPONENTS]
Definition App.cpp:11

Member Data Documentation

◆ METHOD_DELIMITER

constexpr char* Bridge::METHOD_DELIMITER = C_STR(":")
staticconstexpr

Definition at line 46 of file Bridge.h.


The documentation for this class was generated from the following files: