private void PacketArrived(ZigBeeCommunicationsController source, ZigBeeCommunicationsController.Packet packet) { try { if (_log.IsDebugEnabled) { _log.Debug("Packet received [length: " + packet.PacketData.Length + "]\n" + packet.PacketData.ToHexStringWithAscii(16)); } using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext()) { ZigBeeDeviceLog.Finder.LogPacket(ctx, packet); } } catch (Exception ex) { _log.Error("Could not process packet [length: " + packet.PacketData.Length + "]\n" + packet.PacketData.ToHexStringWithAscii(16), ex); } }
public void LogPacket(ZigBeeCoordinatorContext ctx, ZigBeeCommunicationsController.Packet packet) { ZigBeeDevice device = ZigBeeDevice.Finder.FindAddOrUpdate(ctx, packet.Address, packet.NetworkAddress); device.LastPacketDateTime = DateTime.Now; ZigBeeDeviceLog log = new ZigBeeDeviceLog { DateTime = packet.ReceivedDataTime, PacketData = packet.PacketData, ZigBeeDevice = device }; ctx.DbCtx.ZigBeeDeviceLogs.AddObject(log); ctx.DbCtx.SaveChanges(); if (packet is ZigBeeCommunicationsController.ZigBeeReceivePacket) { LogReceivePacket(ctx, device, (ZigBeeCommunicationsController.ZigBeeReceivePacket)packet); } }