You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
4.1 KiB
C#
124 lines
4.1 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using SlnMesnac.Config;
|
|
using SlnMesnac.Model.AirportApiEntity;
|
|
using SQLitePCL;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Text.Json;
|
|
using TouchSocket.Rpc;
|
|
using TouchSocket.Sockets;
|
|
using TouchSocket.WebApi;
|
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace SlnMesnac.TouchSocket
|
|
{
|
|
public class AirPorthttpClient : BackgroundService
|
|
{
|
|
private readonly AppConfig _appConfig;
|
|
private readonly ILogger<AirPorthttpClient> _logger;
|
|
|
|
public AirPorthttpClient(AppConfig appConfig, ILogger<AirPorthttpClient> logger)
|
|
{
|
|
_appConfig = appConfig;
|
|
_logger = logger;
|
|
}
|
|
|
|
public static WebApiClient AirportAGVClient;
|
|
public static WebApiClient AirportManipulatorClient;
|
|
|
|
private WebApiClient CreateWebApiClient(string IpHost)
|
|
{
|
|
var client = new WebApiClient();
|
|
try
|
|
{
|
|
client.Connect(IpHost);
|
|
_logger.LogInformation(IpHost + "连接成功");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("ERROR: " + ex.Message);
|
|
return null;
|
|
}
|
|
return client;
|
|
}
|
|
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
try
|
|
{
|
|
AirportAGVClient = CreateWebApiClient(_appConfig.AGVIpConfig);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError("ERROR: " + ex.Message);
|
|
return Task.FromException(ex);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string AGVCallRequest()
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:", null, new AGVSingalEntity());
|
|
|
|
return responseValue.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// AGV下发任务请求
|
|
/// </summary>
|
|
/// <param name="aGVStateRequest"></param>
|
|
/// <returns></returns>
|
|
public static AGVResponseEntity<ResponseAddTaskDataEntity> AGVAddTaskRequest(AGVRequestAddTaskEntity addTaskEntity)
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("POST:/api/task/addTask", null, addTaskEntity);
|
|
if (responseValue == null)
|
|
{
|
|
return new AGVResponseEntity<ResponseAddTaskDataEntity>();
|
|
}
|
|
string json = responseValue.ToString();
|
|
if (string.IsNullOrEmpty(json))
|
|
{
|
|
return new AGVResponseEntity<ResponseAddTaskDataEntity>();
|
|
}
|
|
AGVResponseEntity<ResponseAddTaskDataEntity> responseEntity;
|
|
responseEntity = JsonSerializer.Deserialize<AGVResponseEntity<ResponseAddTaskDataEntity>>(json);
|
|
return responseEntity;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取AGV所有信息
|
|
/// </summary>
|
|
/// <param name="aGVStateRequest"></param>
|
|
/// <returns></returns>
|
|
public static AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>> AGVStateRequest()
|
|
{
|
|
JToken responseValue = AirportAGVClient.InvokeT<JToken>("GET:http://192.168.40.81:5102/api/task/robot/getRobot", null);
|
|
if (responseValue == null)
|
|
{
|
|
return new AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>>();
|
|
}
|
|
string json = responseValue.ToString();
|
|
if (string.IsNullOrEmpty(json))
|
|
{
|
|
return new AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>>();
|
|
}
|
|
AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>> ResponseEntity;
|
|
ResponseEntity = JsonSerializer.Deserialize<AGVResponseEntity<List<ResponseRobotAtrributeDataEntity>>>(json);
|
|
return ResponseEntity;
|
|
}
|
|
}
|
|
|
|
}
|