Skip to content

Commit

Permalink
Merge pull request #3 from cslrfid/release-S3.2
Browse files Browse the repository at this point in the history
Release s3.2
  • Loading branch information
ksclam authored Dec 30, 2020
2 parents 02c5777 + 70c85c5 commit 7f92593
Show file tree
Hide file tree
Showing 22 changed files with 601 additions and 179 deletions.
31 changes: 31 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Gcc Patch
/*.gcno

.DS_Store

*.xcuserstate
CS108iOSClient.xcodeproj/xcuserdata/TurtleMac01.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
4 changes: 2 additions & 2 deletions CS108iOSClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = S3.1;
MARKETING_VERSION = S3.2;
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
PRODUCT_NAME = CS108Swift;
SWIFT_OBJC_BRIDGING_HEADER = "CS108iOSClient/ViewControllers/CS108iOSClient-Bridging-Header.h";
Expand Down Expand Up @@ -655,7 +655,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = S3.1;
MARKETING_VERSION = S3.2;
PRODUCT_BUNDLE_IDENTIFIER = com.csl.CS108iOSClient;
PRODUCT_NAME = CS108Swift;
SWIFT_OBJC_BRIDGING_HEADER = "CS108iOSClient/ViewControllers/CS108iOSClient-Bridging-Header.h";
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions CS108iOSClient/CSLReader/CSLBleReader+AccessControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL) TAGMSK_PTR:(UInt16)ptr;
- (BOOL) TAGMSK_LEN:(Byte)length;
- (BOOL) setTAGMSK:(UInt16)TAGMSKAddr tagMask:(UInt32)mask;
- (BOOL) TAGWRDAT_SEL:(UInt16)bank;

- (BOOL) TAGACC_BANK:(MEMORYBANK)bank acc_bank2:(MEMORYBANK)bank2;
- (BOOL) TAGACC_PTR:(UInt32)ptr;
Expand Down
194 changes: 145 additions & 49 deletions CS108iOSClient/CSLReader/CSLBleReader+AccessControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,67 @@ - (BOOL) setTAGWRDAT:(UInt16)TAGWRDATAddr data_word:(UInt16)word data_offset:(UI
}
}

- (BOOL) TAGWRDAT_SEL:(UInt16)bank {

@synchronized(self) {
if (connectStatus!=CONNECTED)
{
NSLog(@"Reader is not connected or busy. Access failure");
return false;
}
connectStatus=BUSY;
}
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
[self.recvQueue removeAllObjects];
[self.cmdRespQueue removeAllObjects];

//Initialize data
CSLBlePacket* packet= [[CSLBlePacket alloc] init];
NSData * payloadData;

NSLog(@"----------------------------------------------------------------------");
NSLog(@"TAGWRDAT_SEL - Used to access the tag write buffer. The buffer is set up as a 16 register array.");
NSLog(@"----------------------------------------------------------------------");
unsigned char TAGWRDAT_SEL[] = {0x80, 0x02, 0x70, 0x01, 0x08, 0x0A, bank & 0x7, 0x00, 0x00, 0x00};
packet.prefix=0xA7;
packet.connection = Bluetooth;
packet.payloadLength=0x0A;
packet.deviceId=RFID;
packet.Reserve=0x82;
packet.direction=Downlink;
packet.crc1=0;
packet.crc2=0;
packet.payload=[NSData dataWithBytes:TAGWRDAT_SEL length:sizeof(TAGWRDAT_SEL)];

NSLog(@"BLE packet sending: %@", [packet getPacketInHexString]);
[self sendPackets:packet];

for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
if([self.cmdRespQueue count] != 0)
break;
[NSThread sleepForTimeInterval:0.001f];
}
if ([self.cmdRespQueue count] != 0)
payloadData = ((CSLBlePacket *)[self.cmdRespQueue deqObject]).payload;
else
{
NSLog(@"Command timed out.");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes
return false;
}
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
if (memcmp([payloadData bytes], TAGWRDAT_SEL, 2) == 0 && ((Byte *)[payloadData bytes])[2] == 0x00) {
NSLog(@"TAGWRDAT_SEL sent OK");
return true;
}
else {
NSLog(@"TAGWRDAT_SEL sent FAILED");
return false;
}
}

- (BOOL) sendHostCommandWrite {

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

result = [self TAGACC_DESC_CFG:true retryCount:7];
result = [self TAGACC_BANK:bank acc_bank2:0];
result = [self TAGACC_PTR:0];
result = [self TAGACC_PTR:offset];
result = [self TAGACC_CNT:count secondBank:0];
result = [self TAGACC_ACCPWD:password];


ptr=0; ptr2=0;
ptr+=offset;
while ([data length] > ptr2) {
if (count >= ptr) {
//set TAGWRDAT bank
[self TAGWRDAT_SEL:(ptr2/32)];

if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A09 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
Expand Down Expand Up @@ -1570,58 +1634,90 @@ - (BOOL) startTagMemoryWrite:(MEMORYBANK)bank dataOffset:(UInt16)offset dataCoun
ptr++; ptr2+=2;
}
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A0A data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
result = [self setTAGWRDAT:0x0A10 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}

result = [self sendHostCommandWrite];

//wait for the command-begin and command-end packet
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
if ([self.cmdRespQueue count] >= 2)
break;
[NSThread sleepForTimeInterval:0.001f];
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A11 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}

if ([self.cmdRespQueue count] < 2) {
NSLog(@"Tag read command timed out.");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return false;
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A12 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}

//command-begin
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
if (([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] &&
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0080"]) ||
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] &&
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0000"])
) {
self.lastMacErrorCode=0x0000;
NSLog(@"Receive read command-begin response: OK");
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A13 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
else
{
NSLog(@"Receive read command-begin response: FAILED");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return FALSE;
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A14 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}

//decode command-end
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
if (
([[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) ||
([[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)
)
NSLog(@"Receive read command-end response: OK");
else
{
NSLog(@"Receive read command-end response: FAILED");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return FALSE;
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A15 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A16 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A17 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
if ([data length] > ptr2) {
result = [self setTAGWRDAT:0x0A18 data_word:((((Byte*)[data bytes])[ptr2] << 8)+((Byte*)[data bytes])[ptr2+1]) data_offset:ptr];
ptr++; ptr2+=2;
}
}

result = [self sendHostCommandWrite];

//wait for the command-begin and command-end packet
for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 5 seconds
if ([self.cmdRespQueue count] >= 2)
break;
[NSThread sleepForTimeInterval:0.001f];
}

if ([self.cmdRespQueue count] < 2) {
NSLog(@"Tag read command timed out.");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return false;
}

//command-begin
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
if (([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"02"] &&
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0080"]) ||
([[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(4, 2)] isEqualToString:@"01"] &&
[[recvPacket.getPacketPayloadInHexString substringWithRange:NSMakeRange(8, 4)] isEqualToString:@"0000"])
) {
self.lastMacErrorCode=0x0000;
NSLog(@"Receive read command-begin response: OK");
}
else
{
NSLog(@"Receive read command-begin response: FAILED");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return FALSE;
}

//decode command-end
recvPacket = ((CSLBlePacket *)[self.cmdRespQueue deqObject]);
if (
([[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) ||
([[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)
)
NSLog(@"Receive read command-end response: OK");
else
{
NSLog(@"Receive read command-end response: FAILED");
connectStatus=CONNECTED;
[self.delegate didInterfaceChangeConnectStatus:self]; //this will call the method for connections status chagnes.
return FALSE;
}

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

for (int i=0;i<COMMAND_TIMEOUT_5S;i++) { //receive data or time out in 3 seconds
([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]);
([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.001]]);
if(connectStatus == CONNECTED)
break;
}
Expand Down
11 changes: 11 additions & 0 deletions CS108iOSClient/CSLReader/CSLBleReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ Once it is started, the delegate will be triggered everytime when a battery leve
Stop battery level reporting (notification every 5 seconds)
@return TRUE if the operation is successful
*/
- (BOOL)getSingleBatteryReport;
/**
Get single battery reporting
@return TRUE if the operation is successful
*/
- (BOOL)stopBatteryAutoReporting;
/**
Obtain RFID module firmware version
Expand Down Expand Up @@ -458,6 +463,12 @@ Select which set of algorithm parameter registers to access.
@return TRUE if the operation is successful
*/
- (BOOL)stopInventory;
/**
Set power mode of the device
@param isLowPowerMode Normal Mode = 0, low power standby mode = 1
@return TRUE if the operation is successful
*/
- (BOOL)setPowerMode:(BOOL)isLowPowerMode;
/**
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)
*/
Expand Down
Loading

0 comments on commit 7f92593

Please sign in to comment.