/////////////////////////////////////////////////////////////////////
//                                                                 //
// file: autoGen_SystemClass_CPP.h                                 //
//                                                                 //
/////////////////////////////////////////////////////////////////////
//                                                                 //
// Copyright (c) 2026 Acroname Inc. - All Rights Reserved          //
//                                                                 //
// This file is part of the BrainStem release. See the license.txt //
// file included with this package or go to                        //
// https://acroname.com/software/brainstem-development-kit         //
// for full license details.                                       //
/////////////////////////////////////////////////////////////////////

#ifndef __AUTOGEN_SYSTEM_CPP_H__
#define __AUTOGEN_SYSTEM_CPP_H__

#include "BrainStem-core.h"

#ifdef __GNUC__
#define DEPRECATED(...) __attribute__((deprecated(__VA_ARGS__)))
#elif defined(_MSC_VER)
#define DEPRECATED(...) __declspec(deprecated(__VA_ARGS__))
#else
#define DEPRECATED(...)
#pragma message("DEPRECATED is not defined for this compiler")
#endif

#if defined(__cplusplus)

namespace Acroname {
namespace BrainStem {

/// SystemClass:
/// The System class provides access to the core settings, configuration and system
///   information of the BrainStem module.
/// The class provides access to the model type, serial number and other static information as
///   well as the ability to set boot reflexes, toggle the user LED, as well as affect module
///   and router addresses etc.
/// 
class aLIBEXPORT SystemClass : public EntityClass {

public:

    /// Constructor.
    SystemClass(void);

    /// Destructor.
    virtual ~SystemClass(void);

    /// Initialize the System Class.
    ///
    /// \param pModule The module to which this entity belongs.
    /// \param index The index of the System entity to be addressed.
    ///
    void init(Module* pModule, const uint8_t index);

    /// Get the current address the module uses on the BrainStem network.
    /// 
    /// \param address The address the module is using on the BrainStem network.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getModule(uint8_t* address);

    /// Get the base address of the module.
    /// Software offsets and hardware offsets are added to this base address to produce the
    ///   effective module address.
    /// 
    /// \param address The address the module is using on the BrainStem network.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getModuleBaseAddress(uint8_t* address);

    /// Set the router address the module uses to communicate with the host and heartbeat to in
    ///   order to establish the BrainStem network.
    /// This setting must be saved and the board reset before the setting becomes active.
    /// Warning: changing the router address may cause the module to "drop off" the BrainStem
    ///   network if the new router address is not in use by a BrainStem module.
    /// Please review the BrainStem network fundamentals before modifying the router address.
    /// 
    /// \param address The router address to be used.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setRouter(const uint8_t address);

    /// Get the router address the module uses to communicate with the host and heartbeat to in
    ///   order to establish the BrainStem network.
    /// 
    /// \param address The address.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getRouter(uint8_t* address);

    /// Set the delay between heartbeat packets which are sent from the module.
    /// For link modules, these these heartbeat are sent to the host.
    /// For non-link modules, these heartbeats are sent to the router address.
    /// Interval values are in 25.6 millisecond increments
    /// Valid values are 1-255; default is 10 (256 milliseconds).
    /// 
    /// \param interval The desired heartbeat delay.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setHBInterval(const uint8_t interval);

    /// Get the delay between heartbeat packets which are sent from the module.
    /// For link modules, these these heartbeat are sent to the host.
    /// For non-link modules, these heartbeats are sent to the router address.
    /// Interval values are in 25.6 millisecond increments.
    /// 
    /// \param interval The current heartbeat delay.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getHBInterval(uint8_t* interval);

    /// Set the system LED state. Most modules have a blue system LED.
    /// Refer to the module datasheet for details on the system LED location and color.
    /// 
    /// \param ledOn true: turn the LED on, false: turn LED off.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setLED(const uint8_t ledOn);

    /// Get the system LED state. Most modules have a blue system LED.
    /// Refer to the module datasheet for details on the system LED location and color.
    /// 
    /// \param ledOn true: LED on, false: LED off.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getLED(uint8_t* ledOn);

    /// Sets the scaling factor for the brightness of all LEDs on the system.
    /// The brightness is set to the ratio of this value compared to 255 (maximum).
    /// The colors of each LED may be inconsistent at low brightness levels.
    /// Note that if the brightness is set to zero and the settings are saved, then the LEDs will
    ///   no longer indicate whether the system is powered on.
    /// When troubleshooting, the user configuration may need to be manually reset in order to
    ///   view the LEDs again.
    /// 
    /// \param brightness Brightness value relative to 255
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setLEDMaxBrightness(const uint8_t brightness);

    /// Gets the scaling factor for the brightness of all LEDs on the system.
    /// The brightness is set to the ratio of this value compared to 255 (maximum).
    /// 
    /// \param brightness Brightness value relative to 255
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getLEDMaxBrightness(uint8_t* brightness);

    /// Set a store slot to be mapped when the module boots.
    /// The boot slot will be mapped after the module boots from powers up, receives a reset
    ///   signal on its reset input, or is issued a software reset command.
    /// Set the slot to 255 to disable mapping on boot.
    /// 
    /// \param slot The slot number in aSTORE_INTERNAL to be marked as a boot slot.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setBootSlot(const uint8_t slot);

