Set baudrate, add mock serial struct to test with.
This commit is contained in:
@@ -7,4 +7,5 @@ public protocol LidarSerial {
|
|||||||
func openPort() throws;
|
func openPort() throws;
|
||||||
func readData(ofLength: Int) throws -> Data;
|
func readData(ofLength: Int) throws -> Data;
|
||||||
func writeData(_ data: Data) throws -> Int;
|
func writeData(_ data: Data) throws -> Int;
|
||||||
|
func setBaudrate(baudrate: Int)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class SwiftRPLidar {
|
|||||||
public func connect() throws {
|
public func connect() throws {
|
||||||
disconnect()
|
disconnect()
|
||||||
try serialPort!.openPort()
|
try serialPort!.openPort()
|
||||||
|
serialPort?.setBaudrate(baudrate: 115200)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func disconnect(){
|
public func disconnect(){
|
||||||
|
|||||||
@@ -13,3 +13,28 @@ final class SwiftRPLidarTests: XCTestCase {
|
|||||||
("testExample", testExample),
|
("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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user