:pserver:anonymous@intra.tektonica.com:/opt/cvs - gsmperl - Fri Dec 21 07:37 CET...
[gsmperl.git] / GSM / SMS / OTA / Operatorlogo.pm
1 package GSM::SMS::OTA::Operatorlogo;
2 use GSM::SMS::OTA::Bitmap;
3
4 require  Exporter;
5 @ISA = qw(Exporter);
6  
7 @EXPORT = qw(   OTAOperatorlogo_makestream  
8                 OTAOperatorlogo_PORT    
9                 OTAOperatorlogo_fromb64
10                 OTAOperatorlogo_fromfile
11                 ); 
12
13 $VERSION = '0.1';
14
15 use constant OTAOperatorlogo_PORT => 5506;
16
17 sub OTAOperatorlogo_fromb64 {
18         my ($countrycode, $operatorcode, $b64, $format) = @_;
19
20         my $arr = OTABitmap_fromb64( $b64, $format );
21         return -1 if $arr == -1;
22
23         return OTAOperatorlogo_makestream( $countrycode, $operatorcode, 72, 14, 1, $arr ); 
24 }
25
26 sub OTAOperatorlogo_fromfile {
27         my ($countrycode, $operatorcode, $file) = @_;
28
29         my $arr = OTABitmap_fromfile( $file );
30         return -1 if $arr == -1;
31
32         return OTAOperatorlogo_makestream( $countrycode, $operatorcode, 72, 14, 1, $arr ); 
33 }
34
35
36 sub OTAOperatorlogo_makestream {
37         my ($countrycode, $operatorcode, $width, $height, $depth, $ref_bytearray) = @_;
38
39         my $stream;
40
41         $stream.= encodeOperatorID($countrycode, $operatorcode);
42         $stream.='00';  # Nokia stuff for validity period
43         $stream.=OTABitmap_makestream($width, $height, $depth, $ref_bytearray);
44
45         return $stream;
46 }
47
48 # encode the operator ID (country, operator) into a litlle endian BCD string
49 sub encodeOperatorID {
50         my ($country, $operator) = @_;
51
52         my $c = sprintf("%03d", $country);
53         my $o = sprintf("%02d", $operator);
54
55         my @arr = split /|/, sprintf("%03d%02d", $country, $operator);
56         my @enc;
57  
58         $enc[0] = ($arr[1] & 0x0F) << 4 | ($arr[0] & 0x0F);
59         $enc[1] = (0x0F << 4)           | ($arr[2] & 0x0F);
60         $enc[2] = ($arr[4] & 0x0F) << 4 | ($arr[3] & 0x0F);
61  
62         return join("", map { sprintf("%02X", $_) } @enc );
63
64
65 1;
66
67 =head1 NAME
68
69 GSM::SMS::OTA::Operatorlogo
70
71 =head1 DESCRIPTION
72
73 This package implements encoding of an Operatorlogo icon.
74
75 =head1 METHODS
76
77 =head2 OTAOperatorlogo_fromb64
78
79         $stream = OTAOperatorlogo_fromb64($countrycode, $operatorcode, $b64, $format);
80
81 Create a operator logo from a b64 encoded image in the specified format ( gif, png, ...). The countrycode and operator code are 2 codes that specfify either the operator or the country of the receiving handset.
82
83 =head2 OTAOperatorlogo_fromfile
84
85         $stream = OTAOperatorlogo_fromfile($countrycode, $operatorcode, $file );
86
87 Create a operator logo from a file.
88
89 =head2 OTAOperatorlogo_PORT
90
91 NSB Port number for Operator logos.
92
93 =head1 ISSUES
94
95 The country and operator coe have to be provided manually. It would be 
96 interesting to have other modules: GSM::SMS::Countrycode and GSM::SMS::OPeratorcode , that handle this automatically. Give them a msisdn and they provide you with the code.
97
98 =head1 AUTHOR
99
100 Johan Van den Brande <johan@vandenbrande.com>