优化客户端下线检测

This commit is contained in:
wangxx1809 2024-06-28 17:38:05 +08:00
parent 56137774d8
commit 21152455aa
32 changed files with 3039 additions and 1861 deletions

View File

@ -9,6 +9,7 @@
#include "../Purifier/BasePurifier.h"
#include <thread>
#include "../Registration/Registration.h"
#include "FileDialog.h"
class Controller {
public:
@ -43,6 +44,8 @@ public:
Registration* m_reg;
HBDCamera* m_Camera;
FileDialog m_fileDialog;
private:
bool m_sendTdExitFlag;
thread m_sendParamThread;

View File

@ -0,0 +1,185 @@
#include "FileDialog.h"
#include <algorithm>
#include "../utils/dirent.h"
#include "../utils/StringHelper.h"
#include "../utils/ConverType.hpp"
FileDialog::FileDialog() {
}
FileDialog::~FileDialog() {
}
void FileDialog::GetLogicalDrive(::stream::ResponseAny** rsp) {
//std::vector<std::string> vecDrives;
char szbuf[MAX_PATH] = { 0 };
GetLogicalDriveStrings(MAX_PATH, szbuf);
int nCount = 0;
char* pDrive = szbuf;
string driveStr;
for (size_t nlen = strlen(szbuf); nlen == 3; nCount++)
{
std::string strDrive(pDrive);
driveStr += strDrive + " ";
pDrive += 4;
nlen = strlen(pDrive);
}
stream::ComResponce result;
result.set_data(driveStr);
(*rsp)->mutable_data()->PackFrom(result);
}
inline bool ReplaceString(std::wstring& str, const std::wstring& oldStr, const std::wstring& newStr)
{
bool Finded = false;
size_t pos = 0;
while ((pos = str.find(oldStr, pos)) != std::wstring::npos) {
Finded = true;
str.replace(pos, oldStr.length(), newStr);
pos += newStr.length();
}
return Finded;
}
inline std::vector<std::wstring> splitStringVector(const std::wstring& text, char delimiter)
{
std::vector<std::wstring> arr;
std::wstring::size_type start = 0;
std::wstring::size_type end = text.find(delimiter, start);
while (end != std::string::npos)
{
std::wstring token = text.substr(start, end - start);
if (token != L"")
arr.push_back(token);
start = end + 1;
end = text.find(delimiter, start);
}
arr.push_back(text.substr(start));
return arr;
}
void FileDialog::Request(const ReadData& rd, ::stream::ResponseAny** resp) {
CALLFUNC type = (CALLFUNC)ConverType::TryToI(rd.nameKey);
if (type == CALLFUNC::GetLogicalDrive) {
GetLogicalDrive(resp);
printf("GetLogicalDrive responded...\n");
}
else if(type == CALLFUNC::ScanDir){
std::wstring vPath = StringHelper::Str2Wstr(rd.strValue);
ScanDir(vPath);
stream::ComResponce result;
string dirc;
for (auto start = m_CurrentPath_Decomposition.begin(); start != m_CurrentPath_Decomposition.end(); ++start) {
dirc += StringHelper::Wstr2Str(*start) + " ";
}
result.set_directory(dirc); //当前目录 空格隔开
for (auto start = m_FileList.begin(); start != m_FileList.end(); ++start) {
auto pFileInfo = result.add_fileinfo(); //目录下的文件夹 空格隔开
pFileInfo->set_type("" + start->type);
pFileInfo->set_filename(StringHelper::Wstr2Str(start->fileName));
pFileInfo->set_filepath(StringHelper::Wstr2Str(start->filePath));
pFileInfo->set_ext(StringHelper::Wstr2Str(start->ext));
}
(*resp)->mutable_data()->PackFrom(result);
printf("ScanDir responded...\n");
}
}
bool FileDialog::ScanDir(std::wstring vPath)
{
struct _wdirent** files = 0;
int i = 0;
int n = 0;
m_FileList.clear();
// get currentPath
WDIR* currentDir = _wopendir(vPath.c_str());
if (currentDir == 0) // path not existing
{
vPath = L"."; // current app path
currentDir = _wopendir(vPath.c_str());
}
if (currentDir != 0)
{
std::wstring ws(currentDir->patt);
m_CurrentPath = std::wstring(ws.begin(), ws.end());
ReplaceString(m_CurrentPath, L"\\*", L"");
_wclosedir(currentDir);
m_CurrentPath_Decomposition = splitStringVector(m_CurrentPath, '\\');
}
else
{
return false;
}
n = wscandir(vPath.c_str(), &files, NULL, [](const void* a, const void* b) {
return strcoll(((dirent*)a)->d_name, ((dirent*)b)->d_name);
});
if (n >= 0)
{
for (i = 0; i < n; i++)
{
struct _wdirent* ent = files[i];
FileInfoStruct infos;
infos.fileName = ent->d_name;
if (ent->d_type == DT_REG) {
infos.type = 'f';
}
if (ent->d_type == DT_DIR) {
infos.type = 'd';
}
if (ent->d_type == DT_LNK) {
infos.type = 'l';
}
if (infos.type == 'f')
{
size_t lpt = infos.fileName.find_last_of(L".");
if (lpt != std::wstring::npos)
infos.ext = infos.fileName.substr(lpt);
}
if (infos.fileName != L".")
{
switch (ent->d_type)
{
case DT_REG: infos.type = 'f'; break;
case DT_DIR: infos.type = 'd'; break;
case DT_LNK: infos.type = 'l'; break;
}
m_FileList.push_back(infos);
}
}
for (i = 0; i < n; i++)
{
free(files[i]);
}
free(files);
}
std::sort(m_FileList.begin(), m_FileList.end(), [](FileInfoStruct& a, FileInfoStruct& b) {
bool res;
if (a.type != b.type) res = (a.type < b.type);
else res = (a.fileName < b.fileName);
return res;
});
return true;
}

View File

@ -0,0 +1,43 @@
#pragma once
#include <vector>
#include <string>
#include "../protobuf/stream.pb.h"
#include "../DataManage/RWData.h"
#define MAX_FILE_DIALOG_NAME_BUFFER 1024
struct FileInfoStruct
{
char type;
std::wstring filePath;
std::wstring fileName;
std::wstring ext;
};
enum CALLFUNC {
GetLogicalDrive=0,
ScanDir,
};
class FileDialog
{
public:
FileDialog();
~FileDialog();
public:
void Request(const ReadData& rd, ::stream::ResponseAny** response); //查询路径下的文件、文件夹等
private:
bool ScanDir(std::wstring vPath); //查询路径下的文件、文件夹等
void GetLogicalDrive(::stream::ResponseAny** rsp); //获取盘符等,空格隔开
//void ComposeNewPath(std::vector<std::wstring>::iterator vIter); //组合为一个路径
private:
std::string m_DriverItem; //选中的盘符
std::vector<FileInfoStruct> m_FileList; //当前路径下的文件、文件夹
std::wstring m_SelectedFileName; //选取的文件名
std::wstring m_CurrentPath; //当前的路径
std::vector<std::wstring> m_CurrentPath_Decomposition; //当前路径的文件名集合
std::wstring m_CurrentFilterExt; //文件后缀
};

View File

@ -12,7 +12,7 @@ void ClientWrapper::AddClient(ClientInfo* clientInfo) {
if (!isExist) m_clientList.emplace_back(clientInfo);
}
//下线检测
//下线检测 没用了
void ClientWrapper::OfflineCheck() {
std::lock_guard<std::mutex> lck(m_mux);
auto client = m_clientList.begin();
@ -62,4 +62,18 @@ bool ClientWrapper::IsExist(ClientInfo* ci) {
++client;
}
return flag;
}
void ClientWrapper::CloseOne(ClientInfo* ci) {
std::lock_guard<std::mutex> lck(m_mux);
auto client = m_clientList.begin();
while (client != m_clientList.end()) {
if (*client == ci) {
(*client)->m_context->TryCancel();
delete (*client);
m_clientList.erase(client);
break;
}
++client;
}
}

View File

@ -85,6 +85,8 @@ public:
bool IsExist(ClientInfo* ci);
void CloseOne(ClientInfo* ci);
private:
ClientWrapper() {}
~ClientWrapper() {}

View File

@ -32,6 +32,9 @@ void DataHandle::FuncDataCallBackProc(void* pthis,const ReadData& msg, const lis
else if ((READTYPE)msg.dataType == SCANERCTRLCFG) {
p->m_config->ScanerCtrlCfgReq(msg, lst, response);
}
else if ((READTYPE)msg.dataType == DIRCTROYFUNC) {
p->m_controller->m_fileDialog.Request(msg,response);
}
}

View File

@ -17,6 +17,7 @@ enum READTYPE {
CAMERAPARAMUPDATE, //相机参数更新
PURIFIERFUNC, //净化器接口功能
CONFIGFUNC, //config functions
DIRCTROYFUNC, //请求目录信息
SETZEROPOS, //AxisState使用
AXISSTOPALL, //axis 运动急停

View File

@ -3,7 +3,6 @@
StreamServer::StreamServer(Machine* p)
: m_port(50010)
, m_checkQuitFlag(false)
, m_dataCallBack(nullptr)
, m_machine(p)
, m_handlePtr(nullptr){
@ -12,9 +11,6 @@ StreamServer::StreamServer(Machine* p)
StreamServer::~StreamServer() {
Stop();
m_checkQuitFlag = true;
if (m_checkCloseTd.joinable()) m_checkCloseTd.join();
}
@ -52,7 +48,13 @@ Status StreamServer::AllStream(ServerContext* context, grpc::ServerReaderWriter<
std::thread read([this, &stream, cinfo] {
RequestInfo request;
while (!cinfo->m_readQuitFlag && stream->Read(&request)) {
while (!cinfo->m_readQuitFlag) {
if (!stream->Read(&request)) { //返回false 认为是client掉线了
printf("client %s 下线了\n", cinfo->m_clientAddr.data());
cinfo->m_writeQuitFlag = true;
ClientWrapper::Instance()->CloseOne(cinfo);
break;
}
ReadData readData;
readData.dataType = (READTYPE)request.datatype();
readData.nameKey = request.namekey();
@ -81,12 +83,12 @@ Status StreamServer::AllStream(ServerContext* context, grpc::ServerReaderWriter<
printf("客户端消息dataType:%d,nameKey:%s, strValue:%s,valueType:%d,lst:%zd\n",
readData.dataType, readData.nameKey.c_str(), readData.strValue.c_str(), readData.valueType, paramLst.size());
if (m_dataCallBack) {
readData.its = paramLst;
//readData.its = paramLst;
m_dataCallBack(m_handlePtr,readData, paramLst);
}
}
printf("read thread exit...\n") ;
//printf("read thread exit...\n") ;
});
std::thread write([this, &stream, cinfo] {
@ -118,6 +120,7 @@ Status StreamServer::AllStream(ServerContext* context, grpc::ServerReaderWriter<
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
//printf("write thread exit...\n");
});
read.join();
@ -136,21 +139,6 @@ void StreamServer::Init() {
void StreamServer::Run() {
Stop();
//检测下线线程
m_checkQuitFlag = false;
m_checkCloseTd = std::thread([this] {
while (!m_checkQuitFlag) {
ClientWrapper::Instance()->OfflineCheck();
int count = 10;
while (count-- && !m_checkQuitFlag) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
});
//监听线程
m_listenTd = std::thread([this] {
std::string server_address("0.0.0.0:" + std::to_string(m_port));
@ -175,9 +163,5 @@ void StreamServer::Stop() {
m_listenTd.join();
}
m_checkQuitFlag = true;
if (m_checkCloseTd.joinable())
m_checkCloseTd.join();
}

View File

@ -41,8 +41,6 @@ private:
::grpc::Status Simple(::grpc::ServerContext* context, const ::stream::RequestInfo* request, ::stream::ResponseAny* response);
private:
std::thread m_checkCloseTd; //检测客户端关闭线程
bool m_checkQuitFlag;
DataCallBack m_dataCallBack;
FuncDataCallBack m_funcDataCallBack;

View File

@ -638,7 +638,7 @@ void Machine::ArmAxisMove(AxisConfig::ActiveDirect adr, bool isContinue, bool is
//轴运动函数
void Machine::CallAxisFunc(const ReadData& msg) {
MACHINEFUNC func = (MACHINEFUNC)stoi(msg.nameKey);
MACHINEFUNC func = (MACHINEFUNC)ConverType::TryToI(msg.nameKey);
switch (func) {
case LOADIN:
LoadIn();

View File

@ -247,6 +247,7 @@
<ClCompile Include="Config\dao\SystemBaseDao.cpp" />
<ClCompile Include="Config\dao\TimePowerCompensateDao.cpp" />
<ClCompile Include="Controller\Controller.cpp" />
<ClCompile Include="Controller\FileDialog.cpp" />
<ClCompile Include="Controller\UIBean.h" />
<ClCompile Include="DataManage\ClientInfo.cpp" />
<ClCompile Include="DataManage\DataHandle.cpp" />
@ -481,6 +482,7 @@
<ClInclude Include="Config\dao\TimePowerCompensateDao.h" />
<ClInclude Include="Controller\Base.h" />
<ClInclude Include="Controller\Controller.h" />
<ClInclude Include="Controller\FileDialog.h" />
<ClInclude Include="DataManage\ClientInfo.h" />
<ClInclude Include="DataManage\DataHandle.h" />
<ClInclude Include="DataManage\RWData.h" />

View File

@ -756,6 +756,9 @@
<ClCompile Include="Communication\PowderCarClient.cpp">
<Filter>Communication</Filter>
</ClCompile>
<ClCompile Include="Controller\FileDialog.cpp">
<Filter>Controller</Filter>
</ClCompile>
<ClCompile Include="protobuf\stream.grpc.pb.cc">
<Filter>protobuf</Filter>
</ClCompile>
@ -1891,6 +1894,9 @@
<ClInclude Include="Communication\PowderCarClient.h">
<Filter>Communication</Filter>
</ClInclude>
<ClInclude Include="Controller\FileDialog.h">
<Filter>Controller</Filter>
</ClInclude>
<ClInclude Include="protobuf\stream.grpc.pb.h">
<Filter>protobuf</Filter>
</ClInclude>

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -131,9 +131,19 @@ message ImgInfoResponce{
int32 height = 3;
}
// IOVersionStr接口返回值
// IOVersionStr接口
message ComResponce{
bytes data = 1;
bytes directory = 2;
message FileInfoStruct
{
bytes type = 1; //
bytes filePath = 2;
bytes fileName = 3;
bytes ext = 4; //
}
repeated FileInfoStruct fileInfo = 3;
}
//ScannerCrtlCfg结构体

View File

@ -28,4 +28,7 @@ SendToClients 需要修改
size_t scsize = ConfigManager::GetInstance()->GetMatchScannerControlCfg()->size();为啥是0
配置中文在本地是乱码
配置中文u8在本地是乱码
ScannerControlCfg 函数后面在添加

View File

@ -46,6 +46,8 @@ void DataHandle::Init() {
m_streamClient->SetCallBackFunc(this,&DataHandle::DataCallBackProc);
m_streamClient->Init();
m_funcTest.SetStreamClient(m_streamClient);
//stream::ResponseInfo* response = new stream::ResponseInfo(); //获取一层图层的数据
//m_streamClient->GetLayerByIndex(1, response);
@ -54,7 +56,7 @@ void DataHandle::Init() {
}
void DataHandle::Stop() {
m_streamClient->Stop();
if(m_streamClient) m_streamClient->Stop();
DELP(m_streamClient);
}
@ -130,15 +132,16 @@ void DataHandle::DataCallBackHandle(const ReadData& 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);
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);
printf(" 6: " COLOR_YELLOW "test camera interface...\n" COLOR_RESET);
printf(" 7: " COLOR_YELLOW "test purifier interface...\n" COLOR_RESET);
printf(" 8: " COLOR_YELLOW "test config interface...\n" COLOR_RESET);
printf(" h: " COLOR_YELLOW "print help information...\n" COLOR_RESET);
printf(" e: " COLOR_YELLOW "exit program...\n" COLOR_RESET);
printf(" 1: " COLOR_YELLOW "test all...\n" COLOR_RESET);
printf(" 2: " COLOR_YELLOW "test axis move interface...\n" COLOR_RESET);
printf(" 3: " COLOR_YELLOW "test scan control interface...\n" COLOR_RESET);
printf(" 4: " COLOR_YELLOW "test registration interface...\n" COLOR_RESET);
printf(" 5: " COLOR_YELLOW "test camera interface...\n" COLOR_RESET);
printf(" 6: " COLOR_YELLOW "test purifier interface...\n" COLOR_RESET);
printf(" 7: " COLOR_YELLOW "test config interface...\n" COLOR_RESET);
printf(" 8: " COLOR_YELLOW "test directory interface...\n" COLOR_RESET);
printf(" 100: " COLOR_YELLOW "start test recv param interface...\n" COLOR_RESET);
}
@ -208,24 +211,22 @@ int DataHandle::Request(int index) {
string userInput;
switch (index) {
case 0:
Usage(); break;
case 1:
Stop(); break;
m_funcTest.AllTest(); break;
case 2:
AllTest(); break;
m_funcTest.AxisMoveTest(); break;
case 3:
AxisMoveTest(); break;
m_funcTest.ScanCtrlTest(); break;
case 4:
ScanCtrlTest(); break;
m_funcTest.RegistrationTest(); break;
case 5:
RegistrationTest(); break;
m_funcTest.CameraTest(); break;
case 6:
CameraTest(); break;
m_funcTest.PurifierTest(); break;
case 7:
PurifierTest(); break;
m_funcTest.ConfigTest(); break;
case 8:
ConfigTest(); break;
m_funcTest.DirectoryTest(); break;
case 100:
ParamReadUsage();
while (printf("*请输入命令:") && std::getline(std::cin, userInput)) {
@ -238,8 +239,8 @@ int DataHandle::Request(int index) {
else if (userInput == "h") { //打印用法
ParamReadUsage();
}
else if (userInput.find("push") != string::npos) { //更新数据到服务器
UpdateParamToService(userInput);
else if (userInput.find("update") != string::npos) { //更新数据到服务器
UpdateParamToServer(userInput);
}
else { //接收指定的参数
ReceiveParam(ConverType::TryToI(userInput));
@ -254,15 +255,6 @@ int DataHandle::Request(int index) {
return result;
}
void DataHandle::AllTest() {
AxisMoveTest();
ScanCtrlTest();
RegistrationTest();
CameraTest();
PurifierTest();
ConfigTest();
}
void DataHandle::ReceiveParam(int index) {
if (index == VERSIONRSP) {
@ -281,7 +273,7 @@ void DataHandle::ReceiveParam(int index) {
index = -1;
}
else if (index >= PARAMLIMITCFGPARAM && index <= ELECFGPARAM) {
PushMsg(REQUEST);
PushMsg(REQUEST);
}
else if(index == LOADPARAMRSP){
PushMsg(LOADPARAM);
@ -360,9 +352,9 @@ void DataHandle::PrintScanerCfg(const stream::ScannerCrtlCfgResp& result) {
}
//选择一个参数更新到服务
void DataHandle::UpdateParamToService(const string& input) {
void DataHandle::UpdateParamToServer(const string& input) {
WriteData writeData;
int index = ConverType::TryToI(input.substr(5));
int index = ConverType::TryToI(input.substr(7));
switch (index) {
case PARAMLIMITCFGPARAM:
break;
@ -431,189 +423,3 @@ void DataHandle::UpdateParamToService(const string& input) {
}
//轴运动测试
void DataHandle::AxisMoveTest() {
int count =(int)MACHINEFUNC::END0;
for (int i = 0; i < count; ++i) {
PushMsg(WRITETYPE::AXISMOVEFUNC,to_string(i));
printf("发送请求%d成功...\n", i);
Sleep(100);
}
}
//扫描控制测试
void DataHandle::ScanCtrlTest() {
PushMsg(SCANCTRLFUNC, to_string(BEGINWORK)); printf("call BEGINWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(PAUSEWORK)); printf("call PAUSEWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(PAUSEAUTO)); printf("call PAUSEAUTO function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPWORK)); printf("call STOPWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPREDTEST)); printf("call STOPREDTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(TESTLAYER)); printf("call TESTLAYER function...\n");
PushMsg(SCANCTRLFUNC, to_string(REMOVESCANNER), to_string(1), iINT); printf("call REMOVESCANNER function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTHEATINGMOTION)); printf("call STARTHEATINGMOTION function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPHEATINGMOTION), to_string(0), iBOOL); printf("call STOPHEATINGMOTION function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTDEBUGTEST), "1", iINT); printf("call STARTDEBUGTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPDEBUGTEST), "1", iINT); printf("call STOPDEBUGTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTHEATINGSCANNERTEST), "1", iINT); printf("call STARTHEATINGSCANNERTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPHEATINGSCANNERTEST), "1", iINT); printf("call STOPHEATINGSCANNERTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTGETSCANINFO), "1", iINT); printf("call STARTGETSCANINFO function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPGETSCANINFO), "1", iINT); printf("call STOPGETSCANINFO function...\n");
WriteData wd{ SCANCTRLFUNC,to_string(SETXYOFFSET) ,"1", iINT };
wd.items.emplace_back(Item{"x", to_string(1.23f),iFLOAT});
wd.items.emplace_back(Item{"y", to_string(2.23f),iFLOAT});
PushMsg(wd); printf("call SETXYOFFSET function...\n");
wd.items.clear();
wd.nameKey = to_string(SETANGLE);
wd.items.emplace_back(Item{ "angle", to_string(1.2),iDOUBLE });
PushMsg(wd); printf("call SETANGLE function...\n");
PushMsg(SCANCTRLFUNC, to_string(UPDATESETTING), "1", iINT); printf("call UPDATESETTING function...\n");
wd.items.clear();
wd.nameKey = to_string(UPDATESKYWRITING);
wd.items.emplace_back(Item{ "isList", to_string(true),iBOOL });
PushMsg(wd); printf("call UPDATESKYWRITING function...\n");
wd.items.clear();
wd.nameKey = to_string(SETXYCORRECT);
wd.items.emplace_back(Item{ "x", to_string(2.3),iDOUBLE });
wd.items.emplace_back(Item{ "y", to_string(3.4),iDOUBLE });
PushMsg(wd); printf("call SETXYCORRECT function...\n");
wd.items.clear();
wd.nameKey = to_string(SETK);
wd.items.emplace_back(Item{ "k", to_string(2.1),iDOUBLE });
PushMsg(wd); printf("call SETK function...\n");
wd.items.clear();
wd.nameKey = to_string(FIXPOINTDAOADD);
wd.items.emplace_back(Item{ "cno", to_string(2),iINT });
wd.items.emplace_back(Item{ "pointX", to_string(2.1),iFLOAT });
wd.items.emplace_back(Item{ "pointY", to_string(2.1),iFLOAT });
wd.items.emplace_back(Item{ "duration", to_string(5),iUINT });
PushMsg(wd); printf("call FIXPOINTDAOADD function...\n");
wd.items.clear();
wd.nameKey = to_string(FIXPOINTDAODEL);
wd.items.emplace_back(Item{ "id", to_string(2),iINT });
PushMsg(wd); printf("call FIXPOINTDAODEL function...\n");
}
void DataHandle::RegistrationTest(){
::stream::ResponseAny resp;
stream::RegResponce result;
WriteData wdata{ REGISTFUNC ,to_string(CHECKREG),to_string(time(nullptr)) ,iSTRING };
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());
}
}
void DataHandle::CameraTest() {
int count = (int)CAMERAFUNC::END2;
for (int i = 0; i < count; ++i) {
if (i == GETSHOWIMAGE || i == GETSHOWIMAGES) continue;
if(i == SETDEMANDCATPURE) PushMsg(CAMERAFUNC, to_string(i),to_string(1),iBOOL);
else PushMsg(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);
//修改参数
PushMsg(CAMERAPARAMUPDATE,"LastMouRefImgPosX", to_string(10),iINT);
PushMsg(CAMERAPARAMUPDATE,"LastMouRefImgPosY", to_string(100),iINT);
PushMsg(CAMERAPARAMUPDATE,"ShowFlag", to_string(1),iBOOL);
printf("CAMERAPARAMUPDATE update finish\n");
}
void DataHandle::PurifierTest() {
PushMsg(PURIFIERFUNC, to_string(STARTAUTODEOXYGEN));
printf("STARTAUTODEOXYGEN is called...\n");
PushMsg(PURIFIERFUNC, to_string(STOPAUTODEOXYGEN));
printf("STOPAUTODEOXYGEN is called...\n");
}
void DataHandle::ConfigTest() {
PushMsg(CONFIGFUNC, to_string(SAVECONFIG));
printf("saveconfig is called...\n");
PushMsg(CONFIGFUNC, to_string(SAVEMACHINECONFIG));
printf("savemachineconfig is called...\n");
PushMsg(CONFIGFUNC, to_string(DELETEMACHINEIO));
printf("deletemachineio is called...\n");
WriteData wd{ CONFIGFUNC, to_string(CONTROLRUN) };
wd.items.emplace_back(Item{ "enable", to_string(true) ,iBOOL });
wd.items.emplace_back(Item{ "code", "usp" ,iSTRING });
PushMsg(wd);
printf("controlrun is called...\n");
::stream::ResponseAny resp;
stream::ComResponce result;
WriteData wdata{ CONFIGFUNC ,to_string(IOVERSIONSTR) };
wdata.items.emplace_back(Item{"index","1",iINT});
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ComResponce>()) {
resp.data().UnpackTo(&result);
printf("IOVERSIONSTR resp:%s\n", result.data().data());
}
PushMsg(CONFIGFUNC, to_string(REDTESTCFGSTART));
printf("redtestcfgstart is called...\n");
PushMsg(CONFIGFUNC, to_string(REDTESTCFGSTOP));
printf("redtestcfgstop is called...\n");
}

View File

@ -2,6 +2,7 @@
#include <string>
#include "StreamClient.h"
#include <map>
#include "FuncTest.h"
using namespace std;
@ -11,30 +12,18 @@ class DataHandle{
public:
DataHandle();
virtual ~DataHandle();
DataHandle(const DataHandle& d) = delete;
DataHandle& operator = (const DataHandle& d) = delete;
void Init();
void Stop();
static void DataCallBackProc(void* pthis, const ReadData& msg);
void PushMsg(WRITETYPE dataType, const string& nameKey = "", const string& strValue = "", DATATYPE valueType = UNKNOW, DATAHANDLE handleType = UPDATE);
void PushMsg(const WriteData& wd);
string GetVersion()const {return m_version;}
void ReceiveParam(int index);
int Request(int index);
void AllTest();
void AxisMoveTest(); //轴运动测试
void ScanCtrlTest(); //扫描控制测试
void RegistrationTest(); //注册功能测试
void CameraTest(); //相机功能测试
void PurifierTest(); //净化器功能测试
void ConfigTest(); //配置功能测试
void UpdateParamToService(const string& input);
void UpdateParamToServer(const string& input);
void Usage();
void ParamReadUsage();
@ -42,6 +31,9 @@ public:
int GetPrintParam() const {return m_printIndex;}
private:
void PushMsg(WRITETYPE dataType, const string& nameKey = "", const string& strValue = "", DATATYPE valueType = UNKNOW, DATAHANDLE handleType = UPDATE);
void PushMsg(const WriteData& wd);
void DataCallBackHandle(const ReadData& msg);
void PrintValue(const ReadData& msg);
void PrintScanerCfg(const stream::ScannerCrtlCfgResp& result); //打印config的特殊配置
@ -53,4 +45,6 @@ private:
int m_printIndex; //命令编号
map<int, string> m_dataTypeMp;
FuncTest m_funcTest;
};

View File

@ -125,4 +125,11 @@ enum SCCFGP {
TIMEPOWERCOMPENSATECFG,
};
enum CALLFUNC {
GetLogicalDrive = 0,
ScanDir,
};
#define OUTPUTNAME(x) #x

View File

@ -0,0 +1,239 @@
#include "FuncTest.h"
void FuncTest::PushMsg(WRITETYPE dataType, const string& nameKey, const std::string& strValue, DATATYPE valueType, DATAHANDLE handleType) {
if (m_streamClient) {
WriteData msg;
msg.dataType = dataType;
msg.nameKey = nameKey;
msg.strValue = strValue;
msg.valueType = valueType;
msg.handleType = handleType;
m_streamClient->PushMsg(msg);
}
}
void FuncTest::PushMsg(const WriteData& wd) {
if (m_streamClient) {
m_streamClient->PushMsg(wd);
}
}
void FuncTest::AllTest() {
AxisMoveTest();
ScanCtrlTest();
RegistrationTest();
CameraTest();
PurifierTest();
ConfigTest();
DirectoryTest();
}
//轴运动测试
void FuncTest::AxisMoveTest() {
int count = (int)MACHINEFUNC::END0;
for (int i = 0; i < count; ++i) {
PushMsg(WRITETYPE::AXISMOVEFUNC, to_string(i));
printf("发送请求%d成功...\n", i);
Sleep(100);
}
}
//扫描控制测试
void FuncTest::ScanCtrlTest() {
PushMsg(SCANCTRLFUNC, to_string(BEGINWORK)); printf("call BEGINWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(PAUSEWORK)); printf("call PAUSEWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(PAUSEAUTO)); printf("call PAUSEAUTO function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPWORK)); printf("call STOPWORK function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPREDTEST)); printf("call STOPREDTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(TESTLAYER)); printf("call TESTLAYER function...\n");
PushMsg(SCANCTRLFUNC, to_string(REMOVESCANNER), to_string(1), iINT); printf("call REMOVESCANNER function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTHEATINGMOTION)); printf("call STARTHEATINGMOTION function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPHEATINGMOTION), to_string(0), iBOOL); printf("call STOPHEATINGMOTION function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTDEBUGTEST), "1", iINT); printf("call STARTDEBUGTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPDEBUGTEST), "1", iINT); printf("call STOPDEBUGTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTHEATINGSCANNERTEST), "1", iINT); printf("call STARTHEATINGSCANNERTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPHEATINGSCANNERTEST), "1", iINT); printf("call STOPHEATINGSCANNERTEST function...\n");
PushMsg(SCANCTRLFUNC, to_string(STARTGETSCANINFO), "1", iINT); printf("call STARTGETSCANINFO function...\n");
PushMsg(SCANCTRLFUNC, to_string(STOPGETSCANINFO), "1", iINT); printf("call STOPGETSCANINFO function...\n");
WriteData wd{ SCANCTRLFUNC,to_string(SETXYOFFSET) ,"1", iINT };
wd.items.emplace_back(Item{ "x", to_string(1.23f),iFLOAT });
wd.items.emplace_back(Item{ "y", to_string(2.23f),iFLOAT });
PushMsg(wd); printf("call SETXYOFFSET function...\n");
wd.items.clear();
wd.nameKey = to_string(SETANGLE);
wd.items.emplace_back(Item{ "angle", to_string(1.2),iDOUBLE });
PushMsg(wd); printf("call SETANGLE function...\n");
PushMsg(SCANCTRLFUNC, to_string(UPDATESETTING), "1", iINT); printf("call UPDATESETTING function...\n");
wd.items.clear();
wd.nameKey = to_string(UPDATESKYWRITING);
wd.items.emplace_back(Item{ "isList", to_string(true),iBOOL });
PushMsg(wd); printf("call UPDATESKYWRITING function...\n");
wd.items.clear();
wd.nameKey = to_string(SETXYCORRECT);
wd.items.emplace_back(Item{ "x", to_string(2.3),iDOUBLE });
wd.items.emplace_back(Item{ "y", to_string(3.4),iDOUBLE });
PushMsg(wd); printf("call SETXYCORRECT function...\n");
wd.items.clear();
wd.nameKey = to_string(SETK);
wd.items.emplace_back(Item{ "k", to_string(2.1),iDOUBLE });
PushMsg(wd); printf("call SETK function...\n");
wd.items.clear();
wd.nameKey = to_string(FIXPOINTDAOADD);
wd.items.emplace_back(Item{ "cno", to_string(2),iINT });
wd.items.emplace_back(Item{ "pointX", to_string(2.1),iFLOAT });
wd.items.emplace_back(Item{ "pointY", to_string(2.1),iFLOAT });
wd.items.emplace_back(Item{ "duration", to_string(5),iUINT });
PushMsg(wd); printf("call FIXPOINTDAOADD function...\n");
wd.items.clear();
wd.nameKey = to_string(FIXPOINTDAODEL);
wd.items.emplace_back(Item{ "id", to_string(2),iINT });
PushMsg(wd); printf("call FIXPOINTDAODEL function...\n");
}
void FuncTest::RegistrationTest() {
::stream::ResponseAny resp;
stream::RegResponce result;
WriteData wdata{ REGISTFUNC ,to_string(CHECKREG),to_string(time(nullptr)) ,iSTRING };
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());
}
}
void FuncTest::CameraTest() {
int count = (int)CAMERAFUNC::END2;
for (int i = 0; i < count; ++i) {
if (i == GETSHOWIMAGE || i == GETSHOWIMAGES) continue;
if (i == SETDEMANDCATPURE) PushMsg(CAMERAFUNC, to_string(i), to_string(1), iBOOL);
else PushMsg(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);
//修改参数
PushMsg(CAMERAPARAMUPDATE, "LastMouRefImgPosX", to_string(10), iINT);
PushMsg(CAMERAPARAMUPDATE, "LastMouRefImgPosY", to_string(100), iINT);
PushMsg(CAMERAPARAMUPDATE, "ShowFlag", to_string(1), iBOOL);
printf("CAMERAPARAMUPDATE update finish\n");
}
void FuncTest::PurifierTest() {
PushMsg(PURIFIERFUNC, to_string(STARTAUTODEOXYGEN));
printf("STARTAUTODEOXYGEN is called...\n");
PushMsg(PURIFIERFUNC, to_string(STOPAUTODEOXYGEN));
printf("STOPAUTODEOXYGEN is called...\n");
}
void FuncTest::ConfigTest() {
PushMsg(CONFIGFUNC, to_string(SAVECONFIG));
printf("saveconfig is called...\n");
PushMsg(CONFIGFUNC, to_string(SAVEMACHINECONFIG));
printf("savemachineconfig is called...\n");
PushMsg(CONFIGFUNC, to_string(DELETEMACHINEIO));
printf("deletemachineio is called...\n");
WriteData wd{ CONFIGFUNC, to_string(CONTROLRUN) };
wd.items.emplace_back(Item{ "enable", to_string(true) ,iBOOL });
wd.items.emplace_back(Item{ "code", "usp" ,iSTRING });
PushMsg(wd);
printf("controlrun is called...\n");
::stream::ResponseAny resp;
stream::ComResponce result;
WriteData wdata{ CONFIGFUNC ,to_string(IOVERSIONSTR) };
wdata.items.emplace_back(Item{ "index","1",iINT });
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ComResponce>()) {
resp.data().UnpackTo(&result);
printf("IOVERSIONSTR resp:%s\n", result.data().data());
}
PushMsg(CONFIGFUNC, to_string(REDTESTCFGSTART));
printf("redtestcfgstart is called...\n");
PushMsg(CONFIGFUNC, to_string(REDTESTCFGSTOP));
printf("redtestcfgstop is called...\n");
}
void FuncTest::DirectoryTest() {
::stream::ResponseAny resp;
stream::ComResponce result;
WriteData wdata{ DIRCTROYFUNC ,to_string(GetLogicalDrive) };
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ComResponce>()) {
resp.data().UnpackTo(&result);
printf("GetLogicalDrive resp:%s\n", result.data().data());
}
Sleep(100);
wdata = WriteData{ DIRCTROYFUNC ,to_string(ScanDir),"C://" };
m_streamClient->Request(wdata, &resp);
if (resp.data().Is<stream::ComResponce>()) {
resp.data().UnpackTo(&result);
printf("ScanDir directory:%s\n", result.directory().data());
for (auto& it : result.fileinfo()) {
printf("ScanDir fileinfo type:%s,filename:%s,filepath:%s,ext:%s\n"
, it.type().data(), it.filename().data(), it.filepath().data(), it.ext().data());
}
printf("size:%d\n",result.fileinfo_size());
}
}

View File

@ -0,0 +1,32 @@
#pragma once
#include "FunC.h"
#include "RWData.h"
#include "StreamClient.h"
using namespace std;
class FuncTest {
public:
FuncTest() :m_streamClient(nullptr){}
~FuncTest() {}
void SetStreamClient(StreamClient* sc) {
m_streamClient = sc;
}
void AllTest();
void AxisMoveTest(); //轴运动测试
void ScanCtrlTest(); //扫描控制测试
void RegistrationTest(); //注册功能测试
void CameraTest(); //相机功能测试
void PurifierTest(); //净化器功能测试
void ConfigTest(); //配置功能测试
void DirectoryTest(); //h3d文件目录接口测试
private:
void PushMsg(WRITETYPE dataType, const string& nameKey = "", const string& strValue = "", DATATYPE valueType = UNKNOW, DATAHANDLE handleType = UPDATE);
void PushMsg(const WriteData& wd);
private:
StreamClient* m_streamClient;
};

View File

@ -128,6 +128,7 @@ enum WRITETYPE {
CAMERAPARAMUPDATE, //相机参数更新
PURIFIERFUNC, //净化器接口功能
CONFIGFUNC, //config functions
DIRCTROYFUNC, //请求目录信息
SETZEROPOS, //AxisState使用
AXISSTOPALL, //axis 运动急停
@ -149,6 +150,7 @@ enum WRITETYPE {
SCANERCTRLCFG,
LOADPARAM, //装载参数
SCANCTRLFUNC, //振镜控制函数
REQUEST = 100, //获取配置信息 test用

22
TestClient/FuncTest.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "FuncTest.h"
#include "FunC.h"
#include "../utils/ConverType.h"
#include "../utils/StringHelper.h"
void FuncTest::PushMsg(WRITETYPE dataType, const string& nameKey, const string& strValue, DATATYPE valueType, DATAHANDLE handleType) {
if (m_streamClient) {
WriteData msg;
msg.dataType = dataType;
msg.nameKey = nameKey;
msg.strValue = strValue;
msg.valueType = valueType;
msg.handleType = handleType;
m_streamClient->PushMsg(msg);
}
}
void FuncTest::PushMsg(const WriteData& wd) {
if (m_streamClient) {
m_streamClient->PushMsg(wd);
}
}

16
TestClient/FuncTest.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "FunC.h"
class FuncTest {
public:
FuncTest();
~FuncTest();
private:
void PushMsg(WRITETYPE dataType, const string& nameKey, const string& strValue, DATATYPE valueType, DATAHANDLE handleType);
void PushMsg(const WriteData& wd);
};

View File

@ -142,6 +142,7 @@
<ClCompile Include="ChartletManager.cpp" />
<ClCompile Include="config\bean\HbdLanguage.cpp" />
<ClCompile Include="DataManage\DataHandle.cpp" />
<ClCompile Include="DataManage\FuncTest.cpp" />
<ClCompile Include="DataManage\StreamClient.cpp" />
<ClCompile Include="external\i18n\Entry.cpp" />
<ClCompile Include="external\i18n\I18nUtils.cpp" />
@ -211,6 +212,7 @@
<ClInclude Include="config\bean\HbdLanguage.h" />
<ClInclude Include="DataManage\DataHandle.h" />
<ClInclude Include="DataManage\FunC.h" />
<ClInclude Include="DataManage\FuncTest.h" />
<ClInclude Include="DataManage\RWData.h" />
<ClInclude Include="DataManage\StreamClient.h" />
<ClInclude Include="external\i18n\Entry.h" />

View File

@ -260,6 +260,9 @@
<ClCompile Include="protobuf\stream.pb.cc">
<Filter>protobuf</Filter>
</ClCompile>
<ClCompile Include="DataManage\FuncTest.cpp">
<Filter>DataManage</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="utils\LocalAddr.h">
@ -521,6 +524,9 @@
<ClInclude Include="protobuf\stream.pb.h">
<Filter>protobuf</Filter>
</ClInclude>
<ClInclude Include="DataManage\FuncTest.h">
<Filter>DataManage</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="protobuf\stream.proto">

View File

@ -76,12 +76,19 @@ int main(int argc, char** argv) {
std::getline(std::cin, userInput); // 读取用户输入
unknowCmd = false;
if (userInput.empty()) continue;
if(ConverType::TryToI(userInput)<0 || dataHandle->Request(stoi(userInput)) < 0){
else if (userInput == "h") {
dataHandle->Usage(); continue;
}
else if (userInput == "s") {
dataHandle->Stop();
}
else if (userInput == "e") {
dataHandle->Stop(); break;
}
else if(ConverType::TryToI(userInput)<0 || dataHandle->Request(stoi(userInput)) < 0){
printf("未识别的命令,请重新输入命令:");
unknowCmd = true;
}
}
DELP(dataHandle);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -49,14 +49,6 @@ message ParamInfo{
int32 endLayer = 9;
float powder = 10;
int32 seqNo = 11; //ScannerControlCfg使用
int32 controlNo = 12;
int32 serialNo = 13;
int32 controlType = 14;
bytes cardName = 15;
bytes cardIP = 16;
bool hadAssign = 17;
bool hadMatch = 18; //isEnable公用
}
message RequestInfo { //
@ -139,9 +131,19 @@ message ImgInfoResponce{
int32 height = 3;
}
// IOVersionStr接口返回值
// IOVersionStr接口
message ComResponce{
bytes data = 1;
bytes directory = 2;
message FileInfoStruct
{
bytes type = 1; //
bytes filePath = 2;
bytes fileName = 3;
bytes ext = 4; //
}
repeated FileInfoStruct fileInfo = 3;
}
//ScannerCrtlCfg结构体
@ -151,6 +153,7 @@ message ScannerCrtlCfgResp{
message ScannerCrtlCfgData{
int32 seqNo = 1;
repeated FixPointData fixPointData = 2;
ScanParamCfg scanParamCfg = 3;
ScanParamCfg hatchingParams = 4;
@ -312,3 +315,5 @@ service Stream {
rpc ClientStream (stream RequestInfo) returns (ResponseInfo) {} //
rpc AllStream (stream RequestInfo) returns (stream ResponseInfo) {} //
}