153 lines
7.2 KiB
C
153 lines
7.2 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"},
|
|
{HR_FLOAT, 18, 0, "RAT"}, //Internal Fault code from Modscan
|
|
{HR_FLOAT, 1, 0, "SAT Setpoint"},
|
|
{HR_FLOAT, 681, 0, "RAT Setpoint"},
|
|
{HR_FLOAT, 111, 0, "High RAT Limit"},
|
|
{HR_FLOAT, 114, 0, "Low RAT Limit"},
|
|
{HR_FLOAT, 118, 0, "High SAT Limit"},
|
|
{HR_FLOAT, 122, 0, "Low SAT Limit"},
|
|
{HR_FLOAT, 685, 0, "High RAH Limit"},
|
|
{HR_FLOAT, 689, 0, "Low RAH Limit"},
|
|
{HR, 5, 0, "Setting the EC Fan Max Speed"},
|
|
{HR, 695, 0, "Setting the EC Fan Min Speed"},
|
|
{HR_FLOAT, 693, 0, "Setting Room Temp"},
|
|
{HR, 691, 0, "Setting EC Fan Speed "},
|
|
{DI, 146, 0, "Alarm SAT Sensor Fault"},
|
|
{DI, 1246, 0, "Alarm RAH Sensor Fault"},
|
|
{DI, 1245, 0, "Alarm RAT Sensor Fault"},
|
|
{DI, 1250, 0, "Alarm Filter DP Sensor Fault"},
|
|
{DI, 51, 0, "Alarm Flooding"},
|
|
{DI, 1096, 0, "Alarm Dirty Filter"},
|
|
{DI, 1367, 0, "Alarm High RAT"},
|
|
{DI, 1099, 0, "Alarm Low RAT"},
|
|
{DI, 118, 0, "Alarm High SAT"},
|
|
{DI, 122, 0, "Alarm Low SAT"},
|
|
{DI, 1307, 0, "Alarm High RAH"},
|
|
{DI, 1308, 0, "Alarm Low RAH"},
|
|
{DI, 1342, 0, "Alarm Common"},
|
|
{DI, 148, 0, "Alarm Phase Failure"},
|
|
{DI, 1370, 0, "Alarm Condensate Pump"},
|
|
{DI, 1368, 0, "Alarm Smoke"},
|
|
{DI, 1369, 0, "Alarm Fire"},
|
|
{DI, 131, 0, "Alarm EC Fan #1"},
|
|
{DI, 132, 0, "Alarm EC Fan #2"},
|
|
{DI, 133, 0, "Alarm EC Fan #3"},
|
|
{DI, 134, 0, "Alarm EC Fan #4"},
|
|
{DI, 135, 0, "Alarm EC Fan #5"},
|
|
{DI, 136, 0, "Alarm EC Fan #6"},
|
|
{DI, 1360, 0, "Alarm EC Fan #7"},
|
|
{DI, 1361, 0, "Alarm EC Fan #8"},
|
|
{DI, 1362, 0, "Alarm EC Fan #9"},
|
|
{DI, 138, 0, "Run Status EC Fan #1"},
|
|
{DI, 139, 0, "Run Status EC Fan #2"},
|
|
{DI, 140, 0, "Run Status EC Fan #3"},
|
|
{DI, 141, 0, "Run Status EC Fan #4"},
|
|
{DI, 142, 0, "Run Status EC Fan #5"},
|
|
{DI, 143, 0, "Run Status EC Fan #6"},
|
|
{DI, 1363, 0, "Run Status EC Fan #7"},
|
|
{DI, 1364, 0, "Run Status EC Fan #8"},
|
|
{DI, 1365, 0, "Run Status EC Fan #9"},
|
|
{IR_FLOAT, 99, 0, "SAT Reading"},
|
|
{IR_FLOAT, 70, 0, "RAH Reading"},
|
|
{IR_FLOAT, 101, 0, "RAT Reading"},
|
|
{IR_FLOAT, 106, 0, "Filter DP Reading"},
|
|
{IR_FLOAT, 496, 0, "CW Valve Position"},
|
|
{IR, 53, 0, "Speed EC Fan #1"},
|
|
{IR, 228, 0, "Speed EC Fan #2"},
|
|
{IR, 229, 0, "Speed EC Fan #3"},
|
|
{IR, 230, 0, "Speed EC Fan #4"},
|
|
{IR, 231, 0, "Speed EC Fan #5"},
|
|
{IR, 232, 0, "Speed EC Fan #6"},
|
|
{IR, 678, 0, "Speed EC Fan #7"},
|
|
{IR, 679, 0, "Speed EC Fan #8"},
|
|
{IR, 680, 0, "Speed EC Fan #9"},
|
|
{IR, 274, 0, "Operating Hours EC Fan #1"},
|
|
{IR, 233, 0, "Operating Hours EC Fan #2"},
|
|
{IR, 244, 0, "Operating Hours EC Fan #3"},
|
|
{IR, 235, 0, "Operating Hours EC Fan #4"},
|
|
{IR, 236, 0, "Operating Hours EC Fan #5"},
|
|
{IR, 245, 0, "Operating Hours EC Fan #6"},
|
|
{IR, 486, 0, "Operating Hours EC Fan #7"},
|
|
{IR, 487, 0, "Operating Hours EC Fan #8"},
|
|
{IR, 488, 0, "Operating Hours EC Fan #9"},
|
|
{COIL, 301, 0, "ON/OFF Command By BMS"},
|
|
{COIL, 302, 0, "Enable Off By Supervisory"},
|
|
{COIL, 264, 0, "Alarm Reset"}
|
|
};
|
|
//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
|