aa7876f6f57111e45ce18570ebe23bb4e3082774
[AGL/meta-agl-demo.git] / recipes-demo / kuksa-vss-init / files / kuksa_vss_init.py
1 #!/usr/bin/env python3
2 # Copyright (c) 2022 Aakash Solanki, tech2aks@gmail.com
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a copy of
5 # this software and associated documentation files (the "Software"), to deal in
6 # the Software without restriction, including without limitation the rights to
7 # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 # of the Software, and to permit persons to whom the Software is furnished to do
9 # so, subject to the following conditions:
10 #
11 # The above copyright notice and this permission notice shall be included in all
12 # copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
21
22 import kuksa_viss_client
23 import time
24
25
26 class VSS:
27     def __init__(self, client):
28         self.client = client
29
30         self.speed = "Vehicle.Speed"
31         self.engineRPM = "Vehicle.Powertrain.CombustionEngine.Speed"
32         self.fuelLevel = "Vehicle.Powertrain.FuelSystem.Level"
33         self.coolantTemp = "Vehicle.Powertrain.CombustionEngine.ECT"
34         self.leftIndicator = "Vehicle.Body.Lights.IsLeftIndicatorOn"
35         self.rightIndicator = "Vehicle.Body.Lights.IsRightIndicatorOn"
36         #   // Selected Gear output = > 0 = Neutral, 1/2/.. = Forward, -1/.. = Reverse, 126 = Park, 127 = Drive
37         self.selectedGear = "Vehicle.Powertrain.Transmission.SelectedGear"
38         self.lowBeamOn = "Vehicle.Body.Lights.IsLowBeamOn"
39         self.highBeamOn = "Vehicle.Body.Lights.IsHighBeamOn"
40         self.parkingLightOn = "Vehicle.Body.Lights.IsParkingOn"
41         self.hazardLightOn = "Vehicle.Body.Lights.IsHazardOn"
42         self.travelledDistance = "Vehicle.TravelledDistance"
43         self.trunkLocked = "Vehicle.Body.Trunk.Rear.IsLocked"
44         self.trunkOpen = "Vehicle.Body.Trunk.Rear.IsOpen"
45         #   // \"normal\", \"sport\", \"economy\", \"snow\", \"rain\"]
46         self.performanceMode = "Vehicle.Powertrain.Transmission.PerformanceMode"
47         self.ambientAirTemperature = "Vehicle.Exterior.AirTemperature"
48         self.mil = "Vehicle.OBD.Status.IsMILOn"
49         self.cruiseControlError = "Vehicle.ADAS.CruiseControl.IsError"
50         self.cruiseControlSpeedSet = "Vehicle.ADAS.CruiseControl.SpeedSet"
51         self.cruiseControlisActive = "Vehicle.ADAS.CruiseControl.IsActive"
52         self.batteryChargingStatus = "Vehicle.Powertrain.TractionBattery.Charging.IsCharging"
53         # 
54         self.currLat = "Vehicle.Cabin.CurrentLocation.Latitude"
55         self.currLng = "Vehicle.Cabin.CurrentLocation.Longitude"
56         self.desLat = "Vehicle.Cabin.Infotainment.Navigation.DestinationSet.Latitude"
57         self.desLng = "Vehicle.Cabin.Infotainment.Navigation.DestinationSet.Longitude"
58         self.steeringInfo = "Vehicle.Cabin.SteeringWheel.Switches.Info"
59
60     def setInitialValues(self):
61         print("Setting values")
62         self.client.setValue(self.speed, '5')
63         self.client.setValue(self.engineRPM, '1000')
64         self.client.setValue(self.fuelLevel, '50')
65         self.client.setValue(self.coolantTemp, '70')
66         self.client.setValue(self.leftIndicator, "false")
67         self.client.setValue(self.rightIndicator, "false")
68         self.client.setValue(self.selectedGear, '127')
69         self.client.setValue(self.lowBeamOn, "true")
70         self.client.setValue(self.highBeamOn, "false")
71         self.client.setValue(self.parkingLightOn, "true")
72         self.client.setValue(self.hazardLightOn, "false")
73         self.client.setValue(self.travelledDistance, '100')
74         self.client.setValue(self.trunkLocked, "true")
75         self.client.setValue(self.trunkOpen, "false")
76         self.client.setValue(self.performanceMode, "normal")
77         self.client.setValue(self.ambientAirTemperature, '28')
78         self.client.setValue(self.mil, "false")
79         self.client.setValue(self.cruiseControlError, "false")
80         self.client.setValue(self.cruiseControlisActive, "false")
81         self.client.setValue(self.cruiseControlSpeedSet, '60')
82         self.client.setValue(self.batteryChargingStatus, "true")
83         # 
84         self.client.setValue(self.currLat, "31.708643")
85         self.client.setValue(self.currLng, "76.931882")
86         self.client.setValue(self.desLat, "31.781456")
87         self.client.setValue(self.desLng, "76.997469")
88         # Show the map
89         self.client.setValue(self.steeringInfo, "false")
90         print("All value set succesfully")
91
92
93 def main():
94     config = {"ip": "localhost", "port": 8090, "insecure": False}
95     client = kuksa_viss_client.KuksaClientThread(config)
96     client.start()
97     token_file = open(
98     "/usr/lib/python3.10/site-packages/kuksa_certificates/jwt/all-read-write.json.token", "r")
99     token = token_file.read()
100     client.authorize(token, timeout=2)
101
102     vss = VSS(client)
103
104     time.sleep(2)
105
106     vss.setInitialValues()
107     client.stop()
108
109
110 if __name__ == '__main__':
111     main()