Esempio n. 1
0
        // Simple Handler for receiving the tag reports from the reader
        void reader_OnRoAccessReportReceived(MSG_RO_ACCESS_REPORT msg)
        {
            // Report could be empty
            if (msg.TagReportData == null)
            {
                return;
            }

            // Loop through and print out each tag
            for (int i = 0; i < msg.TagReportData.Length; i++)
            {
                reportCount++;

                // just write out the EPC as a hex string for now. It is guaranteed to be
                // in all LLRP reports regardless of default configuration
                string epc;
                if (msg.TagReportData[i].EPCParameter[0].GetType() == typeof(PARAM_EPC_96))
                {
                    epc = ((PARAM_EPC_96)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                }
                else
                {
                    epc = ((PARAM_EPCData)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                }
                int antennaId                = msg.TagReportData[i].AntennaID.AntennaID;
                int channelIndex             = 0;//msg.TagReportData[i].ChannelIndex.ChannelIndex;
                int inventoryParameterSpecID = msg.TagReportData[i].InventoryParameterSpecID.InventoryParameterSpecID;

                long time    = (long)msg.TagReportData[i].FirstSeenTimestampUTC.Microseconds;
                int  phase   = 0;
                int  rssi    = 0;
                int  doppler = 0;

                // just write out the EPC as a hex string for now. It is guaranteed to be
                // in all LLRP reports regardless of default configuration
                if (msg.TagReportData[i].AccessCommandOpSpecResult.Count != 0)
                {
                    PARAM_C1G2WriteOpSpecResult result =
                        (PARAM_C1G2WriteOpSpecResult)
                        msg.TagReportData[i].AccessCommandOpSpecResult[0];
                    Console.WriteLine(result.NumWordsWritten +
                                      " words written to tag with EPC = " + epc);
                }

                // check for other Impinj Specific tag data and print it out
                if (msg.TagReportData[i].Custom != null)
                {
                    for (int x = 0; x < msg.TagReportData[i].Custom.Count; x++)
                    {
                        if (msg.TagReportData[i].Custom[x].GetType() ==
                            typeof(PARAM_ImpinjSerializedTID))
                        {
                            PARAM_ImpinjSerializedTID stid =
                                (PARAM_ImpinjSerializedTID)msg.TagReportData[i].Custom[x];
                        }
                        if (msg.TagReportData[i].Custom[x].GetType() ==
                            typeof(PARAM_ImpinjPeakRSSI))
                        {
                            PARAM_ImpinjPeakRSSI Prssi =
                                (PARAM_ImpinjPeakRSSI)msg.TagReportData[i].Custom[x];

                            rssi = Prssi.RSSI;
                        }

                        if (msg.TagReportData[i].Custom[x].GetType() ==
                            typeof(PARAM_ImpinjRFDopplerFrequency))
                        {
                            PARAM_ImpinjRFDopplerFrequency DopplerFrequency =
                                (PARAM_ImpinjRFDopplerFrequency)msg.TagReportData[i].Custom[x];

                            doppler = DopplerFrequency.DopplerFrequency;
                        }
                        if (msg.TagReportData[i].Custom[x].GetType() ==
                            typeof(PARAM_ImpinjRFPhaseAngle))
                        {
                            PARAM_ImpinjRFPhaseAngle RFPhaseAngle =
                                (PARAM_ImpinjRFPhaseAngle)msg.TagReportData[i].Custom[x];

                            phase = RFPhaseAngle.PhaseAngle;
                        }
                    }
                }
                listener.tagReport(epc, antennaId, channelIndex, doppler, rssi, phase, time, inventoryParameterSpecID);
                tagMessageList.Add(epc + " " + time);
                // Console.WriteLine(epc);
            }
        }
Esempio n. 2
0
        // Simple Handler for receiving the tag reports from the reader
        static void reader_OnRoAccessReportReceived(MSG_RO_ACCESS_REPORT msg)
        {
            // Report could be empty
            if (msg.TagReportData != null)
            {
                // Loop through and print out each tag
                for (int i = 0; i < msg.TagReportData.Length; i++)
                {
                    reportCount++;

                    // just write out the EPC as a hex string for now. It is guaranteed to be
                    // in all LLRP reports regardless of default configuration
                    string data = "EPC: ";
                    string velData;
                    if (msg.TagReportData[i].EPCParameter[0].GetType() == typeof(PARAM_EPC_96))
                    {
                        currentEpcData = ((PARAM_EPC_96)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                        data          += currentEpcData;
                    }
                    else
                    {
                        currentEpcData = ((PARAM_EPCData)(msg.TagReportData[i].EPCParameter[0])).EPC.ToHexString();
                        data          += currentEpcData;
                    }

                    velData = data;

                    // collect some data for velocity calcs
                    // NOTE: these could be NULL, so we shoudl check
                    if (msg.TagReportData[i].AntennaID != null)
                    {
                        currentAntennaID = msg.TagReportData[i].AntennaID.AntennaID;
                        data            += " ant: " + currentAntennaID.ToString();
                    }

                    if (msg.TagReportData[i].ChannelIndex != null)
                    {
                        currentChannelIndex = msg.TagReportData[i].ChannelIndex.ChannelIndex;
                        data += " ch: " + currentChannelIndex.ToString();
                    }

                    if (msg.TagReportData[i].FirstSeenTimestampUTC != null)
                    {
                        currentReadTime = msg.TagReportData[i].FirstSeenTimestampUTC.Microseconds;
                        data           += " time: " + currentReadTime.ToString();
                    }

                    if (msg.TagReportData[i].Custom != null)
                    {
                        for (int x = 0; x < msg.TagReportData[i].Custom.Length; x++)
                        {
                            // try to make a tag direction report out of it
                            if (msg.TagReportData[i].Custom[x].GetType() == typeof(PARAM_ImpinjRFPhaseAngle))
                            {
                                PARAM_ImpinjRFPhaseAngle rfPhase = (PARAM_ImpinjRFPhaseAngle)msg.TagReportData[i].Custom[x];
                                currentRfPhase = rfPhase.PhaseAngle;
                                data          += " Phase: " + currentRfPhase.ToString();
                            }
                        }
                    }

                    // estimate the velocity and print a filtered version
                    double velocity;
                    if (calculateVelocity(out velocity))
                    {
                        directionCount++;
                        /* keep a filtered value. Use a 1 pole IIR here for simplicity */
                        filteredVelocity = (6 * filteredVelocity + 4 * velocity) / 10.0;

                        if (filteredVelocity > 0.25)
                        {
                            velData += "---->";
                        }
                        else if (filteredVelocity < -0.25)
                        {
                            velData += "<----";
                        }
                        else
                        {
                            velData += "     ";
                        }

                        velData += " Velocity: " + filteredVelocity.ToString("F2");
                    }

                    //Console.WriteLine(data);
                    Console.WriteLine(velData);
                }
            }
        }