PDA

View Full Version : OutGaugePack UDP datagram size?


PoVo
27th December 2011, 22:46
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:
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
};

MadCatX
27th December 2011, 23:14
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

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.

PoVo
27th December 2011, 23:37
Haha just really had a dumb moment :D

Never thought it was a simple as that!

Thanks for clearing that up! :razz:

DarkTimes
31st December 2011, 23:43
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/

MadCatX
1st January 2012, 00:02
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.

DarkTimes
1st January 2012, 01:34
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.