The online racing simulator
Searching in All forums
(901 results)
mikey_G
S2 licensed
Thanks for the link. And yeah, I should've googled it a bit further, but a push in to the right direction is nice too for a n00b

But fortunately, after I get the flags bit down, I know eveything I need to know to make my app
mikey_G
S2 licensed
I hope you like corona

Anyway, here is the working source

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define OG_SHIFTLIGHT 1
#define OG_FULLBEAM 2
#define OG_HANDBRAKE 4
#define OG_PITSPEED 8
#define OG_TC 16
#define OG_HEADLIGHTS 32
#define OG_SIGNAL_L 64
#define OG_SIGNAL_R 128
#define OG_REDLINE 256
#define OG_OILWARN 512
#define OG_1 1024
#define OG_2 2048
#define OG_3 4096
#define OG_4 8192
#define OG_KM 16384
#define OG_BAR 32768

#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))

#define NTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))


#define MYPORT 55555 // the port users will be connecting to

typedef struct
{
unsigned int Time; // time in milliseconds (to check order)

char Car [4]; // Car name
unsigned short Flags; // OG_FLAGS (see below)
unsigned char Gear; // Reverse:0, Neutral:1, First:2...
unsigned char SpareB;
float Speed; // M/S
float RPM; // RPM
float Turbo; // BAR
float EngTemp; // C
float Fuel; // 0 to 1
float OilPress; // BAR
float Spare1;
float Spare2;
float Spare3;
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;
} __attribute__ ((packed)) OutGaugePacket;


float floatSwap (float value)
{
//char *value = (char*) &fl;
char buffer[ 4 ];

buffer[ 0 ] = ((char*)&value)[ 3 ];
buffer[ 1 ] = ((char*)&value)[ 2 ];
buffer[ 2 ] = ((char*)&value)[ 1 ];
buffer[ 3 ] = ((char*)&value)[ 0 ];

return *( (float *) &buffer );
}


int main(void)
{
int sockfd; // let's make a file descriptor
OutGaugePacket og_packet; // let's create an packet
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
socklen_t addr_len;
int numbytes;
memset(&(og_packet),'\0',96); // zero out the struct


//let's create the socket
if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(1);
}

// setting up our contact information here
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MYPORT); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct


//binding our socket to a port and address
if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
perror("bind");
exit(1);
}
addr_len = sizeof(struct sockaddr);

