Class: Ucp::Pdu::UCPMessage
- Inherits:
-
Object
- Object
- Ucp::Pdu::UCPMessage
show all
- Defined in:
- lib/ucp/pdu/ucpmessage.rb
Constant Summary
collapse
- DELIMITER =
"/"
- STX =
2.chr
- ETX =
3.chr
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
usado pelas classes que o extendem
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 40
def initialize()
@dcs="01"
@trn="00"
@fields=[]
@h=Hash.new
@message_ref=0
@part_nr=1
@total_parts=1
end
|
Instance Attribute Details
#dcs ⇒ Object
Returns the value of attribute dcs.
36
37
38
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 36
def dcs
@dcs
end
|
#message_ref ⇒ Object
Returns the value of attribute message_ref.
37
38
39
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 37
def message_ref
@message_ref
end
|
#operation ⇒ Object
33
34
35
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 33
def operation
@operation
end
|
#operation_type ⇒ Object
Returns the value of attribute operation_type.
34
35
36
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 34
def operation_type
@operation_type
end
|
#part_nr ⇒ Object
Returns the value of attribute part_nr.
37
38
39
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 37
def part_nr
@part_nr
end
|
#total_parts ⇒ Object
Returns the value of attribute total_parts.
37
38
39
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 37
def total_parts
@total_parts
end
|
#trn ⇒ Object
Returns the value of attribute trn.
35
36
37
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 35
def trn
@trn
end
|
Instance Method Details
#checksum(s) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 81
def checksum(s)
sum=0
s.each_byte { |byte|
sum+=byte
}
return sum.to_s(16)[-2,2].upcase
end
|
#get_field(field) ⇒ Object
52
53
54
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 52
def get_field(field)
return @h[field]
end
|
#is_ack? ⇒ Boolean
73
74
75
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 73
def is_ack?
return @h.has_key?(:ack)
end
|
#is_nack? ⇒ Boolean
77
78
79
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 77
def is_nack?
return @h.has_key?(:nack)
end
|
#is_operation? ⇒ Boolean
65
66
67
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 65
def is_operation?
return @operation_type=="O"
end
|
#is_result? ⇒ Boolean
69
70
71
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 69
def is_result?
return @operation_type=="R"
end
|
#length(s) ⇒ Object
95
96
97
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 95
def length(s)
return sprintf("%05d",s.length+16)
end
|
#set_field(field, value) ⇒ Object
56
57
58
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 56
def set_field(field,value)
@h[field]=value
end
|
#set_fields(ucpfields = {}) ⇒ Object
60
61
62
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 60
def set_fields(ucpfields={})
@h=@h.merge ucpfields
end
|
#to_s ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/ucp/pdu/ucpmessage.rb', line 99
def to_s
s=""
@fields.each{ |key|
value=@h[key]
if value.nil?
s+=DELIMITER
else
s+=value.to_s+DELIMITER
end
}
pdu=@trn+DELIMITER
pdu+=length(s)+DELIMITER
pdu+=@operation_type+DELIMITER
pdu+=@operation+DELIMITER
pdu+=s
pdu+=checksum(pdu)
pdu=STX+pdu+ETX
return pdu
end
|