Origin commit data
------------------
Branch: master
Commit: 0bbcfaf171
Author: max_10 <max_10@gmx.de>
Date: 2015-11-10 (Tue, 10 Nov 2015)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
max_10
2015-11-10 00:00:04 +01:00
parent f702f386e4
commit 68227f5297
7 changed files with 270 additions and 96 deletions

View File

@@ -1,8 +1,13 @@
/* DVB CI DateTime Manager */
#include <stdio.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include <time.h>
#include "dvbci_datetimemgr.h"
static const char * FILENAME = "[dvbci_datetimemgr]";
eDVBCIDateTimeSession::eDVBCIDateTimeSession(tSlot *tslot)
{
slot = tslot;
@@ -46,8 +51,30 @@ int eDVBCIDateTimeSession::doAction()
return 0;
case stateSendDateTime:
{
struct tm tm_gmt;
struct tm tm_loc;
unsigned char tag[3] = {0x9f, 0x84, 0x41}; // date_time_response
unsigned char msg[7] = {0, 0, 0, 0, 0, 0, 0};
printf("%s -> %s\n", FILENAME, __FUNCTION__);
time_t t = time(NULL);
if ( gmtime_r(&t, &tm_gmt) && localtime_r(&t, &tm_loc) )
{
int Y = tm_gmt.tm_year;
int M = tm_gmt.tm_mon + 1;
int D = tm_gmt.tm_mday;
int L = (M == 1 || M == 2) ? 1 : 0;
int MJD = 14956 + D + (int)((Y - L) * 365.25) + (int)((M + 1 + L * 12) * 30.6001);
#define DEC2BCD(d) (((d / 10) << 4) + (d % 10))
msg[0] = htons(MJD) >> 8;
msg[1] = htons(MJD) & 0xff;
msg[2] = DEC2BCD(tm_gmt.tm_hour);
msg[3] = DEC2BCD(tm_gmt.tm_min);
msg[4] = DEC2BCD(tm_gmt.tm_sec);
msg[5] = htons(tm_loc.tm_gmtoff / 60) >> 8;
msg[6] = htons(tm_loc.tm_gmtoff / 60) & 0xff;
}
sendAPDU(tag, msg, 7);
return 0;
}