Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Fance committed Jan 14, 2025
1 parent 9c4b290 commit 0dd1783
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 75 deletions.
Binary file modified DLLs/T3WebviewApi/t3_webview_api.dll
Binary file not shown.
58 changes: 8 additions & 50 deletions T3000/BacnetWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,15 +856,13 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
CString temp_message;
temp_message.Format(_T("Panel %d is offline!\r\n"), npanel_id);
TRACE(temp_message);
//MessageBox(m_mainWindow, temp_message ,L"Warning", MB_OK);
WrapErrorMessage(builder, tempjson, outmsg, temp_message);
break;
}
else if (npanel_id == 0)
{
CString temp_message;
temp_message.Format(_T("Panel id can't be 0 !"), npanel_id);
//MessageBox(m_mainWindow, temp_message, L"Warning", MB_OK);
WrapErrorMessage(builder, tempjson, outmsg, temp_message);
break;
}
Expand Down Expand Up @@ -903,10 +901,6 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
p_i++;
}





for (int i = 0; i < BAC_OUTPUT_ITEM_COUNT; i++) {
tempjson["data"][p_i]["pid"] = npanel_id;
tempjson["data"][p_i]["type"] = "OUTPUT";
Expand Down Expand Up @@ -1028,7 +1022,6 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
tempjson["data"][p_i]["description"] = (char*)g_screen_data[npanel_id].at(i).description;
tempjson["data"][p_i]["label"] = (char*)g_screen_data[npanel_id].at(i).label;
tempjson["data"][p_i]["count"] = g_screen_data[npanel_id].at(i).webview_element_count;
// tempjson["data"][p_i]["mode"] = (char*)g_screen_data[npanel_id].at(i).mode;
//There is also additional data that does not need to be passed to the webview interface
p_i++;
}
Expand Down Expand Up @@ -1097,16 +1090,10 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
r_i++;
}






const std::string output = Json::writeString(builder, tempjson);
CString temp_cs(output.c_str());
outmsg = temp_cs;
//m_webView->PostWebMessageAsJson(temp_cs);
//Post_Refresh_One_Message(g_bac_instance, READINPUT_T3000, entry_index, entry_index, sizeof(Str_in_point));

break;
}
case WEBVIEW_MESSAGE_TYPE::LOAD_GRAPHIC_ENTRY:
Expand All @@ -1131,29 +1118,15 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
break;
}





if (0)
{
temp_item.Format(_T("%u_%d_json.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d_json.zip"), grp_serial_number, grp_index);
}
else
{
temp_item.Format(_T("%u_%d.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d.zip"), grp_serial_number, grp_index);

}
temp_item.Format(_T("%u_%d.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d.zip"), grp_serial_number, grp_index);

des_file = image_fordor + _T("\\") + temp_item;
des_file_zip = image_fordor + _T("\\") + temp_item_zip;
CString temp_lib_file;
temp_lib_file = _T("hvac_library.json");
des_lib_file = image_fordor + _T("\\") + temp_lib_file;


if (action == LOAD_GRAPHIC_ENTRY)
{
tempjson["action"] = "LOAD_GRAPHIC_ENTRY_RES";
Expand Down Expand Up @@ -1290,27 +1263,16 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)

grp_serial_number = g_selected_serialnumber; //暂时用这个代替
grp_index = screen_list_line;
if (0)
{
temp_item.Format(_T("%u_%d_json.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d_json.zip"), grp_serial_number, grp_index);
}
else
{
temp_item.Format(_T("%u_%d.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d.zip"), grp_serial_number, grp_index);

}
temp_item.Format(_T("%u_%d.txt"), grp_serial_number, grp_index);
temp_item_zip.Format(_T("%u_%d.zip"), grp_serial_number, grp_index);

des_file = image_fordor + _T("\\") + temp_item;
des_file_zip = image_fordor + _T("\\") + temp_item_zip;
CString temp_lib_file;
temp_lib_file = _T("hvac_library.json");
des_lib_file = image_fordor + _T("\\") + temp_lib_file;




int temp_elementcount = json["data"].get("itemsCount", Json::nullValue).asInt();
if (temp_elementcount == 0)
{
Expand Down Expand Up @@ -1361,11 +1323,7 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
}
Sleep(1);
save_button_click = 1;
#if 0
nlohmann::json jsonData = nlohmann::json::parse(file_output);
Str_Json Str_MyJson(jsonData);
Sleep(1);
#endif

