private void Register_OnPushEvent(object sender, BCMsg.BCMsgArgs e) { BCMsg _msg = (sender as BCMsg); try { UInt32 RegisteringDeviceUID = _msg.GetPayload().Reverse().ToUInt32(); Console.WriteLine($"Hello device: {RegisteringDeviceUID.ToString("X4")}"); _msg.Dump(); if ((parentDevice as DeviceManager).DevicePathTable.ContainsKey(RegisteringDeviceUID)) { Console.WriteLine($"Hello device: {RegisteringDeviceUID.ToString("X4")}"); UInt16 PathHash = Crc16.ComputeChecksum(((parentDevice as DeviceManager).DevicePathTable[RegisteringDeviceUID] + "/").ToByteArr()); Console.WriteLine($"PathHash {PathHash.ToString("X4"),6} Path: {(parentDevice as DeviceManager).DevicePathTable[RegisteringDeviceUID] + "/" }"); byte[] TempArr = { (byte)(RegisteringDeviceUID >> 24), (byte)(RegisteringDeviceUID >> 16), (byte)(RegisteringDeviceUID >> 8), (byte)(RegisteringDeviceUID), (byte)(PathHash >> 8), (byte)PathHash }; msg.Build(TempArr); //msg.msgUid = rand.Next(); msg.Command = BCMsg.Commande.PUSH; msg.Dump(); BCMsg.WebInterfaceClass web = new BCMsg.WebInterfaceClass(msg); //client.Publish($"{web.subscriber}", web.Export().ToByteArr()); parentDevice.client.Publish($"{web.subscriber}", web.Export().ToByteArr()); } else { Console.WriteLine($"Unknown device: {msg.GetPayload().ToHexString()}"); } } catch (Exception err) { ConsoleEx.Error($"Could not register"); } }
private void Msg_OnPullEvent(object sender, BCMsg.BCMsgArgs e) { ConsoleEx.Notice($"Device {parentDevice.Path} is ready"); foreach (Peripheral peripheral in parentDevice.Peripherals) { ConsoleEx.Notice($"\t{peripheral.Name} {peripheral.LinkedPeripherals.Count() }"); foreach (Peripheral linkedperipheral in peripheral.LinkedPeripherals) { ConsoleEx.Notice($"\tlinked to: {linkedperipheral.Name} {linkedperipheral.GetPathHash().ToString("X4")}"); byte[] tmp = new byte[] { (byte)(peripheral.NameHash >> 8), (byte)peripheral.NameHash, (byte)(linkedperipheral.GetPathHash() >> 8), (byte)(linkedperipheral.GetPathHash()) }; Push(tmp); } } }