⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ksg_main.cpp

📁 对日本KSG震动探测仪器编写的伴侣服务代码
💻 CPP
字号:
// (Version 1.00 :: 10-Mar-1999 :: Harutoshi Yoshida)
/*===================================================================
	恔搙忣曬僱僢僩儚乕僋僔僗僥儉
	-----------------------------------
		Main Module
	-----------------------------------
	Program Name        : KSG_Main.CPP
	Program Start       : 14-Dec-1998
	Program Completed   : 
===================================================================*/

#include "stdafx.h"
#include "KSG.h"
#include "KSGDoc.h"
#include "KSGView.h"
#include "Dlg_Diag.h"
#include "C_Proc.h"
#include "C_File.h"
#include "C_ComProc.h"
#include "C_SeqProc.h"
#include "C_Work.h"
#include "KSG_File.h"

extern	HWND	MsgHdl;
extern	char	MsgBuff[2][128];

/*=====================================
						m:18-Dec-1998
@p	<< 僔僗僥儉弶婜壔 >>
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void sys_init()
{
	CC_File	pFile;

	// 28-Jan-1999 HY
	sprintf(Data_dir[BSE_DIR], "%s", DirSource[BSE_DIR]);		// 尦 DIR
	pFile.C_MakeDir(Data_dir[BSE_DIR]);

	sprintf(Data_dir[DIR_PDT], "%s%s", DirSource[BSE_DIR], DirSource[DIR_PDT]);		// 僷儔儊乕僞奿擺
	pFile.C_MakeDir(Data_dir[DIR_PDT]);

	sprintf(Data_dir[DIR_EDT], "%s%s", DirSource[BSE_DIR], DirSource[DIR_EDT]);		// 摨堦抧恔僨乕僞僼傽僀儖
	pFile.C_MakeDir(Data_dir[DIR_EDT]);

	sprintf(Data_dir[DIR_WDT], "%s%s", DirSource[BSE_DIR], DirSource[DIR_WDT]);		// 攇宍僨乕僞僼傽僀儖(BIN)
	pFile.C_MakeDir(Data_dir[DIR_WDT]);

	sprintf(Data_dir[DIR_CSV], "%s%s", DirSource[BSE_DIR], DirSource[DIR_CSV]);		// 攇宍僨乕僞僼傽僀儖(CSV)
	pFile.C_MakeDir(Data_dir[DIR_CSV]);

	sprintf(Data_dir[FLE_ENT], "%s%s", Data_dir[DIR_PDT], DirSource[FLE_ENT]);		// 娤應揰搊榐僨乕僞
	sprintf(Data_dir[FLE_SPR], "%s%s", Data_dir[DIR_PDT], DirSource[FLE_SPR]);		// 愝掕僷儔儊乕僞
	sprintf(Data_dir[FLE_RPR], "%s%s", Data_dir[DIR_PDT], DirSource[FLE_RPR]);		// 庴怣僷儔儊乕僞
	sprintf(Data_dir[FLE_LOG], "%s%s", Data_dir[DIR_PDT], DirSource[FLE_LOG]);		// 捠怣儘僌僼傽僀儖
	sprintf(Data_dir[FLE_STT], "%s%s", Data_dir[DIR_PDT], DirSource[FLE_STT]);		// 忬懺忣曬

	sprintf(Data_dir[FLE_INI], "%s%s", Data_dir[BSE_DIR], DirSource[FLE_INI]);		// 愝掕僼傽僀儖
	sprintf(Data_dir[FLE_EWV], "%s%s", Data_dir[BSE_DIR], DirSource[FLE_EWV]);		// 抧恔敪惗帪敪惡壒
	sprintf(Data_dir[FLE_SWV], "%s%s", Data_dir[BSE_DIR], DirSource[FLE_SWV]);		// 忬懺曄壔帪敪惡壒

	INI_file_read();							// 弶婜壔僼傽僀儖撉傒崬傒
}

/*=====================================
						m:11-Dec-1998
@p	<< Dialog Close >>
堷悢丗	n			Dialog No.
栠抣丗	側偟
=====================================*/
void	dialog_close(int n)
{
	if (Disp.Req == 0) {
		DspReqStack(DSP_MENU);
		Disp.Num = 0;
	}
	pOpenDlg = NULL;
}

