livoxProto1: Convert heartbeat sender into daemon coro
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#ifndef LIVOX_PROTO1_DEVICE_H
|
||||
#define LIVOX_PROTO1_DEVICE_H
|
||||
|
||||
#include <boostAsioLinkageFix.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
@@ -17,8 +19,10 @@
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/asio/posix/stream_descriptor.hpp>
|
||||
#include "protocol.h"
|
||||
#include <spinscale/co/dynamicPostingInvoker.h>
|
||||
#include <spinscale/co/invokers.h>
|
||||
#include <spinscale/spinLock.h>
|
||||
#include <spinscale/co/nonViralTaskNursery.h>
|
||||
#include <spinscale/syncCancelerForAsyncWork.h>
|
||||
|
||||
// Custom hash function for std::pair<uint8_t, uint8_t>
|
||||
namespace std {
|
||||
@@ -86,8 +90,20 @@ private:
|
||||
// Heartbeat mechanism
|
||||
void startHeartbeat();
|
||||
void stopHeartbeat();
|
||||
void sendHeartbeat();
|
||||
void onHeartbeatTimer(const boost::system::error_code& error);
|
||||
void sendHeartbeatOnce();
|
||||
|
||||
/** EXPLANATION:
|
||||
* deviceCDaemon is a dynamic posting non-viral coroutine: startHeartbeat()
|
||||
* passes ExplicitPostTarget{componentThread->getIoContext()} so the daemon
|
||||
* body always runs on componentThread. Extensible for future per-device
|
||||
* background work beyond heartbeats.
|
||||
*/
|
||||
sscl::co::DynamicNonViralPostingInvoker deviceCDaemon(
|
||||
sscl::co::ExplicitPostTarget postTarget,
|
||||
std::exception_ptr &exceptionPtr,
|
||||
std::function<void()> callback,
|
||||
sscl::SyncCancelerForAsyncWork &canceler);
|
||||
|
||||
std::string generateClientDeviceIpFromSerialNumber(
|
||||
const std::string& broadcastCode);
|
||||
|
||||
@@ -172,10 +188,9 @@ public:
|
||||
uint8_t smoSubnetNbits;
|
||||
uint16_t dataPort, cmdPort, imuPort;
|
||||
|
||||
// Heartbeat state
|
||||
std::unique_ptr<boost::asio::deadline_timer> heartbeatTimer;
|
||||
std::atomic<bool> heartbeatActive;
|
||||
sscl::SpinLock heartbeatActiveLock;
|
||||
// Heartbeat state (timer lifetime tied to Device ctor/dtor)
|
||||
boost::asio::deadline_timer heartbeatTimer;
|
||||
sscl::co::NonViralTaskNursery daemonNursery;
|
||||
|
||||
// Point cloud data state
|
||||
std::atomic<bool> pcloudDataActive;
|
||||
|
||||
Reference in New Issue
Block a user