新增文件删除 文件上传 目录创建 目录删除
This commit is contained in:
@@ -487,6 +487,133 @@ std::vector<unsigned char> generate_getfilemenu_message(const std::string& filed
|
||||
return GetMsg(dataBuf, static_cast<unsigned char>(MsgRequestType::Request_FileDir));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
|
||||
* @param data <20><>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param sendCount <20><>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD>
|
||||
* @param count <20><>֡<EFBFBD><D6A1>
|
||||
* @param fileSize <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ܴ<EFBFBD>С
|
||||
* @param crc CRCУ<43><D0A3>ֵ
|
||||
* @param filedir <20><><EFBFBD><EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_sendfile_message(const std::vector<unsigned char>& data,
|
||||
std::uint32_t sendCount,
|
||||
std::uint32_t count,
|
||||
std::uint32_t fileSize,
|
||||
std::uint16_t crc,
|
||||
const std::string& filedir) {
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> 17+128 <20>ֽ<EFBFBD>ͷ<EFBFBD><CDB7> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0
|
||||
std::vector<unsigned char> DataBuf(17 + 128 + data.size(), 0x00);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>嵽17+128<32>ֽ<EFBFBD>ͷ<EFBFBD><CDB7>֮<EFBFBD><D6AE>
|
||||
std::copy(data.begin(), data.end(), DataBuf.begin() + 17 + 128);
|
||||
|
||||
DataBuf[0] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[1] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[2] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// 4<>ֽڵ<D6BD>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD>
|
||||
DataBuf[3] = static_cast<unsigned char>(((sendCount + 1) >> 24) & 0xFF);
|
||||
DataBuf[4] = static_cast<unsigned char>(((sendCount + 1) >> 16) & 0xFF);
|
||||
DataBuf[5] = static_cast<unsigned char>(((sendCount + 1) >> 8) & 0xFF);
|
||||
DataBuf[6] = static_cast<unsigned char>((sendCount + 1) & 0xFF);
|
||||
|
||||
// 4<>ֽ<EFBFBD><D6BD><EFBFBD>֡<EFBFBD><D6A1>
|
||||
DataBuf[7] = static_cast<unsigned char>((count >> 24) & 0xFF);
|
||||
DataBuf[8] = static_cast<unsigned char>((count >> 16) & 0xFF);
|
||||
DataBuf[9] = static_cast<unsigned char>((count >> 8) & 0xFF);
|
||||
DataBuf[10] = static_cast<unsigned char>(count & 0xFF);
|
||||
|
||||
// 4<>ֽ<EFBFBD><D6BD>ܴ<EFBFBD>С
|
||||
DataBuf[11] = static_cast<unsigned char>((fileSize >> 24) & 0xFF);
|
||||
DataBuf[12] = static_cast<unsigned char>((fileSize >> 16) & 0xFF);
|
||||
DataBuf[13] = static_cast<unsigned char>((fileSize >> 8) & 0xFF);
|
||||
DataBuf[14] = static_cast<unsigned char>(fileSize & 0xFF);
|
||||
|
||||
// 2<>ֽ<EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD>
|
||||
DataBuf[15] = static_cast<unsigned char>((crc >> 8) & 0xFF);
|
||||
DataBuf[16] = static_cast<unsigned char>(crc & 0xFF);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>17<31><37>ʼ<EFBFBD><CABC>
|
||||
size_t copyLen = std::min(filedir.size(), static_cast<size_t>(128));
|
||||
if (copyLen > 0) {
|
||||
memcpy(DataBuf.data() + 17, filedir.c_str(), copyLen);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
return GetMsg(DataBuf, static_cast<unsigned char>(MsgRequestType::Request_File_Send));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir ɾ<><C9BE><EFBFBD>ļ<EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_deletefile_message(const std::string& filedir) {
|
||||
// <20><><EFBFBD><EFBFBD> 3 <20>ֽ<EFBFBD>ͷ<EFBFBD><CDB7> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0
|
||||
std::vector<unsigned char> DataBuf(3 + 128, 0x00);
|
||||
|
||||
DataBuf[0] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[1] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[2] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>3<EFBFBD><33>ʼ<EFBFBD><CABC>
|
||||
size_t copyLen = std::min(filedir.size(), static_cast<size_t>(128));
|
||||
if (copyLen > 0) {
|
||||
memcpy(DataBuf.data() + 3, filedir.c_str(), copyLen);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>9<EFBFBD><39>Ӧɾ<D3A6><C9BE><EFBFBD>ļ<EFBFBD>
|
||||
return GetMsg(DataBuf, static_cast<unsigned char>(MsgRequestType::Request_File_Del));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir Ŀ¼ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_setmenu_message(const std::string& filedir) {
|
||||
// <20><><EFBFBD><EFBFBD> 3 <20>ֽ<EFBFBD>ͷ<EFBFBD><CDB7> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0
|
||||
std::vector<unsigned char> DataBuf(3 + 128, 0x00);
|
||||
|
||||
DataBuf[0] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[1] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[2] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>3<EFBFBD><33>ʼ<EFBFBD><CABC>
|
||||
size_t copyLen = std::min(filedir.size(), static_cast<size_t>(128));
|
||||
if (copyLen > 0) {
|
||||
memcpy(DataBuf.data() + 3, filedir.c_str(), copyLen);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>11<31><31>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>Ŀ¼
|
||||
return GetMsg(DataBuf, static_cast<unsigned char>(MsgRequestType::Request_Menu_Set));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>Ŀ¼ɾ<C2BC><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir Ŀ¼ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_delmenu_message(const std::string& filedir) {
|
||||
// <20><><EFBFBD><EFBFBD> 3 <20>ֽ<EFBFBD>ͷ<EFBFBD><CDB7> + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>Ϊ0
|
||||
std::vector<unsigned char> DataBuf(3 + 128, 0x00);
|
||||
|
||||
DataBuf[0] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[1] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
DataBuf[2] = 0x00; // <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>3<EFBFBD><33>ʼ<EFBFBD><CABC>
|
||||
size_t copyLen = std::min(filedir.size(), static_cast<size_t>(128));
|
||||
if (copyLen > 0) {
|
||||
memcpy(DataBuf.data() + 3, filedir.c_str(), copyLen);
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>12<31><32>Ӧɾ<D3A6><C9BE>Ŀ¼
|
||||
return GetMsg(DataBuf, static_cast<unsigned char>(MsgRequestType::Request_Menu_Del));
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<unsigned char> generate_requestFixValue_message(unsigned char nCpuNo) {
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
@@ -886,4 +1013,3 @@ std::vector<unsigned char> generate_control_message(uint8_t type, uint8_t ctrlfl
|
||||
return GetMsg(DataBuf, static_cast<unsigned char>(MsgRequestType::Request_Ctrl));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,14 @@ enum class MsgRequestType : unsigned char {
|
||||
Request_New_3S = 0x04,
|
||||
//<2F><><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD>
|
||||
Request_File_Download = 0x07,
|
||||
//<2F>ϴ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD>
|
||||
Request_File_Send = 0x08,
|
||||
//ɾ<><C9BE>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD>
|
||||
Request_File_Del = 0x09,
|
||||
//Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
|
||||
Request_Menu_Set = 0x0b,
|
||||
//Ŀ¼ɾ<C2BC><C9BE>
|
||||
Request_Menu_Del = 0x0c,
|
||||
//ѯ<><D1AF><EFBFBD>ļ<EFBFBD>Ŀ¼
|
||||
Request_FileDir = 0x02,
|
||||
//ѯ<><D1AF>װ<EFBFBD>ö<EFBFBD>ֵ
|
||||
@@ -69,6 +77,8 @@ enum class MsgResponseType : unsigned char {
|
||||
Response_ActiveSOEInfo = 0x17,
|
||||
//<2F><><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD>
|
||||
Response_File_Download = 0x87,
|
||||
//<2F>ϴ<EFBFBD>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD> ֡<><D6A1><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>Ĭ<EFBFBD><C4AC>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>һ֡<D2BB><D6A1>ȫ
|
||||
Response_File_Send = 0x88,
|
||||
//ѯ<><D1AF><EFBFBD>ļ<EFBFBD>Ŀ¼
|
||||
Response_FileDir = 0x82,
|
||||
//ѯ<><D1AF>װ<EFBFBD>ö<EFBFBD>ֵ
|
||||
@@ -2381,6 +2391,40 @@ std::vector<unsigned char> generate_realstat_message(unsigned char nCpuNo, unsig
|
||||
std::vector<unsigned char> generate_downloadfile_message(int frameIndex, const std::string& fileName);
|
||||
//<2F>ļ<EFBFBD>Ŀ¼<C4BF><C2BC>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD>ļ<EFBFBD>·<EFBFBD><C2B7>
|
||||
std::vector<unsigned char> generate_getfilemenu_message(const std::string& filedir);
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
|
||||
* @param data <20><>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param sendCount <20><>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD>
|
||||
* @param count <20><>֡<EFBFBD><D6A1>
|
||||
* @param fileSize <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC>ܴ<EFBFBD>С
|
||||
* @param crc CRCУ<43><D0A3>ֵ
|
||||
* @param filedir <20><><EFBFBD><EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_sendfile_message(const std::vector<unsigned char>& data,
|
||||
std::uint32_t sendCount,
|
||||
std::uint32_t count,
|
||||
std::uint32_t fileSize,
|
||||
std::uint16_t crc,
|
||||
const std::string& filedir);
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir ɾ<><C9BE><EFBFBD>ļ<EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_deletefile_message(const std::string& filedir);
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir Ŀ¼ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_setmenu_message(const std::string& filedir);
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD>Ŀ¼ɾ<C2BC><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param filedir Ŀ¼ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
std::vector<unsigned char> generate_delmenu_message(const std::string& filedir);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::vector<unsigned char> generate_requestFixValue_message(unsigned char nCpuNo);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -64,6 +64,30 @@ static uint32_t CalcNormalCrc32_Char(const std::vector<unsigned char>& bytes,
|
||||
return crc;
|
||||
}
|
||||
|
||||
// 与 C# Crc_16_new 完全对应(Modbus CRC16)
|
||||
static uint16_t CalcCrc16_Char(const std::vector<unsigned char>& bytes)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
|
||||
for (size_t i = 0; i < bytes.size(); ++i)
|
||||
{
|
||||
crc = static_cast<uint16_t>(crc ^ static_cast<uint16_t>(bytes[i]));
|
||||
for (int j = 0; j < 8; ++j)
|
||||
{
|
||||
if ((crc & 0x0001) == 0x0001)
|
||||
{
|
||||
crc = static_cast<uint16_t>((crc >> 1) ^ 0xA001);
|
||||
}
|
||||
else
|
||||
{
|
||||
crc = static_cast<uint16_t>(crc >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
// ClientContext 实现
|
||||
ClientContext::ClientContext(uv_loop_t* loop, const DeviceInfo& device, int index)
|
||||
: loop(loop), state(ConnectionState::DISCONNECTED),
|
||||
@@ -523,6 +547,120 @@ bool ClientContext::has_active_upgrade_task() const
|
||||
return upgrade_task_.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 文件上送参数初始化
|
||||
* @param file 上送文件内容
|
||||
* @param frame_payload_size 单帧数据长
|
||||
* @param dest_file_path 装置端目标全路径
|
||||
* @return 是否初始化成功
|
||||
*/
|
||||
bool ClientContext::prepare_send_file_task(const std::vector<unsigned char>& file,
|
||||
uint32_t frame_payload_size,
|
||||
const std::string& dest_file_path)
|
||||
{
|
||||
if (file.empty() || frame_payload_size == 0 || dest_file_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(send_file_mutex_);
|
||||
|
||||
send_file_task_.file_data = file;
|
||||
send_file_task_.file_size = static_cast<uint32_t>(file.size());
|
||||
send_file_task_.file_crc = CalcCrc16_Char(file);
|
||||
send_file_task_.frame_payload_size = frame_payload_size;
|
||||
send_file_task_.total_frames =
|
||||
static_cast<uint32_t>((file.size() + frame_payload_size - 1) / frame_payload_size);
|
||||
send_file_task_.next_frame_index = 0;
|
||||
send_file_task_.dest_file_path = dest_file_path;
|
||||
send_file_task_.active = (send_file_task_.total_frames > 0);
|
||||
|
||||
return send_file_task_.active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 生成文件上送的下一帧报文
|
||||
* @param out_packet 上送报文
|
||||
* @param finished 是否结束
|
||||
* @return 是否继续
|
||||
*/
|
||||
bool ClientContext::build_next_send_file_packet(std::vector<unsigned char>& out_packet, bool& finished)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(send_file_mutex_);
|
||||
|
||||
finished = false;
|
||||
out_packet.clear();
|
||||
|
||||
if (!send_file_task_.active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (send_file_task_.next_frame_index >= send_file_task_.total_frames) {
|
||||
finished = true;
|
||||
send_file_task_.active = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> frame_data =
|
||||
slice_frame_data(send_file_task_.file_data,
|
||||
send_file_task_.next_frame_index,
|
||||
send_file_task_.frame_payload_size);
|
||||
|
||||
if (frame_data.empty()) {
|
||||
send_file_task_.active = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
out_packet = generate_sendfile_message(
|
||||
frame_data,
|
||||
send_file_task_.next_frame_index, // 0-based,函数内部会 +1
|
||||
send_file_task_.total_frames,
|
||||
send_file_task_.file_size,
|
||||
send_file_task_.file_crc,
|
||||
send_file_task_.dest_file_path
|
||||
);
|
||||
|
||||
++send_file_task_.next_frame_index;
|
||||
|
||||
if (send_file_task_.next_frame_index >= send_file_task_.total_frames) {
|
||||
finished = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 获取当前文件上送的当前帧和总帧数
|
||||
* @param current_frame_index 当前帧
|
||||
* @param total_frames 总帧数
|
||||
* @return 是否正常
|
||||
*/
|
||||
bool ClientContext::get_send_file_progress(uint32_t& current_frame_index, uint32_t& total_frames) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(send_file_mutex_);
|
||||
|
||||
if (!send_file_task_.active) {
|
||||
current_frame_index = 0;
|
||||
total_frames = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
current_frame_index = send_file_task_.next_frame_index;
|
||||
total_frames = send_file_task_.total_frames;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientContext::clear_send_file_task()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(send_file_mutex_);
|
||||
send_file_task_ = SendFileTask{};
|
||||
}
|
||||
|
||||
bool ClientContext::has_active_send_file_task() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(send_file_mutex_);
|
||||
return send_file_task_.active;
|
||||
}
|
||||
|
||||
// 版本比较函数的辅助函数:分割字符串并转换为整数向量
|
||||
std::vector<int> splitVersionString(const std::string& versionStr) {
|
||||
std::vector<int> segments;
|
||||
@@ -1653,6 +1791,108 @@ bool ClientManager::add_file_download_action_to_device(
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 生成删除装置文件报文
|
||||
* @param file_path 文件全路径
|
||||
* @return 发送结果
|
||||
*/
|
||||
bool ClientManager::add_file_delete_action_to_device(
|
||||
const std::string& identifier,
|
||||
const std::string& file_path) {
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// 查找匹配的设备
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier)
|
||||
{
|
||||
// 生成文件删除请求报文
|
||||
auto delMsg = generate_deletefile_message(file_path);
|
||||
|
||||
// 添加动作到队列 (状态: 删除指定文件)
|
||||
ctx->add_action(DeviceState::DEL_FILE, delMsg);
|
||||
|
||||
// 如果当前空闲则立即执行
|
||||
if (ctx->current_state_ == DeviceState::IDLE) {
|
||||
ctx->process_next_action();
|
||||
}
|
||||
|
||||
return true; // 成功添加
|
||||
}
|
||||
}
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 生成创建目录报文
|
||||
* @param file_path 文件全路径
|
||||
* @return 发送结果
|
||||
*/
|
||||
bool ClientManager::add_menu_set_action_to_device(
|
||||
const std::string& identifier,
|
||||
const std::string& file_path) {
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// 查找匹配的设备
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier)
|
||||
{
|
||||
// 生成目录创建请求报文
|
||||
auto delMsg = generate_setmenu_message(file_path);
|
||||
|
||||
// 添加动作到队列 (状态: 创建目录)
|
||||
ctx->add_action(DeviceState::SEND_MENU, delMsg);
|
||||
|
||||
// 如果当前空闲则立即执行
|
||||
if (ctx->current_state_ == DeviceState::IDLE) {
|
||||
ctx->process_next_action();
|
||||
}
|
||||
|
||||
return true; // 成功添加
|
||||
}
|
||||
}
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 生成删除目录报文
|
||||
* @param file_path 文件全路径
|
||||
* @return 发送结果
|
||||
*/
|
||||
bool ClientManager::add_menu_del_action_to_device(
|
||||
const std::string& identifier,
|
||||
const std::string& file_path) {
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
// 查找匹配的设备
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier)
|
||||
{
|
||||
// 生成目录删除请求报文
|
||||
auto delMsg = generate_delmenu_message(file_path);
|
||||
|
||||
// 添加动作到队列 (状态: 删除目录)
|
||||
ctx->add_action(DeviceState::DEL_MENU, delMsg);
|
||||
|
||||
// 如果当前空闲则立即执行
|
||||
if (ctx->current_state_ == DeviceState::IDLE) {
|
||||
ctx->process_next_action();
|
||||
}
|
||||
|
||||
return true; // 成功添加
|
||||
}
|
||||
}
|
||||
return false; // 设备未找到
|
||||
}
|
||||
|
||||
//获取指定装置指定测点下的定值数据
|
||||
bool ClientManager::get_fixedvalue_action_to_device(const std::string& identifier, ushort point_id) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -1908,7 +2148,7 @@ bool ClientManager::read_devversion_action_to_device(const std::string& identifi
|
||||
/**
|
||||
* @brief 生成预升级校验报文
|
||||
* @param path 预校验文件路径
|
||||
* @return 包含完整报文的字节向量
|
||||
* @return 发送结果
|
||||
*/
|
||||
bool ClientManager::set_preupgrade_action_to_device(const std::string& identifier, const std::string& path) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -2043,6 +2283,115 @@ bool ClientManager::try_get_next_upgrade_packet_to_device(const std::string& ide
|
||||
return false; // 未找到设备
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 文件上送动作 发送初始帧
|
||||
* @param file 上送文件内容
|
||||
* @param sin_length 上送单帧长度
|
||||
* @param dest_file_path 装置端目标全路径
|
||||
* @return 发送结果
|
||||
*/
|
||||
bool ClientManager::send_file_action_to_device(const std::string& identifier,
|
||||
const std::vector<unsigned char>& file,
|
||||
int sin_length,
|
||||
const std::string& dest_file_path)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier) {
|
||||
|
||||
// 1. 先准备文件上送任务
|
||||
if (!ctx->prepare_send_file_task(file,
|
||||
static_cast<uint32_t>(sin_length),
|
||||
dest_file_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 生成首帧上送报文
|
||||
std::vector<unsigned char> first_packet;
|
||||
bool finished = false;
|
||||
if (!ctx->build_next_send_file_packet(first_packet, finished) ||
|
||||
first_packet.empty()) {
|
||||
ctx->clear_send_file_task();
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 添加动作到队列
|
||||
ctx->add_action(DeviceState::SEND_FILE, first_packet);
|
||||
|
||||
// 4. 如果当前空闲则立即执行
|
||||
if (ctx->current_state_ == DeviceState::IDLE) {
|
||||
ctx->process_next_action();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 文件上送动作 查询并生成下一帧报文
|
||||
* @param identifier 装置标识(device_id 或 mac)
|
||||
* @param current_frame_index 获取当前帧(0-based,表示下一次要发送的帧号)
|
||||
* @param total_frames 获取总帧数
|
||||
* @param all_sent 是否全部发送完毕
|
||||
* @param packet 输出的下一帧报文;若已发送完毕则为空
|
||||
* @return 获取结果
|
||||
*/
|
||||
bool ClientManager::try_get_next_send_file_packet_to_device(const std::string& identifier,
|
||||
uint32_t& current_frame_index,
|
||||
uint32_t& total_frames,
|
||||
bool& all_sent,
|
||||
std::vector<unsigned char>& packet)
|
||||
{
|
||||
current_frame_index = 0;
|
||||
total_frames = 0;
|
||||
all_sent = false;
|
||||
packet.clear();
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
for (auto& pair : clients_) {
|
||||
auto& ctx = pair.second;
|
||||
if (ctx->device_info.device_id == identifier ||
|
||||
ctx->device_info.mac == identifier)
|
||||
{
|
||||
// 先获取当前进度
|
||||
if (!ctx->get_send_file_progress(current_frame_index, total_frames)) {
|
||||
return false; // 没有活动上送任务
|
||||
}
|
||||
|
||||
// 已经发完
|
||||
if (current_frame_index >= total_frames) {
|
||||
all_sent = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 生成下一帧报文
|
||||
bool finished = false;
|
||||
if (!ctx->build_next_send_file_packet(packet, finished)) {
|
||||
packet.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
// build_next_send_file_packet 之后,next_frame_index 已自增
|
||||
ctx->get_send_file_progress(current_frame_index, total_frames);
|
||||
|
||||
if (current_frame_index >= total_frames) {
|
||||
all_sent = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 生成装置控制命令报文
|
||||
* @param type 命令类型 1-装置复位,2-启动录波,3-启动200ms数据记录,4-启动3秒数据记录
|
||||
|
||||
@@ -50,6 +50,10 @@ enum class DeviceState {
|
||||
READING_REALSTAT, // <20><>ȡʵʱ<CAB5><CAB1><EFBFBD><EFBFBD>
|
||||
READING_EVENTFILE, // <20><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
READING_FILEMENU, // <20><>ȡ<EFBFBD>ļ<EFBFBD>Ŀ¼
|
||||
SEND_FILE, // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
DEL_FILE, // <20>ļ<EFBFBD>ɾ<EFBFBD><C9BE>
|
||||
SEND_MENU, // Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
|
||||
DEL_MENU, // Ŀ¼ɾ<C2BC><C9BE>
|
||||
READING_FILEDATA, // <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
READING_FIXEDVALUE, // <20><>ȡ<EFBFBD><C8A1><EFBFBD>㶨ֵ
|
||||
READING_FIXEDVALUEDES, // <20><>ȡ<EFBFBD><C8A1><EFBFBD>㶨ֵ<E3B6A8><D6B5><EFBFBD><EFBFBD>
|
||||
@@ -185,6 +189,53 @@ public:
|
||||
bool get_upgrade_progress(uint32_t& current_frame_index, uint32_t& total_frames) const;
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>--------------------------------------------------
|
||||
|
||||
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>--------------------------------------------------
|
||||
struct SendFileTask
|
||||
{
|
||||
std::vector<unsigned char> file_data; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
uint32_t file_size = 0; // <20>ļ<EFBFBD><C4BC>ܴ<EFBFBD>С
|
||||
uint16_t file_crc = 0; // <20>ļ<EFBFBD>CRC16
|
||||
uint32_t frame_payload_size = 0; // <20><>֡<EFBFBD><D6A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
uint32_t total_frames = 0; // <20><>֡<EFBFBD><D6A1>
|
||||
uint32_t next_frame_index = 0; // <20><>һ<EFBFBD><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>(0-based)
|
||||
std::string dest_file_path; // װ<>ö<EFBFBD>Ŀ<EFBFBD><C4BF>ȫ·<C8AB><C2B7>
|
||||
bool active = false; // <20><>ǰ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
mutable std::mutex send_file_mutex_;
|
||||
SendFileTask send_file_task_;
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ͳ<EFBFBD><CDB2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
* @param file <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param frame_payload_size <20><>֡<EFBFBD><D6A1><EFBFBD>ݳ<EFBFBD>
|
||||
* @param dest_file_path װ<>ö<EFBFBD>Ŀ<EFBFBD><C4BF>ȫ·<C8AB><C2B7>
|
||||
* @return <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
|
||||
*/
|
||||
bool prepare_send_file_task(const std::vector<unsigned char>& file,
|
||||
uint32_t frame_payload_size,
|
||||
const std::string& dest_file_path);
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>͵<EFBFBD><CDB5><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
|
||||
* @param out_packet <20><><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>
|
||||
* @param finished <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
bool build_next_send_file_packet(std::vector<unsigned char>& out_packet, bool& finished);
|
||||
|
||||
void clear_send_file_task();
|
||||
bool has_active_send_file_task() const;
|
||||
|
||||
/**
|
||||
* @brief <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>͵ĵ<CDB5>ǰ֡<C7B0><D6A1><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>
|
||||
* @param current_frame_index <20><>ǰ֡
|
||||
* @param total_frames <20><>֡<EFBFBD><D6A1>
|
||||
* @return <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
bool get_send_file_progress(uint32_t& current_frame_index, uint32_t& total_frames) const;
|
||||
// <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>--------------------------------------------------
|
||||
|
||||
// ͳ<><CDB3><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>
|
||||
struct PointFloatCache {
|
||||
std::array<tagPqData_Float, 4> data; // <20>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0-3)
|
||||
@@ -477,6 +528,27 @@ public:
|
||||
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD> <20><><EFBFBD><EFBFBD>mac/id + <20>ļ<EFBFBD>λ<EFBFBD><CEBB>
|
||||
bool add_file_download_action_to_device(const std::string& identifier, const std::string& file_path);
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>װ<EFBFBD><D7B0><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param file_path <20>ļ<EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
||||
*/
|
||||
bool add_file_delete_action_to_device(const std::string& identifier, const std::string& file_path);
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
|
||||
* @param file_path <20>ļ<EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
||||
*/
|
||||
bool add_menu_set_action_to_device(const std::string& identifier, const std::string& file_path);
|
||||
|
||||
/**
|
||||
* @brief <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>
|
||||
* @param file_path <20>ļ<EFBFBD>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
||||
*/
|
||||
bool add_menu_del_action_to_device(const std::string& identifier, const std::string& file_path);
|
||||
|
||||
//<2F><>ȡָ<C8A1><D6B8>װ<EFBFBD><D7B0>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĶ<C2B5>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>mac/id + <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool get_fixedvalue_action_to_device(const std::string& identifier, ushort point_id);
|
||||
|
||||
@@ -532,6 +604,33 @@ public:
|
||||
bool& all_sent,
|
||||
std::vector<unsigned char>& packet);
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> <20><><EFBFBD>ͳ<EFBFBD>ʼ֡
|
||||
* @param file <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param sin_length <20><><EFBFBD>͵<EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
||||
* @param dest_file_path װ<>ö<EFBFBD>Ŀ<EFBFBD><C4BF>ȫ·<C8AB><C2B7>
|
||||
* @return <20><><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>
|
||||
*/
|
||||
bool send_file_action_to_device(const std::string& identifier,
|
||||
const std::vector<unsigned char>& file,
|
||||
int sin_length,
|
||||
const std::string& dest_file_path);
|
||||
|
||||
/**
|
||||
* @brief <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
|
||||
* @param identifier װ<>ñ<EFBFBD>ʶ<EFBFBD><CAB6>device_id <20><> mac<61><63>
|
||||
* @param current_frame_index <20><>ȡ<EFBFBD><C8A1>ǰ֡(0-based<65><64><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>һ<EFBFBD><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD>͵<EFBFBD>֡<EFBFBD><D6A1>)
|
||||
* @param total_frames <20><>ȡ<EFBFBD><C8A1>֡<EFBFBD><D6A1>
|
||||
* @param all_sent <20>Ƿ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param packet <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<D2BB><D6A1><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>ѷ<EFBFBD><D1B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
* @return <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
*/
|
||||
bool try_get_next_send_file_packet_to_device(const std::string& identifier,
|
||||
uint32_t& current_frame_index,
|
||||
uint32_t& total_frames,
|
||||
bool& all_sent,
|
||||
std::vector<unsigned char>& packet);
|
||||
|
||||
//<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
|
||||
bool get_dev_status(const std::string& identifier);
|
||||
/**
|
||||
|
||||
@@ -176,14 +176,24 @@ void process_received_message(string mac, string id,const char* data, size_t len
|
||||
ClientManager::instance().read_devversion_action_to_device(id);//主动触发,读取装置版本配置信息,仅在装置登录后执行一次,当前获取版本信息确认对时报文结构。
|
||||
|
||||
//std::vector<unsigned char> file_data = read_file_as_bytes("pqs_arm2.bin");
|
||||
//ClientManager::instance().send_upgrade_action_to_device(id, file_data,10240);//默认单帧最大10240
|
||||
//ClientManager::instance().send_file_action_to_device(id, file_data,10240,"/etc/test1.bin");//默认单帧最大10240 文件上送流程
|
||||
|
||||
//std::vector<unsigned char> file_data = read_file_as_bytes("pqs_arm2.bin");
|
||||
//ClientManager::instance().send_upgrade_action_to_device(id, file_data,10240);//默认单帧最大10240 程序升级流程
|
||||
|
||||
//ClientManager::instance().set_preupgrade_action_to_device(id, "");//装置升级预校验流程 校验文件自动生成 当前填空
|
||||
//ClientManager::instance().set_ctrl_action_to_device(id,0x01,0x00);//尝试装置重启指令!
|
||||
|
||||
//ClientManager::instance().add_menu_set_action_to_device(id,"/etc/tt1");//创建目录
|
||||
//ClientManager::instance().add_file_menu_action_to_device(id, "/etc");
|
||||
//ClientManager::instance().add_menu_del_action_to_device(id, "/etc/tt1");//删除目录
|
||||
//ClientManager::instance().add_file_menu_action_to_device(id, "/etc");
|
||||
|
||||
//ClientManager::instance().add_file_menu_action_to_device(id,"/etc");//测试文件目录读取
|
||||
//ClientManager::instance().add_file_delete_action_to_device(id, "/etc/test1.bin");//文件删除功能
|
||||
//ClientManager::instance().get_dev_status(id);//设备在线情况判断 ture在线 false离线
|
||||
//ClientManager::instance().set_real_state_count("D002", 1,1);//登录后测试实时
|
||||
//ClientManager::instance().add_file_menu_action_to_device(id,"/etc");//测试文件目录读取
|
||||
|
||||
//ClientManager::instance().add_file_download_action_to_device("D002", "/etc/NPQS570_VX_ZJ_2(V103).icd");//测试文件下载
|
||||
//ClientManager::instance().get_fixedvalue_action_to_device(id,1);//测试获取装置测点定值数据
|
||||
//ClientManager::instance().get_fixedvaluedes_action_to_device(id);//测试获取装置定值描述
|
||||
@@ -903,6 +913,124 @@ void process_received_message(string mac, string id,const char* data, size_t len
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceState::SEND_FILE:
|
||||
//文件上送
|
||||
if(udata[8] == static_cast<unsigned char>(MsgResponseType::Response_File_Send)){
|
||||
//文件应答最后一帧后,再回复的结束帧
|
||||
std::cout << "*** send file success ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewACK)) {
|
||||
uint32_t current_frame_index = 0; // 当前帧(下一次要发的帧号,0-based)
|
||||
uint32_t total_frames = 0; // 总帧数
|
||||
bool all_sent = false; // 是否所有帧都已发出
|
||||
std::vector<unsigned char> packet; // 下一帧报文
|
||||
|
||||
bool ok = ClientManager::instance().try_get_next_send_file_packet_to_device(
|
||||
id,
|
||||
current_frame_index,
|
||||
total_frames,
|
||||
all_sent,
|
||||
packet
|
||||
);
|
||||
|
||||
if (!ok) {
|
||||
// 组装后续文件上送报文失败
|
||||
std::cout << "*** send file get next packet fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else if (!packet.empty()) {
|
||||
// 成功拿到下一帧,立即发送
|
||||
std::cout << "已生成并发送下一帧文件上送报文,当前进度: "
|
||||
<< current_frame_index << "/" << total_frames << std::endl;
|
||||
|
||||
// 和升级一样,直接切状态发送,避免被其他动作打断
|
||||
ClientManager::instance().change_device_state(id, DeviceState::SEND_FILE, packet);
|
||||
|
||||
if (all_sent) {
|
||||
std::cout << "最后一帧已发出,等待装置最终文件应答\n";
|
||||
}
|
||||
}
|
||||
else if (all_sent) {
|
||||
// 所有数据帧都已经发送完毕,此时等待 Response_File_Send 最终应答
|
||||
std::cout << "所有文件帧都已发送完毕,等待装置最终文件应答\n";
|
||||
return;
|
||||
}
|
||||
else {
|
||||
// 理论上不应出现
|
||||
std::cout << "*** send file invalid next packet ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
}
|
||||
else if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewNACK)) {
|
||||
// 当前帧被拒收,文件上送失败
|
||||
std::cout << "*** send file 0x41 fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else {
|
||||
// 装置答非所问
|
||||
std::cout << "*** send file ?? fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceState::DEL_FILE:
|
||||
//文件删除
|
||||
if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewACK)) {
|
||||
//文件删除完毕!
|
||||
std::cout << "*** del file success ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewNACK)) {
|
||||
// 当前帧被拒收,文件删除失败
|
||||
std::cout << "*** del file 0x41 fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else {
|
||||
// 装置答非所问
|
||||
std::cout << "*** del file ?? fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceState::SEND_MENU:
|
||||
//创建目录
|
||||
if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewACK)) {
|
||||
//创建目录完毕!
|
||||
std::cout << "*** send menu success ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewNACK)) {
|
||||
// 当前帧被拒收,创建目录失败
|
||||
std::cout << "*** send menu 0x41 fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else {
|
||||
// 装置答非所问
|
||||
std::cout << "*** send menu ?? fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceState::DEL_MENU:
|
||||
//删除目录
|
||||
if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewACK)) {
|
||||
//删除目录完毕!
|
||||
std::cout << "*** del menu success ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_NewNACK)) {
|
||||
// 当前帧被拒收,删除目录失败
|
||||
std::cout << "*** del menu 0x41 fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
else {
|
||||
// 装置答非所问
|
||||
std::cout << "*** del menu ?? fail ***! " << mac << std::endl;
|
||||
ClientManager::instance().change_device_state(id, DeviceState::IDLE);
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceState::READING_FILEDATA:
|
||||
//下载文件数据 和暂态文件下载共用同一功能码
|
||||
if (udata[8] == static_cast<unsigned char>(MsgResponseType::Response_File_Download))
|
||||
|
||||
Reference in New Issue
Block a user