NAME
GSM::Nbit - GSM 7bit and 8bit data encoder and decoder.
VERSION
Version 0.08
SYNOPSIS
GSM::Nbit
Throughout GSM world "special" encodings called 7bit and 8bit are used. Encoding in 8bit is just plain HEX value and is provided here for completeness and ease of use, 7bit packs 8bit data into 7bit HEX value by limiting it to the lower 127 characters - and hence gaining 1 extra char every 8 characters.
That's how you get 160 characters limit on plain text (ASCII + few Greek chars) messages with only 140 bytes for data.
Since many modules need such encodings in them, those functions are refactored here. It's released as separate module and not part of some other distribution exactly for that reason.
Code Sample
use
GSM::Nbit;
my
$gsm
= GSM::Nbit->new();
my
$txt
=
"some text"
;
# We need to encode it first - for details see:
my
$txt0338
= encode(
"gsm0338"
,
$txt
);
my
$txt_7bit
=
$gsm
->encode_7bit_wlen(
$txt
);
# ... we submit it to the GSM network
# ... latter we receive something from GSM network
my
$txt_gsm
=
$gsm
->decode_7bit_wlen(
$txt_7bit
);
# we need to decode it back to computer/Perl representation
my
$txt_orig
= decode(
"gsm0338"
,
$txt_gsm
);
METHODS
new
This is the constructor. Accepts no params.
encode_7bit
This function encodes the string as 7bit packed data in HEX representation. Please note that you probably need to convert the text into gsm0338 format first - we don't automatically do that.
For details see http://www.dreamfabric.com/sms/default_alphabet.html.
You can use Perl's Encode module for that - see: http://search.cpan.org/perldoc?Encode::GSM0338
encode_7bit_wlen
Beside encoding the string as 7bit packed data in HEX representation, this method also adds the length in front of the encoded string, it's needed in some GSM protocols as a kind of checksum and to help with certain edge cases.
decode_7bit
This function decodes the 7bit data in HEX representation back to a "readable" string. Second optional parameter is length - it's used in edge cases when we can't be sure if the last seven 0's in bit representation are meant to be @ sign, or it's a filler and there to just fit the 7bit representation into 8bit data computers (and cellphones) use.
Edge cases happen when length of original text is 7, 15, 23, 31 ... (+8) chars.
decode_7bit_wlen
This function decodes back to a "readable" text string the 7bit data in HEX representation that includes the length as the first value.
encode_8bit
This function encodes the string as 8bit HEX representation of the string.
encode_8bit_wlen
This function encodes the string as 8bit HEX representation of the string and also adds the length in front of the encoded string since it's needed in some GSM protocols as a kind of checksum.
decode_8bit
This function decodes back to a "readable" text string the 8bit HEX representation with length at the start of the string.
decode_8bit_wlen
This function decodes the 8bit HEX representation of the string back to readable text string.
INCOMPATIBILITIES
Note that you might need to update your Encode.pm module beforehand for tests to pass (and to be able to use this in a meaningful way) since older version had a bug for gsm0338 encode/decode of @ char.
AUTHOR
Aleksandar Petrovic, <techcode at cpan.org>
BUGS
Please report any bugs or feature requests to bug-gsm-nbit at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=GSM-Nbit. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc GSM::Nbit
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2010 Aleksandar Petrovic.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.