Browse Source

fixed Code

master
Z 8 months ago
parent
commit
33ea1c52bd
  1. 4
      Common/TcpClientWrapper.cs
  2. 10
      Data/DataServerUrl.cs
  3. 4
      Framework/EGFramework/Module/ProtocolTools/EGHttpClient.cs
  4. 98
      Model/ModelPatrol.cs
  5. 1
      Program.cs
  6. 64
      Protocol/ResponsePatrol.cs

4
Common/TcpClientWrapper.cs

@ -99,7 +99,7 @@ namespace Guidaoji.Common @@ -99,7 +99,7 @@ namespace Guidaoji.Common
//客户端IP和端口号
string clientIP = client.RemoteEndPoint == null ? "" : client.RemoteEndPoint.ToString();
clientIP = clientIP.Substring(0, clientIP.LastIndexOf(':'));
int clientPort = ((IPEndPoint)client.RemoteEndPoint).Port;
int clientPort = ((IPEndPoint)client.LocalEndPoint).Port;
// 将与客户端连接的 套接字 对象添加到集合中;
dict.Add(clientPort, client);
PrintInfo(string.Format("客户端连接成功!IP:{0},端口号:{1}", clientIP, clientPort));
@ -133,7 +133,7 @@ namespace Guidaoji.Common @@ -133,7 +133,7 @@ namespace Guidaoji.Common
{
bConnect = true;
iGuidaojiClientPort = clientPort;
Console.WriteLine("连接成功");
Console.WriteLine("轨道机连接成功");
PrintInfo("客户端连接成功连接成功......");
PrintInfo("Socket is end......");
Thread t = new Thread(GuidaojiExecute);

10
Data/DataServerUrl.cs

@ -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";
}
}

4
Framework/EGFramework/Module/ProtocolTools/EGHttpClient.cs

@ -50,10 +50,10 @@ namespace EGFramework{ @@ -50,10 +50,10 @@ namespace EGFramework{
httpResponse = await HTTPClient.PostAsync(hostUrl,httpContent);
break;
case ProtocolType.HttpPut:
httpResponse = await HTTPClient.PostAsync(hostUrl,httpContent);
httpResponse = await HTTPClient.PutAsync(hostUrl,httpContent);
break;
case ProtocolType.HttpPatch:
httpResponse = await HTTPClient.PostAsync(hostUrl,httpContent);
httpResponse = await HTTPClient.PatchAsync(hostUrl,httpContent);
break;
case ProtocolType.HttpDelete:
httpResponse = await HTTPClient.DeleteAsync(hostUrl);

98
Model/ModelPatrol.cs

@ -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("发送成功");
}
}
}
}

1
Program.cs

@ -48,5 +48,6 @@ public partial class Program :IEGFramework @@ -48,5 +48,6 @@ public partial class Program :IEGFramework
this.EGTCPServerListen(20001);
this.EGEnabledProtocolTool<EGTCPServer>();
this.RegisterModule(new ModelNumericalValue());
this.RegisterModule(new ModelPatrol());
}
}

64
Protocol/ResponsePatrol.cs

@ -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…
Cancel
Save