private void AddOrUpdateTagData(CSLibrary.Structures.TagCallbackInfo info) { InvokeOnMainThread(() => { bool found = false; int cnt; if (BleMvxApplication._rfMicro_Power == 4 && BleMvxApplication._config.RFID_PowerSequencing_NumberofPower != 0) { currentPower = (BleMvxApplication._config.RFID_PowerSequencing_Level[info.antennaPort] / 10).ToString("0.0") + "dB"; RaisePropertyChanged(() => currentPower); } lock (TagInfoList) { UInt16 ocRSSI; UInt16 sensorCode; UInt16 temp; sensorCode = (UInt16)(info.Bank1Data[0] & 0x1ff); // address c ocRSSI = info.Bank1Data[1]; // address d temp = info.Bank1Data[2]; // address e for (cnt = 0; cnt < TagInfoList.Count; cnt++) { if (TagInfoList[cnt].EPC == info.epc.ToString()) { TagInfoList[cnt].OCRSSI = ocRSSI; TagInfoList[cnt].RSSIColor = "Black"; if (ocRSSI >= BleMvxApplication._rfMicro_minOCRSSI && ocRSSI <= BleMvxApplication._rfMicro_maxOCRSSI) { TagInfoList[cnt].GOODOCRSSI = ocRSSI.ToString(); //BleMvxApplication._rfMicro_SensorType // 0 = Sensor code, 1 = Temp //BleMvxApplication._rfMicro_SensorUnit // 0=code, 1=f, 2=c, 3=% switch (BleMvxApplication._rfMicro_SensorType) { case 0: if (BleMvxApplication._rfMicro_TagType == 1 && sensorCode >= 5 && sensorCode <= 490) { double SensorAvgValue; TagInfoList[cnt].SucessCount++; SensorAvgValue = sensorCode; switch (BleMvxApplication._rfMicro_SensorUnit) { case 1: // RAW { TagInfoList[cnt].SensorAvgValue = sensorCode.ToString(); } break; case 4: // Range Allocation { if (sensorCode >= BleMvxApplication._rfMicro_WetDryThresholdValue) { TagInfoList[cnt].SensorAvgValue = "Dry"; } else { TagInfoList[cnt].SensorAvgValue = "Wet"; } } break; } if (TagInfoList[cnt].SucessCount >= 3) { switch (BleMvxApplication._rfMicro_thresholdComparison) { case 0: // > if (SensorAvgValue > BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; default: // < if (SensorAvgValue < BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; } } } break; default: if (temp >= 1300 && temp <= 3500) { double SensorAvgValue; TagInfoList[cnt].SucessCount++; UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); if (caldata == 0) { TagInfoList[cnt].SensorAvgValue = "NoCalData"; } else { switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code TagInfoList[cnt]._sensorValueSum += temp; SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; case 2: // F TagInfoList[cnt]._sensorValueSum += getTempF(temp, caldata); SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; default: // C TagInfoList[cnt]._sensorValueSum += getTempC(temp, caldata); SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; } if (TagInfoList[cnt].SucessCount >= 3) { switch (BleMvxApplication._rfMicro_thresholdComparison) { case 0: // > if (SensorAvgValue > BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; default: // < if (SensorAvgValue < BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; } } } } break; } } else { TagInfoList[cnt].RSSIColor = "Red"; } found = true; break; } } if (!found) { RFMicroTagInfoViewModel item = new RFMicroTagInfoViewModel(); item.EPC = info.epc.ToString(); item.NickName = GetNickName(item.EPC); if (item.NickName != "") { item.DisplayName = item.NickName; } else { item.DisplayName = item.EPC; } item.OCRSSI = ocRSSI; item.SucessCount = 0; item._sensorValueSum = 0; item.SensorAvgValue = ""; item.GOODOCRSSI = ""; item.RSSIColor = "Black"; item.valueColor = "Black"; if (ocRSSI >= BleMvxApplication._rfMicro_minOCRSSI && ocRSSI <= BleMvxApplication._rfMicro_maxOCRSSI) { item.GOODOCRSSI = ocRSSI.ToString(); //BleMvxApplication._rfMicro_SensorType // 0 = Sensor code, 1 = Temp //BleMvxApplication._rfMicro_SensorUnit //0=code, 1=f, 2=c, 3=% switch (BleMvxApplication._rfMicro_SensorType) { case 0: if (sensorCode >= 5 && sensorCode <= 490) { item.SucessCount++; switch (BleMvxApplication._rfMicro_SensorUnit) { case 1: item.SensorAvgValue = sensorCode.ToString(); break; default: if (sensorCode >= BleMvxApplication._rfMicro_WetDryThresholdValue) { item.SensorAvgValue = "Dry"; } else { item.SensorAvgValue = "Wet"; } break; } } break; default: if (temp >= 1300 && temp <= 3500) { item.SucessCount++; UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); if (caldata == 0) { item.SensorAvgValue = "NoCalData"; } else { switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code item._sensorValueSum = temp; item.SensorAvgValue = item._sensorValueSum.ToString(); break; case 2: // F item._sensorValueSum = getTempF(temp, caldata); item.SensorAvgValue = Math.Round(item._sensorValueSum, 2).ToString(); break; default: // C item._sensorValueSum = getTempC(temp, caldata); item.SensorAvgValue = Math.Round(item._sensorValueSum, 2).ToString(); break; } } } break; } } else { item.RSSIColor = "Red"; } TagInfoList.Insert(0, item); _newTagFound = true; Trace.Message("EPC Data = {0}", item.EPC); } } }); }
private void AddOrUpdateTagData(CSLibrary.Structures.TagCallbackInfo info) { InvokeOnMainThread(() => { bool found = false; int cnt; lock (TagInfoList) { UInt16 ocRSSI = info.Bank1Data[1]; UInt16 sensorCode = info.Bank1Data[0]; UInt16 temp = info.Bank1Data[2]; for (cnt = 0; cnt < TagInfoList.Count; cnt++) { if (TagInfoList[cnt].EPC == info.epc.ToString()) { TagInfoList[cnt].OCRSSI = ocRSSI; TagInfoList[cnt].RSSIColor = "Black"; if (ocRSSI >= BleMvxApplication._rfMicro_minOCRSSI && ocRSSI <= BleMvxApplication._rfMicro_maxOCRSSI) { TagInfoList[cnt].GOODOCRSSI = ocRSSI.ToString(); //BleMvxApplication._rfMicro_SensorType // 0 = Sensor code, 1 = Temp //BleMvxApplication._rfMicro_SensorUnit //0=code, 1=f, 2=c, 3=% switch (BleMvxApplication._rfMicro_SensorType) { case 0: if (sensorCode >= 5 && sensorCode <= 490) { double SensorAvgValue; TagInfoList[cnt].SucessCount++; switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code { TagInfoList[cnt]._sensorValueSum += sensorCode; SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); } break; default: // % { TagInfoList[cnt]._sensorValueSum += (double)sensorCode / 512 * 100; SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); } break; } if (TagInfoList[cnt].SucessCount >= 3) { switch (BleMvxApplication._rfMicro_thresholdComparison) { case 0: // > if (SensorAvgValue > BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; default: // < if (SensorAvgValue < BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; } } } break; default: if (temp >= 1300 && temp <= 3500) { double SensorAvgValue; TagInfoList[cnt].SucessCount++; UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code TagInfoList[cnt]._sensorValueSum += temp; SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; case 1: // F TagInfoList[cnt]._sensorValueSum += getTempF(temp, caldata); SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; default: // C TagInfoList[cnt]._sensorValueSum += getTempC(temp, caldata); SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2); TagInfoList[cnt].SensorAvgValue = SensorAvgValue.ToString(); break; } if (TagInfoList[cnt].SucessCount >= 3) { switch (BleMvxApplication._rfMicro_thresholdComparison) { case 0: // > if (SensorAvgValue > BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; default: // < if (SensorAvgValue < BleMvxApplication._rfMicro_thresholdValue) { TagInfoList[cnt].valueColor = BleMvxApplication._rfMicro_thresholdColor; } else { TagInfoList[cnt].valueColor = "Green"; } break; } } } break; } /* * if (BleMvxApplication._rfMicro_SensorUnit == 0) * { * if (sensorCode >= 5 && sensorCode <= 490) * { * TagInfoList[cnt].SucessCount++; * TagInfoList[cnt]._sensorValueSum += sensorCode; * TagInfoList[cnt].SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2).ToString(); * } * } * else * { * if (temp >= 1300 && temp <= 3500) * { * TagInfoList[cnt].SucessCount++; * UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); * TagInfoList[cnt]._sensorValueSum += getTemperatue(info.Bank1Data[2], caldata); * TagInfoList[cnt].SensorAvgValue = Math.Round(TagInfoList[cnt]._sensorValueSum / TagInfoList[cnt].SucessCount, 2).ToString(); * } * } */ } else { TagInfoList[cnt].RSSIColor = "Red"; } found = true; break; } } if (!found) { RFMicroTagInfoViewModel item = new RFMicroTagInfoViewModel(); item.EPC = info.epc.ToString(); item.NickName = GetNickName(item.EPC); if (item.NickName != "") { item.DisplayName = item.NickName; } else { item.DisplayName = item.EPC; } item.OCRSSI = ocRSSI; item.SucessCount = 0; item._sensorValueSum = 0; item.SensorAvgValue = ""; item.GOODOCRSSI = ""; item.RSSIColor = "Black"; item.valueColor = "Black"; if (ocRSSI >= BleMvxApplication._rfMicro_minOCRSSI && ocRSSI <= BleMvxApplication._rfMicro_maxOCRSSI) { item.GOODOCRSSI = ocRSSI.ToString(); //BleMvxApplication._rfMicro_SensorType // 0 = Sensor code, 1 = Temp //BleMvxApplication._rfMicro_SensorUnit //0=code, 1=f, 2=c, 3=% switch (BleMvxApplication._rfMicro_SensorType) { case 0: if (sensorCode >= 5 && sensorCode <= 490) { item.SucessCount++; switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code item._sensorValueSum = sensorCode; item.SensorAvgValue = item._sensorValueSum.ToString(); break; default: // % item._sensorValueSum = (double)sensorCode / 512 * 100; item.SensorAvgValue = item._sensorValueSum.ToString(); break; } } break; default: if (temp >= 1300 && temp <= 3500) { item.SucessCount++; UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); switch (BleMvxApplication._rfMicro_SensorUnit) { case 0: // code item._sensorValueSum = temp; item.SensorAvgValue = item._sensorValueSum.ToString(); break; case 1: // F item._sensorValueSum = getTempF(temp, caldata); item.SensorAvgValue = Math.Round(item._sensorValueSum, 2).ToString(); break; default: // C item._sensorValueSum = getTempC(temp, caldata); item.SensorAvgValue = Math.Round(item._sensorValueSum, 2).ToString(); break; } } break; } /* * if (BleMvxApplication._rfMicro_SensorUnit == 0) * { * if (sensorCode >= 5 && sensorCode <= 490) * { * item.SucessCount++; * item._sensorValueSum = sensorCode; * item.SensorAvgValue = item._sensorValueSum.ToString(); * } * } * else * { * if (temp >= 1300 && temp <= 3500) * { * item.SucessCount++; * UInt64 caldata = (UInt64)(((UInt64)info.Bank2Data[0] << 48) | ((UInt64)info.Bank2Data[1] << 32) | ((UInt64)info.Bank2Data[2] << 16) | ((UInt64)info.Bank2Data[3])); * item._sensorValueSum = getTemperatue(info.Bank1Data[2], caldata); * item.SensorAvgValue = Math.Round(item._sensorValueSum, 2).ToString(); * } * }*/ } else { item.RSSIColor = "Red"; } TagInfoList.Insert(0, item); _newTagFound = true; Trace.Message("EPC Data = {0}", item.EPC); } } }); }