/* * Copyright (c) 2025 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using Aurora.Api; using Aurora.Api.Devices; using VisionCommon; using Hermes; using System.Net.Sockets; namespace VisionLight { /// /// 소켓 조명 베이스 클래스 /// public abstract class LightBase_Socket : LightBase { /// 소켓 통신 protected SocketConn SocketConn = null; /// /// 생성자 /// EquipmentInfo.SimulationMode로 시뮬레이션 상태를 설정한다. /// /// 디바이스 ID protected LightBase_Socket(string deviceId) : base(deviceId) { LightConnType = eLightConnType.Socket; } /// /// 생성자 /// /// 디바이스 ID /// 시뮬레이션 상태 protected LightBase_Socket(string deviceId, bool isSimul) : base(deviceId, isSimul) { LightConnType = eLightConnType.Socket; } /// /// 디바이스 Activate /// /// 디바이스 컨피그 /// protected override int DoActivate(IDeviceConfig config) { SetLightConfig(config as LightConfig); InitLastChParams(); var lightConfig_Socket = (LightConfig_Socket)LightConfig; if (IsSimul) { return E1.OK; } else { if (SocketConn == null) { SocketConn = new SocketConn( DeviceId, IsSimul, lightConfig_Socket.SocketConnConfig.Protocol); } } int res = SocketConn.Connect(lightConfig_Socket.SocketConnConfig); if (res == E1.OK) { SetOnAllInternal(); // 시작시 모든 조명 On (Default) } return res; } /// /// 디바이스 Deactivate /// /// protected override int DoDeactivate() { ClearLastChParams(); if (EquipAdapter.Instance.EquipMode.IsSimulMode()) { return E1.OK; } else { if (SocketConn != null) { return SocketConn.Close(); } } return E1.OK; } /// /// 조명 켜기 /// /// 채널 번호 /// 조명 제어 결과 public eLightResult SetOn(int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetOn(channel); } /// /// 조명 끄기 /// /// 채널 번호 /// 조명 제어 결과 public new eLightResult SetOff(int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetOff(channel); } /// /// 조명 상태 가져오기 /// /// 채널 번호 /// 조명 상태 (on : true, off : false) public new bool GetOnOff(int channel) { return base.GetOnOff(channel); } /// /// 조명 값 가져오기 /// /// 채널 번호 /// 조명 값 public new int GetLevel(int channel) { if (!IsConnected()) { return 0; } return base.GetLevel(channel); } /// /// 조명 값 제어 (개별) /// /// 레벨 /// 채널 번호 /// 조명 제어 결과 public new eLightResult SetLevel(int level, int channel = -1) { if (!IsConnected()) { return eLightResult.NG; } return base.SetLevel(level, channel); } private bool IsConnected() { if (EquipAdapter.Instance.EquipMode.IsSimulMode()) { return true; } else if (SocketConn != null && SocketConn.IsConnected()) { return true; } else { return false; } } } }