85 lines
1.9 KiB
C++
85 lines
1.9 KiB
C++
#ifndef BELT_CONTROLLER_H_
|
|
#define BELT_CONTROLLER_H_
|
|
#include "color.h"
|
|
#include "conveyorBeltGrpcClient.hpp"
|
|
#include <cstdlib>
|
|
#include <glog/logging.h>
|
|
#include <httplib.h>
|
|
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <shared_mutex>
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include "ability_sdk/ControllerHeartbeat.hpp"
|
|
#include "ability_sdk/Heartbeat.hpp"
|
|
|
|
//#include <json/json.h>
|
|
|
|
//#include "http_server.h"
|
|
// 前向声明 HttpServer 类,避免循环依赖
|
|
//class HttpServer;
|
|
|
|
|
|
typedef int ConveyorBeltStatus;
|
|
|
|
|
|
// 控制器类
|
|
class ConveyorBeltController {
|
|
|
|
public:
|
|
|
|
httplib::Server http_server;
|
|
void configure_http_server();
|
|
std::map<int, int> directionMap;
|
|
//std::map<int, std::string> ipMap;
|
|
int port;
|
|
|
|
// 控制器心跳包
|
|
ability_sdk::ControllerHeartbeat heartbeat_pack;
|
|
|
|
// 能力心跳获取
|
|
std::map<uuids::uuid, ability_sdk::Heartbeat> ability_heartbeats;
|
|
bool gather_abilities();
|
|
bool check_ability_status();
|
|
|
|
void init();
|
|
void Run();
|
|
|
|
// 控制器心跳线程
|
|
std::thread th_heartbeat;
|
|
void routine_heartbeat();
|
|
|
|
int handleOpen(float speed, int direction);
|
|
int handleClose();
|
|
int handleCheck();
|
|
void setServerIp(std::string serverIp);
|
|
ConveyorBeltStatus getCurrentStatus();
|
|
ConveyorBeltController();
|
|
~ConveyorBeltController();
|
|
|
|
private:
|
|
std::string ip;
|
|
ConveyorBeltStatus status;
|
|
std::shared_mutex mutex_;
|
|
int IPCPort;
|
|
int abilityPort;
|
|
std::map<int, std::string> ipMap;
|
|
// 状态转换
|
|
int stateSwitch(ConveyorBeltStatus destState, std::string cmd);
|
|
// grpc连接
|
|
int grpcConnect(float speed, int direction);
|
|
// grpc断开
|
|
int grpcDisconnect();
|
|
// grpc检查
|
|
int grpcCheck();
|
|
// 同步状态
|
|
int synchState(std::string json);
|
|
// 简单状态检查
|
|
bool simpleStateCheck();
|
|
|
|
};
|
|
|
|
#endif
|