Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/js/src/manager/SdlManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ class SdlManager extends _SdlManagerBase {
}

this._lifecycleManager = new _LifecycleManager(this._lifecycleConfig, this._lifecycleListener);
if (this._managerListener) {
this._lifecycleManager.setOnVehicleTypeReceived(
this._managerListener.onVehicleTypeReceived.bind(this._managerListener)
);
}

/* FIXME: setSdlSecurity and related methods/classes do not exist
if (this._sdlSecList.length > 0) {
Expand Down
25 changes: 25 additions & 0 deletions lib/js/src/manager/SdlManagerListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SdlManagerListener {
this._managerShouldUpdateLifecycle = (language) => {
return null;
};
this._onVehicleTypeReceived = null;
}

/**
Expand Down Expand Up @@ -126,6 +127,30 @@ class SdlManagerListener {
}
return null;
}

/**
* Set the OnVehicleTypeReceived event callback function.
* @param {function} callback - A function to invoke when the event is triggered.
* @returns {SdlManagerListener} - A reference to this instance to support method chaining.
*/
setOnVehicleTypeReceived (callback) {
this._onVehicleTypeReceived = callback;
return this;
}

/**
* Safely attempts to invoke the OnVehicleTypeReceived event callback function.
* @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on.
* @param {String} systemSoftwareVersion - software version of the system.
* @param {String} systemHardwareVersion - hardware version of the system.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion);
}
return true;
}
}

export { SdlManagerListener };
39 changes: 38 additions & 1 deletion lib/js/src/manager/lifecycle/_LifecycleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ class _LifecycleManager {
this._authToken = authToken;
});

sessionListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this));

return sessionListener;
}

Expand Down Expand Up @@ -406,6 +408,30 @@ class _LifecycleManager {
return registerAppInterface;
}

/**
* Set the OnVehicleTypeReceived function callback.
* @param {function} listener - A function to be invoked when the event occurs.
* @returns {_LifecycleManager} - A reference to this instance to support method chaining.
*/
setOnVehicleTypeReceived (listener) {
this._onVehicleTypeReceived = listener;
return this;
}

/**
* Safely attempts to invoke the onVehicleTypeReceived event.
* @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on.
* @param {String} systemSoftwareVersion - software version of the system.
* @param {String} systemHardwareVersion - hardware version of the system.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion);
}
return true;
}


/* *******************************************************************************************************
********************************** INTERNAL - RPC LISTENERS !! START !! *********************************
Expand Down Expand Up @@ -484,6 +510,17 @@ class _LifecycleManager {
this._cleanProxy();
}

if (this._rpcSpecVersion.isNewerThan(new Version(7, 0, 0)) === 1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi Do the unit tests in LifecycleManagerTests.js need to be updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santhanamk Added tests for new methods.

const vehicleType = registerAppInterfaceResponse.getVehicleType();
const systemSoftwareVersion = registerAppInterfaceResponse.getSystemSoftwareVersion();
const systemHardwareVersion = registerAppInterfaceResponse.getSystemHardwareVersion();
if (!this.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) {
console.warn('(RAI) Disconnecting from head unit, the vehicle is not supported');
this.sendRpcResolve(new UnregisterAppInterface());
this._cleanProxy();
}
}

// parse RAI for system capabilities
this._systemCapabilityManager._parseRaiResponse(registerAppInterfaceResponse);
}
Expand All @@ -503,7 +540,7 @@ class _LifecycleManager {
}
}

_LifecycleManager.MAX_RPC_VERSION = new Version(7, 0, 0);
_LifecycleManager.MAX_RPC_VERSION = new Version(7, 1, 0);
_LifecycleManager.REGISTER_APP_INTERFACE_CORRELATION_ID = 65529;
_LifecycleManager.UNREGISTER_APP_INTERFACE_CORRELATION_ID = 65530;

Expand Down
49 changes: 49 additions & 0 deletions lib/js/src/protocol/_SdlProtocolBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { RpcCreator } from './../rpc/RpcCreator.js';
import { ImageResolution } from '../rpc/structs/ImageResolution.js';
import { VideoStreamingFormat } from '../rpc/structs/VideoStreamingFormat.js';

import { VehicleType } from './../rpc/structs/VehicleType.js';

/**
* Base implementation of sdl protocol.
* Should be able to handle basic control frames and be able to
Expand Down Expand Up @@ -268,6 +270,36 @@ class _SdlProtocolBase {
return this._messageID++;
}

/**
* Gets the Vehicle details received in StartService ACK protocol message
* @returns {Number} - A new numeric message ID.
*/
_getVehicleType(sdlPacket) {
const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE);
if (!make) {
return null;
}
const model = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL);
const modelYear = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MODEL_YEAR);
const trim = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_TRIM);

const vehicleType = new VehicleType({
make,
model,
modelYear,
trim,
});

