Files
smart_wasm/include/KinematicsWebAPI.h
2026-06-01 17:59:51 +08:00

60 lines
1.4 KiB
C++

#ifndef KINEMATICS_WEBAPI_H
#define KINEMATICS_WEBAPI_H
#include "utils.h"
#include "RobotManager.h"
#include "spc_core.h"
#include <string>
#include <atomic>
#include <functional>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
class KinematicsWebAPI
{
private:
std::atomic<bool> running_{false};
int m_port;
std::function<void(const std::string &)> onLog;
// 按功能域分发请求
json dispatchCommand(const std::string &req_cmd, const json &req_param);
// 机器人运动学与机器人管理接口
json handleRobotCommand(const std::string &req_cmd, const json &req_param);
// SPC 接口
json handleSpcCommand(const std::string &req_cmd, const json &req_param);
// 连杆机构接口
json handleFourBarCommand(const std::string &req_cmd, const json &req_param);
// 四足机器人接口
json handleQuadrupedCommand(const std::string &req_cmd, const json &req_param);
// 未知命令的默认响应
json createUnknownCommandResponse(const std::string &req_cmd, const json &req_param) const;
public:
KinematicsWebAPI();
// 日志函数
void log(const std::string &message);
// 获取当前时间戳
std::string getCurrentTimestamp();
// 处理API请求的主函数
std::string func(std::string sanitized_body);
// 初始化函数
std::string init_func();
// 运行状态检查
bool is_running() const;
};
#endif // KINEMATICS_WEBAPI_H