Browse Source

[feat] 报警联动视频

master
fajiao 2 years ago
parent
commit
7e80994591
  1. 92
      EC.Util/CameraSDK/HiK/HiKOriSDK.cs
  2. 35
      EC.Util/CameraSDK/HiK/HiKSDK.cs
  3. 23
      EC.Util/EC.Util.csproj
  4. BIN
      EC.Util/libs/hik-win64/AudioRender.dll
  5. BIN
      EC.Util/libs/hik-win64/HXVA.dll
  6. BIN
      EC.Util/libs/hik-win64/HmMerge.dll
  7. BIN
      EC.Util/libs/hik-win64/PlayCtrl.dll
  8. BIN
      EC.Util/libs/hik-win64/SuperRender.dll
  9. 2
      JiLinApp.Biz/TransmitAlarm/Common/Config.cs
  10. 4
      JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs
  11. 5
      JiLinApp.Docking/Ptz/PtzCmd.cs
  12. 37
      JiLinApp.Docking/Ptz/PtzConfig.cs
  13. 5
      JiLinApp.sln
  14. 10
      JiLinApp/Components/HikRealPlay.xaml
  15. 88
      JiLinApp/Components/HikRealPlay.xaml.cs
  16. 5
      JiLinApp/Core/Config.cs
  17. 3
      JiLinApp/Core/Global.cs
  18. 3
      JiLinApp/Pages/FenceServerManage/Main.xaml.cs
  19. 7
      JiLinApp/Pages/PtzManage/Main.xaml
  20. 70
      JiLinApp/Pages/PtzManage/Main.xaml.cs
  21. 9
      JiLinApp/Pages/PtzManage/MainViewModel.cs
  22. 40
      JiLinApp/config/config.json

92
EC.Util/CameraSDK/HiK/HiKOriSDK.cs

@ -188,6 +188,46 @@ public static class HiKOriSDK
public ushort wZoomPosMax; //变倍参数max public ushort wZoomPosMax; //变倍参数max
} }
//邦诺CVR
public const int MAX_ID_COUNT = 256;
public const int MAX_STREAM_ID_COUNT = 1024;
public const int STREAM_ID_LEN = 32;
public const int PLAN_ID_LEN = 32;
//预览V40接口
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_PREVIEWINFO
{
public Int32 lChannel; //通道号
public uint dwStreamType; // 码流类型,0-主码流,1-子码流,2-码流3,3-码流4 等以此类推
public uint dwLinkMode; // 0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-RTP/RTSP,5-RSTP/HTTP
public IntPtr hPlayWnd; //播放窗口的句柄,为NULL表示不播放图象
public bool bBlocked; //0-非阻塞取流, 1-阻塞取流, 如果阻塞SDK内部connect失败将会有5s的超时才能够返回,不适合于轮询取流操作.
public bool bPassbackRecord; //0-不启用录像回传,1启用录像回传
public byte byPreviewMode; //预览模式,0-正常预览,1-延迟预览
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = STREAM_ID_LEN,
ArraySubType = UnmanagedType.I1
)]
public byte[] byStreamID; //流ID,lChannel为0xffffffff时启用此参数
public byte byProtoType; //应用层取流协议,0-私有协议,1-RTSP协议
public byte byRes1;
public byte byVideoCodingType; //码流数据编解码类型 0-通用编码数据 1-热成像探测器产生的原始数据(温度数据的加密信息,通过去加密运算,将原始数据算出真实的温度值)
public uint dwDisplayBufNum; //播放库播放缓冲区最大缓冲帧数,范围1-50,置0时默认为1
public byte byNPQMode; //NPQ是直连模式,还是过流媒体 0-直连 1-过流媒体
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = 215,
ArraySubType = UnmanagedType.I1
)]
public byte[] byRes;
}
#endregion SDK Struct #endregion SDK Struct
#region Common Method #region Common Method
@ -241,5 +281,57 @@ public static class HiKOriSDK
uint dwPresetIndex uint dwPresetIndex
); );
/*********************************************************
Function: REALDATACALLBACK
Desc:
Input: lRealHandle
dwDataType
pBuffer
dwBufSize
pUser
Output:
Return: void
**********************************************************/
public delegate void REALDATACALLBACK(
Int32 lRealHandle,
UInt32 dwDataType,
IntPtr pBuffer,
UInt32 dwBufSize,
IntPtr pUser
);
/*********************************************************
Function: NET_DVR_RealPlay_V40
Desc:
Input: lUserID [in] NET_DVR_Login()NET_DVR_Login_V30()
lpPreviewInfo [in]
fRealDataCallBack_V30 [in]
pUser [in]
Output:
Return: 1NET_DVR_StopRealPlay等函数的句柄参数
**********************************************************/
[DllImport(LibHcNetSDK)]
public static extern int NET_DVR_RealPlay_V40(
int iUserID,
ref NET_DVR_PREVIEWINFO lpPreviewInfo,
REALDATACALLBACK fRealDataCallBack_V30,
IntPtr pUser
);
// [DllImport(@".\HCNetSDK.dll")]
// public static extern int NET_DVR_GetRealPlayerIndex(int lRealHandle);
/*********************************************************
Function: NET_DVR_StopRealPlay
Desc:
Input: lRealHandle [in] NET_DVR_RealPlay或者NET_DVR_RealPlay_V30的返回值
Output:
Return:
**********************************************************/
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_StopRealPlay(int iRealHandle);
#endregion Common Method #endregion Common Method
} }