const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION);
const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION);

return {
vehicleType,
systemHardwareVersion,
systemSoftwareVersion,
}
}

/**
* Takes an rpc message and sends a single or multi frame packets.
* @param {RpcMessage} rpcMessage - Converts an RpcMessage into an _SdlPacket and sends it.
Expand Down Expand Up @@ -406,6 +438,23 @@ class _SdlProtocolBase {
const version = sdlPacket.getVersion();
const serviceType = sdlPacket.getServiceType();
if (version >= 5) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi On line 440, does this need to be >= 6 instead of >= 5? In the proposal the example method onPacketRead has it as > = 6.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our initial implementation was exactly with >= 6 according to the proposal, but testing alongside the core we never met that condition, it seems the protocol version is not increased with this proposal. Therefore we rolled back to 5.

const vehicleTypeFromPacket = this._getVehicleType(sdlPacket);
if (
vehicleTypeFromPacket
&& this._sdlProtocolListener !== null
&& typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function'
) {
const {vehicleType, systemSoftwareVersion, systemHardwareVersion } = vehicleTypeFromPacket;
if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion)) {
console.warn('Disconnecting from head unit, the vehicle is not supported (ACK)');
this.endService(serviceType, sdlPacket.getSessionID());
if (serviceType === _ServiceType.RPC && this._transportManager !== null) {
this._transportManager.stop();
}
return;
}
}

let mtuTag = null;
if (serviceType === _ServiceType.RPC) {
mtuTag = _ControlFrameTags.RPC.StartServiceACK.MTU;
Expand Down
27 changes: 26 additions & 1 deletion lib/js/src/protocol/_SdlProtocolListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _SdlProtocolListener {
this._onProtocolSessionEnded = null;
this._onProtocolSessionEndedNACKed = null;
this._onAuthTokenReceived = null;
this._onVehicleTypeReceived = null;
this._getSessionId = null;
this._onTransportConnected = null;
}
Expand Down Expand Up @@ -189,6 +190,30 @@ class _SdlProtocolListener {
}
}

/**
* Set the OnVehicleTypeReceived function callback.
* @param {function} listener - A function to be invoked when the event occurs.
* @returns {_SdlProtocolListener} - A reference to this instance to support method chaining.
*/
setOnVehicleTypeReceived (listener) {
this._onVehicleTypeReceived = listener;
return this;
}

/**
* Safely attempts to invoke the onVehicleTypeReceived event.
* @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on.
* @param {String} systemSoftwareVersion - software version of the system.
* @param {String} systemHardwareVersion - hardware version of the system.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi In the proposal the method onVehicleTypeReceived is defined like: onVehicleTypeReceived (sdlManager, vehicleType) {}.... Does your definition starting on line 210 need to match with what the proposal has?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sdlManager parameter is not required in the context of the current library implementation, we assume this was added in the proposal by mistake. systemSoftwareVersion and systemHardwareVersion parameters now under discussion here smartdevicelink/sdl_evolution#1108 this PR already includes changes of that revision.

if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion);
}
return true;
}

/**
* Set the GetSessionId function.
* @param {function} getter - A function to be invoked to retrieve the session ID.
Expand Down Expand Up @@ -254,4 +279,4 @@ class _SdlProtocolListener {
}
}

export { _SdlProtocolListener };
export { _SdlProtocolListener };
8 changes: 7 additions & 1 deletion lib/js/src/protocol/enums/_ControlFrameTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ _ControlFrameTags.RPC = Object.freeze({
VIDEO_SERVICE_TRANSPORTS: 'videoServiceTransports',
/** Auth token to be used for log in into services **/
AUTH_TOKEN: 'authToken',
VEHICLE_MAKE: 'make',
VEHICLE_MODEL: 'model',
VEHICLE_MODEL_YEAR: 'modelYear',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi On line 77, does the tag name need to be model year like it is defined in the proposal or is modelYear okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this is just a typo in the proposal, on testing alongside the core we received modelYear thus included it in camelcase instead of space-separated.

VEHICLE_TRIM: 'trim',
VEHICLE_SYSTEM_SOFTWARE_VERSION: 'systemSoftwareVersion',
VEHICLE_SYSTEM_HARDWARE_VERSION: 'systemHardwareVersion',
}, StartServiceACKBase, StartServiceProtocolVersion, StartServiceHashId),

StartServiceNAK: NAKBase,
Expand Down Expand Up @@ -128,4 +134,4 @@ _ControlFrameTags.Video = Object.freeze({
EndServiceNAK: NAKBase,
});

