550 lines
13 KiB
C++
550 lines
13 KiB
C++
// DevOptDlg.cpp : 实现文件
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "KcCtrl.h"
|
|
#include "KcOperDlg.h"
|
|
#include "KcProtocol.h"
|
|
#include "afxdialogex.h"
|
|
|
|
|
|
// CDevOptDlg 对话框
|
|
|
|
IMPLEMENT_DYNAMIC(CKcOperDlg, CDialogEx)
|
|
|
|
CKcOperDlg::CKcOperDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialogEx(IDD_CK_OPT_DLG, pParent)
|
|
{
|
|
|
|
}
|
|
|
|
CKcOperDlg::~CKcOperDlg()
|
|
{
|
|
}
|
|
|
|
void CKcOperDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialogEx::DoDataExchange(pDX);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CKcOperDlg, CDialogEx)
|
|
ON_BN_CLICKED(IDC_BTN_0xAF, &CKcOperDlg::OnBnClickedBtn0xaf)
|
|
ON_BN_CLICKED(IDC_BTN_0xB0, &CKcOperDlg::OnBnClickedBtn0xb0)
|
|
ON_BN_CLICKED(IDC_BTN_0xB1, &CKcOperDlg::OnBnClickedBtn0xb1)
|
|
ON_BN_CLICKED(IDC_BTN_0x02, &CKcOperDlg::OnBnClickedBtn0x02)
|
|
ON_BN_CLICKED(IDC_BTN_0x03, &CKcOperDlg::OnBnClickedBtn0x03)
|
|
ON_BN_CLICKED(IDC_BTN_0x14, &CKcOperDlg::OnBnClickedBtn0x14)
|
|
ON_BN_CLICKED(IDC_BTN_0x17, &CKcOperDlg::OnBnClickedBtn0x17)
|
|
ON_BN_CLICKED(IDC_BTN_0xB2, &CKcOperDlg::OnBnClickedBtn0xb2)
|
|
ON_BN_CLICKED(IDC_BTN_0xAE, &CKcOperDlg::OnBnClickedBtn0xae)
|
|
ON_BN_CLICKED(IDC_BTN_0x1F, &CKcOperDlg::OnBnClickedBtn0x1f)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CDevOptDlg 消息处理程序
|
|
void CKcOperDlg::OnBnClickedBtn0xaf()
|
|
{
|
|
//构造请求报文
|
|
CKcProtocol protocol;
|
|
unsigned char acMsgContent[1024];
|
|
int nMsgLength;
|
|
protocol.BuildRequestMessage(0xAF, acMsgContent, nMsgLength);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(),theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return ;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize > 0)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret = protocol.Analysis0xAFMessage(acRecv, recvSize);
|
|
theApp.SendMsg2Platform("OPENTCS", AGV_STATUS_RPT, ret);
|
|
}
|
|
else
|
|
{
|
|
//std::cout << "Received: failed." << recvSize << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0xb0()
|
|
{
|
|
//构造请求报文
|
|
CKcProtocol protocol;
|
|
unsigned char acMsgContent[1024];
|
|
int nMsgLength;
|
|
protocol.BuildRequestMessage(0xB0, acMsgContent, nMsgLength);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize > 0)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret = protocol.Analysis0xB0Message(acRecv, recvSize);
|
|
theApp.SendMsg2Platform("OPENTCS", 0xB0, ret);
|
|
}
|
|
else
|
|
{
|
|
//std::cout << "Received: failed." << recvSize << std::endl;
|
|
}
|
|
}
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0x17()
|
|
{
|
|
//构造请求报文
|
|
CKcProtocol protocol;
|
|
unsigned char acMsgContent[1024];
|
|
int nMsgLength;
|
|
protocol.BuildRequestMessage(0x17, acMsgContent, nMsgLength);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize > 0)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret = protocol.Analysis0x17Message(acRecv, recvSize);
|
|
theApp.SendMsg2Platform("OPENTCS", 0x17, ret);
|
|
}
|
|
else
|
|
{
|
|
//std::cout << "Received: failed." << recvSize << std::endl;
|
|
}
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0xb1()
|
|
{
|
|
// TODO: 在此添加控件通知处理程序代码
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0x02()
|
|
{
|
|
Json::Value param;
|
|
|
|
param["varCount"] = 1;
|
|
|
|
Json::Value value;
|
|
Json::Value value_item;
|
|
|
|
value_item["name"] = "NaviControl";
|
|
value_item["count"] = 1;
|
|
|
|
Json::Value member;
|
|
Json::Value member_item;
|
|
member_item["offset"] = 0;
|
|
member_item["length"] = 1;
|
|
member.append(member_item);
|
|
|
|
value_item["member"] = member;
|
|
value.append(value_item);
|
|
param["var"] = value;
|
|
|
|
|
|
Build0x02Message(param);
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0x03()
|
|
{
|
|
Json::Value param;
|
|
|
|
param["var_count"] = 1;
|
|
|
|
Json::Value value;
|
|
Json::Value value_item;
|
|
|
|
value_item["name"] = "NaviControl";
|
|
value_item["count"] = 1;
|
|
|
|
Json::Value member;
|
|
Json::Value member_item;
|
|
member_item["offset"] = 0;
|
|
member_item["length"] = 1;
|
|
member_item["value"] = 1;
|
|
member.append(member_item);
|
|
|
|
value_item["member"] = member;
|
|
value.append(value_item);
|
|
param["var"] = value;
|
|
|
|
|
|
//Json::FastWriter writer;
|
|
//string strJson = writer.write(param);
|
|
//AfxMessageBox(strJson.c_str());
|
|
|
|
|
|
Build0x03Message(param);
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0x14()
|
|
{
|
|
Json::Value param;
|
|
|
|
param["angle"] = 1.0;
|
|
param["x"] = 3.0;
|
|
param["y"] = 2.0;
|
|
|
|
Build0x14Message(param);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0xb2()
|
|
{
|
|
Json::Value param;
|
|
|
|
int nType = 3;
|
|
if (1 == nType)
|
|
{
|
|
param["paramSize"] = 4;
|
|
param["actionParallelManner"] = 2;
|
|
param["actionType"] = 1;
|
|
|
|
Json::Value paramData;
|
|
Json::Value dataItem;
|
|
dataItem["isStopImmediately"] = 1;
|
|
paramData.append(dataItem);
|
|
param["paramData"] = paramData;
|
|
}
|
|
else if(2 == nType)
|
|
{
|
|
param["paramSize"] = 8;
|
|
param["actionParallelManner"] = 2;
|
|
param["actionType"] = 2;
|
|
|
|
Json::Value paramData;
|
|
Json::Value dataItem;
|
|
dataItem["orderId"] = 1;
|
|
dataItem["taskKey"] = 1;
|
|
paramData.append(dataItem);
|
|
param["paramData"] = paramData;
|
|
}
|
|
else if (3 == nType)
|
|
{
|
|
param["paramSize"] = 8;
|
|
param["actionParallelManner"] = 2;
|
|
param["actionType"] = 3;
|
|
|
|
Json::Value paramData;
|
|
Json::Value dataItem;
|
|
dataItem["orderId"] = 1;
|
|
dataItem["isStopImmediately"] = 1;
|
|
paramData.append(dataItem);
|
|
param["paramData"] = paramData;
|
|
}
|
|
|
|
|
|
Build0xB2Message(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKcOperDlg::Build0xAEMessage(Json::Value param)
|
|
{
|
|
|
|
unsigned char acMsgContent[1024] = { 0 };
|
|
int nMsgLength = 0;
|
|
CKcProtocol protocol;
|
|
|
|
protocol.BuildRequestMessage(0xAE, acMsgContent, nMsgLength, param);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize == 28)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret ;
|
|
ret["state"] = 1;
|
|
theApp.SendMsg2Platform("OPENTCS", 0xAE, ret); //下发成功
|
|
}
|
|
else
|
|
{
|
|
Json::Value ret;
|
|
ret["state"] = 0;
|
|
theApp.SendMsg2Platform("OPENTCS", 0xAE, ret); //下发失败
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CKcOperDlg::Build0xB2Message(Json::Value param)
|
|
{
|
|
|
|
unsigned char acMsgContent[1024] = { 0 };
|
|
int nMsgLength = 0;
|
|
CKcProtocol protocol;
|
|
|
|
protocol.BuildRequestMessage(0xB2, acMsgContent, nMsgLength, param);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize == 28)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret;
|
|
ret["state"] = 1;
|
|
theApp.SendMsg2Platform("OPENTCS", 0xB2, ret); //下发成功
|
|
}
|
|
else
|
|
{
|
|
Json::Value ret;
|
|
ret["state"] = 0;
|
|
theApp.SendMsg2Platform("OPENTCS", 0xB2, ret); //下发失败
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CKcOperDlg::Build0x02Message(Json::Value param)
|
|
{
|
|
|
|
unsigned char acMsgContent[1024] = { 0 };
|
|
int nMsgLength = 0;
|
|
CKcProtocol protocol;
|
|
|
|
protocol.BuildRequestMessage(0x02, acMsgContent, nMsgLength, param);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize >= 28)
|
|
{
|
|
Json::Value ret = protocol.Analysis0x02Message(acRecv, recvSize);
|
|
theApp.SendMsg2Platform("OPENTCS", 0x02, ret);
|
|
//Json::Value ret;
|
|
//ret["state"] = 1;
|
|
//theApp.SendMsg2Platform("OPENTCS", 0x02, ret); //下发成功
|
|
}
|
|
else
|
|
{
|
|
Json::Value ret;
|
|
ret["state"] = 0;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x02, ret); //下发失败
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CKcOperDlg::Build0x14Message(Json::Value param)
|
|
{
|
|
|
|
unsigned char acMsgContent[1024] = { 0 };
|
|
int nMsgLength = 0;
|
|
CKcProtocol protocol;
|
|
|
|
protocol.BuildRequestMessage(0x14, acMsgContent, nMsgLength, param);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize >= 28)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret;
|
|
ret["state"] = 1;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x14, ret); //下发成功
|
|
}
|
|
else
|
|
{
|
|
Json::Value ret;
|
|
ret["state"] = 0;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x14, ret); //下发失败
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CKcOperDlg::Build0x03Message(Json::Value param)
|
|
{
|
|
|
|
unsigned char acMsgContent[1024] = { 0 };
|
|
int nMsgLength = 0;
|
|
CKcProtocol protocol;
|
|
|
|
protocol.BuildRequestMessage(0x03, acMsgContent, nMsgLength, param);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize == 28)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
Json::Value ret;
|
|
ret["state"] = 1;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x03, ret); //下发成功
|
|
}
|
|
else
|
|
{
|
|
Json::Value ret;
|
|
ret["state"] = 0;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x03, ret); //下发失败
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0xae()
|
|
{
|
|
//模拟数据报文
|
|
Json::Value param;
|
|
|
|
param["orderId"] = 1;
|
|
param["taskKey"] = 1;
|
|
param["pointSize"] = 2;
|
|
param["pathSize"] = 1;
|
|
|
|
Json::Value pointInfo;
|
|
Json::Value pointItem;
|
|
pointItem["pointSerialNumber"] = 0;
|
|
pointItem["pointId"] = 1;
|
|
pointItem["frontAngle"] = 0;
|
|
pointItem["isFrontAngle"] = 0;
|
|
pointInfo.append(pointItem);
|
|
pointItem["pointSerialNumber"] = 2;
|
|
pointItem["pointId"] = 2;
|
|
pointItem["frontAngle"] = 0;
|
|
pointItem["isFrontAngle"] = 0;
|
|
pointInfo.append(pointItem);
|
|
|
|
param["point"] = pointInfo;
|
|
|
|
|
|
Json::Value pathInfo;
|
|
Json::Value pathItem;
|
|
pathItem["pathSerialNumber"] = 1;
|
|
pathItem["pathId"] = 12;
|
|
pathItem["pathActionSize"] = 0;
|
|
pathItem["pathActionSize"] = 0;
|
|
pathItem["maximumSpeed"] = 1.0;
|
|
pathItem["maximumAngularVelocity"] = 1.0;
|
|
pathItem["isFixedAngle"] = 0;
|
|
pathItem["fixedAngle"] = 0;
|
|
pathItem["drivePosture"] = 0;
|
|
pathInfo.append(pathItem);
|
|
param["path"] = pathInfo;
|
|
|
|
Build0xAEMessage(param);
|
|
}
|
|
|
|
|
|
void CKcOperDlg::OnBnClickedBtn0x1f()
|
|
{
|
|
//构造请求报文
|
|
CKcProtocol protocol;
|
|
unsigned char acMsgContent[1024];
|
|
int nMsgLength;
|
|
protocol.BuildRequestMessage(0x1F, acMsgContent, nMsgLength);
|
|
|
|
if (!m_udpClent.Connect(theApp.m_strControllerIp.GetBuffer(), theApp.m_nControllerPort))
|
|
{
|
|
std::cout << "Connect error." << std::endl;
|
|
return;
|
|
}
|
|
|
|
int lRto = 3000;//重传时间,单位毫秒
|
|
int lRtoCnt = 3;//最大重传次数
|
|
unsigned char acRecv[1024] = { 0 };//接收数据缓冲区
|
|
int lRecvbufSize = sizeof(acRecv);//接收缓冲区大小
|
|
|
|
int recvSize = m_udpClent.SendAndRecv((const char *)acMsgContent, nMsgLength, (char *)acRecv, lRecvbufSize, lRto, lRtoCnt);
|
|
if (recvSize > 0)
|
|
{
|
|
//std::cout << "Received: " << acRecv << std::endl;
|
|
//Json::Value ret = protocol.Analysis0xAFMessage(acRecv, recvSize);
|
|
|
|
Json::Value ret;
|
|
ret["state"] = 1;
|
|
theApp.SendMsg2Platform("OPENTCS", 0x1F, ret);
|
|
}
|
|
else
|
|
{
|
|
//std::cout << "Received: failed." << recvSize << std::endl;
|
|
}
|
|
}
|