//recepcion de paketes 00:00:00:00:00:00:00 private void _bridge_Receive(object sender, PackagesReceivedEventArgs e) { LogProviderManager.Logger.Log(LogType.debug, "Message Receive"); if (e.Packet.Frame.Length <= 0) { return; } if (e.Packet.Frame[0] == CmdGetEui) { Announce(e.Packet.SrcAddr); } else if (e.Packet.Frame[0] == CmdResetEui && e.Packet.Frame.Length >= 9) { var euiAddr = e.Packet.Frame.Skip(1).Take(8).ToArray(); NewDevice?.Invoke(this, new NewDeviceReceivedEventArgs(e.Packet.SrcAddr, euiAddr)); } else { Receive?.Invoke(this, new PackagesReceivedEventArgs(e.Packet)); } }
private void _mesh_Receive(object sender, PackagesReceivedEventArgs e) { var ppk = Parse(e.Packet); var device = DeviceManager.Instance.Devices.FirstOrDefault(a => a.ShortAddress == e.Packet.SrcAddr) ?? DeviceManager.Instance.AddNew(e.Packet.SrcAddr); if ((CommandTypes)ppk.Control.CommandType == CommandTypes.Nack || (CommandTypes)ppk.Control.CommandType == CommandTypes.Ack) { return; } else { if ((CommandTypes)ppk.Control.CommandType == CommandTypes.Event) { LogProviderManager.Logger.LogObject(LogType.warning, "", e.Packet); LogProviderManager.Logger.LogObject(LogType.warning, "", ppk); LogProviderManager.Logger.Log(LogType.warning, "" + string.Join(" ", ppk.Data.Take(8).ToArray().Select(a => a.ToString("X2")))); LogProviderManager.Logger.Log(LogType.warning, Encoding.Default.GetString(ppk.Data.Skip(9).ToArray())); RequestAction(e.Packet.SrcAddr, 0, 0); return; } if ((CommandTypes)ppk.Control.CommandType == CommandTypes.Post) { switch ((Commands)ppk.Command) { case Commands.Eui: device.Address = ppk.Data; LogProviderManager.Logger.Log(LogType.warning, "" + string.Join(" ", device.Address.Select(a => a.ToString("X2")))); break; case Commands.Name: device.Name = Encoding.Default.GetString(ppk.Data); LogProviderManager.Logger.Log(LogType.warning, Encoding.Default.GetString(ppk.Data)); break; case Commands.Class: device.Class = Encoding.Default.GetString(ppk.Data); LogProviderManager.Logger.Log(LogType.warning, Encoding.Default.GetString(ppk.Data)); break; case Commands.NAction: device.ActionsCount = ppk.Data[0]; LogProviderManager.Logger.Log(LogType.warning, device.ActionsCount.ToString()); for (var i = 0; i < device.ActionsCount; i++) { RequestGet(e.Packet.SrcAddr, (byte)Commands.Action, (byte)i, new List <byte>().ToArray()); } break; case Commands.Action: if (ppk.Parameter != null) { if (!device.Actions.ContainsKey(ppk.Parameter.Value)) { device.Actions.Add((int)ppk.Parameter.Value, Encoding.Default.GetString(ppk.Data)); } else { device.Actions[ppk.Parameter.Value] = Encoding.Default.GetString(ppk.Data); } } LogProviderManager.Logger.Log(LogType.warning, Encoding.Default.GetString(ppk.Data)); break; case Commands.NEvents: device.EventCount = ppk.Data[0]; LogProviderManager.Logger.Log(LogType.warning, device.EventCount.ToString()); for (var i = 0; i < device.EventCount; i++) { RequestGet(e.Packet.SrcAddr, (byte)Commands.Event, (byte)i, new List <byte>().ToArray()); } break; case Commands.Event: if (ppk.Parameter != null) { if (!device.Events.ContainsKey(ppk.Parameter.Value)) { device.Events.Add((int)ppk.Parameter.Value, Encoding.Default.GetString(ppk.Data)); } else { device.Events[ppk.Parameter.Value] = Encoding.Default.GetString(ppk.Data); } } LogProviderManager.Logger.Log(LogType.warning, Encoding.Default.GetString(ppk.Data)); break; case Commands.Size: case Commands.NEntries: case Commands.AbsEntry: case Commands.Entry: case Commands.Clear: case Commands.AddEntry: case Commands.DelAbsEntry: case Commands.DelEntry: break; default: throw new ArgumentOutOfRangeException(); } } } LogProviderManager.Logger.Log(LogType.warning, ((Commands)ppk.Command).ToString()); LogProviderManager.Logger.LogObject(LogType.warning, "", e.Packet); }