    /// Get the store slot which is mapped when the module boots.
    /// 
    /// \param slot The slot number in aSTORE_INTERNAL that is mapped after the module
    ///        boots.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getBootSlot(uint8_t* slot);

    /// Get the modules firmware version number.
    /// The version number is packed into the return value.
    /// Utility functions in the aVersion module can unpack the major, minor and patch numbers
    ///   from the version number which looks like M.m.p.
    /// 
    /// \param build The build version date code.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getVersion(uint32_t* build);

    /// Get the modules firmware build number
    /// The build number is a unique hash assigned to a specific firmware.
    /// 
    /// \param build Variable to be filled with build.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getBuild(uint32_t* build);

    /// Get the module's model enumeration.
    /// A subset of the possible model enumerations is defined in BrainStem.h under "BrainStem
    ///   model codes".
    /// Other codes are be used by Acroname for proprietary module types.
    /// 
    /// \param model The module's model enumeration.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getModel(uint8_t* model);

    /// Get the module's hardware revision information.
    /// The content of the hardware version is specific to each Acroname product and used to
    ///   indicate behavioral differences between product revisions.
    /// The codes are not well defined and may change at any time.
    /// 
    /// \param hardwareVersion The module's hardware version information.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getHardwareVersion(uint32_t* hardwareVersion);

    /// Get the module's serial number.
    /// The serial number is a unique 32 bit integer which is usually communicated in hexadecimal
    ///   format.
    /// 
    /// \param serialNumber The module's serial number.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getSerialNumber(uint32_t* serialNumber);

    /// Save the system operating parameters to the persistent module flash memory.
    /// Operating parameters stored in the system flash will be loaded after the module reboots.
    /// Operating parameters include: heartbeat interval, module address, module router address.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr save(void);

    /// Reset the system.
    /// A return value of aErrTimeout indicates a successful reset, as the system resets
    ///   immediately, which tears down the USB-link immediately, thus preventing an affirmative
    ///   response.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr reset(void);

    /// Saves system log events to a slot defined by the module (usually ram slot 0).
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr logEvents(void);

    /// Get the module's accumulated uptime in minutes
    /// 
    /// \param uptimeCounter The module's accumulated uptime in minutes.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getUptime(uint32_t* uptimeCounter);

    /// Get the module's current temperature in micro-C
    /// 
    /// \param temperature The module's system temperature in micro-C
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getTemperature(int32_t* temperature);

    /// Get the module's minimum temperature ever recorded in micro-C (uC).
    /// This value will persists through a power cycle.
    /// 
    /// \param minTemperature The module's minimum system temperature in micro-C
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getMinimumTemperature(int32_t* minTemperature);

    /// Get the module's maximum temperature ever recorded in micro-C (uC).
    /// This value will persists through a power cycle.
    /// 
    /// \param maxTemperature The module's maximum system temperature in micro-C
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getMaximumTemperature(int32_t* maxTemperature);

    /// Get the module's input voltage.
    /// 
    /// \param inputVoltage The module's input voltage reported in microvolts.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getInputVoltage(uint32_t* inputVoltage);

    /// Get the module's input current.
    /// 
    /// \param inputCurrent The module's input current reported in microamps.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getInputCurrent(uint32_t* inputCurrent);

    /// Get the module hardware address offset. This is added to the base address to allow the
    ///   module address to be configured in hardware.
    /// Not all modules support the hardware module address offset. Refer to the module datasheet.
    /// 
    /// \param offset The module address offset.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getModuleHardwareOffset(uint8_t* offset);

    /// Set the software address offset.
    /// This software offset is added to the module base address, and potentially a module
    ///   hardware address to produce the final module address.
    /// You must save the system settings and restart for this to take effect.
    /// Please review the BrainStem network fundamentals before modifying the module address.
    /// 
    /// \param address The address for the module. Value must be even from 0-254.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setModuleSoftwareOffset(const uint8_t address);

    /// Get the software address offset.
    /// This software offset is added to the module base address, and potentially a module
    ///   hardware address to produce the final module address.
    /// You must save the system settings and restart for this to take effect.
    /// Please review the BrainStem network fundamentals before modifying the module address.
    /// 
    /// \param address The address for the module. Value must be even from 0-254.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getModuleSoftwareOffset(uint8_t* address);

    /// Get the router address system setting.
    /// This setting may not be the same as the current router address if the router setting was
    ///   set and saved but no reset has occurred.
    /// Please review the BrainStem network fundamentals before modifying the module address.
    /// 
    /// \param address The address for the module. Value must be even from 0-254.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getRouterAddressSetting(uint8_t* address);

    /// Enables/Disables the route to me function.
    /// This function allows for easy networking of BrainStem modules.
    /// Enabling (1) this function will send an I2C General Call to all devices on the network and
    ///   request that they change their router address to the of the calling device.
    /// Disabling (0) will cause all devices on the BrainStem network to revert to their default
    ///   address.
    /// 
    /// \param enable Enable or disable of the route to me function 1 = enable.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr routeToMe(const uint8_t enable);

