142 lines
7.1 KiB
C
142 lines
7.1 KiB
C
/**
|
|
* @file config.h
|
|
* @brief Main configuration file for the CRAH Unit (TCP) emulator.
|
|
* @author Emmanuel Hernandez Cruz
|
|
* @date 2025-09-02
|
|
*
|
|
* This file contains two important configurations: WiFi network parameters
|
|
* and the Modbus register map for the device.
|
|
*/
|
|
|
|
#ifndef CONFIG_H
|
|
#define CONFIG_H
|
|
|
|
#include "core.h"
|
|
#include "Equipment/Equipment.h"
|
|
|
|
#if defined(USE_MODBUS_IP)
|
|
/**
|
|
* @defgroup ModbusTCPConfig Modbus IP Configuration
|
|
* @brief Parameters for Modbus TCP communication.
|
|
* @{
|
|
*/
|
|
#include <ModbusIP_ESP8266.h>
|
|
const char *ssid = "wifi_name"; /**< @brief The SSID of the WiFi network. */
|
|
const char *password = "wifi_password"; /**< @brief The password for the WiFi network. */
|
|
IPAddress local_IP(192, 168, 1, 234); /**< @brief The static IP address for the device. */
|
|
IPAddress gateway(192, 168, 1, 1); /**< @brief The gateway IP address. */
|
|
IPAddress subnet(255, 255, 255, 0); /**< @brief The subnet mask. */
|
|
|
|
ModbusIP mb;
|
|
#else
|
|
/**
|
|
* @defgroup ModbusRTUConfig Modbus RTU Configuration
|
|
* @brief Parameters for serial Modbus RTU communication.
|
|
* @{
|
|
*/
|
|
#include <ModbusRTU.h>
|
|
const int BAUDRATE = 19200; /**< @brief The serial communication speed in bits per second. */
|
|
const int RX_PIN = 17; /**< @brief The GPIO pin used for receiving data (RX). */
|
|
const int TX_PIN = 16; /**< @brief The GPIO pin used for transmitting data (TX). */
|
|
const int RST_PIN = 4; /**< @brief The GPIO pin connected to the RS485 driver's DE/RE pins for direction control. */
|
|
const int MODBUS_ID = 1; /**< @brief The unique slave ID for this device on the Modbus bus. */
|
|
/** @} */
|
|
|
|
/** @brief Global instance of the Modbus RTU server. */
|
|
ModbusRTU mb;
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
* @defgroup ModbusMapConfig Modbus Map Configuration
|
|
* @brief Defines the Modbus register map and related parameters for the emulator.
|
|
* @{
|
|
*/
|
|
/**
|
|
* @brief The Modbus map for the Equipment device.
|
|
* This array defines all the Modbus points available on the emulated device.
|
|
* The `description` field is crucial as it's used to look up points within the application logic.
|
|
*/
|
|
modbusMap mb_map[] =
|
|
{
|
|
{HR, 15, 0, "State Control"}, //Internal to control from Modscan
|
|
{HR, 16, 0, "Fault Code"}, //Internal Fault code from Modscan
|
|
{DI, 20, 0, "Bypass Not Ready"},
|
|
{DI, 244, 0, "System Shutdown-EPO"},
|
|
{DI, 247, 0, "System Fan Failure"},
|
|
{DI, 245, 0, "Fuse Failure"},
|
|
{DI, 239, 0, "Internal Comms Failure"},
|
|
{DI, 254, 0, "UPS Output on Bypass"},
|
|
{DI, 249, 0, "System Output Off"},
|
|
{DI, 11, 0, "Output Overload"},
|
|
{DI, 263, 0, "Battery Low"},
|
|
{IR, 183, 0, "UPS Battery Status"},
|
|
{IR, 180, 0, "Battery Time Remaining"},
|
|
{IR, 29, 0, "Bypass Input Frequency"},
|
|
{IR, 30, 0, "Bypass Power Phase A"},
|
|
{IR, 31, 0, "Bypass Power Phase B"},
|
|
{IR, 32, 0, "Bypass Power Phase C"},
|
|
{IR, 23, 0, "Bypass Input Voltage RMS A-B"},
|
|
{IR, 26, 0, "Bypass Input Voltage RMS A-N"},
|
|
{IR, 24, 0, "Bypass Input Voltage RMS B-C"},
|
|
{IR, 27, 0, "Bypass Input Voltage RMS B-N"},
|
|
{IR, 25, 0, "Bypass Input Voltage RMS C-A"},
|
|
{IR, 28, 0, "Bypass Input Voltage RMS C-N"},
|
|
{IR, 175, 0, "DC Bus Voltage"},
|
|
{IR, 7, 0, "System Input RMS Current Phase A"},
|
|
{IR, 8, 0, "System Input RMS Current Phase B"},
|
|
{IR, 9, 0, "System Input RMS Current Phase C"},
|
|
{IR, 10, 0, "System Input Frequency"},
|
|
{IR, 17, 0, "System Input Apparent Power Phs A"},
|
|
{IR, 18, 0, "System Input Apparent Power Phs B"},
|
|
{IR, 19, 0, "System Input Apparent Power Phs C"},
|
|
{IR, 14, 0, "System Input Power Phase A"},
|
|
{IR, 15, 0, "System Input Power Phase B"},
|
|
{IR, 16, 0, "System Input Power Phase C"},
|
|
{IR, 11, 0, "System Input Power Factor Phs A"},
|
|
{IR, 12, 0, "System Input Power Factor Phs B"},
|
|
{IR, 13, 0, "System Input Power Factor Phs C"},
|
|
{IR, 1, 0, "System Input RMS A-B"},
|
|
{IR, 4, 0, "System Input RMS A-N"},
|
|
{IR, 2, 0, "System Input RMS B-C"},
|
|
{IR, 5, 0, "System Input RMS B-N"},
|
|
{IR, 3, 0, "System Input RMS C-A"},
|
|
{IR, 6, 0, "System Input RMS C-N"},
|
|
{IR, 50, 0, "System Output Frequency"},
|
|
{IR, 44, 0, "System Output RMS Current Phase A"},
|
|
{IR, 45, 0, "System Output RMS Current Phase B"},
|
|
{IR, 46, 0, "System Output RMS Current Phase C"},
|
|
{IR, 61, 0, "System Output Apparent Power"},
|
|
{IR, 57, 0, "System Output Apparent Power Phs A"},
|
|
{IR, 58, 0, "System Output Apparent Power Phs B"},
|
|
{IR, 59, 0, "System Output Apparent Power Phs C"},
|
|
{IR, 60, 0, "System Output Power"},
|
|
{IR, 54, 0, "System Output Power Phase A"},
|
|
{IR, 55, 0, "System Output Power Phase B"},
|
|
{IR, 56, 0, "System Output Power Phase C"},
|
|
{IR, 51, 0, "System Output Power Factor Phs A"},
|
|
{IR, 52, 0, "System Output Power Factor Phs B"},
|
|
{IR, 53, 0, "System Output Power Factor Phs C"},
|
|
{IR, 38, 0, "System Output Voltage RMS A-B"},
|
|
{IR, 41, 0, "System Output Voltage RMS A-N"},
|
|
{IR, 39, 0, "System Output Voltage RMS B-C"},
|
|
{IR, 42, 0, "System Output Voltage RMS B-N"},
|
|
{IR, 40, 0, "System Output Voltage RMS C-A"},
|
|
{IR, 43, 0, "System Output Voltage RMS C-N"},
|
|
{IR, 164, 0, "UPS Loading Status"},
|
|
};
|
|
//Size of modbus map used in FOR cycles, automatically calculated.
|
|
|
|
/**
|
|
* @brief The total number of entries in the `mb_map` array.
|
|
* This is calculated at compile time and used for iterating over the map.
|
|
*/
|
|
const int map_size = sizeof(mb_map) / sizeof(mb_map[0]);
|
|
|
|
/** @brief The main loop update interval in milliseconds. */
|
|
int interval = 250;
|
|
/** @} */ // End of ModbusMapConfig group
|
|
|
|
#endif // CONFIG_H
|