diff --git a/PrintC/Communication/BaseClient.cpp b/PrintC/Communication/BaseClient.cpp index cac7a79..fe7872d 100644 --- a/PrintC/Communication/BaseClient.cpp +++ b/PrintC/Communication/BaseClient.cpp @@ -139,6 +139,7 @@ void BaseClient::InsertMp(void* startPtr, size_t count, const string& suff) { void BaseClient::UpdateData(const ReadData& msg) { for (auto start = msg.its.begin(); start != msg.its.end(); ++start) { + if (m_baseMp.find(start->nameKey) == m_baseMp.end()) continue; if (start->valueType == iFLOAT) { float val = (float)atof(start->strValue.data()); m_baseMp[start->nameKey]->SetValue(val); diff --git a/PrintC/DataManage/DataHandle.cpp b/PrintC/DataManage/DataHandle.cpp index 8875ac8..d49aa18 100644 --- a/PrintC/DataManage/DataHandle.cpp +++ b/PrintC/DataManage/DataHandle.cpp @@ -28,6 +28,9 @@ void DataHandle::Init() { m_controller->Init(); SetPushMsg(VERSIONREQ); //获取版本信息 + + stream::ResponseInfo* response = new stream::ResponseInfo(); //获取一层图层的数据 + m_streamClient->GetLayerByIndex(1, response); } diff --git a/PrintC/DataManage/DataHandle.h b/PrintC/DataManage/DataHandle.h index 9dd6722..6351ce9 100644 --- a/PrintC/DataManage/DataHandle.h +++ b/PrintC/DataManage/DataHandle.h @@ -27,6 +27,7 @@ public: if (m_streamClient) { WriteData msg; msg.dataType = dataType; + msg.valueType = DATATYPE::UNKNOW; m_streamClient->SetPushMsg(msg); } } diff --git a/PrintC/DataManage/RWData.h b/PrintC/DataManage/RWData.h index b731989..8a8b1f1 100644 --- a/PrintC/DataManage/RWData.h +++ b/PrintC/DataManage/RWData.h @@ -18,9 +18,13 @@ enum READTYPE { INITERRORINFOSRSP, //返回初始化错误信息 VERSIONRSP, //返回版本信息 IOSIGNALRSP, //io信号返回数据 - SYSPARAMDATA, //系统参数数据 + SYSPARAMDATA, // LASERCHILLER, //冷水机参数 + UPSPARAM, //ups参数 + TEMPCTRLPARAM, //TempCtrl参数 + OXYGENPARAM, //测氧参数 + POWERMETERPARAM, // LASERPARAM1, //激光1参数 LASERPARAM2, //激光2参数 @@ -40,16 +44,11 @@ enum READTYPE { SIMPLESUPPLYPARAM_V22, //供应参数v2.2 PURIFIERPARAM, //冷水机参数 - POWERPARAM, // + POWERPARAM, //电能参数 CHILLERPARAM, //冷却器参数 - TEMPCTRLPARAM, //温控参数 - OXYGENPARAM, //测氧参数 POWDERSUPPLYSIMPLEPARAM, // - UPSPARAM, // - SCANNERPOWERPARAM, // - POWERMETERPARAM, // - + SCANNERPOWERPARAM, //ScannerPower 参数 }; diff --git a/PrintC/DataManage/StreamClient.cpp b/PrintC/DataManage/StreamClient.cpp index 9932ae0..9497b8f 100644 --- a/PrintC/DataManage/StreamClient.cpp +++ b/PrintC/DataManage/StreamClient.cpp @@ -20,13 +20,13 @@ StreamClient::~StreamClient() { if (m_connectTd.joinable()) { m_connectTd.join(); } - } void StreamClient::Init() { m_localIp = LocalAddr().GetSystemIpAddress(); std::string target_str = m_localIp +":"+ std::to_string(m_port); - m_stubTwo = Stream::NewStub(grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials())); + m_channelTwo = grpc::CreateChannel(target_str, grpc::InsecureChannelCredentials()); + m_stubTwo = Stream::NewStub(m_channelTwo); m_connectTd = std::thread([this]() { this->AllStream(); @@ -108,3 +108,16 @@ void StreamClient::AllStream() { } +bool StreamClient::GetLayerByIndex(int index, ::stream::ResponseInfo* response){ + // 初始化 gRPC + std::string targetStr = m_localIp + ":" + std::to_string(m_port); + std::unique_ptr _stub = Stream::NewStub(grpc::CreateChannel(targetStr, grpc::InsecureChannelCredentials())); + + ClientContext context; + ::stream::RequestInfo request; + request.set_datatype(LAYERDATAREQ); + request.set_strvalue(std::to_string(index)); + request.set_valuetype((stream::TYPE)iINT); + Status status = _stub->Simple(&context, request, response); + return status.ok(); +} \ No newline at end of file diff --git a/PrintC/DataManage/StreamClient.h b/PrintC/DataManage/StreamClient.h index 5301511..2ac5549 100644 --- a/PrintC/DataManage/StreamClient.h +++ b/PrintC/DataManage/StreamClient.h @@ -30,11 +30,14 @@ public: } void SetPushMsg(const WriteData& msg); + bool GetLayerByIndex(int index, ::stream::ResponseInfo* response); private: bool GetPushMsg(WriteData& msg); private: - std::unique_ptr m_stubTwo; + std::unique_ptr m_stubTwo; //双端流使用 + std::shared_ptr m_channelTwo; + std::unique_ptr m_stub; //请求 回复使用 std::string m_localIp; int m_port; //服务端口 DataCallBack m_dataCallBack; diff --git a/PrintC/Machine/Machine.h b/PrintC/Machine/Machine.h index 5f0fee9..afe2ec7 100644 --- a/PrintC/Machine/Machine.h +++ b/PrintC/Machine/Machine.h @@ -19,6 +19,9 @@ public: void Init(); + virtual void InitSignal(SignalStateWrapper* ssw, void* cc) = 0; + virtual void InitSysParam(SysParamWrapper* spw, void* cc) = 0; + void SetAxisAndSignal(SysParamWrapper* sysParamWrapper, AxisRecordWrapper* axisRecordWrapper/*, PLCAxis* axis*/) { m_SysParamWrapper = sysParamWrapper; diff --git a/PrintC/PLC/SysParam.cpp b/PrintC/PLC/SysParam.cpp index c4c7c24..d8857f9 100644 --- a/PrintC/PLC/SysParam.cpp +++ b/PrintC/PLC/SysParam.cpp @@ -11,7 +11,7 @@ SysParam::SysParam(int addr, int num, void* cc,const string& context, const std: , m_context(context) , m_code(code) { - InitializeCriticalSection(&m_ValueCS); + } SysParam::~SysParam() @@ -23,7 +23,6 @@ SysParam::~SysParam() } m_sysParamMp.clear(); - DeleteCriticalSection(&m_ValueCS); } SysParam::SysParam(SysParam* sp) /*:PLCCommand(sp->m_Receiver)*/ diff --git a/PrintC/PLC/SysParam.h b/PrintC/PLC/SysParam.h index 0e21b8c..4429517 100644 --- a/PrintC/PLC/SysParam.h +++ b/PrintC/PLC/SysParam.h @@ -20,6 +20,14 @@ public: int GetAddr() { return m_Addr; } string GetCode() { return m_code; } + static void SInit() { + InitializeCriticalSection(&m_ValueCS); + } + + static void SFini() { + DeleteCriticalSection(&m_ValueCS); + } + static void Lck() { EnterCriticalSection(&m_ValueCS); } diff --git a/PrintC/UI/Controller.cpp b/PrintC/UI/Controller.cpp index 5cf92bc..0c27047 100644 --- a/PrintC/UI/Controller.cpp +++ b/PrintC/UI/Controller.cpp @@ -28,17 +28,22 @@ Controller::~Controller() { DELP(m_Machine); DELP(m_MachineCfg); - + SysParam::SFini(); } bool Controller::Init() { + SysParam::SInit(); + m_StateCtrlWrapper = new StateCtrlWrapper(); m_SysParamWrapper = new SysParamWrapper(); m_AxisRecordWrapper = new AxisRecordWrapper(); m_SignalStateWrapper = new SignalStateWrapper(); ConfigManager::Instance()->Init(); m_Machine = ConfigManager::Instance()->GetMachine(); + m_Machine->InitSignal(m_SignalStateWrapper, nullptr); + m_Machine->InitSysParam(m_SysParamWrapper, nullptr); + m_Machine->SetAxisAndSignal(m_SysParamWrapper, m_AxisRecordWrapper); m_MachineCfg = ConfigManager::Instance()->GetMachineCfg(); diff --git a/PrintC/UI/UIWin.h b/PrintC/UI/UIWin.h index 9634e4d..379e4c0 100644 --- a/PrintC/UI/UIWin.h +++ b/PrintC/UI/UIWin.h @@ -91,5 +91,5 @@ private: bool m_IsShowInitError; string m_ProductVersion; - map* m_TextureMap ; + map* m_TextureMap; }; \ No newline at end of file diff --git a/PrintC/main.cpp b/PrintC/main.cpp index 1b4f4c5..2ff78f9 100644 --- a/PrintC/main.cpp +++ b/PrintC/main.cpp @@ -57,8 +57,6 @@ public: ChartletManager::GetInstance()->Init(); g_LngManager->Init(); - - DataHandle::Instance()->Init(); m_win = new UIWin(); diff --git a/PrintC/output/Release/log/2024.hbd b/PrintC/output/Release/log/2024.hbd index e9c05d6..605d17c 100644 Binary files a/PrintC/output/Release/log/2024.hbd and b/PrintC/output/Release/log/2024.hbd differ diff --git a/PrintS/Communication/S7Command.h b/PrintS/Communication/S7Command.h index 26cdce4..8a4d75a 100644 --- a/PrintS/Communication/S7Command.h +++ b/PrintS/Communication/S7Command.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "Command.h" #include "snap7/s7_micro_client.h" #include @@ -55,8 +55,10 @@ public: int GetRequestSequence(unsigned char* bseq){return 0;} bool Verify(unsigned char* rseq,int dlength){return true;} - TS7DataItem* getDataItems(){return m_dataItems;}; - unsigned int getItemCount(){return m_itemCount;}; + TS7DataItem* getDataItems(){ + return m_dataItems; + } + unsigned int getItemCount(){return m_itemCount;} public: //boost::function m_s7fun; diff --git a/PrintS/Controller/Controller.cpp b/PrintS/Controller/Controller.cpp index 064ed79..69abd1a 100644 --- a/PrintS/Controller/Controller.cpp +++ b/PrintS/Controller/Controller.cpp @@ -113,6 +113,7 @@ void Controller::Init(){ } m_Purifier->Init(); + m_jobController.StartLoadPrepareJob(); } diff --git a/PrintS/DataManage/ClientInfo.cpp b/PrintS/DataManage/ClientInfo.cpp index c39151a..cc86313 100644 --- a/PrintS/DataManage/ClientInfo.cpp +++ b/PrintS/DataManage/ClientInfo.cpp @@ -18,7 +18,8 @@ void ClientWrapper::OfflineCheck() { auto client = m_clientList.begin(); while (client != m_clientList.end()) { if (!(*client)->IsConnect()) { - printf("%s 下线了...\n", (*client)->m_clientAddr.c_str()); + size_t pos = (*client)->m_clientAddr.find_first_of(':'); + printf("\n%s 下线了...\n", (*client)->m_clientAddr.substr(pos + 1).c_str()); delete (*client); client = m_clientList.erase(client); } diff --git a/PrintS/DataManage/ClientInfo.h b/PrintS/DataManage/ClientInfo.h index 8245010..f283bff 100644 --- a/PrintS/DataManage/ClientInfo.h +++ b/PrintS/DataManage/ClientInfo.h @@ -28,6 +28,7 @@ public: auto lst = m_msgList.begin(); while (lst != m_msgList.end()) { delete (*lst); + ++lst; } m_msgList.clear(); } diff --git a/PrintS/DataManage/DataHandle.cpp b/PrintS/DataManage/DataHandle.cpp index 267b594..722e548 100644 --- a/PrintS/DataManage/DataHandle.cpp +++ b/PrintS/DataManage/DataHandle.cpp @@ -11,14 +11,16 @@ void DataHandle::DataCallBackProc(void* pthis, const ReadData& msg) { void DataHandle::LayersDataCallBackProc(void* pthis,const ReadData& msg, ::stream::LayerData** response) { DataHandle* p = (DataHandle*)pthis; int index = atoi(msg.strValue.data()); - int size = p->m_controller->m_jobController.GetJob()->GetMetaData()->GetLayersVec().size(); + + + int size = (int)p->m_controller->m_jobController.m_PrepareJob->GetMetaData()->GetLayersVec().size(); if (!p || index<1 || index>(int)size) return; - p->m_controller->m_jobController.GetJob()->GetMetaData()->GetLayerByIndex(index-1,response); + p->m_controller->m_jobController.m_PrepareJob->GetMetaData()->GetLayerByIndex(index-1,response); } DataHandle::DataHandle() - : m_dataCallBack(nullptr) - , m_streamServer(nullptr) + : /*m_dataCallBack(nullptr) + ,*/ m_streamServer(nullptr) , m_config(nullptr) , m_controller(nullptr) , m_testFlag(false){ diff --git a/PrintS/DataManage/DataHandle.h b/PrintS/DataManage/DataHandle.h index d544fea..17c1415 100644 --- a/PrintS/DataManage/DataHandle.h +++ b/PrintS/DataManage/DataHandle.h @@ -19,7 +19,7 @@ public: static void DataCallBackProc(void* pthis, const ReadData& msg); static void LayersDataCallBackProc(void* pthis, const ReadData& msg,::stream::LayerData** response); private: - DataCallBack m_dataCallBack; + //DataCallBack m_dataCallBack; std::thread m_testTd; ConfigManager* m_config; diff --git a/PrintS/DataManage/RWData.h b/PrintS/DataManage/RWData.h index eba8c2b..8926fdb 100644 --- a/PrintS/DataManage/RWData.h +++ b/PrintS/DataManage/RWData.h @@ -90,6 +90,7 @@ enum WRITETYPE { INITERRORINFOSRSP, //返回初始化错误信息 VERSIONRSP, //返回版本信息 + IOSIGNALRSP, //io信号返回数据 SYSPARAMDATA, // LASERCHILLER, //冷水机参数 UPSPARAM, //ups参数 @@ -115,8 +116,12 @@ enum WRITETYPE { SIMPLESUPPLYPARAM_V21, //供应参数v2.1 SIMPLESUPPLYPARAM_V22, //供应参数v2.2 - SCANNERPOWERPARAM, PURIFIERPARAM, //冷水机参数 + POWERPARAM, //电能参数 + CHILLERPARAM, //冷却器参数 + + POWDERSUPPLYSIMPLEPARAM, // + SCANNERPOWERPARAM, //ScannerPower 参数 }; diff --git a/PrintS/DataManage/StreamServer.cpp b/PrintS/DataManage/StreamServer.cpp index d9876b7..9faa60e 100644 --- a/PrintS/DataManage/StreamServer.cpp +++ b/PrintS/DataManage/StreamServer.cpp @@ -18,7 +18,7 @@ StreamServer::~StreamServer() { } -//回复后连接中断 +//回复后连接中断 请求打印文件层 ::grpc::Status StreamServer::Simple(::grpc::ServerContext* context, const ::stream::RequestInfo* request, ::stream::LayerData* response) { ReadData readData; @@ -41,7 +41,7 @@ Status StreamServer::AllStream(ServerContext* context, grpc::ServerReaderWriter< string addr = context->peer(); size_t pos = addr.find_first_of(':'); - printf("%s client login...\n", addr.substr(pos+1).c_str()); + printf("\n%s client login...\n", addr.substr(pos+1).c_str()); cinfo->m_clientAddr = context->peer(); cinfo->m_context = context; ClientWrapper::Instance()->AddClient(cinfo); diff --git a/PrintS/HBDSystem.cpp b/PrintS/HBDSystem.cpp index 9b798c9..db18539 100644 --- a/PrintS/HBDSystem.cpp +++ b/PrintS/HBDSystem.cpp @@ -55,7 +55,6 @@ void HBDSystem::GetVersion() string strVersion; ::GetModuleFileName(NULL, cPath, sizeof(cPath)); InfoSize = GetFileVersionInfoSize(cPath, &dwHandle); - printf("version:%d\n", GetLastError()); if (InfoSize == 0L) return; unsigned char* InfoBuf = new unsigned char[InfoSize]; GetFileVersionInfo(cPath, 0, InfoSize, InfoBuf); //获得生成文件使用的代码页及文件版本 @@ -86,10 +85,9 @@ void HBDSystem::GetVersion() void HBDSystem::Usage() { - printf("print service usage:\n"); - printf(" r(run):start run...\n"); - printf(" s(stop):stop run...\n"); - printf(" e(exit):exit program...\n"); - printf(" h(help):print this information...\n"); - + printf(COLOR_GREEN "print service usage:\n" COLOR_RESET); + printf(" r(run): " COLOR_YELLOW "start run...\n" COLOR_RESET); + printf(" s(stop): " COLOR_YELLOW "stop run...\n" COLOR_RESET); + printf(" e(exit): " COLOR_YELLOW "exit program...\n" COLOR_RESET); + printf(" h(help): " COLOR_YELLOW "print help information...\n" COLOR_RESET); } \ No newline at end of file diff --git a/PrintS/HBDSystem.h b/PrintS/HBDSystem.h index 0db10bd..c688b96 100644 --- a/PrintS/HBDSystem.h +++ b/PrintS/HBDSystem.h @@ -8,6 +8,10 @@ #include #include +// 假设你的系统支持ANSI颜色代码 +#define COLOR_RESET "\033[0m" +#define COLOR_GREEN "\033[32m" +#define COLOR_YELLOW "\033[33m" class HBDSystem { public: diff --git a/PrintS/PLC/SysParam.cpp b/PrintS/PLC/SysParam.cpp index aed1d74..5b1851b 100644 --- a/PrintS/PLC/SysParam.cpp +++ b/PrintS/PLC/SysParam.cpp @@ -129,7 +129,8 @@ void SysParamWord::SetValue(short value) { S7WordData sword; sword.wValue = value; - unsigned char* pv = (unsigned char*)m_CtrlCommand->getDataItems()[0].pdata; + TS7DataItem* gg = m_CtrlCommand->getDataItems(); + unsigned char* pv = (unsigned char*)gg[0].pdata; pv[0] = sword.data[1]; pv[1] = sword.data[0]; //short* pv =(short*) m_CtrlCommand->getDataItems()[0].pdata; @@ -215,7 +216,8 @@ void SysParamInt::SetValue(int value) { S7DWordData sdw; sdw.iValue = value; - unsigned char* pv = (unsigned char*)m_CtrlCommand->getDataItems()[0].pdata; + TS7DataItem* gg = m_CtrlCommand->getDataItems(); + unsigned char* pv = (unsigned char*)gg[0].pdata; pv[0] = sdw.data[3]; pv[1] = sdw.data[2]; pv[2] = sdw.data[1]; diff --git a/PrintS/job/H3DFileProcessor.h b/PrintS/job/H3DFileProcessor.h index 2b7a1f8..0b5c4ae 100644 --- a/PrintS/job/H3DFileProcessor.h +++ b/PrintS/job/H3DFileProcessor.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "FileProcessor.h" #include "H3DMetaData.h" @@ -11,7 +11,8 @@ public: int Process(string jobfile); int GetCurrentLayerIndex(void) { return GetLayerIndex(m_MetaData.GetCurrentLayer()); } int GetPreviewLayerIndex(void) { return GetLayerIndex(m_MetaData.GetPreviewLayer()); } - MetaData* GetMetaData() { return &m_MetaData; } + MetaData* GetMetaData() { + return &m_MetaData; } string GetJobTitle() { return m_MetaData.GetJobTitle(); } string GetMaterialName() { return m_MetaData.GetMaterial(); } double GetLayerThickness() { return *m_MetaData.GetLayerThickness(); } diff --git a/PrintS/job/H3DMetaData.cpp b/PrintS/job/H3DMetaData.cpp index 449d744..7da07ff 100644 --- a/PrintS/job/H3DMetaData.cpp +++ b/PrintS/job/H3DMetaData.cpp @@ -162,13 +162,13 @@ bool H3DMetaData::GetLayerByIndex(unsigned int lindex, ::stream::LayerData** res stream::LayerDataBlock* p = (*response)->add_layerdatablock(); p->set_order(datablocks[i]->order); - p->set_blocktype(m_block_map[datablocks[i]]->type); - size_t count = m_block_map[datablocks[i]]->point_indexs.size(); + p->set_blocktype(pbindb->type); + size_t count = pbindb->point_indexs.size(); for (size_t i = 0; i < count; ++i) { if (p->blocktype() == BIN_VECTOR) { stream::VectorDataBlock* pvec = p->add_vecblocks(); - BPBinary::VectorPoint* vecp = (BPBinary::VectorPoint*)(m_block_map[datablocks[i]]->point_indexs[i]); + BPBinary::VectorPoint* vecp = (BPBinary::VectorPoint*)(pbindb->point_indexs[i]); pvec->set_startx(vecp->x1); pvec->set_endx(vecp->y1); pvec->set_starty(vecp->x2); @@ -176,7 +176,7 @@ bool H3DMetaData::GetLayerByIndex(unsigned int lindex, ::stream::LayerData** res } else if (p->blocktype() == BIN_CHAIN) { stream::ChainDataBlock* pChain = p->add_chainblocks(); - BPBinary::ChainPoint* chainp = (BPBinary::ChainPoint*)(m_block_map[datablocks[i]]->point_indexs[i]); + BPBinary::ChainPoint* chainp = (BPBinary::ChainPoint*)(pbindb->point_indexs[i]); pChain->set_dotnum(chainp->num_of_point); for (unsigned int chainPointIndex = 0; chainPointIndex < chainp->num_of_point; ++chainPointIndex) { diff --git a/PrintS/job/JobController.cpp b/PrintS/job/JobController.cpp index be8bdcf..dfed2ef 100644 --- a/PrintS/job/JobController.cpp +++ b/PrintS/job/JobController.cpp @@ -40,8 +40,9 @@ void JobController::StartLoadPrepareJob() DWORD WINAPI JobController::LoadPrepareJobProc(JobController* _this) { if (!_this)return 0; char buffer[512]; - MachineCfg* mcfg = ConfigManager::GetInstance()->GetMachineCfg(); - sprintf_s(buffer, sizeof(buffer), "%sPrepareJob/%d.h3d", g_AppPath.c_str(), mcfg->m_MachineType); + //MachineCfg* mcfg = ConfigManager::GetInstance()->GetMachineCfg(); + //sprintf_s(buffer, sizeof(buffer), "%sPrepareJob/%d.h3d", g_AppPath.c_str(), mcfg->m_MachineType); + sprintf_s(buffer, sizeof(buffer), "D://jobfile//bigmodel_name.h3d"); H3DFileProcessor* fp = new H3DFileProcessor(); if (fp->Process(buffer) != BP_SUCCESS) { diff --git a/PrintS/job/JobController.h b/PrintS/job/JobController.h index ff8ef60..7e98288 100644 --- a/PrintS/job/JobController.h +++ b/PrintS/job/JobController.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "../stdafx.h" #include #include "JobFileProcessor.h" @@ -27,7 +27,8 @@ public: void RemoveJob(string job_title); void RemoveAllJob(); - FileProcessor* GetJob(void) { return m_CurrentJob; } + FileProcessor* GetJob(void) { + return m_CurrentJob; } FileProcessor* GetUnFinishedJob(); float GetLoadProgress(); string GetLoadInfo(); diff --git a/PrintS/output/Release/log/2024.hbd b/PrintS/output/Release/log/2024.hbd index 3474a9b..85fec11 100644 Binary files a/PrintS/output/Release/log/2024.hbd and b/PrintS/output/Release/log/2024.hbd differ