Skip to content

Commit 517364e

Browse files
authored
Merge pull request #32 from cslrfid/release-2.8
Release 2.8
2 parents 468aaa1 + 91eebdf commit 517364e

19 files changed

+830
-387
lines changed

CS108iOSClient.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@
659659
"$(inherited)",
660660
"@executable_path/Frameworks",
661661
);
662+
MARKETING_VERSION = 2.8;
662663
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
663664
PRODUCT_NAME = "$(TARGET_NAME)";
664665
TARGETED_DEVICE_FAMILY = "1,2";
@@ -681,6 +682,7 @@
681682
"$(inherited)",
682683
"@executable_path/Frameworks",
683684
);
685+
MARKETING_VERSION = 2.8;
684686
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
685687
PRODUCT_NAME = "$(TARGET_NAME)";
686688
TARGETED_DEVICE_FAMILY = "1,2";

CS108iOSClient/CSLReader/CSLBleInterface.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,15 @@ - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(C
453453
NSLog(@"Checksum calculated: %02X%02X", ((Byte*)[cs bytes])[1], ((Byte*)[cs bytes])[0]);
454454
if (((Byte*)[cs bytes])[1] == packet.crc1 && ((Byte*)[cs bytes])[0] == packet.crc2) {
455455
NSLog(@"Checksum verification: PASSED");
456-
[recvQueue enqObject:packet];
456+
packet.isCRCPassed=true;
457457
}
458-
else
458+
else {
459459
NSLog(@"Checksum verification: FAILED");
460+
packet.isCRCPassed=false;
461+
}
462+
463+
//always enqueue the packet even it has a checksum verification fail. This will be caught during decoding
464+
[recvQueue enqObject:packet];
460465

461466
NSLog(@"Received packet payload size: 0x%2X byte(s)", ((unsigned char *)[recvBuffer bytes])[2] );
462467

CS108iOSClient/CSLReader/CSLBlePacket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Data information of a Bluetooth LE packet
4949
@property (assign) Byte crc1;
5050
///CRC of data packet (byte 2)
5151
@property (assign) Byte crc2;
52+
///Calculated CRC of the data packet - Pass/Fail
53+
@property (assign) BOOL isCRCPassed;
5254
///payload of data packet (first two bytes would be event code)
5355
@property NSData* payload;
5456

CS108iOSClient/CSLReader/CSLBleReader.m

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,8 @@ - (void)decodePacketsInBufferAsync;
21342134
rfidPacketBufferInHexString=[[NSString alloc] init];
21352135

21362136
int datalen; //data length given on the RFID packet
2137+
int sequenceNumber=0;
2138+
21372139
while (self.bleDevice) //packet decoding will continue as long as there is a connected device instance
21382140
{
21392141
@autoreleasepool {
@@ -2145,6 +2147,30 @@ - (void)decodePacketsInBufferAsync;
21452147
if ([packet isKindOfClass:[NSNull class]]) {
21462148
continue;
21472149
}
2150+
2151+
if (packet.direction==Uplink && packet.deviceId==RFID) {
2152+
2153+
NSLog(@"[decodePacketsInBufferAsync] Current sequence number: %d", sequenceNumber);
2154+
2155+
//validate checksum of packet
2156+
if (!packet.isCRCPassed) {
2157+
NSLog(@"[decodePacketsInBufferAsync] Checksum verification failed. Discarding data in buffer");
2158+
[rfidPacketBuffer setLength:0];
2159+
continue;
2160+
}
2161+
2162+
if ([rfidPacketBuffer length] == 0)
2163+
sequenceNumber=packet.Reserve;
2164+
else {
2165+
if (packet.Reserve != (sequenceNumber+1)) {
2166+
NSLog(@"[decodePacketsInBufferAsync] Packet out-of-order based on sequence number. Discarding data in buffer");
2167+
[rfidPacketBuffer setLength:0];
2168+
continue;
2169+
}
2170+
else
2171+
sequenceNumber++;
2172+
}
2173+
}
21482174
}
21492175
else
21502176
continue;
@@ -2353,7 +2379,7 @@ - (void)decodePacketsInBufferAsync;
23532379
//start decode taq-response message
23542380
//length of data field (in bytes) = ((pkt_len – 3) * 4) – ((flags >> 6) & 3)
23552381
datalen=(((((Byte *)[rfidPacketBuffer bytes])[ptr+4] + (((((Byte *)[rfidPacketBuffer bytes])[ptr+5] << 8) & 0xFF00)))-3) * 4) - ((((Byte *)[rfidPacketBuffer bytes])[ptr+1] >> 6) & 3);
2356-
tag.DATALength=datalen;
2382+
tag.DATALength=datalen / 2;
23572383

23582384
/*
23592385
if (tag.DATA1Length > 0 && (((tag.DATA1Length + tag.DATA2Length) * 2) == datalen))
@@ -2384,7 +2410,9 @@ - (void)decodePacketsInBufferAsync;
23842410

23852411
tag.ACKTimeout=(((Byte *)[rfidPacketBuffer bytes])[ptr+1] & 0x04) >> 2;
23862412

2387-
if ((((Byte *)[rfidPacketBuffer bytes])[ptr+1] & 0x02) >> 1 && tag.BackScatterError == 0xFF && !tag.CRCError && !tag.ACKTimeout) {
2413+
//if access error occurred and nothg of the following: tag backscatter error, ack time out, crc error indicated a fault,
2414+
//read error code form the data field
2415+
if ((((Byte *)[rfidPacketBuffer bytes])[ptr+1] & 0x01) && tag.BackScatterError == 0xFF && !tag.CRCError && !tag.ACKTimeout) {
23882416
tag.AccessError=((Byte *)[rfidPacketBuffer bytes])[ptr+20];
23892417
}
23902418
else
@@ -2587,7 +2615,8 @@ - (void)decodePacketsInBufferAsync;
25872615
tag.PC =((((Byte *)[rfidPacketBuffer bytes])[ptr] << 8) & 0xFF00)+ ((Byte *)[rfidPacketBuffer bytes])[ptr+1];
25882616

25892617
//for the case where we reaches to the end of the BLE packet but not the RFID response packet, where there will be partial packet to be returned from the next packet. The partial tag data will be combined with the next packet being returned.
2590-
if ((ptr + (2 + ((tag.PC >> 11) * 2) + 1)) > ([rfidPacketBuffer length])) {
2618+
//8100 (two bytes) + 8 bytes RFID packet header + payload length being calcuated ont he header
2619+
if ((10 + datalen) > [rfidPacketBuffer length]) {
25912620
//stop decoding and wait for the partial tag data to be appended in the next packet arrival
25922621
NSLog(@"[decodePacketsInBufferAsync] partial tag data being returned. Wait for next rfid response packet for complete tag data.");
25932622
break;

0 commit comments

Comments
 (0)