/*
 * Copyright (c) 2013, Linz Center of Mechatronics GmbH (LCM), web: www.lcm.at
 * All rights reserved.
 */
/*
 * This file is licensed according to the BSD 3-clause license as follows:
 * 
 * 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 "Linz Center of Mechatronics GmbH" and "LCM" 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 "Linz Center of Mechatronics GmbH" 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.
 */
/*
 * This file is part of X2C. web: x2c.lcm.at
 * $LastChangedRevision: 4457 $
 * $LastChangedDate:: 2026-08-13 18:59:23 +0200#$
 */
/* USERCODE-BEGIN:Description */
/* Description: */
/* USERCODE-END:Description */

package at.lcm.x2c.library.control;

import at.lcm.x2c.core.structure.*;
import at.lcm.bu21.general.dtypes.*;

/* USERCODE-BEGIN:Imports */
/* USERCODE-END:Imports */

@SuppressWarnings("unused")
public class ConvFnc_TDSystemO1_Float32 extends JavaConversionFunction {
    private static final long serialVersionUID = 1L;

    @Override
    public void convertMaskToImplementation() throws Exception {
        MaskDouble AMaskVal = (MaskDouble)this.getMaskParameter("A").getMaskDataType();
        TNumeric AMaskData = (TNumeric)AMaskVal.getData();
        double mp_A = AMaskData.getReal(0, 0);
        MaskDouble BMaskVal = (MaskDouble)this.getMaskParameter("B").getMaskDataType();
        TNumeric BMaskData = (TNumeric)BMaskVal.getData();
        double mp_B = BMaskData.getReal(0, 0);
        MaskDouble CMaskVal = (MaskDouble)this.getMaskParameter("C").getMaskDataType();
        TNumeric CMaskData = (TNumeric)CMaskVal.getData();
        double mp_C = CMaskData.getReal(0, 0);
        MaskDouble DMaskVal = (MaskDouble)this.getMaskParameter("D").getMaskDataType();
        TNumeric DMaskData = (TNumeric)DMaskVal.getData();
        double mp_D = DMaskData.getReal(0, 0);

        TNumeric a11CtrVal = this.getImplementationParameterData("a11");
        double cp_a11 = Double.NaN;
        TNumeric b11CtrVal = this.getImplementationParameterData("b11");
        double cp_b11 = Double.NaN;
        TNumeric c11CtrVal = this.getImplementationParameterData("c11");
        double cp_c11 = Double.NaN;
        TNumeric d11CtrVal = this.getImplementationParameterData("d11");
        double cp_d11 = Double.NaN;

        /* ATTENTION: */
        /* The M2I conversion function may either use the mp_* or *MaskVal value to get the Mask Parameter value */
        /* For new or updated implementations, the mp_* value shall be used where possible */
        /* Currently, the mp_* value cannot be used for getting non-scalar Mask Parameter data but will return only the first element for these */
        /* The Implementation Parameter assignment variables cp_* can and shall be used for all Implementation Parameter data types */

        /* INFO: Implementation data assignment for array types when using the cp_* variables */
        /* If the cp_* parameter is a FLASH ARRAY, the cp_* variable is assigned an array type but without an actual array */
        /* The M2I conversion function has to assign an array with the correct size and fill it with content */
        /* If the cp_* parameter is a RAM ARRAY, the cp_* variable is assigned an array with the correct size */
        /* The first element is assigned an invalid value while the other elements are (auto)initialized with zero */
        /* The M2I conversion function has to fill the array with content */

        /* Mask parameter values */
        /* mp_A OR AMaskVal (Number) */
        /* mp_B OR BMaskVal (Number) */
        /* mp_C OR CMaskVal (Number) */
        /* mp_D OR DMaskVal (Number) */

        /* USERCODE-BEGIN:ConvMaskToImplementation */
		/* get mask values and set controller parameter values */
		a11CtrVal.setReal(0, 0, Double.valueOf(AMaskVal.getValue()));
		b11CtrVal.setReal(0, 0, Double.valueOf(BMaskVal.getValue()));
		c11CtrVal.setReal(0, 0, Double.valueOf(CMaskVal.getValue()));
		d11CtrVal.setReal(0, 0, Double.valueOf(DMaskVal.getValue()));

        /* USERCODE-END:ConvMaskToImplementation */

        /* Implementation Parameter values */
        /* cp_a11 OR a11CtrVal (Value) */
        /* cp_b11 OR b11CtrVal (Value) */
        /* cp_c11 OR c11CtrVal (Value) */
        /* cp_d11 OR d11CtrVal (Value) */

        if (Double.isNaN(cp_a11)) {
            this.setImplementationParameterData("a11", a11CtrVal);
        } else {
            this.setImplementationParameterData("a11", new TNumeric(cp_a11));
        }
        if (Double.isNaN(cp_b11)) {
            this.setImplementationParameterData("b11", b11CtrVal);
        } else {
            this.setImplementationParameterData("b11", new TNumeric(cp_b11));
        }
        if (Double.isNaN(cp_c11)) {
            this.setImplementationParameterData("c11", c11CtrVal);
        } else {
            this.setImplementationParameterData("c11", new TNumeric(cp_c11));
        }
        if (Double.isNaN(cp_d11)) {
            this.setImplementationParameterData("d11", d11CtrVal);
        } else {
            this.setImplementationParameterData("d11", new TNumeric(cp_d11));
        }
    }

