// Constructor for PacketCallBackFromReader public PacketWrapper(PacketData.PacketBase Packet, PacketType type, byte[] packetData, int requestNumber, long elapsedMs, int readerIndex, string readerName) { _packet = Packet; _packetType = type; _requestNumber = requestNumber; _elapsedMs = elapsedMs; _readerIndex = readerIndex; _readerName = readerName; _rawPacket = packetData.Clone() as byte[]; _isPseudoPacket = false; }
/// <summary> /// Returns the packetType for a instance of one of the packet layouts classes. /// </summary> /// <param name="packet">The packet instance</param> /// <returns>Returns the Packet Type or return packetType.U_N_D_F_I_N_E_D if the packet is unknown or has no type.</returns> public static PacketType GetPacketType(PacketData.PacketBase packet) { if (packet == null) { System.Diagnostics.Debug.Assert(false, "null packet"); throw new ArgumentNullException("packet", "Null packet pass to RFIDInterface.PacketData.GetPacketType()"); } switch (packet.GetType().Name) { case "Preamble": return PacketType.U_N_D_F_I_N_E_D; case "cmd_beg": return PacketType.CMD_BEGIN; case "cmd_end": return PacketType.CMD_END; case "cmd_active": return PacketType.COMMAND_ACTIVE; case "ant_cyc_beg": return PacketType.ANTENNA_CYCLE_BEGIN; case "ant_cyc_end": return PacketType.ANTENNA_CYCLE_END; case "ant_cyc_beg_diag": return PacketType.ANTENNA_CYCLE_BEGIN_DIAG; case "ant_cyc_end_diag": return PacketType.ANTENNA_CYCLE_END_DIAG; case "ant_beg": return PacketType.ANTENNA_BEGIN; case "ant_end": return PacketType.ANTENNA_END; case "ant_beg_diag": return PacketType.ANTENNA_BEGIN_DIAG; case "ant_end_diag": return PacketType.ANTENNA_END_DIAG; case "inv_rnd_beg": return PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN; case "inv_rnd_end": return PacketType.ISO18K6C_INVENTORY_ROUND_END; case "inv_rnd_beg_diag": return PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN_DIAG; case "inv_rnd_end_diag": return PacketType.ISO18K6C_INVENTORY_ROUND_END_DIAG; case "inventory": return PacketType.ISO18K6C_INVENTORY; case "inventory_diag": return PacketType.ISO18K6C_INVENTORY_DIAG; case "Iso18k6c_access": return PacketType.ISO18K6C_TAG_ACCESS; case "freq_hop_diag": return PacketType.FREQUENCY_HOP_DIAG; case "noncrit_fault": return PacketType.NONCRITICAL_FAULT; case "debug": return PacketType.DEBUG; default: return PacketType.U_N_D_F_I_N_E_D; } }
public PacketWrapper(PacketData.PacketBase Packet, PacketType type) { _packet = Packet; _packetType = type; }
} //private void SavePacket(PacketData.PacketWrapper envelope) /// <summary> /// /// </summary> /// <param name="envelope"></param> private void ProcessPacket( PacketData.PacketWrapper envelope ) { Debug.Assert( envelope.ReaderName == Name ); PacketData.PacketBase packet = envelope.Packet; PacketData.PacketType type = envelope.PacketType; if ( envelope.IsPseudoPacket ) { PacketData.CommandPsuedoPacket psuedo = envelope.Packet as PacketData.CommandPsuedoPacket; Debug.Assert( psuedo != null ); if ( psuedo != null ) { switch ( psuedo.RequestName ) { case "Inventory": case "Tag Access": ReaderRequest readerRequest = new ReaderRequest( ); using ( MemoryStream data = new MemoryStream( psuedo.DataValues ) ) { readerRequest.ReadFrom( data ); } ReaderRequestData.Add( readerRequest ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Exchange( ref _processedCmdReadCount, ProcessedInventoryCount ); #pragma warning restore 420 break; case "BadPacket": BadPacket badPacket = new BadPacket( ); using ( MemoryStream data = new MemoryStream( psuedo.DataValues ) ) { badPacket.ReadFrom( data ); } PacketStream packetStream = new PacketStream( ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call packetStream.packetSequence = System.Threading.Interlocked.Increment( ref _processedPacketIndex ); #pragma warning restore 420 packetStream.readerID = envelope.ReaderIndex; packetStream.reader = envelope.ReaderName; packetStream.packetTime = envelope.Timestamp; packetStream.packetType = "bad packet"; packetStream.elapsedTimeMs = envelope.ElapsedTimeMs; packetStream.requestNumber = envelope.CommandNumber; packetStream.readerIndex = envelope.ReaderIndex; packetStream.rawPacketData = badPacket.RawPacketData; packetStream.packetData = badPacket.RawPacketData == null ? null : BitConverter.ToString( badPacket.RawPacketData ); packetStream.isPseudoPacket = true; PacketStreamData.Add( packetStream ); badPacket.readerID = envelope.ReaderIndex; badPacket.packetData = packetStream.packetData; badPacket.packetSequence = packetStream.packetSequence; badPacket.requestSequence = envelope.CommandNumber; BadPacketData.Add( badPacket ); break; default: Debug.Assert( false ); break; } } } else { PacketStream packetStream = new PacketStream( ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call packetStream.packetSequence = System.Threading.Interlocked.Increment( ref _processedPacketIndex ); #pragma warning restore 420 packetStream.readerID = envelope.ReaderIndex; packetStream.reader = envelope.ReaderName; packetStream.packetTime = envelope.Timestamp; packetStream.packetType = envelope.PacketTypeName; packetStream.elapsedTimeMs = envelope.ElapsedTimeMs; packetStream.requestNumber = envelope.CommandNumber; packetStream.readerIndex = envelope.ReaderIndex; packetStream.rawPacketData = envelope.RawPacket; packetStream.packetData = BitConverter.ToString( envelope.RawPacket ); packetStream.isPseudoPacket = false; PacketStreamData.Add( packetStream ); switch ( type ) { case PacketData.PacketType.CMD_BEGIN: { _commandTagList.Clear( ); _antennaCycleTagList.Clear( ); _antennaTagList.Clear( ); _inventoryCycleTagList.Clear( ); _inventoryRoundTagList.Clear( ); LastUsedAntenna = null; PacketData.cmd_beg cmd_beg = packet as PacketData.cmd_beg; Debug.Assert( cmd_beg != null ); BitVector32 flags = new BitVector32( cmd_beg.flags ); ReaderCommand readerCommand = new ReaderCommand( ); readerCommand.packetSequence = envelope.PacketNumber; readerCommand.readerID = envelope.ReaderIndex; readerCommand.packetTime = envelope.Timestamp; readerCommand.commandStartTime = envelope.ElapsedTimeMs; readerCommand.startingTagCount = ProcessedInventoryCount; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call readerCommand.commandSequence = System.Threading.Interlocked.Increment( ref _processedCommandIndex ); #pragma warning restore 420 readerCommand.continuousModeFlag = flags[ PacketData.PacketBase.continuousMode ] == ( int ) PacketData.PacketBase.ContinuousModeFlag.InContinuousMode ? "Yes" : "No"; readerCommand.commandType = PacketData.PacketBase.GetCommandName( cmd_beg.command ); readerCommand.cmd_begTime = cmd_beg.ms_ctr; ReaderCommandData.Add( readerCommand ); } break; case PacketData.PacketType.CMD_END: { PacketData.cmd_end cmd_end = packet as PacketData.cmd_end; Debug.Assert( cmd_end != null ); // TODO: Remove Debug Code // cmd_end.ms_ctr = FakeTime; if ( ReaderCommandData.Contains( _processedCommandIndex ) ) { ReaderCommand readerCommand = ( ReaderCommand ) ReaderCommandData[ _processedCommandIndex ]; readerCommand.commandEndTime = envelope.ElapsedTimeMs; readerCommand.tagCount = ProcessedInventoryCount - readerCommand.startingTagCount; readerCommand.elapsedTime = readerCommand.CommandEndTime - readerCommand.CommandStartTime; readerCommand.cmd_endTime = cmd_end.ms_ctr; readerCommand.cmd_delta = readerCommand.cmd_endTime - readerCommand.cmd_begTime; readerCommand.commandResult = PacketData.PacketBase.GetResultName( cmd_end.Result ); if ( readerCommand.TagCount > 0 && readerCommand.elapsedTime > 0 ) readerCommand.singulationRate = readerCommand.TagCount / ( readerCommand.elapsedTime / 1000f ); readerCommand.uniqueTagCount = CommandUniqueTags; ReaderCommandData[ _processedCommandIndex ] = readerCommand; } else { Debug.Assert( false, "Unable to find ReaderCommandData for " + _processedCommandIndex.ToString( ) ); } if ( ReaderRequestData.Contains( envelope.CommandNumber ) ) { ReaderRequest readerRequest = ( ReaderRequest ) ReaderRequestData[ envelope.CommandNumber ]; readerRequest.endTime = envelope.Timestamp; readerRequest.requestEndTime = envelope.ElapsedTimeMs; readerRequest.elapsedTime = readerRequest.RequestEndTime - readerRequest.RequestStartTime; readerRequest.packetCount = ProcessedPacketCount - readerRequest.startingPacketCount; readerRequest.tagCount = ProcessedInventoryCount - readerRequest.startingTagCount; if ( readerRequest.TagCount > 0 && readerRequest.elapsedTime > 0 ) readerRequest.singulationRate = readerRequest.TagCount / ( readerRequest.elapsedTime / 1000f ); ReaderRequestData[ envelope.CommandNumber ] = readerRequest; } else { Debug.Assert( false, "Unable to find ReaderRequestData for " + envelope.CommandNumber.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_CYCLE_BEGIN: { _antennaCycleTagList.Clear( ); _antennaTagList.Clear( ); _inventoryCycleTagList.Clear( ); _inventoryRoundTagList.Clear( ); PacketData.ant_cyc_beg cyc_beg = packet as PacketData.ant_cyc_beg; Debug.Assert( cyc_beg != null ); ReaderAntennaCycle readerCycle = new ReaderAntennaCycle( ); readerCycle.packetSequence = envelope.PacketNumber; readerCycle.readerID = envelope.ReaderIndex; readerCycle.packetTime = envelope.Timestamp; readerCycle.startingAntennaCount = ProcessedAntennaCount; readerCycle.startingTagCount = ProcessedInventoryCount; readerCycle.cycleStartTime = envelope.ElapsedTimeMs; readerCycle.commandSequence = _processedCommandIndex; readerCycle.startingInventoryCycleCount = ProcessedInventoryCycleCount; readerCycle.startingRoundCount = ProcessedRoundCount; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call readerCycle.cycleSequence = System.Threading.Interlocked.Increment( ref _processedAntennaCycleIndex ); #pragma warning restore 420 ReaderAntennaCycleData.Add( readerCycle ); } break; case PacketData.PacketType.ANTENNA_CYCLE_BEGIN_DIAG: { PacketData.ant_cyc_beg_diag cyc_beg_diag = packet as PacketData.ant_cyc_beg_diag; Debug.Assert( cyc_beg_diag != null ); if ( ReaderAntennaCycleData.Contains( _processedAntennaCycleIndex ) ) { ReaderAntennaCycle readerCycle = ( ReaderAntennaCycle ) ReaderAntennaCycleData[ _processedAntennaCycleIndex ]; readerCycle.cyc_begTime = cyc_beg_diag.ms_ctr; ReaderAntennaCycleData[ _processedAntennaCycleIndex ] = readerCycle; } else { Debug.Assert( false, "Unable to find ReaderCycleData for " + _processedAntennaCycleIndex.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_CYCLE_END: { PacketData.ant_cyc_end cyc_end = packet as PacketData.ant_cyc_end; Debug.Assert( cyc_end != null ); if ( ReaderAntennaCycleData.Contains( _processedAntennaCycleIndex ) ) { ReaderAntennaCycle readerCycle = ( ReaderAntennaCycle ) ReaderAntennaCycleData[ _processedAntennaCycleIndex ]; readerCycle.cycleEndTime = envelope.ElapsedTimeMs; readerCycle.endingAntennaCount = ProcessedAntennaCount; readerCycle.endingTagCount = ProcessedInventoryCount; readerCycle.uniqueTagCount = AntennaCycleUniqueTags; readerCycle.endingInventoryCycleCount = ProcessedInventoryCycleCount; readerCycle.endingRoundCount = ProcessedRoundCount; ReaderAntennaCycleData[ _processedAntennaCycleIndex ] = readerCycle; } else { Debug.Assert( false, "Unable to find ReaderCycleData for " + _processedAntennaCycleIndex.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_CYCLE_END_DIAG: { PacketData.ant_cyc_end_diag cyc_end_diag = packet as PacketData.ant_cyc_end_diag; Debug.Assert( cyc_end_diag != null ); if ( ReaderAntennaCycleData.Contains( _processedAntennaCycleIndex ) ) { ReaderAntennaCycle readerCycle = ( ReaderAntennaCycle ) ReaderAntennaCycleData[ _processedAntennaCycleIndex ]; readerCycle.cyc_endTime = cyc_end_diag.ms_ctr; ReaderAntennaCycleData[ _processedAntennaCycleIndex ] = readerCycle; } else { Debug.Assert( false, "Unable to find ReaderCycleData for " + _processedAntennaCycleIndex.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_BEGIN: { _antennaTagList.Clear( ); _inventoryCycleTagList.Clear( ); _inventoryRoundTagList.Clear( ); PacketData.ant_beg ant_beg = packet as PacketData.ant_beg; Debug.Assert( ant_beg != null ); AntennaPacket antennaCycle = new AntennaPacket( ); antennaCycle.readerID = envelope.ReaderIndex; antennaCycle.packetTime = envelope.Timestamp; antennaCycle.antennaStartTime = envelope.ElapsedTimeMs; antennaCycle.startingTagCount = ProcessedInventoryCount; antennaCycle.commandSequence = _processedCommandIndex; antennaCycle.cycleSequence = _processedAntennaCycleIndex; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call antennaCycle.antennaSequence = System.Threading.Interlocked.Increment( ref _processedAntennaIndex ); #pragma warning restore 420 antennaCycle.antennaNumber = ant_beg.antenna; AntennaCycleData.Add( antennaCycle ); LastUsedAntenna = ant_beg.antenna; } break; case PacketData.PacketType.ANTENNA_END: { PacketData.ant_end ant_end = packet as PacketData.ant_end; Debug.Assert( ant_end != null ); if ( AntennaCycleData.Contains( _processedAntennaIndex ) ) { AntennaPacket antennaCycle = ( AntennaPacket ) AntennaCycleData[ _processedAntennaIndex ]; antennaCycle.antennaEndTime = envelope.ElapsedTimeMs; if ( antennaCycle.antennaEndTime != null && antennaCycle.antennaStartTime != null ) { antennaCycle.elapsedTime = antennaCycle.antennaEndTime - antennaCycle.antennaStartTime; } antennaCycle.tagCount = ProcessedInventoryCount - antennaCycle.startingTagCount; if ( antennaCycle.TagCount > 0 && antennaCycle.elapsedTime > 0 ) antennaCycle.singulationRate = antennaCycle.TagCount / ( antennaCycle.elapsedTime / 1000f ); antennaCycle.uniqueTagCount = AntennaUniqueTags; AntennaCycleData[ _processedAntennaIndex ] = antennaCycle; } else { Debug.Assert( false, "Unable to find AntennaCycleData for " + _processedAntennaIndex.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_BEGIN_DIAG: { PacketData.ant_beg_diag ant_beg_diag = packet as PacketData.ant_beg_diag; Debug.Assert( ant_beg_diag != null ); if ( AntennaCycleData.Contains( _processedAntennaIndex ) ) { AntennaPacket antennaCycle = ( AntennaPacket ) AntennaCycleData[ _processedAntennaIndex ]; antennaCycle.ant_begTime = ant_beg_diag.ms_ctr; antennaCycle.senseResistorValue = ant_beg_diag.sense_res; AntennaCycleData[ _processedAntennaIndex ] = antennaCycle; } else { Debug.Assert( false, "Unable to find AntennaCycleData for " + _processedAntennaIndex.ToString( ) ); } } break; case PacketData.PacketType.ANTENNA_END_DIAG: { PacketData.ant_end_diag ant_end_diag = packet as PacketData.ant_end_diag; Debug.Assert( ant_end_diag != null ); //TODO: Remove Debug Code //ant_end_diag.ms_ctr = FakeTime; if ( AntennaCycleData.Contains( _processedAntennaIndex ) ) { AntennaPacket antennaCycle = ( AntennaPacket ) AntennaCycleData[ _processedAntennaIndex ]; antennaCycle.ant_endTime = ant_end_diag.ms_ctr; if ( antennaCycle.ant_endTime != null && antennaCycle.ant_begTime != null ) { antennaCycle.ant_delta = antennaCycle.ant_endTime - antennaCycle.ant_begTime; } AntennaCycleData[ _processedAntennaIndex ] = antennaCycle; } else { Debug.Assert( false, "Unable to find AntennaCycleData for " + _processedAntennaIndex.ToString( ) ); } } break; case PacketData.PacketType.INVENTORY_CYCLE_BEGIN: { _inventoryCycleTagList.Clear( ); _inventoryRoundTagList.Clear( ); PacketData.inv_cyc_beg inv_cyc_beg = packet as PacketData.inv_cyc_beg; Debug.Assert( inv_cyc_beg != null ); InventoryCycle inventoryCycle = new InventoryCycle( ); inventoryCycle.packetTime = envelope.Timestamp; inventoryCycle.readerID = envelope.ReaderIndex; inventoryCycle.packetSequence = envelope.PacketNumber; inventoryCycle.commandSequence = _processedCommandIndex; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call inventoryCycle.cycleSequence = System.Threading.Interlocked.Increment( ref _processedInventoryCycleIndex ); #pragma warning restore 420 inventoryCycle.cycleStartTime = envelope.ElapsedTimeMs; inventoryCycle.startingTagCount = ProcessedInventoryCount; inventoryCycle.startingRoundCount = ProcessedInventoryCount; inventoryCycle.inv_cyc_begTime = inv_cyc_beg.ms_ctr; inventoryCycle.antennaNumber = LastUsedAntenna; int index = InventoryCycleData.Add( inventoryCycle ); Debug.Assert( index == inventoryCycle.cycleSequence ); } break; case PacketData.PacketType.INVENTORY_CYCLE_END: { PacketData.inv_cyc_end inv_cyc_end = packet as PacketData.inv_cyc_end; Debug.Assert( inv_cyc_end != null ); if ( InventoryCycleData.Contains( _processedInventoryCycleIndex ) ) { InventoryCycle inventoryCycle = ( InventoryCycle ) InventoryCycleData[ _processedInventoryCycleIndex ]; inventoryCycle.cycleEndTime = envelope.ElapsedTimeMs; inventoryCycle.endingTagCount = ProcessedInventoryCount; inventoryCycle.uniqueTagCount = InventoryCycleUniqueTags; inventoryCycle.endingRoundCount = ProcessedInventoryCount; inventoryCycle.endingRoundCount = ProcessedRoundCount; inventoryCycle.inv_cyc_endTime = inv_cyc_end.ms_ctr; InventoryCycleData[ _processedInventoryCycleIndex ] = inventoryCycle; } else { Debug.Assert( false, "Unable to find InventoryCycleData for " + _processedInventoryCycleIndex.ToString( ) ); } } break; case PacketData.PacketType.CARRIER_INFO: { PacketData.carrier_info carrier_info = packet as PacketData.carrier_info; Debug.Assert( carrier_info != null ); } break; case PacketData.PacketType.INVENTORY_CYCLE_END_DIAGS: { PacketData.inv_cyc_end_diag inv_cyc_end_diag = packet as PacketData.inv_cyc_end_diag; Debug.Assert( inv_cyc_end_diag != null ); if ( InventoryCycleData.Contains( _processedInventoryCycleIndex ) ) { InventoryCycle inventoryCycle = ( InventoryCycle ) InventoryCycleData[ _processedInventoryCycleIndex ]; inventoryCycle.querys = inv_cyc_end_diag.querys; inventoryCycle.rn16rcv = inv_cyc_end_diag.rn16rcv; inventoryCycle.rn16Timeouts = inv_cyc_end_diag.rn16to; inventoryCycle.epcTimeouts = inv_cyc_end_diag.epcto; inventoryCycle.goodReads = inv_cyc_end_diag.good_reads; inventoryCycle.crcFailures = inv_cyc_end_diag.crc_failures; InventoryCycleData[ _processedInventoryCycleIndex ] = inventoryCycle; } else { Debug.Assert( false, "Unable to find InventoryCycleData for " + _processedInventoryCycleIndex.ToString( ) ); } } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN: { _inventoryRoundTagList.Clear( ); PacketData.inv_rnd_beg inv_rnd_beg = packet as PacketData.inv_rnd_beg; Debug.Assert( inv_rnd_beg != null ); InventoryRound inventoryRound = new InventoryRound( ); inventoryRound.packetSequence = envelope.PacketNumber; inventoryRound.readerID = envelope.ReaderIndex; inventoryRound.packetTime = envelope.Timestamp; inventoryRound.commandSequence = _processedCommandIndex; inventoryRound.cycleSequence = _processedAntennaCycleIndex; inventoryRound.antennaSequence = _processedAntennaIndex; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call inventoryRound.roundSequence = System.Threading.Interlocked.Increment( ref _processedRoundIndex ); #pragma warning restore 420 inventoryRound.roundStartTime = envelope.ElapsedTimeMs; inventoryRound.startingTagCount = ProcessedInventoryCount; inventoryRound.antennaNumber = LastUsedAntenna; int index = InventoryRoundData.Add( inventoryRound ); Debug.Assert( index == inventoryRound.roundSequence ); } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN_DIAG: { PacketData.inv_rnd_beg_diag inv_rnd_beg_diag = packet as PacketData.inv_rnd_beg_diag; Debug.Assert( inv_rnd_beg_diag != null ); if ( InventoryRoundData.Contains( _processedRoundIndex ) ) { InventoryRound inventoryRound = ( InventoryRound ) InventoryRoundData[ _processedRoundIndex ]; inventoryRound.inv_rnd_begTime = inv_rnd_beg_diag.ms_ctr; inventoryRound.singulationParameters = inv_rnd_beg_diag.sing_params; BitVector32 parameters = new BitVector32( ( int ) inv_rnd_beg_diag.sing_params ); InventoryRoundData[ _processedRoundIndex ] = inventoryRound; } else { Debug.Assert( false, "Unable to find InventoryRoundData for " + _processedRoundIndex.ToString( ) ); } } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_END: { PacketData.inv_rnd_end inv_rnd_end = packet as PacketData.inv_rnd_end; Debug.Assert( inv_rnd_end != null ); if ( InventoryRoundData.Contains( _processedRoundIndex ) ) { InventoryRound inventoryRound = ( InventoryRound ) InventoryRoundData[ _processedRoundIndex ]; inventoryRound.roundEndTime = envelope.ElapsedTimeMs; inventoryRound.endingTagCount = ProcessedInventoryCount; inventoryRound.uniqueTagCount = InventoryRoundUniqueTags; InventoryRoundData[ _processedRoundIndex ] = inventoryRound; } else { Debug.Assert( false, "Unable to find InventoryRoundData for " + _processedRoundIndex.ToString( ) ); } } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_END_DIAG: { PacketData.inv_rnd_end_diag inv_rnd_end_diag = packet as PacketData.inv_rnd_end_diag; Debug.Assert( inv_rnd_end_diag != null ); if ( InventoryRoundData.Contains( _processedRoundIndex ) ) { InventoryRound inventoryRound = ( InventoryRound ) InventoryRoundData[ _processedRoundIndex ]; inventoryRound.inv_rnd_endTime = inv_rnd_end_diag.ms_ctr; inventoryRound.querys = inv_rnd_end_diag.querys; inventoryRound.rn16rcv = inv_rnd_end_diag.rn16rcv; inventoryRound.rn16Timeouts = inv_rnd_end_diag.rn16to; inventoryRound.epcTimeouts = inv_rnd_end_diag.epcto; inventoryRound.goodReads = inv_rnd_end_diag.good_reads; inventoryRound.crcFailures = inv_rnd_end_diag.crc_failures; //if (inventoryRound.inv_rnd_begTime != null && inventoryRound.inv_rnd_endTime != null) //{ // inventoryRound.inv_rnd_delta = inventoryRound.inv_rnd_endTime - inventoryRound.inv_rnd_begTime; //} InventoryRoundData[ _processedRoundIndex ] = inventoryRound; } else { Debug.Assert( false, "Unable to find InventoryRoundData for " + _processedRoundIndex.ToString( ) ); } } break; case PacketData.PacketType.ISO18K6C_INVENTORY: { PacketData.inventory inventory = packet as PacketData.inventory; Debug.Assert( inventory != null ); BitVector32 flags = new BitVector32( inventory.flags ); bool badCrc = flags[ PacketData.PacketBase.crcResult ] == ( int ) PacketData.PacketBase.CrcResultValues.Bad; if ( badCrc ) { } else { TagRead tagRead = new TagRead( ); tagRead.packetSequence = envelope.PacketNumber; //tagRead.reader = envelope.ReaderName; tagRead.readerID = envelope.ReaderIndex; tagRead.packetTime = envelope.Timestamp; tagRead.readTime = envelope.ElapsedTimeMs; tagRead.commandSequence = _processedCommandIndex; tagRead.cycleSequence = _processedAntennaCycleIndex; tagRead.antennaSequence = _processedAntennaIndex; tagRead.antennaNumber = LastUsedAntenna; tagRead.roundSequence = _processedRoundIndex; tagRead.crcResult = "valid"; #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call tagRead.readSequence = System.Threading.Interlocked.Increment( ref _processedInventoryIndex ); #pragma warning restore 420 tagRead.nb_rssi = inventory.nb_rssi; tagRead.wb_rssi = inventory.wb_rssi; tagRead.ana_ctrl1 = inventory.ana_ctrl1; tagRead.rssi = inventory.rssi; // tagRead.tagType = flags[PacketData.PacketBase.tagType] == 0xC ? "ISO 18000-6C" : "unknown"; string tagData = BitConverter.ToString( inventory.inventory_data, 0, inventory.inventory_data.Length - flags[ PacketData.PacketBase.paddingBytes ] ); tagRead.accessType = "inventory"; tagRead.tagId = tagData; tagRead.inventoryTime = inventory.ms_ctr; TagReadData.Add( tagRead ); ReadRate readRate = new ReadRate( ); if ( 0 == ( readRate.readSequence = _processedInventoryIndex - _processedCmdReadCount ) ) // note _processedInventoryIndex is incremented above { _lastCmdClientTime = envelope.ElapsedTimeMs; _lastCmdDeviceTime = inventory.ms_ctr; } readRate.readerID = envelope.ReaderIndex; readRate.clientReadTime = envelope.ElapsedTimeMs - _lastCmdClientTime; readRate.deviceReadTime = inventory.ms_ctr - _lastCmdDeviceTime; ReadRateData.Add( readRate ); rfidTag tag = new rfidTag( inventory.inventory_data ); _commandTagList.AddOrIncrementTagCount( tag ); _antennaCycleTagList.AddOrIncrementTagCount( tag ); _antennaTagList.AddOrIncrementTagCount( tag ); _inventoryCycleTagList.AddOrIncrementTagCount( tag ); _inventoryRoundTagList.AddOrIncrementTagCount( tag ); } } break; case PacketData.PacketType.ISO18K6C_INVENTORY_DIAG: { PacketData.inventory_diag epc_diag = packet as PacketData.inventory_diag; Debug.Assert( epc_diag != null ); if ( TagReadData.Contains( _processedInventoryIndex ) ) { TagRead tagRead = ( TagRead ) TagReadData[ _processedInventoryIndex ]; tagRead.protocolParameters = epc_diag.prot_parms; TagReadData[ _processedInventoryIndex ] = tagRead; } else { Debug.Assert( false, "Unable to find TagReadData for " + _processedInventoryIndex.ToString( ) ); } } break; case PacketData.PacketType.ISO18K6C_TAG_ACCESS: { PacketData.Iso18k6c_access access = packet as PacketData.Iso18k6c_access; Debug.Assert( access != null ); BitVector32 flags = new BitVector32( access.flags ); bool badCrc = flags[ PacketData.PacketBase.accessCRCFlag ] == ( int ) PacketData.PacketBase.CrcResultValues.Bad; if ( badCrc ) { } else { string tagData = BitConverter.ToString( access.data, 0, access.data.Length - flags[ PacketData.PacketBase.accessPadding ] ); if ( TagReadData.Contains( _processedInventoryIndex ) ) { TagRead tagRead = ( TagRead ) TagReadData[ _processedInventoryIndex ]; tagRead.resultType = flags[ PacketData.PacketBase.accessErrorFlag ] == ( int ) PacketData.PacketBase.ISO_18000_6C_ErrorFlag.AccessError ? "Error" : ""; tagRead.accessType = PacketData.PacketBase.GetTagAccessTypeName( access.command ); tagRead.parameter = envelope.ReadRequest; tagRead.tagData = tagData; TagReadData[ _processedInventoryIndex ] = tagRead; } else { // Check for Read Data - todo // Debug.Assert( false, "Unable to find TagReadData for " + _processedInventoryIndex.ToString( ) ); } } } break; case PacketData.PacketType.FREQUENCY_HOP_DIAG: Debug.Assert( false, "New Packet" ); break; case PacketData.PacketType.NONCRITICAL_FAULT: Debug.Assert( false, "New Packet" ); break; case PacketData.PacketType.COMMAND_ACTIVE: break; case PacketData.PacketType.DEBUG: break; case PacketData.PacketType.U_N_D_F_I_N_E_D: default: Debug.Assert( false, "Unexpected Packet" ); break; } } }
public void WritePacket( PacketData.PacketWrapper envelope ) { _packets++; _formatter.Serialize( WriteableStream, envelope ); }
/// <summary> /// Caculate basic stats and save the packet to a stream /// </summary> /// <param name="envelope"></param> private void SavePacket( PacketData.PacketWrapper envelope ) { // Debug.WriteLineIf((int)envelope.RadioID != (int)_theReaderID.Handle, String.Format("Expected: {0}, Actual: {1}", (int)_theReaderID.Handle, (int)envelope.RadioID), "ERROR"); Debug.Assert( envelope.ReaderName == Name ); PacketData.PacketBase packet = envelope.Packet; PacketData.PacketType type = envelope.PacketType; switch ( type ) { case PacketData.PacketType.CMD_BEGIN: { LastUsedAntenna = null; LastCommandResult = null; PacketData.cmd_beg cmd_beg = packet as PacketData.cmd_beg; Debug.Assert( cmd_beg != null ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawCommandCount ); #pragma warning restore 420 } break; case PacketData.PacketType.CMD_END: { PacketData.cmd_end cmd_end = packet as PacketData.cmd_end; Debug.Assert( cmd_end != null ); LastCommandResult = cmd_end.Result; if ( cmd_end.Result != 0 ) CommandErrors++; } break; case PacketData.PacketType.ANTENNA_CYCLE_BEGIN: { PacketData.ant_cyc_beg cyc_beg = packet as PacketData.ant_cyc_beg; Debug.Assert( cyc_beg != null ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawAntennaCycleCount ); #pragma warning restore 420 // PacketLogger.Comment(String.Format("Start of Cycle {0} Command={1}", RawCycleCount - 1, RawCommandCount - 1)); lock ( _tagInventoryData ) { foreach ( TagInventory ti in TagInventoryData ) { ti.cycleReadCount = 0; ti.totalCycleCount = RawAntennaCycleCount; } } } break; case PacketData.PacketType.ANTENNA_CYCLE_BEGIN_DIAG: { PacketData.ant_cyc_beg_diag cyc_beg_diag = packet as PacketData.ant_cyc_beg_diag; Debug.Assert( cyc_beg_diag != null ); } break; case PacketData.PacketType.ANTENNA_CYCLE_END: { PacketData.ant_cyc_end cyc_end = packet as PacketData.ant_cyc_end; Debug.Assert( cyc_end != null ); // PacketLogger.Comment(String.Format("End of Cycle {0}", RawCycleCount - 1)); } break; case PacketData.PacketType.ANTENNA_CYCLE_END_DIAG: { PacketData.ant_cyc_end_diag cyc_end_diag = packet as PacketData.ant_cyc_end_diag; Debug.Assert( cyc_end_diag != null ); } break; case PacketData.PacketType.ANTENNA_BEGIN: { PacketData.ant_beg ant_beg = packet as PacketData.ant_beg; Debug.Assert( ant_beg != null ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawAntennaCount ); #pragma warning restore 420 LastUsedAntenna = ant_beg.antenna; } break; case PacketData.PacketType.ANTENNA_END: { PacketData.ant_end ant_end = packet as PacketData.ant_end; Debug.Assert( ant_end != null ); LastUsedAntenna = null; } break; case PacketData.PacketType.ANTENNA_BEGIN_DIAG: { PacketData.ant_beg_diag ant_beg_diag = packet as PacketData.ant_beg_diag; Debug.Assert( ant_beg_diag != null ); } break; case PacketData.PacketType.ANTENNA_END_DIAG: { PacketData.ant_end_diag ant_end_diag = packet as PacketData.ant_end_diag; Debug.Assert( ant_end_diag != null ); } break; case PacketData.PacketType.INVENTORY_CYCLE_BEGIN: { PacketData.inv_cyc_beg inv_cyc_beg = packet as PacketData.inv_cyc_beg; Debug.Assert( inv_cyc_beg != null ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawInventoryCycleCount ); #pragma warning restore 420 // PacketLogger.Comment(String.Format("Start of Cycle {0} Command={1}", RawCycleCount - 1, RawCommandCount - 1)); } break; case PacketData.PacketType.INVENTORY_CYCLE_END: { PacketData.inv_cyc_end inv_cyc_end = packet as PacketData.inv_cyc_end; Debug.Assert( inv_cyc_end != null ); } break; case PacketData.PacketType.CARRIER_INFO: { PacketData.carrier_info carrier_info = packet as PacketData.carrier_info; Debug.Assert( carrier_info != null ); } break; case PacketData.PacketType.INVENTORY_CYCLE_END_DIAGS: { PacketData.inv_cyc_end_diag inv_cyc_end_diag = packet as PacketData.inv_cyc_end_diag; Debug.Assert( inv_cyc_end_diag != null ); } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN: { PacketData.inv_rnd_beg inv_rnd_beg = packet as PacketData.inv_rnd_beg; Debug.Assert( inv_rnd_beg != null ); #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawRoundCount ); #pragma warning restore 420 // reference to a volatile field is valid for Interlocked call } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_BEGIN_DIAG: { PacketData.inv_rnd_beg_diag inv_rnd_beg_diag = packet as PacketData.inv_rnd_beg_diag; Debug.Assert( inv_rnd_beg_diag != null ); } break; case PacketData.PacketType.ISO18K6C_INVENTORY_ROUND_END_DIAG: { PacketData.inv_rnd_end_diag inv_rnd_end_diag = packet as PacketData.inv_rnd_end_diag; Debug.Assert( inv_rnd_end_diag != null ); } break; case PacketData.PacketType.ISO18K6C_INVENTORY: { PacketData.inventory epc = packet as PacketData.inventory; Debug.Assert( epc != null ); BitVector32 flags = new BitVector32( epc.flags ); bool badCrc = flags[ PacketData.PacketBase.crcResult ] != 0; if ( badCrc ) { #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _cRCErrors ); #pragma warning restore 420 } else { #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _rawInventoryCount ); #pragma warning restore 420 rfidTag key = new rfidTag( epc.inventory_data ); if ( _sessionTagList.AddOrIncrementTagCount( key ) == 1 ) { _requestTagList.Add( key, 1 ); _periodTagList.Add( key, 1 ); } else { if ( _requestTagList.AddOrIncrementTagCount( key ) == 1 ) { _periodTagList.Add( key, 1 ); } else { _periodTagList.AddOrIncrementTagCount( key ); } } string epcData = BitConverter.ToString( epc.inventory_data, 0, epc.inventory_data.Length - flags[ PacketData.PacketBase.paddingBytes ] ); int CycleSlotNumber = RawAntennaCycleCount == 0 ? 0 : RawAntennaCycleCount - 1; KeyList<TagInventory> epcDataKey = new KeyList<TagInventory>( "tagIdData", epcData ); _inventoryMatrix.AddTagCycle( epcData, CycleSlotNumber ); TagInventory tagInventory = new TagInventory( ); lock ( _tagInventoryData ) { LastUsedAntenna = epc.logic_ant; if ( !TagInventoryData.Contains( epcDataKey ) ) // new tag ID { // PacketLogger.Comment(String.Format("First Read of Tag {0} Command={1}, Cycle={2}", epcData, RawCommandCount - 1, RawCycleCount - 1)); tagInventory.tagIdData = epcData; tagInventory.readCount = 1; tagInventory.cycleReadCount = 1; tagInventory.firstReadTime = epc.ms_ctr; tagInventory.lastReadTime = epc.ms_ctr; tagInventory.firstCommand = RawCommandCount - 1; tagInventory.lastCommand = RawCommandCount - 1; tagInventory.actualCycleCount = 1; tagInventory.totalCycleCount = RawAntennaCycleCount; tagInventory.cycleReadCount = 1; tagInventory.sumOfCommandReads = 0; //tagInventory.readRate = 0; //tagInventory.readerCycleCount; //tagInventory.firstReaderCycle; //tagInventory.lastReaderCycle; //tagInventory.antennaCycleCount; //tagInventory.firstAntennaCycle; //tagInventory.lastAntennaCycle; tagInventory.port0reads = 0; tagInventory.port1reads = 0; tagInventory.port2reads = 0; tagInventory.port3reads = 0; tagInventory.port4reads = 0; tagInventory.port5reads = 0; tagInventory.port6reads = 0; tagInventory.port7reads = 0; tagInventory.port8reads = 0; tagInventory.port9reads = 0; tagInventory.port10reads = 0; tagInventory.port11reads = 0; tagInventory.port12reads = 0; tagInventory.port13reads = 0; tagInventory.port14reads = 0; tagInventory.port15reads = 0; if ( LastUsedAntenna != null ) { switch ( LastUsedAntenna ) { case 0: tagInventory.port0reads = 1; break; case 1: tagInventory.port1reads = 1; break; case 2: tagInventory.port2reads = 1; break; case 3: tagInventory.port3reads = 1; break; case 4: tagInventory.port4reads = 1; break; case 5: tagInventory.port5reads = 1; break; case 6: tagInventory.port6reads = 1; break; case 7: tagInventory.port7reads = 1; break; case 8: tagInventory.port8reads = 1; break; case 9: tagInventory.port9reads = 1; break; case 10: tagInventory.port10reads = 1; break; case 11: tagInventory.port11reads = 1; break; case 12: tagInventory.port12reads = 1; break; case 13: tagInventory.port13reads = 1; break; case 14: tagInventory.port14reads = 1; break; case 15: tagInventory.port15reads = 1; break; default: break; } } // tagInventory.inventoryRoundCount; // tagInventory.firstinventoryRound; // tagInventory.lastinventoryRound; TagInventoryData.Add( tagInventory ); } else { tagInventory = ( TagInventory ) TagInventoryData[ epcDataKey ]; tagInventory.readCount++; if ( tagInventory.lastCommand == CycleSlotNumber ) { tagInventory.cycleReadCount += 1; } else { tagInventory.cycleReadCount = 1; tagInventory.actualCycleCount++; tagInventory.lastCommand = CycleSlotNumber; } tagInventory.totalCycleCount = RawAntennaCycleCount; tagInventory.lastReadTime = epc.ms_ctr; // if (tagInventory.lastReadTime > tagInventory.firstReadTime) //{ // tagInventory.readRate = (float)(tagInventory.ReadCount) / (float)((tagInventory.LastReadTime - tagInventory.FirstReadTime) / 100); //} //tagInventory.commandCount = 1; //tagInventory.firstCommand; //tagInventory.lastCommand; //tagInventory.readerCycleCount; //tagInventory.firstReaderCycle; //tagInventory.lastReaderCycle; //tagInventory.antennaCycleCount; //tagInventory.firstAntennaCycle; //tagInventory.lastAntennaCycle; if ( LastUsedAntenna != null ) { switch ( LastUsedAntenna ) { case 0: tagInventory.port0reads += 1; break; case 1: tagInventory.port1reads += 1; break; case 2: tagInventory.port2reads += 1; break; case 3: tagInventory.port3reads += 1; break; case 4: tagInventory.port4reads += 1; break; case 5: tagInventory.port5reads += 1; break; case 6: tagInventory.port6reads += 1; break; case 7: tagInventory.port7reads += 1; break; case 8: tagInventory.port8reads += 1; break; case 9: tagInventory.port9reads += 1; break; case 10: tagInventory.port10reads += 1; break; case 11: tagInventory.port11reads += 1; break; case 12: tagInventory.port12reads += 1; break; case 13: tagInventory.port13reads += 1; break; case 14: tagInventory.port14reads += 1; break; case 15: tagInventory.port15reads += 1; break; default: break; } } //tagInventory.inventoryRoundCount ; //tagInventory.firstinventoryRound ; //tagInventory.lastinventoryRound ; tagInventory.dataRead = ""; //clark 2011.4. copied from R1000 Tracer TagInventoryData[epcDataKey] = tagInventory; } } } } break; case PacketData.PacketType.ISO18K6C_INVENTORY_DIAG: break; case PacketData.PacketType.ISO18K6C_TAG_ACCESS: { PacketData.Iso18k6c_access access = packet as PacketData.Iso18k6c_access; Debug.Assert( access != null ); BitVector32 flags = new BitVector32( access.flags ); bool badCrc = flags[ PacketData.PacketBase.accessCRCFlag ] == ( int ) PacketData.PacketBase.CrcResultValues.Bad; if ( badCrc ) { #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _cRCErrors ); #pragma warning restore 420 } else { if ( flags[ PacketData.PacketBase.accessErrorFlag ] == ( int ) PacketData.PacketBase.ISO_18000_6C_ErrorFlag.AccessSucceeded ) { #pragma warning disable 420 // reference to a volatile field is valid for Interlocked call System.Threading.Interlocked.Increment( ref _commonAccessCount ); #pragma warning restore 420 } // Update Requests Here - todo // envelope.RecordReadRequest( ( int ) TagBank, TagMemoryLocation, TagMemoryLength, TagPassword ); //Clark 2011.2.18 Copied from R1000 Tracer PacketData.PacketWrapper[] RecentPacketArray = new PacketData.PacketWrapper[RecentPacketList.Count]; RecentPacketList.CopyTo(RecentPacketArray); for (int i = (RecentPacketArray.Length) - 1; i >= 0; i--) { if (RecentPacketArray[i].PacketType == PacketData.PacketType.ISO18K6C_INVENTORY) { PacketData.PacketBase pa = RecentPacketArray[i].Packet; PacketData.inventory epc = (PacketData.inventory)pa; string epcData = BitConverter.ToString(epc.inventory_data, 0, epc.inventory_data.Length);// - flags[PacketData.PacketBase.paddingBytes]); KeyList<TagInventory> epcDataKey = new KeyList<TagInventory>("tagIdData", epcData); //Console.WriteLine(epcData); TagInventory tagInventory = new TagInventory(); lock (_tagInventoryData) { if (TagInventoryData.Contains(epcDataKey)) { tagInventory = (TagInventory)TagInventoryData[epcDataKey]; BitVector32 accessflags = new BitVector32(access.flags); if (access.data.Length >= 2) { if (accessflags[PacketData.PacketBase.accessErrorFlag] == (int)PacketData.PacketBase.ISO_18000_6C_ErrorFlag.AccessSucceeded) { //int Count = TagAccessReqCount * 2; //if (TagAccessReqCount > 8) //{ // Count = 16; // TagAccessReqCount -= 8; //} //tagInventory.dataRead += BitConverter.ToString(access.data, 0, Count);// TagAccessReqCount * 2);//access.data.GetLength(0)); tagInventory.dataRead += BitConverter.ToString(access.data, 0, TagAccessReqCount * 2);//access.data.GetLength(0)); } else tagInventory.dataRead = ""; TagInventoryData[epcDataKey] = tagInventory; } //Console.WriteLine(BitConverter.ToString(access.data, 0, access.data.Length)); } } break; } } } } break; case PacketData.PacketType.FREQUENCY_HOP_DIAG: break; case PacketData.PacketType.DEBUG: { PacketData.debug debugPacket = packet as PacketData.debug; Debug.Assert(debugPacket != null); } break; case PacketData.PacketType.COMMAND_ACTIVE: { PacketData.command_active commandActive = packet as PacketData.command_active; Debug.Assert(commandActive != null); } break; case PacketData.PacketType.NONCRITICAL_FAULT: break; case PacketData.PacketType.U_N_D_F_I_N_E_D: default: break; } // Save the packet FileHandler.WritePacket( envelope ); RecentPacketList.Add( new PacketData.PacketWrapper( envelope ) ); if ( EnableLogging ) { //Write Log PacketLogger.Log( envelope ); } } //private void SavePacket(PacketData.PacketWrapper envelope)
public static void Log( PacketData.PacketWrapper envelope ) { if ( _fileStream == null ) OpenFile( ); if ( envelope.IsPseudoPacket ) { PacketData.CommandPsuedoPacket psuedo = envelope.Packet as PacketData.CommandPsuedoPacket; if ( psuedo != null ) { switch ( psuedo.RequestName ) { case "Inventory": ReaderRequest readerRequest = new ReaderRequest( ); using ( System.IO.MemoryStream data = new System.IO.MemoryStream( psuedo.DataValues ) ) { readerRequest.ReadFrom( data ); } _fileStream.WriteLine( String.Format( "{0:d02}\t{1}\t\"{2}\"\t{3}", envelope.ReaderIndex, envelope.ElapsedTimeMs, "Request", readerRequest.RequestName ) ); break; case "BadPacket": BadPacket badPacket = new BadPacket( ); using ( System.IO.MemoryStream data = new System.IO.MemoryStream( psuedo.DataValues ) ) { badPacket.ReadFrom( data ); } _fileStream.WriteLine( String.Format( "{0:d02}\t{1}\t\"{2}\"\t{3}", envelope.ReaderIndex, envelope.ElapsedTimeMs, "Bad Packet", badPacket.RawPacketData == null ? "No Data" : BitConverter.ToString( badPacket.RawPacketData ) ) ); break; default: System.Diagnostics.Debug.Assert( false ); break; } } } else { _fileStream.WriteLine( String.Format( "{0:d02}\t{1}\t\"{2}\"\t{3}", envelope.ReaderIndex, envelope.ElapsedTimeMs, envelope.PacketTypeName, BitConverter.ToString( envelope.RawPacket ) ) ); } }