RigsofRods
Soft-body Physics Simulation
OutGauge.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
24 
25 #pragma once
26 
27 #include "Application.h"
28 
29 #ifdef USE_SOCKETW
30 #include "SocketW.h"
31 #endif //USE_SOCKETW
32 
33 #ifdef _WIN32
34 #include <Ws2tcpip.h>
35 #define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
36 #else
37 #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
38 #endif // _WIN32
39 
40 namespace RoR {
41 
44 
45 class OutGauge
46 {
47 public:
48 
49  OutGauge(void);
50 
51  void Connect();
52  bool Update(float dt, ActorPtr truck);
53  void Close();
54 
55 private:
56 
57  bool working;
58  float timer;
59  int sockfd;
60 
61 
62 
63  // from LFS/doc/insim.txt
64  enum
65  {
66  OG_SHIFT = 1, // key
67  OG_CTRL = 2, // key
68  OG_TURBO = 8192, // show turbo gauge
69  OG_KM = 16384, // if not set - user prefers MILES
70  OG_BAR = 32768, // if not set - user prefers PSI
71  };
72 
73  enum
74  {
75  DL_SHIFT = BITMASK(1), // bit 0 - shift light
76  DL_FULLBEAM = BITMASK(2), // bit 1 - full beam
77  DL_HANDBRAKE = BITMASK(3), // bit 2 - handbrake
78  DL_PITSPEED = BITMASK(4), // bit 3 - pit speed limiter
79  DL_TC = BITMASK(5), // bit 4 - TC active or switched off
80  DL_SIGNAL_L = BITMASK(6), // bit 5 - left turn signal
81  DL_SIGNAL_R = BITMASK(7), // bit 6 - right turn signal
82  DL_SIGNAL_ANY = BITMASK(8), // bit 7 - shared turn signal
83  DL_OILWARN = BITMASK(9), // bit 8 - oil pressure warning
84  DL_BATTERY = BITMASK(10), // bit 9 - battery warning
85  DL_ABS = BITMASK(11), // bit 10 - ABS active or switched off
86  DL_SPARE = BITMASK(12), // bit 11
87  DL_NUM = BITMASK(13) // bit 14 - end
88  };
89 
90  PACK (struct OutGaugePack
91  {
92  unsigned int Time; // time in milliseconds (to check order)
93  char Car[4]; // Car name
94  unsigned short Flags; // Info (see OG_x below)
95  unsigned char Gear; // Reverse:0, Neutral:1, First:2...
96  unsigned char PLID; // Unique ID of viewed player (0 = none)
97  float Speed; // M/S
98  float RPM; // RPM
99  float Turbo; // BAR
100  float EngTemp; // C
101  float Fuel; // 0 to 1
102  float OilPressure; // BAR
103  float OilTemp; // C
104  unsigned int DashLights; // Dash lights available (see DL_x below)
105  unsigned int ShowLights; // Dash lights currently switched on
106  float Throttle; // 0 to 1
107  float Brake; // 0 to 1
108  float Clutch; // 0 to 1
109  char Display1[16]; // Usually Fuel
110  char Display2[16]; // Usually Settings
111  int ID; // optional - only if OutGauge ID is specified
112  });
113 };
114 
116 
117 } // namespace RoR
118 
RoR::OutGauge::DL_FULLBEAM
@ DL_FULLBEAM
Definition: OutGauge.h:76
RoR::OutGauge::OG_SHIFT
@ OG_SHIFT
Definition: OutGauge.h:66
RoR::OutGauge::DL_SIGNAL_L
@ DL_SIGNAL_L
Definition: OutGauge.h:80
RoR::OutGauge::PACK
PACK(struct OutGaugePack { unsigned int Time;char Car[4];unsigned short Flags;unsigned char Gear;unsigned char PLID;float Speed;float RPM;float Turbo;float EngTemp;float Fuel;float OilPressure;float OilTemp;unsigned int DashLights;unsigned int ShowLights;float Throttle;float Brake;float Clutch;char Display1[16];char Display2[16];int ID;})
RoR::OutGauge::OG_CTRL
@ OG_CTRL
Definition: OutGauge.h:67
RoR::OutGauge::DL_SIGNAL_ANY
@ DL_SIGNAL_ANY
Definition: OutGauge.h:82
RoR::OutGauge::DL_SHIFT
@ DL_SHIFT
Definition: OutGauge.h:75
BITMASK
#define BITMASK(OFFSET)
Definition: BitFlags.h:10
RoR::OutGauge::DL_BATTERY
@ DL_BATTERY
Definition: OutGauge.h:84
RefCountingObjectPtr< Actor >
RoR::OutGauge::OG_KM
@ OG_KM
Definition: OutGauge.h:69
RoR::OutGauge::DL_PITSPEED
@ DL_PITSPEED
Definition: OutGauge.h:78
Application.h
Central state/object manager and communications hub.
RoR::OutGauge
Definition: OutGauge.h:45
RoR::OutGauge::DL_HANDBRAKE
@ DL_HANDBRAKE
Definition: OutGauge.h:77
RoR::OutGauge::OutGauge
OutGauge(void)
Definition: OutGauge.cpp:36
RoR::OutGauge::DL_SIGNAL_R
@ DL_SIGNAL_R
Definition: OutGauge.h:81
RoR::OutGauge::OG_TURBO
@ OG_TURBO
Definition: OutGauge.h:68
RoR::OutGauge::DL_SPARE
@ DL_SPARE
Definition: OutGauge.h:86
RoR::OutGauge::DL_ABS
@ DL_ABS
Definition: OutGauge.h:85
RoR::OutGauge::Close
void Close()
Definition: OutGauge.cpp:43
RoR::OutGauge::timer
float timer
Definition: OutGauge.h:58
RoR::OutGauge::DL_NUM
@ DL_NUM
Definition: OutGauge.h:87
RoR::OutGauge::sockfd
int sockfd
Definition: OutGauge.h:59
RoR::OutGauge::working
bool working
Definition: OutGauge.h:57
RoR::OutGauge::OG_BAR
@ OG_BAR
Definition: OutGauge.h:70
RoR::OutGauge::Update
bool Update(float dt, ActorPtr truck)
Definition: OutGauge.cpp:103
RoR::OutGauge::DL_OILWARN
@ DL_OILWARN
Definition: OutGauge.h:83
RoR::OutGauge::DL_TC
@ DL_TC
Definition: OutGauge.h:79
RoR
Definition: AppContext.h:36
RoR::OutGauge::Connect
void Connect()
Definition: OutGauge.cpp:58