livoxProto1: Implement async getOrCreateDeviceReq+destroyDeviceReq
These are now both fully asynchronous. They also work fully and both connect and disconnect to/from the Avia just fine, in all tested scenarios.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
#include <functional>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@@ -76,29 +77,50 @@ public:
|
||||
uint16_t dataPort, cmdPort, imuPort;
|
||||
|
||||
private:
|
||||
// Connection logic
|
||||
void connect();
|
||||
bool connectToKnownDevice();
|
||||
bool connectByDeviceIdentifier();
|
||||
bool executeHandshake(
|
||||
const std::string& deviceIP, int timeoutMs,
|
||||
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort);
|
||||
// Heartbeat mechanism
|
||||
void startHeartbeat();
|
||||
void sendHeartbeat();
|
||||
void onHeartbeatTimer(const boost::system::error_code& error);
|
||||
std::string generateClientDeviceIpFromSerialNumber(
|
||||
const std::string& broadcastCode);
|
||||
|
||||
// IP detection methods
|
||||
std::optional<std::string> detectSmoIp(const std::string& deviceIP);
|
||||
std::string getSmoIp(const std::string& deviceIP);
|
||||
uint32_t getSubnetMaskFor(uint8_t nbits);
|
||||
|
||||
// Heartbeat mechanism
|
||||
void startHeartbeat();
|
||||
void sendHeartbeat();
|
||||
void onHeartbeatTimer(const boost::system::error_code& error);
|
||||
class ConnectReq;
|
||||
class ConnectToKnownDeviceReq;
|
||||
class ConnectByDeviceIdentifierReq;
|
||||
class ExecuteHandshakeReq;
|
||||
class DisconnectReq;
|
||||
|
||||
public:
|
||||
// Utility methods
|
||||
std::string getSmoIp(const std::string& deviceIP);
|
||||
|
||||
// Callback function type definitions for async methods
|
||||
typedef std::function<void(bool success)> connectReqCbFn;
|
||||
typedef std::function<
|
||||
void(bool success, const std::string& ipAddr, int fd)>
|
||||
connectToKnownDeviceReqCbFn;
|
||||
typedef std::function<
|
||||
void(bool success, const std::string& ipAddr, int fd)>
|
||||
connectByDeviceIdentifierReqCbFn;
|
||||
typedef std::function<void(bool success, int fd)> executeHandshakeReqCbFn;
|
||||
typedef std::function<void(bool success)> disconnectReqCbFn;
|
||||
|
||||
// Async connection methods
|
||||
void connectReq(connectReqCbFn callback);
|
||||
void connectToKnownDeviceReq(connectToKnownDeviceReqCbFn callback);
|
||||
void connectByDeviceIdentifierReq(
|
||||
connectByDeviceIdentifierReqCbFn callback);
|
||||
void executeHandshakeReq(
|
||||
const std::string& deviceIP, executeHandshakeReqCbFn callback);
|
||||
void disconnectReq(disconnectReqCbFn callback);
|
||||
|
||||
// Heartbeat state
|
||||
std::unique_ptr<boost::asio::deadline_timer> heartbeatTimer;
|
||||
int heartbeatSocketFd; // Raw socket file descriptor
|
||||
int heartbeatFd; // Socket file descriptor used for heartbeat
|
||||
std::atomic<bool> heartbeatActive;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user