Commit 2b3863d0 张东亮

添加监控上传功能,默认不开启

1 个父辈 bde4b79a
...@@ -178,6 +178,8 @@ namespace OnlineStore.Common ...@@ -178,6 +178,8 @@ namespace OnlineStore.Common
[MyConfigComment("启用隐藏smf单盘入库按钮")] [MyConfigComment("启用隐藏smf单盘入库按钮")]
public static MyConfig<bool> Enable_HideSingleReelIn = false; public static MyConfig<bool> Enable_HideSingleReelIn = false;
[MyConfigComment("启用上传监控图像给SMF")]
public static MyConfig<bool> Enable_UploadVideo = false;
[MyConfigComment("压紧轴回原失败重试最大次数")] [MyConfigComment("压紧轴回原失败重试最大次数")]
public static MyConfig<int> Comp_Axis_HomeResetTimes = 999; public static MyConfig<int> Comp_Axis_HomeResetTimes = 999;
...@@ -210,5 +212,18 @@ namespace OnlineStore.Common ...@@ -210,5 +212,18 @@ namespace OnlineStore.Common
public static MyConfig<int> SingleInOut_ReelWidth = 7; public static MyConfig<int> SingleInOut_ReelWidth = 7;
[MyConfigComment("单盘出入库的指定尺寸-高度")] [MyConfigComment("单盘出入库的指定尺寸-高度")]
public static MyConfig<int> SingleInOut_ReelHeight = 20; public static MyConfig<int> SingleInOut_ReelHeight = 20;
[MyConfigComment("监控上传功能_相机名")]
public static MyConfig<string[]> UploadVideo_IPCameraNames = new string[] { "cam1", "cam2" };
[MyConfigComment("监控上传功能_监控服务的IP")]
public static MyConfig<string> UploadVideo_ServiceIp = "localhost";
[MyConfigComment("监控上传功能_监控服务的端口")]
public static MyConfig<int> UploadVideo_ServicePort = 8088;
[MyConfigComment("监控上传功能_图像宽度")]
public static MyConfig<int> UploadVideo_ImgWidth = 1920;
[MyConfigComment("监控上传功能_图像高度")]
public static MyConfig<int> UploadVideo_ImgHeight = 1080;
[MyConfigComment("监控上传功能_图像质量")]
public static MyConfig<int> UploadVideo_ImgQuality = 100;
} }
} }
...@@ -5,6 +5,7 @@ using System.Collections.Specialized; ...@@ -5,6 +5,7 @@ using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Net.WebRequestMethods;
namespace OnlineStore.Common namespace OnlineStore.Common
{ {
...@@ -72,6 +73,42 @@ namespace OnlineStore.Common ...@@ -72,6 +73,42 @@ namespace OnlineStore.Common
return new List<SmfLangData>(); return new List<SmfLangData>();
} }
/// <summary>
/// 上传监控
/// </summary>
static string Addr_uploadVideo = "/service/video/upload";
public static bool UploadVideo(string cid, string img)
{
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>
{
{ "cid", cid },
{ "img", ParseBase64Str(img) }
};
var resultStr = HttpHelper.Post(server+Addr_uploadVideo,JsonHelper.SerializeObject(paramMap), 300);
SmfResult smfResult = JsonHelper.DeserializeJsonToObject<SmfResult>(resultStr);
if (smfResult != null)
{
return smfResult.code == 0;
}
}
catch (Exception ex)
{
LogUtil.error($"{cid} UploadVideo error ", ex);
}
return false;
}
static string ParseBase64Str(string base64)
{
if (base64 == null) return "";
string dump = base64.Trim('"', '"').Replace("%", "").Replace(",", "").Replace(" ", "+").Replace("\\", "");
if (dump.Length % 4 > 0)
{
dump = dump.PadRight(dump.Length + 4 - dump.Length % 4, '=');
}
return dump;
}
} }
//{"code":0,"data":"ok","msg":"ok","msgKey":"smfcore.ok","okResult":true} //{"code":0,"data":"ok","msg":"ok","msgKey":"smfcore.ok","okResult":true}
...@@ -89,6 +126,4 @@ namespace OnlineStore.Common ...@@ -89,6 +126,4 @@ namespace OnlineStore.Common
public string lanCode; public string lanCode;
public Dictionary<string, string> resourceMap; public Dictionary<string, string> resourceMap;
} }
} }
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
<Compile Include="DeviceLibrary\CameraTest.cs" /> <Compile Include="DeviceLibrary\CameraTest.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" /> <Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" /> <Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\IPCamera.cs" />
<Compile Include="DeviceLibrary\I_SafetyDevice.cs" /> <Compile Include="DeviceLibrary\I_SafetyDevice.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" /> <Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" /> <Compile Include="DeviceLibrary\LineRunMonitor.cs" />
......
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace DeviceLibrary
{
public class IPCamera
{
public IPCamera()
{
string ip = Setting_Init.UploadVideo_ServiceIp;
int port = Setting_Init.UploadVideo_ServicePort;
server=($"http://{ip}:{port}");
}
string server;
string Addr_getImgBase64 = "/cam/grabOneImgByBase64";
public string GetImgBase64(string cameName)
{
string base64 = "";
try
{
Dictionary<string, string> dic = new Dictionary<string, string>()
{
{ "camName",cameName },
{"width",Setting_Init.UploadVideo_ImgWidth.ToString() },
{"height",Setting_Init.UploadVideo_ImgHeight.ToString()},
{"quality",Setting_Init.UploadVideo_ImgQuality.ToString()},
};
base64 = HttpHelper.Get(GetAddr(Addr_getImgBase64, dic));
}
catch (Exception ex)
{
LogUtil.error($"{cameName} 采集异常", ex);
}
return base64;
}
string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
}
}
\ No newline at end of file \ No newline at end of file
using CodeLibrary;
using OnlineStore; using OnlineStore;
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -891,5 +893,51 @@ namespace DeviceLibrary ...@@ -891,5 +893,51 @@ namespace DeviceLibrary
boxTransport.IgnoreX09 = true; boxTransport.IgnoreX09 = true;
LogUtil.info("按下X09忽略"); LogUtil.info("按下X09忽略");
} }
#region 监控上报
System.Threading.Timer uploadVideotimer;
void uploadVideo(object o)
{
if (Monitor.TryEnter(uploadVideotimer))
{
string[] camnames = Setting_Init.UploadVideo_IPCameraNames;
try
{
if (camnames != null && camnames.Length > 0)
{
for (int i = 0; i < camnames.Length; i++)
{
string base64 = ipCam.GetImgBase64(camnames[i]);
if (!string.IsNullOrEmpty(base64))
{
SMF.UploadVideo($"{Setting_Init.App_CID}_{i + 1}", base64);
}
Thread.Sleep(200);
}
}
}
catch (Exception e)
{
LogUtil.error($"{Name} 上传监控图片异常", e);
}
finally
{
Monitor.Exit(uploadVideotimer);
}
}
}
public IPCamera ipCam;
public void UploadVideoProcessInit()
{
if (!Setting_Init.Enable_UploadVideo) return;
ipCam = new IPCamera();
uploadVideotimer = new System.Threading.Timer(new TimerCallback(uploadVideo), null, 0, 500);
GC.KeepAlive(uploadVideotimer);
LogUtil.info($"{Name} 初始化上传监控模块");
}
#endregion
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -377,6 +377,7 @@ namespace TheMachine ...@@ -377,6 +377,7 @@ namespace TheMachine
} }
SetMsg(lm); SetMsg(lm);
WindowManager.Show(); WindowManager.Show();
RobotManage.mainMachine.UploadVideoProcessInit();
} }
object showMsgLoc = new object(); object showMsgLoc = new object();
void SetMsg(List<Msg> msgs) void SetMsg(List<Msg> msgs)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!