Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 080e818

Browse files
committedNov 22, 2023
持续改进高频、超高频相关功能
1 parent 85ce020 commit 080e818

23 files changed

+1255
-316
lines changed
 

‎DigitalPlatform.RFID/ChipMemory.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,16 @@ public string FindGaoxiaoOI()
12031203
oi = this.FindElement((ElementOID)27)?.Text;
12041204
return oi;
12051205
}
1206+
1207+
public string GetUII()
1208+
{
1209+
string pii = this.FindElement(ElementOID.PII)?.Text;
1210+
string oi = this.FindGaoxiaoOI();
1211+
if (string.IsNullOrEmpty(pii) == false
1212+
&& string.IsNullOrEmpty(oi) == false)
1213+
return oi + "." + pii;
1214+
return pii;
1215+
}
12061216
}
12071217

12081218
#if NO

‎DigitalPlatform.RFID/GaoxiaoUtility.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,9 +1057,12 @@ string DecodeLibraryCode(byte[] bytes)
10571057
// 5) chip 中的 TypeOfUsage 元素内是通用值,在写入 UHF 高校联盟格式时要先映射转换为其私有值
10581058
// parameters:
10591059
// build_user_bank 是否要构造 User Bank 内容。如果不构造的话,Content Parameter 中就不会包含任何 index 信息
1060+
// epc_info 要创建的 EPC Bank 的一些预定义值。
1061+
// 如果 epc_info.ContentParameters 不为 null,则表示直接用它进入 EPC
10601062
public static BuildTagResult BuildTag(LogicChip chip,
10611063
bool build_user_bank,
1062-
bool eas = true)
1064+
bool eas = true,
1065+
GaoxiaoEpcInfo epc_info = null)
10631066
{
10641067
// 2023/11/7
10651068
// 对于不写入 User Bank 的情况进行检查
@@ -1157,13 +1160,19 @@ bool IsNormalBookTou(string value)
11571160
if (build_user_bank)
11581161
user_bank = EncodeUserBank(user_elements, false); // true
11591162

1160-
var epc_info = new GaoxiaoEpcInfo();
1163+
if (epc_info == null)
1164+
epc_info = new GaoxiaoEpcInfo();
11611165
epc_info.Lending = !eas;
1162-
epc_info.Version = 1; // ?
1163-
if (build_user_bank)
1164-
epc_info.ContentParameters = BuildContentParameter(user_elements);
1165-
else
1166-
epc_info.ContentParameters = new int[0];
1166+
// Version(5) Picking(1) Reserve(1)
1167+
// epc_info.Version = 1; // ?
1168+
1169+
if (epc_info.ContentParameters == null)
1170+
{
1171+
if (build_user_bank)
1172+
epc_info.ContentParameters = BuildContentParameter(user_elements);
1173+
else
1174+
epc_info.ContentParameters = new int[0];
1175+
}
11671176
epc_info.PII = chip.FindElement(ElementOID.PII)?.Text;
11681177

11691178
// 重新获取一次

‎DigitalPlatform.RFID/IRfidDriver.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ public class ShelfLock
517517
[Serializable()]
518518
public class SetEasResult : NormalResult
519519
{
520+
// 修改前的 UID
521+
public string OldUID { get; set; }
522+
520523
// 修改后的 UID
521524
// 注: UHF 标签在修改 EAS 以后,UID 会发生变化
522525
public string ChangedUID { get; set; }

‎DigitalPlatform.RFID/RfidTagList.cs

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,81 @@ public static ChipInfo GetUhfChipInfo(TagInfo taginfo,
779779
return result;
780780
}
781781

782+
// 2023/11/20
783+
// 根据 EPC Bank 获知 UHF 标签的 EAS 状态
784+
// parameters:
785+
// gb_afi [out] 返回国标格式的 AFI。注意,针对高校联盟格式会返回 0
786+
public static bool GetUhfEas(string uid,
787+
out int gb_afi)
788+
{
789+
gb_afi = 0;
790+
var epc_bank = Element.FromHexString(uid);
791+
792+
if (UhfUtility.IsBlankTag(epc_bank, null) == true)
793+
{
794+
// 空白标签
795+
return false;
796+
}
797+
else
798+
{
799+
var isGB = UhfUtility.IsISO285604Format(epc_bank, null);
800+
if (isGB)
801+
{
802+
// *** 国标 UHF
803+
var pc = UhfUtility.ParsePC(epc_bank, 2);
804+
gb_afi = pc.AFI;
805+
if (pc.AFI == 0x07)
806+
return true;
807+
return false;
808+
}
809+
else
810+
{
811+
// var use_gxlm_pii = StringUtil.IsInList("gxlm_pii", style);
812+
// *** 高校联盟 UHF
813+
var parse_result = GaoxiaoUtility.ParseTag(
814+
epc_bank,
815+
null,
816+
"");
817+
if (parse_result.Value == -1)
818+
{
819+
return false;
820+
}
821+
if (parse_result.EpcInfo == null)
822+
return false;
823+
return !parse_result.EpcInfo.Lending;
824+
}
825+
}
826+
}
827+
828+
public static string GetHfUii(TagInfo taginfo)
829+
{
830+
try
831+
{
832+
// Exception:
833+
// 可能会抛出异常 ArgumentException TagDataException
834+
var chip = LogicChip.From(taginfo.Bytes,
835+
(int)taginfo.BlockSize,
836+
"" // taginfo.LockStatus
837+
);
838+
839+
var pii = chip?.FindElement(ElementOID.PII)?.Text;
840+
841+
string oi = chip?.FindElement(ElementOID.OI)?.Text;
842+
if (string.IsNullOrEmpty(oi))
843+
oi = chip?.FindElement(ElementOID.AOI)?.Text;
844+
845+
// 构造 UII
846+
if (string.IsNullOrEmpty(oi))
847+
return pii;
848+
else
849+
return oi + "." + pii;
850+
}
851+
catch (Exception ex)
852+
{
853+
return null;
854+
}
855+
}
856+
782857
// 获得 UHF 标签的 UII 内容
783858
// parameters:
784859
// style 风格。如果为 gxlm_pii ,表示不需要返回 oi 部分(因而也不需要解析 .Bytes 部分)
@@ -970,6 +1045,115 @@ public static string GetPiiPart(string oi_pii)
9701045
return parts[1];
9711046
}
9721047

1048+
// 当 EAS 修改后,主动修改 this.Books 中的相关信息
1049+
// parameters:
1050+
// old_uid 原先的 UID
1051+
// changed_uid 修改后的 UID (对于 UHF 标签)
1052+
// "on" "off" 之一(对于 HF 标签)
1053+
public static int ChangeUID(
1054+
BaseChannel<IRfid> channel,
1055+
string old_uid,
1056+
string changed_uid)
1057+
{
1058+
if (string.IsNullOrEmpty(old_uid))
1059+
throw new ArgumentException("old_uid 参数值不应为空");
1060+
1061+
var news = Books;
1062+
int count = 0;
1063+
foreach (TagAndData data in news)
1064+
{
1065+
OneTag tag = data.OneTag;
1066+
if (tag == null)
1067+
continue;
1068+
//if (tag.TagInfo != null && data.Error == null)
1069+
// continue;
1070+
if (tag.Protocol == InventoryInfo.ISO14443A)
1071+
continue;
1072+
1073+
if (tag.UID != old_uid)
1074+
continue;
1075+
1076+
if (tag.Protocol == InventoryInfo.ISO18000P6C)
1077+
{
1078+
if (string.IsNullOrEmpty(changed_uid))
1079+
throw new ArgumentException("changed_uid 参数值不应为空(针对 UHF 标签)");
1080+
1081+
tag.UID = changed_uid;
1082+
if (tag.TagInfo != null)
1083+
{
1084+
tag.TagInfo.UID = changed_uid;
1085+
tag.TagInfo.EAS = GetUhfEas(changed_uid, out int afi);
1086+
if (afi != 0)
1087+
tag.TagInfo.AFI = (byte)afi;
1088+
}
1089+
count++;
1090+
}
1091+
else if (tag.Protocol == InventoryInfo.ISO15693)
1092+
{
1093+
// ClearTagTable(tag.UID);
1094+
1095+
if (changed_uid != "on" && changed_uid != "off")
1096+
throw new ArgumentException($"针对 HF 标签,changed_uid 参数值应当为 'on' 'off' 之一");
1097+
1098+
var eas = changed_uid == "on" ? true : false;
1099+
ChangeTagInfoEas(tag.TagInfo, eas);
1100+
1101+
#if REMOVED
1102+
tag.TagInfo = null;
1103+
// 尝试重新获取 TagInfo。
1104+
// TODO: 也可以优化为直接修改内存对象,而不去访问读写器重新获取标签信息
1105+
1106+
ClearTagTable(tag.UID);
1107+
1108+
// 自动重试一次
1109+
GetTagInfoResult gettaginfo_result = null;
1110+
for (int i = 0; i < 2; i++)
1111+
{
1112+
gettaginfo_result = GetTagInfo(channel, tag.ReaderName, tag.UID, tag.AntennaID, tag.Protocol);
1113+
if (gettaginfo_result.Value != -1)
1114+
break;
1115+
}
1116+
1117+
if (gettaginfo_result.Value == -1)
1118+
{
1119+
data.Error = gettaginfo_result.ErrorInfo;
1120+
continue;
1121+
}
1122+
else
1123+
{
1124+
if (string.IsNullOrEmpty(data.Error) == false)
1125+
{
1126+
data.Error = null;
1127+
}
1128+
}
1129+
1130+
TagInfo info = gettaginfo_result.TagInfo;
1131+
tag.TagInfo = info;
1132+
#endif
1133+
1134+
count++;
1135+
}
1136+
} // end of foreach
1137+
return count;
1138+
}
1139+
1140+
static bool ChangeTagInfoEas(TagInfo tag_info,
1141+
bool eas)
1142+
{
1143+
if (tag_info == null)
1144+
return false;
1145+
if (tag_info.EAS == eas)
1146+
return false;
1147+
1148+
tag_info.EAS = eas;
1149+
// 然后修改 AFI
1150+
if (tag_info.AFI == 0xc2 || tag_info.AFI == 0x07)
1151+
{
1152+
tag_info.AFI = (eas == true ? (byte)0x07 : (byte)0xc2);
1153+
}
1154+
1155+
return true;
1156+
}
9731157

9741158

9751159
// 填充 Books 和 Patrons 每个元素的 .TagInfo
@@ -988,6 +1172,7 @@ public static int FillTagInfo(BaseChannel<IRfid> channel)
9881172
if (tag.Protocol == InventoryInfo.ISO14443A)
9891173
continue;
9901174

1175+
// TODO: 根据 OnlyReadEPC,不要填充 ISO18000P6C 协议的 TagInfo 的 Bytes
9911176
if (tag.TagInfo == null)
9921177
{
9931178
// 自动重试一次

‎RfidCenter/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
3333
// 方法是按如下所示使用“*”: :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.14.23")] // 1.11.*
35+
[assembly: AssemblyVersion("1.14.26")] // 1.11.*
3636
[assembly: AssemblyFileVersion("1.14.0.0")]
3737

3838
// V1.1 2019/2/21 支持 32-bit Windows 环境
@@ -73,5 +73,8 @@
7373
// (2023/11/9) RfidDriver.First 中 GetTagInfo() 有一处优化读取 EPC 中 UMI 为 off 的 UHF 标签的 User Bank 的情形出现了 bug,把原本 HF 标签的 UID 当作 EPC Bank 进行了判断。此 bug 已经修正
7474
// (2023/11/13) OneTag 结构增加了 RSSI 成员。TagInfo 增加了 RSSI 成员
7575
// 新增加两种型号的 UHF 读写器的 XML 元数据。product id 对应于 900003 和 900007
76+
// (2023/11/21) SetEAS() API 返回的结构中增加了一个 OldUID 成员。(此前版本已经增加了 ChangedUI 成员)
77+
// (2023/11/22) SetEAS() API 中增加对 UHF EPC 的 CRC-16 校验,跳过一些不必要的尝试动作
78+
// 对一些地方的 PII 改为适应 UII
7679

7780

‎RfidCenter/RfidCenter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<SuiteName>dp2 V3</SuiteName>
3131
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
3232
<WebPage>publish.htm</WebPage>
33-
<ApplicationRevision>29</ApplicationRevision>
33+
<ApplicationRevision>32</ApplicationRevision>
3434
<ApplicationVersion>1.14.8.%2a</ApplicationVersion>
3535
<UseApplicationTrust>false</UseApplicationTrust>
3636
<CreateDesktopShortcut>true</CreateDesktopShortcut>

‎RfidCenter/RfidServer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ public SetEasResult SetEAS1(
11701170
return new SetEasResult
11711171
{
11721172
Value = 1,
1173+
OldUID = result.OldUID,
11731174
ChangedUID = result.ChangedUID
11741175
};
11751176
}

0 commit comments

Comments
 (0)
Please sign in to comment.