modification sendDateTime

This commit is contained in:
max_10
2017-10-23 23:16:18 +02:00
parent 42811846d7
commit c41f0ea13d
2 changed files with 31 additions and 27 deletions

View File

@@ -48,37 +48,40 @@ int eDVBCIDateTimeSession::doAction()
case stateStarted: case stateStarted:
return 0; return 0;
case stateSendDateTime: case stateSendDateTime:
{ sendDateTime();
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; return 0;
}
case stateFinal: case stateFinal:
printf("stateFinal und action! kann doch garnicht sein ;)\n"); printf("stateFinal und action! kann doch garnicht sein ;)\n");
default: default:
return 0; return 0;
} }
} }
void eDVBCIDateTimeSession::sendDateTime()
{
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);
}

View File

@@ -13,6 +13,7 @@ class eDVBCIDateTimeSession: public eDVBCISession
public: public:
eDVBCIDateTimeSession(eDVBCISlot *tslot); eDVBCIDateTimeSession(eDVBCISlot *tslot);
~eDVBCIDateTimeSession(); ~eDVBCIDateTimeSession();
void sendDateTime();
}; };
#endif #endif