chore: HERV 통합 저장소 재초기화 커밋

손상된 .git 히스토리(missing tree)로 재초기화 후 작업트리 전체 커밋.
.claude/ 만 제외(로컬 에이전트 설정). 구 저장소 백업(.git_corrupt_backup/) 포함.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
jeon
2026-06-16 09:29:03 +09:00
commit a502322188
630 changed files with 65126 additions and 0 deletions
+125
View File
@@ -0,0 +1,125 @@
<Application x:Class="ERVSimulator.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<!-- Tokyo Night palette (DiffuserSimulator 와 동일) -->
<Color x:Key="PrimaryBg">#1E1E2E</Color>
<Color x:Key="SecondaryBg">#2B2B3D</Color>
<Color x:Key="CardBg">#313147</Color>
<Color x:Key="AccentBlue">#7AA2F7</Color>
<Color x:Key="AccentGreen">#9ECE6A</Color>
<Color x:Key="AccentRed">#F7768E</Color>
<Color x:Key="AccentYellow">#E0AF68</Color>
<Color x:Key="AccentCyan">#7DCFFF</Color>
<Color x:Key="AccentPurple">#BB9AF7</Color>
<Color x:Key="AccentOrange">#FF9E64</Color>
<Color x:Key="TextPrimary">#C0CAF5</Color>
<Color x:Key="TextSecondary">#565F89</Color>
<Color x:Key="BorderColor">#3B3B55</Color>
<SolidColorBrush x:Key="PrimaryBgBrush" Color="{StaticResource PrimaryBg}"/>
<SolidColorBrush x:Key="SecondaryBgBrush" Color="{StaticResource SecondaryBg}"/>
<SolidColorBrush x:Key="CardBgBrush" Color="{StaticResource CardBg}"/>
<SolidColorBrush x:Key="AccentBlueBrush" Color="{StaticResource AccentBlue}"/>
<SolidColorBrush x:Key="AccentGreenBrush" Color="{StaticResource AccentGreen}"/>
<SolidColorBrush x:Key="AccentRedBrush" Color="{StaticResource AccentRed}"/>
<SolidColorBrush x:Key="AccentYellowBrush" Color="{StaticResource AccentYellow}"/>
<SolidColorBrush x:Key="AccentCyanBrush" Color="{StaticResource AccentCyan}"/>
<SolidColorBrush x:Key="AccentPurpleBrush" Color="{StaticResource AccentPurple}"/>
<SolidColorBrush x:Key="AccentOrangeBrush" Color="{StaticResource AccentOrange}"/>
<SolidColorBrush x:Key="TextPrimaryBrush" Color="{StaticResource TextPrimary}"/>
<SolidColorBrush x:Key="TextSecondaryBrush" Color="{StaticResource TextSecondary}"/>
<SolidColorBrush x:Key="BorderBrush" Color="{StaticResource BorderColor}"/>
<Style x:Key="ModernButton" TargetType="Button">
<Setter Property="Background" Value="{StaticResource AccentBlueBrush}"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="Padding" Value="18,8"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}"
CornerRadius="6" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Opacity" Value="0.85"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="border" Property="Opacity" Value="0.4"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ModernComboBox" TargetType="ComboBox">
<Setter Property="Background" Value="{StaticResource CardBgBrush}"/>
<Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/>
<Setter Property="FontWeight" Value="SemiBold"/>
<Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="8,5"/>
<Setter Property="FontSize" Value="13"/>
<!-- 드롭다운 목록은 시스템 기본 흰색 배경이므로 항목 글자색을 검정으로 -->
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem">
<Setter Property="Foreground" Value="Black"/>
</Style>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="ModernTextBox" TargetType="TextBox">
<Setter Property="Background" Value="{StaticResource CardBgBrush}"/>
<Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/>
<Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Padding" Value="8,5"/>
<Setter Property="FontSize" Value="13"/>
</Style>
<!-- 공용 카드 (섹션 패널) -->
<Style x:Key="SectionCard" TargetType="Border">
<Setter Property="Background" Value="{StaticResource SecondaryBgBrush}"/>
<Setter Property="CornerRadius" Value="10"/>
<Setter Property="Padding" Value="14,12"/>
<Setter Property="Margin" Value="0,0,0,8"/>
</Style>
<Style x:Key="InnerCard" TargetType="Border">
<Setter Property="Background" Value="{StaticResource CardBgBrush}"/>
<Setter Property="CornerRadius" Value="8"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Margin" Value="4"/>
<Setter Property="BorderBrush" Value="{StaticResource BorderBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
<Style x:Key="SectionTitle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource AccentCyanBrush}"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Margin" Value="0,0,0,6"/>
</Style>
<Style x:Key="FieldLabel" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource TextSecondaryBrush}"/>
<Setter Property="FontSize" Value="11"/>
</Style>
<Style x:Key="FieldValue" TargetType="TextBlock">
<Setter Property="Foreground" Value="{StaticResource TextPrimaryBrush}"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontFamily" Value="Consolas"/>
</Style>
</Application.Resources>
</Application>
@@ -0,0 +1,8 @@
using System.Windows;
namespace ERVSimulator
{
public partial class App : Application
{
}
}
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
<RootNamespace>ERVSimulator</RootNamespace>
<AssemblyName>ERVSimulator</AssemblyName>
<StartupObject>ERVSimulator.App</StartupObject>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.IO.Ports" Version="10.0.5" />
</ItemGroup>
<ItemGroup>
<!-- ERV↔Dashboard 공용 프로토콜 (단일 진실원본) -->
<ProjectReference Include="..\..\..\TestProgram\ErvProtocol\ErvProtocol.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,96 @@
<Window x:Class="ERVSimulator.HystWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="공기질 센서 히스테리시스" SizeToContent="WidthAndHeight"
ResizeMode="NoResize" WindowStartupLocation="CenterOwner"
Background="{StaticResource PrimaryBgBrush}">
<Border Style="{StaticResource SectionCard}" Margin="10">
<StackPanel>
<TextBlock Text="공기질 센서 히스테리시스 — 모드(프리셋)별 오염단계 임계 + 히스(하강)" Style="{StaticResource SectionTitle}"/>
<!-- 활성 프리셋 선택 -->
<StackPanel Orientation="Horizontal" x:Name="PresetPanel" Margin="0,2,0,10">
<TextBlock Text="활성 프리셋" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center" Width="84" FontSize="12" FontWeight="SemiBold"/>
<Button Content="ECO" Tag="0" Click="Preset_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="80" Background="{StaticResource CardBgBrush}"/>
<Button Content="NORMAL" Tag="1" Click="Preset_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="80" Background="{StaticResource CardBgBrush}"/>
<Button Content="TURBO" Tag="2" Click="Preset_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="80" Background="{StaticResource CardBgBrush}"/>
</StackPanel>
<TextBlock Text="오염단계 0~4(좋음·보통·나쁨·매우나쁨·최악). 각 값은 해당 단계의 상한(이하). 4단계(최악)는 3단계 상한 초과. + 히스테리시스(하강)." Foreground="{StaticResource TextSecondaryBrush}" FontSize="10" Margin="0,0,0,6"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="84"/>
<ColumnDefinition Width="84"/>
<ColumnDefinition Width="84"/>
<ColumnDefinition Width="84"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="1" Text="CO2" TextAlignment="Center" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}"/>
<TextBlock Grid.Row="0" Grid.Column="2" Text="PM2.5" TextAlignment="Center" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}"/>
<TextBlock Grid.Row="0" Grid.Column="3" Text="PM10" TextAlignment="Center" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}"/>
<TextBlock Grid.Row="0" Grid.Column="4" Text="VOC" TextAlignment="Center" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="0단계(좋음)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentBlueBrush}"/>
<TextBox x:Name="TCo2_1" Grid.Row="1" Grid.Column="1" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm25_1" Grid.Row="1" Grid.Column="2" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm10_1" Grid.Row="1" Grid.Column="3" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TVoc_1" Grid.Row="1" Grid.Column="4" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="1단계(보통)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentGreenBrush}"/>
<TextBox x:Name="TCo2_2" Grid.Row="2" Grid.Column="1" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm25_2" Grid.Row="2" Grid.Column="2" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm10_2" Grid.Row="2" Grid.Column="3" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TVoc_2" Grid.Row="2" Grid.Column="4" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="2단계(나쁨)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentYellowBrush}"/>
<TextBox x:Name="TCo2_3" Grid.Row="3" Grid.Column="1" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm25_3" Grid.Row="3" Grid.Column="2" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm10_3" Grid.Row="3" Grid.Column="3" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TVoc_3" Grid.Row="3" Grid.Column="4" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="3단계(매우나쁨)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentRedBrush}"/>
<TextBox x:Name="TCo2_4" Grid.Row="4" Grid.Column="1" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm25_4" Grid.Row="4" Grid.Column="2" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TPm10_4" Grid.Row="4" Grid.Column="3" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="TVoc_4" Grid.Row="4" Grid.Column="4" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBlock Grid.Row="5" Grid.Column="0" Text="4단계(최악)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentRedBrush}"/>
<Border Grid.Row="5" Grid.Column="1" Margin="2,1" Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock x:Name="MCo2" TextAlignment="Center" FontSize="11" Padding="3,2" Foreground="{StaticResource TextPrimaryBrush}"/>
</Border>
<Border Grid.Row="5" Grid.Column="2" Margin="2,1" Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock x:Name="MPm25" TextAlignment="Center" FontSize="11" Padding="3,2" Foreground="{StaticResource TextPrimaryBrush}"/>
</Border>
<Border Grid.Row="5" Grid.Column="3" Margin="2,1" Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock x:Name="MPm10" TextAlignment="Center" FontSize="11" Padding="3,2" Foreground="{StaticResource TextPrimaryBrush}"/>
</Border>
<Border Grid.Row="5" Grid.Column="4" Margin="2,1" Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock x:Name="MVoc" TextAlignment="Center" FontSize="11" Padding="3,2" Foreground="{StaticResource TextPrimaryBrush}"/>
</Border>
<TextBlock Grid.Row="6" Grid.Column="0" Text="히스(하강)" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource AccentYellowBrush}"/>
<TextBox x:Name="DCo2" Grid.Row="6" Grid.Column="1" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource AccentYellowBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="DPm25" Grid.Row="6" Grid.Column="2" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource AccentYellowBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="DPm10" Grid.Row="6" Grid.Column="3" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource AccentYellowBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBox x:Name="DVoc" Grid.Row="6" Grid.Column="4" TextAlignment="Center" FontSize="11" Margin="2,1" Padding="3,2" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource AccentYellowBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
</Grid>
<StackPanel Orientation="Horizontal" Margin="0,14,0,0" HorizontalAlignment="Right">
<Button Content="적용" Width="100" Style="{StaticResource ModernButton}" Click="Apply_Click"
Margin="0,0,6,0" Background="{StaticResource AccentBlueBrush}"/>
<Button Content="닫기" Width="90" Style="{StaticResource ModernButton}" Click="Close_Click"
Background="{StaticResource CardBgBrush}"/>
</StackPanel>
</StackPanel>
</Border>
</Window>
@@ -0,0 +1,92 @@
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ERVSimulator.Model;
namespace ERVSimulator
{
// 공기질 센서 히스테리시스 팝업 : 활성 프리셋(ECO/NORMAL/TURBO)의 오염단계 임계 + 히스(하강) 표시·수정
public partial class HystWindow : Window
{
readonly ErvState _state;
public event Action<string>? Applied;
Brush Br(string key) => (Brush)FindResource(key);
public HystWindow(ErvState state)
{
InitializeComponent();
_state = state;
// MainWindow 프리셋 버튼 / 대시보드 CTRL 로 HystPreset 변경 시 팝업도 즉시 동기화
_state.PropertyChanged += OnStateChanged;
RefreshPreset();
}
void OnStateChanged(object? s, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ErvState.HystPreset))
Dispatcher.BeginInvoke(new Action(RefreshPreset));
}
protected override void OnClosed(EventArgs e)
{
_state.PropertyChanged -= OnStateChanged;
base.OnClosed(e);
}
void RefreshPreset()
{
foreach (var child in PresetPanel.Children)
{
if (child is Button btn && btn.Tag is string tag && byte.TryParse(tag, out var p))
{
bool active = p == _state.HystPreset;
btn.Background = active ? Br("AccentCyanBrush") : Br("CardBgBrush");
btn.Foreground = active ? Brushes.Black : Br("TextPrimaryBrush");
}
}
FillGrid(_state.HystPreset);
}
// 활성 프리셋 값으로 표 채우기
void FillGrid(int p)
{
TCo2_1.Text = _state.Co2Thr[p][0].ToString(); TCo2_2.Text = _state.Co2Thr[p][1].ToString(); TCo2_3.Text = _state.Co2Thr[p][2].ToString(); TCo2_4.Text = _state.Co2Thr[p][3].ToString();
TPm25_1.Text = _state.Pm25Thr[p][0].ToString(); TPm25_2.Text = _state.Pm25Thr[p][1].ToString(); TPm25_3.Text = _state.Pm25Thr[p][2].ToString(); TPm25_4.Text = _state.Pm25Thr[p][3].ToString();
TPm10_1.Text = _state.Pm10Thr[p][0].ToString(); TPm10_2.Text = _state.Pm10Thr[p][1].ToString(); TPm10_3.Text = _state.Pm10Thr[p][2].ToString(); TPm10_4.Text = _state.Pm10Thr[p][3].ToString();
TVoc_1.Text = _state.VocThr[p][0].ToString(); TVoc_2.Text = _state.VocThr[p][1].ToString(); TVoc_3.Text = _state.VocThr[p][2].ToString(); TVoc_4.Text = _state.VocThr[p][3].ToString();
DCo2.Text = _state.Co2Db[p].ToString(); DPm25.Text = _state.Pm25Db[p].ToString(); DPm10.Text = _state.Pm10Db[p].ToString(); DVoc.Text = _state.VocDb[p].ToString();
// 4단계(최악) : 3단계 상한 초과 = (상한+1)~ (사양서 10p)
MCo2.Text = $"{_state.Co2Thr[p][3] + 1}~"; MPm25.Text = $"{_state.Pm25Thr[p][3] + 1}~";
MPm10.Text = $"{_state.Pm10Thr[p][3] + 1}~"; MVoc.Text = $"{_state.VocThr[p][3] + 1}~";
}
static ushort P(TextBox tb) { ushort.TryParse(tb.Text, out var v); return v; }
void Preset_Click(object sender, RoutedEventArgs e)
{
if (sender is Button b && b.Tag is string tag && byte.TryParse(tag, out var p) && p < 3)
{
_state.HystPreset = p;
RefreshPreset();
Applied?.Invoke($"[Manual] 히스테리시스 프리셋 → {(p == 0 ? "ECO" : p == 1 ? "NORMAL" : "TURBO")}");
}
}
void Apply_Click(object sender, RoutedEventArgs e)
{
int p = _state.HystPreset;
_state.Co2Thr[p][0] = P(TCo2_1); _state.Co2Thr[p][1] = P(TCo2_2); _state.Co2Thr[p][2] = P(TCo2_3); _state.Co2Thr[p][3] = P(TCo2_4);
_state.Pm25Thr[p][0] = P(TPm25_1); _state.Pm25Thr[p][1] = P(TPm25_2); _state.Pm25Thr[p][2] = P(TPm25_3); _state.Pm25Thr[p][3] = P(TPm25_4);
_state.Pm10Thr[p][0] = P(TPm10_1); _state.Pm10Thr[p][1] = P(TPm10_2); _state.Pm10Thr[p][2] = P(TPm10_3); _state.Pm10Thr[p][3] = P(TPm10_4);
_state.VocThr[p][0] = P(TVoc_1); _state.VocThr[p][1] = P(TVoc_2); _state.VocThr[p][2] = P(TVoc_3); _state.VocThr[p][3] = P(TVoc_4);
_state.Co2Db[p] = P(DCo2); _state.Pm25Db[p] = P(DPm25); _state.Pm10Db[p] = P(DPm10); _state.VocDb[p] = P(DVoc);
Applied?.Invoke($"[Manual] 공기질 센서 히스테리시스 적용 (프리셋 {(p == 0 ? "ECO" : p == 1 ? "NORMAL" : "TURBO")})");
}
void Close_Click(object sender, RoutedEventArgs e) => Close();
}
}
@@ -0,0 +1,389 @@
<Window x:Class="ERVSimulator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ERVSimulator"
Title="ERV 시뮬레이터 - ERV Simulator"
Width="1500" Height="880"
MinWidth="1400" MinHeight="800"
Background="{StaticResource PrimaryBgBrush}"
WindowStartupLocation="CenterScreen">
<Window.Resources>
<local:BoolToOpenCloseConverter x:Key="BoolOC"/>
<local:BoolToBrushConverter x:Key="BoolBrush"/>
<local:ColorTagToBrushConverter x:Key="TagBrush"/>
</Window.Resources>
<Grid Margin="14">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <!-- 0: Title/Connection -->
<RowDefinition Height="Auto"/> <!-- 1: Power + RunMode + Errors -->
<RowDefinition Height="Auto"/> <!-- 2: BodyDampers -->
<RowDefinition Height="Auto"/> <!-- 3: 자동운전 상태 -->
<RowDefinition Height="*"/> <!-- 4: Log -->
</Grid.RowDefinitions>
<!-- Row 0: 타이틀 + 통신 설정 -->
<Border Grid.Row="0" Style="{StaticResource SectionCard}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="ERV 시뮬레이터" FontSize="20" FontWeight="Bold"
Foreground="{StaticResource AccentCyanBrush}" Margin="0,0,14,0"/>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="0,0,24,0">
<TextBlock Text="만든이 : 전경선" Foreground="{StaticResource TextSecondaryBrush}" FontSize="10"/>
<TextBlock Text="수정일 : 2026.05.22" Foreground="{StaticResource TextSecondaryBrush}" FontSize="10"/>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Vertical">
<!-- 통신 포트 카드 1x4 (각 포트 = 2줄: 상단 라벨·포트·통신속도 / 하단 연결·해제·상태) -->
<UniformGrid Columns="4">
<!-- RoomCon -->
<Border Style="{StaticResource InnerCard}" Margin="0,0,6,0" Padding="8,6">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<TextBlock Text="RoomCon" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"
Width="62" FontSize="11" FontWeight="SemiBold"/>
<ComboBox x:Name="RoomConPortCombo" Width="92" Style="{StaticResource ModernComboBox}" Margin="0,0,6,0"/>
<TextBlock Text="9600 8N1" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="RoomConConnectBtn" Content="연결" Style="{StaticResource ModernButton}" Click="RoomConConnect_Click" Padding="12,5" Margin="0,0,4,0"/>
<Button x:Name="RoomConDisconnectBtn" Content="해제" Style="{StaticResource ModernButton}" Click="RoomConDisconnect_Click" Padding="12,5"
Background="{StaticResource AccentRedBrush}"/>
<Ellipse x:Name="RoomConStatus" Width="10" Height="10" Margin="10,0,4,0" Fill="#F7768E" VerticalAlignment="Center"/>
<TextBlock x:Name="RoomConStatusText" Text="미연결" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
</StackPanel>
</Border>
<!-- HomeNet -->
<Border Style="{StaticResource InnerCard}" Margin="0,0,6,0" Padding="8,6">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<TextBlock Text="HomeNet" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"
Width="62" FontSize="11" FontWeight="SemiBold"/>
<ComboBox x:Name="HomeNetPortCombo" Width="92" Style="{StaticResource ModernComboBox}" Margin="0,0,6,0"/>
<ComboBox x:Name="HomeNetBaudCombo" Width="76" Style="{StaticResource ModernComboBox}" SelectedIndex="5">
<ComboBoxItem Content="4800"/>
<ComboBoxItem Content="9600"/>
<ComboBoxItem Content="19200"/>
<ComboBoxItem Content="38400"/>
<ComboBoxItem Content="57600"/>
<ComboBoxItem Content="115200"/>
</ComboBox>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="HomeNetConnectBtn" Content="연결" Style="{StaticResource ModernButton}" Click="HomeNetConnect_Click" Padding="12,5" Margin="0,0,4,0"/>
<Button x:Name="HomeNetDisconnectBtn" Content="해제" Style="{StaticResource ModernButton}" Click="HomeNetDisconnect_Click" Padding="12,5"
Background="{StaticResource AccentRedBrush}"/>
<Ellipse x:Name="HomeNetStatus" Width="10" Height="10" Margin="10,0,4,0" Fill="#F7768E" VerticalAlignment="Center"/>
<TextBlock x:Name="HomeNetStatusText" Text="미연결" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
</StackPanel>
</Border>
<!-- Diffuser (DiffuserSimulator 센서 수신) -->
<Border Style="{StaticResource InnerCard}" Margin="0,0,6,0" Padding="8,6">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<TextBlock Text="Diffuser" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"
Width="62" FontSize="11" FontWeight="SemiBold"/>
<ComboBox x:Name="DiffuserPortCombo" Width="92" Style="{StaticResource ModernComboBox}" Margin="0,0,6,0"/>
<TextBlock Text="115200 8N1" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="DiffuserConnectBtn" Content="연결" Style="{StaticResource ModernButton}" Click="DiffuserConnect_Click" Padding="12,5" Margin="0,0,4,0"/>
<Button x:Name="DiffuserDisconnectBtn" Content="해제" Style="{StaticResource ModernButton}" Click="DiffuserDisconnect_Click" Padding="12,5"
Background="{StaticResource AccentRedBrush}"/>
<Ellipse x:Name="DiffuserStatus" Width="10" Height="10" Margin="10,0,4,0" Fill="#F7768E" VerticalAlignment="Center"/>
<TextBlock x:Name="DiffuserStatusText" Text="미연결" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
</StackPanel>
</Border>
<!-- Hood (후드메인 연동 - HOOD 프로토콜 Rev1.3) -->
<Border Style="{StaticResource InnerCard}" Padding="8,6">
<StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<TextBlock Text="Hood" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"
Width="62" FontSize="11" FontWeight="SemiBold"/>
<ComboBox x:Name="HoodPortCombo" Width="92" Style="{StaticResource ModernComboBox}" Margin="0,0,6,0"/>
<TextBlock Text="115200 8N1" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="HoodConnectBtn" Content="연결" Style="{StaticResource ModernButton}" Click="HoodConnect_Click" Padding="12,5" Margin="0,0,4,0"/>
<Button x:Name="HoodDisconnectBtn" Content="해제" Style="{StaticResource ModernButton}" Click="HoodDisconnect_Click" Padding="12,5"
Background="{StaticResource AccentRedBrush}"/>
<Ellipse x:Name="HoodStatus" Width="10" Height="10" Margin="10,0,4,0" Fill="#F7768E" VerticalAlignment="Center"/>
<TextBlock x:Name="HoodStatusText" Text="미연결" Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center" FontSize="11"/>
</StackPanel>
</StackPanel>
</Border>
</UniformGrid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,6,0,0">
<Button Content="⟳ 포트 새로고침" Style="{StaticResource ModernButton}" Click="RefreshPorts_Click"
Background="{StaticResource CardBgBrush}" Padding="10,4" FontSize="11"/>
</StackPanel>
</StackPanel>
</Grid>
</Border>
<!-- Row 1: 전원 + 운전 모드 + 에러 코드 -->
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Style="{StaticResource SectionCard}" Margin="0,0,8,8">
<StackPanel>
<TextBlock Text="전원" Style="{StaticResource SectionTitle}"/>
<StackPanel Orientation="Horizontal">
<Border x:Name="PowerOnCard" Width="80" Padding="10,6" CornerRadius="6"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" Margin="0,0,6,0">
<TextBlock Text="ON" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16"
Foreground="{StaticResource TextSecondaryBrush}"/>
</Border>
<Border x:Name="PowerOffCard" Width="80" Padding="10,6" CornerRadius="6"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock Text="OFF" HorizontalAlignment="Center" FontWeight="Bold" FontSize="16"
Foreground="{StaticResource TextSecondaryBrush}"/>
</Border>
</StackPanel>
</StackPanel>
</Border>
<Border Grid.Column="1" Style="{StaticResource SectionCard}" Margin="0,0,8,8">
<StackPanel>
<TextBlock Text="운전 모드" Style="{StaticResource SectionTitle}"/>
<!-- 운전모드 + 풍량 + (꺼짐)예약 한 줄 -->
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Horizontal" x:Name="ModePanel" VerticalAlignment="Center">
<Button Content="환기" Tag="Ventilation" Click="ModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="70"
Background="{StaticResource CardBgBrush}"/>
<Button Content="자동" Tag="Auto" Click="ModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="70"
Background="{StaticResource CardBgBrush}"/>
<Button Content="공청" Tag="AirClean" Click="ModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="70"
Background="{StaticResource CardBgBrush}"/>
<Button Content="바이패스" Tag="Bypass" Click="ModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,0,0" MinWidth="70"
Background="{StaticResource CardBgBrush}"/>
</StackPanel>
<TextBlock Text="풍량" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center" FontSize="12" FontWeight="SemiBold" Margin="18,0,8,0"/>
<StackPanel Orientation="Horizontal" x:Name="FanPanel" VerticalAlignment="Center">
<Button Content="0" Tag="0" Click="FanButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,4,0" MinWidth="42" Background="{StaticResource CardBgBrush}"/>
<Button Content="1" Tag="1" Click="FanButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,4,0" MinWidth="42" Background="{StaticResource CardBgBrush}"/>
<Button Content="2" Tag="2" Click="FanButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,4,0" MinWidth="42" Background="{StaticResource CardBgBrush}"/>
<Button Content="3" Tag="3" Click="FanButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,4,0" MinWidth="42" Background="{StaticResource CardBgBrush}"/>
<Button Content="4" Tag="4" Click="FanButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,0,0" MinWidth="42" Background="{StaticResource CardBgBrush}"/>
</StackPanel>
<TextBlock Text="예약(꺼짐)" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center" FontSize="12" FontWeight="SemiBold" Margin="18,0,8,0"/>
<ComboBox x:Name="ReserveCombo" Width="90" Style="{StaticResource ModernComboBox}" VerticalAlignment="Center" SelectionChanged="ReserveCombo_Changed" SelectedIndex="0">
<ComboBoxItem Content="해제"/>
<ComboBoxItem Content="1시간"/>
<ComboBoxItem Content="2시간"/>
<ComboBoxItem Content="3시간"/>
<ComboBoxItem Content="4시간"/>
<ComboBoxItem Content="5시간"/>
<ComboBoxItem Content="6시간"/>
<ComboBoxItem Content="7시간"/>
<ComboBoxItem Content="8시간"/>
</ComboBox>
<TextBlock x:Name="ReserveText" Text="예약 없음" Foreground="{StaticResource AccentYellowBrush}" VerticalAlignment="Center" FontSize="12" Margin="10,0,0,0"/>
</StackPanel>
<!-- 자동모드 프리셋(절전/표준/쾌속) : 자동 선택 시에만 활성, 기본 표준(NORMAL).
선택 프리셋이 공기질 판정 임계(=히스테리시스 임계)를 결정. Tag=프리셋 인덱스 0/1/2 -->
<StackPanel Orientation="Horizontal" x:Name="PresetPanel" Margin="0,8,0,0" VerticalAlignment="Center">
<Button Content="절전 (ECO)" Tag="0" Click="PresetButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="96" Background="{StaticResource CardBgBrush}"/>
<Button Content="표준 (NORMAL)" Tag="1" Click="PresetButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="96" Background="{StaticResource CardBgBrush}"/>
<Button Content="쾌속 (TURBO)" Tag="2" Click="PresetButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,16,0" MinWidth="96" Background="{StaticResource CardBgBrush}"/>
<!-- 공기질 센서 히스테리시스 + 풍량 VSP + 후드연동 (쾌속 옆) -->
<Button Content="공기질 센서 히스테리시스 ▸" Click="OpenHyst_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="84" Background="{StaticResource CardBgBrush}"/>
<Button Content="풍량 VSP ▸" Click="OpenVsp_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" Padding="12,4" Background="{StaticResource CardBgBrush}"/>
<Button x:Name="HoodLinkBtn" Content="후드연동" IsHitTestVisible="False" Style="{StaticResource ModernButton}"
Padding="12,4" Background="{StaticResource CardBgBrush}" Foreground="{StaticResource TextPrimaryBrush}"/>
<Ellipse x:Name="HoodCommLed" Width="9" Height="9" Fill="#F7768E" VerticalAlignment="Center" Margin="8,0,5,0"/>
<TextBlock x:Name="HoodCommText" Text="후드 통신 안됨" FontSize="11" FontWeight="SemiBold"
Foreground="{StaticResource TextSecondaryBrush}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Border>
<!-- 에러 코드 (운전모드 옆, 클릭 토글) -->
<Border Grid.Column="2" Style="{StaticResource SectionCard}" Margin="0,0,0,8">
<StackPanel>
<DockPanel Margin="0,0,0,4">
<TextBlock Text="에러 코드" Style="{StaticResource SectionTitle}" Margin="0"/>
<TextBlock x:Name="ErrorCodeHex" DockPanel.Dock="Right" Style="{StaticResource FieldValue}"
VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{StaticResource TextSecondaryBrush}"/>
</DockPanel>
<StackPanel Orientation="Horizontal">
<Border x:Name="ErrCard_E02" Tag="E02" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3" Margin="0,0,4,0"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="온도센서 에러">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_E02" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="E02" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
<Border x:Name="ErrCard_E09" Tag="E09" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3" Margin="0,0,4,0"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="급기(SA) 팬 에러">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_E09" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="E09" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
<Border x:Name="ErrCard_E10" Tag="E10" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3" Margin="0,0,4,0"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="배기(EA) 팬 에러">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_E10" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="E10" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
<Border x:Name="ErrCard_COLD" Tag="COLD" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3" Margin="0,0,4,0"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="장비보호모드">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_COLD" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="COLD" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
<Border x:Name="ErrCard_E07" Tag="E07" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="내부 통신 에러">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_E07" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="E07" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
</StackPanel>
<!-- 알람(유지보수) : 필터 청소/교환 -->
<StackPanel Orientation="Horizontal" Margin="0,5,0,0">
<Border x:Name="ErrCard_FCLEAN" Tag="FCLEAN" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3" Margin="0,0,4,0"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="필터 청소 알람">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_FCLEAN" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="필터청소" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
<Border x:Name="ErrCard_FCHANGE" Tag="FCHANGE" MouseDown="ErrorCard_Click" Cursor="Hand" CornerRadius="4" Padding="6,3"
Background="{StaticResource CardBgBrush}" BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" ToolTip="필터 교환 알람">
<StackPanel Orientation="Horizontal">
<Ellipse x:Name="ErrLed_FCHANGE" Width="9" Height="9" Fill="#3B3B55" VerticalAlignment="Center" Margin="0,0,4,0"/>
<TextBlock Text="필터교환" FontSize="11" FontWeight="Bold" VerticalAlignment="Center" Foreground="{StaticResource TextPrimaryBrush}"/>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
</Border>
</Grid>
<!-- Row 2: 본체 댐퍼 (6개) -->
<Border Grid.Row="2" Style="{StaticResource SectionCard}">
<StackPanel>
<TextBlock Text="댐퍼 동작 (본체)" Style="{StaticResource SectionTitle}"/>
<ItemsControl x:Name="DamperItems">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="6"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Style="{StaticResource InnerCard}">
<StackPanel>
<DockPanel>
<Border DockPanel.Dock="Left" Width="14" Height="14" CornerRadius="7"
Background="{Binding ColorTag, Converter={StaticResource TagBrush}}"
BorderBrush="{StaticResource BorderBrush}" BorderThickness="1" Margin="0,0,6,0"/>
<TextBlock Text="{Binding Name}" FontWeight="Bold" Foreground="{StaticResource TextPrimaryBrush}"/>
</DockPanel>
<TextBlock Text="{Binding Connector}" Foreground="{StaticResource TextSecondaryBrush}" FontSize="11"/>
<TextBlock FontSize="11" Foreground="{StaticResource TextPrimaryBrush}" FontFamily="Consolas">
<Run Text="각도: "/>
<Run Text="{Binding TargetAngle, Mode=OneWay}"/>
<Run Text="°"/>
</TextBlock>
<TextBlock FontWeight="Bold" Margin="0,4,0,0" FontSize="13"
Text="{Binding IsOpen, Converter={StaticResource BoolOC}}"
Foreground="{Binding IsOpen, Converter={StaticResource BoolBrush}}"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
<!-- Row 3: DL 각실제어 (시나리오모드 + 자동운전 상태) -->
<Border Grid.Row="3" Style="{StaticResource SectionCard}">
<StackPanel>
<TextBlock Text="DL 각실제어" Style="{StaticResource SectionTitle}"/>
<!-- 시나리오모드 -->
<StackPanel Orientation="Horizontal" Margin="0,2,0,0" x:Name="SubModePanel">
<TextBlock Text="시나리오모드" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center" Width="84" FontSize="12" FontWeight="SemiBold"/>
<Button Content="스마트수면" Tag="Sleep" Click="SubModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="84" Background="{StaticResource CardBgBrush}"/>
<Button Content="쾌적조리" Tag="Cook" Click="SubModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,6,0" MinWidth="84" Background="{StaticResource CardBgBrush}"/>
<Button Content="안심회복" Tag="Recovery" Click="SubModeButton_Click" Style="{StaticResource ModernButton}" Margin="0,0,16,0" MinWidth="84" Background="{StaticResource CardBgBrush}"/>
</StackPanel>
<!-- 자동운전 상태 -->
<DockPanel Margin="0,10,0,4">
<TextBlock Text="자동운전 상태" FontSize="12" FontWeight="SemiBold" Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"/>
<Border DockPanel.Dock="Right" Background="{StaticResource CardBgBrush}" CornerRadius="6" Padding="10,3"
BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<TextBlock VerticalAlignment="Center" FontWeight="Bold" FontSize="13" Foreground="{StaticResource AccentCyanBrush}">
<Run Text="동작: "/>
<Run x:Name="AutoStateRun" Text="-"/>
<Run Text=" (분산 / 집중)" Foreground="{StaticResource TextSecondaryBrush}" FontWeight="Normal"/>
</TextBlock>
</Border>
</DockPanel>
<ItemsControl x:Name="RoomLoadItems">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate><UniformGrid Columns="4"/></ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Style="{StaticResource InnerCard}" Margin="3">
<StackPanel>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" FontSize="11" Foreground="{StaticResource TextSecondaryBrush}"/>
<TextBlock Text="{Binding Level, Mode=OneWay}" HorizontalAlignment="Center" FontSize="20" FontWeight="Bold" Foreground="{StaticResource AccentBlueBrush}"/>
<TextBlock Text="{Binding SensorText, Mode=OneWay}" HorizontalAlignment="Center" FontSize="9" Foreground="{StaticResource TextSecondaryBrush}" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</Border>
<!-- Row 4: 통신 로그 -->
<Border Grid.Row="4" Style="{StaticResource SectionCard}">
<DockPanel>
<Grid DockPanel.Dock="Top" Margin="0,0,0,6">
<TextBlock Text="통신 로그" Style="{StaticResource SectionTitle}" Margin="0"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="로그 저장" Style="{StaticResource ModernButton}"
Background="{StaticResource AccentBlueBrush}" Padding="10,3" FontSize="11" Margin="0,0,6,0"
Click="SaveLog_Click"/>
<Button Content="로그 지우기" Style="{StaticResource ModernButton}"
Background="{StaticResource CardBgBrush}" Padding="10,3" FontSize="11"
Click="ClearLog_Click"/>
</StackPanel>
</Grid>
<TextBox x:Name="LogList" IsReadOnly="True" Background="{StaticResource CardBgBrush}"
Foreground="{StaticResource TextPrimaryBrush}" BorderBrush="{StaticResource BorderBrush}"
BorderThickness="1" FontFamily="Consolas" FontSize="11"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"
TextWrapping="NoWrap" Padding="6"/>
</DockPanel>
</Border>
</Grid>
</Window>
@@ -0,0 +1,485 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
using ERVSimulator.Model;
using ERVSimulator.Protocol;
namespace ERVSimulator
{
public partial class MainWindow : Window
{
readonly ErvState _state = new();
readonly DamperSequencer _seq;
readonly SerialChannel _roomConCh = new("RoomCon");
readonly SerialChannel _homeNetCh = new("HomeNet");
readonly SerialChannel _diffuserCh = new("Diffuser");
readonly SerialChannel _hoodCh = new("Hood");
readonly HomeNetProtocol _homeNet;
readonly DiffuserMasterProtocol _diffuser;
readonly HoodMasterProtocol _hood;
readonly RoomConProtocol _roomCon;
readonly AutoLogic _autoLogic;
readonly DispatcherTimer _uiTick;
readonly DispatcherTimer _reserveTick;
// Tokyo Night palette refs
static readonly Brush ConnectedLed = (Brush)new BrushConverter().ConvertFromString("#9ECE6A")!;
static readonly Brush DisconnectedLed = (Brush)new BrushConverter().ConvertFromString("#F7768E")!;
static readonly Brush AccentCyan = (Brush)new BrushConverter().ConvertFromString("#7DCFFF")!;
static readonly Brush AccentGreen = (Brush)new BrushConverter().ConvertFromString("#9ECE6A")!;
static readonly Brush AccentRed = (Brush)new BrushConverter().ConvertFromString("#F7768E")!;
static readonly Brush AccentYellow = (Brush)new BrushConverter().ConvertFromString("#E0AF68")!;
static readonly Brush AccentOrange = (Brush)new BrushConverter().ConvertFromString("#FF9E64")!;
static readonly Brush AccentBlue = (Brush)new BrushConverter().ConvertFromString("#7AA2F7")!;
static readonly Brush CardBg = (Brush)new BrushConverter().ConvertFromString("#313147")!;
static readonly Brush TextSecondary = (Brush)new BrushConverter().ConvertFromString("#565F89")!;
static readonly Brush TextPrimary = (Brush)new BrushConverter().ConvertFromString("#C0CAF5")!;
static readonly Brush BorderColor = (Brush)new BrushConverter().ConvertFromString("#3B3B55")!;
static readonly Brush LedOff = (Brush)new BrushConverter().ConvertFromString("#3B3B55")!;
public MainWindow()
{
InitializeComponent();
_seq = new DamperSequencer(_state);
_homeNet = new HomeNetProtocol(_homeNetCh, _state, _seq, Dispatcher);
_diffuser = new DiffuserMasterProtocol(_diffuserCh, _state, Dispatcher);
_hood = new HoodMasterProtocol(_hoodCh, _state, Dispatcher);
_roomCon = new RoomConProtocol(_roomConCh, _state, _seq, Dispatcher);
_autoLogic = new AutoLogic(_state, _seq);
DamperItems.ItemsSource = _state.BodyDampers;
RoomLoadItems.ItemsSource = _state.Rooms; // 자동운전 상태 - 각실 부하점수
_roomConCh.Log += Log;
_homeNetCh.Log += Log;
_diffuserCh.Log += Log;
_hoodCh.Log += Log;
_roomConCh.ConnectionChanged += b => Dispatcher.BeginInvoke(() => UpdateChannelLed(RoomConStatus, RoomConStatusText, b));
_homeNetCh.ConnectionChanged += b => Dispatcher.BeginInvoke(() => UpdateChannelLed(HomeNetStatus, HomeNetStatusText, b));
_diffuserCh.ConnectionChanged += b => Dispatcher.BeginInvoke(() => UpdateChannelLed(DiffuserStatus, DiffuserStatusText, b));
_hoodCh.ConnectionChanged += b => Dispatcher.BeginInvoke(() => UpdateChannelLed(HoodStatus, HoodStatusText, b));
_homeNet.PacketReceived += Log;
_homeNet.PacketSent += Log;
_diffuser.PacketReceived += Log;
_diffuser.PacketSent += Log;
_hood.PacketReceived += Log;
_hood.PacketSent += Log;
_roomCon.PacketReceived += Log;
_roomCon.PacketSent += Log;
_autoLogic.Log += Log;
_state.PropertyChanged += (_, e) => Dispatcher.BeginInvoke(() =>
{
UpdateTopState();
if (e.PropertyName == nameof(ErvState.ErrorCode) ||
e.PropertyName == nameof(ErvState.E02_TempSensor) ||
e.PropertyName == nameof(ErvState.E09_SaFan) ||
e.PropertyName == nameof(ErvState.E10_EaFan) ||
e.PropertyName == nameof(ErvState.COLD_Protect) ||
e.PropertyName == nameof(ErvState.E07_InternalComm))
{
UpdateErrorIndicators();
}
});
_uiTick = new DispatcherTimer(DispatcherPriority.Normal) { Interval = TimeSpan.FromMilliseconds(100) };
_uiTick.Tick += (_, _) => UpdateRealtime();
_uiTick.Start();
// (꺼짐)예약 1초 카운트다운
_reserveTick = new DispatcherTimer(DispatcherPriority.Normal) { Interval = TimeSpan.FromSeconds(1) };
_reserveTick.Tick += (_, _) => ReserveTick();
_reserveTick.Start();
RefreshPortsList();
UpdateTopState();
UpdateRealtime();
UpdateErrorIndicators();
}
// ---- 시리얼 연결 ----
void RefreshPorts_Click(object sender, RoutedEventArgs e) => RefreshPortsList();
void RefreshPortsList()
{
var ports = SerialChannel.GetAvailablePorts();
RoomConPortCombo.ItemsSource = ports;
HomeNetPortCombo.ItemsSource = ports;
DiffuserPortCombo.ItemsSource = ports;
HoodPortCombo.ItemsSource = ports;
if (ports.Length > 0)
{
if (RoomConPortCombo.SelectedIndex < 0) RoomConPortCombo.SelectedIndex = 0;
if (HomeNetPortCombo.SelectedIndex < 0) HomeNetPortCombo.SelectedIndex = ports.Length > 1 ? 1 : 0;
if (DiffuserPortCombo.SelectedIndex < 0) DiffuserPortCombo.SelectedIndex = ports.Length > 2 ? 2 : 0;
if (HoodPortCombo.SelectedIndex < 0) HoodPortCombo.SelectedIndex = ports.Length > 3 ? 3 : 0;
}
}
void DiffuserConnect_Click(object sender, RoutedEventArgs e)
{
if (DiffuserPortCombo.SelectedItem is string p) _diffuserCh.Connect(p, 115200);
}
void DiffuserDisconnect_Click(object sender, RoutedEventArgs e) => _diffuserCh.Disconnect();
void HoodConnect_Click(object sender, RoutedEventArgs e)
{
if (HoodPortCombo.SelectedItem is string p) _hoodCh.Connect(p, 115200);
}
void HoodDisconnect_Click(object sender, RoutedEventArgs e) => _hoodCh.Disconnect();
void RoomConConnect_Click(object sender, RoutedEventArgs e)
{
if (RoomConPortCombo.SelectedItem is string p) _roomConCh.Connect(p, 9600);
}
void RoomConDisconnect_Click(object sender, RoutedEventArgs e) => _roomConCh.Disconnect();
void HomeNetConnect_Click(object sender, RoutedEventArgs e)
{
if (HomeNetPortCombo.SelectedItem is string p)
{
int baud = 9600;
if (HomeNetBaudCombo.SelectedItem is ComboBoxItem item &&
int.TryParse(item.Content?.ToString(), out var b)) baud = b;
_homeNetCh.Connect(p, baud);
}
}
void HomeNetDisconnect_Click(object sender, RoutedEventArgs e) => _homeNetCh.Disconnect();
void UpdateChannelLed(System.Windows.Shapes.Ellipse led, TextBlock text, bool connected)
{
led.Fill = connected ? ConnectedLed : DisconnectedLed;
text.Text = connected ? "연결됨" : "미연결";
text.Foreground = connected ? AccentGreen : TextSecondary;
}
// ---- 운전 모드 버튼 ----
void ModeButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Button b && b.Tag is string tag && Enum.TryParse<RunMode>(tag, out var m))
{
_state.RunMode = m;
_state.SetRunMode = m;
// 운전모드 전환 시 풍량 1단 (자동 제외 — 자동은 부하점수로 결정)
if (m != RunMode.Auto) _state.FanMode = _state.SetFanMode = 1;
_state.PowerOn = true;
_seq.NotifyCommandChanged();
Log($"[Manual] Mode → {m}");
}
}
// ---- 풍량 0~4 ----
void FanButton_Click(object sender, RoutedEventArgs e)
{
if (sender is Button b && b.Tag is string tag && byte.TryParse(tag, out var f))
{
_state.FanMode = _state.SetFanMode = f;
if (f > 0) _state.PowerOn = true;
_seq.NotifyCommandChanged();
Log($"[Manual] 풍량 → {f}단{(_state.RunMode == RunMode.Auto ? " ( )" : "")}");
}
}
// ---- 자동모드 프리셋 (절전/표준/쾌속) : 자동에서만, 공기질 판정 임계 = 선택 프리셋 ----
void PresetButton_Click(object sender, RoutedEventArgs e)
{
if (_state.RunMode != RunMode.Auto) { Log("프리셋은 자동모드에서만 선택할 수 있습니다."); return; }
if (sender is Button b && b.Tag is string tag && byte.TryParse(tag, out var p))
{
_state.HystPreset = p;
_seq.NotifyCommandChanged();
Log($"[Manual] 프리셋 → {(p == 0 ? "ECO" : p == 1 ? "NORMAL" : "TURBO")}");
}
}
// ---- 시나리오모드 (스마트수면/쾌적조리/안심회복) ----
void SubModeButton_Click(object sender, RoutedEventArgs e)
{
if (sender is not Button b || b.Tag is not string tag) return;
switch (tag)
{
case "Sleep": _state.ExtRunMode = _state.SmartSleep ? (byte)0 : (byte)4; break;
case "Recovery": _state.ExtRunMode = _state.RecoveryMode ? (byte)0 : (byte)1; break;
case "Cook": _state.HoodEnable = !_state.HoodEnable; break;
}
if (_state.ExtRunMode != 0 || _state.HoodEnable) _state.PowerOn = true;
_seq.NotifyCommandChanged();
Log($"[Manual] 시나리오모드 → {_state.SubModeText}");
UpdateTopState();
}
// ---- 풍량 VSP 설정 팝업 ----
VspWindow? _vspWin;
void OpenVsp_Click(object sender, RoutedEventArgs e)
{
if (_vspWin == null)
{
_vspWin = new VspWindow(_state) { Owner = this };
_vspWin.Applied += Log;
_vspWin.Closed += (_, _) => _vspWin = null;
_vspWin.Show();
}
else _vspWin.Activate();
}
// ---- 공기질 센서 히스테리시스 팝업 ----
HystWindow? _hystWin;
void OpenHyst_Click(object sender, RoutedEventArgs e)
{
if (_hystWin == null)
{
_hystWin = new HystWindow(_state) { Owner = this };
_hystWin.Applied += Log;
_hystWin.Closed += (_, _) => _hystWin = null;
_hystWin.Show();
}
else _hystWin.Activate();
}
// ---- (꺼짐)예약 0~8시간 ----
bool _suppressReserveCombo; // 상태→콤보 동기화 중 ReserveCombo_Changed 재진입 차단
void ReserveCombo_Changed(object sender, SelectionChangedEventArgs e)
{
if (_suppressReserveCombo) return;
if (ReserveCombo.SelectedIndex < 0) return;
int hours = ReserveCombo.SelectedIndex; // 0=해제, 1~8시간
_state.ReserveHours = hours;
_state.ReserveRemainSec = hours * 3600;
Log(hours == 0 ? "[Manual] 예약 해제" : $"[Manual] {hours}시간 후 꺼짐 예약");
}
// ---- 에러 카드 토글 ----
void ErrorCard_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (sender is not Border b || b.Tag is not string tag) return;
switch (tag)
{
case "E02": _state.E02_TempSensor = !_state.E02_TempSensor; break;
case "E09": _state.E09_SaFan = !_state.E09_SaFan; break;
case "E10": _state.E10_EaFan = !_state.E10_EaFan; break;
case "COLD": _state.COLD_Protect = !_state.COLD_Protect; break;
case "E07": _state.E07_InternalComm = !_state.E07_InternalComm; break;
case "FCLEAN": _state.FilterClean = !_state.FilterClean; break;
case "FCHANGE": _state.FilterChange = !_state.FilterChange; break;
}
Log($"[Manual] ErrorCode → 0x{_state.ErrorCode:X2}");
}
// ---- UI 갱신 ----
void UpdateTopState()
{
// 전원 카드 강조
SetPowerCard(PowerOnCard, _state.PowerOn, AccentGreen);
SetPowerCard(PowerOffCard, !_state.PowerOn, AccentRed);
// 운전 모드 버튼 강조
foreach (var child in ModePanel.Children)
{
if (child is Button btn && btn.Tag is string tag)
{
bool active = tag == _state.RunMode.ToString();
btn.Background = active ? AccentCyan : CardBg;
btn.Foreground = active ? Brushes.Black : TextPrimary;
}
}
// 풍량 버튼 강조
foreach (var child in FanPanel.Children)
{
if (child is Button btn && btn.Tag is string tag)
{
bool active = tag == _state.FanMode.ToString();
btn.Background = active ? AccentBlue : CardBg;
btn.Foreground = active ? Brushes.Black : TextPrimary;
}
}
// 자동모드 프리셋 버튼 : 자동에서만 활성, 활성 프리셋 강조 (기본 표준=NORMAL)
bool presetEnabled = _state.RunMode == RunMode.Auto;
foreach (var child in PresetPanel.Children)
{
if (child is Button btn && btn.Tag is string tag)
{
bool active = presetEnabled && tag == _state.HystPreset.ToString();
btn.IsEnabled = presetEnabled;
btn.Background = active ? AccentBlue : CardBg;
btn.Foreground = active ? Brushes.Black : TextPrimary;
}
}
// 시나리오모드 버튼 강조
foreach (var child in SubModePanel.Children)
{
if (child is Button btn && btn.Tag is string tag)
{
bool active = tag switch { "Sleep" => _state.SmartSleep, "Cook" => _state.CookingMode, "Recovery" => _state.RecoveryMode, _ => false };
btn.Background = active ? AccentOrange : CardBg;
btn.Foreground = active ? Brushes.Black : TextPrimary;
}
}
}
static void SetPowerCard(Border card, bool active, Brush accent)
{
if (card.Child is TextBlock tb)
{
tb.Foreground = active ? Brushes.White : TextSecondary;
}
card.Background = active ? accent : CardBg;
card.BorderBrush = active ? accent : BorderColor;
}
void UpdateErrorIndicators()
{
UpdateErrLed(ErrCard_E02, ErrLed_E02, _state.E02_TempSensor, AccentRed);
UpdateErrLed(ErrCard_E09, ErrLed_E09, _state.E09_SaFan, AccentRed);
UpdateErrLed(ErrCard_E10, ErrLed_E10, _state.E10_EaFan, AccentRed);
UpdateErrLed(ErrCard_COLD, ErrLed_COLD, _state.COLD_Protect, AccentBlue);
UpdateErrLed(ErrCard_E07, ErrLed_E07, _state.E07_InternalComm, AccentOrange);
UpdateErrLed(ErrCard_FCLEAN, ErrLed_FCLEAN, _state.FilterClean, AccentYellow);
UpdateErrLed(ErrCard_FCHANGE, ErrLed_FCHANGE, _state.FilterChange, AccentYellow);
ErrorCodeHex.Text = $"ErrorCode = 0x{_state.ErrorCode:X2}";
}
static void UpdateErrLed(Border card, System.Windows.Shapes.Ellipse led, bool on, Brush onColor)
{
led.Fill = on ? onColor : LedOff;
card.BorderBrush = on ? onColor : BorderColor;
card.BorderThickness = new Thickness(on ? 2 : 1);
}
void UpdateRealtime()
{
ReserveText.Text = _state.ReserveText;
// 대시보드 등에서 CTRL_RESERVE 로 설정된 예약을 콤보에 반영(수신 명령도 ERVSim 에서 확인 가능)
if (ReserveCombo.SelectedIndex != _state.ReserveHours && _state.ReserveHours >= 0 && _state.ReserveHours <= 8)
{
_suppressReserveCombo = true;
ReserveCombo.SelectedIndex = _state.ReserveHours;
_suppressReserveCombo = false;
}
AutoStateRun.Text = _state.AutoStateText;
// 후드연동 버튼 — 쾌적조리(HoodEnable) ON 시 강조. 단, 통신중 후드 에러는 빨강+에러명 우선.
bool hoodOnline = (DateTime.UtcNow - _hood.LastRxUtc) < TimeSpan.FromSeconds(2);
if (hoodOnline && _state.HoodError != 0)
{
HoodLinkBtn.Background = AccentRed;
HoodLinkBtn.Foreground = Brushes.Black;
HoodLinkBtn.Content = _state.HoodError == 1 ? "후드연동 FAN에러" : "후드연동 기타에러";
}
else
{
HoodLinkBtn.Background = _state.HoodEnable ? AccentOrange : CardBg;
HoodLinkBtn.Foreground = _state.HoodEnable ? Brushes.Black : TextPrimary;
HoodLinkBtn.Content = "후드연동";
}
// 후드 통신 상태 (HoodSimulator 폴 응답 생존) — 후드연동 버튼 옆 표시
HoodCommLed.Fill = hoodOnline ? AccentGreen : AccentRed;
HoodCommText.Text = hoodOnline ? "후드 통신 중" : "후드 통신 안됨";
HoodCommText.Foreground = hoodOnline ? AccentGreen : TextSecondary;
}
// (꺼짐)예약 1초 카운트다운 — 0 도달 시 전원 OFF
void ReserveTick()
{
if (_state.ReserveRemainSec <= 0) return;
_state.ReserveRemainSec--;
if (_state.ReserveRemainSec == 0)
{
_state.ReserveHours = 0;
_state.PowerOn = false;
_state.FanMode = _state.SetFanMode = 0;
_seq.NotifyCommandChanged();
if (ReserveCombo.SelectedIndex != 0) ReserveCombo.SelectedIndex = 0;
Log("[예약] 예약시간 종료 → 전원 OFF");
}
}
// ---- 로그 (DiffuserSimulator 와 동일 : 읽기전용 TextBox, 텍스트 드래그 선택/복사 가능) ----
void Log(string msg)
{
var line = $"[{DateTime.Now:HH:mm:ss.fff}] {msg}";
Dispatcher.BeginInvoke(() =>
{
LogList.AppendText(line + Environment.NewLine);
if (LogList.LineCount > 500)
{
var lines = LogList.Text.Split(Environment.NewLine);
LogList.Text = string.Join(Environment.NewLine, lines[^300..]);
}
LogList.ScrollToEnd();
});
}
void ClearLog_Click(object sender, RoutedEventArgs e) => LogList.Clear();
void SaveLog_Click(object sender, RoutedEventArgs e)
{
var dlg = new Microsoft.Win32.SaveFileDialog
{
Filter = "텍스트 파일 (*.txt)|*.txt",
FileName = $"ErvSimLog_{DateTime.Now:yyyyMMdd_HHmmss}.txt"
};
if (dlg.ShowDialog() == true)
{
try
{
string h = $"========================================\r\n ERV 시뮬레이터 통신 로그\r\n 저장 일시: {DateTime.Now:yyyy-MM-dd HH:mm:ss}\r\n========================================\r\n\r\n";
System.IO.File.WriteAllText(dlg.FileName, h + LogList.Text);
MessageBox.Show($"저장 완료: {dlg.FileName}");
}
catch (Exception ex) { MessageBox.Show($"저장 실패: {ex.Message}"); }
}
}
protected override void OnClosed(EventArgs e)
{
_roomConCh.Dispose();
_homeNetCh.Dispose();
_diffuserCh.Dispose();
_hoodCh.Dispose();
base.OnClosed(e);
}
}
// ---- Converters ----
public class BoolToOpenCloseConverter : IValueConverter
{
public object Convert(object value, Type t, object p, CultureInfo c) =>
(value is bool b && b) ? "열림" : "닫힘";
public object ConvertBack(object v, Type t, object p, CultureInfo c) => DependencyProperty.UnsetValue;
}
public class BoolToBrushConverter : IValueConverter
{
static readonly Brush Open = (Brush)new BrushConverter().ConvertFromString("#9ECE6A")!;
static readonly Brush Close = (Brush)new BrushConverter().ConvertFromString("#F7768E")!;
public object Convert(object value, Type t, object p, CultureInfo c) =>
(value is bool b && b) ? Open : Close;
public object ConvertBack(object v, Type t, object p, CultureInfo c) => DependencyProperty.UnsetValue;
}
public class ColorTagToBrushConverter : IValueConverter
{
public object Convert(object value, Type t, object p, CultureInfo c) =>
value switch
{
"GREEN" => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9ECE6A")!),
"YELLOW" => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E0AF68")!),
"RED" => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F7768E")!),
"BLACK" => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1E1E2E")!),
"BLUE" => new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7AA2F7")!),
"WHITE" => new SolidColorBrush(Colors.WhiteSmoke),
_ => new SolidColorBrush(Colors.Gray),
};
public object ConvertBack(object v, Type t, object p, CultureInfo c) => DependencyProperty.UnsetValue;
}
}
@@ -0,0 +1,289 @@
using System;
using System.Windows.Threading;
namespace ERVSimulator.Model
{
// 펌웨어 [My_system.c] Air_Quality_damper_process() 포팅 (260520 사양)
// - 실별 4종센서 → 0~4 Level (모드별 임계 + 하강 히스테리시스)
// - 부하총점(Score) → 풍량단수, P_max/dP → 댐퍼(대기/집중/분산)
// - 1초 주기. RunMode==Auto && PowerOn 일 때만 댐퍼/풍량 구동.
public class AutoLogic
{
readonly ErvState _state;
readonly DamperSequencer _seq;
readonly DispatcherTimer _timer;
public event Action<string>? Log;
// 센서별 이전 단계(히스테리시스 데드존 유지) [room 1..4]
readonly int[] _prevCo2 = new int[5];
readonly int[] _prevPm25 = new int[5];
readonly int[] _prevPm10 = new int[5];
readonly int[] _prevVoc = new int[5];
// ---- 쾌적조리(후드연동) 메이크업 에어 상태 (사양서 260613 9p) ----
// 쾌적조리는 운전모드가 아닌 후드연동 토글. 토글 ON + 후드 가동중일 때만 메이크업 에어 발동.
// 조리 종료 후 잔여 배출(메이크업 유지)은 후드측이 담당 → ERV는 후드 OFF 신호 받으면 즉시 원래 상태 복귀.
bool _makeup; // 메이크업 에어(강제 연동) 동작중
byte _makeupFan; // 후드 단수 추종 결과 풍량
// 시나리오모드(안심회복/스마트수면/쾌적조리) 해제 시 진입 직전 풍량 복귀용 (운전모드는 시뮬에서 유지됨)
bool _prevScenario;
byte _scenarioSavedFan;
// 스마트수면 : 실별 CO2 히스테리시스 댐퍼 개폐 상태 (사양서 8p, >=1000 OPEN / <=800 CLOSE)
bool _prevSmartSleep;
readonly bool[] _sleepOpen = new bool[5]; // [room 1..4] true=OPEN
public AutoLogic(ErvState state, DamperSequencer seq)
{
_state = state; _seq = seq;
_timer = new DispatcherTimer(DispatcherPriority.Normal) { Interval = TimeSpan.FromSeconds(1) };
_timer.Tick += (_, _) => Process();
_timer.Start();
}
// 센서값 -> 0~4 단계. 하강 시 (임계-데드밴드) 이하라야 내려감. 데드존이면 이전 유지.
static int SensorLevel(int v, ushort[] t, ushort db, int prev)
{
int lv = prev;
if (v <= t[0] - db) lv = 0;
else if (v > t[0] && v <= t[1] - db) lv = 1;
else if (v > t[1] && v <= t[2] - db) lv = 2;
else if (v > t[2] && v <= t[3] - db) lv = 3;
else if (v > t[3]) lv = 4;
return lv;
}
static int ScoreToStage(int s)
{
if (s == 0) return 0;
if (s <= 4) return 1;
if (s <= 8) return 2;
if (s <= 12) return 3;
return 4;
}
// Level(0좋음~4매우나쁨) -> 공기질코드(1매우나쁨~4좋음)
static int AirqCode(int level) => level switch { 0 => 4, 1 => 3, 2 => 2, _ => 1 };
// 쾌적조리(후드연동) 메이크업 에어 상태 갱신. 반환=이번 틱 메이크업 에어 적용 여부.
// 매트릭스(9p 3.1) : 쾌적조리 OFF → 연동없음 / ON+후드꺼짐 → 대기(본래 설정) / ON+후드켜짐 → 메이크업 에어(강제 연동)
// 잔여 배출(메이크업 유지)은 후드측이 담당 → 후드 OFF 신호 받으면 ERV는 즉시 원래 상태 복귀(3.3).
bool UpdateCooking()
{
bool cookEnabled = _state.PowerOn && _state.HoodEnable; // 쾌적조리 토글(전원 ON 전제)
bool hoodOn = cookEnabled && _state.HoodCmd && _state.HoodFan > 0; // 후드 가동중(전원+풍량)
if (hoodOn)
{
if (!_makeup)
{
_makeup = true;
Log?.Invoke("[쾌적조리] 메이크업 에어 진입 — 자동/수동 일시정지");
}
_makeupFan = (byte)Math.Min((int)_state.HoodFan, 4); // 단수 추종(3.2) : 1→1,2→2,3→3,4→4,5→4
return true;
}
// 후드 정지 또는 쾌적조리 해제 → 즉시 원래 상태 복귀(메이크업 유지는 후드측이 담당)
if (_makeup) EndMakeup(cookEnabled ? "후드 OFF — 원래 상태 복귀" : "쾌적조리 해제");
return false;
}
void EndMakeup(string why)
{
_makeup = false;
// 진입 직전 풍량 복귀는 Process()의 시나리오 해제 처리에서 일괄 수행.
Log?.Invoke($"[쾌적조리] 메이크업 종료 ({why})");
}
void Process()
{
int p = _state.HystPreset;
// ---- 실별 Level 산출 (항상 - 표시용) ----
for (int r = 1; r <= 4; r++)
{
var room = _state.GetRoom(r);
int lc = SensorLevel(room.Co2, _state.Co2Thr[p], _state.Co2Db[p], _prevCo2[r]);
int l25 = SensorLevel(room.Pm25, _state.Pm25Thr[p], _state.Pm25Db[p], _prevPm25[r]);
int l10 = SensorLevel(room.Pm10, _state.Pm10Thr[p], _state.Pm10Db[p], _prevPm10[r]);
int lv = SensorLevel(room.Voc, _state.VocThr[p], _state.VocDb[p], _prevVoc[r]);
_prevCo2[r] = lc; _prevPm25[r] = l25; _prevPm10[r] = l10; _prevVoc[r] = lv;
int level = Math.Max(Math.Max(lc, l25), Math.Max(l10, lv));
room.Level = level;
room.AirQuality = AirqCode(level);
}
// ---- 부하총점 / P_max / dP (260428 v.Final : dP = 정렬 내림차순[0]-[1], 동점 포함) ----
// 최고단계 실이 2개 이상 동점이면 P_2nd=P_max → dP=0 → 분산. 한 실만 확실히(2↑) 나쁠 때만 집중.
int score = 0;
int[] levels = new int[4];
for (int r = 1; r <= 4; r++) { levels[r - 1] = _state.GetRoom(r).Level; score += levels[r - 1]; }
Array.Sort(levels); // 오름차순
int pmax = levels[3]; // 최고 단계
int p2nd = levels[2]; // 두번째로 높은 단계(동점 포함)
int dP = pmax - p2nd;
_state.LoadScore = score;
_state.PMax = pmax;
_state.DP = dP;
// ---- 쾌적조리(후드연동) 메이크업 에어 상태 갱신 → 연동운전중(HoodStatus) 소유 ----
bool makeupEffective = UpdateCooking();
_state.HoodStatus = makeupEffective; // 후드 폴 응답 '연동운전중'(롤백 유지 포함)
// ---- 시나리오모드 해제 → 진입 직전 운전모드로 동작 복귀 ----
// 시뮬은 시나리오 중에도 RunMode 를 유지(오버레이)하므로 운전모드는 자동 복귀.
// 시나리오가 덮어쓴 풍량만 진입 직전 값으로 되돌린다(비자동 한정, 자동은 재계산).
bool scenarioActive = _state.RecoveryMode || _state.SmartSleep || makeupEffective;
if (scenarioActive && !_prevScenario)
_scenarioSavedFan = _state.SetFanMode; // 진입 직전 풍량 저장
else if (!scenarioActive && _prevScenario && _state.PowerOn && _state.RunMode != RunMode.Auto)
_state.FanMode = _state.SetFanMode = _scenarioSavedFan; // 해제 → 이전 풍량 복귀
_prevScenario = scenarioActive;
// ---- 댐퍼/풍량 구동 (펌웨어 Air_Quality_damper_process 와 동일) ----
// 대시보드 수동 댐퍼/LED 제어는 환기·공청·바이패스(비자동·시나리오모드 아님)에서만 유지.
// 그 외(자동·시나리오모드·전원OFF)에서는 수동 플래그 해제 → 자동 제어 복귀.
// 쾌적조리 '대기 상태'(토글 ON·후드 꺼짐)는 본래 설정대로 가동 → subActive 아님.
bool subActive = _state.RecoveryMode || _state.SmartSleep || makeupEffective;
bool manualAllowed = _state.PowerOn && _state.RunMode != RunMode.Auto && !subActive;
// 댐퍼 수동 : 환기/공청/바이패스(비자동·비시나리오)에서만 유지, 그 외 해제 → 자동 제어 복귀.
// LED 수동 : 모든 운전모드·댐퍼 변경에도 유지(사용자 요청). 전원 OFF 시에만 해제 → 자동 추종(소등) 복귀.
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
if (!manualAllowed) rm.DamperManual = false;
if (!_state.PowerOn) rm.LedManual = false;
}
bool damperChanged = false;
void SetDamper(DiffuserRoom rm, int sa, int ra)
{
if (rm.MemorySA != sa || rm.MemoryRA != ra) damperChanged = true;
rm.MemorySA = sa; rm.MemoryRA = ra;
}
bool fanChanged = false;
string logTag;
void SetFan(byte st) { if (_state.FanMode != st) { _state.FanMode = _state.SetFanMode = st; fanChanged = true; } }
if (!_state.PowerOn)
{
// 전원 OFF : 전 실 즉시 닫힘 (18초 슬롯 시퀀스 대기 없이 Current 직접 0)
_state.AutoConcentrate = false;
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
SetDamper(rm, 0, 0);
rm.CurrentSA = 0; rm.CurrentRA = 0;
}
logTag = "전원OFF 전실 닫힘";
}
else if (makeupEffective) // 쾌적조리 메이크업 에어 : 전실 급기(SA) 100% 개방, 배기(RA) 닫힘, 후드 단수 추종
{
_state.AutoConcentrate = false;
for (int r = 1; r <= 4; r++) SetDamper(_state.GetRoom(r), 110, 0);
SetFan(_makeupFan);
logTag = $"쾌적조리 메이크업에어(전실 급기) {_makeupFan}단";
}
else if (_state.RecoveryMode) // 안심회복 : 침실1 음압 (급기X 배기O), 나머지 급기O 배기X, 2단
{
_state.AutoConcentrate = false;
SetDamper(_state.GetRoom(1), 110, 0); // 거실 급기
SetDamper(_state.GetRoom(2), 0, 110); // 침실1 배기(음압)
SetDamper(_state.GetRoom(3), 110, 0); // 침실2 급기
SetDamper(_state.GetRoom(4), 110, 0); // 침실3 급기
SetFan(2);
logTag = "안심회복(침실1 음압) 2단";
}
else if (_state.SmartSleep) // 스마트수면 : 1단 고정, 실별 CO2 기준 댐퍼 개폐 (사양서 8p)
{
_state.AutoConcentrate = false;
// 진입 초기상태 : 거실 CLOSE, 침실1~3 OPEN (이후 CO2 히스테리시스의 데드존 시드)
if (!_prevSmartSleep)
{
_sleepOpen[1] = false;
_sleepOpen[2] = _sleepOpen[3] = _sleepOpen[4] = true;
}
// CO2 센서 기준 : 해당 실 CO2 >= 1000 OPEN, <= 800 CLOSE, 그 사이(데드존)는 현재 상태 유지
for (int r = 1; r <= 4; r++)
{
int co2 = _state.GetRoom(r).Co2;
if (co2 >= 1000) _sleepOpen[r] = true;
else if (co2 <= 800) _sleepOpen[r] = false;
int ang = _sleepOpen[r] ? 110 : 0;
SetDamper(_state.GetRoom(r), ang, ang);
}
SetFan(1);
logTag = "스마트수면 CO2기준 실별개폐 1단";
}
else if (_state.RunMode != RunMode.Auto)
{
// 환기/공청/바이패스 : 각실 SA/RA 개방. 단, 대시보드 수동 댐퍼(DamperManual) 실은 그 위치 유지.
_state.AutoConcentrate = false;
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
if (rm.DamperManual) continue; // 대시보드 수동 댐퍼 - 자동 개방 덮어쓰기 안 함
SetDamper(rm, 110, 110);
}
logTag = $"{_state.RunMode} 각실 SA/RA 개방";
}
else
{
// 자동 : 대기 / 집중 / 분산
if (pmax == 0)
{
_state.AutoConcentrate = false;
for (int r = 1; r <= 4; r++) SetDamper(_state.GetRoom(r), 0, 0);
}
else if (dP >= 2)
{
_state.AutoConcentrate = true;
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
int ang = rm.Level == pmax ? 110 : 0;
SetDamper(rm, ang, ang);
}
}
else
{
// 분산 (260428 v.Final) : 1단계 이상 실만 개방, 0단계(좋음) 실은 닫음
_state.AutoConcentrate = false;
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
int ang = rm.Level >= 1 ? 110 : 0;
SetDamper(rm, ang, ang);
}
}
// 최종 풍량 : 부하총점 매핑
byte stage = (byte)ScoreToStage(score);
if (_state.FanMode != stage) { _state.FanMode = _state.SetFanMode = stage; fanChanged = true; }
logTag = $"자동 {(pmax == 0 ? "" : dP >= 2 ? "" : "")} Score={score} dP={dP} → {_state.FanMode}단";
}
// ---- LED : 댐퍼(SA/RA 중 하나라도 개방) 추종. 닫히면 0. 수동 조작(LedManual)은 예외 ----
for (int r = 1; r <= 4; r++)
{
var rm = _state.GetRoom(r);
if (rm.LedManual) continue;
int want = (_state.PowerOn && (rm.MemorySA > 0 || rm.MemoryRA > 0)) ? 9 : 0;
if (rm.LightBright != want) rm.LightBright = want;
}
if (fanChanged || damperChanged)
{
_seq.NotifyCommandChanged();
Log?.Invoke($"[댐퍼] {logTag}");
}
_prevSmartSleep = _state.SmartSleep; // 다음 틱의 스마트수면 진입 감지용
}
}
}
@@ -0,0 +1,169 @@
using System;
using System.Windows.Threading;
namespace ERVSimulator.Model
{
// 펌웨어 [MyMotor.c] Damper_Mode() + Diffuser_Damper_process() 시퀀스를 흉내
// - Cmd 변경 시 18초 시퀀스 트리거 (slot 180 / 120 / 60, 100ms tick)
// - 본체 댐퍼 6개: Run_Mode 에 따라 즉시 목표각 세팅
// - 디퓨저 댐퍼: Memory → Current 슬롯별 복사
// - 팬 PWM: 매 tick ±1 ramp
public class DamperSequencer
{
public ErvState State { get; }
private readonly DispatcherTimer _timer;
private int _diffuserSlot; // 180..0 카운트다운
private int _seqType; // 1=on, 2=off, 3=decrease, 4=increase
private int _prevAirVolume;
private bool _pendingSequence;
public DamperSequencer(ErvState state)
{
State = state;
_timer = new DispatcherTimer(DispatcherPriority.Normal)
{
Interval = TimeSpan.FromMilliseconds(100)
};
_timer.Tick += OnTick;
_timer.Start();
}
// RoomCon/HomeNet 핸들러가 Run_Mode/Fan_Mode 갱신 후 호출
public void NotifyCommandChanged()
{
_pendingSequence = true;
}
void OnTick(object? sender, EventArgs e)
{
// ---- Fan_Speed_process() 시작부: VENT && Fan=0 → 정지 진입 ----
int newAirVolume = (State.RunMode != RunMode.Off && State.FanMode != 0) ? State.FanMode : 0;
if (_pendingSequence)
{
_pendingSequence = false;
_diffuserSlot = 180;
_seqType = DetermineSeqType(_prevAirVolume, newAirVolume);
_prevAirVolume = newAirVolume;
}
// ---- Damper_Mode(Run_Mode) — 본체 댐퍼 즉시 목표각 ----
ApplyBodyDamperMode(EffectiveBodyMode());
// ---- Diffuser_Damper_process() — 슬롯 기반 적용 ----
if (_diffuserSlot == 180)
{
if (_seqType == 1 || _seqType == 4)
CopyMemoryToCurrent(1, 2);
else if (_seqType == 2 || _seqType == 3)
SetFanTargets(); // 즉시 ramp 시작
}
else if (_diffuserSlot == 120)
{
if (_seqType == 1 || _seqType == 4 || _seqType == 2 || _seqType == 3)
CopyMemoryToCurrent(3, 4);
}
else if (_diffuserSlot == 60)
{
if (_seqType == 1 || _seqType == 4)
SetFanTargets();
else if (_seqType == 2 || _seqType == 3)
CopyMemoryToCurrent(1, 2);
}
if (_diffuserSlot > 0) _diffuserSlot--;
// ---- 팬 ramp ±1 (펌웨어와 동일) ----
if (State.Fan1Current < State.Fan1Target) State.Fan1Current++;
else if (State.Fan1Current > State.Fan1Target) State.Fan1Current--;
if (State.Fan2Current < State.Fan2Target) State.Fan2Current++;
else if (State.Fan2Current > State.Fan2Target) State.Fan2Current--;
}
int DetermineSeqType(int prev, int now)
{
if (prev == 0 && now != 0) return 4; // increase (power on)
if (prev != 0 && now == 0) return 3; // decrease (power off)
if (prev > now) return 3;
return 4;
}
RunMode EffectiveBodyMode()
{
// VENT && Fan=0 → 본체 댐퍼는 MODE_OFF 로 진입 (펌웨어 Fan_Speed_process 분기)
if (State.RunMode == RunMode.Off) return RunMode.Off;
if (State.RunMode == RunMode.Ventilation && State.FanMode == 0 &&
State.Fan1Current == 0 && State.Fan2Current == 0)
return RunMode.Off;
return State.RunMode;
}
// 펌웨어 Damper_Mode() — MyMotor.c:472
void ApplyBodyDamperMode(RunMode mode)
{
switch (mode)
{
case RunMode.Ventilation:
SetBody(DamperId.OA, 0); SetBody(DamperId.EA, 0); SetBody(DamperId.BYPASS, 100);
SetBody(DamperId.SA, 0); SetBody(DamperId.RA, 70); SetBody(DamperId.AIR, 105);
break;
case RunMode.AirClean:
SetBody(DamperId.OA, 100); SetBody(DamperId.EA, 100); SetBody(DamperId.BYPASS, 100);
SetBody(DamperId.SA, 0); SetBody(DamperId.RA, 140); SetBody(DamperId.AIR, 0);
break;
case RunMode.Bypass:
SetBody(DamperId.OA, 0); SetBody(DamperId.EA, 0); SetBody(DamperId.BYPASS, 0);
SetBody(DamperId.SA, 0); SetBody(DamperId.RA, 140); SetBody(DamperId.AIR, 105);
break;
case RunMode.Auto:
// 펌웨어는 자동 시 공기질에 따라 VENT/AIR 선택. 단순화: VENT 와 동일.
SetBody(DamperId.OA, 0); SetBody(DamperId.EA, 0); SetBody(DamperId.BYPASS, 100);
SetBody(DamperId.SA, 0); SetBody(DamperId.RA, 70); SetBody(DamperId.AIR, 105);
break;
case RunMode.Off:
default:
SetBody(DamperId.OA, 100); SetBody(DamperId.EA, 100); SetBody(DamperId.BYPASS, 100);
SetBody(DamperId.SA, 100); SetBody(DamperId.RA, 0); SetBody(DamperId.AIR, 105);
break;
}
}
void SetBody(DamperId id, int angle) => State.GetDamper(id).TargetAngle = angle;
void CopyMemoryToCurrent(int fromRoom, int toRoom)
{
for (int r = fromRoom; r <= toRoom; r++)
{
var room = State.GetRoom(r);
room.CurrentSA = room.MemorySA;
room.CurrentRA = room.MemoryRA;
}
}
// 펌웨어 Fan_Speed_Setting(Run_Mode, Fan_Mode) — MyMotor.c:1233
void SetFanTargets()
{
int idx = System.Math.Clamp(State.FanMode, (byte)0, (byte)4);
switch (State.RunMode)
{
case RunMode.Ventilation:
case RunMode.Auto:
State.Fan1Target = State.FanSAPreset_Vent[idx];
State.Fan2Target = State.FanEAPreset_Vent[idx];
break;
case RunMode.Bypass:
State.Fan1Target = State.FanSAPreset_Bypass[idx];
State.Fan2Target = State.FanEAPreset_Bypass[idx];
break;
case RunMode.AirClean:
State.Fan1Target = State.FanSAPreset_Air[idx];
State.Fan2Target = State.FanEAPreset_Air[idx];
break;
default:
State.Fan1Target = 0;
State.Fan2Target = 0;
break;
}
}
}
}
@@ -0,0 +1,267 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace ERVSimulator.Model
{
// 6 본체 댐퍼 (Damper_Mode()가 직접 각도 명령)
public class BodyDamper : INotifyPropertyChanged
{
public string Name { get; }
public string Connector { get; } // CN2, CN10 ...
public string ColorTag { get; } // GREEN, YELLOW ...
public DamperId Id { get; }
private int _targetAngle;
public int TargetAngle
{
get => _targetAngle;
set { if (_targetAngle != value) { _targetAngle = value; OnChanged(); OnChanged(nameof(IsOpen)); } }
}
// 펌웨어 주석: 90 = close, 0 = open, 100/105 = close 변형
// RA(환기)만 '3step--reverse' → 0=닫힘, 70/140=열림 으로 규칙 반대 (MyMotor.c:482)
// → 전원 OFF(RA=0) 시 6개 댐퍼 모두 닫힘으로 표시
public bool IsOpen => Id == DamperId.RA ? TargetAngle >= 50 : TargetAngle < 50;
public BodyDamper(DamperId id, string name, string cn, string color)
{
Id = id; Name = name; Connector = cn; ColorTag = color;
}
public event PropertyChangedEventHandler? PropertyChanged;
void OnChanged([CallerMemberName] string? n = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(n));
}
// 디퓨저 각실 (1~4)
public class DiffuserRoom : INotifyPropertyChanged
{
public int RoomId { get; }
public string Name { get; }
int _memorySA, _memoryRA, _currentSA, _currentRA, _light;
// Memory_* (RoomCon/HomeNet 핸들러가 즉시 갱신, 목표값)
public int MemorySA { get => _memorySA; set { if (_memorySA != value) { _memorySA = value; OnChanged(); } } }
public int MemoryRA { get => _memoryRA; set { if (_memoryRA != value) { _memoryRA = value; OnChanged(); } } }
// Diffuser_Dmp_Ang_* (시퀀서가 슬롯 시간에 Memory→Current 복사)
public int CurrentSA { get => _currentSA; set { if (_currentSA != value) { _currentSA = value; OnChanged(); OnChanged(nameof(IsOpenSA)); } } }
public int CurrentRA { get => _currentRA; set { if (_currentRA != value) { _currentRA = value; OnChanged(); OnChanged(nameof(IsOpenRA)); } } }
public int LightBright { get => _light; set { if (_light != value) { _light = value; OnChanged(); } } }
// 디퓨저 응답이 echo 한 실제 LED 단수 (디퓨저 수동 LED 제어 시 ERV 명령과 다를 수 있음) → STATUS 로 송신
int _ledReported;
public int LedReported { get => _ledReported; set { if (_ledReported != value) { _ledReported = value; OnChanged(); } } }
// 수동 LED 조작(CTRL_LED) 시 true → 자동로직이 LED 를 덮어쓰지 않음(예외). 비-수동모드 진입 시 해제.
public bool LedManual { get; set; }
// 수동 댐퍼 조작(CTRL_DAMPER) 시 true → 비자동(환기/공청/바이패스)에서 자동개방 덮어쓰기 안 함. 자동/부가모드/전원OFF/모드전환 시 해제.
public bool DamperManual { get; set; }
public bool IsOpenSA => CurrentSA > 0;
public bool IsOpenRA => CurrentRA > 0;
// ---- 공기질 센서값 (DiffuserSimulator 응답에서 수신) ----
int _co2, _pm25, _pm10, _voc, _level, _airQuality = 4, _temp, _humi;
public int Co2 { get => _co2; set { if (_co2 != value) { _co2 = value; OnChanged(); } } }
public int Pm25 { get => _pm25; set { if (_pm25 != value) { _pm25 = value; OnChanged(); } } }
public int Pm10 { get => _pm10; set { if (_pm10 != value) { _pm10 = value; OnChanged(); } } }
public int Voc { get => _voc; set { if (_voc != value) { _voc = value; OnChanged(); } } }
public int Temp { get => _temp; set { if (_temp != value) { _temp = value; OnChanged(); } } }
public int Humi { get => _humi; set { if (_humi != value) { _humi = value; OnChanged(); } } }
// 오염 단계 0~4 (자동로직 산출)
public int Level { get => _level; set { if (_level != value) { _level = value; OnChanged(); OnChanged(nameof(SensorText)); } } }
// 공기질 코드 1매우나쁨~4좋음 (STATUS 송신용)
public int AirQuality { get => _airQuality; set { if (_airQuality != value) { _airQuality = value; OnChanged(); } } }
public string SensorText => $"CO2 {Co2} PM2.5 {Pm25} PM10 {Pm10} VOC {Voc} → Lv{Level}";
public DiffuserRoom(int id, string name) { RoomId = id; Name = name; }
public event PropertyChangedEventHandler? PropertyChanged;
void OnChanged([CallerMemberName] string? n = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(n));
}
public class ErvState : INotifyPropertyChanged
{
// ---- 상위 상태 ----
bool _powerOn;
RunMode _runMode = RunMode.Off;
RunMode _setRunMode = RunMode.Off;
byte _fanMode; // 0~4 단
byte _setFanMode;
public bool PowerOn { get => _powerOn; set { if (_powerOn != value) { _powerOn = value; OnChanged(); } } }
public RunMode RunMode { get => _runMode; set { if (_runMode != value) { _runMode = value; OnChanged(); } } }
public RunMode SetRunMode { get => _setRunMode; set { if (_setRunMode != value) { _setRunMode = value; OnChanged(); } } }
public byte FanMode { get => _fanMode; set { if (_fanMode != value) { _fanMode = value; OnChanged(); } } }
public byte SetFanMode { get => _setFanMode; set { if (_setFanMode != value) { _setFanMode = value; OnChanged(); } } }
// ---- 260520 자동 동작로직 상태 ----
byte _hystPreset = 1; // 0 ECO / 1 NORMAL / 2 TURBO
bool _autoConcentrate; // false 분산 / true 집중
int _loadScore, _pMax, _dP;
public byte HystPreset { get => _hystPreset; set { if (_hystPreset != value) { _hystPreset = value; OnChanged(); } } }
public bool AutoConcentrate { get => _autoConcentrate; set { if (_autoConcentrate != value) { _autoConcentrate = value; OnChanged(); OnChanged(nameof(AutoStateText)); } } }
public int LoadScore { get => _loadScore; set { if (_loadScore != value) { _loadScore = value; OnChanged(); OnChanged(nameof(AutoStateText)); } } }
public int PMax { get => _pMax; set { if (_pMax != value) { _pMax = value; OnChanged(); } } }
public int DP { get => _dP; set { if (_dP != value) { _dP = value; OnChanged(); } } }
public string AutoStateText => RunMode == RunMode.Auto
? $"{(PMax == 0 ? "" : AutoConcentrate ? "" : "")} · Score {LoadScore} · {FanMode}단"
: "(자동모드 아님)";
// 부가모드 (월패드 토글/버튼)
byte _extRunMode;
bool _hoodEnable;
public byte ExtRunMode { get => _extRunMode; set { if (_extRunMode != value) { _extRunMode = value; OnChanged(); OnChanged(nameof(SubModeText)); } } } // 1 안심회복 / 4 스마트수면
public bool HoodEnable { get => _hoodEnable; set { if (_hoodEnable != value) { _hoodEnable = value; OnChanged(); OnChanged(nameof(SubModeText)); } } } // 후드연동(쾌적조리)
public bool HoodStatus { get; set; }
public byte ResetState { get; set; } // ERV 리셋 토글 echo
// ---- 후드(HOOD 프로토콜 Rev1.3) 슬레이브 보고값 ----
bool _hoodConnected;
public bool HoodConnected { get => _hoodConnected; set { if (_hoodConnected != value) { _hoodConnected = value; OnChanged(); } } } // 후드 폴 응답 생존(통신 연결)
int _hoodFan; bool _hoodLight; bool _hoodCmd; int _hoodError;
public int HoodFan { get => _hoodFan; set { if (_hoodFan != value) { _hoodFan = value; OnChanged(); } } } // 후드 FAN STATUS 0~5
public bool HoodLight { get => _hoodLight; set { if (_hoodLight != value) { _hoodLight = value; OnChanged(); } } } // 후드 LIGHT STATUS
public bool HoodCmd { get => _hoodCmd; set { if (_hoodCmd != value) { _hoodCmd = value; OnChanged(); } } } // 연동 CMD(후드 동작중)
public int HoodError { get => _hoodError; set { if (_hoodError != value) { _hoodError = value; OnChanged(); } } } // ERROR : 0 정상 / 1 FAN / 2 기타
public bool SmartSleep { get => ExtRunMode == 4; } // 스마트수면
public bool CookingMode { get => HoodEnable; } // 쾌적조리(후드연동)
public bool RecoveryMode { get => ExtRunMode == 1; } // 안심회복
public string SubModeText
{
get
{
var s = "";
if (SmartSleep) s += "스마트수면 ";
if (CookingMode) s += "쾌적조리 ";
if (RecoveryMode) s += "안심회복 ";
return s.Length == 0 ? "없음" : s.Trim();
}
}
// ---- (꺼짐)예약 0~8시간 ----
int _reserveHours; // 0 = 해제
int _reserveRemainSec;
public int ReserveHours { get => _reserveHours; set { if (_reserveHours != value) { _reserveHours = value; OnChanged(); } } }
public int ReserveRemainSec { get => _reserveRemainSec; set { if (_reserveRemainSec != value) { _reserveRemainSec = value; OnChanged(); OnChanged(nameof(ReserveText)); } } }
public string ReserveText => ReserveRemainSec > 0
? $"예약 꺼짐까지 {ReserveRemainSec / 3600}:{(ReserveRemainSec % 3600) / 60:00}:{ReserveRemainSec % 60:00}"
: "예약 없음";
// 히스테리시스 데드밴드(하강) [preset] : CO2,PM2.5,PM10,VOC (사양서 10p)
public ushort[] Co2Db { get; } = { 50, 50, 30 };
public ushort[] Pm25Db { get; } = { 2, 2, 2 };
public ushort[] Pm10Db { get; } = { 5, 5, 5 };
public ushort[] VocDb { get; } = { 5, 5, 3 };
// 모드별(ECO/NORMAL/TURBO) 오염단계 상한 임계 [preset][레벨1~4]
public ushort[][] Co2Thr { get; } = { new ushort[]{1000,1300,1600,2000}, new ushort[]{800,1100,1400,1700}, new ushort[]{700,1000,1300,1600} };
public ushort[][] Pm25Thr { get; } = { new ushort[]{20,38,60,86}, new ushort[]{14,29,49,69}, new ushort[]{12,23,38,52} };
public ushort[][] Pm10Thr { get; } = { new ushort[]{40,86,126,173}, new ushort[]{28,66,102,138}, new ushort[]{24,53,78,104} };
public ushort[][] VocThr { get; } = { new ushort[]{171,195,308,438}, new ushort[]{120,150,250,350}, new ushort[]{103,120,192,263} };
// ---- 본체 6 댐퍼 ----
public ObservableCollection<BodyDamper> BodyDampers { get; }
// ---- 각실 디퓨저 4 룸 ----
public ObservableCollection<DiffuserRoom> Rooms { get; }
// ---- 팬 (BLDC SA/EA) ----
// 펌웨어 PWM duty 0~10000 매핑. UI는 0~10000 슬라이드로 표시 + 환산 RPM 추정.
int _fan1Target, _fan1Current; // SA
int _fan2Target, _fan2Current; // EA
public int Fan1Target { get => _fan1Target; set { if (_fan1Target != value) { _fan1Target = value; OnChanged(); } } }
public int Fan1Current { get => _fan1Current; set { if (_fan1Current != value) { _fan1Current = value; OnChanged(); } } }
public int Fan2Target { get => _fan2Target; set { if (_fan2Target != value) { _fan2Target = value; OnChanged(); } } }
public int Fan2Current { get => _fan2Current; set { if (_fan2Current != value) { _fan2Current = value; OnChanged(); } } }
// ---- 에러 코드 (PPT 매핑 + HERV 펌웨어 My_define.h:206 비트맵) ----
public const byte ERR_FILTER_CLEAN = 0x01;
public const byte ERR_FILTER_CHANGE = 0x02;
public const byte ERR_SOJA_CHANGE = 0x04;
public const byte ERR_TEMP_SENSOR = 0x08; // E02 온도센서 에러
public const byte ERR_PROTECT = 0x10; // COLD 장비보호모드
public const byte ERR_EA_FAN = 0x20; // E10 배기(EA)팬 에러
public const byte ERR_SOMETIME = 0x40; // E07 내부통신 에러
public const byte ERR_SA_FAN = 0x80; // E09 급기(SA)팬 에러
byte _errorCode;
public byte ErrorCode
{
get => _errorCode;
set
{
if (_errorCode != value)
{
_errorCode = value;
OnChanged();
OnChanged(nameof(E02_TempSensor));
OnChanged(nameof(E09_SaFan));
OnChanged(nameof(E10_EaFan));
OnChanged(nameof(COLD_Protect));
OnChanged(nameof(E07_InternalComm));
OnChanged(nameof(FilterClean));
OnChanged(nameof(FilterChange));
}
}
}
// 알람(유지보수) — 필터 청소/교환. 룸콘·대시보드로 ErrorCode 비트로 전달.
public bool FilterClean { get => (ErrorCode & ERR_FILTER_CLEAN) != 0; set => SetErr(ERR_FILTER_CLEAN, value); }
public bool FilterChange { get => (ErrorCode & ERR_FILTER_CHANGE) != 0; set => SetErr(ERR_FILTER_CHANGE, value); }
public bool E02_TempSensor { get => (ErrorCode & ERR_TEMP_SENSOR) != 0; set => SetErr(ERR_TEMP_SENSOR, value); }
public bool E09_SaFan { get => (ErrorCode & ERR_SA_FAN) != 0; set => SetErr(ERR_SA_FAN, value); }
public bool E10_EaFan { get => (ErrorCode & ERR_EA_FAN) != 0; set => SetErr(ERR_EA_FAN, value); }
public bool COLD_Protect { get => (ErrorCode & ERR_PROTECT) != 0; set => SetErr(ERR_PROTECT, value); }
public bool E07_InternalComm { get => (ErrorCode & ERR_SOMETIME) != 0; set => SetErr(ERR_SOMETIME, value); }
void SetErr(byte bit, bool on)
{
byte newVal = on ? (byte)(_errorCode | bit) : (byte)(_errorCode & ~bit);
ErrorCode = newVal;
}
// 1~4단 VSP preset (1바이트 0~255). 기본값 = 사양서 DL H-ERV VSP 실측표 (index 1~4)
public ushort[] FanSAPreset_Vent { get; } = { 0, 56, 63, 70, 86 }; // 환기 SA
public ushort[] FanEAPreset_Vent { get; } = { 0, 57, 63, 70, 85 }; // 환기 EA
public ushort[] FanSAPreset_Bypass { get; } = { 0, 67, 0, 0, 0 }; // 바이패스 SA (기본단)
public ushort[] FanEAPreset_Bypass { get; } = { 0, 75, 0, 0, 0 }; // 바이패스 EA
public ushort[] FanSAPreset_Air { get; } = { 0, 65, 72, 78, 80 }; // 공청 SA
public ushort[] FanEAPreset_Air { get; } = { 0, 0, 0, 0, 0 }; // 공청 EA (미사용 '-')
public ErvState()
{
BodyDampers = new ObservableCollection<BodyDamper>
{
// PPT 순서/색상 매핑
new(DamperId.OA, "외기(OA)", "CN2", "GREEN"),
new(DamperId.AIR, "공청(AIR)", "CN10", "YELLOW"),
new(DamperId.BYPASS, "바이패스", "CN5", "RED"),
new(DamperId.EA, "배기(EA)", "CN3", "BLACK"),
new(DamperId.SA, "급기(SA)", "CN7", "BLUE"),
new(DamperId.RA, "환기(RA) 3단", "CN9", "WHITE"),
};
Rooms = new ObservableCollection<DiffuserRoom>
{
new(1, "거실"),
new(2, "침실1"),
new(3, "침실2"),
new(4, "침실3"),
};
}
public BodyDamper GetDamper(DamperId id)
{
foreach (var d in BodyDampers) if (d.Id == id) return d;
throw new System.InvalidOperationException();
}
public DiffuserRoom GetRoom(int roomId)
{
foreach (var r in Rooms) if (r.RoomId == roomId) return r;
throw new System.InvalidOperationException();
}
public event PropertyChangedEventHandler? PropertyChanged;
void OnChanged([CallerMemberName] string? n = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(n));
}
}
@@ -0,0 +1,24 @@
namespace ERVSimulator.Model
{
// HERV 펌웨어 SPEC_MODE_INFO=0x16 (대림사양, 히터X, 바이패스O, 공청X) 기준
// My_define.h:271 #if !((SPEC_MODE_INFO&0x0F)==0x03||==0x06) 분기
public enum RunMode : byte
{
Ventilation = 0,
Auto = 1,
Bypass = 2,
AirClean = 3,
FanTest = 4,
Off = 10, // MODE_OFF (MyMotor.c)
}
public enum DamperId
{
EA = 1, // 배기
OA = 2, // 외기
BYPASS = 3,
SA = 4, // 급기
RA = 5, // 환기
AIR = 6, // 공청
}
}
@@ -0,0 +1,19 @@
namespace ERVSimulator.Protocol
{
public static class ChecksumHelper
{
public static byte Xor(byte[] data, int start, int length)
{
byte x = 0;
for (int i = 0; i < length; i++) x ^= data[start + i];
return x;
}
public static byte Add(byte[] data, int start, int length)
{
int s = 0;
for (int i = 0; i < length; i++) s += data[start + i];
return (byte)(s & 0xFF);
}
}
}
@@ -0,0 +1,132 @@
using System;
using System.Windows.Threading;
using ERVSimulator.Model;
using ErvProtocol; // 공용 Crc16 (bunbaegi CRC 도 표준 MODBUS 동일)
using RunMode = ERVSimulator.Model.RunMode; // ErvProtocol.RunMode 와 이름 충돌 해소
namespace ERVSimulator.Protocol
{
// 디퓨저 버스 마스터 (115200) <-> DiffuserSimulator(슬레이브)
// 규격 : Protocol/수정_Each_Room_Jushin_protocol_RS485_Rev1.2 (펌웨어 My_Uart.c bunbaegi 미러)
// 목적 : DiffuserSimulator 로부터 각실 센서값(PM2.5/PM10/VOC/CO2) 수신 → ErvState → 자동로직
// - 마스터 폴(29B, 0x10): 실/타입(SA/RA)별 전원·모드·풍량·LED·댐퍼 송신 (poll-response 구조상 필수)
// - 슬레이브 응답(39B, 0x01): 센서값 수신
// ※ ERVSim 은 각실 댐퍼+LED 를 자체 표시하지 않음(DiffuserSimulator 가 표시). 통신만 수행.
public class DiffuserMasterProtocol
{
readonly SerialChannel _ch;
readonly ErvState _state;
readonly Dispatcher _dispatcher;
readonly DispatcherTimer _pollTimer;
int _pollIdx; // (room1 SA),(room1 RA)...(room4 RA) round-robin
readonly byte[] _rx = new byte[39];
int _rxPos;
DateTime _lastByte = DateTime.MinValue;
static readonly TimeSpan FrameGap = TimeSpan.FromMilliseconds(40);
public event Action<string>? PacketReceived;
public event Action<string>? PacketSent;
public bool Verbose { get; set; } = false; // true면 모든 폴 로그
public DiffuserMasterProtocol(SerialChannel ch, ErvState state, Dispatcher dispatcher)
{
_ch = ch; _state = state; _dispatcher = dispatcher;
_ch.ByteReceived += OnByte;
_pollTimer = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromMilliseconds(80) };
_pollTimer.Tick += (_, _) => { if (_ch.IsConnected) PollNext(); };
_pollTimer.Start();
}
byte DiffRunMode() => _state.RunMode switch
{
RunMode.Ventilation => 0x01,
RunMode.Auto => 0x02,
RunMode.Bypass => 0x04,
RunMode.AirClean => 0x08,
_ => 0x01,
};
void PollNext()
{
int room = _pollIdx / 2 + 1; // 1~4
byte id1 = (byte)(_pollIdx % 2 == 0 ? 0x01 : 0x02); // SA / RA
_pollIdx = (_pollIdx + 1) % 8;
var rm = _state.GetRoom(room);
var p = new byte[29];
p[0] = 0xAA; p[1] = 0x10; p[2] = id1; p[3] = (byte)room; p[4] = 0x00;
p[5] = (byte)(_state.PowerOn ? 1 : 0);
p[6] = DiffRunMode();
p[7] = _state.FanMode;
p[8] = (byte)rm.LightBright;
p[9] = (byte)rm.AirQuality;
p[10] = (byte)rm.CurrentSA;
p[11] = (byte)rm.CurrentRA;
ushort crc = Crc16.Modbus(p, 0, 27);
// lo-first : 펌웨어 CRC16()이 표준MODBUS 바이트스왑값 반환 + [27]=icrc>>8 배치 → 와이어는 리틀엔디안
p[27] = (byte)(crc & 0xFF);
p[28] = (byte)(crc >> 8);
_ch.Send(p, 29);
if (Verbose) PacketSent?.Invoke($"Diff TX poll room{room} {(id1 == 1 ? "SA" : "RA")} SA={rm.CurrentSA} RA={rm.CurrentRA} LED={rm.LightBright}");
}
void OnByte(byte b)
{
var now = DateTime.UtcNow;
if (now - _lastByte > FrameGap) _rxPos = 0;
_lastByte = now;
if (_rxPos == 0)
{
if (b == 0xAA) { _rx[0] = b; _rxPos = 1; }
}
else if (_rxPos == 1)
{
if (b == 0x01) { _rx[1] = b; _rxPos = 2; }
else _rxPos = (b == 0xAA) ? 1 : 0;
}
else
{
_rx[_rxPos++] = b;
if (_rxPos >= 39)
{
var copy = (byte[])_rx.Clone();
_dispatcher.BeginInvoke(new Action(() => HandleResponse(copy)));
_rxPos = 0;
}
}
}
void HandleResponse(byte[] p)
{
ushort rxcrc = (ushort)(p[37] | (p[38] << 8)); // lo-first (표준 리틀엔디안)
if (Crc16.Modbus(p, 0, 37) != rxcrc)
{
PacketReceived?.Invoke($"Diff RX CRC오류 {HexFormat.Bytes(p, 39)}");
return;
}
int id1 = p[2]; // 0x01 SA / 0x02 RA
int room = p[3]; // 1~4
if (room < 1 || room > 4) return;
// 센서 (응답 39B, 빅엔디안) : LED[8] PM10[12,13] PM2.5[16,17] 습도[20,21] 온도[22,23] VOC[24,25] CO2[28,29]
int led = p[8]; // 디퓨저가 echo 한 실제 LED 단수 (수동 제어 시 ERV 명령과 다를 수 있음)
int pm10 = (p[12] << 8) | p[13];
int pm25 = (p[16] << 8) | p[17];
int humi = (p[20] << 8) | p[21];
int temp = (p[22] << 8) | p[23];
int voc = (p[24] << 8) | p[25];
int co2 = (p[28] << 8) | p[29];
var rm = _state.GetRoom(room);
bool changed = rm.Co2 != co2 || rm.Pm25 != pm25 || rm.Pm10 != pm10 || rm.Voc != voc || rm.Temp != temp || rm.Humi != humi || rm.LedReported != led;
rm.Pm10 = pm10; rm.Pm25 = pm25; rm.Voc = voc; rm.Co2 = co2; rm.Temp = temp; rm.Humi = humi; rm.LedReported = led;
if (changed || Verbose)
PacketReceived?.Invoke($"Diff RX {rm.Name} 센서 CO2={co2} PM2.5={pm25} PM10={pm10} VOC={voc} 온도={temp} 습도={humi} LED={led} (from {(id1 == 1 ? "SA" : "RA")})");
}
}
}
@@ -0,0 +1,281 @@
using System;
using System.Windows.Threading;
using ERVSimulator.Model;
using ErvProtocol; // 공용 프로토콜 (단일 진실원본) : FrameParser/CtrlFrame/StatusEncoder/StatusRecord
using RunMode = ERVSimulator.Model.RunMode; // ErvProtocol.RunMode 와 이름 충돌 해소
namespace ERVSimulator.Protocol
{
// HOMENET (UART1, 115200 N81) <-> ErvDashboard
// 규격/코덱 모두 공용 라이브러리 ErvProtocol 사용 (PC_ERV_Protocol.md).
// 본 클래스는 ErvState <-> ErvProtocol.StatusRecord 매핑 + 제어명령 적용만 담당.
public class HomeNetProtocol
{
readonly SerialChannel _ch;
readonly ErvState _state;
readonly DamperSequencer _seq;
readonly Dispatcher _dispatcher;
readonly DispatcherTimer _statusTimer;
readonly FrameParser _parser = new();
public event Action<string>? PacketReceived;
public event Action<string>? PacketSent;
public HomeNetProtocol(SerialChannel ch, ErvState state, DamperSequencer seq, Dispatcher dispatcher)
{
_ch = ch; _state = state; _seq = seq; _dispatcher = dispatcher;
_parser.OnFrame += (cmd, pl) => _dispatcher.BeginInvoke(new Action(() => HandleFrame(cmd, pl)));
_parser.OnError += msg => PacketReceived?.Invoke($"HomeNet {msg}");
_ch.ByteReceived += b => _parser.FeedByte(b);
_statusTimer = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromSeconds(1) };
_statusTimer.Tick += (_, _) => { if (_ch.IsConnected) SendStatus(); };
_statusTimer.Start();
}
// ---- ErvState → StatusRecord ----
byte RunModeCode()
{
if (!_state.PowerOn) return 0;
return _state.RunMode switch
{
RunMode.Ventilation => 1,
RunMode.Auto => 2,
RunMode.AirClean => 3,
RunMode.Bypass => 4,
_ => 1,
};
}
StatusRecord BuildRecord()
{
int hp = _state.HystPreset;
var s = new StatusRecord
{
Power = (byte)(_state.PowerOn ? 1 : 0),
RunMode = RunModeCode(),
AutoState = (byte)(_state.AutoConcentrate ? 1 : 0),
FanMode = _state.FanMode,
SubMode = (byte)((_state.SmartSleep ? 0x01 : 0) | (_state.CookingMode ? 0x02 : 0) | (_state.RecoveryMode ? 0x04 : 0)),
Hood = (byte)((_state.HoodEnable ? 0x01 : 0) | (_state.HoodStatus ? 0x02 : 0) | (_state.HoodConnected ? 0x04 : 0)),
HystPreset = (byte)hp,
HystPm25 = _state.Pm25Db[hp],
HystPm10 = _state.Pm10Db[hp],
HystVoc = _state.VocDb[hp],
HystCo2 = _state.Co2Db[hp],
ErrorCode = _state.ErrorCode,
Reset = _state.ResetState,
ReserveRemainSec = _state.ReserveRemainSec,
};
for (int r = 0; r < 4; r++)
{
var room = _state.GetRoom(r + 1);
var rr = s.Rooms[r];
// 비트맵 : bit0=급기(SA) 열림 / bit1=배기(RA) 열림 (StatusRecord.RoomRecord 와 일치)
rr.Damper = (byte)((room.MemorySA != 0 ? 0x01 : 0) | (room.MemoryRA != 0 ? 0x02 : 0));
rr.Pm25 = room.Pm25;
rr.Pm10 = room.Pm10;
rr.Voc = room.Voc;
rr.Co2 = room.Co2;
rr.AirQuality = (byte)room.AirQuality;
// 디퓨저가 응답마다 echo 하는 실제 LED 단수를 보고 → 디퓨저 수동 LED 제어가 대시보드에 반영됨
rr.LedDim = (byte)room.LedReported;
rr.LoadScore = room.Level;
rr.FinalVolume = _state.FanMode;
rr.Temp = (byte)Math.Clamp(room.Temp, 0, 255);
rr.Humi = (byte)Math.Clamp(room.Humi, 0, 255);
}
// VSP : 환기1~4, 바이패스, 공청1~4
for (int i = 1; i <= 4; i++) { s.Vsp[i - 1].Sa = _state.FanSAPreset_Vent[i]; s.Vsp[i - 1].Ea = _state.FanEAPreset_Vent[i]; }
s.Vsp[4].Sa = _state.FanSAPreset_Bypass[1]; s.Vsp[4].Ea = _state.FanEAPreset_Bypass[1];
for (int i = 1; i <= 4; i++) { s.Vsp[4 + i].Sa = _state.FanSAPreset_Air[i]; s.Vsp[4 + i].Ea = _state.FanEAPreset_Air[i]; }
// 히스테리시스 데드밴드 테이블
for (int i = 0; i < 3; i++)
{
s.HystTable[i].Pm25 = _state.Pm25Db[i];
s.HystTable[i].Pm10 = _state.Pm10Db[i];
s.HystTable[i].Voc = _state.VocDb[i];
s.HystTable[i].Co2 = _state.Co2Db[i];
}
// 모드별 오염단계 임계표
for (int i = 0; i < 3; i++)
for (int k = 0; k < 4; k++)
{
s.ThrTable[i].Co2[k] = _state.Co2Thr[i][k];
s.ThrTable[i].Pm25[k] = _state.Pm25Thr[i][k];
s.ThrTable[i].Pm10[k] = _state.Pm10Thr[i][k];
s.ThrTable[i].Voc[k] = _state.VocThr[i][k];
}
return s;
}
public void SendStatus()
{
var frame = StatusEncoder.BuildStatusFrame(BuildRecord());
_ch.Send(frame, frame.Length);
string autoTag = _state.RunMode == RunMode.Auto ? (_state.AutoConcentrate ? " 집중" : " 분산") : ""; // 집중/분산은 자동모드에서만
PacketSent?.Invoke($"HomeNet TX STATUS(0x81) [{(_state.PowerOn ? "ON" : "OFF")} {_state.RunMode} {_state.FanMode}단{autoTag}]");
}
// ---- 수신 제어명령 적용 + ACK ----
void HandleFrame(byte cmd, byte[] pl)
{
byte result = 0;
bool modeChanged = false;
switch (cmd)
{
case CtrlFrame.CTRL_POWER:
if (pl.Length >= 1)
{
bool on = pl[0] != 0;
_state.PowerOn = on;
if (on)
{
// 전원 ON : 환기 모드 + 풍량 1단. 디퓨저 개방·LED 는 AutoLogic 이 댐퍼 상태에 맞춰 구동.
_state.RunMode = _state.SetRunMode = RunMode.Ventilation;
_state.FanMode = _state.SetFanMode = 1;
}
else
{
// 전원 OFF : 정지 (댐퍼 닫힘·LED 소등은 AutoLogic 이 처리)
_state.FanMode = _state.SetFanMode = 0;
}
// 전원 토글 시 수동 LED·댐퍼 해제 → 자동 추종 복귀
for (int r = 1; r <= 4; r++) { var rm = _state.GetRoom(r); rm.LedManual = false; rm.DamperManual = false; }
modeChanged = true;
}
else result = 1;
break;
case CtrlFrame.CTRL_RUNMODE:
if (pl.Length >= 1)
{
if (pl[0] == 0) _state.PowerOn = false;
else
{
_state.PowerOn = true;
RunMode m = pl[0] switch { 1 => RunMode.Ventilation, 2 => RunMode.Auto, 3 => RunMode.AirClean, 4 => RunMode.Bypass, _ => RunMode.Ventilation };
_state.RunMode = _state.SetRunMode = m;
// 운전모드 전환 시 풍량 1단 (자동은 부하점수로 결정하므로 제외)
if (m != RunMode.Auto) _state.FanMode = _state.SetFanMode = 1;
}
// 모드 전환 시 수동 댐퍼만 해제 → 새 모드는 기본(전실 개방)에서 시작.
// 수동 LED 디밍값은 모드가 바뀌어도 유지(사용자 요청, 전원 OFF 시에만 해제).
for (int r = 1; r <= 4; r++) _state.GetRoom(r).DamperManual = false;
modeChanged = true;
}
else result = 1;
break;
case CtrlFrame.CTRL_FAN:
if (pl.Length >= 1)
{
// 모드별 풍량 상한 : 바이패스 1단, 그 외 4단 (자동은 부하점수로 결정)
byte sp = pl[0];
byte max = _state.RunMode == RunMode.Bypass ? (byte)1 : (byte)4;
if (sp > max) sp = max;
_state.FanMode = _state.SetFanMode = sp; modeChanged = true;
}
else result = 1;
break;
case CtrlFrame.CTRL_SUBMODE: // [type][on] 1수면 2조리 3회복
if (pl.Length >= 2)
{
if (pl[0] == 1) _state.ExtRunMode = (byte)(pl[1] != 0 ? 4 : 0);
else if (pl[0] == 2) _state.HoodEnable = pl[1] != 0;
else if (pl[0] == 3) _state.ExtRunMode = (byte)(pl[1] != 0 ? 1 : 0);
else result = 1;
}
else result = 1;
break;
case CtrlFrame.CTRL_HOOD:
if (pl.Length >= 1) _state.HoodEnable = pl[0] != 0; else result = 1;
break;
case CtrlFrame.CTRL_HYST_PRESET:
if (pl.Length >= 1 && pl[0] < 3) _state.HystPreset = pl[0]; else result = 1;
break;
case CtrlFrame.CTRL_HYST_VALUE: // [preset][pm25][pm10][voc][co2] u16 BE
if (pl.Length >= 9 && pl[0] < 3)
{
int ps = pl[0];
_state.Pm25Db[ps] = (ushort)((pl[1] << 8) | pl[2]);
_state.Pm10Db[ps] = (ushort)((pl[3] << 8) | pl[4]);
_state.VocDb[ps] = (ushort)((pl[5] << 8) | pl[6]);
_state.Co2Db[ps] = (ushort)((pl[7] << 8) | pl[8]);
}
else result = 1;
break;
case CtrlFrame.CTRL_DAMPER: // [room][onoff] — 수동 댐퍼 : 비자동(환기/공청/바이패스)에서 위치 유지
if (pl.Length >= 2 && pl[0] >= 1 && pl[0] <= 4)
{
var rm = _state.GetRoom(pl[0]);
int ang = pl[1] != 0 ? 110 : 0;
rm.MemorySA = rm.CurrentSA = ang;
rm.MemoryRA = rm.CurrentRA = ang;
rm.DamperManual = true; // 자동로직이 덮어쓰지 않도록 (자동/모드전환 시 해제)
}
else result = 1;
break;
case CtrlFrame.CTRL_LED: // [room][dim] — 수동 조작 : 자동 추종 해제하고 지정값 유지
if (pl.Length >= 2 && pl[0] >= 1 && pl[0] <= 4)
{
var rm = _state.GetRoom(pl[0]);
rm.LightBright = pl[1];
rm.LedManual = true;
}
else result = 1;
break;
case CtrlFrame.CTRL_RESERVE: // [hours 0~8] : N시간 후 전원 OFF (0=해제)
if (pl.Length >= 1 && pl[0] <= 8)
{
int h = pl[0];
_state.ReserveHours = h;
_state.ReserveRemainSec = h * 3600; // 0이면 해제. 카운트다운/전원OFF는 ReserveTick(1s)이 처리
}
else result = 1;
break;
case CtrlFrame.REQ_STATUS:
break;
case CtrlFrame.CTRL_RESET:
if (pl.Length >= 1) _state.ResetState = (byte)(pl[0] != 0 ? 1 : 0); else result = 1;
break;
case CtrlFrame.CTRL_VSP: // [group][index][sa(2)][ea(2)]
if (pl.Length >= 6) result = SetVsp(pl[0], pl[1], (pl[2] << 8) | pl[3], (pl[4] << 8) | pl[5]); else result = 1;
break;
case CtrlFrame.CTRL_HYST_THR: // [preset][pollutant][L1~L4 u16] : 오염단계 임계 설정
if (pl.Length >= 10 && pl[0] < 3 && pl[1] < 4)
{
int ps = pl[0], g = pl[1];
ushort[] arr = g switch { 0 => _state.Co2Thr[ps], 1 => _state.Pm25Thr[ps], 2 => _state.Pm10Thr[ps], 3 => _state.VocThr[ps], _ => null! };
if (arr != null) for (int k = 0; k < 4; k++) arr[k] = (ushort)((pl[2 + k * 2] << 8) | pl[3 + k * 2]);
else result = 1;
}
else result = 1;
break;
default: result = 1; break;
}
PacketReceived?.Invoke($"HomeNet RX CMD=0x{cmd:X2} len={pl.Length} → {(result == 0 ? "OK" : "ERR")}");
if (modeChanged) _seq.NotifyCommandChanged();
var ack = StatusEncoder.BuildAckFrame(cmd, result);
_ch.Send(ack, ack.Length);
if (cmd == CtrlFrame.REQ_STATUS) SendStatus();
}
byte SetVsp(int grp, int idx, int sa, int ea)
{
if (grp == 0 && idx >= 1 && idx <= 4) { _state.FanSAPreset_Vent[idx] = (ushort)sa; _state.FanEAPreset_Vent[idx] = (ushort)ea; }
else if (grp == 1 && idx == 1) { _state.FanSAPreset_Bypass[1] = (ushort)sa; _state.FanEAPreset_Bypass[1] = (ushort)ea; }
else if (grp == 2 && idx >= 1 && idx <= 4) { _state.FanSAPreset_Air[idx] = (ushort)sa; _state.FanEAPreset_Air[idx] = (ushort)ea; }
else return 1;
return 0;
}
}
}
@@ -0,0 +1,143 @@
using System;
using System.Windows.Threading;
using ERVSimulator.Model;
using RunMode = ERVSimulator.Model.RunMode;
namespace ERVSimulator.Protocol
{
// 후드 버스 마스터 (115200) <-> 후드메인(슬레이브)
// 규격 : Protocol/HOOD/주신전자_protocol_hood_전열교환기_Rev1.3_20241125.xlsx
// - 9바이트 고정, 폴링주기 100~500ms, 응답 50ms 이내, CS = Preamble~CS직전 전체 XOR
// 목적 : ERV(Master) 가 후드메인(Slave) 을 폴 → 후드 FAN/LIGHT/연동CMD 수신 → ErvState 반영
// 마스터 폴(9B) : Preamble | M/S(0x21) | ID | MODE | FAN | 연동EN | 연동운전중 | ERROR | CS
// 슬레이브 응답(9B) : Preamble | M/S(0x11) | ID | FAN STATUS | LIGHT STATUS | 0x00 | 연동CMD | ERROR | CS
public class HoodMasterProtocol
{
const byte PREAMBLE = 0xAA;
const byte MS_MASTER = 0x21;
const byte MS_SLAVE = 0x11;
const byte HOOD_ID = 0x01;
const int FRAME_LEN = 9;
readonly SerialChannel _ch;
readonly ErvState _state;
readonly Dispatcher _dispatcher;
readonly DispatcherTimer _pollTimer;
readonly byte[] _rx = new byte[FRAME_LEN];
int _rxPos;
DateTime _lastByte = DateTime.MinValue;
static readonly TimeSpan FrameGap = TimeSpan.FromMilliseconds(40);
public event Action<string>? PacketReceived;
public event Action<string>? PacketSent;
public bool Verbose { get; set; } = false; // true면 모든 폴 로그
// 후드 통신 생존 표시용 — 마지막으로 유효한 응답을 받은 시각(UTC)
public DateTime LastRxUtc { get; private set; } = DateTime.MinValue;
// 폴(200ms) 기준 이 시간 내 응답이 없으면 미연결로 판정 (몇 회 누락 허용)
static readonly TimeSpan ConnTimeout = TimeSpan.FromMilliseconds(1000);
public HoodMasterProtocol(SerialChannel ch, ErvState state, Dispatcher dispatcher)
{
_ch = ch; _state = state; _dispatcher = dispatcher;
_ch.ByteReceived += OnByte;
// 폴링주기 200ms (사양 100~500ms 범위 내)
_pollTimer = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromMilliseconds(200) };
_pollTimer.Tick += (_, _) =>
{
if (_ch.IsConnected) Poll();
// 폴 주기마다 통신 생존 갱신 : 채널 연결 && 최근 응답 수신 → 연결됨
_state.HoodConnected = _ch.IsConnected && (DateTime.UtcNow - LastRxUtc) < ConnTimeout;
};
_pollTimer.Start();
}
// MODE : 전원 OFF시 0, ON시 1 환기 / 2 자동 / 3 공청 / 4 바이패스 / 5 기타
byte HoodMode()
{
if (!_state.PowerOn) return 0;
return _state.RunMode switch
{
RunMode.Ventilation => 1,
RunMode.Auto => 2,
RunMode.AirClean => 3,
RunMode.Bypass => 4,
RunMode.Off => 0,
_ => 5,
};
}
void Poll()
{
var p = new byte[FRAME_LEN];
p[0] = PREAMBLE;
p[1] = MS_MASTER;
p[2] = HOOD_ID;
p[3] = HoodMode();
p[4] = _state.FanMode; // 전열교환기 FAN 0 OFF, 1~5단
p[5] = (byte)(_state.HoodEnable ? 0x01 : 0x00); // 연동 Enable/Disable
p[6] = (byte)(_state.HoodStatus ? 0x01 : 0x00); // 연동 운전중(후드 연동에 의한 환기장치 동작중)
p[7] = 0x00; // ERROR
p[8] = ChecksumHelper.Xor(p, 0, 8); // CS = Preamble~CS직전 XOR
_ch.Send(p, FRAME_LEN);
if (Verbose)
PacketSent?.Invoke($"Hood TX poll MODE={p[3]} FAN={p[4]} EN={p[5]} 연동운전={p[6]}");
}
void OnByte(byte b)
{
var now = DateTime.UtcNow;
if (now - _lastByte > FrameGap) _rxPos = 0;
_lastByte = now;
if (_rxPos == 0)
{
if (b == PREAMBLE) { _rx[0] = b; _rxPos = 1; }
}
else if (_rxPos == 1)
{
if (b == MS_SLAVE) { _rx[1] = b; _rxPos = 2; }
else _rxPos = (b == PREAMBLE) ? 1 : 0;
}
else
{
_rx[_rxPos++] = b;
if (_rxPos >= FRAME_LEN)
{
var copy = (byte[])_rx.Clone();
_dispatcher.BeginInvoke(new Action(() => HandleResponse(copy)));
_rxPos = 0;
}
}
}
void HandleResponse(byte[] p)
{
byte cs = ChecksumHelper.Xor(p, 0, 8);
if (cs != p[8])
{
PacketReceived?.Invoke($"Hood RX CS오류 {HexFormat.Bytes(p, FRAME_LEN)}");
return;
}
if (p[2] != HOOD_ID) return;
LastRxUtc = DateTime.UtcNow; // 유효 응답 수신 → 통신 생존
_state.HoodConnected = true; // 응답 받았으므로 즉시 연결 표시
int fan = p[3]; // 후드 FAN STATUS : 0 OFF, 1~5단
bool light = p[4] != 0; // 후드 LIGHT STATUS : 0 OFF, 1 ON
bool cmd = p[6] != 0; // 연동 CMD : 0 후드 꺼짐 / 1 후드 켜짐
int err = p[7];
bool changed = _state.HoodFan != fan || _state.HoodLight != light || _state.HoodCmd != cmd || _state.HoodError != err;
_state.HoodFan = fan;
_state.HoodLight = light;
_state.HoodCmd = cmd;
_state.HoodError = err;
// 연동운전중(HoodStatus)은 AutoLogic 이 메이크업 에어 상태(롤백 유지 포함)로 소유.
if (changed || Verbose)
PacketReceived?.Invoke($"Hood RX FAN={fan} LIGHT={(light ? "ON" : "OFF")} 연동CMD={(cmd ? "ON" : "OFF")}{(err != 0 ? $" ERR={err}" : "")}");
}
}
}
@@ -0,0 +1,214 @@
using System;
using ERVSimulator.Model;
namespace ERVSimulator.Protocol
{
// 룸콘 프로토콜 (UART2/SC0)
// 패킷: AA | Cmd | D[2..12] | XOR_SUM[13] | EE (15 byte)
// 펌웨어 [My_RJ2.c] rx_roomcon_check() + roomcon_parsing()
public class RoomConProtocol
{
public const byte HEADER = 0xAA;
public const byte TAIL = 0xEE;
public const int PACKET_LEN = 15;
// Cmd (Rx_roomcon232_buffer[1])
public const byte CMD_NORMAL = 0x00; // 상태 폴링
public const byte CMD_EVENT = 0x01; // 모드/팬 변경 이벤트
public const byte CMD_RESTART1 = 0x02; // 환기단 preset 요청
public const byte CMD_RESTART2 = 0x12; // bypass/air preset 요청
public const byte CMD_VSP = 0x03; // 테스트모드 진입
public const byte CMD_EXIT = 0x04; // 테스트모드 종료
public const byte CMD_HOOD_INFO = 0x0A; // ERV→룸콘 후드 연동 통지 (힘펠 V3.7 RX_DATA_HOOD_INFO)
readonly SerialChannel _ch;
readonly ErvState _state;
readonly DamperSequencer _seq;
readonly System.Windows.Threading.Dispatcher _dispatcher;
readonly byte[] _rx = new byte[PACKET_LEN];
int _rxPos;
bool _hoodLinkReported; // 마지막으로 룸콘에 통지한 후드 연동 상태(변화 시에만 0x0A 송신)
DateTime _lastByte = DateTime.MinValue;
static readonly TimeSpan FrameGap = TimeSpan.FromMilliseconds(50);
public event Action<string>? PacketReceived;
public event Action<string>? PacketSent;
public RoomConProtocol(SerialChannel ch, ErvState state, DamperSequencer seq,
System.Windows.Threading.Dispatcher dispatcher)
{
_ch = ch; _state = state; _seq = seq; _dispatcher = dispatcher;
_ch.ByteReceived += OnByte;
}
void OnByte(byte b)
{
var now = DateTime.UtcNow;
if (now - _lastByte > FrameGap) _rxPos = 0;
_lastByte = now;
// 펌웨어와 동일한 byte 파서 (My_RJ2.c:37)
if (_rxPos == 0)
{
if (b != HEADER) return;
_rx[_rxPos++] = b;
return;
}
if (_rxPos >= 1 && _rxPos <= 12)
{
_rx[_rxPos++] = b;
return;
}
if (_rxPos == 13)
{
byte cksum = ChecksumHelper.Xor(_rx, 0, 13);
if (cksum != b) { _rxPos = 0; return; }
_rx[_rxPos++] = b;
return;
}
if (_rxPos == 14)
{
_rxPos = 0;
if (b != TAIL) return;
byte[] copy = (byte[])_rx.Clone();
_dispatcher.BeginInvoke(new Action(() => HandlePacket(copy)));
}
}
void HandlePacket(byte[] p)
{
PacketReceived?.Invoke($"RoomCon RX: {HexFormat.Bytes(p, 14)} EE");
byte cmd = p[1];
switch (cmd)
{
case CMD_EVENT: HandleEvent(p); break;
case CMD_NORMAL: HandleNormal(p); break;
case CMD_RESTART1: HandleRestart1(); break;
case CMD_RESTART2: HandleRestart2(); break;
case CMD_VSP: HandleVsp(p); break;
case CMD_EXIT: HandleExit(); break;
default:
PacketReceived?.Invoke($" (unknown RoomCon cmd 0x{cmd:X2})");
break;
}
}
// [My_RJ2.c:387] RX_DATA_MODE_EVENT - 운전 모드/팬 변경
void HandleEvent(byte[] p)
{
byte runMode = p[2];
byte fanMode = p[3];
_state.RunMode = (RunMode)runMode;
_state.SetRunMode = (RunMode)runMode;
_state.FanMode = fanMode;
_state.SetFanMode = fanMode;
// VENT && fan=0 ⇒ Power OFF 진입
_state.PowerOn = !(runMode == 0 && fanMode == 0);
// 예약 (룸콘 EVENT [10]=flag / [11]=시 / [12]=분). HOMENET STATUS(reserve)로도 전달 → 대시보드 반영
if (p[10] == 1)
{
int hours = p[11];
_state.ReserveHours = hours; // 0이면 해제
_state.ReserveRemainSec = hours * 3600 + p[12] * 60; // 카운트다운/전원OFF는 ReserveTick(1s) 처리
}
_seq.NotifyCommandChanged();
// 응답: AA 01 RunMode FanMode 00 misc... XOR EE (펌웨어 [My_RJ2.c:489])
var tx = NewPacket();
tx[1] = 0x01;
tx[2] = runMode;
tx[3] = fanMode;
tx[5] = 0; // Heater/UV/Kijer
tx[7] = _state.ErrorCode; // ErrorCode (E02/E07/E09/E10/COLD 비트맵)
tx[8] = 0; // Out_Temperature sign
tx[9] = 20 + 25; // Out_Temperature = 25
tx[10] = 20 + 22; // In_Temperature = 22
FinalizeAndSend(tx);
}
// [My_RJ2.c:327] RX_DATA_MODE_NORMAL - 상태 폴링 응답
void HandleNormal(byte[] p)
{
// 후드 연동 상태가 바뀌면 HOOD_INFO(0x0A)로 통지 (힘펠 V3.7, 펌웨어 Hood_info_command).
// HoodStatus = 연동운전중(후드 가동 → 메이크업 에어). 후드 OFF로 ERV 복귀 시 0x80(OFF) 전송.
if (_state.HoodStatus != _hoodLinkReported)
{
_hoodLinkReported = _state.HoodStatus;
var hi = NewPacket();
hi[1] = CMD_HOOD_INFO;
hi[2] = _state.HoodStatus ? (byte)RunMode.Ventilation : (byte)_state.SetRunMode; // 연동 시 환기
hi[3] = _state.HoodStatus ? (byte)1 : _state.SetFanMode;
hi[6] = _state.HoodStatus ? (byte)0x81 : (byte)0x80; // 후드 연동 ON / OFF
FinalizeAndSend(hi);
return;
}
var tx = NewPacket();
tx[1] = 0x07; // COMMAND_CONTROLL
tx[2] = (byte)_state.SetRunMode;
tx[3] = _state.SetFanMode;
tx[4] = 0; // Auto_Mode
tx[5] = 0;
tx[7] = _state.ErrorCode; // ErrorCode 도 동봉
FinalizeAndSend(tx);
}
// [My_RJ2.c:522] RX_DATA_MODE_RESTART1 - 환기 1~4단 preset
void HandleRestart1()
{
var tx = NewPacket();
tx[1] = 0x02;
tx[4] = 0x10;
tx[5] = (byte)_state.FanSAPreset_Vent[1]; tx[6] = (byte)_state.FanEAPreset_Vent[1];
tx[7] = (byte)_state.FanSAPreset_Vent[2]; tx[8] = (byte)_state.FanEAPreset_Vent[2];
tx[9] = (byte)_state.FanSAPreset_Vent[3]; tx[10] = (byte)_state.FanEAPreset_Vent[3];
tx[11] = (byte)_state.FanSAPreset_Vent[4]; tx[12] = (byte)_state.FanEAPreset_Vent[4];
FinalizeAndSend(tx);
}
// [My_RJ2.c:556] RX_DATA_MODE_RESTART2 - bypass/air preset
void HandleRestart2()
{
var tx = NewPacket();
tx[1] = 0x12;
tx[4] = 0x10;
tx[5] = (byte)_state.FanSAPreset_Bypass[1]; tx[6] = (byte)_state.FanEAPreset_Bypass[1];
tx[7] = (byte)_state.FanSAPreset_Air[1];
tx[8] = (byte)_state.FanSAPreset_Air[2];
tx[9] = (byte)_state.FanSAPreset_Air[3];
tx[10] = (byte)_state.FanSAPreset_Air[4];
FinalizeAndSend(tx);
}
// [My_RJ2.c:579] RX_DATA_MODE_VSP - 테스트 모드 진입 (preset 갱신)
void HandleVsp(byte[] p)
{
// 본 시뮬레이터에선 RX만 기록, preset 변경은 생략
PacketReceived?.Invoke($" VSP select={p[3]} sa={p[4]} ea={p[5]}");
}
void HandleExit()
{
PacketReceived?.Invoke(" VSP exit");
}
byte[] NewPacket()
{
var tx = new byte[PACKET_LEN];
tx[0] = HEADER;
return tx;
}
void FinalizeAndSend(byte[] tx)
{
tx[13] = ChecksumHelper.Xor(tx, 0, 13);
tx[14] = TAIL;
if (_ch.Send(tx, PACKET_LEN))
PacketSent?.Invoke($"RoomCon TX: {HexFormat.Bytes(tx, 15)}");
}
}
}
@@ -0,0 +1,116 @@
using System;
using System.IO.Ports;
using System.Threading;
using System.Threading.Tasks;
namespace ERVSimulator.Protocol
{
// 공용 시리얼 채널 - byte 단위 수신 콜백 + 송신 helper
public class SerialChannel : IDisposable
{
private SerialPort? _port;
private CancellationTokenSource? _cts;
private bool _disposed;
public string ChannelName { get; }
public event Action<byte>? ByteReceived;
public event Action<string>? Log;
public event Action<bool>? ConnectionChanged;
public bool IsConnected => _port?.IsOpen == true;
public SerialChannel(string channelName) { ChannelName = channelName; }
public static string[] GetAvailablePorts() => SerialPort.GetPortNames();
public bool Connect(string portName, int baudRate)
{
try
{
Disconnect();
_port = new SerialPort(portName, baudRate, Parity.None, 8, StopBits.One)
{
ReadTimeout = 100,
WriteTimeout = 200,
Handshake = Handshake.None,
DtrEnable = false,
RtsEnable = false,
};
_port.Open();
_cts = new CancellationTokenSource();
_ = Task.Run(() => ReadLoop(_cts.Token));
Log?.Invoke($"[{ChannelName}] Connected {portName} @ {baudRate}");
ConnectionChanged?.Invoke(true);
return true;
}
catch (Exception ex)
{
Log?.Invoke($"[{ChannelName}] Connect FAIL: {ex.Message}");
return false;
}
}
public void Disconnect()
{
try { _cts?.Cancel(); } catch { }
try { _port?.Close(); } catch { }
_port?.Dispose();
_port = null;
ConnectionChanged?.Invoke(false);
}
void ReadLoop(CancellationToken ct)
{
var buf = new byte[64];
while (!ct.IsCancellationRequested && _port != null && _port.IsOpen)
{
try
{
int n = _port.Read(buf, 0, buf.Length);
for (int i = 0; i < n; i++) ByteReceived?.Invoke(buf[i]);
}
catch (TimeoutException) { /* expected */ }
catch (Exception ex)
{
Log?.Invoke($"[{ChannelName}] ReadLoop error: {ex.Message}");
break;
}
}
}
public bool Send(byte[] data, int length)
{
if (_port == null || !_port.IsOpen) return false;
try
{
_port.Write(data, 0, length);
return true;
}
catch (Exception ex)
{
Log?.Invoke($"[{ChannelName}] Send FAIL: {ex.Message}");
return false;
}
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
Disconnect();
}
}
public static class HexFormat
{
public static string Bytes(byte[] data, int length)
{
var sb = new System.Text.StringBuilder(length * 3);
for (int i = 0; i < length; i++)
{
if (i > 0) sb.Append(' ');
sb.Append(data[i].ToString("X2"));
}
return sb.ToString();
}
}
}
@@ -0,0 +1,44 @@
<Window x:Class="ERVSimulator.VspWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="풍량 VSP 설정" SizeToContent="WidthAndHeight"
ResizeMode="NoResize" WindowStartupLocation="CenterOwner"
Background="{StaticResource PrimaryBgBrush}">
<Border Style="{StaticResource SectionCard}" Margin="10">
<StackPanel>
<TextBlock Text="풍량 VSP 설정 (SA 급기 / EA 배기) — 수정 가능" Style="{StaticResource SectionTitle}"/>
<ItemsControl x:Name="VspItems" Width="990">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate><UniformGrid Columns="3"/></ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Background="{StaticResource CardBgBrush}" CornerRadius="8" Margin="3" Padding="10,8"
BorderBrush="{StaticResource BorderBrush}" BorderThickness="1">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" Width="60" FontSize="13" FontWeight="SemiBold"
Foreground="{StaticResource TextPrimaryBrush}" VerticalAlignment="Center"/>
<TextBlock Text="SA" Margin="0,0,4,0" FontSize="11" Foreground="{StaticResource AccentBlueBrush}" VerticalAlignment="Center"/>
<TextBox Text="{Binding Sa, UpdateSourceTrigger=PropertyChanged}" Width="80" Margin="0,0,10,0" Padding="4,3"
TextAlignment="Right" FontSize="12"
Background="{StaticResource PrimaryBgBrush}" Foreground="{StaticResource TextPrimaryBrush}"
BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
<TextBlock Text="EA" Margin="0,0,4,0" FontSize="11" Foreground="{StaticResource AccentGreenBrush}" VerticalAlignment="Center"/>
<TextBox Text="{Binding Ea, UpdateSourceTrigger=PropertyChanged}" Width="80" Padding="4,3"
TextAlignment="Right" FontSize="12"
Background="{StaticResource PrimaryBgBrush}" Foreground="{StaticResource TextPrimaryBrush}"
BorderBrush="{StaticResource BorderBrush}" BorderThickness="1"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Orientation="Horizontal" Margin="0,12,0,0" HorizontalAlignment="Right">
<Button Content="VSP 적용" Width="100" Style="{StaticResource ModernButton}" Click="Apply_Click"
Margin="0,0,6,0" Background="{StaticResource AccentBlueBrush}"/>
<Button Content="닫기" Width="90" Style="{StaticResource ModernButton}" Click="Close_Click"
Background="{StaticResource CardBgBrush}"/>
</StackPanel>
</StackPanel>
</Border>
</Window>
@@ -0,0 +1,60 @@
using System;
using System.Collections.ObjectModel;
using System.Windows;
using ERVSimulator.Model;
namespace ERVSimulator
{
// 편집 가능한 풍량 VSP 행 (환기1~4, 바이패스, 공청1~4)
public class VspEditRow
{
public string Name { get; set; }
public int Sa { get; set; }
public int Ea { get; set; }
public VspEditRow(string n, int sa, int ea) { Name = n; Sa = sa; Ea = ea; }
}
public partial class VspWindow : Window
{
readonly ErvState _state;
public ObservableCollection<VspEditRow> Rows { get; } = new();
public event Action<string>? Applied;
public VspWindow(ErvState state)
{
InitializeComponent();
_state = state;
Rows.Add(new VspEditRow("환기1", state.FanSAPreset_Vent[1], state.FanEAPreset_Vent[1]));
Rows.Add(new VspEditRow("환기2", state.FanSAPreset_Vent[2], state.FanEAPreset_Vent[2]));
Rows.Add(new VspEditRow("환기3", state.FanSAPreset_Vent[3], state.FanEAPreset_Vent[3]));
Rows.Add(new VspEditRow("환기4", state.FanSAPreset_Vent[4], state.FanEAPreset_Vent[4]));
Rows.Add(new VspEditRow("바이패스", state.FanSAPreset_Bypass[1], state.FanEAPreset_Bypass[1]));
Rows.Add(new VspEditRow("공청1", state.FanSAPreset_Air[1], state.FanEAPreset_Air[1]));
Rows.Add(new VspEditRow("공청2", state.FanSAPreset_Air[2], state.FanEAPreset_Air[2]));
Rows.Add(new VspEditRow("공청3", state.FanSAPreset_Air[3], state.FanEAPreset_Air[3]));
Rows.Add(new VspEditRow("공청4", state.FanSAPreset_Air[4], state.FanEAPreset_Air[4]));
VspItems.ItemsSource = Rows;
}
static ushort Clamp(int v) => (ushort)(v < 0 ? 0 : v > 255 ? 255 : v); // VSP 1바이트
void Apply_Click(object sender, RoutedEventArgs e)
{
_state.FanSAPreset_Vent[1] = Clamp(Rows[0].Sa); _state.FanEAPreset_Vent[1] = Clamp(Rows[0].Ea);
_state.FanSAPreset_Vent[2] = Clamp(Rows[1].Sa); _state.FanEAPreset_Vent[2] = Clamp(Rows[1].Ea);
_state.FanSAPreset_Vent[3] = Clamp(Rows[2].Sa); _state.FanEAPreset_Vent[3] = Clamp(Rows[2].Ea);
_state.FanSAPreset_Vent[4] = Clamp(Rows[3].Sa); _state.FanEAPreset_Vent[4] = Clamp(Rows[3].Ea);
_state.FanSAPreset_Bypass[1] = Clamp(Rows[4].Sa); _state.FanEAPreset_Bypass[1] = Clamp(Rows[4].Ea);
_state.FanSAPreset_Air[1] = Clamp(Rows[5].Sa); _state.FanEAPreset_Air[1] = Clamp(Rows[5].Ea);
_state.FanSAPreset_Air[2] = Clamp(Rows[6].Sa); _state.FanEAPreset_Air[2] = Clamp(Rows[6].Ea);
_state.FanSAPreset_Air[3] = Clamp(Rows[7].Sa); _state.FanEAPreset_Air[3] = Clamp(Rows[7].Ea);
_state.FanSAPreset_Air[4] = Clamp(Rows[8].Sa); _state.FanEAPreset_Air[4] = Clamp(Rows[8].Ea);
Applied?.Invoke("[Manual] 풍량 VSP 값 적용");
}
void Close_Click(object sender, RoutedEventArgs e) => Close();
}
}