Skip to content

Commit

Permalink
Error descriptions and string convertibles simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
philips77 committed Oct 27, 2023
1 parent 0f7834c commit 5589287
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 178 deletions.
20 changes: 10 additions & 10 deletions Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,8 @@
<action selector="setEraseApplicationSettings:" destination="iEC-sa-48q" eventType="valueChanged" id="bwg-Qp-UoE"/>
</connections>
</switch>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Swap Time:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pBz-Mk-mMH">
<rect key="frame" x="16" y="212.66666666666666" width="80" height="18"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Swap time:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pBz-Mk-mMH">
<rect key="frame" x="16" y="212.66666666666666" width="75.666666666666671" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
</label>
Expand All @@ -1462,7 +1462,7 @@
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="No. of Buffers:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yVw-Wh-GgZ">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="No. of buffers:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yVw-Wh-GgZ">
<rect key="frame" x="15.999999999999993" y="238.66666666666666" width="99.333333333333314" height="17.999999999999972"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
Expand All @@ -1473,8 +1473,8 @@
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Byte Alignment:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iDf-Ds-WSW">
<rect key="frame" x="16" y="264.66666666666669" width="109" height="18"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Byte alignment:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iDf-Ds-WSW">
<rect key="frame" x="16.000000000000007" y="264.66666666666669" width="106.66666666666669" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
</label>
Expand Down Expand Up @@ -1844,7 +1844,7 @@
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="No. of Buffers:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ye4-Al-i2r">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="No. of buffers:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ye4-Al-i2r">
<rect key="frame" x="15.999999999999993" y="186.66666666666666" width="99.333333333333314" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
Expand All @@ -1855,8 +1855,8 @@
<color key="textColor" systemColor="secondaryLabelColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Byte Alignment:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FBB-05-fwn">
<rect key="frame" x="16" y="212.66666666666666" width="109" height="18"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="751" text="Byte alignment:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FBB-05-fwn">
<rect key="frame" x="16.000000000000007" y="212.66666666666666" width="106.66666666666669" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
</label>
Expand All @@ -1868,8 +1868,8 @@
<action selector="setDfuAlignment:" destination="xg9-8C-9qN" eventType="touchUpInside" id="hbO-TK-Kw6"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Chunk Size:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eu8-Tg-bYk">
<rect key="frame" x="16" y="238.66666666666666" width="82" height="17.999999999999972"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Chunk size:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eu8-Tg-bYk">
<rect key="frame" x="16" y="238.66666666666666" width="79.333333333333329" height="17.999999999999972"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<nil key="highlightedColor"/>
</label>
Expand Down
23 changes: 0 additions & 23 deletions Example/Example/Util/PeripheralState+String.swift

This file was deleted.

49 changes: 49 additions & 0 deletions Example/Example/Util/StringConvertibles.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA.
*
* SPDX-License-Identifier: Apache-2.0
*/


import Foundation
import iOSMcuManagerLibrary

extension PeripheralState: CustomStringConvertible {

public var description: String {
switch self {
case .connecting: return "CONNECTING..."
case .initializing: return "INITIALIZING..."
case .connected: return "CONNECTED"
case .disconnecting: return "DISCONNECTING..."
case .disconnected: return "DISCONNECTED"
}
}

}

