Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
* supporting groundSpeed
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berger <christian.berger@gu.se>
  • Loading branch information
chrberger committed Feb 6, 2020
1 parent 8dd9709 commit 8ac9ebc
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ the messages according to OpenDLV Standard Message Set into session 111 in
Google Protobuf format, simply start it as follows:

```
docker run --init --rm --net=host chalmersrevere/opendlv-device-gps-nmea-multi:v0.0.15 --nmea_ip=10.42.42.23 --nmea_port=9999 --cid=111 --verbose
docker run --init --rm --net=host chalmersrevere/opendlv-device-gps-nmea-multi:v0.0.16 --nmea_ip=10.42.42.23 --nmea_port=9999 --cid=111 --verbose
```

If you have an NMEA UDP producer, turn this microservice into a UDP-client listening to incoming UDP packets carrying raw NMEA messages:

```
docker run --init --rm --net=host chalmersrevere/opendlv-device-gps-nmea-multi:v0.0.15 --udp --nmea_ip=0.0.0.0 --nmea_port=9999 --cid=111 --verbose
docker run --init --rm --net=host chalmersrevere/opendlv-device-gps-nmea-multi:v0.0.16 --udp --nmea_ip=0.0.0.0 --nmea_port=9999 --cid=111 --verbose
```

## Build from sources on the example of Ubuntu 16.04 LTS
Expand Down
11 changes: 9 additions & 2 deletions src/nmea-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

NMEADecoder::NMEADecoder(
std::function<void(const double &latitude, const double &longitude, const std::chrono::system_clock::time_point &tp)> delegateLatitudeLongitude,
std::function<void(const float &heading, const std::chrono::system_clock::time_point &tp)> delegateHeading
std::function<void(const float &heading, const std::chrono::system_clock::time_point &tp)> delegateHeading,
std::function<void(const float &speed, const std::chrono::system_clock::time_point &tp)> delegateSpeed
) noexcept
: m_delegateLatitudeLongitude(std::move(delegateLatitudeLongitude))
, m_delegateHeading(std::move(delegateHeading)) {
, m_delegateHeading(std::move(delegateHeading))
, m_delegateSpeed(std::move(delegateSpeed)) {
m_buffer = new uint8_t[NMEADecoderConstants::BUFFER_SIZE];
}

Expand Down Expand Up @@ -143,6 +145,11 @@ size_t NMEADecoder::parseBuffer(const uint8_t *buffer, const size_t size, std::c
if (nullptr != m_delegateHeading) {
m_delegateHeading(heading, timestamp);
}

const float speed = static_cast<float>(std::stod(fields[7]) * 0.514444f);
if (nullptr != m_delegateSpeed) {
m_delegateSpeed(speed, timestamp);
}
}
}
// Found CRLF; decode message.
Expand Down
4 changes: 3 additions & 1 deletion src/nmea-decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class NMEADecoder {

public:
NMEADecoder(std::function<void(const double &latitude, const double &longitude, const std::chrono::system_clock::time_point &tp)> delegateLatitudeLongitude,
std::function<void(const float &heading, const std::chrono::system_clock::time_point &tp)> delegateHeading) noexcept;
std::function<void(const float &heading, const std::chrono::system_clock::time_point &tp)> delegateHeading,
std::function<void(const float &speed, const std::chrono::system_clock::time_point &tp)> delegateSpeed) noexcept;
~NMEADecoder();

public:
Expand All @@ -47,6 +48,7 @@ class NMEADecoder {
private:
std::function<void(const double &latitude, const double &longitude, const std::chrono::system_clock::time_point &tp)> m_delegateLatitudeLongitude{};
std::function<void(const float &heading, const std::chrono::system_clock::time_point &tp)> m_delegateHeading{};
std::function<void(const float &speed, const std::chrono::system_clock::time_point &tp)> m_delegateSpeed{};
};

#endif
Expand Down
14 changes: 14 additions & 0 deletions src/opendlv-device-gps-nmea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ int32_t main(int32_t argc, char **argv) {
m.northHeading(heading);
od4Session.send(m, cluon::time::convert(tp), senderStamp);

// Print values on console.
if (VERBOSE) {
std::stringstream buffer;
m.accept([](uint32_t, const std::string &, const std::string &) {},
[&buffer](uint32_t, std::string &&, std::string &&n, auto v) { buffer << n << " = " << std::setprecision(9) << v << '\n'; },
[]() {});
std::cout << buffer.str() << std::endl;
}
},
[&od4Session = od4, senderStamp = ID, VERBOSE](const float &speed, const std::chrono::system_clock::time_point &tp) {
opendlv::proxy::GroundSpeedReading m;
m.groundSpeed(speed);
od4Session.send(m, cluon::time::convert(tp), senderStamp);

// Print values on console.
if (VERBOSE) {
std::stringstream buffer;
Expand Down
Loading

0 comments on commit 8ac9ebc

Please sign in to comment.