update ErrorCode, status, lifecycle
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "lidarlib/error.hpp"
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -83,14 +84,28 @@ class Lidar {
|
||||
public:
|
||||
virtual ~Lidar() = default;
|
||||
|
||||
virtual bool open() = 0;
|
||||
// ErrorCode::Ok on success. Calling open() on an already-open instance
|
||||
// returns AlreadyOpen and leaves the connection untouched.
|
||||
virtual ErrorCode open() = 0;
|
||||
// Idempotent: safe to call before open() or more than once.
|
||||
virtual void close() = 0;
|
||||
// Block until one full scan; false on error/timeout. timeout_ms = 0 → block
|
||||
// indefinitely. No default on purpose: drivers differ (OLEI 1000, SICK 2000).
|
||||
// Block until one full scan; false on error/timeout (see last_error()).
|
||||
// timeout_ms = 0 → block indefinitely. No default on purpose: drivers
|
||||
// differ (OLEI 1000, SICK 2000).
|
||||
virtual bool recv_scan(ScanResult& out, int timeout_ms) = 0;
|
||||
virtual void set_scan_callback(ScanCallback cb) = 0;
|
||||
virtual bool spin_once() = 0;
|
||||
virtual const char* detected_model() const = 0;
|
||||
|
||||
virtual bool is_open() const = 0;
|
||||
// Status of the most recent open()/recv_scan()/spin_once() call.
|
||||
ErrorCode last_error() const { return last_error_; }
|
||||
|
||||
protected:
|
||||
ErrorCode set_error(ErrorCode e) { last_error_ = e; return e; }
|
||||
|
||||
private:
|
||||
ErrorCode last_error_ = ErrorCode::Ok;
|
||||
};
|
||||
|
||||
// OLEI UDP driver.
|
||||
@@ -109,11 +124,12 @@ public:
|
||||
Driver(const Driver&) = delete;
|
||||
Driver& operator=(const Driver&) = delete;
|
||||
|
||||
bool open() override;
|
||||
ErrorCode open() override;
|
||||
void close() override;
|
||||
bool recv_scan(ScanResult& out, int timeout_ms = 1000) override;
|
||||
void set_scan_callback(ScanCallback cb) override { cb_ = std::move(cb); }
|
||||
bool spin_once() override;
|
||||
bool is_open() const override { return sock_fd_ >= 0; }
|
||||
|
||||
// Model name read from the Family B/C header; "AUTO" until one is seen.
|
||||
const char* detected_model() const override { return detected_model_name_.c_str(); }
|
||||
|
||||
Reference in New Issue
Block a user