Skip to content

Commit cb29e88

Browse files
committed
Read object renamed to Select object
1 parent ca27a86 commit cb29e88

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

iOSDFULibrary/Classes/Implementation/SecureDFU/Characteristics/SecureDFUControlPoint.swift

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal enum SecureDFUOpCode : UInt8 {
3737
case calculateChecksum = 0x03
3838
case execute = 0x04
3939
// case no-such-op-code = 0x05
40-
case readObjectInfo = 0x06
40+
case selectObject = 0x06
4141
case getMtu = 0x07 // not supported by this library
4242
case write = 0x08 // not supported by this library
4343
case ping = 0x09 // not supported by this library
@@ -127,8 +127,8 @@ internal enum SecureDFURequest {
127127
case getProtocolVersion
128128
case createCommandObject(withSize: UInt32)
129129
case createDataObject(withSize: UInt32)
130-
case readCommandObjectInfo
131-
case readDataObjectInfo
130+
case selectCommandObject
131+
case selectDataObject
132132
case setPacketReceiptNotification(value: UInt16)
133133
case calculateChecksumCommand
134134
case executeCommand
@@ -139,30 +139,30 @@ internal enum SecureDFURequest {
139139
case getFwVersion(image: SecureDFUImageType)
140140
case abort
141141

142-
var data : Data {
142+
var data: Data {
143143
switch self {
144144
case .getProtocolVersion:
145145
return Data([SecureDFUOpCode.getProtocolVersion.code])
146-
case .createDataObject(let aSize):
146+
case .createDataObject(let size):
147147
var data = Data([SecureDFUOpCode.createObject.code, SecureDFUProcedureType.data.rawValue])
148-
data += aSize.littleEndian
148+
data += size.littleEndian
149149
return data
150-
case .createCommandObject(let aSize):
150+
case .createCommandObject(let size):
151151
var data = Data([SecureDFUOpCode.createObject.code, SecureDFUProcedureType.command.rawValue])
152-
data += aSize.littleEndian
152+
data += size.littleEndian
153153
return data
154-
case .setPacketReceiptNotification(let aSize):
154+
case .setPacketReceiptNotification(let size):
155155
var data = Data([SecureDFUOpCode.setPRNValue.code])
156-
data += aSize.littleEndian
156+
data += size.littleEndian
157157
return data
158158
case .calculateChecksumCommand:
159159
return Data([SecureDFUOpCode.calculateChecksum.code])
160160
case .executeCommand:
161161
return Data([SecureDFUOpCode.execute.code])
162-
case .readCommandObjectInfo:
163-
return Data([SecureDFUOpCode.readObjectInfo.code, SecureDFUProcedureType.command.rawValue])
164-
case .readDataObjectInfo:
165-
return Data([SecureDFUOpCode.readObjectInfo.code, SecureDFUProcedureType.data.rawValue])
162+
case .selectCommandObject:
163+
return Data([SecureDFUOpCode.selectObject.code, SecureDFUProcedureType.command.rawValue])
164+
case .selectDataObject:
165+
return Data([SecureDFUOpCode.selectObject.code, SecureDFUProcedureType.data.rawValue])
166166
case .getMtu:
167167
return Data([SecureDFUOpCode.getMtu.code])
168168
case .write(let bytes):
@@ -181,7 +181,7 @@ internal enum SecureDFURequest {
181181
}
182182
}
183183

184-
var description : String {
184+
var description: String {
185185
switch self {
186186
case .getProtocolVersion: return "Get Protocol Version (Op Code = 0)"
187187
case .createCommandObject(let size): return "Create Command Object (Op Code = 1, Type = 1, Size: \(size)b)"
@@ -190,8 +190,8 @@ internal enum SecureDFURequest {
190190
return "Packet Receipt Notif Req (Op Code = 2, Value = \(number))"
191191
case .calculateChecksumCommand: return "Calculate Checksum (Op Code = 3)"
192192
case .executeCommand: return "Execute Object (Op Code = 4)"
193-
case .readCommandObjectInfo: return "Read Command Object Info (Op Code = 6, Type = 1)"
194-
case .readDataObjectInfo: return "Read Data Object Info (Op Code = 6, Type = 2)"
193+
case .selectCommandObject: return "Select Command Object (Op Code = 6, Type = 1)"
194+
case .selectDataObject: return "Select Data Object (Op Code = 6, Type = 2)"
195195
case .getMtu: return "Get MTU (Op Code = 7)"
196196
case .write(let bytes): return "Write (Op Code = 8, Data = 0x\(bytes.hexString), Length = \(bytes.count))"
197197
case .ping(let id): return "Ping (Op Code = 9, ID = \(id))"
@@ -268,8 +268,8 @@ internal struct SecureDFUResponse {
268268
case .success:
269269
// Parse response data in case of a success.
270270
switch requestOpCode {
271-
case .readObjectInfo:
272-
// The correct reponse for Read Object Info has additional 12 bytes:
271+
case .selectObject:
272+
// The correct reponse for Select Object has additional 12 bytes:
273273
// Max Object Size, Offset and CRC.
274274
guard data.count >= 15 else { return nil }
275275
let maxSize : UInt32 = data.asValue(offset: 3)
@@ -287,7 +287,7 @@ internal struct SecureDFUResponse {
287287
let offset : UInt32 = data.asValue(offset: 3)
288288
let crc : UInt32 = data.asValue(offset: 7)
289289

290-
self.maxSize = 0
290+
self.maxSize = nil
291291
self.offset = offset
292292
self.crc = crc
293293
self.error = nil
@@ -298,9 +298,7 @@ internal struct SecureDFUResponse {
298298
self.error = nil
299299
}
300300
case .extendedError:
301-
// If extended error was received, parse the extended error code
302-
// The correct response for Read Error request has 4 bytes.
303-
// The 4th byte is the extended error code.
301+
// If extended error was received, the 4th byte is the extended error code.
304302
guard data.count >= 4,
305303
let error = SecureDFUExtendedErrorCode(rawValue: data[3]) else {
306304
return nil
@@ -331,14 +329,14 @@ internal struct SecureDFUResponse {
331329
return "Response (Op Code = \(requestOpCode.rawValue), Status = \(status.rawValue), Unsupported Extended Error value)"
332330
case .success:
333331
switch requestOpCode {
334-
case .readObjectInfo:
332+
case .selectObject:
335333
// Max size for a command object is usually around 256. Let's say 1024,
336334
// just to be sure. This is only for logging, so may be wrong.
337-
return String(format: "\(maxSize! > 1024 ? "Data" : "Command") object info (Max size = \(maxSize!), Offset = \(offset!), CRC = %08X)", crc!)
335+
return String(format: "\(maxSize! > 1024 ? "Data" : "Command") object selected (Max size = \(maxSize!), Offset = \(offset!), CRC = %08X)", crc!)
338336
case .calculateChecksum:
339337
return String(format: "Checksum (Offset = \(offset!), CRC = %08X)", crc!)
340338
default:
341-
// Other responses are either not logged, or logged by service or executor,
339+
// Other responses are either not logged, or logged by the service or executor,
342340
// so this 'default' should never be called.
343341
break
344342
}
@@ -630,7 +628,7 @@ internal class SecureDFUControlPoint : NSObject, CBPeripheralDelegate, DFUCharac
630628
switch dfuResponse.status {
631629
case .success:
632630
switch dfuResponse.requestOpCode {
633-
case .readObjectInfo, .calculateChecksum:
631+
case .selectObject, .calculateChecksum:
634632
logger.a("\(dfuResponse.description) received")
635633
response?(dfuResponse)
636634
case .createObject, .setPRNValue, .execute:

iOSDFULibrary/Classes/Implementation/SecureDFU/DFU/SecureDFUExecutor.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ internal class SecureDFUExecutor : DFUExecutor, SecureDFUPeripheralDelegate {
100100
} else {
101101
// The device is ready to proceed with DFU.
102102

103-
// Start by reading command object info to get the maximum write size.
104-
peripheral.readCommandObjectInfo() // -> peripheralDidSendCommandObjectInfo(...) will be
105-
// called when object received.
103+
// Start by selecting Command Object to get the maximum write size.
104+
peripheral.selectCommandObject() // -> peripheralDidSendCommandObjectInfo(...) will be
105+
// called when object received.
106106
}
107107
}
108108

@@ -160,7 +160,7 @@ internal class SecureDFUExecutor : DFUExecutor, SecureDFUPeripheralDelegate {
160160
sendInitPacket(fromOffset: offset) // -> peripheralDidReceiveInitPacket() will be called.
161161
} else {
162162
// PRNs are ready, check out the Data object.
163-
peripheral.readDataObjectInfo() // -> peripheralDidSendDataObjectInfo(...) will be called.
163+
peripheral.selectDataObject() // -> peripheralDidSendDataObjectInfo(...) will be called.
164164
}
165165
}
166166

@@ -278,7 +278,7 @@ internal class SecureDFUExecutor : DFUExecutor, SecureDFUPeripheralDelegate {
278278
}
279279
}
280280

281-
func peripheralDidSendDataObjectInfo(maxLen: UInt32, offset: UInt32, crc: UInt32 ) {
281+
func peripheralDidSendDataObjectInfo(maxLen: UInt32, offset: UInt32, crc: UInt32) {
282282
self.offset = offset
283283

284284
// This is the initial state, if ranges aren't set, assume this is the first

iOSDFULibrary/Classes/Implementation/SecureDFU/Peripheral/SecureDFUPeripheral.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ internal class SecureDFUPeripheral : BaseCommonDFUPeripheral<SecureDFUExecutor,
156156
}
157157

158158
/**
159-
Reads Data Object Info in order to obtain current status and the maximum
160-
object size.
159+
Selects Data Object. As a result, the current status and the maximum
160+
object size is returned.
161161
*/
162-
func readDataObjectInfo() {
163-
dfuService?.readDataObjectInfo(
162+
func selectDataObject() {
163+
dfuService?.selectDataObject(
164164
onReponse: { [weak self] response in
165165
guard let self = self else { return }
166166
guard response.maxSize! > 0 else {
@@ -178,11 +178,11 @@ internal class SecureDFUPeripheral : BaseCommonDFUPeripheral<SecureDFUExecutor,
178178
}
179179

180180
/**
181-
Reads Command Object Info in order to obtain current status and the maximum
182-
object size.
181+
Selects Command Object. As a result, the current status and the maximum
182+
object size is returned.
183183
*/
184-
func readCommandObjectInfo() {
185-
dfuService?.readCommandObjectInfo(
184+
func selectCommandObject() {
185+
dfuService?.selectCommandObject(
186186
onReponse: { [weak self] response in
187187
guard let self = self else { return }
188188
guard response.maxSize! > 0 else {

iOSDFULibrary/Classes/Implementation/SecureDFU/Services/SecureDFUService.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,31 +199,31 @@ import CoreBluetooth
199199
}
200200

201201
/**
202-
Reads Command Object Info. Result it reported using callbacks.
202+
Selects the Command Object. Result it reported using callbacks.
203203

204204
- parameter response: Method called when the response was received.
205205
- parameter report: Method called when an error occurred.
206206
*/
207-
func readCommandObjectInfo(onReponse response: @escaping SecureDFUResponseCallback,
208-
onError report: @escaping ErrorCallback) {
207+
func selectCommandObject(onReponse response: @escaping SecureDFUResponseCallback,
208+
onError report: @escaping ErrorCallback) {
209209
if !aborted {
210-
dfuControlPointCharacteristic?.send(.readCommandObjectInfo,
210+
dfuControlPointCharacteristic?.send(.selectCommandObject,
211211
onResponse: response, onError: report)
212212
} else {
213213
sendReset(onError: report)
214214
}
215215
}
216216

217217
/**
218-
Reads object info Data. Result it reported using callbacks.
218+
Selects the Data Object. Result it reported using callbacks.
219219

220220
- parameter response: Method called when the response was received.
221221
- parameter report: Method called when an error occurred.
222222
*/
223-
func readDataObjectInfo(onReponse response: @escaping SecureDFUResponseCallback,
224-
onError report: @escaping ErrorCallback) {
223+
func selectDataObject(onReponse response: @escaping SecureDFUResponseCallback,
224+
onError report: @escaping ErrorCallback) {
225225
if !aborted {
226-
dfuControlPointCharacteristic?.send(.readDataObjectInfo,
226+
dfuControlPointCharacteristic?.send(.selectDataObject,
227227
onResponse: response, onError: report)
228228
} else {
229229
sendReset(onError: report)

0 commit comments

Comments
 (0)