@@ -1957,8 +1957,10 @@ - (BOOL)setLinkProfile:(LINKPROFILE) profile
19571957 recvPacket = ((CSLBlePacket *)[cmdRespQueue deqObject ]);
19581958 if (([[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (4 , 2 )] isEqualToString: @" 02" ] && [[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (8 , 4 )] isEqualToString: @" 0080" ]) ||
19591959 ([[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (4 , 2 )] isEqualToString: @" 01" ] && [[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (8 , 4 )] isEqualToString: @" 0000" ])
1960- )
1960+ ) {
1961+ self.lastMacErrorCode =0x0000 ;
19611962 NSLog (@" Receive HST_CMD 0x19 command-begin response: OK" );
1963+ }
19621964 else
19631965 {
19641966 NSLog (@" Receive HST_CMD 0x19 command-begin response: FAILED" );
@@ -1972,11 +1974,14 @@ - (BOOL)setLinkProfile:(LINKPROFILE) profile
19721974 if (([[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (4 , 2 )] isEqualToString: @" 02" ] || [[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (4 , 2 )] isEqualToString: @" 01" ]) &&
19731975 ([[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (8 , 4 )] isEqualToString: @" 0180" ] || [[recvPacket.getPacketPayloadInHexString substringWithRange: NSMakeRange (8 , 4 )] isEqualToString: @" 0100" ]) &&
19741976 ((Byte *)[recvPacket.payload bytes ])[14 ] == 0x00 &&
1975- ((Byte *)[recvPacket.payload bytes ])[15 ] == 0x00 )
1977+ ((Byte *)[recvPacket.payload bytes ])[15 ] == 0x00 ) {
1978+ self.lastMacErrorCode =(((Byte *)[recvPacket.payload bytes ])[15 ] << 8 ) + (((Byte *)[recvPacket.payload bytes ])[14 ]);
19761979 NSLog (@" Receive HST_CMD 0x19 command-end response: OK" );
1980+ }
19771981 else
19781982 {
19791983 NSLog (@" Receive HST_CMD 0x19 command-end response: FAILED" );
1984+ self.lastMacErrorCode =(((Byte *)[recvPacket.payload bytes ])[15 ] << 8 ) + (((Byte *)[recvPacket.payload bytes ])[14 ]);
19801985 connectStatus=CONNECTED;
19811986 [self .delegate didInterfaceChangeConnectStatus: self ]; // this will call the method for connections status chagnes.
19821987 return FALSE ;
@@ -2222,6 +2227,7 @@ - (void)decodePacketsInBufferAsync;
22222227 ([[rfidPacketBufferInHexString substringWithRange: NSMakeRange (4 , 2 )] isEqualToString: @" 01" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange (8 , 4 )] isEqualToString: @" 0000" ])
22232228 ) {
22242229 NSLog (@" [decodePacketsInBufferAsync] Command-begin response recieved: %@ " , rfidPacketBufferInHexString);
2230+ self.lastMacErrorCode =0x0000 ;
22252231 // return packet directly to the API for decoding
22262232 [cmdRespQueue enqObject: packet];
22272233 [rfidPacketBuffer setLength: 0 ];
@@ -2238,6 +2244,7 @@ - (void)decodePacketsInBufferAsync;
22382244 ) {
22392245 NSLog (@" [decodePacketsInBufferAsync] Command-end response recieved: %@ " , rfidPacketBufferInHexString);
22402246 // return packet directly to the API for decoding
2247+ self.lastMacErrorCode =(((Byte *)[rfidPacketBuffer bytes ])[15 ] << 8 ) + (((Byte *)[rfidPacketBuffer bytes ])[14 ]);
22412248 [cmdRespQueue enqObject: packet];
22422249 [rfidPacketBuffer setLength: 0 ];
22432250 connectStatus=CONNECTED;
@@ -2436,6 +2443,7 @@ - (void)decodePacketsInBufferAsync;
24362443 ([[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , 2 )] isEqualToString: @" 01" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange ((ptr+2 ) * 2 , 4 )] isEqualToString: @" 0100" ])
24372444 ) {
24382445
2446+ self.lastMacErrorCode =(((Byte *)[rfidPacketBuffer bytes ])[ptr+13 ] << 8 ) + (((Byte *)[rfidPacketBuffer bytes ])[ptr+12 ]);
24392447 // partial command-end packet received
24402448 // remove decoded data from rfid buffer and leave the partial packet on the buffer with 8100 appended to the beginning
24412449
@@ -2554,6 +2562,18 @@ - (void)decodePacketsInBufferAsync;
25542562 [self .delegate didInterfaceChangeConnectStatus: self ]; // this will call the method for connections status chagnes.
25552563 break ;
25562564 }
2565+ // for the case where command-end appended to the packet as the radio stopped unexpectedly
2566+ else if ([[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] containsString: @" 0101010002000000" ]) {
2567+ NSLog (@" [decodePacketsInBufferAsync] Unexpected command-end received. All operations ended" );
2568+ // get mac error code
2569+ int startOfCmdEnd=(int )[[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] rangeOfString: @" 0101010002000000" ].location / 2 ;
2570+ self.lastMacErrorCode =(((Byte *)[rfidPacketBuffer bytes ])[ptr+startOfCmdEnd+13 ] << 8 ) + (((Byte *)[rfidPacketBuffer bytes ])[ptr+startOfCmdEnd+12 ]);
2571+ [cmdRespQueue enqObject: packet];
2572+ [rfidPacketBuffer setLength: 0 ];
2573+ connectStatus=CONNECTED;
2574+ [self .delegate didInterfaceChangeConnectStatus: self ]; // this will call the method for connections status chagnes.
2575+ break ;
2576+ }
25572577 // check if we are getting the beginning of another 8100 packet but with no 8100 event code. If so, add the event code back with the header response
25582578 else if (![[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] containsString: @" 8100" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange ((ptr * 2 ), 2 )] isEqualToString: @" 03" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange ((ptr * 2 )+4 , 4 )] isEqualToString: @" 0580" ]) {
25592579
@@ -2677,6 +2697,18 @@ - (void)decodePacketsInBufferAsync;
26772697 [self .delegate didInterfaceChangeConnectStatus: self ]; // this will call the method for connections status chagnes.
26782698 break ;
26792699 }
2700+ // for the case where command-end appended to the packet as the radio stopped unexpectedly
2701+ else if ([[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] containsString: @" 0101010002000000" ]) {
2702+ NSLog (@" [decodePacketsInBufferAsync] Unexpected command-end received. All operations ended" );
2703+ // get mac error code
2704+ int startOfCmdEnd=(int )[[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] rangeOfString: @" 0101010002000000" ].location / 2 ;
2705+ self.lastMacErrorCode =(((Byte *)[rfidPacketBuffer bytes ])[ptr+startOfCmdEnd+13 ] << 8 ) + (((Byte *)[rfidPacketBuffer bytes ])[ptr+startOfCmdEnd+12 ]);
2706+ [cmdRespQueue enqObject: packet];
2707+ [rfidPacketBuffer setLength: 0 ];
2708+ connectStatus=CONNECTED;
2709+ [self .delegate didInterfaceChangeConnectStatus: self ]; // this will call the method for connections status chagnes.
2710+ break ;
2711+ }
26802712 // check if we are getting the beginning of another 8100 packet but with no 8100 event code. If so, add the event code back with the header response
26812713 else if (![[rfidPacketBufferInHexString substringWithRange: NSMakeRange (ptr * 2 , ([rfidPacketBuffer length ] - ptr) * 2 )] containsString: @" 8100" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange ((ptr * 2 ), 2 )] isEqualToString: @" 04" ] && [[rfidPacketBufferInHexString substringWithRange: NSMakeRange ((ptr * 2 )+4 , 4 )] isEqualToString: @" 0580" ]) {
26822714
0 commit comments