|
|
|
|
@ -185,6 +185,9 @@ namespace
|
|
|
|
|
node->session.stop(); // 等待采集线程退出(≤100ms轮询粒度)
|
|
|
|
|
*pts = node->session.snapshot();
|
|
|
|
|
node->session.reset(); // 清空点集,为下一次 start 准备
|
|
|
|
|
// 按需连接: 结果已到手, 立即断开, 空闲期 SDK 不再收/解析数据(省一个核)
|
|
|
|
|
if (cfg.server.connect_on_demand)
|
|
|
|
|
close_radar_connection(node);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -203,6 +206,8 @@ namespace
|
|
|
|
|
{
|
|
|
|
|
node->session.stop();
|
|
|
|
|
node->session.reset();
|
|
|
|
|
// 注意: 此函数唯一调用点是 handle_scan_start 的强制重启, 之后必然
|
|
|
|
|
// 立即 session.start —— 这里绝不能关连接, 保留现场复用。
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
@ -227,7 +232,9 @@ namespace
|
|
|
|
|
total = calc_item_count(work, snap.box, &detail,
|
|
|
|
|
&top_img, &tw, &th, &tlv, &tarea);
|
|
|
|
|
}
|
|
|
|
|
std::cout << "[TCP][" << snap.radar << "] count结束: task_id=" << snap.task_id
|
|
|
|
|
std::cout << "[TCP][" << snap.radar << "] "
|
|
|
|
|
<< (snap.function == "count_pcd" ? "count_pcd完成" : "count结束")
|
|
|
|
|
<< ": task_id=" << snap.task_id
|
|
|
|
|
<< ", 点数=" << pts.size() << ", 结果=" << total << std::endl;
|
|
|
|
|
|
|
|
|
|
std::ostringstream r;
|
|
|
|
|
@ -244,6 +251,77 @@ namespace
|
|
|
|
|
total, tlv, tarea, &pts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== count_pcd: 离线重算 ====================
|
|
|
|
|
// 输入已有 pcd 路径 + box 参数, 走与在线 count 完全相同的后续逻辑:
|
|
|
|
|
// 稀疏过滤 → z空隙插值 → 分层计数 → 保存 count_data.pcd/图片/log.txt
|
|
|
|
|
// pcd 的 y 是高度(= floor_height - y_mm), 读回时按此还原。
|
|
|
|
|
// 请求: {"function":"count_pcd","pcd":"D:/x/count_data.pcd",
|
|
|
|
|
// "box":{"l":..,"w":..,"h":..,"maxPerLayer":..},"radar":"radar1","task_id":"t1"}
|
|
|
|
|
// 不触碰雷达连接与扫描会话, 可在扫描进行中调用。
|
|
|
|
|
static void handle_count_pcd(const std::string& msg, SOCKET client,
|
|
|
|
|
std::string* resp, const std::string& radar_id)
|
|
|
|
|
{
|
|
|
|
|
std::string pcd_path;
|
|
|
|
|
json_get_string(msg, "pcd", pcd_path);
|
|
|
|
|
std::string task_id;
|
|
|
|
|
json_get_string(msg, "task_id", task_id);
|
|
|
|
|
|
|
|
|
|
CountParams box;
|
|
|
|
|
json_get_string(msg, "task_id", box.task_id);
|
|
|
|
|
json_get_number(msg, "l", box.l);
|
|
|
|
|
json_get_number(msg, "w", box.w);
|
|
|
|
|
json_get_number(msg, "h", box.h);
|
|
|
|
|
double d = 0.0;
|
|
|
|
|
if (json_get_number(msg, "maxPerLayer", d) ||
|
|
|
|
|
json_get_number(msg, "max", d))
|
|
|
|
|
box.maxPerLayer = (int)d;
|
|
|
|
|
|
|
|
|
|
if (pcd_path.empty())
|
|
|
|
|
{
|
|
|
|
|
send_reply(client, resp, "{\"code\":400,\"message\":\"missing pcd path\"}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!(box.l > 0 && box.w > 0 && box.h > 0 && box.maxPerLayer > 0))
|
|
|
|
|
{
|
|
|
|
|
send_reply(client, resp,
|
|
|
|
|
"{\"code\":400,\"message\":\"invalid box (l/w/h/maxPerLayer required)\"}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<double> xs, ys, zs;
|
|
|
|
|
std::string err;
|
|
|
|
|
if (!load_pcd_ascii(pcd_path, xs, ys, zs, err))
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "[TCP][" << radar_id << "] count_pcd 读取失败: " << err << std::endl;
|
|
|
|
|
send_reply(client, resp, "{\"code\":400,\"message\":\"pcd load failed\"}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pcd 的 y=高度 → 还原为 y_mm = floor_height - 高度 (与保存时互逆)
|
|
|
|
|
std::vector<CountPoint> pts;
|
|
|
|
|
pts.reserve(xs.size());
|
|
|
|
|
double floor_h = radar_cfg().count.floor_height;
|
|
|
|
|
for (std::size_t i = 0; i < xs.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
CountPoint p;
|
|
|
|
|
p.x_mm = xs[i];
|
|
|
|
|
p.y_mm = floor_h - ys[i];
|
|
|
|
|
p.z_val = zs[i];
|
|
|
|
|
pts.push_back(p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "[TCP][" << radar_id << "] count_pcd: " << pcd_path
|
|
|
|
|
<< " (" << pts.size() << " 点)" << std::endl;
|
|
|
|
|
|
|
|
|
|
SessionState snap;
|
|
|
|
|
snap.active = true;
|
|
|
|
|
snap.radar = radar_id;
|
|
|
|
|
snap.function = "count_pcd";
|
|
|
|
|
snap.box = box;
|
|
|
|
|
snap.task_id = task_id;
|
|
|
|
|
finish_count(snap, pts, client, resp); // 与在线 count 完全同一条计算/保存路径
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void finish_check(const SessionState& snap,
|
|
|
|
|
const std::vector<CountPoint>& pts,
|
|
|
|
|
SOCKET target, std::string* resp = nullptr)
|
|
|
|
|
@ -369,7 +447,9 @@ namespace
|
|
|
|
|
ack << ",\"scanTime\":" << (int)scan_time;
|
|
|
|
|
ack << ",\"radar\":\"" << radar_id << "\"}";
|
|
|
|
|
|
|
|
|
|
if (!node->connected.load())
|
|
|
|
|
// 未连接时: 按需连接模式下现场建连(约1~3秒); 常驻模式或建连失败才拒绝
|
|
|
|
|
if (!node->connected.load() &&
|
|
|
|
|
!(cfg.server.connect_on_demand && ensure_radar_connected(node)))
|
|
|
|
|
{
|
|
|
|
|
std::string fail = "radar not connected: " + radar_id;
|
|
|
|
|
std::cerr << "[TCP][" << radar_id << "] " << fail << std::endl;
|
|
|
|
|
@ -495,7 +575,9 @@ namespace
|
|
|
|
|
std::cout << "[TCP][" << radar_id << "] 收到ConfigureSpeed: 采集" << seconds
|
|
|
|
|
<< "s 标定变速剖面(每帧Y最大值) ..." << std::endl;
|
|
|
|
|
|
|
|
|
|
if (!node->connected.load())
|
|
|
|
|
// 按需连接: 标定前现场建连, 结束(无论成败)后断开
|
|
|
|
|
if (!node->connected.load() &&
|
|
|
|
|
!(cfg.server.connect_on_demand && ensure_radar_connected(node)))
|
|
|
|
|
{
|
|
|
|
|
std::string fail = "radar not connected: " + radar_id;
|
|
|
|
|
std::cerr << "[TCP][" << radar_id << "] " << fail << std::endl;
|
|
|
|
|
@ -511,6 +593,8 @@ namespace
|
|
|
|
|
std::cout << "[TCP][" << radar_id << "] 扫描运行中被ConfigureSpeed中断" << std::endl;
|
|
|
|
|
rows = collect_speed_profile(*node->driver, seconds, err);
|
|
|
|
|
}
|
|
|
|
|
if (cfg.server.connect_on_demand)
|
|
|
|
|
close_radar_connection(node); // 标定结束即断开
|
|
|
|
|
if (rows < 0)
|
|
|
|
|
{
|
|
|
|
|
std::cerr << "[TCP][" << radar_id << "] ConfigureSpeed失败: " << err << std::endl;
|
|
|
|
|
@ -559,6 +643,11 @@ namespace
|
|
|
|
|
const std::string radar_id = node->id;
|
|
|
|
|
RadarScope scope(radar_id); // 本请求全程使用该雷达的配置
|
|
|
|
|
|
|
|
|
|
if (fn == "count_pcd")
|
|
|
|
|
{
|
|
|
|
|
handle_count_pcd(msg, client, resp, radar_id);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (fn == "ConfigureSpeed" || fn == "configurespeed")
|
|
|
|
|
{
|
|
|
|
|
handle_configure_speed(msg, client, resp, radar_id, node);
|
|
|
|
|
|