    /// Reports the amount of power the system has access to and thus how much power can be
    ///   budgeted to sinking devices.
    /// 
    /// \param power The available power in milli-Watts (mW, 1 t)
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getPowerLimit(uint32_t* power);

    /// Gets the user defined maximum power limit for the system.
    /// Provides mechanism for defining an unregulated power supplies capability.
    /// 
    /// \param power Variable to be filled with the power limit in milli-Watts (mW)
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getPowerLimitMax(uint32_t* power);

    /// Sets a user defined maximum power limit for the system.
    /// Provides mechanism for defining an unregulated power supplies capability.
    /// 
    /// \param power Limit in milli-Watts (mW) to be set.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setPowerLimitMax(const uint32_t power);

    /// Gets a bit mapped representation of the factors contributing to the power limit.
    /// Active limit can be found through PowerDeliverClass::getPowerLimit().
    /// 
    /// \param state Variable to be filled with the state.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getPowerLimitState(uint32_t* state);

    /// Gets the voltage present at the unregulated port.
    /// 
    /// \param voltage Variable to be filled with the voltage in micro-Volts (uV).
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getUnregulatedVoltage(int32_t* voltage);

    /// Gets the current passing through the unregulated port.
    /// 
    /// \param current Variable to be filled with the current in micro-Amps (uA).
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getUnregulatedCurrent(int32_t* current);

    /// Provides the source of the current power source in use.
    /// 
    /// \param source Variable to be filled with enumerated representation of the source.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getInputPowerSource(uint8_t* source);

    /// Gets the systems input power behavior.
    /// This behavior refers to where the device sources its power from and what happens if that
    ///   power source goes away.
    /// 
    /// \param behavior Variable to be filled with an enumerated value representing behavior.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getInputPowerBehavior(uint8_t* behavior);

    /// Sets the systems input power behavior.
    /// This behavior refers to where the device sources its power from and what happens if that
    ///   power source goes away.
    /// 
    /// \param behavior An enumerated representation of behavior to be set.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setInputPowerBehavior(const uint8_t behavior);

    /// Gets the input power behavior configuration
    /// Certain behaviors use a list of ports to determine priority when budgeting power.
    /// 
    /// \param buffer pointer to the start of a c style buffer to be filled
    /// \param bufferLength Length of the buffer to be filed
    /// \param unloadedLength Length that was actually received and filled.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getInputPowerBehaviorConfig(uint32_t* buffer, const size_t bufferLength, size_t* unloadedLength);

    /// Sets the input power behavior configuration
    /// Certain behaviors use a list of ports to determine priority when budgeting power.
    /// 
    /// \param buffer Pointer to the start of a c style buffer to be transferred.
    /// \param bufferLength Length of the buffer to be transferred.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setInputPowerBehaviorConfig(const uint32_t* buffer, const size_t bufferLength);

    /// Gets a user defined name of the device.
    /// Helpful for identifying ports/devices in a static environment.
    /// 
    /// \param buffer pointer to the start of a c style buffer to be filled
    /// \param bufferLength Length of the buffer to be filed
    /// \param unloadedLength Length that was actually received and filled.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getName(uint8_t* buffer, const size_t bufferLength, size_t* unloadedLength);

    /// Sets a user defined name for the device.
    /// Helpful for identification when multiple devices of the same type are present in a system.
    /// 
    /// \param buffer Pointer to the start of a c style buffer to be transferred.
    /// \param bufferLength Length of the buffer to be transferred.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setName(const uint8_t* buffer, const size_t bufferLength);

    /// Resets the device to it factory default configuration.
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr resetDeviceToFactoryDefaults(void);

    /// Gets the link interface configuration.
    /// This refers to which interface is being used for control by the device.
    /// 
    /// \param linkInterface Variable to be filled with an enumerated value representing
    ///        interface.
    ///            - 0 = Auto= systemLinkAuto
    ///            - 1 = Control Port = systemLinkUSBControl
    ///            - 2 = Hub Upstream Port = systemLinkUSBHub
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getLinkInterface(uint8_t* linkInterface);

    /// Sets the link interface configuration.
    /// This refers to which interface is being used for control by the device.
    /// 
    /// \param linkInterface An enumerated representation of interface to be set.
    ///            - 0 = Auto= systemLinkAuto
    ///            - 1 = Control Port = systemLinkUSBControl
    ///            - 2 = Hub Upstream Port = systemLinkUSBHub
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr setLinkInterface(const uint8_t linkInterface);

    /// Gets any system level errors.
    /// Calling this function will clear the current errors. If the error persists it will be set
    ///   again.
    /// 
    /// \param errors Bit mapped field representing the devices errors
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getErrors(uint32_t* errors);

    /// Gets the firmware protocol features
    /// 
    /// \param features Value representing the firmware protocol features
    /// 
    /// \return Returns \ref EntityReturnValues "common entity" return values
    aErr getProtocolFeatures(uint32_t* features);



};

} // namespace BrainStem
} // namespace Acroname

#endif // defined(__cplusplus)

#endif // __AUTOGEN_SYSTEM_CPP_H__