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 next 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 );
}
Re: Since Raspberry have not RTC clock, I propose add SetTime functionality [message #47125 is a reply to message #47118] Thu, 15 December 2016 20:31 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 589
Registered: November 2008
Location: France
Contributor
Hello Sergey,

The RPI linux doesn't already do something to manage this ??
Re: Since Raspberry have not RTC clock, I propose add SetTime functionality [message #47126 is a reply to message #47125] Thu, 15 December 2016 20:49 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 741
Registered: January 2008
Location: Moscow, Russia
Contributor

RPI has no RTC (with an independent power supply) clock onboard.
Therefore the appropriate system call of setting of system clock leads to a procedure call of setting up of time on the real-time hardware clock. And as it's absent, the command is quietly ignored by system.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Fri, 16 December 2016 10:05]

Report message to a moderator

Previous Topic: Crash on Cout with MSC15
Next Topic: Problem with FreeBSD
Goto Forum:
  


Current Time: Thu Dec 03 15:09:40 CET 2020

Total time taken to generate the page: 0.01544 seconds