|
11 | 11 |
|
12 | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s, %d: " fmt, __func__, __LINE__ |
13 | 13 |
|
| 14 | +#include <linux/bcd.h> |
14 | 15 | #include <linux/crc32.h> |
15 | 16 | #include <linux/kernel.h> |
| 17 | +#include <linux/ktime.h> |
16 | 18 | #include <linux/printk.h> |
17 | 19 | #include <linux/ratelimit.h> |
18 | 20 | #include <linux/slab.h> |
19 | 21 | #include <linux/string.h> |
20 | 22 | #include <linux/string.h> |
| 23 | +#include <linux/time.h> |
21 | 24 | #include <linux/types.h> |
22 | 25 |
|
23 | 26 | #include "vidtv_common.h" |
@@ -1953,16 +1956,51 @@ u32 vidtv_psi_eit_write_into(struct vidtv_psi_eit_write_args args) |
1953 | 1956 | struct vidtv_psi_table_eit_event |
1954 | 1957 | *vidtv_psi_eit_event_init(struct vidtv_psi_table_eit_event *head, u16 event_id) |
1955 | 1958 | { |
1956 | | - const u8 DURATION_ONE_HOUR[] = {1, 0, 0}; |
| 1959 | + const u8 DURATION[] = {0x23, 0x59, 0x59}; /* BCD encoded */ |
1957 | 1960 | struct vidtv_psi_table_eit_event *e; |
| 1961 | + struct timespec64 ts; |
| 1962 | + struct tm time; |
| 1963 | + int mjd, l; |
| 1964 | + __be16 mjd_be; |
1958 | 1965 |
|
1959 | 1966 | e = kzalloc(sizeof(*e), GFP_KERNEL); |
1960 | 1967 | if (!e) |
1961 | 1968 | return NULL; |
1962 | 1969 |
|
1963 | 1970 | e->event_id = cpu_to_be16(event_id); |
1964 | | - memset(e->start_time, 0xff, sizeof(e->start_time)); //todo: 0xff means 'unspecified' |
1965 | | - memcpy(e->duration, DURATION_ONE_HOUR, sizeof(e->duration)); //todo, default to this for now |
| 1971 | + |
| 1972 | + ts = ktime_to_timespec64(ktime_get_real()); |
| 1973 | + time64_to_tm(ts.tv_sec, 0, &time); |
| 1974 | + |
| 1975 | + /* Convert date to Modified Julian Date - per EN 300 468 Annex C */ |
| 1976 | + if (time.tm_mon < 2) |
| 1977 | + l = 1; |
| 1978 | + else |
| 1979 | + l = 0; |
| 1980 | + |
| 1981 | + mjd = 14956 + time.tm_mday; |
| 1982 | + mjd += (time.tm_year - l) * 36525 / 100; |
| 1983 | + mjd += (time.tm_mon + 2 + l * 12) * 306001 / 10000; |
| 1984 | + mjd_be = cpu_to_be16(mjd); |
| 1985 | + |
| 1986 | + /* |
| 1987 | + * Store MJD and hour/min/sec to the event. |
| 1988 | + * |
| 1989 | + * Let's make the event to start on a full hour |
| 1990 | + */ |
| 1991 | + memcpy(e->start_time, &mjd_be, sizeof(mjd_be)); |
| 1992 | + e->start_time[2] = bin2bcd(time.tm_hour); |
| 1993 | + e->start_time[3] = 0; |
| 1994 | + e->start_time[4] = 0; |
| 1995 | + |
| 1996 | + /* |
| 1997 | + * TODO: for now, the event will last for a day. Should be |
| 1998 | + * enough for testing purposes, but if one runs the driver |
| 1999 | + * for more than that, the current event will become invalid. |
| 2000 | + * So, we need a better code here in order to change the start |
| 2001 | + * time once the event expires. |
| 2002 | + */ |
| 2003 | + memcpy(e->duration, DURATION, sizeof(e->duration)); |
1966 | 2004 |
|
1967 | 2005 | e->bitfield = cpu_to_be16(RUNNING << 13); |
1968 | 2006 |
|
|
0 commit comments