} //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 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 ) ) ); } }