2026-01-26 18:56:53 +09:00

99 lines
3.5 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Hermes;
using Hermes.Functional;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading.Tasks;
namespace VisionLight {
/// <summary>
/// [상시 조명 컨트롤러 - 2CH / 시리얼 통신]
/// Range : (0,1023)
/// Baudrate : 19200 or 57600 bps
/// DataBit : 8 bit
/// StopBit : 1 bit
/// ParityBit : None
/// </summary>
public class Light_LVS_PT0205 : Light_LVS_PT {
/// <summary>
/// LVS_PT0205 생성자
/// </summary>
/// <param name="deviceId"> Device Id </param>
public Light_LVS_PT0205(string deviceId) : base(deviceId) {
DeviceId = deviceId;
}
/// <summary>
/// Channel 개별로 설정하는 protocol이 없어 temp 저장하는 Channel 통신여부를 확인할 수 있는 Param 제공
/// 2CH에만 제공. ( 1CH/4CH 개별로 세팅하는 protocol 존재 )
/// </summary>
private bool[] ChannelCom = new bool[2];
internal override byte[] CreateSetOnReqMsg(int channel) {
string msg = "";
if (channel != -1 && channel > 0) {
ChannelCom[channel - 1] = true;
// :1O10[CR][LF] -> 1번 채널 켜기
msg = string.Format("{0}{1}{2}{3:D1}{4:D1}{5}{6}",
":", "1", "O", ChannelCom[0], ChannelCom[1], "\r", "\n");
}
else {
// :1O11[CR][LF] -> 모든 채널 켜기
msg = string.Format("{0}{1}{2}{3}{4}{5}{6}",
":", "1", "O", "1", "1", "\r", "\n");
}
return Encoding.UTF8.GetBytes(msg);
}
internal override byte[] CreateSetOffReqMsg(int channel) {
string msg = "";
if (channel != -1 && channel > 0) {
ChannelCom[channel - 1] = false;
// :1O10[CR][LF] -> 2번 채널 끄기
msg = string.Format("{0}{1}{2}{3:D1}{4:D1}{5}{6}",
":", "1", "O", ChannelCom[0], ChannelCom[1], "\r", "\n");
}
else {
// :1O00[CR][LF] -> 모든 채널 켜기
msg = string.Format("{0}{1}{2}{3}{4}{5}{6}",
":", "1", "O", "0", "0", "\r", "\n");
}
return Encoding.UTF8.GetBytes(msg);
}
internal override byte[] CreateSetLevelReqMsg(int level, int channel) {
string msg = "";
if (channel != -1) {
// :110100[CR][LF] -> 1번 채널 밝기 100 설정
msg = string.Format("{0}{1}{2:D1}{3:D4}{4}{5}",
":", "1", channel, level, "\r", "\n");
}
else {
// 110100,100[CR][LF] -> 모든 채널 밝기 100으로 설정 (1/2 CH)
msg = string.Format("{0}{1}{2}{3:D4}{4}{5:D3}{6}{7}",
":", "1", "1", level, ",", level, "\r", "\n");
}
return Encoding.UTF8.GetBytes(msg);
}
/// <summary>
/// Device Deactiavate 될 때 호출
/// </summary>
/// <returns></returns>
protected override int DoDeactivate() {
ChannelCom.ForEach(x => x = false);
return base.DoDeactivate();
}
}
}