319 lines
6.4 KiB
C++
319 lines
6.4 KiB
C++
// WcsMainDialog.cpp : 实现文件
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "afxdialogex.h"
|
|
#include "ConfigDLg.h"
|
|
#include "QrGuide.h"
|
|
#include "QrMainDialog.h"
|
|
|
|
#define CLEAR_CACHE_TIMER 1
|
|
|
|
// CMainDialog 对话框
|
|
|
|
IMPLEMENT_DYNAMIC(CQrMainDialog, CDialogEx)
|
|
|
|
CQrMainDialog::CQrMainDialog(CWnd* pParent /*=NULL*/)
|
|
: CDialogEx(IDD_MAIN_DIALOG, pParent)
|
|
{
|
|
}
|
|
|
|
CQrMainDialog::~CQrMainDialog()
|
|
{
|
|
|
|
}
|
|
|
|
void CQrMainDialog::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialogEx::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_EDIT_LOG, m_EditMultiLine);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CQrMainDialog, CDialogEx)
|
|
|
|
ON_WM_TIMER()
|
|
ON_COMMAND(IDR_MENU_CONFIG, &CQrMainDialog::OnMenuConfig)
|
|
ON_MESSAGE(WM_CAM_NETMESSAGE, &CQrMainDialog::OnTcpNetMsg)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CMainDialog 消息处理程序
|
|
|
|
//和模块进程通讯的管道回调函数:
|
|
void g_PipeCallBack(void* pObj, int lMsgId, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
CQrMainDialog* pModule = (CQrMainDialog*)pObj;
|
|
if (CEXPIPE_CONNECT_OK == lMsgId)
|
|
{
|
|
//连接成功
|
|
//if (FALSE == pModule->PostMessage(WM_PLATFORM_CONNECT_OK, NULL, NULL)) { LogOutToFile("g_PipeCallBack PostMessage error[%d]", lMsgId); }
|
|
LogOutToFile("已连接父进程管道");
|
|
|
|
//向WMS服务器请求设备配置信息
|
|
//theApp.SendMsg2Platform("WMS", DEVICE_CONFIG_REQ, NULL);
|
|
}
|
|
else if (CEXPIPE_DIS_CLIENT == lMsgId)
|
|
{
|
|
//管道断开,结束
|
|
#ifndef _DEBUG
|
|
LogOutToFile("父进程连接管道断开,本模块自动退出");
|
|
//if (FALSE == pModule->PostMessage(WM_CLOSE, NULL, NULL)) { LogOutToFile("g_PipeCallBack PostMessage error[%d]", lMsgId); }
|
|
pModule->PostMessage(WM_COMMAND, MAKEWPARAM(ID_TRAY_EXIT, 0), 0);
|
|
#endif
|
|
}
|
|
else if (CEXPIPE_NEW_DATA == lMsgId)
|
|
{
|
|
pModule->ProcessPipeMsg(lMsgId, (char*)wparam, (int)lparam);
|
|
}
|
|
else
|
|
{
|
|
;
|
|
}
|
|
}
|
|
|
|
void CQrMainDialog::AddLog2Edit(CString strMsg)
|
|
{
|
|
CString str;
|
|
m_EditMultiLine.GetWindowText(str);
|
|
|
|
if (str.GetLength() > 2048)
|
|
{
|
|
str = ""; //自动清理日志
|
|
}
|
|
|
|
str += strMsg;
|
|
str += "\r\n";
|
|
m_EditMultiLine.SetWindowText(str);
|
|
m_EditMultiLine.LineScroll(m_EditMultiLine.GetLineCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CQrMainDialog::ProcessPipeMsg(int lMsgId, char* pData, int lLen)
|
|
{
|
|
if (lLen == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
PIPE_DATA_STRUCT* pstData = (PIPE_DATA_STRUCT*)pData;
|
|
|
|
//平台转发给插件的消息
|
|
if (pstData->lMsgId == MAIN_2_MODULE_WMS && pstData->lDataLen > 0)
|
|
{
|
|
Json::Reader reader;
|
|
Json::Value root;
|
|
if (reader.parse((char*)pstData->acData, root))
|
|
{
|
|
CString strReceiver = root["receiver"].asString().c_str();
|
|
CString strSender = root["sender"].asString().c_str();
|
|
int nMsgType = root["type"].asInt();
|
|
|
|
|
|
//获取设备配置信息返回
|
|
/*if (nMsgType == DEVICE_CONFIG_RET)
|
|
{
|
|
|
|
}
|
|
else if (nMsgType == SET_TRANS_MODE_REQ && m_bDeviceInit) //设置输送线的工作模式
|
|
{
|
|
|
|
}
|
|
else if (nMsgType == GET_TRANS_STATE_REQ)//请求获取输送线状态
|
|
{
|
|
|
|
}*/
|
|
|
|
}
|
|
}
|
|
else if (pstData->lMsgId == MAIN_2_MODULE_SHOWWINDOW)
|
|
{
|
|
//PostMessage(WM_COMMAND, MAKEWPARAM(ID_TRAY_SHOW, 0), 0);
|
|
AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
|
|
SetForegroundWindow();
|
|
}
|
|
|
|
LogOutToFile("HttpServiceListener::OnRecvRequest End");
|
|
}
|
|
|
|
|
|
BOOL CQrMainDialog::OnInitDialog()
|
|
{
|
|
CDialogEx::OnInitDialog();
|
|
|
|
|
|
CString strPipe;
|
|
for (int i = 0; i < __argc; i++)
|
|
{
|
|
if (0 == strcmp(__argv[i], "-pipe") && i + 1 < __argc)
|
|
{
|
|
strPipe = __argv[i + 1];
|
|
}
|
|
}
|
|
|
|
if (strPipe.IsEmpty())
|
|
{
|
|
char acPipe[256] = "";
|
|
|
|
CString iniPath = theApp.m_strModulePath.Left(theApp.m_strModulePath.ReverseFind('\\') + 1);
|
|
//m_strModulePath = theApp.m_strModulePath.ReverseFind("\\");
|
|
iniPath = iniPath + "pipe.ini";
|
|
//中文名称,仅显示用
|
|
GetPrivateProfileString("AGV-MODULE", "PIPE_QR-GUIDE", "", acPipe, 256, iniPath);
|
|
strPipe = acPipe;
|
|
}
|
|
g_pstPipeClient->RegisterCall(g_PipeCallBack, this);
|
|
g_pstPipeClient->Connect(strPipe.GetBuffer());
|
|
|
|
|
|
m_tcpClient.InitNetInfo(theApp.m_strCameraIp, theApp.m_nCameraPort);
|
|
m_tcpClient.RegisterHwnd(m_hWnd, this);
|
|
m_tcpClient.ConnectServer();
|
|
|
|
|
|
SetTimer(CLEAR_CACHE_TIMER, 100, NULL);
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// 异常: OCX 属性页应返回 FALSE
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL CQrMainDialog::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if (pMsg->message == WM_KEYDOWN&&pMsg->wParam == VK_RETURN)
|
|
return TRUE;
|
|
if (pMsg->message == WM_KEYDOWN&&pMsg->wParam == VK_ESCAPE)
|
|
return TRUE;
|
|
|
|
return CDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CQrMainDialog::OnTimer(UINT_PTR nIDEvent)
|
|
{
|
|
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
switch (nIDEvent)
|
|
{
|
|
case CLEAR_CACHE_TIMER:
|
|
m_nLastTag = 0;
|
|
break;
|
|
}
|
|
CDialogEx::OnTimer(nIDEvent);
|
|
}
|
|
|
|
|
|
|
|
void CQrMainDialog::OnMenuConfig()
|
|
{
|
|
// TODO: 在此添加命令处理程序代码
|
|
CConfigDLg dlg;
|
|
dlg.DoModal();
|
|
}
|
|
|
|
|
|
LRESULT CQrMainDialog::OnTcpNetMsg(WPARAM wparam, LPARAM lparam)
|
|
{
|
|
NET_TCP_PACKET* pNetPacket = (NET_TCP_PACKET*)lparam;
|
|
|
|
switch (wparam)
|
|
{
|
|
case NET_CAM_CONNECT_OK:
|
|
{
|
|
GetDlgItem(IDC_CAM_STATUS)->SetWindowText("引导相机已连接");
|
|
m_bCamConnect = TRUE;
|
|
break;
|
|
}
|
|
|
|
case NET_CAM_DISCONNECT:
|
|
{
|
|
GetDlgItem(IDC_CAM_STATUS)->SetWindowText("引导相机已断开");
|
|
m_bCamConnect = FALSE;
|
|
break;
|
|
}
|
|
case NET_CAM_DATA_MSG:
|
|
{
|
|
HandleMessage(pNetPacket->pData, pNetPacket->lLen);
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
delete[] pNetPacket->pData;
|
|
delete pNetPacket;
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
void CQrMainDialog::HandleMessage(char * pMsg, int nMsgLen)
|
|
{
|
|
|
|
/*char recvdata_str1[1024] = "\0";
|
|
char tmp_str1[10] = "\0";
|
|
for (int i = 0; i < nMsgLen; i ++)
|
|
{
|
|
sprintf_s(tmp_str1, "%02X ", (unsigned char)pMsg[i]);
|
|
strcat_s(recvdata_str1, tmp_str1);
|
|
}
|
|
|
|
AddLog2Edit(recvdata_str1);*/
|
|
|
|
|
|
//解析坐标,角度信息,发送给驱动插件
|
|
int nPositionX;
|
|
short sPositionY;
|
|
unsigned short sAngle;
|
|
uint64_t lTagNum;
|
|
|
|
int nBit3, nBit4, nBit5, nBit6;
|
|
|
|
|
|
nPositionX = int(pMsg[2] & 0x07) * 0x80 * 0x4000 + int(pMsg[3]) * 0x4000 + int(pMsg[4]) * 0x80 + int(pMsg[5]);
|
|
if (nPositionX >> 23 >0)
|
|
{
|
|
nPositionX += 0xFF000000;
|
|
}
|
|
|
|
|
|
sPositionY = (short)pMsg[6] * 0x80 + (short)pMsg[7];
|
|
//Y是负值
|
|
if (sPositionY >> 13 > 0)
|
|
{
|
|
sPositionY += 0xC000;
|
|
}
|
|
|
|
sAngle = pMsg[10] * 0x80 + pMsg[11];
|
|
lTagNum = pMsg[13] * 0x4000 * 0x4000 + pMsg[14] * 0x80 * 0x4000 + pMsg[15] * 0x4000 + pMsg[16] * 0x80 + pMsg[17];
|
|
|
|
|
|
if (m_nLastTag != lTagNum )
|
|
{
|
|
Json::Value ret;
|
|
|
|
ret["x"] = nPositionX;
|
|
ret["y"] = sPositionY;
|
|
ret["angle"] = sAngle;
|
|
ret["tag"] = (uint)lTagNum;
|
|
|
|
m_nLastTag = lTagNum;
|
|
m_nLastX = nPositionX;
|
|
m_nLastY = sPositionY;
|
|
m_nLastAngle = sAngle;
|
|
|
|
|
|
Json::FastWriter writer;
|
|
string strJson = writer.write(ret);
|
|
|
|
AddLog2Edit(strJson.c_str());
|
|
|
|
theApp.SendMsg2Platform("DRIVER", GUIDE_QRCODE, ret);
|
|
}
|
|
} |