fixing build, minimal dependencies

This commit is contained in:
pelikhan 2023-05-18 13:10:49 -07:00
Родитель 53baaeb940
Коммит a9e4ebc4a3
9 изменённых файлов: 17 добавлений и 379 удалений

Просмотреть файл

@ -7,10 +7,6 @@
<ItemGroup>
<ProjectReference Include="..\Jacdac.NET.Clients\Jacdac.NET.Clients.csproj" />
<ProjectReference Include="..\Jacdac.NET.Logging\Jacdac.NET.Logging.csproj" />
<ProjectReference Include="..\Jacdac.NET.Servers.AzureIotHub\Jacdac.NET.Servers.AzureIotHub.csproj" />
<ProjectReference Include="..\Jacdac.NET.Servers.SoundPlayer\Jacdac.NET.Servers.SoundPlayer.csproj" />
<ProjectReference Include="..\Jacdac.NET.Transports.LibUsb\Jacdac.NET.Transports.LibUsb.csproj" />
<ProjectReference Include="..\Jacdac.NET.Transports.Spi\Jacdac.NET.Transports.Spi.csproj" />
<ProjectReference Include="..\Jacdac.NET.Transports.WebSockets\Jacdac.NET.Transports.WebSockets.csproj" />
<ProjectReference Include="..\Jacdac.NET\Jacdac.NET.csproj" />

Просмотреть файл

@ -7,9 +7,14 @@ using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Threading;
#if LOGGING
using Jacdac.Logging;
#endif
using System.Collections.Generic;
#if IOTHUB
using Microsoft.Azure.Devices.Client;
#endif
namespace Jacdac.Playground
{
@ -29,14 +34,18 @@ namespace Jacdac.Playground
services.Add(new SettingsServer(settings));
if (args.Contains("prototest"))
services.Add(new ProtoTestServer());
#if SOUNDS
if (args.Contains("sounds"))
services.Add(new SoundPlayerServer(new NetCoreAudioSoundPlayer("sounds")));
#endif
#if IOTHUB
if (args.Contains("iothub"))
{
var hub = new AzureIoTHubClient(TransportType.Mqtt_Tcp_Only, settings);
services.Add(new AzureIotHubHealthServer(hub));
services.Add(new JacscriptCloudServer(hub));
}
#endif
// create and start bus
var bus = new JDBus(null, new JDBusOptions()
@ -82,9 +91,11 @@ namespace Jacdac.Playground
Console.WriteLine($"adding websocket connection to {url}");
bus.AddTransport(WebSocketTransport.Create(new Uri(url)));
break;
#if LIBUSB
case "libusb":
Console.WriteLine($"adding libusb transport");
bus.AddTransport(Jacdac.Transports.LibUsb.LibUsbTransport.Create());
#endif
break;
}
}

Просмотреть файл

