Modbus Vault v1.0
Loading...
Searching...
No Matches
modbus_analyzer.c File Reference

Implementation of the modbus analyzer. More...

#include "modbus_analyzer.h"
#include "debug_pins.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "event_bus.h"
#include "metrics.h"
#include "modbus_parser.h"
#include "runtime_tasks.h"
Include dependency graph for modbus_analyzer.c:

Macros

#define MODBUS_ANALYZER_EVENTS_QUEUE_SIZE   (20U)
 

Functions

static void modbus_analyzer_task (void *parameters_void_ptr)
 Analyzer task.
 
static void modbus_analyzer_stop_task (void)
 Stop modbus analyzer task.
 
static void emit_modbus_frame_callback (const modbus_slicer_frame_t *frame_ptr, void *arg_void_ptr)
 Callback on-frame-ready from slicer.
 
static void on_rs485_driver_event_callback (void *arg_void_ptr, const rs485_driver_event_t *event_ptr)
 Callback for rs485 driver to queue events.
 
esp_err_t modbus_analyzer_init (modbus_analyzer_t *analyzer_ptr, modbus_analyzer_config_t *config_ptr)
 Initialize Modbus analyzer.
 
void modbus_analyzer_deinit (modbus_analyzer_t *analyzer_ptr)
 Deinitialize Modbus analyzer.
 

Variables

static const char * TAG = "MODBUS_ANALYZER"
 
static TaskHandle_t modbus_analyzer_task_handle
 
runtime_task_config_t modbus_analyzer_task_config
 

Detailed Description

Implementation of the modbus analyzer.

  • Provide a task that receive raw bytes from lower layer and shape them into frames using 'modbus slicer'
  • Uses 'system event bus' to emit data/errors for consumers

Macro Definition Documentation

◆ MODBUS_ANALYZER_EVENTS_QUEUE_SIZE

#define MODBUS_ANALYZER_EVENTS_QUEUE_SIZE   (20U)

Task queue size

Function Documentation

◆ emit_modbus_frame_callback()

static void emit_modbus_frame_callback ( const modbus_slicer_frame_t frame_ptr,
void *  arg_void_ptr 
)
static

Callback on-frame-ready from slicer.

Emit system event with type depends whether there was an error or data-frame

Parameters
frame_ptrPointer to modbus frame
arg_void_ptrVoid pointer to argument
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modbus_analyzer_deinit()

void modbus_analyzer_deinit ( modbus_analyzer_t analyzer_ptr)

Deinitialize Modbus analyzer.

Parameters
analyzer_ptrPointer to analyzer instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modbus_analyzer_init()

esp_err_t modbus_analyzer_init ( modbus_analyzer_t analyzer_ptr,
modbus_analyzer_config_t config_ptr 
)

Initialize Modbus analyzer.

Initialize Modbus analyzer by initializing a slicer instance

Parameters
analyzer_ptrPointer to analyzer instance
config_ptrPointer to analyzer configuration instance
Returns
esp_err_t Initialize result
Return values
ESP_OKInitialize success
ESP_ERR_INVALID_ARGProvided invalid argument(s)

< Task queue size

Here is the call graph for this function:
Here is the caller graph for this function:

◆ modbus_analyzer_task()

static void modbus_analyzer_task ( void *  parameters_void_ptr)
static

Analyzer task.

Receive bytes from RS485 driver, checks for RS485 driver errors then feeds them to slicer if there was data

Parameters
parameters_void_ptrVoid pointer to task parameters
Note
parameters_void_ptr must be a pointer to analyzer instance
Here is the call graph for this function:

◆ on_rs485_driver_event_callback()

static void on_rs485_driver_event_callback ( void *  arg_void_ptr,
const rs485_driver_event_t event_ptr 
)
static

Callback for rs485 driver to queue events.

Parameters
arg_void_ptrVoid pointer to modbus analyzer type structure
event_ptrPointer to rs485 driver event
Here is the caller graph for this function:

Variable Documentation

◆ modbus_analyzer_task_config

runtime_task_config_t modbus_analyzer_task_config
Initial value:
.arg = NULL,
static void modbus_analyzer_task(void *parameters_void_ptr)
Analyzer task.
Definition modbus_analyzer.c:39
static TaskHandle_t modbus_analyzer_task_handle
Definition modbus_analyzer.c:27
static void modbus_analyzer_stop_task(void)
Stop modbus analyzer task.
Definition modbus_analyzer.c:112
#define MODBUS_ANALYZER_TASK_STACK_DEPTH
Definition modbus_analyzer.h:25
#define MODBUS_ANALYZER_TASK_CPU_AFFINITY
Definition modbus_analyzer.h:27
#define MODBUS_ANALYZER_TASK_PRIORITY
Definition modbus_analyzer.h:26
#define MODBUS_ANALYZER_TASK_NAME
Definition modbus_analyzer.h:24

Modbus analyzer task configuration structure

◆ modbus_analyzer_task_handle

TaskHandle_t modbus_analyzer_task_handle
static

Modbus analyzer task handle

◆ TAG

const char* TAG = "MODBUS_ANALYZER"
static

Modbus analyzer TAG name