Skip to content

Commit ad46477

Browse files
committed
Added code for new gnss message in comments
1 parent 75e0d4a commit ad46477

File tree

12 files changed

+58
-1462
lines changed

12 files changed

+58
-1462
lines changed

boards/varmint_h7/common/Varmint.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,15 @@ bool Varmint::gnss_read(rosflight_firmware::GnssStruct * gnss)
248248
if (gps_.rxFifoReadMostRecent((uint8_t *) &p, sizeof(p))) {
249249
gnss->header = p.header;
250250
gnss->pps = p.pps;
251-
struct tm tm;
252-
tm.tm_sec = p.pvt.sec;
253-
tm.tm_min = p.pvt.min;
254-
tm.tm_hour = p.pvt.hour;
255-
tm.tm_mday = p.pvt.day;
256-
tm.tm_mon = p.pvt.month - 1;
257-
tm.tm_year = p.pvt.year - 1900;
258-
gnss->time = mktime(&tm);
251+
// struct tm tm;
252+
// tm.tm_sec = p.pvt.sec;
253+
// tm.tm_min = p.pvt.min;
254+
// tm.tm_hour = p.pvt.hour;
255+
// tm.tm_mday = p.pvt.day;
256+
// tm.tm_mon = p.pvt.month - 1;
257+
// tm.tm_year = p.pvt.year - 1900;
258+
//gnss->time = mktime(&tm);
259+
gnss->unix_seconds = p.unix_seconds; // Unix time
259260
gnss->t_acc = p.pvt.tAcc;
260261
gnss->time_of_week = p.pvt.iTOW;
261262
gnss->year = p.pvt.year;

boards/varmint_h7/common/drivers/Ubx.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
#include "Packets.h"
4343
#include "misc.h"
44-
44+
#include <ctime>
4545
extern Time64 time64;
4646

4747
#define SET(buf, data, type) *((type *) (buf)) = data
@@ -235,6 +235,19 @@ void Ubx::endDma(void)
235235
if ((p.cl == 0x01) && (p.id == 0x07)) {
236236
gotPvt_ = time64.Us();
237237
memcpy((uint8_t *) &(ubx_.pvt), p.payload, sizeof(ubx_.pvt));
238+
struct tm tm;
239+
tm.tm_sec = ubx_.pvt.sec;
240+
tm.tm_min = ubx_.pvt.min;
241+
tm.tm_hour = ubx_.pvt.hour;
242+
tm.tm_mday = ubx_.pvt.day;
243+
tm.tm_mon = ubx_.pvt.month - 1;
244+
tm.tm_year = ubx_.pvt.year - 1900;
245+
ubx_.unix_seconds = mktime(&tm);
246+
if (ubx_.pvt.nano<0)
247+
{
248+
ubx_.unix_seconds -= 1;
249+
ubx_.pvt.nano += 1000000000;
250+
}
238251
} else if ((p.cl == 0x01) && (p.id == 0x20)) {
239252
gotTime_ = time64.Us();
240253
memcpy((uint8_t *) (&ubx_.time), p.payload, sizeof(ubx_.time));

boards/varmint_h7/common/drivers/Ubx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ typedef struct __attribute__((__packed__))
136136
typedef struct __attribute__((__packed__)) // This matches the Ubx packet, do not modify
137137
{
138138
rosflight_firmware::PacketHeader header;
139+
int64_t unix_seconds; // computed from pvt time values
139140
uint64_t drdy;
140141
uint64_t groupDelay; // us, time from measurement to drdy, (approximate!)
141142
uint64_t pps;

comms/mavlink/generating_v1.0_instructions.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ git clone https://github.com/rosflight/mavlink.git
77
# Create the .c/h files from that directory
88
# in windows:
99
set PYTHONPATH=%PYTHONPATH%;path\to\mavlink\repo && python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=./v1.0 rosflight.xml
10-
# e.g.,
10+
# e.g.,
11+
rmdir /s v1.0
1112
set PYTHONPATH=%PYTHONPATH%;C:\Projects\mavlink && python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=./v1.0 rosflight.xml
1213

1314
# in linux:

comms/mavlink/mavlink.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,35 @@ void Mavlink::send_imu(uint8_t system_id, uint64_t timestamp_us, const turbomath
142142
gyro.x, gyro.y, gyro.z, temperature);
143143
send_message(msg, 0);
144144
}
145+
146+
#ifdef MAVLINK_MESSAGE_INFO_ROSFLIGHT2_GNSS
147+
void Mavlink::send_gnss(uint8_t system_id, const GNSSData & data)
148+
{
149+
mavlink_message_t msg;
150+
mavlink_msg_rosflight2_gnss_pack(
151+
system_id, compid_, &msg,
152+
data.unix_seconds, // Unix time in seconds
153+
data.nano, // nanoseconds
154+
data.fix_type,
155+
data.num_sat,
156+
data.lat, data.lon, data.height_ellipsoid,
157+
data.vel_n, data.vel_e, data.vel_d,
158+
data.h_acc, data.v_acc, data.speed_accy,
159+
data.header.timestamp);
160+
send_message(msg);
161+
}
162+
#else
145163
void Mavlink::send_gnss(uint8_t system_id, const GNSSData & data)
146164
{
147165
mavlink_message_t msg;
148166
mavlink_msg_rosflight_gnss_pack(
149-
system_id, compid_, &msg, data.time_of_week, data.fix_type, data.time, data.nano, data.lat,
167+
system_id, compid_, &msg, data.time_of_week, data.fix_type, data.unix_seconds, data.nano, data.lat,
150168
data.lon, data.height_ellipsoid, data.vel_n, data.vel_e, data.vel_d, data.h_acc, data.v_acc, data.ecef.x,
151169
data.ecef.y, data.ecef.z, data.ecef.p_acc, data.ecef.vx, data.ecef.vy, data.ecef.vz,
152170
data.ecef.s_acc, data.header.timestamp);
153171
send_message(msg);
154172
}
173+
#endif
155174

156175
void Mavlink::send_gnss_full(uint8_t system_id, const GNSSFull & full)
157176
{

comms/mavlink/rosflight.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ git clone https://github.com/rosflight/mavlink.git
88

99
# Create the .c/h files from that directory
1010
# in windows:
11+
rmdir /s v1.0
12+
Y
1113
set PYTHONPATH=%PYTHONPATH%;path\to\mavlink\repo && python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=./v1.0 rosflight.xml
1214
# e.g.,
15+
rmdir /s v1.0
16+
Y
1317
set PYTHONPATH=%PYTHONPATH%;C:\Projects\mavlink && python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=./v1.0 rosflight.xml
1418

1519
# in linux:
20+
sudo rm -r ./v1.0
1621
PYTHONPATH=$PYTHONPATH:/path/to/mavlink/repo python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=./v1.0 rosflight.xml
1722

1823
# If you are in the mavlink repo environment with rosflight.xml in the standard location:
@@ -316,8 +321,8 @@ python3 -m pymavlink.tools.mavgen --lang=C --wire-protocol=1.0 --output=generate
316321
<field type="uint32_t" name="doRearm"/>
317322
</message>
318323
<!--
319-
<message id="197" name="ROSFLIGHT_GNSS">
320-
<description>Rosflight GNSS message</description>
324+
<message id="197" name="ROSFLIGHT2_GNSS">
325+
<description>Rosflight2 GNSS message</description>
321326
<field type="int64_t" name="seconds">Unix time, in seconds</field>
322327
<field type="int32_t" name="nanos">Fractional Unix time</field>
323328
<field type="uint8_t" name="fix_type" enum="GNSS_FIX_TYPE">GNSS fix type</field>

comms/mavlink/v1.0/rosflight/mavlink.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef MAVLINK_H
77
#define MAVLINK_H
88

9-
#define MAVLINK_PRIMARY_XML_HASH -7137736376506596709
9+
#define MAVLINK_PRIMARY_XML_HASH -428044560288662501
1010

1111
#ifndef MAVLINK_STX
1212
#define MAVLINK_STX 254

0 commit comments

Comments
 (0)