@@ -29,7 +29,8 @@ final class DeviceManager: NSObject {
29
29
var onAPDUReceived : ( ( DeviceManager , Data ) -> Void ) ?
30
30
31
31
fileprivate var chunksize = 0
32
- fileprivate var pendingChunks : [ Data ] = [ ]
32
+ fileprivate var pendingOutput : [ Data ] = [ ]
33
+ fileprivate var pendingInput : [ Data ] = [ ]
33
34
fileprivate var writeCharacteristic : CBCharacteristic ?
34
35
fileprivate var notifyCharacteristic : CBCharacteristic ?
35
36
fileprivate var controlpointLengthCharacteristic : CBCharacteristic ?
@@ -68,7 +69,7 @@ final class DeviceManager: NSObject {
68
69
onDebugMessage ? ( self , " Trying to split APDU into chunks... " )
69
70
if let chunks = TransportHelper . split ( data, command: . message, chuncksize: chunksize) , chunks. count > 0 {
70
71
onDebugMessage ? ( self , " Successfully split APDU into \( chunks. count) part(s) " )
71
- pendingChunks = chunks
72
+ pendingOutput = chunks
72
73
writeNextPendingChunk ( )
73
74
}
74
75
else {
@@ -78,12 +79,12 @@ final class DeviceManager: NSObject {
78
79
}
79
80
80
81
fileprivate func writeNextPendingChunk( ) {
81
- guard pendingChunks . count > 0 else {
82
+ guard pendingOutput . count > 0 else {
82
83
onDebugMessage ? ( self , " Trying to write pending chunk but nothing left to write " )
83
84
return
84
85
}
85
86
86
- let chunk = pendingChunks . removeFirst ( )
87
+ let chunk = pendingOutput . removeFirst ( )
87
88
onDebugMessage ? ( self , " Writing pending chunk = \( chunk) " )
88
89
peripheral. writeValue ( chunk, for: writeCharacteristic!, type: . withResponse)
89
90
}
@@ -109,10 +110,10 @@ final class DeviceManager: NSObject {
109
110
}
110
111
111
112
// join APDU
112
- pendingChunks . append ( chunk)
113
- if let APDU = TransportHelper . join ( pendingChunks , command: . message) {
113
+ pendingInput . append ( chunk)
114
+ if let APDU = TransportHelper . join ( pendingInput , command: . message) {
114
115
onDebugMessage ? ( self , " Successfully joined APDU = \( APDU) " )
115
- pendingChunks . removeAll ( )
116
+ pendingInput . removeAll ( )
116
117
onAPDUReceived ? ( self , APDU)
117
118
}
118
119
}
0 commit comments