Clean and Test làn 3
Some checks failed
Test / test (push) Has been cancelled

This commit is contained in:
2026-06-13 14:04:56 +07:00
parent fbc0c11be2
commit c05b1d5f5c
12 changed files with 281 additions and 40 deletions

View File

@@ -3,7 +3,6 @@
#include "util/id_util.hpp"
#include <chrono>
#include <ctime>
namespace lm {

View File

@@ -67,7 +67,6 @@ bool ModbusTriggerService::writeCoil(int coil_id, bool value, std::string& err)
std::lock_guard<std::mutex> lock(mu_);
const bool prev = coils_.count(coil_id) ? coils_.at(coil_id) : false;
coils_[coil_id] = value;
prev_coils_[coil_id] = value;
if (!prev && value)
{
const auto trigger = store_.findTriggerByCoil(coil_id);

View File

@@ -35,7 +35,6 @@ private:
mutable std::mutex mu_;
std::unordered_map<int, bool> coils_;
std::unordered_map<int, bool> prev_coils_;
std::atomic<bool> stop_{false};
std::thread tcp_thread_;

View File

@@ -5,16 +5,18 @@
namespace lm {
bool ApiServer::enqueueRequest(const nlohmann::json& request, httplib::Response& res, int status_code)
std::optional<nlohmann::json> ApiServer::enqueueMission(const nlohmann::json& request, std::string& err)
{
nlohmann::json payload;
std::string err;
if (!MissionEnqueue::buildPayload(mission_store_, request, payload, err))
{
HttpUtil::jsonError(res, 400, err);
return false;
}
const auto entry = mission_queue_.enqueue(payload, err);
return std::nullopt;
return mission_queue_.enqueue(payload, err);
}
bool ApiServer::enqueueRequest(const nlohmann::json& request, httplib::Response& res, int status_code)
{
std::string err;
const auto entry = enqueueMission(request, err);
if (!entry)
{
HttpUtil::jsonError(res, 400, err);
@@ -249,11 +251,8 @@ void ApiServer::registerMirV2Routes(httplib::Server& svr)
}
if (!payload.contains("source"))
payload["source"] = "rest_api_v2";
nlohmann::json built;
std::string err;
if (!MissionEnqueue::buildPayload(mission_store_, payload, built, err))
return HttpUtil::jsonError(res, 400, err);
const auto entry = mission_queue_.enqueue(built, err);
const auto entry = enqueueMission(payload, err);
if (!entry)
return HttpUtil::jsonError(res, 400, err);
HttpUtil::addCors(res);

View File

@@ -14,10 +14,10 @@ class ApiServer
{
public:
ApiServer(StateRepository& repo,
MissionQueue& mission_queue,
MissionStore& mission_store,
ModbusTriggerService& modbus,
MissionScheduler& scheduler);
MissionQueue& mission_queue,
MissionStore& mission_store,
ModbusTriggerService& modbus,
MissionScheduler& scheduler);
void registerRoutes(httplib::Server& svr);
@@ -29,6 +29,7 @@ private:
MissionScheduler& scheduler_;
bool enqueueRequest(const nlohmann::json& request, httplib::Response& res, int status_code = 201);
std::optional<nlohmann::json> enqueueMission(const nlohmann::json& request, std::string& err);
nlohmann::json toMirQueueEntry(const nlohmann::json& entry) const;
void registerMissionRoutes(httplib::Server& svr);
void registerMirV2Routes(httplib::Server& svr);