60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from .processor_utils import get_scl_representation, format_variable_name,get_target_scl_name
|
|
|
|
|
|
# TODO: Import necessary functions from processor_utils
|
|
# Example: from .processor_utils import get_scl_representation, format_variable_name
|
|
# Or: import processors.processor_utils as utils
|
|
|
|
# TODO: Define constants if needed (e.g., SCL_SUFFIX) or import them
|
|
SCL_SUFFIX = "_scl"
|
|
|
|
# --- Function code starts ---
|
|
def process_scoil(instruction, network_id, scl_map, access_map, data):
|
|
"""Genera SCL para Set Coil (SCoil): IF condition THEN variable := TRUE; END_IF;"""
|
|
instr_uid = instruction["instruction_uid"]
|
|
instr_type = instruction["type"]
|
|
if instr_type.endswith(SCL_SUFFIX) or "_error" in instr_type:
|
|
return False # Ya procesado o con error
|
|
|
|
# Obtener condición de entrada (RLO)
|
|
in_info = instruction["inputs"].get("in")
|
|
condition_scl = get_scl_representation(in_info, network_id, scl_map, access_map)
|
|
|
|
# Obtener operando (variable a poner a TRUE)
|
|
operand_info = instruction["inputs"].get("operand")
|
|
variable_scl = get_scl_representation(operand_info, network_id, scl_map, access_map)
|
|
|
|
# Verificar dependencias
|
|
if condition_scl is None or variable_scl is None:
|
|
return False # Dependencias no listas
|
|
|
|
# Verificar que el operando sea una variable
|
|
if not (operand_info and operand_info.get("type") == "variable"):
|
|
print(f"Error: SCoil {instr_uid} operando no es variable o falta info (Tipo: {operand_info.get('type')}).")
|
|
instruction["scl"] = f"// ERROR: SCoil {instr_uid} operando no es variable."
|
|
instruction["type"] += "_error"
|
|
return True # Procesado con error
|
|
|
|
# Formatear nombre de variable
|
|
variable_name_formatted = format_variable_name(variable_scl)
|
|
|
|
# Generar SCL
|
|
scl_core = f"{variable_name_formatted} := TRUE;"
|
|
scl_final = (
|
|
f"IF {condition_scl} THEN\n {scl_core}\nEND_IF;" if condition_scl != "TRUE" else scl_core
|
|
)
|
|
|
|
# Actualizar instrucción
|
|
instruction["scl"] = scl_final
|
|
instruction["type"] = instr_type + SCL_SUFFIX
|
|
# SCoil no genera salida 'out' ni 'eno' significativas para propagar
|
|
return True
|
|
|
|
# --- Function code ends ---
|
|
|
|
# --- Processor Information Function ---
|
|
def get_processor_info():
|
|
"""Devuelve la información para la bobina Set (SCoil)."""
|
|
return {'type_name': 'scoil', 'processor_func': process_scoil, 'priority': 3}
|