File tree Expand file tree Collapse file tree 4 files changed +79
-2
lines changed Expand file tree Collapse file tree 4 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -1273,6 +1273,26 @@ class Node extends rclnodejs.ShadowNode {
12731273 return params ;
12741274 }
12751275
1276+ /**
1277+ * Get the types of given parameters.
1278+ *
1279+ * Return the types of given parameters.
1280+ *
1281+ * @param {string[] } [names] - The names of the declared parameters.
1282+ * @return {Uint8Array } - The types.
1283+ */
1284+ getParameterTypes ( names = [ ] ) {
1285+ let types = [ ] ;
1286+
1287+ for ( const name of names ) {
1288+ const descriptor = this . _parameterDescriptors . get ( name ) ;
1289+ if ( descriptor ) {
1290+ types . push ( descriptor . type ) ;
1291+ }
1292+ }
1293+ return types ;
1294+ }
1295+
12761296 /**
12771297 * Get the names of all declared parameters.
12781298 *
Original file line number Diff line number Diff line change @@ -110,6 +110,16 @@ class ParameterService {
110110 }
111111 ) ;
112112
113+ // Create GetParameterTypes service.
114+ const getParameterTypesServiceName = nodeName + '/get_parameter_types' ;
115+ this . _node . createService (
116+ 'rcl_interfaces/srv/GetParameterTypes' ,
117+ getParameterTypesServiceName ,
118+ ( request , response ) => {
119+ this . _handleGetParameterTypes ( request , response ) ;
120+ }
121+ ) ;
122+
113123 // create SetParametersAtomically service
114124 const setParametersAtomicallyServiceName =
115125 nodeName + '/set_parameters_atomically' ;
@@ -266,6 +276,23 @@ class ParameterService {
266276 response . send ( msg ) ;
267277 }
268278
279+ /**
280+ * Get a list of parameter types.
281+ *
282+ * request.names identifies the parameter types to get.
283+ *
284+ * @param {GetParameterTypes_Request } request - The client request.
285+ * @param {GetParameterTypes_Response } response - The service response with
286+ * Uint8Array.
287+ * @return {undefined } -
288+ */
289+ _handleGetParameterTypes ( request , response ) {
290+ const types = this . _node . getParameterTypes ( request . names ) ;
291+ const msg = response . template ;
292+ msg . types = types ;
293+ response . send ( msg ) ;
294+ }
295+
269296 /**
270297 * Update a list of parameters atomically.
271298 *
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ describe('Node extra destroy methods testing', function () {
9393 const AddTwoInts = 'example_interfaces/srv/AddTwoInts' ;
9494 // const AddTwoInts = rclnodejs.require('example_interfaces/srv/AddTwoInts');
9595 var service = node . createService ( AddTwoInts , 'add_two_ints' , ( ) => { } ) ;
96- assert . deepStrictEqual ( node . _services . length , 6 ) ;
96+ assert . deepStrictEqual ( node . _services . length , 7 ) ;
9797
9898 assertThrowsError (
9999 function ( ) {
@@ -105,7 +105,7 @@ describe('Node extra destroy methods testing', function () {
105105 ) ;
106106
107107 node . destroyService ( service ) ;
108- assert . deepStrictEqual ( node . _services . length , 5 ) ;
108+ assert . deepStrictEqual ( node . _services . length , 6 ) ;
109109 } ) ;
110110
111111 it ( 'destroyTimer()' , function ( ) {
Original file line number Diff line number Diff line change @@ -367,4 +367,34 @@ describe('Parameter_server tests', function () {
367367 `Expected 3 parameter-events, received ${ eventCount } events.`
368368 ) ;
369369 } ) ;
370+
371+ it ( 'Get_parameter_types' , async function ( ) {
372+ const client = clientNode . createClient (
373+ 'rcl_interfaces/srv/GetParameterTypes' ,
374+ 'test_node/get_parameter_types'
375+ ) ;
376+ await client . waitForService ( ) ;
377+
378+ const ParamTypes = rclnodejs . require ( 'rcl_interfaces/msg/ParameterType' ) ;
379+ const request = new ( rclnodejs . require (
380+ 'rcl_interfaces/srv/GetParameterTypes'
381+ ) . Request ) ( ) ;
382+ request . names = [ 'p1' , 'p2' , 'A.p3' ] ;
383+ let success = false ;
384+
385+ client . sendRequest ( request , ( response ) => {
386+ assert . deepEqual ( response . types . length , 3 ) ;
387+ assert . deepEqual (
388+ response . types ,
389+ Uint8Array . from ( [
390+ ParamTypes . PARAMETER_STRING ,
391+ ParamTypes . PARAMETER_INTEGER ,
392+ ParamTypes . PARAMETER_BOOL ,
393+ ] )
394+ ) ;
395+ success = true ;
396+ } ) ;
397+ await assertUtils . createDelay ( STD_WAIT ) ;
398+ assert . ok ( success ) ;
399+ } ) ;
370400} ) ;
You can’t perform that action at this time.
0 commit comments