351 lines
11 KiB
C++
Raw Normal View History

2024-05-11 17:43:38 +08:00
#include "DataHandle.h"
#include "FunC.h"
#define DELP(p) if(p){delete p; p = nullptr;}
// 假设你的系统支持ANSI颜色代码
#define COLOR_RESET "\033[0m"
#define COLOR_GREEN "\033[32m"
#define COLOR_YELLOW "\033[33m"
void DataHandle::DataCallBackProc(void* pthis, const ReadData& msg) {
DataHandle* p = (DataHandle*)pthis;
ReadData readData = msg;
p->DataCallBackHandle(readData);
}
DataHandle::DataHandle()
: m_dataCallBack(nullptr)
, m_streamClient(nullptr)
, m_printIndex(-1){
m_dataTypeMp[iBOOL] = "iBOOL";
m_dataTypeMp[iSHORT] = "iSHORT";
m_dataTypeMp[iUSHORT] = "iUSHORT";
m_dataTypeMp[iINT] = "iINT";
m_dataTypeMp[iUINT] = "iUINT";
m_dataTypeMp[iFLOAT] = "iFLOAT";
m_dataTypeMp[iSTRING] = "iSTRING";
m_dataTypeMp[iCHAR] = "iCHAR";
m_dataTypeMp[iUCHAR] = "iUCHAR";
m_dataTypeMp[iWORD] = "iWORD";
m_dataTypeMp[UNKNOW] = "UNKNOW";
}
DataHandle::~DataHandle() {
DELP(m_streamClient);
}
2024-05-15 17:59:04 +08:00
2024-05-11 17:43:38 +08:00
void DataHandle::Init() {
m_streamClient = new StreamClient();
m_streamClient->SetCallBackFunc(this,&DataHandle::DataCallBackProc);
m_streamClient->Init();
2024-05-15 17:59:04 +08:00
//stream::ResponseInfo* response = new stream::ResponseInfo(); //获取一层图层的数据
//m_streamClient->GetLayerByIndex(1, response);
2024-05-11 17:43:38 +08:00
}
void DataHandle::Stop() {
m_streamClient->Stop();
DELP(m_streamClient);
}
void DataHandle::SetPushMsg(WRITETYPE dataType, const string& nameKey, const string& strValue, DATATYPE valueType) {
if (m_streamClient) {
WriteData msg;
msg.dataType = dataType;
msg.nameKey = nameKey;
msg.strValue = strValue;
msg.valueType = valueType;
m_streamClient->SetPushMsg(msg);
}
}
void DataHandle::PrintValue(const ReadData& msg){
if (m_printIndex == msg.dataType) {
auto it = msg.its.begin();
while (it != msg.its.end()) {
it->nameKey;
string valueType = m_dataTypeMp[(*it).valueType];
printf("接收:dataType:%d,nameKey:%*s, strvalue:%*s, valueType:%s\n",
msg.dataType, 33, it->nameKey.data(), 13, it->strValue.data(), valueType.data());
++it;
}
printf("共有参数%zd个...\n", msg.its.size());
2024-05-15 13:38:34 +08:00
if(m_printIndex == 9 || m_printIndex == 36){
2024-05-11 17:43:38 +08:00
static int count = 0;
++count;
if (count == 4) { count = 0; m_printIndex = -1; } //激光参数默认4个
}
2024-05-15 13:38:34 +08:00
else {
m_printIndex = -1;
}
2024-05-11 17:43:38 +08:00
}
}
void DataHandle::DataCallBackHandle(const ReadData& msg) {
if (msg.dataType == VERSIONRSP) {
if (m_printIndex != VERSIONRSP) return;
m_version = msg.its.front().strValue;
printf("版本:%s\n", m_version.data());
m_printIndex = -1;
}
else {
PrintValue(msg);
}
}
void DataHandle::Usage() {
printf(COLOR_GREEN "print TestClient usage:\n" COLOR_RESET);
printf(" 0: " COLOR_YELLOW "print help information...\n" COLOR_RESET);
printf(" 1: " COLOR_YELLOW "exit program...\n" COLOR_RESET);
2024-05-15 17:59:04 +08:00
printf(" 2: " COLOR_YELLOW "test all...\n" COLOR_RESET);
printf(" 3: " COLOR_YELLOW "test axis move interface...\n" COLOR_RESET);
printf(" 4: " COLOR_YELLOW "test scan control interface...\n" COLOR_RESET);
printf(" 5: " COLOR_YELLOW "test registration interface...\n" COLOR_RESET);
2024-05-17 10:57:17 +08:00
printf(" 6: " COLOR_YELLOW "test camera interface...\n" COLOR_RESET);
2024-05-17 15:57:36 +08:00
printf(" 7: " COLOR_YELLOW "test purifier interface...\n" COLOR_RESET);
2024-05-11 17:43:38 +08:00
printf(" 100: " COLOR_YELLOW "start test recv param interface...\n" COLOR_RESET);
}
void DataHandle::ParamReadUsage() {
printf(COLOR_GREEN "print param usage:\n" COLOR_RESET);
printf(" h: " COLOR_YELLOW "print this information...\n" COLOR_RESET);
printf(" q: " COLOR_YELLOW "return to the previous level...\n" COLOR_RESET);
printf(" 0: " COLOR_YELLOW "print alarm param...\n" COLOR_RESET);
2024-05-15 13:38:34 +08:00
printf(" 1: " COLOR_YELLOW "print version rsp...\n" COLOR_RESET);
printf(" 2: " COLOR_YELLOW "print io signal rsp...\n" COLOR_RESET);
printf(" 3: " COLOR_YELLOW "print system param data...\n" COLOR_RESET);
printf(" 4: " COLOR_YELLOW "print laserchiller data...\n" COLOR_RESET);
printf(" 5: " COLOR_YELLOW "print ups param data...\n" COLOR_RESET);
printf(" 6: " COLOR_YELLOW "print temp ctrl param data...\n" COLOR_RESET);
printf(" 7: " COLOR_YELLOW "print oxygenparam data...\n" COLOR_RESET);
printf(" 8: " COLOR_YELLOW "print laser param data...\n" COLOR_RESET);
printf(" 9: " COLOR_YELLOW "print simplesupplyparam_v10 data...\n" COLOR_RESET);
printf(" 10: " COLOR_YELLOW "print SIMPLESUPPLYPARAM_V21 data...\n" COLOR_RESET);
printf(" 11: " COLOR_YELLOW "print SIMPLESUPPLYPARAM_V22 data...\n" COLOR_RESET);
printf(" 12: " COLOR_YELLOW "print purifier param data...\n" COLOR_RESET);
printf(" 13: " COLOR_YELLOW "print power meter param data...\n" COLOR_RESET);
printf(" 14: " COLOR_YELLOW "print powder supply simple param data...\n" COLOR_RESET);
printf(" 15: " COLOR_YELLOW "print scanner power param data...\n" COLOR_RESET);
printf(" 16: " COLOR_YELLOW "print axismold data...\n" COLOR_RESET);
printf(" 17: " COLOR_YELLOW "print axismold slave data...\n" COLOR_RESET);
printf(" 18: " COLOR_YELLOW "print axisclean data...\n" COLOR_RESET);
printf(" 19: " COLOR_YELLOW "print axisclean slave data...\n" COLOR_RESET);
printf(" 20: " COLOR_YELLOW "print axisload data...\n" COLOR_RESET);
printf(" 21: " COLOR_YELLOW "print axismarm data...\n" COLOR_RESET);
printf(" 22: " COLOR_YELLOW "print axismsupply data...\n" COLOR_RESET);
printf(" 23: " COLOR_YELLOW "print axisele data...\n" COLOR_RESET);
printf(" 24: " COLOR_YELLOW "print axisele slave data...\n" COLOR_RESET);
printf(" 25: " COLOR_YELLOW "print paramlimitcfg param data...\n" COLOR_RESET);
printf(" 26: " COLOR_YELLOW "print extcfg param data...\n" COLOR_RESET);
printf(" 27: " COLOR_YELLOW "print moldcfg param data...\n" COLOR_RESET);
printf(" 28: " COLOR_YELLOW "print loadcfg param data...\n" COLOR_RESET);
printf(" 29: " COLOR_YELLOW "print armcfgparam data...\n" COLOR_RESET);
printf(" 30: " COLOR_YELLOW "print supplycfgparam data...\n" COLOR_RESET);
printf(" 31: " COLOR_YELLOW "print cleancfgparam data...\n" COLOR_RESET);
printf(" 32: " COLOR_YELLOW "print elecfgparam data...\n" COLOR_RESET);
printf(" 33: " COLOR_YELLOW "print loadparamrsp data...\n" COLOR_RESET);
printf(" 34: " COLOR_YELLOW "print scan ctrl state data...\n" COLOR_RESET);
printf(" 35: " COLOR_YELLOW "print scan ctrl Param data...\n" COLOR_RESET);
printf(" 36: " COLOR_YELLOW "print xy scan state data...\n" COLOR_RESET);
2024-05-17 10:57:17 +08:00
printf(" 37: " COLOR_YELLOW "print camera param data...\n" COLOR_RESET);
2024-05-15 17:59:04 +08:00
}
2024-05-11 17:43:38 +08:00
2024-05-15 17:59:04 +08:00
int DataHandle::Request(int index) {
int result = 0;
string userInput;
switch (index) {
case 0:
Usage(); break;
case 1:
Stop(); break;
case 2:
AllTest(); break;
case 3:
AxisMoveTest(); break;
case 4:
ScanCtrlTest(); break;
case 5:
RegistrationTest(); break;
2024-05-17 10:57:17 +08:00
case 6:
CameraTest(); break;
2024-05-17 15:57:36 +08:00
case 7:
PurifierTest(); break;
2024-05-15 17:59:04 +08:00
case 100:
ParamReadUsage();
while (printf("*请输入命令:") && std::getline(std::cin, userInput)) {
if (userInput == "q") {
printf("返回上一级...\n"); break;
}
else if (userInput.empty()) {
continue;
}
else if (userInput == "h") {
ParamReadUsage(); continue;
}
ParamRequest(stoi(userInput));
}
break;
default:
result = -1;
break;
}
2024-05-11 17:43:38 +08:00
2024-05-15 17:59:04 +08:00
return result;
2024-05-11 17:43:38 +08:00
}
void DataHandle::AllTest() {
AxisMoveTest();
ScanCtrlTest();
2024-05-15 17:59:04 +08:00
RegistrationTest();
2024-05-17 10:57:17 +08:00
CameraTest();
2024-05-11 17:43:38 +08:00
}
2024-05-15 17:59:04 +08:00
void DataHandle::ParamRequest(int index) {
2024-05-11 17:43:38 +08:00
if (index == 2) {
SetPushMsg(VERSIONREQ); //获取版本信息
}
else if (index >= 26 && index <= 33) {
SetPushMsg(REQUEST);
}
else if(index == 34){
SetPushMsg(LOADPARAM,"");
}
2024-05-15 13:38:34 +08:00
else if (index == 36) {
SetPushMsg(REQUEST,to_string(index));
}
2024-05-11 17:43:38 +08:00
m_printIndex = index;
while (m_printIndex >= 0) {
Sleep(100);
static int count = 0;
++count;
if (count == 10 && m_printIndex >= 0) { //等待1s没用收到消息判断为服务器没用发送
count = 0;
printf("服务器没有发送此参数...\n");
break;
}
}
}
//轴运动测试
void DataHandle::AxisMoveTest() {
int count =(int)MACHINEFUNC::END0;
for (int i = 0; i < count; ++i) {
SetPushMsg(WRITETYPE::AXISMOVEFUNC,to_string(i));
printf("发送请求%d成功...\n", i);
Sleep(1000);
}
}
//扫描控制测试
void DataHandle::ScanCtrlTest() {
int count = (int)SCANCTRLFUNC::END1;
for (int i = 0; i < count; ++i) {
2024-05-17 10:57:17 +08:00
if (i == REMOVESCANNER) {
2024-05-11 17:43:38 +08:00
SetPushMsg(WRITETYPE::SCANCTRLFUNC, to_string(i), to_string(1),iINT);
}
2024-05-17 10:57:17 +08:00
else if (i == STOPHEATINGMOTION) {
2024-05-11 17:43:38 +08:00
SetPushMsg(WRITETYPE::SCANCTRLFUNC, to_string(i),to_string(0),iBOOL);
}
else {
SetPushMsg(WRITETYPE::SCANCTRLFUNC, to_string(i));
}
printf("发送请求%d成功...\n", i);
2024-05-17 10:57:17 +08:00
Sleep(500);
2024-05-11 17:43:38 +08:00
}
2024-05-15 13:38:34 +08:00
2024-05-15 17:59:04 +08:00
}
void DataHandle::RegistrationTest(){
::stream::ResponseAny resp;
stream::RegResponce result;
2024-05-17 10:57:17 +08:00
WriteData wdata{ REGISTFUNC ,to_string(CHECKREG),to_string(time(nullptr)) ,iSTRING };
2024-05-15 17:59:04 +08:00
m_streamClient->Request(wdata,&resp);
if (resp.data().Is<stream::RegResponce>()) {
resp.data().UnpackTo(&result);
printf("CHECKREG resp:%d\n", result.data());
}
Sleep(100);
wdata.strValue = "123456789";
wdata.nameKey = to_string(GETSN);
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::RegResponce>()) {
resp.data().UnpackTo(&result);
printf("GETSN resp:%u\n", (unsigned int)result.data());
}
Sleep(100);
wdata.strValue = "regconfig";
wdata.nameKey = to_string(CHECKREGKEY);
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::RegResponce>()) {
resp.data().UnpackTo(&result);
printf("CHECKREGKEY resp:%d\n", result.data());
}
2024-05-17 10:57:17 +08:00
}
void DataHandle::CameraTest() {
int count = (int)CAMERAFUNC::END2;
for (int i = 0; i < count; ++i) {
if (i == GETSHOWIMAGE || i == GETSHOWIMAGES) continue;
if(i == SETDEMANDCATPURE) SetPushMsg(CAMERAFUNC, to_string(i),to_string(1),iBOOL);
else SetPushMsg(CAMERAFUNC, to_string(i));
printf("发送请求%d成功...\n", i);
Sleep(100);
}
::stream::ResponseAny resp;
stream::ImgInfoResponce result;
WriteData wdata{ CAMERAFUNC ,to_string(GETSHOWIMAGE)};
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ImgInfoResponce>()) {
resp.data().UnpackTo(&result);
printf("GETSHOWIMAGE resp:%u\n", result.levelimage());
}
Sleep(100);
resp.Clear();
wdata.nameKey = to_string(GETSHOWIMAGES);
wdata.strValue = to_string(5); //测试值
wdata.valueType = iINT; //测试值
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ImgInfoResponce>()) {
resp.data().UnpackTo(&result);
printf("GETSHOWIMAGES resp levelimg:%u,height:%d,width:%d\n", result.levelimage(),result.width(),result.height());
}
Sleep(100);
//修改参数
SetPushMsg(WRITETYPE::CAMERAPARAMUPDATE,"LastMouRefImgPosX", to_string(10),iINT);
SetPushMsg(WRITETYPE::CAMERAPARAMUPDATE,"LastMouRefImgPosY", to_string(100),iINT);
SetPushMsg(WRITETYPE::CAMERAPARAMUPDATE,"ShowFlag", to_string(1),iBOOL);
printf("CAMERAPARAMUPDATE update finish\n");
2024-05-17 15:57:36 +08:00
}
void DataHandle::PurifierTest() {
SetPushMsg(PURIFIERFUNC, to_string(STARTAUTODEOXYGEN));
printf("STARTAUTODEOXYGEN is called...\n");
SetPushMsg(PURIFIERFUNC, to_string(STOPAUTODEOXYGEN));
printf("STOPAUTODEOXYGEN is called...\n");
2024-05-11 17:43:38 +08:00
}