/*=====================================
						m:22-Dec-1998
@p	<< 僄儔乕儊僢僙乕僕昞帵 >>
堷悢丗	msg				僄儔乕儊僢僙乕僕暥帤楍
栠抣丗	側偟
=====================================*/
void	err_disp(char *msg)
{
	User_work = 1;
	if (pOpenDlg != NULL) {
		// ver 1.30
		//pOpenDlg->MessageBox(msg, "僄儔乕儊僢僙乕僕", MB_OK | MB_ICONHAND);
		pOpenDlg->MessageBox(msg, "Error Message", MB_OK | MB_ICONHAND);
	}
	else {
		// ver 1.30
		//pKSGView->MessageBox(msg, "僄儔乕儊僢僙乕僕", MB_OK | MB_ICONHAND);
		pKSGView->MessageBox(msg, "Error Message", MB_OK | MB_ICONHAND);
	}
	User_work = 0;
}

/*=====================================
						m:23-Dec-1998
@p	<< 儚乕僯儞僌儊僢僙乕僕昞帵 >>
堷悢丗	msg				儚乕僯儞僌儊僢僙乕僕暥帤楍
栠抣丗	側偟
=====================================*/
void	war_disp(char *msg)
{
	User_work = 1;
	if (pOpenDlg != NULL) {
		// ver 1.30
		//pOpenDlg->MessageBox(msg, "儚乕僯儞僌儊僢僙乕僕", MB_OK | MB_ICONEXCLAMATION);
		pOpenDlg->MessageBox(msg, "Warning Message", MB_OK | MB_ICONEXCLAMATION);
	}
	else {
		// ver 1.30
		//pKSGView->MessageBox(msg, "儚乕僯儞僌儊僢僙乕僕", MB_OK | MB_ICONEXCLAMATION);
		pKSGView->MessageBox(msg, "Warning Message", MB_OK | MB_ICONEXCLAMATION);
	}
	User_work = 0;
}

/*=====================================
						m:22-Dec-1998
@p	<< 慖戰儊僢僙乕僕昞帵 >>
堷悢丗	msg			慖戰儊僢僙乕僕暥帤楍
		flg			昞帵套皋  [0]:慖戰  /  [1]:妋擣
栠抣丗	IDOK / IDCANCEL
=====================================*/
int	sel_disp(char *msg, int flg)
{
	int 	ret, icon;
	// ver 1.30
	//char	*msg_ttl[2] = { "慖戰儊僢僙乕僕" , "妋擣儊僢僙乕僕" };
	char	*msg_ttl[2] = { "慖戰Message" , "妋擣Message" };

	User_work = 1;
	if (flg == 0) {								// 慖戰儊僢僙乕僕
		icon = MB_OKCANCEL | MB_ICONQUESTION;
	}
	else {										// 妋擣儊僢僙乕僕
		icon = MB_OK | MB_ICONASTERISK;
	}
	if (pOpenDlg != NULL) {
		ret = pOpenDlg->MessageBox(msg, msg_ttl[flg], icon);
	}
	else {
		ret = pKSGView->MessageBox(msg, msg_ttl[flg], icon);
	}
	User_work = 0;
	return ret;
}

