MeshX 0.4
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_io_bridge.cpp File Reference

MeshX IO Bridge Implementation. More...

#include "../interface/meshx_io_bridge.h"
#include "../inc/meshx_io_factory.hpp"
#include "../inc/meshx_io_interface.hpp"
#include "../inc/meshx_io_types.hpp"
#include <vector>
#include <memory>

Functions

meshx_io_handle_t meshx_io_create (const meshx_io_config_t *config)
 Create IO instance from configuration.
void meshx_io_destroy (meshx_io_handle_t handle)
 Destroy IO instance.
meshx_err_t meshx_io_execute (meshx_io_handle_t handle, meshx_io_func_t function, const uint32_t *args, uint8_t arg_count)
 Execute IO function.
uint8_t meshx_io_get_logical_pin (meshx_io_handle_t handle)
 Get logical pin number.
const char * meshx_io_get_name (meshx_io_handle_t handle)
 Get pin name.
bool meshx_io_is_function_supported (meshx_io_handle_t handle, meshx_io_func_t function)
 Check if function is supported.
meshx_err_t meshx_io_set_level (meshx_io_handle_t handle, uint8_t level)
 Set pin level (convenience function).
meshx_err_t meshx_io_get_level (meshx_io_handle_t handle, uint8_t *level)
 Get pin level (convenience function).
meshx_err_t meshx_io_toggle (meshx_io_handle_t handle)
 Toggle pin level (convenience function).
meshx_err_t meshx_io_init (void)
 Initialize IO subsystem.
meshx_err_t meshx_io_deinit (void)
 Deinitialize IO subsystem.

Detailed Description

MeshX IO Bridge Implementation.

This file implements the C bridge for the C++ IO abstraction layer. It provides the glue between C applications and C++ IO instances.

Author
MeshX Team
Date
2024

Function Documentation

◆ meshx_io_create()

meshx_io_handle_t meshx_io_create ( const meshx_io_config_t * config)

Create IO instance from configuration.

Parameters
configIO configuration
Returns
meshx_io_handle_t IO instance handle, NULL on failure
23 {
24 if (config == nullptr) {
25 return nullptr;
26 }
27
28 IoConfig io_config;
29 io_config.logical_pin = config->logical_pin;
30 io_config.type = static_cast<IoType>(config->io_type);
31 io_config.name = config->name ? config->name : "";
32
33 // Copy configuration based on type
34 if (io_config.type == IoType::GPIO) {
35 io_config.config.gpio.mode = config->config.gpio.mode;
36 io_config.config.gpio.pull = config->config.gpio.pull;
37 io_config.config.gpio.drive = config->config.gpio.drive;
40 } else if (io_config.type == IoType::PWM) {
41 io_config.config.pwm.frequency = config->config.pwm.frequency;
42 io_config.config.pwm.duty_cycle = config->config.pwm.duty_cycle;
43 io_config.config.pwm.resolution = config->config.pwm.resolution;
44 io_config.config.pwm.channel = config->config.pwm.channel;
45 }
46
47 auto instance = MeshXIoFactory::getInstance().create(io_config);
48 if (!instance) {
49 return nullptr;
50 }
51
52 // Return as raw pointer (opaque handle)
53 return static_cast<meshx_io_handle_t>(instance.release());
54}
static MeshXIoFactory & getInstance()
Get singleton instance.
Definition meshx_io_factory.cpp:26
std::unique_ptr< MeshXIoInterface > create(const IoConfig &config)
Create IO instance.
Definition meshx_io_factory.cpp:69
void * meshx_io_handle_t
Opaque handle to IO instance.
Definition meshx_io_bridge.h:26
IoType
IO Type enumeration.
Definition meshx_io_factory.hpp:24
IO Configuration Structure.
Definition meshx_io_factory.hpp:35
bool signal_inversion
Definition meshx_io_factory.hpp:47
uint8_t pull
Definition meshx_io_factory.hpp:44
uint32_t frequency
Definition meshx_io_factory.hpp:51
uint8_t resolution
Definition meshx_io_factory.hpp:53
struct meshx::IoConfig::@322131243157366012127327120072350016325131204373::@367141106155340206106161007235363020301330311260 gpio
uint8_t logical_pin
Definition meshx_io_factory.hpp:36
uint8_t duty_cycle
Definition meshx_io_factory.hpp:52
uint8_t mode
Definition meshx_io_factory.hpp:43
struct meshx::IoConfig::@322131243157366012127327120072350016325131204373::@240320275032304141243012114035354247040336106337 pwm
IoType type
Definition meshx_io_factory.hpp:37
union meshx::IoConfig::@322131243157366012127327120072350016325131204373 config
uint8_t drive
Definition meshx_io_factory.hpp:45
uint8_t initial_level
Definition meshx_io_factory.hpp:46
std::string name
Definition meshx_io_factory.hpp:38
uint8_t channel
Definition meshx_io_factory.hpp:54
struct meshx_io_config_t::@200043212040355171322045102300102313244163277162::@121023260072206274007113107267121236225137237146 pwm
uint8_t channel
Definition meshx_io_bridge.h:65
uint8_t io_type
Definition meshx_io_bridge.h:49
uint8_t mode
Definition meshx_io_bridge.h:54
struct meshx_io_config_t::@200043212040355171322045102300102313244163277162::@136271060226257263336073166042050314245271222173 gpio
uint8_t drive
Definition meshx_io_bridge.h:56
union meshx_io_config_t::@200043212040355171322045102300102313244163277162 config
bool signal_inversion
Definition meshx_io_bridge.h:58
uint8_t resolution
Definition meshx_io_bridge.h:64
uint8_t duty_cycle
Definition meshx_io_bridge.h:63
const char * name
Definition meshx_io_bridge.h:50
uint8_t pull
Definition meshx_io_bridge.h:55
uint8_t initial_level
Definition meshx_io_bridge.h:57
uint8_t logical_pin
Definition meshx_io_bridge.h:48
uint32_t frequency
Definition meshx_io_bridge.h:62

