freemodbus: Fix bug with incorrect coils read mask
Contains two different component folders per each implementation (serial_master and serial_slave) with concrete ports. Added common public api for master and slave and common interface for master and slave implementation. Add support of cmake system (added cmake files). Added sdkconfig.defaults files for slave and master modbus examples. Updated make file and KConfig for freemodbus component Update according to review and fix doxygen warnings Fix Doxyfile to pass documentation build Update headers and change interface file names as per review comments Merge branch feature/freemodbus_move_rs485_mode_control Update after review: The stack modbus folder updated to support master and slave ports together and moved into freemodbus/modbus Stack and port files updated to remove duplicated simbols Make file, KConfig and CMakeLists.txt updated to compile master and slave stacks, common interface and concrete implementations of ports Stack callback functions execute callbacks using interface pointer from concrete port implementation User can instantiate any of concrete port using common API (only one concrete port at a time) and it does not require to select port by KConfig Port pins and mode configuration moved into example files from port files to allow user select pins and port mode (customer request) Changes tested using pymodbus, ModbusPoll and communication between two boards Updated DoxyFile according to public include path Fix maximum instance size for slave (merge from master of customer issue) Fix critical section issue TW#28622 (change spin lock based critical section to semaphore) Move serial port files into component port folder for master and slave accordingly Fix example issue showed in the log when IO slave is not configured correctly Fix conflicts while merging from origin/master Fix errors handling in modbus controller interface + some final corrections according to review Update maximum allowed number of slaves in the network segment Fix bug with incorrect coils read mask Closes https://github.com/espressif/esp-idf/issues/858
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/*=====================================================================================
|
||||
* Description:
|
||||
* C file to define user defined parameters for Modbus example
|
||||
*====================================================================================*/
|
||||
|
||||
#ifndef _DEVICEPARAMS_H_
|
||||
#define _DEVICEPARAMS_H_
|
||||
|
||||
#include "mbcontroller.h" // for common Modbus defines
|
||||
|
||||
// Enumeration of modbus device addresses accessed by master device
|
||||
enum {
|
||||
MB_DEVICE_ADDR1 = 1,
|
||||
MB_DEVICE_ADDR2 = 2,
|
||||
MB_DEVICE_ADDR3 = 3,
|
||||
};
|
||||
|
||||
// Enumeration of all supported CIDs for device (used in parameter definition table)
|
||||
enum {
|
||||
CID_DATA_CHAN_0 = 0,
|
||||
CID_HUMIDITY_1,
|
||||
CID_TEMPERATURE_1,
|
||||
CID_HUMIDITY_2,
|
||||
CID_TEMPERATURE_2,
|
||||
CID_RELAY_P1,
|
||||
CID_RELAY_P2,
|
||||
CID_COUNT,
|
||||
};
|
||||
|
||||
#define DEVICE_PARAM_MAX_SIZE 24
|
||||
|
||||
// The structures below define the parameters that will be accessed by Modbus master device.
|
||||
// These parameters reflect the parameters in the address space of external devices in Modbus network.
|
||||
// They defined for each modbus register type (coils, discreet inputs, holding registers, input registers).
|
||||
// These are not required but can be used by user to link characteristic to corresponded field
|
||||
// See the parameter definition table for more information.
|
||||
// It is just example and it is responsibility of user to define them as required.
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
// Parameter: discrete_input0
|
||||
uint8_t discrete_input0:1;
|
||||
// Parameter: discrete_input1
|
||||
uint8_t discrete_input1:1;
|
||||
// Parameter: discrete_input2
|
||||
uint8_t discrete_input2:1;
|
||||
// Parameter: discrete_input3
|
||||
uint8_t discrete_input3:1;
|
||||
// Parameter: discrete_input4
|
||||
uint8_t discrete_input4:1;
|
||||
// Parameter: discrete_input5
|
||||
uint8_t discrete_input5:1;
|
||||
// Parameter: discrete_input6
|
||||
uint8_t discrete_input6:1;
|
||||
// Parameter: discrete_input7
|
||||
uint8_t discrete_input7:1;
|
||||
uint8_t discrete_input_port1:8;
|
||||
} discrete_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
// Note: For correct access the coils storage for each addressed parameter
|
||||
// has to include at least 2 byte (register)!
|
||||
#pragma pack(push, 1)
|
||||
typedef union
|
||||
{
|
||||
struct {
|
||||
// Parameter: Coil 0 : Coil0
|
||||
|
||||
uint8_t coil0:1;
|
||||
// Parameter: Coil 1 : Coil1
|
||||
uint8_t coil1:1;
|
||||
// Parameter: Coil 2 : Coil2
|
||||
uint8_t coil2:1;
|
||||
// Parameter: Coil 3 : Coil3
|
||||
uint8_t coil3:1;
|
||||
// Parameter: Coil 4 : Coil4
|
||||
uint8_t coil4:1;
|
||||
// Parameter: Coil 5 : Coil5
|
||||
uint8_t coil5:1;
|
||||
// Parameter: Coil 6 : Coil6
|
||||
uint8_t coil6:1;
|
||||
// Parameter: Coil 7 : Coil7
|
||||
uint8_t coil7:1;
|
||||
uint8_t coil_port2:8;
|
||||
};
|
||||
uint8_t coils_port1;
|
||||
uint8_t coils_port2;
|
||||
} coil_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
// Input register structure to keep characteristic's values
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
// Parameter: Data channel 0 : data_chan0
|
||||
float data_chan0;
|
||||
// Parameter: Data channel 1 : data_chan1
|
||||
float data_chan1;
|
||||
// Parameter: Data channel 2 : data_chan2
|
||||
float data_chan2;
|
||||
// Parameter: Data channel 3 : data_chan3
|
||||
float data_chan3;
|
||||
} input_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
// Holding register structure to keep characteristic's values
|
||||
#pragma pack(push, 1)
|
||||
typedef struct
|
||||
{
|
||||
// Parameter: Data channel 0 : mb_device1_humidity
|
||||
float mb_device1_humidity;
|
||||
// Parameter: Data channel 1 : mb_device1_temperature
|
||||
float mb_device1_temperature;
|
||||
// Parameter: Data channel 2 : mb_device2_humidity
|
||||
float mb_device2_humidity;
|
||||
// Parameter: Data channel 3 : mb_device2_temperature
|
||||
float mb_device2_temperature;
|
||||
// Parameter: Protocol version : protocol_version
|
||||
uint16_t mb_device1_protocol_version;
|
||||
// Parameter: Hardware version : hardware_version
|
||||
uint16_t mb_device1_hardware_version;
|
||||
// Parameter: Software Version : software_version
|
||||
uint16_t mb_device1_software_version;
|
||||
// Parameter: Software Revision : software_revision
|
||||
uint16_t mb_device1_software_revision;
|
||||
// Parameter: Device Type : deviceType :
|
||||
uint16_t mb_device1_device_type;
|
||||
uint8_t mb_device1_string_test[PARAM_SIZE_ASCII24];
|
||||
} holding_reg_params_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
extern holding_reg_params_t holding_reg_params;
|
||||
extern input_reg_params_t input_reg_params;
|
||||
extern coil_reg_params_t coil_reg_params;
|
||||
extern discrete_reg_params_t discrete_reg_params;
|
||||
|
||||
extern const mb_parameter_descriptor_t device_parameters[];
|
||||
extern const uint16_t num_device_parameters;
|
||||
|
||||
#endif /* _DEVICEPARAMS_H_ */
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __SENSE_MB_H__
|
||||
#define __SENSE_MB_H__
|
||||
|
||||
#include "mbcontroller.h"
|
||||
#include "device_params.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /**< _cplusplus */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t cid; /*!< Characteristic cid */
|
||||
const char* param_key; /*!< The key (name) of the parameter */
|
||||
const char* param_units; /*!< The units of the parameter */
|
||||
mb_parameter_opt_t param_opts; /*!< Parameter options */
|
||||
mb_param_perms_t access; /*!< Access permissions based on mode */
|
||||
void* instance_ptr; /*!< Data instance for the parameter */
|
||||
mb_descr_type_t instance_type; /*!< Type of instance value */
|
||||
size_t instance_size; /*!< Size of instance to save data */
|
||||
uint8_t change_flag; /*!< Change value flag */
|
||||
esp_err_t status; /*!< Status of the value */
|
||||
uint64_t timestamp; /*!< Time stamp of last access to parameter */
|
||||
} characteristic_descriptor_t;
|
||||
|
||||
esp_err_t sense_modbus_init();
|
||||
esp_err_t sense_modbus_get_characteristics(characteristic_descriptor_t** cid_table, uint16_t* table_size);
|
||||
esp_err_t sense_modbus_read_value(uint16_t cid, void* value);
|
||||
esp_err_t sense_modbus_send_value(uint16_t cid, void* value);
|
||||
esp_err_t sense_modbus_get_cid_data(uint16_t cid, characteristic_descriptor_t* cid_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /**< _cplusplus */
|
||||
|
||||
#endif /**< __SENSE_MB_H__ */
|
||||
Reference in New Issue
Block a user