@ -1,140 +0,0 @@
/** Autogenerated file. Do not edit. */
using Jacdac;
using System;
namespace Jacdac.Clients
{
/// <summary>
/// Health and diagnostics information about the Azure Iot Hub connection.
/// Implements a client for the Azure IoT Hub Health service.
/// </summary>
/// <seealso cref="https://microsoft.github.io/jacdac-docs/services/azureiothubhealth/" />
public partial class AzureIotHubHealthClient : Client
{
public AzureIotHubHealthClient(JDBus bus, string name)
: base(bus, name, ServiceClasses.AzureIotHubHealth)
{
}
/// <summary>
/// Tries to read the <c>hub_name</c> register value.
/// Something like `my-iot-hub.azure-devices.net` if available.,
/// </summary>
bool TryGetHubName(out string value)
{
object[] values;
if (this.TryGetRegisterValues((ushort)AzureIotHubHealthReg.HubName, AzureIotHubHealthRegPack.HubName, out values))
{
value = (string)values[0];
return true;
}
else
{
value = default(string);
return false;
}
}
/// <summary>
/// Tries to read the <c>hub_device_id</c> register value.
/// Device identifier in Azure Iot Hub if available.,
/// </summary>
bool TryGetHubDeviceId(out string value)
{
object[] values;
if (this.TryGetRegisterValues((ushort)AzureIotHubHealthReg.HubDeviceId, AzureIotHubHealthRegPack.HubDeviceId, out values))
{
value = (string)values[0];
return true;
}
else
{
value = default(string);
return false;
}
}
/// <summary>
/// Reads the <c>connection_status</c> register value.
/// Indicates the status of connection. A message beyond the [0..3] range represents an HTTP error code.,
/// </summary>
public AzureIotHubHealthConnectionStatus ConnectionStatus
{
get
{
return (AzureIotHubHealthConnectionStatus)this.GetRegisterValue((ushort)AzureIotHubHealthReg.ConnectionStatus, AzureIotHubHealthRegPack.ConnectionStatus);
}
}
/// <summary>
/// Reads the <c>push_period</c> register value.
/// How often to push data to the cloud., _: ms
/// </summary>
public uint PushPeriod
{
get
{
return (uint)this.GetRegisterValue((ushort)AzureIotHubHealthReg.PushPeriod, AzureIotHubHealthRegPack.PushPeriod);
}
set
{
this.SetRegisterValue((ushort)AzureIotHubHealthReg.PushPeriod, AzureIotHubHealthRegPack.PushPeriod, value);
}
}
/// <summary>
/// Reads the <c>push_watchdog_period</c> register value.
/// If no message is published within given period, the device resets.
/// This can be due to connectivity problems or due to the device having nothing to publish.
/// Forced to be at least `2 * flush_period`.
/// Set to `0` to disable (default)., _: ms
/// </summary>
public uint PushWatchdogPeriod
{
get
{
return (uint)this.GetRegisterValue((ushort)AzureIotHubHealthReg.PushWatchdogPeriod, AzureIotHubHealthRegPack.PushWatchdogPeriod);
}
set
{
this.SetRegisterValue((ushort)AzureIotHubHealthReg.PushWatchdogPeriod, AzureIotHubHealthRegPack.PushWatchdogPeriod, value);
}
}
/// <summary>
/// Raised when the connection status changes
/// </summary>
public event ClientEventHandler ConnectionStatusChange
{
add
{
this.AddEvent((ushort)AzureIotHubHealthEvent.ConnectionStatusChange, value);
}
remove
{
this.RemoveEvent((ushort)AzureIotHubHealthEvent.ConnectionStatusChange, value);
}
}
/// <summary>
/// Raised when a message has been sent to the hub.
/// </summary>
public event ClientEventHandler MessageSent
{
add
{
this.AddEvent((ushort)AzureIotHubHealthEvent.MessageSent, value);
}
remove
{
this.RemoveEvent((ushort)AzureIotHubHealthEvent.MessageSent, value);
}
}
}
}

Просмотреть файл

@ -43,21 +43,6 @@ namespace Jacdac.Clients
}
}
/// <summary>
/// Emitted when cloud requests to run some action.
/// </summary>
public event ClientEventHandler CloudCommand
{
add
{
this.AddEvent((ushort)CloudAdapterEvent.CloudCommand, value);
}
remove
{
this.RemoveEvent((ushort)CloudAdapterEvent.CloudCommand, value);
}
}
/// <summary>
/// Emitted when we connect or disconnect from the cloud.
/// </summary>

Просмотреть файл

@ -17,8 +17,8 @@ namespace Jacdac.Clients
/// <param name="rgb"></param>
public void SetColor(uint rgb, uint transitionMilliseconds = 0)
{
var speed = (uint)(transitionMilliseconds <= 0 ? 0 : Math.Max(4, 512 / transitionMilliseconds));
this.Animate((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, speed);
//var speed = (uint)(transitionMilliseconds <= 0 ? 0 : Math.Max(4, 512 / transitionMilliseconds));
//this.Animate((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, speed);
}
}
}

Просмотреть файл

@ -78,7 +78,9 @@ namespace Jacdac
catch (AckException ex)
{
this.free();
#pragma warning disable CA2200 // Rethrow to preserve stack details
throw ex;
#pragma warning restore CA2200 // Rethrow to preserve stack details
}
this._count++;
}

Просмотреть файл

@ -21,10 +21,10 @@ namespace Jacdac.Samples
// grab brightness
var brightness = (uint)(slider.Position * 100);
// blue
led.Animate(0, 0, brightness, speed);
//led.Animate(0, 0, brightness, speed);
Thread.Sleep(500);
// red
led.Animate(brightness, 0, 0, speed);
//led.Animate(brightness, 0, 0, speed);
Thread.Sleep(500);
}
};

