Skip to content

Commit

Permalink
Merge branch 'feature/abstraction'
Browse files Browse the repository at this point in the history
  • Loading branch information
oddbear committed Feb 9, 2022
2 parents bddb51a + 41773a2 commit 57fa519
Show file tree
Hide file tree
Showing 51 changed files with 1,707 additions and 1,227 deletions.
27 changes: 27 additions & 0 deletions Revelator.io24.Api/Configuration/ServiceProviderExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.DependencyInjection;
using Revelator.io24.Api.Models;
using Revelator.io24.Api.Services;

namespace Revelator.io24.Api.Configuration
{
public static class ServiceProviderExtension
{
public static void AddRevelatorAPI(this IServiceCollection serviceCollection)
{
//Services:
serviceCollection.AddSingleton<BroadcastService>();
serviceCollection.AddSingleton<CommunicationService>();
serviceCollection.AddSingleton<MonitorService>();

//Models:
serviceCollection.AddSingleton<RoutingModel>();
serviceCollection.AddSingleton<MicrophoneModel>();
serviceCollection.AddSingleton<FatChannelMonitorModel>();
serviceCollection.AddSingleton<ValuesMonitorModel>();

//API:
serviceCollection.AddSingleton<RoutingTable>();
serviceCollection.AddSingleton<Microphones>();
}
}
}
12 changes: 10 additions & 2 deletions Revelator.io24.Api/Enums/Headphones.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
namespace Revelator.io24.Api.Enums
using System.ComponentModel;

namespace Revelator.io24.Api.Enums
{
//TODO: This can be changed to Output.
public enum Headphones : ushort
{
//Route: "global/phonesSrc"
Unknown = ushort.MaxValue,
//TODO: Not ushort, but uint (should add 2 zero bytes):

[Description("Main")]
Main = 0, // 0: 0x00, 0x00, 0x00, 0x00, 0.0f

[Description("Stream Mix A")]
MixA = 16128, //16128: 0x00, 0x00, 0x00, 0x3F, 0.5f

[Description("Stream Mix B")]
MixB = 16256 //16256: 0x00, 0x00, 0x80, 0x3F, 1.0f
}
}
9 changes: 9 additions & 0 deletions Revelator.io24.Api/Enums/Value.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Revelator.io24.Api.Enums
{
public enum Value
{
On,
Off,
Toggle
}
}
5 changes: 1 addition & 4 deletions Revelator.io24.Api/Helpers/PackageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static byte[] GetHeader()
return new byte[] { 0x55, 0x43, 0x00, 0x01 };
}

public static byte[] GetFromToBytes()
public static byte[] GetFromToBytes(ushort deviceId)
{
//Seems to always be this from the device (and inversed pair from service).
//Not sure what this is.
Expand All @@ -21,9 +21,6 @@ public static byte[] GetFromToBytes()
// to: 0x68, 0x00, 0x6b, 0x00
// from firmware 1.19 to 1.21... interesting.
//6b is a part of the broadcast message, and needs to be the same... the 0x68 can be changed.

var deviceId = BroadcastService.Current?.DeviceId ?? throw new InvalidOperationException("DeviceId not received yet.");

var clientIdBytes = BitConverter.GetBytes(104);
var deviceIdBytes = BitConverter.GetBytes(deviceId);

Expand Down
3 changes: 2 additions & 1 deletion Revelator.io24.Api/Messages/Readers/JM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public static string GetJsonMessage(byte[] data)
var header = data[0..4];
var messageLength = data[4..6];
var messageType = data[6..8];
var customBytes = data[8..12];
var from = data[8..10];
var to = data[10..12];

var size = BitConverter.ToInt32(data[12..16]);

Expand Down
3 changes: 2 additions & 1 deletion Revelator.io24.Api/Messages/Readers/ZM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static string GetJsonMessage(byte[] data)
var header = data[0..4];
var messageLength = data[4..6];
var messageType = data[6..8];
var customBytes = data[8..12];
var from = data[8..10];
var to = data[10..12];

var size = BitConverter.ToInt32(data[12..16]);

Expand Down
115 changes: 115 additions & 0 deletions Revelator.io24.Api/Messages/TcpMessageWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System.Text;
using System.Text.Json;

namespace Revelator.io24.Api.Messages
{
public class TcpMessageWriter
{
private readonly ushort _deviceId;

public TcpMessageWriter(ushort deviceId)
{
_deviceId = deviceId;
}

public byte[] CreateClientInfoMessage()
{
var data = CreateHeader(_deviceId);

var json = JsonSerializer.Serialize(new
{
id = "Subscribe",
clientName = "UC-Surface",
clientInternalName = "ucremoteapp",
clientType = "CustomAPI",
clientDescription = "CustomAPI for Revelator io24",
clientIdentifier = "661b1ece-b4d3-44b3-913c-d12964456f0b",
clientOptions = "perm users",
clientEncoding = 23117
});

//JsonLength [12..16]:
data.AddRange(BitConverter.GetBytes(json.Length));

//Json [16..]
data.AddRange(Encoding.ASCII.GetBytes(json));

return Create(data, "JM");
}

public byte[] CreateKeepAliveMessage()
{
var data = CreateHeader(_deviceId);

return Create(data, "KA");
}

public byte[] CreateWelcomeMessage(ushort monitorPort)
{
var data = CreateHeader(_deviceId);

//Port [12..14]:
data.AddRange(BitConverter.GetBytes(monitorPort));

return Create(data, "UM");
}

public byte[] CreateRouteUpdate(string route, float value)
{
var data = CreateHeader(_deviceId);

//Text [12..x]:
data.AddRange(Encoding.ASCII.GetBytes(route));

//Empty [0..3]:
data.AddRange(new byte[] { 0x00, 0x00, 0x00 });

//State [x+3..x+7]:
data.AddRange(BitConverter.GetBytes(value));

return Create(data, "PV");
}

private static byte[] Create(List<byte> data, string messageType)
{
//Length [4..6]:
var length = (ushort)(data.Count - 6);
var lengthBytes = BitConverter.GetBytes(length);
data[4] = lengthBytes[0];
data[5] = lengthBytes[1];

//MessageType [6..8]:
var messageTypeBytes = Encoding.ASCII.GetBytes(messageType);
if (messageTypeBytes.Length != 2)
throw new InvalidOperationException("Messagetype must be two bytes.");

data[6] = messageTypeBytes[0];
data[7] = messageTypeBytes[1];

return data.ToArray();
}

private static List<byte> CreateHeader(ushort deviceId)
{
var data = new List<byte>();

//Header [0..4]:
data.AddRange(Encoding.ASCII.GetBytes("UC"));
data.AddRange(BitConverter.GetBytes((ushort)256));

//Length [4..6] (placeholder):
data.AddRange(new byte[] { 0x00, 0x00 });

//MessageType [6..8] (placeholder):
data.AddRange(new byte[] { 0x00, 0x00 });

//From [8..10]:
data.AddRange(BitConverter.GetBytes((ushort)104));

//To [10..12]:
data.AddRange(BitConverter.GetBytes(deviceId));

return data;
}
}
}
66 changes: 0 additions & 66 deletions Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs

This file was deleted.

39 changes: 0 additions & 39 deletions Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs

This file was deleted.

44 changes: 0 additions & 44 deletions Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs

This file was deleted.

Loading

0 comments on commit 57fa519

Please sign in to comment.