Skip to content

Commit 5067bf2

Browse files
authored
Convert most variables to camelCase (#27)
* update namings to snakeCase * forgot to update TLE * update examples
1 parent 982c8c7 commit 5067bf2

25 files changed

+743
-724
lines changed

examples/create_ccsds_packet.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ pub fn main() !void {
77
defer _ = gpa.deinit();
88
const allocator = gpa.allocator();
99

10-
const raw_test_packet: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
11-
var converted_test_packet = try Ccsds.init(&raw_test_packet, allocator, null);
12-
defer converted_test_packet.deinit();
10+
const rawTestPacket: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
11+
var convertedTestPacket = try Ccsds.init(&rawTestPacket, allocator, null);
12+
defer convertedTestPacket.deinit();
1313

14-
std.debug.print("CCSDS Packet Created:\n{any}", .{converted_test_packet});
14+
std.debug.print("CCSDS Packet Created:\n{any}", .{convertedTestPacket});
1515
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"secondary_header_length": 12
2+
"secondaryHeaderLength": 12
33
}

examples/create_ccsds_packet_config.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ pub fn main() !void {
88
defer _ = gpa.deinit();
99
const allocator = gpa.allocator();
1010

11-
const config_file = try std.fs.cwd().readFileAlloc(allocator, "examples/create_ccsds_packet_config.json", 512);
12-
defer allocator.free(config_file);
11+
const configFile = try std.fs.cwd().readFileAlloc(allocator, "examples/create_ccsds_packet_config.json", 512);
12+
defer allocator.free(configFile);
1313

14-
const config = try Ccsds.parseConfig(config_file, allocator);
14+
const config = try Ccsds.parseConfig(configFile, allocator);
1515

16-
const raw_test_packet: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
17-
var converted_test_packet = try Ccsds.init(&raw_test_packet, allocator, config);
18-
defer converted_test_packet.deinit();
16+
const rawTestPacket: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
17+
var convertedTestPacket = try Ccsds.init(&rawTestPacket, allocator, config);
18+
defer convertedTestPacket.deinit();
1919

20-
std.debug.print("\nCCSDS Packet Created:\n{any}", .{converted_test_packet});
20+
std.debug.print("\nCCSDS Packet Created:\n{any}", .{convertedTestPacket});
2121
}

examples/orbit_phase_change.zig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ pub fn main() !void {
1111
defer _ = gpa.deinit();
1212
const allocator = gpa.allocator();
1313

14-
const test_tle =
14+
const testTle =
1515
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1616
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1717
;
1818

19-
var tle = try Tle.parse(test_tle, allocator);
19+
var tle = try Tle.parse(testTle, allocator);
2020
defer tle.deinit();
2121

22-
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
23-
defer test_sc.deinit();
22+
var testSc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
23+
defer testSc.deinit();
2424

25-
const phase_maneuver = Impulse{
25+
const phaseManeuver = Impulse{
2626
.time = 2500000.0,
27-
.delta_v = .{ 1.0, 0.0, 0.0 },
27+
.deltaV = .{ 1.0, 0.0, 0.0 },
2828
.mode = .Phase,
29-
.phase_change = math.pi / 2.0,
29+
.phaseChange = math.pi / 2.0,
3030
};
3131

32-
const impulses = [_]Impulse{phase_maneuver};
32+
const impulses = [_]Impulse{phaseManeuver};
3333

34-
try test_sc.propagate(
35-
test_sc.tle.first_line.epoch,
34+
try testSc.propagate(
35+
testSc.tle.firstLine.epoch,
3636
3, // 3 days worth of orbit predictions
3737
1, // steps, i.e. repredict every simulated second
3838
&impulses,
3939
);
4040

41-
for (test_sc.orbit_predictions.items) |iter| {
41+
for (testSc.orbitPredictions.items) |iter| {
4242
const r = math.sqrt(iter.state[0] * iter.state[0] + iter.state[1] * iter.state[1] + iter.state[2] * iter.state[2]);
4343

4444
std.debug.print("Next Prediction is: {any}\n", .{r});

examples/orbit_plane_change.zig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ pub fn main() !void {
1111
defer _ = gpa.deinit();
1212
const allocator = gpa.allocator();
1313

14-
const test_tle =
14+
const testTle =
1515
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1616
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1717
;
1818

19-
var tle = try Tle.parse(test_tle, allocator);
19+
var tle = try Tle.parse(testTle, allocator);
2020
defer tle.deinit();
2121

22-
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
23-
defer test_sc.deinit();
22+
var testSc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
23+
defer testSc.deinit();
2424

25-
const plane_change_maneuver = Impulse{
25+
const planeChangeManeuver = Impulse{
2626
.time = 2500000.0,
27-
.delta_v = .{ 0.0, 0.0, 0.0 }, // Not used for plane changes
28-
.mode = .Plane_Change,
29-
.plane_change = .{
30-
.delta_inclination = math.pi / 18.0, // 10-degree inclination change
31-
.delta_raan = math.pi / 36.0, // 5-degree RAAN change
27+
.deltaV = .{ 0.0, 0.0, 0.0 }, // Not used for plane changes
28+
.mode = .PlaneChange,
29+
.planeChange = .{
30+
.deltaInclination = math.pi / 18.0, // 10-degree inclination change
31+
.deltaRaan = math.pi / 36.0, // 5-degree RAAN change
3232
},
3333
};
3434

35-
const impulses = [_]Impulse{plane_change_maneuver};
35+
const impulses = [_]Impulse{planeChangeManeuver};
3636

37-
try test_sc.propagate(
38-
test_sc.tle.first_line.epoch,
37+
try testSc.propagate(
38+
testSc.tle.firstLine.epoch,
3939
3, // 3 days worth of orbit predictions
4040
1, // steps, i.e. repredict every simulated second
4141
&impulses,
4242
);
4343

44-
for (test_sc.orbit_predictions.items) |iter| {
44+
for (testSc.orbitPredictions.items) |iter| {
4545
const r = math.sqrt(iter.state[0] * iter.state[0] + iter.state[1] * iter.state[1] + iter.state[2] * iter.state[2]);
4646

4747
std.debug.print("Next Prediction is: {any}\n", .{r});

examples/orbit_prop.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ pub fn main() !void {
1010
defer _ = gpa.deinit();
1111
const allocator = gpa.allocator();
1212

13-
const test_tle =
13+
const testTle =
1414
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1515
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1616
;
1717

18-
var tle = try Tle.parse(test_tle, allocator);
18+
var tle = try Tle.parse(testTle, allocator);
1919
defer tle.deinit();
2020

21-
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
22-
defer test_sc.deinit();
21+
var testSc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
22+
defer testSc.deinit();
2323

24-
try test_sc.propagate(
25-
test_sc.tle.first_line.epoch,
24+
try testSc.propagate(
25+
testSc.tle.firstLine.epoch,
2626
3, // 3 days worth of orbit predictions
2727
1, // steps, i.e. repredict every simulated second
2828
null,
2929
);
3030

31-
for (test_sc.orbit_predictions.items) |iter| {
31+
for (testSc.orbitPredictions.items) |iter| {
3232
const r = math.sqrt(iter.state[0] * iter.state[0] + iter.state[1] * iter.state[1] + iter.state[2] * iter.state[2]);
3333

3434
std.debug.print("Next Prediction is: {any}\n", .{r});

examples/orbit_prop_impulse.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ pub fn main() !void {
1010
defer _ = gpa.deinit();
1111
const allocator = gpa.allocator();
1212

13-
const test_tle =
13+
const testTle =
1414
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1515
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1616
;
1717

18-
var tle = try Tle.parse(test_tle, allocator);
18+
var tle = try Tle.parse(testTle, allocator);
1919
defer tle.deinit();
2020

21-
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
22-
defer test_sc.deinit();
21+
var testSc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
22+
defer testSc.deinit();
2323

2424
const impulses = [_]Spacecraft.Impulse{
25-
.{ .time = 3600.0, .delta_v = .{ 0.05, 0.03, 0.01 }, .mode = .Absolute },
26-
.{ .time = 7200.0, .delta_v = .{ 1.1, -0.05, 0.02 }, .mode = .Absolute },
27-
.{ .time = 10800.0, .delta_v = .{ -0.03, 0.08, -0.01 }, .mode = .Absolute },
25+
.{ .time = 3600.0, .deltaV = .{ 0.05, 0.03, 0.01 }, .mode = .Absolute },
26+
.{ .time = 7200.0, .deltaV = .{ 1.1, -0.05, 0.02 }, .mode = .Absolute },
27+
.{ .time = 10800.0, .deltaV = .{ -0.03, 0.08, -0.01 }, .mode = .Absolute },
2828
};
2929

30-
try test_sc.propagate(
31-
test_sc.tle.first_line.epoch,
30+
try testSc.propagate(
31+
testSc.tle.firstLine.epoch,
3232
3, // 3 days worth of orbit predictions
3333
1, // steps, i.e. repredict every simulated second
3434
&impulses,
3535
);
3636

37-
for (test_sc.orbit_predictions.items) |iter| {
37+
for (testSc.orbitPredictions.items) |iter| {
3838
const r = math.sqrt(iter.state[0] * iter.state[0] + iter.state[1] * iter.state[1] + iter.state[2] * iter.state[2]);
3939

4040
std.debug.print("Next Prediction is: {any}\n", .{r});

examples/parse_ccsds.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ pub fn main() !void {
88
defer _ = gpa.deinit();
99
const allocator = gpa.allocator();
1010

11-
const file_name = "./test/ccsds.bin".*;
11+
const fileName = "./test/ccsds.bin".*;
1212

1313
const P = Parser(Ccsds);
1414
var parser = try P.init(null, null, 1024, allocator);
1515
defer parser.deinit();
1616

17-
_ = try parser.parseFromFile(&file_name, null, null);
17+
_ = try parser.parseFromFile(&fileName, null, null);
1818

1919
for (parser.packets.items) |packet| {
2020
std.log.info("Packets from files: 0x{x}", .{packet.packets});

examples/parse_ccsds_file_sync.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ pub fn main() !void {
88
defer _ = gpa.deinit();
99
const allocator = gpa.allocator();
1010

11-
const file_name = "./test/ccsds.bin".*;
12-
const sync_pattern = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02 };
11+
const fileName = "./test/ccsds.bin".*;
12+
const syncPattern = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02 };
1313

1414
const P = Parser(Ccsds);
1515
var parser = try P.init(null, null, 1024, allocator);
1616
defer parser.deinit();
1717

18-
_ = try parser.parseFromFile(&file_name, &sync_pattern, null);
18+
_ = try parser.parseFromFile(&fileName, &syncPattern, null);
1919

2020
for (parser.packets.items) |packet| {
2121
std.log.info("Packets from files: 0x{x}", .{packet.packets});

examples/parse_fits_file.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ pub fn main() !void {
77
defer _ = gpa.deinit();
88
const allocator = gpa.allocator();
99

10-
var fits_png = try Fits.open_and_parse(allocator);
11-
defer fits_png.close();
10+
var fitsPng = try Fits.open_and_parse(allocator);
11+
defer fitsPng.close();
1212
}

examples/parse_tle.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ pub fn main() !void {
77
defer _ = gpa.deinit();
88
const allocator = gpa.allocator();
99

10-
const test_tle =
10+
const testTle =
1111
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1212
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1313
;
1414

15-
var tle = try Tle.parse(test_tle, allocator);
15+
var tle = try Tle.parse(testTle, allocator);
1616
defer tle.deinit();
1717

1818
tle.output();

examples/parse_vita49.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ pub fn main() !void {
88
defer _ = gpa.deinit();
99
const allocator = gpa.allocator();
1010

11+
const file_name = "./test/vita49.bin".*;
12+
const sync_pattern = .{ 0x3A, 0x02, 0x0a, 0x00, 0x34, 0x12, 0x00, 0x00, 0x00, 0x56 };
1113
const P = Parser(Vita49);
12-
const ip = "127.0.0.1".*;
13-
const port: u16 = 65432;
14-
var parser = try P.init(&ip, port, 1024, allocator);
14+
var parser = try P.init(null, null, 1024, allocator);
1515
defer parser.deinit();
16-
_ = try parser.start(null);
16+
17+
_ = try parser.parseFromFile(&file_name, &sync_pattern, null);
18+
for (parser.packets.items) |packet| {
19+
try std.testing.expectEqualStrings("Hello, VITA 49!", packet.payload);
20+
}
1721
}

examples/parse_vita49_callback.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ pub fn main() !void {
88
defer _ = gpa.deinit();
99
const allocator = gpa.allocator();
1010

11+
const file_name = "./test/vita49.bin".*;
12+
const sync_pattern = .{ 0x3A, 0x02, 0x0a, 0x00, 0x34, 0x12, 0x00, 0x00, 0x00, 0x56 };
1113
const P = Parser(Vita49);
12-
const ip = "127.0.0.1".*;
13-
const port: u16 = 65432;
14-
var parser = try P.init(&ip, port, 1024, allocator);
14+
var parser = try P.init(null, null, 1024, allocator);
1515
defer parser.deinit();
16-
_ = try parser.start(callback);
16+
17+
_ = try parser.parseFromFile(&file_name, &sync_pattern, callback);
18+
for (parser.packets.items) |packet| {
19+
try std.testing.expectEqualStrings("Hello, VITA 49!", packet.payload);
20+
}
1721
}
1822

1923
fn callback(packet: Vita49) void {

examples/simple_spacecraft_orientation.zig

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,41 @@ pub fn main() !void {
99
defer _ = gpa.deinit();
1010
const allocator = gpa.allocator();
1111

12-
const raw_tle =
12+
const rawTle =
1313
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
1414
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
1515
;
16-
var test_tle = try Tle.parse(raw_tle, allocator);
17-
defer test_tle.deinit();
18-
var sc = Spacecraft.init("dummy_sc", test_tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
16+
var testTle = try Tle.parse(rawTle, allocator);
17+
defer testTle.deinit();
18+
var sc = Spacecraft.init("dummy_sc", testTle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
1919
defer sc.deinit();
2020

21-
sc.angular_velocity = .{ 0.0, 0.0, 0.0 };
21+
sc.angularVelocity = .{ 0.0, 0.0, 0.0 };
2222

2323
const dt = 120.0; // 2 mins time step
24-
const simulation_time = 3 * 24 * 60 * 60.0; // 3 days in seconds
25-
const orbital_period = 90 * 60.0; // 90 minutes orbital period
24+
const simulationTime = 3 * 24 * 60 * 60.0; // 3 days in seconds
25+
const orbitalPeriod = 90 * 60.0; // 90 minutes orbital period
2626
var t: f64 = 0;
2727

28-
while (t < simulation_time) : (t += dt) {
28+
while (t < simulationTime) : (t += dt) {
2929
// Simulate a dramatic torque effect
30-
const torque_x = 0.001 * @sin(2 * std.math.pi * t / (orbital_period * 2));
31-
const torque_y = 0.0005 * @cos(2 * std.math.pi * t / (orbital_period * 3));
32-
const torque_z = 0.0002 * @sin(2 * std.math.pi * t / orbital_period);
30+
const torqueX = 0.001 * @sin(2 * std.math.pi * t / (orbitalPeriod * 2));
31+
const torqueY = 0.0005 * @cos(2 * std.math.pi * t / (orbitalPeriod * 3));
32+
const torqueZ = 0.0002 * @sin(2 * std.math.pi * t / orbitalPeriod);
3333

3434
// Update angular velocity based on torque (simplified)
35-
sc.angular_velocity[0] += torque_x * dt;
36-
sc.angular_velocity[1] += torque_y * dt;
37-
sc.angular_velocity[2] += torque_z * dt;
35+
sc.angularVelocity[0] += torqueX * dt;
36+
sc.angularVelocity[1] += torqueY * dt;
37+
sc.angularVelocity[2] += torqueZ * dt;
3838

3939
// Update attitude
4040
sc.updateAttitude();
4141
sc.propagateAttitude(dt);
4242

4343
// Simulate simple circular orbit
44-
const orbit_radius = 7000.0;
45-
const x = orbit_radius * @cos(2 * std.math.pi * t / orbital_period);
46-
const y = orbit_radius * @sin(2 * std.math.pi * t / orbital_period);
44+
const orbitRadius = 7000.0;
45+
const x = orbitRadius * @cos(2 * std.math.pi * t / orbitalPeriod);
46+
const y = orbitRadius * @sin(2 * std.math.pi * t / orbitalPeriod);
4747
const z = 0.0;
4848

4949
std.log.debug("Showing orbiting info: {d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d}\n", .{
@@ -52,9 +52,9 @@ pub fn main() !void {
5252
sc.quaternion[1],
5353
sc.quaternion[2],
5454
sc.quaternion[3],
55-
sc.angular_velocity[0],
56-
sc.angular_velocity[1],
57-
sc.angular_velocity[2],
55+
sc.angularVelocity[0],
56+
sc.angularVelocity[1],
57+
sc.angularVelocity[2],
5858
x,
5959
y,
6060
z,

0 commit comments

Comments
 (0)