Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » Bugs (& fixes) » Since Raspberry have not RTC clock, I propose add SetTime functionality
Since Raspberry have not RTC clock, I propose add SetTime functionality [message #47118] Sun, 11 December 2016 18:52 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 741
Registered: January 2008
Location: Moscow, Russia
Contributor

I propose this variant of function SetTime( Time ) (file Core/TimeDate.cpp)


bool SetSysTime(Time time)
{
#ifdef __ARM_EABI__
	struct tm mytime;
    struct timeval garfield;
    time_t new_time;
	int result_t;

	//Set Time struct
	mytime.tm_sec = time.second;      // Seconds
	mytime.tm_min = time.minute;      // Minutes
	mytime.tm_hour = time.hour+1;       // Hours
	mytime.tm_mday = time.day;        // Day of Month
	mytime.tm_mon = time.month-1;     // Month
	mytime.tm_year = time.year-1900;    // Year


	new_time = mktime(&mytime);
	garfield.tv_sec =new_time;
	garfield.tv_usec=0;

	result_t=settimeofday(&garfield,NULL);
	if(result_t<0)
	{
		fprintf(stderr,"Error setting the Time.\n");
		return false;
	}
	else
	{
		return true;
	}
#else
#ifdef PLATFORM_POSIX
	struct tm      tmp_time;
	tmp_time.tm_sec  = time.second;
	tmp_time.tm_min  = time.minute;
	tmp_time.tm_hour = time.hour;
	tmp_time.tm_mday = time.day;
	tmp_time.tm_mon  = time.month-1;
	tmp_time.tm_year = time.year-1900;
	time_t raw_time  = mktime(&tmp_time);

	struct timespec sys_time;
	sys_time.tv_sec  = raw_time;
	sys_time.tv_nsec = 0;

	int result = clock_settime(CLOCK_REALTIME, &sys_time);
	return (result == 0);
#endif
#endif

#ifdef PLATFORM_WIN32
	SYSTEMTIME systime;
	systime.wYear	= time.year;
	systime.wMonth	= time.month;
	systime.wDay	= time.day;
	systime.wHour	= time.hour;
	systime.wMinute	= time.minute;
	systime.wSecond	= time.second;
	systime.wDayOfWeek = 0;
	systime.wMilliseconds = 0;
	return SetLocalTime( &systime );
#endif
}


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
 
Read Message
Read Message
Read Message
Previous Topic: Crash on Cout with MSC15
Next Topic: Problem with FreeBSD
Goto Forum:
  


Current Time: Wed Mar 03 16:23:32 CET 2021

Total time taken to generate the page: 0.01399 seconds