|
@@ -3,6 +3,7 @@
|
|
|
|
|
|
#include "CurlHttp.h"
|
|
#include "CurlHttp.h"
|
|
#include "fmt/format.h"
|
|
#include "fmt/format.h"
|
|
|
|
+#include "GlobalInfo.h"
|
|
|
|
|
|
|
|
|
|
FromSuperBrain::FromSuperBrain()
|
|
FromSuperBrain::FromSuperBrain()
|
|
@@ -28,26 +29,35 @@ FromSuperBrain::~FromSuperBrain()
|
|
bool FromSuperBrain::getToken()
|
|
bool FromSuperBrain::getToken()
|
|
{
|
|
{
|
|
std::string response;
|
|
std::string response;
|
|
- std::string httpBody = R"({"appSecret":"Setyir9yxvSiFGB/wsv4YHWiNmrgeaZhzJKi7c7Gmk04Z5Kd/hCifL+0WnfCRDJF","appKey":"x1pcq13r"})";
|
|
|
|
|
|
+ /* fmt需要 {{ 才能输出一个 { */
|
|
|
|
+ std::string httpBody = fmt::format(R"({{"appSecret":"{}","appKey":"{}"}})", m_appSecret, m_appKey);
|
|
std::vector<std::string> vecHeader;
|
|
std::vector<std::string> vecHeader;
|
|
vecHeader.push_back("Content-Type: application/json");
|
|
vecHeader.push_back("Content-Type: application/json");
|
|
std::string url = m_url + m_tokenPath;
|
|
std::string url = m_url + m_tokenPath;
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "url:{}", url);
|
|
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "httpBody:{}", httpBody);
|
|
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "url:{}", url);
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "httpBody:{}", httpBody);
|
|
if(!CurlHttp::Post(url, vecHeader, httpBody, response))
|
|
if(!CurlHttp::Post(url, vecHeader, httpBody, response))
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}", response);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "response:{}", response);
|
|
|
|
+ /* 解析json信息 */
|
|
|
|
+ nJson json0 = nJson::parse(response);
|
|
|
|
+ auto code = json0["code"].get<std::string>();
|
|
|
|
+ if(code != "0")
|
|
{
|
|
{
|
|
SPDLOG_LOGGER_ERROR(m_logger, "Get Token failed");
|
|
SPDLOG_LOGGER_ERROR(m_logger, "Get Token failed");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "response:{}", response);
|
|
|
|
- m_token = response;
|
|
|
|
|
|
+ json0["data"]["accessToken"].get_to(m_token);
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "Token:{}", m_token);
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/* 获取算法列表 */
|
|
/* 获取算法列表 */
|
|
-bool FromSuperBrain::getTaskTypeList()
|
|
|
|
|
|
+bool FromSuperBrain::getTaskTypeList(std::vector<AlgorithmInfo>& vecInfo)
|
|
{
|
|
{
|
|
if(m_token.empty())
|
|
if(m_token.empty())
|
|
{
|
|
{
|
|
@@ -59,18 +69,35 @@ bool FromSuperBrain::getTaskTypeList()
|
|
vecHeader.push_back(fmt::format("accessToken: {}", m_token));
|
|
vecHeader.push_back(fmt::format("accessToken: {}", m_token));
|
|
std::string url = m_url + m_taskTypeListPath;
|
|
std::string url = m_url + m_taskTypeListPath;
|
|
if(!CurlHttp::Get(url, vecHeader, response))
|
|
if(!CurlHttp::Get(url, vecHeader, response))
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}}", response);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "TaskTypeList: \n{}", response);
|
|
|
|
+ /* 解析json信息 */
|
|
|
|
+ nJson json0 = nJson::parse(response);
|
|
|
|
+ auto retCode = json0.at("code").get<std::string>();
|
|
|
|
+ if(retCode != "0")
|
|
{
|
|
{
|
|
SPDLOG_LOGGER_ERROR(m_logger, "Get TaskTypeList failed");
|
|
SPDLOG_LOGGER_ERROR(m_logger, "Get TaskTypeList failed");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "response:{}", response);
|
|
|
|
- m_taskTypeList = response;
|
|
|
|
|
|
+ auto data = json0.at("data");
|
|
|
|
+ for(auto& it : data)
|
|
|
|
+ {
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "muAiName:{}", it["muAiName"].get<std::string>());
|
|
|
|
+ AlgorithmInfo info;
|
|
|
|
+ info.ActionID = it.at("ability").get<std::string>();
|
|
|
|
+ info.ActionName = it.at("muAiName").get<std::string>();
|
|
|
|
+ info.ActionTaskID = it["taskTypeId"].get<int>();
|
|
|
|
+ vecInfo.push_back(info);
|
|
|
|
+ }
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
/* 获取设备列表信息 */
|
|
/* 获取设备列表信息 */
|
|
-bool FromSuperBrain::getDeviceList()
|
|
|
|
|
|
+bool FromSuperBrain::getDeviceList(std::vector<DeviceInfo>& vecInfo)
|
|
{
|
|
{
|
|
if(m_token.empty())
|
|
if(m_token.empty())
|
|
{
|
|
{
|
|
@@ -83,10 +110,66 @@ bool FromSuperBrain::getDeviceList()
|
|
std::string url = m_url + m_deviceListPath;
|
|
std::string url = m_url + m_deviceListPath;
|
|
if(!CurlHttp::Get(url, vecHeader, response))
|
|
if(!CurlHttp::Get(url, vecHeader, response))
|
|
{
|
|
{
|
|
- SPDLOG_LOGGER_ERROR(m_logger, "Get TaskTypeList failed");
|
|
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "{}", response);
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // SPDLOG_LOGGER_DEBUG(m_logger, "DeivceList: \n{}", response);
|
|
|
|
+ /* 解析JSON信息 */
|
|
|
|
+ nJson json0 = nJson::parse(response);
|
|
|
|
+ auto retCode = json0.at("code").get<std::string>();
|
|
|
|
+ if(retCode != "0")
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "Get DeviceList failed");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ DeviceInfo info;
|
|
|
|
+ nJson json1 = json0["data"];
|
|
|
|
+ for(const auto& it : json1)
|
|
|
|
+ {
|
|
|
|
+ info.DeviceID = it["deviceId"].get<int>();
|
|
|
|
+ info.DeviceName = it["deviceName"].get<std::string>();
|
|
|
|
+ info.DeviceSerial = it["deviceSerial"].get<std::string>();
|
|
|
|
+ info.DeviceType = it["deviceType"].get<std::string>();
|
|
|
|
+ /* 这三个可能是null */
|
|
|
|
+ info.DevicePort = it["port"].is_null() ? 0 : it["port"].get<int>();
|
|
|
|
+ info.UserAccount = it["userAccount"].is_null() ? "" : it["userAccount"].get<std::string>();
|
|
|
|
+ info.UserPassword = it["userPWD"].is_null() ? "" : it["userPWD"].get<std::string>();
|
|
|
|
+ /* 解析任务类型列表 */
|
|
|
|
+ nJson json2 = it["taskTypeList"];
|
|
|
|
+ for(const auto& it1 : json2)
|
|
|
|
+ {
|
|
|
|
+ AlgorithmInfo info1;
|
|
|
|
+ info1.ActionID = it1["ability"].get<std::string>();
|
|
|
|
+ info1.ActionName = it1["taskTypeName"].get<std::string>();
|
|
|
|
+ info1.ActionTaskID = it1["taskTypeId"].get<int>();
|
|
|
|
+ info.vecAlgorithmInfo.push_back(info1);
|
|
|
|
+ }
|
|
|
|
+ vecInfo.push_back(info);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* 图片识别 */
|
|
|
|
+bool FromSuperBrain::imageRecognition()
|
|
|
|
+{
|
|
|
|
+ if(m_token.empty())
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "Token is empty");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ std::string response;
|
|
|
|
+ std::vector<std::string> vecHeader;
|
|
|
|
+ vecHeader.push_back(fmt::format("accessToken: {}", m_token));
|
|
|
|
+ /* 拼接地址 */
|
|
|
|
+ std::string url = m_url + m_imageRecognitionPath;
|
|
|
|
+ if(!CurlHttp::Get(url, vecHeader, response))
|
|
|
|
+ {
|
|
|
|
+ SPDLOG_LOGGER_ERROR(m_logger, "Get imageRecognition failed");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- SPDLOG_LOGGER_DEBUG(m_logger, "response:{}", response);
|
|
|
|
|
|
+ SPDLOG_LOGGER_DEBUG(m_logger, "imageRecognition: \n{}", response);
|
|
|
|
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|