Skip to content

Commit

Permalink
Merge pull request #180 from NordicSemiconductor/overflow-operator
Browse files Browse the repository at this point in the history
Use of native Swift Overflow Operator to rotate Sequence Numbers
  • Loading branch information
dinesharjani authored Nov 28, 2023
2 parents a396f1d + 02a8e4e commit f0d4787
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions Source/McuManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public typealias McuSequenceNumber = UInt8

extension McuSequenceNumber {

mutating func rotate() {
self = self == .max ? 0 : self + 1
}

static func random() -> McuSequenceNumber {
McuSequenceNumber.random(in: UInt8.min...UInt8.max)
}
Expand Down Expand Up @@ -140,7 +136,8 @@ open class McuManager {
robBuffer.logDelegate = logDelegate
robBuffer.enqueueExpectation(for: packetSequenceNumber)
send(data: packetData, timeout: timeout, callback: _callback)
nextSequenceNumber.rotate()
// Use of Overflow operator
nextSequenceNumber = nextSequenceNumber &+ 1
}

public func send<T: McuMgrResponse>(data: Data, timeout: Int, callback: @escaping McuMgrCallback<T>) {
Expand Down

0 comments on commit f0d4787

Please sign in to comment.