Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #75 from w3c/rl-integration
Browse files Browse the repository at this point in the history
Rl integration
  • Loading branch information
UlfBj authored Nov 1, 2023
2 parents 1c00076 + 512d5c6 commit 138fa8e
Show file tree
Hide file tree
Showing 24 changed files with 685 additions and 102 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ logs/
.gitignore
***workspace.code-workspace
***.vscode
/client/client-1.0/grpc_client/grpc_map_client/static/node_modules/
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#
# All files and artifacts in the repository at https://github.com/w3c/automotive-vissv2
# are licensed under the provisions of the license provided by the LICENSE file in this repository.
# To run with redis as state storage use docker compose. This can be used to build individual images but will not
# run.

ARG GO_VERSION=1.18
ARG VSSTREE_NAME="vss_vissv2.binary"
ARG BUILD_IMAGE="golang:latest"
Expand Down
38 changes: 0 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,6 @@ The master branch is a fork from the single-process branch.

### Using Docker-Compose to launch a W3CServer instance

The W3C server can also be built and launched using docker and docker-compose please follow below links to install docker and docker-compose

https://docs.docker.com/install/linux/docker-ce/ubuntu/
https://docs.docker.com/compose/install/

to launch use

```bash
$ docker compose -f docker-compose.yml build
...
=> => exporting layers 0.1s
=> => writing image sha256:f392918448ece4b26b5c430ffc53c5f2da8872d030c11a22b42360dbf9676934 0.0s
=> => naming to docker.io/library/automotive-viss2-feeder
```

```bash
$ docker compose -f docker-compose.yml up
✔ Container container_volumes Created 0.0s
✔ Container vissv2server Created 0.0s
✔ Container app_redis Created 0.0s
✔ Container feeder Recreated 0.1s
Attaching to app_redis, container_volumes, feeder, vissv2server
```
to stop use

```bash
$ docker-compose down
✔ Container vissv2server Stopped 0.2s
✔ Container app_redis Stopped 0.2s
✔ Container feeder Stopped 0.1s
✔ Container container_volumes Stopped
```

if server needs to be rebuilt due to src code modifications

```bash
$ docker-compose up -d --force-recreate --build
```


# 1. server
Expand Down
13 changes: 10 additions & 3 deletions client/client-1.0/grpc_client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"log"
"os"
"time"
)
Expand All @@ -27,7 +28,7 @@ var clientCert tls.Certificate
var caCertPool x509.CertPool

const (
address = "localhost"
address = "127.0.0.1"
name = "VISSv2-gRPC-client"
)

Expand All @@ -40,7 +41,7 @@ func initCommandList() {
// commandList[0] = `{"action":"get","path":"Vehicle/Cabin/Door/Row1/Right/IsOpen","requestId":"232"}`
//commandList[0] = `{"action":"get","path":"Vehicle/Cabin/Door","filter":{"type":"paths","parameter":"*.*.IsOpen"},"requestId":"235"}`
// commandList[1] = `{"action":"subscribe","path":"Vehicle/Cabin/Door/Row1/Right/IsOpen","filter":{"type":"timebased","parameter":{"period":"3000"}},"requestId":"246"}`
commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":[{"type":"paths","parameter":["CurrentLocation.Latitude", "CurrentLocation.Longitude"]}, {"type":"timebased","parameter":{"period":"100"}}],"requestId":"285"}`
commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":[{"type":"paths","parameter":["Speed","CurrentLocation.Latitude", "CurrentLocation.Longitude"]}, {"type":"timebased","parameter":{"period":"100"}}],"requestId":"285"}`
commandList[0] = `{"action":"get","path":"Vehicle/Speed","requestId":"232"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle/Speed","filter":{"type":"timebased","parameter":{"period":"100"}},"requestId":"246"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":[{"type":"paths","parameter":["Speed", "Chassis/Accelerator/PedalPosition"]},{"type":"timebased","parameter":{"period":"100"}}],"requestId":"246"}`
Expand All @@ -65,6 +66,7 @@ func noStreamCall(commandIndex int) {
conn, err = grpc.Dial(address+portNo, grpc.WithTransportCredentials(tlsCredentials), grpc.WithBlock())
} else {
// grpc.Dial

utils.Info.Printf("connecting to port = 8887")
conn, err = grpc.Dial(address+":8887", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
}
Expand All @@ -81,7 +83,11 @@ func noStreamCall(commandIndex int) {
var vssResponse string
if commandIndex == 0 {
pbRequest := utils.GetRequestJsonToPb(vssRequest, grpcCompression)
pbResponse, _ := client.GetRequest(ctx, pbRequest)
pbResponse, err := client.GetRequest(ctx, pbRequest)
if err != nil {
log.Fatal(err)
return
}
vssResponse = utils.GetResponsePbToJson(pbResponse, grpcCompression)
} else if commandIndex == 2 {
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest, grpcCompression)
Expand Down Expand Up @@ -138,6 +144,7 @@ func streamCall(commandIndex int) {

func main() {
// Create new parser object

parser := argparse.NewParser("print", "gRPC client")
// Create string flag
logFile := parser.Flag("", "logfile", &argparse.Options{Required: false, Help: "outputs to logfile in ./logs folder"})
Expand Down
190 changes: 190 additions & 0 deletions client/client-1.0/grpc_client/grpc_map_client/grpc_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/**
* (C) 2023 Ford Motor Company
* (C) 2023 Volvo Cars
*
* All files and artifacts in the repository at https://github.com/w3c/automotive-viss2
* are licensed under the provisions of the license provided by the LICENSE file in this repository.
*
**/
package main

import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"github.com/akamensky/argparse"
"github.com/gorilla/mux"
"github.com/w3c/automotive-viss2/client/client-1.0/grpc_client/grpc_map_client/mapserver"
pb "github.com/w3c/automotive-viss2/grpc_pb"
utils "github.com/w3c/automotive-viss2/utils"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"log"
"os"
"time"
)

var clientCert tls.Certificate
var caCertPool x509.CertPool

const (
address = "127.0.0.1"
name = "VISSv2-gRPC-client"
)

var grpcCompression utils.Compression

var commandList []string

func initCommandList() {
commandList = make([]string, 4)
// commandList[0] = `{"action":"get","path":"Vehicle/Cabin/Door/Row1/Right/IsOpen","requestId":"232"}`
//commandList[0] = `{"action":"get","path":"Vehicle/Cabin/Door","filter":{"type":"paths","parameter":"*.*.IsOpen"},"requestId":"235"}`
// commandList[1] = `{"action":"subscribe","path":"Vehicle/Cabin/Door/Row1/Right/IsOpen","filter":{"type":"timebased","parameter":{"period":"3000"}},"requestId":"246"}`
commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":[{"type":"paths","parameter":["Speed","CurrentLocation.Latitude", "CurrentLocation.Longitude"]}, {"type":"timebased","parameter":{"period":"100"}}],"requestId":"285"}`
commandList[0] = `{"action":"get","path":"Vehicle/Speed","requestId":"232"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle/Speed","filter":{"type":"timebased","parameter":{"period":"100"}},"requestId":"246"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":[{"type":"paths","parameter":["Speed", "Chassis/Accelerator/PedalPosition"]},{"type":"timebased","parameter":{"period":"100"}}],"requestId":"246"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle","filter":{"type":"paths","parameter":["Speed", "Chassis/Accelerator/PedalPosition"]},"requestId":"246"}`
//commandList[1] = `{"action":"subscribe","path":"Vehicle/Speed","requestId":"258"}`
commandList[2] = `{"action":"unsubscribe","subscriptionId":"1","requestId":"240"}`
commandList[3] = `{"action":"set", "path":"Vehicle/Body/Lights/IsLeftIndicatorOn", "value":"999", "requestId":"245"}`
}

// {"action":"subscribe","path":"Vehicle","filter":{"type":"paths","parameter":["Speed", "Chassis.Accelerator.PedalPosition"]},"requestId":"246"}`

func noStreamCall(commandIndex int) {
var conn *grpc.ClientConn
var err error
if secConfig.TransportSec == "yes" {
config := &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: &caCertPool,
}
tlsCredentials := credentials.NewTLS(config)
portNo := secConfig.GrpcSecPort
conn, err = grpc.Dial(address+portNo, grpc.WithTransportCredentials(tlsCredentials), grpc.WithBlock())
} else {
// grpc.Dial

utils.Info.Printf("connecting to port = 8887")
conn, err = grpc.Dial(address+":8887", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
}
if err != nil {
fmt.Printf("did not connect: %v", err)
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
vssRequest := commandList[commandIndex]
var vssResponse string
if commandIndex == 0 {
pbRequest := utils.GetRequestJsonToPb(vssRequest, grpcCompression)
pbResponse, err := client.GetRequest(ctx, pbRequest)
if err != nil {
log.Fatal(err)
return
}
vssResponse = utils.GetResponsePbToJson(pbResponse, grpcCompression)
} else if commandIndex == 2 {
pbRequest := utils.UnsubscribeRequestJsonToPb(vssRequest, grpcCompression)
pbResponse, _ := client.UnsubscribeRequest(ctx, pbRequest)
vssResponse = utils.UnsubscribeResponsePbToJson(pbResponse, grpcCompression)
} else {
pbRequest := utils.SetRequestJsonToPb(vssRequest, grpcCompression)
pbResponse, _ := client.SetRequest(ctx, pbRequest)
vssResponse = utils.SetResponsePbToJson(pbResponse, grpcCompression)
}
if err != nil {
fmt.Printf("Error when issuing request=:%s", vssRequest)
} else {
fmt.Printf("Received response:%s", vssResponse)
}
}

func streamCall(commandIndex int) {
var conn *grpc.ClientConn
var err error
if secConfig.TransportSec == "yes" {
config := &tls.Config{
Certificates: []tls.Certificate{clientCert},
RootCAs: &caCertPool,
}
tlsCredentials := credentials.NewTLS(config)
portNo := secConfig.GrpcSecPort
conn, err = grpc.Dial(address+portNo, grpc.WithTransportCredentials(tlsCredentials), grpc.WithBlock())
} else {
conn, err = grpc.Dial(address+":8887", grpc.WithInsecure(), grpc.WithBlock())
}
if err != nil {
fmt.Printf("did not connect: %v", err)
return
}
defer conn.Close()
client := pb.NewVISSv2Client(conn)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
vssRequest := commandList[commandIndex]
pbRequest := utils.SubscribeRequestJsonToPb(vssRequest, grpcCompression)
stream, err := client.SubscribeRequest(ctx, pbRequest)
for {
pbResponse, err := stream.Recv()
vssResponse := utils.SubscribeStreamPbToJson(pbResponse, grpcCompression)
if err != nil {
fmt.Printf("Error=%v when issuing request=:%s", err, vssRequest)
} else {
fmt.Printf("Received response:%s\n", vssResponse)
}
}
}

func main() {
// Create new parser object
go mapserver.ServeWebViewSite(mux.NewRouter())

parser := argparse.NewParser("print", "gRPC client")
// Create string flag
logFile := parser.Flag("", "logfile", &argparse.Options{Required: false, Help: "outputs to logfile in ./logs folder"})
logLevel := parser.Selector("", "loglevel", []string{"trace", "debug", "info", "warn", "error", "fatal", "panic"}, &argparse.Options{
Required: false,
Help: "changes log output level",
Default: "info"})

// Parse input
err := parser.Parse(os.Args)
if err != nil {
fmt.Print(parser.Usage(err))
}

utils.InitLog("grpc_client-log.txt", "./logs", *logFile, *logLevel)
grpcCompression = utils.PB_LEVEL1
readTransportSecConfig()
utils.Info.Printf("secConfig.TransportSec=%s", secConfig.TransportSec)
if secConfig.TransportSec == "yes" {
caCertPool = *prepareTransportSecConfig()
}
initCommandList()

fmt.Printf("Command indicies: 0=GET, 1=SUBSCRIBE, 2=UNSUBSCRIBE, 3=SET, any other value terminates.\n")
var commandIndex int
for {
fmt.Printf("\nCommand index [0-3]:")
fmt.Scanf("%d", &commandIndex)
if commandIndex < 0 || commandIndex > 3 {
break
}
fmt.Printf("Command:%s", commandList[commandIndex])
if commandIndex == 1 { // subscribe
go streamCall(commandIndex)
} else {
go noStreamCall(commandIndex)
}
time.Sleep(1 * time.Second)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/******** Peter Winzell (c), 10/30/23 *********************************************/

package mapserver

import (
"github.com/gorilla/mux"
"net/http"
)

const (
ReleaseTag = "server 0.0.1"
)

var pingHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// log.Println("pingHandler called ...")
w.WriteHeader(http.StatusOK)
w.Write([]byte(" HTTP status(200) OK code returned running: " + ReleaseTag))
})

func ServeWebViewSite(r *mux.Router) error {

r.Handle("/version", pingHandler).Methods("GET")
r.Handle("/", http.FileServer(http.Dir("./static/")))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("./static/"))))

return http.ListenAndServe(":8085", r)

}
35 changes: 35 additions & 0 deletions client/client-1.0/grpc_client/grpc_map_client/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<head>
<meta charset="UTF-8">
<title>Volvo Cars(c) 2023 VISSv2 remotive labs example </title>
<title>Accessible Map</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
a.skiplink {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
padding: 0;
border: 0;
height: 1px;
width: 1px;
overflow: hidden;
}
a.skiplink:focus {
clip: auto;
height: auto;
width: auto;
background-color: #fff;
padding: 0.3em;
}
#map:focus {
outline: #4A74A8 solid 0.15em;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="module" src="mappen.js"></script>
</body>
19 changes: 19 additions & 0 deletions client/client-1.0/grpc_client/grpc_map_client/static/mappen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';

new Map({
target: 'map',
layers: [
new TileLayer({
source: new XYZ({
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
})
})
],
view: new View({
center: [0, 0],
zoom: 10
})
});
Loading

0 comments on commit 138fa8e

Please sign in to comment.