mirror of
https://gitlab.com/fabinfra/fabhardware/fabmeter.git
synced 2025-03-12 22:51:44 +01:00
179 lines
6.9 KiB
C
179 lines
6.9 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2016-2021 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/*=====================================================================================
|
|
* Description:
|
|
* The Modbus parameter structures used to define Modbus instances that
|
|
* can be addressed by Modbus protocol. Define these structures per your needs in
|
|
* your application. Below is just an example of possible parameters.
|
|
*====================================================================================*/
|
|
#ifndef _DEVICE_PARAMS
|
|
#define _DEVICE_PARAMS
|
|
|
|
#include <stdint.h>
|
|
|
|
// This file defines structure of modbus parameters which reflect correspond modbus address space
|
|
// for each modbus register type (coils, discreet inputs, holding registers, input registers)
|
|
#pragma pack(push, 1)
|
|
typedef struct
|
|
{
|
|
uint8_t discrete_input0:1;
|
|
uint8_t discrete_input1:1;
|
|
uint8_t discrete_input2:1;
|
|
uint8_t discrete_input3:1;
|
|
uint8_t discrete_input4:1;
|
|
uint8_t discrete_input5:1;
|
|
uint8_t discrete_input6:1;
|
|
uint8_t discrete_input7:1;
|
|
uint8_t discrete_input_port1:8;
|
|
} discrete_reg_params_t;
|
|
#pragma pack(pop)
|
|
|
|
#pragma pack(push, 1)
|
|
typedef struct
|
|
{
|
|
uint8_t coils_port0;
|
|
uint8_t coils_port1;
|
|
} coil_reg_params_t;
|
|
#pragma pack(pop)
|
|
|
|
#pragma pack(push, 1)
|
|
typedef struct
|
|
{
|
|
float voltage_L1N; // 0
|
|
float voltage_L2N; // 2
|
|
float voltage_L3N; // 4
|
|
float current_L1; // 6
|
|
float current_L2; // 8
|
|
float current_L3; // 10
|
|
float active_power_L1; // 12
|
|
float active_power_L2; // 14
|
|
float active_power_L3; // 16
|
|
float apparent_power_L1; // 18
|
|
float apparent_power_L2; // 20
|
|
float apparent_power_L3; // 22
|
|
float reactive_power_L1; // 24
|
|
float reactive_power_L2; // 26
|
|
float reactive_power_L3; // 28
|
|
float power_factor_L1; // 30
|
|
float power_factor_L2; // 32
|
|
float power_factor_L3; // 34
|
|
float voltage_avg_LN; // 36
|
|
float current_avg; // 38
|
|
float current_sum; // 40
|
|
float active_power_sum; // 42
|
|
float apparent_power_sum; // 44
|
|
float reactive_power_sum; // 46
|
|
float power_factor_sum; // 48
|
|
float frequency; // 50
|
|
float active_energy_import; // 52
|
|
float active_energy_export; // 54
|
|
float voltage_L1L2; // 56
|
|
float voltage_L2L3; // 58
|
|
float voltage_L3L1; // 60
|
|
float voltage_avg_LL; // 62
|
|
float current_N; // 64
|
|
float active_energy_sum; // 66
|
|
float reactive_energy_sum; // 68
|
|
float active_energy_resettable_sum; // 70
|
|
float reactive_energy_resettable_sum; // 72
|
|
float active_energy_import_resettable; // 74
|
|
float active_energy_export_resettable; // 76
|
|
float active_energy_net; // 78
|
|
float active_power_import_sum; // 80
|
|
float active_power_export_sum; // 82
|
|
} input_reg_params_t;
|
|
#pragma pack(pop)
|
|
|
|
#pragma pack(push, 1)
|
|
typedef struct
|
|
{
|
|
float sys_type; // 0
|
|
float pulse_width; // 2
|
|
float kppa; // 4
|
|
float parrity_and_stop; // 6
|
|
float modbus_addr; // 8
|
|
float pulse_const; // 10
|
|
float password; // 12
|
|
float baudrate; // 14
|
|
float auto_scroll_time; // 16
|
|
float backlight_time; // 18
|
|
float pulse_1_energy_type; // 20
|
|
uint16_t reset_history; // 22
|
|
uint32_t serial_number; // 24
|
|
uint16_t meter_type; // 28
|
|
uint16_t fw_version; // 30
|
|
|
|
} 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;
|
|
|
|
// Enumeration of all supported CIDs for device (used in parameter definition table)
|
|
enum {
|
|
CID_INP_U_L1N = 0, // Input voltage L1-N
|
|
CID_INP_U_L2N, // Input voltage L2-N
|
|
CID_INP_U_L3N, // Input voltage L3-N
|
|
CID_INP_I_L1, // Input current L1
|
|
CID_INP_I_L2, // Input current L2
|
|
CID_INP_I_L3, // Input current L3
|
|
CID_INP_P_L1, // Input active power L1
|
|
CID_INP_P_L2, // Input active power L2
|
|
CID_INP_P_L3, // Input active power L3
|
|
CID_INP_S_L1, // Input apparent power L1
|
|
CID_INP_S_L2, // Input apparent power L2
|
|
CID_INP_S_L3, // Input apparent power L3
|
|
CID_INP_Q_L1, // Input reactive power L1
|
|
CID_INP_Q_L2, // Input reactive power L2
|
|
CID_INP_Q_L3, // Input reactive power L3
|
|
CID_INP_PF_L1, // Input power factor L1
|
|
CID_INP_PF_L2, // Input power factor L2
|
|
CID_INP_PF_L3, // Input power factor L3
|
|
CID_INP_U_LN_AVG, // Input voltage L-N average
|
|
CID_INP_I_L_AVG, // Input current L average
|
|
CID_INP_I_SUM, // Input current sum
|
|
CID_INP_P_SUM, // Input active power sum
|
|
CID_INP_S_SUM, // Input apparent power sum
|
|
CID_INP_Q_SUM, // Input reactive power sum
|
|
CID_INP_PF_SUM, // Input power factor average
|
|
CID_INP_FREQ, // Input frequency
|
|
CID_INP_E_IMP, // Input energy import
|
|
CID_INP_E_EXP, // Input energy export
|
|
CID_INP_U_L1L2, // Input voltage L1-L2
|
|
CID_INP_U_L2L3, // Input voltage L2-L3
|
|
CID_INP_U_L3L1, // Input voltage L3-L1
|
|
CID_INP_U_LL_AVG, // Input voltage L-L average
|
|
CID_INP_I_N, // Input current N
|
|
CID_INP_E_SUM, // Input energy sum
|
|
CID_INP_Eq_SUM, // Input energy reactive sum
|
|
CID_INP_E_RESET_SUM, // Input resettable energy sum
|
|
CID_INP_Eq_RESET_SUM, // Input resettable reactive energy sum
|
|
CID_INP_E_RESET_IMP, // Input resettable energy import
|
|
CID_INP_E_RESET_EXP, // Input resettable energy export
|
|
CID_INP_E_NET, // Input net energy *import - export*
|
|
CID_INP_P_IMP_SUM, // Input power import sum
|
|
CID_INP_P_EXP_SUM, // Input power export sum
|
|
CID_HLD_SYS_TYPE, // System type (1 - Single phase, 3 - Three phase)
|
|
CID_HLD_PULSE_WIDTH, // Pulse width (60ms, 100ms, 200ms)
|
|
CID_HLD_KPPA, // Key Parameter Programming Authorization (0 - not authorized, 1 - authorized)
|
|
CID_HLD_PARITY_AND_STOP, // Parity and stop bits (0 - 1 stop bit, no parity, 1 - 1 stop bit, even parity, 2 - 1 stop bit, odd parity, 3 - 2 stop bits, no parity)
|
|
CID_HLD_MB_ADDR, // Modbus address (1-247)
|
|
CID_HLD_PULSE_CONST,// Pulse constant (0 - 1000 imp/kWh, 1 - 100 imp/kWh, 2 - 10 imp/kWh, 3 - 1 imp/kWh)
|
|
CID_HLD_PASSWD, // Password (0 - 9999, default 1000)
|
|
CID_HLD_BAUDRATE, // Baudrate (0 - 2400, 1 - 4800, 2 - 9600, 3 - 19200, 5 - 1200)
|
|
CID_HLD_AUTO_SCROLL_TIME, // Auto scroll time (0-60 - time in seconds)
|
|
CID_HLD_BACKLIGHT_TIME, // Backlight time (0-121, 0 - always on, 121, always off, 1-120 - time in seconds)
|
|
CID_HLD_PULSE_1_E_TYPE, // Pulse 1 energy type (1 - import, 2 - total, 3 - export)
|
|
CID_HLD_RST_HIST, // Reset history (0x0003 - reset energy info)
|
|
CID_HLD_SERIAL, // Serial number (uint32_t, read only)
|
|
CID_HLD_METER_TYPE, // Meter type (0x0089 - SDM72D-M-2, read only)
|
|
CID_HLD_METER_FIRMWARE // Meter firmware (Format XX.YY, XX = data[0], YY = data[1] , read only)
|
|
};
|
|
|
|
#endif // !defined(_DEVICE_PARAMS)
|