export { _ControlFrameTags };
export { _ControlFrameTags };
23 changes: 22 additions & 1 deletion lib/js/src/rpc/messages/RegisterAppInterfaceResponse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable camelcase */
/*
* Copyright (c) 2020, SmartDeviceLink Consortium, Inc.
* Copyright (c) 2021, SmartDeviceLink Consortium, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -431,6 +431,26 @@ class RegisterAppInterfaceResponse extends RpcResponse {
return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION);
}

/**
* Set the SystemHardwareVersion
* @since SmartDeviceLink 7.1.0
* @param {String} version - The hardware version of the system - The desired SystemHardwareVersion.
* {'string_min_length': 1, 'string_max_length': 500}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi Are these defined somewhere? For example, the string_min_length 1 string_max_length 500? It would be nice to cross verify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is autogenerated code, no RPC classes in the library for now those cross-verify such parameters.

* @returns {RegisterAppInterfaceResponse} - The class instance for method chaining.
*/
setSystemHardwareVersion (version) {
this.setParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION, version);
return this;
}

/**
* Get the SystemHardwareVersion
* @returns {String} - the KEY_SYSTEM_HARDWARE_VERSION value
*/
getSystemHardwareVersion () {
return this.getParameter(RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION);
}

/**
* Set the IconResumed
* @since SmartDeviceLink 5.0.0
Expand Down Expand Up @@ -469,6 +489,7 @@ RegisterAppInterfaceResponse.KEY_SUPPORTED_DIAG_MODES = 'supportedDiagModes';
RegisterAppInterfaceResponse.KEY_HMI_CAPABILITIES = 'hmiCapabilities';
RegisterAppInterfaceResponse.KEY_SDL_VERSION = 'sdlVersion';
RegisterAppInterfaceResponse.KEY_SYSTEM_SOFTWARE_VERSION = 'systemSoftwareVersion';
RegisterAppInterfaceResponse.KEY_SYSTEM_HARDWARE_VERSION = 'systemHardwareVersion';
RegisterAppInterfaceResponse.KEY_ICON_RESUMED = 'iconResumed';

export { RegisterAppInterfaceResponse };
14 changes: 13 additions & 1 deletion lib/js/src/session/_SdlSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class _SdlSession {
sdlProtocolListener.setOnRpcMessageReceived(this.onRpcMessageReceived.bind(this));
sdlProtocolListener.setOnTransportConnected(this.onTransportConnected.bind(this));
sdlProtocolListener.setOnAuthTokenReceived(this.onAuthTokenReceived.bind(this));
sdlProtocolListener.setOnVehicleTypeReceived(this.onVehicleTypeReceived.bind(this));

sdlProtocolListener.setGetDesiredVideoParams(this.getDesiredVideoParams.bind(this));
sdlProtocolListener.setSetAcceptedVideoParams(this.setAcceptedVideoParams.bind(this));
Expand Down Expand Up @@ -168,6 +169,17 @@ class _SdlSession {
this._sdlSessionListener.onAuthTokenReceived(authToken, this._sessionId);
}

/**
* A way to determine if this SDL session should continue to be active while
* connected to the determined vehicle type.
* @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on.
* @param {String} systemSoftwareVersion - software version of the system.
* @param {String} systemHardwareVersion - hardware version of the system.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ymalovanyi In the proposal this method is defined as onVehicleTypeReceived (sdlManager, vehicleType) {}. Does your method definition need to change to match with the proposal?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this._sdlSessionListener.onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion);
}

/** **********************************************************************************************************************************************************************
* END: _SdlProtocolListener implemented methods
Expand Down Expand Up @@ -324,4 +336,4 @@ class _SdlSession {
}
}

export { _SdlSession };
export { _SdlSession };
27 changes: 26 additions & 1 deletion lib/js/src/session/_SdlSessionListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class _SdlSessionListener {
this._onRpcMessageReceived = null;
this._onTransportConnected = null;
this._onAuthTokenReceived = null;
this._onVehicleTypeReceived = null;
}

/**
Expand Down Expand Up @@ -159,6 +160,30 @@ class _SdlSessionListener {
}
}

/**
* Set the onVehicleTypeReceived function.
* @param {function} listener - A function to be invoked when the event occurs.
* @returns {_SdlSessionListener} - A reference to this instance to allow method chaining.
*/
setOnVehicleTypeReceived (listener) {
this._onVehicleTypeReceived = listener;
return this;
}

/**
* Safely attempts to invoke the onVehicleTypeReceived event.
* @param {VehicleType} vehicleType - the type of vehicle that this session is currently active on.
* @param {String} systemSoftwareVersion - software version of the system.
* @param {String} systemHardwareVersion - hardware version of the system.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType, systemSoftwareVersion, systemHardwareVersion) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType, systemSoftwareVersion, systemHardwareVersion);
}
return true;
}

/**
* Safely attempts to invoke the onRpcMessageReceived event.
* @param {RpcMessage} rpcMessage - An RpcMessage.
Expand All @@ -179,4 +204,4 @@ class _SdlSessionListener {
}
}

export { _SdlSessionListener };
export { _SdlSessionListener };
Loading