diff options
author | Hritik Chouhan <hritikc3961@gmail.com> | 2022-09-01 19:15:56 +0200 |
---|---|---|
committer | Hritik Chouhan <hritikc3961@gmail.com> | 2022-09-16 17:25:01 +0200 |
commit | 5559cdb261cfd3e69daa2349906f071dc2491c0d (patch) | |
tree | 12a530a7ab6b8f5fc758f228bf1729e733db9aa8 /lib/kuksa-server | |
parent | b7ba5e78b0ca5245cd9c09313d40561e75d0b120 (diff) |
Upload Flutter-HVAC application for IVI
Flutter hvac app which sets value to KUKSA.VAL like
Fan speed,left and right zone climate temperature,
AC vent direction, Air circulation,Front and Rear Wind
shield defrost.
Update UI and removed Unused code.
Bug-AGL: SPEC-4546
Change-Id: I57f7a9a2954520f4bb781a5ec02be612d72cf404
Signed-off-by: Hritik Chouhan <hritikc3961@gmail.com>
Diffstat (limited to 'lib/kuksa-server')
-rw-r--r-- | lib/kuksa-server/intial_connection.dart | 44 | ||||
-rw-r--r-- | lib/kuksa-server/on_boarding_page.dart | 65 | ||||
-rw-r--r-- | lib/kuksa-server/vehicle-class.dart | 53 | ||||
-rw-r--r-- | lib/kuksa-server/vehicle-provider.dart | 47 | ||||
-rw-r--r-- | lib/kuksa-server/vehicle_config.dart | 39 | ||||
-rw-r--r-- | lib/kuksa-server/vehicle_methods.dart | 97 | ||||
-rw-r--r-- | lib/kuksa-server/vehicle_server_path.dart | 36 |
7 files changed, 381 insertions, 0 deletions
diff --git a/lib/kuksa-server/intial_connection.dart b/lib/kuksa-server/intial_connection.dart new file mode 100644 index 0000000..0ba4e9f --- /dev/null +++ b/lib/kuksa-server/intial_connection.dart @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_hvac/kuksa-server/vehicle_config.dart'; + +import 'on_boarding_page.dart'; + +class InitialScreen extends ConsumerWidget { + InitialScreen({Key? key, required this.client}) : super(key: key); + final HttpClient client; + late WebSocket socket; + + @override + Widget build(BuildContext context, ref) { + final sockConnect = ref.watch(sockConnectprovider(client)); + + return sockConnect.when( + data: (socket) { + this.socket = socket; + this.socket.pingInterval = const Duration(seconds: 2); + return OnBoardingPage(client: client, socket: this.socket); + }, + error: (e, stk) { + print(e); + ref.refresh(sockConnectprovider(client)); + return const Scaffold( + backgroundColor: Colors.black, + body: Center( + child: Text( + 'error', + style: TextStyle(color: Colors.white), + )), + ); + }, + loading: () => const Scaffold( + backgroundColor: Colors.black, + body: Center( + child: Text('loading', style: TextStyle(color: Colors.white))), + ), + ); + } +} diff --git a/lib/kuksa-server/on_boarding_page.dart b/lib/kuksa-server/on_boarding_page.dart new file mode 100644 index 0000000..a14145c --- /dev/null +++ b/lib/kuksa-server/on_boarding_page.dart @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:async'; +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_hvac/kuksa-server/vehicle_config.dart'; +import 'package:flutter_hvac/kuksa-server/vehicle_methods.dart'; + +import '../home_page.dart'; + +class OnBoardingPage extends ConsumerStatefulWidget { + const OnBoardingPage({Key? key, required this.client, required this.socket}) + : super(key: key); + final WebSocket socket; + final HttpClient client; + + @override + ConsumerState<OnBoardingPage> createState() => _OnBoardingPageState(); +} + +class _OnBoardingPageState extends ConsumerState<OnBoardingPage> { + late Timer _timer; + late WebSocket _socket; + + + @override + void initState() { + super.initState(); + _socket = widget.socket; + VISS.init(widget.socket,ref); + _timer = Timer.periodic(const Duration(seconds: 2), (timer) { + + if (widget.socket.readyState == 3) { + ref.refresh(sockConnectprovider(widget.client)); + } + }); + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { + widget.socket.listen( + (data) { + + }, + onError: (e, stk) { + print(e.toString()); + ref.refresh(sockConnectprovider(widget.client)); + }, + ); + }); + } + + @override + void dispose() { + super.dispose(); + _timer.cancel(); + widget.socket.close(786887, "Connection lost with server!"); + } + + @override + Widget build(BuildContext context) { + return MyHome_Page( + socket: _socket, + ); + } +} diff --git a/lib/kuksa-server/vehicle-class.dart b/lib/kuksa-server/vehicle-class.dart new file mode 100644 index 0000000..a04ad90 --- /dev/null +++ b/lib/kuksa-server/vehicle-class.dart @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: Apache-2.0 + +class vehicle { + late bool isAcActive; + late bool isFrontDefrosterActive; + late bool isRearDefrosterActive; + late bool isAcDirectionUp; + late bool isAcDirectionDown; + late bool isAcDirectionMiddle; + late bool isRecirculationActive; + late bool isAutoActive; + late bool isFreshAirCirculateActive; + + vehicle({ + required this.isAcActive, + required this.isAcDirectionDown, + required this.isAcDirectionMiddle, + required this.isAcDirectionUp, + required this.isFrontDefrosterActive, + required this.isRearDefrosterActive, + required this.isRecirculationActive, + required this.isAutoActive, + required this.isFreshAirCirculateActive, + }); + + vehicle copywith({ + bool? isAcActive, + bool? isAcDirectionDown, + bool? isAcDirectionMiddle, + bool? isAcDirectionUp, + bool? isFrontDefrosterActive, + bool? isRearDefrosterActive, + bool? isRecirculationActive, + bool? isAutoActive, + bool? isFreshAirCirculateActive, + }) { + return vehicle( + isAcActive: isAcActive ?? this.isAcActive, + isAcDirectionDown: isAcDirectionDown ?? this.isAcDirectionDown, + isAcDirectionMiddle: isAcDirectionMiddle ?? this.isAcDirectionMiddle, + isAcDirectionUp: isAcDirectionUp ?? this.isAcDirectionUp, + isFrontDefrosterActive: + isFrontDefrosterActive ?? this.isFrontDefrosterActive, + isRearDefrosterActive: + isRearDefrosterActive ?? this.isRearDefrosterActive, + isRecirculationActive: + isRecirculationActive ?? this.isRecirculationActive, + isAutoActive: isAutoActive ?? this.isAutoActive, + isFreshAirCirculateActive: isFreshAirCirculateActive ?? this.isFreshAirCirculateActive, + + ); + } +} diff --git a/lib/kuksa-server/vehicle-provider.dart b/lib/kuksa-server/vehicle-provider.dart new file mode 100644 index 0000000..f070a53 --- /dev/null +++ b/lib/kuksa-server/vehicle-provider.dart @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_hvac/kuksa-server/vehicle-class.dart'; + +final vehicleProvider = StateNotifierProvider<VehicleSignal, vehicle>( + (ref) => VehicleSignal(), +); + +class VehicleSignal extends StateNotifier<vehicle> { + static vehicle intial_value = vehicle( + isAcActive: false, + isAcDirectionDown: false, + isAcDirectionMiddle: false, + isAcDirectionUp: false, + isFrontDefrosterActive: false, + isRearDefrosterActive: false, + isRecirculationActive: false, + isAutoActive: false, + isFreshAirCirculateActive : false, + ); + VehicleSignal() : super(intial_value); + + void update({ + bool? isAcActive, + bool? isAcDirectionDown, + bool? isAcDirectionUp, + bool? isAcDirectionMiddle, + bool? isFrontDefrosterActive, + bool? isRearDefrosterActive, + bool? isRecirculationActive, + bool? isAutoActive, + bool? isFreshAirCirculateActive, + }) { + state = state.copywith( + isAcActive: isAcActive, + isAcDirectionDown: isAcDirectionDown, + isAcDirectionMiddle: isAcDirectionMiddle, + isAcDirectionUp: isAcDirectionUp, + isFrontDefrosterActive: isFrontDefrosterActive, + isRearDefrosterActive: isRearDefrosterActive, + isRecirculationActive: isRecirculationActive, + isAutoActive : isAutoActive, + isFreshAirCirculateActive : isFreshAirCirculateActive, + ); + } +} diff --git a/lib/kuksa-server/vehicle_config.dart b/lib/kuksa-server/vehicle_config.dart new file mode 100644 index 0000000..6eff800 --- /dev/null +++ b/lib/kuksa-server/vehicle_config.dart @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 + + +import 'dart:io'; +import 'package:flutter_hvac/config.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:http/http.dart' as http; + + + +final sockConnectprovider = FutureProvider.family<WebSocket, HttpClient>( + (ref, client) => connect(client,ref)); + + + +// load certificates and set context and returns http client +Future<HttpClient> initializeClient() async { + + + SecurityContext ctx = SecurityContext.defaultContext; + + HttpClient client = HttpClient(context: ctx) + ..findProxy = null + ..badCertificateCallback = (cert, host, port) { + return true; + }; + return client; +} + + + +Future<WebSocket> connect(HttpClient client, ref) async { + final config = ref.read(ConfigStateprovider); + WebSocket socket = await WebSocket.connect( + "wss://${config.hostname}:${config.port}", + customClient: client); + return socket; +} + diff --git a/lib/kuksa-server/vehicle_methods.dart b/lib/kuksa-server/vehicle_methods.dart new file mode 100644 index 0000000..2dda79f --- /dev/null +++ b/lib/kuksa-server/vehicle_methods.dart @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: Apache-2.0 + +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_hvac/config.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_hvac/kuksa-server/vehicle_server_path.dart'; + + +class VISS { + static const requestId = "test-id"; + static void init(WebSocket socket,WidgetRef ref) { + authorize(socket,ref); + + subscribe(socket,ref, VSPath.vehicleFrontLeftTier); + subscribe(socket,ref, VSPath.vehicleFrontRightTier); + subscribe(socket,ref, VSPath.vehicleRearLeftTier); + subscribe(socket,ref, VSPath.vehicleRearRightTier); + subscribe(socket,ref, VSPath.vehicleIsChildLockActiveLeft); + subscribe(socket,ref, VSPath.vehicleIsChildLockActiveRight); + subscribe(socket,ref, VSPath.vehicleCurrentLatitude); + subscribe(socket,ref, VSPath.vehicleCurrentLongitude); + subscribe(socket,ref, VSPath.vehicleInsideTemperature); + subscribe(socket,ref, VSPath.vehicleAmbientAirTemperature); + } + + static void update(WebSocket socket,WidgetRef ref) { + get(socket,ref, VSPath.vehicleAmbientAirTemperature); + get(socket,ref, VSPath.vehicleTrunkLocked); + get(socket, ref,VSPath.vehicleTrunkOpen); + + get(socket,ref, VSPath.vehicleFrontLeftTier); + get(socket,ref, VSPath.vehicleFrontRightTier); + get(socket,ref, VSPath.vehicleRearLeftTier); + get(socket,ref, VSPath.vehicleRearRightTier); + get(socket,ref, VSPath.vehicleIsChildLockActiveLeft); + get(socket,ref, VSPath.vehicleIsChildLockActiveRight); + get(socket,ref, VSPath.vehicleCurrentLatitude); + get(socket,ref, VSPath.vehicleCurrentLongitude); + get(socket,ref, VSPath.vehicleInsideTemperature); + } + + static void authorize(WebSocket socket,WidgetRef ref) { + final config = ref.read(ConfigStateprovider); + Map<String, dynamic> map = { + "action": "authorize", + "tokens": config.kuksaAuthToken, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + static void get(WebSocket socket,WidgetRef ref ,String path) { + final config = ref.read(ConfigStateprovider); + + Map<String, dynamic> map = { + "action": "get", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + static void set( + WebSocket socket, + WidgetRef ref, + String path, + String value, + ) { + final config = ref.read(ConfigStateprovider); + + Map<String, dynamic> map = { + "action": "set", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId, + "value": value + }; + socket.add(jsonEncode(map)); + } + + static void subscribe(WebSocket socket,WidgetRef ref, String path) { + final config = ref.read(ConfigStateprovider); + + Map<String, dynamic> map = { + "action": "subscribe", + "tokens": config.kuksaAuthToken, + "path": path, + "requestId": requestId + }; + socket.add(jsonEncode(map)); + } + + +} diff --git a/lib/kuksa-server/vehicle_server_path.dart b/lib/kuksa-server/vehicle_server_path.dart new file mode 100644 index 0000000..c61c3ca --- /dev/null +++ b/lib/kuksa-server/vehicle_server_path.dart @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 + + +class VSPath { + + + static const String vehicleTrunkLocked = "Vehicle.Body.Trunk.IsLocked"; + static const String vehicleTrunkOpen = "Vehicle.Body.Trunk.IsOpen"; + + + static const String vehicleAmbientAirTemperature = + "Vehicle.AmbientAirTemperature"; + + static const String vehicleFrontLeftTier = + "Vehicle.Chassis.Axle.Row1.Wheel.Left.Tire.Pressure"; + static const String vehicleFrontRightTier = + "Vehicle.Chassis.Axle.Row1.Wheel.Right.Tire.Pressure"; + static const String vehicleRearLeftTier = + "Vehicle.Chassis.Axle.Row2.Wheel.Left.Tire.Pressure"; + + static const String vehicleRearRightTier = + "Vehicle.Chassis.Axle.Row2.Wheel.Right.Tire.Pressure"; + static const String vehicleIsChildLockActiveLeft = + "Vehicle.Cabin.Door.Row2.Left.IsChildLockActive"; + static const String vehicleIsChildLockActiveRight = + "Vehicle.Cabin.Door.Row2.Right.IsChildLockActive"; + static const String vehicleCurrentLongitude = + "Vehicle.CurrentLocation.Longitude"; + static const String vehicleCurrentLatitude = + "Vehicle.CurrentLocation.Latitude"; + + static const String vehicleInsideTemperature = + "Vehicle.Cabin.HVAC.AmbientAirTemperature"; + static const String vehicleFrontLeftAc = + "Vehicle.Cabin.HVAC.Station.Row1.Left.AirDistribution"; +} |