Exemplo n.º 1
0
int		WaitForOperationCompletion( int sessionHandle , double lfTimeout , double lfLowLevelTimeout )
{
	double			lfStartTime						=	0.0,
					lfCurrentTime					=	0.0;

	int				iOpcStatus						=	0;
	
	char			szReadFeedback[LOW_STRING]		=	{0};
	
	int				count							=	0;
	
	int				iTimeout						=	0;
	
	int				iError							=	0;
	
	viGetAttribute ( sessionHandle , VI_ATTR_TMO_VALUE , &iTimeout );   
	
	SetBreakOnLibraryErrors (0); 
	
	viSetAttribute ( sessionHandle , VI_ATTR_TMO_VALUE , (lfLowLevelTimeout*1E3) );  
	
	GetCurrentDateTime(&lfStartTime);
	
	do
	{
		viPrintf( sessionHandle , "*OPC?\n" );
						
		viRead( sessionHandle, szReadFeedback , (LOW_STRING-1) , &count );
	
		iOpcStatus = atoi(szReadFeedback);
		
		if ( iOpcStatus )
			break;
		
		GetCurrentDateTime(&lfCurrentTime);
		
	} while((lfCurrentTime-lfStartTime) < lfTimeout );
	
	if ( iOpcStatus )
	{
		viPrintf( sessionHandle , ":SYST:ERR?\n" );
		SetBreakOnLibraryErrors (0);
		viRead( sessionHandle, szReadFeedback , LOW_STRING , &count );
		SetBreakOnLibraryErrors (1);
	
		iError = atoi(szReadFeedback);
	
		if ( iError == -420 )
		{
			viPrintf( sessionHandle , "*CLS\n" );  
		}
	}
	
	viSetAttribute ( sessionHandle , VI_ATTR_TMO_VALUE , iTimeout );  
	
	SetBreakOnLibraryErrors (1); 
	
	return iOpcStatus;
}
Exemplo n.º 2
0
void CUtil::AddLog(char* string)
{
	USES_CONVERSION;
	HANDLE filehandle;
	DWORD dwReadBytes;
	char buffer[2048];
	filehandle = CreateFile(CA2W((GetCurrentPath() + "\Log.txt").c_str()), GENERIC_WRITE, 0, 0, OPEN_ALWAYS, 0, 0);
	SetFilePointer(filehandle, 0, 0, FILE_END);
	sprintf_s(buffer, 1024, "(%s): %s\r\n", GetCurrentDateTime().c_str(), string);
	printf_s("(%s): %s\r\n", GetCurrentDateTime().c_str(), string);
	WriteFile(filehandle, buffer, strlen(buffer), &dwReadBytes, 0);
	CloseHandle(filehandle);
}
Exemplo n.º 3
0
void
PGTYPESdate_today(date * d)
{
	struct tm	ts;

	GetCurrentDateTime(&ts);
	*d = date2j(ts.tm_year, ts.tm_mon, ts.tm_mday) - date2j(2000, 1, 1);
	return;
}
Exemplo n.º 4
0
void
PGTYPEStimestamp_current(timestamp * ts)
{
	struct tm	tm;

	GetCurrentDateTime(&tm);
	tm2timestamp(&tm, 0, NULL, ts);
	return;
}
Exemplo n.º 5
0
int		Delay_LastComplete( int handle )
{
	double		lfCurrentTime		=	0.0,
				lfTimeOut			=	10.0, 
				lfStartTime			=	0.0;
	
	int			iOpcValue			=	0;
	
	int			status				=	0;
	
	ViAttrState	attrValue			=	0;
		
	if ( viGetAttribute ( handle , VI_ATTR_TMO_VALUE , &attrValue ) == 0 )
		lfTimeOut = attrValue / 1E3;

	GetCurrentDateTime ( &lfStartTime );
	GetCurrentDateTime ( &lfCurrentTime ); 
	
	while(( lfCurrentTime - lfStartTime ) < lfTimeOut ) 
	{
		
		GetCurrentDateTime ( &lfCurrentTime );  
		
		status = viPrintf ( handle , "*OPC?\n");
	
		if ( status )
			continue;
		
		Delay ( 0.2 );
		
		status = viScanf ( handle , "%d" , &iOpcValue);

		if ( status )
			continue;
		
		if ( iOpcValue == 1 )
			return 0;
	}
	
	return -1;	
}
Exemplo n.º 6
0
bool GeneratePID(char *szRegId,char *szStatus,char *Desc)
{
	try
	{
		char szTempPIDFile[FILE_SIZE];
		char szPIDFile[FILE_SIZE];
		char szAlertDateTime[50];
		char szAppPath[FILE_SIZE];
		char szText[2048];

		memset(szAppPath,0,FILE_SIZE);
		
		::GetModuleFileName(NULL,szAppPath,FILE_SIZE);
		
		char *ptr = strrchr(szAppPath,'\\');
		
		if(ptr)
		{
			ptr++;
			*ptr='\0';
		}

		memset(szAlertDateTime,0,sizeof(szAlertDateTime));
		memset(szText,0,sizeof(szText));
		
		GetCurrentDateTime(szAlertDateTime);
		
		char szTimeStamp[100] = {0};
		memset(szTimeStamp, NULL, sizeof(szTimeStamp));
		GetTimeStamp(szTimeStamp);
		
		memset(szTempPIDFile,0,sizeof(szTempPIDFile));
		memset(szPIDFile,0,sizeof(szPIDFile));
		sprintf(szTempPIDFile,"%s\\Configuration\\%s_zBEXShare_%s.ini\0",szAppPath,szRegId,szTimeStamp);
		
		sprintf(szPIDFile,"%s\\PMSTATUS\\%s_zBEXShare_%s.ini\0",szAppPath,szRegId,szTimeStamp);
		memset(szText,0,sizeof(szText));
		sprintf(szText,PID_TEXT,szRegId,szAlertDateTime,szStatus,Desc);
		
		WriteToLog(szTempPIDFile,szText);
		CopyFile(szTempPIDFile,szPIDFile,FALSE);
		DeleteFile(szTempPIDFile);
		return true;
	}
	catch(...)
	{
		return false;
	}
	return true;
}
Exemplo n.º 7
0
Datum get_semester(PG_FUNCTION_ARGS) {
  pg_tm current_date;
  GetCurrentDateTime(&current_date);

  DateADT entering_date = DatumGetDateADT(PG_GETARG_DATUM(0));

  int entering_year, entering_month, entering_day;
  j2date(entering_date + date2j(2000, 1, 1), &entering_year, &entering_month, &entering_day);

  int semester = (current_date.tm_year - entering_year) * 2;
  if (current_date.tm_mon > 6)
    semester++;
  
  PG_RETURN_INT32(semester);
}
Exemplo n.º 8
0
 int CLog::Write(LOG_LEVEL logLevel, const TCHAR* data, int len)
 {
     TCHAR text[2*MAX_LOG_LENGTH+10] = {};
     TCHAR dateTime[MAX_LOG_LENGTH] = {};
     // 获取当前时间
     GetCurrentDateTime(dateTime);
     // log的格式, 时间 [等级] log内容
     _stprintf(text, _T("%s [%s] %s\r\n"), dateTime, s_logInfo[logLevel], data);
     if (INVALID_HANDLE_VALUE == m_hFile)
         return -1;
     CSimpleAutoLock autoLock(&m_lock);
     DWORD dw = 0;
     if (!WriteFile(m_hFile, text, _tcsclen(text)*sizeof(TCHAR), &dw, NULL))
         return -2;
     return (int)dw;
 }
