Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 18915

Re: GetCurDateTime function - how is this?

$
0
0

hey UST_,

1) Edison is my first shot at embedded, I selected it because it was a dual core Intel atom processor with a quark (Pentium) mcu with a Linux OS  To me this meant, I could use the same tools I was use to programming Intel CPUs with.  I use the mini breakout board. I've never used Arduino, so I don't have that experience to relate to, and eclipse is, less than I desired, I didn't want to have to learn another language or another IDE - (just my personal preferences).  I like that edison has that flexibility.

2) for native language, I am personally programming in pascal using Kylix3, and some C using gcc - giving me the elf Linux format executables I need.  I accomplish much over ssh and an onboard editor and compile right on Edison.

3) My understanding was that the network time already updates the RTC, so when I boot, initiate the wifi connection, the time updates to the OS automatically, and I simply ask Linux to give me the time (which for me is in UTC).  Kylix gives me datetime as a float value, the integer part in days since Dec 30 1899, and the fractional part of the days.

For seconds today as integer x :=  trunc( fract (datetime) *86400); 
A formatted string s := FormatDateTime('YYYYMMDD.HHMMSS',now);

4) the question is how do you interface with the OS to run a system commands or executables in Arduino.

if you can tie into the gcc functions: (where gcc is already included in the Edison image)

 

#include <stdio.h>

#include <time.h>

 

void main() {

time_t t = time(NULL);

struct tm tm = *localtime(&t);

// if you need as an integer;

int secondstoday = tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec;

// when you need to print it as string

printf("%04d%02d%02d:%02d%02d%02d\n",tm.tm_year+1900,tm.tm_mon+1,tm.tm_mday,tm.tm_hour,tm.tm_min,tm.tm_sec);

// when you need to print it as an integer

printf("%d\n",secondstoday);

}

 

put that in a file testtime.c

gcc -o testtime testtime.c

./testtime

 

tm has the structure for your time elements year, month, day, hour, min, sec

 

Although Kylix has functions for me, in a worst case pickle, I'd be able to call libc.System(PChar('./testtime > tmpfile'));

and then read an executable's output from the tmpfile -- I imagined Arduino has to have something of the same.

  -- I now understand that arduino has a system("commandlinetorun");

 

Update: after the network time has updated the system time you can push that to the rtc using the command line hwclock --systohc.

after that you can check on your rtc status by reading the file /proc/driver/rtc  using cat /proc/driver/rtc


Viewing all articles
Browse latest Browse all 18915

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>