2026-01-26 14:51:28 +09:00

140 lines
4.6 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.Api;
using Hermes;
using LightControlCCS_Library;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisionCommon;
namespace VisionLight {
/// <summary>
/// LightControlCCS_Library 사용 (Socket)
/// Inkjet Oledos 향 검증 완료
/// </summary>
public class Light_CCS : LightBase_Socket {
ManagementMain managementMain;
/// <summary>
/// Light CCS 생성자
/// </summary>
/// <param name="deviceId">Device Id</param>
/// <param name="isSimul">Simulation Mode</param>
public Light_CCS(string deviceId, bool isSimul) : base(deviceId, isSimul) {
DeviceId = deviceId;
IsSimul = isSimul;
try {
managementMain = new ManagementMain();
}
catch (Exception ex) {
LOG.W("Warning : " + ex.Message, ".ctor");
}
}
/// <summary>
/// Light CCS 생성자
/// </summary>
/// <param name="deviceId">디바이스 Id</param>
public Light_CCS(string deviceId) : base(deviceId)
{
DeviceId = deviceId;
IsSimul = false;
try {
managementMain = new ManagementMain();
} catch (Exception ex) {
LOG.W("Warning : " + ex.Message, ".ctor");
}
}
private bool CCS_SetValue(int channel, int value) {
if (IsSimul) { return true; }
return managementMain.SetValue(channel, value);
}
/// <summary>
/// Set Level Implement
/// </summary>
/// <param name="level">레벨</param>
/// <param name="channel">채널</param>
/// <returns></returns>
protected override eLightResult SetLevelImpl(int level, int channel) {
LOG.FuncI();
return CCS_SetValue(channel, level) ? eLightResult.OK : eLightResult.NG;
}
/// <summary>
/// Set Off Implement
/// </summary>
/// <param name="channel">채널</param>
/// <returns>Light 결과 값</returns>
protected override eLightResult SetOffImpl(int channel) {
LOG.FuncI();
return SetLevelImpl(0, channel);
}
/// <summary>
/// Set On Implement
/// </summary>
/// <param name="channel">채널</param>
/// <returns>Light 결과 값 </returns>
protected override eLightResult SetOnImpl(int channel) {
LOG.FuncI();
int level = LightConfig.Channels.Max;
if (LastChLevels.Count > channel) {
level = LastChLevels[channel];
}
return CCS_SetValue(channel, level) ? eLightResult.OK : eLightResult.NG;
}
/// <summary>
/// Device Activate
/// </summary>
/// <param name="config">Device Config</param>
/// <returns>결과 값</returns>
protected override int DoActivate(IDeviceConfig config) {
base.SetLightConfig(config as LightConfig);
base.InitLastChParams();
var sockConfig = (LightConfig_Socket)LightConfig;
IsSimul = EquipAdapter.Instance.EquipMode.IsSimulMode();
bool res = true;
if (IsSimul) {
res = true;
}
else {
try {
res = managementMain.Connect(sockConfig.SocketConnConfig.Address.IpAddress, sockConfig.SocketConnConfig.Address.PortNumber);
}
catch (Exception ex) {
LOG.W("Warning : " + ex.Message, "DoActivate");
res = false;
}
}
if (res) {
base.SetOnAllInternal(); // 시작시 모든 조명 On (Default)
return E1.OK;
}
else { return -3000000; }
}
/// <summary>
/// Device Deactiavate 될 때 호출
/// </summary>
/// <returns></returns>
protected override int DoDeactivate() {
base.ClearLastChParams();
if (IsSimul) {
return E1.OK;
}
else {
try {
return managementMain.DisConnect() ? E1.OK : -3000000;
}
catch (Exception ex) {
LOG.W("Warning : " + ex.Message, "DoDeactivate");
return -3000000;
}
}
}
}
}