Exemplo n.º 9
0
void LogToFile(LOG_LEVEL ll, const TCHAR* fmt, ...)
{
    TCHAR text[MAX_LOG_LENGTH] = {};

    va_list vl;
    va_start( vl, fmt );
    _vstprintf(text, fmt , vl);
    va_end( vl);      
    // 最后的字符串处理
#ifdef _DEBUG
    TCHAR dateTime[MAX_LOG_LENGTH] = {};
    GetCurrentDateTime(dateTime);
    _tprintf(_T("%s [%s]  %s\r\n" ), dateTime, s_logInfo[ll], text);
#endif

    Log()->Write(ll, text, _tcsclen(text));
}
Exemplo n.º 10
0
CDateTime CDateTime::GetUTCDateTime()
{
  TIME_ZONE_INFORMATION tz;

  CDateTime time(GetCurrentDateTime());
  switch(GetTimeZoneInformation(&tz))
  {
    case TIME_ZONE_ID_DAYLIGHT:
        time += CDateTimeSpan(0, 0, tz.Bias + tz.DaylightBias, 0);
        break;
    case TIME_ZONE_ID_STANDARD:
        time += CDateTimeSpan(0, 0, tz.Bias + tz.StandardBias, 0);
        break;
    case TIME_ZONE_ID_UNKNOWN:
        time += CDateTimeSpan(0, 0, tz.Bias, 0);
        break;
  }

  return time;
}
Exemplo n.º 11
0
void UT::LogToFile(QString data)
{
	QString printData;
	printData.append("FBApi " + GetCurrentDateTime()+"  "+data);
	
	if ( UT::m_Debugfile.open( IO_WriteOnly | IO_Append  ) )
	{
		QTextStream stream( &UT::m_Debugfile );
		//stream.setAutoDetectUnicode(true);
		stream.setCodec("UTF-8");
		stream << printData << endl;
		UT::m_Debugfile.close();
	} 
	else 
	{
		QTextStream stream( &UT::m_Debugfile );
		//stream.setAutoDetectUnicode(true);
		stream.setCodec("UTF-8");
		stream << printData << endl;
		UT::m_Debugfile.close();
	}

}
Exemplo n.º 12
0
// Called from the menu experiment->begin
int exp_Begin (void)
{
    int size;

    if (acqchanG.channels.nItems < 1)
    {
        MessagePopup ("Begin Experiment Failed:",
                      "Please select at least one channel for acquisition");
        return FALSE;
    }
    // Check datafile dir exists (in case it was removed after it was set
    int dirNameLen;
    if( ! FileExists(dataFile.dataDir, &dirNameLen) ) {
        MessagePopup ("Begin Experiment Failed:",
                      "Data dir does not exist! ");
        return FALSE;
    }
    if (!acqchanlist_AllocMemory()) return FALSE;
        
    // set filepath from the data dir, timestamp, suffix and extension
    double dt;
    GetCurrentDateTime(&dt); // sec from 1900, local time
    char fname[MAX_PATHNAME_LEN];
    FormatDateTimeString(dt, "%Y-%m-%d_%H%M%S", fname, MAX_PATHNAME_LEN-1);
    sprintf(dataFile.filePath,"%s\\%s_%s.daas", dataFile.dataDir, fname, dataFile.fileSuffix);
    util_printfLog("Starting Experiment...\n");
    util_printfLog("Data file path: %s\n", dataFile.filePath);
    SetCtrlVal (acqG.p.setup, ACQSETUP_FILEPATH, dataFile.filePath);                      
    //updateGraphSource();

    utilG.acq.pt = 0;
    expG.InitExp();
    acqchanlist_InitDataFile(dataFile.filePath);
    exp_StartDaq();

    return TRUE;
}
Exemplo n.º 13
0
CDateTime CDateTime::GetUTCDateTime()
{
    CDateTime time(GetCurrentDateTime());
    time += GetTimezoneBias();
    return time;
}
Exemplo n.º 14
0
/* DecodeDateTime()
 * Interpret previously parsed fields for general date and time.
 * Return 0 if full date, 1 if only time, and negative DTERR code if problems.
 * (Currently, all callers treat 1 as an error return too.)
 *
 *		External format(s):
 *				"<weekday> <month>-<day>-<year> <hour>:<minute>:<second>"
 *				"Fri Feb-7-1997 15:23:27"
 *				"Feb-7-1997 15:23:27"
 *				"2-7-1997 15:23:27"
 *				"1997-2-7 15:23:27"
 *				"1997.038 15:23:27"		(day of year 1-366)
 *		Also supports input in compact time:
 *				"970207 152327"
 *				"97038 152327"
 *				"20011225T040506.789-07"
 *
 * Use the system-provided functions to get the current time zone
 * if not specified in the input string.
 *
 * If the date is outside the range of pg_time_t (in practice that could only
 * happen if pg_time_t is just 32 bits), then assume UTC time zone - thomas
 * 1997-05-27
 */
