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

Commit

Permalink
Fixing Reply Feeder
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbosch committed Jul 3, 2023
1 parent 2b84f5a commit ef3aba5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 42 deletions.
31 changes: 27 additions & 4 deletions replay/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Usage of kuksa.val replay feature

![kuksa.val Logo](../../doc/pictures/logo.png)
![kuksa.val Logo](../doc/img/logo.png)

Once you recorded your server in- and outputs to your record file using the [record feature](../../src/VssDatabase_Record.cpp) the replay script can replay the same data with exact timing into the `kuksa.val` server.
Once you recorded your server in- and outputs to your record file using the [record feature](../../src/VssDatabase_Record.cpp) the replay script can replay the same data with exact timing into the `kuksa.val` server.
An example log can be found in [testlog.csv](testlog.csv)

## Usage

Expand All @@ -19,15 +20,37 @@ Provide a different path than the default one using
$ ./kuksa-val-server --record=recordGetAndSet --record-path=/path/to/logs
```

### Replay a file to the server
### Configuration

Please configure [config.ini](config.ini) to set log file path and select your Replay mode.

#### Avaliable replay modes are:
#### Available replay modes are:

|mode|action|
|-|-|
| Set | Replay Set Value only|
| SetGet | Replay Get Value and Set Value to the server |


### Run Replay

The Replay tool relies on that `kuksa-client` is installed.

```
$ pip install kuksa-client
```

Then replay can be run like this.

```
~/kuksa.val.feeders/replay$ python _replay.py
connect to wss://127.0.0.1:8090
Websocket connected securely.
Connected successfully
Replaying data from testlog.csv
Replay successful
```

## Limitations

* Replay only support communication with KUKSA.val Server using Websocket, it does not support communication with KUKSA.val Databroker
64 changes: 31 additions & 33 deletions replay/_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,60 @@
# SPDX-License-Identifier: Apache-2.0
########################################################################

import sys, os
import time, datetime
import sys
import os
import time
import datetime
import traceback
import configparser
import csv
import string
from kuksa_client import KuksaClientThread

scriptDir= os.path.dirname(os.path.realpath(__file__))
scriptDir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(scriptDir, "..", ".."))

from kuksa_viss_client import *

def workaround_dict(a,b):
pass

# Expected columns in log file from KUKSA.val Server
rowIDs = [
"timestamp",
"ID",
"action",
"attribute",
"path",
"value"
]

try:
config = configparser.ConfigParser()
config.read('config.ini')
except:
except Exception:
print("Unable to read config file")
os._exit(0)

args=config['replay'] #get replay data
vsscfg = config['vss'] #get Client data from config file
args = config['replay'] # get replay data
vsscfg = config['vss'] # get Client data from config file
csv_path = args.get('path')

try:
commThread = KuksaClientThread(vsscfg) #make new thread
commThread = KuksaClientThread(vsscfg) # make new thread
commThread.start()
commThread.authorize(token=commThread.tokenfile)
commThread.authorize()
connected = commThread.checkConnection()
if not connected:
print("Could not connect successfully")
sys.exit(-1)
print("Connected successfully")
except:
print("Could not connect successfully")
except Exception:
print("Exception when trying to connect")
sys.exit(-1)

try:

actionFunctions = {
"get": commThread.getValue,
"set": commThread.setValue
}

if args.get('mode') == 'Set':
actionFunctions["get"] = workaround_dict #don't call get functions when getValue is not specified
elif args.get('mode') == 'SetGet':
pass
else:
if not args.get('mode') in ['Set', 'SetGet']:
raise AttributeError

with open(csv_path,"r") as recordFile:
fileData = csv.DictReader(recordFile,rowIDs,delimiter=';')
with open(csv_path, "r") as recordFile:
print("Replaying data from " + csv_path)
fileData = csv.DictReader(recordFile, rowIDs, delimiter=';')

timestamp_pre = 0
for row in fileData:
Expand All @@ -83,21 +78,24 @@ def workaround_dict(a,b):
if timestamp_pre != 0:
curr = datetime.datetime.strptime(timestamp_curr, '%Y-%b-%d %H:%M:%S.%f')
pre = datetime.datetime.strptime(timestamp_pre, '%Y-%b-%d %H:%M:%S.%f')
delta = (curr-pre).total_seconds() #get time delta between the timestamps
delta = (curr-pre).total_seconds() # get time delta between the timestamps
else:
delta=0
delta = 0

timestamp_pre = timestamp_curr

time.sleep(delta)
actionFunctions.get(row['action'])(row['path'],row['value'])
if row['action'] == 'set':
commThread.setValue(row['path'], row['value'])
elif args.get('mode') == 'SetGet':
commThread.getValue(row['path'])

print("Replay successful")

except AttributeError:
print("Wrong attributes used. Please check config.ini")

except:
except Exception:
traceback.print_exc()

os._exit(1)
11 changes: 6 additions & 5 deletions replay/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
ip=127.0.0.1
port=8090
insecure=false
token=../../kuksa_certificates/jwt/all-read-write.json.token
token=../../kuksa.val/kuksa_certificates/jwt/all-read-write.json.token
timeout=0.01
certificate=../../kuksa_certificates/Client.pem
key=../../kuksa_certificates/Client.key
cacertificate=../../kuksa_certificates/CA.pem
certificate=../../kuksa.val/kuksa_certificates/Client.pem
key=../../kuksa.val/kuksa_certificates/Client.key
cacertificate=../../kuksa.val/kuksa_certificates/CA.pem

[replay]
path=/home/isw6fe/kuksa.val/build/src/logs/record-20210823_102152.log.csv
path=testlog.csv
# use Set or SetGet
mode=SetGet
7 changes: 7 additions & 0 deletions replay/testlog.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
2023-Jul-03 14:21:04.902324;0;set;value;Vehicle.Speed;"54"
2023-Jul-03 14:21:07.366425;1;set;value;Vehicle.Speed;"5"
2023-Jul-03 14:21:09.342065;2;set;value;Vehicle.Speed;"12"
2023-Jul-03 14:21:11.564240;3;set;value;Vehicle.Speed;"54"
2023-Jul-03 14:21:12.606443;4;get;value;Vehicle.Speed
2023-Jul-03 14:21:13.606443;5;get;value;Vehicle.Speed
2023-Jul-03 14:21:14.342065;6;set;value;Vehicle.Speed;"12"

0 comments on commit ef3aba5

Please sign in to comment.