X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=perl%2FDevice%2FNokia.pm;fp=perl%2FDevice%2FNokia.pm;h=5a589142ed999d041d58ebb8888261e464576f21;hp=0000000000000000000000000000000000000000;hb=deb5077783ff39fea9f1712cbfb3c1380ab0a4c8;hpb=b6c6ce582390d8fce9324f955fa56db18e1c0b67 diff --git a/perl/Device/Nokia.pm b/perl/Device/Nokia.pm new file mode 100755 index 0000000..5a58914 --- /dev/null +++ b/perl/Device/Nokia.pm @@ -0,0 +1,119 @@ +# Device::Nokia +# Author: Tim Pope + +# A Perl class to interface GSM devices as AT modems +# Basically just a few enhancements to Device::Gsm + +package Device::Nokia; +$Device$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; + +use strict; +use Device::Gsm; + +@Device::Nokia::ISA = ('Device::Gsm'); + +# +# Who is the manufacturer of this device? +# +sub manufacturer() { + my $self = shift; + my($ok, $man); + + # Test if manufacturer code command is supported + if( $self->test_command('+CGMI') ) { + + $self->atsend( 'AT+CGMI' . Device::Modem::CR ); + ($ok, $man) = $self->parse_answer(); + + $self->log->write('info', 'manufacturer of this device appears to be ['.$man.']'); + + } + + return $man || $ok; + +} +# +# What is the model of this device? +# +sub model() { + my $self = shift; + my($code, $model); + + # Test if manufacturer code command is supported + if( $self->test_command('+CGMM') ) { + + $self->atsend( 'AT+CGMM' . Device::Modem::CR ); + ($code, $model) = $self->parse_answer(); + + $self->log->write('info', 'model of this device is ['.$model.']'); + + } + + return $model || $code; +} + +# +# Get mobile phone indicators +# +sub indicators() { + my $self = shift; + my($supported,$values,%results); + + # Test if manufacturer code command is supported + if( $self->test_command('+CIND') ) { + $self->atsend( 'AT+CIND=?' . Device::Modem::CR ); + ($_, $supported) = $self->parse_answer(); + $supported =~ s/^\+CIND: //; + $self->atsend( 'AT+CIND?' . Device::Modem::CR ); + ($_, $values) = $self->parse_answer(); + $values =~ s/^\+CIND: //; + #@values = split (/,/, $values); + foreach (split (/,/, $values)) { + $supported =~ s/\("([^"]*)",\([^)]*\)\),?//; + $results{$1} = $_; + } + $self->log->write('info', 'Indicator data retrieved (' . scalar(keys(%results)) . 'values)'); + + } + return %results; +} + +# +# Get mobile phone battery strength +# +sub battery_strength() { + my $self = shift; + # Error code, dBm (signal power), bit error rate + my($code, $strength, $line_power); + + # Test if signal quality command is implemented + if( $self->test_command('+CBC') ) { + + $self->atsend( 'AT+CBC' . Device::Modem::CR ); + ($code, $strength) = $self->parse_answer(); + + if( $strength =~ /\+CBC: (\d+),(\d+)/ ) { + + ($line_power, $strength) = ($1, $2); + + $self->log->write('info', 'battery strength is ['.$strength.'], line power ['.$line_power.']'); + + } else { + + $self->log->write('warn', 'cannot obtain battery strength'); + + } + + } else { + + $self->log->write('warn', 'battery strength command not supported!'); + + } + + return wantarray ? ($line_power, $strength) : $strength; + +} + +1; + +__END__