◆ meshx_io_deinit()

meshx_err_t meshx_io_deinit ( void )

Deinitialize IO subsystem.

Returns
meshx_err_t Error code
132 {
133 // No specific deinit needed for factory singleton
134 return MESHX_SUCCESS;
135}
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385

◆ meshx_io_destroy()

void meshx_io_destroy ( meshx_io_handle_t handle)

Destroy IO instance.

Parameters
handleIO instance handle
56 {
57 if (handle != nullptr) {
58 delete static_cast<MeshXIoInterface*>(handle);
59 }
60}
Abstract IO Interface.
Definition meshx_io_interface.hpp:44

◆ meshx_io_execute()

meshx_err_t meshx_io_execute ( meshx_io_handle_t handle,
meshx_io_func_t function,
const uint32_t * args,
uint8_t arg_count )

Execute IO function.

Parameters
handleIO instance handle
functionIO function to execute
argsFunction arguments array
arg_countNumber of arguments
Returns
meshx_err_t Error code
65 {
66 if (handle == nullptr) {
67 return MESHX_INVALID_ARG;
68 }
69
70 MeshXIoInterface* instance = static_cast<MeshXIoInterface*>(handle);
71 std::vector<uint32_t> arg_vec;
72 if (args != nullptr && arg_count > 0) {
73 arg_vec.assign(args, args + arg_count);
74 }
75
76 int result = instance->execute(static_cast<IoFunction>(function), arg_vec);
77 return (result == 0) ? MESHX_SUCCESS : MESHX_FAIL;
78}
virtual int execute(IoFunction function, const std::vector< uint32_t > &args)=0
Execute IO function.
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
@ MESHX_FAIL
Definition meshx_err.h:45
IoFunction
IO Function Types for function-based API.
Definition meshx_io_interface.hpp:25

◆ meshx_io_get_level()

meshx_err_t meshx_io_get_level ( meshx_io_handle_t handle,
uint8_t * level )

Get pin level (convenience function).

Parameters
handleIO instance handle
[out]levelPointer to store pin level
Returns
meshx_err_t Error code
110 {
111 if (handle == nullptr || level == nullptr) {
112 return MESHX_INVALID_ARG;
113 }
114 int result = static_cast<MeshXIoInterface*>(handle)->getLevel(level);
115 return (result == 0) ? MESHX_SUCCESS : MESHX_FAIL;
116}

◆ meshx_io_get_logical_pin()

uint8_t meshx_io_get_logical_pin ( meshx_io_handle_t handle)

Get logical pin number.

Parameters
handleIO instance handle
Returns
uint8_t Logical pin number
80 {
81 if (handle == nullptr) {
82 return 0xFF;
83 }
84 return static_cast<MeshXIoInterface*>(handle)->getLogicalPin();
85}

◆ meshx_io_get_name()

const char * meshx_io_get_name ( meshx_io_handle_t handle)

Get pin name.

Parameters
handleIO instance handle
Returns
const char* Pin name
87 {
88 if (handle == nullptr) {
89 return nullptr;
90 }
91 return static_cast<MeshXIoInterface*>(handle)->getName();
92}

◆ meshx_io_init()

meshx_err_t meshx_io_init ( void )

Initialize IO subsystem.

This function initializes the IO factory and registers all IO types.

Returns
meshx_err_t Error code
126 {
127 // Factory initializes itself on getInstance()
129 return MESHX_SUCCESS;
130}

◆ meshx_io_is_function_supported()

bool meshx_io_is_function_supported ( meshx_io_handle_t handle,
meshx_io_func_t function )

Check if function is supported.

Parameters
handleIO instance handle
functionIO function to check
Returns
true if function is supported
false if function is not supported
95 {
96 if (handle == nullptr) {
97 return false;
98 }
99 return static_cast<MeshXIoInterface*>(handle)->isFunctionSupported(static_cast<IoFunction>(function));
100}

◆ meshx_io_set_level()

meshx_err_t meshx_io_set_level ( meshx_io_handle_t handle,
uint8_t level )

Set pin level (convenience function).

Parameters
handleIO instance handle
levelPin level (0 = low, 1 = high)
Returns
meshx_err_t Error code
102 {
103 if (handle == nullptr) {
104 return MESHX_INVALID_ARG;
105 }
106 int result = static_cast<MeshXIoInterface*>(handle)->setLevel(level);
107 return (result == 0) ? MESHX_SUCCESS : MESHX_FAIL;
108}

◆ meshx_io_toggle()

meshx_err_t meshx_io_toggle ( meshx_io_handle_t handle)

Toggle pin level (convenience function).

Parameters
handleIO instance handle
Returns
meshx_err_t Error code
118 {
119 if (handle == nullptr) {
120 return MESHX_INVALID_ARG;
121 }
122 int result = static_cast<MeshXIoInterface*>(handle)->toggle();
123 return (result == 0) ? MESHX_SUCCESS : MESHX_FAIL;
124}