-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsam1_dgs.cpp
More file actions
137 lines (114 loc) · 4.36 KB
/
Copy pathsam1_dgs.cpp
File metadata and controls
137 lines (114 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// AutoDGS / openSAM: Sam1Legacy
//
// Copyright (C) 2026 Holger Teutsch
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
// USA
//
#include "sam1_dgs.h"
#include <cassert>
#include "dgs/dgs_impl.h"
#include "log_msg.h"
namespace dgs {
SAM1DRefs sam1_drefs;
// A Sam1Legacy implementation for a DGS
class Sam1Legacy : public DGS {
Mode mode_ = kIdle;
Mode prev_mode_ = kIdle;
const std::string name_; // for logging only
XPLMDrawInfo_t drawinfo_{};
public:
Sam1Legacy(const std::string& name);
~Sam1Legacy() override;
bool HasEqStatus() const noexcept override { return false; }
bool isVdgs() const noexcept override { return false; }
void SetGuidanceParams(const GuidanceParams& params) override;
void SetPos(const XPLMDrawInfo_t& drawinfo, float height) override;
void SetPos(const XPLMDrawInfo_t& drawinfo) override;
void SetMode(Mode mode) override;
void UpdateInstance() override {}; // no instance to update
};
// external interface
bool InitSam1Legacy() {
return true;
}
std::unique_ptr<DGS> CreateSam1Legacy(const std::string& name) {
return std::make_unique<Sam1Legacy>(name);
}
// Sam1Legacy implementation
Sam1Legacy::Sam1Legacy(const std::string& name) : name_(name) {
LogMsg("Creating Sam1Legacy instance for stand '%s'", name_.c_str());
}
void Sam1Legacy::SetMode(Mode mode) {
if (mode_ == mode)
return;
prev_mode_ = mode_;
mode_ = mode;
LogMsg("Sam1Legacy '%s' mode changed from %d to %d", name_.c_str(), (int)prev_mode_, (int)mode_);
if (mode_ >= kArrival) {
sam1_drefs.is_active = true;
sam1_drefs.dgs_x = drawinfo_.x;
sam1_drefs.dgs_z = drawinfo_.z;
} else if (mode_ == kIdle && prev_mode_ >= kArrival) // the DGS was active and now it's idle
sam1_drefs.is_active = false; // deactivate
}
Sam1Legacy::~Sam1Legacy() {
if (mode_ > kIdle)
sam1_drefs.is_active = false;
}
void Sam1Legacy::SetGuidanceParams(const GuidanceParams& dgs_params) {
// translate into compatible SAM1 values
sam1_drefs.lateral = -dgs_params.ref_x;
sam1_drefs.longitudinal = std::min(dgs_params.ref_z, 30.0f);
if (dgs_params.status == 0 || dgs_params.status == kDgsGstIdentified) {
sam1_drefs.status = SAM1_TRACK;
if (sam1_drefs.longitudinal <= 0.0f) {
sam1_drefs.status = SAM1_STOP_ZONE;
sam1_drefs.lateral = 0.0f;
}
} else if (dgs_params.status == kDgsGstStop) {
sam1_drefs.status = SAM1_STOP_ZONE;
sam1_drefs.lateral = 0.0f;
} else if (dgs_params.status == kDgsGstOk) {
sam1_drefs.status = SAM1_STOP_ZONE;
sam1_drefs.lateral = 0.0f;
sam1_drefs.longitudinal = -0.1f;
} else if (dgs_params.status == kDgsGstTooFar) {
sam1_drefs.status = SAM1_TRACK;
} else {
sam1_drefs.status = SAM1_IDLE;
sam1_drefs.lateral = SAM1_LATERAL_OFF;
sam1_drefs.longitudinal = 0.0f;
}
static float log_ts;
if (now > log_ts + 2.0f) {
log_ts = now;
LogMsg("SAM1, active %d, x: %0.1f, status: %d, lateral: %0.1f, longitudinal: %0.1f",
sam1_drefs.is_active, sam1_drefs.dgs_x, (int)sam1_drefs.status, sam1_drefs.lateral, sam1_drefs.longitudinal);
}
}
void Sam1Legacy::SetPos(const XPLMDrawInfo_t& drawinfo, [[maybe_unused]]float height) {
drawinfo_ = drawinfo;
LogMsg("SAM1 position updated, x: %0.1f, y: %0.1f, z: %0.1f", drawinfo_.x, drawinfo_.y, drawinfo_.z);
if (mode_ >= kArrival) {
sam1_drefs.dgs_x = drawinfo_.x;
sam1_drefs.dgs_z = drawinfo_.z;
}
}
void Sam1Legacy::SetPos(const XPLMDrawInfo_t& drawinfo) {
SetPos(drawinfo, 0.0f);
}
} // namespace dgs