mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-29 05:10:45 +08:00
添加GRPC服务用来部署到linux设备如树莓派,通过这些设备和树莓派连接进行web控制,以便于电子脱离pc
This commit is contained in:
@@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronBot.BraincasePrevie
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronBot.BraincasePreview.Tests.MSTest", "src\ElectronBot.BraincasePreview.Tests.MSTest\ElectronBot.BraincasePreview.Tests.MSTest.csproj", "{BE221B1D-5216-4592-90CE-C5B854BF4A33}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebService", "WebService", "{713E0140-982E-4FBF-8F3B-F22093A865CD}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Verdure.ElectronBot.GrpcService", "src\Verdure.ElectronBot.GrpcService\Verdure.ElectronBot.GrpcService.csproj", "{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -95,10 +99,29 @@ Global
|
||||
{BE221B1D-5216-4592-90CE-C5B854BF4A33}.Release|x64.Build.0 = Release|x64
|
||||
{BE221B1D-5216-4592-90CE-C5B854BF4A33}.Release|x86.ActiveCfg = Release|x86
|
||||
{BE221B1D-5216-4592-90CE-C5B854BF4A33}.Release|x86.Build.0 = Release|x86
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|arm64.ActiveCfg = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|arm64.Build.0 = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|arm64.ActiveCfg = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|arm64.Build.0 = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|x64.Build.0 = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{FF25CC1E-90B8-449A-AE9C-20F1504DDAC2} = {713E0140-982E-4FBF-8F3B-F22093A865CD}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0EBF82F3-30A6-4BCC-950A-360C126FC118}
|
||||
EndGlobalSection
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32819.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectronBot.DotNet", "src\ElectronBot.DotNet\ElectronBot.DotNet.csproj", "{8FD16BB5-D953-44CB-8709-A79998337A1C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Verdure.ElectronBot.GrpcService", "src\Verdure.ElectronBot.GrpcService\Verdure.ElectronBot.GrpcService.csproj", "{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|arm64 = Debug|arm64
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|arm64 = Release|arm64
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|arm64.ActiveCfg = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|arm64.Build.0 = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|arm64.ActiveCfg = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|arm64.Build.0 = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8FD16BB5-D953-44CB-8709-A79998337A1C}.Release|x86.Build.0 = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|arm64.ActiveCfg = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|arm64.Build.0 = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|arm64.ActiveCfg = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|arm64.Build.0 = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9FE05D7A-FA55-4C77-8CE7-F1EEF3765999}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0EBF82F3-30A6-4BCC-950A-360C126FC118}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -11,5 +11,17 @@
|
||||
<PackageReference Include="Microsoft.Graph" Version="4.42.0" />
|
||||
<PackageReference Include="Microsoft.Identity.Client" Version="4.47.1" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.21.7" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.49.0" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.49.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.49.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Protos\electronbotaction.proto" GrpcServices="Client" />
|
||||
<Protobuf Include="Protos\greet.proto" GrpcServices="Client" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Verdure.ElectronBot.GrpcService";
|
||||
|
||||
package electronbotactionGrpc;
|
||||
|
||||
// The electronbotaction service definition.
|
||||
service ElectronBotActionGrpc {
|
||||
// Sends a greeting
|
||||
rpc PlayEmoticonAction (EmoticonActionFrameRequest) returns (EbHelloReply);
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
message EmoticonActionFrameRequest {
|
||||
float J1 = 1;
|
||||
float J2 = 2;
|
||||
float J3 = 3;
|
||||
float J4 = 4;
|
||||
float J5 = 5;
|
||||
float J6 = 6;
|
||||
bool Enable = 7;
|
||||
bytes FrameBuffer = 8;
|
||||
}
|
||||
|
||||
// The response message containing the greetings.
|
||||
message EbHelloReply {
|
||||
string message = 9;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Verdure.ElectronBot.GrpcService";
|
||||
|
||||
package greet;
|
||||
|
||||
// The greeting service definition.
|
||||
service Greeter {
|
||||
// Sends a greeting
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// The response message containing the greetings.
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using ElectronBot.BraincasePreview.Core.Models;
|
||||
using Google.Protobuf;
|
||||
using Verdure.ElectronBot.GrpcService;
|
||||
|
||||
namespace ElectronBot.BraincasePreview.Services.EbotGrpcService;
|
||||
public class EbGrpcService
|
||||
{
|
||||
private readonly ElectronBotActionGrpc.ElectronBotActionGrpcClient _client;
|
||||
public EbGrpcService(ElectronBotActionGrpc.ElectronBotActionGrpcClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task<string> PlayEmoticonActionFrameAsync(EmoticonActionFrame frame)
|
||||
{
|
||||
var data = new EmoticonActionFrameRequest
|
||||
{
|
||||
FrameBuffer = ByteString.CopyFrom(frame.FrameBuffer),
|
||||
|
||||
Enable = frame.Enable,
|
||||
J1 = frame.J1,
|
||||
J2 = frame.J2,
|
||||
J3 = frame.J3,
|
||||
J4 = frame.J4,
|
||||
J5 = frame.J5,
|
||||
J6 = frame.J6
|
||||
};
|
||||
var result = await _client.PlayEmoticonActionAsync(data);
|
||||
|
||||
return result.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ using Microsoft.Graphics.Canvas;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Verdure.ElectronBot.GrpcService;
|
||||
using Windows.Media.Playback;
|
||||
|
||||
namespace ElectronBot.BraincasePreview;
|
||||
@@ -138,6 +139,13 @@ public partial class App : Application
|
||||
|
||||
services.AddSingleton<IActionExpressionProviderFactory, ActionExpressionProviderFactory>();
|
||||
|
||||
|
||||
services.AddGrpcClient<ElectronBotActionGrpc.ElectronBotActionGrpcClient>(o =>
|
||||
{
|
||||
o.Address = new Uri("http://192.168.3.236:5241");
|
||||
});
|
||||
|
||||
services.AddSingleton<Services.EbotGrpcService.EbGrpcService>();
|
||||
// Configuration
|
||||
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
|
||||
}).
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
<ItemGroup>
|
||||
<Manifest Include="$(ApplicationManifest)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.0.0" />
|
||||
<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
|
||||
|
||||
+7
-3
@@ -3,6 +3,7 @@ using ElectronBot.BraincasePreview.Contracts.Services;
|
||||
using ElectronBot.BraincasePreview.Core.Models;
|
||||
using ElectronBot.BraincasePreview.Helpers;
|
||||
using ElectronBot.BraincasePreview.Models;
|
||||
using ElectronBot.BraincasePreview.Services.EbotGrpcService;
|
||||
using OpenCvSharp;
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
@@ -49,7 +50,7 @@ public class DefaultActionExpressionProvider : IActionExpressionProvider
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task PlayActionExpressionAsync(string actionName, List<ElectronBotAction> actions)
|
||||
public async Task PlayActionExpressionAsync(string actionName, List<ElectronBotAction> actions)
|
||||
{
|
||||
Mat image = new();
|
||||
|
||||
@@ -108,9 +109,12 @@ public class DefaultActionExpressionProvider : IActionExpressionProvider
|
||||
currentAction.J6);
|
||||
|
||||
EmojiPlayHelper.Current.Enqueue(frameData);
|
||||
|
||||
//通过grpc通讯和树莓派传输数据
|
||||
var grpcClient = App.GetService<EbGrpcService>();
|
||||
|
||||
await grpcClient.PlayEmoticonActionFrameAsync(frameData);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-ef": {
|
||||
"version": "6.0.10",
|
||||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using ElectronBot.DotNet;
|
||||
using Verdure.ElectronBot.GrpcService.Models;
|
||||
|
||||
namespace Verdure.ElectronBot.GrpcService;
|
||||
public class EmojiPlayHelper
|
||||
{
|
||||
private static EmojiPlayHelper _current;
|
||||
public static EmojiPlayHelper Current => _current ??= new EmojiPlayHelper();
|
||||
|
||||
private readonly Queue<EmoticonActionFrame> _actonFrame = new();
|
||||
|
||||
private readonly object _actonFrameLock = new();
|
||||
|
||||
public IElectronLowLevel ElectronLowLevel
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public int Interval
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
var thread = new Thread(RunPlayAsync);
|
||||
|
||||
ElectronLowLevel.Connect();
|
||||
//thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_actonFrame.Clear();
|
||||
}
|
||||
|
||||
private void RunPlayAsync()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (_actonFrameLock)
|
||||
{
|
||||
if (_actonFrame.Count > 10)
|
||||
{
|
||||
var frame = _actonFrame.Dequeue();
|
||||
|
||||
|
||||
if (ElectronLowLevel.IsConnected)
|
||||
{
|
||||
ElectronLowLevel.SetImageSrc(frame.FrameBuffer);
|
||||
ElectronLowLevel.SetJointAngles(frame.J1, frame.J2, frame.J3, frame.J4, frame.J5, frame.J6, frame.Enable);
|
||||
ElectronLowLevel.Sync();
|
||||
}
|
||||
|
||||
Thread.Sleep(Interval);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Enqueue(EmoticonActionFrame frame)
|
||||
{
|
||||
_actonFrame.Enqueue(frame);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
namespace Verdure.ElectronBot.GrpcService.Models;
|
||||
public class EmoticonActionFrame
|
||||
{
|
||||
public byte[] FrameBuffer
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J1
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J2
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J3
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J4
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J5
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public float J6
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public bool Enable
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public EmoticonActionFrame(
|
||||
byte[] imgData,
|
||||
bool enable = false,
|
||||
float j1 = 0,
|
||||
float j2 = 0,
|
||||
float j3 = 0,
|
||||
float j4 = 0,
|
||||
float j5 = 0,
|
||||
float j6 = 0)
|
||||
{
|
||||
FrameBuffer = imgData;
|
||||
J1 = j1;
|
||||
J2 = j2;
|
||||
J3 = j3;
|
||||
J4 = j4;
|
||||
J5 = j5;
|
||||
J6 = j6;
|
||||
Enable = enable;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using ElectronBot.DotNet;
|
||||
using Verdure.ElectronBot.GrpcService;
|
||||
using Verdure.ElectronBot.GrpcService.Services;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Additional configuration is required to successfully run gRPC on macOS.
|
||||
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddGrpc();
|
||||
|
||||
builder.Services.AddSingleton<IElectronLowLevel, ElectronLowLevel>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
EmojiPlayHelper.Current.ElectronLowLevel = app.Services.GetRequiredService<IElectronLowLevel>();
|
||||
|
||||
EmojiPlayHelper.Current.Start();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
app.MapGrpcService<GreeterService>();
|
||||
app.MapGrpcService<ElectronBotActionService>();
|
||||
app.MapGet("/abc", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Verdure.ElectronBot.GrpcService": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5191",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Verdure.ElectronBot.GrpcService";
|
||||
|
||||
package electronbotactiongrpc;
|
||||
|
||||
// The electronbotaction service definition.
|
||||
service ElectronBotActionGrpc {
|
||||
// Sends a greeting
|
||||
rpc PlayEmoticonAction (EmoticonActionFrameRequest) returns (EbHelloReply);
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
message EmoticonActionFrameRequest {
|
||||
float J1 = 1;
|
||||
float J2 = 2;
|
||||
float J3 = 3;
|
||||
float J4 = 4;
|
||||
float J5 = 5;
|
||||
float J6 = 6;
|
||||
bool Enable = 7;
|
||||
bytes FrameBuffer = 8;
|
||||
}
|
||||
|
||||
// The response message containing the greetings.
|
||||
message EbHelloReply {
|
||||
string message = 9;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option csharp_namespace = "Verdure.ElectronBot.GrpcService";
|
||||
|
||||
package greet;
|
||||
|
||||
// The greeting service definition.
|
||||
service Greeter {
|
||||
// Sends a greeting
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
}
|
||||
|
||||
// The request message containing the user's name.
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// The response message containing the greetings.
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using ElectronBot.DotNet;
|
||||
using Grpc.Core;
|
||||
using Verdure.ElectronBot.GrpcService.Models;
|
||||
|
||||
namespace Verdure.ElectronBot.GrpcService.Services;
|
||||
public class ElectronBotActionService : ElectronBotActionGrpc.ElectronBotActionGrpcBase
|
||||
{
|
||||
private readonly ILogger<ElectronBotActionService> _logger;
|
||||
|
||||
private readonly IElectronLowLevel _electronLowLevel;
|
||||
public ElectronBotActionService(ILogger<ElectronBotActionService> logger, IElectronLowLevel electronLowLevel)
|
||||
{
|
||||
_logger = logger;
|
||||
_electronLowLevel = electronLowLevel;
|
||||
}
|
||||
|
||||
public override Task<EbHelloReply> PlayEmoticonAction(
|
||||
EmoticonActionFrameRequest request, ServerCallContext context)
|
||||
{
|
||||
var frameAction = request.FrameBuffer.ToByteArray();
|
||||
|
||||
var actionData = new EmoticonActionFrame(frameAction, request.Enable,
|
||||
request.J1,
|
||||
request.J2,
|
||||
request.J3,
|
||||
request.J4,
|
||||
request.J5,
|
||||
request.J6);
|
||||
|
||||
EmojiPlayHelper.Current.Enqueue(actionData);
|
||||
|
||||
var result = new EbHelloReply() { Message = "ok" };
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Grpc.Core;
|
||||
using Verdure.ElectronBot.GrpcService;
|
||||
|
||||
namespace Verdure.ElectronBot.GrpcService.Services;
|
||||
public class GreeterService : Greeter.GreeterBase
|
||||
{
|
||||
private readonly ILogger<GreeterService> _logger;
|
||||
public GreeterService(ILogger<GreeterService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
|
||||
{
|
||||
return Task.FromResult(new HelloReply
|
||||
{
|
||||
Message = "Hello " + request.Name
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Protos\electronbotaction.proto" GrpcServices="Server" />
|
||||
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ElectronBot.DotNet\ElectronBot.DotNet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
"EndpointDefaults": {
|
||||
"Protocols": "Http2"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user