//
// Created by Ht on 2020/8/21.
//

#ifndef LIBDEVCPP_MGBUSPROTOCOL_H
#define LIBDEVCPP_MGBUSPROTOCOL_H


#include "QCommonProtocol.h"
#include "MgBusCommon.h"
#include <functional>

namespace jedge {
    //处理Mgbus的基础通信消息

    static const char* mg_protocol_key_beat_ = "beat";
    static const char* mg_protocol_key_auth_ = "auth";
    static const char* mg_protocol_key_quit_ = "quit";
    static const char* mg_protocol_key_node_ = "node";
    static const char* mg_protocol_key_debug_ = "debug";
    static const char* mg_protocol_key_group_ = "group";
    static const char* mg_protocol_key_mgnet_ = "mgnet";

    class JE_API MgbusProtocol :
            public QCommonProtocol {

    public:
        void initProtocol() override {
            //初始化协议表
            qlibc::QData d;d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_heart_beat_); //b : heart beat
            addMessage(mg_protocol_key_beat_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_regist_);  //l : login
            addMessage(mg_protocol_key_auth_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_quit_); //q : quit
            addMessage(mg_protocol_key_quit_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_net_); //n : net
            addMessage(mg_protocol_key_node_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_debug_); //d: debug
            addMessage(mg_protocol_key_debug_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_group_);  //g: group
            addMessage(mg_protocol_key_group_, d);
            d.putObjFmtString(JEDGE_MGBUS_CMD_KEY, jedge_mgbus_cmd_mgnet_);  //m : mgbus net
            addMessage(mg_protocol_key_mgnet_, d);
            QCommonProtocol::initProtocol();
        }
    };
}


#endif //LIBDEVCPP_MGBUSPROTOCOL_H
