add interface
This commit is contained in:
@@ -2222,6 +2222,8 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
try {
|
||||
switch (parsed.type) {
|
||||
case 1101: { // 读取目录
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
|
||||
int ret = recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEMENU),1);
|
||||
if(-1 == ret){ //0记录成功往下执行,1装置正忙,-1未找到装置
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND), //响应
|
||||
@@ -2240,7 +2242,6 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
DIY_INFOLOG_CODE(devid,1,LOG_CODE_CLOUD, "记录装置状态成功,准备读取目录");
|
||||
}
|
||||
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
parsed.name = msgObj["Name"].get<std::string>();
|
||||
parsed.ok = true;
|
||||
|
||||
@@ -2252,7 +2253,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
|
||||
case 1102: { // 下载文件
|
||||
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_FILEDATA), 1);
|
||||
if (-1 == ret) {
|
||||
@@ -2273,7 +2274,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
}
|
||||
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
|
||||
parsed.name = msgObj["Name"].get<std::string>();
|
||||
parsed.ok = true;
|
||||
|
||||
@@ -2625,7 +2626,200 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
|
||||
////////lnk20260312新增读取运行状态、版本、对时、重启
|
||||
////////lnk20260402新增目录新建、删除,文件删除,文件上传
|
||||
case 1116: { // 文件上送
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
if (!msgObj.contains("RemoteName") || !msgObj["RemoteName"].is_string()) return false;
|
||||
|
||||
parsed.ok = true;
|
||||
|
||||
std::cout << "[parsemsg] send file, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
//【1】recordguid
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SEND_FILE), 1);
|
||||
if (-1 == ret) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||
"未找到该装置,文件上送指令执行失败");
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,文件上送指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else if (ret > 0) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
|
||||
"该装置正忙,文件上送指令执行失败");
|
||||
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,文件上送指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
std::cout << "记录装置状态成功,准备执行文件上送" << std::endl;
|
||||
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "记录装置状态成功,准备执行文件上送");
|
||||
}
|
||||
}
|
||||
|
||||
//【2】取参数(加 sanitize)
|
||||
std::string remote_path = sanitize(msgObj["Name"].get<std::string>()); // 云端路径
|
||||
std::string dest_file_path = sanitize(msgObj["RemoteName"].get<std::string>()); // 装置路径
|
||||
|
||||
std::cout << "[parsemsg][1116] remote=" << remote_path
|
||||
<< ", dest=" << dest_file_path << std::endl;
|
||||
|
||||
//【3】先下载到本地
|
||||
std::string local_path = getfilefromweb(devid, remote_path);
|
||||
|
||||
if (local_path.empty()) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"文件上送失败,下载源文件失败: " + remote_path);
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "文件发送装置失败,下载源文件失败");
|
||||
return true;
|
||||
}
|
||||
|
||||
//【4】读取本地文件
|
||||
std::ifstream in(local_path.c_str(), std::ios::in | std::ios::binary);
|
||||
if (!in.is_open()) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"文件上送失败,无法打开本地文件: " + local_path);
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "文件发送装置失败,无法打开本地文件");
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> file_data;
|
||||
|
||||
in.seekg(0, std::ios::end);
|
||||
std::streamoff file_size = in.tellg();
|
||||
in.seekg(0, std::ios::beg);
|
||||
|
||||
if (file_size < 0) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"文件上送失败,读取文件大小异常: " + local_path);
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "文件发送装置失败,读取文件大小异常");
|
||||
return true;
|
||||
}
|
||||
|
||||
file_data.resize(static_cast<size_t>(file_size));
|
||||
if (file_size > 0) {
|
||||
in.read(reinterpret_cast<char*>(&file_data[0]), file_size);
|
||||
}
|
||||
in.close();
|
||||
|
||||
//【5】下发到装置
|
||||
if (!ClientManager::instance().send_file_action_to_device(
|
||||
devid, file_data, 10240, dest_file_path)) {
|
||||
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"文件上送指令下发失败");
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "文件上送指令下发失败");
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
case 1117: { // 文件删除
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
parsed.ok = true;
|
||||
|
||||
std::cout << "[parsemsg] delete file, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::DEL_FILE), 1);
|
||||
if (-1 == ret) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||
"未找到该装置,文件删除指令执行失败");
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,文件删除指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else if (ret > 0) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
|
||||
"该装置正忙,文件删除指令执行失败");
|
||||
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,文件删除指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
std::cout << "记录装置状态成功,准备执行文件删除" << std::endl;
|
||||
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "记录装置状态成功,准备执行文件删除");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string dev_file_name = msgObj["Name"].get<std::string>();
|
||||
|
||||
std::cout << "[parsemsg][1117] Name=" << dev_file_name << std::endl;
|
||||
|
||||
ClientManager::instance().add_file_delete_action_to_device(devid, dev_file_name);
|
||||
return true;
|
||||
}
|
||||
case 1118: { // 目录创建
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
parsed.ok = true;
|
||||
|
||||
std::cout << "[parsemsg] create menu, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SEND_MENU), 1);
|
||||
if (-1 == ret) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||
"未找到该装置,目录创建指令执行失败");
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,目录创建指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else if (ret > 0) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
|
||||
"该装置正忙,目录创建指令执行失败");
|
||||
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,目录创建指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
std::cout << "记录装置状态成功,准备执行目录创建" << std::endl;
|
||||
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "记录装置状态成功,准备执行目录创建");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string dir_name = msgObj["Name"].get<std::string>();
|
||||
|
||||
std::cout << "[parsemsg][1118] Name=" << dir_name << std::endl;
|
||||
|
||||
ClientManager::instance().add_menu_set_action_to_device(devid, dir_name);
|
||||
return true;
|
||||
}
|
||||
case 1119: { // 目录删除
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
parsed.ok = true;
|
||||
|
||||
std::cout << "[parsemsg] delete menu, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::DEL_MENU), 1);
|
||||
if (-1 == ret) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||
"未找到该装置,目录删除指令执行失败");
|
||||
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,目录删除指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else if (ret > 0) {
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
|
||||
"该装置正忙,目录删除指令执行失败");
|
||||
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,目录删除指令执行失败");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
std::cout << "记录装置状态成功,准备执行目录删除" << std::endl;
|
||||
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "记录装置状态成功,准备执行目录删除");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string dir_name = msgObj["Name"].get<std::string>();
|
||||
|
||||
std::cout << "[parsemsg][1119] Name=" << dir_name << std::endl;
|
||||
|
||||
ClientManager::instance().add_menu_del_action_to_device(devid, dir_name);
|
||||
return true;
|
||||
}
|
||||
////////lnk20260402新增目录新建、删除,文件删除,文件上传
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user