LivoxProto1: Implemented Device and getOrCreateDevice

Includes everything from sending heartbeat msgs to performing
the connection handshake. We also accept many params to
provider-params to customize and make things easier.
This commit is contained in:
2025-09-06 20:06:38 -04:00
parent 25234c4229
commit a0d577bf81
18 changed files with 1906 additions and 403 deletions
+60
View File
@@ -0,0 +1,60 @@
#ifndef LIVOXPROTO1_CORE_H
#define LIVOXPROTO1_CORE_H
#include <vector>
#include <string>
#include <memory>
#include <cstdint>
#include "device.h"
#include "broadcastListener.h"
namespace livoxProto1 {
class DeviceManager
{
public:
DeviceManager();
~DeviceManager() = default;
static void deviceGoneAwayInd(const comms::DiscoveredDevice &device);
std::shared_ptr<Device> getOrCreateDevice(
const std::string &deviceIdentifier,
const std::shared_ptr<smo::ComponentThread>& componentThread,
int handshakeTimeoutMs, int retryDelayMs,
const std::string& smoIp, uint8_t smoSubnetNbits,
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort);
std::shared_ptr<Device> getDevice(const std::string &deviceIdentifier);
std::shared_ptr<Device> getDevice(const comms::DiscoveredDevice &device)
{ return getDevice(device.deviceIdentifier); }
private:
// Helper methods
bool isDeviceKnown(const std::string& deviceIdentifier);
// Configuration
static constexpr int RETRY_DELAY_SECONDS = 3; // <N> seconds delay
public:
std::vector<std::shared_ptr<Device>> devices;
comms::BroadcastListener broadcastListener;
};
void main(const std::shared_ptr<smo::ComponentThread> &componentThread);
void exit(void);
// Global state structure
struct ProtoState
{
bool isInitialized = false;
std::shared_ptr<smo::ComponentThread> componentThread;
std::unique_ptr<DeviceManager> deviceManager;
};
// Access to global state for extern "C" functions
ProtoState& getProtoState();
} // namespace livoxProto1
#endif // LIVOXPROTO1_CORE_H