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

The App class represents the main application component. More...

#include <App.h>

Inheritance diagram for App:
[legend]

Public Member Functions

 App ()
 Default constructor for the App class.
 
ComponentbyId (short id)
 Retrieves a component by its ID.
 
virtual short debug ()
 Performs debugging operations for the application.
 
virtual short info ()
 Retrieves information about the application.
 
virtual short loop ()
 Runs the main loop of the application.
 
virtual short numByFlag (ushort flag)
 Retrieves the number of components with a specific flag.
 
virtual void printRegisters ()
 
virtual short registerComponents (Bridge *bridge)
 Register all components in Bridge
 
virtual short setup ()
 Performs the setup operations for the application and it's components.
 
- 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 (short val0, short val1)
 Virtual function to display information about the component.
 
virtual short onError (short id, short error)
 
virtual short onMessage (int id, E_CALLS verb, E_MessageFlags flags, const void *user, Component *src)
 Handles incoming messages.
 
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)
 

Public Attributes

Bridgebridge
 
Vector< Component * > components
 The list of components in the application.
 
millis_t DEBUG_INTERVAL
 The interval for debugging operations.
 
millis_t debugTS
 The timestamp for the last debug operation.
 
millis_t loopTS
 The timestamp for the last loop operation.
 
Vector< ModbusGateway * > nComponents
 The list of components in the application.
 
Timer< 10, millistimer
 The timer used for scheduling tasks.
 
millis_t wait
 The wait time between loop iterations.
 
millis_t waitTS
 The timestamp for the last wait operation.
 
- 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
 

Additional Inherited Members

- 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.
 

Detailed Description

The App class represents the main application component.

This class inherits from the Component class and provides functionality for setting up, running the main loop, debugging, and providing information about the application.

Definition at line 17 of file App.h.

Constructor & Destructor Documentation

◆ App()

App::App ( )

Default constructor for the App class.

Definition at line 14 of file App.cpp.

15{
16 DEBUG_INTERVAL = 1000;
17 components.setStorage(componentsArray);
19 debugTS = 0;
20}
static Component * componentsArray[MAX_COMPONENTS]
Definition App.cpp:11
static ModbusGateway * componentsArrayModbus[MAX_COMPONENTS]
Definition App.cpp:12
Vector< ModbusGateway * > nComponents
The list of components in the application.
Definition App.h:78
millis_t debugTS
The timestamp for the last debug operation.
Definition App.h:83
millis_t DEBUG_INTERVAL
The interval for debugging operations.
Definition App.h:108
Vector< Component * > components
The list of components in the application.
Definition App.h:73
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

Member Function Documentation

◆ byId()

Component * App::byId ( short id)

Retrieves a component by its ID.

Parameters
idThe ID of the component to retrieve.
Returns
A pointer to the component with the specified ID, or nullptr if not found.

Definition at line 140 of file App.cpp.

141{
142 uchar s = components.size();
143 for (uchar i = 0; i < s; i++)
144 {
146 if (component->id == id)
147 {
148 return component;
149 }
150 }
151 return NULL;
152}
The Component class represents a generic component.
Definition Component.h:21
Definition xtimer.h:21
unsigned char uchar
Definition types.h:7

◆ debug()

short App::debug ( )
virtual

Performs debugging operations for the application.

Returns
A status code indicating the result of the debug operation.

Reimplemented from Component.

Definition at line 99 of file App.cpp.

100{
101 if (millis() - debugTS > DEBUG_INTERVAL)
102 {
103 uchar s = components.size();
104 uchar nb = 0;
105 for (uchar i = 0; i < s; i++)
106 {
108 if (component->hasFlag(OBJECT_RUN_FLAGS::E_OF_DEBUG))
109 {
110 if (component->debug())
111 {
112 Serial.println("\n");
113 nb++;
114 }
115 }
116 }
117 if (nb)
118 {
119 Serial.println("\n");
120 }
121 debugTS = millis();
122 }
123 return E_OK;
124}
#define E_OK

◆ info()

short App::info ( )
virtual

Retrieves information about the application.

Returns
A status code indicating the result of the info operation.

Reimplemented from Component.

Definition at line 126 of file App.cpp.