35
EC.Util/CameraSDK/HiK/HiKSDK.cs

@ -8,6 +8,8 @@ public class HiKSDK : ICameraSDK
private int LoginId { get; set; } = -1; private int LoginId { get; set; } = -1;
private int realplayHandle { get; set; } = -1;
#endregion Attr #endregion Attr
public HiKSDK(CameraInfo cameraInfo) : base(cameraInfo) public HiKSDK(CameraInfo cameraInfo) : base(cameraInfo)
@ -140,4 +142,37 @@ public class HiKSDK : ICameraSDK
} }
#endregion Ptz Method #endregion Ptz Method
#region Video Method
public void StartPlay(IntPtr hwnd)
{
bool ret = ConnectSuccess();
if (!ret) return;
HiKOriSDK.NET_DVR_PREVIEWINFO previewInfo = new()
{
hPlayWnd = hwnd, //预览窗口
lChannel = 1, //预览的设备通道
dwStreamType = 0, //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推
dwLinkMode = 0, //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP
bBlocked = true, //0- 非阻塞取流,1- 阻塞取流
dwDisplayBufNum = 1, //播放库播放缓冲区最大缓冲帧数
byProtoType = 0,
byPreviewMode = 0
};
IntPtr pUser = new(); //用户数据
realplayHandle = HiKOriSDK.NET_DVR_RealPlay_V40(LoginId, ref previewInfo, null, pUser);
if (realplayHandle < 0) BuildException();
}
public void StopPlay()
{
if (realplayHandle >= 0)
{
HiKOriSDK.NET_DVR_StopRealPlay(realplayHandle);
realplayHandle = -1;
}
}
#endregion Video Method
} }

23
EC.Util/EC.Util.csproj

