From 2b60d0f31338455469b96ae1b81d0c7ad5d2f948 Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Tue, 2 Jul 2024 22:11:01 -0400 Subject: [PATCH 1/6] setup and test parsers --- src/parsers.zig | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ src/vita49.zig | 4 +- 2 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 src/parsers.zig diff --git a/src/parsers.zig b/src/parsers.zig new file mode 100644 index 0000000..bc3e565 --- /dev/null +++ b/src/parsers.zig @@ -0,0 +1,110 @@ +const std = @import("std"); +const net = std.net; +const Vita49 = @import("vita49.zig").Vita49; +const CCSDS = @import("ccsds.zig").CCSDS; + +pub fn Parser(comptime Frame: type) type { + return struct { + ip_address: []const u8, + port: u16, + buffer_size: u64 = 1024, + is_running: bool = false, + should_stop: bool = false, + + const Self = @This(); + + pub fn new(ip_address: []const u8, port: u16, buffer_size: u64) Self { + return .{ + .ip_address = ip_address, + .port = port, + .buffer_size = buffer_size, + }; + } + + pub fn parse_from_file(self: Self) void { + self.is_running; + } + + pub fn start(self: *Self) !void { + std.log.warn("print something out and keep it please", .{}); + const addr = try net.Address.parseIp4(self.ip_address, self.port); + // const stream_ip = net.Address{ .in = loopback }; + + const stream = try net.tcpConnectToAddress(addr); + defer stream.close(); + + std.log.info("connected to socket successful", .{}); + + var incoming_buffer = std.mem.zeroes([1024]u8); + while (!self.should_stop) { + _ = try stream.read(&incoming_buffer); + const new_frame = Frame.new(&incoming_buffer); + std.log.info("message recieved: {any}", .{new_frame}); + } + } + + pub fn stop(self: *Self) void { + self.should_stop = true; + } + }; +} + +/// this is for running the tests ONLY +fn _run_test_server() !void { + const loopback = try net.Ip4Address.parse("127.0.0.1", 65432); + const localhost = net.Address{ .in = loopback }; + var server = try localhost.listen(.{ + .reuse_port = true, + }); + defer server.deinit(); + + const addr = server.listen_address; + std.log.info("Listening on {}\n", .{addr.getPort()}); + + var client = try server.accept(); + defer client.stream.close(); + + std.log.info("Connection received! {}\n", .{client.address}); + const vita49_pkt = [_]u8{ + 0x3A, 0x02, 0x0A, 0x00, 0x34, 0x12, 0x00, 0x00, 0x00, 0x56, 0x34, + 0x12, 0x78, 0x9A, 0xBC, 0xDE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x56, 0x49, + 0x54, 0x41, 0x20, 0x34, 0x39, 0x21, + }; + var counter: usize = 0; + while (counter < 5) { + _ = try client.stream.writeAll(&vita49_pkt); + std.time.sleep(2 * std.time.ns_per_s); + counter += 1; + } +} + +test "Vita49 Parser Test" { + const ip = "127.0.0.1".*; + const port: u16 = 65432; + const parser = Parser(Vita49); + var par_test = parser.new(&ip, port, 1024); + + { + const t1 = try std.Thread.spawn(.{}, _run_test_server, .{}); + defer t1.join(); + + std.time.sleep(2 * std.time.ns_per_s); + + const t2 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) !void { + try pt.start(); + } + }.run, .{&par_test}); + defer t2.join(); + + std.time.sleep(10 * std.time.ns_per_s); + + const t3 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) void { + pt.stop(); + } + }.run, .{&par_test}); + defer t3.join(); + } +} diff --git a/src/vita49.zig b/src/vita49.zig index e133ca8..7e4ad95 100644 --- a/src/vita49.zig +++ b/src/vita49.zig @@ -156,7 +156,7 @@ pub const Vita49 = struct { trailer = Trailer.new(stream[payload_range.end..]); payload = stream[payload_range.start..payload_range.end]; } else { - payload = stream[payload_range.start..]; + payload = stream[payload_range.start..payload_range.end]; } if (header.tsi != TSI.none) { var tmp_array: [4]u8 = undefined; @@ -209,8 +209,6 @@ pub const Vita49 = struct { } }; -pub const Vita49_Parser = struct { stream: []const u8, packets: []const Vita49 }; - test "Test Vita49 Packet w/o trailer" { const vita49_test_packet = [_]u8{ // Packet header From ab51e5f272fa92d43a39184016652cb2560e04a5 Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Tue, 2 Jul 2024 22:28:49 -0400 Subject: [PATCH 2/6] add a config option to vita49, but not implemented --- src/parsers.zig | 60 ++++++++++++++++++++++++++++++++++++++++--------- src/vita49.zig | 9 +++++--- 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/parsers.zig b/src/parsers.zig index bc3e565..d1ea573 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -26,7 +26,6 @@ pub fn Parser(comptime Frame: type) type { } pub fn start(self: *Self) !void { - std.log.warn("print something out and keep it please", .{}); const addr = try net.Address.parseIp4(self.ip_address, self.port); // const stream_ip = net.Address{ .in = loopback }; @@ -38,7 +37,7 @@ pub fn Parser(comptime Frame: type) type { var incoming_buffer = std.mem.zeroes([1024]u8); while (!self.should_stop) { _ = try stream.read(&incoming_buffer); - const new_frame = Frame.new(&incoming_buffer); + const new_frame = Frame.new(&incoming_buffer, null); std.log.info("message recieved: {any}", .{new_frame}); } } @@ -50,7 +49,7 @@ pub fn Parser(comptime Frame: type) type { } /// this is for running the tests ONLY -fn _run_test_server() !void { +fn _run_test_server(parse_type: []const u8) !void { const loopback = try net.Ip4Address.parse("127.0.0.1", 65432); const localhost = net.Address{ .in = loopback }; var server = try localhost.listen(.{ @@ -65,15 +64,24 @@ fn _run_test_server() !void { defer client.stream.close(); std.log.info("Connection received! {}\n", .{client.address}); - const vita49_pkt = [_]u8{ - 0x3A, 0x02, 0x0A, 0x00, 0x34, 0x12, 0x00, 0x00, 0x00, 0x56, 0x34, - 0x12, 0x78, 0x9A, 0xBC, 0xDE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x56, 0x49, - 0x54, 0x41, 0x20, 0x34, 0x39, 0x21, - }; + + var _pkt: []const u8 = undefined; + if (std.mem.eql(u8, parse_type, "vita49")) { + _pkt = &[_]u8{ + 0x3A, 0x02, 0x0A, 0x00, 0x34, 0x12, 0x00, 0x00, 0x00, 0x56, 0x34, + 0x12, 0x78, 0x9A, 0xBC, 0xDE, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2C, 0x20, 0x56, 0x49, + 0x54, 0x41, 0x20, 0x34, 0x39, 0x21, + }; + } else { + _pkt = &[_]u8{ + 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, + 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + }; + } var counter: usize = 0; while (counter < 5) { - _ = try client.stream.writeAll(&vita49_pkt); + _ = try client.stream.writeAll(_pkt); std.time.sleep(2 * std.time.ns_per_s); counter += 1; } @@ -86,7 +94,37 @@ test "Vita49 Parser Test" { var par_test = parser.new(&ip, port, 1024); { - const t1 = try std.Thread.spawn(.{}, _run_test_server, .{}); + const t1 = try std.Thread.spawn(.{}, _run_test_server, .{"vita49"}); + defer t1.join(); + + std.time.sleep(2 * std.time.ns_per_s); + + const t2 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) !void { + try pt.start(); + } + }.run, .{&par_test}); + defer t2.join(); + + std.time.sleep(10 * std.time.ns_per_s); + + const t3 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) void { + pt.stop(); + } + }.run, .{&par_test}); + defer t3.join(); + } +} + +test "CCSDS Parser Test" { + const ip = "127.0.0.1".*; + const port: u16 = 65432; + const parser = Parser(CCSDS); + var par_test = parser.new(&ip, port, 1024); + + { + const t1 = try std.Thread.spawn(.{}, _run_test_server, .{"ccsds"}); defer t1.join(); std.time.sleep(2 * std.time.ns_per_s); diff --git a/src/vita49.zig b/src/vita49.zig index 7e4ad95..5632d12 100644 --- a/src/vita49.zig +++ b/src/vita49.zig @@ -112,7 +112,10 @@ pub const Vita49 = struct { const Self = @This(); - pub fn new(stream: []const u8) !Self { + pub fn new(stream: []const u8, config: ?[]const u8) !Self { + if (config != null) { + std.log.debug("Config found for Vita49 but this hasnt been implemeneted yet", .{}); + } if (stream.len < 4) { return Vita49Error.InsufficentData; } @@ -238,7 +241,7 @@ test "Test Vita49 Packet w/o trailer" { 0x21, }; - const vita49_packet = try Vita49.new(&vita49_test_packet); + const vita49_packet = try Vita49.new(&vita49_test_packet, null); try std.testing.expectEqual(null, vita49_packet.i_timestamp); try std.testing.expectEqual(128, vita49_packet.f_timestamp); @@ -270,7 +273,7 @@ test "Test Vita49 Packet w/ trailer" { 0xBB, 0xCC, 0xDD, }; - const vita49_packet = try Vita49.new(&vita49_test_packet); + const vita49_packet = try Vita49.new(&vita49_test_packet, null); try std.testing.expectEqual(4660, vita49_packet.stream_id); try std.testing.expectEqual(null, vita49_packet.class_id); From 8aba2a1d8d84709ef233bffbeb7fb40cbbc6baeb Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Tue, 2 Jul 2024 22:44:21 -0400 Subject: [PATCH 3/6] add parsers to tests command --- build.zig | 13 +++++++++++++ src/ccsds.zig | 6 +++--- src/parsers.zig | 27 ++++++++++++++++++++------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/build.zig b/build.zig index 02ea037..453d4da 100644 --- a/build.zig +++ b/build.zig @@ -56,6 +56,12 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + _ = b.addModule("astroz.parsers", .{ + .root_source_file = b.path("src/parser.zig"), + .target = target, + .optimize = optimize, + }); + const coord_unit_tests = b.addTest(.{ .root_source_file = b.path("src/coordinates.zig"), }); @@ -86,10 +92,17 @@ pub fn build(b: *std.Build) void { const run_vita49_unit_tests = b.addRunArtifact(vita49_unit_tests); + const parsers_unit_tests = b.addTest(.{ + .root_source_file = b.path("src/parsers.zig"), + }); + + const run_parsers_unit_tests = b.addRunArtifact(parsers_unit_tests); + const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_coord_unit_tests.step); test_step.dependOn(&run_ccsds_unit_tests.step); test_step.dependOn(&run_time_unit_tests.step); test_step.dependOn(&run_constants_unit_tests.step); test_step.dependOn(&run_vita49_unit_tests.step); + test_step.dependOn(&run_parsers_unit_tests.step); } diff --git a/src/ccsds.zig b/src/ccsds.zig index 637c7d3..c0f4b5b 100644 --- a/src/ccsds.zig +++ b/src/ccsds.zig @@ -16,7 +16,7 @@ pub const CCSDS = struct { const Self = @This(); - pub fn new(raw_packets: []const u8, config: ?Config) Self { + pub fn new(raw_packets: []const u8, config: ?Config) !Self { const primary_header = raw_packets[0..6]; const version = @as(u3, @truncate((primary_header[0] >> 5) & 0x07)); const packet_type = @as(u1, @truncate((primary_header[0] >> 4) & 0x01)); @@ -63,7 +63,7 @@ test "CCSDS Structure Testing w/ config" { const test_allocator = std.testing.allocator; const config = try parse_config(test_config, test_allocator); - const converted_test_packet = CCSDS.new(&raw_test_packet, config); + const converted_test_packet = try CCSDS.new(&raw_test_packet, config); const packets = .{ 7, 8, 9, 10 }; @@ -78,7 +78,7 @@ test "CCSDS Structure Testing w/ config" { test "CCSDS Structure Testing w/o config" { const raw_test_packet: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }; - const converted_test_packet = CCSDS.new(&raw_test_packet, null); + const converted_test_packet = try CCSDS.new(&raw_test_packet, null); const packets = .{ 5, 6, 7, 8, 9, 10 }; diff --git a/src/parsers.zig b/src/parsers.zig index d1ea573..214e870 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -10,17 +10,25 @@ pub fn Parser(comptime Frame: type) type { buffer_size: u64 = 1024, is_running: bool = false, should_stop: bool = false, + packets: std.ArrayList(Frame), + allocator: std.mem.Allocator, const Self = @This(); - pub fn new(ip_address: []const u8, port: u16, buffer_size: u64) Self { + pub fn new(ip_address: []const u8, port: u16, buffer_size: u64, allocator: std.mem.Allocator) Self { return .{ .ip_address = ip_address, .port = port, .buffer_size = buffer_size, + .packets = std.ArrayList(Frame).init(allocator), + .allocator = allocator, }; } + pub fn deinit(self: *Self) void { + self.packets.deinit(); + } + pub fn parse_from_file(self: Self) void { self.is_running; } @@ -37,8 +45,9 @@ pub fn Parser(comptime Frame: type) type { var incoming_buffer = std.mem.zeroes([1024]u8); while (!self.should_stop) { _ = try stream.read(&incoming_buffer); - const new_frame = Frame.new(&incoming_buffer, null); + const new_frame = try Frame.new(&incoming_buffer, null); std.log.info("message recieved: {any}", .{new_frame}); + _ = try self.packets.append(new_frame); } } @@ -50,9 +59,9 @@ pub fn Parser(comptime Frame: type) type { /// this is for running the tests ONLY fn _run_test_server(parse_type: []const u8) !void { - const loopback = try net.Ip4Address.parse("127.0.0.1", 65432); - const localhost = net.Address{ .in = loopback }; - var server = try localhost.listen(.{ + const ip_addr = try net.Ip4Address.parse("127.0.0.1", 65432); + const test_host = net.Address{ .in = ip_addr }; + var server = try test_host.listen(.{ .reuse_port = true, }); defer server.deinit(); @@ -91,7 +100,8 @@ test "Vita49 Parser Test" { const ip = "127.0.0.1".*; const port: u16 = 65432; const parser = Parser(Vita49); - var par_test = parser.new(&ip, port, 1024); + var par_test = parser.new(&ip, port, 1024, std.testing.allocator); + defer par_test.deinit(); { const t1 = try std.Thread.spawn(.{}, _run_test_server, .{"vita49"}); @@ -115,13 +125,15 @@ test "Vita49 Parser Test" { }.run, .{&par_test}); defer t3.join(); } + try std.testing.expectEqual(8, par_test.packets.capacity); } test "CCSDS Parser Test" { const ip = "127.0.0.1".*; const port: u16 = 65432; const parser = Parser(CCSDS); - var par_test = parser.new(&ip, port, 1024); + var par_test = parser.new(&ip, port, 1024, std.testing.allocator); + defer par_test.deinit(); { const t1 = try std.Thread.spawn(.{}, _run_test_server, .{"ccsds"}); @@ -145,4 +157,5 @@ test "CCSDS Parser Test" { }.run, .{&par_test}); defer t3.join(); } + try std.testing.expectEqual(8, par_test.packets.capacity); } From 9f2f3ef65922d504a95a057cd232b7d5d1a9c22b Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Tue, 2 Jul 2024 22:46:44 -0400 Subject: [PATCH 4/6] starting to update readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6097d2e..a41ce6e 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ b.installArtifact(exe); ### Examples -#### Create a CCSDS Parser +#### Create a CCSDS Packet ##### W/O Config @@ -121,7 +121,10 @@ pub fn main() !void { } ``` +#### Setup Vita49 Parser +```zig +``` #### precess a star to July 30, 2005 From 27a1c9168f1f2682895eac1308485c50cedeae2f Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Wed, 3 Jul 2024 00:00:59 -0400 Subject: [PATCH 5/6] add callbacks to the parser --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++----- src/ccsds.zig | 2 +- src/lib.zig | 2 ++ src/parsers.zig | 47 +++++++++++++++++++++++++++++++++++---- src/time.zig | 1 - src/vita49.zig | 17 +++++++-------- 6 files changed, 106 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a41ce6e..20e445a 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Astronomical and Spacecraft Toolkit Written in Zig for Zig! ### Spacecraft - [x] CCSDS Packets - - [ ] CCSDS Stream Parser + - [x] CCSDS Stream Parser - [x] VITA49 Packets - - [ ] Vita49 Stream Parser + - [x] Vita49 Stream Parser - [ ] Orbital Maneuvers - [ ] Impulse Maneuvers - [ ] Phase Maneuvers @@ -70,6 +70,56 @@ b.installArtifact(exe); ### Examples + +### Setup Vita49 Parser + +#### W/ Callback + +```zig +const std = @import("std"); +const astroz = @import("astroz"); +const Vita49 = astroz.vita49.Vita49; +const Parser = astroz.parsers.Parser; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); + + const P = Parser(Vita49); + const ip = "127.0.0.1".*; + const port: u16 = 65432; + var parser = P.new(&ip, port, 1024, allocator); + _ = try parser.start(callback); +} + +fn callback(packet: Vita49) void { + std.debug.print("Packet recieved: {any}", .{packet}); +} +``` + +#### W/O Callback + +```zig +const std = @import("std"); +const astroz = @import("astroz"); +const Vita49 = astroz.vita49.Vita49; +const Parser = astroz.parsers.Parser; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + const allocator = gpa.allocator(); + + const P = Parser(Vita49); + const ip = "127.0.0.1".*; + const port: u16 = 65432; + var parser = P.new(&ip, port, 1024, allocator); + _ = try parser.start(null); +} + +``` + #### Create a CCSDS Packet ##### W/O Config @@ -120,10 +170,6 @@ pub fn main() !void { std.debug.print("\nCCSDS Packet Created:\n{any}", .{converted_test_packet}); } -``` -#### Setup Vita49 Parser - -```zig ``` #### precess a star to July 30, 2005 diff --git a/src/ccsds.zig b/src/ccsds.zig index c0f4b5b..f0a2b2c 100644 --- a/src/ccsds.zig +++ b/src/ccsds.zig @@ -29,7 +29,7 @@ pub const CCSDS = struct { var start: u8 = 6; const secondary_header: ?[]const u8 = if (secondary_header_flag) blk: { if (raw_packets.len < 10) { - std.debug.print("packet length is too short to have a secondary header", .{}); + std.log.warn("packet length is too short to have a secondary header", .{}); break :blk null; } start = if (config != null) config.?.secondary_header_length else 10; diff --git a/src/lib.zig b/src/lib.zig index 0e86467..8d8e7ca 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -3,3 +3,5 @@ pub const constants = @import("constants.zig"); pub const time = @import("time.zig"); pub const coordinates = @import("coordinates.zig"); pub const calculations = @import("calculations.zig"); +pub const vita49 = @import("vita49.zig"); +pub const parsers = @import("parsers.zig"); diff --git a/src/parsers.zig b/src/parsers.zig index 214e870..24cb931 100644 --- a/src/parsers.zig +++ b/src/parsers.zig @@ -33,9 +33,8 @@ pub fn Parser(comptime Frame: type) type { self.is_running; } - pub fn start(self: *Self) !void { + pub fn start(self: *Self, comptime callback: ?fn (Frame) void) !void { const addr = try net.Address.parseIp4(self.ip_address, self.port); - // const stream_ip = net.Address{ .in = loopback }; const stream = try net.tcpConnectToAddress(addr); defer stream.close(); @@ -48,6 +47,9 @@ pub fn Parser(comptime Frame: type) type { const new_frame = try Frame.new(&incoming_buffer, null); std.log.info("message recieved: {any}", .{new_frame}); _ = try self.packets.append(new_frame); + if (callback != null) { + callback.?(new_frame); + } } } @@ -96,6 +98,11 @@ fn _run_test_server(parse_type: []const u8) !void { } } +/// this is for running tests ONLY +fn _test_callback(packet: Vita49) void { + std.log.debug("CALLBACK CALLED: {any}", .{packet}); +} + test "Vita49 Parser Test" { const ip = "127.0.0.1".*; const port: u16 = 65432; @@ -111,7 +118,39 @@ test "Vita49 Parser Test" { const t2 = try std.Thread.spawn(.{}, struct { fn run(pt: *parser) !void { - try pt.start(); + try pt.start(null); + } + }.run, .{&par_test}); + defer t2.join(); + + std.time.sleep(10 * std.time.ns_per_s); + + const t3 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) void { + pt.stop(); + } + }.run, .{&par_test}); + defer t3.join(); + } + try std.testing.expectEqual(8, par_test.packets.capacity); +} + +test "Vita49 Parser Test w/ Callback" { + const ip = "127.0.0.1".*; + const port: u16 = 65432; + const parser = Parser(Vita49); + var par_test = parser.new(&ip, port, 1024, std.testing.allocator); + defer par_test.deinit(); + + { + const t1 = try std.Thread.spawn(.{}, _run_test_server, .{"vita49"}); + defer t1.join(); + + std.time.sleep(2 * std.time.ns_per_s); + + const t2 = try std.Thread.spawn(.{}, struct { + fn run(pt: *parser) !void { + try pt.start(_test_callback); } }.run, .{&par_test}); defer t2.join(); @@ -143,7 +182,7 @@ test "CCSDS Parser Test" { const t2 = try std.Thread.spawn(.{}, struct { fn run(pt: *parser) !void { - try pt.start(); + try pt.start(null); } }.run, .{&par_test}); defer t2.join(); diff --git a/src/time.zig b/src/time.zig index b726c4e..34541e4 100644 --- a/src/time.zig +++ b/src/time.zig @@ -88,7 +88,6 @@ pub const Datetime = struct { const hours = @as(u8, @intCast(@divFloor(remaining_seconds, std.time.s_per_hour))); remaining_seconds -= hours * @as(i64, std.time.s_per_hour); const minutes = @as(u8, @intCast(@divFloor(remaining_seconds, std.time.s_per_min))); - // const seconds = @as(u8, @intCast(remaining_seconds % std.time.s_per_min)); const seconds = @mod(remaining_seconds, std.time.s_per_min); return Datetime.new_datetime(year, month, day, hours, minutes, @as(f16, @floatFromInt(seconds))); diff --git a/src/vita49.zig b/src/vita49.zig index 5632d12..87bdffb 100644 --- a/src/vita49.zig +++ b/src/vita49.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const debug = std.debug; pub const Vita49Error = error{ MalformedPayloadRange, InsufficentData }; @@ -72,14 +71,14 @@ pub const Header = packed struct { } pub fn output(self: Self) void { - debug.print("Vita49 Packet Header:\n", .{}); - debug.print("Packet type: {}\n", .{self.packet_type}); - debug.print("Class ID: {}\n", .{self.class_id}); - debug.print("Trailer Present: {}\n", .{self.trailer}); - debug.print("TSI: {}\n", .{self.tsi}); - debug.print("TSF: {}\n", .{self.tsf}); - debug.print("Packet_Count: {}\n", .{self.packet_count}); - debug.print("Packet_Size: {}\n", .{self.packet_size}); + std.log.info("Vita49 Packet Header:\n", .{}); + std.log.info("Packet type: {}\n", .{self.packet_type}); + std.log.info.print("Class ID: {}\n", .{self.class_id}); + std.log.info("Trailer Present: {}\n", .{self.trailer}); + std.log.info("TSI: {}\n", .{self.tsi}); + std.log.info("TSF: {}\n", .{self.tsf}); + std.log.info("Packet_Count: {}\n", .{self.packet_count}); + std.log.info("Packet_Size: {}\n", .{self.packet_size}); } }; From f5224637747d563760d045555f9f7938aa80a1bd Mon Sep 17 00:00:00 2001 From: Anthony Templeton Date: Wed, 3 Jul 2024 00:02:19 -0400 Subject: [PATCH 6/6] clean up readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 20e445a..68b7d69 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,6 @@ b.installArtifact(exe); ### Examples - ### Setup Vita49 Parser #### W/ Callback