From 3737566f8ce06ec6d5bb946895113784739c0520 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Fri, 10 Jul 2020 22:27:00 +0930 Subject: [PATCH 1/3] Set baudrate, add mock serial struct to test with. --- Sources/SwiftRPLidar/LidarSerial.swift | 1 + Sources/SwiftRPLidar/SwiftRPLidar.swift | 1 + .../SwiftRPLidarTests/SwiftRPLidarTests.swift | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Sources/SwiftRPLidar/LidarSerial.swift b/Sources/SwiftRPLidar/LidarSerial.swift index 3fc9d57..222acae 100644 --- a/Sources/SwiftRPLidar/LidarSerial.swift +++ b/Sources/SwiftRPLidar/LidarSerial.swift @@ -7,4 +7,5 @@ public protocol LidarSerial { func openPort() throws; func readData(ofLength: Int) throws -> Data; func writeData(_ data: Data) throws -> Int; + func setBaudrate(baudrate: Int) } diff --git a/Sources/SwiftRPLidar/SwiftRPLidar.swift b/Sources/SwiftRPLidar/SwiftRPLidar.swift index a2785d4..32ec0bc 100644 --- a/Sources/SwiftRPLidar/SwiftRPLidar.swift +++ b/Sources/SwiftRPLidar/SwiftRPLidar.swift @@ -78,6 +78,7 @@ public class SwiftRPLidar { public func connect() throws { disconnect() try serialPort!.openPort() + serialPort?.setBaudrate(baudrate: 115200) } public func disconnect(){ diff --git a/Tests/SwiftRPLidarTests/SwiftRPLidarTests.swift b/Tests/SwiftRPLidarTests/SwiftRPLidarTests.swift index b64f39a..9628782 100644 --- a/Tests/SwiftRPLidarTests/SwiftRPLidarTests.swift +++ b/Tests/SwiftRPLidarTests/SwiftRPLidarTests.swift @@ -13,3 +13,28 @@ final class SwiftRPLidarTests: XCTestCase { ("testExample", testExample), ] } + +struct MockSerialPort: LidarSerial { + + var dtr: Bool + + var inWaiting: Int + + func closePort() { + } + + func openPort() throws { + } + + func readData(ofLength: Int) throws -> Data { + return Data() + } + + func writeData(_ data: Data) throws -> Int { + return 0 + } + + func setBaudrate(baudrate: Int) { + + } +} From 102ca314a11dabe1a19024a804cab513cd1c48f1 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Fri, 10 Jul 2020 22:47:45 +0930 Subject: [PATCH 2/3] Fix LidarScan properties. --- Sources/SwiftRPLidar/SwiftRPLidar.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftRPLidar/SwiftRPLidar.swift b/Sources/SwiftRPLidar/SwiftRPLidar.swift index 32ec0bc..d78c668 100644 --- a/Sources/SwiftRPLidar/SwiftRPLidar.swift +++ b/Sources/SwiftRPLidar/SwiftRPLidar.swift @@ -46,10 +46,10 @@ func processScan(raw: Data) throws -> LidarScan { } public struct LidarScan{ - var newScan: Bool - var quality: UInt8 - var angle: Float - var distance: Float + public let newScan: Bool + public let quality: UInt8 + public let angle: Float + public let distance: Float } From b8f61e3acb168bca516cece83404cf1c909ab4c5 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Fri, 10 Jul 2020 23:01:52 +0930 Subject: [PATCH 3/3] Remove SwiftSerial dependency. --- Package.swift | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index bb520b2..53e5e2a 100644 --- a/Package.swift +++ b/Package.swift @@ -6,21 +6,16 @@ import PackageDescription let package = Package( name: "SwiftRPLidar", products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "SwiftRPLidar", targets: ["SwiftRPLidar"]), ], dependencies: [ - // Dependencies declare other packages that this package depends on. - .package(url: "https://vato.ddns.net/gitlab/vato007/SwiftSerial.git", .branch("dtr_support")) ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "SwiftRPLidar", - dependencies: [.product(name: "SwiftSerial", package: "SwiftSerial")]), + dependencies: []), .testTarget( name: "SwiftRPLidarTests", dependencies: ["SwiftRPLidar"]),