Class: Empp::EmppParser

Inherits:
Object
  • Object
show all
Defined in:
lib/empp/empp_parser.rb

Constant Summary collapse

@@logger =
EmppLogger.instance

Class Method Summary collapse

Class Method Details

.logger=(logger) ⇒ Object



18
19
20
# File 'lib/empp/empp_parser.rb', line 18

def self.logger=(logger)
  @@logger = logger
end

.parseBody(object, body) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/empp/empp_parser.rb', line 64

def self.parseBody(object, body)
  @@logger.debug("Enter EmppParser:: parse body")
  case object.command_id
  when Constants::EMPP_CONNECT_RESP
    parseConnectResp(object, body)
  
  # no need to process active_test resp
  #when Constants::EMPP_ACTIVE_TEST_RESP
  # ;
  when Constants::EMPP_SUBMIT_RESP
    parseSubmitResp(object, body)
  
  when Constants::EMPP_DELIVER
    parseEmppDeliver(object, body)
  end # end case
  @@logger.debug("Leave EmppParser parse body")
end

.parseConnectResp(object, body) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/empp/empp_parser.rb', line 82

def self.parseConnectResp(object, body)
  sio = StringIO.new(body)
  status = ''
  sio.read(4, status)
  status = BinData::Uint32be.read(status)
  object.status = status
end

.parseDeliveryState(content) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/empp/empp_parser.rb', line 147

def self.parseDeliveryState(content)
  @@logger.debug("Enter EmppParser::parseDeliveryState")

  @@logger.debug("EmppParser::parseDeliveryState content=#{content}")
  sio = StringIO.new(content)
  msg_id = sio.read(10)
  state = sio.read(7)
  submit_time = sio.read(10)
  done_time = sio.read(10)
  dest_terminal_id = sio.read(32)
  dest_terminal_id = dest_terminal_id.unpack("A*")[0] # delete tailing zeros
  sequence_id = sio.read(4)
  sequence_id = BinData::Uint32be.read(sequence_id)

  deliveryState = DeliveryState.new
  deliveryState.msg_id = msg_id
  deliveryState.state = state
  deliveryState.submit_time = submit_time
  deliveryState.done_time = done_time
  deliveryState.dest_terminal_id = dest_terminal_id
  deliveryState.sequence_id = sequence_id
  @@logger.debug("mppParser::parseDeliveryState get Object=#{deliveryState}")

  @@logger.debug("LeaveEmppParser::parseDeliveryState")
  deliveryState
end

.parseEmppDeliver(object, body) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/empp/empp_parser.rb', line 106

def self.parseEmppDeliver(object, body)
  @@logger.debug("Enter EmppParser::parseEmppDeliver")
  @@logger.debug("EmppParser::parseEmppDeliver object=#{object}")

  sio = StringIO.new(body)
  tmpVal = ''
  msg_id = sio.read(10)
  dest_id = sio.read(21)
  service_id = sio.read(10)

  sio.read(2)

  msg_fmt = sio.read(1)
  msg_fmt = msg_fmt[0] # 1 byte integer

  src_terminal_id = sio.read(32)
  src_terminal_id = src_terminal_id.unpack("A*")[0] # delete trailing zeros
  src_terminal_id = Utils::Utils.deal_with_terminal_id(src_terminal_id)
  
  sio.read(1)

  registered_delivery = sio.read(1)
  registered_delivery = registered_delivery[0]

  msg_length = sio.read(1)
  msg_length = msg_length[0]

  msg_content = sio.read(msg_length)

  object.msg_id = msg_id
  object.dest_id = dest_id
  object.service_id = service_id
  object.msg_format = msg_fmt
  object.src_terminal_id = src_terminal_id
  object.msg_length = msg_length
  object.msg_content = msg_content
  object.registered_delivery = registered_delivery

  @@logger.debug("Leave EmppParser::parseEmppDeliver")
end

.parseHeader(header) ⇒ Object



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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/empp/empp_parser.rb', line 22

def self.parseHeader(header)

  sio = StringIO.new(header)

  total_length = ''
  sio.read(4, total_length)
  total_length = BinData::Uint32be.read(total_length)

  command_id = ''
  sio.read(4, command_id)
  command_id = BinData::Uint32be.read(command_id)

  sequence_id = ''
  sio.read(4, sequence_id)
  sequence_id = BinData::Uint32be.read(sequence_id)

  object = nil

  case command_id
  when Constants::EMPP_CONNECT_RESP
    object = MsgConnectResp.new

  when Constants::EMPP_ACTIVE_TEST_RESP
    object = MsgActiveTestResp.new

  when Constants::EMPP_SUBMIT_RESP
    object = MsgSubmitResp.new

  when Constants::EMPP_DELIVER
    object = MsgDelivery.new
  else
    object = EmppBase.new
    object.command_id = -1
  end # end case

  object.total_length = total_length
  object.sequence_id = sequence_id

  object

end

.parseSubmitResp(object, body) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/empp/empp_parser.rb', line 90

def self.parseSubmitResp(object, body)
  @@logger.debug("Enter EmppParser::parseSubmitResp")
  @@logger.debug("EmppParser parseSubmitResp object=#{object}")

  sio = StringIO.new(body)
  status = ''
  msg_id = sio.read(10)
  sio.read(4, status)
  status = BinData::Uint32be.read(status)

  object.msg_id = msg_id
  object.status = status

  @@logger.debug("Leave EmppParser::parseSubmitResp")
end