127{
128 uchar s = components.size();
129 for (uchar i = 0; i < s; i++)
130 {
132 if (component->hasFlag(OBJECT_RUN_FLAGS::E_OF_INFO))
133 {
134 component->info();
135 }
136 }
137 return E_OK;
138}

◆ loop()

short App::loop ( )
virtual

Runs the main loop of the application.

Returns
A status code indicating the result of the loop operation.

Reimplemented from Component.

Reimplemented in PHApp.

Definition at line 63 of file App.cpp.

64{
65 timer.tick();
66 now = millis();
67 uchar s = components.size();
68 for (uchar i = 0; i < s; i++)
69 {
71 if (component->hasFlag(OBJECT_RUN_FLAGS::E_OF_LOOP))
72 {
73 component->now = now;
74 component->loop();
75 }
76 }
77 debug();
78 return E_OK;
79}
virtual short debug()
Performs debugging operations for the application.
Definition App.cpp:99
Timer< 10, millis > timer
The timer used for scheduling tasks.
Definition App.h:103
millis_t now
The current time in milliseconds.
Definition Component.h:216
void tick()
Definition xtimer.h:49

◆ numByFlag()

short App::numByFlag ( ushort flag)
virtual

Retrieves the number of components with a specific flag.

Parameters
flagThe flag to filter the components by.
Returns
The number of components with the specified flag.

Definition at line 84 of file App.cpp.

85{
86 uchar s = components.size();
87 uchar l = 0;
88 for (uchar i = 0; i < s; i++)
89 {
91 if (!!(component->hasFlag(flag)))
92 {
93 l++;
94 }
95 }
96 return l;
97}

◆ printRegisters()

virtual void App::printRegisters ( )
inlinevirtual

Reimplemented in PHApp.

Definition at line 123 of file App.h.

123{ return E_OK; }

◆ registerComponents()

short App::registerComponents ( Bridge * bridge)
virtual

Register all components in Bridge

Returns
A status code indicating the result of the setup operation.

Definition at line 48 of file App.cpp.

49{
50 uchar s = components.size();
51 for (uchar i = 0; i < s; i++)
52 {
54 if (component->hasFlag(OBJECT_RUN_FLAGS::E_OF_DISABLED))
55 {
56 continue;
57 }
58 component->onRegisterMethods(bridge);
59 }
60 return E_OK;
61}
Bridge * bridge
Definition App.h:121

◆ setup()

short App::setup ( )
virtual

Performs the setup operations for the application and it's components.

Returns
A status code indicating the result of the setup operation.

Reimplemented from Component.

Reimplemented in PHApp.

Definition at line 22 of file App.cpp.

23{
24 Log.verbose(F("* App:setup *" CR));
25 uchar s = components.size();
26 for (uchar i = 0; i < s; i++)
27 {
29 if (!component->owner)
30 {
31 component->owner = this;
32 }
33 if (component->hasFlag(OBJECT_RUN_FLAGS::E_OF_SETUP))
34 {
35 component->setup();
36 }
37 }
38
39 info();
40 /*
41 if (bridge)
42 {
43 bridge->onRegisterMethods(bridge);
44 }*/
45 return E_OK;
46}
virtual short info()
Retrieves information about the application.
Definition App.cpp:126

Member Data Documentation

◆ bridge

Bridge* App::bridge

Definition at line 121 of file App.h.

◆ components

Vector<Component *> App::components

The list of components in the application.

Definition at line 73 of file App.h.

◆ DEBUG_INTERVAL

millis_t App::DEBUG_INTERVAL

The interval for debugging operations.

Definition at line 108 of file App.h.

◆ debugTS

millis_t App::debugTS

The timestamp for the last debug operation.

Definition at line 83 of file App.h.

◆ loopTS

millis_t App::loopTS

The timestamp for the last loop operation.

Definition at line 88 of file App.h.

◆ nComponents

Vector<ModbusGateway *> App::nComponents

The list of components in the application.

Definition at line 78 of file App.h.

◆ timer

Timer<10, millis> App::timer

The timer used for scheduling tasks.

Definition at line 103 of file App.h.

◆ wait

millis_t App::wait

The wait time between loop iterations.

Definition at line 93 of file App.h.

◆ waitTS

millis_t App::waitTS

The timestamp for the last wait operation.

Definition at line 98 of file App.h.


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