Skip to content

Commit

Permalink
Fix for the new firmware.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddbear committed Feb 2, 2022
1 parent d45abe7 commit cc009f5
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
7 changes: 4 additions & 3 deletions Revelator.io24.Api/Enums/Headphones.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
24 changes: 21 additions & 3 deletions Revelator.io24.Api/Helpers/PackageHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using Revelator.io24.Api.Services;
using System.Text;

namespace Revelator.io24.Api.Helpers
{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Revelator.io24.Api/Messages/Writers/ClientInfoMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Revelator.io24.Api/Messages/Writers/KeepAliveMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Revelator.io24.Api/Messages/Writers/WelcomeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 7 additions & 0 deletions Revelator.io24.Api/Services/BroadcastService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ namespace Revelator.io24.Api.Services
/// </summary>
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;

Expand All @@ -29,6 +32,8 @@ public BroadcastService()
_thread.Start();

_infoWaitHandle = new ManualResetEvent(false);

Current = this;
}

public ushort WaitForFirstBroadcast()
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions Revelator.io24.Api/Services/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte>();

Expand All @@ -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;

Expand All @@ -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<byte>(0x00, 5).ToArray();
//Empty [x..x+3]:
var empty = Enumerable.Repeat<byte>(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;

Expand Down
18 changes: 9 additions & 9 deletions Revelator.io24.TouchPortal/RevelatorIo24Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,30 @@ private void RouteChange(string name, IReadOnlyCollection<ActionDataSelected> 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)
Expand Down

0 comments on commit cc009f5

Please sign in to comment.