/** * @file core.h * @brief Core constants and definitions for the Industrial Emulator project. * @author Emmanuel Hernandez Cruz * @date 2025-09-06 * * This file contains shared constants, enumerations, and definitions that are * used across both the main application firmware and the Core library. * Placing these in a central, shared header prevents duplication and makes * configuration easier. * @note This file is intended to be included in the main `.ino` file. */ #ifndef CORE_H #define CORE_H #include "Equipment/Equipment.h" // Include the appropriate Modbus library header based on the build flag. // Define USE_MODBUS_IP in your build flags (e.g., platformio.ini) for Modbus IP. // Otherwise, it will default to Modbus RTU. #if defined(USE_MODBUS_IP) #include // Or your specific Modbus IP library #else #include // Or your specific Modbus RTU library #endif /** * @defgroup ModbusCategoryCodes Modbus Point Category Codes * @brief Integer constants used in the `modbusMap` to identify the type of Modbus point. * These codes determine which `ModbusPoint` subclass is created by the factory. * @{ */ const int COIL = 0; /**< @brief 0x: R/W Coil */ const int DI = 1; /**< @brief 1x: R Discrete Inputs */ const int IR = 3; /**< @brief 3x: R Input Register - Single word */ const int IR_10X = 31; /**< @brief 3x: R Input Register - Single word, 10x scaled */ const int IR_LONG = 32; /**< @brief 3x: R Input Register - Double word, Long type */ const int IR_FLOAT = 33; /**< @brief 3x: R Input Register - Double word, Float encoding */ const int HR = 4; /**< @brief 4x: R/W Holding Register - Single word */ const int HR_10x = 41; /**< @brief 4x: R/W Holding Register - Single word, 10x scaled */ const int HR_LONG = 42; /**< @brief 4x: R/W Holding Register - Double word, Long type */ const int HR_FLOAT = 43; /**< @brief 4x: R/W Holding Register - Double word, Float encoding */ /** @} */ /** * @struct modbusMap * @brief Defines the structure for a single entry in the Modbus map. */ struct modbusMap { int category; /**< @brief The Modbus category (e.g., COIL, HR, IR_FLOAT). */ int address; /**< @brief The Modbus address (0-9999). */ int value; /**< @brief The initial value for the point. */ char description[35];/**< @brief A descriptive name for the point. Used as a key for access. */ }; /** * @brief Timestamp for managing the main application loop interval. * Used in the main `.cpp` file to control the frequency of the `EquipmentInstance.update()` call. */ unsigned long previousMillis = 0; /** * @defgroup GlobalInstances Global Instances * @brief Globally accessible objects for the Modbus server and Equipment. * @{ */ /** * @brief Global Modbus object instance. * The type is determined at compile time based on the USE_MODBUS_IP flag. */ #if defined(USE_MODBUS_IP) extern ModbusIP mb; // Use ModbusIP class /** @brief An instance of the Equipment class, representing the emulated Equipment unit. */ Equipment EquipmentInstance(&mb); #else extern ModbusRTU mb; // Use ModbusRTU class /** @brief An instance of the Equipment class, representing the emulated Equipment unit. */ Equipment EquipmentInstance(&mb); #endif /** @} */ #endif // CORE_H