extension BootloaderInfoResponse.Mode: CustomStringConvertible {

public var description: String {
switch self {
case .unknown:
return "Unknown"
case .singleApplication:
return "Single application"
case .swapUsingScratch:
return "Swap using scratch partition"
case .overwrite:
return "Overwrite (upgrade-only)"
case .swapNoScratch:
return "Swap without scratch"
case .directXIPNoRevert:
return "Direct-XIP without revert"
case .directXIPWithRevert:
return "Direct-XIP with revert"
case .RAMLoader:
return "RAM Loader"
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ extension FileUploadViewController: UIDocumentMenuDelegate, UIDocumentPickerDele
do {
return try Data(contentsOf: url)
} catch {
print("Error reading file: \(error)")
status.textColor = .systemRed
status.text = "COULD NOT OPEN FILE"
status.text = error.localizedDescription
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
// MARK: - Logic

private func setSwapTime() {
let alertController = UIAlertController(title: "Swap Time (in seconds)", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Swap time (in seconds)", message: nil, preferredStyle: .actionSheet)
let seconds = [0, 5, 10, 20, 30, 40]
seconds.forEach { numberOfSeconds in
alertController.addAction(UIAlertAction(title: "\(numberOfSeconds) seconds", style: .default) {
Expand All @@ -124,7 +124,7 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
}

private func setPipelineDepth() {
let alertController = UIAlertController(title: "Number of Buffers", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Number of buffers", message: nil, preferredStyle: .actionSheet)
let values = [2, 3, 4, 5, 6]
values.forEach { value in
let title = value == values.first ? "Disabled" : "\(value)"
Expand All @@ -139,11 +139,12 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
}

private func setByteAlignment() {
let alertController = UIAlertController(title: "Byte Alignment", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Byte alignment", message: nil, preferredStyle: .actionSheet)
ImageUploadAlignment.allCases.forEach { alignmentValue in
alertController.addAction(UIAlertAction(title: alignmentValue.description, style: .default) {
let text = "\(alignmentValue)"
alertController.addAction(UIAlertAction(title: text, style: .default) {
action in
self.dfuByteAlignment.text = alignmentValue.description
self.dfuByteAlignment.text = text
self.dfuManagerConfiguration.byteAlignment = alignmentValue
})
}
Expand All @@ -158,9 +159,9 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
guard dfuManagerConfiguration.pipelineDepth == 1 || dfuManagerConfiguration.byteAlignment != .disabled else {

dfuManagerConfiguration.byteAlignment = FirmwareUpgradeConfiguration().byteAlignment
dfuByteAlignment.text = dfuManagerConfiguration.byteAlignment.description
dfuByteAlignment.text = "\(dfuManagerConfiguration.byteAlignment)"

let alert = UIAlertController(title: "Byte Alignment Setting Changed", message: """
let alert = UIAlertController(title: "Byte alignment setting changed", message: """
Pipelining requires a Byte Alignment setting to be applied, otherwise chunk offsets can't be predicted as more Data is sent.
""", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
Expand All @@ -171,9 +172,10 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
}

private func selectMode(for package: McuMgrPackage) {
let alertController = UIAlertController(title: "Select Mode", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Select mode", message: nil, preferredStyle: .actionSheet)
FirmwareUpgradeMode.allCases.forEach { upgradeMode in
alertController.addAction(UIAlertAction(title: upgradeMode.description, style: .default) {
let text = "\(upgradeMode)"
alertController.addAction(UIAlertAction(title: text, style: .default) {
action in
self.dfuManagerConfiguration.upgradeMode = upgradeMode
self.startFirmwareUpgrade(package: package)
Expand All @@ -200,9 +202,8 @@ final class FirmwareUpgradeViewController: UIViewController, McuMgrViewControlle
do {
try dfuManager.start(images: package.images, using: dfuManagerConfiguration)
} catch {
print("Error reading hash: \(error)")
status.textColor = .systemRed
status.text = "ERROR"
status.text = error.localizedDescription
actionStart.isEnabled = false
}
}
Expand Down Expand Up @@ -282,7 +283,7 @@ extension FirmwareUpgradeViewController: FirmwareUpgradeDelegate {
actionSelect.isEnabled = true
eraseSwitch.isEnabled = true
status.textColor = .systemRed
status.text = "\(error.localizedDescription)"
status.text = error.localizedDescription
status.numberOfLines = 0
dfuSpeed.isHidden = true
}
Expand Down Expand Up @@ -359,15 +360,14 @@ extension FirmwareUpgradeViewController: UIDocumentMenuDelegate, UIDocumentPicke
dfuSwapTime.numberOfLines = 0
dfuNumberOfBuffers.text = dfuManagerConfiguration.pipelineDepth == 1 ? "Disabled" : "\(dfuManagerConfiguration.pipelineDepth + 1)"
dfuNumberOfBuffers.numberOfLines = 0
dfuByteAlignment.text = dfuManagerConfiguration.byteAlignment.description
dfuByteAlignment.text = "\(dfuManagerConfiguration.byteAlignment)"
dfuByteAlignment.numberOfLines = 0
} catch {
print("Error reading hash: \(error)")
fileName.text = url.lastPathComponent
fileSize.text = ""
fileHash.text = ""
status.textColor = .systemRed
status.text = "Error Loading File: \(error.localizedDescription)"
status.text = error.localizedDescription
status.numberOfLines = 0
actionStart.isEnabled = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FirmwareUploadViewController: UIViewController, McuMgrViewController {
}

@IBAction func setNumberOfBuffers(_ sender: UIButton) {
let alertController = UIAlertController(title: "Number of Buffers", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Number of buffers", message: nil, preferredStyle: .actionSheet)
let values = [2, 3, 4, 5, 6]
values.forEach { value in
let title = value == values.first ? "Disabled" : "\(value)"
Expand All @@ -54,19 +54,20 @@ class FirmwareUploadViewController: UIViewController, McuMgrViewController {
}

@IBAction func setDfuAlignment(_ sender: UIButton) {
let alertController = UIAlertController(title: "Byte Alignment", message: nil, preferredStyle: .actionSheet)
let alertController = UIAlertController(title: "Byte alignment", message: nil, preferredStyle: .actionSheet)
ImageUploadAlignment.allCases.forEach { alignmentValue in
alertController.addAction(UIAlertAction(title: alignmentValue.description, style: .default) {
let text = "\(alertController)"
alertController.addAction(UIAlertAction(title: text, style: .default) {
action in
self.dfuByteAlignment.text = alignmentValue.description
self.dfuByteAlignment.text = text
self.uploadConfiguration.byteAlignment = alignmentValue
})
}
present(alertController, addingCancelAction: true)
}

@IBAction func setChunkSize(_ sender: Any) {
let alertController = UIAlertController(title: "Set Chunk Size", message: "0 means Default (MTU Size)", preferredStyle: .alert)
let alertController = UIAlertController(title: "Set chunk size", message: "0 means default (MTU size)", preferredStyle: .alert)
alertController.addTextField { (textField) in
textField.placeholder = "\(self.uploadConfiguration.reassemblyBufferSize)"
textField.keyboardType = .decimalPad
Expand Down Expand Up @@ -272,7 +273,7 @@ extension FirmwareUploadViewController: UIDocumentMenuDelegate, UIDocumentPicker
fileHash.numberOfLines = 0

dfuNumberOfBuffers.text = uploadConfiguration.pipelineDepth == 1 ? "Disabled" : "\(uploadConfiguration.pipelineDepth + 1)"
dfuByteAlignment.text = uploadConfiguration.byteAlignment.description
dfuByteAlignment.text = "\(uploadConfiguration.byteAlignment)"
dfuChunkSize.text = "\(uploadConfiguration.reassemblyBufferSize)"

status.textColor = .primary
Expand All @@ -283,7 +284,7 @@ extension FirmwareUploadViewController: UIDocumentMenuDelegate, UIDocumentPicker
fileSize.text = ""
fileHash.text = ""
status.textColor = .systemRed
status.text = "INVALID FILE"
status.text = "Invalid file"
actionStart.isEnabled = false
}
(parent as! ImageController).innerViewReloaded()
Expand Down
Loading

0 comments on commit 5589287

Please sign in to comment.