Просмотреть файл

@ -1,88 +0,0 @@
using System;
namespace Jacdac.Servers
{
public interface IAzureIoTHubHealth
{
string HubName { get; }
string HubDeviceId { get; }
AzureIotHubHealthConnectionStatus ConnectionStatus { get; }
void Connect();
void Disconnect();
void SetConnectionString(string connectionString);
event EventHandler ConnectionStatusChanged;
event EventHandler MessageSent;
}
public sealed class AzureIotHubHealthServer : JDServiceServer
{
private IAzureIoTHubHealth hub;
private readonly JDDynamicRegisterServer hubNameRegister;
private readonly JDDynamicRegisterServer hubDeviceIdRegister;
private readonly JDDynamicRegisterServer connectionStatusRegister;
public AzureIotHubHealthServer(IAzureIoTHubHealth hub, JDServiceServerOptions options = null)
: base(ServiceClasses.AzureIotHubHealth, options)
{
this.hub = hub;
this.AddRegister(this.hubNameRegister = new JDDynamicRegisterServer((ushort)AzureIotHubHealthReg.HubName, AzureIotHubHealthRegPack.HubName, (server) => new object[] { this.hub.HubName }));
this.AddRegister(this.hubDeviceIdRegister = new JDDynamicRegisterServer((ushort)AzureIotHubHealthReg.HubDeviceId, AzureIotHubHealthRegPack.HubDeviceId, (server) => new object[] { this.hub.HubDeviceId }));
this.AddRegister(this.connectionStatusRegister = new JDDynamicRegisterServer((ushort)AzureIotHubHealthReg.ConnectionStatus, AzureIotHubHealthRegPack.ConnectionStatus, (server) => new object[] { (ushort)this.hub.ConnectionStatus }));
// restricted command
this.AddCommand((ushort)AzureIotHubHealthCmd.SetConnectionString, this.handleSetConnectionString);
this.hub.MessageSent += handleMessageSent;
this.hub.ConnectionStatusChanged += handleConnectionStatusChanged;
}
public override string ToString()
{
return this.hub == null ? "disposed" : $"{this.hub.HubName} in {this.hub.HubDeviceId}: {this.hub.ConnectionStatus}";
}
private void handleConnectionStatusChanged(object sender, EventArgs e)
{
if (this.hub == null)
throw new ObjectDisposedException("server");
var payload = PacketEncoding.Pack(AzureIotHubHealthEventPack.ConnectionStatusChange, new object[] { (ushort)this.hub.ConnectionStatus });
this.SendEvent((ushort)AzureIotHubHealthEvent.ConnectionStatusChange, payload);
}
private void handleMessageSent(object sender, EventArgs e)
{
if (this.hub == null)
throw new ObjectDisposedException("server");
this.SendEvent((ushort)AzureIotHubHealthEvent.MessageSent);
}
private void handleSetConnectionString(JDNode sender, PacketEventArgs args)
{
if (this.hub == null)
throw new ObjectDisposedException("server");
var value = PacketEncoding.UnPack(AzureIotHubHealthCmdPack.SetConnectionString, args.Packet.Data);
var connectionString = (string)value[0];
this.hub.SetConnectionString(connectionString);
}
public override void Dispose()
{
var hub = this.hub;
if (hub != null)
{
this.hub = null;
hub.MessageSent -= handleMessageSent;
hub.ConnectionStatusChanged -= handleConnectionStatusChanged;
}
}
}
}

Просмотреть файл

