QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AshtechPlan.cc
Go to the documentation of this file.
2
3#include <cmath>
4
5#include <QtCore/QByteArrayView>
6
7#include "GPSProtocolMath.h"
8#include "GPSReceiverConfig.h"
9
10namespace Ashtech::Plan {
11
12namespace {
13
15double degreesMinutes(double degrees)
16{
17 const double magnitude = std::abs(degrees);
18 const double whole = std::trunc(magnitude);
19 return whole * 100.0 + (magnitude - whole) * 60.0;
20}
21
22} // namespace
23
24GPSCommandOutcome rejection(std::string_view reply)
25{
26 return reply.starts_with("$PASHR,NAK*") ? GPSCommandOutcome::Rejected : GPSCommandOutcome::Pending;
27}
28
29GPSCommandOutcome acknowledgement(std::string_view reply)
30{
31 return reply.starts_with("$PASHR,ACK*") ? GPSCommandOutcome::Acknowledged : rejection(reply);
32}
33
34QByteArray line(std::string_view command)
35{
36 return QByteArrayView(command).toByteArray() + "\r\n";
37}
38
39QByteArray line(std::string_view command, char port)
40{
41 return line(command).replace("{port}", QByteArray(1, port));
42}
43
44QByteArray surveyStart(std::chrono::seconds duration)
45{
46 return "$PASHS,POS,AVG," + QByteArray::number(static_cast<unsigned>(duration.count())) + "\r\n";
47}
48
49QByteArray fixedPosition(const GPSEllipsoidPosition& position)
50{
51 const double latitude = position.latitudeDegrees;
52 const double longitude = position.longitudeDegrees;
53 return "$PASHS,POS," + gpsFixedDecimal(degreesMinutes(latitude), 8) + (latitude < 0.0 ? ",S," : ",N,") +
54 gpsFixedDecimal(degreesMinutes(longitude), 8) + (longitude < 0.0 ? ",W," : ",E,") +
55 gpsFixedDecimal(position.altitudeMeters, 5) + ",PC1\r\n";
56}
57
59{
61 {.label = "$PASHS,POS (fixed position)"});
62}
63
64GPSCommandSequence sequence(std::span<const Setting> settings, char port)
65{
66 GPSCommandSequence result;
67 for (const Setting& setting : settings) {
68 result.steps.emplace_back(
69 gpsCommand(line(setting.command, port), RESPONSE_TIMEOUT, acknowledgement, {.required = setting.required}));
70 }
71 return result;
72}
73
74} // namespace Ashtech::Plan
GPSCommandOutcome
Definition GPSCommand.h:33
GPSCommandSequence::Command gpsCommand(QByteArray wire, std::chrono::milliseconds timeout, std::variant< GPSTextMatcher, GPSCommandSequence::RawReply > reply, GPSCommandOptions options={})
Definition GPSCommand.h:162
QByteArray gpsFixedDecimal(double value, int decimals)
int32_t latitude
Definition UBXPlan.cc:40
int32_t longitude
Definition UBXPlan.cc:42
QByteArray surveyStart(std::chrono::seconds duration)
GPSCommandOutcome rejection(std::string_view reply)
A NAK rejects any command.
GPSCommandSequence::Command fixedPositionCommand(const GPSEllipsoidPosition &position)
The fixedPosition() command, acknowledged by an ACK and labelled without its coordinates.
QByteArray fixedPosition(const GPSEllipsoidPosition &position)
GPSCommandSequence sequence(std::span< const Setting > settings, char port)
settings for port, each acknowledged by an ACK.
constexpr std::chrono::milliseconds RESPONSE_TIMEOUT
Per attempt, for every command.
Definition AshtechPlan.h:28
GPSCommandOutcome acknowledgement(std::string_view reply)
A $PASHS setting is acknowledged by an ACK.
QByteArray line(std::string_view command)
command as one CR/LF-terminated line.
std::vector< Command > steps
Definition GPSCommand.h:150
WGS84 geodetic position with ellipsoid height, not mean-sea-level altitude.