libosmscout  1.1.1
SpeedAgent.h
Go to the documentation of this file.
1 #ifndef OSMSCOUT_NAVIGATION_SPEED_AGENT_H
2 #define OSMSCOUT_NAVIGATION_SPEED_AGENT_H
3 
4 /*
5  This source is part of the libosmscout library
6  Copyright (C) 2019 Lukas Karas
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  */
22 
26 
27 namespace osmscout {
28 
29 struct OSMSCOUT_API CurrentSpeedMessage CLASS_FINAL : public NavigationMessage
30 {
31  double speed; // km/h
32 
33  CurrentSpeedMessage(const Timestamp& timestamp,
34  double speed);
35 };
36 
37 struct OSMSCOUT_API MaxAllowedSpeedMessage CLASS_FINAL : public NavigationMessage
38 {
39  double maxAllowedSpeed; // km/h
40  bool defined;
41 
42  MaxAllowedSpeedMessage(const Timestamp& timestamp,
43  double maxAllowedSpeed,
44  bool defined);
45 };
46 
47 class OSMSCOUT_API SpeedAgent CLASS_FINAL : public NavigationAgent
48 {
49 private:
50  struct TrackSegment
51  {
52  Distance distance;
53  Timestamp::duration duration{Timestamp::duration::zero()};
54 
55  inline TrackSegment(const Distance &distance, const Timestamp::duration &duration):
56  distance(distance), duration(duration)
57  {}
58  };
59  std::list<TrackSegment> segmentFifo; // buffer of segments for 5 seconds used for speed computation
60 
61  struct Position
62  {
63  GeoCoord coord;
65 
66  inline operator bool() const
67  {
68  return time.time_since_epoch()!=Timestamp::duration::zero();
69  }
70  };
71  Position lastPosition;
72 
73  double lastReportedMaxSpeed{-1};
74 
75 public:
76  explicit SpeedAgent() = default;
77  std::list<NavigationMessageRef> Process(const NavigationMessageRef& message) override;
78 };
79 }
80 
81 #endif //OSMSCOUT_NAVIGATION_SPEED_AGENT_H
82 
std::chrono::system_clock::time_point Timestamp
Definition: Time.h:27
Definition: Area.h:86
double speed
Definition: SpeedAgent.h:31
bool defined
Definition: SpeedAgent.h:40
Definition: Area.h:38
double maxAllowedSpeed
Definition: SpeedAgent.h:39
#define CLASS_FINAL
Definition: Compiler.h:26
#define OSMSCOUT_API
Definition: CoreImportExport.h:45
Definition: Engine.h:78
std::shared_ptr< NavigationMessage > NavigationMessageRef
Definition: Engine.h:56
Timestamp time
Definition: SpeedAgent.h:64
Definition: Engine.h:48