Class: Ocpp::Rails::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
app/services/ocpp/rails/message_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(charge_point, raw_message) ⇒ MessageHandler

Returns a new instance of MessageHandler.



6
7
8
9
# File 'app/services/ocpp/rails/message_handler.rb', line 6

def initialize(charge_point, raw_message)
  @charge_point = charge_point
  @raw_message = raw_message
end

Instance Attribute Details

#charge_pointObject (readonly)

Returns the value of attribute charge_point.



4
5
6
# File 'app/services/ocpp/rails/message_handler.rb', line 4

def charge_point
  @charge_point
end

#raw_messageObject (readonly)

Returns the value of attribute raw_message.



4
5
6
# File 'app/services/ocpp/rails/message_handler.rb', line 4

def raw_message
  @raw_message
end

Instance Method Details

#processObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/ocpp/rails/message_handler.rb', line 11

def process
  parsed = Protocol.parse(raw_message)

  case parsed[:type]
  when "CALL"
    handle_call(parsed)
  when "CALLRESULT"
    handle_callresult(parsed)
  when "CALLERROR"
    handle_callerror(parsed)
  when "PARSE_ERROR"
    log_error("Failed to parse message: #{parsed[:error]}")
    send_callerror(SecureRandom.uuid, "FormationViolation", "Invalid JSON format")
  when "UNKNOWN"
    log_error("Unknown message type: #{parsed[:raw]}")
    send_callerror(SecureRandom.uuid, "ProtocolError", "Unknown message type")
  end
rescue => e
  send_internal_error(parsed && parsed[:message_id], e, "Error processing message")
end