-
Notifications
You must be signed in to change notification settings - Fork 1
/
SMS.rb
executable file
·46 lines (38 loc) · 869 Bytes
/
SMS.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class SMS
attr_accessor :message, :udh, :from, :to, :pdu
def initialize(message = "", from = "", to = "")
@message, @from, @to = message, from, to
@udh = ""
end
def SMS.create_from_pdu(pdu, modemname = "")
sms = SMS.new
sms.message = IA5.decode(pdu.message)
sms.pdu = pdu
sms.udh = ""
if pdu.originator.nil?
sms.from = modemname
else
sms.from = pdu.originator
end
if pdu.destination.nil?
sms.to = modemname
else
sms.to = pdu.destination
end
return sms
end
def to_pdu
pdu = PDU.new
pdu.originator = @from
pdu.destination = @to
pdu.message = IA5.encode @message
return pdu
end
def xml
"<sms>" +
"<to>" + @to.nil? + "</to>" +
"<from>" + @from + "</from>" +
"<message>" + @message + "</message>" +
"</sms>\n"
end
end