@@ -240,6 +240,7 @@ pub fn readEni(
240
240
/// Read information for simulator.
241
241
/// Not required unless you are running the simulator.
242
242
sim : bool ,
243
+ pv_name_prefix : ? []const u8 ,
243
244
) ! gcat. Arena (ENI ) {
244
245
const arena = try allocator .create (std .heap .ArenaAllocator );
245
246
errdefer allocator .destroy (arena );
@@ -251,6 +252,7 @@ pub fn readEni(
251
252
arena .allocator (),
252
253
state_change_timeout_us ,
253
254
sim ,
255
+ pv_name_prefix ,
254
256
),
255
257
};
256
258
}
@@ -261,12 +263,19 @@ pub fn readEniLeaky(
261
263
allocator : std.mem.Allocator ,
262
264
state_change_timeout_us : u32 ,
263
265
sim : bool ,
266
+ pv_name_prefix : ? []const u8 ,
264
267
) ! ENI {
265
268
var subdevice_configs = std .ArrayList (gcat .ENI .SubdeviceConfiguration ).init (allocator );
266
269
defer subdevice_configs .deinit ();
267
270
const num_subdevices = try self .countSubdevices ();
268
271
for (0.. num_subdevices ) | i | {
269
- const config = try self .readSubdeviceConfigurationLeaky (allocator , @intCast (i ), state_change_timeout_us , sim );
272
+ const config = try self .readSubdeviceConfigurationLeaky (
273
+ allocator ,
274
+ @intCast (i ),
275
+ state_change_timeout_us ,
276
+ sim ,
277
+ pv_name_prefix ,
278
+ );
270
279
try subdevice_configs .append (config );
271
280
}
272
281
return gcat.ENI { .subdevices = try subdevice_configs .toOwnedSlice () };
@@ -278,6 +287,7 @@ pub fn readSubdeviceConfiguration(
278
287
ring_position : u16 ,
279
288
state_change_timeout_us : u32 ,
280
289
sim : bool ,
290
+ pv_name_prefix : ? []const u8 ,
281
291
) ! gcat. Arena (ENI .SubdeviceConfiguration ) {
282
292
const arena = try allocator .create (std .heap .ArenaAllocator );
283
293
errdefer allocator .destroy (arena );
@@ -290,6 +300,7 @@ pub fn readSubdeviceConfiguration(
290
300
ring_position ,
291
301
state_change_timeout_us ,
292
302
sim ,
303
+ pv_name_prefix ,
293
304
),
294
305
};
295
306
}
@@ -302,6 +313,7 @@ pub fn readSubdeviceConfigurationLeaky(
302
313
ring_position : u16 ,
303
314
state_change_timeout_us : u32 ,
304
315
sim : bool ,
316
+ pv_name_prefix : ? []const u8 ,
305
317
) ! ENI.SubdeviceConfiguration {
306
318
const station_address = Subdevice .stationAddressFromRingPos (ring_position );
307
319
const info = try sii .readSIIFP_ps (
@@ -453,6 +465,7 @@ pub fn readSubdeviceConfigurationLeaky(
453
465
name ,
454
466
try allocator .dupeZ (u8 , object_description .name .slice ()),
455
467
try allocator .dupeZ (u8 , entry_description .data .slice ()),
468
+ pv_name_prefix ,
456
469
);
457
470
}
458
471
try entries .append (ENI.SubdeviceConfiguration.PDO.Entry {
@@ -548,6 +561,7 @@ pub fn readSubdeviceConfigurationLeaky(
548
561
name ,
549
562
pdo_name orelse "" ,
550
563
entry_name orelse "" ,
564
+ pv_name_prefix ,
551
565
);
552
566
}
553
567
@@ -642,17 +656,32 @@ pub fn processVariableNameZ(
642
656
subdevice_name : []const u8 ,
643
657
pdo_name : []const u8 ,
644
658
entry_description : []const u8 ,
645
- ) error {OutOfMemory }! [:0 ]u8 {
659
+ maybe_prefix : ? []const u8 ,
660
+ ) error {OutOfMemory }! [:0 ]const u8 {
646
661
const direction_str : []const u8 = if (direction == .input ) "inputs" else "outputs" ;
647
- const name = try std .fmt .allocPrintZ (allocator , "subdevices/{}/{s}/{s}/0x{x:04}/{s}/0x{x:02}/{s}" , .{
648
- ring_position ,
649
- zenohSanitize (try allocator .dupe (u8 , subdevice_name )),
650
- direction_str ,
651
- pdo_idx ,
652
- zenohSanitize (try allocator .dupe (u8 , pdo_name )),
653
- entry_idx ,
654
- zenohSanitize (try allocator .dupe (u8 , entry_description )),
655
- });
662
+ var name : [:0 ]const u8 = undefined ;
663
+ if (maybe_prefix ) | prefix | {
664
+ name = try std .fmt .allocPrintZ (allocator , "{s}/subdevices/{}/{s}/{s}/0x{x:04}/{s}/0x{x:02}/{s}" , .{
665
+ prefix ,
666
+ ring_position ,
667
+ zenohSanitize (try allocator .dupe (u8 , subdevice_name )),
668
+ direction_str ,
669
+ pdo_idx ,
670
+ zenohSanitize (try allocator .dupe (u8 , pdo_name )),
671
+ entry_idx ,
672
+ zenohSanitize (try allocator .dupe (u8 , entry_description )),
673
+ });
674
+ } else {
675
+ name = try std .fmt .allocPrintZ (allocator , "subdevices/{}/{s}/{s}/0x{x:04}/{s}/0x{x:02}/{s}" , .{
676
+ ring_position ,
677
+ zenohSanitize (try allocator .dupe (u8 , subdevice_name )),
678
+ direction_str ,
679
+ pdo_idx ,
680
+ zenohSanitize (try allocator .dupe (u8 , pdo_name )),
681
+ entry_idx ,
682
+ zenohSanitize (try allocator .dupe (u8 , entry_description )),
683
+ });
684
+ }
656
685
657
686
return name ;
658
687
}
0 commit comments