… | |
… | |
30 | package Linux::DVB; |
30 | package Linux::DVB; |
31 | |
31 | |
32 | use Fcntl (); |
32 | use Fcntl (); |
33 | |
33 | |
34 | BEGIN { |
34 | BEGIN { |
35 | $VERSION = '0.3'; |
35 | $VERSION = '0.4'; |
36 | @ISA = qw(Exporter); |
36 | @ISA = qw(Exporter); |
37 | |
37 | |
38 | require XSLoader; |
38 | require XSLoader; |
39 | XSLoader::load __PACKAGE__, $VERSION; |
39 | XSLoader::load __PACKAGE__, $VERSION; |
40 | |
40 | |
… | |
… | |
448 | 0x2 => 'unpublished', |
448 | 0x2 => 'unpublished', |
449 | 0x3 => 'live broadcast', |
449 | 0x3 => 'live broadcast', |
450 | }, |
450 | }, |
451 | ); |
451 | ); |
452 | |
452 | |
|
|
453 | =item ($sec,$min,$hour) = Linux::DVB::Decode::time $hms |
|
|
454 | |
|
|
455 | =item ($mday,$mon,$year) = Linux::DVB::Decode::date $mjd |
|
|
456 | |
453 | =item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::time $mjd, $time |
457 | =item ($sec,$min,$hour,$mday,$mon,$year) = Linux::DVB::Decode::datetime $mjd, $hms |
|
|
458 | |
|
|
459 | =item $sec = Linux::DVB::Decode::time_linear $hms |
|
|
460 | |
|
|
461 | =item $sec = Linux::DVB::Decode::datetime_linear $mjd, $hms |
454 | |
462 | |
455 | Break down a "DVB time" (modified julian date + bcd encoded seconds) into |
463 | Break down a "DVB time" (modified julian date + bcd encoded seconds) into |
456 | it's components in UTC (i.e. use Time::Local::timegm to convert to UNIX |
464 | it's components (non-C<_linear>) or into a seconds count (C<_linear> |
457 | time). |
465 | variants) since the epoch (C<datetime_linear>) or the start of the day |
|
|
466 | (C<time_linear>). |
458 | |
467 | |
459 | =cut |
468 | The format of the returns value of the date and datetime functions is |
|
|
469 | I<not> compatible with C<Time::Local>. Use the C<_linear> functions |
|
|
470 | instead. |
460 | |
471 | |
|
|
472 | Example: |
|
|
473 | |
|
|
474 | my $time = Linux::DVB::Decode::datetime_linear $mjd, $hms |
|
|
475 | printf "Starts at %s\n", |
|
|
476 | POSIX::strftime "%Y-%m-%d %H:%M:%S", |
|
|
477 | localtime $time; |
|
|
478 | |
|
|
479 | =cut |
|
|
480 | |
461 | sub time($$) { |
481 | sub time($) { |
462 | my ($mjd, $time) = @_; |
482 | my ($time) = @_; |
|
|
483 | |
|
|
484 | # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left |
|
|
485 | my $hour = sprintf "%02x", ($time >> 16) & 0xFF; |
|
|
486 | my $minute = sprintf "%02x", ($time >> 8) & 0xFF; |
|
|
487 | my $second = sprintf "%02x", ($time ) & 0xFF; |
|
|
488 | |
|
|
489 | ($second, $minute, $hour) |
|
|
490 | } |
|
|
491 | |
|
|
492 | sub date($) { |
|
|
493 | my ($mjd) = @_; |
463 | |
494 | |
464 | # Date is given in Modified Julian Date |
495 | # Date is given in Modified Julian Date |
465 | # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) |
496 | # Decoding routines taken from ANNEX C, ETSI EN 300 468 (DVB SI) |
466 | my $y_ = int ($mjd - 15078.2) / 365.25; |
497 | my $y_ = int (($mjd - 15078.2) / 365.25); |
467 | my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); |
498 | my $m_ = int (($mjd - 14956.1 - int ($y_ * 365.25)) / 30.6001); |
468 | my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); |
499 | my $day = $mjd - 14956 - int ($y_ * 365.25) - int ($m_ * 30.6001); |
469 | my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; |
500 | my $k = $m_ == 14 or $m_ == 15 ? 1 : 0; |
470 | my $year = $y_ + $k + 1900; |
501 | my $year = $y_ + $k + 1900; |
471 | my $month = $m_ - 1 - $k * 12; |
502 | my $month = $m_ - 1 - $k * 12; |
472 | |
503 | |
473 | # Time is in UTC, 24 bit, every nibble one digit in BCD from right to left |
504 | ($day, $month, $year) |
474 | my $hour = sprintf "%02x", ($time >> 16) & 0xFF; |
505 | } |
475 | my $minute = sprintf "%02x", ($time >> 8) & 0xFF; |
|
|
476 | my $second = sprintf "%02x", ($time ) & 0xFF; |
|
|
477 | |
506 | |
|
|
507 | sub datetime($$) { |
|
|
508 | (Linux::DVB::Decode::time $_[1], date $_[0]) |
|
|
509 | } |
|
|
510 | |
|
|
511 | sub time_linear($) { |
|
|
512 | my ($s, $m, $h) = Linux::DVB::Decode::time $_[0]; |
|
|
513 | |
|
|
514 | (($h * 60) + $m * 60) + $s |
|
|
515 | } |
|
|
516 | |
|
|
517 | sub datetime_linear($$) { |
478 | return ($second, $minute, $hour, $day, $month, $year); |
518 | my ($sec, $min, $hour, $mday, $mon, $year) = |
|
|
519 | Linux::DVB::Decode::datetime $_[0], $_[1]; |
|
|
520 | |
|
|
521 | require Time::Local; |
|
|
522 | Time::Local::timegm ($sec, $min, $hour, $mday, $mon - 1, $year) |
479 | } |
523 | } |
480 | |
524 | |
481 | =back |
525 | =back |
482 | |
526 | |
483 | =head1 AUTHORS |
527 | =head1 AUTHORS |