Skip to content

Commit fa4e59f

Browse files
committed
upgrade to zig 0.14.1, process variable name prefix
1 parent b64c191 commit fa4e59f

File tree

5 files changed

+52
-18
lines changed

5 files changed

+52
-18
lines changed

build.zig.zon

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
.{
22
.name = .gatorcat,
3-
.version = "0.3.6",
3+
.version = "0.3.7",
44
.fingerprint = 0xb9356c7c4de9ca59, // Changing this has security and trust implications.
5-
.minimum_zig_version = "0.14.0",
5+
.minimum_zig_version = "0.14.1",
66
.dependencies = .{
77
.flags = .{
88
.url = "git+https://github.com/n0s4/flags#0e2491d8e6d2be38dc0c2ce8e103469886e468bb",
99
.hash = "flags-0.10.0-a_9h3kR2AABNAfaPGRyOOGmWsfv12Hk6JQPTX4MM446s",
1010
},
1111
.zenoh = .{
12-
.url = "git+https://github.com/kj4tmp/zenoh-zig.git#fd3ea547804fdf87465a94adf200539a9a519e42",
13-
.hash = "zenoh-1.3.4-QDbMY420AAD1bNUEOw4An1GiHFY8KqHnTjp2HEt44d0U",
12+
.url = "git+https://github.com/kj4tmp/zenoh-zig#2b34a27a97aeda2b38c7a9cba9f72a3f406e3095",
13+
.hash = "zenoh-1.3.4-QDbMY420AACP2-YTF6esmKintDLIT6Bp5DBWRRTrbP4f",
1414
},
1515
.zbor = .{
1616
.url = "git+https://github.com/r4gus/zbor.git#d575ecf6cb5a797c1992d03591c25c8d0bb9b2cc",

doc/examples/simple4/main.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn main() !void {
2020
gpa.allocator(),
2121
10_000_000,
2222
false,
23+
null,
2324
);
2425
defer eni.deinit();
2526

src/cli/run.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub const Args = struct {
2828
eni_file_json: ?[:0]const u8 = null,
2929
rt_prio: ?i32 = null,
3030
verbose: bool = false,
31+
pv_name_prefix: ?[]const u8,
3132

3233
pub const ZenohLogLevel = enum { trace, debug, info, warn, @"error" };
3334

@@ -47,6 +48,7 @@ pub const Args = struct {
4748
.eni_file_json = "Same as --eni-file but as JSON.",
4849
.rt_prio = "Set a real-time priority for this process. Does nothing on windows.",
4950
.verbose = "Enable verbose logs.",
51+
.pv_name_prefix = "Add a prefix (separated by /) to process variable names, if desired. Not applicable if eni file provided.",
5052
};
5153
};
5254

@@ -153,7 +155,7 @@ pub fn run(allocator: std.mem.Allocator, args: Args) RunError!void {
153155
error.RecvTimeout, error.Wkc => continue :bus_scan,
154156
};
155157

156-
break :blk scanner.readEni(allocator, args.preop_timeout_us, false) catch |err| switch (err) {
158+
break :blk scanner.readEni(allocator, args.preop_timeout_us, false, args.pv_name_prefix) catch |err| switch (err) {
157159
error.LinkError,
158160
error.Overflow,
159161
error.NoSpaceLeft,

src/cli/scan.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub const Args = struct {
1313
mbx_timeout_us: u32 = 50_000,
1414
json: bool = false,
1515
sim: bool = false,
16+
pv_name_prefix: ?[]const u8,
1617
pub const descriptions = .{
1718
.ifname = "Network interface to use for the bus scan.",
1819
.recv_timeout_us = "Frame receive timeout in microseconds.",
@@ -21,6 +22,7 @@ pub const Args = struct {
2122
.ring_position = "Optionally specify only a single subdevice at this ring position to be scanned.",
2223
.json = "Export the ENI as JSON instead of ZON.",
2324
.sim = "Also scan information required for simulation.",
25+
.pv_name_prefix = "Add a prefix to process variable names, if desired. (separated by /)",
2426
};
2527
};
2628

@@ -41,7 +43,7 @@ pub fn scan(allocator: std.mem.Allocator, args: Args) !void {
4143
try scanner.assignStationAddresses(num_subdevices);
4244

4345
if (args.ring_position) |ring_position| {
44-
const subdevice_eni = try scanner.readSubdeviceConfiguration(allocator, ring_position, args.PREOP_timeout_us, args.sim);
46+
const subdevice_eni = try scanner.readSubdeviceConfiguration(allocator, ring_position, args.PREOP_timeout_us, args.sim, args.pv_name_prefix);
4547
defer subdevice_eni.deinit();
4648
var std_out = std.io.getStdOut();
4749

@@ -53,7 +55,7 @@ pub fn scan(allocator: std.mem.Allocator, args: Args) !void {
5355
try std_out.writer().writeByte('\n');
5456
}
5557
} else {
56-
const eni = try scanner.readEni(allocator, args.PREOP_timeout_us, args.sim);
58+
const eni = try scanner.readEni(allocator, args.PREOP_timeout_us, args.sim, args.pv_name_prefix);
5759
defer eni.deinit();
5860

5961
var std_out = std.io.getStdOut();

src/module/Scanner.zig

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub fn readEni(
240240
/// Read information for simulator.
241241
/// Not required unless you are running the simulator.
242242
sim: bool,
243+
pv_name_prefix: ?[]const u8,
243244
) !gcat.Arena(ENI) {
244245
const arena = try allocator.create(std.heap.ArenaAllocator);
245246
errdefer allocator.destroy(arena);
@@ -251,6 +252,7 @@ pub fn readEni(
251252
arena.allocator(),
252253
state_change_timeout_us,
253254
sim,
255+
pv_name_prefix,
254256
),
255257
};
256258
}
@@ -261,12 +263,19 @@ pub fn readEniLeaky(
261263
allocator: std.mem.Allocator,
262264
state_change_timeout_us: u32,
263265
sim: bool,
266+
pv_name_prefix: ?[]const u8,
264267
) !ENI {
265268
var subdevice_configs = std.ArrayList(gcat.ENI.SubdeviceConfiguration).init(allocator);
266269
defer subdevice_configs.deinit();
267270
const num_subdevices = try self.countSubdevices();
268271
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+
);
270279
try subdevice_configs.append(config);
271280
}
272281
return gcat.ENI{ .subdevices = try subdevice_configs.toOwnedSlice() };
@@ -278,6 +287,7 @@ pub fn readSubdeviceConfiguration(
278287
ring_position: u16,
279288
state_change_timeout_us: u32,
280289
sim: bool,
290+
pv_name_prefix: ?[]const u8,
281291
) !gcat.Arena(ENI.SubdeviceConfiguration) {
282292
const arena = try allocator.create(std.heap.ArenaAllocator);
283293
errdefer allocator.destroy(arena);
@@ -290,6 +300,7 @@ pub fn readSubdeviceConfiguration(
290300
ring_position,
291301
state_change_timeout_us,
292302
sim,
303+
pv_name_prefix,
293304
),
294305
};
295306
}
@@ -302,6 +313,7 @@ pub fn readSubdeviceConfigurationLeaky(
302313
ring_position: u16,
303314
state_change_timeout_us: u32,
304315
sim: bool,
316+
pv_name_prefix: ?[]const u8,
305317
) !ENI.SubdeviceConfiguration {
306318
const station_address = Subdevice.stationAddressFromRingPos(ring_position);
307319
const info = try sii.readSIIFP_ps(
@@ -453,6 +465,7 @@ pub fn readSubdeviceConfigurationLeaky(
453465
name,
454466
try allocator.dupeZ(u8, object_description.name.slice()),
455467
try allocator.dupeZ(u8, entry_description.data.slice()),
468+
pv_name_prefix,
456469
);
457470
}
458471
try entries.append(ENI.SubdeviceConfiguration.PDO.Entry{
@@ -548,6 +561,7 @@ pub fn readSubdeviceConfigurationLeaky(
548561
name,
549562
pdo_name orelse "",
550563
entry_name orelse "",
564+
pv_name_prefix,
551565
);
552566
}
553567

@@ -642,17 +656,32 @@ pub fn processVariableNameZ(
642656
subdevice_name: []const u8,
643657
pdo_name: []const u8,
644658
entry_description: []const u8,
645-
) error{OutOfMemory}![:0]u8 {
659+
maybe_prefix: ?[]const u8,
660+
) error{OutOfMemory}![:0]const u8 {
646661
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+
}
656685

657686
return name;
658687
}

0 commit comments

Comments
 (0)