@ -7,15 +7,29 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="libs\hik-win64\AudioRender.dll" />
<None Remove="libs\hik-win64\HCCore.dll" /> <None Remove="libs\hik-win64\HCCore.dll" />
<None Remove="libs\hik-win64\HCNetSDK.dll" /> <None Remove="libs\hik-win64\HCNetSDK.dll" />
<None Remove="libs\hik-win64\HCNetSDKCom\HCCoreDevCfg.dll" /> <None Remove="libs\hik-win64\HCNetSDKCom\HCCoreDevCfg.dll" />
<None Remove="libs\hik-win64\HCNetSDKCom\HCPreview.dll" /> <None Remove="libs\hik-win64\HCNetSDKCom\HCPreview.dll" />
<None Remove="libs\hik-win64\HmMerge.dll" />
<None Remove="libs\hik-win64\HXVA.dll" />
<None Remove="libs\hik-win64\libcrypto-1_1-x64.dll" /> <None Remove="libs\hik-win64\libcrypto-1_1-x64.dll" />
<None Remove="libs\hik-win64\libssl-1_1-x64.dll" /> <None Remove="libs\hik-win64\libssl-1_1-x64.dll" />
<None Remove="libs\hik-win64\PlayCtrl.dll" />
<None Remove="libs\hik-win64\SuperRender.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="libs\hik-win64\HXVA.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="libs\hik-win64\AudioRender.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libs\hik-win64\HCCore.dll"> <Content Include="libs\hik-win64\HCCore.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
@ -28,12 +42,21 @@
<Content Include="libs\hik-win64\HCNetSDKCom\HCPreview.dll"> <Content Include="libs\hik-win64\HCNetSDKCom\HCPreview.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="libs\hik-win64\HmMerge.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libs\hik-win64\libcrypto-1_1-x64.dll"> <Content Include="libs\hik-win64\libcrypto-1_1-x64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="libs\hik-win64\libssl-1_1-x64.dll"> <Content Include="libs\hik-win64\libssl-1_1-x64.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Content Include="libs\hik-win64\PlayCtrl.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libs\hik-win64\SuperRender.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

BIN
EC.Util/libs/hik-win64/AudioRender.dll

Binary file not shown.

BIN
EC.Util/libs/hik-win64/HXVA.dll

Binary file not shown.

BIN
EC.Util/libs/hik-win64/HmMerge.dll

Binary file not shown.

BIN
EC.Util/libs/hik-win64/PlayCtrl.dll

Binary file not shown.

BIN
EC.Util/libs/hik-win64/SuperRender.dll

Binary file not shown.

2
JiLinApp.Biz/TransmitAlarm/Common/Config.cs

@ -2,6 +2,8 @@
public class TransmitAlarmConfig public class TransmitAlarmConfig
{ {
public bool RealPlay { get; set; }
public string Type { get; set; } public string Type { get; set; }
public MqttConfig Mqtt { get; set; } public MqttConfig Mqtt { get; set; }

4
JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs

@ -104,8 +104,4 @@ public class AlarmMqttService : IAlarmService
} }
#endregion Server Event #endregion Server Event
#region
#endregion
} }

5
JiLinApp.Docking/Ptz/PtzCmd.cs