/*=====================================
						m:09-Dec-1998
@p	<< Dialog昞帵僞僗僋 >>
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	dialog_task()
{
	s_int phs = 0;

	if (Disp.Req != 0){
		switch (phs){
		case 0:		//-----( 尰嵼昞帵拞偺僟僀傾儘僌傪僋儘乕僘 )-----
			if (pOpenDlg != NULL){
				(pOpenDlg)->PostMessage(WM_CLOSE);
			}
			phs = 10;
			break;
		case 10:	//-----( Close Wait )-----
			if (pOpenDlg == NULL){
				pKSGView->PostMessage(WM_SWITCH_DIALOG, (WPARAM) Disp.Req, NULL);
				phs = 20;
			}
			break;
		case 20:	//-----( Open Wait )-----
			if (pOpenDlg != NULL){
				Disp.Num = Disp.Req;
				Disp.Req = 0;
				phs = 0;
			}
			break;
		}
	}
}

/*=====================================
						m:10-Dec-1998
@p	<< 報嶞僞僗僋 >>
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	print_task()
{
	switch (Print_req) {
	case DSP_MAP:	// No break;				// 抧恾夋柺		// ver 1.30
	case DSP_MAG:	// No break;				// 嵟怴丒恔搙堦棗昞帵
	case DSP_DIAG:	// No break;				// 攇宍僨乕僞丒僌儔僼昞帵
	case DSP_ENT:	// No break;				// 娤應揰搊榐堦棗
	case DSP_PAR:	// No break;				// 僷儔儊乕僞愝掕丒嶲徠
	case DSP_LGI:	// No break;				// 捠怣寢壥堦棗
	case DSP_LGS:								// 忬懺忣曬
		Print_num = Print_req;
		pKSGView->PostMessage(WM_PRINT_EXEC, NULL, NULL);
		Print_req = 0;
		break;
	}
}

/*=====================================
						m:14-Dec-1998
@p	<< 儅僢僾夋柺嫮惂昞帵僞僗僋 >>
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	map_active_task()
{
	s_int phs = 0, sv_cnt = 0;
	CWnd*		pMainWnd;
	CWnd*		pWnd;
//	int			wNT;
//	long		p;
	char *mes[] = {
			// ver 1.30
			//"抧恔敪惗偟傑偟偨両",
			//"忬懺僗僥乕僞僗偑峏怴偝傟傑偟偨丅"
			"抧恔敪惗両",
			"忬懺Status峏怴"
	};

	if (Map_Active && pOpenDlg != NULL){
		switch (phs){		//
		case 0:		//
			if (Disp.StkPoi == 0 && Disp.Req == 0){
				Disp.Enable = 0;
				phs = 10;
			}
			break;
		case 10:
			StopScreenSaver();							// 僗僋儕儞乕儞僙乕僶乕掆巭
			phs = 15;
			break;
		case 15:
			phs = 18;
			break;
		case 18:
			if (Plat_Form == 1) {					// NT?
				pKSGView->SetForegroundWindow();
			}
			else {
				pOpenDlg->SetForegroundWindow();
			}
			if (User_work == 1) {
				UwrkMesCls = 0;
				pKSGView->PostMessage(WM_DISP_MESS, (WPARAM) mes[Map_Active-1], NULL);
			}
			else{
				UwrkMesCls = 1;
			}
			phs = 20;
			break;
		case 20:
			if (UwrkMesCls){
				phs = 30;
			}
			break;

		case 30:
			pMainWnd = AfxGetMainWnd();
			pWnd = pKSGView->GetForegroundWindow();
			if (pWnd == NULL ||
				pWnd->m_hWnd == pMainWnd->m_hWnd ||
				pWnd->m_hWnd == pKSGView->m_hWnd ||
				pWnd->m_hWnd == pOpenDlg->m_hWnd){

				phs = 40;
			}
			else{
				pWnd->SendMessage(WM_CLOSE);
				::Sleep(1);
			}
			break;

		case 40:
			Map_Active = 0;
			Disp.Enable = 1;
			DspReqStack(DSP_MAP);
			phs = 0;
			break;
		}
	}
}

/*=====================================
						m:24-Jan-1999
@p	<< Dialog愗傝懼偊妋擣 >>
=====================================*/
void	dsp_stk_chk()
{
	if (Disp.StkPoi > 0 && Disp.Req == 0){
		Disp.Req = Disp.StkBuf[-- Disp.StkPoi];
	}
}

