-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from meshtastic/wip
Protos
- Loading branch information
Showing
7 changed files
with
531 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Security.Cryptography; | ||
using Meshtastic.Data; | ||
using Meshtastic.Data.MessageFactories; | ||
using Meshtastic.Protobufs; | ||
using Microsoft.Extensions.Logging; | ||
using Spectre.Console.Json; | ||
using Newtonsoft.Json; | ||
|
||
namespace Meshtastic.Cli.CommandHandlers; | ||
|
||
public class RegisterCommandHandlerCommandHandler(DeviceConnectionContext context, CommandContext commandContext) : DeviceCommandHandler(context, commandContext) | ||
{ | ||
public async Task<DeviceStateContainer> Handle() | ||
{ | ||
var wantConfig = new ToRadioMessageFactory().CreateWantConfigMessage(); | ||
var container = await Connection.WriteToRadio(wantConfig, CompleteOnConfigReceived); | ||
Connection.Disconnect(); | ||
return container; | ||
} | ||
|
||
public override async Task OnCompleted(FromRadio packet, DeviceStateContainer container) | ||
{ | ||
Logger.LogInformation("Getting registration info..."); | ||
var key = container.MyNodeInfo.DeviceId; | ||
var user = container.Nodes.Find(n => n.Num == container.MyNodeInfo.MyNodeNum)?.User; | ||
#pragma warning disable CS0612 // Type or member is obsolete | ||
var macAddress = user?.Macaddr; | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
if (key == null || key.All(b => b == 0) || user == null || macAddress == null) | ||
{ | ||
Logger.LogError("Device does not have a valid key or mac address, and cannot be registered."); | ||
return; | ||
} | ||
var jsonForm = JsonConvert.SerializeObject(new | ||
{ | ||
MeshtasticDeviceId = Convert.ToHexString(key.ToByteArray()), | ||
MACAddress = Convert.ToHexString(macAddress.ToByteArray()), | ||
DeviceHardwareId = container.Metadata.HwModel, | ||
container.Metadata.FirmwareVersion, | ||
}); | ||
|
||
var json = new JsonText(jsonForm); | ||
|
||
AnsiConsole.Write( new Panel(json) | ||
.Header("Registration Information") | ||
.Collapse() | ||
.RoundedBorder() | ||
.BorderColor(Color.Blue)); | ||
|
||
await Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Meshtastic.Cli.Binders; | ||
using Meshtastic.Cli.CommandHandlers; | ||
using Meshtastic.Cli.Enums; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meshtastic.Cli.Commands; | ||
|
||
public class RegisterCommand : Command | ||
{ | ||
public RegisterCommand(string name, string description, Option<string> port, Option<string> host, | ||
Option<OutputFormat> output, Option<LogLevel> log) : base(name, description) | ||
{ | ||
this.SetHandler(async (context, commandContext) => | ||
{ | ||
var handler = new RegisterCommandHandlerCommandHandler(context, commandContext); | ||
await handler.Handle(); | ||
}, | ||
new DeviceConnectionBinder(port, host), | ||
new CommandContextBinder(log, output, new Option<uint?>("dest"), new Option<bool>("select-dest"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.