Skip to content

Commit b5b13de

Browse files
authored
Merge pull request #39 from cslrfid/release-3.2
Release 3.2
2 parents 406c6b2 + 5a8fe48 commit b5b13de

22 files changed

+611
-195
lines changed

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# Xcode
2+
#
3+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
4+
5+
## User settings
6+
xcuserdata/
7+
8+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9+
*.xcscmblueprint
10+
*.xccheckout
11+
12+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
13+
build/
14+
DerivedData/
15+
*.moved-aside
16+
*.pbxuser
17+
!default.pbxuser
18+
*.mode1v3
19+
!default.mode1v3
20+
*.mode2v3
21+
!default.mode2v3
22+
*.perspectivev3
23+
!default.perspectivev3
24+
25+
## Gcc Patch
26+
/*.gcno
27+
28+
.DS_Store
129

230
*.xcuserstate
331
CS108iOSClient.xcodeproj/xcuserdata/TurtleMac01.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

CS108iOSClient.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
"$(inherited)",
666666
"@executable_path/Frameworks",
667667
);
668-
MARKETING_VERSION = 3.1;
668+
MARKETING_VERSION = 3.2;
669669
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
670670
PRODUCT_NAME = "$(TARGET_NAME)";
671671
TARGETED_DEVICE_FAMILY = "1,2";
@@ -688,7 +688,7 @@
688688
"$(inherited)",
689689
"@executable_path/Frameworks",
690690
);
691-
MARKETING_VERSION = 3.1;
691+
MARKETING_VERSION = 3.2;
692692
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
693693
PRODUCT_NAME = "$(TARGET_NAME)";
694694
TARGETED_DEVICE_FAMILY = "1,2";

CS108iOSClient/CSLReader/CSLBleReader+AccessControl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4848
- (BOOL) TAGMSK_PTR:(UInt16)ptr;
4949
- (BOOL) TAGMSK_LEN:(Byte)length;
5050
- (BOOL) setTAGMSK:(UInt16)TAGMSKAddr tagMask:(UInt32)mask;
51+
- (BOOL) TAGWRDAT_SEL:(UInt16)bank;
5152

5253
- (BOOL) TAGACC_BANK:(MEMORYBANK)bank acc_bank2:(MEMORYBANK)bank2;
5354
- (BOOL) TAGACC_PTR:(UInt32)ptr;

CS108iOSClient/CSLReader/CSLBleReader+AccessControl.m

Lines changed: 145 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,67 @@ - (BOOL) setTAGWRDAT:(UInt16)TAGWRDATAddr data_word:(UInt16)word data_offset:(UI
890890
}
891891
}
892892

893+
- (BOOL) TAGWRDAT_SEL:(UInt16)bank {
894+
895+
@synchronized(self) {
896+
if (connectStatus!=CONNECTED)
897+
{
898+
NSLog(@"Reader is not connected or busy. Access failure");
899+
return false;
900+
}
901+
connectStatus=BUSY;
902+
}
903+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
904+
[self.recvQueue removeAllObjects];
905+
[self.cmdRespQueue removeAllObjects];
906+
907+
//Initialize data
908+
CSLBlePacket* packet= [[CSLBlePacket alloc] init];
909+
NSData * payloadData;
910+
911+
NSLog(@"----------------------------------------------------------------------");
912+
NSLog(@"TAGWRDAT_SEL - Used to access the tag write buffer. The buffer is set up as a 16 register array.");
913+
NSLog(@"----------------------------------------------------------------------");
914+
unsigned char TAGWRDAT_SEL[] = {0x80, 0x02, 0x70, 0x01, 0x08, 0x0A, bank & 0x7, 0x00, 0x00, 0x00};
915+
packet.prefix=0xA7;
916+
packet.connection = Bluetooth;
917+
packet.payloadLength=0x0A;
918+
packet.deviceId=RFID;
919+
packet.Reserve=0x82;
920+
packet.direction=Downlink;
921+
packet.crc1=0;
922+
packet.crc2=0;
923+
packet.payload=[NSData dataWithBytes:TAGWRDAT_SEL length:sizeof(TAGWRDAT_SEL)];
924+
925+
NSLog(@"BLE packet sending: %@", [packet getPacketInHexString]);
926+
[self sendPackets:packet];
927+
928+
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
929+
if([self.cmdRespQueue count] != 0)
930+
break;
931+
[NSThread sleepForTimeInterval:0.001f];
932+
}
933+
if ([self.cmdRespQueue count] != 0)
934+
payloadData = ((CSLBlePacket *)[self.cmdRespQueue deqObject]).payload;
935+
else
936+
{
937+
NSLog(@"Command timed out.");
938+
connectStatus=CONNECTED;
939+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes
940+
return false;
941+
}
942+
connectStatus=CONNECTED;
943+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
944+
if (memcmp([payloadData bytes], TAGWRDAT_SEL, 2) == 0 && ((Byte *)[payloadData bytes])[2] == 0x00) {
945+
NSLog(@"TAGWRDAT_SEL sent OK");
946+
return true;
947+
}
948+
else {
949+
NSLog(@"TAGWRDAT_SEL sent FAILED");
950+
return false;
951+
}
952+
}
953+
893954
- (BOOL) sendHostCommandWrite {
894955

895956
@synchronized(self) {
@@ -1534,14 +1595,17 @@ - (BOOL) startTagMemoryWrite:(MEMORYBANK)bank dataOffset:(UInt16)offset dataCoun
15341595

15351596
result = [self TAGACC_DESC_CFG:true retryCount:7];
15361597
result = [self TAGACC_BANK:bank acc_bank2:0];
1537-
result = [self TAGACC_PTR:0];
1598+
result = [self TAGACC_PTR:offset];
15381599
result = [self TAGACC_CNT:count secondBank:0];
15391600
result = [self TAGACC_ACCPWD:password];
15401601

1602+
15411603
ptr=0; ptr2=0;
1542-
ptr+=offset;
15431604
while ([data length] > ptr2) {
1544-
if (count >= ptr) {
1605+
//set TAGWRDAT bank
1606+
[self TAGWRDAT_SEL:(ptr2/32)];
1607+
1608+
if ([data length] > ptr2) {
15451609
result = [self setTAGWRDAT:0x0A09 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
15461610
ptr++; ptr2+=2;
15471611
}
@@ -1570,58 +1634,90 @@ - (BOOL) startTagMemoryWrite:(MEMORYBANK)bank dataOffset:(UInt16)offset dataCoun
15701634
ptr++; ptr2+=2;
15711635
}
15721636
if ([data length] > ptr2) {
1573-
result = [self setTAGWRDAT:0x0A0A data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1637+
result = [self setTAGWRDAT:0x0A10 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
15741638
ptr++; ptr2+=2;
15751639
}
1576-
1577-
result = [self sendHostCommandWrite];
1578-
1579-
//wait for the command-begin and command-end packet
1580-
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
1581-
if ([self.cmdRespQueue count] >= 2)
1582-
break;
1583-
[NSThread sleepForTimeInterval:0.001f];
1640+
if ([data length] > ptr2) {
1641+
result = [self setTAGWRDAT:0x0A11 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1642+
ptr++; ptr2+=2;
15841643
}
1585-
1586-
if ([self.cmdRespQueue count] < 2) {
1587-
NSLog(@"Tag read command timed out.");
1588-
connectStatus=CONNECTED;
1589-
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1590-
return false;
1644+
if ([data length] > ptr2) {
1645+
result = [self setTAGWRDAT:0x0A12 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1646+
ptr++; ptr2+=2;
15911647
}
1592-
1593-
//command-begin
1594-
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
1595-
if (([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] &&
1596-
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0080"]) ||
1597-
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] &&
1598-
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0000"])
1599-
) {
1600-
self.lastMacErrorCode=0x0000;
1601-
NSLog(@"Receive read command-begin response: OK");
1648+
if ([data length] > ptr2) {
1649+
result = [self setTAGWRDAT:0x0A13 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1650+
ptr++; ptr2+=2;
16021651
}
1603-
else
1604-
{
1605-
NSLog(@"Receive read command-begin response: FAILED");
1606-
connectStatus=CONNECTED;
1607-
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1608-
return FALSE;
1652+
if ([data length] > ptr2) {
1653+
result = [self setTAGWRDAT:0x0A14 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1654+
ptr++; ptr2+=2;
16091655
}
1610-
1611-
//decode command-end
1612-
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
1613-
if (
1614-
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] && [[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0180"] && ((Byte *)[recvPacket.payload bytes])[14] == 0x00 && ((Byte *)[recvPacket.payload bytes])[15] == 0x00) ||
1615-
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] && [[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0100"] && ((Byte *)[recvPacket.payload bytes])[14] == 0x00 && ((Byte *)[recvPacket.payload bytes])[15] == 0x00)
1616-
)
1617-
NSLog(@"Receive read command-end response: OK");
1618-
else
1619-
{
1620-
NSLog(@"Receive read command-end response: FAILED");
1621-
connectStatus=CONNECTED;
1622-
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1623-
return FALSE;
1656+
if ([data length] > ptr2) {
1657+
result = [self setTAGWRDAT:0x0A15 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1658+
ptr++; ptr2+=2;
1659+
}
1660+
if ([data length] > ptr2) {
1661+
result = [self setTAGWRDAT:0x0A16 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1662+
ptr++; ptr2+=2;
1663+
}
1664+
if ([data length] > ptr2) {
1665+
result = [self setTAGWRDAT:0x0A17 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1666+
ptr++; ptr2+=2;
16241667
}
1668+
if ([data length] > ptr2) {
1669+
result = [self setTAGWRDAT:0x0A18 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
1670+
ptr++; ptr2+=2;
1671+
}
1672+
}
1673+
1674+
result = [self sendHostCommandWrite];
1675+
1676+
//wait for the command-begin and command-end packet
1677+
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
1678+
if ([self.cmdRespQueue count] >= 2)
1679+
break;
1680+
[NSThread sleepForTimeInterval:0.001f];
1681+
}
1682+
1683+
if ([self.cmdRespQueue count] < 2) {
1684+
NSLog(@"Tag read command timed out.");
1685+
connectStatus=CONNECTED;
1686+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1687+
return false;
1688+
}
1689+
1690+
//command-begin
1691+
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
1692+
if (([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] &&
1693+
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0080"]) ||
1694+
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] &&
1695+
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0000"])
1696+
) {
1697+
self.lastMacErrorCode=0x0000;
1698+
NSLog(@"Receive read command-begin response: OK");
1699+
}
1700+
else
1701+
{
1702+
NSLog(@"Receive read command-begin response: FAILED");
1703+
connectStatus=CONNECTED;
1704+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1705+
return FALSE;
1706+
}
1707+
1708+
//decode command-end
1709+
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
1710+
if (
1711+
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] && [[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0180"] && ((Byte *)[recvPacket.payload bytes])[14] == 0x00 && ((Byte *)[recvPacket.payload bytes])[15] == 0x00) ||
1712+
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] && [[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0100"] && ((Byte *)[recvPacket.payload bytes])[14] == 0x00 && ((Byte *)[recvPacket.payload bytes])[15] == 0x00)
1713+
)
1714+
NSLog(@"Receive read command-end response: OK");
1715+
else
1716+
{
1717+
NSLog(@"Receive read command-end response: FAILED");
1718+
connectStatus=CONNECTED;
1719+
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
1720+
return FALSE;
16251721
}
16261722

16271723
connectStatus=CONNECTED;
@@ -1687,7 +1783,7 @@ - (BOOL)stopTagSearch {
16871783
[self performSelectorInBackground:@selector(stopTagSearchBlocking) withObject:(nil)];
16881784

16891785
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 3 seconds
1690-
([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]);
1786+
([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.001]]);
16911787
if(connectStatus == CONNECTED)
16921788
break;
16931789
}

CS108iOSClient/CSLReader/CSLBleReader.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ Once it is started, the delegate will be triggered everytime when a battery leve
312312
Stop battery level reporting (notification every 5 seconds)
313313
@return TRUE if the operation is successful
314314
*/
315+
- (BOOL)getSingleBatteryReport;
316+
/**
317+
Get single battery reporting
318+
@return TRUE if the operation is successful
319+
*/
315320
- (BOOL)stopBatteryAutoReporting;
316321
/**
317322
Obtain RFID module firmware version
@@ -458,6 +463,12 @@ Select which set of algorithm parameter registers to access.
458463
@return TRUE if the operation is successful
459464
*/
460465
- (BOOL)stopInventory;
466+
/**
467+
Set power mode of the device
468+
@param isLowPowerMode Normal Mode = 0, low power standby mode = 1
469+
@return TRUE if the operation is successful
470+
*/
471+
- (BOOL)setPowerMode:(BOOL)isLowPowerMode;
461472
/**
462473
Start the data packet decoding routine, where a selector will be running on a background thread and decode the received packet if commands were being sent out previously. Results will be returned to the recvQueue (for asynchornous commands) and to cmdRespQueue (for synchronous commands)
463474
*/

0 commit comments

Comments
 (0)