@ -1,128 +0,0 @@
using System;
namespace Jacdac.Servers
{
[Serializable]
public sealed class TwinChangedEventsArgs
{
public string Path { get; private set; }
public double Value { get; private set; }
public TwinChangedEventsArgs(string path, double value)
{
this.Path = path;
this.Value = value;
}
}
public delegate void TwinChangedEventHandler(IJacscriptCloud sender, TwinChangedEventsArgs args);
[Serializable]
public sealed class CloudCommandEventArgs
{
public uint SequenceNumber { get; private set; }
public string Command { get; private set; }
public double[] Arguments { get; private set; }
public CloudCommandEventArgs(uint sequenceNumber, string command, double[] arguments)
{
this.SequenceNumber = sequenceNumber;
this.Command = command;
this.Arguments = arguments;
}
}
public delegate void CloudCommandEventHandler(IJacscriptCloud cloud, CloudCommandEventArgs args);
public interface IJacscriptCloud
{
bool IsConnected { get; }
void Upload(string label, double[] value);
bool TryGetTwin(string path, out double current);
void SubscribeTwin(string path);
void AckCloudCommand(uint sequenceNumber, double[] result);
event TwinChangedEventHandler TwinChanged;
event CloudCommandEventHandler CloudCommand;
}
/// <summary>
/// A server implementation of the Jascript cloud service
/// </summary>
public sealed class JacscriptCloudServer : JDServiceServer
{
readonly IJacscriptCloud Cloud;
readonly JDDynamicRegisterServer connectedRegister;
public JacscriptCloudServer(IJacscriptCloud cloud, JDServiceServerOptions options = null) : base(ServiceClasses.JacscriptCloud, options)
{
this.Cloud = cloud;
this.AddRegister(this.connectedRegister = new JDDynamicRegisterServer((ushort)JacscriptCloudReg.Connected, JacscriptCloudRegPack.Connected, (args) => new object[] { this.Cloud.IsConnected }));
this.AddCommand((ushort)JacscriptCloudCmd.Upload, this.handleUpload);
this.AddCommand((ushort)JacscriptCloudCmd.GetTwin, this.handleGetTwin);
this.AddCommand((ushort)JacscriptCloudCmd.AckCloudCommand, this.handleAckCloudCommand);
this.Cloud.TwinChanged += handleTwinChange;
this.Cloud.CloudCommand += handleCloudCommand;
}
public override void Dispose()
{
base.Dispose();
this.Cloud.TwinChanged -= handleTwinChange;
this.Cloud.CloudCommand -= handleCloudCommand;
}
private void handleCloudCommand(IJacscriptCloud cloud, CloudCommandEventArgs args)
{
var seqno = args.SequenceNumber;
var command = args.Command;
var arguments = new object[args.Arguments.Length];
for (var i = 0; i < args.Arguments.Length; ++i)
arguments[i] = new object[] { args.Arguments[i] };
var data = PacketEncoding.Pack(JacscriptCloudEventPack.CloudCommand, new object[] { seqno, command, arguments });
this.SendEvent((ushort)JacscriptCloudEvent.TwinChange, data);
}
private void handleTwinChange(IJacscriptCloud sender, TwinChangedEventsArgs args)
{
this.SendEvent((ushort)JacscriptCloudEvent.TwinChange);
}
private void handleUpload(JDNode sender, PacketEventArgs args)
{
var pkt = args.Packet;
var data = pkt.Data;
var values = PacketEncoding.UnPack(JacscriptCloudCmdPack.Upload, data);
var label = (string)values[0];
var value = (double[])values[1];
this.Cloud.Upload(label, value);
}
private void handleGetTwin(JDNode sender, PacketEventArgs args)
{
var pkt = args.Packet;
var data = pkt.Data;
var values = PacketEncoding.UnPack(JacscriptCloudCmdPack.GetTwin, data);
var path = (string)values[0];
double current;
if (this.Cloud.TryGetTwin(path, out current))
{
var reportPayload = PacketEncoding.Pack(JacscriptCloudCmdPack.GetTwinReport, new object[] { path, current });
var reportPkt = Packet.From((ushort)JacscriptCloudCmd.GetTwin, reportPayload);
this.Device.SendPacket(reportPkt);
}
}
private void handleAckCloudCommand(JDNode sender, PacketEventArgs args)
{
var pkt = args.Packet;
var data = pkt.Data;
var values = PacketEncoding.UnPack(JacscriptCloudCmdPack.AckCloudCommand, data);
var seqNo = (uint)values[0];
var res = (object[])values[1];
var results = new double[res.Length];
for (var i = 0; i < res.Length; i++)
results[i] = (double)(((object[])res[i])[0]);
this.Cloud.AckCloudCommand(seqNo, results);
}
}
}