/*
 * ProviewR   Open Source Process Control.
 * Copyright (C) 2005-2025 SSAB EMEA AB.
 *
 * This file is part of ProviewR.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ProviewR. If not, see <http://www.gnu.org/licenses/>
 *
 * Linking ProviewR statically or dynamically with other modules is
 * making a combined work based on ProviewR. Thus, the terms and
 * conditions of the GNU General Public License cover the whole
 * combination.
 *
 * In addition, as a special exception, the copyright holders of
 * ProviewR give you permission to, from the build function in the
 * ProviewR Configurator, combine ProviewR with modules generated by the
 * ProviewR PLC Editor to a PLC program, regardless of the license
 * terms of these modules. You may copy and distribute the resulting
 * combined work under the terms of your choice, provided that every
 * copy of the combined work is accompanied by a complete copy of
 * the source code of ProviewR (the version used to produce the
 * combined work), being distributed under the terms of the GNU
 * General Public License plus this exception.
 */
#include <string.h>
#include "co_math.h"
#include "rt_plc.h"
#include "rt_plc_data.h"
/* 		PLC RUTINER			*/

DpCollect


void DpCollect_exec(plc_sThread* tp, pwr_sClass_DpCollect* object)
{
  int i;
  pwr_tBoolean** InP;
  for (i = 0; i < object->MaxIndex; i++) {
    InP = (pwr_tBoolean**)((char*)&object->DpIn1P + i * pwr_cInputOffset);
    object->Dp[i] = **InP;
  }
}

ApCollect


void ApCollect_exec(plc_sThread* tp, pwr_sClass_ApCollect* object)
{
  int i;
  pwr_tFloat32** InP;
  for (i = 0; i < object->MaxIndex; i++) {
    InP = (pwr_tFloat32**)((char*)&object->ApIn1P + i * pwr_cInputOffset);
    object->Ap[i] = **InP;
  }
}

IpCollect


void IpCollect_exec(plc_sThread* tp, pwr_sClass_IpCollect* object)
{
  int i;
  pwr_tInt32** InP;
  for (i = 0; i < object->MaxIndex; i++) {
    InP = (pwr_tInt32**)((char*)&object->IpIn1P + i * pwr_cInputOffset);
    object->Ip[i] = **InP;
  }
}

DpDistribute


void DpDistribute_exec(plc_sThread* tp, pwr_sClass_DpDistribute* object)
{
  if (*object->DataInP)
    memcpy(&object->DpOut1, *object->DataInP,
        MIN(object->MaxIndex, 24) * sizeof(pwr_tBoolean));
}

ApDistribute


void ApDistribute_exec(plc_sThread* tp, pwr_sClass_ApDistribute* object)
{
  if (*object->DataInP)
    memcpy(&object->ApOut1, *object->DataInP,
        MIN(object->MaxIndex, 24) * sizeof(pwr_tFloat32));
}

IpDistribute


void IpDistribute_exec(plc_sThread* tp, pwr_sClass_IpDistribute* object)
{
  if (*object->DataInP)
    memcpy(&object->IpOut1, *object->DataInP,
        MIN(object->MaxIndex, 24) * sizeof(pwr_tInt32));
}

DataCollect


void DataCollect_exec(plc_sThread* tp, pwr_sClass_DataCollect* object)
{
  int i;
  pwr_tDataRef** InP;
  for (i = 0; i < object->MaxIndex; i++) {
    InP = (pwr_tDataRef**)((char*)&object->DataIn1P + i * pwr_cInputOffset);
    memcpy(&object->DataP[i], *InP, sizeof(pwr_tDataRef));
  }
}

CStoAttrRefP


void CStoAttrRefP_exec(
    plc_sThread* tp, pwr_sClass_CStoAttrRefP* o, pwr_sAttrRef* aref)
{
  if (*o->CondP)
    *aref = o->InP->Aref;
}