for (;;){
// receiving the goodies
if ((numbytes=recvfrom(sockfd, (void *)&og_packet, sizeof(OutGaugePacket) , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}
printf("\ngot packet from %s\n",inet_ntoa(their_addr.sin_addr));
printf("packet is %d bytes long\n\n", numbytes);

printf("Contents of packet:\n");
printf("Time = %u \t\tmemory address is %#X\n", NTOHL(og_packet.Time), &og_packet.Time);
printf("Car = %s \t\t\tmemory address is %#X\n", &og_packet.Car, &og_packet.Car);
printf("Gear = %d \t\t\tmemory address is %#X\n", og_packet.Gear -1, &og_packet.Gear);
printf("SpareB = %d \t\tmemory address is %#X\n", og_packet.SpareB, &og_packet.Gear);
printf("Speed = %.f \t\tmemory address is %#X\n", (floatSwap(og_packet.Speed)) * 3.6, &og_packet.Speed);
printf("RPM = %.f \t\tmemory address is %#X\n", floatSwap(og_packet.RPM), &og_packet.RPM);
printf("Turbo = %f \tmemory address is %#X\n", floatSwap(og_packet.Turbo), &og_packet.Turbo);
printf("EngTemp = %.f \t\tmemory address is %#X\n", floatSwap(og_packet.EngTemp), &og_packet.EngTemp);
printf("Fuel = %f \tmemory address is %#X\n", floatSwap(og_packet.Fuel), &og_packet.Fuel);
printf("OilPress = %.2f \tmemory address is %#X\n", floatSwap(og_packet.OilPress), &og_packet.OilPress);
printf("Spare1 = %.2f \tmemory address is %#X\n", floatSwap(og_packet.Spare1), &og_packet.Spare1);
printf("Spare2 = %.2f \tmemory address is %#X\n", floatSwap(og_packet.Spare2), &og_packet.Spare2);
printf("Spare3 = %.2f \tmemory address is %#X\n", floatSwap(og_packet.Spare3), &og_packet.Spare3);
printf("Throttle = %.f%% \tmemory address is %#X\n", (floatSwap(og_packet.Throttle) * 100), &og_packet.Throttle);
printf("Brake = %.f%% \t\tmemory address is %#X\n", (floatSwap(og_packet.Brake)* 100), &og_packet.Brake);
printf("Clutch = %.f%% \t\tmemory address is %#X\n", (floatSwap(og_packet.Clutch)* 100), &og_packet.Clutch);
printf("Display1 = %s\t\t\t%#X\n", &og_packet.Display1, &og_packet.Display1);
printf("Display2 = %s\t\t\t%#X\n", &og_packet.Display2, &og_packet.Display2);
printf("ID = %u \t\t\tmemory address is %#X\n", NTOHL(og_packet.ID), &og_packet.ID);
}

close(sockfd);

return 0;
}


It's far from nice, but it's a easy sample application where other people can play with, I learned a lot of it anyway.


Here some output
got packet from 192.168.1.2
packet is 96 bytes long

Contents of packet:
Time = 167580 memory address is 0XBFFFF8B4
Car = RB4 memory address is 0XBFFFF8B8
Gear = 3 memory address is 0XBFFFF8BE
SpareB = 0 memory address is 0XBFFFF8BE
Speed = 96 memory address is 0XBFFFF8C0
RPM = 7090 memory address is 0XBFFFF8C4
Turbo = 0.082909 memory address is 0XBFFFF8C8
EngTemp = 0 memory address is 0XBFFFF8CC
Fuel = 0.069851 memory address is 0XBFFFF8D0
OilPress = 0.00 memory address is 0XBFFFF8D4
Spare1 = 0.00 memory address is 0XBFFFF8D8
Spare2 = 0.00 memory address is 0XBFFFF8DC
Spare3 = 0.00 memory address is 0XBFFFF8E0
Throttle = 80% memory address is 0XBFFFF8E4
Brake = 0% memory address is 0XBFFFF8E8
Clutch = 20% memory address is 0XBFFFF8EC
Display1 = Fuel 5.2 0XBFFFF8F0
Display2 = Brake Bal F 73% 0XBFFFF900
ID = 1 memory address is 0XBFFFF910

Now all I have to do is getting the values in to a nice Cocoa app, and then beauty ensues

Btw, does anyone have any tips for getting the flag status out of the 16 bit "Flags" element?
mikey_G
S2 licensed
isn't criticism also an opinion?
mikey_G
S2 licensed
I've driven it in the new patch, but if you play a little bit with the diff, you can make a quite nice car out of it.
mikey_G
S2 licensed
It works really nice, I'll post an updated source tomorrow with all the other structure elements outputted.
I'm really glad the app works now, because I did get kinda hopeless (and I actually wanted to spend indepence day differently then coding the whole evening )

Anyhow, thanks again Kada, it wouldn't have been possible without you

me to bed now
mikey_G
S2 licensed
That one is also working great, which one do you think I should use? I've once seen an app in Xcode to time your functions, but forgot how it worked.
mikey_G
S2 licensed
Your solution works too, and I prefer yours to be honest. Putting the floats to char in the struct is just not nice.

Right now this is my output:
[Session started at 2007-04-24 02:01:01 +0200.]


got packet from 192.168.1.2
packet is 96 bytes long

Time = 23690, memory address is BFFFF910
Car = FXO, memory address is BFFFF914
Speed = 133.660039, memory address is BFFFF91C
RPM = 6800.274902, memory address is BFFFF920
ID of connection = 1
sizeof struct = 96


OutGuage has exited with status 0.

As you can see, it works!!!!


Thank you so much Kada_CZ, you've been a great help to me. I owe you one
mikey_G
S2 licensed
I think I found something that works, and complies with Occam Razor

float floatSwap(char *value)
{
char buffer[ 4 ];

buffer[ 0 ] = value[ 3 ];
buffer[ 1 ] = value[ 2 ];
buffer[ 2 ] = value[ 1 ];
buffer[ 3 ] = value[ 0 ];

return *( (float *) &buffer );
}

I swap the RPM data type in the OutGuagepacket structure to "char RPM[4];"

and then i output it:

printf("RPM = %f, memory address is %X\n", floatSwap(&og_packet.RPM), &og_packet.RPM);

This does raise a warning for me:

warning: passing argument 1 of 'floatSwap' from incompatible pointer type

Would be nice if I could get rid of it.


This is my output now, check the RPM in the middle of the output:

[Session started at 2007-04-24 01:51:33 +0200.]


got packet from 192.168.1.2
packet is 96 bytes long

Time = 21180, memory address is BFFFF880
Car = FXO, memory address is BFFFF884
Speed = 0.000000, memory address is A
RPM = 7941.076172, memory address is BFFFF890
ID of connection = 1
sizeof struct = 96

RPM = 2432237568.000000, memory address is BFFFF890


OutGuageFoundation has exited with status 0.

It looks like its working, and the solution was the easiest I could ever think of.
mikey_G
S2 licensed
Quote from Kada_CZ :
#define HTONL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))

#define NTOHL(n) (((((unsigned long)(n) & 0xFF)) << 24) | \
((((unsigned long)(n) & 0xFF00)) << 8) | \
((((unsigned long)(n) & 0xFF0000)) >> 8) | \
((((unsigned long)(n) & 0xFF000000)) >> 24))