/*=====================================
						m:09-Dec-1998
@p	<< 儊僀儞僞僗僋 >>
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	main_task()
{
	int ch = 0, n_cnt = 0;
	clock_t	n_clk_e;
	clock_t	o_clk_e;
	clock_t	n_clock[MAX_CH];
	clock_t	o_clock[MAX_CH];
	CC_Seq pSeq;
	//struct S_DateTime dt;
	static	int	cnt = 0;
	//BOOL	bBool;

	while (MsgHdl == NULL){
		if (++ n_cnt > 250){
			n_cnt = 0;
			::Sleep(10);
		}
		// Dialog愗傝懼偊妋擣
		dsp_stk_chk();

		// Dialog昞帵
		if (Disp.Req){
			dialog_task();
			::Sleep(1);
		}
		// 報嶞
		if (Print_req){
			print_task();
			::Sleep(1);
		}

		// 抧恾夋柺嫮惂昞帵
		if (Map_Active){
			map_active_task();
			::Sleep(1);
		}
	}

	// 23-Jan:HY
	n_cnt = 0;
	n_clk_e = clock();			// clock timer end
	while (1){
		if (++ n_cnt > 300){
			n_cnt = 0;
			::Sleep(10);
		}

		// Dialog愗傝懼偊妋擣
		dsp_stk_chk();

		// Dialog昞帵
		if (Disp.Req){
			dialog_task();
			::Sleep(1);
		}
		// 報嶞
		if (Print_req){
			print_task();
			::Sleep(1);
		}

		// 抧恾夋柺嫮惂昞帵
		if (Map_Active){
			map_active_task();
			::Sleep(1);
		}

		// 捠怣僞僗僋張棟
		o_clock[ch] = n_clock[ch];
		n_clock[ch] = clock();			// clock timer end
		Rcw[ch].TimerC -= (n_clock[ch] - o_clock[ch]);

		if (Scw[ch].TimEnb){
			Scw[ch].TimerC -= (n_clock[ch] - o_clock[ch]);
		}

		Com_Main(ch);
		pSeq.Seq_Main(ch);

		// channel 峏怴
		if (++ ch >= MAX_CH){
			ch = 0;
			TskCnt ++;

			// 摨堦抧恔娔帇僞僀儅乕
			o_clk_e = n_clk_e;
			n_clk_e = clock();			// clock timer end
			if (E_quakeTimer <= ONE_PACK_TIME * 2){
				E_quakeTimer += (n_clk_e - o_clk_e);
			}
			// 10-Feb-1999
			if (HpcCtr.TimerC <= HPC_PACK_TIME * 2){
				HpcCtr.TimerC += (n_clk_e - o_clk_e);
			}

			// 05-Mar-1999
			if (DspDev.TimerC <= DISP_DEV_TIME * 2){
				DspDev.TimerC += (n_clk_e - o_clk_e);
			}

			#if DEMO_SEQ
				// 08-Mar-1999
				if (SeqDat.TimerC <= ONE_PACK_TIME * 2){
					SeqDat.TimerC += (n_clk_e - o_clk_e);
				}
			#endif
		}

		// ver 1.30
		// TCP/IP捠怣僞僗僋
		//if (TCP_send_req == 1){
		//	TCPIP_task();
		//	::Sleep(1);
		//	TCP_send_req = 0;
		//}
		//// 2001-11-27(MK@CQ)
		//switch (TCP_send_req2) {
		//case 1:
		//	cnt = 10;
		//	TCP_send_req2 = 10;
		//	// no break;
		//case 10:
		//	if (cnt) {
		//		bBool = pKSGView->TCPIP_task2();
		//		if (bBool == TRUE) {
		//			TCP_send_req2 = 50;
		//		}
		//		else {
		//			::Sleep(2000);
		//			cnt --;
		//		}
		//	}
		//	else {
		//		TCP_send_req2 = 50;
		//	}
		//	break;
		//case 50:
		//	TCP_send_req2 = 0;
		//	break;	
		//}
		//switch (Hpc_HealthPhs) {
		//case 0:
		//	StoNowTime(&dt);
		//	//if (dt.min == 0 && dt.sec == 0) {
		//	if ((dt.hor == 2 && dt.min == 0) || (dt.hor == 14 && dt.min == 0)) {
		//		pKSGView->TCPIP_task3();
		//		Hpc_HealthPhs = 10;
		//	}
		//	break;
		//case 10:
		//	StoNowTime(&dt);
		//	if (dt.min != 0) {
		//		Hpc_HealthPhs = 0;
		//	}
		//	break;
		//}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -