#region << 版 本 注 释 >>

/*--------------------------------------------------------------------
* 版权所有 (c) 2025 WenJY 保留所有权利。
* CLR版本：4.0.30319.42000
* 机器名称：Mr.Wen's MacBook Pro
* 命名空间：Sln.Iot.CFX
* 唯一标识：686D7EAB-9E42-43B2-B990-AF162E76F781
*
* 创建者：WenJY
* 电子邮箱：
* 创建时间：2025-10-24 15:18:38
* 版本：V1.0.0
* 描述：
*
*--------------------------------------------------------------------
* 修改人：
* 时间：
* 修改说明：
*
* 版本：V1.0.0
*--------------------------------------------------------------------*/

#endregion << 版 本 注 释 >>

using CFX;
using CFX.Production;
using CFX.Structures;
using Sln.Iot.CFX.RequestReceived;
using Sln.Iot.PLC;
using Sln.Iot.Serilog;
using static System.Runtime.CompilerServices.RuntimeHelpers;
using System.Text;

namespace Sln.Iot.CFX.CFXRequestes;

/// <summary>
/// 5.4.3.1.3 - 获取激活配方请求
///  GetActiveRecipeRequest/Response
/// </summary>
public class GetActiveRecipeRequestReceived1 : BaseGetActiveRecipeRequestReceived
{
    private readonly PLCConnect _plc = PLCConnect.Instance;


    /// <summary>
    /// 子类重写处理
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public override CFXMessage SubHandle(GetActiveRecipeRequest request)
    {

        string restr1 = string.Empty;
        string restr2 = string.Empty;

        //获取现在激活的配方
        var res1 = _plc.ReadBytes(_plc.PLC21, "D12600", 10);
        var res2 = _plc.ReadBytes(_plc.PLC21, "D12600", 10);

        if (res1.IsSuccess)
        {
            restr1 = Encoding.ASCII.GetString(res1.Content);
            restr1 = restr1.Replace("\0", "");
        }
        if (res2.IsSuccess)
        {
            restr2 = Encoding.ASCII.GetString(res2.Content);
            restr2 = restr2.Replace("\0", "");
        }

        CFXMessage response = new GetActiveRecipeResponse()
        {
            ActiveRecipeName = $"Recipe1:[{restr1}];Recipe2:[{restr2}]",
            ActiveRecipeRevision = "1.0",
            Result = new RequestResult()
            {
                Result = StatusResult.Success,
                ResultCode = 0,
                Message = ""
            }
            //配方数据
        };

        return response;
    }
}