-
Notifications
You must be signed in to change notification settings - Fork 63
/
ExampleServerTestApp.scala
70 lines (59 loc) · 2.34 KB
/
ExampleServerTestApp.scala
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
package com.thenewmotion.ocpp
package json
package example
import java.time.Instant
import scala.concurrent.ExecutionContext.Implicits.global
import scala.io.Source
import api._
import com.thenewmotion.ocpp.messages.v20._
object ExampleServerTestApp extends App {
val server = new Ocpp20JsonServer(2345) {
override def handleConnection(chargePointIdentity: String, conn: Ocpp20JsonServer.OutgoingEndpoint): CsmsRequestHandler = {
conn.onClose.foreach(_ => println(s"Disconnected client $chargePointIdentity"))
{
(req: CsmsRequest) =>
println(s"Received request $req from client $chargePointIdentity")
(req match {
case req: HeartbeatRequest => HeartbeatResponse(currentTime = Instant.now())
case req: TransactionEventRequest if req.idToken.exists(_.idToken == "04EC2CC2552281") =>
TransactionEventResponse(
totalCost = None,
chargingPriority = None,
idTokenInfo = Some(IdTokenInfo(
status = AuthorizationStatus.Blocked,
cacheExpiryDateTime = None,
chargingPriority = None,
groupIdToken = None,
language1 = None,
language2 = None,
personalMessage = None
)),
updatedPersonalMessage = None
)
case req: TransactionEventRequest =>
TransactionEventResponse(
totalCost = None,
chargingPriority = None,
idTokenInfo = Some(IdTokenInfo(
status = AuthorizationStatus.Accepted,
cacheExpiryDateTime = None,
chargingPriority = None,
groupIdToken = None,
language1 = None,
language2 = None,
personalMessage = None
)),
updatedPersonalMessage = None
)
case req: StatusNotificationRequest => StatusNotificationResponse()
case _ =>
throw OcppException(PayloadErrorCode.NotImplemented, "Request type not implemented")
}): CsmsResponse
}
}
}
server.start()
println("Example server listening at port 2345. Press ENTER to exit.")
Source.stdin.bufferedReader.readLine()
server.stop()
}