Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
Companion App iOS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
card10
Companion App iOS
Commits
9905a3cf
Commit
9905a3cf
authored
Aug 22, 2019
by
Roddi Deecke
Committed by
Thomas Mellenthin
Aug 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix control statements
mostly parentheses
parent
54b8b5e9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
28 deletions
+31
-28
.swiftlint.yml
.swiftlint.yml
+0
-2
card10badge/Bluetooth/BluetoothManager.swift
card10badge/Bluetooth/BluetoothManager.swift
+2
-2
card10badge/Bluetooth/DataTransferManager.swift
card10badge/Bluetooth/DataTransferManager.swift
+18
-13
card10badge/Conncted/ConnectedViewController.swift
card10badge/Conncted/ConnectedViewController.swift
+2
-2
card10badge/Hatchery/HatcheryClient.swift
card10badge/Hatchery/HatcheryClient.swift
+2
-2
card10badge/Hatchery/HatcheryRootTableViewController.swift
card10badge/Hatchery/HatcheryRootTableViewController.swift
+7
-7
No files found.
.swiftlint.yml
View file @
9905a3cf
...
...
@@ -18,12 +18,10 @@ disabled_rules:
-
force_cast
-
syntactic_sugar
-
implicit_getter
-
control_statement
-
todo
-
file_length
-
function_body_length
-
cyclomatic_complexity
-
unneeded_break_in_switch
-
type_body_length
-
vertical_parameter_alignment
\ No newline at end of file
card10badge/Bluetooth/BluetoothManager.swift
View file @
9905a3cf
...
...
@@ -385,7 +385,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
func
peripheral
(
_
peripheral
:
CBPeripheral
,
didDiscoverServices
error
:
Error
?)
{
for
service
in
peripheral
.
services
!
{
print
(
"found service:
\(
service
.
uuid
)
"
)
if
(
service
.
uuid
.
isEqual
(
card10ServiceUUID
)
)
{
if
service
.
uuid
.
isEqual
(
card10ServiceUUID
)
{
peripheral
.
discoverCharacteristics
([
card10TimeCharacteristic
,
card10VibrateCharacteristic
,
card10RocketsCharacteristic
,
...
...
@@ -399,7 +399,7 @@ class BluetoothManager: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
card10SingleRgbLedCharacteristic
,
card10LightSensorCharacteristic
],
for
:
service
)
}
if
(
service
.
uuid
.
isEqual
(
card10RxTxServiceUUID
)
)
{
if
service
.
uuid
.
isEqual
(
card10RxTxServiceUUID
)
{
peripheral
.
discoverCharacteristics
([
card10TXWriteCharacteristicUUID
,
card10RXReadCharacteristicUUID
],
for
:
service
)
}
...
...
card10badge/Bluetooth/DataTransferManager.swift
View file @
9905a3cf
...
...
@@ -62,23 +62,24 @@ class DataTransferManager: NSObject {
switch
packageType
{
case
.
START
?:
break
case
.
START_ACK
?:
self
.
transferState
=
.
READY_TO_SEND
let
chunkToSend
=
self
.
chunkedReader
?
.
nextChunk
()
guard
chunkToSend
!.
count
>
0
else
{
self
.
sendPackage
(
type
:
.
ERROR
,
payload
:
nil
,
offset
:
0
);
return
}
self
.
currentChunkToSend
=
chunkToSend
sendPackage
(
type
:
.
CHUNK
,
payload
:
chunkToSend
,
offset
:
0
)
break
case
.
CHUNK
?:
break
case
.
CHUNK_ACK
?:
self
.
transferState
=
.
CHUNK_SENT
// calculate CRC and send new chunk
let
range
:
Range
<
Data
.
Index
>
=
0
..<
1
let
crc
=
package
.
subdata
(
in
:
range
)
updateProgress
()
if
(
checkChunkWithResponse
(
crc
)
)
{
if
(
currentChunkToSend
!.
count
<
chunkedReader
!.
packageSize
)
{
if
checkChunkWithResponse
(
crc
)
{
if
currentChunkToSend
!.
count
<
chunkedReader
!.
packageSize
{
// The last package arrived, we are done here
sendPackage
(
type
:
.
FINISH
,
payload
:
nil
,
offset
:
0
)
break
...
...
@@ -88,34 +89,36 @@ class DataTransferManager: NSObject {
self
.
currentChunkToSend
=
chunkToSend
sendPackage
(
type
:
.
CHUNK
,
payload
:
chunkToSend
,
offset
:
self
.
chunkedReader
!.
currentOffset
-
20
)
}
}
else
if
(
retryCount
<
9
)
{
}
else
if
retryCount
<
9
{
sendPackage
(
type
:
.
CHUNK
,
payload
:
self
.
currentChunkToSend
,
offset
:
self
.
chunkedReader
!.
currentOffset
-
20
)
retryCount
+=
1
}
else
{
self
.
sendPackage
(
type
:
.
ERROR
,
payload
:
nil
,
offset
:
0
)
}
break
case
.
FINISH
?:
break
case
.
FINISH_ACK
?:
// finished, cleanup
self
.
transferState
=
.
FINISH_SENT
self
.
chunkedReader
=
nil
self
.
dataToSend
=
nil
self
.
transferState
=
.
IDLE
break
case
.
ERROR
?:
// fucked up, send error ack
print
(
"Error from card10, message "
,
String
(
data
:
package
,
encoding
:
.
ascii
)
!
)
self
.
sendPackage
(
type
:
.
ERROR_ACK
,
payload
:
nil
,
offset
:
0
)
delegate
?
.
didFailToSendFile
()
break
case
.
ERROR_ACK
?:
// device knows we aborted
self
.
chunkedReader
=
nil
self
.
dataToSend
=
nil
self
.
transferState
=
.
IDLE
break
default
:
print
(
"Broken Package "
,
firstChar
)
}
...
...
@@ -141,31 +144,33 @@ class DataTransferManager: NSObject {
payloadToSend
=
PackageType
.
START
.
rawValue
.
data
(
using
:
.
ascii
)
payloadToSend
?
.
append
(
payload
!
)
lastPackageSentAt
=
NSDate
.
init
()
.
timeIntervalSinceNow
break
case
.
START_ACK
:
break
case
.
CHUNK
:
payloadToSend
=
PackageType
.
CHUNK
.
rawValue
.
data
(
using
:
.
ascii
)
var
int
=
UInt32
(
bigEndian
:
UInt32
(
offset
))
payloadToSend
?
.
append
(
Data
(
bytes
:
&
int
,
count
:
MemoryLayout
.
size
(
ofValue
:
UInt32
())))
payloadToSend
?
.
append
(
payload
!
)
lastPackageSentAt
=
NSDate
.
init
()
.
timeIntervalSinceNow
break
case
.
CHUNK_ACK
:
break
case
.
FINISH
:
payloadToSend
=
PackageType
.
FINISH
.
rawValue
.
data
(
using
:
.
ascii
)
break
case
.
FINISH_ACK
:
break
case
.
ERROR
:
payloadToSend
=
PackageType
.
ERROR
.
rawValue
.
data
(
using
:
.
ascii
)
delegate
?
.
didFailToSendFile
()
break
case
.
ERROR_ACK
:
payloadToSend
=
PackageType
.
ERROR_ACK
.
rawValue
.
data
(
using
:
.
ascii
)
delegate
?
.
didFailToSendFile
()
break
}
if
payloadToSend
!=
nil
{
delegate
?
.
wantsToSendPackage
(
payloadToSend
!
)
...
...
@@ -180,7 +185,7 @@ class DataTransferManager: NSObject {
let
responseInUInt32
=
response
.
withUnsafeBytes
{
$0
.
load
(
as
:
UInt8
.
self
)
}
let
chunkInUInt8
=
[
UInt8
](
self
.
currentChunkToSend
!
)
let
checksum
=
CRC32
.
checksum
(
bytes
:
chunkInUInt8
)
if
(
responseInUInt32
==
checksum
)
{
if
responseInUInt32
==
checksum
{
return
true
}
return
false
...
...
card10badge/Conncted/ConnectedViewController.swift
View file @
9905a3cf
...
...
@@ -126,7 +126,7 @@ extension ConnectedViewController {
extension
ConnectedViewController
{
func
documentPicker
(
_
controller
:
UIDocumentPickerViewController
,
didPickDocumentsAt
urls
:
[
URL
])
{
if
(
controller
.
documentPickerMode
==
.
import
)
{
if
controller
.
documentPickerMode
==
.
import
{
for
url
in
urls
{
do
{
let
data
=
try
Data
(
contentsOf
:
url
as
URL
)
...
...
@@ -202,7 +202,7 @@ extension ConnectedViewController {
var
g
:
UInt8
=
0
var
b
:
UInt8
=
0
while
(
UInt64
(
r
)
+
UInt64
(
g
)
+
UInt64
(
b
)
==
UInt64
(
0
)
)
{
while
UInt64
(
r
)
+
UInt64
(
g
)
+
UInt64
(
b
)
==
UInt64
(
0
)
{
r
=
UInt8
.
random
(
in
:
0
..<
3
)
*
127
// 128 would overflow UInt 😬
g
=
UInt8
.
random
(
in
:
0
..<
3
)
*
127
b
=
UInt8
.
random
(
in
:
0
..<
3
)
*
127
...
...
card10badge/Hatchery/HatcheryClient.swift
View file @
9905a3cf
...
...
@@ -140,7 +140,7 @@ class HatcheryClient: NSObject, URLSessionDelegate {
let
documentsUrl
=
FileManager
.
default
.
temporaryDirectory
let
destinationUrl
=
documentsUrl
.
appendingPathComponent
(
fromURL
.
lastPathComponent
)
if
(
FileManager
.
default
.
fileExists
(
atPath
:
destinationUrl
.
path
)
)
{
if
FileManager
.
default
.
fileExists
(
atPath
:
destinationUrl
.
path
)
{
do
{
try
FileManager
.
default
.
removeItem
(
at
:
destinationUrl
)
}
catch
{
...
...
@@ -176,7 +176,7 @@ class HatcheryClient: NSObject, URLSessionDelegate {
folderNameForEgg
=
fileName
.
deletingLastPathComponent
()
.
path
// Kind of betting on that there are no subfolders
}
try
FileManager
.
default
.
createDirectory
(
at
:
fileName
.
deletingLastPathComponent
(),
withIntermediateDirectories
:
true
,
attributes
:
nil
)
if
(
FileManager
.
default
.
createFile
(
atPath
:
fileName
.
path
,
contents
:
data
,
attributes
:
nil
)
)
{
if
FileManager
.
default
.
createFile
(
atPath
:
fileName
.
path
,
contents
:
data
,
attributes
:
nil
)
{
createdFileCount
+=
1
//Increment so we know if we wrote all the files
}
else
{
print
(
"Failed to write file to path "
,
fileName
)
...
...
card10badge/Hatchery/HatcheryRootTableViewController.swift
View file @
9905a3cf
...
...
@@ -43,7 +43,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
}
override
func
viewDidAppear
(
_
animated
:
Bool
)
{
if
(
client
?
.
loadedEggs
.
count
==
0
)
{
if
client
?
.
loadedEggs
.
count
==
0
{
client
?
.
updateListOfHatcheryEggs
()
}
super
.
viewDidAppear
(
animated
)
...
...
@@ -74,7 +74,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
let
cell
=
tableView
.
dequeueReusableCell
(
withIdentifier
:
"HatcheryRootTableViewCell"
,
for
:
indexPath
)
as!
HatcheryRootTableViewCell
let
eggForCell
:
HatcheryEgg
if
(
isFiltering
()
)
{
if
isFiltering
(
)
{
eggForCell
=
self
.
filteredEggs
[
indexPath
.
row
]
}
else
{
eggForCell
=
(
self
.
client
?
.
loadedEggs
[
indexPath
.
section
][
indexPath
.
row
])
!
...
...
@@ -87,7 +87,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
}
override
func
tableView
(
_
tableView
:
UITableView
,
viewForHeaderInSection
section
:
Int
)
->
UIView
?
{
if
(
isFiltering
()
)
{
if
isFiltering
(
)
{
return
nil
}
...
...
@@ -105,7 +105,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
}
override
func
tableView
(
_
tableView
:
UITableView
,
heightForHeaderInSection
section
:
Int
)
->
CGFloat
{
if
(
isFiltering
()
)
{
if
isFiltering
(
)
{
return
0
}
return
44
...
...
@@ -115,7 +115,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
let
indexPath
=
self
.
tableView
.
indexPathForSelectedRow
!
let
eggForCell
:
HatcheryEgg
if
(
isFiltering
()
)
{
if
isFiltering
(
)
{
eggForCell
=
self
.
filteredEggs
[
indexPath
.
row
]
}
else
{
eggForCell
=
(
self
.
client
?
.
loadedEggs
[
indexPath
.
section
][
indexPath
.
row
])
!
...
...
@@ -128,7 +128,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
func
didRefreshListOfEggs
()
{
self
.
refreshControl
?
.
endRefreshing
()
if
(
self
.
tableView
.
numberOfSections
>
0
)
{
if
self
.
tableView
.
numberOfSections
>
0
{
let
rangeToReload
=
IndexSet
.
init
(
integersIn
:
0
..<
(
client
?
.
loadedEggs
.
count
)
!
)
self
.
tableView
.
reloadSections
(
rangeToReload
,
with
:
.
automatic
)
}
else
{
...
...
@@ -139,7 +139,7 @@ class HatcheryRootTableViewController: UITableViewController, HatcheryClientDele
func
didFailToRefreshListOfEggs
(
_
error
:
Error
?)
{
self
.
refreshControl
?
.
endRefreshing
()
var
errorToShow
:
String
=
"Failed to download eggs"
if
(
error
!=
nil
)
{
if
error
!=
nil
{
errorToShow
.
append
(
contentsOf
:
"
\n
"
)
errorToShow
.
append
(
contentsOf
:
error
!.
localizedDescription
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment