Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
23 changes: 23 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,28 @@ 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.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType);
}
return true;
}
}

export { SdlManagerListener };
2 changes: 1 addition & 1 deletion lib/js/src/manager/_SdlManagerBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _SdlManagerBase {
* @class
* @private
* @param {AppConfig} appConfig - An instance of AppConfig describing the application's metadata and desired transport
* @param {ManagerListener} managerListener - An instance of ManagerListener to be used to listen for manager events
* @param {SdlManagerListener} managerListener - An instance of ManagerListener to be used to listen for manager events
*/
constructor (appConfig = null, managerListener = null) {
this._state = -1;
Expand Down
36 changes: 36 additions & 0 deletions 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,28 @@ 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.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType);
}
return true;
}


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

// to avoid double firing the onVehicleTypeReceived event
// try to define vehicleType and fire onVehicleTypeReceived here
// only if that was not received from SdlSession before
if (!this._sdlSession.didReceiveVehicleType()) {
const vehicleType = registerAppInterfaceResponse.getVehicleType();
if (!this.onVehicleTypeReceived(vehicleType)) {
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 Down
50 changes: 48 additions & 2 deletions lib/js/src/protocol/_SdlProtocolBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ import { _FrameType } from './enums/_FrameType.js';
import { _MessageFrameAssembler } from './_MessageFrameAssembler.js';
import { _SdlPacket } from './_SdlPacket.js';
import { _ControlFrameTags } from './enums/_ControlFrameTags.js';
import { _BitConverter } from './../util/_BitConverter.js';
import { _BitConverter } from '../util/_BitConverter.js';

Choose a reason for hiding this comment

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

@ymalovanyi @vladmu Do you need unit tests for this? For example, sdl java suite has SdlProtocolTests

Copy link
Contributor

Choose a reason for hiding this comment

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

@santhanamk we don't need the test for this particular line as this is just a shortenest path identical to previous but aligned with the style of other imports.

Choose a reason for hiding this comment

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

@vladmu I meant do you need unit tests overall for the changes made to this file?

Copy link
Contributor

Choose a reason for hiding this comment

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

@santhanamk it is hard to define expectations of such tests in the order of the library and this class as we don't have any tests of previous functionality covered here. We appreciate any help in this case.

Choose a reason for hiding this comment

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

@vladmu Ok no problem. It was an optional request, as these were not existing before.


import { _SdlPacketFactory } from './_SdlPacketFactory.js';
import { RpcCreator } from './../rpc/RpcCreator.js';
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,33 @@ class _SdlProtocolBase {
return this._messageID++;
}

/**
* Gets the Vehicle details received in StartService ACK protocol message
* @returns {VehicleType|null} - A RPC VehicleType struct received from the packet if exists null otherwise.
*/
_getVehicleType(sdlPacket) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation here is missing the @param tag for the sdlPacket parameter. There also needs to be a space before the function parentheses on line 277. Use the command npm run lint to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

const make = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_MAKE);
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);

// TODO: awaiting 0293 revisions to process those fields
const systemHardwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_HARDWARE_VERSION);
const systemSoftwareVersion = sdlPacket.getTag(_ControlFrameTags.RPC.StartServiceACK.VEHICLE_SYSTEM_SOFTWARE_VERSION);
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems unfinished since these values are never used.

Copy link
Contributor

Choose a reason for hiding this comment

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

@renonick87 no, the method is finished and reflects the current state of the proposal. Without revisions, we receive those fields here but never use or process them. The TODO was added to reflect that the processing needs to be added after accepting the revisions.


// if no any VehicleType tags in the packet just return null
if (!make && !model && !modelYear && !trim) {
return null;
}

return new VehicleType({
make,
model,
modelYear,
trim,
});
}

/**
* 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 +435,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.

// check if vehicleType data exists then fire onVehicleTypeReceived protocol listener event
const vehicleType = this._getVehicleType(sdlPacket);
if (
vehicleType
&& this._sdlProtocolListener !== null
&& typeof this._sdlProtocolListener.onVehicleTypeReceived === 'function'
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation for lines 441-443 is incorrect. There is an indentation of 14 spaces but it should be 16. Use the command npm run lint to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

) {
if (!this._sdlProtocolListener.onVehicleTypeReceived(vehicleType)) {
console.warn('(ACK) Disconnecting from head unit, the vehicle is not supported');
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
25 changes: 24 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,28 @@ 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.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType);
}
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 +277,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/session/_SdlSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class _SdlSession {
this._sdlProtocolListener = this._setupSdlProtocolListener();

this._sdlProtocol = new _SdlProtocol(baseTransportConfig, this._sdlProtocolListener);
this._didReceiveVehicleType = false;
}

/**
Expand All @@ -77,6 +78,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 +170,25 @@ class _SdlSession {
this._sdlSessionListener.onAuthTokenReceived(authToken, this._sessionId);
}

/**
* A way to determine if VehicleType already received
* @returns {Boolean} Return true if received
*/
didReceiveVehicleType() {
Copy link
Contributor

Choose a reason for hiding this comment

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

There needs to be a space before the function parentheses on line 177. Use the command npm run lint to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

return this._didReceiveVehicleType;
}

/**
* 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.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType) {
// set the flag as this event fires only once if VehicleType was received
this._didReceiveVehicleType = true;
return this._sdlSessionListener.onVehicleTypeReceived(vehicleType);
}

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

export { _SdlSession };
export { _SdlSession };
25 changes: 24 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,28 @@ 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.
* @returns {Boolean} Return true if this session should continue, false if the session should end
*/
onVehicleTypeReceived (vehicleType) {
if (typeof this._onVehicleTypeReceived === 'function') {
return !!this._onVehicleTypeReceived(vehicleType);
}
return true;
}

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

export { _SdlSessionListener };
export { _SdlSessionListener };
16 changes: 16 additions & 0 deletions tests/managers/lifecycle/LifecycleManagerTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,21 @@ module.exports = function (appClient) {
Validator.assertNotNullUndefined(version.getPatchVersion());
done();
});
it('testOnVehicleTypeReceived', function (done) {
const mockVehicleType = {};
const defaultResult = true;
let actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType);
Validator.assertEquals(actualResult, defaultResult);

const testResult = false;
const testListener = function (vehicleType) {
return testResult;
};
sdlManager.getFileManager()._lifecycleManager.setOnVehicleTypeReceived(testListener);
actualResult = sdlManager.getFileManager()._lifecycleManager.onVehicleTypeReceived(mockVehicleType);
Validator.assertEquals(actualResult, testResult);

done();
});
});
};