diff --git a/CCEXPipe/CCEXPipe.vcxproj b/CCEXPipe/CCEXPipe.vcxproj index 50a86d7..9b22cd3 100644 --- a/CCEXPipe/CCEXPipe.vcxproj +++ b/CCEXPipe/CCEXPipe.vcxproj @@ -22,7 +22,7 @@ {548705F2-AF3E-45B7-A716-578791B1ECBE} CCEXPipe Win32Proj - 10.0 + 10.0.10586.0 @@ -35,7 +35,7 @@ DynamicLibrary MultiByte true - v143 + v140 DynamicLibrary @@ -45,7 +45,7 @@ DynamicLibrary MultiByte - v143 + v140 diff --git a/Platform/Agv-Platform.vcxproj b/Platform/Agv-Platform.vcxproj index c7dc851..abf1018 100644 --- a/Platform/Agv-Platform.vcxproj +++ b/Platform/Agv-Platform.vcxproj @@ -21,7 +21,7 @@ {4DA0C82B-2496-4A33-BDCE-E89D85A60BF8} VcsClient - 10.0 + 10.0.10586.0 MFCProj @@ -43,14 +43,14 @@ Application true - v143 + v140 MultiByte Dynamic Application false - v143 + v140 true MultiByte Dynamic diff --git a/Plugin/Driver/Driver.vcxproj b/Plugin/Driver/Driver.vcxproj index c446ed3..4b7473d 100644 --- a/Plugin/Driver/Driver.vcxproj +++ b/Plugin/Driver/Driver.vcxproj @@ -21,7 +21,7 @@ {8BBB60C1-510D-47BC-8FD2-E14E9EA3A156} VcsClient - 10.0 + 10.0.10586.0 MFCProj @@ -43,14 +43,14 @@ Application true - v143 + v140 MultiByte Dynamic Application false - v143 + v140 true MultiByte Dynamic diff --git a/Plugin/Fast/Fast.cpp b/Plugin/Fast/Fast.cpp index 3749db5..8ad57c8 100644 --- a/Plugin/Fast/Fast.cpp +++ b/Plugin/Fast/Fast.cpp @@ -133,7 +133,6 @@ CString CFastApp::SendMsg2Platform(CString strReceiver, int nMsgType, Json::Valu string strJson = writer.write(root); g_pstPipeClient->SendeMsg(WCS_2_WMS_DATA, (char*)strJson.c_str(), strJson.length()); - LogOutToFile("FAST::SendMsg2Platform End"); return ""; diff --git a/Plugin/Fast/Fast.vcxproj b/Plugin/Fast/Fast.vcxproj index 3815b54..3d37acd 100644 --- a/Plugin/Fast/Fast.vcxproj +++ b/Plugin/Fast/Fast.vcxproj @@ -23,7 +23,7 @@ {EDB92B51-C3C2-44DA-B21D-6BB824264D08} GrabImage_Display Win32Proj - 10.0 + 10.0.10586.0 @@ -40,14 +40,14 @@ Application - v143 + v140 MultiByte true Dynamic Application - v143 + v140 MultiByte Dynamic diff --git a/Plugin/Fast/FastMainDialog.cpp b/Plugin/Fast/FastMainDialog.cpp index 718e3a5..7de1477 100644 --- a/Plugin/Fast/FastMainDialog.cpp +++ b/Plugin/Fast/FastMainDialog.cpp @@ -121,7 +121,107 @@ void CFastMainDialog::ProcessPipeMsg(int lMsgId, char* pData, int lLen) LogOutToFile("HttpServiceListener::OnRecvRequest End"); } +// TCP服务端线程 +UINT CFastMainDialog::TCPListenerThread(LPVOID pParam) { + CFastMainDialog* pThis = (CFastMainDialog*)pParam; + SOCKET hServer = pThis->m_hServerSocket; + while (true) { + SOCKET hClient = accept(hServer, NULL, NULL); + if (hClient == INVALID_SOCKET) continue; + + char buffer[4096]; + int bytesRecv = recv(hClient, buffer, sizeof(buffer), 0); + if (bytesRecv > 0) { + CString strMsg(buffer, bytesRecv); + pThis->ProcessTCPMessage(strMsg); + } + closesocket(hClient); + } + return 0; +} + +// 处理收到的TCP消息 +void CFastMainDialog::ProcessTCPMessage(const CString& strJson) { + LogOutToFile("FAST::ProcessTCPMessage Received: %s", strJson); + + Json::Reader reader; + Json::Value root; + if (!reader.parse((LPCTSTR)strJson, root)) { + LogOutToFile("JSON parse error!"); + return; + } + + // 验证必要字段 + if (!root.isMember("receiver") || !root.isMember("type")) { + LogOutToFile("Invalid message format"); + return; + } + + // 通过现有平台接口转发 + CString strReceiver = root["receiver"].asString().c_str(); + int nMsgType = root["type"].asInt(); + Json::Value params = root.get("params", Json::nullValue); + + theApp.SendMsg2Platform(strReceiver, nMsgType, params); +} + +// 启动TCP服务 +void CFastMainDialog::StartTCPServer() +{ + // 1. 初始化Winsock + WSADATA wsaData; + int wsResult = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (wsResult != 0) { + LogOutToFile("[TCP] WSAStartup failed: %d", wsResult); + return; + } + + // 2. 创建Socket + m_hServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (m_hServerSocket == INVALID_SOCKET) { + LogOutToFile("[TCP] Socket creation failed: %d", WSAGetLastError()); + WSACleanup(); + return; + } + + // 3. 设置端口复用(可选) + int optval = 1; + setsockopt(m_hServerSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof(optval)); + + // 4. 绑定端口 + sockaddr_in service; + service.sin_family = AF_INET; + service.sin_addr.s_addr = INADDR_ANY; + service.sin_port = htons(6000); + + if (::bind(m_hServerSocket, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR) + { + LogOutToFile("[TCP] Bind failed on port 6000: %d", WSAGetLastError()); + closesocket(m_hServerSocket); + WSACleanup(); + return; + } + + // 5. 开始监听 + if (listen(m_hServerSocket, SOMAXCONN) == SOCKET_ERROR) + { + LogOutToFile("[TCP] Listen failed: %d", WSAGetLastError()); + closesocket(m_hServerSocket); + WSACleanup(); + return; + } + + // 6. 启动线程 + m_pListenerThread = AfxBeginThread(TCPListenerThread, this); + if (m_pListenerThread == NULL) { + LogOutToFile("[TCP] Thread creation failed!"); + closesocket(m_hServerSocket); + WSACleanup(); + return; + } + LogOutToFile("[TCP] Server successfully started on port 6000"); +} BOOL CFastMainDialog::OnInitDialog() { CDialogEx::OnInitDialog(); @@ -155,7 +255,7 @@ BOOL CFastMainDialog::OnInitDialog() //初始化本地相机 InitLocalCamera(); - + StartTCPServer(); // 新增TCP服务启动 return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } diff --git a/Plugin/Fast/FastMainDialog.h b/Plugin/Fast/FastMainDialog.h index 9da1c0d..d485dda 100644 --- a/Plugin/Fast/FastMainDialog.h +++ b/Plugin/Fast/FastMainDialog.h @@ -13,6 +13,9 @@ public: CFastMainDialog(CWnd* pParent = NULL); // 标准构造函数 virtual ~CFastMainDialog(); + void StartTCPServer(); + void StopTCPServer(); + // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_MAIN_DIALOG }; @@ -35,4 +38,10 @@ public: afx_msg void OnTimer(UINT_PTR nIDEvent); void ProcessPipeMsg(int lMsgId, char* pData, int lLen); + +private: + static UINT __cdecl TCPListenerThread(LPVOID pParam); + void ProcessTCPMessage(const CString& strJson); + CWinThread* m_pListenerThread; + SOCKET m_hServerSocket; }; diff --git a/Plugin/KcCtrl/KcCtrl.vcxproj b/Plugin/KcCtrl/KcCtrl.vcxproj index 18add1b..06fd241 100644 --- a/Plugin/KcCtrl/KcCtrl.vcxproj +++ b/Plugin/KcCtrl/KcCtrl.vcxproj @@ -21,7 +21,7 @@ {77089A10-F10B-4E0E-B045-86271BFD1A07} VcsClient - 10.0 + 10.0.10586.0 MFCProj @@ -43,14 +43,14 @@ Application true - v143 + v140 MultiByte Dynamic Application false - v143 + v140 true MultiByte Dynamic diff --git a/Plugin/Plc/Plc.vcxproj b/Plugin/Plc/Plc.vcxproj index 191440a..0c81e1a 100644 --- a/Plugin/Plc/Plc.vcxproj +++ b/Plugin/Plc/Plc.vcxproj @@ -21,7 +21,7 @@ {CD291D2B-F677-46FC-BC5F-0C4A18CBBC11} VcsClient - 10.0 + 10.0.10586.0 MFCProj @@ -43,14 +43,14 @@ Application true - v143 + v140 MultiByte Dynamic Application false - v143 + v140 true MultiByte Dynamic diff --git a/Plugin/QrGuide/QrGuide.vcxproj b/Plugin/QrGuide/QrGuide.vcxproj index 9eeb675..ea564c2 100644 --- a/Plugin/QrGuide/QrGuide.vcxproj +++ b/Plugin/QrGuide/QrGuide.vcxproj @@ -23,7 +23,7 @@ {A98ADD5C-021A-494A-9E04-61E7F3220104} GrabImage_Display Win32Proj - 10.0 + 10.0.10586.0 @@ -40,14 +40,14 @@ Application - v143 + v140 MultiByte true Dynamic Application - v143 + v140 MultiByte Dynamic