唐山轨道机控制端TCP服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
5.2 KiB

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";
//调用轨道机方法
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)
{
if(gui.data.type == "0"){
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}else{
Console.WriteLine(gui.data.type);
}
}
await Task.Delay(1000);
gui = TcpClientWrapper.SendDataRead();
}
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("发送成功");
await Task.Delay(5000);
}
}
}
}