@ -1,13 +1,12 @@
using EC.Util.CameraSDK; using EC.Util.CameraSDK;
using System;
namespace JiLinApp.Docking.Ptz; namespace JiLinApp.Docking.Ptz;
public class PtzCmd public class PtzCmd
{ {
public static PtzControlType GetControlType(string ctrlStr) public static PtzControlType GetControlType(string ctrlType)
{ {
return ctrlStr switch return ctrlType switch
{ {
"PelcoD" => PtzControlType.PelcoD, "PelcoD" => PtzControlType.PelcoD,
"PelcoP" => PtzControlType.PelcoP, "PelcoP" => PtzControlType.PelcoP,

37
JiLinApp.Docking/Ptz/PtzConfig.cs

@ -0,0 +1,37 @@
namespace JiLinApp.Docking.Ptz;
public class PtzControlTypeConfig
{
public string Type { get; set; }
public string Name { get; set; }
}
public class PtzControlTypeConfigHelper
{
private static Dictionary<string, PtzControlTypeConfig> PctConfigDict { get; set; }
public static void Init(List<PtzControlTypeConfig> ptzCtrlTypes)
{
if (PctConfigDict != null) return;
Dictionary<string, PtzControlTypeConfig> dict = new();
foreach (var cfg in ptzCtrlTypes)
{
dict.Add(cfg.Name, cfg);
}
PctConfigDict ??= dict;
}
public static PtzControlType GetControlType(string ctrlName)
{
PctConfigDict.TryGetValue(ctrlName, out var cfg);
string ctrlType = cfg != null ? cfg.Type : "";
return ctrlType switch
{
"PelcoD" => PtzControlType.PelcoD,
"PelcoP" => PtzControlType.PelcoP,
"HikSdk" => PtzControlType.HikSdk,
_ => PtzControlType.None
};
}
}

5
JiLinApp.sln

@ -11,11 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiLinApp.Docking", "JiLinAp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiLinApp.Biz", "JiLinApp.Biz\JiLinApp.Biz.csproj", "{7CE63A50-C92C-4554-8E0C-F7BED355C1FD}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JiLinApp.Biz", "JiLinApp.Biz\JiLinApp.Biz.csproj", "{7CE63A50-C92C-4554-8E0C-F7BED355C1FD}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{97F952A2-D735-42D6-A21B-DCEA87C2D6C9}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU

10
JiLinApp/Components/HikRealPlay.xaml

@ -0,0 +1,10 @@
<Window x:Class="JiLinApp.Components.HikRealPlay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="HikRealPlay" Height="430" Width="640" ShowInTaskbar="False">
<Image Name="player">
</Image>
</Window>

88
JiLinApp/Components/HikRealPlay.xaml.cs

@ -0,0 +1,88 @@
using EC.Util.CameraSDK;
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace JiLinApp.Components;
/// <summary>
/// HikRealPlay.xaml 的交互逻辑
/// </summary>
public partial class HikRealPlay : Window
{
#region
private HiKSDK hikSdk { get; }
#endregion
public HikRealPlay(HiKSDK hikSdk)
{
InitializeComponent();
this.hikSdk = hikSdk;
}
~HikRealPlay()
{
StopPlay();
}
#region Base
public void StartPlay()
{
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(player)).Handle;
hikSdk.StartPlay(hwnd);
}
public void StopPlay()
{
hikSdk.StopPlay();
}
#endregion
private const int GWL_STYLE = -16;
private const int WS_MAXIMIZEBOX = 0x10000;
private const int WS_MINIMIZEBOX = 0x20000;
private const int SWP_NOSIZE = 0x0001;
private const int SWP_NOMOVE = 0x0002;
private const int SWP_NOZORDER = 0x0004;
private const int SWP_FRAMECHANGED = 0x0020;
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
private static extern int GetWindowLong32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int GetWindowLongPtr(IntPtr hwnd, int index);
[DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
private static extern int SetWindowLong32(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
private static extern int SetWindowLongPtr(IntPtr hwnd, int index, int value);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
#region Util
public void HideMinButton()
{
IntPtr hwnd = new WindowInteropHelper(this).Handle;
if (IntPtr.Size == 4)
{
var currentStyle = GetWindowLong32(hwnd, GWL_STYLE);
_ = SetWindowLong32(hwnd, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX));
}
else
{
var currentStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
_ = SetWindowLongPtr(hwnd, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX));
}
//call SetWindowPos to make sure the SetWindowLongPtr take effect according to MSDN
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
#endregion
}

5
JiLinApp/Core/Config.cs

@ -1,5 +1,6 @@
using EC.Util.CameraSDK; using EC.Util.CameraSDK;
using JiLinApp.Biz.TransmitAlarm; using JiLinApp.Biz.TransmitAlarm;
using JiLinApp.Docking.Ptz;
using System.Collections.Generic; using System.Collections.Generic;
namespace JiLinApp.Core; namespace JiLinApp.Core;
@ -8,9 +9,11 @@ public class AppConfig
{ {
public BaseConfig Base { get; set; } public BaseConfig Base { get; set; }
public TransmitAlarmConfig TransmitAlarm { get; set; } public List<PtzControlTypeConfig> ptzCtrlTypes { get; set; }
public List<CameraInfo> CameraList { get; set; } public List<CameraInfo> CameraList { get; set; }
public TransmitAlarmConfig TransmitAlarm { get; set; }
} }
public class BaseConfig public class BaseConfig

3
JiLinApp/Core/Global.cs

@ -1,6 +1,7 @@
using EC.Util.Common; using EC.Util.Common;
using JiLinApp.Biz.TransmitAlarm; using JiLinApp.Biz.TransmitAlarm;
using JiLinApp.Docking.Alarm; using JiLinApp.Docking.Alarm;
using JiLinApp.Docking.Ptz;
using NewLife.Configuration; using NewLife.Configuration;
using System; using System;
using System.IO; using System.IO;
@ -30,6 +31,8 @@ public static class Global
// 控制台 // 控制台
if (AppConfig.Base.Console) SystemUtil.AllocConsole(); if (AppConfig.Base.Console) SystemUtil.AllocConsole();
// ptzCtrlTypes
PtzControlTypeConfigHelper.Init(AppConfig.ptzCtrlTypes);
AlarmService = AlarmServiceFactory.CreateService(AppConfig.TransmitAlarm); AlarmService = AlarmServiceFactory.CreateService(AppConfig.TransmitAlarm);
AlarmService?.Start(); AlarmService?.Start();

3
JiLinApp/Pages/FenceServerManage/Main.xaml.cs

@ -1,4 +1,5 @@
using JiLinApp.Docking.FenceAlarm; using JiLinApp.Core;
using JiLinApp.Docking.FenceAlarm;
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;

7
JiLinApp/Pages/PtzManage/Main.xaml

@ -94,11 +94,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<ComboBox Name="ControlType" materialDesign:HintAssist.Hint="控制类型" Width="200" SelectionChanged="ControlType_SelectionChanged" Style="{StaticResource MaterialDesignOutlinedComboBox}"> <ComboBox Name="ControlTypeName" materialDesign:HintAssist.Hint="控制类型" Width="200" SelectionChanged="ControlTypeName_SelectionChanged" Style="{StaticResource MaterialDesignOutlinedComboBox}">
<ComboBoxItem Content="PelcoD" />
<ComboBoxItem Content="PelcoP" />
<ComboBoxItem Content="DCamera" />
<ComboBoxItem Content="HikSdk" />
</ComboBox> </ComboBox>
<ComboBox Name="CameraId" materialDesign:HintAssist.Hint="相机Id" Width="200" Margin="0 10 0 0" SelectedIndex="0" Style="{StaticResource MaterialDesignOutlinedComboBox}"> <ComboBox Name="CameraId" materialDesign:HintAssist.Hint="相机Id" Width="200" Margin="0 10 0 0" SelectedIndex="0" Style="{StaticResource MaterialDesignOutlinedComboBox}">
</ComboBox> </ComboBox>
@ -169,6 +165,7 @@
<ComboBox Name="PresetId" materialDesign:HintAssist.Hint="预置点Id" Width="200" SelectedIndex="0" Style="{StaticResource MaterialDesignOutlinedComboBox}"> <ComboBox Name="PresetId" materialDesign:HintAssist.Hint="预置点Id" Width="200" SelectedIndex="0" Style="{StaticResource MaterialDesignOutlinedComboBox}">
</ComboBox> </ComboBox>
<Button Name="GotoBtn" Content="前往预置点" Width="120" Margin="0 10 0 0" Click="GotoBtn_Click" Style="{StaticResource MaterialDesignRaisedLightButton}" /> <Button Name="GotoBtn" Content="前往预置点" Width="120" Margin="0 10 0 0" Click="GotoBtn_Click" Style="{StaticResource MaterialDesignRaisedLightButton}" />
<Button Name="TestBtn" Content="测试" Width="120" Visibility="Visible" Margin="0 10 0 0" Click="TestBtn_Click" Style="{StaticResource MaterialDesignRaisedLightButton}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</GroupBox> </GroupBox>

70
JiLinApp/Pages/PtzManage/Main.xaml.cs

@ -1,5 +1,7 @@
using EC.Util.CameraSDK; using EC.Util.CameraSDK;
using EC.Util.Port; using EC.Util.Port;
using ImTools;
using JiLinApp.Components;
using JiLinApp.Core; using JiLinApp.Core;
using JiLinApp.Docking.Ptz; using JiLinApp.Docking.Ptz;
using NewLife.Reflection; using NewLife.Reflection;
@ -55,6 +57,15 @@ public partial class Main : UserControl
ComName.Items.Add(new ComboBoxItem { Content = port }); ComName.Items.Add(new ComboBoxItem { Content = port });
} }
// 解析海康相机
TaskUtil.RunCatch(() => Dispatcher.Invoke(LoadHikCamera));
// 初始化云台控制类型
foreach (var cfg in Global.AppConfig.ptzCtrlTypes)
{
ControlTypeName.Items.Add(new ComboBoxItem { Content = cfg.Name });
}
// 初始化下拉框 Id // 初始化下拉框 Id
for (int i = 1; i <= 5; i++) for (int i = 1; i <= 5; i++)
{ {
@ -71,11 +82,8 @@ public partial class Main : UserControl
btn.AddHandler(Button.MouseUpEvent, new MouseButtonEventHandler(PtzBtn_MouseUp), true); btn.AddHandler(Button.MouseUpEvent, new MouseButtonEventHandler(PtzBtn_MouseUp), true);
} }
// 解析海康相机
TaskUtil.RunCatch(() => Dispatcher.Invoke(LoadHikCamera));
// 刷新控件状态 // 刷新控件状态
ControlType.SelectedIndex = 0; ControlTypeName.SelectedIndex = 0;
} }
private bool IsConnect() private bool IsConnect()
@ -140,7 +148,7 @@ public partial class Main : UserControl
private void PtzBtn_MouseDown(object sender, RoutedEventArgs e) private void PtzBtn_MouseDown(object sender, RoutedEventArgs e)
{ {
PtzControlType ctrlType = PtzCmd.GetControlType(ControlType.Text); PtzControlType ctrlType = PtzControlTypeConfigHelper.GetControlType(ControlTypeName.Text);
PtzCmdType cmdType = PtzCmd.GetCmdType(((Button)sender).Name.Replace("Btn", "")); PtzCmdType cmdType = PtzCmd.GetCmdType(((Button)sender).Name.Replace("Btn", ""));
switch (ctrlType) switch (ctrlType)
@ -173,7 +181,7 @@ public partial class Main : UserControl
private void PtzBtn_MouseUp(object sender, RoutedEventArgs e) private void PtzBtn_MouseUp(object sender, RoutedEventArgs e)
{ {
PtzControlType ctrlType = PtzCmd.GetControlType(ControlType.Text); PtzControlType ctrlType = PtzControlTypeConfigHelper.GetControlType(ControlTypeName.Text);
PtzCmdType cmdType; PtzCmdType cmdType;
switch (ctrlType) switch (ctrlType)
{ {
@ -201,7 +209,7 @@ public partial class Main : UserControl
private void GotoBtn_Click(object sender, RoutedEventArgs e) private void GotoBtn_Click(object sender, RoutedEventArgs e)
{ {
PtzControlType ctrlType = PtzCmd.GetControlType(ControlType.Text); PtzControlType ctrlType = PtzControlTypeConfigHelper.GetControlType(ControlTypeName.Text);
PtzCmdType cmdType = PtzCmdType.PresetGoto; PtzCmdType cmdType = PtzCmdType.PresetGoto;
byte presetId = byte.Parse(PresetId.Text); byte presetId = byte.Parse(PresetId.Text);
@ -226,6 +234,10 @@ public partial class Main : UserControl
} }
} }
private void TestBtn_Click(object sender, RoutedEventArgs e)
{
}
private void ControlType_SelectionChanged(object sender, SelectionChangedEventArgs e) private void ControlType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if (CameraId == null || CameraIp == null) return; if (CameraId == null || CameraIp == null) return;
@ -252,18 +264,62 @@ public partial class Main : UserControl
} }
} }
private void ControlTypeName_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CameraId == null || CameraIp == null) return;
string ctrlTypeName = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
PtzControlType ctrlType = PtzControlTypeConfigHelper.GetControlType(ctrlTypeName);
switch (ctrlType)
{
case PtzControlType.PelcoD:
case PtzControlType.PelcoP:
CameraId.IsEnabled = true;
CameraIp.IsEnabled = false;
break;
case PtzControlType.HikSdk:
CameraId.IsEnabled = false;
CameraIp.IsEnabled = true;
break;
default:
CameraId.IsEnabled = false;
CameraIp.IsEnabled = false;
break;
}
}
#endregion ElementEvent #endregion ElementEvent
#region InvokeEvent #region InvokeEvent
public void GotoPreset() public void GotoPreset()
{ {
if (Global.AppConfig.TransmitAlarm.RealPlay)
{
PtzControlType ctrlType = PtzControlTypeConfigHelper.GetControlType(ControlTypeName.Text);
if (ctrlType == PtzControlType.HikSdk) ShowLiveVideo();
}
GotoBtn_Click(null, null); GotoBtn_Click(null, null);
// 切换至下一预置点
int index = PresetId.SelectedIndex; int index = PresetId.SelectedIndex;
index = (index + 1) % PresetId.Items.Count; index = (index + 1) % PresetId.Items.Count;
PresetId.SelectedIndex = index; PresetId.SelectedIndex = index;
} }
public void ShowLiveVideo()
{
string cameraIp = CameraIp.Text;
HikMap.TryGetValue(cameraIp, out HiKSDK hikSdk);
if (hikSdk == null) return;
HikRealPlay realPlay = new(hikSdk);
realPlay.Owner = Window.GetWindow(this);
realPlay.Show();
realPlay.HideMinButton();
realPlay.StartPlay();
}
#endregion InvokeEvent #endregion InvokeEvent
#region HikMap #region HikMap