break;
}
case WEBVIEW_MESSAGE_TYPE::UPDATE_ENTRY:
Expand Down Expand Up @@ -1991,8 +1949,8 @@ void HandleWebViewMsg(CString msg ,CString &outmsg, int msg_source = 0)
{
if (temp_name_index > 0)
{
temp_image_path.Format(_T("%s\\%s-%d.%s"), web_image_folder, temp_file_name_without_suffix, temp_name_index, temp_suffix);
cs_filename.Format(_T("%s-%d.%s"), temp_file_name_without_suffix, temp_name_index, temp_suffix);
temp_image_path.Format(_T("%s\\%s-%d.%s"), web_image_folder.GetBuffer(), temp_file_name_without_suffix.GetBuffer(), temp_name_index, temp_suffix.GetBuffer());
cs_filename.Format(_T("%s-%d.%s"), temp_file_name_without_suffix.GetBuffer(), temp_name_index, temp_suffix.GetBuffer());
}
else
{
Expand Down
63 changes: 38 additions & 25 deletions T3000/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15853,13 +15853,13 @@ DWORD WINAPI CMainFrame::CreateWebServerClientThreadfun(LPVOID lpVoid)
_T("127.0.0.1")
);

char sendbuf[2048] = {0};
char sendbuf[10240] = {0};
// 发送和接收数据的缓冲区
WideCharToMultiByte(CP_ACP, 0, handshakeRequest.GetBuffer(), -1, sendbuf, 2048, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, handshakeRequest.GetBuffer(), -1, sendbuf, 10240, NULL, NULL);

//const char* sendbuf = "This is a test message from client";
char recvbuf[2048] = {0};
int recvbuflen = 2048;
char recvbuf[10240] = {0};
int recvbuflen = 10240;

// 发送初始数据
iResult = send(ConnectSocket, sendbuf, (int)strlen(sendbuf), 0);
Expand All @@ -15874,7 +15874,7 @@ DWORD WINAPI CMainFrame::CreateWebServerClientThreadfun(LPVOID lpVoid)

// 循环接收和处理数据
while (true) {
memset(recvbuf, 0, 2048);
memset(recvbuf, 0, 10240);
iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
if (iResult > 0)
{
Expand Down Expand Up @@ -15903,29 +15903,42 @@ DWORD WINAPI CMainFrame::CreateWebServerClientThreadfun(LPVOID lpVoid)
}
TRACE("%s\r\n", sendbuf);
}
else if (receivedData.length() > 2)
else if (receivedData.length() > 6)
{
std::string filteredData = receivedData.substr(2);
// 检查从第三个字节开始的数据是否与 {" 一模一样
if (filteredData.find("{\"") == 0)
{
//调用别的函数处理数据
CString msg = CString(filteredData.c_str());
CString outmsg;
HandleWebViewMsg(msg, outmsg,1); //msg_source = 1 代表来自外部浏览器的消息, 需要根据panel 还有index 来加载对应的 data
std::string filteredData = receivedData;
int loop_count = 0; //有时候前面多4个字节 从第三个字节开始是长度,有时候又只有两个字节。这里循环判断 大括号加冒号为起点.
do
{

//std::string filteredData = receivedData.substr(2);
if (filteredData.find("{\"") == 0)
{
//调用别的函数处理数据
CString msg = CString(filteredData.c_str());
CString outmsg;
HandleWebViewMsg(msg, outmsg, 1); //msg_source = 1 代表来自外部浏览器的消息, 需要根据panel 还有index 来加载对应的 data

vector<unsigned char> wsFrame = CreateWebSocketFrame(outmsg);
iResult = send(ConnectSocket, reinterpret_cast<const char*>(wsFrame.data()), wsFrame.size(), 0);
vector<unsigned char> wsFrame = CreateWebSocketFrame(outmsg);
iResult = send(ConnectSocket, reinterpret_cast<const char*>(wsFrame.data()), wsFrame.size(), 0);

if (iResult == SOCKET_ERROR)
{
TRACE("send failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
TRACE("%d\r\n", sendbuf);
}
if (iResult == SOCKET_ERROR)
{
TRACE("send failed: %d\n", WSAGetLastError());
closesocket(ConnectSocket);
WSACleanup();
return 1;
}
TRACE("%d\r\n", sendbuf);
break;
}
else
{
loop_count++;
if (loop_count > 6)
break; // 没搜到起始 信号;
filteredData = receivedData.substr(loop_count); // 检查从第loop_count个字节开始的数据是否与 {" 一模一样
}
} while (loop_count < 7);
}

}
Expand Down

0 comments on commit 0dd1783

Please sign in to comment.