|
Home > Archive > Unix Programming > January 2007 > *nix date to PLC date and back
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
*nix date to PLC date and back
|
|
| CptDondo 2007-01-23, 1:23 pm |
| I am working on a project where my *nix box will talk to a PLC. (A PLC
is sort of a brain-damaged computer...)
The PLC in question returns the date in the following 6 byte sequence:
0 year (0-99) current year (BCD value)
1 month (1-12) current month (BCD value)
2 day (1-31) current day (BCD value)
3 hour (0-23) current hour (BCD value)
4 minute (0-59) current minute (BCD value)
5 second (0-59) current second (BCD value)
The year is assumed to start at 2000.
I need to convert this monster to a *nix type long int (32 bit) date and
back.
On the PLC I have a BCD to int conversion which will take byte-pairs and
covert them to 16 bit ints. I can multiply, divide, etc.
From this I need to build the *nix date....
I can't quite get my head around the conversion algorithm. Most
resources on the web use stuff like PERL and awk, none of which I have
available.
So.... Anyone know the algorithm for calculating the *nix date?
Thanks,
--Yan
| |
| John Gordon 2007-01-23, 8:03 pm |
| In <12rco513dfbhkf7@corp.supernews.com> CptDondo <yan@NsOeSiPnAeMr.com> writes:
> I need to convert this monster to a *nix type long int (32 bit) date and
> back.
Fill in a "struct tm" with the values from the PLC, then call mktime()
on it.
--
John Gordon "... What with you being his parents and all,
gordon@panix.com I think that you could be trusted not to shaft
him." -- Robert Chang, rec.games.board
|
|
|
|
|