Class: Ucp::Pdu::UCPMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/ucp/pdu/ucpmessage.rb

Direct Known Subclasses

UCP01, UCP30, UCP31, UCP5x, UCP60, UCP61, UcpOperation, UcpResult

Constant Summary collapse

DELIMITER =
"/"
STX =
2.chr
ETX =
3.chr

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUCPMessage

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

#dcsObject (readonly)

Returns the value of attribute dcs.



36
37
38
# File 'lib/ucp/pdu/ucpmessage.rb', line 36

def dcs
  @dcs
end

#message_refObject (readonly)

Returns the value of attribute message_ref.



37
38
39
# File 'lib/ucp/pdu/ucpmessage.rb', line 37

def message_ref
  @message_ref
end

#operationObject (readonly)

@@trn=“00”



33
34
35
# File 'lib/ucp/pdu/ucpmessage.rb', line 33

def operation
  @operation
end

#operation_typeObject (readonly)

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_nrObject (readonly)

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_partsObject (readonly)

Returns the value of attribute total_parts.



37
38
39
# File 'lib/ucp/pdu/ucpmessage.rb', line 37

def total_parts
  @total_parts
end

#trnObject

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)
  # The <checksum> is derived by the addition of all bytes of the header, data field separators
  # and data fields (i.e. all characters after the stx-character, up to and including the last “/”
  # before the checksum field). The 8 Least Significant Bits (LSB) of the result is then
  # represented as two printable characters.

  sum=0
  s.each_byte { |byte|
    sum+=byte
  }
  #return sprintf("%02x",sum)[-2,2]
  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

Returns:

  • (Boolean)


73
74
75
# File 'lib/ucp/pdu/ucpmessage.rb', line 73

def is_ack?
  return @h.has_key?(:ack)
end

#is_nack?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/ucp/pdu/ucpmessage.rb', line 77

def is_nack?
  return @h.has_key?(:nack)
end

#is_operation?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ucp/pdu/ucpmessage.rb', line 65

def is_operation?
  return @operation_type=="O"
end

#is_result?Boolean

Returns:

  • (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_sObject



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