int
DecodeDateTime(char **field, int *ftype, int nf, int *dtype, struct tm *tm, fsec_t *fsec, int *tzp)
{
	int			fmask = 0,
				tmask,
				type;
	int			ptype = 0;		/* "prefix type" for ISO y2001m02d04 format */
	int			i;
	int			val;
	int			dterr;
	int			mer = HR24;
	bool		haveTextMonth = FALSE;
	bool		isjulian = FALSE;
	bool		is2digits = FALSE;
	bool		bc = FALSE;
	pg_tz	   *namedTz = NULL;
	struct tm cur_tm;

	/*
	 * We'll insist on at least all of the date fields, but initialize the
	 * remaining fields in case they are not set later...
	 */
	*dtype = DTK_DATE;
	tm->tm_hour = 0;
	tm->tm_min = 0;
	tm->tm_sec = 0;
	*fsec = 0;
	/* don't know daylight savings time status apriori */
	tm->tm_isdst = -1;
	if (tzp != NULL)
		*tzp = 0;

	for (i = 0; i < nf; i++)
	{
		switch (ftype[i])
		{
			case DTK_DATE:
				/***
				 * Integral julian day with attached time zone?
				 * All other forms with JD will be separated into
				 * distinct fields, so we handle just this case here.
				 ***/
				if (ptype == DTK_JULIAN)
				{
					char	   *cp;
					int			val;

					if (tzp == NULL)
						return DTERR_BAD_FORMAT;

					errno = 0;
					val = strtoi(field[i], &cp, 10);
					if (errno == ERANGE || val < 0)
						return DTERR_FIELD_OVERFLOW;

					j2date(val, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
					isjulian = TRUE;

					/* Get the time zone from the end of the string */
					dterr = DecodeTimezone(cp, tzp);
					if (dterr)
						return dterr;

					tmask = DTK_DATE_M | DTK_TIME_M | DTK_M(TZ);
					ptype = 0;
					break;
				}
				/***
				 * Already have a date? Then this might be a time zone name
				 * with embedded punctuation (e.g. "America/New_York") or a
				 * run-together time with trailing time zone (e.g. hhmmss-zz).
				 * - thomas 2001-12-25
				 *
				 * We consider it a time zone if we already have month & day.
				 * This is to allow the form "mmm dd hhmmss tz year", which
				 * we've historically accepted.
				 ***/
				else if (ptype != 0 ||
						 ((fmask & (DTK_M(MONTH) | DTK_M(DAY))) ==
						  (DTK_M(MONTH) | DTK_M(DAY))))
				{
					/* No time zone accepted? Then quit... */
					if (tzp == NULL)
						return DTERR_BAD_FORMAT;

					if (isdigit((unsigned char) *field[i]) || ptype != 0)
					{
						char	   *cp;

						if (ptype != 0)
						{
							/* Sanity check; should not fail this test */
							if (ptype != DTK_TIME)
								return DTERR_BAD_FORMAT;
							ptype = 0;
						}

						/*
						 * Starts with a digit but we already have a time
						 * field? Then we are in trouble with a date and time
						 * already...
						 */
						if ((fmask & DTK_TIME_M) == DTK_TIME_M)
							return DTERR_BAD_FORMAT;

						if ((cp = strchr(field[i], '-')) == NULL)
							return DTERR_BAD_FORMAT;

						/* Get the time zone from the end of the string */
						dterr = DecodeTimezone(cp, tzp);
						if (dterr)
							return dterr;
						*cp = '\0';

						/*
						 * Then read the rest of the field as a concatenated
						 * time
						 */
						dterr = DecodeNumberField(strlen(field[i]), field[i],
												  fmask,
												  &tmask, tm,
												  fsec, &is2digits);
						if (dterr < 0)
							return dterr;

						/*
						 * modify tmask after returning from
						 * DecodeNumberField()
						 */
						tmask |= DTK_M(TZ);
					}
					else
					{
						namedTz = pg_tzset(field[i]);
						if (!namedTz)
						{
							/*
							 * We should return an error code instead of
							 * ereport'ing directly, but then there is no way
							 * to report the bad time zone name.
							 */
							warnx("time zone \"%s\" not recognized",
											field[i]);
						}
						/* we'll apply the zone setting below */
						tmask = DTK_M(TZ);
					}
				}
				else
				{
					dterr = DecodeDate(field[i], fmask,
									   &tmask, &is2digits, tm);
					if (dterr)
						return dterr;
				}
				break;

			case DTK_TIME:

				/*
				 * This might be an ISO time following a "t" field.
				 */
				if (ptype != 0)
				{
					/* Sanity check; should not fail this test */
					if (ptype != DTK_TIME)
						return DTERR_BAD_FORMAT;
					ptype = 0;
				}
				dterr = DecodeTime(field[i], fmask, INTERVAL_FULL_RANGE,
								   &tmask, tm, fsec);
				if (dterr)
					return dterr;

				/*
				 * Check upper limit on hours; other limits checked in
				 * DecodeTime()
				 */
				/* test for > 24:00:00 */
				if (tm->tm_hour > HOURS_PER_DAY ||
					(tm->tm_hour == HOURS_PER_DAY &&
					 (tm->tm_min > 0 || tm->tm_sec > 0 || *fsec > 0)))
					return DTERR_FIELD_OVERFLOW;
				break;

			case DTK_TZ:
				{
					int			tz;

					if (tzp == NULL)
						return DTERR_BAD_FORMAT;

					dterr = DecodeTimezone(field[i], &tz);
					if (dterr)
						return dterr;
					*tzp = tz;
					tmask = DTK_M(TZ);
				}
				break;

			case DTK_NUMBER:

				/*
				 * Was this an "ISO date" with embedded field labels? An
				 * example is "y2001m02d04" - thomas 2001-02-04
				 */
				if (ptype != 0)
				{
					char	   *cp;
					int			val;

					errno = 0;
					val = strtoi(field[i], &cp, 10);
					if (errno == ERANGE)
						return DTERR_FIELD_OVERFLOW;

					/*
					 * only a few kinds are allowed to have an embedded
					 * decimal
					 */
					if (*cp == '.')
						switch (ptype)
						{
							case DTK_JULIAN:
							case DTK_TIME:
							case DTK_SECOND:
								break;
							default:
								return DTERR_BAD_FORMAT;
								break;
						}
					else if (*cp != '\0')
						return DTERR_BAD_FORMAT;

					switch (ptype)
					{
						case DTK_YEAR:
							tm->tm_year = val;
							tmask = DTK_M(YEAR);
							break;

						case DTK_MONTH:

							/*
							 * already have a month and hour? then assume
							 * minutes
							 */
							if ((fmask & DTK_M(MONTH)) != 0 &&
								(fmask & DTK_M(HOUR)) != 0)
							{
								tm->tm_min = val;
								tmask = DTK_M(MINUTE);
							}
							else
							{
								tm->tm_mon = val;
								tmask = DTK_M(MONTH);
							}
							break;

						case DTK_DAY:
							tm->tm_mday = val;
							tmask = DTK_M(DAY);
							break;

						case DTK_HOUR:
							tm->tm_hour = val;
							tmask = DTK_M(HOUR);
							break;

						case DTK_MINUTE:
							tm->tm_min = val;
							tmask = DTK_M(MINUTE);
							break;

						case DTK_SECOND:
							tm->tm_sec = val;
							tmask = DTK_M(SECOND);
							if (*cp == '.')
							{
								dterr = ParseFractionalSecond(cp, fsec);
								if (dterr)
									return dterr;
								tmask = DTK_ALL_SECS_M;
							}
							break;

						case DTK_TZ:
							tmask = DTK_M(TZ);
							dterr = DecodeTimezone(field[i], tzp);
							if (dterr)
								return dterr;
							break;

						case DTK_JULIAN:
							/* previous field was a label for "julian date" */
							if (val < 0)
								return DTERR_FIELD_OVERFLOW;
							tmask = DTK_DATE_M;
							j2date(val, &tm->tm_year, &tm->tm_mon, &tm->tm_mday);
							isjulian = TRUE;

							/* fractional Julian Day? */
							if (*cp == '.')
							{
								double		time;

								errno = 0;
								time = strtod(cp, &cp);
								if (*cp != '\0' || errno != 0)
									return DTERR_BAD_FORMAT;

#ifdef HAVE_INT64_TIMESTAMP
								time *= USECS_PER_DAY;
#else
								time *= SECS_PER_DAY;
#endif
								dt2time(time,
										&tm->tm_hour, &tm->tm_min,
										&tm->tm_sec, fsec);
								tmask |= DTK_TIME_M;
							}
							break;

						case DTK_TIME:
							/* previous field was "t" for ISO time */
							dterr = DecodeNumberField(strlen(field[i]), field[i],
													  (fmask | DTK_DATE_M),
													  &tmask, tm,
													  fsec, &is2digits);
							if (dterr < 0)
								return dterr;
							if (tmask != DTK_TIME_M)
								return DTERR_BAD_FORMAT;
							break;

						default:
							return DTERR_BAD_FORMAT;
							break;
					}

					ptype = 0;
					*dtype = DTK_DATE;
				}
				else
				{
					char	   *cp;
					int			flen;

					flen = strlen(field[i]);
					cp = strchr(field[i], '.');

					/* Embedded decimal and no date yet? */
					if (cp != NULL && !(fmask & DTK_DATE_M))
					{
						dterr = DecodeDate(field[i], fmask,
										   &tmask, &is2digits, tm);
						if (dterr)
							return dterr;
					}
					/* embedded decimal and several digits before? */
					else if (cp != NULL && flen - strlen(cp) > 2)
					{
						/*
						 * Interpret as a concatenated date or time Set the
						 * type field to allow decoding other fields later.
						 * Example: 20011223 or 040506
						 */
						dterr = DecodeNumberField(flen, field[i], fmask,
												  &tmask, tm,
												  fsec, &is2digits);
						if (dterr < 0)
							return dterr;
					}
					else if (flen > 4)
					{
						dterr = DecodeNumberField(flen, field[i], fmask,
												  &tmask, tm,
												  fsec, &is2digits);
						if (dterr < 0)
							return dterr;
					}
					/* otherwise it is a single date/time field... */
					else
					{
						dterr = DecodeNumber(flen, field[i],
											 haveTextMonth, fmask,
											 &tmask, tm,
											 fsec, &is2digits);
						if (dterr)
							return dterr;
					}
				}
				break;

			case DTK_STRING:
			case DTK_SPECIAL:
				type = DecodeSpecial(i, field[i], &val);
				if (type == IGNORE_DTF)
					continue;

				tmask = DTK_M(type);
				switch (type)
				{
					case RESERV:
						switch (val)
						{
							case DTK_CURRENT:
								warnx("date/time value \"current\" is no longer supported");

								return DTERR_BAD_FORMAT;
								break;

							case DTK_NOW:
								tmask = (DTK_DATE_M | DTK_TIME_M | DTK_M(TZ));
								*dtype = DTK_DATE;
								GetCurrentTimeUsec(tm, fsec, tzp);
								break;

							case DTK_YESTERDAY:
								tmask = DTK_DATE_M;
								*dtype = DTK_DATE;
								GetCurrentDateTime(&cur_tm);
								j2date(date2j(cur_tm.tm_year, cur_tm.tm_mon, cur_tm.tm_mday) - 1,
									&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
								break;

							case DTK_TODAY:
								tmask = DTK_DATE_M;
								*dtype = DTK_DATE;
								GetCurrentDateTime(&cur_tm);
								tm->tm_year = cur_tm.tm_year;
								tm->tm_mon = cur_tm.tm_mon;
								tm->tm_mday = cur_tm.tm_mday;
								break;

							case DTK_TOMORROW:
								tmask = DTK_DATE_M;
								*dtype = DTK_DATE;
								GetCurrentDateTime(&cur_tm);
								j2date(date2j(cur_tm.tm_year, cur_tm.tm_mon, cur_tm.tm_mday) + 1,
									&tm->tm_year, &tm->tm_mon, &tm->tm_mday);
								break;

							case DTK_ZULU:
								tmask = (DTK_TIME_M | DTK_M(TZ));
								*dtype = DTK_DATE;
								tm->tm_hour = 0;
								tm->tm_min = 0;
								tm->tm_sec = 0;
								if (tzp != NULL)
									*tzp = 0;
								break;

							default:
								*dtype = val;
						}

						break;

					case MONTH:

						/*
						 * already have a (numeric) month? then see if we can
						 * substitute...
						 */
						if ((fmask & DTK_M(MONTH)) && !haveTextMonth &&
							!(fmask & DTK_M(DAY)) && tm->tm_mon >= 1 &&
							tm->tm_mon <= 31)
						{
							tm->tm_mday = tm->tm_mon;
							tmask = DTK_M(DAY);
						}
						haveTextMonth = TRUE;
						tm->tm_mon = val;
						break;

					case DTZMOD:

						/*
						 * daylight savings time modifier (solves "MET DST"
						 * syntax)
						 */
						tmask |= DTK_M(DTZ);
						tm->tm_isdst = 1;
						if (tzp == NULL)
							return DTERR_BAD_FORMAT;
						*tzp += val * MINS_PER_HOUR;
						break;

					case DTZ:

						/*
						 * set mask for TZ here _or_ check for DTZ later when
						 * getting default timezone
						 */
						tmask |= DTK_M(TZ);
						tm->tm_isdst = 1;
						if (tzp == NULL)
							return DTERR_BAD_FORMAT;
						*tzp = val * MINS_PER_HOUR;
						break;

					case TZ:
						tm->tm_isdst = 0;
						if (tzp == NULL)
							return DTERR_BAD_FORMAT;
						*tzp = val * MINS_PER_HOUR;
						break;

					case IGNORE_DTF:
						break;

					case AMPM:
						mer = val;
						break;

					case ADBC:
						bc = (val == BC);
						break;

					case DOW:
						tm->tm_wday = val;
						break;

					case UNITS:
						tmask = 0;
						ptype = val;
						break;

					case ISOTIME:

						/*
						 * This is a filler field "t" indicating that the next
						 * field is time. Try to verify that this is sensible.
						 */
						tmask = 0;

						/* No preceding date? Then quit... */
						if ((fmask & DTK_DATE_M) != DTK_DATE_M)
							return DTERR_BAD_FORMAT;

						/***
						 * We will need one of the following fields:
						 *	DTK_NUMBER should be hhmmss.fff
						 *	DTK_TIME should be hh:mm:ss.fff
						 *	DTK_DATE should be hhmmss-zz
						 ***/
						if (i >= nf - 1 ||
							(ftype[i + 1] != DTK_NUMBER &&
							 ftype[i + 1] != DTK_TIME &&
							 ftype[i + 1] != DTK_DATE))
							return DTERR_BAD_FORMAT;

						ptype = val;
						break;

					case UNKNOWN_FIELD:

						/*
						 * Before giving up and declaring error, check to see
						 * if it is an all-alpha timezone name.
						 */
						namedTz = pg_tzset(field[i]);
						if (!namedTz)
							return DTERR_BAD_FORMAT;
						/* we'll apply the zone setting below */
						tmask = DTK_M(TZ);
						break;

					default:
						return DTERR_BAD_FORMAT;
				}
				break;

			default:
				return DTERR_BAD_FORMAT;
		}

		if (tmask & fmask)
			return DTERR_BAD_FORMAT;
		fmask |= tmask;
	}							/* end loop over fields */

	/* do final checking/adjustment of Y/M/D fields */
	dterr = ValidateDate(fmask, isjulian, is2digits, bc, tm);
	if (dterr)
		return dterr;

	/* handle AM/PM */
	if (mer != HR24 && tm->tm_hour > HOURS_PER_DAY / 2)
		return DTERR_FIELD_OVERFLOW;
	if (mer == AM && tm->tm_hour == HOURS_PER_DAY / 2)
		tm->tm_hour = 0;
	else if (mer == PM && tm->tm_hour != HOURS_PER_DAY / 2)
		tm->tm_hour += HOURS_PER_DAY / 2;

	/* do additional checking for full date specs... */
	if (*dtype == DTK_DATE)
	{
		if ((fmask & DTK_DATE_M) != DTK_DATE_M)
		{
			if ((fmask & DTK_TIME_M) == DTK_TIME_M)
				return 1;
			return DTERR_BAD_FORMAT;
		}

		/*
		 * If we had a full timezone spec, compute the offset (we could not do
		 * it before, because we need the date to resolve DST status).
		 */
		if (namedTz != NULL)
		{
			/* daylight savings time modifier disallowed with full TZ */
			if (fmask & DTK_M(DTZMOD))
				return DTERR_BAD_FORMAT;

			*tzp = DetermineTimeZoneOffset(tm, namedTz);
		}

		/* timezone not specified? then find local timezone if possible */
		if (tzp != NULL && !(fmask & DTK_M(TZ)))
		{
			/*
			 * daylight savings time modifier but no standard timezone? then
			 * error
			 */
			if (fmask & DTK_M(DTZMOD))
				return DTERR_BAD_FORMAT;

			*tzp = DetermineTimeZoneOffset(tm, session_timezone);
		}
	}

	return 0;
}
Exemplo n.º 15
0
int CVICALLBACK Command (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
	if(event != EVENT_LEFT_CLICK)
		return 0;
	
	if(CheckAuth(OP_TANK) == 0)
		return 0;
	if (!ButtonConfirm (panel,control))		
		return 0; 
	
	switch (control) {
		case PANEL_TANK_AMAKE_OFF:
			if(testBit(sys->tk[curTankId].hsMakeEnd,RB) > 0)
			{
				MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","½Ð¥ý±Æ©ñ¡A¤~¥i°õ¦æ°t¼Ñ¡I");
				break;
			}
			if(g_setupMake == 0)
			{
				resetBit(sys->tk[curTankId].hsMakeStop); 
				GetCtrlVal(panel,PANEL_TANK_AC1_MAKE,&sys->tk[curTankId].MakeCH1);
				GetCtrlVal(panel,PANEL_TANK_AC2_MAKE,&sys->tk[curTankId].MakeCH2); 
				GetCtrlVal(panel,PANEL_TANK_AC3_MAKE,&sys->tk[curTankId].MakeCH3);
				GetCtrlVal(panel,PANEL_TANK_AC4_MAKE,&sys->tk[curTankId].MakeCH4);
				g_makeBit = sys->tk[curTankId].hsMake;
				g_setupMake = 1;
				
				ActionLog(TANK_MAKE_ACT_EVENT,curTankId,1,sys->tk[curTankId].MakeCH1,sys->tk[curTankId].MakeCH2,sys->tk[curTankId].MakeCH3);
			}
			break;
		case PANEL_TANK_AMAKE_ON:
			setBit(sys->tk[curTankId].hsMakeStop);
			
			ActionLog(TANK_MAKE_ACT_EVENT,curTankId,0,0,0,0);
			break;
			
		case PANEL_TANK_MMAKE_OFF:
			if(testBit(sys->tk[curTankId].hsMakeEnd,RB) == 0)
			{
				MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","°t¼Ñ¥¼§¹¦¨¡A¤£¥i²K¥[¡I");
				break;
			}
			if(g_setupMMake == 0)
			{
				resetBit(sys->tk[curTankId].hsMMakeStop); 
				GetCtrlVal(panel,PANEL_TANK_AC1_MAKE,&sys->tk[curTankId].MMakeCH1);
				GetCtrlVal(panel,PANEL_TANK_AC2_MAKE,&sys->tk[curTankId].MMakeCH2); 
				GetCtrlVal(panel,PANEL_TANK_AC3_MAKE,&sys->tk[curTankId].MMakeCH3);
				GetCtrlVal(panel,PANEL_TANK_AC4_MAKE,&sys->tk[curTankId].MMakeCH4);
				g_mmakeBit = sys->tk[curTankId].hsMMake;
				g_setupMMake = 1;
				
				ActionLog(TANK_MMAKE_ACT_EVENT,curTankId,1,sys->tk[curTankId].MMakeCH1,sys->tk[curTankId].MMakeCH2,sys->tk[curTankId].MMakeCH3);
			}
			break;
		case PANEL_TANK_MMAKE_ON:
			setBit(sys->tk[curTankId].hsMMakeStop);
			
			ActionLog(TANK_MAKE_ACT_EVENT,curTankId,0,0,0,0);
			break;	
			
		case PANEL_TANK_AC1_DOS_OFF:
			setBit(sys->tk[curTankId].hsAC1Dos);
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,1,1,0,0);
			
			break;
		case PANEL_TANK_AC1_DOS_ON:
			resetBit(sys->tk[curTankId].hsAC1Dos);
			
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,1,0,0,0);
			break;	
			
		case PANEL_TANK_AC2_DOS_OFF:
			setBit(sys->tk[curTankId].hsAC2Dos);
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,2,1,0,0);
			
			break;
		case PANEL_TANK_AC2_DOS_ON:
			resetBit(sys->tk[curTankId].hsAC2Dos);
			
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,2,0,0,0);
			break;
			
		case PANEL_TANK_AC3_DOS_OFF:
			setBit(sys->tk[curTankId].hsAC3Dos);
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,3,1,0,0);
			
			break;
		case PANEL_TANK_AC3_DOS_ON:
			resetBit(sys->tk[curTankId].hsAC3Dos);
			
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,3,0,0,0);
			break;	
			
		case PANEL_TANK_AC4_DOS_OFF:
			setBit(sys->tk[curTankId].hsAC4Dos);
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,4,1,0,0);
			
			break;
		case PANEL_TANK_AC4_DOS_ON:
			resetBit(sys->tk[curTankId].hsAC4Dos);
			
			ActionLog(TANK_DOS_ACT_EVENT,curTankId,4,0,0,0);
			break;	
			
        case PANEL_TANK_WASH_OFF:
			setBit(sys->tk[curTankId].hsWash);
			
			ActionLog(TANK_WASH_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_WASH_ON:
			resetBit(sys->tk[curTankId].hsWash);
			
			ActionLog(TANK_WASH_ACT_EVENT,curTankId,0,0,0,0);
			break;
			
		case PANEL_TANK_DOWN_OFF:
			/*if(testBit(sys->tk[curTankId].hsMakeEnd,RB) == 0)
			{
				MessagePopup("¾Þ§@±ø¥ó¤£º¡¨¬","°t¼Ñ¥¼§¹¦¨¡A¤£¥i±Æ©ñ¡I¡I");
				break;
			}  */
			setBit(sys->tk[curTankId].hsDown);
			ActionLog(TANK_DOWN_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_DOWN_ON:
			resetBit(sys->tk[curTankId].hsDown);
			ActionLog(TANK_DOWN_ACT_EVENT,curTankId,0,0,0,0);
			break;
			
		case PANEL_TANK_PUMP_OFF:
			resetBit(sys->tk[curTankId].hsPump);
			ActionLog(TANK_PUMP_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_PUMP_ON:
			ActionLog(TANK_PUMP_ACT_EVENT,curTankId,0,0,0,0);
			setBit(sys->tk[curTankId].hsPump);
			break;
			
		case PANEL_TANK_PUMPIN_OFF:
			resetBit(sys->tk[curTankId].hsPumpIn);
			ActionLog(TANK_PUMP_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_PUMPIN_ON:
			ActionLog(TANK_PUMP_ACT_EVENT,curTankId,0,0,0,0);
			setBit(sys->tk[curTankId].hsPumpIn);
			break;	
			
		case PANEL_TANK_HEAT_OFF:
			resetBit(sys->tk[curTankId].hsHeat);
			ActionLog(TANK_HEAT_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_HEAT_ON:
			setBit(sys->tk[curTankId].hsHeat);
			ActionLog(TANK_HEAT_ACT_EVENT,curTankId,0,0,0,0);
			break;
			
		case PANEL_TANK_ADD_WATER_OFF:
			setBit(sys->tk[curTankId].hsAddWater);
			ActionLog(TANK_ADD_WATER_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_ADD_WATER_ON:
			resetBit(sys->tk[curTankId].hsAddWater);
			ActionLog(TANK_ADD_WATER_ACT_EVENT,curTankId,0,0,0,0);
			break;	
			
		case PANEL_TANK_SHUT_OFF:
			setBit(sys->tk[curTankId].hsShutOpen);
			resetBit(sys->tk[curTankId].hsShutClose);
			ActionLog(TANK_SHUT_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_SHUT_ON:
			setBit(sys->tk[curTankId].hsShutClose);
			resetBit(sys->tk[curTankId].hsShutOpen);
			ActionLog(TANK_SHUT_ACT_EVENT,curTankId,0,0,0,0);
			break;	
			
/*		case PANEL_TANK_BUBB_OFF:
			setBit(sys->tk[curTankId].hsBubble);
			ActionLog(TANK_BUBB_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_BUBB_ON:
			resetBit(sys->tk[curTankId].hsBubble);
			ActionLog(TANK_BUBB_ACT_EVENT,curTankId,0,0,0,0);
			break;
					   
		case PANEL_TANK_DRAIN_OFF:
			setBit(sys->tk[curTankId].hsDrain);
			ActionLog(TANK_DRAIN_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_DRAIN_ON:
			resetBit(sys->tk[curTankId].hsDrain);
			ActionLog(TANK_DRAIN_ACT_EVENT,curTankId,0,0,0,0);
			break;	
	*/	
			
		case PANEL_TANK_FILL_OFF:
			//ChangFillStatus(sys->rtk[curRTankId1].hsFill,1);
			setBit(sys->rtk[curRTankId1].hsFill);
			GetCurrentDateTime(&sys->rtk[curRTankId1].car.iPrcTM[curTankId]);
			ActionLog(TANK_CAR_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_FILL_ON:
			resetBit(sys->rtk[curRTankId1].hsFill);
			//ChangFillStatus(sys->rtk[curRTankId1].hsFill,0);
			ActionLog(TANK_CAR_ACT_EVENT,curTankId,0,0,0,0);
			break;	
			
		case PANEL_TANK_FILL2_OFF:
			setBit(sys->rtk[curRTankId2].hsFill);
			GetCurrentDateTime(&sys->rtk[curRTankId2].car.iPrcTM[curTankId]);
			//ChangFillStatus(sys->rtk[curRTankId2].hsFill,1);
			ActionLog(TANK_CAR_ACT_EVENT,curTankId,1,0,0,0);
			break;
		case PANEL_TANK_FILL2_ON:
			resetBit(sys->rtk[curRTankId2].hsFill);
			//ChangFillStatus(sys->rtk[curRTankId2].hsFill,0);
			ActionLog(TANK_CAR_ACT_EVENT,curTankId,0,0,0,0);
			break;	
	}
	
	return 0;
}
void*      MINI_CIRCUITS_STD_Driver_SetValue( int hHandle , char *pCommandName , void *pValue , int iValueLength , int iValueSize , ...  )
{
	STD_ERROR					StdError						=	{0};
	
	tsLocalStorage				*pLocalStorage					=	NULL;			
	
	int							iCommandIndex					=	0,
								bCommandFound					=	0;

	char						szCommand[LOW_STRING]			=	{0};

	unsigned int				iValue							=	0;
	
	short						value							=	0;
	
	char						*retStr							=	NULL;	
	
	char						*pError							=	szCommand,
								*pCommand						=	szCommand;
	
	double						lfDelay							=	0.0,
								lfCurrentTime					=	0.0;
	
	IF (( hHandle == 0 ) , "Handle can't be zero." );
	
	CHK_CMT( CmtGetTSVPtr ( hHandle, &pLocalStorage));

	IF (( pValue == NULL ) ,"Value pointer is NULL" );  
	
	for ( iCommandIndex = 0 ; iCommandIndex < pLocalStorage->listSize ; iCommandIndex++ )
		if ((strlen(pLocalStorage->pMINI_CIRCUITS_CommandList[iCommandIndex].szCommandName)) && ( strcmp( pCommandName , pLocalStorage->pMINI_CIRCUITS_CommandList[iCommandIndex].szCommandName ) == 0 ))
		{
			bCommandFound = 1;
			break;
		}

	IF (( bCommandFound == 0 ) , "Command was not found.");   
	
	pLocalStorage->iLastIndex = iCommandIndex;
	
	switch(iValueSize)
	{
		case 1:
				if ( iValueLength == 1 )
					iValue = *((char*)pValue);
				
				if ( iValueLength > 1 )
					iValue = atoi((char*)pValue);  
					
				break;
		case 2:
				iValue = *((short*)pValue);
				break;
		case 4:
				iValue = *((int*)pValue);
				break;						
		case 8:
				iValue = (char)*((__int64*)pValue);
				break;

		default:
				break;
	}
			
	sprintf( szCommand , ":%s:%s:STATE:%d" , pLocalStorage->pMINI_CIRCUITS_CommandList[iCommandIndex].szSubDeviceName , pLocalStorage->pMINI_CIRCUITS_CommandList[iCommandIndex].szSubDeviceLocation , iValue );

	GetCurrentDateTime (&lfCurrentTime);
	
	lfDelay = pLocalStorage->pMINI_CIRCUITS_CommandList[iCommandIndex].lfSetDelay - ( lfCurrentTime - pLocalStorage->lfLastSendCommandTime );
	
	if ( lfDelay > 0.0 )
		DelayWithEventProcessing(lfDelay);
	
	STD_ERR( ModularZT__USB_ControlSend_SCPI ( pLocalStorage->hDriverHandle , NULL , &pCommand ,&retStr, &value ));
	
	pLocalStorage->lfLastSendCommandTime = lfCurrentTime;
	
	IF (( value == 0 ) , "Not successfully." );
	
	if ( retStr )
	{
		StdError.error = atoi(retStr);
		
		if ( StdError.error < 0 )
		{
			pError = strchr( retStr , ' ' );
			
			if ( pError )
			{
				FORCE_ERR( StdError.error , pError )
			}
		}
	}