2025-09-06 20:06:38 -04:00
|
|
|
#ifndef LIVOXPROTO1_CORE_H
|
|
|
|
|
#define LIVOXPROTO1_CORE_H
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <cstdint>
|
2025-09-09 12:07:49 -04:00
|
|
|
#include <optional>
|
|
|
|
|
#include <user/senseApiDesc.h>
|
2025-09-06 20:06:38 -04:00
|
|
|
#include "device.h"
|
|
|
|
|
#include "broadcastListener.h"
|
2025-10-22 06:17:42 -04:00
|
|
|
#include "udpCommandDemuxer.h"
|
2025-09-09 12:07:49 -04:00
|
|
|
#include "livoxProto1.h"
|
2025-09-27 18:30:09 -04:00
|
|
|
#include <callback.h>
|
2025-09-06 20:06:38 -04:00
|
|
|
|
|
|
|
|
namespace livoxProto1 {
|
|
|
|
|
|
|
|
|
|
class DeviceManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DeviceManager();
|
|
|
|
|
~DeviceManager() = default;
|
|
|
|
|
|
|
|
|
|
static void deviceGoneAwayInd(const comms::DiscoveredDevice &device);
|
|
|
|
|
|
2025-09-09 12:07:49 -04:00
|
|
|
void getOrCreateDeviceReq(
|
2025-09-06 20:06:38 -04:00
|
|
|
const std::string &deviceIdentifier,
|
|
|
|
|
const std::shared_ptr<smo::ComponentThread>& componentThread,
|
2025-11-01 02:45:24 -04:00
|
|
|
int commandTimeoutMs, int retryDelayMs,
|
2025-09-06 20:06:38 -04:00
|
|
|
const std::string& smoIp, uint8_t smoSubnetNbits,
|
2025-09-09 12:07:49 -04:00
|
|
|
uint16_t dataPort, uint16_t cmdPort, uint16_t imuPort,
|
2025-09-27 18:30:09 -04:00
|
|
|
smo::Callback<livoxProto1_getOrCreateDeviceReqCbFn> callback);
|
2025-09-06 20:06:38 -04:00
|
|
|
|
2025-09-09 12:07:49 -04:00
|
|
|
void destroyDeviceReq(
|
|
|
|
|
std::shared_ptr<Device> device,
|
2025-09-27 18:30:09 -04:00
|
|
|
smo::Callback<livoxProto1_destroyDeviceReqCbFn> callback);
|
2025-09-06 20:06:38 -04:00
|
|
|
|
2025-09-09 12:07:49 -04:00
|
|
|
std::optional<std::shared_ptr<Device>> getDevice(
|
|
|
|
|
const std::string &deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
std::optional<std::shared_ptr<Device>> getDevice(
|
|
|
|
|
const comms::DiscoveredDevice &device)
|
|
|
|
|
{
|
|
|
|
|
return getDevice(device.deviceIdentifier);
|
|
|
|
|
}
|
2025-09-06 20:06:38 -04:00
|
|
|
|
2025-09-09 12:07:49 -04:00
|
|
|
private:
|
2025-09-06 20:06:38 -04:00
|
|
|
// Configuration
|
|
|
|
|
static constexpr int RETRY_DELAY_SECONDS = 3; // <N> seconds delay
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::vector<std::shared_ptr<Device>> devices;
|
|
|
|
|
comms::BroadcastListener broadcastListener;
|
2025-10-22 06:17:42 -04:00
|
|
|
comms::UdpCommandDemuxer udpCommandDemuxer;
|
2025-09-09 12:07:49 -04:00
|
|
|
|
|
|
|
|
// Nested continuation class for async device creation
|
|
|
|
|
class GetOrCreateDeviceReq;
|
|
|
|
|
class DestroyDeviceReq;
|
2025-09-06 20:06:38 -04:00
|
|
|
};
|
|
|
|
|
|
2025-09-09 12:07:49 -04:00
|
|
|
void main(
|
|
|
|
|
const std::shared_ptr<smo::ComponentThread> &componentThread,
|
2025-10-01 18:47:42 -04:00
|
|
|
const smo::stim_buff::SmoCallbacks& smoCallbacks);
|
2025-09-06 20:06:38 -04:00
|
|
|
void exit(void);
|
|
|
|
|
|
|
|
|
|
// Global state structure
|
|
|
|
|
struct ProtoState
|
|
|
|
|
{
|
|
|
|
|
bool isInitialized = false;
|
|
|
|
|
std::shared_ptr<smo::ComponentThread> componentThread;
|
|
|
|
|
std::unique_ptr<DeviceManager> deviceManager;
|
2025-10-01 18:47:42 -04:00
|
|
|
smo::stim_buff::SmoCallbacks smoCallbacks;
|
2025-09-06 20:06:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Access to global state for extern "C" functions
|
|
|
|
|
ProtoState& getProtoState();
|
|
|
|
|
|
|
|
|
|
} // namespace livoxProto1
|
|
|
|
|
|
|
|
|
|
#endif // LIVOXPROTO1_CORE_H
|