Skip to content

Commit 648a883

Browse files
committed
test SeaTalk autopilot model apply
1 parent a0af271 commit 648a883

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

tests/test_seatalk_model_apply.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cmath>
22
#include <cstdio>
33
#include <cstdlib>
4+
#include <cstring>
45

56
#include <seatalk.hpp>
67

@@ -60,7 +61,38 @@ int main() {
6061
REQUIRE(model.steering.rudder.angle_deg.valid);
6162
NEAR(model.steering.rudder.angle_deg.value, -2.0f, 0.001f);
6263

63-
REQUIRE(receiver.decoded_count() == 7);
64+
const uint8_t autopilot[] = {0x84, 0x16, 0x40, 0x00, 0x42, 0x00, 0xfe, 0x01, 0x08};
65+
accept(receiver, model, autopilot, sizeof(autopilot), now_us);
66+
REQUIRE(model.autopilot.controller.enabled.value);
67+
REQUIRE(model.autopilot.controller.mode.value == ship_data_model::AutopilotMode::compass);
68+
REQUIRE(model.autopilot.controller.heading_deg.valid);
69+
REQUIRE(model.autopilot.controller.heading_command_deg.valid);
70+
NEAR(model.autopilot.controller.heading_deg.value, 90.0f, 0.001f);
71+
NEAR(model.autopilot.controller.heading_command_deg.value, 90.0f, 0.001f);
72+
NEAR(model.steering.rudder.angle_deg.value, -2.0f, 0.001f);
73+
74+
const uint8_t nav_to_wp[] = {0x85, 0xb5, 0x07, 0x01, 0x00, 0x05, 0x07, 0x00};
75+
accept(receiver, model, nav_to_wp, sizeof(nav_to_wp), now_us);
76+
REQUIRE(model.route.apb.xte_nmi.valid);
77+
REQUIRE(model.route.apb.heading_to_steer_deg.valid);
78+
REQUIRE(model.route.waypoint.distance_nmi.valid);
79+
REQUIRE(model.route.apb.mode_hint.value == ship_data_model::AutopilotMode::nav);
80+
NEAR(model.route.apb.xte_nmi.value, 1.23f, 0.001f);
81+
NEAR(model.route.apb.heading_to_steer_deg.value, 90.0f, 0.001f);
82+
NEAR(model.route.waypoint.distance_nmi.value, 8.0f, 0.001f);
83+
84+
const uint8_t key[] = {0x86, 0x01, 0x41, 0xbe};
85+
accept(receiver, model, key, sizeof(key), now_us);
86+
REQUIRE(std::strcmp(model.notifications.messages.event.event_id, "seatalk_ap_key") == 0);
87+
REQUIRE(model.notifications.messages.event.event_state == 'L');
88+
REQUIRE(std::strcmp(model.notifications.messages.event.event_text, "auto") == 0);
89+
90+
const uint8_t variation[] = {0x99, 0x00, 0xfe};
91+
accept(receiver, model, variation, sizeof(variation), now_us);
92+
REQUIRE(model.ins.imu.magnetic_variation_deg.valid);
93+
NEAR(model.ins.imu.magnetic_variation_deg.value, -2.0f, 0.001f);
94+
95+
REQUIRE(receiver.decoded_count() == 11);
6496
REQUIRE(receiver.unsupported_count() == 0);
6597
return 0;
6698
}

0 commit comments

Comments
 (0)