//
// Created by zx on 23-4-11.
//

#ifndef NAVIGATION_TERMINATOR_EMQX_H
#define NAVIGATION_TERMINATOR_EMQX_H
#include <mutex>
#include "paho_client.h"

typedef void (*NavStatuCallback)(const NavMessage::NavStatu& statu,void* context);

class Terminator_emqx {
public:
    Terminator_emqx(std::string nodeId,std::string pubTopic,std::string subTopic);
    ~Terminator_emqx();
    bool Connect(std::string ip,int port);
    void set_statu_arrived(NavStatuCallback callback,void* context);
    void SendNavCmd(const NavMessage::NavCmd& cmd);

protected:

    NavStatuCallback StatuArrivedCallback_;
    static void StatuArrivedCallback(std::string topic,int QOS,MqttMsg& msg,void* context);

    std::mutex mtx_;

    Paho_client* client_;
    void* context_;
    std::string nodeId_;
    std::string pubTopic_;
    std::string subTopic_;
public:
    MqttMsg msg_;
};

#endif //NAVIGATION_TERMINATOR_EMQX_H