It works great for the ints, time and connection ID show up perfectly, but the floats are still messed up

[Session started at 2007-04-24 01:11:59 +0200.]


got packet from 192.168.1.2
packet is 96 bytes long

Time = 255830, memory address is BFFFF790
Car = RB4, memory address is BFFFF794
Speed = 0.000000, memory address is A
RPM = -419242517033593602048.000000, memory address is BFFFF7A0
ID of connection = 1
sizeof struct = 96

RPM = 128.000000, memory address is BFFFF7A0

RPM = 128.000000, memory address is BFFFF7A0

RPM = 128.000000, memory address is BFFFF7A0

OutGuage has exited with status 0.
[Session started at 2007-04-24 01:12:04 +0200.]


got packet from 192.168.1.2
packet is 96 bytes long

Time = 261400, memory address is BFFFF790
Car = RB4, memory address is BFFFF794
Speed = nan, memory address is A
RPM = -16382559176468975824404480.000000, memory address is BFFFF7A0
ID of connection = 1
sizeof struct = 96

RPM = 128.000000, memory address is BFFFF7A0

RPM = 128.000000, memory address is BFFFF7A0

RPM = 128.000000, memory address is BFFFF7A0

OutGuage has exited with status 0.

But indeed, the OSX functions were just nothing more then some useless shit, weird...
I did get warnings though that I was overriding NTOHL and HTONL, so maybe they existed already.
Last edited by mikey_G, .
mikey_G
S2 licensed
Ok, got the connection number endiannes swapped with this

// 4-byte number
int INT_little_endian_TO_big_endian(int i)
{
return((i&0xff)<<24)+((i&0xff00)<<8)+((i&0xff0000)>>8)+((i>>24)&0xff);
}

It now shows Connection number = 1

babysteps for me
mikey_G
S2 licensed
No, but seriously, I had some plans for some nice apps but if I'm not even able to do this then I beter throw them into the bin.
So far my only accomplishments are getting the car name and getting a connection ID that actually stays stable, the other values just change with every packet
mikey_G
S2 licensed
Tried them both, this is the output what i get, your commands are on the bottom

[Session started at 2007-04-24 00:31:52 +0200.]


got packet from 192.168.1.2
packet is 96 bytes long

Time = 2929786880, memory address is BFFFF950
Car = RB4, memory address is BFFFF954
Speed = 1587048.125000, memory address is BFFFF95C
RPM = -29579291864432017246519296.000000, memory address is BFFFF960
ID of connection = 16777216
sizeof struct = 96

RPM = 2147483648.000000, memory address is BFFFF960

RPM = 2147483648.000000, memory address is BFFFF960


OutGuage has exited with status 0.

I'm getting more confused by the moment, and have an urge to throw this mac away
mikey_G
S2 licensed
Quote from Kada_CZ :It seems, that I was wrong with the "int ID" field. If "OutGauge ID" is set to 0 in the cfg.txt, then LFS (0.5W) sends only 92 bytes in the packet. If "OutGauge ID" is anything nonzero, then LFS send 96 bytes. I'm not sure, if it's a bug or a feature .

Yeah, I just tried that, and that's the case, pretty weird normal behaviour if you ask me

Quote from Kada_CZ :Ha, maybe I got it. Mac is a "big endian" system, PC is a "little endian", maybe this is the problem.

Hmm, kinda forgot how to change that around. I know that with the port and ip address you can do htons() and htonl(). I'll try to look a bit more into this.
mikey_G
S2 licensed
oy, that comma was indeed a bad mistake. Xcode didn't even complain about it (shows how good it is)
But I'll definitely try to make this working tomorrow in a loop, and if it doesn't I'll just start from scratch again with your sources as guidance.

btw, I did the changes you said, but i still get huge floating point numbers as results, and they're hardly stable (sometimes a negative number, sometimes positive, maybe there are some alignment issues, but I can't really find them).
mikey_G
S2 licensed
Well, it's our first league we've ever organized, so thanks for the complement Smile
mikey_G
S2 licensed
Yeah, here the lastest version, with the ID int because I do want to have that in my app.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define OG_SHIFTLIGHT 1
#define OG_FULLBEAM 2
#define OG_HANDBRAKE 4
#define OG_PITSPEED 8
#define OG_TC 16
#define OG_HEADLIGHTS 32
#define OG_SIGNAL_L 64
#define OG_SIGNAL_R 128
#define OG_REDLINE 256
#define OG_OILWARN 512
#define OG_1 1024
#define OG_2 2048
#define OG_3 4096
#define OG_4 8192
#define OG_KM 16384
#define OG_BAR 32768

#define MYPORT 55555 // the port users will be connecting to
#define MAXBUFLEN 92

typedef struct
{
unsigned int Time; // time in milliseconds (to check order)

char Car [4]; // Car name
unsigned short Flags; // OG_FLAGS (see below)
unsigned char Gear; // Reverse:0, Neutral:1, First:2...
unsigned char SpareB;
float Speed; // M/S
float RPM; // RPM
float Turbo; // BAR
float EngTemp; // C
float Fuel; // 0 to 1
float OilPress; // BAR
float Spare1;
float Spare2;
float Spare3;
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;
} __attribute__ ((packed)) OutGaugePacket;

int main(void)
{
int sockfd;
OutGaugePacket og_packet;
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
socklen_t addr_len;
int numbytes;

//memset(&(og_packet),'\0',95); // zero out the struct

if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(1);
}

my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MYPORT); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
perror("bind");
exit(1);
}

addr_len = sizeof(struct sockaddr);
if ((numbytes=recvfrom(sockfd, &og_packet, MAXBUFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}

printf("\n\ngot packet from %s\n",inet_ntoa(their_addr.sin_addr));
printf("packet is %d bytes long\n\n", numbytes);

printf("Time = %u, memory address is %X\n", og_packet.Time &og_packet.Time);
printf("Car = %s, memory address is %X\n", &og_packet.Car, &og_packet.Car);

printf("Speed = %f, memory address is %X\n", og_packet.Speed, &og_packet.Speed);
printf("RPM = %f, memory address is %X\n", og_packet.RPM, &og_packet.RPM);
printf("ID of connection = %d", og_packet.ID);
printf("\nsizeof struct = %d", sizeof(og_packet));

close(sockfd);

return 0;
}

As you can see, I stole your packet name, it made more sense

The above is still not working btw
Last edited by mikey_G, .
mikey_G
S2 licensed
Quote from dawesdust_12 :Cocoa is amazingly easy to create a GUI for, it should almost be illegal. I created a string character counter in like 3 minutes, with a GUI that looks remarkably sexy.

Yup, everything looks hot in Cocoa
mikey_G
S2 licensed
Well, I've added that to my structure, but didn't solve anything. I also did a sizeof() on the structure, and with and without it came back as 92 bytes in total.
I will definitely look at your sources to discover how you're doing it (and I'm quite used to messy code ).
mikey_G
S2 licensed
Well, the only thing I have to focus on now is getting this to work, so it's better if I stay here to solve the outgauge problem.
Making those full screen apps in cocoa wouldn't be a big problem, because there are good resources for it if you get stuck.
mikey_G
S2 licensed
pm sent

Well, I'm trying to make 2 full screen apps in Mac OS X. 1 that shows a pitboard so I can drive with shift-F on, and another one that shows all the outgauge of a group of people, so you can track your team for example.
But the future of those apps look pale, when I can't even make this simple app work
mikey_G
S2 licensed
Quote from dynofiend :im a bit confused

i already submitted a hotlap from so5 to enter the series, do i now need to submit another one to confirm my placing?

You're in the league with moose, you already qualified for it by sending a hotlap in time, so don't worry.
mikey_G
S2 licensed
Ok, I've changed the things which you mentioned, and the app is still acting the same

The updated source is here:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define OG_SHIFTLIGHT 1
#define OG_FULLBEAM 2
#define OG_HANDBRAKE 4
#define OG_PITSPEED 8
#define OG_TC 16
#define OG_HEADLIGHTS 32
#define OG_SIGNAL_L 64
#define OG_SIGNAL_R 128
#define OG_REDLINE 256
#define OG_OILWARN 512
#define OG_1 1024
#define OG_2 2048
#define OG_3 4096
#define OG_4 8192
#define OG_KM 16384
#define OG_BAR 32768

#define MYPORT 55555 // the port users will be connecting to
#define MAXBUFLEN 92

typedef struct
{
unsigned int Time; // time in milliseconds (to check order)

char Car [4]; // Car name
unsigned short Flags; // OG_FLAGS (see below)
unsigned char Gear; // Reverse:0, Neutral:1, First:2...
unsigned char SpareB;
float Speed; // M/S
float RPM; // RPM
float Turbo; // BAR
float EngTemp; // C
float Fuel; // 0 to 1
float OilPress; // BAR
float Spare1;
float Spare2;
float Spare3;
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
}OutGauge;

int main(void)
{
int sockfd;
OutGauge new;
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
socklen_t addr_len;
int numbytes;

memset(&(new),'\0',95); // zero out the struct

if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(1);
}

my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MYPORT); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
perror("bind");
exit(1);
}

addr_len = sizeof(struct sockaddr);
if ((numbytes=recvfrom(sockfd, &new, MAXBUFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}
new.Speed = htonl(new.Speed);
printf("\n\ngot packet from %s\n",inet_ntoa(their_addr.sin_addr));
printf("packet is %d bytes long\n\n", numbytes);

printf("Time = %u, memory address is %X\n", new.Time &new.Time);
printf("Car = %s, memory address is %X\n", &new.Car, &new.Car);

printf("Speed = %f, memory address is %X\n", new.Speed, &new.Speed);
printf("RPM = %f, memory address is %X\n", new.RPM, &new.RPM);

close(sockfd);

return 0;
}

You can see the output in the attachment along with the memory addresses (check the memory address of new.Time )

The thing that is still puzzelling me, is that the car name is read perfectly everytime, but the other field are just bogus.
By the way, if you have a better way to get the data from recvfrom() to a structure, please post. There isn't a single tutorial or sample app here in C or Objective-C, so I really need some help.
Simple OutGauge app in C not working
mikey_G
S2 licensed
Hi, I was playing around a bit on my macbook, and made this app so I can get outgauge data to display on it in a fancy way
So I decided to make a simple application first in C and BSD sockets. I can receive the UDP packets fine, and can clearly see the car's name when the app receives a packet, but the rest is messed up.

As you can see I changed the default outgauge struct a bit, because there are no byte and word data types in C or objective-C, so I just put chars there with the right sizes.

Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define OG_SHIFTLIGHT 1
#define OG_FULLBEAM 2
#define OG_HANDBRAKE 4
#define OG_PITSPEED 8
#define OG_TC 16
#define OG_HEADLIGHTS 32
#define OG_SIGNAL_L 64
#define OG_SIGNAL_R 128
#define OG_REDLINE 256
#define OG_OILWARN 512
#define OG_1 1024
#define OG_2 2048
#define OG_3 4096
#define OG_4 8192
#define OG_KM 16384
#define OG_BAR 32768

#define MYPORT 55555 // the port users will be connecting to
#define MAXBUFLEN 96

typedef struct {
unsigned Time;
char Car[4];
char Flags[2];
char Gear;
char SpareB;
float Speed;
float RPM;
float Turbo; // BAR
float EngTemp; // C
float Fuel; // 0 to 1
float OilPress; // BAR
float Spare1;
float Spare2;
float Spare3;
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
} OutGauge;

int main(void)
{
int sockfd;
OutGauge new;
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
socklen_t addr_len;
int numbytes;

memset(&(new),'\0',96); // zero out the struct

if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
perror("socket");
exit(1);
}

my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(MYPORT); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
perror("bind");
exit(1);
}

addr_len = sizeof(struct sockaddr);
if ((numbytes=recvfrom(sockfd, &new, MAXBUFLEN-1 , 0, (struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}

printf("got packet from %s\n",inet_ntoa(their_addr.sin_addr));
printf("packet is %d bytes long\n\n", numbytes);

printf("Time = %u\n", new.Time);
printf("Car = %s\n", &new.Car);

printf("Speed = %f\n", new.Speed);
printf("RPM = %f\n", new.RPM);

close(sockfd);

return 0;
}

It would be great if someone can help me make this app work. By the way, I know this isn't the preferred style of coding, but it was just something simple.

Check the attachment to see the weird output sometimes. You can see it gets the type of car right, but everything else is just messed up.
Last edited by mikey_G, .
mikey_G
S2 licensed
I know, I was just kidding. We can always do the shitzenring after the test race
mikey_G
S2 licensed
Quote from TFalke55 :sounds really good... Is realy better to test the "How will it going to be" on a propper track, than on an Autocross Layout!

HEY! don't diss the shitzenring :uglyhamme
FGED GREDG RDFGDR GSFDG