Z
8 months ago
6 changed files with 176 additions and 5 deletions
@ -1,5 +1,13 @@
@@ -1,5 +1,13 @@
|
||||
namespace Emergency_platform{ |
||||
public class DataServerUrl{ |
||||
public const string Url = ""; |
||||
|
||||
//Default is http://192.168.10.104:8080 |
||||
public string ServerAddress { set; get; } = ""; |
||||
public const string FrpAddress = "http://175.178.105.185:13000"; |
||||
public const string LocalAddress = "http://192.168.10.104:8080"; |
||||
/// <summary> |
||||
/// /api/CabinetInstance/id |
||||
/// </summary> |
||||
public const string UrlCabinetInstanceId = "/api/CabinetInstance/id"; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
using System.Net.Http.Json; |
||||
using System.Text; |
||||
using System.Text.Json; |
||||
using EGFramework; |
||||
using Guidaoji; |
||||
using Guidaoji.Camera; |
||||
using Guidaoji.Common; |
||||
using Newtonsoft.Json; |
||||
|
||||
namespace Emergency_platform{ |
||||
public class ModelPatrol : EGModule,IEGFramework |
||||
{ |
||||
public override void Init() |
||||
{ |
||||
this.EGRegisterMessageEvent<ResponsePatrol>((e,sender,protocol)=>{ |
||||
Console.WriteLine("Get Command " + e.action); |
||||
Console.WriteLine("Command params is" + e.action + "|" + e.taskid + "|" + e.cabinetid); |
||||
ExecutePatrol(e,sender,protocol); |
||||
}); |
||||
this.EGOnMessage<ResponsePatrol>(); |
||||
} |
||||
|
||||
public async void ExecutePatrol(ResponsePatrol responsePatrol,string sender,ProtocolType protocolType){ |
||||
//var obj = JsonConvert.DeserializeObject<MyObject>(task); |
||||
//obj.cabinetid[] 可以得到要识别的柜子id |
||||
//把要识别的柜子id发送给硬件抓图,算法返回数据 |
||||
//把数据返回给应急平台,将柜子识别完之后返回数据 和算法交流返回的数据 |
||||
//var result = AlgorithmTCP.Connect(picPath, targetName); |
||||
foreach (int cabinetId in responsePatrol.cabinetid) |
||||
{ |
||||
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg"; |
||||
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4"; |
||||
//调用轨道机方法 |
||||
Console.WriteLine(cabinetId); |
||||
using (var httpClient = new HttpClient()) |
||||
{ |
||||
//发送post请求 |
||||
//origin url = http://192.168.10.104:8080/api/CabinetInstance/id |
||||
var response = await httpClient.PostAsJsonAsync(DataServerUrl.LocalAddress + DataServerUrl.UrlCabinetInstanceId, cabinetId.ToString()); |
||||
if (response.IsSuccessStatusCode) |
||||
{ |
||||
var responseBody = await response.Content.ReadAsStringAsync(); |
||||
Console.WriteLine(responseBody); |
||||
JsonDocument jsonDocument = JsonDocument.Parse(responseBody); |
||||
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data"); |
||||
string cabinetPosX = dataElement.GetProperty("cabinetPosX").GetString(); |
||||
string cabinetPosY = dataElement.GetProperty("cabinetPosY").GetString(); |
||||
float poseP = float.Parse(dataElement.GetProperty("poseP").GetString()); |
||||
float poseT = float.Parse(dataElement.GetProperty("poseT").GetString()); |
||||
float poseZ = float.Parse(dataElement.GetProperty("poseZ").GetString()); |
||||
var posX = double.Parse(cabinetPosX); |
||||
var posY = double.Parse(cabinetPosY); |
||||
//Console.WriteLine(cabinetPosX); |
||||
//Console.WriteLine(cabinetPosY); |
||||
//Console.WriteLine(poseX); |
||||
//Console.WriteLine(poseY); |
||||
//Console.WriteLine(poseP); |
||||
//Console.WriteLine(poseT); |
||||
//Console.WriteLine(poseZ); |
||||
//CHNetHelp.SaveViedo(true, 1, videoPath); |
||||
TcpClientWrapper.GuiDaoJiMove(posX, posY); |
||||
GuiDaoJiRet gui = TcpClientWrapper.SendDataRead(); |
||||
bool guidaoji = true; |
||||
while (guidaoji) |
||||
{ |
||||
if (gui != null && gui.data.type == "0") |
||||
{ |
||||
guidaoji = false; |
||||
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath); |
||||
CHNetHelp.JPEG(1, picPath); |
||||
} |
||||
} |
||||
Console.WriteLine("轨道机运动成功"); |
||||
} |
||||
else |
||||
{ |
||||
//处理错误响应 |
||||
Console.WriteLine("请求失败"); |
||||
} |
||||
} |
||||
//发给算法 |
||||
|
||||
//模拟的返回数据 |
||||
RequestPatrol requestPatrol = new RequestPatrol(){ |
||||
taskid = "1", |
||||
cabinetid = cabinetId, |
||||
}; |
||||
requestPatrol.target.Add(new PatrolTarget("1号电流表","100.1")); |
||||
requestPatrol.target.Add(new PatrolTarget("3号指示灯","亮")); |
||||
requestPatrol.target.Add(new PatrolTarget("停电牌","无")); |
||||
//发送数据 |
||||
this.EGSendMessage(requestPatrol,sender,protocolType); |
||||
//socket_commu.Send(dataBytes); |
||||
Console.WriteLine("发送成功"); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
using EGFramework; |
||||
using Newtonsoft.Json; |
||||
namespace Emergency_platform{ |
||||
public class ResponsePatrol : IResponse |
||||
{ |
||||
public string action { set; get; } |
||||
public string taskid { set; get; } |
||||
public List<int> cabinetid { set; get; } |
||||
|
||||
public bool TrySetData(string protocolData, byte[] protocolBytes) |
||||
{ |
||||
try |
||||
{ |
||||
ResponsePatrol data = JsonConvert.DeserializeObject<ResponsePatrol>(protocolData); |
||||
if(data.action == "patrol"){ |
||||
this.action = data.action; |
||||
this.taskid = data.taskid; |
||||
this.cabinetid = data.cabinetid; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
catch (System.Exception) |
||||
{ |
||||
return false; |
||||
throw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class RequestPatrol : IRequest |
||||
{ |
||||
public string action = "identify"; |
||||
public string date { set; get; } |
||||
public string taskid { set; get; } |
||||
public int cabinetid = 1; |
||||
public List<PatrolTarget> target { set; get; } |
||||
public RequestPatrol(){ |
||||
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
||||
target = new List<PatrolTarget>(); |
||||
} |
||||
public RequestPatrol(List<PatrolTarget> target){ |
||||
this.target = target; |
||||
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
||||
} |
||||
public byte[] ToProtocolByteData() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public string ToProtocolData() |
||||
{ |
||||
return JsonConvert.SerializeObject(this); |
||||
} |
||||
} |
||||
public struct PatrolTarget{ |
||||
public string name { set; get; } |
||||
public string result { set; get; } |
||||
public PatrolTarget(string name_,string result_){ |
||||
name = name_; |
||||
result = result_; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue