Example #1
0
/***************************************************************** 
 * GhP_TimeSched_Make(int nUnitCnt) 
 *  매 시간을 체크한다. 1분다 시스템 시간을 출력한다.  
 *  매분이 바뀔 때마다 g_MainMinuteFlag 값을 1로 설정한다. 
 */
void daegu_TimeSched_Make(int nUnitCnt)
{
	int i = 0;
    int j = 0;
    int nTempPno1 = 0;
    int nTempPno2 = 0;
    int nTempPno3 = 0;  
    int nTempPno4 = 0;    
   
    // Get group setting variable from ddc point table.
    nTempPno1 = 0;
    nTempPno2 = 0;
    nTempPno3 = 0;
    nTempPno4 = 0;
    
    // 그룹의 수는 10개, 그룹마다 시간설정의 갯수는 12개로 고정합니다. 
    // 대구대에서 설정이 바뀌었기 때문에 Hardcoding합니다. 21=> 그룹시작시간 / 22=> 그룹종료시간 / 23=> 그룹모드. 
	// 총 10개의 그룹을 사용.
	for (i = 0 ; i < 10; i++)  {
		// 각 그룹마다 최대 20개의 시간을 사용.
		for (j = 0; j < 20; j++) {
            GHP_PCM_Data.nSchedRun[i][j] = pGet(GHP_GROUP_DAY_START_PCM, nTempPno1);
            GHP_PCM_Data.nSchedStop[i][j] = pGet(GHP_GROUP_DAY_STOP_PCM, nTempPno2);
    
            GHP_PCM_Data.nSchedWeekRun[i][j] = pGet(GHP_GROUP_WEEK_START_PCM, nTempPno1++);
            GHP_PCM_Data.nSchedWeekStop[i][j] = pGet(GHP_GROUP_WEEK_STOP_PCM, nTempPno2++);
        }
    }    
    
    // 그룹에서 시작시간과 종료시간의 설정여부를 체크합니다. 
	// 총 10개의 그룹.
	for (i = 0; i < 10; i++) {
        GHP_PCM_Data.nSchedRunSt[i] = pGet(GHP_GROUP_ST_PCM, nTempPno3++);
        GHP_PCM_Data.nSchedStopSt[i] = pGet(GHP_GROUP_ST_PCM, nTempPno3++);
        
        GHP_PCM_Data.nSchedWeekSt[i] = pGet(GHP_GROUP_ST_PCM, i + 20);
        GHP_PCM_Data.nSchedWeekRunSt[i] = pGet(GHP_GROUP_ST_PCM, 30 + nTempPno4++);
        GHP_PCM_Data.nSchedWeekStopSt[i] = pGet(GHP_GROUP_ST_PCM, 30 + nTempPno4++);
    }
    
	// ?? 이부분은 사용하는가요???ㅎㅎ????????????????????????????
	/* 	  
    // 각 GHP 실내기의 그룹번호를 확인합니다. 
    for (i = 0; i < nUnitCnt; i++) {
        nGrp = pGet(GHP_GROUP_PCM, i);
        GhP_Block_Set_GrpNum(GHP_PCM_Data.nBno[i], nGrp, g_nGhpCnt);
        GHP_PCM_Data.nGroupNumber[i] = nGrp;       
    } 
	*/   
}
Example #2
0
void daegu_get_grpnum(int n_idx) 
{

	int n_pno = g_UnitData[n_idx].pno;

	g_UnitData[n_idx].group = pGet(GHP_GROUP_PCM, n_pno);

	// 학사모드는 모드가 항상 "시간"으로 되어야 한다.
	if (g_UnitData[n_idx].group == 0) {
		pSet(GHP_GROUP_MODE_PCM, g_UnitData[n_idx].pno, 1);
		g_UnitData[n_idx].group_mode = 1;
		return;
	}

	if ( g_UnitData[n_idx].group > 10 ) {
		pSet(GHP_GROUP_PCM, n_pno, 10);
		g_UnitData[n_idx].group = pGet(GHP_GROUP_PCM, n_pno);
	}
}
Example #3
0
void daegu_get_ghp_data(void)
{
	int i = 0;
	FILE *fp;
	char filename[32];
	int datasize = 0;
	
	fprintf(stdout, "%s()\n", __FUNCTION__);
	fflush(stdout);
		
	g_pDongInfo = malloc( (sizeof(g_GHP_Info) * 256) );
	memset(g_pDongInfo, 0x00, (sizeof(g_GHP_Info) * 256));

	// get filename	
	memset(filename, 0x00, sizeof(filename));
	switch (g_sddcNum) {
		case 1 :
			memcpy(filename, "daegu_class_a.dat", sizeof("daegu_class_a.dat"));
			break;
					
		default :
			return;
	}
	
	
	if( (fp = fopen(filename, "r") ) == NULL) {
		printf("%s open fail.\n", filename);
		return;			
	}

	fprintf(stdout, "%s() Read File :: %s \n", __FUNCTION__, filename);
	fflush(stdout);
	
	datasize = sizeof(g_GHP_Info);
	for( i = 0; i < 256; i++ ) 
		fread((g_pDongInfo + i), datasize, 1, fp);
	
	fclose(fp);

	for (i = 0; i < g_unitCnt; i++) {
		g_UnitData[i].pno = (g_pDongInfo + i)->nPno;
		g_UnitData[i].block = (g_pDongInfo + i)->nBno;
		g_UnitData[i].chkTouch = 1;
		/*
		fprintf(stderr, "[%s] %d,%d,%d,%d,%d,%d,%d,%d,%d\n",
		b_group_list[i],
		(g_pDongInfo + i)->nPno,
		(g_pDongInfo + i)->nBno,
		(g_pDongInfo + i)->nDDC,
		(g_pDongInfo + i)->nDDR,
		(g_pDongInfo + i)->nOutUnit,
		(g_pDongInfo + i)->nInUnit,
		(g_pDongInfo + i)->nType,
		(g_pDongInfo + i)->nFloor,
		(g_pDongInfo + i)->nSection);
		*/

		g_UnitData[i].on_off = (int)pGet(GHP_ONOFF_PCM, g_UnitData[i].pno);
		g_UnitData[i].r_temp = (int)pGet(GHP_TEMP_PCM, g_UnitData[i].pno);
		g_UnitData[i].s_temp = (int)pGet(GHP_SET_TEMP_PCM, g_UnitData[i].pno);
		g_UnitData[i].aamode = (int)pGet(GHP_MODE_PCM, g_UnitData[i].pno);
		g_UnitData[i].wind_s = (int)pGet(GHP_WINDSPEED_PCM, g_UnitData[i].pno);
		g_UnitData[i].wind_d = (int)pGet(GHP_WINDDIRECTION_PCM, g_UnitData[i].pno);


		fprintf(stderr, ">> g_unitCnt %d,%d,%d %d %d,%d %d %d,%d\n",
		g_UnitData[i].pno,
		g_UnitData[i].block,
		g_UnitData[i].chkTouch,
		g_UnitData[i].on_off,
		g_UnitData[i].r_temp,
		g_UnitData[i].s_temp,
		g_UnitData[i].aamode,
		g_UnitData[i].wind_s,
		g_UnitData[i].wind_d );
		fflush(stderr);
	}
	return;
}
Example #4
0
void daegu_while(void)
{
	int i = 0;
	//int j = 0;
	int st = 0;												// Fsm status
	int result = 0;
	int n_val = 0;											// value
	int n_tempval = 0;										// Temp value		
	//int n_chkval = 0;										// check value
	int now_time = 0 ;
	int set_time = 0;
	int n_loopcnt = 0;
	struct timeval diff_time;
	time_t     tm_nd;
	unsigned int n_temp_minute = 0;
	struct tm *tm_ptr;

	
	st = ST_GET_POLLING;

	while (1) {
		//IfaceGhpSelectSleep(1, 0);
		//continue;

		// 대구대학교 스케쥴
		for (i = 0; i < g_unitCnt; i++) {
			daegu_TimeSched_Make(i);
			daegu_TimeSched_Execution(i);
		}
		
		// 1분마다 시간을 Point에 기록한다.		
		time(&tm_nd);
		tm_ptr = localtime(&tm_nd);
		fprintf(stdout, " >> TIME  %d, %d \n", tm_ptr->tm_hour, tm_ptr->tm_min);
		fflush(stdout);	
		now_time = (tm_ptr->tm_hour * 100) +  tm_ptr->tm_min; 
		n_tempval = pGet(GHP_MODE_STATUS_PCM, 250);
		if ( n_tempval != now_time ) {
			pSet(GHP_MODE_STATUS_PCM, 250, now_time);
			pSet(GHP_MODE_STATUS_PCM, 251, now_time);
			set_time = now_time;
		}


		// GHP 값을 읽어오거나 제어한다. 
		switch (st) {
			case ST_GET_POLLING:
				result = Send_Polling();
				switch(result)
				{
					case POLL_REQUIRE_STARTUP:	
						st = ST_STARTUP;	
						break;
					
					case POLL_EMPTY_DATA:
					case POLL_OK:		
						if (Send_Polling() == POLL_REQUIRE_STARTUP) {
							st = ST_STARTUP;	
							break;
						}
						else {
							st = ST_CHK_USER_CONTROL;
							break;
						}
					
					default: 
						st = ST_CHK_USER_CONTROL;
						break;
				}
				break;

			case ST_CHK_USER_CONTROL:
				CheckUserControl();
				st = ST_GET_USER_CONTROL;
				break;

			case ST_GET_USER_CONTROL:
				while(Do_User_Control()) {

					if (Send_Polling() == POLL_REQUIRE_STARTUP) {
						st = ST_STARTUP;	
						break;
					}
				}
				st = ST_GET_GHP_UNIT;
				break;

			case ST_GET_GHP_UNIT:
				Get_Ghp_Unit();
				if (Send_Polling() == POLL_REQUIRE_STARTUP) {
					st = ST_STARTUP;	
					break;
				}   
				st = ST_GET_POLLING;
				break;

			case ST_STARTUP:
				Startup_SDDC();
				st = ST_GET_POLLING;
				break;

			default:
				st = ST_GET_POLLING;
				break;
		}


		if ( n_loopcnt++ > 60 ) {
			n_loopcnt = 0;
			system( "hwclock --hctosys" );
		}
		
		// 사용자의 시간설정을 처리한다. 
		n_tempval = pGet(GHP_MODE_STATUS_PCM, 251);
		if ( n_tempval != set_time ) {
			fprintf(stdout, " >> SET TIME  %d \n", n_tempval);
			fflush(stdout);	

			if ( n_tempval > set_time ) {
				n_temp_minute = set_time % 100;
				
				set_time = set_time - n_temp_minute;
								
				n_val = ((n_tempval - set_time) / 100) * 3600;
				fprintf(stdout, " >> hour  %d \n", n_val);
				n_val += ((n_tempval - set_time) % 100) * 60;
				fprintf(stdout, " >> minute  %d \n", n_val);

				gettimeofday( &diff_time, NULL );
				//fprintf(stdout, " >> diff_time.tv_sec  %d \n", diff_time.tv_sec);
				diff_time.tv_sec = diff_time.tv_sec + n_val - (n_temp_minute * 60);
				settimeofday( &diff_time, NULL );
				//fprintf(stdout, " >> ++ diff_time.tv_sec  %d \n", diff_time.tv_sec);
				fflush(stdout);
			}
			
			if ( n_tempval < set_time ) {
				n_temp_minute = set_time % 100;
				
				set_time = set_time - n_temp_minute;
				
				n_val = ((set_time - n_tempval) / 100) * 3600;
				fprintf(stdout, " >> hour  %d \n", n_val);
				n_val += ((set_time - n_tempval) % 100) * 60;
				fprintf(stdout, " >> minute  %d \n", n_val);
				
				
				if ( ((set_time - n_tempval) % 100) > 60 ) {
					n_val -= 40 * 60;
				}

				gettimeofday( &diff_time, NULL );
				//fprintf(stdout, " >> diff_time.tv_sec  %d \n", diff_time.tv_sec);
				diff_time.tv_sec = diff_time.tv_sec - n_val - (n_temp_minute * 60);
				settimeofday( &diff_time, NULL );
				//fprintf(stdout, " >> -- diff_time.tv_sec  %d \n", diff_time.tv_sec);
				fflush(stdout);
			}

			pSet(GHP_MODE_STATUS_PCM, 251, n_tempval);
			set_time = n_tempval;

			// 현장에서 테스트 할것..
			system( "hwclock --systohc" );
		}
	}
}
	T Get(NInt index) const
	{
		native_type nativeValue;
		NCheck(pGet(this->GetOwnerHandle(), index, &nativeValue));
		return NTypeTraits<T>::FromNative(nativeValue, true);
	}
	T Get(NInt index) const
	{
		native_type nativeValue;
		NCheck(pGet(index, &nativeValue));
		return NTypeTraits<T>::FromNative(nativeValue, true);
	}
Example #7
0
void Write_Point(int point_number, int pno, int val)
/****************************************************************/
{
	float value = (float)val;
	
	switch(point_number) {
		case 1:		//On Off			
			if (pGet(GHP_ERROR_PCM, pno) > 0 || pGet(GHP_ERROR_NUM_PCM, pno) > 0) {
				pSet(GHP_ONOFF_PCM, pno, 0); 
				pSet(GHP_ONOFF_FAN_PCM, pno, 0); 
				prePtbl[GHP_ONOFF_PCM][pno] = 0;
				prePtbl[GHP_ONOFF_FAN_PCM][pno] = 0;				
				return;
			}
			
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {				
				pSet(GHP_ONOFF_PCM, pno, value); 
				pSet(GHP_ONOFF_FAN_PCM, pno, value); 
				prePtbl[GHP_ONOFF_PCM][pno] = value;
				prePtbl[GHP_ONOFF_FAN_PCM][pno] = value;
				break;
			}
			break;

		case 4:		//Mode
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_MODE_PCM, pno, value); 
				prePtbl[GHP_MODE_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Mode(%d %d %f)\n", GHP_MODE_PCM, pno, value); 
				break;
			}
		case 2:		//Set temperature
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_SET_TEMP_PCM, pno, value); 
				prePtbl[GHP_SET_TEMP_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset SetTemp(%d %d %f)\n ", GHP_SET_TEMP_PCM,  pno, value); 
				break;
			}
			
		case 5:		//Room temperature
			pSet(GHP_TEMP_PCM, pno, value); 
			prePtbl[GHP_TEMP_PCM][pno] = value;
			if ( g_dbgShow ) {
				printf("Pset Temp(%d %d %f)\n ", GHP_TEMP_PCM,  pno, value); 
		
				printf("Pset OnOff(%d %d %f)\n", GHP_ONOFF_PCM,  pno, value);
				printf("Pset OnOff(%d %d %f)\n", GHP_ONOFF_FAN_PCM,  pno, value);
			}
			
			pSet(GHP_ERROR_PCM, pno, 0); 
			pSet(GHP_ERROR_NUM_PCM, pno, 0); 
			
			prePtbl[GHP_ERROR_PCM][pno] = 0;
			prePtbl[GHP_ERROR_NUM_PCM][pno] = 0;					
			
			break;

		case 30:	//Wind Speed
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_WINDSPEED_PCM, pno, value); 
				prePtbl[GHP_WINDSPEED_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Speed(%d %d %f)\n ", GHP_WINDSPEED_PCM,  pno, value); 
				break;
			}

		case 31:	//Wind Direction
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				// 풍향인 경우에만 값에 1을 빼서 값을 쓴다.
				value = value - 1;
				
				pSet(GHP_WINDDIRECTION_PCM, pno, value);
				prePtbl[GHP_WINDDIRECTION_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Direction(%d %d %f)\n ", GHP_WINDDIRECTION_PCM,  pno, value);  
				break;
			}
		
		#ifdef DAEGU_GHP	
		// Remote mode 1 
		// 실내기 리모콘의 운전/정지 버튼을 제어합니다. 
		case 6:	
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_REMOTE_1_PCM, pno, value);
				prePtbl[GHP_REMOTE_1_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Remote 1 (%d %d %f)\n ", GHP_REMOTE_1_PCM,  pno, value);  
				break;
			}
			break;

		// Remote mode 2 
		// 실내기 리모콘의 온도설정 버튼을 제어합니다. 
		case 7:		
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_REMOTE_2_PCM, pno, value);
				prePtbl[GHP_REMOTE_2_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Remote 2 (%d %d %f)\n ", GHP_REMOTE_2_PCM,  pno, value);  
				break;
			}
			break;

		// Remote mode 3 
		// 실내기 리모콘의 냉난방 버튼을 제어합니다. 
		case 8:		
			if (prePtbl[GHP_ONOFF_PCM][pno] != g_fExPtbl[GHP_ONOFF_PCM][pno]) {
				if ( g_dbgShow )
					printf("blocking >>>>>>>>>>>>>>>>>>>>\n");
				break;	
			}
			else {			
				pSet(GHP_REMOTE_3_PCM, pno, value);
				prePtbl[GHP_REMOTE_3_PCM][pno] = value;
				if ( g_dbgShow )
					printf("Pset Remote 3 (%d %d %f)\n ", GHP_REMOTE_3_PCM,  pno, value);  
				break;
			}
			break;
		#endif

		default:
			pno = 254;	
			value = 0;
			break;
	}
	//printf("Pno (%d), Val (%f)\n", pno, value);  	
}