-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtcrelai.rb
83 lines (75 loc) · 2.61 KB
/
tcrelai.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
######################################################################################
# tcrelai.rb :
######################################################################################
#
# Serveur OcppTC Client OCppTC
# ------------------- --------------------
# | | | |
# Freshmile -----> |ARGV[0]:ARGV[1] |---> | ARGV[2]:ARGV[2]|--> Saia
# | | | |
# ------------------- --------------------
#
#
######################################################################################
require_relative 'server.rb' # serveur OcppTC
require_relative 'tc.rb' # client OcppTC
#============================================================
# Client TC : emule une supervision emetrice TC ==> borne
#============================================================
class ClientTC
def initialize(server)
puts "Client to #{server}..."
@server=server
@hto=server
@hfrom ="http://localhost:9090/ocpp"
end
def csend(cbi,cmd,args)
socket=PostSoapCp.new({
"HCHARGEBOXID"=> cbi,
"HMESSID" => "A%",
"HFROM" => @hfrom,
"HTO" => @hto
})
puts "#{'='*20} #{cmd}..."
estart=Time.now
response=socket.csend(@server,cmd,args)
eend=Time.now
puts "Request Timing: #{(eend.to_f-estart.to_f)*1000} ms \n\n\n"
response
end
end
#============================================================
# Server TC : emule une borne recevant une TC
#============================================================
class ServerTC
include AppliAbstract
def initialize(ip,port,client)
@client=client
@s=ServerSoapOcpp.new(self,{:ip=> ip, :port=> port})
p "server start..."
@s.start
p "server started !"
end
def clearCache(hpara)
[email protected](hpara['HCHARGEBOXID'],:clearCache)
end
def reset(hpara)
[email protected]( hpara['HCHARGEBOXID'],:reset,hpara)
end
def changeAvailability(hpara)
[email protected](hpara['HCHARGEBOXID'],:changeAvailability,hpara)
end
def unlockConnector(hpara)
[email protected](hpara['HCHARGEBOXID'],:unlockConnector,hpara)
end
def remoteStartTransaction(hpara)
[email protected](hpara['HCHARGEBOXID'],:remoteStartTransaction,hpara)
end
def remoteStopTransaction(hpara)
[email protected](hpara['HCHARGEBOXID'],:remoteStopTransaction ,hpara)
end
def wait() @s.join end
end
cli=ClientTC.new("http://#{ARGV[2]}:#{ARGV[3]}/ocpp")
sv=ServerTC.new(ARGV[0],ARGV[1],cli)
sv.wait