    @Override
    public void convertImplementationToMask() throws Exception {
        MaskDouble AMaskVal = (MaskDouble)this.getMaskParameter("A").getMaskDataType();
        TNumeric AMaskData = (TNumeric)AMaskVal.getData();
        double mp_A = Double.NaN;
        MaskDouble BMaskVal = (MaskDouble)this.getMaskParameter("B").getMaskDataType();
        TNumeric BMaskData = (TNumeric)BMaskVal.getData();
        double mp_B = Double.NaN;
        MaskDouble CMaskVal = (MaskDouble)this.getMaskParameter("C").getMaskDataType();
        TNumeric CMaskData = (TNumeric)CMaskVal.getData();
        double mp_C = Double.NaN;
        MaskDouble DMaskVal = (MaskDouble)this.getMaskParameter("D").getMaskDataType();
        TNumeric DMaskData = (TNumeric)DMaskVal.getData();
        double mp_D = Double.NaN;

        TNumeric a11CtrVal = this.getImplementationParameterData("a11");
        double cp_a11 = a11CtrVal.getReal(0, 0);
        TNumeric b11CtrVal = this.getImplementationParameterData("b11");
        double cp_b11 = b11CtrVal.getReal(0, 0);
        TNumeric c11CtrVal = this.getImplementationParameterData("c11");
        double cp_c11 = c11CtrVal.getReal(0, 0);
        TNumeric d11CtrVal = this.getImplementationParameterData("d11");
        double cp_d11 = d11CtrVal.getReal(0, 0);

        /* ATTENTION: */
        /* The I2M conversion function may either use the cp_* or *CtrlVal value to get the Implementation Parameter value */
        /* For new or updated implementations, the cp_* value shall be used for all Implementation Parameter data types */
        /* The Mask Parameter assignment variables cp_* shall be used where possible */
        /* Currently, the mp_* variable assignment value cannot be used for setting non-scalar Mask Parameter data */

        /* Implementation Parameter values */
        /* cp_a11 OR a11CtrVal (Value) */
        /* cp_b11 OR b11CtrVal (Value) */
        /* cp_c11 OR c11CtrVal (Value) */
        /* cp_d11 OR d11CtrVal (Value) */

        /* USERCODE-BEGIN:ConvImplementationToMask */
		/* get controller values and set mask parameter values */
		AMaskData.setReal(0, 0, a11CtrVal.getReal(0, 0));
		BMaskData.setReal(0, 0, b11CtrVal.getReal(0, 0));
		CMaskData.setReal(0, 0, c11CtrVal.getReal(0, 0));
		DMaskData.setReal(0, 0, d11CtrVal.getReal(0, 0));

        /* USERCODE-END:ConvImplementationToMask */

        /* Mask parameter values */
        /* mp_A OR AMaskVal (Number) */
        /* mp_B OR BMaskVal (Number) */
        /* mp_C OR CMaskVal (Number) */
        /* mp_D OR DMaskVal (Number) */

        if (Double.isNaN(mp_A)) {
            this.getMaskParameter("A").setValue(AMaskData.toFullString());
        } else {
            this.getMaskParameter("A").setValue(new TNumeric(mp_A).toFullString());
        }
        if (Double.isNaN(mp_B)) {
            this.getMaskParameter("B").setValue(BMaskData.toFullString());
        } else {
            this.getMaskParameter("B").setValue(new TNumeric(mp_B).toFullString());
        }
        if (Double.isNaN(mp_C)) {
            this.getMaskParameter("C").setValue(CMaskData.toFullString());
        } else {
            this.getMaskParameter("C").setValue(new TNumeric(mp_C).toFullString());
        }
        if (Double.isNaN(mp_D)) {
            this.getMaskParameter("D").setValue(DMaskData.toFullString());
        } else {
            this.getMaskParameter("D").setValue(new TNumeric(mp_D).toFullString());
        }
    }
}
