/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.Api;
using Aurora.Api.DataType;
using Aurora.Api.Devices;
using PropertyTools.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO.Ports;
using VisionCommon;
namespace VisionLight {
#region Light Model Def
///
/// 조명 디바이스 모델 리스트
/// 이름 형식 : 제조사_모델
///
///
public enum eLightModel {
///
/// TSM사 P12RV2
///
TSM_P12RV2 = 0,
///
/// TSM사 I16R
///
TSM_I16R,
///
/// TSM사 STM16C
///
TSM_STM16C,
///
/// LVS사 PN
///
LVS_PN,
///
/// LVS사 PT0105
///
LVS_PT0105,
///
/// LVS사 PT0205
///
LVS_PT0205,
///
/// LVS사 PT0405
///
LVS_PT0405,
///
/// LVS사 EN04
///
LVS_EN04,
///
/// LVS사 EN04_SOCKET
///
LVS_EN04_SOCKET,
///
/// LVS사 ES08
///
LVS_ES08,
///
/// LVS사 ES08_SOCKET
///
LVS_ES08_SOCKET,
///
/// LEESOS LPD
///
LEESOS_LPD,
///
/// CCS
///
CCS,
///
/// IPLUS MODBUS_SERIAL
///
IPLUS_LED_MODBUS_SERIAL,
///
/// ERI사 E_MINI
///
ERI_E_MINI,
///
/// CAS사 Esamrt series
///
ESMART,
///
/// 장비 전용 조명 디바이스 A
///
MachineLight_A = 50,
///
/// 장비 전용 조명 디바이스 B
///
MachineLight_B,
///
/// 장비 전용 조명 디바이스 C
/// ,
MachineLight_C
}
internal static class LightModelDef {
public static Dictionary LightModels { get; set; } =
new Dictionary() {
{ eLightModel.TSM_P12RV2, typeof(Light_TSM_P12RV2) },
{ eLightModel.TSM_I16R, typeof(Light_TSM_I16R) },
{ eLightModel.TSM_STM16C, typeof(Light_TSM_STM16C) },
{ eLightModel.LVS_PN, typeof(Light_LVS_PN) },
{ eLightModel.LVS_PT0105, typeof(Light_LVS_PT0105) },
{ eLightModel.LVS_PT0205, typeof(Light_LVS_PT0205) },
{ eLightModel.LVS_PT0405, typeof(Light_LVS_PT0405) },
{ eLightModel.LVS_EN04, typeof(Light_LVS_EN04) },
{ eLightModel.LVS_EN04_SOCKET, typeof(Light_LVS_EN04_Socket) },
{ eLightModel.LVS_ES08, typeof(Light_LVS_ES08) },
{ eLightModel.LVS_ES08_SOCKET, typeof(Light_LVS_ES08_Socket) },
{ eLightModel.LEESOS_LPD, typeof(Light_LEESOS_LPD) },
{ eLightModel.CCS, typeof(Light_CCS) },
{ eLightModel.IPLUS_LED_MODBUS_SERIAL, typeof(Light_iPulse_ModbusSerial) },
{ eLightModel.ERI_E_MINI, typeof(Light_ERI_E_MINI) },
{ eLightModel.ESMART, typeof(Light_Esmart) }
};
}
#endregion
///
/// 조명 구동 방식
///
public enum eLightType {
/// 상시 구동
Continuous,
/// 점멸 구동 (짧은 시간 동안 강한 빛을 내는 섬광 방식)
Strobe
}
///
/// 조명 컬러 타입
///
public enum LightColorType {
///
/// Red
///
R = 0,
///
/// Green
///
G = 1,
///
/// Blue
///
B = 2,
///
/// White
///
W = 3,
///
/// None
///
None = 4
}
///
/// 조명 장치 타입
///
public enum LightDeviceType {
///
/// Bar형
///
Bar = 0,
///
/// Ring 형
///
Ring = 1,
///
/// Half Ring 형
///
Half_Ring = 2,
///
/// Side
///
Side = 3,
///
/// Spot
///
Spot = 4,
///
/// Coaxial
///
Coaxial = 5,
///
/// Half Coaxial
///
Half_Coaxial = 6,
///
/// BackLight
///
BackLight = 7,
///
/// ETC
///
ETC = 8
}
///
/// 조명 연결 타입
///
public enum eLightConnType {
///
/// Serial
///
Serial,
///
/// Socket
///
Socket,
///
/// ModBus Serial
///
ModbusSereial,
///
/// None
///
None,
}
///
/// 조명 디바이스 컨피그 (베이스)
///
public class LightConfig : IDeviceConfig {
///
/// Light Model
///
[SelectorStyle(SelectorStyle.ComboBox)]
public eLightModel LightModel { get; set; } = eLightModel.TSM_I16R;
///
/// Light Type
///
public eLightType LightType { get; set; } = eLightType.Continuous;
/// 미사용
[Browsable(false)]
public IConnConfig ConnConfig { get; set; }
/// 레벨 Min, Max
public Range DimRange { get; set; } = (0, 255);
/// 총 채널 개수
public Range Channels { get; set; } = (1, 8);
///
/// Channel Config
///
public ObservableCollection ChannelConfigs { get; set; } = new ObservableCollection();
///
/// 디폴트 조명 컨피그 가져오기
///
/// 조명 연결 타입
/// 조명 디바이스 컨피그
public static IDeviceConfig GetDefaultConfig(eLightConnType lightConnType) {
if (lightConnType == eLightConnType.Serial) {
return new LightConfig_Serial();
}
else if (lightConnType == eLightConnType.Socket) {
return new LightConfig_Socket();
}
else if (lightConnType == eLightConnType.ModbusSereial) {
return new LightConnfig_ModbusSerial();
}
else {
Logger.E("Not supported Light connection type!!!");
return null;
}
}
}
///
/// 조명 디바이스 컨피그 (시리얼 통신용)
///
public class LightConfig_Serial : LightConfig {
///
/// Serial Connection Config
///
public SerialConnConfig SerialConnConfig { get; set; } = new SerialConnConfig() {
PortNum = 1,
BaudRate = 115200,
Parity = Parity.None,
StopBits = StopBits.One,
DataBits = 8
};
}
///
/// 조명 디바이스 컨피그 (소켓 통신용)
///
public class LightConfig_Socket : LightConfig {
///
/// Socket Connection 컨피그
///
public SocketConnConfig SocketConnConfig { get; set; } = new SocketConnConfig() {
Address = new SocketAddress() {
IpAddress = "100.100.100.100",
PortNumber = 6000
},
Protocol = SocketProtocol.UDP,
ResponseTimeMS = 3000
};
}
///
/// 조명 디바이스 컨피그 (모드버스 시리얼 통신용)
///
public class LightConnfig_ModbusSerial : LightConfig {
///
/// Light Config(Modbus Serial)
///
public LightConnfig_ModbusSerial() {
ModbusSerialConnConfig = new ModbusSerialConnConfig() {
PortNum = 1,
BaudRate = 115200,
Parity = Parity.None,
StopBits = StopBits.One,
DataBits = 8,
Slave = 0
};
ConnConfig = ModbusSerialConnConfig;
}
private ModbusSerialConnConfig _ModbusSerialConnConfig;
///
/// Modbus Serial Connection Config
///
public ModbusSerialConnConfig ModbusSerialConnConfig {
get => _ModbusSerialConnConfig;
set {
_ModbusSerialConnConfig = value;
ConnConfig = ModbusSerialConnConfig;
}
}
}
///
/// Light Config Info
/// LighId | DimRange | ChConfig
///
public class LightConfigInfo : ICloneCopy {
///
/// Light Id
///
public eLightId LightId { get; set; } = eLightId.None;
///
/// Dim Ranged (0, 255)
///
public Range DimRange { get; set; } = (0, 255);
///
/// Channel Config
///
public ChConfig ChConfig { get; set; } = new ChConfig();
///
/// Clone
///
///
public LightConfigInfo Clone() {
return ((ICloneable)this).Clone() as LightConfigInfo;
}
///
/// Copy To Target
///
/// 복사할 타겟
public void CopyTo(LightConfigInfo target) {
target.LightId = this.LightId;
target.DimRange = (this.DimRange.Min, this.DimRange.Max);
target.ChConfig = this.ChConfig.Clone();
}
object ICloneable.Clone() {
var cloneObj = new LightConfigInfo();
CopyTo(cloneObj);
return cloneObj;
}
}
///
/// 채널 컨피그
///
public class ChConfig : ICloneCopy {
///
/// 채널
///
public int Ch { get; set; } = 1;
///
/// On/Off
///
public bool OnOff { get; set; } = true;
///
/// 레벨
///
public int Level { get; set; } = 80;
///
/// Light 디바이스 종류
///
public LightDeviceType DeviceType { get; set; } = LightDeviceType.Ring;
///
/// 컬러 타입
///
public LightColorType ColorType { get; set; } = LightColorType.W;
///
/// 캠 ID
///
public eCamId CamId { get; set; } = eCamId.None;
///
/// Clone
///
///
public ChConfig Clone() {
return ((ICloneable)this).Clone() as ChConfig;
}
///
/// Copy To Target
///
/// 복사할 타겟
public void CopyTo(ChConfig target) {
target.CamId = this.CamId;
target.Ch = this.Ch;
target.ColorType = this.ColorType;
target.DeviceType = this.DeviceType;
target.Level = this.Level;
target.OnOff = this.OnOff;
}
object ICloneable.Clone() {
var cloneObj = new ChConfig();
CopyTo(cloneObj);
return cloneObj;
}
}
}