예제 #1
0
int CScheduler::LoadFromFile(){

	CString strName;
	CString temp;

	strName.Format(_T("%spreferences.ini"), thePrefs.GetMuleDirectory(EMULE_CONFIGDIR));
	CIni ini(strName, _T("Scheduler"));
	
	UINT max=ini.GetInt(_T("Count"),0);
	UINT count=0;

	while (count<max) {
		strName.Format(_T("Schedule#%i"),count);
		temp=ini.GetString(_T("Title"),_T(""),strName);
		if (temp!=_T("")) {
			Schedule_Struct* news= new Schedule_Struct();
			news->title=temp;
			news->day=ini.GetInt(_T("Day"),0);
			news->enabled=ini.GetBool(_T("Enabled"));
			news->time=ini.GetInt(_T("StartTime"));
			news->time2=ini.GetInt(_T("EndTime"));
			ini.SerGet(true, news->actions,
				ARRSIZE(news->actions), _T("Actions"));
			ini.SerGet(true, news->values,
				ARRSIZE(news->values), _T("Values"));

			AddSchedule(news);
			count++;
		} else break;
	}

	return count;
}
예제 #2
0
void CScheduler::SetWeekly(int action,bool activate)
{
	bool Currentactivated = HasWeekly(action);
    if (  Currentactivated == activate) 
		 return; // nothing to do. 

	if ( ( Currentactivated == false )&& (activate == true)) { // must we insert a new? 
     	Schedule_Struct* newschedule=new Schedule_Struct();
		struct tm tmTemp;
	    CTime tNow = CTime(safe_mktime(CTime::GetCurrentTime().GetLocalTm(&tmTemp)));
	
	    newschedule->day=tNow.GetDayOfWeek();
	    newschedule->enabled=true;
	    newschedule->time=time(NULL);
	    newschedule->time2=time(NULL);
	    newschedule->title=GetResString(IDS_SCHEDTEXT);
	    newschedule->ResetActions();
		newschedule->actions[0]=action;
		newschedule->values[0]=L"update";
		AddSchedule(newschedule);
		thePrefs.scheduler=true; // enable scheduler
	}
	if ((Currentactivated == true )&& (activate == false)) { // we must delete

		Schedule_Struct* curschedule;
		for (uint8 si=0;si< GetCount();si++) {
			curschedule=  GetSchedule(si);
			if (curschedule->actions[0]==0 || !curschedule->enabled) continue;
			if (curschedule->day!=DAY_DAYLY) { // not daily, so must be weekly ( or montly, good also) 
				for (int ai=0;ai<16;ai++) {
					if (curschedule->actions[ai]==action) {
						RemoveSchedule(si);
						return ;
					}
				}
			}
		}
		// not found? then schedule does not exist. ASSERT()?;
		return ;
	}
};
예제 #3
0
/**
* @brief Alarm processing thread.
*/
void *ProcAlarmThread(void *arg)
{
	int iCurTime;
	void *status = PROC_SUCESS;
	time_t tCurrentTime;
	struct tm *tmnow;
	AlarmParam_t* pEvironment = (AlarmParam_t*)arg;
	unsigned char enableIn,enableOut=0,trigger;
	LogEntry_t tLog;
	SysInfo *pSysInfo = pAlarmSysInfo;
	DBG("QID: %d\n", pEvironment ->msg_id);
	DBG("From: %d\n", pEvironment ->msg_buf.src);
	DBG("pSysInfo: %p\n", pSysInfo);
	DBG("Index: %d\n", pEvironment ->msg_buf.index);
	if((iCurTime = time(&tCurrentTime)) == -1){
		ERR("Fail on get current time\n");
		status =PROC_FAIL;
		goto ALARM_EXIT;
	}
	tmnow = localtime(&tCurrentTime);
	memcpy(&tLog.time, tmnow, sizeof(struct tm));
	switch(pEvironment->msg_buf.event){
		case ALARM_EVENT_AUDIO_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_AUDIO_TRIG \n");
			if((pSysInfo->audio_config.alarmON == 0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_AUDIO)){
				break;
			}
			AddSchedule(AUDIO_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Audio Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_MOTION_DETECT:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_MOTION_DETECT \n");
			if((pSysInfo->motion_config.motionenable==0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_MOTION)){
				break;
			}
			SetJpegStartSerial(pEvironment->msg_buf.serial);
			AddSchedule(MOTION_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Motion Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_ALARMRESET_TRIG:
		{
			DBG("ALARM_EVENT_ALARMRESET_TRIG \n");
			ResetSchedule();
			Set_AlarmDuration(0);
			setAudioCount(-1);
			break;
		}
		case ALARM_EVENT_ALARMIN_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_ALARMIN_TRIG \n");
			enableIn=(pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.gioinenable);
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			/** check if turn gio alarm on   */
			if((enableIn==0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_EXT)){
				break;
			}
			AddSchedule(EXT_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "External Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_ALARMETH_TRIG:
		{
			int alarmDuration;
			DBG("ALARM_EVENT_ALARMETH_TRIG \n");
			alarmDuration=pSysInfo->lan_config.nAlarmDuration;
			/**  check if turn Ethernet alarm on */
			if((pSysInfo->lan_config.lostalarm == 0)||
			   (pSysInfo->lan_config.alarmstatus&FLG_UI_ETH)){
				break;
			}
			AddSchedule(ETH_SCHEDULE, tmnow, pSysInfo);
			enableOut = (pSysInfo->lan_config.nExtAlarm&pSysInfo->lan_config.giooutenable);
			trigger=pSysInfo->lan_config.gioouttype;
			if(enableOut==1){
				dm355_gio_write(GIO_ALARMOUT,trigger);
				Set_AlarmDuration(alarmDuration);
			}
			sprintf(tLog.event, "Ethernet Alarm");
			fSetSysLog(&tLog);
			int count=0;
			count=getAudioCount();
			if ( count > 0){
				setAudioCount(alarmDuration);
				break;
			}
			else
				setAudioCount(alarmDuration);
			AlarmAudio_Play(pEvironment->audMsg_id);
			break;
		}
		case ALARM_EVENT_SCHEDULE:
		{
			int nflag, bIsAviRun;
			int isFTPAVI,isSDAVI;
			int supportJPG,supportH264,supportH264cif,supportMpeg4,supportMpeg4cif,supportAVI;
			DBG("ALARM_EVENT_SCHEDULE \n");
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			isSDAVI=pSysInfo->sdcard_config.sdfileformat;
			supportJPG = pSysInfo->lan_config.Supportstream1;
			supportMpeg4 = pSysInfo->lan_config.Supportstream2;
			supportMpeg4cif = pSysInfo->lan_config.Supportstream3;
			supportH264 = pSysInfo->lan_config.Supportstream5;
			supportH264cif = pSysInfo->lan_config.Supportstream6;
			supportAVI = supportH264|supportH264cif|supportMpeg4|supportMpeg4cif;
			bIsAviRun = 0;
			sprintf(tLog.event, "Schedule Record");
			nflag =0;
			if(pSysInfo->sdcard_config.sdinsert<=1){
				if(supportAVI&&pSysInfo->sdcard_config.sdrenable&&isSDAVI==0&&
						!gbSD_WriteProtect){
					nflag |= AVI_TO_SD;
					bIsAviRun = 1;
				}
				if(supportAVI&&pSysInfo->ftp_config.rftpenable&&isFTPAVI==0){
					nflag |= AVI_TO_FTP;
					bIsAviRun = 1;
				}
				if(bIsAviRun){
					AviRun(0, nflag);
					SemWait(pEvironment->hAlarmSem);
					gSchAviRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			} else {
				/* AVI no stop case */
				if(supportAVI&&pSysInfo->sdcard_config.sdrenable&&isSDAVI==0&&
						!gbSD_WriteProtect){
					AviRun(1, AVI_TO_SD);
					SemWait(pEvironment->hAlarmSem);
					gSchAviRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			nflag =0;
			if(isSDAVI==1&&pSysInfo->sdcard_config.sdrenable &&
					!gbSD_WriteProtect)
				nflag |= JPG_TO_SD;
			/* Megapixel JPEG mode */
			if(!supportAVI&&pSysInfo->sdcard_config.sdrenable&&!gbSD_WriteProtect)
				nflag |= JPG_TO_SD;
			if(pSysInfo->sdcard_config.sdinsert<=1){
				if(isFTPAVI==1 &&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				/* Megapixel JPEG mode*/
				if(!supportAVI&&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				if(nflag){
					JpgRun(nflag, 0 );
					SemWait(pEvironment->hAlarmSem);
					gSchJpgRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			else{
				if(supportJPG&&pSysInfo->ftp_config.rftpenable)
					nflag |= JPG_TO_FTP;
				if(nflag){
					JpgRun(nflag, 1 );
					SemWait(pEvironment->hAlarmSem);
					gSchJpgRun = 1;
					SemRelease(pEvironment->hAlarmSem);
				}
			}
			fSetSysLog(&tLog);
			break;
		}
		case ALARM_EVENT_SCHEDULE_END:
		{
			int isFTPAVI;
			int supportJPG=0,supportH264=0,supportH264cif=0,supportMpeg4=0,supportMpeg4cif=0,supportAVI=0;
			DBG("ALARM_EVENT_SCHEDULE_END\n");
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			isFTPAVI=pSysInfo->ftp_config.ftpfileformat;
			supportJPG = pSysInfo->lan_config.Supportstream1;
			supportMpeg4 = pSysInfo->lan_config.Supportstream2;
			supportMpeg4cif = pSysInfo->lan_config.Supportstream3;
			supportH264 = pSysInfo->lan_config.Supportstream5;
			supportH264cif = pSysInfo->lan_config.Supportstream6;
			supportAVI = supportH264|supportH264cif|supportMpeg4|supportMpeg4cif;
			if(pSysInfo->sdcard_config.sdinsert==3){
				/* AVI no stop case */
				SemWait(pEvironment->hAlarmSem);
				if(!gbSD_WriteProtect && gSchAviRun){
					AviStop();
					gSchAviRun = 0;
				}
				if(gSchJpgRun){
					JpgStop(1);
					gSchJpgRun = 0;
				}
				SemRelease(pEvironment->hAlarmSem);
			} else {
				SemWait(pEvironment->hAlarmSem);
				if(gSchAviRun){
					AviStop();
					gSchAviRun = 0;
				}
				if(gSchJpgRun){
					JpgStop(0);
					gSchJpgRun = 0;
				}
				SemRelease(pEvironment->hAlarmSem);
			}
			break;
		}
		default:
			ERR("Unknown Event\n");
			sprintf(tLog.event, "Unknown Event");
			fSetSysLog(&tLog);
			status = PROC_FAIL;
			break;
	}

ALARM_EXIT:
	free(pEvironment);
	DBG("Free evironment sucess\n");
	pthread_exit(status);
	return status;
}