/********************************************
*                   Data.cs                 *
********************************************/
/*******************************************************************************************************************************************************
*    All Project Files Copyright © 2025 by The ep5 Educational Broadcasting Foundation                                                                 *
*                                                                                                                                                      *
*    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:    *
*                                                                                                                                                      *
*        →  Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer:              *
*        →  Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the     *
*           documentation and/or other materials provided with the distribution.                                                                       *
*        →  Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this    *
*           software without specific prior written permission.                                                                                        *
*                                                                                                                                                      *
*    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED     *
*    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO  EVENT SHALL THE COPYRIGHT HOLDER OR     *
*    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,         *
*    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF         *
*    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT, INCLUDING NEGLIGENCE OR OTHERWISE, ARISING IN ANY WAY OUT OF THE USE OF THIS           *
*    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                                                                                      *
*******************************************************************************************************************************************************/

//  Written/updated 21 December 2025 by David Fisher
//  Copyright © 2025 by The ep5 Educational Broadcasting Foundation; all rights reserved

/****************************************************************************************************
 *                                                                                                  *
 *     This code is specific to the I/O hardware and its driver.                                    *
 *                                                                                                  *
 ***************************************************************************************************/

/****************************************************************************************************************************************************************
 *                                                                                                                                                              *
 *  Note: the intent is to use ISO 8601 format and notation for all dates and times. From https://www.iso.org/iso-8601-date-and-time-format.html                *
 *  ISO 8601 tackles date/time uncertainty by setting out an internationally agreed way to represent dates: YYYY-MM-DD                                          *
 *  Therefore, the order of the elements used to express date and time in ISO 8601 is as follows: year, month, day, hour, minutes, seconds, and milliseconds.   *
 *  For example, 27 September 2022 at 6 pm is represented as 2022-09-27 18:00:00.000.                                                                           *
 *                                                                                                                                                              *
 ***************************************************************************************************************************************************************/

namespace TaskScheduler
{
    /// <summary>
    ///     These variables are used throughout the program in computations and display of data.
    ///     They are not part of the machine-state data, but are fixed or working program data.
    /// </summary>
    public class Data
    {
        /// <summary>These values are fixed for the program and do not change during execution.</summary>
        /// <remarks name="ipAddress">The IP address of the fieldbus coupler used to communicate with the ProtosX digital I/O terminals.</remarks>
        public static readonly string ipAddress = "10.10.1.1";                  // fieldbus coupler IP address
        /// <remarks name="port">This is the default port number for Modbus over Ethernet.</remarks>
        public static readonly int port = 502;                                  // default Modbus TCP port
        /// <remarks name="numberOfCoils">This is the Modbus parameter which fixes the number of contiguous digital output points to write to or read from</remarks>
        public static readonly ushort numberOfCoils = 32;                       // number of discrete coils to read or write
        /// <remarks name="coilInputStartAddress">This is the Modbus parameter which fixes the starting address for reading digital inputs.</remarks>
        public static readonly ushort coilInputStartAddress = 0;                // starting address for reading digital inputs
        /// <remarks name="coilOutputStartAddress">This is the Modbus parameter which fixes the starting address for writing digital outputs.</remarks>
        public static readonly ushort coilOutputStartAddress = 0;               // starting address for writing to digital outputs
        /// <remarks name="failureCode">These codes are used to identify the reason for program interruption and/or termination.</remarks>
        public static readonly byte[] failureCode = 
                                           [0,                                  // 0 = success
                                            1,                                  // 1 = digital I/O write failure
                                            2,                                  // 2 = analogue I/O write failure
                                            3,                                  // 3 = operator quit; transfer temporary log file to archive, then end program
                                            4,                                  // 4 = bad config file
                                            5,                                  // 5 = init failure
                                            6,                                  // 6 = digital I/O read failure
                                            7];                                 // 7 = analogue I/O read failure

        /// <summary>Working program data</summary>
        /// <summary>This title identifies the program, recipe, and begin datetime.</summary>
        public static string? processRunTitle;
        /// <summary>This file is created with a unique name when the run begins. It logs machine-state values.</summary>
        public static string? tempFileName;
        /// <summary>These channels are on the two ProtosX PX-149 digital terminals used for digital inputs. They will need to be tied to a data dictionary for readable names.</summary>
        public static int numberOfDigitalInputs;
        /// <summary>These channels are on the two ProtosX PX-249 digital terminals used for digital outputs. They will need to be tied to a data dictionary for readable names.</summary>
        public static int numberOfDigitalOutputs;
    }
}