9
JiLinApp/Pages/PtzManage/MainViewModel.cs

@ -52,13 +52,4 @@ public class MainViewModel : ViewModelBase
} }
#endregion InvokeEvent #endregion InvokeEvent
#region Send
private void SendAlarm(AlarmMessage alarm)
{
//AlarmPubSocket.SendMoreFrame(AppConfig.Zmq.AlarmPubTopic).SendFrame(obj.ToJson());
}
#endregion Send
} }

40
JiLinApp/config/config.json

@ -2,16 +2,25 @@
"base": { "base": {
"console": false "console": false
}, },
"transmitAlarm": { "ptzCtrlTypes": [
"type": "mqtt", {
"mqtt": { "type": "PelcoD",
"port": "1883", "Name": "协议Pd"
"username": "admin", },
"password": "public", {
"clientId": "alarmClient", "type": "PelcoP",
"transmitTopic": "alarm/transmit" "Name": "协议Pp"
},
{
"type": "DCamera",
"Name": "协议D"
},
{
"type": "HikSdk",
"Name": "协议H"
} }
},
],
"cameraList": [ "cameraList": [
{ {
"ip": "192.168.1.65", "ip": "192.168.1.65",
@ -31,5 +40,16 @@
"username": "admin", "username": "admin",
"password": "hk123456" "password": "hk123456"
} }
] ],
"transmitAlarm": {
"realPlay": true,
"type": "mqtt",
"mqtt": {
"port": "1883",
"username": "admin",
"password": "public",
"clientId": "alarmClient",
"transmitTopic": "alarm/transmit"
}
}
} }
Loading…
Cancel
Save