From cc009f52649b602e212ff7717cef344f9af9405a Mon Sep 17 00:00:00 2001 From: oddbear Date: Wed, 2 Feb 2022 19:32:57 +0100 Subject: [PATCH] Fix for the new firmware. --- Revelator.io24.Api/Enums/Headphones.cs | 7 +++--- Revelator.io24.Api/Helpers/PackageHelper.cs | 24 ++++++++++++++++--- .../Messages/Writers/ClientInfoMessage.cs | 2 +- .../Messages/Writers/KeepAliveMessage.cs | 2 +- .../Messages/Writers/WelcomeMessage.cs | 2 +- .../Services/BroadcastService.cs | 7 ++++++ Revelator.io24.Api/Services/UpdateService.cs | 12 +++++----- .../RevelatorIo24Plugin.cs | 18 +++++++------- 8 files changed, 50 insertions(+), 24 deletions(-) diff --git a/Revelator.io24.Api/Enums/Headphones.cs b/Revelator.io24.Api/Enums/Headphones.cs index e2c482a..10289e4 100644 --- a/Revelator.io24.Api/Enums/Headphones.cs +++ b/Revelator.io24.Api/Enums/Headphones.cs @@ -4,8 +4,9 @@ public enum Headphones : ushort { //Route: "global/phonesSrc" Unknown = ushort.MaxValue, - Main = 0, // 0: 0x00, 0x00, 0.0f - MixA = 16128, //16128: 0x00, 0x3F, 0.5f - MixB = 16256 //16256: 0x80, 0x3F, 1.0f + //TODO: Not ushort, but uint (should add 2 zero bytes): + Main = 0, // 0: 0x00, 0x00, 0x00, 0x00, 0.0f + MixA = 16128, //16128: 0x00, 0x00, 0x00, 0x3F, 0.5f + MixB = 16256 //16256: 0x00, 0x00, 0x80, 0x3F, 1.0f } } diff --git a/Revelator.io24.Api/Helpers/PackageHelper.cs b/Revelator.io24.Api/Helpers/PackageHelper.cs index d85ac02..60490ab 100644 --- a/Revelator.io24.Api/Helpers/PackageHelper.cs +++ b/Revelator.io24.Api/Helpers/PackageHelper.cs @@ -1,4 +1,5 @@ -using System.Text; +using Revelator.io24.Api.Services; +using System.Text; namespace Revelator.io24.Api.Helpers { @@ -9,13 +10,30 @@ public static byte[] GetHeader() return new byte[] { 0x55, 0x43, 0x00, 0x01 }; } - public static byte[] GetDeviceCustomBytes() + public static byte[] GetFromToBytes() { //Seems to always be this from the device (and inversed pair from service). //Not sure what this is. //66:00:68:00 -> Incomming from service //68:00:66:00 -> Outgoing to service - return new byte[] { 0x68, 0x00, 0x66, 0x00 }; + + //Did change from: 0x68, 0x00, 0x66, 0x00 + // 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); + + var fromTo = new byte[4]; + fromTo[0] = clientIdBytes[0]; + fromTo[1] = clientIdBytes[1]; + fromTo[2] = deviceIdBytes[0]; + fromTo[3] = deviceIdBytes[1]; + + return fromTo; } public static bool IsUcNetPackage(byte[] data, int index = 0) diff --git a/Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs b/Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs index 385481f..46adfa9 100644 --- a/Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs +++ b/Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs @@ -42,7 +42,7 @@ public static byte[] Create() message[7] = messageType[1]; //CustomBytes: - var customBytes = PackageHelper.GetDeviceCustomBytes(); + var customBytes = PackageHelper.GetFromToBytes(); message[8] = customBytes[0]; message[9] = customBytes[1]; message[10] = customBytes[2]; diff --git a/Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs b/Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs index 0cd1700..3d38d44 100644 --- a/Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs +++ b/Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs @@ -27,7 +27,7 @@ public static byte[] Create() message[7] = messageType[1]; //CustomBytes: - var customBytes = PackageHelper.GetDeviceCustomBytes(); + var customBytes = PackageHelper.GetFromToBytes(); message[8] = customBytes[0]; message[9] = customBytes[1]; message[10] = customBytes[2]; diff --git a/Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs b/Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs index 45fa485..3b3e3bd 100644 --- a/Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs +++ b/Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs @@ -27,7 +27,7 @@ public static byte[] Create(ushort monitorPort) message[7] = messageType[1]; //CustomBytes (this is one of the few messages that works without the CustomBytes): - var customBytes = PackageHelper.GetDeviceCustomBytes(); + var customBytes = PackageHelper.GetFromToBytes(); message[8] = customBytes[0]; message[9] = customBytes[1]; message[10] = customBytes[2]; diff --git a/Revelator.io24.Api/Services/BroadcastService.cs b/Revelator.io24.Api/Services/BroadcastService.cs index 5ddce84..15b14e2 100644 --- a/Revelator.io24.Api/Services/BroadcastService.cs +++ b/Revelator.io24.Api/Services/BroadcastService.cs @@ -12,10 +12,13 @@ namespace Revelator.io24.Api.Services /// public class BroadcastService : IDisposable { + public static BroadcastService? Current; + private readonly UdpClient _udpClient; private readonly Thread _thread; public ushort DeviceTcpPort { get; private set; } + public ushort DeviceId { get; private set; } private readonly ManualResetEvent _infoWaitHandle; @@ -29,6 +32,8 @@ public BroadcastService() _thread.Start(); _infoWaitHandle = new ManualResetEvent(false); + + Current = this; } public ushort WaitForFirstBroadcast() @@ -66,7 +71,9 @@ private void Listener() continue; } + //TODO: What if... multiple devices? DeviceTcpPort = BitConverter.ToUInt16(data[4..6]); + DeviceId = BitConverter.ToUInt16(data[8..10]); //1.19 -> 281: //1.21 -> 281: diff --git a/Revelator.io24.Api/Services/UpdateService.cs b/Revelator.io24.Api/Services/UpdateService.cs index 7f03b80..9b49f5c 100644 --- a/Revelator.io24.Api/Services/UpdateService.cs +++ b/Revelator.io24.Api/Services/UpdateService.cs @@ -86,7 +86,7 @@ private void _communicationService_RouteChange(string route, ushort state) } } - public void SetRouteValue(string route, ushort value) + public void SetRouteValue(string route, uint value) { var message = new List(); @@ -104,7 +104,7 @@ public void SetRouteValue(string route, ushort value) length += messageType.Length; //CustomBytes [8..10]: - var customBytes = PackageHelper.GetDeviceCustomBytes(); + var customBytes = PackageHelper.GetFromToBytes(); message.AddRange(customBytes); length += customBytes.Length; @@ -113,13 +113,13 @@ public void SetRouteValue(string route, ushort value) message.AddRange(text); length += text.Length; - //Empty [x..x+5]: - var empty = Enumerable.Repeat(0x00, 5).ToArray(); + //Empty [x..x+3]: + var empty = Enumerable.Repeat(0x00, 3).ToArray(); message.AddRange(empty); length += empty.Length; - //State [x+5..x+7]: - var state = BitConverter.GetBytes(value); //Float, but on two bytes (ints are AA,BB,00,00 this is 00,00,AA,BB + //State [x+3..x+7]: + var state = BitConverter.GetBytes(value); //Float: ON / OFF -> 0.0 / 1.0 -> { 0x00, 0x00, 0x00, 0x00 } / { 0x00, 0x00, 0x80, 0x3F } message.AddRange(state); length += state.Length; diff --git a/Revelator.io24.TouchPortal/RevelatorIo24Plugin.cs b/Revelator.io24.TouchPortal/RevelatorIo24Plugin.cs index 6672c07..7ff5df4 100644 --- a/Revelator.io24.TouchPortal/RevelatorIo24Plugin.cs +++ b/Revelator.io24.TouchPortal/RevelatorIo24Plugin.cs @@ -96,30 +96,30 @@ private void RouteChange(string name, IReadOnlyCollection da _updateService.SetRouteValue(route, value); } - private ushort ActionToValue(string route, string action) + private uint ActionToValue(string route, string action) { if (action == "Turn On") { var value = route.EndsWith("mute") - ? 0 - : 16256; + ? 0u + : 16256u; - return (ushort)value; + return value; } if (action == "Turn Off") { var value = route.EndsWith("mute") - ? 16256 - : 0; + ? 16256u + : 0u; - return (ushort)value; + return value; } var hasRoute = _updateService.Routing.GetValueByRoute(route); return route.EndsWith("mute") - ? (ushort)(hasRoute ? 16256 : 0) - : (ushort)(hasRoute ? 0 : 16256); + ? (hasRoute ? 16256u : 0u) + : (hasRoute ? 0u : 16256u); } private string InputToPart(string input)