示例#1
0
 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);
     }
 }
示例#2
0
        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);
            }
        }
示例#3
0
 private void LogReceivePacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, ZigBeeCommunicationsController.ZigBeeReceivePacket packet)
 {
     FiveVoltPacket fiveVoltPacket = FiveVoltPacket.Decode(packet.ReceiveData);
     if (fiveVoltPacket is InvalidFileVoltPacket)
     {
         InvalidFileVoltPacket invalidPacket = (InvalidFileVoltPacket)fiveVoltPacket;
         _log.Error("Invalid five volt packet. Reason \"" + invalidPacket.Reason + "\"");
     }
     else if (fiveVoltPacket is CapabilityFiveVoltPacket)
     {
         CapabilityFiveVoltPacket capabilityFiveVoltPacket = (CapabilityFiveVoltPacket)fiveVoltPacket;
         LogCapabilityFiveVoltPacket(ctx, device, capabilityFiveVoltPacket);
     }
     else if (fiveVoltPacket is CapabilityDataFiveVoltPacket)
     {
         CapabilityDataFiveVoltPacket capabilityDataFiveVoltPacket = (CapabilityDataFiveVoltPacket)fiveVoltPacket;
         LogCapabilityDataFiveVoltPacket(ctx, device, capabilityDataFiveVoltPacket);
     }
     else if (fiveVoltPacket is MessageFiveVoltPacket)
     {
         MessageFiveVoltPacket messageFiveVoltPacket = (MessageFiveVoltPacket)fiveVoltPacket;
         LogMessageFiveVoltPacket(ctx, device, messageFiveVoltPacket);
     }
     else
     {
         _log.Error("Unhandled five volt packet type [" + fiveVoltPacket.GetType() + "]");
     }
 }