The online racing simulator
OutGaugePack UDP datagram size?
(6 posts, started )
#1 - PoVo
OutGaugePack UDP datagram size?
Hi,

I'm currently coding an OutGauge packet receiver for my Android phone in Java.

I have hit a problem where I don't know the size of the buffer in bytes for the datagram.

What's the size of the OG packet for the buffer? More importantly, how is it calculated from such detail:

<?php 
struct OutGaugePack
{
    
unsigned    Time;            // time in milliseconds (to check order)

    
char        Car[4];            // Car name
    
word        Flags;            // Info (see OG_x below)
    
byte        Gear;            // Reverse:0, Neutral:1, First:2...
    
byte        PLID;            // Unique ID of viewed player (0 = none)
    
float        Speed;            // M/S
    
float        RPM;            // RPM
    
float        Turbo;            // BAR
    
float        EngTemp;        // C
    
float        Fuel;            // 0 to 1
    
float        OilPressure;    // BAR
    
float        OilTemp;        // C
    
unsigned    DashLights;        // Dash lights available (see DL_x below)
    
unsigned    ShowLights;        // Dash lights currently switched on
    
float        Throttle;        // 0 to 1
    
float        Brake;            // 0 to 1
    
float        Clutch;            // 0 to 1
    
char        Display1[16];    // Usually Fuel
    
char        Display2[16];    // Usually Settings

    
int            ID;                // optional - only if OutGauge ID is specified
};
?>

This is actually quite easy, assuming that LFS is a 32bit x86 application. It's pretty easy to google the sizes of each variable type, x86 architecture uses

<?php 
int 
32 bits 4 bytes
unsigned 
unsigned int 32 bits 4 bytes
float 
32 bits 4 bytes
double 
64 bits 8 bytes
char 
8 bits 1 byte
byte 
unsigned char 8 bits 1 byte
short 
16 bits 2 bytes
word 
unsigned short 16 bits 2 bytes
?>


Size of an array is always SIZE_OF_TYPE * ARRAY_LENGTH, for instance the "Car" string in the OutGauge packet takes up 4 bytes. Also note that "byte" and "word" are not 'official' data types (at least not in C/C++), Scawen defined those manually to spare himself writing "unsigned short" all the time.

With this in mind, it's easy to calculate that an OutGauge packet is either 92 or 96 bytes long, it depends on whether the ID is being used.
#3 - PoVo
Haha just really had a dumb moment

Never thought it was a simple as that!

Thanks for clearing that up!
You're probably going to have more trouble when you figure out that Java doesn't support unsigned integers. There is a whole open-source Java InSim library that you can steal code from (including OutGauge code), where it would seem that someone else has solved all these problems before you.

http://sourceforge.net/projects/jinsim/
The only problem I can see here is the "Time" value which could eventually exceed 2^31. I guess you could use long instead of int to work around this issue.
Yeah, you're probably right. I was just thinking you'd need to store any byte, word or unsigned value as a different data-type (short, int and long respectively). I don't know why the makers of Java decided to do it this way, I guess it made sense at the time.

OutGaugePack UDP datagram size?
(6 posts, started )
FGED GREDG RDFGDR GSFDG