// Vcs-Client.cpp : 定义应用程序的类行为。 // #include "stdafx.h" #include "KcCtrl.h" #include "KcMainDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif CCEXPipeClientBase* g_pstPipeClient = CCEXPipeClientBase::CreateObj(); // CVcsClientApp BEGIN_MESSAGE_MAP(CKcCtrlApp, CWinApp) ON_COMMAND(ID_HELP, &CWinApp::OnHelp) END_MESSAGE_MAP() // CVcsClientApp 构造 CKcCtrlApp::CKcCtrlApp() { // 支持重新启动管理器 m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; m_nReqPointId = -1; m_nReqPointType = -1; } // 唯一的一个 CVcsClientApp 对象 CKcCtrlApp theApp; HANDLE hmutex; // CVcsClientApp 初始化 BOOL CKcCtrlApp::InitInstance() { hmutex = CreateMutexA(nullptr, FALSE, "agv-plugin-kc-ctrl"); int err = GetLastError(); if (err == ERROR_ALREADY_EXISTS) { CloseHandle(hmutex); hmutex = nullptr; //AfxMessageBox("服务实例已启动."); return FALSE; } CHAR dir[1000] = { 0 }; int filelen = GetModuleFileName(NULL, dir, 1000); //WriteLog(dir); int i = filelen; while (dir[i] != '\\')i--; dir[i] = '\0'; m_strModulePath = dir; GetCtrlServerInfo(); // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); // 创建 shell 管理器,以防对话框包含 // 任何 shell 树视图控件或 shell 列表视图控件。 CShellManager *pShellManager = new CShellManager; // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); CKcMainDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: 在此放置处理何时用 // “确定”来关闭对话框的代码 } else if (nResponse == IDCANCEL) { // TODO: 在此放置处理何时用 // “取消”来关闭对话框的代码 } else if (nResponse == -1) { TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); } // 删除上面创建的 shell 管理器。 if (pShellManager != NULL) { delete pShellManager; } #ifndef _AFXDLL ControlBarCleanUp(); #endif // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return FALSE; } CString CKcCtrlApp::SendMsg2Platform(CString strReceiver, int nMsgType, Json::Value param) { //LogOutToFile("DRIVER::SendMsg2Platform Begin"); // 获取当前时间 CTime currentTime = CTime::GetCurrentTime(); // 格式化输出 CString strTime; strTime.Format(_T("%d-%02d-%02d %02d:%02d:%02d"),currentTime.GetYear(),currentTime.GetMonth(),currentTime.GetDay(),currentTime.GetHour(),currentTime.GetMinute(),currentTime.GetSecond()); static UINT32 nSerialNum = 0; Json::Value root; root["sender"] = "KC-CTRL"; // 插件名称,SwingArm root["receiver"] = strReceiver.GetBuffer(); root["serial_num"] = ++nSerialNum; root["time"] = strTime.GetBuffer(); root["vehicle_name"] = "50"; /****************************************************** nMsgType使用以下4种类型 CREATE_TASK_RET = 2, //WCS->WMS 创建任务返回 EXECUTE_TASK_RET = 4, //WCS->WMS 执行任务返回 DEVICE_STATE_REPORT = 5, //WCS->WMS 设备状态上报(包含错误码) DEVICE_CONFIG_REQ = 6, //WCS->WMS 请求设备配置信息 *******************************************************/ root["type"] = nMsgType; root["params"] = param; //root["name"] = "vehicles-01"; strTime.ReleaseBuffer(); Json::FastWriter writer; string strJson = writer.write(root); BOOL bRet = g_pstPipeClient->SendeMsg(WCS_2_WMS_DATA, (char*)strJson.c_str(), strJson.length()); //LogOutToFile("DRIVER::SendMsg2Platform End"); TRACE("转发给平台:%d\n", bRet); return ""; } void CKcCtrlApp::GetCtrlServerInfo() { char acIp[32] = ""; CString iniPath = theApp.m_strModulePath + "\\config.ini"; GetPrivateProfileString("SERVER", "IP", "", acIp, 32, iniPath); m_strControllerIp = acIp; m_nControllerPort = GetPrivateProfileInt("SERVER", "PORT", 0, iniPath); //获取协议授权码 char acAuth[48] = ""; GetPrivateProfileString("SERVER", "AUTH", "", acAuth, 48, iniPath); sscanf(acAuth, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", &m_acAuthCoce[0], &m_acAuthCoce[1], &m_acAuthCoce[2], &m_acAuthCoce[3], &m_acAuthCoce[4], &m_acAuthCoce[5], &m_acAuthCoce[6], &m_acAuthCoce[7], &m_acAuthCoce[8], &m_acAuthCoce[9], &m_acAuthCoce[10], &m_acAuthCoce[11], &m_acAuthCoce[12], &m_acAuthCoce[13], &m_acAuthCoce[14], &m_acAuthCoce[15]); return ; } void CKcCtrlApp::ChangeGuideType(int nType) { if (nType == QRCODE_TYPE) { Json::Value param; param["request_point_id"] = theApp.m_nReqPointId; param["request_point_type"] = theApp.m_nReqPointType; SendMsg2Platform("DRIVER", CHANGE_GUIDE_TYPE, param); } }