195 lines
6.1 KiB
C#
195 lines
6.1 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VisionLight {
|
|
/// <summary>
|
|
/// LVS PT Series Base Code
|
|
/// PT0105 | PT0205 | PT0405
|
|
/// </summary>
|
|
public abstract class Light_LVS_PT : LightBase_Serial {
|
|
/// <summary>
|
|
/// Light_LVS_PT생성자
|
|
/// </summary>
|
|
/// <param name="deviceId">디바이스 Id</param>
|
|
public Light_LVS_PT(string deviceId) : base(deviceId) {
|
|
DeviceId = deviceId;
|
|
LOG = new Aurora.Api.Logger(deviceId);
|
|
}
|
|
|
|
#region Set On (Single or All)
|
|
/// <summary>
|
|
/// Set On Implement
|
|
/// </summary>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns>Light 결과</returns>
|
|
protected override eLightResult SetOnImpl(int channel) {
|
|
lock (LockThis) {
|
|
if (SendData_SetOn(channel) == E1.OK) {
|
|
return eLightResult.OK;
|
|
}
|
|
else {
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
}
|
|
|
|
private int SendData_SetOn(int channel) {
|
|
try {
|
|
byte[] sendData = CreateSetOnReqMsg(channel);
|
|
byte[] recvData = new byte[1];
|
|
SerialConn.WriteAndRead(sendData, recvData, sendData.Length);
|
|
if (!CheckResponse(recvData)) { return E1.GENERIC; }
|
|
return E1.OK;
|
|
}
|
|
catch (Exception e) {
|
|
LOG.FuncE(e.Message);
|
|
}
|
|
|
|
return E1.GENERIC;
|
|
}
|
|
#endregion
|
|
|
|
#region Set Off (Single or All)
|
|
/// <summary>
|
|
/// Set Off Implement
|
|
/// </summary>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns>Light 결과 </returns>
|
|
protected override eLightResult SetOffImpl(int channel) {
|
|
lock (LockThis) {
|
|
if (SendData_SetOff(channel) == E1.OK) {
|
|
return eLightResult.OK;
|
|
}
|
|
else {
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
}
|
|
|
|
private int SendData_SetOff(int channel) {
|
|
try {
|
|
byte[] sendData = CreateSetOffReqMsg(channel);
|
|
byte[] recvData = new byte[1];
|
|
SerialConn.WriteAndRead(sendData, recvData, sendData.Length);
|
|
if (!CheckResponse(recvData)) { return E1.GENERIC; }
|
|
}
|
|
catch (Exception e) {
|
|
LOG.FuncE(e.Message);
|
|
}
|
|
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Set Level (Single or All)
|
|
/// <summary>
|
|
/// Set level Implement
|
|
/// </summary>
|
|
/// <param name="level">레벨</param>
|
|
/// <param name="channel">채널</param>
|
|
/// <returns></returns>
|
|
protected override eLightResult SetLevelImpl(int level, int channel) {
|
|
lock (LockThis) {
|
|
if (SendData_SetLevel(level, channel) == E1.OK) {
|
|
return eLightResult.OK;
|
|
}
|
|
else {
|
|
return eLightResult.NG;
|
|
}
|
|
}
|
|
}
|
|
|
|
private int SendData_SetLevel(int level, int channel) {
|
|
try {
|
|
byte[] sendData = CreateSetLevelReqMsg(level, channel);
|
|
byte[] recvData = new byte[1];
|
|
SerialConn.WriteAndRead(sendData, recvData, sendData.Length);
|
|
if (!CheckResponse(recvData)) { return E1.GENERIC; }
|
|
return E1.OK;
|
|
}
|
|
catch (Exception e) {
|
|
LOG.FuncE(e.Message);
|
|
}
|
|
|
|
return E1.GENERIC;
|
|
}
|
|
#endregion
|
|
|
|
#region Create Req Msg
|
|
|
|
/// <summary>
|
|
/// Set On 할 때 요청 Msg
|
|
/// </summary>
|
|
/// <param name="channel">ChannelRange 안의 Channel</param>
|
|
/// <returns></returns>
|
|
internal abstract byte[] CreateSetOnReqMsg(int channel);
|
|
/// <summary>
|
|
/// Set Off 할 때 요청 Msg
|
|
/// </summary>
|
|
/// <param name="channel">ChannelRange 안의 Channel</param>
|
|
/// <returns></returns>
|
|
internal abstract byte[] CreateSetOffReqMsg(int channel);
|
|
/// <summary>
|
|
/// Set Level 할 때의 요청 Msg
|
|
/// </summary>
|
|
/// <param name="level">DimRange 안의 Level</param>
|
|
/// <param name="channel">ChannelRange 안의 Channel</param>
|
|
/// <returns></returns>
|
|
internal abstract byte[] CreateSetLevelReqMsg(int level, int channel);
|
|
internal virtual byte[] CreateGetLevelReqMsg(int channel) {
|
|
// :R1[CR][LF] -> 1채널 밝기
|
|
string msg = string.Format("{0}{1}{2:D1}{3}{4}",
|
|
":", "R", channel, "\r", "\n");
|
|
return Encoding.UTF8.GetBytes(msg);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Util Light
|
|
/*검증 필요
|
|
private int GetLevelFromLightController(int channel) {
|
|
try {
|
|
if(!CheckChannel(channel)) { return E1.GENERIC; }
|
|
byte[] sendData = CreateGetLevelReqMsg(channel);
|
|
byte[] recvData = new byte[1];
|
|
SerialConn.WriteAndRead(sendData, recvData, sendData.Length);
|
|
if (recvData.Length > 0 && recvData.FirstOrDefault() == ACK) {
|
|
return recvData[0]; // temp value
|
|
}
|
|
else {
|
|
LOG.E($"Receive Error : {recvData}");
|
|
return E1.GENERIC;
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
LOG.FuncE(e.Message);
|
|
}
|
|
|
|
return E1.GENERIC;
|
|
}*/
|
|
#endregion
|
|
|
|
const byte ACK = 0x06;
|
|
internal bool CheckResponse(byte[] response) {
|
|
if (response.Length > 0 && response.FirstOrDefault() == ACK) {
|
|
return true;
|
|
}
|
|
else {
|
|
LOG.E($"Receive Error : {response}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|