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) { + + } +}