唐山轨道机控制端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.

3155 lines
171 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using Newtonsoft.Json.Linq;
using static System.Collections.Specialized.BitVector32;
using System.Security.Cryptography;
using System.Timers;
using Newtonsoft.Json;
using System.Threading;
using System.Collections.Concurrent;
using System.Net.Http;
using System.Net.Http.Json;
using System.Data.Common;
using System.Diagnostics.SymbolStore;
using Guidaoji.Camera;
using Guidaoji.Common;
using System.IO;
using Guidaoji;
namespace Emergency_platform
{
public class TCP
{
Socket socket_commu;
System.Timers.Timer timer = new System.Timers.Timer();
JObject json;
public void Socket()
{
Socket server_socketListen = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ips = IPAddress.Any;
IPEndPoint ipNode = new IPEndPoint(ips, 20001);//网络端点:为IP地址和端口号
//服务端必须绑定一个端口才能listen(),要不然客户端就不知道该连哪个端口了
server_socketListen.Bind(ipNode);
//监听后,如果客户端这时调用connect()发出连接请求,服务器端就会接收到这个请求
//listen函数将socket变为被动类型的,等待客户的连接请求。
server_socketListen.Listen(10);
//服务端有两个socket;这里Accept()返回的相当于是客户端的socket,用于和客户端发送(send)和接收(recv)数据
socket_commu = server_socketListen.Accept();
Console.WriteLine("连接成功");
while (true)
{
//接收数据
byte[] buffer = new byte[1024 * 1024];
int bytesRead = socket_commu.Receive(buffer);
//将接收到的数据转换为字符串
string task = Encoding.UTF8.GetString(buffer, 0, bytesRead);
//当前时间
DateTime date1 = DateTime.Now;
//要执行的任务
TaskRun(task, date1);
}
}
/// <summary>
/// 主任务
/// </summary>
public async void TaskRun(string task, DateTime date)
{
var json = JObject.Parse(task);
var action = json["action"].Value<string>();
Console.WriteLine(action);
if (action == "numericalValue")
{
var halmet = json["halmet"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
if (halmet == "")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
//电流表、电压表、功率表只是需要读取数据返回给平台
int taskId = json["taskid"].Value<int>();
string cabinetID = json["cabinetid"].Value<string>();
//从数据库中获取柜子坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetID);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//抓图返回给算法,返回数据
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入电流表数值");
string ammeter = "200";
//按照格式返回给应急平台
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetID,
targetname = targetName,
result = ammeter
};
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
CHNetHelp.SaveViedo(false, 1, videoPath);
}
else//需要识别安全帽
{
//轨道机在初始位置先识别安全帽
//原地指令
//CHNetHelp.SaveViedo(true, 1, videoPath);
//TcpClientWrapper.GuiDaoJiMove(0, 0);
//GuiDaoJiRet gui = TcpClientWrapper.SendDataRead();
//bool guidaoji = true;
//while (guidaoji)
//{
// if (gui.data.type == "0")
// {
// guidaoji = false;
// CHNetHelp.SetCameraProcess(OperationType.PTZ, 0, 0, 0, 1, videoPath);
// CHNetHelp.JPEG(1, picPath);
// }
//}
//Console.WriteLine("轨道机运动成功");
//将图片发送给算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//戴了安全帽执行下一步,没有戴则报警
//算法返回数据
var halmetResult = true;
if (halmetResult == true)//戴了
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
//电流表、电压表、功率表只是需要读取数据返回给平台
int taskId = json["taskid"].Value<int>();
string cabinetID = json["cabinetid"].Value<string>();
//从数据库中获取柜子坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetID);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//调用相机方法获取图片
//抓图返回给算法,返回数据
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入电流表数值");
string ammeter = "150";
//按照格式返回给应急平台
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetID,
targetname = targetName,
result = ammeter
};
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else//没戴
{
//报警
//不正确
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104/api/AlarmType/type", "安全帽");
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
result = "false"
};
}
}
}
else if (action == "switch")
{
var halmet = json["halmet"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
if (halmet == "")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
if (targetName.Contains("断路器"))
{
string taskId = json["taskid"].Value<string>();
string cabinetId = json["cabinetid"].Value<string>();
string state = json["state"].Value<string>();
string operate = json["operate"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//算法返回结果
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入开关状态");
string stateResult = "0";
//进行判断 操作前相等是正确的,操作后相等是不正确的
if (operate == "0" && stateResult == state)//0是闭合,1是开
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
//存储运行信息到数据库
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "0" && stateResult != state)
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到运行日志数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "1" && stateResult != state)
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
else if (targetName.Contains("刀闸") || targetName.Contains("小车"))
{
{
string taskId = json["taskid"].Value<string>();
string cabinetId = json["cabinetid"].Value<string>();
string state = json["state"].Value<string>();
string operate = json["operate"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入开关状态");
string stateResult = "0";
//进行判断 操作前相等是正确的,操作后相等是不正确的
if (operate == "0" && stateResult == state)//0是闭合,1是开
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
//存储运行信息到数据库
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "0" && stateResult != state)
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "1" && stateResult != state)
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
//CHNetHelp.SaveViedo(false, 1, videoPath);
}
else
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
}
}
else//需要识别安全帽
{
//轨道机在初始位置先识别安全帽
//原地指令
//CHNetHelp.SaveViedo(true, 1, videoPath);
//TcpClientWrapper.GuiDaoJiMove(0, 0);
//GuiDaoJiRet gui = TcpClientWrapper.SendDataRead();
//bool guidaoji = true;
//while (guidaoji)
//{
// if (gui.data.type == "0")
// {
// guidaoji = false;
// CHNetHelp.SetCameraProcess(OperationType.PTZ, 0, 0, 0, 1, videoPath);
// CHNetHelp.JPEG(1, picPath);
// }
//}
//Console.WriteLine("轨道机运动成功");
//将图片发送给算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//戴了安全帽执行下一步,没有戴则报警
//算法返回数据
var halmetResult = true;
if (halmetResult == true)
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
//Console.WriteLine(targetName);
if (targetName.Contains("断路器"))
{
string taskId = json["taskid"].Value<string>();
string cabinetId = json["cabinetid"].Value<string>();
string state = json["state"].Value<string>();
string operate = json["operate"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入开关状态");
string stateResult = "0";
//进行判断 操作前相等是正确的,操作后相等是不正确的
if (operate == "0" && stateResult == state)//0是闭合,1是开
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
//存储运行信息到数据库
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "0" && stateResult != state)
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "1" && stateResult != state)
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
else if (targetName.Contains("刀闸") || targetName.Contains("小车"))
{
string taskId = json["taskid"].Value<string>();
string cabinetId = json["cabinetid"].Value<string>();
string state = json["state"].Value<string>();
string operate = json["operate"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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(10, 10);
GuiDaoJiRet gui = TcpClientWrapper.SendDataRead();
bool guidaoji = true;
while (guidaoji)
{
if (gui.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, 1, 1, 1, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入开关状态");
string stateResult = "0";
//进行判断 操作前相等是正确的,操作后相等是不正确的
if (operate == "0" && stateResult == state)//0是闭合,1是开
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
//存储运行信息到数据库
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "0" && stateResult != state)
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (operate == "1" && stateResult != state)
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
//不正确
//发送tagretname来获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
}
else//没戴
{
//报警
//不正确
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", "安全帽");
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
result = "false"
};
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
}
else if (action == "whether")
{
var halmet = json["halmet"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
if (halmet == "")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
//剩下的都是判断有还是没有
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入true或者false");
string stateResult = "true";
if (stateResult == "true")
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
//不正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
Console.WriteLine(manageLight);
Console.WriteLine(message);
Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
bool isRunning = true;
while (isRunning)
{
//一直抓图,直到算法一直识别知道返回值为true跳出循环
string timerResult = await StartTimerTask();
//将返回的路径传给算法
//var results = AlgorithmTCP.Connect(timerResult, targetName);
//假设返回值为result
bool result = false;
if (result == true)
{
isRunning = false;
}
await Task.Delay(TimeSpan.FromMinutes(1));
}
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath,
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
else//需要识别安全帽
{
//轨道机在初始位置先识别安全帽
//原地指令
//CHNetHelp.SaveViedo(true, 1, videoPath);
//TcpClientWrapper.GuiDaoJiMove(0, 0);
//GuiDaoJiRet gui = TcpClientWrapper.SendDataRead();
//bool guidaoji = true;
//while (guidaoji)
//{
// if (gui.data.type == "0")
// {
// guidaoji = false;
// CHNetHelp.SetCameraProcess(OperationType.PTZ, 0, 0, 0, 1, videoPath);
// CHNetHelp.JPEG(1, picPath);
// }
//}
//Console.WriteLine("轨道机运动成功");
//将图片发送给算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//戴了安全帽执行下一步,没有戴则报警
//算法返回数据
var halmetResult = true;
if (halmetResult == true)
{
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
//剩下的都是判断有还是没有
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
//将坐标给到轨道机
//要发送的参数
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", cabinetId);
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.data.type == "0")
{
guidaoji = false;
CHNetHelp.SetCameraProcess(OperationType.PTZ, poseP, poseT, poseZ, 1, videoPath);
CHNetHelp.JPEG(1, picPath);
}
}
Console.WriteLine("轨道机运动成功");
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//图片给到算法
//var result = AlgorithmTCP.Connect(picPath, targetName);
//Console.WriteLine("请输入true还是false");
string stateResult = "true";
if (stateResult == "true")
{
//正确
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
var returndata = new
{
action = action,
taskid = taskId,
date = date.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//获取报警信息并亮灯
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
bool isRunning = true;
while (isRunning)
{
//一直抓图,直到算法一直识别知道返回值为true跳出循环
string timerResult = await StartTimerTask();
//将返回的路径传给算法
//var results = AlgorithmTCP.Connect(timerResult, targetName);
//假设返回值为result
bool result = false;
if (result == true)
{
isRunning = false;
}
await Task.Delay(TimeSpan.FromMinutes(1));
}
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "false",
voiceBroadcast = true,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
}
else//没戴
{
//报警
//不正确
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", "安全帽");
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
result = "false"
};
//将JSON数据对象序列化为字符串
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
}
else if (action == "true")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
var returndata = new
{
action = action,
taskid = taskId,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
//var options = new JsonSerializerOptions { WriteIndented = true };
//string jsonString = System.Text.Json.JsonSerializer.Serialize(returndata, options);
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (action == "false")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
//通过目标名称targetName查询数据库获取报警信息和灯的状态
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = taskId,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "false"
};
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将JSON数据对象序列化为字符串
//var options = new JsonSerializerOptions { WriteIndented = true };
//string jsonString = System.Text.Json.JsonSerializer.Serialize(returndata, options);
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else if (action == "alert")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
var obj = JsonConvert.DeserializeObject<MyObject>(task);
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
//obj.cabinetid[] 可以得到要识别的柜子id
//把要识别的柜子id发送给硬件抓图,算法返回数据
//把数据返回给应急平台,将柜子识别完之后返回数据 和算法交流返回的数据
//var result = AlgorithmTCP.Connect(picPath, targetName);
for (int i = 0; i < obj.cabinetid.Length; i++)
{
//调用轨道机方法
Console.WriteLine(obj.cabinetid[i]);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Cabinet/id", obj.cabinetid[i]);
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
}
//算法抓图返回
var result = true;
if (result == true)
{
var returndata = new
{
action = action,
taskid = obj.taskid,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
result = result
};
//将JSON数据对象序列化为字符串
//var options = new JsonSerializerOptions { WriteIndented = true };
//string jsonString = System.Text.Json.JsonSerializer.Serialize(returndata, options);
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
else
{
//获取报警信息
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
//Console.WriteLine(manageLight);
//Console.WriteLine(message);
//Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
var returndata = new
{
action = action,
taskid = obj.taskid,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
result = result
};
//将JSON数据对象序列化为字符串
//var options = new JsonSerializerOptions { WriteIndented = true };
//string jsonString = System.Text.Json.JsonSerializer.Serialize(returndata, options);
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
else if (action == "patrol")
{
var obj = JsonConvert.DeserializeObject<MyObject>(task);
//obj.cabinetid[] 可以得到要识别的柜子id
//把要识别的柜子id发送给硬件抓图,算法返回数据
//把数据返回给应急平台,将柜子识别完之后返回数据 和算法交流返回的数据
//var result = AlgorithmTCP.Connect(picPath, targetName);
for (int i = 0; i < obj.cabinetid.Length; i++)
{
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
//调用轨道机方法
Console.WriteLine(obj.cabinetid[i]);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/CabinetInstance/id", obj.cabinetid[i]);
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("请求失败");
}
}
//发给算法
//模拟的返回数据
var target = new MyClass[]
{
new MyClass{ name = "1号电流表",result = "100.1"},
new MyClass{ name = "3号指示灯",result = "亮"},
new MyClass{ name = "停电牌",result = "无"}
};
var returndata = new
{
action = "identify",
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = 1,
target = target
};
//将JSON数据对象序列化为字符串
//var options = new JsonSerializerOptions { WriteIndented = true };
//string jsonString = System.Text.Json.JsonSerializer.Serialize(returndata, options);
string jsonString = JsonConvert.SerializeObject(returndata);
//将JSON字符串转换为字节数组
byte[] dataBytes = Encoding.UTF8.GetBytes(jsonString);
//发送数据
socket_commu.Send(dataBytes);
Console.WriteLine("发送成功");
}
}
else if (action == "patroltrue")
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
var returndata = new
{
action = action,
taskid = taskId,
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
cabinetid = cabinetId,
targetname = targetName,
result = "true"
};
//将信息存储到数据库
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
}
else
{
//获取要识别的目标名称进行分类
string targetName = json["targetname"].Value<string>();
Console.WriteLine(targetName);
string cabinetId = json["cabinetid"].Value<string>();
string taskId = json["taskid"].Value<string>();
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
string videoPath = $"D:/Video/{DateTime.Now:yyyyMMddHHmmss}.mp4";
//获取报警信息
if (targetName.Contains("电流表") || targetName.Contains("电压表") || targetName.Contains("功率表") || targetName.Contains("断路器"))
{
int startIndex = targetName.Length - 3;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
Console.WriteLine(manageLight);
Console.WriteLine(message);
Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
}
else
{
int startIndex = targetName.Length - 2;
string lastThreeChars = targetName.Substring(startIndex);
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/AlarmType/type", lastThreeChars);
Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
JsonDocument jsonDocument = JsonDocument.Parse(responseBody);
JsonElement dataElement = jsonDocument.RootElement.GetProperty("data");
var manageLight = int.Parse(dataElement.GetProperty("manageLight").GetString());
string message = dataElement.GetProperty("message").GetString();
string manageVoice = dataElement.GetProperty("manageVoice").GetString();
Console.WriteLine(manageLight);
Console.WriteLine(message);
Console.WriteLine(manageVoice);
TcpClientWrapper.SetLedAndVoice(manageLight, manageVoice);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到数据库
//要发送的参数
var parameter = new
{
taskID = taskId,
runModel = "指令模式",
taskName = targetName + "抽检",
startTime = date,
endTime = DateTime.Now,
taskPoint = "点位1",
result = "true",
voiceBroadcast = false,
alarmNumber = 0,
alarmType = lastThreeChars
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Run", parameter);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
//将信息存储到运报警志数据库
//要发送的参数
var parameter1 = new
{
alarmType = lastThreeChars,
alarmPoint = "点位1",
alarmTime = date,
operate = videoPath
};
using (var httpClient = new HttpClient())
{
//发送post请求
var response = await httpClient.PostAsJsonAsync("http://192.168.10.104:8080/api/Alarm", parameter1);
//Console.WriteLine(response);
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
//Console.WriteLine(responseBody);
}
else
{
//处理错误响应
Console.WriteLine("请求失败");
}
}
}
}
}
static async Task<string> StartTimerTask()
{
Task<string> task = TimerTask();
await task;
return task.Result;
}
static async Task<string> TimerTask()
{
string picPath = $"D:/Picture/{DateTime.Now:yyyyMMddHHmmss}.jpeg";
CHNetHelp.JPEG(1, picPath);
return picPath;
}
}
}