Modify README and add comments for some cryptic methods

develop
Guillaume DOTT 2013-09-12 10:35:13 +02:00
parent 550a2b4d3d
commit be53921802
5 changed files with 36 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# Biju
[WIP] Biju is an easy way to mount a GSM modem to send, to receive and to delete messages through a ruby interface.
Biju is an easy way to mount a GSM modem to send, to receive and to delete messages through a ruby interface.
This is project is based on this [code snippet](http://dzone.com/snippets/send-and-receive-sms-text).
## Installation
@ -20,19 +20,22 @@ Or install it yourself as:
## Usage
```
@modem = Biju::Modem.new(:port => "/dev/tty.HUAWEIMobile-Modem")
modem = Biju::Hayes.new('/dev/tty.HUAWEIMobile-Modem', pin: '0000')
# method to list all messages
@modem.messages.each do |sms|
# it can take the status in argument
# :unread, :read, :unsent, :sent, :all
modem.messages.each do |sms|
puts sms
end
# method to send sms
sms = Biju::Sms.new(:phone_number => '+3312345678', :message => 'hello world')
@modem.send(sms)
sms = Biju::Sms.new(phone_number: '+3312345678', message: 'hello world')
modem.send(sms)
@modem.close
modem.close
```
## TODO
1. Write missing test for modem module.

View File

@ -26,6 +26,10 @@ module Biju
extended_error
end
def close
modem.close
end
def at_command(cmd = nil, *args, &block)
command = ['AT', cmd].compact.join
command_args = args.compact.to_hayes

View File

@ -35,14 +35,22 @@ module Biju
string.scan(/../).map(&:hex).each_with_index do |octet, i|
index = i % 7
# Only keep the bits for the current character and
# add relevant bits from the previous octet
# to get the full septet and decode the current character
current = ((octet & (2 ** (7 - index) - 1)) << index) | next_char
res = add_char(res, current)
current_length += 1
# Break when the number of septet is reached
# to prevent to add a last @ when there is 7 septets.
# The last octet will have one more septet to ignore.
break if length > 0 && current_length >= length
# Get the relevant bits for the next character
next_char = octet >> (7 - index)
# When index is 6, next_char contains a full septet
if index == 6
res = add_char(res, next_char)
current_length += 1
@ -58,6 +66,9 @@ module Biju
length = 0
string.chars.each do |char|
# Look for the current character in basic character set and
# extension and concatenate the reversed septets to get
# full octets
if get_septet(char)
res << get_septet(char).reverse
length += 1
@ -67,9 +78,11 @@ module Biju
length += 2
end
end
# Add necessary bits to get a full octet
res << ('0' * (8 - (res.length % 8))) unless res.length % 8 == 0
[
# Group by octet, reverse them and print them in hex
res.scan(/.{8}/).map { |octet| '%02x' % octet.reverse.to_i(2) }.join,
length: length,
]

View File

@ -21,6 +21,7 @@ module Biju
end
def length
# If the last character is 0xF, remove this one from length
number.length - (number[-2, 2].hex >> 4 == 15 ? 1 : 0)
end
end

View File

@ -1,3 +1,5 @@
require 'date'
module Biju
module PDU
class Timestamp
@ -8,13 +10,19 @@ module Biju
end
def timezone
# The last 2 digits of the timestamp are for the timezone
timezone = timestamp[-2, 2].reverse.hex
# The MSB define the plus-minus sign. 0 for +, 1 for -
sign = (timezone >> 7 == 0 ? '+' : '-')
# The following 3 bits represent tens digit
# and the last 4 bits are for the units digit
tens_digit = ((timezone & 0b01110000) >> 4)
units_digit = (timezone & 0b00001111)
sign << '%02d' % ((tens_digit * 10 + units_digit) / 4)
# Timezone is in quarters of an hour
sign << '%02d' % ((tens_digit * 10 + units_digit) / 4)
end
def to_datetime