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
4fdfc8b8
Commit
4fdfc8b8
authored
Aug 24, 2019
by
Thomas Mellenthin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix crc32 calculation
parent
ee9f76c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
card10badge/Bluetooth/DataTransferManager.swift
card10badge/Bluetooth/DataTransferManager.swift
+6
-12
card10badge/Bluetooth/UInt+Extension.swift
card10badge/Bluetooth/UInt+Extension.swift
+6
-0
No files found.
card10badge/Bluetooth/DataTransferManager.swift
View file @
4fdfc8b8
...
...
@@ -51,6 +51,7 @@ class DataTransferManager: NSObject {
var
lastPackageSentAt
:
TimeInterval
?
var
dataToSend
:
Data
?
var
currentChunkToSend
:
Data
?
var
currentChunkToSendCrc32
:
UInt32
=
0
var
retryCount
:
Int
=
0
init
(
_
delegateToUse
:
DataTransferManagerDelegate
)
{
...
...
@@ -78,7 +79,7 @@ class DataTransferManager: NSObject {
case
.
CHUNK_ACK
?:
self
.
transferState
=
.
CHUNK_SENT
// calculate CRC and send new chunk
let
range
:
Range
<
Data
.
Index
>
=
0
..<
1
let
range
:
Range
<
Data
.
Index
>
=
1
..<
5
let
crc
=
package
.
subdata
(
in
:
range
)
updateProgress
()
if
checkChunkWithResponse
(
crc
)
{
...
...
@@ -156,6 +157,8 @@ class DataTransferManager: NSObject {
var
int
=
UInt32
(
bigEndian
:
UInt32
(
offset
))
payloadToSend
?
.
append
(
Data
(
bytes
:
&
int
,
count
:
MemoryLayout
.
size
(
ofValue
:
UInt32
())))
payloadToSend
?
.
append
(
payload
!
)
// pre-calculate the expected CRC sum for that packet (must include header and offset)
currentChunkToSendCrc32
=
CRC32
.
checksum
(
bytes
:
payloadToSend
!.
bytes
)
lastPackageSentAt
=
NSDate
.
init
()
.
timeIntervalSinceNow
case
.
CHUNK_ACK
:
...
...
@@ -181,17 +184,8 @@ class DataTransferManager: NSObject {
}
func
checkChunkWithResponse
(
_
response
:
Data
)
->
Bool
{
return
true
//FIXME: This CRC32 implementation doesn't work. Disabled for now
let
responseInUInt32
=
response
.
withUnsafeBytes
{
$0
.
load
(
as
:
UInt8
.
self
)
}
let
chunkInUInt8
=
[
UInt8
](
self
.
currentChunkToSend
!
)
let
checksum
=
CRC32
.
checksum
(
bytes
:
chunkInUInt8
)
if
responseInUInt32
==
checksum
{
return
true
}
return
false
// compares received crc32 with the previously calculated checksum
return
response
.
withUnsafeBytes
{
$0
.
load
(
as
:
UInt32
.
self
)
}
==
currentChunkToSendCrc32
}
func
updateProgress
()
{
...
...
card10badge/Bluetooth/UInt+Extension.swift
View file @
4fdfc8b8
...
...
@@ -21,3 +21,9 @@ extension isDataInt {
extension
UInt16
:
isDataInt
{
}
extension
UInt64
:
isDataInt
{
}
extension
Data
{
var
bytes
:
[
UInt8
]
{
return
[
UInt8
](
self
)
}
}
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